Repair botch in application of patch.
[official-gcc.git] / gcc / calls.c
blob87f610e1f6aa5e81306264ed15539e4e0243c0aa
1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995 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)
9 any later version.
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. */
20 #include "config.h"
21 #include "rtl.h"
22 #include "tree.h"
23 #include "flags.h"
24 #include "expr.h"
25 #ifdef __STDC__
26 #include <stdarg.h>
27 #else
28 #include <varargs.h>
29 #endif
30 #include "insn-flags.h"
32 /* Decide whether a function's arguments should be processed
33 from first to last or from last to first.
35 They should if the stack and args grow in opposite directions, but
36 only if we have push insns. */
38 #ifdef PUSH_ROUNDING
40 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
41 #define PUSH_ARGS_REVERSED /* If it's last to first */
42 #endif
44 #endif
46 /* Like STACK_BOUNDARY but in units of bytes, not bits. */
47 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
49 /* Data structure and subroutines used within expand_call. */
51 struct arg_data
53 /* Tree node for this argument. */
54 tree tree_value;
55 /* Mode for value; TYPE_MODE unless promoted. */
56 enum machine_mode mode;
57 /* Current RTL value for argument, or 0 if it isn't precomputed. */
58 rtx value;
59 /* Initially-compute RTL value for argument; only for const functions. */
60 rtx initial_value;
61 /* Register to pass this argument in, 0 if passed on stack, or an
62 EXPR_LIST if the arg is to be copied into multiple different
63 registers. */
64 rtx reg;
65 /* If REG was promoted from the actual mode of the argument expression,
66 indicates whether the promotion is sign- or zero-extended. */
67 int unsignedp;
68 /* Number of registers to use. 0 means put the whole arg in registers.
69 Also 0 if not passed in registers. */
70 int partial;
71 /* Non-zero if argument must be passed on stack.
72 Note that some arguments may be passed on the stack
73 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
74 pass_on_stack identifies arguments that *cannot* go in registers. */
75 int pass_on_stack;
76 /* Offset of this argument from beginning of stack-args. */
77 struct args_size offset;
78 /* Similar, but offset to the start of the stack slot. Different from
79 OFFSET if this arg pads downward. */
80 struct args_size slot_offset;
81 /* Size of this argument on the stack, rounded up for any padding it gets,
82 parts of the argument passed in registers do not count.
83 If REG_PARM_STACK_SPACE is defined, then register parms
84 are counted here as well. */
85 struct args_size size;
86 /* Location on the stack at which parameter should be stored. The store
87 has already been done if STACK == VALUE. */
88 rtx stack;
89 /* Location on the stack of the start of this argument slot. This can
90 differ from STACK if this arg pads downward. This location is known
91 to be aligned to FUNCTION_ARG_BOUNDARY. */
92 rtx stack_slot;
93 #ifdef ACCUMULATE_OUTGOING_ARGS
94 /* Place that this stack area has been saved, if needed. */
95 rtx save_area;
96 #endif
97 #ifdef STRICT_ALIGNMENT
98 /* If an argument's alignment does not permit direct copying into registers,
99 copy in smaller-sized pieces into pseudos. These are stored in a
100 block pointed to by this field. The next field says how many
101 word-sized pseudos we made. */
102 rtx *aligned_regs;
103 int n_aligned_regs;
104 #endif
107 #ifdef ACCUMULATE_OUTGOING_ARGS
108 /* A vector of one char per byte of stack space. A byte if non-zero if
109 the corresponding stack location has been used.
110 This vector is used to prevent a function call within an argument from
111 clobbering any stack already set up. */
112 static char *stack_usage_map;
114 /* Size of STACK_USAGE_MAP. */
115 static int highest_outgoing_arg_in_use;
117 /* stack_arg_under_construction is nonzero when an argument may be
118 initialized with a constructor call (including a C function that
119 returns a BLKmode struct) and expand_call must take special action
120 to make sure the object being constructed does not overlap the
121 argument list for the constructor call. */
122 int stack_arg_under_construction;
123 #endif
125 static int calls_function PROTO((tree, int));
126 static int calls_function_1 PROTO((tree, int));
127 static void emit_call_1 PROTO((rtx, tree, int, int, rtx, rtx, int,
128 rtx, int));
129 static void store_one_arg PROTO ((struct arg_data *, rtx, int, int,
130 tree, int));
132 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
133 `alloca'.
135 If WHICH is 0, return 1 if EXP contains a call to any function.
136 Actually, we only need return 1 if evaluating EXP would require pushing
137 arguments on the stack, but that is too difficult to compute, so we just
138 assume any function call might require the stack. */
140 static tree calls_function_save_exprs;
142 static int
143 calls_function (exp, which)
144 tree exp;
145 int which;
147 int val;
148 calls_function_save_exprs = 0;
149 val = calls_function_1 (exp, which);
150 calls_function_save_exprs = 0;
151 return val;
154 static int
155 calls_function_1 (exp, which)
156 tree exp;
157 int which;
159 register int i;
160 enum tree_code code = TREE_CODE (exp);
161 int type = TREE_CODE_CLASS (code);
162 int length = tree_code_length[(int) code];
164 /* If this code is langauge-specific, we don't know what it will do. */
165 if ((int) code >= NUM_TREE_CODES)
166 return 1;
168 /* Only expressions and references can contain calls. */
169 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
170 && type != 'b')
171 return 0;
173 switch (code)
175 case CALL_EXPR:
176 if (which == 0)
177 return 1;
178 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
179 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
180 == FUNCTION_DECL))
182 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
184 if ((DECL_BUILT_IN (fndecl)
185 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA)
186 || (DECL_SAVED_INSNS (fndecl)
187 && (FUNCTION_FLAGS (DECL_SAVED_INSNS (fndecl))
188 & FUNCTION_FLAGS_CALLS_ALLOCA)))
189 return 1;
192 /* Third operand is RTL. */
193 length = 2;
194 break;
196 case SAVE_EXPR:
197 if (SAVE_EXPR_RTL (exp) != 0)
198 return 0;
199 if (value_member (exp, calls_function_save_exprs))
200 return 0;
201 calls_function_save_exprs = tree_cons (NULL_TREE, exp,
202 calls_function_save_exprs);
203 return (TREE_OPERAND (exp, 0) != 0
204 && calls_function_1 (TREE_OPERAND (exp, 0), which));
206 case BLOCK:
208 register tree local;
210 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
211 if (DECL_INITIAL (local) != 0
212 && calls_function_1 (DECL_INITIAL (local), which))
213 return 1;
216 register tree subblock;
218 for (subblock = BLOCK_SUBBLOCKS (exp);
219 subblock;
220 subblock = TREE_CHAIN (subblock))
221 if (calls_function_1 (subblock, which))
222 return 1;
224 return 0;
226 case METHOD_CALL_EXPR:
227 length = 3;
228 break;
230 case WITH_CLEANUP_EXPR:
231 length = 1;
232 break;
234 case RTL_EXPR:
235 return 0;
238 for (i = 0; i < length; i++)
239 if (TREE_OPERAND (exp, i) != 0
240 && calls_function_1 (TREE_OPERAND (exp, i), which))
241 return 1;
243 return 0;
246 /* Force FUNEXP into a form suitable for the address of a CALL,
247 and return that as an rtx. Also load the static chain register
248 if FNDECL is a nested function.
250 CALL_FUSAGE points to a variable holding the prospective
251 CALL_INSN_FUNCTION_USAGE information. */
254 prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen)
255 rtx funexp;
256 tree fndecl;
257 rtx *call_fusage;
258 int reg_parm_seen;
260 rtx static_chain_value = 0;
262 funexp = protect_from_queue (funexp, 0);
264 if (fndecl != 0)
265 /* Get possible static chain value for nested function in C. */
266 static_chain_value = lookup_static_chain (fndecl);
268 /* Make a valid memory address and copy constants thru pseudo-regs,
269 but not for a constant address if -fno-function-cse. */
270 if (GET_CODE (funexp) != SYMBOL_REF)
271 funexp =
272 #ifdef SMALL_REGISTER_CLASSES
273 /* If we are using registers for parameters, force the
274 function address into a register now. */
275 reg_parm_seen ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
277 #endif
278 memory_address (FUNCTION_MODE, funexp);
279 else
281 #ifndef NO_FUNCTION_CSE
282 if (optimize && ! flag_no_function_cse)
283 #ifdef NO_RECURSIVE_FUNCTION_CSE
284 if (fndecl != current_function_decl)
285 #endif
286 funexp = force_reg (Pmode, funexp);
287 #endif
290 if (static_chain_value != 0)
292 emit_move_insn (static_chain_rtx, static_chain_value);
294 use_reg (call_fusage, static_chain_rtx);
297 return funexp;
300 /* Generate instructions to call function FUNEXP,
301 and optionally pop the results.
302 The CALL_INSN is the first insn generated.
304 FUNTYPE is the data type of the function, or, for a library call,
305 the identifier for the name of the call. This is given to the
306 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
308 STACK_SIZE is the number of bytes of arguments on the stack,
309 rounded up to STACK_BOUNDARY; zero if the size is variable.
310 This is both to put into the call insn and
311 to generate explicit popping code if necessary.
313 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
314 It is zero if this call doesn't want a structure value.
316 NEXT_ARG_REG is the rtx that results from executing
317 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
318 just after all the args have had their registers assigned.
319 This could be whatever you like, but normally it is the first
320 arg-register beyond those used for args in this call,
321 or 0 if all the arg-registers are used in this call.
322 It is passed on to `gen_call' so you can put this info in the call insn.
324 VALREG is a hard register in which a value is returned,
325 or 0 if the call does not return a value.
327 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
328 the args to this call were processed.
329 We restore `inhibit_defer_pop' to that value.
331 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
332 denote registers used by the called function.
334 IS_CONST is true if this is a `const' call. */
336 static void
337 emit_call_1 (funexp, funtype, stack_size, struct_value_size, next_arg_reg,
338 valreg, old_inhibit_defer_pop, call_fusage, is_const)
339 rtx funexp;
340 tree funtype;
341 int stack_size;
342 int struct_value_size;
343 rtx next_arg_reg;
344 rtx valreg;
345 int old_inhibit_defer_pop;
346 rtx call_fusage;
347 int is_const;
349 rtx stack_size_rtx = GEN_INT (stack_size);
350 rtx struct_value_size_rtx = GEN_INT (struct_value_size);
351 rtx call_insn;
352 int already_popped = 0;
354 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
355 and we don't want to load it into a register as an optimization,
356 because prepare_call_address already did it if it should be done. */
357 if (GET_CODE (funexp) != SYMBOL_REF)
358 funexp = memory_address (FUNCTION_MODE, funexp);
360 #ifndef ACCUMULATE_OUTGOING_ARGS
361 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
362 if (HAVE_call_pop && HAVE_call_value_pop
363 && (RETURN_POPS_ARGS (funtype, stack_size) > 0 || stack_size == 0))
365 rtx n_pop = GEN_INT (RETURN_POPS_ARGS (funtype, stack_size));
366 rtx pat;
368 /* If this subroutine pops its own args, record that in the call insn
369 if possible, for the sake of frame pointer elimination. */
370 if (valreg)
371 pat = gen_call_value_pop (valreg,
372 gen_rtx (MEM, FUNCTION_MODE, funexp),
373 stack_size_rtx, next_arg_reg, n_pop);
374 else
375 pat = gen_call_pop (gen_rtx (MEM, FUNCTION_MODE, funexp),
376 stack_size_rtx, next_arg_reg, n_pop);
378 emit_call_insn (pat);
379 already_popped = 1;
381 else
382 #endif
383 #endif
385 #if defined (HAVE_call) && defined (HAVE_call_value)
386 if (HAVE_call && HAVE_call_value)
388 if (valreg)
389 emit_call_insn (gen_call_value (valreg,
390 gen_rtx (MEM, FUNCTION_MODE, funexp),
391 stack_size_rtx, next_arg_reg,
392 NULL_RTX));
393 else
394 emit_call_insn (gen_call (gen_rtx (MEM, FUNCTION_MODE, funexp),
395 stack_size_rtx, next_arg_reg,
396 struct_value_size_rtx));
398 else
399 #endif
400 abort ();
402 /* Find the CALL insn we just emitted. */
403 for (call_insn = get_last_insn ();
404 call_insn && GET_CODE (call_insn) != CALL_INSN;
405 call_insn = PREV_INSN (call_insn))
408 if (! call_insn)
409 abort ();
411 /* Put the register usage information on the CALL. If there is already
412 some usage information, put ours at the end. */
413 if (CALL_INSN_FUNCTION_USAGE (call_insn))
415 rtx link;
417 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
418 link = XEXP (link, 1))
421 XEXP (link, 1) = call_fusage;
423 else
424 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
426 /* If this is a const call, then set the insn's unchanging bit. */
427 if (is_const)
428 CONST_CALL_P (call_insn) = 1;
430 /* Restore this now, so that we do defer pops for this call's args
431 if the context of the call as a whole permits. */
432 inhibit_defer_pop = old_inhibit_defer_pop;
434 #ifndef ACCUMULATE_OUTGOING_ARGS
435 /* If returning from the subroutine does not automatically pop the args,
436 we need an instruction to pop them sooner or later.
437 Perhaps do it now; perhaps just record how much space to pop later.
439 If returning from the subroutine does pop the args, indicate that the
440 stack pointer will be changed. */
442 if (stack_size != 0 && RETURN_POPS_ARGS (funtype, stack_size) > 0)
444 if (!already_popped)
445 CALL_INSN_FUNCTION_USAGE (call_insn) =
446 gen_rtx (EXPR_LIST, VOIDmode,
447 gen_rtx (CLOBBER, VOIDmode, stack_pointer_rtx),
448 CALL_INSN_FUNCTION_USAGE (call_insn));
449 stack_size -= RETURN_POPS_ARGS (funtype, stack_size);
450 stack_size_rtx = GEN_INT (stack_size);
453 if (stack_size != 0)
455 if (flag_defer_pop && inhibit_defer_pop == 0 && !is_const)
456 pending_stack_adjust += stack_size;
457 else
458 adjust_stack (stack_size_rtx);
460 #endif
463 /* Generate all the code for a function call
464 and return an rtx for its value.
465 Store the value in TARGET (specified as an rtx) if convenient.
466 If the value is stored in TARGET then TARGET is returned.
467 If IGNORE is nonzero, then we ignore the value of the function call. */
470 expand_call (exp, target, ignore)
471 tree exp;
472 rtx target;
473 int ignore;
475 /* List of actual parameters. */
476 tree actparms = TREE_OPERAND (exp, 1);
477 /* RTX for the function to be called. */
478 rtx funexp;
479 /* Tree node for the function to be called (not the address!). */
480 tree funtree;
481 /* Data type of the function. */
482 tree funtype;
483 /* Declaration of the function being called,
484 or 0 if the function is computed (not known by name). */
485 tree fndecl = 0;
486 char *name = 0;
488 /* Register in which non-BLKmode value will be returned,
489 or 0 if no value or if value is BLKmode. */
490 rtx valreg;
491 /* Address where we should return a BLKmode value;
492 0 if value not BLKmode. */
493 rtx structure_value_addr = 0;
494 /* Nonzero if that address is being passed by treating it as
495 an extra, implicit first parameter. Otherwise,
496 it is passed by being copied directly into struct_value_rtx. */
497 int structure_value_addr_parm = 0;
498 /* Size of aggregate value wanted, or zero if none wanted
499 or if we are using the non-reentrant PCC calling convention
500 or expecting the value in registers. */
501 int struct_value_size = 0;
502 /* Nonzero if called function returns an aggregate in memory PCC style,
503 by returning the address of where to find it. */
504 int pcc_struct_value = 0;
506 /* Number of actual parameters in this call, including struct value addr. */
507 int num_actuals;
508 /* Number of named args. Args after this are anonymous ones
509 and they must all go on the stack. */
510 int n_named_args;
511 /* Count arg position in order args appear. */
512 int argpos;
514 /* Vector of information about each argument.
515 Arguments are numbered in the order they will be pushed,
516 not the order they are written. */
517 struct arg_data *args;
519 /* Total size in bytes of all the stack-parms scanned so far. */
520 struct args_size args_size;
521 /* Size of arguments before any adjustments (such as rounding). */
522 struct args_size original_args_size;
523 /* Data on reg parms scanned so far. */
524 CUMULATIVE_ARGS args_so_far;
525 /* Nonzero if a reg parm has been scanned. */
526 int reg_parm_seen;
527 /* Nonzero if this is an indirect function call. */
528 int current_call_is_indirect = 0;
530 /* Nonzero if we must avoid push-insns in the args for this call.
531 If stack space is allocated for register parameters, but not by the
532 caller, then it is preallocated in the fixed part of the stack frame.
533 So the entire argument block must then be preallocated (i.e., we
534 ignore PUSH_ROUNDING in that case). */
536 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
537 int must_preallocate = 1;
538 #else
539 #ifdef PUSH_ROUNDING
540 int must_preallocate = 0;
541 #else
542 int must_preallocate = 1;
543 #endif
544 #endif
546 /* Size of the stack reserved for parameter registers. */
547 int reg_parm_stack_space = 0;
549 /* 1 if scanning parms front to back, -1 if scanning back to front. */
550 int inc;
551 /* Address of space preallocated for stack parms
552 (on machines that lack push insns), or 0 if space not preallocated. */
553 rtx argblock = 0;
555 /* Nonzero if it is plausible that this is a call to alloca. */
556 int may_be_alloca;
557 /* Nonzero if this is a call to setjmp or a related function. */
558 int returns_twice;
559 /* Nonzero if this is a call to `longjmp'. */
560 int is_longjmp;
561 /* Nonzero if this is a call to an inline function. */
562 int is_integrable = 0;
563 /* Nonzero if this is a call to a `const' function.
564 Note that only explicitly named functions are handled as `const' here. */
565 int is_const = 0;
566 /* Nonzero if this is a call to a `volatile' function. */
567 int is_volatile = 0;
568 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
569 /* Define the boundary of the register parm stack space that needs to be
570 save, if any. */
571 int low_to_save = -1, high_to_save;
572 rtx save_area = 0; /* Place that it is saved */
573 #endif
575 #ifdef ACCUMULATE_OUTGOING_ARGS
576 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
577 char *initial_stack_usage_map = stack_usage_map;
578 #endif
580 rtx old_stack_level = 0;
581 int old_pending_adj = 0;
582 int old_stack_arg_under_construction;
583 int old_inhibit_defer_pop = inhibit_defer_pop;
584 tree old_cleanups = cleanups_this_call;
585 rtx call_fusage = 0;
586 register tree p;
587 register int i, j;
589 /* See if we can find a DECL-node for the actual function.
590 As a result, decide whether this is a call to an integrable function. */
592 p = TREE_OPERAND (exp, 0);
593 if (TREE_CODE (p) == ADDR_EXPR)
595 fndecl = TREE_OPERAND (p, 0);
596 if (TREE_CODE (fndecl) != FUNCTION_DECL)
597 fndecl = 0;
598 else
600 if (!flag_no_inline
601 && fndecl != current_function_decl
602 && DECL_INLINE (fndecl)
603 && DECL_SAVED_INSNS (fndecl))
604 is_integrable = 1;
605 else if (! TREE_ADDRESSABLE (fndecl))
607 /* In case this function later becomes inlinable,
608 record that there was already a non-inline call to it.
610 Use abstraction instead of setting TREE_ADDRESSABLE
611 directly. */
612 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline)
613 warning_with_decl (fndecl, "can't inline call to `%s'");
614 mark_addressable (fndecl);
617 if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
618 && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
619 is_const = 1;
621 if (TREE_THIS_VOLATILE (fndecl))
622 is_volatile = 1;
626 /* If we don't have specific function to call, see if we have a
627 constant or `noreturn' function from the type. */
628 if (fndecl == 0)
630 is_const = TREE_READONLY (TREE_TYPE (TREE_TYPE (p)));
631 is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
634 #ifdef REG_PARM_STACK_SPACE
635 #ifdef MAYBE_REG_PARM_STACK_SPACE
636 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
637 #else
638 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
639 #endif
640 #endif
642 /* Warn if this value is an aggregate type,
643 regardless of which calling convention we are using for it. */
644 if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
645 warning ("function call has aggregate value");
647 /* Set up a place to return a structure. */
649 /* Cater to broken compilers. */
650 if (aggregate_value_p (exp))
652 /* This call returns a big structure. */
653 is_const = 0;
655 #ifdef PCC_STATIC_STRUCT_RETURN
657 pcc_struct_value = 1;
658 /* Easier than making that case work right. */
659 if (is_integrable)
661 /* In case this is a static function, note that it has been
662 used. */
663 if (! TREE_ADDRESSABLE (fndecl))
664 mark_addressable (fndecl);
665 is_integrable = 0;
668 #else /* not PCC_STATIC_STRUCT_RETURN */
670 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
672 if (target && GET_CODE (target) == MEM)
673 structure_value_addr = XEXP (target, 0);
674 else
676 /* Assign a temporary on the stack to hold the value. */
678 /* For variable-sized objects, we must be called with a target
679 specified. If we were to allocate space on the stack here,
680 we would have no way of knowing when to free it. */
682 if (struct_value_size < 0)
683 abort ();
685 structure_value_addr
686 = XEXP (assign_stack_temp (BLKmode, struct_value_size, 1), 0);
687 MEM_IN_STRUCT_P (structure_value_addr)
688 = AGGREGATE_TYPE_P (TREE_TYPE (exp));
689 target = 0;
692 #endif /* not PCC_STATIC_STRUCT_RETURN */
695 /* If called function is inline, try to integrate it. */
697 if (is_integrable)
699 rtx temp;
700 rtx before_call = get_last_insn ();
702 temp = expand_inline_function (fndecl, actparms, target,
703 ignore, TREE_TYPE (exp),
704 structure_value_addr);
706 /* If inlining succeeded, return. */
707 if ((HOST_WIDE_INT) temp != -1)
709 if (flag_short_temps)
711 /* Perform all cleanups needed for the arguments of this
712 call (i.e. destructors in C++). It is ok if these
713 destructors clobber RETURN_VALUE_REG, because the
714 only time we care about this is when TARGET is that
715 register. But in C++, we take care to never return
716 that register directly. */
717 expand_cleanups_to (old_cleanups);
720 #ifdef ACCUMULATE_OUTGOING_ARGS
721 /* If the outgoing argument list must be preserved, push
722 the stack before executing the inlined function if it
723 makes any calls. */
725 for (i = reg_parm_stack_space - 1; i >= 0; i--)
726 if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
727 break;
729 if (stack_arg_under_construction || i >= 0)
731 rtx insn = NEXT_INSN (before_call), seq;
733 /* Look for a call in the inline function code.
734 If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is
735 nonzero then there is a call and it is not necessary
736 to scan the insns. */
738 if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0)
739 for (; insn; insn = NEXT_INSN (insn))
740 if (GET_CODE (insn) == CALL_INSN)
741 break;
743 if (insn)
745 /* Reserve enough stack space so that the largest
746 argument list of any function call in the inline
747 function does not overlap the argument list being
748 evaluated. This is usually an overestimate because
749 allocate_dynamic_stack_space reserves space for an
750 outgoing argument list in addition to the requested
751 space, but there is no way to ask for stack space such
752 that an argument list of a certain length can be
753 safely constructed. */
755 int adjust = OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl));
756 #ifdef REG_PARM_STACK_SPACE
757 /* Add the stack space reserved for register arguments
758 in the inline function. What is really needed is the
759 largest value of reg_parm_stack_space in the inline
760 function, but that is not available. Using the current
761 value of reg_parm_stack_space is wrong, but gives
762 correct results on all supported machines. */
763 adjust += reg_parm_stack_space;
764 #endif
765 start_sequence ();
766 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
767 allocate_dynamic_stack_space (GEN_INT (adjust),
768 NULL_RTX, BITS_PER_UNIT);
769 seq = get_insns ();
770 end_sequence ();
771 emit_insns_before (seq, NEXT_INSN (before_call));
772 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
775 #endif
777 /* If the result is equivalent to TARGET, return TARGET to simplify
778 checks in store_expr. They can be equivalent but not equal in the
779 case of a function that returns BLKmode. */
780 if (temp != target && rtx_equal_p (temp, target))
781 return target;
782 return temp;
785 /* If inlining failed, mark FNDECL as needing to be compiled
786 separately after all. If function was declared inline,
787 give a warning. */
788 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
789 && ! TREE_ADDRESSABLE (fndecl))
790 warning_with_decl (fndecl, "can't inline call to `%s'");
791 mark_addressable (fndecl);
794 /* When calling a const function, we must pop the stack args right away,
795 so that the pop is deleted or moved with the call. */
796 if (is_const)
797 NO_DEFER_POP;
799 function_call_count++;
801 if (fndecl && DECL_NAME (fndecl))
802 name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
804 /* On some machines (such as the PA) indirect calls have a different
805 calling convention than normal calls. FUNCTION_ARG in the target
806 description can look at current_call_is_indirect to determine which
807 calling convention to use. */
808 current_call_is_indirect = (fndecl == 0);
809 #if 0
810 = TREE_CODE (TREE_OPERAND (exp, 0)) == NON_LVALUE_EXPR ? 1 : 0;
811 #endif
813 #if 0
814 /* Unless it's a call to a specific function that isn't alloca,
815 if it has one argument, we must assume it might be alloca. */
817 may_be_alloca =
818 (!(fndecl != 0 && strcmp (name, "alloca"))
819 && actparms != 0
820 && TREE_CHAIN (actparms) == 0);
821 #else
822 /* We assume that alloca will always be called by name. It
823 makes no sense to pass it as a pointer-to-function to
824 anything that does not understand its behavior. */
825 may_be_alloca =
826 (name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
827 && name[0] == 'a'
828 && ! strcmp (name, "alloca"))
829 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
830 && name[0] == '_'
831 && ! strcmp (name, "__builtin_alloca"))));
832 #endif
834 /* See if this is a call to a function that can return more than once
835 or a call to longjmp. */
837 returns_twice = 0;
838 is_longjmp = 0;
840 if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 15)
842 char *tname = name;
844 /* Disregard prefix _, __ or __x. */
845 if (name[0] == '_')
847 if (name[1] == '_' && name[2] == 'x')
848 tname += 3;
849 else if (name[1] == '_')
850 tname += 2;
851 else
852 tname += 1;
855 if (tname[0] == 's')
857 returns_twice
858 = ((tname[1] == 'e'
859 && (! strcmp (tname, "setjmp")
860 || ! strcmp (tname, "setjmp_syscall")))
861 || (tname[1] == 'i'
862 && ! strcmp (tname, "sigsetjmp"))
863 || (tname[1] == 'a'
864 && ! strcmp (tname, "savectx")));
865 if (tname[1] == 'i'
866 && ! strcmp (tname, "siglongjmp"))
867 is_longjmp = 1;
869 else if ((tname[0] == 'q' && tname[1] == 's'
870 && ! strcmp (tname, "qsetjmp"))
871 || (tname[0] == 'v' && tname[1] == 'f'
872 && ! strcmp (tname, "vfork")))
873 returns_twice = 1;
875 else if (tname[0] == 'l' && tname[1] == 'o'
876 && ! strcmp (tname, "longjmp"))
877 is_longjmp = 1;
880 if (may_be_alloca)
881 current_function_calls_alloca = 1;
883 /* Don't let pending stack adjusts add up to too much.
884 Also, do all pending adjustments now
885 if there is any chance this might be a call to alloca. */
887 if (pending_stack_adjust >= 32
888 || (pending_stack_adjust > 0 && may_be_alloca))
889 do_pending_stack_adjust ();
891 /* Operand 0 is a pointer-to-function; get the type of the function. */
892 funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
893 if (TREE_CODE (funtype) != POINTER_TYPE)
894 abort ();
895 funtype = TREE_TYPE (funtype);
897 /* Push the temporary stack slot level so that we can free any temporaries
898 we make. */
899 push_temp_slots ();
901 /* Start updating where the next arg would go. */
902 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX);
904 /* If struct_value_rtx is 0, it means pass the address
905 as if it were an extra parameter. */
906 if (structure_value_addr && struct_value_rtx == 0)
908 /* If structure_value_addr is a REG other than
909 virtual_outgoing_args_rtx, we can use always use it. If it
910 is not a REG, we must always copy it into a register.
911 If it is virtual_outgoing_args_rtx, we must copy it to another
912 register in some cases. */
913 rtx temp = (GET_CODE (structure_value_addr) != REG
914 #ifdef ACCUMULATE_OUTGOING_ARGS
915 || (stack_arg_under_construction
916 && structure_value_addr == virtual_outgoing_args_rtx)
917 #endif
918 ? copy_addr_to_reg (structure_value_addr)
919 : structure_value_addr);
921 actparms
922 = tree_cons (error_mark_node,
923 make_tree (build_pointer_type (TREE_TYPE (funtype)),
924 temp),
925 actparms);
926 structure_value_addr_parm = 1;
929 /* Count the arguments and set NUM_ACTUALS. */
930 for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
931 num_actuals = i;
933 /* Compute number of named args.
934 Normally, don't include the last named arg if anonymous args follow.
935 We do include the last named arg if STRICT_ARGUMENT_NAMING is defined.
936 (If no anonymous args follow, the result of list_length is actually
937 one too large. This is harmless.)
939 If SETUP_INCOMING_VARARGS is defined and STRICT_ARGUMENT_NAMING is not,
940 this machine will be able to place unnamed args that were passed in
941 registers into the stack. So treat all args as named. This allows the
942 insns emitting for a specific argument list to be independent of the
943 function declaration.
945 If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable
946 way to pass unnamed args in registers, so we must force them into
947 memory. */
948 #if !defined(SETUP_INCOMING_VARARGS) || defined(STRICT_ARGUMENT_NAMING)
949 if (TYPE_ARG_TYPES (funtype) != 0)
950 n_named_args
951 = (list_length (TYPE_ARG_TYPES (funtype))
952 #ifndef STRICT_ARGUMENT_NAMING
953 /* Don't include the last named arg. */
955 #endif
956 /* Count the struct value address, if it is passed as a parm. */
957 + structure_value_addr_parm);
958 else
959 #endif
960 /* If we know nothing, treat all args as named. */
961 n_named_args = num_actuals;
963 /* Make a vector to hold all the information about each arg. */
964 args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
965 bzero ((char *) args, num_actuals * sizeof (struct arg_data));
967 args_size.constant = 0;
968 args_size.var = 0;
970 /* In this loop, we consider args in the order they are written.
971 We fill up ARGS from the front or from the back if necessary
972 so that in any case the first arg to be pushed ends up at the front. */
974 #ifdef PUSH_ARGS_REVERSED
975 i = num_actuals - 1, inc = -1;
976 /* In this case, must reverse order of args
977 so that we compute and push the last arg first. */
978 #else
979 i = 0, inc = 1;
980 #endif
982 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
983 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
985 tree type = TREE_TYPE (TREE_VALUE (p));
986 int unsignedp;
987 enum machine_mode mode;
989 args[i].tree_value = TREE_VALUE (p);
991 /* Replace erroneous argument with constant zero. */
992 if (type == error_mark_node || TYPE_SIZE (type) == 0)
993 args[i].tree_value = integer_zero_node, type = integer_type_node;
995 /* If TYPE is a transparent union, pass things the way we would
996 pass the first field of the union. We have already verified that
997 the modes are the same. */
998 if (TYPE_TRANSPARENT_UNION (type))
999 type = TREE_TYPE (TYPE_FIELDS (type));
1001 /* Decide where to pass this arg.
1003 args[i].reg is nonzero if all or part is passed in registers.
1005 args[i].partial is nonzero if part but not all is passed in registers,
1006 and the exact value says how many words are passed in registers.
1008 args[i].pass_on_stack is nonzero if the argument must at least be
1009 computed on the stack. It may then be loaded back into registers
1010 if args[i].reg is nonzero.
1012 These decisions are driven by the FUNCTION_... macros and must agree
1013 with those made by function.c. */
1015 /* See if this argument should be passed by invisible reference. */
1016 if ((TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1017 && contains_placeholder_p (TYPE_SIZE (type)))
1018 || TYPE_NEEDS_CONSTRUCTING (type)
1019 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1020 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, TYPE_MODE (type),
1021 type, argpos < n_named_args)
1022 #endif
1025 #ifdef FUNCTION_ARG_CALLEE_COPIES
1026 if (FUNCTION_ARG_CALLEE_COPIES (args_so_far, TYPE_MODE (type), type,
1027 argpos < n_named_args)
1028 /* If it's in a register, we must make a copy of it too. */
1029 /* ??? Is this a sufficient test? Is there a better one? */
1030 && !(TREE_CODE (args[i].tree_value) == VAR_DECL
1031 && REG_P (DECL_RTL (args[i].tree_value))))
1033 args[i].tree_value = build1 (ADDR_EXPR,
1034 build_pointer_type (type),
1035 args[i].tree_value);
1036 type = build_pointer_type (type);
1038 else
1039 #endif
1041 /* We make a copy of the object and pass the address to the
1042 function being called. */
1043 rtx copy;
1045 if (TYPE_SIZE (type) == 0
1046 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1048 /* This is a variable-sized object. Make space on the stack
1049 for it. */
1050 rtx size_rtx = expr_size (TREE_VALUE (p));
1052 if (old_stack_level == 0)
1054 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1055 old_pending_adj = pending_stack_adjust;
1056 pending_stack_adjust = 0;
1059 copy = gen_rtx (MEM, BLKmode,
1060 allocate_dynamic_stack_space (size_rtx,
1061 NULL_RTX,
1062 TYPE_ALIGN (type)));
1064 else
1066 int size = int_size_in_bytes (type);
1067 copy = assign_stack_temp (TYPE_MODE (type), size, 1);
1070 MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
1072 store_expr (args[i].tree_value, copy, 0);
1074 args[i].tree_value = build1 (ADDR_EXPR,
1075 build_pointer_type (type),
1076 make_tree (type, copy));
1077 type = build_pointer_type (type);
1081 mode = TYPE_MODE (type);
1082 unsignedp = TREE_UNSIGNED (type);
1084 #ifdef PROMOTE_FUNCTION_ARGS
1085 mode = promote_mode (type, mode, &unsignedp, 1);
1086 #endif
1088 args[i].unsignedp = unsignedp;
1089 args[i].mode = mode;
1090 args[i].reg = FUNCTION_ARG (args_so_far, mode, type,
1091 argpos < n_named_args);
1092 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1093 if (args[i].reg)
1094 args[i].partial
1095 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, type,
1096 argpos < n_named_args);
1097 #endif
1099 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
1101 /* If FUNCTION_ARG returned an (expr_list (nil) FOO), it means that
1102 we are to pass this arg in the register(s) designated by FOO, but
1103 also to pass it in the stack. */
1104 if (args[i].reg && GET_CODE (args[i].reg) == EXPR_LIST
1105 && XEXP (args[i].reg, 0) == 0)
1106 args[i].pass_on_stack = 1, args[i].reg = XEXP (args[i].reg, 1);
1108 /* If this is an addressable type, we must preallocate the stack
1109 since we must evaluate the object into its final location.
1111 If this is to be passed in both registers and the stack, it is simpler
1112 to preallocate. */
1113 if (TREE_ADDRESSABLE (type)
1114 || (args[i].pass_on_stack && args[i].reg != 0))
1115 must_preallocate = 1;
1117 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1118 we cannot consider this function call constant. */
1119 if (TREE_ADDRESSABLE (type))
1120 is_const = 0;
1122 /* Compute the stack-size of this argument. */
1123 if (args[i].reg == 0 || args[i].partial != 0
1124 #ifdef REG_PARM_STACK_SPACE
1125 || reg_parm_stack_space > 0
1126 #endif
1127 || args[i].pass_on_stack)
1128 locate_and_pad_parm (mode, type,
1129 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1131 #else
1132 args[i].reg != 0,
1133 #endif
1134 fndecl, &args_size, &args[i].offset,
1135 &args[i].size);
1137 #ifndef ARGS_GROW_DOWNWARD
1138 args[i].slot_offset = args_size;
1139 #endif
1141 #ifndef REG_PARM_STACK_SPACE
1142 /* If a part of the arg was put into registers,
1143 don't include that part in the amount pushed. */
1144 if (! args[i].pass_on_stack)
1145 args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1146 / (PARM_BOUNDARY / BITS_PER_UNIT)
1147 * (PARM_BOUNDARY / BITS_PER_UNIT));
1148 #endif
1150 /* Update ARGS_SIZE, the total stack space for args so far. */
1152 args_size.constant += args[i].size.constant;
1153 if (args[i].size.var)
1155 ADD_PARM_SIZE (args_size, args[i].size.var);
1158 /* Since the slot offset points to the bottom of the slot,
1159 we must record it after incrementing if the args grow down. */
1160 #ifdef ARGS_GROW_DOWNWARD
1161 args[i].slot_offset = args_size;
1163 args[i].slot_offset.constant = -args_size.constant;
1164 if (args_size.var)
1166 SUB_PARM_SIZE (args[i].slot_offset, args_size.var);
1168 #endif
1170 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1171 have been used, etc. */
1173 FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type,
1174 argpos < n_named_args);
1177 #ifdef FINAL_REG_PARM_STACK_SPACE
1178 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
1179 args_size.var);
1180 #endif
1182 /* Compute the actual size of the argument block required. The variable
1183 and constant sizes must be combined, the size may have to be rounded,
1184 and there may be a minimum required size. */
1186 original_args_size = args_size;
1187 if (args_size.var)
1189 /* If this function requires a variable-sized argument list, don't try to
1190 make a cse'able block for this call. We may be able to do this
1191 eventually, but it is too complicated to keep track of what insns go
1192 in the cse'able block and which don't. */
1194 is_const = 0;
1195 must_preallocate = 1;
1197 args_size.var = ARGS_SIZE_TREE (args_size);
1198 args_size.constant = 0;
1200 #ifdef STACK_BOUNDARY
1201 if (STACK_BOUNDARY != BITS_PER_UNIT)
1202 args_size.var = round_up (args_size.var, STACK_BYTES);
1203 #endif
1205 #ifdef REG_PARM_STACK_SPACE
1206 if (reg_parm_stack_space > 0)
1208 args_size.var
1209 = size_binop (MAX_EXPR, args_size.var,
1210 size_int (REG_PARM_STACK_SPACE (fndecl)));
1212 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1213 /* The area corresponding to register parameters is not to count in
1214 the size of the block we need. So make the adjustment. */
1215 args_size.var
1216 = size_binop (MINUS_EXPR, args_size.var,
1217 size_int (reg_parm_stack_space));
1218 #endif
1220 #endif
1222 else
1224 #ifdef STACK_BOUNDARY
1225 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
1226 / STACK_BYTES) * STACK_BYTES);
1227 #endif
1229 #ifdef REG_PARM_STACK_SPACE
1230 args_size.constant = MAX (args_size.constant,
1231 reg_parm_stack_space);
1232 #ifdef MAYBE_REG_PARM_STACK_SPACE
1233 if (reg_parm_stack_space == 0)
1234 args_size.constant = 0;
1235 #endif
1236 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1237 args_size.constant -= reg_parm_stack_space;
1238 #endif
1239 #endif
1242 /* See if we have or want to preallocate stack space.
1244 If we would have to push a partially-in-regs parm
1245 before other stack parms, preallocate stack space instead.
1247 If the size of some parm is not a multiple of the required stack
1248 alignment, we must preallocate.
1250 If the total size of arguments that would otherwise create a copy in
1251 a temporary (such as a CALL) is more than half the total argument list
1252 size, preallocation is faster.
1254 Another reason to preallocate is if we have a machine (like the m88k)
1255 where stack alignment is required to be maintained between every
1256 pair of insns, not just when the call is made. However, we assume here
1257 that such machines either do not have push insns (and hence preallocation
1258 would occur anyway) or the problem is taken care of with
1259 PUSH_ROUNDING. */
1261 if (! must_preallocate)
1263 int partial_seen = 0;
1264 int copy_to_evaluate_size = 0;
1266 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1268 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1269 partial_seen = 1;
1270 else if (partial_seen && args[i].reg == 0)
1271 must_preallocate = 1;
1273 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1274 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1275 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1276 || TREE_CODE (args[i].tree_value) == COND_EXPR
1277 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1278 copy_to_evaluate_size
1279 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1282 if (copy_to_evaluate_size * 2 >= args_size.constant
1283 && args_size.constant > 0)
1284 must_preallocate = 1;
1287 /* If the structure value address will reference the stack pointer, we must
1288 stabilize it. We don't need to do this if we know that we are not going
1289 to adjust the stack pointer in processing this call. */
1291 if (structure_value_addr
1292 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
1293 || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr))
1294 && (args_size.var
1295 #ifndef ACCUMULATE_OUTGOING_ARGS
1296 || args_size.constant
1297 #endif
1299 structure_value_addr = copy_to_reg (structure_value_addr);
1301 /* If this function call is cse'able, precompute all the parameters.
1302 Note that if the parameter is constructed into a temporary, this will
1303 cause an additional copy because the parameter will be constructed
1304 into a temporary location and then copied into the outgoing arguments.
1305 If a parameter contains a call to alloca and this function uses the
1306 stack, precompute the parameter. */
1308 /* If we preallocated the stack space, and some arguments must be passed
1309 on the stack, then we must precompute any parameter which contains a
1310 function call which will store arguments on the stack.
1311 Otherwise, evaluating the parameter may clobber previous parameters
1312 which have already been stored into the stack. */
1314 for (i = 0; i < num_actuals; i++)
1315 if (is_const
1316 || ((args_size.var != 0 || args_size.constant != 0)
1317 && calls_function (args[i].tree_value, 1))
1318 || (must_preallocate && (args_size.var != 0 || args_size.constant != 0)
1319 && calls_function (args[i].tree_value, 0)))
1321 push_temp_slots ();
1323 args[i].initial_value = args[i].value
1324 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1326 preserve_temp_slots (args[i].value);
1327 pop_temp_slots ();
1329 /* ANSI doesn't require a sequence point here,
1330 but PCC has one, so this will avoid some problems. */
1331 emit_queue ();
1333 args[i].initial_value = args[i].value
1334 = protect_from_queue (args[i].initial_value, 0);
1336 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != args[i].mode)
1337 args[i].value
1338 = convert_modes (args[i].mode,
1339 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1340 args[i].value, args[i].unsignedp);
1343 /* Now we are about to start emitting insns that can be deleted
1344 if a libcall is deleted. */
1345 if (is_const)
1346 start_sequence ();
1348 /* If we have no actual push instructions, or shouldn't use them,
1349 make space for all args right now. */
1351 if (args_size.var != 0)
1353 if (old_stack_level == 0)
1355 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1356 old_pending_adj = pending_stack_adjust;
1357 pending_stack_adjust = 0;
1358 #ifdef ACCUMULATE_OUTGOING_ARGS
1359 /* stack_arg_under_construction says whether a stack arg is
1360 being constructed at the old stack level. Pushing the stack
1361 gets a clean outgoing argument block. */
1362 old_stack_arg_under_construction = stack_arg_under_construction;
1363 stack_arg_under_construction = 0;
1364 #endif
1366 argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
1368 else
1370 /* Note that we must go through the motions of allocating an argument
1371 block even if the size is zero because we may be storing args
1372 in the area reserved for register arguments, which may be part of
1373 the stack frame. */
1375 int needed = args_size.constant;
1377 /* Store the maximum argument space used. It will be pushed by the
1378 prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow checking). */
1380 if (needed > current_function_outgoing_args_size)
1381 current_function_outgoing_args_size = needed;
1383 if (must_preallocate)
1385 #ifdef ACCUMULATE_OUTGOING_ARGS
1386 /* Since the stack pointer will never be pushed, it is possible for
1387 the evaluation of a parm to clobber something we have already
1388 written to the stack. Since most function calls on RISC machines
1389 do not use the stack, this is uncommon, but must work correctly.
1391 Therefore, we save any area of the stack that was already written
1392 and that we are using. Here we set up to do this by making a new
1393 stack usage map from the old one. The actual save will be done
1394 by store_one_arg.
1396 Another approach might be to try to reorder the argument
1397 evaluations to avoid this conflicting stack usage. */
1399 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1400 /* Since we will be writing into the entire argument area, the
1401 map must be allocated for its entire size, not just the part that
1402 is the responsibility of the caller. */
1403 needed += reg_parm_stack_space;
1404 #endif
1406 #ifdef ARGS_GROW_DOWNWARD
1407 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1408 needed + 1);
1409 #else
1410 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1411 needed);
1412 #endif
1413 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
1415 if (initial_highest_arg_in_use)
1416 bcopy (initial_stack_usage_map, stack_usage_map,
1417 initial_highest_arg_in_use);
1419 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
1420 bzero (&stack_usage_map[initial_highest_arg_in_use],
1421 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
1422 needed = 0;
1424 /* The address of the outgoing argument list must not be copied to a
1425 register here, because argblock would be left pointing to the
1426 wrong place after the call to allocate_dynamic_stack_space below.
1429 argblock = virtual_outgoing_args_rtx;
1431 #else /* not ACCUMULATE_OUTGOING_ARGS */
1432 if (inhibit_defer_pop == 0)
1434 /* Try to reuse some or all of the pending_stack_adjust
1435 to get this space. Maybe we can avoid any pushing. */
1436 if (needed > pending_stack_adjust)
1438 needed -= pending_stack_adjust;
1439 pending_stack_adjust = 0;
1441 else
1443 pending_stack_adjust -= needed;
1444 needed = 0;
1447 /* Special case this because overhead of `push_block' in this
1448 case is non-trivial. */
1449 if (needed == 0)
1450 argblock = virtual_outgoing_args_rtx;
1451 else
1452 argblock = push_block (GEN_INT (needed), 0, 0);
1454 /* We only really need to call `copy_to_reg' in the case where push
1455 insns are going to be used to pass ARGBLOCK to a function
1456 call in ARGS. In that case, the stack pointer changes value
1457 from the allocation point to the call point, and hence
1458 the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
1459 But might as well always do it. */
1460 argblock = copy_to_reg (argblock);
1461 #endif /* not ACCUMULATE_OUTGOING_ARGS */
1465 #ifdef ACCUMULATE_OUTGOING_ARGS
1466 /* The save/restore code in store_one_arg handles all cases except one:
1467 a constructor call (including a C function returning a BLKmode struct)
1468 to initialize an argument. */
1469 if (stack_arg_under_construction)
1471 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1472 rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
1473 #else
1474 rtx push_size = GEN_INT (args_size.constant);
1475 #endif
1476 if (old_stack_level == 0)
1478 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1479 old_pending_adj = pending_stack_adjust;
1480 pending_stack_adjust = 0;
1481 /* stack_arg_under_construction says whether a stack arg is
1482 being constructed at the old stack level. Pushing the stack
1483 gets a clean outgoing argument block. */
1484 old_stack_arg_under_construction = stack_arg_under_construction;
1485 stack_arg_under_construction = 0;
1486 /* Make a new map for the new argument list. */
1487 stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
1488 bzero (stack_usage_map, highest_outgoing_arg_in_use);
1489 highest_outgoing_arg_in_use = 0;
1491 allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
1493 /* If argument evaluation might modify the stack pointer, copy the
1494 address of the argument list to a register. */
1495 for (i = 0; i < num_actuals; i++)
1496 if (args[i].pass_on_stack)
1498 argblock = copy_addr_to_reg (argblock);
1499 break;
1501 #endif
1504 /* If we preallocated stack space, compute the address of each argument.
1505 We need not ensure it is a valid memory address here; it will be
1506 validized when it is used. */
1507 if (argblock)
1509 rtx arg_reg = argblock;
1510 int arg_offset = 0;
1512 if (GET_CODE (argblock) == PLUS)
1513 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1515 for (i = 0; i < num_actuals; i++)
1517 rtx offset = ARGS_SIZE_RTX (args[i].offset);
1518 rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1519 rtx addr;
1521 /* Skip this parm if it will not be passed on the stack. */
1522 if (! args[i].pass_on_stack && args[i].reg != 0)
1523 continue;
1525 if (GET_CODE (offset) == CONST_INT)
1526 addr = plus_constant (arg_reg, INTVAL (offset));
1527 else
1528 addr = gen_rtx (PLUS, Pmode, arg_reg, offset);
1530 addr = plus_constant (addr, arg_offset);
1531 args[i].stack = gen_rtx (MEM, args[i].mode, addr);
1532 MEM_IN_STRUCT_P (args[i].stack)
1533 = AGGREGATE_TYPE_P (TREE_TYPE (args[i].tree_value));
1535 if (GET_CODE (slot_offset) == CONST_INT)
1536 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1537 else
1538 addr = gen_rtx (PLUS, Pmode, arg_reg, slot_offset);
1540 addr = plus_constant (addr, arg_offset);
1541 args[i].stack_slot = gen_rtx (MEM, args[i].mode, addr);
1545 #ifdef PUSH_ARGS_REVERSED
1546 #ifdef STACK_BOUNDARY
1547 /* If we push args individually in reverse order, perform stack alignment
1548 before the first push (the last arg). */
1549 if (argblock == 0)
1550 anti_adjust_stack (GEN_INT (args_size.constant
1551 - original_args_size.constant));
1552 #endif
1553 #endif
1555 /* Don't try to defer pops if preallocating, not even from the first arg,
1556 since ARGBLOCK probably refers to the SP. */
1557 if (argblock)
1558 NO_DEFER_POP;
1560 /* Get the function to call, in the form of RTL. */
1561 if (fndecl)
1563 /* If this is the first use of the function, see if we need to
1564 make an external definition for it. */
1565 if (! TREE_USED (fndecl))
1567 assemble_external (fndecl);
1568 TREE_USED (fndecl) = 1;
1571 /* Get a SYMBOL_REF rtx for the function address. */
1572 funexp = XEXP (DECL_RTL (fndecl), 0);
1574 else
1575 /* Generate an rtx (probably a pseudo-register) for the address. */
1577 push_temp_slots ();
1578 funexp = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1579 pop_temp_slots (); /* FUNEXP can't be BLKmode */
1580 emit_queue ();
1583 /* Figure out the register where the value, if any, will come back. */
1584 valreg = 0;
1585 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
1586 && ! structure_value_addr)
1588 if (pcc_struct_value)
1589 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
1590 fndecl);
1591 else
1592 valreg = hard_function_value (TREE_TYPE (exp), fndecl);
1595 /* Precompute all register parameters. It isn't safe to compute anything
1596 once we have started filling any specific hard regs. */
1597 reg_parm_seen = 0;
1598 for (i = 0; i < num_actuals; i++)
1599 if (args[i].reg != 0 && ! args[i].pass_on_stack)
1601 reg_parm_seen = 1;
1603 if (args[i].value == 0)
1605 push_temp_slots ();
1606 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
1607 VOIDmode, 0);
1608 preserve_temp_slots (args[i].value);
1609 pop_temp_slots ();
1611 /* ANSI doesn't require a sequence point here,
1612 but PCC has one, so this will avoid some problems. */
1613 emit_queue ();
1616 /* If we are to promote the function arg to a wider mode,
1617 do it now. */
1619 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
1620 args[i].value
1621 = convert_modes (args[i].mode,
1622 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1623 args[i].value, args[i].unsignedp);
1625 /* If the value is expensive, and we are inside an appropriately
1626 short loop, put the value into a pseudo and then put the pseudo
1627 into the hard reg.
1629 For small register classes, also do this if this call uses
1630 register parameters. This is to avoid reload conflicts while
1631 loading the parameters registers. */
1633 if ((! (GET_CODE (args[i].value) == REG
1634 || (GET_CODE (args[i].value) == SUBREG
1635 && GET_CODE (SUBREG_REG (args[i].value)) == REG)))
1636 && args[i].mode != BLKmode
1637 && rtx_cost (args[i].value, SET) > 2
1638 #ifdef SMALL_REGISTER_CLASSES
1639 && (reg_parm_seen || preserve_subexpressions_p ())
1640 #else
1641 && preserve_subexpressions_p ()
1642 #endif
1644 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
1647 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1648 /* The argument list is the property of the called routine and it
1649 may clobber it. If the fixed area has been used for previous
1650 parameters, we must save and restore it.
1652 Here we compute the boundary of the that needs to be saved, if any. */
1654 #ifdef ARGS_GROW_DOWNWARD
1655 for (i = 0; i < reg_parm_stack_space + 1; i++)
1656 #else
1657 for (i = 0; i < reg_parm_stack_space; i++)
1658 #endif
1660 if (i >= highest_outgoing_arg_in_use
1661 || stack_usage_map[i] == 0)
1662 continue;
1664 if (low_to_save == -1)
1665 low_to_save = i;
1667 high_to_save = i;
1670 if (low_to_save >= 0)
1672 int num_to_save = high_to_save - low_to_save + 1;
1673 enum machine_mode save_mode
1674 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
1675 rtx stack_area;
1677 /* If we don't have the required alignment, must do this in BLKmode. */
1678 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
1679 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
1680 save_mode = BLKmode;
1682 stack_area = gen_rtx (MEM, save_mode,
1683 memory_address (save_mode,
1685 #ifdef ARGS_GROW_DOWNWARD
1686 plus_constant (argblock,
1687 - high_to_save)
1688 #else
1689 plus_constant (argblock,
1690 low_to_save)
1691 #endif
1693 if (save_mode == BLKmode)
1695 save_area = assign_stack_temp (BLKmode, num_to_save, 1);
1696 MEM_IN_STRUCT_P (save_area) = 0;
1697 emit_block_move (validize_mem (save_area), stack_area,
1698 GEN_INT (num_to_save),
1699 PARM_BOUNDARY / BITS_PER_UNIT);
1701 else
1703 save_area = gen_reg_rtx (save_mode);
1704 emit_move_insn (save_area, stack_area);
1707 #endif
1710 /* Now store (and compute if necessary) all non-register parms.
1711 These come before register parms, since they can require block-moves,
1712 which could clobber the registers used for register parms.
1713 Parms which have partial registers are not stored here,
1714 but we do preallocate space here if they want that. */
1716 for (i = 0; i < num_actuals; i++)
1717 if (args[i].reg == 0 || args[i].pass_on_stack)
1718 store_one_arg (&args[i], argblock, may_be_alloca,
1719 args_size.var != 0, fndecl, reg_parm_stack_space);
1721 #ifdef STRICT_ALIGNMENT
1722 /* If we have a parm that is passed in registers but not in memory
1723 and whose alignment does not permit a direct copy into registers,
1724 make a group of pseudos that correspond to each register that we
1725 will later fill. */
1727 for (i = 0; i < num_actuals; i++)
1728 if (args[i].reg != 0 && ! args[i].pass_on_stack
1729 && args[i].mode == BLKmode
1730 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
1731 < MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
1733 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1734 int big_endian_correction = 0;
1736 args[i].n_aligned_regs
1737 = args[i].partial ? args[i].partial
1738 : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
1740 args[i].aligned_regs = (rtx *) alloca (sizeof (rtx)
1741 * args[i].n_aligned_regs);
1743 /* Structures smaller than a word are aligned to the least signifcant
1744 byte (to the right). On a BYTES_BIG_ENDIAN machine, this means we
1745 must skip the empty high order bytes when calculating the bit
1746 offset. */
1747 if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD)
1748 big_endian_correction = (BITS_PER_WORD - (bytes * BITS_PER_UNIT));
1750 for (j = 0; j < args[i].n_aligned_regs; j++)
1752 rtx reg = gen_reg_rtx (word_mode);
1753 rtx word = operand_subword_force (args[i].value, j, BLKmode);
1754 int bitsize = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
1755 int bitpos;
1757 args[i].aligned_regs[j] = reg;
1759 /* Clobber REG and move each partword into it. Ensure we don't
1760 go past the end of the structure. Note that the loop below
1761 works because we've already verified that padding
1762 and endianness are compatible. */
1764 emit_insn (gen_rtx (CLOBBER, VOIDmode, reg));
1766 for (bitpos = 0;
1767 bitpos < BITS_PER_WORD && bytes > 0;
1768 bitpos += bitsize, bytes -= bitsize / BITS_PER_UNIT)
1770 int xbitpos = bitpos + big_endian_correction;
1772 store_bit_field (reg, bitsize, xbitpos, word_mode,
1773 extract_bit_field (word, bitsize, bitpos, 1,
1774 NULL_RTX, word_mode,
1775 word_mode,
1776 bitsize / BITS_PER_UNIT,
1777 BITS_PER_WORD),
1778 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
1782 #endif
1784 /* Now store any partially-in-registers parm.
1785 This is the last place a block-move can happen. */
1786 if (reg_parm_seen)
1787 for (i = 0; i < num_actuals; i++)
1788 if (args[i].partial != 0 && ! args[i].pass_on_stack)
1789 store_one_arg (&args[i], argblock, may_be_alloca,
1790 args_size.var != 0, fndecl, reg_parm_stack_space);
1792 #ifndef PUSH_ARGS_REVERSED
1793 #ifdef STACK_BOUNDARY
1794 /* If we pushed args in forward order, perform stack alignment
1795 after pushing the last arg. */
1796 if (argblock == 0)
1797 anti_adjust_stack (GEN_INT (args_size.constant
1798 - original_args_size.constant));
1799 #endif
1800 #endif
1802 /* If register arguments require space on the stack and stack space
1803 was not preallocated, allocate stack space here for arguments
1804 passed in registers. */
1805 #if ! defined(ACCUMULATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
1806 if (must_preallocate == 0 && reg_parm_stack_space > 0)
1807 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
1808 #endif
1810 /* Pass the function the address in which to return a structure value. */
1811 if (structure_value_addr && ! structure_value_addr_parm)
1813 emit_move_insn (struct_value_rtx,
1814 force_reg (Pmode,
1815 force_operand (structure_value_addr,
1816 NULL_RTX)));
1817 if (GET_CODE (struct_value_rtx) == REG)
1818 use_reg (&call_fusage, struct_value_rtx);
1821 funexp = prepare_call_address (funexp, fndecl, &call_fusage, reg_parm_seen);
1823 /* Now do the register loads required for any wholly-register parms or any
1824 parms which are passed both on the stack and in a register. Their
1825 expressions were already evaluated.
1827 Mark all register-parms as living through the call, putting these USE
1828 insns in the CALL_INSN_FUNCTION_USAGE field. */
1830 for (i = 0; i < num_actuals; i++)
1832 rtx list = args[i].reg;
1833 int partial = args[i].partial;
1835 while (list)
1837 rtx reg;
1838 int nregs;
1840 /* Process each register that needs to get this arg. */
1841 if (GET_CODE (list) == EXPR_LIST)
1842 reg = XEXP (list, 0), list = XEXP (list, 1);
1843 else
1844 reg = list, list = 0;
1846 /* Set to non-negative if must move a word at a time, even if just
1847 one word (e.g, partial == 1 && mode == DFmode). Set to -1 if
1848 we just use a normal move insn. This value can be zero if the
1849 argument is a zero size structure with no fields. */
1850 nregs = (partial ? partial
1851 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1852 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1853 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1854 : -1));
1856 /* If simple case, just do move. If normal partial, store_one_arg
1857 has already loaded the register for us. In all other cases,
1858 load the register(s) from memory. */
1860 if (nregs == -1)
1861 emit_move_insn (reg, args[i].value);
1863 #ifdef STRICT_ALIGNMENT
1864 /* If we have pre-computed the values to put in the registers in
1865 the case of non-aligned structures, copy them in now. */
1867 else if (args[i].n_aligned_regs != 0)
1868 for (j = 0; j < args[i].n_aligned_regs; j++)
1869 emit_move_insn (gen_rtx (REG, word_mode, REGNO (reg) + j),
1870 args[i].aligned_regs[j]);
1871 #endif
1873 else if (args[i].partial == 0 || args[i].pass_on_stack)
1874 move_block_to_reg (REGNO (reg),
1875 validize_mem (args[i].value), nregs,
1876 args[i].mode);
1878 if (nregs == -1)
1879 use_reg (&call_fusage, reg);
1880 else
1881 use_regs (&call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1883 /* PARTIAL referred only to the first register, so clear it for the
1884 next time. */
1885 partial = 0;
1889 /* Perform postincrements before actually calling the function. */
1890 emit_queue ();
1892 /* All arguments and registers used for the call must be set up by now! */
1894 /* Generate the actual call instruction. */
1895 emit_call_1 (funexp, funtype, args_size.constant, struct_value_size,
1896 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
1897 valreg, old_inhibit_defer_pop, call_fusage, is_const);
1899 /* If call is cse'able, make appropriate pair of reg-notes around it.
1900 Test valreg so we don't crash; may safely ignore `const'
1901 if return type is void. */
1902 if (is_const && valreg != 0)
1904 rtx note = 0;
1905 rtx temp = gen_reg_rtx (GET_MODE (valreg));
1906 rtx insns;
1908 /* Construct an "equal form" for the value which mentions all the
1909 arguments in order as well as the function name. */
1910 #ifdef PUSH_ARGS_REVERSED
1911 for (i = 0; i < num_actuals; i++)
1912 note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1913 #else
1914 for (i = num_actuals - 1; i >= 0; i--)
1915 note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1916 #endif
1917 note = gen_rtx (EXPR_LIST, VOIDmode, funexp, note);
1919 insns = get_insns ();
1920 end_sequence ();
1922 emit_libcall_block (insns, temp, valreg, note);
1924 valreg = temp;
1926 else if (is_const)
1928 /* Otherwise, just write out the sequence without a note. */
1929 rtx insns = get_insns ();
1931 end_sequence ();
1932 emit_insns (insns);
1935 /* For calls to `setjmp', etc., inform flow.c it should complain
1936 if nonvolatile values are live. */
1938 if (returns_twice)
1940 emit_note (name, NOTE_INSN_SETJMP);
1941 current_function_calls_setjmp = 1;
1944 if (is_longjmp)
1945 current_function_calls_longjmp = 1;
1947 /* Notice functions that cannot return.
1948 If optimizing, insns emitted below will be dead.
1949 If not optimizing, they will exist, which is useful
1950 if the user uses the `return' command in the debugger. */
1952 if (is_volatile || is_longjmp)
1953 emit_barrier ();
1955 /* If value type not void, return an rtx for the value. */
1957 /* If there are cleanups to be called, don't use a hard reg as target. */
1958 if (cleanups_this_call != old_cleanups
1959 && target && REG_P (target)
1960 && REGNO (target) < FIRST_PSEUDO_REGISTER)
1961 target = 0;
1963 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
1964 || ignore)
1966 target = const0_rtx;
1968 else if (structure_value_addr)
1970 if (target == 0 || GET_CODE (target) != MEM)
1972 target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1973 memory_address (TYPE_MODE (TREE_TYPE (exp)),
1974 structure_value_addr));
1975 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
1978 else if (pcc_struct_value)
1980 if (target == 0)
1982 /* We used leave the value in the location that it is
1983 returned in, but that causes problems if it is used more
1984 than once in one expression. Rather than trying to track
1985 when a copy is required, we always copy when TARGET is
1986 not specified. This calling sequence is only used on
1987 a few machines and TARGET is usually nonzero. */
1988 if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
1990 target = assign_stack_temp (BLKmode,
1991 int_size_in_bytes (TREE_TYPE (exp)),
1994 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
1996 /* Save this temp slot around the pop below. */
1997 preserve_temp_slots (target);
1999 else
2000 target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
2003 if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
2004 emit_move_insn (target, gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
2005 copy_to_reg (valreg)));
2006 else
2007 emit_block_move (target, gen_rtx (MEM, BLKmode, copy_to_reg (valreg)),
2008 expr_size (exp),
2009 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
2011 else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2012 && GET_MODE (target) == GET_MODE (valreg))
2013 /* TARGET and VALREG cannot be equal at this point because the latter
2014 would not have REG_FUNCTION_VALUE_P true, while the former would if
2015 it were referring to the same register.
2017 If they refer to the same register, this move will be a no-op, except
2018 when function inlining is being done. */
2019 emit_move_insn (target, valreg);
2020 else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2022 /* Some machines (the PA for example) want to return all small
2023 structures in registers regardless of the structure's alignment.
2025 Deal with them explicitly by copying from the return registers
2026 into the target MEM locations. */
2027 int bytes = int_size_in_bytes (TREE_TYPE (exp));
2028 int n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2029 int i;
2030 enum machine_mode tmpmode;
2032 if (target == 0)
2033 target = assign_stack_temp (BLKmode, bytes, 0);
2034 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2036 /* We could probably emit more efficient code for machines
2037 which do not use strict alignment, but it doesn't seem
2038 worth the effort at the current time. */
2039 for (i = 0; i < n_regs; i++)
2041 rtx src = operand_subword_force (valreg, i, BLKmode);
2042 rtx dst = operand_subword (target, i, 1, BLKmode);
2043 int bitsize = MIN (TYPE_ALIGN (TREE_TYPE (exp)), BITS_PER_WORD);
2044 int bitpos, big_endian_correction = 0;
2046 /* Should never happen. */
2047 if (src == NULL || dst == NULL)
2048 abort ();
2050 if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD)
2051 big_endian_correction
2052 = (BITS_PER_WORD - (bytes * BITS_PER_UNIT));
2054 for (bitpos = 0;
2055 bitpos < BITS_PER_WORD && bytes > 0;
2056 bitpos += bitsize, bytes -= bitsize / BITS_PER_UNIT)
2058 int xbitpos = bitpos + big_endian_correction;
2060 store_bit_field (dst, bitsize, xbitpos, word_mode,
2061 extract_bit_field (src, bitsize, bitpos, 1,
2062 NULL_RTX, word_mode,
2063 word_mode,
2064 bitsize / BITS_PER_UNIT,
2065 BITS_PER_WORD),
2066 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
2070 else
2071 target = copy_to_reg (valreg);
2073 #ifdef PROMOTE_FUNCTION_RETURN
2074 /* If we promoted this return value, make the proper SUBREG. TARGET
2075 might be const0_rtx here, so be careful. */
2076 if (GET_CODE (target) == REG
2077 && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
2078 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
2080 tree type = TREE_TYPE (exp);
2081 int unsignedp = TREE_UNSIGNED (type);
2083 /* If we don't promote as expected, something is wrong. */
2084 if (GET_MODE (target)
2085 != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
2086 abort ();
2088 target = gen_rtx (SUBREG, TYPE_MODE (type), target, 0);
2089 SUBREG_PROMOTED_VAR_P (target) = 1;
2090 SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
2092 #endif
2094 if (flag_short_temps)
2096 /* Perform all cleanups needed for the arguments of this call
2097 (i.e. destructors in C++). */
2098 expand_cleanups_to (old_cleanups);
2101 /* If size of args is variable or this was a constructor call for a stack
2102 argument, restore saved stack-pointer value. */
2104 if (old_stack_level)
2106 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
2107 pending_stack_adjust = old_pending_adj;
2108 #ifdef ACCUMULATE_OUTGOING_ARGS
2109 stack_arg_under_construction = old_stack_arg_under_construction;
2110 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2111 stack_usage_map = initial_stack_usage_map;
2112 #endif
2114 #ifdef ACCUMULATE_OUTGOING_ARGS
2115 else
2117 #ifdef REG_PARM_STACK_SPACE
2118 if (save_area)
2120 enum machine_mode save_mode = GET_MODE (save_area);
2121 rtx stack_area
2122 = gen_rtx (MEM, save_mode,
2123 memory_address (save_mode,
2124 #ifdef ARGS_GROW_DOWNWARD
2125 plus_constant (argblock, - high_to_save)
2126 #else
2127 plus_constant (argblock, low_to_save)
2128 #endif
2131 if (save_mode != BLKmode)
2132 emit_move_insn (stack_area, save_area);
2133 else
2134 emit_block_move (stack_area, validize_mem (save_area),
2135 GEN_INT (high_to_save - low_to_save + 1),
2136 PARM_BOUNDARY / BITS_PER_UNIT);
2138 #endif
2140 /* If we saved any argument areas, restore them. */
2141 for (i = 0; i < num_actuals; i++)
2142 if (args[i].save_area)
2144 enum machine_mode save_mode = GET_MODE (args[i].save_area);
2145 rtx stack_area
2146 = gen_rtx (MEM, save_mode,
2147 memory_address (save_mode,
2148 XEXP (args[i].stack_slot, 0)));
2150 if (save_mode != BLKmode)
2151 emit_move_insn (stack_area, args[i].save_area);
2152 else
2153 emit_block_move (stack_area, validize_mem (args[i].save_area),
2154 GEN_INT (args[i].size.constant),
2155 PARM_BOUNDARY / BITS_PER_UNIT);
2158 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2159 stack_usage_map = initial_stack_usage_map;
2161 #endif
2163 /* If this was alloca, record the new stack level for nonlocal gotos.
2164 Check for the handler slots since we might not have a save area
2165 for non-local gotos. */
2167 if (may_be_alloca && nonlocal_goto_handler_slot != 0)
2168 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
2170 pop_temp_slots ();
2172 return target;
2175 /* Output a library call to function FUN (a SYMBOL_REF rtx)
2176 (emitting the queue unless NO_QUEUE is nonzero),
2177 for a value of mode OUTMODE,
2178 with NARGS different arguments, passed as alternating rtx values
2179 and machine_modes to convert them to.
2180 The rtx values should have been passed through protect_from_queue already.
2182 NO_QUEUE will be true if and only if the library call is a `const' call
2183 which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent
2184 to the variable is_const in expand_call.
2186 NO_QUEUE must be true for const calls, because if it isn't, then
2187 any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes,
2188 and will be lost if the libcall sequence is optimized away.
2190 NO_QUEUE must be false for non-const calls, because if it isn't, the
2191 call insn will have its CONST_CALL_P bit set, and it will be incorrectly
2192 optimized. For instance, the instruction scheduler may incorrectly
2193 move memory references across the non-const call. */
2195 void
2196 emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
2197 int nargs, ...))
2199 #ifndef __STDC__
2200 rtx orgfun;
2201 int no_queue;
2202 enum machine_mode outmode;
2203 int nargs;
2204 #endif
2205 va_list p;
2206 /* Total size in bytes of all the stack-parms scanned so far. */
2207 struct args_size args_size;
2208 /* Size of arguments before any adjustments (such as rounding). */
2209 struct args_size original_args_size;
2210 register int argnum;
2211 rtx fun;
2212 int inc;
2213 int count;
2214 rtx argblock = 0;
2215 CUMULATIVE_ARGS args_so_far;
2216 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2217 struct args_size offset; struct args_size size; };
2218 struct arg *argvec;
2219 int old_inhibit_defer_pop = inhibit_defer_pop;
2220 rtx call_fusage = 0;
2221 /* library calls are never indirect calls. */
2222 int current_call_is_indirect = 0;
2224 VA_START (p, nargs);
2226 #ifndef __STDC__
2227 orgfun = va_arg (p, rtx);
2228 no_queue = va_arg (p, int);
2229 outmode = va_arg (p, enum machine_mode);
2230 nargs = va_arg (p, int);
2231 #endif
2233 fun = orgfun;
2235 /* Copy all the libcall-arguments out of the varargs data
2236 and into a vector ARGVEC.
2238 Compute how to pass each argument. We only support a very small subset
2239 of the full argument passing conventions to limit complexity here since
2240 library functions shouldn't have many args. */
2242 argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
2244 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun);
2246 args_size.constant = 0;
2247 args_size.var = 0;
2249 push_temp_slots ();
2251 for (count = 0; count < nargs; count++)
2253 rtx val = va_arg (p, rtx);
2254 enum machine_mode mode = va_arg (p, enum machine_mode);
2256 /* We cannot convert the arg value to the mode the library wants here;
2257 must do it earlier where we know the signedness of the arg. */
2258 if (mode == BLKmode
2259 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2260 abort ();
2262 /* On some machines, there's no way to pass a float to a library fcn.
2263 Pass it as a double instead. */
2264 #ifdef LIBGCC_NEEDS_DOUBLE
2265 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2266 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
2267 #endif
2269 /* There's no need to call protect_from_queue, because
2270 either emit_move_insn or emit_push_insn will do that. */
2272 /* Make sure it is a reasonable operand for a move or push insn. */
2273 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2274 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2275 val = force_operand (val, NULL_RTX);
2277 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2278 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2280 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2281 be viewed as just an efficiency improvement. */
2282 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2283 emit_move_insn (slot, val);
2284 val = force_operand (XEXP (slot, 0), NULL_RTX);
2285 mode = Pmode;
2287 #endif
2289 argvec[count].value = val;
2290 argvec[count].mode = mode;
2292 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2293 if (argvec[count].reg && GET_CODE (argvec[count].reg) == EXPR_LIST)
2294 abort ();
2295 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2296 argvec[count].partial
2297 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2298 #else
2299 argvec[count].partial = 0;
2300 #endif
2302 locate_and_pad_parm (mode, NULL_TREE,
2303 argvec[count].reg && argvec[count].partial == 0,
2304 NULL_TREE, &args_size, &argvec[count].offset,
2305 &argvec[count].size);
2307 if (argvec[count].size.var)
2308 abort ();
2310 #ifndef REG_PARM_STACK_SPACE
2311 if (argvec[count].partial)
2312 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2313 #endif
2315 if (argvec[count].reg == 0 || argvec[count].partial != 0
2316 #ifdef REG_PARM_STACK_SPACE
2317 || 1
2318 #endif
2320 args_size.constant += argvec[count].size.constant;
2322 #ifdef ACCUMULATE_OUTGOING_ARGS
2323 /* If this arg is actually passed on the stack, it might be
2324 clobbering something we already put there (this library call might
2325 be inside the evaluation of an argument to a function whose call
2326 requires the stack). This will only occur when the library call
2327 has sufficient args to run out of argument registers. Abort in
2328 this case; if this ever occurs, code must be added to save and
2329 restore the arg slot. */
2331 if (argvec[count].reg == 0 || argvec[count].partial != 0)
2332 abort ();
2333 #endif
2335 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree)0, 1);
2337 va_end (p);
2339 /* If this machine requires an external definition for library
2340 functions, write one out. */
2341 assemble_external_libcall (fun);
2343 original_args_size = args_size;
2344 #ifdef STACK_BOUNDARY
2345 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2346 / STACK_BYTES) * STACK_BYTES);
2347 #endif
2349 #ifdef REG_PARM_STACK_SPACE
2350 args_size.constant = MAX (args_size.constant,
2351 REG_PARM_STACK_SPACE (NULL_TREE));
2352 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2353 args_size.constant -= REG_PARM_STACK_SPACE (NULL_TREE);
2354 #endif
2355 #endif
2357 if (args_size.constant > current_function_outgoing_args_size)
2358 current_function_outgoing_args_size = args_size.constant;
2360 #ifdef ACCUMULATE_OUTGOING_ARGS
2361 args_size.constant = 0;
2362 #endif
2364 #ifndef PUSH_ROUNDING
2365 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2366 #endif
2368 #ifdef PUSH_ARGS_REVERSED
2369 #ifdef STACK_BOUNDARY
2370 /* If we push args individually in reverse order, perform stack alignment
2371 before the first push (the last arg). */
2372 if (argblock == 0)
2373 anti_adjust_stack (GEN_INT (args_size.constant
2374 - original_args_size.constant));
2375 #endif
2376 #endif
2378 #ifdef PUSH_ARGS_REVERSED
2379 inc = -1;
2380 argnum = nargs - 1;
2381 #else
2382 inc = 1;
2383 argnum = 0;
2384 #endif
2386 /* Push the args that need to be pushed. */
2388 for (count = 0; count < nargs; count++, argnum += inc)
2390 register enum machine_mode mode = argvec[argnum].mode;
2391 register rtx val = argvec[argnum].value;
2392 rtx reg = argvec[argnum].reg;
2393 int partial = argvec[argnum].partial;
2395 if (! (reg != 0 && partial == 0))
2396 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
2397 argblock, GEN_INT (argvec[count].offset.constant));
2398 NO_DEFER_POP;
2401 #ifndef PUSH_ARGS_REVERSED
2402 #ifdef STACK_BOUNDARY
2403 /* If we pushed args in forward order, perform stack alignment
2404 after pushing the last arg. */
2405 if (argblock == 0)
2406 anti_adjust_stack (GEN_INT (args_size.constant
2407 - original_args_size.constant));
2408 #endif
2409 #endif
2411 #ifdef PUSH_ARGS_REVERSED
2412 argnum = nargs - 1;
2413 #else
2414 argnum = 0;
2415 #endif
2417 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
2419 /* Now load any reg parms into their regs. */
2421 for (count = 0; count < nargs; count++, argnum += inc)
2423 register enum machine_mode mode = argvec[argnum].mode;
2424 register rtx val = argvec[argnum].value;
2425 rtx reg = argvec[argnum].reg;
2426 int partial = argvec[argnum].partial;
2428 if (reg != 0 && partial == 0)
2429 emit_move_insn (reg, val);
2430 NO_DEFER_POP;
2433 /* For version 1.37, try deleting this entirely. */
2434 if (! no_queue)
2435 emit_queue ();
2437 /* Any regs containing parms remain in use through the call. */
2438 for (count = 0; count < nargs; count++)
2439 if (argvec[count].reg != 0)
2440 use_reg (&call_fusage, argvec[count].reg);
2442 /* Don't allow popping to be deferred, since then
2443 cse'ing of library calls could delete a call and leave the pop. */
2444 NO_DEFER_POP;
2446 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
2447 will set inhibit_defer_pop to that value. */
2449 emit_call_1 (fun, get_identifier (XSTR (orgfun, 0)), args_size.constant, 0,
2450 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2451 outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
2452 old_inhibit_defer_pop + 1, call_fusage, no_queue);
2454 pop_temp_slots ();
2456 /* Now restore inhibit_defer_pop to its actual original value. */
2457 OK_DEFER_POP;
2460 /* Like emit_library_call except that an extra argument, VALUE,
2461 comes second and says where to store the result.
2462 (If VALUE is zero, this function chooses a convenient way
2463 to return the value.
2465 This function returns an rtx for where the value is to be found.
2466 If VALUE is nonzero, VALUE is returned. */
2469 emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
2470 enum machine_mode outmode, int nargs, ...))
2472 #ifndef __STDC__
2473 rtx orgfun;
2474 rtx value;
2475 int no_queue;
2476 enum machine_mode outmode;
2477 int nargs;
2478 #endif
2479 va_list p;
2480 /* Total size in bytes of all the stack-parms scanned so far. */
2481 struct args_size args_size;
2482 /* Size of arguments before any adjustments (such as rounding). */
2483 struct args_size original_args_size;
2484 register int argnum;
2485 rtx fun;
2486 int inc;
2487 int count;
2488 rtx argblock = 0;
2489 CUMULATIVE_ARGS args_so_far;
2490 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2491 struct args_size offset; struct args_size size; };
2492 struct arg *argvec;
2493 int old_inhibit_defer_pop = inhibit_defer_pop;
2494 rtx call_fusage = 0;
2495 rtx mem_value = 0;
2496 int pcc_struct_value = 0;
2497 int struct_value_size = 0;
2498 /* library calls are never indirect calls. */
2499 int current_call_is_indirect = 0;
2500 int is_const;
2502 VA_START (p, nargs);
2504 #ifndef __STDC__
2505 orgfun = va_arg (p, rtx);
2506 value = va_arg (p, rtx);
2507 no_queue = va_arg (p, int);
2508 outmode = va_arg (p, enum machine_mode);
2509 nargs = va_arg (p, int);
2510 #endif
2512 is_const = no_queue;
2513 fun = orgfun;
2515 /* If this kind of value comes back in memory,
2516 decide where in memory it should come back. */
2517 if (aggregate_value_p (type_for_mode (outmode, 0)))
2519 #ifdef PCC_STATIC_STRUCT_RETURN
2520 rtx pointer_reg
2521 = hard_function_value (build_pointer_type (type_for_mode (outmode, 0)),
2523 mem_value = gen_rtx (MEM, outmode, pointer_reg);
2524 pcc_struct_value = 1;
2525 if (value == 0)
2526 value = gen_reg_rtx (outmode);
2527 #else /* not PCC_STATIC_STRUCT_RETURN */
2528 struct_value_size = GET_MODE_SIZE (outmode);
2529 if (value != 0 && GET_CODE (value) == MEM)
2530 mem_value = value;
2531 else
2532 mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
2533 #endif
2535 /* This call returns a big structure. */
2536 is_const = 0;
2539 /* ??? Unfinished: must pass the memory address as an argument. */
2541 /* Copy all the libcall-arguments out of the varargs data
2542 and into a vector ARGVEC.
2544 Compute how to pass each argument. We only support a very small subset
2545 of the full argument passing conventions to limit complexity here since
2546 library functions shouldn't have many args. */
2548 argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
2550 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun);
2552 args_size.constant = 0;
2553 args_size.var = 0;
2555 count = 0;
2557 push_temp_slots ();
2559 /* If there's a structure value address to be passed,
2560 either pass it in the special place, or pass it as an extra argument. */
2561 if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
2563 rtx addr = XEXP (mem_value, 0);
2564 nargs++;
2566 /* Make sure it is a reasonable operand for a move or push insn. */
2567 if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
2568 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
2569 addr = force_operand (addr, NULL_RTX);
2571 argvec[count].value = addr;
2572 argvec[count].mode = Pmode;
2573 argvec[count].partial = 0;
2575 argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
2576 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2577 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
2578 abort ();
2579 #endif
2581 locate_and_pad_parm (Pmode, NULL_TREE,
2582 argvec[count].reg && argvec[count].partial == 0,
2583 NULL_TREE, &args_size, &argvec[count].offset,
2584 &argvec[count].size);
2587 if (argvec[count].reg == 0 || argvec[count].partial != 0
2588 #ifdef REG_PARM_STACK_SPACE
2589 || 1
2590 #endif
2592 args_size.constant += argvec[count].size.constant;
2594 FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree)0, 1);
2596 count++;
2599 for (; count < nargs; count++)
2601 rtx val = va_arg (p, rtx);
2602 enum machine_mode mode = va_arg (p, enum machine_mode);
2604 /* We cannot convert the arg value to the mode the library wants here;
2605 must do it earlier where we know the signedness of the arg. */
2606 if (mode == BLKmode
2607 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2608 abort ();
2610 /* On some machines, there's no way to pass a float to a library fcn.
2611 Pass it as a double instead. */
2612 #ifdef LIBGCC_NEEDS_DOUBLE
2613 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2614 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
2615 #endif
2617 /* There's no need to call protect_from_queue, because
2618 either emit_move_insn or emit_push_insn will do that. */
2620 /* Make sure it is a reasonable operand for a move or push insn. */
2621 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2622 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2623 val = force_operand (val, NULL_RTX);
2625 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2626 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2628 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2629 be viewed as just an efficiency improvement. */
2630 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2631 emit_move_insn (slot, val);
2632 val = XEXP (slot, 0);
2633 mode = Pmode;
2635 #endif
2637 argvec[count].value = val;
2638 argvec[count].mode = mode;
2640 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2641 if (argvec[count].reg && GET_CODE (argvec[count].reg) == EXPR_LIST)
2642 abort ();
2643 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2644 argvec[count].partial
2645 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2646 #else
2647 argvec[count].partial = 0;
2648 #endif
2650 locate_and_pad_parm (mode, NULL_TREE,
2651 argvec[count].reg && argvec[count].partial == 0,
2652 NULL_TREE, &args_size, &argvec[count].offset,
2653 &argvec[count].size);
2655 if (argvec[count].size.var)
2656 abort ();
2658 #ifndef REG_PARM_STACK_SPACE
2659 if (argvec[count].partial)
2660 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2661 #endif
2663 if (argvec[count].reg == 0 || argvec[count].partial != 0
2664 #ifdef REG_PARM_STACK_SPACE
2665 || 1
2666 #endif
2668 args_size.constant += argvec[count].size.constant;
2670 #ifdef ACCUMULATE_OUTGOING_ARGS
2671 /* If this arg is actually passed on the stack, it might be
2672 clobbering something we already put there (this library call might
2673 be inside the evaluation of an argument to a function whose call
2674 requires the stack). This will only occur when the library call
2675 has sufficient args to run out of argument registers. Abort in
2676 this case; if this ever occurs, code must be added to save and
2677 restore the arg slot. */
2679 if (argvec[count].reg == 0 || argvec[count].partial != 0)
2680 abort ();
2681 #endif
2683 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree)0, 1);
2685 va_end (p);
2687 /* If this machine requires an external definition for library
2688 functions, write one out. */
2689 assemble_external_libcall (fun);
2691 original_args_size = args_size;
2692 #ifdef STACK_BOUNDARY
2693 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2694 / STACK_BYTES) * STACK_BYTES);
2695 #endif
2697 #ifdef REG_PARM_STACK_SPACE
2698 args_size.constant = MAX (args_size.constant,
2699 REG_PARM_STACK_SPACE (NULL_TREE));
2700 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2701 args_size.constant -= REG_PARM_STACK_SPACE (NULL_TREE);
2702 #endif
2703 #endif
2705 if (args_size.constant > current_function_outgoing_args_size)
2706 current_function_outgoing_args_size = args_size.constant;
2708 #ifdef ACCUMULATE_OUTGOING_ARGS
2709 args_size.constant = 0;
2710 #endif
2712 #ifndef PUSH_ROUNDING
2713 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2714 #endif
2716 #ifdef PUSH_ARGS_REVERSED
2717 #ifdef STACK_BOUNDARY
2718 /* If we push args individually in reverse order, perform stack alignment
2719 before the first push (the last arg). */
2720 if (argblock == 0)
2721 anti_adjust_stack (GEN_INT (args_size.constant
2722 - original_args_size.constant));
2723 #endif
2724 #endif
2726 #ifdef PUSH_ARGS_REVERSED
2727 inc = -1;
2728 argnum = nargs - 1;
2729 #else
2730 inc = 1;
2731 argnum = 0;
2732 #endif
2734 /* Push the args that need to be pushed. */
2736 for (count = 0; count < nargs; count++, argnum += inc)
2738 register enum machine_mode mode = argvec[argnum].mode;
2739 register rtx val = argvec[argnum].value;
2740 rtx reg = argvec[argnum].reg;
2741 int partial = argvec[argnum].partial;
2743 if (! (reg != 0 && partial == 0))
2744 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
2745 argblock, GEN_INT (argvec[count].offset.constant));
2746 NO_DEFER_POP;
2749 #ifndef PUSH_ARGS_REVERSED
2750 #ifdef STACK_BOUNDARY
2751 /* If we pushed args in forward order, perform stack alignment
2752 after pushing the last arg. */
2753 if (argblock == 0)
2754 anti_adjust_stack (GEN_INT (args_size.constant
2755 - original_args_size.constant));
2756 #endif
2757 #endif
2759 #ifdef PUSH_ARGS_REVERSED
2760 argnum = nargs - 1;
2761 #else
2762 argnum = 0;
2763 #endif
2765 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
2767 /* Now load any reg parms into their regs. */
2769 for (count = 0; count < nargs; count++, argnum += inc)
2771 register enum machine_mode mode = argvec[argnum].mode;
2772 register rtx val = argvec[argnum].value;
2773 rtx reg = argvec[argnum].reg;
2774 int partial = argvec[argnum].partial;
2776 if (reg != 0 && partial == 0)
2777 emit_move_insn (reg, val);
2778 NO_DEFER_POP;
2781 #if 0
2782 /* For version 1.37, try deleting this entirely. */
2783 if (! no_queue)
2784 emit_queue ();
2785 #endif
2787 /* Any regs containing parms remain in use through the call. */
2788 for (count = 0; count < nargs; count++)
2789 if (argvec[count].reg != 0)
2790 use_reg (&call_fusage, argvec[count].reg);
2792 /* Pass the function the address in which to return a structure value. */
2793 if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
2795 emit_move_insn (struct_value_rtx,
2796 force_reg (Pmode,
2797 force_operand (XEXP (mem_value, 0),
2798 NULL_RTX)));
2799 if (GET_CODE (struct_value_rtx) == REG)
2800 use_reg (&call_fusage, struct_value_rtx);
2803 /* Don't allow popping to be deferred, since then
2804 cse'ing of library calls could delete a call and leave the pop. */
2805 NO_DEFER_POP;
2807 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
2808 will set inhibit_defer_pop to that value. */
2810 emit_call_1 (fun, get_identifier (XSTR (orgfun, 0)), args_size.constant,
2811 struct_value_size,
2812 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2813 (outmode != VOIDmode && mem_value == 0
2814 ? hard_libcall_value (outmode) : NULL_RTX),
2815 old_inhibit_defer_pop + 1, call_fusage, is_const);
2817 /* Now restore inhibit_defer_pop to its actual original value. */
2818 OK_DEFER_POP;
2820 pop_temp_slots ();
2822 /* Copy the value to the right place. */
2823 if (outmode != VOIDmode)
2825 if (mem_value)
2827 if (value == 0)
2828 value = mem_value;
2829 if (value != mem_value)
2830 emit_move_insn (value, mem_value);
2832 else if (value != 0)
2833 emit_move_insn (value, hard_libcall_value (outmode));
2834 else
2835 value = hard_libcall_value (outmode);
2838 return value;
2841 #if 0
2842 /* Return an rtx which represents a suitable home on the stack
2843 given TYPE, the type of the argument looking for a home.
2844 This is called only for BLKmode arguments.
2846 SIZE is the size needed for this target.
2847 ARGS_ADDR is the address of the bottom of the argument block for this call.
2848 OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
2849 if this machine uses push insns. */
2851 static rtx
2852 target_for_arg (type, size, args_addr, offset)
2853 tree type;
2854 rtx size;
2855 rtx args_addr;
2856 struct args_size offset;
2858 rtx target;
2859 rtx offset_rtx = ARGS_SIZE_RTX (offset);
2861 /* We do not call memory_address if possible,
2862 because we want to address as close to the stack
2863 as possible. For non-variable sized arguments,
2864 this will be stack-pointer relative addressing. */
2865 if (GET_CODE (offset_rtx) == CONST_INT)
2866 target = plus_constant (args_addr, INTVAL (offset_rtx));
2867 else
2869 /* I have no idea how to guarantee that this
2870 will work in the presence of register parameters. */
2871 target = gen_rtx (PLUS, Pmode, args_addr, offset_rtx);
2872 target = memory_address (QImode, target);
2875 return gen_rtx (MEM, BLKmode, target);
2877 #endif
2879 /* Store a single argument for a function call
2880 into the register or memory area where it must be passed.
2881 *ARG describes the argument value and where to pass it.
2883 ARGBLOCK is the address of the stack-block for all the arguments,
2884 or 0 on a machine where arguments are pushed individually.
2886 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
2887 so must be careful about how the stack is used.
2889 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
2890 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
2891 that we need not worry about saving and restoring the stack.
2893 FNDECL is the declaration of the function we are calling. */
2895 static void
2896 store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl,
2897 reg_parm_stack_space)
2898 struct arg_data *arg;
2899 rtx argblock;
2900 int may_be_alloca;
2901 int variable_size;
2902 tree fndecl;
2903 int reg_parm_stack_space;
2905 register tree pval = arg->tree_value;
2906 rtx reg = 0;
2907 int partial = 0;
2908 int used = 0;
2909 int i, lower_bound, upper_bound;
2911 if (TREE_CODE (pval) == ERROR_MARK)
2912 return;
2914 /* Push a new temporary level for any temporaries we make for
2915 this argument. */
2916 push_temp_slots ();
2918 #ifdef ACCUMULATE_OUTGOING_ARGS
2919 /* If this is being stored into a pre-allocated, fixed-size, stack area,
2920 save any previous data at that location. */
2921 if (argblock && ! variable_size && arg->stack)
2923 #ifdef ARGS_GROW_DOWNWARD
2924 /* stack_slot is negative, but we want to index stack_usage_map */
2925 /* with positive values. */
2926 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
2927 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
2928 else
2929 abort ();
2931 lower_bound = upper_bound - arg->size.constant;
2932 #else
2933 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
2934 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
2935 else
2936 lower_bound = 0;
2938 upper_bound = lower_bound + arg->size.constant;
2939 #endif
2941 for (i = lower_bound; i < upper_bound; i++)
2942 if (stack_usage_map[i]
2943 #ifdef REG_PARM_STACK_SPACE
2944 /* Don't store things in the fixed argument area at this point;
2945 it has already been saved. */
2946 && i > reg_parm_stack_space
2947 #endif
2949 break;
2951 if (i != upper_bound)
2953 /* We need to make a save area. See what mode we can make it. */
2954 enum machine_mode save_mode
2955 = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
2956 rtx stack_area
2957 = gen_rtx (MEM, save_mode,
2958 memory_address (save_mode, XEXP (arg->stack_slot, 0)));
2960 if (save_mode == BLKmode)
2962 arg->save_area = assign_stack_temp (BLKmode,
2963 arg->size.constant, 1);
2964 MEM_IN_STRUCT_P (arg->save_area)
2965 = AGGREGATE_TYPE_P (TREE_TYPE (arg->tree_value));
2966 preserve_temp_slots (arg->save_area);
2967 emit_block_move (validize_mem (arg->save_area), stack_area,
2968 GEN_INT (arg->size.constant),
2969 PARM_BOUNDARY / BITS_PER_UNIT);
2971 else
2973 arg->save_area = gen_reg_rtx (save_mode);
2974 emit_move_insn (arg->save_area, stack_area);
2978 #endif
2980 /* If this isn't going to be placed on both the stack and in registers,
2981 set up the register and number of words. */
2982 if (! arg->pass_on_stack)
2983 reg = arg->reg, partial = arg->partial;
2985 if (reg != 0 && partial == 0)
2986 /* Being passed entirely in a register. We shouldn't be called in
2987 this case. */
2988 abort ();
2990 #ifdef STRICT_ALIGNMENT
2991 /* If this arg needs special alignment, don't load the registers
2992 here. */
2993 if (arg->n_aligned_regs != 0)
2994 reg = 0;
2995 #endif
2997 /* If this is being partially passed in a register, but multiple locations
2998 are specified, we assume that the one partially used is the one that is
2999 listed first. */
3000 if (reg && GET_CODE (reg) == EXPR_LIST)
3001 reg = XEXP (reg, 0);
3003 /* If this is being passed partially in a register, we can't evaluate
3004 it directly into its stack slot. Otherwise, we can. */
3005 if (arg->value == 0)
3007 #ifdef ACCUMULATE_OUTGOING_ARGS
3008 /* stack_arg_under_construction is nonzero if a function argument is
3009 being evaluated directly into the outgoing argument list and
3010 expand_call must take special action to preserve the argument list
3011 if it is called recursively.
3013 For scalar function arguments stack_usage_map is sufficient to
3014 determine which stack slots must be saved and restored. Scalar
3015 arguments in general have pass_on_stack == 0.
3017 If this argument is initialized by a function which takes the
3018 address of the argument (a C++ constructor or a C function
3019 returning a BLKmode structure), then stack_usage_map is
3020 insufficient and expand_call must push the stack around the
3021 function call. Such arguments have pass_on_stack == 1.
3023 Note that it is always safe to set stack_arg_under_construction,
3024 but this generates suboptimal code if set when not needed. */
3026 if (arg->pass_on_stack)
3027 stack_arg_under_construction++;
3028 #endif
3029 arg->value = expand_expr (pval,
3030 (partial
3031 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
3032 ? NULL_RTX : arg->stack,
3033 VOIDmode, 0);
3035 /* If we are promoting object (or for any other reason) the mode
3036 doesn't agree, convert the mode. */
3038 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
3039 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
3040 arg->value, arg->unsignedp);
3042 #ifdef ACCUMULATE_OUTGOING_ARGS
3043 if (arg->pass_on_stack)
3044 stack_arg_under_construction--;
3045 #endif
3048 /* Don't allow anything left on stack from computation
3049 of argument to alloca. */
3050 if (may_be_alloca)
3051 do_pending_stack_adjust ();
3053 if (arg->value == arg->stack)
3054 /* If the value is already in the stack slot, we are done. */
3056 else if (arg->mode != BLKmode)
3058 register int size;
3060 /* Argument is a scalar, not entirely passed in registers.
3061 (If part is passed in registers, arg->partial says how much
3062 and emit_push_insn will take care of putting it there.)
3064 Push it, and if its size is less than the
3065 amount of space allocated to it,
3066 also bump stack pointer by the additional space.
3067 Note that in C the default argument promotions
3068 will prevent such mismatches. */
3070 size = GET_MODE_SIZE (arg->mode);
3071 /* Compute how much space the push instruction will push.
3072 On many machines, pushing a byte will advance the stack
3073 pointer by a halfword. */
3074 #ifdef PUSH_ROUNDING
3075 size = PUSH_ROUNDING (size);
3076 #endif
3077 used = size;
3079 /* Compute how much space the argument should get:
3080 round up to a multiple of the alignment for arguments. */
3081 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
3082 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
3083 / (PARM_BOUNDARY / BITS_PER_UNIT))
3084 * (PARM_BOUNDARY / BITS_PER_UNIT));
3086 /* This isn't already where we want it on the stack, so put it there.
3087 This can either be done with push or copy insns. */
3088 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
3089 0, partial, reg, used - size,
3090 argblock, ARGS_SIZE_RTX (arg->offset));
3092 else
3094 /* BLKmode, at least partly to be pushed. */
3096 register int excess;
3097 rtx size_rtx;
3099 /* Pushing a nonscalar.
3100 If part is passed in registers, PARTIAL says how much
3101 and emit_push_insn will take care of putting it there. */
3103 /* Round its size up to a multiple
3104 of the allocation unit for arguments. */
3106 if (arg->size.var != 0)
3108 excess = 0;
3109 size_rtx = ARGS_SIZE_RTX (arg->size);
3111 else
3113 /* PUSH_ROUNDING has no effect on us, because
3114 emit_push_insn for BLKmode is careful to avoid it. */
3115 excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
3116 + partial * UNITS_PER_WORD);
3117 size_rtx = expr_size (pval);
3120 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
3121 TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
3122 reg, excess, argblock, ARGS_SIZE_RTX (arg->offset));
3126 /* Unless this is a partially-in-register argument, the argument is now
3127 in the stack.
3129 ??? Note that this can change arg->value from arg->stack to
3130 arg->stack_slot and it matters when they are not the same.
3131 It isn't totally clear that this is correct in all cases. */
3132 if (partial == 0)
3133 arg->value = arg->stack_slot;
3135 /* Once we have pushed something, pops can't safely
3136 be deferred during the rest of the arguments. */
3137 NO_DEFER_POP;
3139 /* ANSI doesn't require a sequence point here,
3140 but PCC has one, so this will avoid some problems. */
3141 emit_queue ();
3143 /* Free any temporary slots made in processing this argument. Show
3144 that we might have taken the address of something and pushed that
3145 as an operand. */
3146 preserve_temp_slots (NULL_RTX);
3147 free_temp_slots ();
3148 pop_temp_slots ();
3150 #ifdef ACCUMULATE_OUTGOING_ARGS
3151 /* Now mark the segment we just used. */
3152 if (argblock && ! variable_size && arg->stack)
3153 for (i = lower_bound; i < upper_bound; i++)
3154 stack_usage_map[i] = 1;
3155 #endif