OSDN Git Service

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