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