OSDN Git Service

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