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