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