]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/calls.c
check-init.c: New file.
[thirdparty/gcc.git] / gcc / calls.c
CommitLineData
51bbfa0c 1/* Convert function calls to rtl insns, for GNU C compiler.
2e0dd623 2 Copyright (C) 1989, 92-97, 1998 Free Software Foundation, Inc.
51bbfa0c
RS
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
940d9d63
RK
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
51bbfa0c
RS
20
21#include "config.h"
670ee920
KG
22#include "system.h"
23#include "rtl.h"
24#include "tree.h"
25#include "flags.h"
26#include "expr.h"
27#include "regs.h"
51bbfa0c 28#include "insn-flags.h"
5f6da302 29#include "toplev.h"
d6f4ec51 30#include "output.h"
51bbfa0c 31
c795bca9
BS
32#if !defined PREFERRED_STACK_BOUNDARY && defined STACK_BOUNDARY
33#define PREFERRED_STACK_BOUNDARY STACK_BOUNDARY
34#endif
35
51bbfa0c 36/* Decide whether a function's arguments should be processed
bbc8a071
RK
37 from first to last or from last to first.
38
39 They should if the stack and args grow in opposite directions, but
40 only if we have push insns. */
51bbfa0c 41
51bbfa0c 42#ifdef PUSH_ROUNDING
bbc8a071 43
40083ddf 44#if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
51bbfa0c
RS
45#define PUSH_ARGS_REVERSED /* If it's last to first */
46#endif
bbc8a071 47
51bbfa0c
RS
48#endif
49
c795bca9
BS
50/* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
51#define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
51bbfa0c
RS
52
53/* Data structure and subroutines used within expand_call. */
54
55struct arg_data
56{
57 /* Tree node for this argument. */
58 tree tree_value;
1efe6448
RK
59 /* Mode for value; TYPE_MODE unless promoted. */
60 enum machine_mode mode;
51bbfa0c
RS
61 /* Current RTL value for argument, or 0 if it isn't precomputed. */
62 rtx value;
63 /* Initially-compute RTL value for argument; only for const functions. */
64 rtx initial_value;
65 /* Register to pass this argument in, 0 if passed on stack, or an
cacbd532 66 PARALLEL if the arg is to be copied into multiple non-contiguous
51bbfa0c
RS
67 registers. */
68 rtx reg;
84b55618
RK
69 /* If REG was promoted from the actual mode of the argument expression,
70 indicates whether the promotion is sign- or zero-extended. */
71 int unsignedp;
51bbfa0c
RS
72 /* Number of registers to use. 0 means put the whole arg in registers.
73 Also 0 if not passed in registers. */
74 int partial;
d64f5a78
RS
75 /* Non-zero if argument must be passed on stack.
76 Note that some arguments may be passed on the stack
77 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
78 pass_on_stack identifies arguments that *cannot* go in registers. */
51bbfa0c
RS
79 int pass_on_stack;
80 /* Offset of this argument from beginning of stack-args. */
81 struct args_size offset;
82 /* Similar, but offset to the start of the stack slot. Different from
83 OFFSET if this arg pads downward. */
84 struct args_size slot_offset;
85 /* Size of this argument on the stack, rounded up for any padding it gets,
86 parts of the argument passed in registers do not count.
87 If REG_PARM_STACK_SPACE is defined, then register parms
88 are counted here as well. */
89 struct args_size size;
90 /* Location on the stack at which parameter should be stored. The store
91 has already been done if STACK == VALUE. */
92 rtx stack;
93 /* Location on the stack of the start of this argument slot. This can
94 differ from STACK if this arg pads downward. This location is known
95 to be aligned to FUNCTION_ARG_BOUNDARY. */
96 rtx stack_slot;
97#ifdef ACCUMULATE_OUTGOING_ARGS
98 /* Place that this stack area has been saved, if needed. */
99 rtx save_area;
100#endif
4ab56118
RK
101 /* If an argument's alignment does not permit direct copying into registers,
102 copy in smaller-sized pieces into pseudos. These are stored in a
103 block pointed to by this field. The next field says how many
104 word-sized pseudos we made. */
105 rtx *aligned_regs;
106 int n_aligned_regs;
51bbfa0c
RS
107};
108
109#ifdef ACCUMULATE_OUTGOING_ARGS
b94301c2 110/* A vector of one char per byte of stack space. A byte if non-zero if
51bbfa0c
RS
111 the corresponding stack location has been used.
112 This vector is used to prevent a function call within an argument from
113 clobbering any stack already set up. */
114static char *stack_usage_map;
115
116/* Size of STACK_USAGE_MAP. */
117static int highest_outgoing_arg_in_use;
2f4aa534
RS
118
119/* stack_arg_under_construction is nonzero when an argument may be
120 initialized with a constructor call (including a C function that
121 returns a BLKmode struct) and expand_call must take special action
122 to make sure the object being constructed does not overlap the
123 argument list for the constructor call. */
124int stack_arg_under_construction;
51bbfa0c
RS
125#endif
126
20efdf74
JL
127static int calls_function PROTO ((tree, int));
128static int calls_function_1 PROTO ((tree, int));
129static void emit_call_1 PROTO ((rtx, tree, tree, HOST_WIDE_INT,
130 HOST_WIDE_INT, rtx, rtx,
131 int, rtx, int));
132static void special_function_p PROTO ((char *, tree, int *, int *,
133 int *, int *));
134static void precompute_register_parameters PROTO ((int, struct arg_data *,
135 int *));
322e3e34 136static void store_one_arg PROTO ((struct arg_data *, rtx, int, int,
c84e2712 137 int));
20efdf74
JL
138static void store_unaligned_arguments_into_pseudos PROTO ((struct arg_data *,
139 int));
140
141#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
142static rtx save_fixed_argument_area PROTO ((int, rtx, int *, int *));
143static void restore_fixed_argument_area PROTO ((rtx, rtx, int, int));
144#endif
51bbfa0c 145\f
1ce0cb53
JW
146/* If WHICH is 1, return 1 if EXP contains a call to the built-in function
147 `alloca'.
148
149 If WHICH is 0, return 1 if EXP contains a call to any function.
150 Actually, we only need return 1 if evaluating EXP would require pushing
151 arguments on the stack, but that is too difficult to compute, so we just
152 assume any function call might require the stack. */
51bbfa0c 153
1c8d7aef
RS
154static tree calls_function_save_exprs;
155
51bbfa0c 156static int
1ce0cb53 157calls_function (exp, which)
51bbfa0c 158 tree exp;
1ce0cb53 159 int which;
1c8d7aef
RS
160{
161 int val;
162 calls_function_save_exprs = 0;
163 val = calls_function_1 (exp, which);
164 calls_function_save_exprs = 0;
165 return val;
166}
167
168static int
169calls_function_1 (exp, which)
170 tree exp;
171 int which;
51bbfa0c
RS
172{
173 register int i;
0207efa2
RK
174 enum tree_code code = TREE_CODE (exp);
175 int type = TREE_CODE_CLASS (code);
176 int length = tree_code_length[(int) code];
51bbfa0c 177
ddd5a7c1 178 /* If this code is language-specific, we don't know what it will do. */
0207efa2
RK
179 if ((int) code >= NUM_TREE_CODES)
180 return 1;
51bbfa0c 181
0207efa2 182 /* Only expressions and references can contain calls. */
3b59a331
RS
183 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
184 && type != 'b')
51bbfa0c
RS
185 return 0;
186
0207efa2 187 switch (code)
51bbfa0c
RS
188 {
189 case CALL_EXPR:
1ce0cb53
JW
190 if (which == 0)
191 return 1;
192 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
193 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
0207efa2
RK
194 == FUNCTION_DECL))
195 {
196 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
197
198 if ((DECL_BUILT_IN (fndecl)
199 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA)
200 || (DECL_SAVED_INSNS (fndecl)
201 && (FUNCTION_FLAGS (DECL_SAVED_INSNS (fndecl))
202 & FUNCTION_FLAGS_CALLS_ALLOCA)))
203 return 1;
204 }
51bbfa0c
RS
205
206 /* Third operand is RTL. */
207 length = 2;
208 break;
209
210 case SAVE_EXPR:
211 if (SAVE_EXPR_RTL (exp) != 0)
212 return 0;
1c8d7aef
RS
213 if (value_member (exp, calls_function_save_exprs))
214 return 0;
215 calls_function_save_exprs = tree_cons (NULL_TREE, exp,
216 calls_function_save_exprs);
217 return (TREE_OPERAND (exp, 0) != 0
218 && calls_function_1 (TREE_OPERAND (exp, 0), which));
51bbfa0c
RS
219
220 case BLOCK:
ef03bc85
CH
221 {
222 register tree local;
223
224 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
1ce0cb53 225 if (DECL_INITIAL (local) != 0
1c8d7aef 226 && calls_function_1 (DECL_INITIAL (local), which))
ef03bc85
CH
227 return 1;
228 }
229 {
230 register tree subblock;
231
232 for (subblock = BLOCK_SUBBLOCKS (exp);
233 subblock;
234 subblock = TREE_CHAIN (subblock))
1c8d7aef 235 if (calls_function_1 (subblock, which))
ef03bc85
CH
236 return 1;
237 }
238 return 0;
51bbfa0c
RS
239
240 case METHOD_CALL_EXPR:
241 length = 3;
242 break;
243
244 case WITH_CLEANUP_EXPR:
245 length = 1;
246 break;
247
248 case RTL_EXPR:
249 return 0;
e9a25f70
JL
250
251 default:
252 break;
51bbfa0c
RS
253 }
254
255 for (i = 0; i < length; i++)
256 if (TREE_OPERAND (exp, i) != 0
1c8d7aef 257 && calls_function_1 (TREE_OPERAND (exp, i), which))
51bbfa0c
RS
258 return 1;
259
260 return 0;
261}
262\f
263/* Force FUNEXP into a form suitable for the address of a CALL,
264 and return that as an rtx. Also load the static chain register
265 if FNDECL is a nested function.
266
77cac2f2
RK
267 CALL_FUSAGE points to a variable holding the prospective
268 CALL_INSN_FUNCTION_USAGE information. */
51bbfa0c 269
03dacb02 270rtx
77cac2f2 271prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen)
51bbfa0c
RS
272 rtx funexp;
273 tree fndecl;
77cac2f2 274 rtx *call_fusage;
01368078 275 int reg_parm_seen;
51bbfa0c
RS
276{
277 rtx static_chain_value = 0;
278
279 funexp = protect_from_queue (funexp, 0);
280
281 if (fndecl != 0)
0f41302f 282 /* Get possible static chain value for nested function in C. */
51bbfa0c
RS
283 static_chain_value = lookup_static_chain (fndecl);
284
285 /* Make a valid memory address and copy constants thru pseudo-regs,
286 but not for a constant address if -fno-function-cse. */
287 if (GET_CODE (funexp) != SYMBOL_REF)
01368078 288 /* If we are using registers for parameters, force the
e9a25f70
JL
289 function address into a register now. */
290 funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
291 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
292 : memory_address (FUNCTION_MODE, funexp));
51bbfa0c
RS
293 else
294 {
295#ifndef NO_FUNCTION_CSE
296 if (optimize && ! flag_no_function_cse)
297#ifdef NO_RECURSIVE_FUNCTION_CSE
298 if (fndecl != current_function_decl)
299#endif
300 funexp = force_reg (Pmode, funexp);
301#endif
302 }
303
304 if (static_chain_value != 0)
305 {
306 emit_move_insn (static_chain_rtx, static_chain_value);
307
f991a240
RK
308 if (GET_CODE (static_chain_rtx) == REG)
309 use_reg (call_fusage, static_chain_rtx);
51bbfa0c
RS
310 }
311
312 return funexp;
313}
314
315/* Generate instructions to call function FUNEXP,
316 and optionally pop the results.
317 The CALL_INSN is the first insn generated.
318
607ea900 319 FNDECL is the declaration node of the function. This is given to the
2c8da025
RK
320 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
321
334c4f0f
RK
322 FUNTYPE is the data type of the function. This is given to the macro
323 RETURN_POPS_ARGS to determine whether this function pops its own args.
324 We used to allow an identifier for library functions, but that doesn't
325 work when the return type is an aggregate type and the calling convention
326 says that the pointer to this aggregate is to be popped by the callee.
51bbfa0c
RS
327
328 STACK_SIZE is the number of bytes of arguments on the stack,
c795bca9 329 rounded up to PREFERRED_STACK_BOUNDARY; zero if the size is variable.
51bbfa0c
RS
330 This is both to put into the call insn and
331 to generate explicit popping code if necessary.
332
333 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
334 It is zero if this call doesn't want a structure value.
335
336 NEXT_ARG_REG is the rtx that results from executing
337 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
338 just after all the args have had their registers assigned.
339 This could be whatever you like, but normally it is the first
340 arg-register beyond those used for args in this call,
341 or 0 if all the arg-registers are used in this call.
342 It is passed on to `gen_call' so you can put this info in the call insn.
343
344 VALREG is a hard register in which a value is returned,
345 or 0 if the call does not return a value.
346
347 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
348 the args to this call were processed.
349 We restore `inhibit_defer_pop' to that value.
350
94b25f81
RK
351 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
352 denote registers used by the called function.
51bbfa0c
RS
353
354 IS_CONST is true if this is a `const' call. */
355
322e3e34 356static void
2c8da025 357emit_call_1 (funexp, fndecl, funtype, stack_size, struct_value_size,
5d6155d4
RK
358 next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
359 is_const)
51bbfa0c 360 rtx funexp;
c84e2712
KG
361 tree fndecl ATTRIBUTE_UNUSED;
362 tree funtype ATTRIBUTE_UNUSED;
e5e809f4
JL
363 HOST_WIDE_INT stack_size;
364 HOST_WIDE_INT struct_value_size;
51bbfa0c
RS
365 rtx next_arg_reg;
366 rtx valreg;
367 int old_inhibit_defer_pop;
77cac2f2 368 rtx call_fusage;
51bbfa0c
RS
369 int is_const;
370{
e5d70561
RK
371 rtx stack_size_rtx = GEN_INT (stack_size);
372 rtx struct_value_size_rtx = GEN_INT (struct_value_size);
51bbfa0c 373 rtx call_insn;
081f5e7e 374#ifndef ACCUMULATE_OUTGOING_ARGS
51bbfa0c 375 int already_popped = 0;
081f5e7e 376#endif
51bbfa0c
RS
377
378 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
379 and we don't want to load it into a register as an optimization,
380 because prepare_call_address already did it if it should be done. */
381 if (GET_CODE (funexp) != SYMBOL_REF)
382 funexp = memory_address (FUNCTION_MODE, funexp);
383
384#ifndef ACCUMULATE_OUTGOING_ARGS
385#if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
386 if (HAVE_call_pop && HAVE_call_value_pop
2c8da025
RK
387 && (RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0
388 || stack_size == 0))
51bbfa0c 389 {
2c8da025 390 rtx n_pop = GEN_INT (RETURN_POPS_ARGS (fndecl, funtype, stack_size));
51bbfa0c
RS
391 rtx pat;
392
393 /* If this subroutine pops its own args, record that in the call insn
394 if possible, for the sake of frame pointer elimination. */
2c8da025 395
51bbfa0c
RS
396 if (valreg)
397 pat = gen_call_value_pop (valreg,
38a448ca 398 gen_rtx_MEM (FUNCTION_MODE, funexp),
51bbfa0c
RS
399 stack_size_rtx, next_arg_reg, n_pop);
400 else
38a448ca 401 pat = gen_call_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
51bbfa0c
RS
402 stack_size_rtx, next_arg_reg, n_pop);
403
404 emit_call_insn (pat);
405 already_popped = 1;
406 }
407 else
408#endif
409#endif
410
411#if defined (HAVE_call) && defined (HAVE_call_value)
412 if (HAVE_call && HAVE_call_value)
413 {
414 if (valreg)
415 emit_call_insn (gen_call_value (valreg,
38a448ca 416 gen_rtx_MEM (FUNCTION_MODE, funexp),
e992302c
BK
417 stack_size_rtx, next_arg_reg,
418 NULL_RTX));
51bbfa0c 419 else
38a448ca 420 emit_call_insn (gen_call (gen_rtx_MEM (FUNCTION_MODE, funexp),
51bbfa0c
RS
421 stack_size_rtx, next_arg_reg,
422 struct_value_size_rtx));
423 }
424 else
425#endif
426 abort ();
427
77cac2f2 428 /* Find the CALL insn we just emitted. */
51bbfa0c
RS
429 for (call_insn = get_last_insn ();
430 call_insn && GET_CODE (call_insn) != CALL_INSN;
431 call_insn = PREV_INSN (call_insn))
432 ;
433
434 if (! call_insn)
435 abort ();
436
e59e60a7
RK
437 /* Put the register usage information on the CALL. If there is already
438 some usage information, put ours at the end. */
439 if (CALL_INSN_FUNCTION_USAGE (call_insn))
440 {
441 rtx link;
442
443 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
444 link = XEXP (link, 1))
445 ;
446
447 XEXP (link, 1) = call_fusage;
448 }
449 else
450 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
51bbfa0c
RS
451
452 /* If this is a const call, then set the insn's unchanging bit. */
453 if (is_const)
454 CONST_CALL_P (call_insn) = 1;
455
b1e64e0d
RS
456 /* Restore this now, so that we do defer pops for this call's args
457 if the context of the call as a whole permits. */
458 inhibit_defer_pop = old_inhibit_defer_pop;
459
51bbfa0c
RS
460#ifndef ACCUMULATE_OUTGOING_ARGS
461 /* If returning from the subroutine does not automatically pop the args,
462 we need an instruction to pop them sooner or later.
463 Perhaps do it now; perhaps just record how much space to pop later.
464
465 If returning from the subroutine does pop the args, indicate that the
466 stack pointer will be changed. */
467
2c8da025 468 if (stack_size != 0 && RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0)
51bbfa0c
RS
469 {
470 if (!already_popped)
e3da301d 471 CALL_INSN_FUNCTION_USAGE (call_insn)
38a448ca
RH
472 = gen_rtx_EXPR_LIST (VOIDmode,
473 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
474 CALL_INSN_FUNCTION_USAGE (call_insn));
2c8da025 475 stack_size -= RETURN_POPS_ARGS (fndecl, funtype, stack_size);
e5d70561 476 stack_size_rtx = GEN_INT (stack_size);
51bbfa0c
RS
477 }
478
479 if (stack_size != 0)
480 {
70a73141 481 if (flag_defer_pop && inhibit_defer_pop == 0 && !is_const)
51bbfa0c
RS
482 pending_stack_adjust += stack_size;
483 else
484 adjust_stack (stack_size_rtx);
485 }
486#endif
487}
488
20efdf74
JL
489/* Determine if the function identified by NAME and FNDECL is one with
490 special properties we wish to know about.
491
492 For example, if the function might return more than one time (setjmp), then
493 set RETURNS_TWICE to a nonzero value.
494
495 Similarly set IS_LONGJMP for if the function is in the longjmp family.
496
497 Set IS_MALLOC for any of the standard memory allocation functions which
498 allocate from the heap.
499
500 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
501 space from the stack such as alloca. */
502
503static void
504special_function_p (name, fndecl, returns_twice, is_longjmp,
505 is_malloc, may_be_alloca)
506 char *name;
507 tree fndecl;
508 int *returns_twice;
509 int *is_longjmp;
510 int *is_malloc;
511 int *may_be_alloca;
512{
513 *returns_twice = 0;
514 *is_longjmp = 0;
515 *is_malloc = 0;
516 *may_be_alloca = 0;
517
518 /* We assume that alloca will always be called by name. It
519 makes no sense to pass it as a pointer-to-function to
520 anything that does not understand its behavior. */
521 *may_be_alloca
522 = (name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
523 && name[0] == 'a'
524 && ! strcmp (name, "alloca"))
525 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
526 && name[0] == '_'
527 && ! strcmp (name, "__builtin_alloca"))));
528
529 if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
530 /* Exclude functions not at the file scope, or not `extern',
531 since they are not the magic functions we would otherwise
532 think they are. */
533 && DECL_CONTEXT (fndecl) == NULL_TREE && TREE_PUBLIC (fndecl))
534 {
535 char *tname = name;
536
537 /* Disregard prefix _, __ or __x. */
538 if (name[0] == '_')
539 {
540 if (name[1] == '_' && name[2] == 'x')
541 tname += 3;
542 else if (name[1] == '_')
543 tname += 2;
544 else
545 tname += 1;
546 }
547
548 if (tname[0] == 's')
549 {
550 *returns_twice
551 = ((tname[1] == 'e'
552 && (! strcmp (tname, "setjmp")
553 || ! strcmp (tname, "setjmp_syscall")))
554 || (tname[1] == 'i'
555 && ! strcmp (tname, "sigsetjmp"))
556 || (tname[1] == 'a'
557 && ! strcmp (tname, "savectx")));
558 if (tname[1] == 'i'
559 && ! strcmp (tname, "siglongjmp"))
560 *is_longjmp = 1;
561 }
562 else if ((tname[0] == 'q' && tname[1] == 's'
563 && ! strcmp (tname, "qsetjmp"))
564 || (tname[0] == 'v' && tname[1] == 'f'
565 && ! strcmp (tname, "vfork")))
566 *returns_twice = 1;
567
568 else if (tname[0] == 'l' && tname[1] == 'o'
569 && ! strcmp (tname, "longjmp"))
570 *is_longjmp = 1;
571 /* XXX should have "malloc" attribute on functions instead
572 of recognizing them by name. */
573 else if (! strcmp (tname, "malloc")
574 || ! strcmp (tname, "calloc")
575 || ! strcmp (tname, "realloc")
576 /* Note use of NAME rather than TNAME here. These functions
577 are only reserved when preceded with __. */
578 || ! strcmp (name, "__vn") /* mangled __builtin_vec_new */
579 || ! strcmp (name, "__nw") /* mangled __builtin_new */
580 || ! strcmp (name, "__builtin_new")
581 || ! strcmp (name, "__builtin_vec_new"))
582 *is_malloc = 1;
583 }
584}
585
586/* Precompute all register parameters as described by ARGS, storing values
587 into fields within the ARGS array.
588
589 NUM_ACTUALS indicates the total number elements in the ARGS array.
590
591 Set REG_PARM_SEEN if we encounter a register parameter. */
592
593static void
594precompute_register_parameters (num_actuals, args, reg_parm_seen)
595 int num_actuals;
596 struct arg_data *args;
597 int *reg_parm_seen;
598{
599 int i;
600
601 *reg_parm_seen = 0;
602
603 for (i = 0; i < num_actuals; i++)
604 if (args[i].reg != 0 && ! args[i].pass_on_stack)
605 {
606 *reg_parm_seen = 1;
607
608 if (args[i].value == 0)
609 {
610 push_temp_slots ();
611 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
612 VOIDmode, 0);
613 preserve_temp_slots (args[i].value);
614 pop_temp_slots ();
615
616 /* ANSI doesn't require a sequence point here,
617 but PCC has one, so this will avoid some problems. */
618 emit_queue ();
619 }
620
621 /* If we are to promote the function arg to a wider mode,
622 do it now. */
623
624 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
625 args[i].value
626 = convert_modes (args[i].mode,
627 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
628 args[i].value, args[i].unsignedp);
629
630 /* If the value is expensive, and we are inside an appropriately
631 short loop, put the value into a pseudo and then put the pseudo
632 into the hard reg.
633
634 For small register classes, also do this if this call uses
635 register parameters. This is to avoid reload conflicts while
636 loading the parameters registers. */
637
638 if ((! (GET_CODE (args[i].value) == REG
639 || (GET_CODE (args[i].value) == SUBREG
640 && GET_CODE (SUBREG_REG (args[i].value)) == REG)))
641 && args[i].mode != BLKmode
642 && rtx_cost (args[i].value, SET) > 2
643 && ((SMALL_REGISTER_CLASSES && *reg_parm_seen)
644 || preserve_subexpressions_p ()))
645 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
646 }
647}
648
649#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
650
651 /* The argument list is the property of the called routine and it
652 may clobber it. If the fixed area has been used for previous
653 parameters, we must save and restore it. */
654static rtx
655save_fixed_argument_area (reg_parm_stack_space, argblock,
656 low_to_save, high_to_save)
657 int reg_parm_stack_space;
658 rtx argblock;
659 int *low_to_save;
660 int *high_to_save;
661{
662 int i;
663 rtx save_area = NULL_RTX;
664
665 /* Compute the boundary of the that needs to be saved, if any. */
666#ifdef ARGS_GROW_DOWNWARD
667 for (i = 0; i < reg_parm_stack_space + 1; i++)
668#else
669 for (i = 0; i < reg_parm_stack_space; i++)
670#endif
671 {
672 if (i >= highest_outgoing_arg_in_use
673 || stack_usage_map[i] == 0)
674 continue;
675
676 if (*low_to_save == -1)
677 *low_to_save = i;
678
679 *high_to_save = i;
680 }
681
682 if (*low_to_save >= 0)
683 {
684 int num_to_save = *high_to_save - *low_to_save + 1;
685 enum machine_mode save_mode
686 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
687 rtx stack_area;
688
689 /* If we don't have the required alignment, must do this in BLKmode. */
690 if ((*low_to_save & (MIN (GET_MODE_SIZE (save_mode),
691 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
692 save_mode = BLKmode;
693
694#ifdef ARGS_GROW_DOWNWARD
695 stack_area = gen_rtx_MEM (save_mode,
696 memory_address (save_mode,
697 plus_constant (argblock,
698 - *high_to_save)));
699#else
700 stack_area = gen_rtx_MEM (save_mode,
701 memory_address (save_mode,
702 plus_constant (argblock,
703 *low_to_save)));
704#endif
705 if (save_mode == BLKmode)
706 {
707 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
708 MEM_IN_STRUCT_P (save_area) = 0;
709 emit_block_move (validize_mem (save_area), stack_area,
710 GEN_INT (num_to_save),
711 PARM_BOUNDARY / BITS_PER_UNIT);
712 }
713 else
714 {
715 save_area = gen_reg_rtx (save_mode);
716 emit_move_insn (save_area, stack_area);
717 }
718 }
719 return save_area;
720}
721
722static void
723restore_fixed_argument_area (save_area, argblock, high_to_save, low_to_save)
724 rtx save_area;
725 rtx argblock;
726 int high_to_save;
727 int low_to_save;
728{
729 enum machine_mode save_mode = GET_MODE (save_area);
730#ifdef ARGS_GROW_DOWNWARD
731 rtx stack_area
732 = gen_rtx_MEM (save_mode,
733 memory_address (save_mode,
734 plus_constant (argblock,
735 - high_to_save)));
736#else
737 rtx stack_area
738 = gen_rtx_MEM (save_mode,
739 memory_address (save_mode,
740 plus_constant (argblock,
741 low_to_save)));
742#endif
743
744 if (save_mode != BLKmode)
745 emit_move_insn (stack_area, save_area);
746 else
747 emit_block_move (stack_area, validize_mem (save_area),
748 GEN_INT (high_to_save - low_to_save + 1),
749 PARM_BOUNDARY / BITS_PER_UNIT);
750}
751#endif
752
753/* If any elements in ARGS refer to parameters that are to be passed in
754 registers, but not in memory, and whose alignment does not permit a
755 direct copy into registers. Copy the values into a group of pseudos
756 which we will later copy into the appropriate hard registers. */
757static void
758store_unaligned_arguments_into_pseudos (args, num_actuals)
759 struct arg_data *args;
760 int num_actuals;
761{
762 int i, j;
763
764 for (i = 0; i < num_actuals; i++)
765 if (args[i].reg != 0 && ! args[i].pass_on_stack
766 && args[i].mode == BLKmode
767 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
768 < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
769 {
770 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
771 int big_endian_correction = 0;
772
773 args[i].n_aligned_regs
774 = args[i].partial ? args[i].partial
775 : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
776
777 args[i].aligned_regs = (rtx *) alloca (sizeof (rtx)
778 * args[i].n_aligned_regs);
779
780 /* Structures smaller than a word are aligned to the least
781 significant byte (to the right). On a BYTES_BIG_ENDIAN machine,
782 this means we must skip the empty high order bytes when
783 calculating the bit offset. */
784 if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD)
785 big_endian_correction = (BITS_PER_WORD - (bytes * BITS_PER_UNIT));
786
787 for (j = 0; j < args[i].n_aligned_regs; j++)
788 {
789 rtx reg = gen_reg_rtx (word_mode);
790 rtx word = operand_subword_force (args[i].value, j, BLKmode);
791 int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
792 int bitalign = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
793
794 args[i].aligned_regs[j] = reg;
795
796 /* There is no need to restrict this code to loading items
797 in TYPE_ALIGN sized hunks. The bitfield instructions can
798 load up entire word sized registers efficiently.
799
800 ??? This may not be needed anymore.
801 We use to emit a clobber here but that doesn't let later
802 passes optimize the instructions we emit. By storing 0 into
803 the register later passes know the first AND to zero out the
804 bitfield being set in the register is unnecessary. The store
805 of 0 will be deleted as will at least the first AND. */
806
807 emit_move_insn (reg, const0_rtx);
808
809 bytes -= bitsize / BITS_PER_UNIT;
810 store_bit_field (reg, bitsize, big_endian_correction, word_mode,
811 extract_bit_field (word, bitsize, 0, 1,
812 NULL_RTX, word_mode,
813 word_mode,
814 bitalign / BITS_PER_UNIT,
815 BITS_PER_WORD),
816 bitalign / BITS_PER_UNIT, BITS_PER_WORD);
817 }
818 }
819}
820
51bbfa0c
RS
821/* Generate all the code for a function call
822 and return an rtx for its value.
823 Store the value in TARGET (specified as an rtx) if convenient.
824 If the value is stored in TARGET then TARGET is returned.
825 If IGNORE is nonzero, then we ignore the value of the function call. */
826
827rtx
8129842c 828expand_call (exp, target, ignore)
51bbfa0c
RS
829 tree exp;
830 rtx target;
831 int ignore;
51bbfa0c
RS
832{
833 /* List of actual parameters. */
834 tree actparms = TREE_OPERAND (exp, 1);
835 /* RTX for the function to be called. */
836 rtx funexp;
51bbfa0c
RS
837 /* Data type of the function. */
838 tree funtype;
839 /* Declaration of the function being called,
840 or 0 if the function is computed (not known by name). */
841 tree fndecl = 0;
842 char *name = 0;
843
844 /* Register in which non-BLKmode value will be returned,
845 or 0 if no value or if value is BLKmode. */
846 rtx valreg;
847 /* Address where we should return a BLKmode value;
848 0 if value not BLKmode. */
849 rtx structure_value_addr = 0;
850 /* Nonzero if that address is being passed by treating it as
851 an extra, implicit first parameter. Otherwise,
852 it is passed by being copied directly into struct_value_rtx. */
853 int structure_value_addr_parm = 0;
854 /* Size of aggregate value wanted, or zero if none wanted
855 or if we are using the non-reentrant PCC calling convention
856 or expecting the value in registers. */
e5e809f4 857 HOST_WIDE_INT struct_value_size = 0;
51bbfa0c
RS
858 /* Nonzero if called function returns an aggregate in memory PCC style,
859 by returning the address of where to find it. */
860 int pcc_struct_value = 0;
861
862 /* Number of actual parameters in this call, including struct value addr. */
863 int num_actuals;
864 /* Number of named args. Args after this are anonymous ones
865 and they must all go on the stack. */
866 int n_named_args;
867 /* Count arg position in order args appear. */
868 int argpos;
869
870 /* Vector of information about each argument.
871 Arguments are numbered in the order they will be pushed,
872 not the order they are written. */
873 struct arg_data *args;
874
875 /* Total size in bytes of all the stack-parms scanned so far. */
876 struct args_size args_size;
877 /* Size of arguments before any adjustments (such as rounding). */
878 struct args_size original_args_size;
879 /* Data on reg parms scanned so far. */
880 CUMULATIVE_ARGS args_so_far;
881 /* Nonzero if a reg parm has been scanned. */
882 int reg_parm_seen;
efd65a8b 883 /* Nonzero if this is an indirect function call. */
51bbfa0c
RS
884
885 /* Nonzero if we must avoid push-insns in the args for this call.
886 If stack space is allocated for register parameters, but not by the
887 caller, then it is preallocated in the fixed part of the stack frame.
888 So the entire argument block must then be preallocated (i.e., we
889 ignore PUSH_ROUNDING in that case). */
890
51bbfa0c
RS
891#ifdef PUSH_ROUNDING
892 int must_preallocate = 0;
893#else
894 int must_preallocate = 1;
51bbfa0c
RS
895#endif
896
f72aed24 897 /* Size of the stack reserved for parameter registers. */
6f90e075
JW
898 int reg_parm_stack_space = 0;
899
51bbfa0c
RS
900 /* 1 if scanning parms front to back, -1 if scanning back to front. */
901 int inc;
902 /* Address of space preallocated for stack parms
903 (on machines that lack push insns), or 0 if space not preallocated. */
904 rtx argblock = 0;
905
906 /* Nonzero if it is plausible that this is a call to alloca. */
907 int may_be_alloca;
9ae8ffe7
JL
908 /* Nonzero if this is a call to malloc or a related function. */
909 int is_malloc;
51bbfa0c
RS
910 /* Nonzero if this is a call to setjmp or a related function. */
911 int returns_twice;
912 /* Nonzero if this is a call to `longjmp'. */
913 int is_longjmp;
914 /* Nonzero if this is a call to an inline function. */
915 int is_integrable = 0;
51bbfa0c
RS
916 /* Nonzero if this is a call to a `const' function.
917 Note that only explicitly named functions are handled as `const' here. */
918 int is_const = 0;
919 /* Nonzero if this is a call to a `volatile' function. */
920 int is_volatile = 0;
921#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
922 /* Define the boundary of the register parm stack space that needs to be
923 save, if any. */
924 int low_to_save = -1, high_to_save;
925 rtx save_area = 0; /* Place that it is saved */
926#endif
927
928#ifdef ACCUMULATE_OUTGOING_ARGS
929 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
930 char *initial_stack_usage_map = stack_usage_map;
69d4ca36 931 int old_stack_arg_under_construction;
51bbfa0c
RS
932#endif
933
934 rtx old_stack_level = 0;
79be3418 935 int old_pending_adj = 0;
51bbfa0c 936 int old_inhibit_defer_pop = inhibit_defer_pop;
77cac2f2 937 rtx call_fusage = 0;
51bbfa0c 938 register tree p;
4ab56118 939 register int i, j;
51bbfa0c 940
7815214e
RK
941 /* The value of the function call can be put in a hard register. But
942 if -fcheck-memory-usage, code which invokes functions (and thus
943 damages some hard registers) can be inserted before using the value.
944 So, target is always a pseudo-register in that case. */
7d384cc0 945 if (current_function_check_memory_usage)
7815214e
RK
946 target = 0;
947
51bbfa0c
RS
948 /* See if we can find a DECL-node for the actual function.
949 As a result, decide whether this is a call to an integrable function. */
950
951 p = TREE_OPERAND (exp, 0);
952 if (TREE_CODE (p) == ADDR_EXPR)
953 {
954 fndecl = TREE_OPERAND (p, 0);
955 if (TREE_CODE (fndecl) != FUNCTION_DECL)
fdff8c6d 956 fndecl = 0;
51bbfa0c
RS
957 else
958 {
959 if (!flag_no_inline
960 && fndecl != current_function_decl
aa10adff 961 && DECL_INLINE (fndecl)
1cf4f698
RK
962 && DECL_SAVED_INSNS (fndecl)
963 && RTX_INTEGRATED_P (DECL_SAVED_INSNS (fndecl)))
51bbfa0c
RS
964 is_integrable = 1;
965 else if (! TREE_ADDRESSABLE (fndecl))
966 {
13d39dbc 967 /* In case this function later becomes inlinable,
51bbfa0c
RS
968 record that there was already a non-inline call to it.
969
970 Use abstraction instead of setting TREE_ADDRESSABLE
971 directly. */
da8c1713
RK
972 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
973 && optimize > 0)
1907795e
JM
974 {
975 warning_with_decl (fndecl, "can't inline call to `%s'");
976 warning ("called from here");
977 }
51bbfa0c
RS
978 mark_addressable (fndecl);
979 }
980
d45cf215
RS
981 if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
982 && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
51bbfa0c 983 is_const = 1;
5e24110e
RS
984
985 if (TREE_THIS_VOLATILE (fndecl))
986 is_volatile = 1;
51bbfa0c
RS
987 }
988 }
989
fdff8c6d
RK
990 /* If we don't have specific function to call, see if we have a
991 constant or `noreturn' function from the type. */
992 if (fndecl == 0)
993 {
994 is_const = TREE_READONLY (TREE_TYPE (TREE_TYPE (p)));
995 is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
996 }
997
6f90e075
JW
998#ifdef REG_PARM_STACK_SPACE
999#ifdef MAYBE_REG_PARM_STACK_SPACE
1000 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
1001#else
1002 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
1003#endif
1004#endif
1005
e5e809f4
JL
1006#if defined(PUSH_ROUNDING) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1007 if (reg_parm_stack_space > 0)
1008 must_preallocate = 1;
1009#endif
1010
51bbfa0c
RS
1011 /* Warn if this value is an aggregate type,
1012 regardless of which calling convention we are using for it. */
05e3bdb9 1013 if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
51bbfa0c
RS
1014 warning ("function call has aggregate value");
1015
1016 /* Set up a place to return a structure. */
1017
1018 /* Cater to broken compilers. */
1019 if (aggregate_value_p (exp))
1020 {
1021 /* This call returns a big structure. */
1022 is_const = 0;
1023
1024#ifdef PCC_STATIC_STRUCT_RETURN
9e7b1d0a
RS
1025 {
1026 pcc_struct_value = 1;
0dd532dc
JW
1027 /* Easier than making that case work right. */
1028 if (is_integrable)
1029 {
1030 /* In case this is a static function, note that it has been
1031 used. */
1032 if (! TREE_ADDRESSABLE (fndecl))
1033 mark_addressable (fndecl);
1034 is_integrable = 0;
1035 }
9e7b1d0a
RS
1036 }
1037#else /* not PCC_STATIC_STRUCT_RETURN */
1038 {
1039 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
51bbfa0c 1040
9e7b1d0a
RS
1041 if (target && GET_CODE (target) == MEM)
1042 structure_value_addr = XEXP (target, 0);
1043 else
1044 {
e9a25f70
JL
1045 /* Assign a temporary to hold the value. */
1046 tree d;
51bbfa0c 1047
9e7b1d0a
RS
1048 /* For variable-sized objects, we must be called with a target
1049 specified. If we were to allocate space on the stack here,
1050 we would have no way of knowing when to free it. */
51bbfa0c 1051
002bdd6c
RK
1052 if (struct_value_size < 0)
1053 abort ();
1054
e9a25f70
JL
1055 /* This DECL is just something to feed to mark_addressable;
1056 it doesn't get pushed. */
1057 d = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (exp));
1058 DECL_RTL (d) = assign_temp (TREE_TYPE (exp), 1, 0, 1);
1059 mark_addressable (d);
1060 structure_value_addr = XEXP (DECL_RTL (d), 0);
e5e809f4 1061 TREE_USED (d) = 1;
9e7b1d0a
RS
1062 target = 0;
1063 }
1064 }
1065#endif /* not PCC_STATIC_STRUCT_RETURN */
51bbfa0c
RS
1066 }
1067
1068 /* If called function is inline, try to integrate it. */
1069
1070 if (is_integrable)
1071 {
1072 rtx temp;
69d4ca36 1073#ifdef ACCUMULATE_OUTGOING_ARGS
2f4aa534 1074 rtx before_call = get_last_insn ();
69d4ca36 1075#endif
51bbfa0c
RS
1076
1077 temp = expand_inline_function (fndecl, actparms, target,
1078 ignore, TREE_TYPE (exp),
1079 structure_value_addr);
1080
1081 /* If inlining succeeded, return. */
2e0dd623 1082 if (temp != (rtx) (HOST_WIDE_INT) -1)
51bbfa0c 1083 {
d64f5a78 1084#ifdef ACCUMULATE_OUTGOING_ARGS
2f4aa534
RS
1085 /* If the outgoing argument list must be preserved, push
1086 the stack before executing the inlined function if it
1087 makes any calls. */
1088
1089 for (i = reg_parm_stack_space - 1; i >= 0; i--)
1090 if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
1091 break;
1092
1093 if (stack_arg_under_construction || i >= 0)
1094 {
a1917650
RK
1095 rtx first_insn
1096 = before_call ? NEXT_INSN (before_call) : get_insns ();
1097 rtx insn, seq;
2f4aa534 1098
d64f5a78
RS
1099 /* Look for a call in the inline function code.
1100 If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is
1101 nonzero then there is a call and it is not necessary
1102 to scan the insns. */
1103
1104 if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0)
a1917650 1105 for (insn = first_insn; insn; insn = NEXT_INSN (insn))
d64f5a78
RS
1106 if (GET_CODE (insn) == CALL_INSN)
1107 break;
2f4aa534
RS
1108
1109 if (insn)
1110 {
d64f5a78
RS
1111 /* Reserve enough stack space so that the largest
1112 argument list of any function call in the inline
1113 function does not overlap the argument list being
1114 evaluated. This is usually an overestimate because
1115 allocate_dynamic_stack_space reserves space for an
1116 outgoing argument list in addition to the requested
1117 space, but there is no way to ask for stack space such
1118 that an argument list of a certain length can be
e5e809f4 1119 safely constructed.
d64f5a78 1120
e5e809f4
JL
1121 Add the stack space reserved for register arguments, if
1122 any, in the inline function. What is really needed is the
d64f5a78
RS
1123 largest value of reg_parm_stack_space in the inline
1124 function, but that is not available. Using the current
1125 value of reg_parm_stack_space is wrong, but gives
1126 correct results on all supported machines. */
e5e809f4
JL
1127
1128 int adjust = (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl))
1129 + reg_parm_stack_space);
1130
2f4aa534 1131 start_sequence ();
ccf5d244 1132 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
e5d70561
RK
1133 allocate_dynamic_stack_space (GEN_INT (adjust),
1134 NULL_RTX, BITS_PER_UNIT);
2f4aa534
RS
1135 seq = get_insns ();
1136 end_sequence ();
a1917650 1137 emit_insns_before (seq, first_insn);
e5d70561 1138 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
2f4aa534
RS
1139 }
1140 }
d64f5a78 1141#endif
51bbfa0c
RS
1142
1143 /* If the result is equivalent to TARGET, return TARGET to simplify
1144 checks in store_expr. They can be equivalent but not equal in the
1145 case of a function that returns BLKmode. */
1146 if (temp != target && rtx_equal_p (temp, target))
1147 return target;
1148 return temp;
1149 }
1150
1151 /* If inlining failed, mark FNDECL as needing to be compiled
0481a55e
RK
1152 separately after all. If function was declared inline,
1153 give a warning. */
1154 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
da8c1713 1155 && optimize > 0 && ! TREE_ADDRESSABLE (fndecl))
1907795e
JM
1156 {
1157 warning_with_decl (fndecl, "inlining failed in call to `%s'");
1158 warning ("called from here");
1159 }
51bbfa0c
RS
1160 mark_addressable (fndecl);
1161 }
1162
1163 /* When calling a const function, we must pop the stack args right away,
1164 so that the pop is deleted or moved with the call. */
1165 if (is_const)
1166 NO_DEFER_POP;
1167
1168 function_call_count++;
1169
1170 if (fndecl && DECL_NAME (fndecl))
1171 name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
1172
51bbfa0c 1173 /* See if this is a call to a function that can return more than once
20efdf74
JL
1174 or a call to longjmp or malloc. */
1175 special_function_p (name, fndecl, &returns_twice, &is_longjmp,
1176 &is_malloc, &may_be_alloca);
51bbfa0c 1177
51bbfa0c
RS
1178 if (may_be_alloca)
1179 current_function_calls_alloca = 1;
1180
1181 /* Don't let pending stack adjusts add up to too much.
1182 Also, do all pending adjustments now
1183 if there is any chance this might be a call to alloca. */
1184
1185 if (pending_stack_adjust >= 32
1186 || (pending_stack_adjust > 0 && may_be_alloca))
1187 do_pending_stack_adjust ();
1188
1189 /* Operand 0 is a pointer-to-function; get the type of the function. */
1190 funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
1191 if (TREE_CODE (funtype) != POINTER_TYPE)
1192 abort ();
1193 funtype = TREE_TYPE (funtype);
1194
cc79451b
RK
1195 /* Push the temporary stack slot level so that we can free any temporaries
1196 we make. */
51bbfa0c
RS
1197 push_temp_slots ();
1198
eecb6f50
JL
1199 /* Start updating where the next arg would go.
1200
1201 On some machines (such as the PA) indirect calls have a different
1202 calling convention than normal calls. The last argument in
1203 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
1204 or not. */
1205 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, (fndecl == 0));
51bbfa0c
RS
1206
1207 /* If struct_value_rtx is 0, it means pass the address
1208 as if it were an extra parameter. */
1209 if (structure_value_addr && struct_value_rtx == 0)
1210 {
5582b006
RK
1211 /* If structure_value_addr is a REG other than
1212 virtual_outgoing_args_rtx, we can use always use it. If it
1213 is not a REG, we must always copy it into a register.
1214 If it is virtual_outgoing_args_rtx, we must copy it to another
1215 register in some cases. */
1216 rtx temp = (GET_CODE (structure_value_addr) != REG
d64f5a78 1217#ifdef ACCUMULATE_OUTGOING_ARGS
5582b006
RK
1218 || (stack_arg_under_construction
1219 && structure_value_addr == virtual_outgoing_args_rtx)
d64f5a78 1220#endif
5582b006
RK
1221 ? copy_addr_to_reg (structure_value_addr)
1222 : structure_value_addr);
d64f5a78 1223
51bbfa0c
RS
1224 actparms
1225 = tree_cons (error_mark_node,
1226 make_tree (build_pointer_type (TREE_TYPE (funtype)),
2f4aa534 1227 temp),
51bbfa0c
RS
1228 actparms);
1229 structure_value_addr_parm = 1;
1230 }
1231
1232 /* Count the arguments and set NUM_ACTUALS. */
1233 for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
1234 num_actuals = i;
1235
1236 /* Compute number of named args.
1237 Normally, don't include the last named arg if anonymous args follow.
e5e809f4 1238 We do include the last named arg if STRICT_ARGUMENT_NAMING is nonzero.
469225d8
JW
1239 (If no anonymous args follow, the result of list_length is actually
1240 one too large. This is harmless.)
51bbfa0c 1241
e5e809f4 1242 If SETUP_INCOMING_VARARGS is defined and STRICT_ARGUMENT_NAMING is zero,
469225d8
JW
1243 this machine will be able to place unnamed args that were passed in
1244 registers into the stack. So treat all args as named. This allows the
1245 insns emitting for a specific argument list to be independent of the
1246 function declaration.
51bbfa0c
RS
1247
1248 If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable
1249 way to pass unnamed args in registers, so we must force them into
1250 memory. */
e5e809f4
JL
1251
1252 if ((STRICT_ARGUMENT_NAMING
1253#ifndef SETUP_INCOMING_VARARGS
1254 || 1
1255#endif
1256 )
1257 && TYPE_ARG_TYPES (funtype) != 0)
51bbfa0c 1258 n_named_args
0ee902cb 1259 = (list_length (TYPE_ARG_TYPES (funtype))
0ee902cb 1260 /* Don't include the last named arg. */
d0f9021a 1261 - (STRICT_ARGUMENT_NAMING ? 0 : 1)
0ee902cb
RM
1262 /* Count the struct value address, if it is passed as a parm. */
1263 + structure_value_addr_parm);
51bbfa0c 1264 else
51bbfa0c
RS
1265 /* If we know nothing, treat all args as named. */
1266 n_named_args = num_actuals;
1267
1268 /* Make a vector to hold all the information about each arg. */
1269 args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
4c9a05bc 1270 bzero ((char *) args, num_actuals * sizeof (struct arg_data));
51bbfa0c
RS
1271
1272 args_size.constant = 0;
1273 args_size.var = 0;
1274
1275 /* In this loop, we consider args in the order they are written.
0ee902cb 1276 We fill up ARGS from the front or from the back if necessary
51bbfa0c
RS
1277 so that in any case the first arg to be pushed ends up at the front. */
1278
1279#ifdef PUSH_ARGS_REVERSED
1280 i = num_actuals - 1, inc = -1;
1281 /* In this case, must reverse order of args
1282 so that we compute and push the last arg first. */
1283#else
1284 i = 0, inc = 1;
1285#endif
1286
1287 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1288 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
1289 {
1290 tree type = TREE_TYPE (TREE_VALUE (p));
321e0bba 1291 int unsignedp;
84b55618 1292 enum machine_mode mode;
51bbfa0c
RS
1293
1294 args[i].tree_value = TREE_VALUE (p);
1295
1296 /* Replace erroneous argument with constant zero. */
1297 if (type == error_mark_node || TYPE_SIZE (type) == 0)
1298 args[i].tree_value = integer_zero_node, type = integer_type_node;
1299
5c1c34d3
RK
1300 /* If TYPE is a transparent union, pass things the way we would
1301 pass the first field of the union. We have already verified that
1302 the modes are the same. */
1303 if (TYPE_TRANSPARENT_UNION (type))
1304 type = TREE_TYPE (TYPE_FIELDS (type));
1305
51bbfa0c
RS
1306 /* Decide where to pass this arg.
1307
1308 args[i].reg is nonzero if all or part is passed in registers.
1309
1310 args[i].partial is nonzero if part but not all is passed in registers,
1311 and the exact value says how many words are passed in registers.
1312
1313 args[i].pass_on_stack is nonzero if the argument must at least be
1314 computed on the stack. It may then be loaded back into registers
1315 if args[i].reg is nonzero.
1316
1317 These decisions are driven by the FUNCTION_... macros and must agree
1318 with those made by function.c. */
1319
51bbfa0c 1320 /* See if this argument should be passed by invisible reference. */
7ef1fbd7
RK
1321 if ((TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1322 && contains_placeholder_p (TYPE_SIZE (type)))
657bb6dc 1323 || TREE_ADDRESSABLE (type)
7ef1fbd7
RK
1324#ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1325 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, TYPE_MODE (type),
1326 type, argpos < n_named_args)
1327#endif
1328 )
51bbfa0c 1329 {
173cd503
JM
1330 /* If we're compiling a thunk, pass through invisible
1331 references instead of making a copy. */
1332 if (current_function_is_thunk
5e0de251 1333#ifdef FUNCTION_ARG_CALLEE_COPIES
173cd503
JM
1334 || (FUNCTION_ARG_CALLEE_COPIES (args_so_far, TYPE_MODE (type),
1335 type, argpos < n_named_args)
1336 /* If it's in a register, we must make a copy of it too. */
1337 /* ??? Is this a sufficient test? Is there a better one? */
1338 && !(TREE_CODE (args[i].tree_value) == VAR_DECL
1339 && REG_P (DECL_RTL (args[i].tree_value)))
1340 && ! TREE_ADDRESSABLE (type))
1341#endif
1342 )
51bbfa0c 1343 {
5e0de251
DE
1344 args[i].tree_value = build1 (ADDR_EXPR,
1345 build_pointer_type (type),
1346 args[i].tree_value);
1347 type = build_pointer_type (type);
51bbfa0c
RS
1348 }
1349 else
82c0ff02 1350 {
5e0de251
DE
1351 /* We make a copy of the object and pass the address to the
1352 function being called. */
1353 rtx copy;
51bbfa0c 1354
5e0de251 1355 if (TYPE_SIZE (type) == 0
2d59d98e
RK
1356 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1357 || (flag_stack_check && ! STACK_CHECK_BUILTIN
1358 && (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0
1359 || (TREE_INT_CST_LOW (TYPE_SIZE (type))
1360 > STACK_CHECK_MAX_VAR_SIZE * BITS_PER_UNIT))))
5e0de251
DE
1361 {
1362 /* This is a variable-sized object. Make space on the stack
1363 for it. */
1364 rtx size_rtx = expr_size (TREE_VALUE (p));
1365
1366 if (old_stack_level == 0)
1367 {
1368 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1369 old_pending_adj = pending_stack_adjust;
1370 pending_stack_adjust = 0;
1371 }
1372
38a448ca
RH
1373 copy = gen_rtx_MEM (BLKmode,
1374 allocate_dynamic_stack_space (size_rtx,
1375 NULL_RTX,
1376 TYPE_ALIGN (type)));
5e0de251
DE
1377 }
1378 else
1379 {
1380 int size = int_size_in_bytes (type);
6fa51029 1381 copy = assign_stack_temp (TYPE_MODE (type), size, 0);
5e0de251 1382 }
51bbfa0c 1383
05e3bdb9 1384 MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
6e87e69e 1385
5e0de251 1386 store_expr (args[i].tree_value, copy, 0);
ba3a053e 1387 is_const = 0;
5e0de251
DE
1388
1389 args[i].tree_value = build1 (ADDR_EXPR,
1390 build_pointer_type (type),
1391 make_tree (type, copy));
1392 type = build_pointer_type (type);
1393 }
51bbfa0c 1394 }
51bbfa0c 1395
84b55618 1396 mode = TYPE_MODE (type);
321e0bba 1397 unsignedp = TREE_UNSIGNED (type);
84b55618
RK
1398
1399#ifdef PROMOTE_FUNCTION_ARGS
321e0bba 1400 mode = promote_mode (type, mode, &unsignedp, 1);
84b55618
RK
1401#endif
1402
321e0bba 1403 args[i].unsignedp = unsignedp;
1efe6448 1404 args[i].mode = mode;
84b55618 1405 args[i].reg = FUNCTION_ARG (args_so_far, mode, type,
51bbfa0c
RS
1406 argpos < n_named_args);
1407#ifdef FUNCTION_ARG_PARTIAL_NREGS
1408 if (args[i].reg)
1409 args[i].partial
84b55618 1410 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, type,
51bbfa0c
RS
1411 argpos < n_named_args);
1412#endif
1413
84b55618 1414 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
51bbfa0c 1415
cacbd532
JW
1416 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1417 it means that we are to pass this arg in the register(s) designated
1418 by the PARALLEL, but also to pass it in the stack. */
1419 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1420 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1421 args[i].pass_on_stack = 1;
51bbfa0c
RS
1422
1423 /* If this is an addressable type, we must preallocate the stack
1424 since we must evaluate the object into its final location.
1425
1426 If this is to be passed in both registers and the stack, it is simpler
1427 to preallocate. */
1428 if (TREE_ADDRESSABLE (type)
1429 || (args[i].pass_on_stack && args[i].reg != 0))
1430 must_preallocate = 1;
1431
1432 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1433 we cannot consider this function call constant. */
1434 if (TREE_ADDRESSABLE (type))
1435 is_const = 0;
1436
1437 /* Compute the stack-size of this argument. */
1438 if (args[i].reg == 0 || args[i].partial != 0
6f90e075 1439 || reg_parm_stack_space > 0
51bbfa0c 1440 || args[i].pass_on_stack)
1efe6448 1441 locate_and_pad_parm (mode, type,
51bbfa0c
RS
1442#ifdef STACK_PARMS_IN_REG_PARM_AREA
1443 1,
1444#else
1445 args[i].reg != 0,
1446#endif
1447 fndecl, &args_size, &args[i].offset,
1448 &args[i].size);
1449
1450#ifndef ARGS_GROW_DOWNWARD
1451 args[i].slot_offset = args_size;
1452#endif
1453
51bbfa0c
RS
1454 /* If a part of the arg was put into registers,
1455 don't include that part in the amount pushed. */
e5e809f4 1456 if (reg_parm_stack_space == 0 && ! args[i].pass_on_stack)
51bbfa0c
RS
1457 args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1458 / (PARM_BOUNDARY / BITS_PER_UNIT)
1459 * (PARM_BOUNDARY / BITS_PER_UNIT));
51bbfa0c
RS
1460
1461 /* Update ARGS_SIZE, the total stack space for args so far. */
1462
1463 args_size.constant += args[i].size.constant;
1464 if (args[i].size.var)
1465 {
1466 ADD_PARM_SIZE (args_size, args[i].size.var);
1467 }
1468
1469 /* Since the slot offset points to the bottom of the slot,
1470 we must record it after incrementing if the args grow down. */
1471#ifdef ARGS_GROW_DOWNWARD
1472 args[i].slot_offset = args_size;
1473
1474 args[i].slot_offset.constant = -args_size.constant;
1475 if (args_size.var)
1476 {
1477 SUB_PARM_SIZE (args[i].slot_offset, args_size.var);
1478 }
1479#endif
1480
1481 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1482 have been used, etc. */
1483
1484 FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type,
1485 argpos < n_named_args);
1486 }
1487
6f90e075
JW
1488#ifdef FINAL_REG_PARM_STACK_SPACE
1489 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
1490 args_size.var);
1491#endif
1492
51bbfa0c
RS
1493 /* Compute the actual size of the argument block required. The variable
1494 and constant sizes must be combined, the size may have to be rounded,
1495 and there may be a minimum required size. */
1496
1497 original_args_size = args_size;
1498 if (args_size.var)
1499 {
1500 /* If this function requires a variable-sized argument list, don't try to
1501 make a cse'able block for this call. We may be able to do this
1502 eventually, but it is too complicated to keep track of what insns go
1503 in the cse'able block and which don't. */
1504
1505 is_const = 0;
1506 must_preallocate = 1;
1507
1508 args_size.var = ARGS_SIZE_TREE (args_size);
1509 args_size.constant = 0;
1510
c795bca9
BS
1511#ifdef PREFERRED_STACK_BOUNDARY
1512 if (PREFERRED_STACK_BOUNDARY != BITS_PER_UNIT)
51bbfa0c
RS
1513 args_size.var = round_up (args_size.var, STACK_BYTES);
1514#endif
1515
6f90e075 1516 if (reg_parm_stack_space > 0)
51bbfa0c
RS
1517 {
1518 args_size.var
1519 = size_binop (MAX_EXPR, args_size.var,
e5e809f4 1520 size_int (reg_parm_stack_space));
51bbfa0c
RS
1521
1522#ifndef OUTGOING_REG_PARM_STACK_SPACE
1523 /* The area corresponding to register parameters is not to count in
1524 the size of the block we need. So make the adjustment. */
1525 args_size.var
1526 = size_binop (MINUS_EXPR, args_size.var,
6f90e075 1527 size_int (reg_parm_stack_space));
51bbfa0c
RS
1528#endif
1529 }
51bbfa0c
RS
1530 }
1531 else
1532 {
c795bca9 1533#ifdef PREFERRED_STACK_BOUNDARY
51bbfa0c
RS
1534 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
1535 / STACK_BYTES) * STACK_BYTES);
1536#endif
1537
51bbfa0c 1538 args_size.constant = MAX (args_size.constant,
6f90e075 1539 reg_parm_stack_space);
e5e809f4 1540
e1336658
JW
1541#ifdef MAYBE_REG_PARM_STACK_SPACE
1542 if (reg_parm_stack_space == 0)
1543 args_size.constant = 0;
1544#endif
e5e809f4 1545
51bbfa0c 1546#ifndef OUTGOING_REG_PARM_STACK_SPACE
6f90e075 1547 args_size.constant -= reg_parm_stack_space;
51bbfa0c
RS
1548#endif
1549 }
1550
1551 /* See if we have or want to preallocate stack space.
1552
1553 If we would have to push a partially-in-regs parm
1554 before other stack parms, preallocate stack space instead.
1555
1556 If the size of some parm is not a multiple of the required stack
1557 alignment, we must preallocate.
1558
1559 If the total size of arguments that would otherwise create a copy in
1560 a temporary (such as a CALL) is more than half the total argument list
1561 size, preallocation is faster.
1562
1563 Another reason to preallocate is if we have a machine (like the m88k)
1564 where stack alignment is required to be maintained between every
1565 pair of insns, not just when the call is made. However, we assume here
1566 that such machines either do not have push insns (and hence preallocation
1567 would occur anyway) or the problem is taken care of with
1568 PUSH_ROUNDING. */
1569
1570 if (! must_preallocate)
1571 {
1572 int partial_seen = 0;
1573 int copy_to_evaluate_size = 0;
1574
1575 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1576 {
1577 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1578 partial_seen = 1;
1579 else if (partial_seen && args[i].reg == 0)
1580 must_preallocate = 1;
1581
1582 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1583 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1584 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1585 || TREE_CODE (args[i].tree_value) == COND_EXPR
1586 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1587 copy_to_evaluate_size
1588 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1589 }
1590
c62f36cf
RS
1591 if (copy_to_evaluate_size * 2 >= args_size.constant
1592 && args_size.constant > 0)
51bbfa0c
RS
1593 must_preallocate = 1;
1594 }
1595
1596 /* If the structure value address will reference the stack pointer, we must
1597 stabilize it. We don't need to do this if we know that we are not going
1598 to adjust the stack pointer in processing this call. */
1599
1600 if (structure_value_addr
1601 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
1602 || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr))
1603 && (args_size.var
1604#ifndef ACCUMULATE_OUTGOING_ARGS
1605 || args_size.constant
1606#endif
1607 ))
1608 structure_value_addr = copy_to_reg (structure_value_addr);
1609
1610 /* If this function call is cse'able, precompute all the parameters.
1611 Note that if the parameter is constructed into a temporary, this will
1612 cause an additional copy because the parameter will be constructed
1613 into a temporary location and then copied into the outgoing arguments.
1614 If a parameter contains a call to alloca and this function uses the
1615 stack, precompute the parameter. */
1616
1ce0cb53
JW
1617 /* If we preallocated the stack space, and some arguments must be passed
1618 on the stack, then we must precompute any parameter which contains a
1619 function call which will store arguments on the stack.
1620 Otherwise, evaluating the parameter may clobber previous parameters
1621 which have already been stored into the stack. */
1622
51bbfa0c
RS
1623 for (i = 0; i < num_actuals; i++)
1624 if (is_const
1625 || ((args_size.var != 0 || args_size.constant != 0)
1ce0cb53
JW
1626 && calls_function (args[i].tree_value, 1))
1627 || (must_preallocate && (args_size.var != 0 || args_size.constant != 0)
1628 && calls_function (args[i].tree_value, 0)))
51bbfa0c 1629 {
657bb6dc
JM
1630 /* If this is an addressable type, we cannot pre-evaluate it. */
1631 if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))
1632 abort ();
1633
cc79451b
RK
1634 push_temp_slots ();
1635
51bbfa0c 1636 args[i].initial_value = args[i].value
e5d70561 1637 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1efe6448 1638
51bbfa0c 1639 preserve_temp_slots (args[i].value);
cc79451b 1640 pop_temp_slots ();
51bbfa0c
RS
1641
1642 /* ANSI doesn't require a sequence point here,
1643 but PCC has one, so this will avoid some problems. */
1644 emit_queue ();
8e6c802b
RK
1645
1646 args[i].initial_value = args[i].value
1647 = protect_from_queue (args[i].initial_value, 0);
1648
1649 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != args[i].mode)
1650 args[i].value
1651 = convert_modes (args[i].mode,
1652 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1653 args[i].value, args[i].unsignedp);
51bbfa0c
RS
1654 }
1655
1656 /* Now we are about to start emitting insns that can be deleted
1657 if a libcall is deleted. */
9ae8ffe7 1658 if (is_const || is_malloc)
51bbfa0c
RS
1659 start_sequence ();
1660
1661 /* If we have no actual push instructions, or shouldn't use them,
1662 make space for all args right now. */
1663
1664 if (args_size.var != 0)
1665 {
1666 if (old_stack_level == 0)
1667 {
e5d70561 1668 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
51bbfa0c
RS
1669 old_pending_adj = pending_stack_adjust;
1670 pending_stack_adjust = 0;
d64f5a78 1671#ifdef ACCUMULATE_OUTGOING_ARGS
2f4aa534
RS
1672 /* stack_arg_under_construction says whether a stack arg is
1673 being constructed at the old stack level. Pushing the stack
1674 gets a clean outgoing argument block. */
1675 old_stack_arg_under_construction = stack_arg_under_construction;
1676 stack_arg_under_construction = 0;
d64f5a78 1677#endif
51bbfa0c
RS
1678 }
1679 argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
1680 }
26a258fe 1681 else
51bbfa0c
RS
1682 {
1683 /* Note that we must go through the motions of allocating an argument
1684 block even if the size is zero because we may be storing args
1685 in the area reserved for register arguments, which may be part of
1686 the stack frame. */
26a258fe 1687
51bbfa0c
RS
1688 int needed = args_size.constant;
1689
0f41302f
MS
1690 /* Store the maximum argument space used. It will be pushed by
1691 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
1692 checking). */
51bbfa0c
RS
1693
1694 if (needed > current_function_outgoing_args_size)
1695 current_function_outgoing_args_size = needed;
1696
26a258fe
PB
1697 if (must_preallocate)
1698 {
1699#ifdef ACCUMULATE_OUTGOING_ARGS
1700 /* Since the stack pointer will never be pushed, it is possible for
1701 the evaluation of a parm to clobber something we have already
1702 written to the stack. Since most function calls on RISC machines
1703 do not use the stack, this is uncommon, but must work correctly.
1704
1705 Therefore, we save any area of the stack that was already written
1706 and that we are using. Here we set up to do this by making a new
1707 stack usage map from the old one. The actual save will be done
1708 by store_one_arg.
1709
1710 Another approach might be to try to reorder the argument
1711 evaluations to avoid this conflicting stack usage. */
1712
e5e809f4 1713#ifndef OUTGOING_REG_PARM_STACK_SPACE
26a258fe
PB
1714 /* Since we will be writing into the entire argument area, the
1715 map must be allocated for its entire size, not just the part that
1716 is the responsibility of the caller. */
1717 needed += reg_parm_stack_space;
51bbfa0c
RS
1718#endif
1719
1720#ifdef ARGS_GROW_DOWNWARD
26a258fe
PB
1721 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1722 needed + 1);
51bbfa0c 1723#else
26a258fe
PB
1724 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1725 needed);
51bbfa0c 1726#endif
26a258fe 1727 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
51bbfa0c 1728
26a258fe
PB
1729 if (initial_highest_arg_in_use)
1730 bcopy (initial_stack_usage_map, stack_usage_map,
1731 initial_highest_arg_in_use);
51bbfa0c 1732
26a258fe
PB
1733 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
1734 bzero (&stack_usage_map[initial_highest_arg_in_use],
1735 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
1736 needed = 0;
2f4aa534 1737
26a258fe
PB
1738 /* The address of the outgoing argument list must not be copied to a
1739 register here, because argblock would be left pointing to the
1740 wrong place after the call to allocate_dynamic_stack_space below.
1741 */
2f4aa534 1742
26a258fe 1743 argblock = virtual_outgoing_args_rtx;
2f4aa534 1744
51bbfa0c 1745#else /* not ACCUMULATE_OUTGOING_ARGS */
26a258fe 1746 if (inhibit_defer_pop == 0)
51bbfa0c 1747 {
26a258fe
PB
1748 /* Try to reuse some or all of the pending_stack_adjust
1749 to get this space. Maybe we can avoid any pushing. */
1750 if (needed > pending_stack_adjust)
1751 {
1752 needed -= pending_stack_adjust;
1753 pending_stack_adjust = 0;
1754 }
1755 else
1756 {
1757 pending_stack_adjust -= needed;
1758 needed = 0;
1759 }
51bbfa0c 1760 }
26a258fe
PB
1761 /* Special case this because overhead of `push_block' in this
1762 case is non-trivial. */
1763 if (needed == 0)
1764 argblock = virtual_outgoing_args_rtx;
51bbfa0c 1765 else
26a258fe
PB
1766 argblock = push_block (GEN_INT (needed), 0, 0);
1767
1768 /* We only really need to call `copy_to_reg' in the case where push
1769 insns are going to be used to pass ARGBLOCK to a function
1770 call in ARGS. In that case, the stack pointer changes value
1771 from the allocation point to the call point, and hence
1772 the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
1773 But might as well always do it. */
1774 argblock = copy_to_reg (argblock);
51bbfa0c 1775#endif /* not ACCUMULATE_OUTGOING_ARGS */
26a258fe 1776 }
51bbfa0c
RS
1777 }
1778
bfbf933a
RS
1779#ifdef ACCUMULATE_OUTGOING_ARGS
1780 /* The save/restore code in store_one_arg handles all cases except one:
1781 a constructor call (including a C function returning a BLKmode struct)
1782 to initialize an argument. */
1783 if (stack_arg_under_construction)
1784 {
e5e809f4 1785#ifndef OUTGOING_REG_PARM_STACK_SPACE
e5d70561 1786 rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
bfbf933a 1787#else
e5d70561 1788 rtx push_size = GEN_INT (args_size.constant);
bfbf933a
RS
1789#endif
1790 if (old_stack_level == 0)
1791 {
e5d70561 1792 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
bfbf933a
RS
1793 old_pending_adj = pending_stack_adjust;
1794 pending_stack_adjust = 0;
1795 /* stack_arg_under_construction says whether a stack arg is
1796 being constructed at the old stack level. Pushing the stack
1797 gets a clean outgoing argument block. */
1798 old_stack_arg_under_construction = stack_arg_under_construction;
1799 stack_arg_under_construction = 0;
1800 /* Make a new map for the new argument list. */
1801 stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
1802 bzero (stack_usage_map, highest_outgoing_arg_in_use);
1803 highest_outgoing_arg_in_use = 0;
1804 }
e5d70561 1805 allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
bfbf933a
RS
1806 }
1807 /* If argument evaluation might modify the stack pointer, copy the
1808 address of the argument list to a register. */
1809 for (i = 0; i < num_actuals; i++)
1810 if (args[i].pass_on_stack)
1811 {
1812 argblock = copy_addr_to_reg (argblock);
1813 break;
1814 }
1815#endif
1816
1817
51bbfa0c
RS
1818 /* If we preallocated stack space, compute the address of each argument.
1819 We need not ensure it is a valid memory address here; it will be
1820 validized when it is used. */
1821 if (argblock)
1822 {
1823 rtx arg_reg = argblock;
1824 int arg_offset = 0;
1825
1826 if (GET_CODE (argblock) == PLUS)
1827 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1828
1829 for (i = 0; i < num_actuals; i++)
1830 {
1831 rtx offset = ARGS_SIZE_RTX (args[i].offset);
1832 rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1833 rtx addr;
1834
1835 /* Skip this parm if it will not be passed on the stack. */
1836 if (! args[i].pass_on_stack && args[i].reg != 0)
1837 continue;
1838
1839 if (GET_CODE (offset) == CONST_INT)
1840 addr = plus_constant (arg_reg, INTVAL (offset));
1841 else
38a448ca 1842 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
51bbfa0c
RS
1843
1844 addr = plus_constant (addr, arg_offset);
38a448ca 1845 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
0c0600d5 1846 MEM_IN_STRUCT_P (args[i].stack)
05e3bdb9 1847 = AGGREGATE_TYPE_P (TREE_TYPE (args[i].tree_value));
51bbfa0c
RS
1848
1849 if (GET_CODE (slot_offset) == CONST_INT)
1850 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1851 else
38a448ca 1852 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
51bbfa0c
RS
1853
1854 addr = plus_constant (addr, arg_offset);
38a448ca 1855 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
51bbfa0c
RS
1856 }
1857 }
1858
1859#ifdef PUSH_ARGS_REVERSED
c795bca9 1860#ifdef PREFERRED_STACK_BOUNDARY
51bbfa0c
RS
1861 /* If we push args individually in reverse order, perform stack alignment
1862 before the first push (the last arg). */
1863 if (argblock == 0)
e5d70561
RK
1864 anti_adjust_stack (GEN_INT (args_size.constant
1865 - original_args_size.constant));
51bbfa0c
RS
1866#endif
1867#endif
1868
1869 /* Don't try to defer pops if preallocating, not even from the first arg,
1870 since ARGBLOCK probably refers to the SP. */
1871 if (argblock)
1872 NO_DEFER_POP;
1873
1874 /* Get the function to call, in the form of RTL. */
1875 if (fndecl)
ef5d30c9
RK
1876 {
1877 /* If this is the first use of the function, see if we need to
1878 make an external definition for it. */
1879 if (! TREE_USED (fndecl))
1880 {
1881 assemble_external (fndecl);
1882 TREE_USED (fndecl) = 1;
1883 }
1884
1885 /* Get a SYMBOL_REF rtx for the function address. */
1886 funexp = XEXP (DECL_RTL (fndecl), 0);
1887 }
51bbfa0c
RS
1888 else
1889 /* Generate an rtx (probably a pseudo-register) for the address. */
1890 {
cc79451b 1891 push_temp_slots ();
e5d70561 1892 funexp = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
cc79451b 1893 pop_temp_slots (); /* FUNEXP can't be BLKmode */
7815214e
RK
1894
1895 /* Check the function is executable. */
7d384cc0 1896 if (current_function_check_memory_usage)
7815214e
RK
1897 emit_library_call (chkr_check_exec_libfunc, 1,
1898 VOIDmode, 1,
1899 funexp, ptr_mode);
51bbfa0c
RS
1900 emit_queue ();
1901 }
1902
1903 /* Figure out the register where the value, if any, will come back. */
1904 valreg = 0;
1905 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
1906 && ! structure_value_addr)
1907 {
1908 if (pcc_struct_value)
1909 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
1910 fndecl);
1911 else
1912 valreg = hard_function_value (TREE_TYPE (exp), fndecl);
1913 }
1914
1915 /* Precompute all register parameters. It isn't safe to compute anything
0f41302f 1916 once we have started filling any specific hard regs. */
20efdf74 1917 precompute_register_parameters (num_actuals, args, &reg_parm_seen);
51bbfa0c
RS
1918
1919#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
e5e809f4 1920
20efdf74
JL
1921 /* Save the fixed argument area if it's part of the caller's frame and
1922 is clobbered by argument setup for this call. */
1923 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
1924 &low_to_save, &high_to_save);
b94301c2 1925#endif
20efdf74 1926
51bbfa0c
RS
1927
1928 /* Now store (and compute if necessary) all non-register parms.
1929 These come before register parms, since they can require block-moves,
1930 which could clobber the registers used for register parms.
1931 Parms which have partial registers are not stored here,
1932 but we do preallocate space here if they want that. */
1933
1934 for (i = 0; i < num_actuals; i++)
1935 if (args[i].reg == 0 || args[i].pass_on_stack)
1936 store_one_arg (&args[i], argblock, may_be_alloca,
c84e2712 1937 args_size.var != 0, reg_parm_stack_space);
51bbfa0c 1938
4ab56118
RK
1939 /* If we have a parm that is passed in registers but not in memory
1940 and whose alignment does not permit a direct copy into registers,
1941 make a group of pseudos that correspond to each register that we
1942 will later fill. */
45d44c98 1943 if (STRICT_ALIGNMENT)
20efdf74 1944 store_unaligned_arguments_into_pseudos (args, num_actuals);
4ab56118 1945
51bbfa0c
RS
1946 /* Now store any partially-in-registers parm.
1947 This is the last place a block-move can happen. */
1948 if (reg_parm_seen)
1949 for (i = 0; i < num_actuals; i++)
1950 if (args[i].partial != 0 && ! args[i].pass_on_stack)
1951 store_one_arg (&args[i], argblock, may_be_alloca,
c84e2712 1952 args_size.var != 0, reg_parm_stack_space);
51bbfa0c
RS
1953
1954#ifndef PUSH_ARGS_REVERSED
c795bca9 1955#ifdef PREFERRED_STACK_BOUNDARY
51bbfa0c
RS
1956 /* If we pushed args in forward order, perform stack alignment
1957 after pushing the last arg. */
1958 if (argblock == 0)
e5d70561
RK
1959 anti_adjust_stack (GEN_INT (args_size.constant
1960 - original_args_size.constant));
51bbfa0c
RS
1961#endif
1962#endif
1963
756e0e12
RS
1964 /* If register arguments require space on the stack and stack space
1965 was not preallocated, allocate stack space here for arguments
1966 passed in registers. */
6e716e89 1967#if ! defined(ACCUMULATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
756e0e12 1968 if (must_preallocate == 0 && reg_parm_stack_space > 0)
e5d70561 1969 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
756e0e12
RS
1970#endif
1971
51bbfa0c
RS
1972 /* Pass the function the address in which to return a structure value. */
1973 if (structure_value_addr && ! structure_value_addr_parm)
1974 {
1975 emit_move_insn (struct_value_rtx,
1976 force_reg (Pmode,
e5d70561
RK
1977 force_operand (structure_value_addr,
1978 NULL_RTX)));
7815214e
RK
1979
1980 /* Mark the memory for the aggregate as write-only. */
7d384cc0 1981 if (current_function_check_memory_usage)
7815214e
RK
1982 emit_library_call (chkr_set_right_libfunc, 1,
1983 VOIDmode, 3,
1984 structure_value_addr, ptr_mode,
1985 GEN_INT (struct_value_size), TYPE_MODE (sizetype),
956d6950
JL
1986 GEN_INT (MEMORY_USE_WO),
1987 TYPE_MODE (integer_type_node));
7815214e 1988
51bbfa0c 1989 if (GET_CODE (struct_value_rtx) == REG)
77cac2f2 1990 use_reg (&call_fusage, struct_value_rtx);
51bbfa0c
RS
1991 }
1992
77cac2f2 1993 funexp = prepare_call_address (funexp, fndecl, &call_fusage, reg_parm_seen);
8b0f9101 1994
51bbfa0c
RS
1995 /* Now do the register loads required for any wholly-register parms or any
1996 parms which are passed both on the stack and in a register. Their
1997 expressions were already evaluated.
1998
1999 Mark all register-parms as living through the call, putting these USE
77cac2f2 2000 insns in the CALL_INSN_FUNCTION_USAGE field. */
51bbfa0c 2001
bb1b857a
GK
2002#ifdef LOAD_ARGS_REVERSED
2003 for (i = num_actuals - 1; i >= 0; i--)
2004#else
51bbfa0c 2005 for (i = 0; i < num_actuals; i++)
bb1b857a 2006#endif
51bbfa0c 2007 {
cacbd532 2008 rtx reg = args[i].reg;
51bbfa0c 2009 int partial = args[i].partial;
cacbd532 2010 int nregs;
51bbfa0c 2011
cacbd532 2012 if (reg)
51bbfa0c 2013 {
6b972c4f
JW
2014 /* Set to non-negative if must move a word at a time, even if just
2015 one word (e.g, partial == 1 && mode == DFmode). Set to -1 if
2016 we just use a normal move insn. This value can be zero if the
2017 argument is a zero size structure with no fields. */
51bbfa0c
RS
2018 nregs = (partial ? partial
2019 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
6b972c4f
JW
2020 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
2021 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
2022 : -1));
51bbfa0c 2023
cacbd532
JW
2024 /* Handle calls that pass values in multiple non-contiguous
2025 locations. The Irix 6 ABI has examples of this. */
2026
2027 if (GET_CODE (reg) == PARALLEL)
aac5cc16
RH
2028 {
2029 emit_group_load (reg, args[i].value,
2030 int_size_in_bytes (TREE_TYPE (args[i].tree_value)),
2031 (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
2032 / BITS_PER_UNIT));
2033 }
cacbd532 2034
51bbfa0c
RS
2035 /* If simple case, just do move. If normal partial, store_one_arg
2036 has already loaded the register for us. In all other cases,
2037 load the register(s) from memory. */
2038
cacbd532 2039 else if (nregs == -1)
51bbfa0c 2040 emit_move_insn (reg, args[i].value);
4ab56118 2041
4ab56118
RK
2042 /* If we have pre-computed the values to put in the registers in
2043 the case of non-aligned structures, copy them in now. */
2044
2045 else if (args[i].n_aligned_regs != 0)
2046 for (j = 0; j < args[i].n_aligned_regs; j++)
38a448ca 2047 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
4ab56118 2048 args[i].aligned_regs[j]);
4ab56118 2049
cacbd532 2050 else if (partial == 0 || args[i].pass_on_stack)
6b972c4f
JW
2051 move_block_to_reg (REGNO (reg),
2052 validize_mem (args[i].value), nregs,
2053 args[i].mode);
0304dfbb 2054
cacbd532
JW
2055 /* Handle calls that pass values in multiple non-contiguous
2056 locations. The Irix 6 ABI has examples of this. */
2057 if (GET_CODE (reg) == PARALLEL)
2058 use_group_regs (&call_fusage, reg);
2059 else if (nregs == -1)
0304dfbb
DE
2060 use_reg (&call_fusage, reg);
2061 else
2062 use_regs (&call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
51bbfa0c
RS
2063 }
2064 }
2065
2066 /* Perform postincrements before actually calling the function. */
2067 emit_queue ();
2068
2069 /* All arguments and registers used for the call must be set up by now! */
2070
51bbfa0c 2071 /* Generate the actual call instruction. */
2c8da025 2072 emit_call_1 (funexp, fndecl, funtype, args_size.constant, struct_value_size,
51bbfa0c 2073 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
77cac2f2 2074 valreg, old_inhibit_defer_pop, call_fusage, is_const);
51bbfa0c
RS
2075
2076 /* If call is cse'able, make appropriate pair of reg-notes around it.
2077 Test valreg so we don't crash; may safely ignore `const'
80a3ad45
JW
2078 if return type is void. Disable for PARALLEL return values, because
2079 we have no way to move such values into a pseudo register. */
2080 if (is_const && valreg != 0 && GET_CODE (valreg) != PARALLEL)
51bbfa0c
RS
2081 {
2082 rtx note = 0;
2083 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2084 rtx insns;
2085
9ae8ffe7
JL
2086 /* Mark the return value as a pointer if needed. */
2087 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2088 {
2089 tree pointed_to = TREE_TYPE (TREE_TYPE (exp));
2090 mark_reg_pointer (temp, TYPE_ALIGN (pointed_to) / BITS_PER_UNIT);
2091 }
2092
51bbfa0c
RS
2093 /* Construct an "equal form" for the value which mentions all the
2094 arguments in order as well as the function name. */
2095#ifdef PUSH_ARGS_REVERSED
2096 for (i = 0; i < num_actuals; i++)
38a448ca 2097 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
51bbfa0c
RS
2098#else
2099 for (i = num_actuals - 1; i >= 0; i--)
38a448ca 2100 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
51bbfa0c 2101#endif
38a448ca 2102 note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
51bbfa0c
RS
2103
2104 insns = get_insns ();
2105 end_sequence ();
2106
2107 emit_libcall_block (insns, temp, valreg, note);
2108
2109 valreg = temp;
2110 }
4f48d56a
RK
2111 else if (is_const)
2112 {
2113 /* Otherwise, just write out the sequence without a note. */
2114 rtx insns = get_insns ();
2115
2116 end_sequence ();
2117 emit_insns (insns);
2118 }
9ae8ffe7
JL
2119 else if (is_malloc)
2120 {
2121 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2122 rtx last, insns;
2123
2124 /* The return value from a malloc-like function is a pointer. */
2125 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2126 mark_reg_pointer (temp, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2127
2128 emit_move_insn (temp, valreg);
2129
2130 /* The return value from a malloc-like function can not alias
2131 anything else. */
2132 last = get_last_insn ();
2133 REG_NOTES (last) =
38a448ca 2134 gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));
9ae8ffe7
JL
2135
2136 /* Write out the sequence. */
2137 insns = get_insns ();
2138 end_sequence ();
2139 emit_insns (insns);
2140 valreg = temp;
2141 }
51bbfa0c
RS
2142
2143 /* For calls to `setjmp', etc., inform flow.c it should complain
2144 if nonvolatile values are live. */
2145
2146 if (returns_twice)
2147 {
2148 emit_note (name, NOTE_INSN_SETJMP);
2149 current_function_calls_setjmp = 1;
2150 }
2151
2152 if (is_longjmp)
2153 current_function_calls_longjmp = 1;
2154
2155 /* Notice functions that cannot return.
2156 If optimizing, insns emitted below will be dead.
2157 If not optimizing, they will exist, which is useful
2158 if the user uses the `return' command in the debugger. */
2159
2160 if (is_volatile || is_longjmp)
2161 emit_barrier ();
2162
51bbfa0c
RS
2163 /* If value type not void, return an rtx for the value. */
2164
e976b8b2
MS
2165 /* If there are cleanups to be called, don't use a hard reg as target.
2166 We need to double check this and see if it matters anymore. */
e9a25f70 2167 if (any_pending_cleanups (1)
51bbfa0c
RS
2168 && target && REG_P (target)
2169 && REGNO (target) < FIRST_PSEUDO_REGISTER)
2170 target = 0;
2171
2172 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
2173 || ignore)
2174 {
2175 target = const0_rtx;
2176 }
2177 else if (structure_value_addr)
2178 {
2179 if (target == 0 || GET_CODE (target) != MEM)
29008b51 2180 {
38a448ca
RH
2181 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2182 memory_address (TYPE_MODE (TREE_TYPE (exp)),
2183 structure_value_addr));
05e3bdb9 2184 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
29008b51 2185 }
51bbfa0c
RS
2186 }
2187 else if (pcc_struct_value)
2188 {
f78b5ca1
JL
2189 /* This is the special C++ case where we need to
2190 know what the true target was. We take care to
2191 never use this value more than once in one expression. */
38a448ca
RH
2192 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2193 copy_to_reg (valreg));
f78b5ca1 2194 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
51bbfa0c 2195 }
cacbd532
JW
2196 /* Handle calls that return values in multiple non-contiguous locations.
2197 The Irix 6 ABI has examples of this. */
2198 else if (GET_CODE (valreg) == PARALLEL)
2199 {
aac5cc16
RH
2200 int bytes = int_size_in_bytes (TREE_TYPE (exp));
2201
cacbd532
JW
2202 if (target == 0)
2203 {
2b4092f2 2204 target = assign_stack_temp (TYPE_MODE (TREE_TYPE (exp)), bytes, 0);
cacbd532
JW
2205 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2206 preserve_temp_slots (target);
2207 }
2208
aac5cc16
RH
2209 emit_group_store (target, valreg, bytes,
2210 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
cacbd532 2211 }
059c3d84
JW
2212 else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2213 && GET_MODE (target) == GET_MODE (valreg))
2214 /* TARGET and VALREG cannot be equal at this point because the latter
2215 would not have REG_FUNCTION_VALUE_P true, while the former would if
2216 it were referring to the same register.
2217
2218 If they refer to the same register, this move will be a no-op, except
2219 when function inlining is being done. */
2220 emit_move_insn (target, valreg);
766b19fb 2221 else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
c36fce9a 2222 target = copy_blkmode_from_reg (target, valreg, TREE_TYPE (exp));
51bbfa0c
RS
2223 else
2224 target = copy_to_reg (valreg);
2225
84b55618 2226#ifdef PROMOTE_FUNCTION_RETURN
5d2ac65e
RK
2227 /* If we promoted this return value, make the proper SUBREG. TARGET
2228 might be const0_rtx here, so be careful. */
2229 if (GET_CODE (target) == REG
766b19fb 2230 && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
5d2ac65e 2231 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
84b55618 2232 {
321e0bba
RK
2233 tree type = TREE_TYPE (exp);
2234 int unsignedp = TREE_UNSIGNED (type);
84b55618 2235
321e0bba
RK
2236 /* If we don't promote as expected, something is wrong. */
2237 if (GET_MODE (target)
2238 != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
5d2ac65e
RK
2239 abort ();
2240
38a448ca 2241 target = gen_rtx_SUBREG (TYPE_MODE (type), target, 0);
84b55618
RK
2242 SUBREG_PROMOTED_VAR_P (target) = 1;
2243 SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
2244 }
2245#endif
2246
2f4aa534
RS
2247 /* If size of args is variable or this was a constructor call for a stack
2248 argument, restore saved stack-pointer value. */
51bbfa0c
RS
2249
2250 if (old_stack_level)
2251 {
e5d70561 2252 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
51bbfa0c 2253 pending_stack_adjust = old_pending_adj;
d64f5a78 2254#ifdef ACCUMULATE_OUTGOING_ARGS
2f4aa534
RS
2255 stack_arg_under_construction = old_stack_arg_under_construction;
2256 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2257 stack_usage_map = initial_stack_usage_map;
d64f5a78 2258#endif
51bbfa0c 2259 }
51bbfa0c
RS
2260#ifdef ACCUMULATE_OUTGOING_ARGS
2261 else
2262 {
2263#ifdef REG_PARM_STACK_SPACE
2264 if (save_area)
20efdf74
JL
2265 restore_fixed_argument_area (save_area, argblock,
2266 high_to_save, low_to_save);
b94301c2 2267#endif
51bbfa0c 2268
51bbfa0c
RS
2269 /* If we saved any argument areas, restore them. */
2270 for (i = 0; i < num_actuals; i++)
2271 if (args[i].save_area)
2272 {
2273 enum machine_mode save_mode = GET_MODE (args[i].save_area);
2274 rtx stack_area
38a448ca
RH
2275 = gen_rtx_MEM (save_mode,
2276 memory_address (save_mode,
2277 XEXP (args[i].stack_slot, 0)));
51bbfa0c
RS
2278
2279 if (save_mode != BLKmode)
2280 emit_move_insn (stack_area, args[i].save_area);
2281 else
2282 emit_block_move (stack_area, validize_mem (args[i].save_area),
e5d70561 2283 GEN_INT (args[i].size.constant),
51bbfa0c
RS
2284 PARM_BOUNDARY / BITS_PER_UNIT);
2285 }
2286
2287 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2288 stack_usage_map = initial_stack_usage_map;
2289 }
2290#endif
2291
59257ff7
RK
2292 /* If this was alloca, record the new stack level for nonlocal gotos.
2293 Check for the handler slots since we might not have a save area
0f41302f 2294 for non-local gotos. */
59257ff7 2295
ba716ac9 2296 if (may_be_alloca && nonlocal_goto_handler_slots != 0)
e5d70561 2297 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
51bbfa0c
RS
2298
2299 pop_temp_slots ();
2300
2301 return target;
2302}
2303\f
322e3e34
RK
2304/* Output a library call to function FUN (a SYMBOL_REF rtx)
2305 (emitting the queue unless NO_QUEUE is nonzero),
2306 for a value of mode OUTMODE,
2307 with NARGS different arguments, passed as alternating rtx values
2308 and machine_modes to convert them to.
2309 The rtx values should have been passed through protect_from_queue already.
2310
2311 NO_QUEUE will be true if and only if the library call is a `const' call
2312 which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent
2313 to the variable is_const in expand_call.
2314
2315 NO_QUEUE must be true for const calls, because if it isn't, then
2316 any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes,
2317 and will be lost if the libcall sequence is optimized away.
2318
2319 NO_QUEUE must be false for non-const calls, because if it isn't, the
2320 call insn will have its CONST_CALL_P bit set, and it will be incorrectly
2321 optimized. For instance, the instruction scheduler may incorrectly
2322 move memory references across the non-const call. */
2323
2324void
4f90e4a0
RK
2325emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
2326 int nargs, ...))
322e3e34 2327{
5148a72b 2328#ifndef ANSI_PROTOTYPES
4f90e4a0
RK
2329 rtx orgfun;
2330 int no_queue;
2331 enum machine_mode outmode;
2332 int nargs;
2333#endif
322e3e34
RK
2334 va_list p;
2335 /* Total size in bytes of all the stack-parms scanned so far. */
2336 struct args_size args_size;
2337 /* Size of arguments before any adjustments (such as rounding). */
2338 struct args_size original_args_size;
2339 register int argnum;
322e3e34 2340 rtx fun;
322e3e34
RK
2341 int inc;
2342 int count;
2343 rtx argblock = 0;
2344 CUMULATIVE_ARGS args_so_far;
2345 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
f046b3cc 2346 struct args_size offset; struct args_size size; rtx save_area; };
322e3e34
RK
2347 struct arg *argvec;
2348 int old_inhibit_defer_pop = inhibit_defer_pop;
77cac2f2 2349 rtx call_fusage = 0;
e5e809f4 2350 int reg_parm_stack_space = 0;
f046b3cc
JL
2351#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2352 /* Define the boundary of the register parm stack space that needs to be
2353 save, if any. */
2354 int low_to_save = -1, high_to_save;
2355 rtx save_area = 0; /* Place that it is saved */
2356#endif
2357
2358#ifdef ACCUMULATE_OUTGOING_ARGS
2359 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2360 char *initial_stack_usage_map = stack_usage_map;
2361 int needed;
2362#endif
2363
2364#ifdef REG_PARM_STACK_SPACE
69d4ca36 2365 /* Size of the stack reserved for parameter registers. */
f046b3cc
JL
2366#ifdef MAYBE_REG_PARM_STACK_SPACE
2367 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2368#else
2369 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
2370#endif
2371#endif
322e3e34 2372
4f90e4a0
RK
2373 VA_START (p, nargs);
2374
5148a72b 2375#ifndef ANSI_PROTOTYPES
4f90e4a0 2376 orgfun = va_arg (p, rtx);
322e3e34
RK
2377 no_queue = va_arg (p, int);
2378 outmode = va_arg (p, enum machine_mode);
2379 nargs = va_arg (p, int);
4f90e4a0
RK
2380#endif
2381
2382 fun = orgfun;
322e3e34
RK
2383
2384 /* Copy all the libcall-arguments out of the varargs data
2385 and into a vector ARGVEC.
2386
2387 Compute how to pass each argument. We only support a very small subset
2388 of the full argument passing conventions to limit complexity here since
2389 library functions shouldn't have many args. */
2390
2391 argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
f046b3cc
JL
2392 bzero ((char *) argvec, nargs * sizeof (struct arg));
2393
322e3e34 2394
eecb6f50 2395 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
322e3e34
RK
2396
2397 args_size.constant = 0;
2398 args_size.var = 0;
2399
888aa7a9
RS
2400 push_temp_slots ();
2401
322e3e34
RK
2402 for (count = 0; count < nargs; count++)
2403 {
2404 rtx val = va_arg (p, rtx);
2405 enum machine_mode mode = va_arg (p, enum machine_mode);
2406
2407 /* We cannot convert the arg value to the mode the library wants here;
2408 must do it earlier where we know the signedness of the arg. */
2409 if (mode == BLKmode
2410 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2411 abort ();
2412
2413 /* On some machines, there's no way to pass a float to a library fcn.
2414 Pass it as a double instead. */
2415#ifdef LIBGCC_NEEDS_DOUBLE
2416 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
7373d92d 2417 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
322e3e34
RK
2418#endif
2419
2420 /* There's no need to call protect_from_queue, because
2421 either emit_move_insn or emit_push_insn will do that. */
2422
2423 /* Make sure it is a reasonable operand for a move or push insn. */
2424 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2425 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2426 val = force_operand (val, NULL_RTX);
2427
322e3e34
RK
2428#ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2429 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
888aa7a9 2430 {
a44492f0
RK
2431 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2432 be viewed as just an efficiency improvement. */
888aa7a9
RS
2433 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2434 emit_move_insn (slot, val);
8301b6e2 2435 val = force_operand (XEXP (slot, 0), NULL_RTX);
a44492f0 2436 mode = Pmode;
888aa7a9 2437 }
322e3e34
RK
2438#endif
2439
888aa7a9
RS
2440 argvec[count].value = val;
2441 argvec[count].mode = mode;
2442
322e3e34 2443 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
cacbd532 2444 if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
322e3e34
RK
2445 abort ();
2446#ifdef FUNCTION_ARG_PARTIAL_NREGS
2447 argvec[count].partial
2448 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2449#else
2450 argvec[count].partial = 0;
2451#endif
2452
2453 locate_and_pad_parm (mode, NULL_TREE,
2454 argvec[count].reg && argvec[count].partial == 0,
2455 NULL_TREE, &args_size, &argvec[count].offset,
2456 &argvec[count].size);
2457
2458 if (argvec[count].size.var)
2459 abort ();
2460
e5e809f4 2461 if (reg_parm_stack_space == 0 && argvec[count].partial)
322e3e34 2462 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
322e3e34
RK
2463
2464 if (argvec[count].reg == 0 || argvec[count].partial != 0
e5e809f4 2465 || reg_parm_stack_space > 0)
322e3e34
RK
2466 args_size.constant += argvec[count].size.constant;
2467
0f41302f 2468 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
322e3e34
RK
2469 }
2470 va_end (p);
2471
f046b3cc
JL
2472#ifdef FINAL_REG_PARM_STACK_SPACE
2473 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2474 args_size.var);
2475#endif
2476
322e3e34
RK
2477 /* If this machine requires an external definition for library
2478 functions, write one out. */
2479 assemble_external_libcall (fun);
2480
2481 original_args_size = args_size;
c795bca9 2482#ifdef PREFERRED_STACK_BOUNDARY
322e3e34
RK
2483 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2484 / STACK_BYTES) * STACK_BYTES);
2485#endif
2486
322e3e34 2487 args_size.constant = MAX (args_size.constant,
f046b3cc 2488 reg_parm_stack_space);
e5e809f4 2489
322e3e34 2490#ifndef OUTGOING_REG_PARM_STACK_SPACE
f046b3cc 2491 args_size.constant -= reg_parm_stack_space;
322e3e34
RK
2492#endif
2493
322e3e34
RK
2494 if (args_size.constant > current_function_outgoing_args_size)
2495 current_function_outgoing_args_size = args_size.constant;
26a258fe
PB
2496
2497#ifdef ACCUMULATE_OUTGOING_ARGS
f046b3cc
JL
2498 /* Since the stack pointer will never be pushed, it is possible for
2499 the evaluation of a parm to clobber something we have already
2500 written to the stack. Since most function calls on RISC machines
2501 do not use the stack, this is uncommon, but must work correctly.
2502
2503 Therefore, we save any area of the stack that was already written
2504 and that we are using. Here we set up to do this by making a new
2505 stack usage map from the old one.
2506
2507 Another approach might be to try to reorder the argument
2508 evaluations to avoid this conflicting stack usage. */
2509
2510 needed = args_size.constant;
e5e809f4
JL
2511
2512#ifndef OUTGOING_REG_PARM_STACK_SPACE
f046b3cc
JL
2513 /* Since we will be writing into the entire argument area, the
2514 map must be allocated for its entire size, not just the part that
2515 is the responsibility of the caller. */
2516 needed += reg_parm_stack_space;
2517#endif
2518
2519#ifdef ARGS_GROW_DOWNWARD
2520 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2521 needed + 1);
2522#else
2523 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2524 needed);
322e3e34 2525#endif
f046b3cc
JL
2526 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
2527
2528 if (initial_highest_arg_in_use)
2529 bcopy (initial_stack_usage_map, stack_usage_map,
2530 initial_highest_arg_in_use);
2531
2532 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2533 bzero (&stack_usage_map[initial_highest_arg_in_use],
2534 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
2535 needed = 0;
322e3e34 2536
f046b3cc
JL
2537 /* The address of the outgoing argument list must not be copied to a
2538 register here, because argblock would be left pointing to the
2539 wrong place after the call to allocate_dynamic_stack_space below.
2540 */
2541
2542 argblock = virtual_outgoing_args_rtx;
2543#else /* not ACCUMULATE_OUTGOING_ARGS */
322e3e34
RK
2544#ifndef PUSH_ROUNDING
2545 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2546#endif
f046b3cc 2547#endif
322e3e34
RK
2548
2549#ifdef PUSH_ARGS_REVERSED
c795bca9 2550#ifdef PREFERRED_STACK_BOUNDARY
322e3e34
RK
2551 /* If we push args individually in reverse order, perform stack alignment
2552 before the first push (the last arg). */
2553 if (argblock == 0)
2554 anti_adjust_stack (GEN_INT (args_size.constant
2555 - original_args_size.constant));
2556#endif
2557#endif
2558
2559#ifdef PUSH_ARGS_REVERSED
2560 inc = -1;
2561 argnum = nargs - 1;
2562#else
2563 inc = 1;
2564 argnum = 0;
2565#endif
2566
f046b3cc
JL
2567#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2568 /* The argument list is the property of the called routine and it
2569 may clobber it. If the fixed area has been used for previous
2570 parameters, we must save and restore it.
2571
2572 Here we compute the boundary of the that needs to be saved, if any. */
2573
2574#ifdef ARGS_GROW_DOWNWARD
2575 for (count = 0; count < reg_parm_stack_space + 1; count++)
2576#else
2577 for (count = 0; count < reg_parm_stack_space; count++)
2578#endif
2579 {
2580 if (count >= highest_outgoing_arg_in_use
2581 || stack_usage_map[count] == 0)
2582 continue;
2583
2584 if (low_to_save == -1)
2585 low_to_save = count;
2586
2587 high_to_save = count;
2588 }
2589
2590 if (low_to_save >= 0)
2591 {
2592 int num_to_save = high_to_save - low_to_save + 1;
2593 enum machine_mode save_mode
2594 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
2595 rtx stack_area;
2596
2597 /* If we don't have the required alignment, must do this in BLKmode. */
2598 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
2599 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
2600 save_mode = BLKmode;
2601
ceb83206 2602#ifdef ARGS_GROW_DOWNWARD
38a448ca
RH
2603 stack_area = gen_rtx_MEM (save_mode,
2604 memory_address (save_mode,
38a448ca 2605 plus_constant (argblock,
ceb83206 2606 - high_to_save)));
f046b3cc 2607#else
ceb83206
JL
2608 stack_area = gen_rtx_MEM (save_mode,
2609 memory_address (save_mode,
38a448ca 2610 plus_constant (argblock,
ceb83206 2611 low_to_save)));
f046b3cc 2612#endif
f046b3cc
JL
2613 if (save_mode == BLKmode)
2614 {
2615 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
2616 MEM_IN_STRUCT_P (save_area) = 0;
2617 emit_block_move (validize_mem (save_area), stack_area,
2618 GEN_INT (num_to_save),
2619 PARM_BOUNDARY / BITS_PER_UNIT);
2620 }
2621 else
2622 {
2623 save_area = gen_reg_rtx (save_mode);
2624 emit_move_insn (save_area, stack_area);
2625 }
2626 }
2627#endif
2628
322e3e34
RK
2629 /* Push the args that need to be pushed. */
2630
5e26979c
JL
2631 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
2632 are to be pushed. */
322e3e34
RK
2633 for (count = 0; count < nargs; count++, argnum += inc)
2634 {
2635 register enum machine_mode mode = argvec[argnum].mode;
2636 register rtx val = argvec[argnum].value;
2637 rtx reg = argvec[argnum].reg;
2638 int partial = argvec[argnum].partial;
69d4ca36 2639#ifdef ACCUMULATE_OUTGOING_ARGS
f046b3cc 2640 int lower_bound, upper_bound, i;
69d4ca36 2641#endif
322e3e34
RK
2642
2643 if (! (reg != 0 && partial == 0))
f046b3cc
JL
2644 {
2645#ifdef ACCUMULATE_OUTGOING_ARGS
2646 /* If this is being stored into a pre-allocated, fixed-size, stack
2647 area, save any previous data at that location. */
2648
2649#ifdef ARGS_GROW_DOWNWARD
2650 /* stack_slot is negative, but we want to index stack_usage_map
2651 with positive values. */
5e26979c
JL
2652 upper_bound = -argvec[argnum].offset.constant + 1;
2653 lower_bound = upper_bound - argvec[argnum].size.constant;
f046b3cc 2654#else
5e26979c
JL
2655 lower_bound = argvec[argnum].offset.constant;
2656 upper_bound = lower_bound + argvec[argnum].size.constant;
f046b3cc
JL
2657#endif
2658
2659 for (i = lower_bound; i < upper_bound; i++)
2660 if (stack_usage_map[i]
f046b3cc
JL
2661 /* Don't store things in the fixed argument area at this point;
2662 it has already been saved. */
e5e809f4 2663 && i > reg_parm_stack_space)
f046b3cc
JL
2664 break;
2665
2666 if (i != upper_bound)
2667 {
e5e809f4 2668 /* We need to make a save area. See what mode we can make it. */
f046b3cc 2669 enum machine_mode save_mode
5e26979c 2670 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
f046b3cc
JL
2671 MODE_INT, 1);
2672 rtx stack_area
38a448ca
RH
2673 = gen_rtx_MEM (save_mode,
2674 memory_address (save_mode,
2675 plus_constant (argblock, argvec[argnum].offset.constant)));
5e26979c
JL
2676 argvec[argnum].save_area = gen_reg_rtx (save_mode);
2677 emit_move_insn (argvec[argnum].save_area, stack_area);
f046b3cc
JL
2678 }
2679#endif
2680 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
e5e809f4
JL
2681 argblock, GEN_INT (argvec[argnum].offset.constant),
2682 reg_parm_stack_space);
f046b3cc
JL
2683
2684#ifdef ACCUMULATE_OUTGOING_ARGS
2685 /* Now mark the segment we just used. */
2686 for (i = lower_bound; i < upper_bound; i++)
2687 stack_usage_map[i] = 1;
2688#endif
2689
2690 NO_DEFER_POP;
2691 }
322e3e34
RK
2692 }
2693
2694#ifndef PUSH_ARGS_REVERSED
c795bca9 2695#ifdef PREFERRED_STACK_BOUNDARY
322e3e34
RK
2696 /* If we pushed args in forward order, perform stack alignment
2697 after pushing the last arg. */
2698 if (argblock == 0)
2699 anti_adjust_stack (GEN_INT (args_size.constant
2700 - original_args_size.constant));
2701#endif
2702#endif
2703
2704#ifdef PUSH_ARGS_REVERSED
2705 argnum = nargs - 1;
2706#else
2707 argnum = 0;
2708#endif
2709
77cac2f2 2710 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
8b0f9101 2711
322e3e34
RK
2712 /* Now load any reg parms into their regs. */
2713
5e26979c
JL
2714 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
2715 are to be pushed. */
322e3e34
RK
2716 for (count = 0; count < nargs; count++, argnum += inc)
2717 {
322e3e34
RK
2718 register rtx val = argvec[argnum].value;
2719 rtx reg = argvec[argnum].reg;
2720 int partial = argvec[argnum].partial;
2721
2722 if (reg != 0 && partial == 0)
2723 emit_move_insn (reg, val);
2724 NO_DEFER_POP;
2725 }
2726
2727 /* For version 1.37, try deleting this entirely. */
2728 if (! no_queue)
2729 emit_queue ();
2730
2731 /* Any regs containing parms remain in use through the call. */
322e3e34
RK
2732 for (count = 0; count < nargs; count++)
2733 if (argvec[count].reg != 0)
77cac2f2 2734 use_reg (&call_fusage, argvec[count].reg);
322e3e34 2735
322e3e34
RK
2736 /* Don't allow popping to be deferred, since then
2737 cse'ing of library calls could delete a call and leave the pop. */
2738 NO_DEFER_POP;
2739
2740 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
2741 will set inhibit_defer_pop to that value. */
2742
334c4f0f
RK
2743 /* The return type is needed to decide how many bytes the function pops.
2744 Signedness plays no role in that, so for simplicity, we pretend it's
2745 always signed. We also assume that the list of arguments passed has
2746 no impact, so we pretend it is unknown. */
2747
2c8da025
RK
2748 emit_call_1 (fun,
2749 get_identifier (XSTR (orgfun, 0)),
b3776927
RK
2750 build_function_type (outmode == VOIDmode ? void_type_node
2751 : type_for_mode (outmode, 0), NULL_TREE),
334c4f0f 2752 args_size.constant, 0,
322e3e34
RK
2753 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2754 outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
77cac2f2 2755 old_inhibit_defer_pop + 1, call_fusage, no_queue);
322e3e34 2756
888aa7a9
RS
2757 pop_temp_slots ();
2758
322e3e34
RK
2759 /* Now restore inhibit_defer_pop to its actual original value. */
2760 OK_DEFER_POP;
f046b3cc
JL
2761
2762#ifdef ACCUMULATE_OUTGOING_ARGS
2763#ifdef REG_PARM_STACK_SPACE
e9a25f70
JL
2764 if (save_area)
2765 {
2766 enum machine_mode save_mode = GET_MODE (save_area);
ceb83206 2767#ifdef ARGS_GROW_DOWNWARD
e9a25f70 2768 rtx stack_area
38a448ca
RH
2769 = gen_rtx_MEM (save_mode,
2770 memory_address (save_mode,
ceb83206
JL
2771 plus_constant (argblock,
2772 - high_to_save)));
f046b3cc 2773#else
ceb83206
JL
2774 rtx stack_area
2775 = gen_rtx_MEM (save_mode,
2776 memory_address (save_mode,
2777 plus_constant (argblock, low_to_save)));
f046b3cc 2778#endif
f046b3cc 2779
e9a25f70
JL
2780 if (save_mode != BLKmode)
2781 emit_move_insn (stack_area, save_area);
2782 else
2783 emit_block_move (stack_area, validize_mem (save_area),
2784 GEN_INT (high_to_save - low_to_save + 1),
2785 PARM_BOUNDARY / BITS_PER_UNIT);
2786 }
f046b3cc
JL
2787#endif
2788
2789 /* If we saved any argument areas, restore them. */
2790 for (count = 0; count < nargs; count++)
2791 if (argvec[count].save_area)
2792 {
2793 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
2794 rtx stack_area
38a448ca
RH
2795 = gen_rtx_MEM (save_mode,
2796 memory_address (save_mode,
2797 plus_constant (argblock, argvec[count].offset.constant)));
f046b3cc
JL
2798
2799 emit_move_insn (stack_area, argvec[count].save_area);
2800 }
2801
2802 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2803 stack_usage_map = initial_stack_usage_map;
2804#endif
322e3e34
RK
2805}
2806\f
2807/* Like emit_library_call except that an extra argument, VALUE,
2808 comes second and says where to store the result.
fac0ad80
RS
2809 (If VALUE is zero, this function chooses a convenient way
2810 to return the value.
322e3e34 2811
fac0ad80
RS
2812 This function returns an rtx for where the value is to be found.
2813 If VALUE is nonzero, VALUE is returned. */
2814
2815rtx
4f90e4a0
RK
2816emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
2817 enum machine_mode outmode, int nargs, ...))
322e3e34 2818{
5148a72b 2819#ifndef ANSI_PROTOTYPES
4f90e4a0
RK
2820 rtx orgfun;
2821 rtx value;
2822 int no_queue;
2823 enum machine_mode outmode;
2824 int nargs;
2825#endif
322e3e34
RK
2826 va_list p;
2827 /* Total size in bytes of all the stack-parms scanned so far. */
2828 struct args_size args_size;
2829 /* Size of arguments before any adjustments (such as rounding). */
2830 struct args_size original_args_size;
2831 register int argnum;
322e3e34 2832 rtx fun;
322e3e34
RK
2833 int inc;
2834 int count;
2835 rtx argblock = 0;
2836 CUMULATIVE_ARGS args_so_far;
2837 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
f046b3cc 2838 struct args_size offset; struct args_size size; rtx save_area; };
322e3e34
RK
2839 struct arg *argvec;
2840 int old_inhibit_defer_pop = inhibit_defer_pop;
77cac2f2 2841 rtx call_fusage = 0;
322e3e34 2842 rtx mem_value = 0;
fac0ad80 2843 int pcc_struct_value = 0;
4f389214 2844 int struct_value_size = 0;
d61bee95 2845 int is_const;
e5e809f4 2846 int reg_parm_stack_space = 0;
69d4ca36 2847#ifdef ACCUMULATE_OUTGOING_ARGS
f046b3cc 2848 int needed;
69d4ca36 2849#endif
f046b3cc
JL
2850
2851#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2852 /* Define the boundary of the register parm stack space that needs to be
2853 save, if any. */
2854 int low_to_save = -1, high_to_save;
2855 rtx save_area = 0; /* Place that it is saved */
2856#endif
2857
2858#ifdef ACCUMULATE_OUTGOING_ARGS
69d4ca36 2859 /* Size of the stack reserved for parameter registers. */
f046b3cc
JL
2860 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2861 char *initial_stack_usage_map = stack_usage_map;
2862#endif
2863
2864#ifdef REG_PARM_STACK_SPACE
2865#ifdef MAYBE_REG_PARM_STACK_SPACE
2866 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2867#else
2868 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
2869#endif
2870#endif
322e3e34 2871
4f90e4a0
RK
2872 VA_START (p, nargs);
2873
5148a72b 2874#ifndef ANSI_PROTOTYPES
4f90e4a0 2875 orgfun = va_arg (p, rtx);
322e3e34
RK
2876 value = va_arg (p, rtx);
2877 no_queue = va_arg (p, int);
2878 outmode = va_arg (p, enum machine_mode);
2879 nargs = va_arg (p, int);
4f90e4a0
RK
2880#endif
2881
d61bee95 2882 is_const = no_queue;
4f90e4a0 2883 fun = orgfun;
322e3e34
RK
2884
2885 /* If this kind of value comes back in memory,
2886 decide where in memory it should come back. */
fac0ad80 2887 if (aggregate_value_p (type_for_mode (outmode, 0)))
322e3e34 2888 {
fac0ad80
RS
2889#ifdef PCC_STATIC_STRUCT_RETURN
2890 rtx pointer_reg
2891 = hard_function_value (build_pointer_type (type_for_mode (outmode, 0)),
2892 0);
38a448ca 2893 mem_value = gen_rtx_MEM (outmode, pointer_reg);
fac0ad80
RS
2894 pcc_struct_value = 1;
2895 if (value == 0)
2896 value = gen_reg_rtx (outmode);
2897#else /* not PCC_STATIC_STRUCT_RETURN */
4f389214 2898 struct_value_size = GET_MODE_SIZE (outmode);
fac0ad80 2899 if (value != 0 && GET_CODE (value) == MEM)
322e3e34
RK
2900 mem_value = value;
2901 else
2902 mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
fac0ad80 2903#endif
779c643a
JW
2904
2905 /* This call returns a big structure. */
2906 is_const = 0;
322e3e34
RK
2907 }
2908
2909 /* ??? Unfinished: must pass the memory address as an argument. */
2910
2911 /* Copy all the libcall-arguments out of the varargs data
2912 and into a vector ARGVEC.
2913
2914 Compute how to pass each argument. We only support a very small subset
2915 of the full argument passing conventions to limit complexity here since
2916 library functions shouldn't have many args. */
2917
2918 argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
d3c4e2ab 2919 bzero ((char *) argvec, (nargs + 1) * sizeof (struct arg));
322e3e34 2920
eecb6f50 2921 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
322e3e34
RK
2922
2923 args_size.constant = 0;
2924 args_size.var = 0;
2925
2926 count = 0;
2927
888aa7a9
RS
2928 push_temp_slots ();
2929
322e3e34
RK
2930 /* If there's a structure value address to be passed,
2931 either pass it in the special place, or pass it as an extra argument. */
fac0ad80 2932 if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
322e3e34
RK
2933 {
2934 rtx addr = XEXP (mem_value, 0);
fac0ad80 2935 nargs++;
322e3e34 2936
fac0ad80
RS
2937 /* Make sure it is a reasonable operand for a move or push insn. */
2938 if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
2939 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
2940 addr = force_operand (addr, NULL_RTX);
322e3e34 2941
fac0ad80 2942 argvec[count].value = addr;
4fc3dcd5 2943 argvec[count].mode = Pmode;
fac0ad80 2944 argvec[count].partial = 0;
322e3e34 2945
4fc3dcd5 2946 argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
322e3e34 2947#ifdef FUNCTION_ARG_PARTIAL_NREGS
4fc3dcd5 2948 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
fac0ad80 2949 abort ();
322e3e34
RK
2950#endif
2951
4fc3dcd5 2952 locate_and_pad_parm (Pmode, NULL_TREE,
fac0ad80
RS
2953 argvec[count].reg && argvec[count].partial == 0,
2954 NULL_TREE, &args_size, &argvec[count].offset,
2955 &argvec[count].size);
322e3e34
RK
2956
2957
fac0ad80 2958 if (argvec[count].reg == 0 || argvec[count].partial != 0
e5e809f4 2959 || reg_parm_stack_space > 0)
fac0ad80 2960 args_size.constant += argvec[count].size.constant;
322e3e34 2961
0f41302f 2962 FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
fac0ad80
RS
2963
2964 count++;
322e3e34
RK
2965 }
2966
2967 for (; count < nargs; count++)
2968 {
2969 rtx val = va_arg (p, rtx);
2970 enum machine_mode mode = va_arg (p, enum machine_mode);
2971
2972 /* We cannot convert the arg value to the mode the library wants here;
2973 must do it earlier where we know the signedness of the arg. */
2974 if (mode == BLKmode
2975 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2976 abort ();
2977
2978 /* On some machines, there's no way to pass a float to a library fcn.
2979 Pass it as a double instead. */
2980#ifdef LIBGCC_NEEDS_DOUBLE
2981 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
7373d92d 2982 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
322e3e34
RK
2983#endif
2984
2985 /* There's no need to call protect_from_queue, because
2986 either emit_move_insn or emit_push_insn will do that. */
2987
2988 /* Make sure it is a reasonable operand for a move or push insn. */
2989 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2990 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2991 val = force_operand (val, NULL_RTX);
2992
322e3e34
RK
2993#ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2994 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
888aa7a9 2995 {
a44492f0
RK
2996 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2997 be viewed as just an efficiency improvement. */
888aa7a9
RS
2998 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2999 emit_move_insn (slot, val);
3000 val = XEXP (slot, 0);
3001 mode = Pmode;
3002 }
322e3e34
RK
3003#endif
3004
888aa7a9
RS
3005 argvec[count].value = val;
3006 argvec[count].mode = mode;
3007
322e3e34 3008 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
cacbd532 3009 if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
322e3e34
RK
3010 abort ();
3011#ifdef FUNCTION_ARG_PARTIAL_NREGS
3012 argvec[count].partial
3013 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3014#else
3015 argvec[count].partial = 0;
3016#endif
3017
3018 locate_and_pad_parm (mode, NULL_TREE,
3019 argvec[count].reg && argvec[count].partial == 0,
3020 NULL_TREE, &args_size, &argvec[count].offset,
3021 &argvec[count].size);
3022
3023 if (argvec[count].size.var)
3024 abort ();
3025
e5e809f4 3026 if (reg_parm_stack_space == 0 && argvec[count].partial)
322e3e34 3027 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
322e3e34
RK
3028
3029 if (argvec[count].reg == 0 || argvec[count].partial != 0
e5e809f4 3030 || reg_parm_stack_space > 0)
322e3e34
RK
3031 args_size.constant += argvec[count].size.constant;
3032
0f41302f 3033 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
322e3e34
RK
3034 }
3035 va_end (p);
3036
f046b3cc
JL
3037#ifdef FINAL_REG_PARM_STACK_SPACE
3038 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
3039 args_size.var);
3040#endif
322e3e34
RK
3041 /* If this machine requires an external definition for library
3042 functions, write one out. */
3043 assemble_external_libcall (fun);
3044
3045 original_args_size = args_size;
c795bca9 3046#ifdef PREFERRED_STACK_BOUNDARY
322e3e34
RK
3047 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
3048 / STACK_BYTES) * STACK_BYTES);
3049#endif
3050
322e3e34 3051 args_size.constant = MAX (args_size.constant,
f046b3cc 3052 reg_parm_stack_space);
e5e809f4 3053
322e3e34 3054#ifndef OUTGOING_REG_PARM_STACK_SPACE
fc990856 3055 args_size.constant -= reg_parm_stack_space;
322e3e34
RK
3056#endif
3057
322e3e34
RK
3058 if (args_size.constant > current_function_outgoing_args_size)
3059 current_function_outgoing_args_size = args_size.constant;
26a258fe
PB
3060
3061#ifdef ACCUMULATE_OUTGOING_ARGS
f046b3cc
JL
3062 /* Since the stack pointer will never be pushed, it is possible for
3063 the evaluation of a parm to clobber something we have already
3064 written to the stack. Since most function calls on RISC machines
3065 do not use the stack, this is uncommon, but must work correctly.
3066
3067 Therefore, we save any area of the stack that was already written
3068 and that we are using. Here we set up to do this by making a new
3069 stack usage map from the old one.
3070
3071 Another approach might be to try to reorder the argument
3072 evaluations to avoid this conflicting stack usage. */
3073
3074 needed = args_size.constant;
e5e809f4
JL
3075
3076#ifndef OUTGOING_REG_PARM_STACK_SPACE
f046b3cc
JL
3077 /* Since we will be writing into the entire argument area, the
3078 map must be allocated for its entire size, not just the part that
3079 is the responsibility of the caller. */
3080 needed += reg_parm_stack_space;
3081#endif
3082
3083#ifdef ARGS_GROW_DOWNWARD
3084 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3085 needed + 1);
3086#else
3087 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3088 needed);
322e3e34 3089#endif
f046b3cc
JL
3090 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3091
3092 if (initial_highest_arg_in_use)
3093 bcopy (initial_stack_usage_map, stack_usage_map,
3094 initial_highest_arg_in_use);
3095
3096 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3097 bzero (&stack_usage_map[initial_highest_arg_in_use],
3098 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3099 needed = 0;
322e3e34 3100
f046b3cc
JL
3101 /* The address of the outgoing argument list must not be copied to a
3102 register here, because argblock would be left pointing to the
3103 wrong place after the call to allocate_dynamic_stack_space below.
3104 */
3105
3106 argblock = virtual_outgoing_args_rtx;
3107#else /* not ACCUMULATE_OUTGOING_ARGS */
322e3e34
RK
3108#ifndef PUSH_ROUNDING
3109 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3110#endif
f046b3cc 3111#endif
322e3e34
RK
3112
3113#ifdef PUSH_ARGS_REVERSED
c795bca9 3114#ifdef PREFERRED_STACK_BOUNDARY
322e3e34
RK
3115 /* If we push args individually in reverse order, perform stack alignment
3116 before the first push (the last arg). */
3117 if (argblock == 0)
3118 anti_adjust_stack (GEN_INT (args_size.constant
3119 - original_args_size.constant));
3120#endif
3121#endif
3122
3123#ifdef PUSH_ARGS_REVERSED
3124 inc = -1;
3125 argnum = nargs - 1;
3126#else
3127 inc = 1;
3128 argnum = 0;
3129#endif
3130
f046b3cc
JL
3131#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3132 /* The argument list is the property of the called routine and it
3133 may clobber it. If the fixed area has been used for previous
3134 parameters, we must save and restore it.
3135
3136 Here we compute the boundary of the that needs to be saved, if any. */
3137
3138#ifdef ARGS_GROW_DOWNWARD
3139 for (count = 0; count < reg_parm_stack_space + 1; count++)
3140#else
3141 for (count = 0; count < reg_parm_stack_space; count++)
3142#endif
3143 {
3144 if (count >= highest_outgoing_arg_in_use
3145 || stack_usage_map[count] == 0)
3146 continue;
3147
3148 if (low_to_save == -1)
3149 low_to_save = count;
3150
3151 high_to_save = count;
3152 }
3153
3154 if (low_to_save >= 0)
3155 {
3156 int num_to_save = high_to_save - low_to_save + 1;
3157 enum machine_mode save_mode
3158 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
3159 rtx stack_area;
3160
3161 /* If we don't have the required alignment, must do this in BLKmode. */
3162 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
3163 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
3164 save_mode = BLKmode;
3165
ceb83206 3166#ifdef ARGS_GROW_DOWNWARD
38a448ca
RH
3167 stack_area = gen_rtx_MEM (save_mode,
3168 memory_address (save_mode,
38a448ca 3169 plus_constant (argblock,
ceb83206 3170 - high_to_save)));
f046b3cc 3171#else
ceb83206
JL
3172 stack_area = gen_rtx_MEM (save_mode,
3173 memory_address (save_mode,
38a448ca 3174 plus_constant (argblock,
ceb83206 3175 low_to_save)));
f046b3cc 3176#endif
f046b3cc
JL
3177 if (save_mode == BLKmode)
3178 {
3179 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
3180 MEM_IN_STRUCT_P (save_area) = 0;
3181 emit_block_move (validize_mem (save_area), stack_area,
3182 GEN_INT (num_to_save),
3183 PARM_BOUNDARY / BITS_PER_UNIT);
3184 }
3185 else
3186 {
3187 save_area = gen_reg_rtx (save_mode);
3188 emit_move_insn (save_area, stack_area);
3189 }
3190 }
3191#endif
3192
322e3e34
RK
3193 /* Push the args that need to be pushed. */
3194
5e26979c
JL
3195 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3196 are to be pushed. */
322e3e34
RK
3197 for (count = 0; count < nargs; count++, argnum += inc)
3198 {
3199 register enum machine_mode mode = argvec[argnum].mode;
3200 register rtx val = argvec[argnum].value;
3201 rtx reg = argvec[argnum].reg;
3202 int partial = argvec[argnum].partial;
69d4ca36 3203#ifdef ACCUMULATE_OUTGOING_ARGS
f046b3cc 3204 int lower_bound, upper_bound, i;
69d4ca36 3205#endif
322e3e34
RK
3206
3207 if (! (reg != 0 && partial == 0))
f046b3cc
JL
3208 {
3209#ifdef ACCUMULATE_OUTGOING_ARGS
3210 /* If this is being stored into a pre-allocated, fixed-size, stack
3211 area, save any previous data at that location. */
3212
3213#ifdef ARGS_GROW_DOWNWARD
3214 /* stack_slot is negative, but we want to index stack_usage_map
3215 with positive values. */
5e26979c
JL
3216 upper_bound = -argvec[argnum].offset.constant + 1;
3217 lower_bound = upper_bound - argvec[argnum].size.constant;
f046b3cc 3218#else
5e26979c
JL
3219 lower_bound = argvec[argnum].offset.constant;
3220 upper_bound = lower_bound + argvec[argnum].size.constant;
f046b3cc
JL
3221#endif
3222
3223 for (i = lower_bound; i < upper_bound; i++)
3224 if (stack_usage_map[i]
f046b3cc
JL
3225 /* Don't store things in the fixed argument area at this point;
3226 it has already been saved. */
e5e809f4 3227 && i > reg_parm_stack_space)
f046b3cc
JL
3228 break;
3229
3230 if (i != upper_bound)
3231 {
e5e809f4 3232 /* We need to make a save area. See what mode we can make it. */
f046b3cc 3233 enum machine_mode save_mode
5e26979c 3234 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
f046b3cc
JL
3235 MODE_INT, 1);
3236 rtx stack_area
38a448ca
RH
3237 = gen_rtx_MEM (save_mode,
3238 memory_address (save_mode,
3239 plus_constant (argblock,
3240 argvec[argnum].offset.constant)));
5e26979c
JL
3241 argvec[argnum].save_area = gen_reg_rtx (save_mode);
3242 emit_move_insn (argvec[argnum].save_area, stack_area);
f046b3cc
JL
3243 }
3244#endif
3245 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
e5e809f4
JL
3246 argblock, GEN_INT (argvec[argnum].offset.constant),
3247 reg_parm_stack_space);
f046b3cc
JL
3248
3249#ifdef ACCUMULATE_OUTGOING_ARGS
3250 /* Now mark the segment we just used. */
3251 for (i = lower_bound; i < upper_bound; i++)
3252 stack_usage_map[i] = 1;
3253#endif
3254
3255 NO_DEFER_POP;
3256 }
322e3e34
RK
3257 }
3258
3259#ifndef PUSH_ARGS_REVERSED
c795bca9 3260#ifdef PREFERRED_STACK_BOUNDARY
322e3e34
RK
3261 /* If we pushed args in forward order, perform stack alignment
3262 after pushing the last arg. */
3263 if (argblock == 0)
3264 anti_adjust_stack (GEN_INT (args_size.constant
3265 - original_args_size.constant));
3266#endif
3267#endif
3268
3269#ifdef PUSH_ARGS_REVERSED
3270 argnum = nargs - 1;
3271#else
3272 argnum = 0;
3273#endif
3274
77cac2f2 3275 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
8b0f9101 3276
322e3e34
RK
3277 /* Now load any reg parms into their regs. */
3278
5e26979c
JL
3279 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3280 are to be pushed. */
322e3e34
RK
3281 for (count = 0; count < nargs; count++, argnum += inc)
3282 {
322e3e34
RK
3283 register rtx val = argvec[argnum].value;
3284 rtx reg = argvec[argnum].reg;
3285 int partial = argvec[argnum].partial;
3286
3287 if (reg != 0 && partial == 0)
3288 emit_move_insn (reg, val);
3289 NO_DEFER_POP;
3290 }
3291
3292#if 0
3293 /* For version 1.37, try deleting this entirely. */
3294 if (! no_queue)
3295 emit_queue ();
3296#endif
3297
3298 /* Any regs containing parms remain in use through the call. */
322e3e34
RK
3299 for (count = 0; count < nargs; count++)
3300 if (argvec[count].reg != 0)
77cac2f2 3301 use_reg (&call_fusage, argvec[count].reg);
322e3e34 3302
fac0ad80
RS
3303 /* Pass the function the address in which to return a structure value. */
3304 if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
3305 {
3306 emit_move_insn (struct_value_rtx,
3307 force_reg (Pmode,
3308 force_operand (XEXP (mem_value, 0),
3309 NULL_RTX)));
3310 if (GET_CODE (struct_value_rtx) == REG)
77cac2f2 3311 use_reg (&call_fusage, struct_value_rtx);
fac0ad80
RS
3312 }
3313
322e3e34
RK
3314 /* Don't allow popping to be deferred, since then
3315 cse'ing of library calls could delete a call and leave the pop. */
3316 NO_DEFER_POP;
3317
3318 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3319 will set inhibit_defer_pop to that value. */
334c4f0f
RK
3320 /* See the comment in emit_library_call about the function type we build
3321 and pass here. */
322e3e34 3322
2c8da025
RK
3323 emit_call_1 (fun,
3324 get_identifier (XSTR (orgfun, 0)),
334c4f0f
RK
3325 build_function_type (type_for_mode (outmode, 0), NULL_TREE),
3326 args_size.constant, struct_value_size,
322e3e34 3327 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
4d6a19ff 3328 mem_value == 0 ? hard_libcall_value (outmode) : NULL_RTX,
77cac2f2 3329 old_inhibit_defer_pop + 1, call_fusage, is_const);
322e3e34
RK
3330
3331 /* Now restore inhibit_defer_pop to its actual original value. */
3332 OK_DEFER_POP;
3333
888aa7a9
RS
3334 pop_temp_slots ();
3335
322e3e34
RK
3336 /* Copy the value to the right place. */
3337 if (outmode != VOIDmode)
3338 {
3339 if (mem_value)
3340 {
3341 if (value == 0)
fac0ad80 3342 value = mem_value;
322e3e34
RK
3343 if (value != mem_value)
3344 emit_move_insn (value, mem_value);
3345 }
3346 else if (value != 0)
3347 emit_move_insn (value, hard_libcall_value (outmode));
fac0ad80
RS
3348 else
3349 value = hard_libcall_value (outmode);
322e3e34 3350 }
fac0ad80 3351
f046b3cc
JL
3352#ifdef ACCUMULATE_OUTGOING_ARGS
3353#ifdef REG_PARM_STACK_SPACE
e9a25f70
JL
3354 if (save_area)
3355 {
3356 enum machine_mode save_mode = GET_MODE (save_area);
ceb83206 3357#ifdef ARGS_GROW_DOWNWARD
e9a25f70 3358 rtx stack_area
38a448ca
RH
3359 = gen_rtx_MEM (save_mode,
3360 memory_address (save_mode,
ceb83206
JL
3361 plus_constant (argblock,
3362 - high_to_save)));
f046b3cc 3363#else
ceb83206
JL
3364 rtx stack_area
3365 = gen_rtx_MEM (save_mode,
3366 memory_address (save_mode,
3367 plus_constant (argblock, low_to_save)));
f046b3cc 3368#endif
e9a25f70
JL
3369 if (save_mode != BLKmode)
3370 emit_move_insn (stack_area, save_area);
3371 else
3372 emit_block_move (stack_area, validize_mem (save_area),
3373 GEN_INT (high_to_save - low_to_save + 1),
f046b3cc 3374 PARM_BOUNDARY / BITS_PER_UNIT);
e9a25f70 3375 }
f046b3cc
JL
3376#endif
3377
3378 /* If we saved any argument areas, restore them. */
3379 for (count = 0; count < nargs; count++)
3380 if (argvec[count].save_area)
3381 {
3382 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3383 rtx stack_area
38a448ca 3384 = gen_rtx_MEM (save_mode,
f046b3cc
JL
3385 memory_address (save_mode, plus_constant (argblock,
3386 argvec[count].offset.constant)));
3387
3388 emit_move_insn (stack_area, argvec[count].save_area);
3389 }
3390
3391 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3392 stack_usage_map = initial_stack_usage_map;
3393#endif
3394
fac0ad80 3395 return value;
322e3e34
RK
3396}
3397\f
51bbfa0c
RS
3398#if 0
3399/* Return an rtx which represents a suitable home on the stack
3400 given TYPE, the type of the argument looking for a home.
3401 This is called only for BLKmode arguments.
3402
3403 SIZE is the size needed for this target.
3404 ARGS_ADDR is the address of the bottom of the argument block for this call.
3405 OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
3406 if this machine uses push insns. */
3407
3408static rtx
3409target_for_arg (type, size, args_addr, offset)
3410 tree type;
3411 rtx size;
3412 rtx args_addr;
3413 struct args_size offset;
3414{
3415 rtx target;
3416 rtx offset_rtx = ARGS_SIZE_RTX (offset);
3417
3418 /* We do not call memory_address if possible,
3419 because we want to address as close to the stack
3420 as possible. For non-variable sized arguments,
3421 this will be stack-pointer relative addressing. */
3422 if (GET_CODE (offset_rtx) == CONST_INT)
3423 target = plus_constant (args_addr, INTVAL (offset_rtx));
3424 else
3425 {
3426 /* I have no idea how to guarantee that this
3427 will work in the presence of register parameters. */
38a448ca 3428 target = gen_rtx_PLUS (Pmode, args_addr, offset_rtx);
51bbfa0c
RS
3429 target = memory_address (QImode, target);
3430 }
3431
38a448ca 3432 return gen_rtx_MEM (BLKmode, target);
51bbfa0c
RS
3433}
3434#endif
3435\f
3436/* Store a single argument for a function call
3437 into the register or memory area where it must be passed.
3438 *ARG describes the argument value and where to pass it.
3439
3440 ARGBLOCK is the address of the stack-block for all the arguments,
d45cf215 3441 or 0 on a machine where arguments are pushed individually.
51bbfa0c
RS
3442
3443 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
3444 so must be careful about how the stack is used.
3445
3446 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
3447 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
3448 that we need not worry about saving and restoring the stack.
3449
3450 FNDECL is the declaration of the function we are calling. */
3451
3452static void
c84e2712 3453store_one_arg (arg, argblock, may_be_alloca, variable_size,
6f90e075 3454 reg_parm_stack_space)
51bbfa0c
RS
3455 struct arg_data *arg;
3456 rtx argblock;
3457 int may_be_alloca;
3458 int variable_size;
6f90e075 3459 int reg_parm_stack_space;
51bbfa0c
RS
3460{
3461 register tree pval = arg->tree_value;
3462 rtx reg = 0;
3463 int partial = 0;
3464 int used = 0;
69d4ca36 3465#ifdef ACCUMULATE_OUTGOING_ARGS
51bbfa0c 3466 int i, lower_bound, upper_bound;
69d4ca36 3467#endif
51bbfa0c
RS
3468
3469 if (TREE_CODE (pval) == ERROR_MARK)
3470 return;
3471
cc79451b
RK
3472 /* Push a new temporary level for any temporaries we make for
3473 this argument. */
3474 push_temp_slots ();
3475
51bbfa0c
RS
3476#ifdef ACCUMULATE_OUTGOING_ARGS
3477 /* If this is being stored into a pre-allocated, fixed-size, stack area,
3478 save any previous data at that location. */
3479 if (argblock && ! variable_size && arg->stack)
3480 {
3481#ifdef ARGS_GROW_DOWNWARD
0f41302f
MS
3482 /* stack_slot is negative, but we want to index stack_usage_map
3483 with positive values. */
51bbfa0c
RS
3484 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3485 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
3486 else
50eb43ca 3487 upper_bound = 0;
51bbfa0c
RS
3488
3489 lower_bound = upper_bound - arg->size.constant;
3490#else
3491 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3492 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
3493 else
3494 lower_bound = 0;
3495
3496 upper_bound = lower_bound + arg->size.constant;
3497#endif
3498
3499 for (i = lower_bound; i < upper_bound; i++)
3500 if (stack_usage_map[i]
51bbfa0c
RS
3501 /* Don't store things in the fixed argument area at this point;
3502 it has already been saved. */
e5e809f4 3503 && i > reg_parm_stack_space)
51bbfa0c
RS
3504 break;
3505
3506 if (i != upper_bound)
3507 {
3508 /* We need to make a save area. See what mode we can make it. */
3509 enum machine_mode save_mode
3510 = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
3511 rtx stack_area
38a448ca
RH
3512 = gen_rtx_MEM (save_mode,
3513 memory_address (save_mode,
3514 XEXP (arg->stack_slot, 0)));
51bbfa0c
RS
3515
3516 if (save_mode == BLKmode)
3517 {
3518 arg->save_area = assign_stack_temp (BLKmode,
6fa51029 3519 arg->size.constant, 0);
3668e76e
JL
3520 MEM_IN_STRUCT_P (arg->save_area)
3521 = AGGREGATE_TYPE_P (TREE_TYPE (arg->tree_value));
cc79451b 3522 preserve_temp_slots (arg->save_area);
51bbfa0c 3523 emit_block_move (validize_mem (arg->save_area), stack_area,
e5d70561 3524 GEN_INT (arg->size.constant),
51bbfa0c
RS
3525 PARM_BOUNDARY / BITS_PER_UNIT);
3526 }
3527 else
3528 {
3529 arg->save_area = gen_reg_rtx (save_mode);
3530 emit_move_insn (arg->save_area, stack_area);
3531 }
3532 }
3533 }
3534#endif
3535
3536 /* If this isn't going to be placed on both the stack and in registers,
3537 set up the register and number of words. */
3538 if (! arg->pass_on_stack)
3539 reg = arg->reg, partial = arg->partial;
3540
3541 if (reg != 0 && partial == 0)
3542 /* Being passed entirely in a register. We shouldn't be called in
3543 this case. */
3544 abort ();
3545
4ab56118
RK
3546 /* If this arg needs special alignment, don't load the registers
3547 here. */
3548 if (arg->n_aligned_regs != 0)
3549 reg = 0;
4ab56118 3550
4ab56118 3551 /* If this is being passed partially in a register, we can't evaluate
51bbfa0c
RS
3552 it directly into its stack slot. Otherwise, we can. */
3553 if (arg->value == 0)
d64f5a78
RS
3554 {
3555#ifdef ACCUMULATE_OUTGOING_ARGS
3556 /* stack_arg_under_construction is nonzero if a function argument is
3557 being evaluated directly into the outgoing argument list and
3558 expand_call must take special action to preserve the argument list
3559 if it is called recursively.
3560
3561 For scalar function arguments stack_usage_map is sufficient to
3562 determine which stack slots must be saved and restored. Scalar
3563 arguments in general have pass_on_stack == 0.
3564
3565 If this argument is initialized by a function which takes the
3566 address of the argument (a C++ constructor or a C function
3567 returning a BLKmode structure), then stack_usage_map is
3568 insufficient and expand_call must push the stack around the
3569 function call. Such arguments have pass_on_stack == 1.
3570
3571 Note that it is always safe to set stack_arg_under_construction,
3572 but this generates suboptimal code if set when not needed. */
3573
3574 if (arg->pass_on_stack)
3575 stack_arg_under_construction++;
3576#endif
3a08477a
RK
3577 arg->value = expand_expr (pval,
3578 (partial
3579 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
3580 ? NULL_RTX : arg->stack,
e5d70561 3581 VOIDmode, 0);
1efe6448
RK
3582
3583 /* If we are promoting object (or for any other reason) the mode
3584 doesn't agree, convert the mode. */
3585
7373d92d
RK
3586 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
3587 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
3588 arg->value, arg->unsignedp);
1efe6448 3589
d64f5a78
RS
3590#ifdef ACCUMULATE_OUTGOING_ARGS
3591 if (arg->pass_on_stack)
3592 stack_arg_under_construction--;
3593#endif
3594 }
51bbfa0c
RS
3595
3596 /* Don't allow anything left on stack from computation
3597 of argument to alloca. */
3598 if (may_be_alloca)
3599 do_pending_stack_adjust ();
3600
3601 if (arg->value == arg->stack)
7815214e 3602 {
7d384cc0
KR
3603 /* If the value is already in the stack slot, we are done moving
3604 data. */
3605 if (current_function_check_memory_usage && GET_CODE (arg->stack) == MEM)
7815214e 3606 {
7815214e
RK
3607 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
3608 XEXP (arg->stack, 0), ptr_mode,
7d384cc0 3609 ARGS_SIZE_RTX (arg->size),
7815214e 3610 TYPE_MODE (sizetype),
956d6950
JL
3611 GEN_INT (MEMORY_USE_RW),
3612 TYPE_MODE (integer_type_node));
7815214e
RK
3613 }
3614 }
1efe6448 3615 else if (arg->mode != BLKmode)
51bbfa0c
RS
3616 {
3617 register int size;
3618
3619 /* Argument is a scalar, not entirely passed in registers.
3620 (If part is passed in registers, arg->partial says how much
3621 and emit_push_insn will take care of putting it there.)
3622
3623 Push it, and if its size is less than the
3624 amount of space allocated to it,
3625 also bump stack pointer by the additional space.
3626 Note that in C the default argument promotions
3627 will prevent such mismatches. */
3628
1efe6448 3629 size = GET_MODE_SIZE (arg->mode);
51bbfa0c
RS
3630 /* Compute how much space the push instruction will push.
3631 On many machines, pushing a byte will advance the stack
3632 pointer by a halfword. */
3633#ifdef PUSH_ROUNDING
3634 size = PUSH_ROUNDING (size);
3635#endif
3636 used = size;
3637
3638 /* Compute how much space the argument should get:
3639 round up to a multiple of the alignment for arguments. */
1efe6448 3640 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
51bbfa0c
RS
3641 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
3642 / (PARM_BOUNDARY / BITS_PER_UNIT))
3643 * (PARM_BOUNDARY / BITS_PER_UNIT));
3644
3645 /* This isn't already where we want it on the stack, so put it there.
3646 This can either be done with push or copy insns. */
e5e809f4
JL
3647 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, 0,
3648 partial, reg, used - size, argblock,
3649 ARGS_SIZE_RTX (arg->offset), reg_parm_stack_space);
51bbfa0c
RS
3650 }
3651 else
3652 {
3653 /* BLKmode, at least partly to be pushed. */
3654
3655 register int excess;
3656 rtx size_rtx;
3657
3658 /* Pushing a nonscalar.
3659 If part is passed in registers, PARTIAL says how much
3660 and emit_push_insn will take care of putting it there. */
3661
3662 /* Round its size up to a multiple
3663 of the allocation unit for arguments. */
3664
3665 if (arg->size.var != 0)
3666 {
3667 excess = 0;
3668 size_rtx = ARGS_SIZE_RTX (arg->size);
3669 }
3670 else
3671 {
51bbfa0c
RS
3672 /* PUSH_ROUNDING has no effect on us, because
3673 emit_push_insn for BLKmode is careful to avoid it. */
0cf91217 3674 excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
51bbfa0c 3675 + partial * UNITS_PER_WORD);
e4f93898 3676 size_rtx = expr_size (pval);
51bbfa0c
RS
3677 }
3678
1efe6448 3679 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
51bbfa0c 3680 TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
e5e809f4
JL
3681 reg, excess, argblock, ARGS_SIZE_RTX (arg->offset),
3682 reg_parm_stack_space);
51bbfa0c
RS
3683 }
3684
3685
3686 /* Unless this is a partially-in-register argument, the argument is now
3687 in the stack.
3688
3689 ??? Note that this can change arg->value from arg->stack to
3690 arg->stack_slot and it matters when they are not the same.
3691 It isn't totally clear that this is correct in all cases. */
3692 if (partial == 0)
3693 arg->value = arg->stack_slot;
3694
3695 /* Once we have pushed something, pops can't safely
3696 be deferred during the rest of the arguments. */
3697 NO_DEFER_POP;
3698
3699 /* ANSI doesn't require a sequence point here,
3700 but PCC has one, so this will avoid some problems. */
3701 emit_queue ();
3702
db907e7b
RK
3703 /* Free any temporary slots made in processing this argument. Show
3704 that we might have taken the address of something and pushed that
3705 as an operand. */
3706 preserve_temp_slots (NULL_RTX);
51bbfa0c 3707 free_temp_slots ();
cc79451b 3708 pop_temp_slots ();
51bbfa0c
RS
3709
3710#ifdef ACCUMULATE_OUTGOING_ARGS
3711 /* Now mark the segment we just used. */
3712 if (argblock && ! variable_size && arg->stack)
3713 for (i = lower_bound; i < upper_bound; i++)
3714 stack_usage_map[i] = 1;
3715#endif
3716}