]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/calls.c
(yylex): At eof, if binding levels not popped,
[thirdparty/gcc.git] / gcc / calls.c
CommitLineData
51bbfa0c
RS
1/* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989, 1992 Free Software Foundation, Inc.
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"
25#include "insn-flags.h"
26
27/* Decide whether a function's arguments should be processed
28 from first to last or from last to first. */
29
30#ifdef STACK_GROWS_DOWNWARD
31#ifdef PUSH_ROUNDING
32#define PUSH_ARGS_REVERSED /* If it's last to first */
33#endif
34#endif
35
36/* Like STACK_BOUNDARY but in units of bytes, not bits. */
37#define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
38
39/* Data structure and subroutines used within expand_call. */
40
41struct arg_data
42{
43 /* Tree node for this argument. */
44 tree tree_value;
45 /* Current RTL value for argument, or 0 if it isn't precomputed. */
46 rtx value;
47 /* Initially-compute RTL value for argument; only for const functions. */
48 rtx initial_value;
49 /* Register to pass this argument in, 0 if passed on stack, or an
50 EXPR_LIST if the arg is to be copied into multiple different
51 registers. */
52 rtx reg;
84b55618
RK
53 /* If REG was promoted from the actual mode of the argument expression,
54 indicates whether the promotion is sign- or zero-extended. */
55 int unsignedp;
51bbfa0c
RS
56 /* Number of registers to use. 0 means put the whole arg in registers.
57 Also 0 if not passed in registers. */
58 int partial;
d64f5a78
RS
59 /* Non-zero if argument must be passed on stack.
60 Note that some arguments may be passed on the stack
61 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
62 pass_on_stack identifies arguments that *cannot* go in registers. */
51bbfa0c
RS
63 int pass_on_stack;
64 /* Offset of this argument from beginning of stack-args. */
65 struct args_size offset;
66 /* Similar, but offset to the start of the stack slot. Different from
67 OFFSET if this arg pads downward. */
68 struct args_size slot_offset;
69 /* Size of this argument on the stack, rounded up for any padding it gets,
70 parts of the argument passed in registers do not count.
71 If REG_PARM_STACK_SPACE is defined, then register parms
72 are counted here as well. */
73 struct args_size size;
74 /* Location on the stack at which parameter should be stored. The store
75 has already been done if STACK == VALUE. */
76 rtx stack;
77 /* Location on the stack of the start of this argument slot. This can
78 differ from STACK if this arg pads downward. This location is known
79 to be aligned to FUNCTION_ARG_BOUNDARY. */
80 rtx stack_slot;
81#ifdef ACCUMULATE_OUTGOING_ARGS
82 /* Place that this stack area has been saved, if needed. */
83 rtx save_area;
84#endif
85};
86
87#ifdef ACCUMULATE_OUTGOING_ARGS
b94301c2 88/* A vector of one char per byte of stack space. A byte if non-zero if
51bbfa0c
RS
89 the corresponding stack location has been used.
90 This vector is used to prevent a function call within an argument from
91 clobbering any stack already set up. */
92static char *stack_usage_map;
93
94/* Size of STACK_USAGE_MAP. */
95static int highest_outgoing_arg_in_use;
2f4aa534
RS
96
97/* stack_arg_under_construction is nonzero when an argument may be
98 initialized with a constructor call (including a C function that
99 returns a BLKmode struct) and expand_call must take special action
100 to make sure the object being constructed does not overlap the
101 argument list for the constructor call. */
102int stack_arg_under_construction;
51bbfa0c
RS
103#endif
104
105static void store_one_arg ();
106extern enum machine_mode mode_for_size ();
107\f
1ce0cb53
JW
108/* If WHICH is 1, return 1 if EXP contains a call to the built-in function
109 `alloca'.
110
111 If WHICH is 0, return 1 if EXP contains a call to any function.
112 Actually, we only need return 1 if evaluating EXP would require pushing
113 arguments on the stack, but that is too difficult to compute, so we just
114 assume any function call might require the stack. */
51bbfa0c
RS
115
116static int
1ce0cb53 117calls_function (exp, which)
51bbfa0c 118 tree exp;
1ce0cb53 119 int which;
51bbfa0c
RS
120{
121 register int i;
122 int type = TREE_CODE_CLASS (TREE_CODE (exp));
123 int length = tree_code_length[(int) TREE_CODE (exp)];
124
125 /* Only expressions and references can contain calls. */
126
3b59a331
RS
127 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
128 && type != 'b')
51bbfa0c
RS
129 return 0;
130
131 switch (TREE_CODE (exp))
132 {
133 case CALL_EXPR:
1ce0cb53
JW
134 if (which == 0)
135 return 1;
136 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
137 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
138 == FUNCTION_DECL)
139 && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
140 && (DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
141 == BUILT_IN_ALLOCA))
51bbfa0c
RS
142 return 1;
143
144 /* Third operand is RTL. */
145 length = 2;
146 break;
147
148 case SAVE_EXPR:
149 if (SAVE_EXPR_RTL (exp) != 0)
150 return 0;
151 break;
152
153 case BLOCK:
ef03bc85
CH
154 {
155 register tree local;
156
157 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
1ce0cb53
JW
158 if (DECL_INITIAL (local) != 0
159 && calls_function (DECL_INITIAL (local), which))
ef03bc85
CH
160 return 1;
161 }
162 {
163 register tree subblock;
164
165 for (subblock = BLOCK_SUBBLOCKS (exp);
166 subblock;
167 subblock = TREE_CHAIN (subblock))
1ce0cb53 168 if (calls_function (subblock, which))
ef03bc85
CH
169 return 1;
170 }
171 return 0;
51bbfa0c
RS
172
173 case METHOD_CALL_EXPR:
174 length = 3;
175 break;
176
177 case WITH_CLEANUP_EXPR:
178 length = 1;
179 break;
180
181 case RTL_EXPR:
182 return 0;
183 }
184
185 for (i = 0; i < length; i++)
186 if (TREE_OPERAND (exp, i) != 0
1ce0cb53 187 && calls_function (TREE_OPERAND (exp, i), which))
51bbfa0c
RS
188 return 1;
189
190 return 0;
191}
192\f
193/* Force FUNEXP into a form suitable for the address of a CALL,
194 and return that as an rtx. Also load the static chain register
195 if FNDECL is a nested function.
196
197 USE_INSNS points to a variable holding a chain of USE insns
198 to which a USE of the static chain
199 register should be added, if required. */
200
201rtx
202prepare_call_address (funexp, fndecl, use_insns)
203 rtx funexp;
204 tree fndecl;
205 rtx *use_insns;
206{
207 rtx static_chain_value = 0;
208
209 funexp = protect_from_queue (funexp, 0);
210
211 if (fndecl != 0)
212 /* Get possible static chain value for nested function in C. */
213 static_chain_value = lookup_static_chain (fndecl);
214
215 /* Make a valid memory address and copy constants thru pseudo-regs,
216 but not for a constant address if -fno-function-cse. */
217 if (GET_CODE (funexp) != SYMBOL_REF)
218 funexp = memory_address (FUNCTION_MODE, funexp);
219 else
220 {
221#ifndef NO_FUNCTION_CSE
222 if (optimize && ! flag_no_function_cse)
223#ifdef NO_RECURSIVE_FUNCTION_CSE
224 if (fndecl != current_function_decl)
225#endif
226 funexp = force_reg (Pmode, funexp);
227#endif
228 }
229
230 if (static_chain_value != 0)
231 {
232 emit_move_insn (static_chain_rtx, static_chain_value);
233
234 /* Put the USE insn in the chain we were passed. It will later be
235 output immediately in front of the CALL insn. */
236 push_to_sequence (*use_insns);
237 emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx));
238 *use_insns = get_insns ();
239 end_sequence ();
240 }
241
242 return funexp;
243}
244
245/* Generate instructions to call function FUNEXP,
246 and optionally pop the results.
247 The CALL_INSN is the first insn generated.
248
249 FUNTYPE is the data type of the function, or, for a library call,
250 the identifier for the name of the call. This is given to the
251 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
252
253 STACK_SIZE is the number of bytes of arguments on the stack,
254 rounded up to STACK_BOUNDARY; zero if the size is variable.
255 This is both to put into the call insn and
256 to generate explicit popping code if necessary.
257
258 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
259 It is zero if this call doesn't want a structure value.
260
261 NEXT_ARG_REG is the rtx that results from executing
262 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
263 just after all the args have had their registers assigned.
264 This could be whatever you like, but normally it is the first
265 arg-register beyond those used for args in this call,
266 or 0 if all the arg-registers are used in this call.
267 It is passed on to `gen_call' so you can put this info in the call insn.
268
269 VALREG is a hard register in which a value is returned,
270 or 0 if the call does not return a value.
271
272 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
273 the args to this call were processed.
274 We restore `inhibit_defer_pop' to that value.
275
276 USE_INSNS is a chain of USE insns to be emitted immediately before
277 the actual CALL insn.
278
279 IS_CONST is true if this is a `const' call. */
280
281void
282emit_call_1 (funexp, funtype, stack_size, struct_value_size, next_arg_reg,
283 valreg, old_inhibit_defer_pop, use_insns, is_const)
284 rtx funexp;
285 tree funtype;
286 int stack_size;
287 int struct_value_size;
288 rtx next_arg_reg;
289 rtx valreg;
290 int old_inhibit_defer_pop;
291 rtx use_insns;
292 int is_const;
293{
e5d70561
RK
294 rtx stack_size_rtx = GEN_INT (stack_size);
295 rtx struct_value_size_rtx = GEN_INT (struct_value_size);
51bbfa0c
RS
296 rtx call_insn;
297 int already_popped = 0;
298
299 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
300 and we don't want to load it into a register as an optimization,
301 because prepare_call_address already did it if it should be done. */
302 if (GET_CODE (funexp) != SYMBOL_REF)
303 funexp = memory_address (FUNCTION_MODE, funexp);
304
305#ifndef ACCUMULATE_OUTGOING_ARGS
306#if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
307 if (HAVE_call_pop && HAVE_call_value_pop
308 && (RETURN_POPS_ARGS (funtype, stack_size) > 0 || stack_size == 0))
309 {
e5d70561 310 rtx n_pop = GEN_INT (RETURN_POPS_ARGS (funtype, stack_size));
51bbfa0c
RS
311 rtx pat;
312
313 /* If this subroutine pops its own args, record that in the call insn
314 if possible, for the sake of frame pointer elimination. */
315 if (valreg)
316 pat = gen_call_value_pop (valreg,
317 gen_rtx (MEM, FUNCTION_MODE, funexp),
318 stack_size_rtx, next_arg_reg, n_pop);
319 else
320 pat = gen_call_pop (gen_rtx (MEM, FUNCTION_MODE, funexp),
321 stack_size_rtx, next_arg_reg, n_pop);
322
323 emit_call_insn (pat);
324 already_popped = 1;
325 }
326 else
327#endif
328#endif
329
330#if defined (HAVE_call) && defined (HAVE_call_value)
331 if (HAVE_call && HAVE_call_value)
332 {
333 if (valreg)
334 emit_call_insn (gen_call_value (valreg,
335 gen_rtx (MEM, FUNCTION_MODE, funexp),
e992302c
BK
336 stack_size_rtx, next_arg_reg,
337 NULL_RTX));
51bbfa0c
RS
338 else
339 emit_call_insn (gen_call (gen_rtx (MEM, FUNCTION_MODE, funexp),
340 stack_size_rtx, next_arg_reg,
341 struct_value_size_rtx));
342 }
343 else
344#endif
345 abort ();
346
347 /* Find the CALL insn we just emitted and write the USE insns before it. */
348 for (call_insn = get_last_insn ();
349 call_insn && GET_CODE (call_insn) != CALL_INSN;
350 call_insn = PREV_INSN (call_insn))
351 ;
352
353 if (! call_insn)
354 abort ();
355
356 /* Put the USE insns before the CALL. */
357 emit_insns_before (use_insns, call_insn);
358
359 /* If this is a const call, then set the insn's unchanging bit. */
360 if (is_const)
361 CONST_CALL_P (call_insn) = 1;
362
51bbfa0c
RS
363#ifndef ACCUMULATE_OUTGOING_ARGS
364 /* If returning from the subroutine does not automatically pop the args,
365 we need an instruction to pop them sooner or later.
366 Perhaps do it now; perhaps just record how much space to pop later.
367
368 If returning from the subroutine does pop the args, indicate that the
369 stack pointer will be changed. */
370
371 if (stack_size != 0 && RETURN_POPS_ARGS (funtype, stack_size) > 0)
372 {
373 if (!already_popped)
374 emit_insn (gen_rtx (CLOBBER, VOIDmode, stack_pointer_rtx));
375 stack_size -= RETURN_POPS_ARGS (funtype, stack_size);
e5d70561 376 stack_size_rtx = GEN_INT (stack_size);
51bbfa0c
RS
377 }
378
379 if (stack_size != 0)
380 {
381 if (flag_defer_pop && inhibit_defer_pop == 0)
382 pending_stack_adjust += stack_size;
383 else
384 adjust_stack (stack_size_rtx);
385 }
386#endif
ff1e9821
RS
387
388 inhibit_defer_pop = old_inhibit_defer_pop;
51bbfa0c
RS
389}
390
391/* Generate all the code for a function call
392 and return an rtx for its value.
393 Store the value in TARGET (specified as an rtx) if convenient.
394 If the value is stored in TARGET then TARGET is returned.
395 If IGNORE is nonzero, then we ignore the value of the function call. */
396
397rtx
8129842c 398expand_call (exp, target, ignore)
51bbfa0c
RS
399 tree exp;
400 rtx target;
401 int ignore;
51bbfa0c
RS
402{
403 /* List of actual parameters. */
404 tree actparms = TREE_OPERAND (exp, 1);
405 /* RTX for the function to be called. */
406 rtx funexp;
407 /* Tree node for the function to be called (not the address!). */
408 tree funtree;
409 /* Data type of the function. */
410 tree funtype;
411 /* Declaration of the function being called,
412 or 0 if the function is computed (not known by name). */
413 tree fndecl = 0;
414 char *name = 0;
415
416 /* Register in which non-BLKmode value will be returned,
417 or 0 if no value or if value is BLKmode. */
418 rtx valreg;
419 /* Address where we should return a BLKmode value;
420 0 if value not BLKmode. */
421 rtx structure_value_addr = 0;
422 /* Nonzero if that address is being passed by treating it as
423 an extra, implicit first parameter. Otherwise,
424 it is passed by being copied directly into struct_value_rtx. */
425 int structure_value_addr_parm = 0;
426 /* Size of aggregate value wanted, or zero if none wanted
427 or if we are using the non-reentrant PCC calling convention
428 or expecting the value in registers. */
429 int struct_value_size = 0;
430 /* Nonzero if called function returns an aggregate in memory PCC style,
431 by returning the address of where to find it. */
432 int pcc_struct_value = 0;
433
434 /* Number of actual parameters in this call, including struct value addr. */
435 int num_actuals;
436 /* Number of named args. Args after this are anonymous ones
437 and they must all go on the stack. */
438 int n_named_args;
439 /* Count arg position in order args appear. */
440 int argpos;
441
442 /* Vector of information about each argument.
443 Arguments are numbered in the order they will be pushed,
444 not the order they are written. */
445 struct arg_data *args;
446
447 /* Total size in bytes of all the stack-parms scanned so far. */
448 struct args_size args_size;
449 /* Size of arguments before any adjustments (such as rounding). */
450 struct args_size original_args_size;
451 /* Data on reg parms scanned so far. */
452 CUMULATIVE_ARGS args_so_far;
453 /* Nonzero if a reg parm has been scanned. */
454 int reg_parm_seen;
455
456 /* Nonzero if we must avoid push-insns in the args for this call.
457 If stack space is allocated for register parameters, but not by the
458 caller, then it is preallocated in the fixed part of the stack frame.
459 So the entire argument block must then be preallocated (i.e., we
460 ignore PUSH_ROUNDING in that case). */
461
462#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
463 int must_preallocate = 1;
464#else
465#ifdef PUSH_ROUNDING
466 int must_preallocate = 0;
467#else
468 int must_preallocate = 1;
469#endif
470#endif
471
f72aed24 472 /* Size of the stack reserved for parameter registers. */
6f90e075
JW
473 int reg_parm_stack_space = 0;
474
51bbfa0c
RS
475 /* 1 if scanning parms front to back, -1 if scanning back to front. */
476 int inc;
477 /* Address of space preallocated for stack parms
478 (on machines that lack push insns), or 0 if space not preallocated. */
479 rtx argblock = 0;
480
481 /* Nonzero if it is plausible that this is a call to alloca. */
482 int may_be_alloca;
483 /* Nonzero if this is a call to setjmp or a related function. */
484 int returns_twice;
485 /* Nonzero if this is a call to `longjmp'. */
486 int is_longjmp;
487 /* Nonzero if this is a call to an inline function. */
488 int is_integrable = 0;
51bbfa0c
RS
489 /* Nonzero if this is a call to a `const' function.
490 Note that only explicitly named functions are handled as `const' here. */
491 int is_const = 0;
492 /* Nonzero if this is a call to a `volatile' function. */
493 int is_volatile = 0;
494#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
495 /* Define the boundary of the register parm stack space that needs to be
496 save, if any. */
497 int low_to_save = -1, high_to_save;
498 rtx save_area = 0; /* Place that it is saved */
499#endif
500
501#ifdef ACCUMULATE_OUTGOING_ARGS
502 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
503 char *initial_stack_usage_map = stack_usage_map;
504#endif
505
506 rtx old_stack_level = 0;
507 int old_pending_adj;
2f4aa534 508 int old_stack_arg_under_construction;
51bbfa0c
RS
509 int old_inhibit_defer_pop = inhibit_defer_pop;
510 tree old_cleanups = cleanups_this_call;
511
512 rtx use_insns = 0;
513
514 register tree p;
515 register int i;
516
517 /* See if we can find a DECL-node for the actual function.
518 As a result, decide whether this is a call to an integrable function. */
519
520 p = TREE_OPERAND (exp, 0);
521 if (TREE_CODE (p) == ADDR_EXPR)
522 {
523 fndecl = TREE_OPERAND (p, 0);
524 if (TREE_CODE (fndecl) != FUNCTION_DECL)
525 {
526 /* May still be a `const' function if it is
527 a call through a pointer-to-const.
528 But we don't handle that. */
529 fndecl = 0;
530 }
531 else
532 {
533 if (!flag_no_inline
534 && fndecl != current_function_decl
535 && DECL_SAVED_INSNS (fndecl))
536 is_integrable = 1;
537 else if (! TREE_ADDRESSABLE (fndecl))
538 {
13d39dbc 539 /* In case this function later becomes inlinable,
51bbfa0c
RS
540 record that there was already a non-inline call to it.
541
542 Use abstraction instead of setting TREE_ADDRESSABLE
543 directly. */
216d5cdd 544 if (DECL_INLINE (fndecl) && extra_warnings && !flag_no_inline)
51bbfa0c
RS
545 warning_with_decl (fndecl, "can't inline call to `%s' which was declared inline");
546 mark_addressable (fndecl);
547 }
548
d45cf215
RS
549 if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
550 && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
51bbfa0c
RS
551 is_const = 1;
552 }
553 }
554
555 is_volatile = TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
556
6f90e075
JW
557#ifdef REG_PARM_STACK_SPACE
558#ifdef MAYBE_REG_PARM_STACK_SPACE
559 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
560#else
561 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
562#endif
563#endif
564
51bbfa0c
RS
565 /* Warn if this value is an aggregate type,
566 regardless of which calling convention we are using for it. */
567 if (warn_aggregate_return
568 && (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
569 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
570 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE))
571 warning ("function call has aggregate value");
572
573 /* Set up a place to return a structure. */
574
575 /* Cater to broken compilers. */
576 if (aggregate_value_p (exp))
577 {
578 /* This call returns a big structure. */
579 is_const = 0;
580
581#ifdef PCC_STATIC_STRUCT_RETURN
582 if (flag_pcc_struct_return)
583 {
584 pcc_struct_value = 1;
585 is_integrable = 0; /* Easier than making that case work right. */
586 }
587 else
588#endif
589 {
590 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
591
592 if (struct_value_size < 0)
593 abort ();
594
595 if (target && GET_CODE (target) == MEM)
596 structure_value_addr = XEXP (target, 0);
597 else
598 {
599 /* Assign a temporary on the stack to hold the value. */
600
601 /* For variable-sized objects, we must be called with a target
602 specified. If we were to allocate space on the stack here,
603 we would have no way of knowing when to free it. */
604
605 structure_value_addr
606 = XEXP (assign_stack_temp (BLKmode, struct_value_size, 1), 0);
607 target = 0;
608 }
609 }
610 }
611
612 /* If called function is inline, try to integrate it. */
613
614 if (is_integrable)
615 {
616 rtx temp;
2f4aa534 617 rtx before_call = get_last_insn ();
51bbfa0c
RS
618
619 temp = expand_inline_function (fndecl, actparms, target,
620 ignore, TREE_TYPE (exp),
621 structure_value_addr);
622
623 /* If inlining succeeded, return. */
854e97f0 624 if ((HOST_WIDE_INT) temp != -1)
51bbfa0c 625 {
2f4aa534
RS
626 int i;
627
d64f5a78
RS
628 /* Perform all cleanups needed for the arguments of this call
629 (i.e. destructors in C++). It is ok if these destructors
630 clobber RETURN_VALUE_REG, because the only time we care about
631 this is when TARGET is that register. But in C++, we take
632 care to never return that register directly. */
633 expand_cleanups_to (old_cleanups);
634
635#ifdef ACCUMULATE_OUTGOING_ARGS
2f4aa534
RS
636 /* If the outgoing argument list must be preserved, push
637 the stack before executing the inlined function if it
638 makes any calls. */
639
640 for (i = reg_parm_stack_space - 1; i >= 0; i--)
641 if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
642 break;
643
644 if (stack_arg_under_construction || i >= 0)
645 {
d64f5a78 646 rtx insn = NEXT_INSN (before_call), seq;
2f4aa534 647
d64f5a78
RS
648 /* Look for a call in the inline function code.
649 If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is
650 nonzero then there is a call and it is not necessary
651 to scan the insns. */
652
653 if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0)
654 for (; insn; insn = NEXT_INSN (insn))
655 if (GET_CODE (insn) == CALL_INSN)
656 break;
2f4aa534
RS
657
658 if (insn)
659 {
d64f5a78
RS
660 /* Reserve enough stack space so that the largest
661 argument list of any function call in the inline
662 function does not overlap the argument list being
663 evaluated. This is usually an overestimate because
664 allocate_dynamic_stack_space reserves space for an
665 outgoing argument list in addition to the requested
666 space, but there is no way to ask for stack space such
667 that an argument list of a certain length can be
668 safely constructed. */
669
670 int adjust = OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl));
671#ifdef REG_PARM_STACK_SPACE
672 /* Add the stack space reserved for register arguments
673 in the inline function. What is really needed is the
674 largest value of reg_parm_stack_space in the inline
675 function, but that is not available. Using the current
676 value of reg_parm_stack_space is wrong, but gives
677 correct results on all supported machines. */
678 adjust += reg_parm_stack_space;
679#endif
2f4aa534
RS
680 start_sequence ();
681 emit_stack_save (SAVE_BLOCK, &old_stack_level, 0);
e5d70561
RK
682 allocate_dynamic_stack_space (GEN_INT (adjust),
683 NULL_RTX, BITS_PER_UNIT);
2f4aa534
RS
684 seq = get_insns ();
685 end_sequence ();
686 emit_insns_before (seq, NEXT_INSN (before_call));
e5d70561 687 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
2f4aa534
RS
688 }
689 }
d64f5a78 690#endif
51bbfa0c
RS
691
692 /* If the result is equivalent to TARGET, return TARGET to simplify
693 checks in store_expr. They can be equivalent but not equal in the
694 case of a function that returns BLKmode. */
695 if (temp != target && rtx_equal_p (temp, target))
696 return target;
697 return temp;
698 }
699
700 /* If inlining failed, mark FNDECL as needing to be compiled
701 separately after all. */
702 mark_addressable (fndecl);
703 }
704
705 /* When calling a const function, we must pop the stack args right away,
706 so that the pop is deleted or moved with the call. */
707 if (is_const)
708 NO_DEFER_POP;
709
710 function_call_count++;
711
712 if (fndecl && DECL_NAME (fndecl))
713 name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
714
715#if 0
716 /* Unless it's a call to a specific function that isn't alloca,
717 if it has one argument, we must assume it might be alloca. */
718
719 may_be_alloca =
720 (!(fndecl != 0 && strcmp (name, "alloca"))
721 && actparms != 0
722 && TREE_CHAIN (actparms) == 0);
723#else
724 /* We assume that alloca will always be called by name. It
725 makes no sense to pass it as a pointer-to-function to
726 anything that does not understand its behavior. */
727 may_be_alloca =
728 (name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
729 && name[0] == 'a'
730 && ! strcmp (name, "alloca"))
731 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
732 && name[0] == '_'
733 && ! strcmp (name, "__builtin_alloca"))));
734#endif
735
736 /* See if this is a call to a function that can return more than once
737 or a call to longjmp. */
738
739 returns_twice = 0;
740 is_longjmp = 0;
741
742 if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 15)
743 {
744 char *tname = name;
745
746 if (name[0] == '_')
747 tname += ((name[1] == '_' && name[2] == 'x') ? 3 : 1);
748
749 if (tname[0] == 's')
750 {
751 returns_twice
752 = ((tname[1] == 'e'
753 && (! strcmp (tname, "setjmp")
754 || ! strcmp (tname, "setjmp_syscall")))
755 || (tname[1] == 'i'
756 && ! strcmp (tname, "sigsetjmp"))
757 || (tname[1] == 'a'
758 && ! strcmp (tname, "savectx")));
759 if (tname[1] == 'i'
760 && ! strcmp (tname, "siglongjmp"))
761 is_longjmp = 1;
762 }
763 else if ((tname[0] == 'q' && tname[1] == 's'
764 && ! strcmp (tname, "qsetjmp"))
765 || (tname[0] == 'v' && tname[1] == 'f'
766 && ! strcmp (tname, "vfork")))
767 returns_twice = 1;
768
769 else if (tname[0] == 'l' && tname[1] == 'o'
770 && ! strcmp (tname, "longjmp"))
771 is_longjmp = 1;
772 }
773
51bbfa0c
RS
774 if (may_be_alloca)
775 current_function_calls_alloca = 1;
776
777 /* Don't let pending stack adjusts add up to too much.
778 Also, do all pending adjustments now
779 if there is any chance this might be a call to alloca. */
780
781 if (pending_stack_adjust >= 32
782 || (pending_stack_adjust > 0 && may_be_alloca))
783 do_pending_stack_adjust ();
784
785 /* Operand 0 is a pointer-to-function; get the type of the function. */
786 funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
787 if (TREE_CODE (funtype) != POINTER_TYPE)
788 abort ();
789 funtype = TREE_TYPE (funtype);
790
791 /* Push the temporary stack slot level so that we can free temporaries used
792 by each of the arguments separately. */
793 push_temp_slots ();
794
795 /* Start updating where the next arg would go. */
85ec8ec4 796 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX);
51bbfa0c
RS
797
798 /* If struct_value_rtx is 0, it means pass the address
799 as if it were an extra parameter. */
800 if (structure_value_addr && struct_value_rtx == 0)
801 {
d64f5a78 802#ifdef ACCUMULATE_OUTGOING_ARGS
2f4aa534
RS
803 /* If the stack will be adjusted, make sure the structure address
804 does not refer to virtual_outgoing_args_rtx. */
805 rtx temp = (stack_arg_under_construction
806 ? copy_addr_to_reg (structure_value_addr)
807 : force_reg (Pmode, structure_value_addr));
d64f5a78
RS
808#else
809 rtx temp = force_reg (Pmode, structure_value_addr);
810#endif
811
51bbfa0c
RS
812 actparms
813 = tree_cons (error_mark_node,
814 make_tree (build_pointer_type (TREE_TYPE (funtype)),
2f4aa534 815 temp),
51bbfa0c
RS
816 actparms);
817 structure_value_addr_parm = 1;
818 }
819
820 /* Count the arguments and set NUM_ACTUALS. */
821 for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
822 num_actuals = i;
823
824 /* Compute number of named args.
825 Normally, don't include the last named arg if anonymous args follow.
826 (If no anonymous args follow, the result of list_length
827 is actually one too large.)
828
829 If SETUP_INCOMING_VARARGS is defined, this machine will be able to
830 place unnamed args that were passed in registers into the stack. So
831 treat all args as named. This allows the insns emitting for a specific
d45cf215 832 argument list to be independent of the function declaration.
51bbfa0c
RS
833
834 If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable
835 way to pass unnamed args in registers, so we must force them into
836 memory. */
837#ifndef SETUP_INCOMING_VARARGS
838 if (TYPE_ARG_TYPES (funtype) != 0)
839 n_named_args
840 = list_length (TYPE_ARG_TYPES (funtype)) - 1
841 /* Count the struct value address, if it is passed as a parm. */
842 + structure_value_addr_parm;
843 else
844#endif
845 /* If we know nothing, treat all args as named. */
846 n_named_args = num_actuals;
847
848 /* Make a vector to hold all the information about each arg. */
849 args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
850 bzero (args, num_actuals * sizeof (struct arg_data));
851
852 args_size.constant = 0;
853 args_size.var = 0;
854
855 /* In this loop, we consider args in the order they are written.
856 We fill up ARGS from the front of from the back if necessary
857 so that in any case the first arg to be pushed ends up at the front. */
858
859#ifdef PUSH_ARGS_REVERSED
860 i = num_actuals - 1, inc = -1;
861 /* In this case, must reverse order of args
862 so that we compute and push the last arg first. */
863#else
864 i = 0, inc = 1;
865#endif
866
867 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
868 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
869 {
870 tree type = TREE_TYPE (TREE_VALUE (p));
84b55618 871 enum machine_mode mode;
51bbfa0c
RS
872
873 args[i].tree_value = TREE_VALUE (p);
874
875 /* Replace erroneous argument with constant zero. */
876 if (type == error_mark_node || TYPE_SIZE (type) == 0)
877 args[i].tree_value = integer_zero_node, type = integer_type_node;
878
879 /* Decide where to pass this arg.
880
881 args[i].reg is nonzero if all or part is passed in registers.
882
883 args[i].partial is nonzero if part but not all is passed in registers,
884 and the exact value says how many words are passed in registers.
885
886 args[i].pass_on_stack is nonzero if the argument must at least be
887 computed on the stack. It may then be loaded back into registers
888 if args[i].reg is nonzero.
889
890 These decisions are driven by the FUNCTION_... macros and must agree
891 with those made by function.c. */
892
893#ifdef FUNCTION_ARG_PASS_BY_REFERENCE
894 /* See if this argument should be passed by invisible reference. */
895 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, TYPE_MODE (type), type,
896 argpos < n_named_args))
897 {
898 /* We make a copy of the object and pass the address to the function
899 being called. */
51bbfa0c
RS
900 rtx copy;
901
82c0ff02
RS
902 if (TYPE_SIZE (type) == 0
903 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
51bbfa0c
RS
904 {
905 /* This is a variable-sized object. Make space on the stack
906 for it. */
e5d70561 907 rtx size_rtx = expand_expr (size_in_bytes (type), NULL_RTX,
51bbfa0c
RS
908 VOIDmode, 0);
909
910 if (old_stack_level == 0)
911 {
e5d70561 912 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
51bbfa0c
RS
913 old_pending_adj = pending_stack_adjust;
914 pending_stack_adjust = 0;
915 }
916
917 copy = gen_rtx (MEM, BLKmode,
e5d70561 918 allocate_dynamic_stack_space (size_rtx, NULL_RTX,
5130a5cc 919 TYPE_ALIGN (type)));
51bbfa0c
RS
920 }
921 else
82c0ff02
RS
922 {
923 int size = int_size_in_bytes (type);
924 copy = assign_stack_temp (TYPE_MODE (type), size, 1);
925 }
51bbfa0c
RS
926
927 store_expr (args[i].tree_value, copy, 0);
928
929 args[i].tree_value = build1 (ADDR_EXPR, build_pointer_type (type),
930 make_tree (type, copy));
931 type = build_pointer_type (type);
932 }
933#endif
934
84b55618
RK
935 mode = TYPE_MODE (type);
936
937#ifdef PROMOTE_FUNCTION_ARGS
938 /* Compute the mode in which the arg is actually to be extended to. */
939 if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == ENUMERAL_TYPE
940 || TREE_CODE (type) == BOOLEAN_TYPE || TREE_CODE (type) == CHAR_TYPE
941 || TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == POINTER_TYPE
942 || TREE_CODE (type) == OFFSET_TYPE)
943 {
944 int unsignedp = TREE_UNSIGNED (type);
945 PROMOTE_MODE (mode, unsignedp, type);
946 args[i].unsignedp = unsignedp;
947 }
948#endif
949
950 args[i].reg = FUNCTION_ARG (args_so_far, mode, type,
51bbfa0c
RS
951 argpos < n_named_args);
952#ifdef FUNCTION_ARG_PARTIAL_NREGS
953 if (args[i].reg)
954 args[i].partial
84b55618 955 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, type,
51bbfa0c
RS
956 argpos < n_named_args);
957#endif
958
84b55618 959 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
51bbfa0c
RS
960
961 /* If FUNCTION_ARG returned an (expr_list (nil) FOO), it means that
962 we are to pass this arg in the register(s) designated by FOO, but
963 also to pass it in the stack. */
964 if (args[i].reg && GET_CODE (args[i].reg) == EXPR_LIST
965 && XEXP (args[i].reg, 0) == 0)
966 args[i].pass_on_stack = 1, args[i].reg = XEXP (args[i].reg, 1);
967
968 /* If this is an addressable type, we must preallocate the stack
969 since we must evaluate the object into its final location.
970
971 If this is to be passed in both registers and the stack, it is simpler
972 to preallocate. */
973 if (TREE_ADDRESSABLE (type)
974 || (args[i].pass_on_stack && args[i].reg != 0))
975 must_preallocate = 1;
976
977 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
978 we cannot consider this function call constant. */
979 if (TREE_ADDRESSABLE (type))
980 is_const = 0;
981
982 /* Compute the stack-size of this argument. */
983 if (args[i].reg == 0 || args[i].partial != 0
984#ifdef REG_PARM_STACK_SPACE
6f90e075 985 || reg_parm_stack_space > 0
51bbfa0c
RS
986#endif
987 || args[i].pass_on_stack)
988 locate_and_pad_parm (TYPE_MODE (type), type,
989#ifdef STACK_PARMS_IN_REG_PARM_AREA
990 1,
991#else
992 args[i].reg != 0,
993#endif
994 fndecl, &args_size, &args[i].offset,
995 &args[i].size);
996
997#ifndef ARGS_GROW_DOWNWARD
998 args[i].slot_offset = args_size;
999#endif
1000
1001#ifndef REG_PARM_STACK_SPACE
1002 /* If a part of the arg was put into registers,
1003 don't include that part in the amount pushed. */
1004 if (! args[i].pass_on_stack)
1005 args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1006 / (PARM_BOUNDARY / BITS_PER_UNIT)
1007 * (PARM_BOUNDARY / BITS_PER_UNIT));
1008#endif
1009
1010 /* Update ARGS_SIZE, the total stack space for args so far. */
1011
1012 args_size.constant += args[i].size.constant;
1013 if (args[i].size.var)
1014 {
1015 ADD_PARM_SIZE (args_size, args[i].size.var);
1016 }
1017
1018 /* Since the slot offset points to the bottom of the slot,
1019 we must record it after incrementing if the args grow down. */
1020#ifdef ARGS_GROW_DOWNWARD
1021 args[i].slot_offset = args_size;
1022
1023 args[i].slot_offset.constant = -args_size.constant;
1024 if (args_size.var)
1025 {
1026 SUB_PARM_SIZE (args[i].slot_offset, args_size.var);
1027 }
1028#endif
1029
1030 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1031 have been used, etc. */
1032
1033 FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type,
1034 argpos < n_named_args);
1035 }
1036
6f90e075
JW
1037#ifdef FINAL_REG_PARM_STACK_SPACE
1038 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
1039 args_size.var);
1040#endif
1041
51bbfa0c
RS
1042 /* Compute the actual size of the argument block required. The variable
1043 and constant sizes must be combined, the size may have to be rounded,
1044 and there may be a minimum required size. */
1045
1046 original_args_size = args_size;
1047 if (args_size.var)
1048 {
1049 /* If this function requires a variable-sized argument list, don't try to
1050 make a cse'able block for this call. We may be able to do this
1051 eventually, but it is too complicated to keep track of what insns go
1052 in the cse'able block and which don't. */
1053
1054 is_const = 0;
1055 must_preallocate = 1;
1056
1057 args_size.var = ARGS_SIZE_TREE (args_size);
1058 args_size.constant = 0;
1059
1060#ifdef STACK_BOUNDARY
1061 if (STACK_BOUNDARY != BITS_PER_UNIT)
1062 args_size.var = round_up (args_size.var, STACK_BYTES);
1063#endif
1064
1065#ifdef REG_PARM_STACK_SPACE
6f90e075 1066 if (reg_parm_stack_space > 0)
51bbfa0c
RS
1067 {
1068 args_size.var
1069 = size_binop (MAX_EXPR, args_size.var,
1070 size_int (REG_PARM_STACK_SPACE (fndecl)));
1071
1072#ifndef OUTGOING_REG_PARM_STACK_SPACE
1073 /* The area corresponding to register parameters is not to count in
1074 the size of the block we need. So make the adjustment. */
1075 args_size.var
1076 = size_binop (MINUS_EXPR, args_size.var,
6f90e075 1077 size_int (reg_parm_stack_space));
51bbfa0c
RS
1078#endif
1079 }
1080#endif
1081 }
1082 else
1083 {
1084#ifdef STACK_BOUNDARY
1085 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
1086 / STACK_BYTES) * STACK_BYTES);
1087#endif
1088
1089#ifdef REG_PARM_STACK_SPACE
1090 args_size.constant = MAX (args_size.constant,
6f90e075 1091 reg_parm_stack_space);
51bbfa0c 1092#ifndef OUTGOING_REG_PARM_STACK_SPACE
6f90e075 1093 args_size.constant -= reg_parm_stack_space;
51bbfa0c
RS
1094#endif
1095#endif
1096 }
1097
1098 /* See if we have or want to preallocate stack space.
1099
1100 If we would have to push a partially-in-regs parm
1101 before other stack parms, preallocate stack space instead.
1102
1103 If the size of some parm is not a multiple of the required stack
1104 alignment, we must preallocate.
1105
1106 If the total size of arguments that would otherwise create a copy in
1107 a temporary (such as a CALL) is more than half the total argument list
1108 size, preallocation is faster.
1109
1110 Another reason to preallocate is if we have a machine (like the m88k)
1111 where stack alignment is required to be maintained between every
1112 pair of insns, not just when the call is made. However, we assume here
1113 that such machines either do not have push insns (and hence preallocation
1114 would occur anyway) or the problem is taken care of with
1115 PUSH_ROUNDING. */
1116
1117 if (! must_preallocate)
1118 {
1119 int partial_seen = 0;
1120 int copy_to_evaluate_size = 0;
1121
1122 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1123 {
1124 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1125 partial_seen = 1;
1126 else if (partial_seen && args[i].reg == 0)
1127 must_preallocate = 1;
1128
1129 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1130 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1131 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1132 || TREE_CODE (args[i].tree_value) == COND_EXPR
1133 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1134 copy_to_evaluate_size
1135 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1136 }
1137
c62f36cf
RS
1138 if (copy_to_evaluate_size * 2 >= args_size.constant
1139 && args_size.constant > 0)
51bbfa0c
RS
1140 must_preallocate = 1;
1141 }
1142
1143 /* If the structure value address will reference the stack pointer, we must
1144 stabilize it. We don't need to do this if we know that we are not going
1145 to adjust the stack pointer in processing this call. */
1146
1147 if (structure_value_addr
1148 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
1149 || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr))
1150 && (args_size.var
1151#ifndef ACCUMULATE_OUTGOING_ARGS
1152 || args_size.constant
1153#endif
1154 ))
1155 structure_value_addr = copy_to_reg (structure_value_addr);
1156
1157 /* If this function call is cse'able, precompute all the parameters.
1158 Note that if the parameter is constructed into a temporary, this will
1159 cause an additional copy because the parameter will be constructed
1160 into a temporary location and then copied into the outgoing arguments.
1161 If a parameter contains a call to alloca and this function uses the
1162 stack, precompute the parameter. */
1163
1ce0cb53
JW
1164 /* If we preallocated the stack space, and some arguments must be passed
1165 on the stack, then we must precompute any parameter which contains a
1166 function call which will store arguments on the stack.
1167 Otherwise, evaluating the parameter may clobber previous parameters
1168 which have already been stored into the stack. */
1169
51bbfa0c
RS
1170 for (i = 0; i < num_actuals; i++)
1171 if (is_const
1172 || ((args_size.var != 0 || args_size.constant != 0)
1ce0cb53
JW
1173 && calls_function (args[i].tree_value, 1))
1174 || (must_preallocate && (args_size.var != 0 || args_size.constant != 0)
1175 && calls_function (args[i].tree_value, 0)))
51bbfa0c
RS
1176 {
1177 args[i].initial_value = args[i].value
e5d70561 1178 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
51bbfa0c
RS
1179 preserve_temp_slots (args[i].value);
1180 free_temp_slots ();
1181
1182 /* ANSI doesn't require a sequence point here,
1183 but PCC has one, so this will avoid some problems. */
1184 emit_queue ();
1185 }
1186
1187 /* Now we are about to start emitting insns that can be deleted
1188 if a libcall is deleted. */
1189 if (is_const)
1190 start_sequence ();
1191
1192 /* If we have no actual push instructions, or shouldn't use them,
1193 make space for all args right now. */
1194
1195 if (args_size.var != 0)
1196 {
1197 if (old_stack_level == 0)
1198 {
e5d70561 1199 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
51bbfa0c
RS
1200 old_pending_adj = pending_stack_adjust;
1201 pending_stack_adjust = 0;
d64f5a78 1202#ifdef ACCUMULATE_OUTGOING_ARGS
2f4aa534
RS
1203 /* stack_arg_under_construction says whether a stack arg is
1204 being constructed at the old stack level. Pushing the stack
1205 gets a clean outgoing argument block. */
1206 old_stack_arg_under_construction = stack_arg_under_construction;
1207 stack_arg_under_construction = 0;
d64f5a78 1208#endif
51bbfa0c
RS
1209 }
1210 argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
1211 }
1212 else if (must_preallocate)
1213 {
1214 /* Note that we must go through the motions of allocating an argument
1215 block even if the size is zero because we may be storing args
1216 in the area reserved for register arguments, which may be part of
1217 the stack frame. */
1218 int needed = args_size.constant;
1219
1220#ifdef ACCUMULATE_OUTGOING_ARGS
1221 /* Store the maximum argument space used. It will be pushed by the
1222 prologue.
1223
1224 Since the stack pointer will never be pushed, it is possible for
1225 the evaluation of a parm to clobber something we have already
1226 written to the stack. Since most function calls on RISC machines
1227 do not use the stack, this is uncommon, but must work correctly.
1228
1229 Therefore, we save any area of the stack that was already written
1230 and that we are using. Here we set up to do this by making a new
1231 stack usage map from the old one. The actual save will be done
1232 by store_one_arg.
1233
1234 Another approach might be to try to reorder the argument
1235 evaluations to avoid this conflicting stack usage. */
1236
1237 if (needed > current_function_outgoing_args_size)
1238 current_function_outgoing_args_size = needed;
1239
1240#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1241 /* Since we will be writing into the entire argument area, the
1242 map must be allocated for its entire size, not just the part that
1243 is the responsibility of the caller. */
6f90e075 1244 needed += reg_parm_stack_space;
51bbfa0c
RS
1245#endif
1246
1247#ifdef ARGS_GROW_DOWNWARD
1248 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1249 needed + 1);
1250#else
1251 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, needed);
1252#endif
1253 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
1254
1255 if (initial_highest_arg_in_use)
1256 bcopy (initial_stack_usage_map, stack_usage_map,
1257 initial_highest_arg_in_use);
1258
1259 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
1260 bzero (&stack_usage_map[initial_highest_arg_in_use],
1261 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
1262 needed = 0;
2f4aa534 1263
bfbf933a
RS
1264 /* The address of the outgoing argument list must not be copied to a
1265 register here, because argblock would be left pointing to the
1266 wrong place after the call to allocate_dynamic_stack_space below. */
2f4aa534 1267
51bbfa0c 1268 argblock = virtual_outgoing_args_rtx;
2f4aa534 1269
51bbfa0c
RS
1270#else /* not ACCUMULATE_OUTGOING_ARGS */
1271 if (inhibit_defer_pop == 0)
1272 {
1273 /* Try to reuse some or all of the pending_stack_adjust
1274 to get this space. Maybe we can avoid any pushing. */
1275 if (needed > pending_stack_adjust)
1276 {
1277 needed -= pending_stack_adjust;
1278 pending_stack_adjust = 0;
1279 }
1280 else
1281 {
1282 pending_stack_adjust -= needed;
1283 needed = 0;
1284 }
1285 }
1286 /* Special case this because overhead of `push_block' in this
1287 case is non-trivial. */
1288 if (needed == 0)
1289 argblock = virtual_outgoing_args_rtx;
1290 else
e5d70561 1291 argblock = push_block (GEN_INT (needed), 0, 0);
51bbfa0c
RS
1292
1293 /* We only really need to call `copy_to_reg' in the case where push
1294 insns are going to be used to pass ARGBLOCK to a function
1295 call in ARGS. In that case, the stack pointer changes value
1296 from the allocation point to the call point, and hence
1297 the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
1298 But might as well always do it. */
1299 argblock = copy_to_reg (argblock);
1300#endif /* not ACCUMULATE_OUTGOING_ARGS */
1301 }
1302
bfbf933a
RS
1303
1304#ifdef ACCUMULATE_OUTGOING_ARGS
1305 /* The save/restore code in store_one_arg handles all cases except one:
1306 a constructor call (including a C function returning a BLKmode struct)
1307 to initialize an argument. */
1308 if (stack_arg_under_construction)
1309 {
1310#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
e5d70561 1311 rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
bfbf933a 1312#else
e5d70561 1313 rtx push_size = GEN_INT (args_size.constant);
bfbf933a
RS
1314#endif
1315 if (old_stack_level == 0)
1316 {
e5d70561 1317 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
bfbf933a
RS
1318 old_pending_adj = pending_stack_adjust;
1319 pending_stack_adjust = 0;
1320 /* stack_arg_under_construction says whether a stack arg is
1321 being constructed at the old stack level. Pushing the stack
1322 gets a clean outgoing argument block. */
1323 old_stack_arg_under_construction = stack_arg_under_construction;
1324 stack_arg_under_construction = 0;
1325 /* Make a new map for the new argument list. */
1326 stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
1327 bzero (stack_usage_map, highest_outgoing_arg_in_use);
1328 highest_outgoing_arg_in_use = 0;
1329 }
e5d70561 1330 allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
bfbf933a
RS
1331 }
1332 /* If argument evaluation might modify the stack pointer, copy the
1333 address of the argument list to a register. */
1334 for (i = 0; i < num_actuals; i++)
1335 if (args[i].pass_on_stack)
1336 {
1337 argblock = copy_addr_to_reg (argblock);
1338 break;
1339 }
1340#endif
1341
1342
51bbfa0c
RS
1343 /* If we preallocated stack space, compute the address of each argument.
1344 We need not ensure it is a valid memory address here; it will be
1345 validized when it is used. */
1346 if (argblock)
1347 {
1348 rtx arg_reg = argblock;
1349 int arg_offset = 0;
1350
1351 if (GET_CODE (argblock) == PLUS)
1352 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1353
1354 for (i = 0; i < num_actuals; i++)
1355 {
1356 rtx offset = ARGS_SIZE_RTX (args[i].offset);
1357 rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1358 rtx addr;
1359
1360 /* Skip this parm if it will not be passed on the stack. */
1361 if (! args[i].pass_on_stack && args[i].reg != 0)
1362 continue;
1363
1364 if (GET_CODE (offset) == CONST_INT)
1365 addr = plus_constant (arg_reg, INTVAL (offset));
1366 else
1367 addr = gen_rtx (PLUS, Pmode, arg_reg, offset);
1368
1369 addr = plus_constant (addr, arg_offset);
1370 args[i].stack
1371 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (args[i].tree_value)), addr);
1372
1373 if (GET_CODE (slot_offset) == CONST_INT)
1374 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1375 else
1376 addr = gen_rtx (PLUS, Pmode, arg_reg, slot_offset);
1377
1378 addr = plus_constant (addr, arg_offset);
1379 args[i].stack_slot
1380 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (args[i].tree_value)), addr);
1381 }
1382 }
1383
1384#ifdef PUSH_ARGS_REVERSED
1385#ifdef STACK_BOUNDARY
1386 /* If we push args individually in reverse order, perform stack alignment
1387 before the first push (the last arg). */
1388 if (argblock == 0)
e5d70561
RK
1389 anti_adjust_stack (GEN_INT (args_size.constant
1390 - original_args_size.constant));
51bbfa0c
RS
1391#endif
1392#endif
1393
1394 /* Don't try to defer pops if preallocating, not even from the first arg,
1395 since ARGBLOCK probably refers to the SP. */
1396 if (argblock)
1397 NO_DEFER_POP;
1398
1399 /* Get the function to call, in the form of RTL. */
1400 if (fndecl)
1401 /* Get a SYMBOL_REF rtx for the function address. */
1402 funexp = XEXP (DECL_RTL (fndecl), 0);
1403 else
1404 /* Generate an rtx (probably a pseudo-register) for the address. */
1405 {
e5d70561 1406 funexp = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
51bbfa0c
RS
1407 free_temp_slots (); /* FUNEXP can't be BLKmode */
1408 emit_queue ();
1409 }
1410
1411 /* Figure out the register where the value, if any, will come back. */
1412 valreg = 0;
1413 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
1414 && ! structure_value_addr)
1415 {
1416 if (pcc_struct_value)
1417 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
1418 fndecl);
1419 else
1420 valreg = hard_function_value (TREE_TYPE (exp), fndecl);
1421 }
1422
1423 /* Precompute all register parameters. It isn't safe to compute anything
1424 once we have started filling any specific hard regs. */
1425 reg_parm_seen = 0;
1426 for (i = 0; i < num_actuals; i++)
1427 if (args[i].reg != 0 && ! args[i].pass_on_stack)
1428 {
84b55618
RK
1429 enum machine_mode mode;
1430
51bbfa0c
RS
1431 reg_parm_seen = 1;
1432
1433 if (args[i].value == 0)
1434 {
e5d70561
RK
1435 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
1436 VOIDmode, 0);
51bbfa0c
RS
1437 preserve_temp_slots (args[i].value);
1438 free_temp_slots ();
1439
1440 /* ANSI doesn't require a sequence point here,
1441 but PCC has one, so this will avoid some problems. */
1442 emit_queue ();
1443 }
84b55618
RK
1444
1445 /* If we are to promote the function arg to a wider mode,
1446 do it now. */
1447 mode = (GET_CODE (args[i].reg) == EXPR_LIST
1448 ? GET_MODE (XEXP (args[i].reg, 0)) : GET_MODE (args[i].reg));
1449
1709c754 1450 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != mode)
84b55618
RK
1451 args[i].value = convert_to_mode (mode, args[i].value,
1452 args[i].unsignedp);
51bbfa0c
RS
1453 }
1454
1455#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1456 /* The argument list is the property of the called routine and it
1457 may clobber it. If the fixed area has been used for previous
1458 parameters, we must save and restore it.
1459
1460 Here we compute the boundary of the that needs to be saved, if any. */
1461
b94301c2
RS
1462#ifdef ARGS_GROW_DOWNWARD
1463 for (i = 0; i < reg_parm_stack_space + 1; i++)
1464#else
6f90e075 1465 for (i = 0; i < reg_parm_stack_space; i++)
b94301c2 1466#endif
51bbfa0c
RS
1467 {
1468 if (i >= highest_outgoing_arg_in_use
1469 || stack_usage_map[i] == 0)
1470 continue;
1471
1472 if (low_to_save == -1)
1473 low_to_save = i;
1474
1475 high_to_save = i;
1476 }
1477
1478 if (low_to_save >= 0)
1479 {
1480 int num_to_save = high_to_save - low_to_save + 1;
1481 enum machine_mode save_mode
1482 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
1483 rtx stack_area;
1484
1485 /* If we don't have the required alignment, must do this in BLKmode. */
1486 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
1487 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
1488 save_mode = BLKmode;
1489
1490 stack_area = gen_rtx (MEM, save_mode,
1491 memory_address (save_mode,
b94301c2
RS
1492
1493#ifdef ARGS_GROW_DOWNWARD
1494 plus_constant (argblock,
1495 - high_to_save)
1496#else
51bbfa0c 1497 plus_constant (argblock,
b94301c2
RS
1498 low_to_save)
1499#endif
1500 ));
51bbfa0c
RS
1501 if (save_mode == BLKmode)
1502 {
1503 save_area = assign_stack_temp (BLKmode, num_to_save, 1);
1504 emit_block_move (validize_mem (save_area), stack_area,
e5d70561 1505 GEN_INT (num_to_save),
51bbfa0c
RS
1506 PARM_BOUNDARY / BITS_PER_UNIT);
1507 }
1508 else
1509 {
1510 save_area = gen_reg_rtx (save_mode);
1511 emit_move_insn (save_area, stack_area);
1512 }
1513 }
1514#endif
1515
1516
1517 /* Now store (and compute if necessary) all non-register parms.
1518 These come before register parms, since they can require block-moves,
1519 which could clobber the registers used for register parms.
1520 Parms which have partial registers are not stored here,
1521 but we do preallocate space here if they want that. */
1522
1523 for (i = 0; i < num_actuals; i++)
1524 if (args[i].reg == 0 || args[i].pass_on_stack)
1525 store_one_arg (&args[i], argblock, may_be_alloca,
6f90e075 1526 args_size.var != 0, fndecl, reg_parm_stack_space);
51bbfa0c
RS
1527
1528 /* Now store any partially-in-registers parm.
1529 This is the last place a block-move can happen. */
1530 if (reg_parm_seen)
1531 for (i = 0; i < num_actuals; i++)
1532 if (args[i].partial != 0 && ! args[i].pass_on_stack)
1533 store_one_arg (&args[i], argblock, may_be_alloca,
6f90e075 1534 args_size.var != 0, fndecl, reg_parm_stack_space);
51bbfa0c
RS
1535
1536#ifndef PUSH_ARGS_REVERSED
1537#ifdef STACK_BOUNDARY
1538 /* If we pushed args in forward order, perform stack alignment
1539 after pushing the last arg. */
1540 if (argblock == 0)
e5d70561
RK
1541 anti_adjust_stack (GEN_INT (args_size.constant
1542 - original_args_size.constant));
51bbfa0c
RS
1543#endif
1544#endif
1545
756e0e12
RS
1546 /* If register arguments require space on the stack and stack space
1547 was not preallocated, allocate stack space here for arguments
1548 passed in registers. */
1549#if ! defined(ALLOCATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
1550 if (must_preallocate == 0 && reg_parm_stack_space > 0)
e5d70561 1551 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
756e0e12
RS
1552#endif
1553
51bbfa0c
RS
1554 /* Pass the function the address in which to return a structure value. */
1555 if (structure_value_addr && ! structure_value_addr_parm)
1556 {
1557 emit_move_insn (struct_value_rtx,
1558 force_reg (Pmode,
e5d70561
RK
1559 force_operand (structure_value_addr,
1560 NULL_RTX)));
51bbfa0c
RS
1561 if (GET_CODE (struct_value_rtx) == REG)
1562 {
1563 push_to_sequence (use_insns);
1564 emit_insn (gen_rtx (USE, VOIDmode, struct_value_rtx));
1565 use_insns = get_insns ();
1566 end_sequence ();
1567 }
1568 }
1569
1570 /* Now do the register loads required for any wholly-register parms or any
1571 parms which are passed both on the stack and in a register. Their
1572 expressions were already evaluated.
1573
1574 Mark all register-parms as living through the call, putting these USE
1575 insns in a list headed by USE_INSNS. */
1576
1577 for (i = 0; i < num_actuals; i++)
1578 {
1579 rtx list = args[i].reg;
1580 int partial = args[i].partial;
1581
1582 while (list)
1583 {
1584 rtx reg;
1585 int nregs;
1586
1587 /* Process each register that needs to get this arg. */
1588 if (GET_CODE (list) == EXPR_LIST)
1589 reg = XEXP (list, 0), list = XEXP (list, 1);
1590 else
1591 reg = list, list = 0;
1592
1593 /* Set to non-zero if must move a word at a time, even if just one
1594 word (e.g, partial == 1 && mode == DFmode). Set to zero if
1595 we just use a normal move insn. */
1596 nregs = (partial ? partial
1597 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1598 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1599 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1600 : 0));
1601
1602 /* If simple case, just do move. If normal partial, store_one_arg
1603 has already loaded the register for us. In all other cases,
1604 load the register(s) from memory. */
1605
1606 if (nregs == 0)
1607 emit_move_insn (reg, args[i].value);
1608 else if (args[i].partial == 0 || args[i].pass_on_stack)
1609 move_block_to_reg (REGNO (reg),
1610 validize_mem (args[i].value), nregs,
1611 TYPE_MODE (TREE_TYPE (args[i].tree_value)));
1612
1613 push_to_sequence (use_insns);
1614 if (nregs == 0)
1615 emit_insn (gen_rtx (USE, VOIDmode, reg));
1616 else
1617 use_regs (REGNO (reg), nregs);
1618 use_insns = get_insns ();
1619 end_sequence ();
1620
1621 /* PARTIAL referred only to the first register, so clear it for the
1622 next time. */
1623 partial = 0;
1624 }
1625 }
1626
1627 /* Perform postincrements before actually calling the function. */
1628 emit_queue ();
1629
1630 /* All arguments and registers used for the call must be set up by now! */
1631
1632 funexp = prepare_call_address (funexp, fndecl, &use_insns);
1633
1634 /* Generate the actual call instruction. */
1635 emit_call_1 (funexp, funtype, args_size.constant, struct_value_size,
1636 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
1637 valreg, old_inhibit_defer_pop, use_insns, is_const);
1638
1639 /* If call is cse'able, make appropriate pair of reg-notes around it.
1640 Test valreg so we don't crash; may safely ignore `const'
1641 if return type is void. */
1642 if (is_const && valreg != 0)
1643 {
1644 rtx note = 0;
1645 rtx temp = gen_reg_rtx (GET_MODE (valreg));
1646 rtx insns;
1647
1648 /* Construct an "equal form" for the value which mentions all the
1649 arguments in order as well as the function name. */
1650#ifdef PUSH_ARGS_REVERSED
1651 for (i = 0; i < num_actuals; i++)
1652 note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1653#else
1654 for (i = num_actuals - 1; i >= 0; i--)
1655 note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1656#endif
1657 note = gen_rtx (EXPR_LIST, VOIDmode, funexp, note);
1658
1659 insns = get_insns ();
1660 end_sequence ();
1661
1662 emit_libcall_block (insns, temp, valreg, note);
1663
1664 valreg = temp;
1665 }
1666
1667 /* For calls to `setjmp', etc., inform flow.c it should complain
1668 if nonvolatile values are live. */
1669
1670 if (returns_twice)
1671 {
1672 emit_note (name, NOTE_INSN_SETJMP);
1673 current_function_calls_setjmp = 1;
1674 }
1675
1676 if (is_longjmp)
1677 current_function_calls_longjmp = 1;
1678
1679 /* Notice functions that cannot return.
1680 If optimizing, insns emitted below will be dead.
1681 If not optimizing, they will exist, which is useful
1682 if the user uses the `return' command in the debugger. */
1683
1684 if (is_volatile || is_longjmp)
1685 emit_barrier ();
1686
51bbfa0c
RS
1687 /* If value type not void, return an rtx for the value. */
1688
1689 /* If there are cleanups to be called, don't use a hard reg as target. */
1690 if (cleanups_this_call != old_cleanups
1691 && target && REG_P (target)
1692 && REGNO (target) < FIRST_PSEUDO_REGISTER)
1693 target = 0;
1694
1695 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
1696 || ignore)
1697 {
1698 target = const0_rtx;
1699 }
1700 else if (structure_value_addr)
1701 {
1702 if (target == 0 || GET_CODE (target) != MEM)
29008b51
JW
1703 {
1704 target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1705 memory_address (TYPE_MODE (TREE_TYPE (exp)),
1706 structure_value_addr));
1707 MEM_IN_STRUCT_P (target)
1708 = (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1709 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
1710 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE);
1711 }
51bbfa0c
RS
1712 }
1713 else if (pcc_struct_value)
1714 {
1715 if (target == 0)
29008b51
JW
1716 {
1717 target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1718 copy_to_reg (valreg));
1719 MEM_IN_STRUCT_P (target)
1720 = (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1721 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
1722 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE);
1723 }
51bbfa0c
RS
1724 else if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
1725 emit_move_insn (target, gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1726 copy_to_reg (valreg)));
1727 else
1728 emit_block_move (target, gen_rtx (MEM, BLKmode, copy_to_reg (valreg)),
1729 expr_size (exp),
1730 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
1731 }
84b55618
RK
1732 else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
1733 && GET_MODE (target) == GET_MODE (valreg))
51bbfa0c
RS
1734 /* TARGET and VALREG cannot be equal at this point because the latter
1735 would not have REG_FUNCTION_VALUE_P true, while the former would if
1736 it were referring to the same register.
1737
1738 If they refer to the same register, this move will be a no-op, except
1739 when function inlining is being done. */
1740 emit_move_insn (target, valreg);
1741 else
1742 target = copy_to_reg (valreg);
1743
84b55618
RK
1744#ifdef PROMOTE_FUNCTION_RETURN
1745 /* If we promoted this return value, make the proper SUBREG. */
1746 if (GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
1747 {
1748 enum machine_mode mode = GET_MODE (target);
1749 int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
1750
1751 if (TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE
1752 || TREE_CODE (TREE_TYPE (exp)) == ENUMERAL_TYPE
1753 || TREE_CODE (TREE_TYPE (exp)) == BOOLEAN_TYPE
1754 || TREE_CODE (TREE_TYPE (exp)) == CHAR_TYPE
1755 || TREE_CODE (TREE_TYPE (exp)) == REAL_TYPE
1756 || TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE
1757 || TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE)
1758 {
1759 PROMOTE_MODE (mode, unsignedp, TREE_TYPE (exp));
1760 }
1761
1762 target = gen_rtx (SUBREG, TYPE_MODE (TREE_TYPE (exp)), target, 0);
1763 SUBREG_PROMOTED_VAR_P (target) = 1;
1764 SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
1765 }
1766#endif
1767
51bbfa0c
RS
1768 /* Perform all cleanups needed for the arguments of this call
1769 (i.e. destructors in C++). */
1770 expand_cleanups_to (old_cleanups);
1771
2f4aa534
RS
1772 /* If size of args is variable or this was a constructor call for a stack
1773 argument, restore saved stack-pointer value. */
51bbfa0c
RS
1774
1775 if (old_stack_level)
1776 {
e5d70561 1777 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
51bbfa0c 1778 pending_stack_adjust = old_pending_adj;
d64f5a78 1779#ifdef ACCUMULATE_OUTGOING_ARGS
2f4aa534
RS
1780 stack_arg_under_construction = old_stack_arg_under_construction;
1781 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
1782 stack_usage_map = initial_stack_usage_map;
d64f5a78 1783#endif
51bbfa0c 1784 }
51bbfa0c
RS
1785#ifdef ACCUMULATE_OUTGOING_ARGS
1786 else
1787 {
1788#ifdef REG_PARM_STACK_SPACE
1789 if (save_area)
1790 {
1791 enum machine_mode save_mode = GET_MODE (save_area);
1792 rtx stack_area
1793 = gen_rtx (MEM, save_mode,
1794 memory_address (save_mode,
b94301c2
RS
1795#ifdef ARGS_GROW_DOWNWARD
1796 plus_constant (argblock, - high_to_save)
1797#else
1798 plus_constant (argblock, low_to_save)
1799#endif
1800 ));
51bbfa0c
RS
1801
1802 if (save_mode != BLKmode)
1803 emit_move_insn (stack_area, save_area);
1804 else
1805 emit_block_move (stack_area, validize_mem (save_area),
e5d70561
RK
1806 GEN_INT (high_to_save - low_to_save + 1),
1807 PARM_BOUNDARY / BITS_PER_UNIT);
51bbfa0c
RS
1808 }
1809#endif
1810
1811 /* If we saved any argument areas, restore them. */
1812 for (i = 0; i < num_actuals; i++)
1813 if (args[i].save_area)
1814 {
1815 enum machine_mode save_mode = GET_MODE (args[i].save_area);
1816 rtx stack_area
1817 = gen_rtx (MEM, save_mode,
1818 memory_address (save_mode,
1819 XEXP (args[i].stack_slot, 0)));
1820
1821 if (save_mode != BLKmode)
1822 emit_move_insn (stack_area, args[i].save_area);
1823 else
1824 emit_block_move (stack_area, validize_mem (args[i].save_area),
e5d70561 1825 GEN_INT (args[i].size.constant),
51bbfa0c
RS
1826 PARM_BOUNDARY / BITS_PER_UNIT);
1827 }
1828
1829 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
1830 stack_usage_map = initial_stack_usage_map;
1831 }
1832#endif
1833
59257ff7
RK
1834 /* If this was alloca, record the new stack level for nonlocal gotos.
1835 Check for the handler slots since we might not have a save area
1836 for non-local gotos. */
1837
1838 if (may_be_alloca && nonlocal_goto_handler_slot != 0)
e5d70561 1839 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
51bbfa0c
RS
1840
1841 pop_temp_slots ();
1842
1843 return target;
1844}
1845\f
1846#if 0
1847/* Return an rtx which represents a suitable home on the stack
1848 given TYPE, the type of the argument looking for a home.
1849 This is called only for BLKmode arguments.
1850
1851 SIZE is the size needed for this target.
1852 ARGS_ADDR is the address of the bottom of the argument block for this call.
1853 OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
1854 if this machine uses push insns. */
1855
1856static rtx
1857target_for_arg (type, size, args_addr, offset)
1858 tree type;
1859 rtx size;
1860 rtx args_addr;
1861 struct args_size offset;
1862{
1863 rtx target;
1864 rtx offset_rtx = ARGS_SIZE_RTX (offset);
1865
1866 /* We do not call memory_address if possible,
1867 because we want to address as close to the stack
1868 as possible. For non-variable sized arguments,
1869 this will be stack-pointer relative addressing. */
1870 if (GET_CODE (offset_rtx) == CONST_INT)
1871 target = plus_constant (args_addr, INTVAL (offset_rtx));
1872 else
1873 {
1874 /* I have no idea how to guarantee that this
1875 will work in the presence of register parameters. */
1876 target = gen_rtx (PLUS, Pmode, args_addr, offset_rtx);
1877 target = memory_address (QImode, target);
1878 }
1879
1880 return gen_rtx (MEM, BLKmode, target);
1881}
1882#endif
1883\f
1884/* Store a single argument for a function call
1885 into the register or memory area where it must be passed.
1886 *ARG describes the argument value and where to pass it.
1887
1888 ARGBLOCK is the address of the stack-block for all the arguments,
d45cf215 1889 or 0 on a machine where arguments are pushed individually.
51bbfa0c
RS
1890
1891 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
1892 so must be careful about how the stack is used.
1893
1894 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
1895 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
1896 that we need not worry about saving and restoring the stack.
1897
1898 FNDECL is the declaration of the function we are calling. */
1899
1900static void
6f90e075
JW
1901store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl,
1902 reg_parm_stack_space)
51bbfa0c
RS
1903 struct arg_data *arg;
1904 rtx argblock;
1905 int may_be_alloca;
1906 int variable_size;
1907 tree fndecl;
6f90e075 1908 int reg_parm_stack_space;
51bbfa0c
RS
1909{
1910 register tree pval = arg->tree_value;
1911 rtx reg = 0;
1912 int partial = 0;
1913 int used = 0;
1914 int i, lower_bound, upper_bound;
1915
1916 if (TREE_CODE (pval) == ERROR_MARK)
1917 return;
1918
1919#ifdef ACCUMULATE_OUTGOING_ARGS
1920 /* If this is being stored into a pre-allocated, fixed-size, stack area,
1921 save any previous data at that location. */
1922 if (argblock && ! variable_size && arg->stack)
1923 {
1924#ifdef ARGS_GROW_DOWNWARD
1925 /* stack_slot is negative, but we want to index stack_usage_map */
1926 /* with positive values. */
1927 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
1928 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
1929 else
1930 abort ();
1931
1932 lower_bound = upper_bound - arg->size.constant;
1933#else
1934 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
1935 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
1936 else
1937 lower_bound = 0;
1938
1939 upper_bound = lower_bound + arg->size.constant;
1940#endif
1941
1942 for (i = lower_bound; i < upper_bound; i++)
1943 if (stack_usage_map[i]
1944#ifdef REG_PARM_STACK_SPACE
1945 /* Don't store things in the fixed argument area at this point;
1946 it has already been saved. */
6f90e075 1947 && i > reg_parm_stack_space
51bbfa0c
RS
1948#endif
1949 )
1950 break;
1951
1952 if (i != upper_bound)
1953 {
1954 /* We need to make a save area. See what mode we can make it. */
1955 enum machine_mode save_mode
1956 = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
1957 rtx stack_area
1958 = gen_rtx (MEM, save_mode,
1959 memory_address (save_mode, XEXP (arg->stack_slot, 0)));
1960
1961 if (save_mode == BLKmode)
1962 {
1963 arg->save_area = assign_stack_temp (BLKmode,
1964 arg->size.constant, 1);
1965 emit_block_move (validize_mem (arg->save_area), stack_area,
e5d70561 1966 GEN_INT (arg->size.constant),
51bbfa0c
RS
1967 PARM_BOUNDARY / BITS_PER_UNIT);
1968 }
1969 else
1970 {
1971 arg->save_area = gen_reg_rtx (save_mode);
1972 emit_move_insn (arg->save_area, stack_area);
1973 }
1974 }
1975 }
1976#endif
1977
1978 /* If this isn't going to be placed on both the stack and in registers,
1979 set up the register and number of words. */
1980 if (! arg->pass_on_stack)
1981 reg = arg->reg, partial = arg->partial;
1982
1983 if (reg != 0 && partial == 0)
1984 /* Being passed entirely in a register. We shouldn't be called in
1985 this case. */
1986 abort ();
1987
1988 /* If this is being partially passed in a register, but multiple locations
1989 are specified, we assume that the one partially used is the one that is
1990 listed first. */
1991 if (reg && GET_CODE (reg) == EXPR_LIST)
1992 reg = XEXP (reg, 0);
1993
1994 /* If this is being passes partially in a register, we can't evaluate
1995 it directly into its stack slot. Otherwise, we can. */
1996 if (arg->value == 0)
d64f5a78
RS
1997 {
1998#ifdef ACCUMULATE_OUTGOING_ARGS
1999 /* stack_arg_under_construction is nonzero if a function argument is
2000 being evaluated directly into the outgoing argument list and
2001 expand_call must take special action to preserve the argument list
2002 if it is called recursively.
2003
2004 For scalar function arguments stack_usage_map is sufficient to
2005 determine which stack slots must be saved and restored. Scalar
2006 arguments in general have pass_on_stack == 0.
2007
2008 If this argument is initialized by a function which takes the
2009 address of the argument (a C++ constructor or a C function
2010 returning a BLKmode structure), then stack_usage_map is
2011 insufficient and expand_call must push the stack around the
2012 function call. Such arguments have pass_on_stack == 1.
2013
2014 Note that it is always safe to set stack_arg_under_construction,
2015 but this generates suboptimal code if set when not needed. */
2016
2017 if (arg->pass_on_stack)
2018 stack_arg_under_construction++;
2019#endif
e5d70561
RK
2020 arg->value = expand_expr (pval, partial ? NULL_RTX : arg->stack,
2021 VOIDmode, 0);
d64f5a78
RS
2022#ifdef ACCUMULATE_OUTGOING_ARGS
2023 if (arg->pass_on_stack)
2024 stack_arg_under_construction--;
2025#endif
2026 }
51bbfa0c
RS
2027
2028 /* Don't allow anything left on stack from computation
2029 of argument to alloca. */
2030 if (may_be_alloca)
2031 do_pending_stack_adjust ();
2032
2033 if (arg->value == arg->stack)
2034 /* If the value is already in the stack slot, we are done. */
2035 ;
2036 else if (TYPE_MODE (TREE_TYPE (pval)) != BLKmode)
2037 {
2038 register int size;
2039
2040 /* Argument is a scalar, not entirely passed in registers.
2041 (If part is passed in registers, arg->partial says how much
2042 and emit_push_insn will take care of putting it there.)
2043
2044 Push it, and if its size is less than the
2045 amount of space allocated to it,
2046 also bump stack pointer by the additional space.
2047 Note that in C the default argument promotions
2048 will prevent such mismatches. */
2049
2050 size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (pval)));
2051 /* Compute how much space the push instruction will push.
2052 On many machines, pushing a byte will advance the stack
2053 pointer by a halfword. */
2054#ifdef PUSH_ROUNDING
2055 size = PUSH_ROUNDING (size);
2056#endif
2057 used = size;
2058
2059 /* Compute how much space the argument should get:
2060 round up to a multiple of the alignment for arguments. */
2061 if (none != FUNCTION_ARG_PADDING (TYPE_MODE (TREE_TYPE (pval)),
2062 TREE_TYPE (pval)))
2063 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
2064 / (PARM_BOUNDARY / BITS_PER_UNIT))
2065 * (PARM_BOUNDARY / BITS_PER_UNIT));
2066
2067 /* This isn't already where we want it on the stack, so put it there.
2068 This can either be done with push or copy insns. */
2069 emit_push_insn (arg->value, TYPE_MODE (TREE_TYPE (pval)),
2070 TREE_TYPE (pval), 0, 0, partial, reg,
2071 used - size, argblock, ARGS_SIZE_RTX (arg->offset));
2072 }
2073 else
2074 {
2075 /* BLKmode, at least partly to be pushed. */
2076
2077 register int excess;
2078 rtx size_rtx;
2079
2080 /* Pushing a nonscalar.
2081 If part is passed in registers, PARTIAL says how much
2082 and emit_push_insn will take care of putting it there. */
2083
2084 /* Round its size up to a multiple
2085 of the allocation unit for arguments. */
2086
2087 if (arg->size.var != 0)
2088 {
2089 excess = 0;
2090 size_rtx = ARGS_SIZE_RTX (arg->size);
2091 }
2092 else
2093 {
2094 register tree size = size_in_bytes (TREE_TYPE (pval));
2095 /* PUSH_ROUNDING has no effect on us, because
2096 emit_push_insn for BLKmode is careful to avoid it. */
2097 excess = (arg->size.constant - TREE_INT_CST_LOW (size)
2098 + partial * UNITS_PER_WORD);
e5d70561 2099 size_rtx = expand_expr (size, NULL_RTX, VOIDmode, 0);
51bbfa0c
RS
2100 }
2101
2102 emit_push_insn (arg->value, TYPE_MODE (TREE_TYPE (pval)),
2103 TREE_TYPE (pval), size_rtx,
2104 TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
2105 reg, excess, argblock, ARGS_SIZE_RTX (arg->offset));
2106 }
2107
2108
2109 /* Unless this is a partially-in-register argument, the argument is now
2110 in the stack.
2111
2112 ??? Note that this can change arg->value from arg->stack to
2113 arg->stack_slot and it matters when they are not the same.
2114 It isn't totally clear that this is correct in all cases. */
2115 if (partial == 0)
2116 arg->value = arg->stack_slot;
2117
2118 /* Once we have pushed something, pops can't safely
2119 be deferred during the rest of the arguments. */
2120 NO_DEFER_POP;
2121
2122 /* ANSI doesn't require a sequence point here,
2123 but PCC has one, so this will avoid some problems. */
2124 emit_queue ();
2125
2126 /* Free any temporary slots made in processing this argument. */
2127 free_temp_slots ();
2128
2129#ifdef ACCUMULATE_OUTGOING_ARGS
2130 /* Now mark the segment we just used. */
2131 if (argblock && ! variable_size && arg->stack)
2132 for (i = lower_bound; i < upper_bound; i++)
2133 stack_usage_map[i] = 1;
2134#endif
2135}