OSDN Git Service

* calls.c (expand_call): Don't bother generating tail call
[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, 1995, 1996, 1997, 1998
3    1999, 2000 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "rtl.h"
25 #include "tree.h"
26 #include "flags.h"
27 #include "expr.h"
28 #include "function.h"
29 #include "regs.h"
30 #include "insn-flags.h"
31 #include "toplev.h"
32 #include "output.h"
33 #include "tm_p.h"
34
35 #if !defined FUNCTION_OK_FOR_SIBCALL
36 #define FUNCTION_OK_FOR_SIBCALL(DECL) 1
37 #endif
38
39 #if !defined PREFERRED_STACK_BOUNDARY && defined STACK_BOUNDARY
40 #define PREFERRED_STACK_BOUNDARY STACK_BOUNDARY
41 #endif
42
43 /* Decide whether a function's arguments should be processed
44    from first to last or from last to first.
45
46    They should if the stack and args grow in opposite directions, but
47    only if we have push insns.  */
48
49 #ifdef PUSH_ROUNDING
50
51 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
52 #define PUSH_ARGS_REVERSED      /* If it's last to first */
53 #endif
54
55 #endif
56
57 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits.  */
58 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
59
60 /* Data structure and subroutines used within expand_call.  */
61
62 struct arg_data
63 {
64   /* Tree node for this argument.  */
65   tree tree_value;
66   /* Mode for value; TYPE_MODE unless promoted.  */
67   enum machine_mode mode;
68   /* Current RTL value for argument, or 0 if it isn't precomputed.  */
69   rtx value;
70   /* Initially-compute RTL value for argument; only for const functions.  */
71   rtx initial_value;
72   /* Register to pass this argument in, 0 if passed on stack, or an
73      PARALLEL if the arg is to be copied into multiple non-contiguous
74      registers.  */
75   rtx reg;
76   /* If REG was promoted from the actual mode of the argument expression,
77      indicates whether the promotion is sign- or zero-extended.  */
78   int unsignedp;
79   /* Number of registers to use.  0 means put the whole arg in registers.
80      Also 0 if not passed in registers.  */
81   int partial;
82   /* Non-zero if argument must be passed on stack.
83      Note that some arguments may be passed on the stack
84      even though pass_on_stack is zero, just because FUNCTION_ARG says so.
85      pass_on_stack identifies arguments that *cannot* go in registers.  */
86   int pass_on_stack;
87   /* Offset of this argument from beginning of stack-args.  */
88   struct args_size offset;
89   /* Similar, but offset to the start of the stack slot.  Different from
90      OFFSET if this arg pads downward.  */
91   struct args_size slot_offset;
92   /* Size of this argument on the stack, rounded up for any padding it gets,
93      parts of the argument passed in registers do not count.
94      If REG_PARM_STACK_SPACE is defined, then register parms
95      are counted here as well.  */
96   struct args_size size;
97   /* Location on the stack at which parameter should be stored.  The store
98      has already been done if STACK == VALUE.  */
99   rtx stack;
100   /* Location on the stack of the start of this argument slot.  This can
101      differ from STACK if this arg pads downward.  This location is known
102      to be aligned to FUNCTION_ARG_BOUNDARY.  */
103   rtx stack_slot;
104 #ifdef ACCUMULATE_OUTGOING_ARGS
105   /* Place that this stack area has been saved, if needed.  */
106   rtx save_area;
107 #endif
108   /* If an argument's alignment does not permit direct copying into registers,
109      copy in smaller-sized pieces into pseudos.  These are stored in a
110      block pointed to by this field.  The next field says how many
111      word-sized pseudos we made.  */
112   rtx *aligned_regs;
113   int n_aligned_regs;
114   /* The amount that the stack pointer needs to be adjusted to
115      force alignment for the next argument.  */
116   struct args_size alignment_pad;
117 };
118
119 #ifdef ACCUMULATE_OUTGOING_ARGS
120 /* A vector of one char per byte of stack space.  A byte if non-zero if
121    the corresponding stack location has been used.
122    This vector is used to prevent a function call within an argument from
123    clobbering any stack already set up.  */
124 static char *stack_usage_map;
125
126 /* Size of STACK_USAGE_MAP.  */
127 static int highest_outgoing_arg_in_use;
128
129 /* stack_arg_under_construction is nonzero when an argument may be
130    initialized with a constructor call (including a C function that
131    returns a BLKmode struct) and expand_call must take special action
132    to make sure the object being constructed does not overlap the
133    argument list for the constructor call.  */
134 int stack_arg_under_construction;
135 #endif
136
137 static int calls_function       PARAMS ((tree, int));
138 static int calls_function_1     PARAMS ((tree, int));
139
140 #define ECF_IS_CONST            1
141 #define ECF_NOTHROW             2
142 #define ECF_SIBCALL             4
143 static void emit_call_1         PARAMS ((rtx, tree, tree, HOST_WIDE_INT,
144                                          HOST_WIDE_INT, HOST_WIDE_INT, rtx,
145                                          rtx, int, rtx, int));
146 static void precompute_register_parameters      PARAMS ((int,
147                                                          struct arg_data *,
148                                                          int *));
149 static void store_one_arg       PARAMS ((struct arg_data *, rtx, int, int,
150                                          int));
151 static void store_unaligned_arguments_into_pseudos PARAMS ((struct arg_data *,
152                                                             int));
153 static int finalize_must_preallocate            PARAMS ((int, int,
154                                                          struct arg_data *,
155                                                          struct args_size *));
156 static void precompute_arguments                PARAMS ((int, int, int,
157                                                          struct arg_data *,
158                                                          struct args_size *));
159 static int compute_argument_block_size          PARAMS ((int, 
160                                                          struct args_size *,
161                                                          int));
162 static void initialize_argument_information     PARAMS ((int,
163                                                          struct arg_data *,
164                                                          struct args_size *,
165                                                          int, tree, tree,
166                                                          CUMULATIVE_ARGS *,
167                                                          int, rtx *, int *,
168                                                          int *, int *));
169 static void compute_argument_addresses          PARAMS ((struct arg_data *,
170                                                          rtx, int));
171 static rtx rtx_for_function_call                PARAMS ((tree, tree));
172 static void load_register_parameters            PARAMS ((struct arg_data *,
173                                                          int, rtx *));
174 static int libfunc_nothrow                      PARAMS ((rtx));
175
176 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
177 static rtx save_fixed_argument_area     PARAMS ((int, rtx, int *, int *));
178 static void restore_fixed_argument_area PARAMS ((rtx, rtx, int, int));
179 #endif
180 \f
181 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
182    `alloca'.
183
184    If WHICH is 0, return 1 if EXP contains a call to any function.
185    Actually, we only need return 1 if evaluating EXP would require pushing
186    arguments on the stack, but that is too difficult to compute, so we just
187    assume any function call might require the stack.  */
188
189 static tree calls_function_save_exprs;
190
191 static int
192 calls_function (exp, which)
193      tree exp;
194      int which;
195 {
196   int val;
197   calls_function_save_exprs = 0;
198   val = calls_function_1 (exp, which);
199   calls_function_save_exprs = 0;
200   return val;
201 }
202
203 static int
204 calls_function_1 (exp, which)
205      tree exp;
206      int which;
207 {
208   register int i;
209   enum tree_code code = TREE_CODE (exp);
210   int type = TREE_CODE_CLASS (code);
211   int length = tree_code_length[(int) code];
212
213   /* If this code is language-specific, we don't know what it will do.  */
214   if ((int) code >= NUM_TREE_CODES)
215     return 1;
216
217   /* Only expressions and references can contain calls.  */
218   if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
219       && type != 'b')
220     return 0;
221
222   switch (code)
223     {
224     case CALL_EXPR:
225       if (which == 0)
226         return 1;
227       else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
228                && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
229                    == FUNCTION_DECL))
230         {
231           tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
232
233           if ((DECL_BUILT_IN (fndecl)
234                && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
235                && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA)
236               || (DECL_SAVED_INSNS (fndecl)
237                   && DECL_SAVED_INSNS (fndecl)->calls_alloca))
238             return 1;
239         }
240
241       /* Third operand is RTL.  */
242       length = 2;
243       break;
244
245     case SAVE_EXPR:
246       if (SAVE_EXPR_RTL (exp) != 0)
247         return 0;
248       if (value_member (exp, calls_function_save_exprs))
249         return 0;
250       calls_function_save_exprs = tree_cons (NULL_TREE, exp,
251                                              calls_function_save_exprs);
252       return (TREE_OPERAND (exp, 0) != 0
253               && calls_function_1 (TREE_OPERAND (exp, 0), which));
254
255     case BLOCK:
256       {
257         register tree local;
258
259         for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
260           if (DECL_INITIAL (local) != 0
261               && calls_function_1 (DECL_INITIAL (local), which))
262             return 1;
263       }
264       {
265         register tree subblock;
266
267         for (subblock = BLOCK_SUBBLOCKS (exp);
268              subblock;
269              subblock = TREE_CHAIN (subblock))
270           if (calls_function_1 (subblock, which))
271             return 1;
272       }
273       return 0;
274
275     case METHOD_CALL_EXPR:
276       length = 3;
277       break;
278
279     case WITH_CLEANUP_EXPR:
280       length = 1;
281       break;
282
283     case RTL_EXPR:
284       return 0;
285       
286     default:
287       break;
288     }
289
290   for (i = 0; i < length; i++)
291     if (TREE_OPERAND (exp, i) != 0
292         && calls_function_1 (TREE_OPERAND (exp, i), which))
293       return 1;
294
295   return 0;
296 }
297 \f
298 /* Force FUNEXP into a form suitable for the address of a CALL,
299    and return that as an rtx.  Also load the static chain register
300    if FNDECL is a nested function.
301
302    CALL_FUSAGE points to a variable holding the prospective
303    CALL_INSN_FUNCTION_USAGE information.  */
304
305 rtx
306 prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen)
307      rtx funexp;
308      tree fndecl;
309      rtx *call_fusage;
310      int reg_parm_seen;
311 {
312   rtx static_chain_value = 0;
313
314   funexp = protect_from_queue (funexp, 0);
315
316   if (fndecl != 0)
317     /* Get possible static chain value for nested function in C.  */
318     static_chain_value = lookup_static_chain (fndecl);
319
320   /* Make a valid memory address and copy constants thru pseudo-regs,
321      but not for a constant address if -fno-function-cse.  */
322   if (GET_CODE (funexp) != SYMBOL_REF)
323     /* If we are using registers for parameters, force the
324        function address into a register now.  */
325     funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
326               ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
327               : memory_address (FUNCTION_MODE, funexp));
328   else
329     {
330 #ifndef NO_FUNCTION_CSE
331       if (optimize && ! flag_no_function_cse)
332 #ifdef NO_RECURSIVE_FUNCTION_CSE
333         if (fndecl != current_function_decl)
334 #endif
335           funexp = force_reg (Pmode, funexp);
336 #endif
337     }
338
339   if (static_chain_value != 0)
340     {
341       emit_move_insn (static_chain_rtx, static_chain_value);
342
343       if (GET_CODE (static_chain_rtx) == REG)
344         use_reg (call_fusage, static_chain_rtx);
345     }
346
347   return funexp;
348 }
349
350 /* Generate instructions to call function FUNEXP,
351    and optionally pop the results.
352    The CALL_INSN is the first insn generated.
353
354    FNDECL is the declaration node of the function.  This is given to the
355    macro RETURN_POPS_ARGS to determine whether this function pops its own args.
356
357    FUNTYPE is the data type of the function.  This is given to the macro
358    RETURN_POPS_ARGS to determine whether this function pops its own args.
359    We used to allow an identifier for library functions, but that doesn't
360    work when the return type is an aggregate type and the calling convention
361    says that the pointer to this aggregate is to be popped by the callee.
362
363    STACK_SIZE is the number of bytes of arguments on the stack,
364    ROUNDED_STACK_SIZE is that number rounded up to
365    PREFERRED_STACK_BOUNDARY; zero if the size is variable.  This is
366    both to put into the call insn and to generate explicit popping
367    code if necessary.
368
369    STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
370    It is zero if this call doesn't want a structure value.
371
372    NEXT_ARG_REG is the rtx that results from executing
373      FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
374    just after all the args have had their registers assigned.
375    This could be whatever you like, but normally it is the first
376    arg-register beyond those used for args in this call,
377    or 0 if all the arg-registers are used in this call.
378    It is passed on to `gen_call' so you can put this info in the call insn.
379
380    VALREG is a hard register in which a value is returned,
381    or 0 if the call does not return a value.
382
383    OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
384    the args to this call were processed.
385    We restore `inhibit_defer_pop' to that value.
386
387    CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
388    denote registers used by the called function.
389
390    IS_CONST is true if this is a `const' call.  */
391
392 static void
393 emit_call_1 (funexp, fndecl, funtype, stack_size, rounded_stack_size,
394              struct_value_size, next_arg_reg, valreg, old_inhibit_defer_pop,
395              call_fusage, ecf_flags)
396      rtx funexp;
397      tree fndecl ATTRIBUTE_UNUSED;
398      tree funtype ATTRIBUTE_UNUSED;
399      HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED;
400      HOST_WIDE_INT rounded_stack_size;
401      HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED;
402      rtx next_arg_reg;
403      rtx valreg;
404      int old_inhibit_defer_pop;
405      rtx call_fusage;
406      int ecf_flags;
407 {
408   rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
409 #if defined (HAVE_call) && defined (HAVE_call_value)
410   rtx struct_value_size_rtx = GEN_INT (struct_value_size);
411 #endif
412   rtx call_insn;
413 #ifndef ACCUMULATE_OUTGOING_ARGS
414   int already_popped = 0;
415   HOST_WIDE_INT n_popped = RETURN_POPS_ARGS (fndecl, funtype, stack_size);
416 #endif
417
418   /* Ensure address is valid.  SYMBOL_REF is already valid, so no need,
419      and we don't want to load it into a register as an optimization,
420      because prepare_call_address already did it if it should be done.  */
421   if (GET_CODE (funexp) != SYMBOL_REF)
422     funexp = memory_address (FUNCTION_MODE, funexp);
423
424 #ifndef ACCUMULATE_OUTGOING_ARGS
425 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
426   if ((ecf_flags & ECF_SIBCALL)
427       && HAVE_sibcall_pop && HAVE_sibcall_value_pop
428       && (RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0 
429           || stack_size == 0))
430     {
431       rtx n_pop = GEN_INT (RETURN_POPS_ARGS (fndecl, funtype, stack_size));
432       rtx pat;
433
434       /* If this subroutine pops its own args, record that in the call insn
435          if possible, for the sake of frame pointer elimination.  */
436
437       if (valreg)
438         pat = gen_sibcall_value_pop (valreg,
439                                      gen_rtx_MEM (FUNCTION_MODE, funexp),
440                                      rounded_stack_size_rtx, next_arg_reg,
441                                      n_pop);
442       else
443         pat = gen_sibcall_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
444                                rounded_stack_size_rtx, next_arg_reg, n_pop);
445
446       emit_call_insn (pat);
447       already_popped = 1;
448     }
449   else
450 #endif
451
452 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
453 /* If the target has "call" or "call_value" insns, then prefer them
454    if no arguments are actually popped.  If the target does not have
455    "call" or "call_value" insns, then we must use the popping versions
456    even if the call has no arguments to pop.  */
457 #if defined (HAVE_call) && defined (HAVE_call_value)
458   if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
459        && n_popped > 0)
460 #else
461   if (HAVE_call_pop && HAVE_call_value_pop)
462 #endif
463     {
464       rtx n_pop = GEN_INT (n_popped);
465       rtx pat;
466
467       /* If this subroutine pops its own args, record that in the call insn
468          if possible, for the sake of frame pointer elimination.  */
469
470       if (valreg)
471         pat = gen_call_value_pop (valreg,
472                                   gen_rtx_MEM (FUNCTION_MODE, funexp),
473                                   rounded_stack_size_rtx, next_arg_reg, n_pop);
474       else
475         pat = gen_call_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
476                             rounded_stack_size_rtx, next_arg_reg, n_pop);
477
478       emit_call_insn (pat);
479       already_popped = 1;
480     }
481   else
482 #endif
483 #endif
484
485 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
486   if ((ecf_flags & ECF_SIBCALL)
487       && HAVE_sibcall && HAVE_sibcall_value)
488     {
489       if (valreg)
490         emit_call_insn (gen_sibcall_value (valreg,
491                                            gen_rtx_MEM (FUNCTION_MODE, funexp),
492                                            rounded_stack_size_rtx,
493                                            next_arg_reg, NULL_RTX));
494       else
495         emit_call_insn (gen_sibcall (gen_rtx_MEM (FUNCTION_MODE, funexp),
496                                      rounded_stack_size_rtx, next_arg_reg,
497                                      struct_value_size_rtx));
498     }
499   else
500 #endif
501
502 #if defined (HAVE_call) && defined (HAVE_call_value)
503   if (HAVE_call && HAVE_call_value)
504     {
505       if (valreg)
506         emit_call_insn (gen_call_value (valreg,
507                                         gen_rtx_MEM (FUNCTION_MODE, funexp),
508                                         rounded_stack_size_rtx, next_arg_reg,
509                                         NULL_RTX));
510       else
511         emit_call_insn (gen_call (gen_rtx_MEM (FUNCTION_MODE, funexp),
512                                   rounded_stack_size_rtx, next_arg_reg,
513                                   struct_value_size_rtx));
514     }
515   else
516 #endif
517     abort ();
518
519   /* Find the CALL insn we just emitted.  */
520   for (call_insn = get_last_insn ();
521        call_insn && GET_CODE (call_insn) != CALL_INSN;
522        call_insn = PREV_INSN (call_insn))
523     ;
524
525   if (! call_insn)
526     abort ();
527
528   /* Put the register usage information on the CALL.  If there is already
529      some usage information, put ours at the end.  */
530   if (CALL_INSN_FUNCTION_USAGE (call_insn))
531     {
532       rtx link;
533
534       for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
535            link = XEXP (link, 1))
536         ;
537
538       XEXP (link, 1) = call_fusage;
539     }
540   else
541     CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
542
543   /* If this is a const call, then set the insn's unchanging bit.  */
544   if (ecf_flags & ECF_IS_CONST)
545     CONST_CALL_P (call_insn) = 1;
546
547   /* If this call can't throw, attach a REG_EH_REGION reg note to that
548      effect.  */
549   if (ecf_flags & ECF_NOTHROW)
550     REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, const0_rtx,
551                                                REG_NOTES (call_insn));
552
553   SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
554
555   /* Restore this now, so that we do defer pops for this call's args
556      if the context of the call as a whole permits.  */
557   inhibit_defer_pop = old_inhibit_defer_pop;
558
559 #ifndef ACCUMULATE_OUTGOING_ARGS
560   /* If returning from the subroutine does not automatically pop the args,
561      we need an instruction to pop them sooner or later.
562      Perhaps do it now; perhaps just record how much space to pop later.
563
564      If returning from the subroutine does pop the args, indicate that the
565      stack pointer will be changed.  */
566
567   /* The space for the args is no longer waiting for the call; either it
568      was popped by the call, or it'll be popped below.  */
569   arg_space_so_far -= rounded_stack_size;
570
571   if (n_popped > 0)
572     {
573       if (!already_popped)
574         CALL_INSN_FUNCTION_USAGE (call_insn)
575           = gen_rtx_EXPR_LIST (VOIDmode,
576                                gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
577                                CALL_INSN_FUNCTION_USAGE (call_insn));
578       rounded_stack_size -= n_popped;
579       rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
580     }
581
582   if (rounded_stack_size != 0)
583     {
584       if (flag_defer_pop && inhibit_defer_pop == 0
585           && !(ecf_flags & ECF_IS_CONST))
586         pending_stack_adjust += rounded_stack_size;
587       else
588         adjust_stack (rounded_stack_size_rtx);
589     }
590 #endif
591 }
592
593 /* Determine if the function identified by NAME and FNDECL is one with
594    special properties we wish to know about.
595
596    For example, if the function might return more than one time (setjmp), then
597    set RETURNS_TWICE to a nonzero value.
598
599    Similarly set IS_LONGJMP for if the function is in the longjmp family.
600
601    Set IS_MALLOC for any of the standard memory allocation functions which
602    allocate from the heap.
603
604    Set MAY_BE_ALLOCA for any memory allocation function that might allocate
605    space from the stack such as alloca.  */
606
607 void
608 special_function_p (fndecl, returns_twice, is_longjmp, fork_or_exec,
609                     is_malloc, may_be_alloca)
610      tree fndecl;
611      int *returns_twice;
612      int *is_longjmp;
613      int *fork_or_exec;
614      int *is_malloc;
615      int *may_be_alloca;
616 {
617   *returns_twice = 0;
618   *is_longjmp = 0;
619   *fork_or_exec = 0;
620   *may_be_alloca = 0;
621
622   /* The function decl may have the `malloc' attribute.  */
623   *is_malloc = fndecl && DECL_IS_MALLOC (fndecl);
624
625   if (! *is_malloc 
626       && fndecl && DECL_NAME (fndecl)
627       && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
628       /* Exclude functions not at the file scope, or not `extern',
629          since they are not the magic functions we would otherwise
630          think they are.  */
631       && DECL_CONTEXT (fndecl) == NULL_TREE && TREE_PUBLIC (fndecl))
632     {
633       char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
634       char *tname = name;
635
636       /* We assume that alloca will always be called by name.  It
637          makes no sense to pass it as a pointer-to-function to
638          anything that does not understand its behavior.  */
639       *may_be_alloca
640         = (((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
641              && name[0] == 'a'
642              && ! strcmp (name, "alloca"))
643             || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
644                 && name[0] == '_'
645                 && ! strcmp (name, "__builtin_alloca"))));
646
647       /* Disregard prefix _, __ or __x.  */
648       if (name[0] == '_')
649         {
650           if (name[1] == '_' && name[2] == 'x')
651             tname += 3;
652           else if (name[1] == '_')
653             tname += 2;
654           else
655             tname += 1;
656         }
657
658       if (tname[0] == 's')
659         {
660           *returns_twice
661              = ((tname[1] == 'e'
662                  && (! strcmp (tname, "setjmp")
663                      || ! strcmp (tname, "setjmp_syscall")))
664                 || (tname[1] == 'i'
665                     && ! strcmp (tname, "sigsetjmp"))
666                 || (tname[1] == 'a'
667                     && ! strcmp (tname, "savectx")));
668           if (tname[1] == 'i'
669               && ! strcmp (tname, "siglongjmp"))
670             *is_longjmp = 1;
671         }
672       else if ((tname[0] == 'q' && tname[1] == 's'
673                 && ! strcmp (tname, "qsetjmp"))
674                || (tname[0] == 'v' && tname[1] == 'f'
675                    && ! strcmp (tname, "vfork")))
676         *returns_twice = 1;
677
678       else if (tname[0] == 'l' && tname[1] == 'o'
679                && ! strcmp (tname, "longjmp"))
680         *is_longjmp = 1;
681
682       else if ((tname[0] == 'f' && tname[1] == 'o'
683                 && ! strcmp (tname, "fork"))
684                /* Linux specific: __clone.  check NAME to insist on the
685                   leading underscores, to avoid polluting the ISO / POSIX
686                   namespace.  */
687                || (name[0] == '_' && name[1] == '_'
688                    && ! strcmp (tname, "clone"))
689                || (tname[0] == 'e' && tname[1] == 'x' && tname[2] == 'e'
690                    && tname[3] == 'c' && (tname[4] == 'l' || tname[4] == 'v')
691                    && (tname[5] == '\0'
692                        || ((tname[5] == 'p' || tname[5] == 'e')
693                            && tname[6] == '\0'))))
694         *fork_or_exec = 1;
695
696       /* Do not add any more malloc-like functions to this list,
697          instead mark them as malloc functions using the malloc attribute.
698          Note, realloc is not suitable for attribute malloc since
699          it may return the same address across multiple calls.
700          C++ operator new is not suitable because it is not required
701          to return a unique pointer; indeed, the standard placement new
702          just returns its argument. */
703       else if (TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl))) == Pmode
704                && (! strcmp (tname, "malloc")
705                    || ! strcmp (tname, "calloc")
706                    || ! strcmp (tname, "strdup")))
707         *is_malloc = 1;
708     }
709 }
710
711 /* Precompute all register parameters as described by ARGS, storing values
712    into fields within the ARGS array.
713
714    NUM_ACTUALS indicates the total number elements in the ARGS array.
715
716    Set REG_PARM_SEEN if we encounter a register parameter.  */
717
718 static void
719 precompute_register_parameters (num_actuals, args, reg_parm_seen)
720      int num_actuals;
721      struct arg_data *args;
722      int *reg_parm_seen;
723 {
724   int i;
725
726   *reg_parm_seen = 0;
727
728   for (i = 0; i < num_actuals; i++)
729     if (args[i].reg != 0 && ! args[i].pass_on_stack)
730       {
731         *reg_parm_seen = 1;
732
733         if (args[i].value == 0)
734           {
735             push_temp_slots ();
736             args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
737                                          VOIDmode, 0);
738             preserve_temp_slots (args[i].value);
739             pop_temp_slots ();
740
741             /* ANSI doesn't require a sequence point here,
742                but PCC has one, so this will avoid some problems.  */
743             emit_queue ();
744           }
745
746         /* If we are to promote the function arg to a wider mode,
747            do it now.  */
748
749         if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
750           args[i].value
751             = convert_modes (args[i].mode,
752                              TYPE_MODE (TREE_TYPE (args[i].tree_value)),
753                              args[i].value, args[i].unsignedp);
754
755         /* If the value is expensive, and we are inside an appropriately 
756            short loop, put the value into a pseudo and then put the pseudo
757            into the hard reg.
758
759            For small register classes, also do this if this call uses
760            register parameters.  This is to avoid reload conflicts while
761            loading the parameters registers.  */
762
763         if ((! (GET_CODE (args[i].value) == REG
764                 || (GET_CODE (args[i].value) == SUBREG
765                     && GET_CODE (SUBREG_REG (args[i].value)) == REG)))
766             && args[i].mode != BLKmode
767             && rtx_cost (args[i].value, SET) > 2
768             && ((SMALL_REGISTER_CLASSES && *reg_parm_seen)
769                 || preserve_subexpressions_p ()))
770           args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
771       }
772 }
773
774 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
775
776   /* The argument list is the property of the called routine and it
777      may clobber it.  If the fixed area has been used for previous
778      parameters, we must save and restore it.  */
779 static rtx
780 save_fixed_argument_area (reg_parm_stack_space, argblock,
781                           low_to_save, high_to_save)
782      int reg_parm_stack_space;
783      rtx argblock;
784      int *low_to_save;
785      int *high_to_save;
786 {
787   int i;
788   rtx save_area = NULL_RTX;
789
790   /* Compute the boundary of the that needs to be saved, if any.  */
791 #ifdef ARGS_GROW_DOWNWARD
792   for (i = 0; i < reg_parm_stack_space + 1; i++)
793 #else
794   for (i = 0; i < reg_parm_stack_space; i++)
795 #endif
796     {
797       if (i >= highest_outgoing_arg_in_use
798           || stack_usage_map[i] == 0)
799         continue;
800
801       if (*low_to_save == -1)
802         *low_to_save = i;
803
804       *high_to_save = i;
805     }
806
807   if (*low_to_save >= 0)
808     {
809       int num_to_save = *high_to_save - *low_to_save + 1;
810       enum machine_mode save_mode
811         = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
812       rtx stack_area;
813
814       /* If we don't have the required alignment, must do this in BLKmode.  */
815       if ((*low_to_save & (MIN (GET_MODE_SIZE (save_mode),
816                                 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
817         save_mode = BLKmode;
818
819 #ifdef ARGS_GROW_DOWNWARD
820       stack_area = gen_rtx_MEM (save_mode,
821                                 memory_address (save_mode,
822                                                 plus_constant (argblock,
823                                                                - *high_to_save)));
824 #else
825       stack_area = gen_rtx_MEM (save_mode,
826                                 memory_address (save_mode,
827                                                 plus_constant (argblock,
828                                                                *low_to_save)));
829 #endif
830       if (save_mode == BLKmode)
831         {
832           save_area = assign_stack_temp (BLKmode, num_to_save, 0);
833           /* Cannot use emit_block_move here because it can be done by a library
834              call which in turn gets into this place again and deadly infinite
835              recursion happens.  */
836           move_by_pieces (validize_mem (save_area), stack_area, num_to_save,
837                           PARM_BOUNDARY / BITS_PER_UNIT);
838         }
839       else
840         {
841           save_area = gen_reg_rtx (save_mode);
842           emit_move_insn (save_area, stack_area);
843         }
844     }
845   return save_area;
846 }
847
848 static void
849 restore_fixed_argument_area (save_area, argblock, high_to_save, low_to_save)
850      rtx save_area;
851      rtx argblock;
852      int high_to_save;
853      int low_to_save;
854 {
855   enum machine_mode save_mode = GET_MODE (save_area);
856 #ifdef ARGS_GROW_DOWNWARD
857   rtx stack_area
858     = gen_rtx_MEM (save_mode,
859                    memory_address (save_mode,
860                                    plus_constant (argblock,
861                                                   - high_to_save)));
862 #else
863   rtx stack_area
864     = gen_rtx_MEM (save_mode,
865                    memory_address (save_mode,
866                                    plus_constant (argblock,
867                                                   low_to_save)));
868 #endif
869
870   if (save_mode != BLKmode)
871     emit_move_insn (stack_area, save_area);
872   else
873     /* Cannot use emit_block_move here because it can be done by a library
874        call which in turn gets into this place again and deadly infinite
875        recursion happens.  */
876     move_by_pieces (stack_area, validize_mem (save_area),
877                     high_to_save - low_to_save + 1,
878                     PARM_BOUNDARY / BITS_PER_UNIT);
879 }
880 #endif
881           
882 /* If any elements in ARGS refer to parameters that are to be passed in
883    registers, but not in memory, and whose alignment does not permit a
884    direct copy into registers.  Copy the values into a group of pseudos
885    which we will later copy into the appropriate hard registers. 
886
887    Pseudos for each unaligned argument will be stored into the array
888    args[argnum].aligned_regs.  The caller is responsible for deallocating
889    the aligned_regs array if it is nonzero.  */
890
891 static void
892 store_unaligned_arguments_into_pseudos (args, num_actuals)
893      struct arg_data *args;
894      int num_actuals;
895 {
896   int i, j;
897      
898   for (i = 0; i < num_actuals; i++)
899     if (args[i].reg != 0 && ! args[i].pass_on_stack
900         && args[i].mode == BLKmode
901         && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
902             < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
903       {
904         int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
905         int big_endian_correction = 0;
906
907         args[i].n_aligned_regs
908           = args[i].partial ? args[i].partial
909             : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
910
911         args[i].aligned_regs = (rtx *) xmalloc (sizeof (rtx)
912                                                 * args[i].n_aligned_regs);
913
914         /* Structures smaller than a word are aligned to the least
915            significant byte (to the right).  On a BYTES_BIG_ENDIAN machine,
916            this means we must skip the empty high order bytes when
917            calculating the bit offset.  */
918         if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD)
919           big_endian_correction = (BITS_PER_WORD  - (bytes * BITS_PER_UNIT));
920
921         for (j = 0; j < args[i].n_aligned_regs; j++)
922           {
923             rtx reg = gen_reg_rtx (word_mode);
924             rtx word = operand_subword_force (args[i].value, j, BLKmode);
925             int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
926             int bitalign = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
927
928             args[i].aligned_regs[j] = reg;
929
930             /* There is no need to restrict this code to loading items
931                in TYPE_ALIGN sized hunks.  The bitfield instructions can
932                load up entire word sized registers efficiently.
933
934                ??? This may not be needed anymore.
935                We use to emit a clobber here but that doesn't let later
936                passes optimize the instructions we emit.  By storing 0 into
937                the register later passes know the first AND to zero out the
938                bitfield being set in the register is unnecessary.  The store
939                of 0 will be deleted as will at least the first AND.  */
940
941             emit_move_insn (reg, const0_rtx);
942
943             bytes -= bitsize / BITS_PER_UNIT;
944             store_bit_field (reg, bitsize, big_endian_correction, word_mode,
945                              extract_bit_field (word, bitsize, 0, 1,
946                                                 NULL_RTX, word_mode,
947                                                 word_mode,
948                                                 bitalign / BITS_PER_UNIT,
949                                                 BITS_PER_WORD),
950                              bitalign / BITS_PER_UNIT, BITS_PER_WORD);
951           }
952       }
953 }
954
955 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
956    ACTPARMS. 
957
958    NUM_ACTUALS is the total number of parameters.
959
960    N_NAMED_ARGS is the total number of named arguments.
961
962    FNDECL is the tree code for the target of this call (if known)
963
964    ARGS_SO_FAR holds state needed by the target to know where to place
965    the next argument.
966
967    REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
968    for arguments which are passed in registers.
969
970    OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
971    and may be modified by this routine.
972
973    OLD_PENDING_ADJ, MUST_PREALLOCATE and IS_CONST are pointers to integer
974    flags which may may be modified by this routine.  */
975
976 static void
977 initialize_argument_information (num_actuals, args, args_size, n_named_args,
978                                  actparms, fndecl, args_so_far,
979                                  reg_parm_stack_space, old_stack_level,
980                                  old_pending_adj, must_preallocate, is_const)
981      int num_actuals ATTRIBUTE_UNUSED;
982      struct arg_data *args;
983      struct args_size *args_size;
984      int n_named_args ATTRIBUTE_UNUSED;
985      tree actparms;
986      tree fndecl;
987      CUMULATIVE_ARGS *args_so_far;
988      int reg_parm_stack_space;
989      rtx *old_stack_level;
990      int *old_pending_adj;
991      int *must_preallocate;
992      int *is_const;
993 {
994   /* 1 if scanning parms front to back, -1 if scanning back to front.  */
995   int inc;
996
997   /* Count arg position in order args appear.  */
998   int argpos;
999
1000   struct args_size alignment_pad;
1001   int i;
1002   tree p;
1003   
1004   args_size->constant = 0;
1005   args_size->var = 0;
1006
1007   /* In this loop, we consider args in the order they are written.
1008      We fill up ARGS from the front or from the back if necessary
1009      so that in any case the first arg to be pushed ends up at the front.  */
1010
1011 #ifdef PUSH_ARGS_REVERSED
1012   i = num_actuals - 1, inc = -1;
1013   /* In this case, must reverse order of args
1014      so that we compute and push the last arg first.  */
1015 #else
1016   i = 0, inc = 1;
1017 #endif
1018
1019   /* I counts args in order (to be) pushed; ARGPOS counts in order written.  */
1020   for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
1021     {
1022       tree type = TREE_TYPE (TREE_VALUE (p));
1023       int unsignedp;
1024       enum machine_mode mode;
1025
1026       args[i].tree_value = TREE_VALUE (p);
1027
1028       /* Replace erroneous argument with constant zero.  */
1029       if (type == error_mark_node || TYPE_SIZE (type) == 0)
1030         args[i].tree_value = integer_zero_node, type = integer_type_node;
1031
1032       /* If TYPE is a transparent union, pass things the way we would
1033          pass the first field of the union.  We have already verified that
1034          the modes are the same.  */
1035       if (TYPE_TRANSPARENT_UNION (type))
1036         type = TREE_TYPE (TYPE_FIELDS (type));
1037
1038       /* Decide where to pass this arg.
1039
1040          args[i].reg is nonzero if all or part is passed in registers.
1041
1042          args[i].partial is nonzero if part but not all is passed in registers,
1043          and the exact value says how many words are passed in registers.
1044
1045          args[i].pass_on_stack is nonzero if the argument must at least be
1046          computed on the stack.  It may then be loaded back into registers
1047          if args[i].reg is nonzero.
1048
1049          These decisions are driven by the FUNCTION_... macros and must agree
1050          with those made by function.c.  */
1051
1052       /* See if this argument should be passed by invisible reference.  */
1053       if ((TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1054            && contains_placeholder_p (TYPE_SIZE (type)))
1055           || TREE_ADDRESSABLE (type)
1056 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1057           || FUNCTION_ARG_PASS_BY_REFERENCE (*args_so_far, TYPE_MODE (type),
1058                                              type, argpos < n_named_args)
1059 #endif
1060           )
1061         {
1062           /* If we're compiling a thunk, pass through invisible
1063              references instead of making a copy.  */
1064           if (current_function_is_thunk
1065 #ifdef FUNCTION_ARG_CALLEE_COPIES
1066               || (FUNCTION_ARG_CALLEE_COPIES (*args_so_far, TYPE_MODE (type),
1067                                              type, argpos < n_named_args)
1068                   /* If it's in a register, we must make a copy of it too.  */
1069                   /* ??? Is this a sufficient test?  Is there a better one? */
1070                   && !(TREE_CODE (args[i].tree_value) == VAR_DECL
1071                        && REG_P (DECL_RTL (args[i].tree_value)))
1072                   && ! TREE_ADDRESSABLE (type))
1073 #endif
1074               )
1075             {
1076               /* C++ uses a TARGET_EXPR to indicate that we want to make a
1077                  new object from the argument.  If we are passing by
1078                  invisible reference, the callee will do that for us, so we
1079                  can strip off the TARGET_EXPR.  This is not always safe,
1080                  but it is safe in the only case where this is a useful
1081                  optimization; namely, when the argument is a plain object.
1082                  In that case, the frontend is just asking the backend to
1083                  make a bitwise copy of the argument. */
1084                  
1085               if (TREE_CODE (args[i].tree_value) == TARGET_EXPR
1086                   && (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND
1087                                                   (args[i].tree_value, 1)))
1088                       == 'd')
1089                   && ! REG_P (DECL_RTL (TREE_OPERAND (args[i].tree_value, 1))))
1090                 args[i].tree_value = TREE_OPERAND (args[i].tree_value, 1);
1091
1092               args[i].tree_value = build1 (ADDR_EXPR,
1093                                            build_pointer_type (type),
1094                                            args[i].tree_value);
1095               type = build_pointer_type (type);
1096             }
1097           else
1098             {
1099               /* We make a copy of the object and pass the address to the
1100                  function being called.  */
1101               rtx copy;
1102
1103               if (TYPE_SIZE (type) == 0
1104                   || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1105                   || (flag_stack_check && ! STACK_CHECK_BUILTIN
1106                       && (0 < compare_tree_int (TYPE_SIZE_UNIT (type),
1107                                                 STACK_CHECK_MAX_VAR_SIZE))))
1108                 {
1109                   /* This is a variable-sized object.  Make space on the stack
1110                      for it.  */
1111                   rtx size_rtx = expr_size (TREE_VALUE (p));
1112
1113                   if (*old_stack_level == 0)
1114                     {
1115                       emit_stack_save (SAVE_BLOCK, old_stack_level, NULL_RTX);
1116                       *old_pending_adj = pending_stack_adjust;
1117                       pending_stack_adjust = 0;
1118                     }
1119
1120                   copy = gen_rtx_MEM (BLKmode,
1121                                       allocate_dynamic_stack_space (size_rtx,
1122                                                                     NULL_RTX,
1123                                                                     TYPE_ALIGN (type)));
1124                 }
1125               else
1126                 {
1127                   int size = int_size_in_bytes (type);
1128                   copy = assign_stack_temp (TYPE_MODE (type), size, 0);
1129                 }
1130
1131               MEM_SET_IN_STRUCT_P (copy, AGGREGATE_TYPE_P (type));
1132
1133               store_expr (args[i].tree_value, copy, 0);
1134               *is_const = 0;
1135
1136               args[i].tree_value = build1 (ADDR_EXPR,
1137                                            build_pointer_type (type),
1138                                            make_tree (type, copy));
1139               type = build_pointer_type (type);
1140             }
1141         }
1142
1143       mode = TYPE_MODE (type);
1144       unsignedp = TREE_UNSIGNED (type);
1145
1146 #ifdef PROMOTE_FUNCTION_ARGS
1147       mode = promote_mode (type, mode, &unsignedp, 1);
1148 #endif
1149
1150       args[i].unsignedp = unsignedp;
1151       args[i].mode = mode;
1152       args[i].reg = FUNCTION_ARG (*args_so_far, mode, type,
1153                                   argpos < n_named_args);
1154 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1155       if (args[i].reg)
1156         args[i].partial
1157           = FUNCTION_ARG_PARTIAL_NREGS (*args_so_far, mode, type,
1158                                         argpos < n_named_args);
1159 #endif
1160
1161       args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
1162
1163       /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1164          it means that we are to pass this arg in the register(s) designated
1165          by the PARALLEL, but also to pass it in the stack.  */
1166       if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1167           && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1168         args[i].pass_on_stack = 1;
1169
1170       /* If this is an addressable type, we must preallocate the stack
1171          since we must evaluate the object into its final location.
1172
1173          If this is to be passed in both registers and the stack, it is simpler
1174          to preallocate.  */
1175       if (TREE_ADDRESSABLE (type)
1176           || (args[i].pass_on_stack && args[i].reg != 0))
1177         *must_preallocate = 1;
1178
1179       /* If this is an addressable type, we cannot pre-evaluate it.  Thus,
1180          we cannot consider this function call constant.  */
1181       if (TREE_ADDRESSABLE (type))
1182         *is_const = 0;
1183
1184       /* Compute the stack-size of this argument.  */
1185       if (args[i].reg == 0 || args[i].partial != 0
1186           || reg_parm_stack_space > 0
1187           || args[i].pass_on_stack)
1188         locate_and_pad_parm (mode, type,
1189 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1190                              1,
1191 #else
1192                              args[i].reg != 0,
1193 #endif
1194                              fndecl, args_size, &args[i].offset,
1195                              &args[i].size, &alignment_pad);
1196
1197 #ifndef ARGS_GROW_DOWNWARD
1198       args[i].slot_offset = *args_size;
1199 #endif
1200
1201       args[i].alignment_pad = alignment_pad;
1202
1203       /* If a part of the arg was put into registers,
1204          don't include that part in the amount pushed.  */
1205       if (reg_parm_stack_space == 0 && ! args[i].pass_on_stack)
1206         args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1207                                   / (PARM_BOUNDARY / BITS_PER_UNIT)
1208                                   * (PARM_BOUNDARY / BITS_PER_UNIT));
1209       
1210       /* Update ARGS_SIZE, the total stack space for args so far.  */
1211
1212       args_size->constant += args[i].size.constant;
1213       if (args[i].size.var)
1214         {
1215           ADD_PARM_SIZE (*args_size, args[i].size.var);
1216         }
1217
1218       /* Since the slot offset points to the bottom of the slot,
1219          we must record it after incrementing if the args grow down.  */
1220 #ifdef ARGS_GROW_DOWNWARD
1221       args[i].slot_offset = *args_size;
1222
1223       args[i].slot_offset.constant = -args_size->constant;
1224       if (args_size->var)
1225         SUB_PARM_SIZE (args[i].slot_offset, args_size->var);
1226 #endif
1227
1228       /* Increment ARGS_SO_FAR, which has info about which arg-registers
1229          have been used, etc.  */
1230
1231       FUNCTION_ARG_ADVANCE (*args_so_far, TYPE_MODE (type), type,
1232                             argpos < n_named_args);
1233     }
1234 }
1235
1236 /* Update ARGS_SIZE to contain the total size for the argument block.
1237    Return the original constant component of the argument block's size.
1238
1239    REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1240    for arguments passed in registers.  */
1241
1242 static int
1243 compute_argument_block_size (reg_parm_stack_space, args_size,
1244                              preferred_stack_boundary)
1245      int reg_parm_stack_space;
1246      struct args_size *args_size;
1247      int preferred_stack_boundary ATTRIBUTE_UNUSED;
1248 {
1249   int unadjusted_args_size = args_size->constant;
1250
1251   /* Compute the actual size of the argument block required.  The variable
1252      and constant sizes must be combined, the size may have to be rounded,
1253      and there may be a minimum required size.  */
1254
1255   if (args_size->var)
1256     {
1257       args_size->var = ARGS_SIZE_TREE (*args_size);
1258       args_size->constant = 0;
1259
1260 #ifdef PREFERRED_STACK_BOUNDARY
1261       preferred_stack_boundary /= BITS_PER_UNIT;
1262       if (preferred_stack_boundary > 1)
1263         args_size->var = round_up (args_size->var, preferred_stack_boundary);
1264 #endif
1265
1266       if (reg_parm_stack_space > 0)
1267         {
1268           args_size->var
1269             = size_binop (MAX_EXPR, args_size->var,
1270                           ssize_int (reg_parm_stack_space));
1271
1272 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1273           /* The area corresponding to register parameters is not to count in
1274              the size of the block we need.  So make the adjustment.  */
1275           args_size->var
1276             = size_binop (MINUS_EXPR, args_size->var,
1277                           ssize_int (reg_parm_stack_space));
1278 #endif
1279         }
1280     }
1281   else
1282     {
1283 #ifdef PREFERRED_STACK_BOUNDARY
1284       preferred_stack_boundary /= BITS_PER_UNIT;
1285       if (preferred_stack_boundary < 1)
1286         preferred_stack_boundary = 1;
1287       args_size->constant = (((args_size->constant
1288                                + arg_space_so_far
1289                                + pending_stack_adjust
1290                                + preferred_stack_boundary - 1)
1291                               / preferred_stack_boundary
1292                               * preferred_stack_boundary)
1293                              - arg_space_so_far
1294                              - pending_stack_adjust);
1295 #endif
1296
1297       args_size->constant = MAX (args_size->constant,
1298                                  reg_parm_stack_space);
1299
1300 #ifdef MAYBE_REG_PARM_STACK_SPACE
1301       if (reg_parm_stack_space == 0)
1302         args_size->constant = 0;
1303 #endif
1304
1305 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1306       args_size->constant -= reg_parm_stack_space;
1307 #endif
1308     }
1309   return unadjusted_args_size;
1310 }
1311
1312 /* Precompute parameters as needed for a function call.
1313
1314    IS_CONST indicates the target function is a pure function.
1315
1316    MUST_PREALLOCATE indicates that we must preallocate stack space for
1317    any stack arguments.
1318
1319    NUM_ACTUALS is the number of arguments.
1320
1321    ARGS is an array containing information for each argument; this routine
1322    fills in the INITIAL_VALUE and VALUE fields for each precomputed argument.
1323
1324    ARGS_SIZE contains information about the size of the arg list.  */
1325
1326 static void
1327 precompute_arguments (is_const, must_preallocate, num_actuals, args, args_size)
1328      int is_const;
1329      int must_preallocate;
1330      int num_actuals;
1331      struct arg_data *args;
1332      struct args_size *args_size;
1333 {
1334   int i;
1335
1336   /* If this function call is cse'able, precompute all the parameters.
1337      Note that if the parameter is constructed into a temporary, this will
1338      cause an additional copy because the parameter will be constructed
1339      into a temporary location and then copied into the outgoing arguments.
1340      If a parameter contains a call to alloca and this function uses the
1341      stack, precompute the parameter.  */
1342
1343   /* If we preallocated the stack space, and some arguments must be passed
1344      on the stack, then we must precompute any parameter which contains a
1345      function call which will store arguments on the stack.
1346      Otherwise, evaluating the parameter may clobber previous parameters
1347      which have already been stored into the stack.  */
1348
1349   for (i = 0; i < num_actuals; i++)
1350     if (is_const
1351         || ((args_size->var != 0 || args_size->constant != 0)
1352             && calls_function (args[i].tree_value, 1))
1353         || (must_preallocate
1354             && (args_size->var != 0 || args_size->constant != 0)
1355             && calls_function (args[i].tree_value, 0)))
1356       {
1357         /* If this is an addressable type, we cannot pre-evaluate it.  */
1358         if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))
1359           abort ();
1360
1361         push_temp_slots ();
1362
1363         args[i].value
1364           = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1365
1366         preserve_temp_slots (args[i].value);
1367         pop_temp_slots ();
1368
1369         /* ANSI doesn't require a sequence point here,
1370            but PCC has one, so this will avoid some problems.  */
1371         emit_queue ();
1372
1373         args[i].initial_value = args[i].value
1374           = protect_from_queue (args[i].value, 0);
1375
1376         if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != args[i].mode)
1377           {
1378             args[i].value
1379               = convert_modes (args[i].mode, 
1380                                TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1381                                args[i].value, args[i].unsignedp);
1382 #ifdef PROMOTE_FOR_CALL_ONLY
1383             /* CSE will replace this only if it contains args[i].value
1384                pseudo, so convert it down to the declared mode using
1385                a SUBREG.  */
1386             if (GET_CODE (args[i].value) == REG
1387                 && GET_MODE_CLASS (args[i].mode) == MODE_INT)
1388               {
1389                 args[i].initial_value
1390                   = gen_rtx_SUBREG (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1391                                     args[i].value, 0);
1392                 SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1393                 SUBREG_PROMOTED_UNSIGNED_P (args[i].initial_value)
1394                   = args[i].unsignedp;
1395               }
1396 #endif
1397           }
1398       }
1399 }
1400
1401 /* Given the current state of MUST_PREALLOCATE and information about
1402    arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1403    compute and return the final value for MUST_PREALLOCATE.  */
1404
1405 static int
1406 finalize_must_preallocate (must_preallocate, num_actuals, args, args_size)
1407      int must_preallocate;
1408      int num_actuals;
1409      struct arg_data *args;
1410      struct args_size *args_size;
1411 {
1412   /* See if we have or want to preallocate stack space.
1413
1414      If we would have to push a partially-in-regs parm
1415      before other stack parms, preallocate stack space instead.
1416
1417      If the size of some parm is not a multiple of the required stack
1418      alignment, we must preallocate.
1419
1420      If the total size of arguments that would otherwise create a copy in
1421      a temporary (such as a CALL) is more than half the total argument list
1422      size, preallocation is faster.
1423
1424      Another reason to preallocate is if we have a machine (like the m88k)
1425      where stack alignment is required to be maintained between every
1426      pair of insns, not just when the call is made.  However, we assume here
1427      that such machines either do not have push insns (and hence preallocation
1428      would occur anyway) or the problem is taken care of with
1429      PUSH_ROUNDING.  */
1430
1431   if (! must_preallocate)
1432     {
1433       int partial_seen = 0;
1434       int copy_to_evaluate_size = 0;
1435       int i;
1436
1437       for (i = 0; i < num_actuals && ! must_preallocate; i++)
1438         {
1439           if (args[i].partial > 0 && ! args[i].pass_on_stack)
1440             partial_seen = 1;
1441           else if (partial_seen && args[i].reg == 0)
1442             must_preallocate = 1;
1443
1444           if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1445               && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1446                   || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1447                   || TREE_CODE (args[i].tree_value) == COND_EXPR
1448                   || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1449             copy_to_evaluate_size
1450               += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1451         }
1452
1453       if (copy_to_evaluate_size * 2 >= args_size->constant
1454           && args_size->constant > 0)
1455         must_preallocate = 1;
1456     }
1457   return must_preallocate;
1458 }
1459
1460 /* If we preallocated stack space, compute the address of each argument
1461    and store it into the ARGS array.
1462
1463    We need not ensure it is a valid memory address here; it will be 
1464    validized when it is used.
1465
1466    ARGBLOCK is an rtx for the address of the outgoing arguments.  */
1467
1468 static void
1469 compute_argument_addresses (args, argblock, num_actuals)
1470      struct arg_data *args;
1471      rtx argblock;
1472      int num_actuals;
1473 {
1474   if (argblock)
1475     {
1476       rtx arg_reg = argblock;
1477       int i, arg_offset = 0;
1478
1479       if (GET_CODE (argblock) == PLUS)
1480         arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1481
1482       for (i = 0; i < num_actuals; i++)
1483         {
1484           rtx offset = ARGS_SIZE_RTX (args[i].offset);
1485           rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1486           rtx addr;
1487
1488           /* Skip this parm if it will not be passed on the stack.  */
1489           if (! args[i].pass_on_stack && args[i].reg != 0)
1490             continue;
1491
1492           if (GET_CODE (offset) == CONST_INT)
1493             addr = plus_constant (arg_reg, INTVAL (offset));
1494           else
1495             addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1496
1497           addr = plus_constant (addr, arg_offset);
1498           args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1499           MEM_SET_IN_STRUCT_P 
1500             (args[i].stack,
1501              AGGREGATE_TYPE_P (TREE_TYPE (args[i].tree_value)));
1502
1503           if (GET_CODE (slot_offset) == CONST_INT)
1504             addr = plus_constant (arg_reg, INTVAL (slot_offset));
1505           else
1506             addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1507
1508           addr = plus_constant (addr, arg_offset);
1509           args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1510         }
1511     }
1512 }
1513                                                
1514 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1515    in a call instruction.
1516
1517    FNDECL is the tree node for the target function.  For an indirect call
1518    FNDECL will be NULL_TREE.
1519
1520    EXP is the CALL_EXPR for this call.  */
1521
1522 static rtx
1523 rtx_for_function_call (fndecl, exp)
1524      tree fndecl;
1525      tree exp;
1526 {
1527   rtx funexp;
1528
1529   /* Get the function to call, in the form of RTL.  */
1530   if (fndecl)
1531     {
1532       /* If this is the first use of the function, see if we need to
1533          make an external definition for it.  */
1534       if (! TREE_USED (fndecl))
1535         {
1536           assemble_external (fndecl);
1537           TREE_USED (fndecl) = 1;
1538         }
1539
1540       /* Get a SYMBOL_REF rtx for the function address.  */
1541       funexp = XEXP (DECL_RTL (fndecl), 0);
1542     }
1543   else
1544     /* Generate an rtx (probably a pseudo-register) for the address.  */
1545     {
1546       rtx funaddr;
1547       push_temp_slots ();
1548       funaddr = funexp = 
1549           expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1550       pop_temp_slots ();        /* FUNEXP can't be BLKmode */
1551
1552       /* Check the function is executable.  */
1553       if (current_function_check_memory_usage)
1554         {
1555 #ifdef POINTERS_EXTEND_UNSIGNED
1556           /* It might be OK to convert funexp in place, but there's
1557              a lot going on between here and when it happens naturally
1558              that this seems safer. */
1559           funaddr = convert_memory_address (Pmode, funexp);
1560 #endif
1561           emit_library_call (chkr_check_exec_libfunc, 1,
1562                              VOIDmode, 1,
1563                              funaddr, Pmode);
1564         }
1565       emit_queue ();
1566     }
1567   return funexp;
1568 }
1569
1570 /* Do the register loads required for any wholly-register parms or any
1571    parms which are passed both on the stack and in a register.  Their
1572    expressions were already evaluated. 
1573
1574    Mark all register-parms as living through the call, putting these USE
1575    insns in the CALL_INSN_FUNCTION_USAGE field.  */
1576
1577 static void
1578 load_register_parameters (args, num_actuals, call_fusage)
1579      struct arg_data *args;
1580      int num_actuals;
1581      rtx *call_fusage;
1582 {
1583   int i, j;
1584
1585 #ifdef LOAD_ARGS_REVERSED
1586   for (i = num_actuals - 1; i >= 0; i--)
1587 #else
1588   for (i = 0; i < num_actuals; i++)
1589 #endif
1590     {
1591       rtx reg = args[i].reg;
1592       int partial = args[i].partial;
1593       int nregs;
1594
1595       if (reg)
1596         {
1597           /* Set to non-negative if must move a word at a time, even if just
1598              one word (e.g, partial == 1 && mode == DFmode).  Set to -1 if
1599              we just use a normal move insn.  This value can be zero if the
1600              argument is a zero size structure with no fields.  */
1601           nregs = (partial ? partial
1602                    : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1603                       ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1604                           + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1605                       : -1));
1606
1607           /* Handle calls that pass values in multiple non-contiguous
1608              locations.  The Irix 6 ABI has examples of this.  */
1609
1610           if (GET_CODE (reg) == PARALLEL)
1611             {
1612               emit_group_load (reg, args[i].value,
1613                                int_size_in_bytes (TREE_TYPE (args[i].tree_value)),
1614                                (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
1615                                 / BITS_PER_UNIT));
1616             }
1617
1618           /* If simple case, just do move.  If normal partial, store_one_arg
1619              has already loaded the register for us.  In all other cases,
1620              load the register(s) from memory.  */
1621
1622           else if (nregs == -1)
1623             emit_move_insn (reg, args[i].value);
1624
1625           /* If we have pre-computed the values to put in the registers in
1626              the case of non-aligned structures, copy them in now.  */
1627
1628           else if (args[i].n_aligned_regs != 0)
1629             for (j = 0; j < args[i].n_aligned_regs; j++)
1630               emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
1631                               args[i].aligned_regs[j]);
1632
1633           else if (partial == 0 || args[i].pass_on_stack)
1634             move_block_to_reg (REGNO (reg),
1635                                validize_mem (args[i].value), nregs,
1636                                args[i].mode);
1637
1638           /* Handle calls that pass values in multiple non-contiguous
1639              locations.  The Irix 6 ABI has examples of this.  */
1640           if (GET_CODE (reg) == PARALLEL)
1641             use_group_regs (call_fusage, reg);
1642           else if (nregs == -1)
1643             use_reg (call_fusage, reg);
1644           else
1645             use_regs (call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1646         }
1647     }
1648 }
1649
1650 /* Generate all the code for a function call
1651    and return an rtx for its value.
1652    Store the value in TARGET (specified as an rtx) if convenient.
1653    If the value is stored in TARGET then TARGET is returned.
1654    If IGNORE is nonzero, then we ignore the value of the function call.  */
1655
1656 rtx
1657 expand_call (exp, target, ignore)
1658      tree exp;
1659      rtx target;
1660      int ignore;
1661 {
1662   /* Nonzero if we are currently expanding a call.  */
1663   static int currently_expanding_call = 0;
1664
1665   /* List of actual parameters.  */
1666   tree actparms = TREE_OPERAND (exp, 1);
1667   /* RTX for the function to be called.  */
1668   rtx funexp;
1669   /* Sequence of insns to perform a tail recursive "call".  */
1670   rtx tail_recursion_insns = NULL_RTX;
1671   /* Sequence of insns to perform a normal "call".  */
1672   rtx normal_call_insns = NULL_RTX;
1673   /* Sequence of insns to perform a tail recursive "call".  */
1674   rtx tail_call_insns = NULL_RTX;
1675   /* Data type of the function.  */
1676   tree funtype;
1677   /* Declaration of the function being called,
1678      or 0 if the function is computed (not known by name).  */
1679   tree fndecl = 0;
1680   char *name = 0;
1681 #ifdef ACCUMULATE_OUTGOING_ARGS
1682   rtx before_call;
1683 #endif
1684   rtx insn;
1685   int safe_for_reeval;
1686   int pass;
1687
1688   /* Register in which non-BLKmode value will be returned,
1689      or 0 if no value or if value is BLKmode.  */
1690   rtx valreg;
1691   /* Address where we should return a BLKmode value;
1692      0 if value not BLKmode.  */
1693   rtx structure_value_addr = 0;
1694   /* Nonzero if that address is being passed by treating it as
1695      an extra, implicit first parameter.  Otherwise,
1696      it is passed by being copied directly into struct_value_rtx.  */
1697   int structure_value_addr_parm = 0;
1698   /* Size of aggregate value wanted, or zero if none wanted
1699      or if we are using the non-reentrant PCC calling convention
1700      or expecting the value in registers.  */
1701   HOST_WIDE_INT struct_value_size = 0;
1702   /* Nonzero if called function returns an aggregate in memory PCC style,
1703      by returning the address of where to find it.  */
1704   int pcc_struct_value = 0;
1705
1706   /* Number of actual parameters in this call, including struct value addr.  */
1707   int num_actuals;
1708   /* Number of named args.  Args after this are anonymous ones
1709      and they must all go on the stack.  */
1710   int n_named_args;
1711
1712   /* Vector of information about each argument.
1713      Arguments are numbered in the order they will be pushed,
1714      not the order they are written.  */
1715   struct arg_data *args;
1716
1717   /* Total size in bytes of all the stack-parms scanned so far.  */
1718   struct args_size args_size;
1719   /* Size of arguments before any adjustments (such as rounding).  */
1720   int unadjusted_args_size;
1721   /* Data on reg parms scanned so far.  */
1722   CUMULATIVE_ARGS args_so_far;
1723   /* Nonzero if a reg parm has been scanned.  */
1724   int reg_parm_seen;
1725   /* Nonzero if this is an indirect function call.  */
1726
1727   /* Nonzero if we must avoid push-insns in the args for this call. 
1728      If stack space is allocated for register parameters, but not by the
1729      caller, then it is preallocated in the fixed part of the stack frame.
1730      So the entire argument block must then be preallocated (i.e., we
1731      ignore PUSH_ROUNDING in that case).  */
1732
1733 #ifdef PUSH_ROUNDING
1734   int must_preallocate = 0;
1735 #else
1736   int must_preallocate = 1;
1737 #endif
1738
1739   /* Size of the stack reserved for parameter registers.  */
1740   int reg_parm_stack_space = 0;
1741
1742   /* Address of space preallocated for stack parms
1743      (on machines that lack push insns), or 0 if space not preallocated.  */
1744   rtx argblock = 0;
1745
1746   /* Nonzero if it is plausible that this is a call to alloca.  */
1747   int may_be_alloca;
1748   /* Nonzero if this is a call to malloc or a related function. */
1749   int is_malloc;
1750   /* Nonzero if this is a call to setjmp or a related function.  */
1751   int returns_twice;
1752   /* Nonzero if this is a call to `longjmp'.  */
1753   int is_longjmp;
1754   /* Nonzero if this is a syscall that makes a new process in the image of
1755      the current one.  */
1756   int fork_or_exec;
1757   /* Nonzero if this is a call to an inline function.  */
1758   int is_integrable = 0;
1759   /* Nonzero if this is a call to a `const' function.
1760      Note that only explicitly named functions are handled as `const' here.  */
1761   int is_const = 0;
1762   /* Nonzero if this is a call to a `volatile' function.  */
1763   int is_volatile = 0;
1764   /* Nonzero if this is a call to a function that won't throw an exception.  */
1765   int nothrow = TREE_NOTHROW (exp);
1766 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1767   /* Define the boundary of the register parm stack space that needs to be
1768      save, if any.  */
1769   int low_to_save = -1, high_to_save;
1770   rtx save_area = 0;            /* Place that it is saved */
1771 #endif
1772
1773 #ifdef ACCUMULATE_OUTGOING_ARGS
1774   int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
1775   char *initial_stack_usage_map = stack_usage_map;
1776   int old_stack_arg_under_construction = 0;
1777 #endif
1778
1779   rtx old_stack_level = 0;
1780   int old_pending_adj = 0;
1781   int old_inhibit_defer_pop = inhibit_defer_pop;
1782   rtx call_fusage;
1783   register tree p;
1784   register int i;
1785   int preferred_stack_boundary;
1786
1787   /* The value of the function call can be put in a hard register.  But
1788      if -fcheck-memory-usage, code which invokes functions (and thus
1789      damages some hard registers) can be inserted before using the value.
1790      So, target is always a pseudo-register in that case.  */
1791   if (current_function_check_memory_usage)
1792     target = 0;
1793
1794   /* See if we can find a DECL-node for the actual function.
1795      As a result, decide whether this is a call to an integrable function.  */
1796
1797   p = TREE_OPERAND (exp, 0);
1798   if (TREE_CODE (p) == ADDR_EXPR)
1799     {
1800       fndecl = TREE_OPERAND (p, 0);
1801       if (TREE_CODE (fndecl) != FUNCTION_DECL)
1802         fndecl = 0;
1803       else
1804         {
1805           if (!flag_no_inline
1806               && fndecl != current_function_decl
1807               && DECL_INLINE (fndecl)
1808               && DECL_SAVED_INSNS (fndecl)
1809               && DECL_SAVED_INSNS (fndecl)->inlinable)
1810             is_integrable = 1;
1811           else if (! TREE_ADDRESSABLE (fndecl))
1812             {
1813               /* In case this function later becomes inlinable,
1814                  record that there was already a non-inline call to it.
1815
1816                  Use abstraction instead of setting TREE_ADDRESSABLE
1817                  directly.  */
1818               if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
1819                   && optimize > 0)
1820                 {
1821                   warning_with_decl (fndecl, "can't inline call to `%s'");
1822                   warning ("called from here");
1823                 }
1824               mark_addressable (fndecl);
1825             }
1826
1827           if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
1828               && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
1829             is_const = 1;
1830
1831           if (TREE_THIS_VOLATILE (fndecl))
1832             is_volatile = 1;
1833
1834           if (TREE_NOTHROW (fndecl))
1835             nothrow = 1;
1836         }
1837     }
1838
1839   /* If we don't have specific function to call, see if we have a 
1840      constant or `noreturn' function from the type.  */
1841   if (fndecl == 0)
1842     {
1843       is_const = TREE_READONLY (TREE_TYPE (TREE_TYPE (p)));
1844       is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
1845     }
1846
1847 #ifdef REG_PARM_STACK_SPACE
1848 #ifdef MAYBE_REG_PARM_STACK_SPACE
1849   reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
1850 #else
1851   reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
1852 #endif
1853 #endif
1854
1855 #if defined(PUSH_ROUNDING) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1856   if (reg_parm_stack_space > 0)
1857     must_preallocate = 1;
1858 #endif
1859
1860   /* Warn if this value is an aggregate type,
1861      regardless of which calling convention we are using for it.  */
1862   if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
1863     warning ("function call has aggregate value");
1864
1865   /* Set up a place to return a structure.  */
1866
1867   /* Cater to broken compilers.  */
1868   if (aggregate_value_p (exp))
1869     {
1870       /* This call returns a big structure.  */
1871       is_const = 0;
1872
1873 #ifdef PCC_STATIC_STRUCT_RETURN
1874       {
1875         pcc_struct_value = 1;
1876         /* Easier than making that case work right.  */
1877         if (is_integrable)
1878           {
1879             /* In case this is a static function, note that it has been
1880                used.  */
1881             if (! TREE_ADDRESSABLE (fndecl))
1882               mark_addressable (fndecl);
1883             is_integrable = 0;
1884           }
1885       }
1886 #else /* not PCC_STATIC_STRUCT_RETURN */
1887       {
1888         struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
1889
1890         if (target && GET_CODE (target) == MEM)
1891           structure_value_addr = XEXP (target, 0);
1892         else
1893           {
1894             /* Assign a temporary to hold the value.  */
1895             tree d;
1896
1897             /* For variable-sized objects, we must be called with a target
1898                specified.  If we were to allocate space on the stack here,
1899                we would have no way of knowing when to free it.  */
1900
1901             if (struct_value_size < 0)
1902               abort ();
1903
1904             /* This DECL is just something to feed to mark_addressable;
1905                it doesn't get pushed.  */
1906             d = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (exp));
1907             DECL_RTL (d) = assign_temp (TREE_TYPE (exp), 1, 0, 1);
1908             mark_addressable (d);
1909             mark_temp_addr_taken (DECL_RTL (d));
1910             structure_value_addr = XEXP (DECL_RTL (d), 0);
1911             TREE_USED (d) = 1;
1912             target = 0;
1913           }
1914       }
1915 #endif /* not PCC_STATIC_STRUCT_RETURN */
1916     }
1917
1918   /* If called function is inline, try to integrate it.  */
1919
1920   if (is_integrable)
1921     {
1922       rtx temp;
1923
1924 #ifdef ACCUMULATE_OUTGOING_ARGS
1925       before_call = get_last_insn ();
1926 #endif
1927
1928       temp = expand_inline_function (fndecl, actparms, target,
1929                                      ignore, TREE_TYPE (exp),
1930                                      structure_value_addr);
1931
1932       /* If inlining succeeded, return.  */
1933       if (temp != (rtx) (HOST_WIDE_INT) -1)
1934         {
1935 #ifdef ACCUMULATE_OUTGOING_ARGS
1936           /* If the outgoing argument list must be preserved, push
1937              the stack before executing the inlined function if it
1938              makes any calls.  */
1939
1940           for (i = reg_parm_stack_space - 1; i >= 0; i--)
1941             if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
1942               break;
1943
1944           if (stack_arg_under_construction || i >= 0)
1945             {
1946               rtx first_insn
1947                 = before_call ? NEXT_INSN (before_call) : get_insns ();
1948               rtx insn = NULL_RTX, seq;
1949
1950               /* Look for a call in the inline function code.
1951                  If DECL_SAVED_INSNS (fndecl)->outgoing_args_size is
1952                  nonzero then there is a call and it is not necessary
1953                  to scan the insns.  */
1954
1955               if (DECL_SAVED_INSNS (fndecl)->outgoing_args_size == 0)
1956                 for (insn = first_insn; insn; insn = NEXT_INSN (insn))
1957                   if (GET_CODE (insn) == CALL_INSN)
1958                     break;
1959
1960               if (insn)
1961                 {
1962                   /* Reserve enough stack space so that the largest
1963                      argument list of any function call in the inline
1964                      function does not overlap the argument list being
1965                      evaluated.  This is usually an overestimate because
1966                      allocate_dynamic_stack_space reserves space for an
1967                      outgoing argument list in addition to the requested
1968                      space, but there is no way to ask for stack space such
1969                      that an argument list of a certain length can be
1970                      safely constructed. 
1971
1972                      Add the stack space reserved for register arguments, if
1973                      any, in the inline function.  What is really needed is the
1974                      largest value of reg_parm_stack_space in the inline
1975                      function, but that is not available.  Using the current
1976                      value of reg_parm_stack_space is wrong, but gives
1977                      correct results on all supported machines.  */
1978
1979                   int adjust = (DECL_SAVED_INSNS (fndecl)->outgoing_args_size
1980                                 + reg_parm_stack_space);
1981
1982                   start_sequence ();
1983                   emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1984                   allocate_dynamic_stack_space (GEN_INT (adjust),
1985                                                 NULL_RTX, BITS_PER_UNIT);
1986                   seq = get_insns ();
1987                   end_sequence ();
1988                   emit_insns_before (seq, first_insn);
1989                   emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
1990                 }
1991             }
1992 #endif
1993
1994           /* If the result is equivalent to TARGET, return TARGET to simplify
1995              checks in store_expr.  They can be equivalent but not equal in the
1996              case of a function that returns BLKmode.  */
1997           if (temp != target && rtx_equal_p (temp, target))
1998             return target;
1999           return temp;
2000         }
2001
2002       /* If inlining failed, mark FNDECL as needing to be compiled
2003          separately after all.  If function was declared inline,
2004          give a warning.  */
2005       if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
2006           && optimize > 0 && ! TREE_ADDRESSABLE (fndecl))
2007         {
2008           warning_with_decl (fndecl, "inlining failed in call to `%s'");
2009           warning ("called from here");
2010         }
2011       mark_addressable (fndecl);
2012     }
2013
2014   currently_expanding_call++;
2015
2016   /* If we're considering tail recursion optimizations, verify that the
2017      arguments are safe for re-evaluation.  If we can unsave them, wrap
2018      each argument in an UNSAVE_EXPR.  */
2019
2020   safe_for_reeval = 0;
2021   if (optimize >= 2
2022       && currently_expanding_call == 1
2023       && stmt_loop_nest_empty ()
2024       && ! any_pending_cleanups (1))
2025     {
2026       /* Verify that each argument is safe for re-evaluation.  */
2027       for (p = actparms; p; p = TREE_CHAIN (p))
2028         if (! safe_for_unsave (TREE_VALUE (p)))
2029           break;
2030
2031       if (p == NULL_TREE)
2032         {
2033           tree new_actparms = NULL_TREE, q;
2034
2035           for (p = actparms; p ; p = TREE_CHAIN (p))
2036             {
2037               tree np = build_tree_list (TREE_PURPOSE (p),
2038                                          unsave_expr (TREE_VALUE (p)));
2039               if (new_actparms)
2040                 TREE_CHAIN (q) = np;
2041               else
2042                 new_actparms = np;
2043               q = np;
2044             }
2045
2046           actparms = new_actparms;
2047           safe_for_reeval = 1;
2048         }
2049     }
2050
2051   /* Generate a tail recursion sequence when calling ourselves.  */
2052
2053   if (safe_for_reeval
2054       && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
2055       && TREE_OPERAND (TREE_OPERAND (exp, 0), 0) == current_function_decl)
2056     {
2057       /* We want to emit any pending stack adjustments before the tail
2058          recursion "call".  That way we know any adjustment after the tail
2059          recursion call can be ignored if we indeed use the tail recursion
2060          call expansion.  */
2061       int save_pending_stack_adjust = pending_stack_adjust;
2062       rtx last;
2063
2064       /* Use a new sequence to hold any RTL we generate.  We do not even
2065          know if we will use this RTL yet.  The final decision can not be
2066          made until after RTL generation for the entire function is
2067          complete.  */
2068       push_to_sequence (0);
2069
2070       /* Emit the pending stack adjustments before we expand any arguments.  */
2071       do_pending_stack_adjust ();
2072
2073       optimize_tail_recursion (exp, get_last_insn ());
2074  
2075       last = get_last_insn ();
2076       tail_recursion_insns = get_insns ();
2077       end_sequence ();
2078
2079       /* If the last insn on the tail recursion sequence is not a
2080          BARRIER, then tail recursion optimization failed.  */
2081       if (last == NULL_RTX || GET_CODE (last) != BARRIER)
2082         tail_recursion_insns = NULL_RTX;
2083
2084       /* Restore the original pending stack adjustment for the sibling and
2085          normal call cases below.  */
2086       pending_stack_adjust = save_pending_stack_adjust;
2087     }
2088
2089   function_call_count++;
2090
2091   if (fndecl && DECL_NAME (fndecl))
2092     name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
2093
2094 #ifdef PREFERRED_STACK_BOUNDARY
2095   preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2096 #else
2097   preferred_stack_boundary = STACK_BOUNDARY;
2098 #endif
2099
2100   /* Ensure current function's preferred stack boundary is at least
2101      what we need.  We don't have to increase alignment for recursive
2102      functions.  */
2103   if (cfun->preferred_stack_boundary < preferred_stack_boundary
2104       && fndecl != current_function_decl)
2105     cfun->preferred_stack_boundary = preferred_stack_boundary;
2106
2107   /* See if this is a call to a function that can return more than once
2108      or a call to longjmp or malloc.  */
2109   special_function_p (fndecl, &returns_twice, &is_longjmp, &fork_or_exec,
2110                       &is_malloc, &may_be_alloca);
2111
2112   if (may_be_alloca)
2113     current_function_calls_alloca = 1;
2114
2115   /* Operand 0 is a pointer-to-function; get the type of the function.  */
2116   funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
2117   if (! POINTER_TYPE_P (funtype))
2118     abort ();
2119   funtype = TREE_TYPE (funtype);
2120
2121   /* We want to make two insn chains; one for a sibling call, the other
2122      for a normal call.  We will select one of the two chains after
2123      initial RTL generation is complete.  */
2124   for (pass = 0; pass < 2; pass++)
2125     {
2126       int sibcall_failure = 0;
2127       /* We want to emit ay pending stack adjustments before the tail
2128          recursion "call".  That way we know any adjustment after the tail
2129          recursion call can be ignored if we indeed use the tail recursion
2130          call expansion.  */
2131       int save_pending_stack_adjust;
2132       rtx insns;
2133       rtx before_call;
2134
2135       if (pass == 0)
2136         {
2137           /* Various reasons we can not use a sibling call.  */
2138           if (! safe_for_reeval
2139 #ifdef HAVE_sibcall_epilogue
2140               || ! HAVE_sibcall_epilogue
2141 #else
2142               || 1
2143 #endif
2144               /* The structure value address is used and modified in the
2145                  loop below.  It does not seem worth the effort to save and
2146                  restore it as a state variable since few optimizable
2147                  sibling calls will return a structure.  */
2148               || structure_value_addr != NULL_RTX
2149               /* If the register holding the address is a callee saved
2150                  register, then we lose.  We have no way to prevent that,
2151                  so we only allow calls to named functions.  */
2152               || fndecl == NULL_TREE
2153               || ! FUNCTION_OK_FOR_SIBCALL (fndecl))
2154             continue;
2155
2156           /* We know at this point that there are not currently any
2157              pending cleanups.  If, however, in the process of evaluating
2158              the arguments we were to create some, we'll need to be
2159              able to get rid of them.  */
2160           expand_start_target_temps ();
2161
2162           /* State variables we need to save and restore between
2163              iterations.  */
2164           save_pending_stack_adjust = pending_stack_adjust;
2165         }
2166
2167       /* Other state variables that we must reinitialize each time
2168          through the loop (that are not initialized by the loop itself.  */
2169       argblock = 0;
2170       call_fusage = 0;
2171
2172       /* Start a new sequence for the normal call case. 
2173
2174          From this point on, if the sibling call fails, we want to set
2175          sibcall_failure instead of continuing the loop.  */
2176       start_sequence ();
2177
2178       /* When calling a const function, we must pop the stack args right away,
2179          so that the pop is deleted or moved with the call.  */
2180       if (is_const)
2181         NO_DEFER_POP;
2182
2183       /* Don't let pending stack adjusts add up to too much.
2184          Also, do all pending adjustments now if there is any chance
2185          this might be a call to alloca or if we are expanding a sibling
2186          call sequence.  */
2187       if (pending_stack_adjust >= 32
2188           || (pending_stack_adjust > 0 && may_be_alloca)
2189           || pass == 0)
2190         do_pending_stack_adjust ();
2191
2192       if (profile_arc_flag && fork_or_exec)
2193         {
2194           /* A fork duplicates the profile information, and an exec discards
2195              it.  We can't rely on fork/exec to be paired.  So write out the
2196              profile information we have gathered so far, and clear it.  */
2197           /* ??? When Linux's __clone is called with CLONE_VM set, profiling
2198              is subject to race conditions, just as with multithreaded
2199              programs.  */
2200
2201           emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__bb_fork_func"), 0,
2202                              VOIDmode, 0);
2203         }
2204
2205       /* Push the temporary stack slot level so that we can free any
2206          temporaries we make.  */
2207       push_temp_slots ();
2208
2209       /* Start updating where the next arg would go.
2210
2211          On some machines (such as the PA) indirect calls have a different
2212          calling convention than normal calls.  The last argument in
2213          INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2214          or not.  */
2215       INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, (fndecl == 0));
2216
2217       /* If struct_value_rtx is 0, it means pass the address
2218          as if it were an extra parameter.  */
2219       if (structure_value_addr && struct_value_rtx == 0)
2220         {
2221           /* If structure_value_addr is a REG other than
2222              virtual_outgoing_args_rtx, we can use always use it.  If it
2223              is not a REG, we must always copy it into a register.
2224              If it is virtual_outgoing_args_rtx, we must copy it to another
2225              register in some cases.  */
2226           rtx temp = (GET_CODE (structure_value_addr) != REG
2227 #ifdef ACCUMULATE_OUTGOING_ARGS
2228                       || (stack_arg_under_construction
2229                           && structure_value_addr == virtual_outgoing_args_rtx)
2230 #endif
2231                       ? copy_addr_to_reg (structure_value_addr)
2232                       : structure_value_addr);
2233
2234           actparms
2235             = tree_cons (error_mark_node,
2236                          make_tree (build_pointer_type (TREE_TYPE (funtype)),
2237                                     temp),
2238                          actparms);
2239           structure_value_addr_parm = 1;
2240         }
2241
2242       /* Count the arguments and set NUM_ACTUALS.  */
2243       for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
2244       num_actuals = i;
2245
2246       /* Compute number of named args.
2247          Normally, don't include the last named arg if anonymous args follow.
2248          We do include the last named arg if STRICT_ARGUMENT_NAMING is nonzero.
2249          (If no anonymous args follow, the result of list_length is actually
2250          one too large.  This is harmless.)
2251
2252          If PRETEND_OUTGOING_VARARGS_NAMED is set and STRICT_ARGUMENT_NAMING is
2253          zero, this machine will be able to place unnamed args that were
2254          passed in registers into the stack.  So treat all args as named.
2255          This allows the insns emitting for a specific argument list to be
2256          independent of the function declaration.
2257
2258          If PRETEND_OUTGOING_VARARGS_NAMED is not set, we do not have any
2259          reliable way to pass unnamed args in registers, so we must force
2260          them into memory.  */
2261
2262       if ((STRICT_ARGUMENT_NAMING
2263            || ! PRETEND_OUTGOING_VARARGS_NAMED)
2264           && TYPE_ARG_TYPES (funtype) != 0)
2265         n_named_args
2266           = (list_length (TYPE_ARG_TYPES (funtype))
2267              /* Don't include the last named arg.  */
2268              - (STRICT_ARGUMENT_NAMING ? 0 : 1)
2269              /* Count the struct value address, if it is passed as a parm.  */
2270              + structure_value_addr_parm);
2271       else
2272         /* If we know nothing, treat all args as named.  */
2273         n_named_args = num_actuals;
2274
2275       /* Make a vector to hold all the information about each arg.  */
2276       args = (struct arg_data *) alloca (num_actuals
2277                                          * sizeof (struct arg_data));
2278       bzero ((char *) args, num_actuals * sizeof (struct arg_data));
2279
2280       /* Build up entries inthe ARGS array, compute the size of the arguments
2281          into ARGS_SIZE, etc.  */
2282       initialize_argument_information (num_actuals, args, &args_size,
2283                                        n_named_args, actparms, fndecl,
2284                                        &args_so_far, reg_parm_stack_space,
2285                                        &old_stack_level, &old_pending_adj,
2286                                        &must_preallocate, &is_const);
2287
2288 #ifdef FINAL_REG_PARM_STACK_SPACE
2289       reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2290                                                          args_size.var);
2291 #endif
2292       
2293       if (args_size.var)
2294         {
2295           /* If this function requires a variable-sized argument list, don't
2296              try to make a cse'able block for this call.  We may be able to
2297              do this eventually, but it is too complicated to keep track of
2298              what insns go in the cse'able block and which don't. 
2299
2300              Also do not make a sibling call.  */
2301
2302           is_const = 0;
2303           must_preallocate = 1;
2304           sibcall_failure = 1;
2305         }
2306
2307       /* Compute the actual size of the argument block required.  The variable
2308          and constant sizes must be combined, the size may have to be rounded,
2309          and there may be a minimum required size.  When generating a sibcall
2310          pattern, do not round up, since we'll be re-using whatever space our
2311          caller provided.  */
2312       unadjusted_args_size
2313         = compute_argument_block_size (reg_parm_stack_space, &args_size,
2314                                        (pass == 0 ? 0
2315                                         : preferred_stack_boundary));
2316
2317       /* If the callee pops its own arguments, then it must pop exactly
2318          the same number of arguments as the current function.  */
2319       if (RETURN_POPS_ARGS (fndecl, funtype, unadjusted_args_size)
2320           != RETURN_POPS_ARGS (current_function_decl,
2321                                TREE_TYPE (current_function_decl),
2322                                current_function_args_size))
2323         sibcall_failure = 1;
2324
2325       /* Now make final decision about preallocating stack space.  */
2326       must_preallocate = finalize_must_preallocate (must_preallocate,
2327                                                     num_actuals, args,
2328                                                     &args_size);
2329
2330       /* If the structure value address will reference the stack pointer, we
2331          must stabilize it.  We don't need to do this if we know that we are
2332          not going to adjust the stack pointer in processing this call.  */
2333
2334       if (structure_value_addr
2335           && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
2336               || reg_mentioned_p (virtual_outgoing_args_rtx,
2337                                   structure_value_addr))
2338           && (args_size.var
2339 #ifndef ACCUMULATE_OUTGOING_ARGS
2340               || args_size.constant
2341 #endif
2342               ))
2343         structure_value_addr = copy_to_reg (structure_value_addr);
2344
2345       /* Precompute any arguments as needed.  */
2346       precompute_arguments (is_const, must_preallocate, num_actuals,
2347                             args, &args_size);
2348
2349       /* Now we are about to start emitting insns that can be deleted
2350          if a libcall is deleted.  */
2351       if (is_const || is_malloc)
2352         start_sequence ();
2353
2354       /* If we have no actual push instructions, or shouldn't use them,
2355          make space for all args right now.  */
2356
2357       if (args_size.var != 0)
2358         {
2359           if (old_stack_level == 0)
2360             {
2361               emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2362               old_pending_adj = pending_stack_adjust;
2363               pending_stack_adjust = 0;
2364 #ifdef ACCUMULATE_OUTGOING_ARGS
2365               /* stack_arg_under_construction says whether a stack arg is
2366                  being constructed at the old stack level.  Pushing the stack
2367                  gets a clean outgoing argument block.  */
2368               old_stack_arg_under_construction = stack_arg_under_construction;
2369               stack_arg_under_construction = 0;
2370 #endif
2371             }
2372           argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
2373         }
2374       else
2375         {
2376           /* Note that we must go through the motions of allocating an argument
2377              block even if the size is zero because we may be storing args
2378              in the area reserved for register arguments, which may be part of
2379              the stack frame.  */
2380
2381           int needed = args_size.constant;
2382
2383           /* Store the maximum argument space used.  It will be pushed by
2384              the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2385              checking).  */
2386
2387           if (needed > current_function_outgoing_args_size)
2388             current_function_outgoing_args_size = needed;
2389
2390           if (must_preallocate)
2391             {
2392 #ifdef ACCUMULATE_OUTGOING_ARGS
2393               /* Since the stack pointer will never be pushed, it is possible
2394                  for the evaluation of a parm to clobber something we have
2395                  already written to the stack.  Since most function calls on
2396                  RISC machines do not use the stack, this is uncommon, but
2397                  must work correctly.
2398
2399                  Therefore, we save any area of the stack that was already
2400                  written and that we are using.  Here we set up to do this by
2401                  making a new stack usage map from the old one.  The actual
2402                  save will be done by store_one_arg. 
2403
2404                  Another approach might be to try to reorder the argument
2405                  evaluations to avoid this conflicting stack usage.  */
2406
2407 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2408               /* Since we will be writing into the entire argument area, the
2409                  map must be allocated for its entire size, not just the part
2410                  that is the responsibility of the caller.  */
2411               needed += reg_parm_stack_space;
2412 #endif
2413
2414 #ifdef ARGS_GROW_DOWNWARD
2415               highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2416                                                  needed + 1);
2417 #else
2418               highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2419                                                  needed);
2420 #endif
2421               stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
2422
2423               if (initial_highest_arg_in_use)
2424                 bcopy (initial_stack_usage_map, stack_usage_map,
2425                        initial_highest_arg_in_use);
2426
2427               if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2428                 bzero (&stack_usage_map[initial_highest_arg_in_use],
2429                        (highest_outgoing_arg_in_use
2430                         - initial_highest_arg_in_use));
2431               needed = 0;
2432
2433               /* The address of the outgoing argument list must not be copied
2434                  to a register here, because argblock would be left pointing
2435                  to the wrong place after the call to
2436                  allocate_dynamic_stack_space below. */
2437
2438               argblock = virtual_outgoing_args_rtx;
2439
2440 #else /* not ACCUMULATE_OUTGOING_ARGS */
2441               if (inhibit_defer_pop == 0)
2442                 {
2443                   /* Try to reuse some or all of the pending_stack_adjust
2444                      to get this space.  Maybe we can avoid any pushing.  */
2445                   if (needed > pending_stack_adjust)
2446                     {
2447                       needed -= pending_stack_adjust;
2448                       pending_stack_adjust = 0;
2449                     }
2450                   else
2451                     {
2452                       pending_stack_adjust -= needed;
2453                       needed = 0;
2454                     }
2455                 }
2456               /* Special case this because overhead of `push_block' in this
2457                  case is non-trivial.  */
2458               if (needed == 0)
2459                 argblock = virtual_outgoing_args_rtx;
2460               else
2461                 argblock = push_block (GEN_INT (needed), 0, 0);
2462
2463               /* We only really need to call `copy_to_reg' in the case where
2464                  push insns are going to be used to pass ARGBLOCK to a function
2465                  call in ARGS.  In that case, the stack pointer changes value
2466                  from the allocation point to the call point, and hence
2467                  the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
2468                  But might as well always do it.  */
2469               argblock = copy_to_reg (argblock);
2470 #endif /* not ACCUMULATE_OUTGOING_ARGS */
2471             }
2472         }
2473
2474       /* The argument block when performing a sibling call is the
2475          incoming argument block.  */
2476       if (pass == 0)
2477         {
2478           rtx temp = plus_constant (arg_pointer_rtx,
2479                                     FIRST_PARM_OFFSET (current_function_decl));
2480           argblock = force_reg (Pmode, force_operand (temp, NULL_RTX));
2481         }
2482
2483 #ifdef ACCUMULATE_OUTGOING_ARGS
2484       /* The save/restore code in store_one_arg handles all cases except one:
2485          a constructor call (including a C function returning a BLKmode struct)
2486          to initialize an argument.  */
2487       if (stack_arg_under_construction)
2488         {
2489 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2490           rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
2491 #else
2492           rtx push_size = GEN_INT (args_size.constant);
2493 #endif
2494           if (old_stack_level == 0)
2495             {
2496               emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2497               old_pending_adj = pending_stack_adjust;
2498               pending_stack_adjust = 0;
2499               /* stack_arg_under_construction says whether a stack arg is
2500                  being constructed at the old stack level.  Pushing the stack
2501                  gets a clean outgoing argument block.  */
2502               old_stack_arg_under_construction = stack_arg_under_construction;
2503               stack_arg_under_construction = 0;
2504               /* Make a new map for the new argument list.  */
2505               stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
2506               bzero (stack_usage_map, highest_outgoing_arg_in_use);
2507               highest_outgoing_arg_in_use = 0;
2508             }
2509           allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
2510         }
2511       /* If argument evaluation might modify the stack pointer, copy the
2512          address of the argument list to a register.  */
2513       for (i = 0; i < num_actuals; i++)
2514         if (args[i].pass_on_stack)
2515           {
2516             argblock = copy_addr_to_reg (argblock);
2517             break;
2518           }
2519 #endif
2520
2521       compute_argument_addresses (args, argblock, num_actuals);
2522
2523 #ifdef PUSH_ARGS_REVERSED
2524 #ifdef PREFERRED_STACK_BOUNDARY
2525       /* If we push args individually in reverse order, perform stack alignment
2526          before the first push (the last arg).  */
2527       if (args_size.constant != unadjusted_args_size)
2528         {
2529           /* When the stack adjustment is pending, we get better code
2530              by combining the adjustments.  */
2531           if (pending_stack_adjust && ! is_const
2532               && ! inhibit_defer_pop)
2533             {
2534               args_size.constant = (unadjusted_args_size
2535                                     + ((pending_stack_adjust
2536                                         + args_size.constant
2537                                         + arg_space_so_far
2538                                         - unadjusted_args_size)
2539                                        % (preferred_stack_boundary
2540                                           / BITS_PER_UNIT)));
2541               pending_stack_adjust -= (args_size.constant
2542                                        - unadjusted_args_size);
2543               do_pending_stack_adjust ();
2544             }
2545           else if (argblock == 0)
2546             anti_adjust_stack (GEN_INT (args_size.constant
2547                                         - unadjusted_args_size));
2548           arg_space_so_far += args_size.constant - unadjusted_args_size;
2549
2550           /* Now that the stack is properly aligned, pops can't safely
2551              be deferred during the evaluation of the arguments.  */
2552           NO_DEFER_POP;
2553         }
2554 #endif
2555 #endif
2556
2557       /* Don't try to defer pops if preallocating, not even from the first arg,
2558          since ARGBLOCK probably refers to the SP.  */
2559       if (argblock)
2560         NO_DEFER_POP;
2561
2562       funexp = rtx_for_function_call (fndecl, exp);
2563
2564       /* Figure out the register where the value, if any, will come back.  */
2565       valreg = 0;
2566       if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
2567           && ! structure_value_addr)
2568         {
2569           if (pcc_struct_value)
2570             valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
2571                                           fndecl, 0);
2572           else
2573             valreg = hard_function_value (TREE_TYPE (exp), fndecl, 0);
2574         }
2575
2576       /* Precompute all register parameters.  It isn't safe to compute anything
2577          once we have started filling any specific hard regs.  */
2578       precompute_register_parameters (num_actuals, args, &reg_parm_seen);
2579
2580 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2581       /* Save the fixed argument area if it's part of the caller's frame and
2582          is clobbered by argument setup for this call.  */
2583       save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
2584                                             &low_to_save, &high_to_save);
2585 #endif
2586
2587       /* Now store (and compute if necessary) all non-register parms.
2588          These come before register parms, since they can require block-moves,
2589          which could clobber the registers used for register parms.
2590          Parms which have partial registers are not stored here,
2591          but we do preallocate space here if they want that.  */
2592
2593       for (i = 0; i < num_actuals; i++)
2594         if (args[i].reg == 0 || args[i].pass_on_stack)
2595           store_one_arg (&args[i], argblock, may_be_alloca,
2596                          args_size.var != 0, reg_parm_stack_space);
2597
2598       /* If we have a parm that is passed in registers but not in memory
2599          and whose alignment does not permit a direct copy into registers,
2600          make a group of pseudos that correspond to each register that we
2601          will later fill.  */
2602       if (STRICT_ALIGNMENT)
2603         store_unaligned_arguments_into_pseudos (args, num_actuals);
2604
2605       /* Now store any partially-in-registers parm.
2606          This is the last place a block-move can happen.  */
2607       if (reg_parm_seen)
2608         for (i = 0; i < num_actuals; i++)
2609           if (args[i].partial != 0 && ! args[i].pass_on_stack)
2610             store_one_arg (&args[i], argblock, may_be_alloca,
2611                            args_size.var != 0, reg_parm_stack_space);
2612
2613 #ifndef PUSH_ARGS_REVERSED
2614 #ifdef PREFERRED_STACK_BOUNDARY
2615       /* If we pushed args in forward order, perform stack alignment
2616          after pushing the last arg.  */
2617       /* ??? Fix for arg_space_so_far.  */
2618       if (argblock == 0)
2619         anti_adjust_stack (GEN_INT (args_size.constant
2620                                     - unadjusted_args_size));
2621 #endif
2622 #endif
2623
2624       /* If register arguments require space on the stack and stack space
2625          was not preallocated, allocate stack space here for arguments
2626          passed in registers.  */
2627 #if ! defined(ACCUMULATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
2628       if (must_preallocate == 0 && reg_parm_stack_space > 0)
2629         anti_adjust_stack (GEN_INT (reg_parm_stack_space));
2630 #endif
2631
2632       /* Pass the function the address in which to return a
2633          structure value.  */
2634       if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
2635         {
2636           emit_move_insn (struct_value_rtx,
2637                           force_reg (Pmode,
2638                                      force_operand (structure_value_addr,
2639                                                     NULL_RTX)));
2640
2641           /* Mark the memory for the aggregate as write-only.  */
2642           if (current_function_check_memory_usage)
2643             emit_library_call (chkr_set_right_libfunc, 1,
2644                                VOIDmode, 3,
2645                                structure_value_addr, ptr_mode, 
2646                                GEN_INT (struct_value_size),
2647                                TYPE_MODE (sizetype),
2648                                GEN_INT (MEMORY_USE_WO),
2649                                TYPE_MODE (integer_type_node));
2650
2651           if (GET_CODE (struct_value_rtx) == REG)
2652             use_reg (&call_fusage, struct_value_rtx);
2653         }
2654
2655       funexp = prepare_call_address (funexp, fndecl, &call_fusage,
2656                                      reg_parm_seen);
2657
2658       load_register_parameters (args, num_actuals, &call_fusage);
2659      
2660       /* Perform postincrements before actually calling the function.  */
2661       emit_queue ();
2662
2663       /* Save a pointer to the last insn before the call, so that we can
2664          later safely search backwards to find the CALL_INSN.  */
2665       before_call = get_last_insn ();
2666
2667       /* All arguments and registers used for the call must be set up by
2668          now!  */
2669
2670       /* Generate the actual call instruction.  */
2671       emit_call_1 (funexp, fndecl, funtype, unadjusted_args_size,
2672                    args_size.constant, struct_value_size,
2673                    FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2674                    valreg, old_inhibit_defer_pop, call_fusage,
2675                    ((is_const ? ECF_IS_CONST : 0)
2676                     | (nothrow ? ECF_NOTHROW : 0)
2677                     | (pass == 0 ? ECF_SIBCALL : 0)));
2678
2679       /* If call is cse'able, make appropriate pair of reg-notes around it.
2680          Test valreg so we don't crash; may safely ignore `const'
2681          if return type is void.  Disable for PARALLEL return values, because
2682          we have no way to move such values into a pseudo register.  */
2683       if (is_const && valreg != 0 && GET_CODE (valreg) != PARALLEL)
2684         {
2685           rtx note = 0;
2686           rtx temp = gen_reg_rtx (GET_MODE (valreg));
2687           rtx insns;
2688
2689           /* Mark the return value as a pointer if needed.  */
2690           if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2691             {
2692               tree pointed_to = TREE_TYPE (TREE_TYPE (exp));
2693               mark_reg_pointer (temp, TYPE_ALIGN (pointed_to) / BITS_PER_UNIT);
2694             }
2695
2696           /* Construct an "equal form" for the value which mentions all the
2697              arguments in order as well as the function name.  */
2698 #ifdef PUSH_ARGS_REVERSED
2699           for (i = 0; i < num_actuals; i++)
2700             note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
2701 #else
2702           for (i = num_actuals - 1; i >= 0; i--)
2703             note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
2704 #endif
2705           note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
2706
2707           insns = get_insns ();
2708           end_sequence ();
2709
2710           emit_libcall_block (insns, temp, valreg, note);
2711   
2712           valreg = temp;
2713         }
2714       else if (is_const)
2715         {
2716           /* Otherwise, just write out the sequence without a note.  */
2717           rtx insns = get_insns ();
2718
2719           end_sequence ();
2720           emit_insns (insns);
2721         }
2722       else if (is_malloc)
2723         {
2724           rtx temp = gen_reg_rtx (GET_MODE (valreg));
2725           rtx last, insns;
2726
2727           /* The return value from a malloc-like function is a pointer. */
2728           if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2729             mark_reg_pointer (temp, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2730
2731           emit_move_insn (temp, valreg);
2732
2733           /* The return value from a malloc-like function can not alias
2734              anything else.  */
2735           last = get_last_insn ();
2736           REG_NOTES (last) = 
2737             gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));
2738
2739           /* Write out the sequence.  */
2740           insns = get_insns ();
2741           end_sequence ();
2742           emit_insns (insns);
2743           valreg = temp;
2744         }
2745
2746       /* For calls to `setjmp', etc., inform flow.c it should complain
2747          if nonvolatile values are live.  For functions that cannot return,
2748          inform flow that control does not fall through.  */
2749
2750       if (returns_twice || is_volatile || is_longjmp || pass == 0)
2751         {
2752           /* The barrier or NOTE_INSN_SETJMP note must be emitted
2753              immediately after the CALL_INSN.  Some ports emit more
2754              than just a CALL_INSN above, so we must search for it here.  */
2755
2756           rtx last = get_last_insn ();
2757           while (GET_CODE (last) != CALL_INSN)
2758             {
2759               last = PREV_INSN (last);
2760               /* There was no CALL_INSN?  */
2761               if (last == before_call)
2762                 abort ();
2763             }
2764
2765           if (returns_twice)
2766             {
2767               emit_note_after (NOTE_INSN_SETJMP, last);
2768               current_function_calls_setjmp = 1;
2769               sibcall_failure = 1;
2770             }
2771           else
2772             emit_barrier_after (last);
2773         }
2774
2775       if (is_longjmp)
2776         current_function_calls_longjmp = 1, sibcall_failure = 1;
2777
2778       /* If value type not void, return an rtx for the value.  */
2779
2780       /* If there are cleanups to be called, don't use a hard reg as target.
2781          We need to double check this and see if it matters anymore.  */
2782       if (any_pending_cleanups (1)
2783           && target && REG_P (target)
2784           && REGNO (target) < FIRST_PSEUDO_REGISTER)
2785         target = 0, sibcall_failure = 1;
2786
2787       if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
2788           || ignore)
2789         {
2790           target = const0_rtx;
2791         }
2792       else if (structure_value_addr)
2793         {
2794           if (target == 0 || GET_CODE (target) != MEM)
2795             {
2796               target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2797                                     memory_address (TYPE_MODE (TREE_TYPE (exp)),
2798                                                     structure_value_addr));
2799               MEM_SET_IN_STRUCT_P (target,
2800                                    AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2801             }
2802         }
2803       else if (pcc_struct_value)
2804         {
2805           /* This is the special C++ case where we need to
2806              know what the true target was.  We take care to
2807              never use this value more than once in one expression.  */
2808           target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2809                                 copy_to_reg (valreg));
2810           MEM_SET_IN_STRUCT_P (target, AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2811         }
2812       /* Handle calls that return values in multiple non-contiguous locations.
2813          The Irix 6 ABI has examples of this.  */
2814       else if (GET_CODE (valreg) == PARALLEL)
2815         {
2816           int bytes = int_size_in_bytes (TREE_TYPE (exp));
2817
2818           if (target == 0)
2819             {
2820               target = assign_stack_temp (TYPE_MODE (TREE_TYPE (exp)),
2821                                           bytes, 0);
2822               MEM_SET_IN_STRUCT_P (target, AGGREGATE_TYPE_P (TREE_TYPE (exp)));
2823               preserve_temp_slots (target);
2824             }
2825
2826           if (! rtx_equal_p (target, valreg))
2827             emit_group_store (target, valreg, bytes,
2828                               TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
2829           /* We can not support sibling calls for this case.  */
2830           sibcall_failure = 1;
2831         }
2832       else if (target
2833                && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2834                && GET_MODE (target) == GET_MODE (valreg))
2835         {
2836           /* TARGET and VALREG cannot be equal at this point because the
2837              latter would not have REG_FUNCTION_VALUE_P true, while the
2838              former would if it were referring to the same register.
2839
2840              If they refer to the same register, this move will be a no-op,
2841              except when function inlining is being done.  */
2842           emit_move_insn (target, valreg);
2843         }
2844       else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2845         target = copy_blkmode_from_reg (target, valreg, TREE_TYPE (exp));
2846       else
2847         target = copy_to_reg (valreg);
2848
2849 #ifdef PROMOTE_FUNCTION_RETURN
2850       /* If we promoted this return value, make the proper SUBREG.  TARGET
2851          might be const0_rtx here, so be careful.  */
2852       if (GET_CODE (target) == REG
2853           && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
2854           && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
2855         {
2856           tree type = TREE_TYPE (exp);
2857           int unsignedp = TREE_UNSIGNED (type);
2858
2859           /* If we don't promote as expected, something is wrong.  */
2860           if (GET_MODE (target)
2861               != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
2862             abort ();
2863
2864           target = gen_rtx_SUBREG (TYPE_MODE (type), target, 0);
2865           SUBREG_PROMOTED_VAR_P (target) = 1;
2866           SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
2867         }
2868 #endif
2869
2870       /* If size of args is variable or this was a constructor call for a stack
2871          argument, restore saved stack-pointer value.  */
2872
2873       if (old_stack_level)
2874         {
2875           emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
2876           pending_stack_adjust = old_pending_adj;
2877 #ifdef ACCUMULATE_OUTGOING_ARGS
2878           stack_arg_under_construction = old_stack_arg_under_construction;
2879           highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2880           stack_usage_map = initial_stack_usage_map;
2881 #endif
2882           sibcall_failure = 1;
2883         }
2884 #ifdef ACCUMULATE_OUTGOING_ARGS
2885       else
2886         {
2887 #ifdef REG_PARM_STACK_SPACE
2888           if (save_area)
2889             {
2890               restore_fixed_argument_area (save_area, argblock,
2891                                            high_to_save, low_to_save);
2892               sibcall_failure = 1;
2893             }
2894 #endif
2895
2896           /* If we saved any argument areas, restore them.  */
2897           for (i = 0; i < num_actuals; i++)
2898             if (args[i].save_area)
2899               {
2900                 enum machine_mode save_mode = GET_MODE (args[i].save_area);
2901                 rtx stack_area
2902                   = gen_rtx_MEM (save_mode,
2903                                  memory_address (save_mode,
2904                                                  XEXP (args[i].stack_slot, 0)));
2905
2906                 if (save_mode != BLKmode)
2907                   emit_move_insn (stack_area, args[i].save_area);
2908                 else
2909                   emit_block_move (stack_area,
2910                                    validize_mem (args[i].save_area),
2911                                    GEN_INT (args[i].size.constant),
2912                                    PARM_BOUNDARY / BITS_PER_UNIT);
2913                 sibcall_failure = 1;
2914               }
2915
2916           highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2917           stack_usage_map = initial_stack_usage_map;
2918         }
2919 #endif
2920
2921       /* If this was alloca, record the new stack level for nonlocal gotos.  
2922          Check for the handler slots since we might not have a save area
2923          for non-local gotos.  */
2924
2925       if (may_be_alloca && nonlocal_goto_handler_slots != 0)
2926         emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
2927
2928       pop_temp_slots ();
2929
2930       /* Free up storage we no longer need.  */
2931       for (i = 0; i < num_actuals; ++i)
2932         if (args[i].aligned_regs)
2933           free (args[i].aligned_regs);
2934
2935       if (pass == 0)
2936         {
2937           /* Undo the fake expand_start_target_temps we did earlier.  If
2938              there had been any cleanups created, we've already set
2939              sibcall_failure.  */
2940           expand_end_target_temps ();
2941         }
2942
2943       insns = get_insns ();
2944       end_sequence ();
2945
2946       if (pass == 0)
2947         {
2948           tail_call_insns = insns;
2949
2950           /* If the current function's argument block is not large enough
2951              to hold the outoing arguments, or we encountered some other
2952              situation we couldn't handle, zero out the sequence.  */
2953           if (current_function_args_size < args_size.constant
2954               || sibcall_failure)
2955             tail_call_insns = NULL_RTX;
2956
2957           /* Restore the pending stack adjustment now that we have
2958              finished generating the sibling call sequence.  */
2959           pending_stack_adjust = save_pending_stack_adjust;
2960         }
2961       else
2962         normal_call_insns = insns;
2963     }
2964
2965   /* The function optimize_sibling_and_tail_recursive_calls doesn't
2966      handle CALL_PLACEHOLDERs inside other CALL_PLACEHOLDERs.  This
2967      can happen if the arguments to this function call an inline
2968      function who's expansion contains another CALL_PLACEHOLDER.
2969
2970      If there are any C_Ps in any of these sequences, replace them
2971      with their normal call. */
2972
2973   for (insn = normal_call_insns; insn; insn = NEXT_INSN (insn))
2974     if (GET_CODE (insn) == CALL_INSN
2975         && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
2976       replace_call_placeholder (insn, sibcall_use_normal);
2977
2978   for (insn = tail_call_insns; insn; insn = NEXT_INSN (insn))
2979     if (GET_CODE (insn) == CALL_INSN
2980         && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
2981       replace_call_placeholder (insn, sibcall_use_normal);
2982
2983   for (insn = tail_recursion_insns; insn; insn = NEXT_INSN (insn))
2984     if (GET_CODE (insn) == CALL_INSN
2985         && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
2986       replace_call_placeholder (insn, sibcall_use_normal);
2987
2988   /* If this was a potential tail recursion site, then emit a
2989      CALL_PLACEHOLDER with the normal and the tail recursion streams.
2990      One of them will be selected later.  */
2991   if (tail_recursion_insns || tail_call_insns)
2992     {
2993       /* The tail recursion label must be kept around.  We could expose
2994          its use in the CALL_PLACEHOLDER, but that creates unwanted edges
2995          and makes determining true tail recursion sites difficult.
2996
2997          So we set LABEL_PRESERVE_P here, then clear it when we select
2998          one of the call sequences after rtl generation is complete.  */
2999       if (tail_recursion_insns)
3000         LABEL_PRESERVE_P (tail_recursion_label) = 1;
3001       emit_call_insn (gen_rtx_CALL_PLACEHOLDER (VOIDmode, normal_call_insns,
3002                                                 tail_call_insns,
3003                                                 tail_recursion_insns,
3004                                                 tail_recursion_label));
3005     }
3006   else
3007     emit_insns (normal_call_insns);
3008
3009   currently_expanding_call--;
3010
3011   return target;
3012 }
3013 \f
3014 /* Returns nonzero if FUN is the symbol for a library function which can
3015    not throw.  */
3016
3017 static int
3018 libfunc_nothrow (fun)
3019      rtx fun;
3020 {
3021   if (fun == throw_libfunc
3022       || fun == rethrow_libfunc
3023       || fun == sjthrow_libfunc
3024       || fun == sjpopnthrow_libfunc)
3025     return 0;
3026
3027   return 1;
3028 }
3029
3030 /* Output a library call to function FUN (a SYMBOL_REF rtx)
3031    (emitting the queue unless NO_QUEUE is nonzero),
3032    for a value of mode OUTMODE,
3033    with NARGS different arguments, passed as alternating rtx values
3034    and machine_modes to convert them to.
3035    The rtx values should have been passed through protect_from_queue already.
3036
3037    NO_QUEUE will be true if and only if the library call is a `const' call
3038    which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent
3039    to the variable is_const in expand_call.
3040
3041    NO_QUEUE must be true for const calls, because if it isn't, then
3042    any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes,
3043    and will be lost if the libcall sequence is optimized away.
3044
3045    NO_QUEUE must be false for non-const calls, because if it isn't, the
3046    call insn will have its CONST_CALL_P bit set, and it will be incorrectly
3047    optimized.  For instance, the instruction scheduler may incorrectly
3048    move memory references across the non-const call.  */
3049
3050 void
3051 emit_library_call VPARAMS((rtx orgfun, int no_queue, enum machine_mode outmode,
3052                            int nargs, ...))
3053 {
3054 #ifndef ANSI_PROTOTYPES
3055   rtx orgfun;
3056   int no_queue;
3057   enum machine_mode outmode;
3058   int nargs;
3059 #endif
3060   va_list p;
3061   /* Total size in bytes of all the stack-parms scanned so far.  */
3062   struct args_size args_size;
3063   /* Size of arguments before any adjustments (such as rounding).  */
3064   struct args_size original_args_size;
3065   register int argnum;
3066   rtx fun;
3067   int inc;
3068   int count;
3069   struct args_size alignment_pad;
3070   rtx argblock = 0;
3071   CUMULATIVE_ARGS args_so_far;
3072   struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
3073                struct args_size offset; struct args_size size; rtx save_area; };
3074   struct arg *argvec;
3075   int old_inhibit_defer_pop = inhibit_defer_pop;
3076   rtx call_fusage = 0;
3077   int reg_parm_stack_space = 0;
3078   int nothrow;
3079 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3080   /* Define the boundary of the register parm stack space that needs to be
3081      save, if any.  */
3082   int low_to_save = -1, high_to_save = 0;
3083   rtx save_area = 0;            /* Place that it is saved */
3084 #endif
3085
3086 #ifdef ACCUMULATE_OUTGOING_ARGS
3087   int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3088   char *initial_stack_usage_map = stack_usage_map;
3089   int needed;
3090 #endif
3091
3092 #ifdef REG_PARM_STACK_SPACE
3093   /* Size of the stack reserved for parameter registers.  */
3094 #ifdef MAYBE_REG_PARM_STACK_SPACE
3095   reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3096 #else
3097   reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3098 #endif
3099 #endif
3100
3101   VA_START (p, nargs);
3102
3103 #ifndef ANSI_PROTOTYPES
3104   orgfun = va_arg (p, rtx);
3105   no_queue = va_arg (p, int);
3106   outmode = va_arg (p, enum machine_mode);
3107   nargs = va_arg (p, int);
3108 #endif
3109
3110   fun = orgfun;
3111
3112   nothrow = libfunc_nothrow (fun);
3113
3114   /* Copy all the libcall-arguments out of the varargs data
3115      and into a vector ARGVEC.
3116
3117      Compute how to pass each argument.  We only support a very small subset
3118      of the full argument passing conventions to limit complexity here since
3119      library functions shouldn't have many args.  */
3120
3121   argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
3122   bzero ((char *) argvec, nargs * sizeof (struct arg));
3123
3124
3125   INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
3126
3127   args_size.constant = 0;
3128   args_size.var = 0;
3129
3130   push_temp_slots ();
3131
3132 #ifdef PREFERRED_STACK_BOUNDARY
3133   /* Ensure current function's preferred stack boundary is at least
3134      what we need.  */
3135   if (cfun->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3136     cfun->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3137 #endif
3138
3139   for (count = 0; count < nargs; count++)
3140     {
3141       rtx val = va_arg (p, rtx);
3142       enum machine_mode mode = va_arg (p, enum machine_mode);
3143
3144       /* We cannot convert the arg value to the mode the library wants here;
3145          must do it earlier where we know the signedness of the arg.  */
3146       if (mode == BLKmode
3147           || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
3148         abort ();
3149
3150       /* On some machines, there's no way to pass a float to a library fcn.
3151          Pass it as a double instead.  */
3152 #ifdef LIBGCC_NEEDS_DOUBLE
3153       if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
3154         val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
3155 #endif
3156
3157       /* There's no need to call protect_from_queue, because
3158          either emit_move_insn or emit_push_insn will do that.  */
3159
3160       /* Make sure it is a reasonable operand for a move or push insn.  */
3161       if (GET_CODE (val) != REG && GET_CODE (val) != MEM
3162           && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
3163         val = force_operand (val, NULL_RTX);
3164
3165 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3166       if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
3167         {
3168           /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
3169              be viewed as just an efficiency improvement.  */
3170           rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
3171           emit_move_insn (slot, val);
3172           val = force_operand (XEXP (slot, 0), NULL_RTX);
3173           mode = Pmode;
3174         }
3175 #endif
3176
3177       argvec[count].value = val;
3178       argvec[count].mode = mode;
3179
3180       argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
3181
3182 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3183       argvec[count].partial
3184         = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3185 #else
3186       argvec[count].partial = 0;
3187 #endif
3188
3189       locate_and_pad_parm (mode, NULL_TREE,
3190                            argvec[count].reg && argvec[count].partial == 0,
3191                            NULL_TREE, &args_size, &argvec[count].offset,
3192                            &argvec[count].size, &alignment_pad);
3193
3194       if (argvec[count].size.var)
3195         abort ();
3196
3197       if (reg_parm_stack_space == 0 && argvec[count].partial)
3198         argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
3199
3200       if (argvec[count].reg == 0 || argvec[count].partial != 0
3201           || reg_parm_stack_space > 0)
3202         args_size.constant += argvec[count].size.constant;
3203
3204       FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3205     }
3206   va_end (p);
3207
3208 #ifdef FINAL_REG_PARM_STACK_SPACE
3209   reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
3210                                                      args_size.var);
3211 #endif
3212       
3213   /* If this machine requires an external definition for library
3214      functions, write one out.  */
3215   assemble_external_libcall (fun);
3216
3217   original_args_size = args_size;
3218 #ifdef PREFERRED_STACK_BOUNDARY
3219   args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
3220                          / STACK_BYTES) * STACK_BYTES);
3221 #endif
3222
3223   args_size.constant = MAX (args_size.constant,
3224                             reg_parm_stack_space);
3225
3226 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3227   args_size.constant -= reg_parm_stack_space;
3228 #endif
3229
3230   if (args_size.constant > current_function_outgoing_args_size)
3231     current_function_outgoing_args_size = args_size.constant;
3232
3233 #ifdef ACCUMULATE_OUTGOING_ARGS
3234   /* Since the stack pointer will never be pushed, it is possible for
3235      the evaluation of a parm to clobber something we have already
3236      written to the stack.  Since most function calls on RISC machines
3237      do not use the stack, this is uncommon, but must work correctly.
3238
3239      Therefore, we save any area of the stack that was already written
3240      and that we are using.  Here we set up to do this by making a new
3241      stack usage map from the old one.
3242
3243      Another approach might be to try to reorder the argument
3244      evaluations to avoid this conflicting stack usage.  */
3245
3246   needed = args_size.constant;
3247
3248 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3249   /* Since we will be writing into the entire argument area, the
3250      map must be allocated for its entire size, not just the part that
3251      is the responsibility of the caller.  */
3252   needed += reg_parm_stack_space;
3253 #endif
3254
3255 #ifdef ARGS_GROW_DOWNWARD
3256   highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3257                                      needed + 1);
3258 #else
3259   highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3260                                      needed);
3261 #endif
3262   stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3263
3264   if (initial_highest_arg_in_use)
3265     bcopy (initial_stack_usage_map, stack_usage_map,
3266            initial_highest_arg_in_use);
3267
3268   if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3269     bzero (&stack_usage_map[initial_highest_arg_in_use],
3270            highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3271   needed = 0;
3272
3273   /* The address of the outgoing argument list must not be copied to a
3274      register here, because argblock would be left pointing to the
3275      wrong place after the call to allocate_dynamic_stack_space below.
3276      */
3277
3278   argblock = virtual_outgoing_args_rtx;
3279 #else /* not ACCUMULATE_OUTGOING_ARGS */
3280 #ifndef PUSH_ROUNDING
3281   argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3282 #endif
3283 #endif
3284
3285 #ifdef PUSH_ARGS_REVERSED
3286 #ifdef PREFERRED_STACK_BOUNDARY
3287   /* If we push args individually in reverse order, perform stack alignment
3288      before the first push (the last arg).  */
3289   if (argblock == 0)
3290     anti_adjust_stack (GEN_INT (args_size.constant
3291                                 - original_args_size.constant));
3292 #endif
3293 #endif
3294
3295 #ifdef PUSH_ARGS_REVERSED
3296   inc = -1;
3297   argnum = nargs - 1;
3298 #else
3299   inc = 1;
3300   argnum = 0;
3301 #endif
3302
3303 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3304   /* The argument list is the property of the called routine and it
3305      may clobber it.  If the fixed area has been used for previous
3306      parameters, we must save and restore it.
3307
3308      Here we compute the boundary of the that needs to be saved, if any.  */
3309
3310 #ifdef ARGS_GROW_DOWNWARD
3311   for (count = 0; count < reg_parm_stack_space + 1; count++)
3312 #else
3313   for (count = 0; count < reg_parm_stack_space; count++)
3314 #endif
3315     {
3316       if (count >=  highest_outgoing_arg_in_use
3317           || stack_usage_map[count] == 0)
3318         continue;
3319
3320       if (low_to_save == -1)
3321         low_to_save = count;
3322
3323       high_to_save = count;
3324     }
3325
3326   if (low_to_save >= 0)
3327     {
3328       int num_to_save = high_to_save - low_to_save + 1;
3329       enum machine_mode save_mode
3330         = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
3331       rtx stack_area;
3332
3333       /* If we don't have the required alignment, must do this in BLKmode.  */
3334       if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
3335                                BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
3336         save_mode = BLKmode;
3337
3338 #ifdef ARGS_GROW_DOWNWARD
3339       stack_area = gen_rtx_MEM (save_mode,
3340                                 memory_address (save_mode,
3341                                                 plus_constant (argblock,
3342                                                                - high_to_save)));
3343 #else
3344       stack_area = gen_rtx_MEM (save_mode,
3345                                 memory_address (save_mode,
3346                                                 plus_constant (argblock,
3347                                                                low_to_save)));
3348 #endif
3349       if (save_mode == BLKmode)
3350         {
3351           save_area = assign_stack_temp (BLKmode, num_to_save, 0);
3352           emit_block_move (validize_mem (save_area), stack_area,
3353                            GEN_INT (num_to_save),
3354                            PARM_BOUNDARY / BITS_PER_UNIT);
3355         }
3356       else
3357         {
3358           save_area = gen_reg_rtx (save_mode);
3359           emit_move_insn (save_area, stack_area);
3360         }
3361     }
3362 #endif
3363           
3364   /* Push the args that need to be pushed.  */
3365
3366   /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3367      are to be pushed.  */
3368   for (count = 0; count < nargs; count++, argnum += inc)
3369     {
3370       register enum machine_mode mode = argvec[argnum].mode;
3371       register rtx val = argvec[argnum].value;
3372       rtx reg = argvec[argnum].reg;
3373       int partial = argvec[argnum].partial;
3374 #ifdef ACCUMULATE_OUTGOING_ARGS
3375       int lower_bound, upper_bound, i;
3376 #endif
3377
3378       if (! (reg != 0 && partial == 0))
3379         {
3380 #ifdef ACCUMULATE_OUTGOING_ARGS
3381           /* If this is being stored into a pre-allocated, fixed-size, stack
3382              area, save any previous data at that location.  */
3383
3384 #ifdef ARGS_GROW_DOWNWARD
3385           /* stack_slot is negative, but we want to index stack_usage_map
3386              with positive values.  */
3387           upper_bound = -argvec[argnum].offset.constant + 1;
3388           lower_bound = upper_bound - argvec[argnum].size.constant;
3389 #else
3390           lower_bound = argvec[argnum].offset.constant;
3391           upper_bound = lower_bound + argvec[argnum].size.constant;
3392 #endif
3393
3394           for (i = lower_bound; i < upper_bound; i++)
3395             if (stack_usage_map[i]
3396                 /* Don't store things in the fixed argument area at this point;
3397                    it has already been saved.  */
3398                 && i > reg_parm_stack_space)
3399               break;
3400
3401           if (i != upper_bound)
3402             {
3403               /* We need to make a save area.  See what mode we can make it. */
3404               enum machine_mode save_mode
3405                 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
3406                                  MODE_INT, 1);
3407               rtx stack_area
3408                 = gen_rtx_MEM
3409                   (save_mode,
3410                    memory_address
3411                    (save_mode,
3412                     plus_constant (argblock,
3413                                    argvec[argnum].offset.constant)));
3414
3415               argvec[argnum].save_area = gen_reg_rtx (save_mode);
3416               emit_move_insn (argvec[argnum].save_area, stack_area);
3417             }
3418 #endif
3419           emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
3420                           argblock, GEN_INT (argvec[argnum].offset.constant),
3421                           reg_parm_stack_space, ARGS_SIZE_RTX (alignment_pad));
3422
3423 #ifdef ACCUMULATE_OUTGOING_ARGS
3424           /* Now mark the segment we just used.  */
3425           for (i = lower_bound; i < upper_bound; i++)
3426             stack_usage_map[i] = 1;
3427 #endif
3428
3429           NO_DEFER_POP;
3430         }
3431     }
3432
3433 #ifndef PUSH_ARGS_REVERSED
3434 #ifdef PREFERRED_STACK_BOUNDARY
3435   /* If we pushed args in forward order, perform stack alignment
3436      after pushing the last arg.  */
3437   if (argblock == 0)
3438     anti_adjust_stack (GEN_INT (args_size.constant
3439                                 - original_args_size.constant));
3440 #endif
3441 #endif
3442
3443 #ifdef PUSH_ARGS_REVERSED
3444   argnum = nargs - 1;
3445 #else
3446   argnum = 0;
3447 #endif
3448
3449   fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
3450
3451   /* Now load any reg parms into their regs.  */
3452
3453   /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3454      are to be pushed.  */
3455   for (count = 0; count < nargs; count++, argnum += inc)
3456     {
3457       register rtx val = argvec[argnum].value;
3458       rtx reg = argvec[argnum].reg;
3459       int partial = argvec[argnum].partial;
3460
3461       /* Handle calls that pass values in multiple non-contiguous
3462          locations.  The PA64 has examples of this for library calls.  */
3463       if (reg != 0 && GET_CODE (reg) == PARALLEL)
3464         emit_group_load (reg, val,
3465                          GET_MODE_SIZE (GET_MODE (val)),
3466                          GET_MODE_ALIGNMENT (GET_MODE (val)));
3467       else if (reg != 0 && partial == 0)
3468         emit_move_insn (reg, val);
3469
3470       NO_DEFER_POP;
3471     }
3472
3473   /* For version 1.37, try deleting this entirely.  */
3474   if (! no_queue)
3475     emit_queue ();
3476
3477   /* Any regs containing parms remain in use through the call.  */
3478   for (count = 0; count < nargs; count++)
3479     {
3480       rtx reg = argvec[count].reg;
3481       if (reg != 0 && GET_CODE (argvec[count].reg) == PARALLEL)
3482         use_group_regs (&call_fusage, reg);
3483       else if (reg != 0)
3484         use_reg (&call_fusage, reg);
3485     }
3486
3487   /* Don't allow popping to be deferred, since then
3488      cse'ing of library calls could delete a call and leave the pop.  */
3489   NO_DEFER_POP;
3490
3491   /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3492      will set inhibit_defer_pop to that value.  */
3493
3494   /* The return type is needed to decide how many bytes the function pops.
3495      Signedness plays no role in that, so for simplicity, we pretend it's
3496      always signed.  We also assume that the list of arguments passed has
3497      no impact, so we pretend it is unknown.  */
3498
3499   emit_call_1 (fun, 
3500                get_identifier (XSTR (orgfun, 0)), 
3501                build_function_type (outmode == VOIDmode ? void_type_node
3502                                     : type_for_mode (outmode, 0), NULL_TREE),
3503                original_args_size.constant, args_size.constant, 0,
3504                FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3505                outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
3506                old_inhibit_defer_pop + 1, call_fusage,
3507                ((no_queue ? ECF_IS_CONST : 0)
3508                 | (nothrow ? ECF_NOTHROW : 0)));
3509
3510   pop_temp_slots ();
3511
3512   /* Now restore inhibit_defer_pop to its actual original value.  */
3513   OK_DEFER_POP;
3514
3515 #ifdef ACCUMULATE_OUTGOING_ARGS
3516 #ifdef REG_PARM_STACK_SPACE
3517   if (save_area)
3518     {
3519       enum machine_mode save_mode = GET_MODE (save_area);
3520 #ifdef ARGS_GROW_DOWNWARD
3521       rtx stack_area
3522         = gen_rtx_MEM (save_mode,
3523                        memory_address (save_mode,
3524                                        plus_constant (argblock,
3525                                                        - high_to_save)));
3526 #else
3527       rtx stack_area
3528         = gen_rtx_MEM (save_mode,
3529                        memory_address (save_mode,
3530                                        plus_constant (argblock, low_to_save)));
3531 #endif
3532
3533       if (save_mode != BLKmode)
3534         emit_move_insn (stack_area, save_area);
3535       else
3536         emit_block_move (stack_area, validize_mem (save_area),
3537                          GEN_INT (high_to_save - low_to_save + 1),
3538                          PARM_BOUNDARY / BITS_PER_UNIT);
3539     }
3540 #endif
3541           
3542   /* If we saved any argument areas, restore them.  */
3543   for (count = 0; count < nargs; count++)
3544     if (argvec[count].save_area)
3545       {
3546         enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3547         rtx stack_area
3548           = gen_rtx_MEM (save_mode,
3549                          memory_address
3550                          (save_mode,
3551                           plus_constant (argblock,
3552                                          argvec[count].offset.constant)));
3553
3554         emit_move_insn (stack_area, argvec[count].save_area);
3555       }
3556
3557   highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3558   stack_usage_map = initial_stack_usage_map;
3559 #endif
3560 }
3561 \f
3562 /* Like emit_library_call except that an extra argument, VALUE,
3563    comes second and says where to store the result.
3564    (If VALUE is zero, this function chooses a convenient way
3565    to return the value.
3566
3567    This function returns an rtx for where the value is to be found.
3568    If VALUE is nonzero, VALUE is returned.  */
3569
3570 rtx
3571 emit_library_call_value VPARAMS((rtx orgfun, rtx value, int no_queue,
3572                                  enum machine_mode outmode, int nargs, ...))
3573 {
3574 #ifndef ANSI_PROTOTYPES
3575   rtx orgfun;
3576   rtx value;
3577   int no_queue;
3578   enum machine_mode outmode;
3579   int nargs;
3580 #endif
3581   va_list p;
3582   /* Total size in bytes of all the stack-parms scanned so far.  */
3583   struct args_size args_size;
3584   /* Size of arguments before any adjustments (such as rounding).  */
3585   struct args_size original_args_size;
3586   register int argnum;
3587   rtx fun;
3588   int inc;
3589   int count;
3590   struct args_size alignment_pad;
3591   rtx argblock = 0;
3592   CUMULATIVE_ARGS args_so_far;
3593   struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
3594                struct args_size offset; struct args_size size; rtx save_area; };
3595   struct arg *argvec;
3596   int old_inhibit_defer_pop = inhibit_defer_pop;
3597   rtx call_fusage = 0;
3598   rtx mem_value = 0;
3599   int pcc_struct_value = 0;
3600   int struct_value_size = 0;
3601   int is_const;
3602   int reg_parm_stack_space = 0;
3603   int nothrow;
3604 #ifdef ACCUMULATE_OUTGOING_ARGS
3605   int needed;
3606 #endif
3607
3608 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3609   /* Define the boundary of the register parm stack space that needs to be
3610      save, if any.  */
3611   int low_to_save = -1, high_to_save = 0;
3612   rtx save_area = 0;            /* Place that it is saved */
3613 #endif
3614
3615 #ifdef ACCUMULATE_OUTGOING_ARGS
3616   /* Size of the stack reserved for parameter registers.  */
3617   int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3618   char *initial_stack_usage_map = stack_usage_map;
3619 #endif
3620
3621 #ifdef REG_PARM_STACK_SPACE
3622 #ifdef MAYBE_REG_PARM_STACK_SPACE
3623   reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3624 #else
3625   reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3626 #endif
3627 #endif
3628
3629   VA_START (p, nargs);
3630
3631 #ifndef ANSI_PROTOTYPES
3632   orgfun = va_arg (p, rtx);
3633   value = va_arg (p, rtx);
3634   no_queue = va_arg (p, int);
3635   outmode = va_arg (p, enum machine_mode);
3636   nargs = va_arg (p, int);
3637 #endif
3638
3639   is_const = no_queue;
3640   fun = orgfun;
3641
3642   nothrow = libfunc_nothrow (fun);
3643
3644 #ifdef PREFERRED_STACK_BOUNDARY
3645   /* Ensure current function's preferred stack boundary is at least
3646      what we need.  */
3647   if (cfun->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3648     cfun->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3649 #endif
3650
3651   /* If this kind of value comes back in memory,
3652      decide where in memory it should come back.  */
3653   if (aggregate_value_p (type_for_mode (outmode, 0)))
3654     {
3655 #ifdef PCC_STATIC_STRUCT_RETURN
3656       rtx pointer_reg
3657         = hard_function_value (build_pointer_type (type_for_mode (outmode, 0)),
3658                                0, 0);
3659       mem_value = gen_rtx_MEM (outmode, pointer_reg);
3660       pcc_struct_value = 1;
3661       if (value == 0)
3662         value = gen_reg_rtx (outmode);
3663 #else /* not PCC_STATIC_STRUCT_RETURN */
3664       struct_value_size = GET_MODE_SIZE (outmode);
3665       if (value != 0 && GET_CODE (value) == MEM)
3666         mem_value = value;
3667       else
3668         mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
3669 #endif
3670
3671       /* This call returns a big structure.  */
3672       is_const = 0;
3673     }
3674
3675   /* ??? Unfinished: must pass the memory address as an argument.  */
3676
3677   /* Copy all the libcall-arguments out of the varargs data
3678      and into a vector ARGVEC.
3679
3680      Compute how to pass each argument.  We only support a very small subset
3681      of the full argument passing conventions to limit complexity here since
3682      library functions shouldn't have many args.  */
3683
3684   argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
3685   bzero ((char *) argvec, (nargs + 1) * sizeof (struct arg));
3686
3687   INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
3688
3689   args_size.constant = 0;
3690   args_size.var = 0;
3691
3692   count = 0;
3693
3694   push_temp_slots ();
3695
3696   /* If there's a structure value address to be passed,
3697      either pass it in the special place, or pass it as an extra argument.  */
3698   if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
3699     {
3700       rtx addr = XEXP (mem_value, 0);
3701       nargs++;
3702
3703       /* Make sure it is a reasonable operand for a move or push insn.  */
3704       if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
3705           && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
3706         addr = force_operand (addr, NULL_RTX);
3707
3708       argvec[count].value = addr;
3709       argvec[count].mode = Pmode;
3710       argvec[count].partial = 0;
3711
3712       argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
3713 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3714       if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
3715         abort ();
3716 #endif
3717
3718       locate_and_pad_parm (Pmode, NULL_TREE,
3719                            argvec[count].reg && argvec[count].partial == 0,
3720                            NULL_TREE, &args_size, &argvec[count].offset,
3721                            &argvec[count].size, &alignment_pad);
3722
3723
3724       if (argvec[count].reg == 0 || argvec[count].partial != 0
3725           || reg_parm_stack_space > 0)
3726         args_size.constant += argvec[count].size.constant;
3727
3728       FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
3729
3730       count++;
3731     }
3732
3733   for (; count < nargs; count++)
3734     {
3735       rtx val = va_arg (p, rtx);
3736       enum machine_mode mode = va_arg (p, enum machine_mode);
3737
3738       /* We cannot convert the arg value to the mode the library wants here;
3739          must do it earlier where we know the signedness of the arg.  */
3740       if (mode == BLKmode
3741           || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
3742         abort ();
3743
3744       /* On some machines, there's no way to pass a float to a library fcn.
3745          Pass it as a double instead.  */
3746 #ifdef LIBGCC_NEEDS_DOUBLE
3747       if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
3748         val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
3749 #endif
3750
3751       /* There's no need to call protect_from_queue, because
3752          either emit_move_insn or emit_push_insn will do that.  */
3753
3754       /* Make sure it is a reasonable operand for a move or push insn.  */
3755       if (GET_CODE (val) != REG && GET_CODE (val) != MEM
3756           && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
3757         val = force_operand (val, NULL_RTX);
3758
3759 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3760       if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
3761         {
3762           /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
3763              be viewed as just an efficiency improvement.  */
3764           rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
3765           emit_move_insn (slot, val);
3766           val = XEXP (slot, 0);
3767           mode = Pmode;
3768         }
3769 #endif
3770
3771       argvec[count].value = val;
3772       argvec[count].mode = mode;
3773
3774       argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
3775
3776 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3777       argvec[count].partial
3778         = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3779 #else
3780       argvec[count].partial = 0;
3781 #endif
3782
3783       locate_and_pad_parm (mode, NULL_TREE,
3784                            argvec[count].reg && argvec[count].partial == 0,
3785                            NULL_TREE, &args_size, &argvec[count].offset,
3786                            &argvec[count].size, &alignment_pad);
3787
3788       if (argvec[count].size.var)
3789         abort ();
3790
3791       if (reg_parm_stack_space == 0 && argvec[count].partial)
3792         argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
3793
3794       if (argvec[count].reg == 0 || argvec[count].partial != 0
3795           || reg_parm_stack_space > 0)
3796         args_size.constant += argvec[count].size.constant;
3797
3798       FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3799     }
3800   va_end (p);
3801
3802 #ifdef FINAL_REG_PARM_STACK_SPACE
3803   reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
3804                                                      args_size.var);
3805 #endif
3806   /* If this machine requires an external definition for library
3807      functions, write one out.  */
3808   assemble_external_libcall (fun);
3809
3810   original_args_size = args_size;
3811 #ifdef PREFERRED_STACK_BOUNDARY
3812   args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
3813                          / STACK_BYTES) * STACK_BYTES);
3814 #endif
3815
3816   args_size.constant = MAX (args_size.constant,
3817                             reg_parm_stack_space);
3818
3819 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3820   args_size.constant -= reg_parm_stack_space;
3821 #endif
3822
3823   if (args_size.constant > current_function_outgoing_args_size)
3824     current_function_outgoing_args_size = args_size.constant;
3825
3826 #ifdef ACCUMULATE_OUTGOING_ARGS
3827   /* Since the stack pointer will never be pushed, it is possible for
3828      the evaluation of a parm to clobber something we have already
3829      written to the stack.  Since most function calls on RISC machines
3830      do not use the stack, this is uncommon, but must work correctly.
3831
3832      Therefore, we save any area of the stack that was already written
3833      and that we are using.  Here we set up to do this by making a new
3834      stack usage map from the old one.
3835
3836      Another approach might be to try to reorder the argument
3837      evaluations to avoid this conflicting stack usage.  */
3838
3839   needed = args_size.constant;
3840
3841 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3842   /* Since we will be writing into the entire argument area, the
3843      map must be allocated for its entire size, not just the part that
3844      is the responsibility of the caller.  */
3845   needed += reg_parm_stack_space;
3846 #endif
3847
3848 #ifdef ARGS_GROW_DOWNWARD
3849   highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3850                                      needed + 1);
3851 #else
3852   highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3853                                      needed);
3854 #endif
3855   stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3856
3857   if (initial_highest_arg_in_use)
3858     bcopy (initial_stack_usage_map, stack_usage_map,
3859            initial_highest_arg_in_use);
3860
3861   if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3862     bzero (&stack_usage_map[initial_highest_arg_in_use],
3863            highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3864   needed = 0;
3865
3866   /* The address of the outgoing argument list must not be copied to a
3867      register here, because argblock would be left pointing to the
3868      wrong place after the call to allocate_dynamic_stack_space below.
3869      */
3870
3871   argblock = virtual_outgoing_args_rtx;
3872 #else /* not ACCUMULATE_OUTGOING_ARGS */
3873 #ifndef PUSH_ROUNDING
3874   argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3875 #endif
3876 #endif
3877
3878 #ifdef PUSH_ARGS_REVERSED
3879 #ifdef PREFERRED_STACK_BOUNDARY
3880   /* If we push args individually in reverse order, perform stack alignment
3881      before the first push (the last arg).  */
3882   if (argblock == 0)
3883     anti_adjust_stack (GEN_INT (args_size.constant
3884                                 - original_args_size.constant));
3885 #endif
3886 #endif
3887
3888 #ifdef PUSH_ARGS_REVERSED
3889   inc = -1;
3890   argnum = nargs - 1;
3891 #else
3892   inc = 1;
3893   argnum = 0;
3894 #endif
3895
3896 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3897   /* The argument list is the property of the called routine and it
3898      may clobber it.  If the fixed area has been used for previous
3899      parameters, we must save and restore it.
3900
3901      Here we compute the boundary of the that needs to be saved, if any.  */
3902
3903 #ifdef ARGS_GROW_DOWNWARD
3904   for (count = 0; count < reg_parm_stack_space + 1; count++)
3905 #else
3906   for (count = 0; count < reg_parm_stack_space; count++)
3907 #endif
3908     {
3909       if (count >=  highest_outgoing_arg_in_use
3910           || stack_usage_map[count] == 0)
3911         continue;
3912
3913       if (low_to_save == -1)
3914         low_to_save = count;
3915
3916       high_to_save = count;
3917     }
3918
3919   if (low_to_save >= 0)
3920     {
3921       int num_to_save = high_to_save - low_to_save + 1;
3922       enum machine_mode save_mode
3923         = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
3924       rtx stack_area;
3925
3926       /* If we don't have the required alignment, must do this in BLKmode.  */
3927       if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
3928                                BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
3929         save_mode = BLKmode;
3930
3931 #ifdef ARGS_GROW_DOWNWARD
3932       stack_area = gen_rtx_MEM (save_mode,
3933                                 memory_address (save_mode,
3934                                                 plus_constant (argblock,
3935                                                                - high_to_save)));
3936 #else
3937       stack_area = gen_rtx_MEM (save_mode,
3938                                 memory_address (save_mode,
3939                                                 plus_constant (argblock,
3940                                                                low_to_save)));
3941 #endif
3942       if (save_mode == BLKmode)
3943         {
3944           save_area = assign_stack_temp (BLKmode, num_to_save, 0);
3945           emit_block_move (validize_mem (save_area), stack_area,
3946                            GEN_INT (num_to_save),
3947                            PARM_BOUNDARY / BITS_PER_UNIT);
3948         }
3949       else
3950         {
3951           save_area = gen_reg_rtx (save_mode);
3952           emit_move_insn (save_area, stack_area);
3953         }
3954     }
3955 #endif
3956           
3957   /* Push the args that need to be pushed.  */
3958
3959   /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3960      are to be pushed.  */
3961   for (count = 0; count < nargs; count++, argnum += inc)
3962     {
3963       register enum machine_mode mode = argvec[argnum].mode;
3964       register rtx val = argvec[argnum].value;
3965       rtx reg = argvec[argnum].reg;
3966       int partial = argvec[argnum].partial;
3967 #ifdef ACCUMULATE_OUTGOING_ARGS
3968       int lower_bound, upper_bound, i;
3969 #endif
3970
3971       if (! (reg != 0 && partial == 0))
3972         {
3973 #ifdef ACCUMULATE_OUTGOING_ARGS
3974           /* If this is being stored into a pre-allocated, fixed-size, stack
3975              area, save any previous data at that location.  */
3976
3977 #ifdef ARGS_GROW_DOWNWARD
3978           /* stack_slot is negative, but we want to index stack_usage_map
3979              with positive values.  */
3980           upper_bound = -argvec[argnum].offset.constant + 1;
3981           lower_bound = upper_bound - argvec[argnum].size.constant;
3982 #else
3983           lower_bound = argvec[argnum].offset.constant;
3984           upper_bound = lower_bound + argvec[argnum].size.constant;
3985 #endif
3986
3987           for (i = lower_bound; i < upper_bound; i++)
3988             if (stack_usage_map[i]
3989                 /* Don't store things in the fixed argument area at this point;
3990                    it has already been saved.  */
3991                 && i > reg_parm_stack_space)
3992               break;
3993
3994           if (i != upper_bound)
3995             {
3996               /* We need to make a save area.  See what mode we can make it. */
3997               enum machine_mode save_mode
3998                 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
3999                                  MODE_INT, 1);
4000               rtx stack_area
4001                 = gen_rtx_MEM
4002                   (save_mode,
4003                    memory_address
4004                    (save_mode,
4005                     plus_constant (argblock,
4006                                    argvec[argnum].offset.constant)));
4007               argvec[argnum].save_area = gen_reg_rtx (save_mode);
4008
4009               emit_move_insn (argvec[argnum].save_area, stack_area);
4010             }
4011 #endif
4012           emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
4013                           argblock, GEN_INT (argvec[argnum].offset.constant),
4014                           reg_parm_stack_space, ARGS_SIZE_RTX (alignment_pad));
4015
4016 #ifdef ACCUMULATE_OUTGOING_ARGS
4017           /* Now mark the segment we just used.  */
4018           for (i = lower_bound; i < upper_bound; i++)
4019             stack_usage_map[i] = 1;
4020 #endif
4021
4022           NO_DEFER_POP;
4023         }
4024     }
4025
4026 #ifndef PUSH_ARGS_REVERSED
4027 #ifdef PREFERRED_STACK_BOUNDARY
4028   /* If we pushed args in forward order, perform stack alignment
4029      after pushing the last arg.  */
4030   if (argblock == 0)
4031     anti_adjust_stack (GEN_INT (args_size.constant
4032                                 - original_args_size.constant));
4033 #endif
4034 #endif
4035
4036 #ifdef PUSH_ARGS_REVERSED
4037   argnum = nargs - 1;
4038 #else
4039   argnum = 0;
4040 #endif
4041
4042   fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
4043
4044   /* Now load any reg parms into their regs.  */
4045
4046   /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4047      are to be pushed.  */
4048   for (count = 0; count < nargs; count++, argnum += inc)
4049     {
4050       register rtx val = argvec[argnum].value;
4051       rtx reg = argvec[argnum].reg;
4052       int partial = argvec[argnum].partial;
4053
4054       /* Handle calls that pass values in multiple non-contiguous
4055          locations.  The PA64 has examples of this for library calls.  */
4056       if (reg != 0 && GET_CODE (reg) == PARALLEL)
4057         emit_group_load (reg, val,
4058                          GET_MODE_SIZE (GET_MODE (val)),
4059                          GET_MODE_ALIGNMENT (GET_MODE (val)));
4060       else if (reg != 0 && partial == 0)
4061         emit_move_insn (reg, val);
4062
4063       NO_DEFER_POP;
4064     }
4065
4066 #if 0
4067   /* For version 1.37, try deleting this entirely.  */
4068   if (! no_queue)
4069     emit_queue ();
4070 #endif
4071
4072   /* Any regs containing parms remain in use through the call.  */
4073   for (count = 0; count < nargs; count++)
4074     {
4075       rtx reg = argvec[count].reg;
4076       if (reg != 0 && GET_CODE (reg) == PARALLEL)
4077         use_group_regs (&call_fusage, reg);
4078       else if (reg != 0)
4079         use_reg (&call_fusage, reg);
4080     }
4081
4082   /* Pass the function the address in which to return a structure value.  */
4083   if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
4084     {
4085       emit_move_insn (struct_value_rtx,
4086                       force_reg (Pmode,
4087                                  force_operand (XEXP (mem_value, 0),
4088                                                 NULL_RTX)));
4089       if (GET_CODE (struct_value_rtx) == REG)
4090           use_reg (&call_fusage, struct_value_rtx);
4091     }
4092
4093   /* Don't allow popping to be deferred, since then
4094      cse'ing of library calls could delete a call and leave the pop.  */
4095   NO_DEFER_POP;
4096
4097   /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4098      will set inhibit_defer_pop to that value.  */
4099   /* See the comment in emit_library_call about the function type we build
4100      and pass here.  */
4101
4102   emit_call_1 (fun, 
4103                get_identifier (XSTR (orgfun, 0)),
4104                build_function_type (type_for_mode (outmode, 0), NULL_TREE),
4105                original_args_size.constant, args_size.constant,
4106                struct_value_size,
4107                FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
4108                mem_value == 0 ? hard_libcall_value (outmode) : NULL_RTX,
4109                old_inhibit_defer_pop + 1, call_fusage,
4110                ((is_const ? ECF_IS_CONST : 0)
4111                 | (nothrow ? ECF_NOTHROW : 0)));
4112
4113   /* Now restore inhibit_defer_pop to its actual original value.  */
4114   OK_DEFER_POP;
4115
4116   pop_temp_slots ();
4117
4118   /* Copy the value to the right place.  */
4119   if (outmode != VOIDmode)
4120     {
4121       if (mem_value)
4122         {
4123           if (value == 0)
4124             value = mem_value;
4125           if (value != mem_value)
4126             emit_move_insn (value, mem_value);
4127         }
4128       else if (value != 0)
4129         emit_move_insn (value, hard_libcall_value (outmode));
4130       else
4131         value = hard_libcall_value (outmode);
4132     }
4133
4134 #ifdef ACCUMULATE_OUTGOING_ARGS
4135 #ifdef REG_PARM_STACK_SPACE
4136   if (save_area)
4137     {
4138       enum machine_mode save_mode = GET_MODE (save_area);
4139 #ifdef ARGS_GROW_DOWNWARD
4140       rtx stack_area
4141         = gen_rtx_MEM (save_mode,
4142                        memory_address (save_mode,
4143                                        plus_constant (argblock,
4144                                                       - high_to_save)));
4145 #else
4146       rtx stack_area
4147         = gen_rtx_MEM (save_mode,
4148                        memory_address (save_mode,
4149                                        plus_constant (argblock, low_to_save)));
4150 #endif
4151       if (save_mode != BLKmode)
4152         emit_move_insn (stack_area, save_area);
4153       else
4154         emit_block_move (stack_area, validize_mem (save_area),
4155                          GEN_INT (high_to_save - low_to_save + 1),
4156                              PARM_BOUNDARY / BITS_PER_UNIT);
4157     }
4158 #endif
4159           
4160   /* If we saved any argument areas, restore them.  */
4161   for (count = 0; count < nargs; count++)
4162     if (argvec[count].save_area)
4163       {
4164         enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
4165         rtx stack_area
4166           = gen_rtx_MEM (save_mode,
4167                          memory_address
4168                          (save_mode,
4169                           plus_constant (argblock,
4170                                          argvec[count].offset.constant)));
4171
4172         emit_move_insn (stack_area, argvec[count].save_area);
4173       }
4174
4175   highest_outgoing_arg_in_use = initial_highest_arg_in_use;
4176   stack_usage_map = initial_stack_usage_map;
4177 #endif
4178
4179   return value;
4180 }
4181 \f
4182 #if 0
4183 /* Return an rtx which represents a suitable home on the stack
4184    given TYPE, the type of the argument looking for a home.
4185    This is called only for BLKmode arguments.
4186
4187    SIZE is the size needed for this target.
4188    ARGS_ADDR is the address of the bottom of the argument block for this call.
4189    OFFSET describes this parameter's offset into ARGS_ADDR.  It is meaningless
4190    if this machine uses push insns.  */
4191
4192 static rtx
4193 target_for_arg (type, size, args_addr, offset)
4194      tree type;
4195      rtx size;
4196      rtx args_addr;
4197      struct args_size offset;
4198 {
4199   rtx target;
4200   rtx offset_rtx = ARGS_SIZE_RTX (offset);
4201
4202   /* We do not call memory_address if possible,
4203      because we want to address as close to the stack
4204      as possible.  For non-variable sized arguments,
4205      this will be stack-pointer relative addressing.  */
4206   if (GET_CODE (offset_rtx) == CONST_INT)
4207     target = plus_constant (args_addr, INTVAL (offset_rtx));
4208   else
4209     {
4210       /* I have no idea how to guarantee that this
4211          will work in the presence of register parameters.  */
4212       target = gen_rtx_PLUS (Pmode, args_addr, offset_rtx);
4213       target = memory_address (QImode, target);
4214     }
4215
4216   return gen_rtx_MEM (BLKmode, target);
4217 }
4218 #endif
4219 \f
4220 /* Store a single argument for a function call
4221    into the register or memory area where it must be passed.
4222    *ARG describes the argument value and where to pass it.
4223
4224    ARGBLOCK is the address of the stack-block for all the arguments,
4225    or 0 on a machine where arguments are pushed individually.
4226
4227    MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4228    so must be careful about how the stack is used. 
4229
4230    VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4231    argument stack.  This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4232    that we need not worry about saving and restoring the stack.
4233
4234    FNDECL is the declaration of the function we are calling.  */
4235
4236 static void
4237 store_one_arg (arg, argblock, may_be_alloca, variable_size,
4238                reg_parm_stack_space)
4239      struct arg_data *arg;
4240      rtx argblock;
4241      int may_be_alloca;
4242      int variable_size ATTRIBUTE_UNUSED;
4243      int reg_parm_stack_space;
4244 {
4245   register tree pval = arg->tree_value;
4246   rtx reg = 0;
4247   int partial = 0;
4248   int used = 0;
4249 #ifdef ACCUMULATE_OUTGOING_ARGS
4250   int i, lower_bound = 0, upper_bound = 0;
4251 #endif
4252
4253   if (TREE_CODE (pval) == ERROR_MARK)
4254     return;
4255
4256   /* Push a new temporary level for any temporaries we make for
4257      this argument.  */
4258   push_temp_slots ();
4259
4260 #ifdef ACCUMULATE_OUTGOING_ARGS
4261   /* If this is being stored into a pre-allocated, fixed-size, stack area,
4262      save any previous data at that location.  */
4263   if (argblock && ! variable_size && arg->stack)
4264     {
4265 #ifdef ARGS_GROW_DOWNWARD
4266       /* stack_slot is negative, but we want to index stack_usage_map
4267          with positive values.  */
4268       if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4269         upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
4270       else
4271         upper_bound = 0;
4272
4273       lower_bound = upper_bound - arg->size.constant;
4274 #else
4275       if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4276         lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
4277       else
4278         lower_bound = 0;
4279
4280       upper_bound = lower_bound + arg->size.constant;
4281 #endif
4282
4283       for (i = lower_bound; i < upper_bound; i++)
4284         if (stack_usage_map[i]
4285             /* Don't store things in the fixed argument area at this point;
4286                it has already been saved.  */
4287             && i > reg_parm_stack_space)
4288           break;
4289
4290       if (i != upper_bound)
4291         {
4292           /* We need to make a save area.  See what mode we can make it.  */
4293           enum machine_mode save_mode
4294             = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
4295           rtx stack_area
4296             = gen_rtx_MEM (save_mode,
4297                            memory_address (save_mode,
4298                                            XEXP (arg->stack_slot, 0)));
4299
4300           if (save_mode == BLKmode)
4301             {
4302               arg->save_area = assign_stack_temp (BLKmode,
4303                                                   arg->size.constant, 0);
4304               MEM_SET_IN_STRUCT_P (arg->save_area,
4305                                    AGGREGATE_TYPE_P (TREE_TYPE
4306                                                      (arg->tree_value))); 
4307               preserve_temp_slots (arg->save_area);
4308               emit_block_move (validize_mem (arg->save_area), stack_area,
4309                                GEN_INT (arg->size.constant),
4310                                PARM_BOUNDARY / BITS_PER_UNIT);
4311             }
4312           else
4313             {
4314               arg->save_area = gen_reg_rtx (save_mode);
4315               emit_move_insn (arg->save_area, stack_area);
4316             }
4317         }
4318     }
4319
4320   /* Now that we have saved any slots that will be overwritten by this
4321      store, mark all slots this store will use.  We must do this before
4322      we actually expand the argument since the expansion itself may
4323      trigger library calls which might need to use the same stack slot.  */
4324   if (argblock && ! variable_size && arg->stack)
4325     for (i = lower_bound; i < upper_bound; i++)
4326       stack_usage_map[i] = 1;
4327 #endif
4328
4329   /* If this isn't going to be placed on both the stack and in registers,
4330      set up the register and number of words.  */
4331   if (! arg->pass_on_stack)
4332     reg = arg->reg, partial = arg->partial;
4333
4334   if (reg != 0 && partial == 0)
4335     /* Being passed entirely in a register.  We shouldn't be called in
4336        this case.   */
4337     abort ();
4338
4339   /* If this arg needs special alignment, don't load the registers
4340      here.  */
4341   if (arg->n_aligned_regs != 0)
4342     reg = 0;
4343   
4344   /* If this is being passed partially in a register, we can't evaluate
4345      it directly into its stack slot.  Otherwise, we can.  */
4346   if (arg->value == 0)
4347     {
4348 #ifdef ACCUMULATE_OUTGOING_ARGS
4349       /* stack_arg_under_construction is nonzero if a function argument is
4350          being evaluated directly into the outgoing argument list and
4351          expand_call must take special action to preserve the argument list
4352          if it is called recursively.
4353
4354          For scalar function arguments stack_usage_map is sufficient to
4355          determine which stack slots must be saved and restored.  Scalar
4356          arguments in general have pass_on_stack == 0.
4357
4358          If this argument is initialized by a function which takes the
4359          address of the argument (a C++ constructor or a C function
4360          returning a BLKmode structure), then stack_usage_map is
4361          insufficient and expand_call must push the stack around the
4362          function call.  Such arguments have pass_on_stack == 1.
4363
4364          Note that it is always safe to set stack_arg_under_construction,
4365          but this generates suboptimal code if set when not needed.  */
4366
4367       if (arg->pass_on_stack)
4368         stack_arg_under_construction++;
4369 #endif
4370       arg->value = expand_expr (pval,
4371                                 (partial
4372                                  || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
4373                                 ? NULL_RTX : arg->stack,
4374                                 VOIDmode, 0);
4375
4376       /* If we are promoting object (or for any other reason) the mode
4377          doesn't agree, convert the mode.  */
4378
4379       if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
4380         arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
4381                                     arg->value, arg->unsignedp);
4382
4383 #ifdef ACCUMULATE_OUTGOING_ARGS
4384       if (arg->pass_on_stack)
4385         stack_arg_under_construction--;
4386 #endif
4387     }
4388
4389   /* Don't allow anything left on stack from computation
4390      of argument to alloca.  */
4391   if (may_be_alloca)
4392     do_pending_stack_adjust ();
4393
4394   if (arg->value == arg->stack)
4395     {
4396       /* If the value is already in the stack slot, we are done.  */
4397       if (current_function_check_memory_usage && GET_CODE (arg->stack) == MEM)
4398         {
4399           emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4400                              XEXP (arg->stack, 0), Pmode, 
4401                              ARGS_SIZE_RTX (arg->size),
4402                              TYPE_MODE (sizetype),
4403                              GEN_INT (MEMORY_USE_RW),
4404                              TYPE_MODE (integer_type_node));
4405         }
4406     }
4407   else if (arg->mode != BLKmode)
4408     {
4409       register int size;
4410
4411       /* Argument is a scalar, not entirely passed in registers.
4412          (If part is passed in registers, arg->partial says how much
4413          and emit_push_insn will take care of putting it there.)
4414          
4415          Push it, and if its size is less than the
4416          amount of space allocated to it,
4417          also bump stack pointer by the additional space.
4418          Note that in C the default argument promotions
4419          will prevent such mismatches.  */
4420
4421       size = GET_MODE_SIZE (arg->mode);
4422       /* Compute how much space the push instruction will push.
4423          On many machines, pushing a byte will advance the stack
4424          pointer by a halfword.  */
4425 #ifdef PUSH_ROUNDING
4426       size = PUSH_ROUNDING (size);
4427 #endif
4428       used = size;
4429
4430       /* Compute how much space the argument should get:
4431          round up to a multiple of the alignment for arguments.  */
4432       if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
4433         used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4434                  / (PARM_BOUNDARY / BITS_PER_UNIT))
4435                 * (PARM_BOUNDARY / BITS_PER_UNIT));
4436
4437       /* This isn't already where we want it on the stack, so put it there.
4438          This can either be done with push or copy insns.  */
4439       emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, 0,
4440                       partial, reg, used - size, argblock,
4441                       ARGS_SIZE_RTX (arg->offset), reg_parm_stack_space,
4442                       ARGS_SIZE_RTX (arg->alignment_pad));
4443
4444       arg_space_so_far += used;
4445     }
4446   else
4447     {
4448       /* BLKmode, at least partly to be pushed.  */
4449
4450       register int excess;
4451       rtx size_rtx;
4452
4453       /* Pushing a nonscalar.
4454          If part is passed in registers, PARTIAL says how much
4455          and emit_push_insn will take care of putting it there.  */
4456
4457       /* Round its size up to a multiple
4458          of the allocation unit for arguments.  */
4459
4460       if (arg->size.var != 0)
4461         {
4462           excess = 0;
4463           size_rtx = ARGS_SIZE_RTX (arg->size);
4464         }
4465       else
4466         {
4467           /* PUSH_ROUNDING has no effect on us, because
4468              emit_push_insn for BLKmode is careful to avoid it.  */
4469           excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
4470                     + partial * UNITS_PER_WORD);
4471           size_rtx = expr_size (pval);
4472           arg_space_so_far += excess + INTVAL (size_rtx);
4473         }
4474
4475       emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
4476                       TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
4477                       reg, excess, argblock, ARGS_SIZE_RTX (arg->offset),
4478                       reg_parm_stack_space,
4479                       ARGS_SIZE_RTX (arg->alignment_pad));
4480     }
4481
4482
4483   /* Unless this is a partially-in-register argument, the argument is now
4484      in the stack. 
4485
4486      ??? Note that this can change arg->value from arg->stack to
4487      arg->stack_slot and it matters when they are not the same.
4488      It isn't totally clear that this is correct in all cases.  */
4489   if (partial == 0)
4490     arg->value = arg->stack_slot;
4491
4492   /* Once we have pushed something, pops can't safely
4493      be deferred during the rest of the arguments.  */
4494   NO_DEFER_POP;
4495
4496   /* ANSI doesn't require a sequence point here,
4497      but PCC has one, so this will avoid some problems.  */
4498   emit_queue ();
4499
4500   /* Free any temporary slots made in processing this argument.  Show
4501      that we might have taken the address of something and pushed that
4502      as an operand.  */
4503   preserve_temp_slots (NULL_RTX);
4504   free_temp_slots ();
4505   pop_temp_slots ();
4506 }