OSDN Git Service

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