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