OSDN Git Service

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