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