OSDN Git Service

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