OSDN Git Service

1f69a63ee14423407fd18f4c79ad7fbf6a92f797
[pf3gnuchains/gcc-fork.git] / gcc / calls.c
1 /* Convert function calls to rtl insns, for GNU C compiler.
2    Copyright (C) 1989, 1992 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include "config.h"
21 #include "rtl.h"
22 #include "tree.h"
23 #include "flags.h"
24 #include "expr.h"
25 #include "insn-flags.h"
26
27 /* Decide whether a function's arguments should be processed
28    from first to last or from last to first.  */
29
30 #ifdef STACK_GROWS_DOWNWARD
31 #ifdef PUSH_ROUNDING
32 #define PUSH_ARGS_REVERSED      /* If it's last to first */
33 #endif
34 #endif
35
36 /* Like STACK_BOUNDARY but in units of bytes, not bits.  */
37 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
38
39 /* Data structure and subroutines used within expand_call.  */
40
41 struct arg_data
42 {
43   /* Tree node for this argument.  */
44   tree tree_value;
45   /* Mode for value; TYPE_MODE unless promoted.  */
46   enum machine_mode mode;
47   /* Current RTL value for argument, or 0 if it isn't precomputed.  */
48   rtx value;
49   /* Initially-compute RTL value for argument; only for const functions.  */
50   rtx initial_value;
51   /* Register to pass this argument in, 0 if passed on stack, or an
52      EXPR_LIST if the arg is to be copied into multiple different
53      registers.  */
54   rtx reg;
55   /* If REG was promoted from the actual mode of the argument expression,
56      indicates whether the promotion is sign- or zero-extended.  */
57   int unsignedp;
58   /* Number of registers to use.  0 means put the whole arg in registers.
59      Also 0 if not passed in registers.  */
60   int partial;
61   /* Non-zero if argument must be passed on stack.
62      Note that some arguments may be passed on the stack
63      even though pass_on_stack is zero, just because FUNCTION_ARG says so.
64      pass_on_stack identifies arguments that *cannot* go in registers.  */
65   int pass_on_stack;
66   /* Offset of this argument from beginning of stack-args.  */
67   struct args_size offset;
68   /* Similar, but offset to the start of the stack slot.  Different from
69      OFFSET if this arg pads downward.  */
70   struct args_size slot_offset;
71   /* Size of this argument on the stack, rounded up for any padding it gets,
72      parts of the argument passed in registers do not count.
73      If REG_PARM_STACK_SPACE is defined, then register parms
74      are counted here as well.  */
75   struct args_size size;
76   /* Location on the stack at which parameter should be stored.  The store
77      has already been done if STACK == VALUE.  */
78   rtx stack;
79   /* Location on the stack of the start of this argument slot.  This can
80      differ from STACK if this arg pads downward.  This location is known
81      to be aligned to FUNCTION_ARG_BOUNDARY.  */
82   rtx stack_slot;
83 #ifdef ACCUMULATE_OUTGOING_ARGS
84   /* Place that this stack area has been saved, if needed.  */
85   rtx save_area;
86 #endif
87 #ifdef STRICT_ALIGNMENT
88   /* If an argument's alignment does not permit direct copying into registers,
89      copy in smaller-sized pieces into pseudos.  These are stored in a
90      block pointed to by this field.  The next field says how many
91      word-sized pseudos we made.  */
92   rtx *aligned_regs;
93   int n_aligned_regs;
94 #endif
95 };
96
97 #ifdef ACCUMULATE_OUTGOING_ARGS
98 /* A vector of one char per byte of stack space.  A byte if non-zero if
99    the corresponding stack location has been used.
100    This vector is used to prevent a function call within an argument from
101    clobbering any stack already set up.  */
102 static char *stack_usage_map;
103
104 /* Size of STACK_USAGE_MAP.  */
105 static int highest_outgoing_arg_in_use;
106
107 /* stack_arg_under_construction is nonzero when an argument may be
108    initialized with a constructor call (including a C function that
109    returns a BLKmode struct) and expand_call must take special action
110    to make sure the object being constructed does not overlap the
111    argument list for the constructor call.  */
112 int stack_arg_under_construction;
113 #endif
114
115 static void store_one_arg ();
116 extern enum machine_mode mode_for_size ();
117 \f
118 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
119    `alloca'.
120
121    If WHICH is 0, return 1 if EXP contains a call to any function.
122    Actually, we only need return 1 if evaluating EXP would require pushing
123    arguments on the stack, but that is too difficult to compute, so we just
124    assume any function call might require the stack.  */
125
126 static int
127 calls_function (exp, which)
128      tree exp;
129      int which;
130 {
131   register int i;
132   int type = TREE_CODE_CLASS (TREE_CODE (exp));
133   int length = tree_code_length[(int) TREE_CODE (exp)];
134
135   /* Only expressions and references can contain calls.  */
136
137   if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
138       && type != 'b')
139     return 0;
140
141   switch (TREE_CODE (exp))
142     {
143     case CALL_EXPR:
144       if (which == 0)
145         return 1;
146       else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
147                && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
148                    == FUNCTION_DECL)
149                && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
150                && (DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
151                    == BUILT_IN_ALLOCA))
152         return 1;
153
154       /* Third operand is RTL.  */
155       length = 2;
156       break;
157
158     case SAVE_EXPR:
159       if (SAVE_EXPR_RTL (exp) != 0)
160         return 0;
161       break;
162
163     case BLOCK:
164       {
165         register tree local;
166
167         for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
168           if (DECL_INITIAL (local) != 0
169               && calls_function (DECL_INITIAL (local), which))
170             return 1;
171       }
172       {
173         register tree subblock;
174
175         for (subblock = BLOCK_SUBBLOCKS (exp);
176              subblock;
177              subblock = TREE_CHAIN (subblock))
178           if (calls_function (subblock, which))
179             return 1;
180       }
181       return 0;
182
183     case METHOD_CALL_EXPR:
184       length = 3;
185       break;
186
187     case WITH_CLEANUP_EXPR:
188       length = 1;
189       break;
190
191     case RTL_EXPR:
192       return 0;
193     }
194
195   for (i = 0; i < length; i++)
196     if (TREE_OPERAND (exp, i) != 0
197         && calls_function (TREE_OPERAND (exp, i), which))
198       return 1;
199
200   return 0;
201 }
202 \f
203 /* Force FUNEXP into a form suitable for the address of a CALL,
204    and return that as an rtx.  Also load the static chain register
205    if FNDECL is a nested function.
206
207    USE_INSNS points to a variable holding a chain of USE insns
208    to which a USE of the static chain
209    register should be added, if required.  */
210
211 rtx
212 prepare_call_address (funexp, fndecl, use_insns)
213      rtx funexp;
214      tree fndecl;
215      rtx *use_insns;
216 {
217   rtx static_chain_value = 0;
218
219   funexp = protect_from_queue (funexp, 0);
220
221   if (fndecl != 0)
222     /* Get possible static chain value for nested function in C. */
223     static_chain_value = lookup_static_chain (fndecl);
224
225   /* Make a valid memory address and copy constants thru pseudo-regs,
226      but not for a constant address if -fno-function-cse.  */
227   if (GET_CODE (funexp) != SYMBOL_REF)
228     funexp = memory_address (FUNCTION_MODE, funexp);
229   else
230     {
231 #ifndef NO_FUNCTION_CSE
232       if (optimize && ! flag_no_function_cse)
233 #ifdef NO_RECURSIVE_FUNCTION_CSE
234         if (fndecl != current_function_decl)
235 #endif
236           funexp = force_reg (Pmode, funexp);
237 #endif
238     }
239
240   if (static_chain_value != 0)
241     {
242       emit_move_insn (static_chain_rtx, static_chain_value);
243
244       /* Put the USE insn in the chain we were passed.  It will later be
245          output immediately in front of the CALL insn.  */
246       push_to_sequence (*use_insns);
247       emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx));
248       *use_insns = get_insns ();
249       end_sequence ();
250     }
251
252   return funexp;
253 }
254
255 /* Generate instructions to call function FUNEXP,
256    and optionally pop the results.
257    The CALL_INSN is the first insn generated.
258
259    FUNTYPE is the data type of the function, or, for a library call,
260    the identifier for the name of the call.  This is given to the
261    macro RETURN_POPS_ARGS to determine whether this function pops its own args.
262
263    STACK_SIZE is the number of bytes of arguments on the stack,
264    rounded up to STACK_BOUNDARY; zero if the size is variable.
265    This is both to put into the call insn and
266    to generate explicit popping code if necessary.
267
268    STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
269    It is zero if this call doesn't want a structure value.
270
271    NEXT_ARG_REG is the rtx that results from executing
272      FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
273    just after all the args have had their registers assigned.
274    This could be whatever you like, but normally it is the first
275    arg-register beyond those used for args in this call,
276    or 0 if all the arg-registers are used in this call.
277    It is passed on to `gen_call' so you can put this info in the call insn.
278
279    VALREG is a hard register in which a value is returned,
280    or 0 if the call does not return a value.
281
282    OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
283    the args to this call were processed.
284    We restore `inhibit_defer_pop' to that value.
285
286    USE_INSNS is a chain of USE insns to be emitted immediately before
287    the actual CALL insn.
288
289    IS_CONST is true if this is a `const' call.  */
290
291 void
292 emit_call_1 (funexp, funtype, stack_size, struct_value_size, next_arg_reg,
293              valreg, old_inhibit_defer_pop, use_insns, is_const)
294      rtx funexp;
295      tree funtype;
296      int stack_size;
297      int struct_value_size;
298      rtx next_arg_reg;
299      rtx valreg;
300      int old_inhibit_defer_pop;
301      rtx use_insns;
302      int is_const;
303 {
304   rtx stack_size_rtx = GEN_INT (stack_size);
305   rtx struct_value_size_rtx = GEN_INT (struct_value_size);
306   rtx call_insn;
307   int already_popped = 0;
308
309   /* Ensure address is valid.  SYMBOL_REF is already valid, so no need,
310      and we don't want to load it into a register as an optimization,
311      because prepare_call_address already did it if it should be done.  */
312   if (GET_CODE (funexp) != SYMBOL_REF)
313     funexp = memory_address (FUNCTION_MODE, funexp);
314
315 #ifndef ACCUMULATE_OUTGOING_ARGS
316 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
317   if (HAVE_call_pop && HAVE_call_value_pop
318       && (RETURN_POPS_ARGS (funtype, stack_size) > 0 || stack_size == 0))
319     {
320       rtx n_pop = GEN_INT (RETURN_POPS_ARGS (funtype, stack_size));
321       rtx pat;
322
323       /* If this subroutine pops its own args, record that in the call insn
324          if possible, for the sake of frame pointer elimination.  */
325       if (valreg)
326         pat = gen_call_value_pop (valreg,
327                                   gen_rtx (MEM, FUNCTION_MODE, funexp),
328                                   stack_size_rtx, next_arg_reg, n_pop);
329       else
330         pat = gen_call_pop (gen_rtx (MEM, FUNCTION_MODE, funexp),
331                             stack_size_rtx, next_arg_reg, n_pop);
332
333       emit_call_insn (pat);
334       already_popped = 1;
335     }
336   else
337 #endif
338 #endif
339
340 #if defined (HAVE_call) && defined (HAVE_call_value)
341   if (HAVE_call && HAVE_call_value)
342     {
343       if (valreg)
344         emit_call_insn (gen_call_value (valreg,
345                                         gen_rtx (MEM, FUNCTION_MODE, funexp),
346                                         stack_size_rtx, next_arg_reg,
347                                         NULL_RTX));
348       else
349         emit_call_insn (gen_call (gen_rtx (MEM, FUNCTION_MODE, funexp),
350                                   stack_size_rtx, next_arg_reg,
351                                   struct_value_size_rtx));
352     }
353   else
354 #endif
355     abort ();
356
357   /* Find the CALL insn we just emitted and write the USE insns before it.  */
358   for (call_insn = get_last_insn ();
359        call_insn && GET_CODE (call_insn) != CALL_INSN;
360        call_insn = PREV_INSN (call_insn))
361     ;
362
363   if (! call_insn)
364     abort ();
365
366   /* Put the USE insns before the CALL.  */
367   emit_insns_before (use_insns, call_insn);
368
369   /* If this is a const call, then set the insn's unchanging bit.  */
370   if (is_const)
371     CONST_CALL_P (call_insn) = 1;
372
373 #ifndef ACCUMULATE_OUTGOING_ARGS
374   /* If returning from the subroutine does not automatically pop the args,
375      we need an instruction to pop them sooner or later.
376      Perhaps do it now; perhaps just record how much space to pop later.
377
378      If returning from the subroutine does pop the args, indicate that the
379      stack pointer will be changed.  */
380
381   if (stack_size != 0 && RETURN_POPS_ARGS (funtype, stack_size) > 0)
382     {
383       if (!already_popped)
384         emit_insn (gen_rtx (CLOBBER, VOIDmode, stack_pointer_rtx));
385       stack_size -= RETURN_POPS_ARGS (funtype, stack_size);
386       stack_size_rtx = GEN_INT (stack_size);
387     }
388
389   if (stack_size != 0)
390     {
391       if (flag_defer_pop && inhibit_defer_pop == 0)
392         pending_stack_adjust += stack_size;
393       else
394         adjust_stack (stack_size_rtx);
395     }
396 #endif
397
398   inhibit_defer_pop = old_inhibit_defer_pop;
399 }
400
401 /* Generate all the code for a function call
402    and return an rtx for its value.
403    Store the value in TARGET (specified as an rtx) if convenient.
404    If the value is stored in TARGET then TARGET is returned.
405    If IGNORE is nonzero, then we ignore the value of the function call.  */
406
407 rtx
408 expand_call (exp, target, ignore)
409      tree exp;
410      rtx target;
411      int ignore;
412 {
413   /* List of actual parameters.  */
414   tree actparms = TREE_OPERAND (exp, 1);
415   /* RTX for the function to be called.  */
416   rtx funexp;
417   /* Tree node for the function to be called (not the address!).  */
418   tree funtree;
419   /* Data type of the function.  */
420   tree funtype;
421   /* Declaration of the function being called,
422      or 0 if the function is computed (not known by name).  */
423   tree fndecl = 0;
424   char *name = 0;
425
426   /* Register in which non-BLKmode value will be returned,
427      or 0 if no value or if value is BLKmode.  */
428   rtx valreg;
429   /* Address where we should return a BLKmode value;
430      0 if value not BLKmode.  */
431   rtx structure_value_addr = 0;
432   /* Nonzero if that address is being passed by treating it as
433      an extra, implicit first parameter.  Otherwise,
434      it is passed by being copied directly into struct_value_rtx.  */
435   int structure_value_addr_parm = 0;
436   /* Size of aggregate value wanted, or zero if none wanted
437      or if we are using the non-reentrant PCC calling convention
438      or expecting the value in registers.  */
439   int struct_value_size = 0;
440   /* Nonzero if called function returns an aggregate in memory PCC style,
441      by returning the address of where to find it.  */
442   int pcc_struct_value = 0;
443
444   /* Number of actual parameters in this call, including struct value addr.  */
445   int num_actuals;
446   /* Number of named args.  Args after this are anonymous ones
447      and they must all go on the stack.  */
448   int n_named_args;
449   /* Count arg position in order args appear.  */
450   int argpos;
451
452   /* Vector of information about each argument.
453      Arguments are numbered in the order they will be pushed,
454      not the order they are written.  */
455   struct arg_data *args;
456
457   /* Total size in bytes of all the stack-parms scanned so far.  */
458   struct args_size args_size;
459   /* Size of arguments before any adjustments (such as rounding).  */
460   struct args_size original_args_size;
461   /* Data on reg parms scanned so far.  */
462   CUMULATIVE_ARGS args_so_far;
463   /* Nonzero if a reg parm has been scanned.  */
464   int reg_parm_seen;
465
466   /* Nonzero if we must avoid push-insns in the args for this call. 
467      If stack space is allocated for register parameters, but not by the
468      caller, then it is preallocated in the fixed part of the stack frame.
469      So the entire argument block must then be preallocated (i.e., we
470      ignore PUSH_ROUNDING in that case).  */
471
472 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
473   int must_preallocate = 1;
474 #else
475 #ifdef PUSH_ROUNDING
476   int must_preallocate = 0;
477 #else
478   int must_preallocate = 1;
479 #endif
480 #endif
481
482   /* Size of the stack reserved for parameter registers.  */
483   int reg_parm_stack_space = 0;
484
485   /* 1 if scanning parms front to back, -1 if scanning back to front.  */
486   int inc;
487   /* Address of space preallocated for stack parms
488      (on machines that lack push insns), or 0 if space not preallocated.  */
489   rtx argblock = 0;
490
491   /* Nonzero if it is plausible that this is a call to alloca.  */
492   int may_be_alloca;
493   /* Nonzero if this is a call to setjmp or a related function.  */
494   int returns_twice;
495   /* Nonzero if this is a call to `longjmp'.  */
496   int is_longjmp;
497   /* Nonzero if this is a call to an inline function.  */
498   int is_integrable = 0;
499   /* Nonzero if this is a call to a `const' function.
500      Note that only explicitly named functions are handled as `const' here.  */
501   int is_const = 0;
502   /* Nonzero if this is a call to a `volatile' function.  */
503   int is_volatile = 0;
504 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
505   /* Define the boundary of the register parm stack space that needs to be
506      save, if any.  */
507   int low_to_save = -1, high_to_save;
508   rtx save_area = 0;            /* Place that it is saved */
509 #endif
510
511 #ifdef ACCUMULATE_OUTGOING_ARGS
512   int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
513   char *initial_stack_usage_map = stack_usage_map;
514 #endif
515
516   rtx old_stack_level = 0;
517   int old_pending_adj;
518   int old_stack_arg_under_construction;
519   int old_inhibit_defer_pop = inhibit_defer_pop;
520   tree old_cleanups = cleanups_this_call;
521
522   rtx use_insns = 0;
523
524   register tree p;
525   register int i, j;
526
527   /* See if we can find a DECL-node for the actual function.
528      As a result, decide whether this is a call to an integrable function.  */
529
530   p = TREE_OPERAND (exp, 0);
531   if (TREE_CODE (p) == ADDR_EXPR)
532     {
533       fndecl = TREE_OPERAND (p, 0);
534       if (TREE_CODE (fndecl) != FUNCTION_DECL)
535         {
536           /* May still be a `const' function if it is
537              a call through a pointer-to-const.
538              But we don't handle that.  */
539           fndecl = 0;
540         }
541       else
542         {
543           if (!flag_no_inline
544               && fndecl != current_function_decl
545               && DECL_SAVED_INSNS (fndecl))
546             is_integrable = 1;
547           else if (! TREE_ADDRESSABLE (fndecl))
548             {
549               /* In case this function later becomes inlinable,
550                  record that there was already a non-inline call to it.
551
552                  Use abstraction instead of setting TREE_ADDRESSABLE
553                  directly.  */
554               if (DECL_INLINE (fndecl) && extra_warnings && !flag_no_inline)
555                 warning_with_decl (fndecl, "can't inline call to `%s' which was declared inline");
556               mark_addressable (fndecl);
557             }
558
559           if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
560               && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
561             is_const = 1;
562         }
563     }
564
565   is_volatile = TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
566
567 #ifdef REG_PARM_STACK_SPACE
568 #ifdef MAYBE_REG_PARM_STACK_SPACE
569   reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
570 #else
571   reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
572 #endif
573 #endif
574
575   /* Warn if this value is an aggregate type,
576      regardless of which calling convention we are using for it.  */
577   if (warn_aggregate_return
578       && (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
579           || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
580           || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE))
581     warning ("function call has aggregate value");
582
583   /* Set up a place to return a structure.  */
584
585   /* Cater to broken compilers.  */
586   if (aggregate_value_p (exp))
587     {
588       /* This call returns a big structure.  */
589       is_const = 0;
590
591 #ifdef PCC_STATIC_STRUCT_RETURN
592       if (flag_pcc_struct_return)
593         {
594           pcc_struct_value = 1;
595           is_integrable = 0;  /* Easier than making that case work right.  */
596         }
597       else
598 #endif
599         {
600           struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
601
602           if (struct_value_size < 0)
603             abort ();
604
605           if (target && GET_CODE (target) == MEM)
606             structure_value_addr = XEXP (target, 0);
607           else
608             {
609               /* Assign a temporary on the stack to hold the value.  */
610
611               /* For variable-sized objects, we must be called with a target
612                  specified.  If we were to allocate space on the stack here,
613                  we would have no way of knowing when to free it.  */
614
615               structure_value_addr
616                 = XEXP (assign_stack_temp (BLKmode, struct_value_size, 1), 0);
617               target = 0;
618             }
619         }
620     }
621
622   /* If called function is inline, try to integrate it.  */
623
624   if (is_integrable)
625     {
626       rtx temp;
627       rtx before_call = get_last_insn ();
628
629       temp = expand_inline_function (fndecl, actparms, target,
630                                      ignore, TREE_TYPE (exp),
631                                      structure_value_addr);
632
633       /* If inlining succeeded, return.  */
634       if ((HOST_WIDE_INT) temp != -1)
635         {
636           /* Perform all cleanups needed for the arguments of this call
637              (i.e. destructors in C++).  It is ok if these destructors
638              clobber RETURN_VALUE_REG, because the only time we care about
639              this is when TARGET is that register.  But in C++, we take
640              care to never return that register directly.  */
641           expand_cleanups_to (old_cleanups);
642
643 #ifdef ACCUMULATE_OUTGOING_ARGS
644           /* If the outgoing argument list must be preserved, push
645              the stack before executing the inlined function if it
646              makes any calls.  */
647
648           for (i = reg_parm_stack_space - 1; i >= 0; i--)
649             if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
650               break;
651
652           if (stack_arg_under_construction || i >= 0)
653             {
654               rtx insn = NEXT_INSN (before_call), seq;
655
656               /* Look for a call in the inline function code.
657                  If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is
658                  nonzero then there is a call and it is not necessary
659                  to scan the insns.  */
660
661               if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0)
662                 for (; insn; insn = NEXT_INSN (insn))
663                   if (GET_CODE (insn) == CALL_INSN)
664                     break;
665
666               if (insn)
667                 {
668                   /* Reserve enough stack space so that the largest
669                      argument list of any function call in the inline
670                      function does not overlap the argument list being
671                      evaluated.  This is usually an overestimate because
672                      allocate_dynamic_stack_space reserves space for an
673                      outgoing argument list in addition to the requested
674                      space, but there is no way to ask for stack space such
675                      that an argument list of a certain length can be
676                      safely constructed.  */
677
678                   int adjust = OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl));
679 #ifdef REG_PARM_STACK_SPACE
680                   /* Add the stack space reserved for register arguments
681                      in the inline function.  What is really needed is the
682                      largest value of reg_parm_stack_space in the inline
683                      function, but that is not available.  Using the current
684                      value of reg_parm_stack_space is wrong, but gives
685                      correct results on all supported machines.  */
686                   adjust += reg_parm_stack_space;
687 #endif
688                   start_sequence ();
689                   emit_stack_save (SAVE_BLOCK, &old_stack_level, 0);
690                   allocate_dynamic_stack_space (GEN_INT (adjust),
691                                                 NULL_RTX, BITS_PER_UNIT);
692                   seq = get_insns ();
693                   end_sequence ();
694                   emit_insns_before (seq, NEXT_INSN (before_call));
695                   emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
696                 }
697             }
698 #endif
699
700           /* If the result is equivalent to TARGET, return TARGET to simplify
701              checks in store_expr.  They can be equivalent but not equal in the
702              case of a function that returns BLKmode.  */
703           if (temp != target && rtx_equal_p (temp, target))
704             return target;
705           return temp;
706         }
707
708       /* If inlining failed, mark FNDECL as needing to be compiled
709          separately after all.  */
710       mark_addressable (fndecl);
711     }
712
713   /* When calling a const function, we must pop the stack args right away,
714      so that the pop is deleted or moved with the call.  */
715   if (is_const)
716     NO_DEFER_POP;
717
718   function_call_count++;
719
720   if (fndecl && DECL_NAME (fndecl))
721     name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
722
723 #if 0
724   /* Unless it's a call to a specific function that isn't alloca,
725      if it has one argument, we must assume it might be alloca.  */
726
727   may_be_alloca =
728     (!(fndecl != 0 && strcmp (name, "alloca"))
729      && actparms != 0
730      && TREE_CHAIN (actparms) == 0);
731 #else
732   /* We assume that alloca will always be called by name.  It
733      makes no sense to pass it as a pointer-to-function to
734      anything that does not understand its behavior.  */
735   may_be_alloca =
736     (name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
737                  && name[0] == 'a'
738                  && ! strcmp (name, "alloca"))
739                 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
740                     && name[0] == '_'
741                     && ! strcmp (name, "__builtin_alloca"))));
742 #endif
743
744   /* See if this is a call to a function that can return more than once
745      or a call to longjmp.  */
746
747   returns_twice = 0;
748   is_longjmp = 0;
749
750   if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 15)
751     {
752       char *tname = name;
753
754       if (name[0] == '_')
755         tname += ((name[1] == '_' && name[2] == 'x') ? 3 : 1);
756
757       if (tname[0] == 's')
758         {
759           returns_twice
760             = ((tname[1] == 'e'
761                 && (! strcmp (tname, "setjmp")
762                     || ! strcmp (tname, "setjmp_syscall")))
763                || (tname[1] == 'i'
764                    && ! strcmp (tname, "sigsetjmp"))
765                || (tname[1] == 'a'
766                    && ! strcmp (tname, "savectx")));
767           if (tname[1] == 'i'
768               && ! strcmp (tname, "siglongjmp"))
769             is_longjmp = 1;
770         }
771       else if ((tname[0] == 'q' && tname[1] == 's'
772                 && ! strcmp (tname, "qsetjmp"))
773                || (tname[0] == 'v' && tname[1] == 'f'
774                    && ! strcmp (tname, "vfork")))
775         returns_twice = 1;
776
777       else if (tname[0] == 'l' && tname[1] == 'o'
778                && ! strcmp (tname, "longjmp"))
779         is_longjmp = 1;
780     }
781
782   if (may_be_alloca)
783     current_function_calls_alloca = 1;
784
785   /* Don't let pending stack adjusts add up to too much.
786      Also, do all pending adjustments now
787      if there is any chance this might be a call to alloca.  */
788
789   if (pending_stack_adjust >= 32
790       || (pending_stack_adjust > 0 && may_be_alloca))
791     do_pending_stack_adjust ();
792
793   /* Operand 0 is a pointer-to-function; get the type of the function.  */
794   funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
795   if (TREE_CODE (funtype) != POINTER_TYPE)
796     abort ();
797   funtype = TREE_TYPE (funtype);
798
799   /* Push the temporary stack slot level so that we can free temporaries used
800      by each of the arguments separately.  */
801   push_temp_slots ();
802
803   /* Start updating where the next arg would go.  */
804   INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX);
805
806   /* If struct_value_rtx is 0, it means pass the address
807      as if it were an extra parameter.  */
808   if (structure_value_addr && struct_value_rtx == 0)
809     {
810 #ifdef ACCUMULATE_OUTGOING_ARGS
811       /* If the stack will be adjusted, make sure the structure address
812          does not refer to virtual_outgoing_args_rtx.  */
813       rtx temp = (stack_arg_under_construction
814                   ? copy_addr_to_reg (structure_value_addr)
815                   : force_reg (Pmode, structure_value_addr));
816 #else
817       rtx temp = force_reg (Pmode, structure_value_addr);
818 #endif
819
820       actparms
821         = tree_cons (error_mark_node,
822                      make_tree (build_pointer_type (TREE_TYPE (funtype)),
823                                 temp),
824                      actparms);
825       structure_value_addr_parm = 1;
826     }
827
828   /* Count the arguments and set NUM_ACTUALS.  */
829   for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
830   num_actuals = i;
831
832   /* Compute number of named args.
833      Normally, don't include the last named arg if anonymous args follow.
834      (If no anonymous args follow, the result of list_length
835      is actually one too large.)
836
837      If SETUP_INCOMING_VARARGS is defined, this machine will be able to
838      place unnamed args that were passed in registers into the stack.  So
839      treat all args as named.  This allows the insns emitting for a specific
840      argument list to be independent of the function declaration.
841
842      If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable
843      way to pass unnamed args in registers, so we must force them into
844      memory.  */
845 #ifndef SETUP_INCOMING_VARARGS
846   if (TYPE_ARG_TYPES (funtype) != 0)
847     n_named_args
848       = list_length (TYPE_ARG_TYPES (funtype)) - 1
849         /* Count the struct value address, if it is passed as a parm.  */
850         + structure_value_addr_parm;
851   else
852 #endif
853     /* If we know nothing, treat all args as named.  */
854     n_named_args = num_actuals;
855
856   /* Make a vector to hold all the information about each arg.  */
857   args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
858   bzero (args, num_actuals * sizeof (struct arg_data));
859
860   args_size.constant = 0;
861   args_size.var = 0;
862
863   /* In this loop, we consider args in the order they are written.
864      We fill up ARGS from the front of from the back if necessary
865      so that in any case the first arg to be pushed ends up at the front.  */
866
867 #ifdef PUSH_ARGS_REVERSED
868   i = num_actuals - 1, inc = -1;
869   /* In this case, must reverse order of args
870      so that we compute and push the last arg first.  */
871 #else
872   i = 0, inc = 1;
873 #endif
874
875   /* I counts args in order (to be) pushed; ARGPOS counts in order written.  */
876   for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
877     {
878       tree type = TREE_TYPE (TREE_VALUE (p));
879       enum machine_mode mode;
880
881       args[i].tree_value = TREE_VALUE (p);
882
883       /* Replace erroneous argument with constant zero.  */
884       if (type == error_mark_node || TYPE_SIZE (type) == 0)
885         args[i].tree_value = integer_zero_node, type = integer_type_node;
886
887       /* Decide where to pass this arg.
888
889          args[i].reg is nonzero if all or part is passed in registers.
890
891          args[i].partial is nonzero if part but not all is passed in registers,
892          and the exact value says how many words are passed in registers.
893
894          args[i].pass_on_stack is nonzero if the argument must at least be
895          computed on the stack.  It may then be loaded back into registers
896          if args[i].reg is nonzero.
897
898          These decisions are driven by the FUNCTION_... macros and must agree
899          with those made by function.c.  */
900
901 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
902       /* See if this argument should be passed by invisible reference.  */
903       if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, TYPE_MODE (type), type,
904                                           argpos < n_named_args))
905         {
906           /* We make a copy of the object and pass the address to the function
907              being called.  */
908           rtx copy;
909
910           if (TYPE_SIZE (type) == 0
911               || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
912             {
913               /* This is a variable-sized object.  Make space on the stack
914                  for it.  */
915               rtx size_rtx = expand_expr (size_in_bytes (type), NULL_RTX,
916                                           VOIDmode, 0);
917
918               if (old_stack_level == 0)
919                 {
920                   emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
921                   old_pending_adj = pending_stack_adjust;
922                   pending_stack_adjust = 0;
923                 }
924
925               copy = gen_rtx (MEM, BLKmode,
926                               allocate_dynamic_stack_space (size_rtx, NULL_RTX,
927                                                             TYPE_ALIGN (type)));
928             }
929           else
930             {
931               int size = int_size_in_bytes (type);
932               copy = assign_stack_temp (TYPE_MODE (type), size, 1);
933             }
934
935           store_expr (args[i].tree_value, copy, 0);
936
937           args[i].tree_value = build1 (ADDR_EXPR, build_pointer_type (type),
938                                        make_tree (type, copy));
939           type = build_pointer_type (type);
940         }
941 #endif
942
943       mode = TYPE_MODE (type);
944
945 #ifdef PROMOTE_FUNCTION_ARGS
946       /* Compute the mode in which the arg is actually to be extended to.  */
947       if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == ENUMERAL_TYPE
948           || TREE_CODE (type) == BOOLEAN_TYPE || TREE_CODE (type) == CHAR_TYPE
949           || TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == POINTER_TYPE
950           || TREE_CODE (type) == OFFSET_TYPE)
951         {
952           int unsignedp = TREE_UNSIGNED (type);
953           PROMOTE_MODE (mode, unsignedp, type);
954           args[i].unsignedp = unsignedp;
955         }
956 #endif
957
958       args[i].mode = mode;
959       args[i].reg = FUNCTION_ARG (args_so_far, mode, type,
960                                   argpos < n_named_args);
961 #ifdef FUNCTION_ARG_PARTIAL_NREGS
962       if (args[i].reg)
963         args[i].partial
964           = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, type,
965                                         argpos < n_named_args);
966 #endif
967
968       args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
969
970       /* If FUNCTION_ARG returned an (expr_list (nil) FOO), it means that
971          we are to pass this arg in the register(s) designated by FOO, but
972          also to pass it in the stack.  */
973       if (args[i].reg && GET_CODE (args[i].reg) == EXPR_LIST
974           && XEXP (args[i].reg, 0) == 0)
975         args[i].pass_on_stack = 1, args[i].reg = XEXP (args[i].reg, 1);
976
977       /* If this is an addressable type, we must preallocate the stack
978          since we must evaluate the object into its final location.
979
980          If this is to be passed in both registers and the stack, it is simpler
981          to preallocate.  */
982       if (TREE_ADDRESSABLE (type)
983           || (args[i].pass_on_stack && args[i].reg != 0))
984         must_preallocate = 1;
985
986       /* If this is an addressable type, we cannot pre-evaluate it.  Thus,
987          we cannot consider this function call constant.  */
988       if (TREE_ADDRESSABLE (type))
989         is_const = 0;
990
991       /* Compute the stack-size of this argument.  */
992       if (args[i].reg == 0 || args[i].partial != 0
993 #ifdef REG_PARM_STACK_SPACE
994           || reg_parm_stack_space > 0
995 #endif
996           || args[i].pass_on_stack)
997         locate_and_pad_parm (mode, type,
998 #ifdef STACK_PARMS_IN_REG_PARM_AREA
999                              1,
1000 #else
1001                              args[i].reg != 0,
1002 #endif
1003                              fndecl, &args_size, &args[i].offset,
1004                              &args[i].size);
1005
1006 #ifndef ARGS_GROW_DOWNWARD
1007       args[i].slot_offset = args_size;
1008 #endif
1009
1010 #ifndef REG_PARM_STACK_SPACE
1011       /* If a part of the arg was put into registers,
1012          don't include that part in the amount pushed.  */
1013       if (! args[i].pass_on_stack)
1014         args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1015                                   / (PARM_BOUNDARY / BITS_PER_UNIT)
1016                                   * (PARM_BOUNDARY / BITS_PER_UNIT));
1017 #endif
1018       
1019       /* Update ARGS_SIZE, the total stack space for args so far.  */
1020
1021       args_size.constant += args[i].size.constant;
1022       if (args[i].size.var)
1023         {
1024           ADD_PARM_SIZE (args_size, args[i].size.var);
1025         }
1026
1027       /* Since the slot offset points to the bottom of the slot,
1028          we must record it after incrementing if the args grow down.  */
1029 #ifdef ARGS_GROW_DOWNWARD
1030       args[i].slot_offset = args_size;
1031
1032       args[i].slot_offset.constant = -args_size.constant;
1033       if (args_size.var)
1034         {
1035           SUB_PARM_SIZE (args[i].slot_offset, args_size.var);
1036         }
1037 #endif
1038
1039       /* Increment ARGS_SO_FAR, which has info about which arg-registers
1040          have been used, etc.  */
1041
1042       FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type,
1043                             argpos < n_named_args);
1044     }
1045
1046 #ifdef FINAL_REG_PARM_STACK_SPACE
1047   reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
1048                                                      args_size.var);
1049 #endif
1050       
1051   /* Compute the actual size of the argument block required.  The variable
1052      and constant sizes must be combined, the size may have to be rounded,
1053      and there may be a minimum required size.  */
1054
1055   original_args_size = args_size;
1056   if (args_size.var)
1057     {
1058       /* If this function requires a variable-sized argument list, don't try to
1059          make a cse'able block for this call.  We may be able to do this
1060          eventually, but it is too complicated to keep track of what insns go
1061          in the cse'able block and which don't.  */
1062
1063       is_const = 0;
1064       must_preallocate = 1;
1065
1066       args_size.var = ARGS_SIZE_TREE (args_size);
1067       args_size.constant = 0;
1068
1069 #ifdef STACK_BOUNDARY
1070       if (STACK_BOUNDARY != BITS_PER_UNIT)
1071         args_size.var = round_up (args_size.var, STACK_BYTES);
1072 #endif
1073
1074 #ifdef REG_PARM_STACK_SPACE
1075       if (reg_parm_stack_space > 0)
1076         {
1077           args_size.var
1078             = size_binop (MAX_EXPR, args_size.var,
1079                           size_int (REG_PARM_STACK_SPACE (fndecl)));
1080
1081 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1082           /* The area corresponding to register parameters is not to count in
1083              the size of the block we need.  So make the adjustment.  */
1084           args_size.var
1085             = size_binop (MINUS_EXPR, args_size.var,
1086                           size_int (reg_parm_stack_space));
1087 #endif
1088         }
1089 #endif
1090     }
1091   else
1092     {
1093 #ifdef STACK_BOUNDARY
1094       args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
1095                              / STACK_BYTES) * STACK_BYTES);
1096 #endif
1097
1098 #ifdef REG_PARM_STACK_SPACE
1099       args_size.constant = MAX (args_size.constant,
1100                                 reg_parm_stack_space);
1101 #ifdef MAYBE_REG_PARM_STACK_SPACE
1102       if (reg_parm_stack_space == 0)
1103         args_size.constant = 0;
1104 #endif
1105 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1106       args_size.constant -= reg_parm_stack_space;
1107 #endif
1108 #endif
1109     }
1110
1111   /* See if we have or want to preallocate stack space.
1112
1113      If we would have to push a partially-in-regs parm
1114      before other stack parms, preallocate stack space instead.
1115
1116      If the size of some parm is not a multiple of the required stack
1117      alignment, we must preallocate.
1118
1119      If the total size of arguments that would otherwise create a copy in
1120      a temporary (such as a CALL) is more than half the total argument list
1121      size, preallocation is faster.
1122
1123      Another reason to preallocate is if we have a machine (like the m88k)
1124      where stack alignment is required to be maintained between every
1125      pair of insns, not just when the call is made.  However, we assume here
1126      that such machines either do not have push insns (and hence preallocation
1127      would occur anyway) or the problem is taken care of with
1128      PUSH_ROUNDING.  */
1129
1130   if (! must_preallocate)
1131     {
1132       int partial_seen = 0;
1133       int copy_to_evaluate_size = 0;
1134
1135       for (i = 0; i < num_actuals && ! must_preallocate; i++)
1136         {
1137           if (args[i].partial > 0 && ! args[i].pass_on_stack)
1138             partial_seen = 1;
1139           else if (partial_seen && args[i].reg == 0)
1140             must_preallocate = 1;
1141
1142           if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1143               && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1144                   || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1145                   || TREE_CODE (args[i].tree_value) == COND_EXPR
1146                   || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1147             copy_to_evaluate_size
1148               += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1149         }
1150
1151       if (copy_to_evaluate_size * 2 >= args_size.constant
1152           && args_size.constant > 0)
1153         must_preallocate = 1;
1154     }
1155
1156   /* If the structure value address will reference the stack pointer, we must
1157      stabilize it.  We don't need to do this if we know that we are not going
1158      to adjust the stack pointer in processing this call.  */
1159
1160   if (structure_value_addr
1161       && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
1162        || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr))
1163       && (args_size.var
1164 #ifndef ACCUMULATE_OUTGOING_ARGS
1165           || args_size.constant
1166 #endif
1167           ))
1168     structure_value_addr = copy_to_reg (structure_value_addr);
1169
1170   /* If this function call is cse'able, precompute all the parameters.
1171      Note that if the parameter is constructed into a temporary, this will
1172      cause an additional copy because the parameter will be constructed
1173      into a temporary location and then copied into the outgoing arguments.
1174      If a parameter contains a call to alloca and this function uses the
1175      stack, precompute the parameter.  */
1176
1177   /* If we preallocated the stack space, and some arguments must be passed
1178      on the stack, then we must precompute any parameter which contains a
1179      function call which will store arguments on the stack.
1180      Otherwise, evaluating the parameter may clobber previous parameters
1181      which have already been stored into the stack.  */
1182
1183   for (i = 0; i < num_actuals; i++)
1184     if (is_const
1185         || ((args_size.var != 0 || args_size.constant != 0)
1186             && calls_function (args[i].tree_value, 1))
1187         || (must_preallocate && (args_size.var != 0 || args_size.constant != 0)
1188             && calls_function (args[i].tree_value, 0)))
1189       {
1190         args[i].initial_value = args[i].value
1191           = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1192
1193         if (GET_MODE (args[i].value ) != VOIDmode
1194             && GET_MODE (args[i].value) != args[i].mode)
1195           args[i].value = convert_to_mode (args[i].mode, args[i].value,
1196                                            args[i].unsignedp);
1197         preserve_temp_slots (args[i].value);
1198
1199         free_temp_slots ();
1200
1201         /* ANSI doesn't require a sequence point here,
1202            but PCC has one, so this will avoid some problems.  */
1203         emit_queue ();
1204       }
1205
1206   /* Now we are about to start emitting insns that can be deleted
1207      if a libcall is deleted.  */
1208   if (is_const)
1209     start_sequence ();
1210
1211   /* If we have no actual push instructions, or shouldn't use them,
1212      make space for all args right now.  */
1213
1214   if (args_size.var != 0)
1215     {
1216       if (old_stack_level == 0)
1217         {
1218           emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1219           old_pending_adj = pending_stack_adjust;
1220           pending_stack_adjust = 0;
1221 #ifdef ACCUMULATE_OUTGOING_ARGS
1222           /* stack_arg_under_construction says whether a stack arg is
1223              being constructed at the old stack level.  Pushing the stack
1224              gets a clean outgoing argument block.  */
1225           old_stack_arg_under_construction = stack_arg_under_construction;
1226           stack_arg_under_construction = 0;
1227 #endif
1228         }
1229       argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
1230     }
1231   else if (must_preallocate)
1232     {
1233       /* Note that we must go through the motions of allocating an argument
1234          block even if the size is zero because we may be storing args
1235          in the area reserved for register arguments, which may be part of
1236          the stack frame.  */
1237       int needed = args_size.constant;
1238
1239 #ifdef ACCUMULATE_OUTGOING_ARGS
1240       /* Store the maximum argument space used.  It will be pushed by the
1241          prologue.
1242
1243          Since the stack pointer will never be pushed, it is possible for
1244          the evaluation of a parm to clobber something we have already
1245          written to the stack.  Since most function calls on RISC machines
1246          do not use the stack, this is uncommon, but must work correctly.
1247          
1248          Therefore, we save any area of the stack that was already written
1249          and that we are using.  Here we set up to do this by making a new
1250          stack usage map from the old one.  The actual save will be done
1251          by store_one_arg. 
1252
1253          Another approach might be to try to reorder the argument
1254          evaluations to avoid this conflicting stack usage.  */
1255
1256       if (needed > current_function_outgoing_args_size)
1257         current_function_outgoing_args_size = needed;
1258
1259 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1260       /* Since we will be writing into the entire argument area, the
1261          map must be allocated for its entire size, not just the part that
1262          is the responsibility of the caller.  */
1263       needed += reg_parm_stack_space;
1264 #endif
1265
1266 #ifdef ARGS_GROW_DOWNWARD
1267       highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1268                                          needed + 1);
1269 #else
1270       highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, needed);
1271 #endif
1272       stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
1273
1274       if (initial_highest_arg_in_use)
1275         bcopy (initial_stack_usage_map, stack_usage_map,
1276                initial_highest_arg_in_use);
1277
1278       if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
1279         bzero (&stack_usage_map[initial_highest_arg_in_use],
1280                highest_outgoing_arg_in_use - initial_highest_arg_in_use);
1281       needed = 0;
1282
1283       /* The address of the outgoing argument list must not be copied to a
1284          register here, because argblock would be left pointing to the
1285          wrong place after the call to allocate_dynamic_stack_space below. */
1286
1287       argblock = virtual_outgoing_args_rtx;
1288
1289 #else /* not ACCUMULATE_OUTGOING_ARGS */
1290       if (inhibit_defer_pop == 0)
1291         {
1292           /* Try to reuse some or all of the pending_stack_adjust
1293              to get this space.  Maybe we can avoid any pushing.  */
1294           if (needed > pending_stack_adjust)
1295             {
1296               needed -= pending_stack_adjust;
1297               pending_stack_adjust = 0;
1298             }
1299           else
1300             {
1301               pending_stack_adjust -= needed;
1302               needed = 0;
1303             }
1304         }
1305       /* Special case this because overhead of `push_block' in this
1306          case is non-trivial.  */
1307       if (needed == 0)
1308         argblock = virtual_outgoing_args_rtx;
1309       else
1310         argblock = push_block (GEN_INT (needed), 0, 0);
1311
1312       /* We only really need to call `copy_to_reg' in the case where push
1313          insns are going to be used to pass ARGBLOCK to a function
1314          call in ARGS.  In that case, the stack pointer changes value
1315          from the allocation point to the call point, and hence
1316          the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
1317          But might as well always do it.  */
1318       argblock = copy_to_reg (argblock);
1319 #endif /* not ACCUMULATE_OUTGOING_ARGS */
1320     }
1321
1322
1323 #ifdef ACCUMULATE_OUTGOING_ARGS
1324   /* The save/restore code in store_one_arg handles all cases except one:
1325      a constructor call (including a C function returning a BLKmode struct)
1326      to initialize an argument.  */
1327   if (stack_arg_under_construction)
1328     {
1329 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1330       rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
1331 #else
1332       rtx push_size = GEN_INT (args_size.constant);
1333 #endif
1334       if (old_stack_level == 0)
1335         {
1336           emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1337           old_pending_adj = pending_stack_adjust;
1338           pending_stack_adjust = 0;
1339           /* stack_arg_under_construction says whether a stack arg is
1340              being constructed at the old stack level.  Pushing the stack
1341              gets a clean outgoing argument block.  */
1342           old_stack_arg_under_construction = stack_arg_under_construction;
1343           stack_arg_under_construction = 0;
1344           /* Make a new map for the new argument list.  */
1345           stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
1346           bzero (stack_usage_map, highest_outgoing_arg_in_use);
1347           highest_outgoing_arg_in_use = 0;
1348         }
1349       allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
1350     }
1351   /* If argument evaluation might modify the stack pointer, copy the
1352      address of the argument list to a register.  */
1353   for (i = 0; i < num_actuals; i++)
1354     if (args[i].pass_on_stack)
1355       {
1356         argblock = copy_addr_to_reg (argblock);
1357         break;
1358       }
1359 #endif
1360
1361
1362   /* If we preallocated stack space, compute the address of each argument.
1363      We need not ensure it is a valid memory address here; it will be 
1364      validized when it is used.  */
1365   if (argblock)
1366     {
1367       rtx arg_reg = argblock;
1368       int arg_offset = 0;
1369
1370       if (GET_CODE (argblock) == PLUS)
1371         arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1372
1373       for (i = 0; i < num_actuals; i++)
1374         {
1375           rtx offset = ARGS_SIZE_RTX (args[i].offset);
1376           rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1377           rtx addr;
1378
1379           /* Skip this parm if it will not be passed on the stack.  */
1380           if (! args[i].pass_on_stack && args[i].reg != 0)
1381             continue;
1382
1383           if (GET_CODE (offset) == CONST_INT)
1384             addr = plus_constant (arg_reg, INTVAL (offset));
1385           else
1386             addr = gen_rtx (PLUS, Pmode, arg_reg, offset);
1387
1388           addr = plus_constant (addr, arg_offset);
1389           args[i].stack = gen_rtx (MEM, args[i].mode, addr);
1390
1391           if (GET_CODE (slot_offset) == CONST_INT)
1392             addr = plus_constant (arg_reg, INTVAL (slot_offset));
1393           else
1394             addr = gen_rtx (PLUS, Pmode, arg_reg, slot_offset);
1395
1396           addr = plus_constant (addr, arg_offset);
1397           args[i].stack_slot = gen_rtx (MEM, args[i].mode, addr);
1398         }
1399     }
1400                                                
1401 #ifdef PUSH_ARGS_REVERSED
1402 #ifdef STACK_BOUNDARY
1403   /* If we push args individually in reverse order, perform stack alignment
1404      before the first push (the last arg).  */
1405   if (argblock == 0)
1406     anti_adjust_stack (GEN_INT (args_size.constant
1407                                 - original_args_size.constant));
1408 #endif
1409 #endif
1410
1411   /* Don't try to defer pops if preallocating, not even from the first arg,
1412      since ARGBLOCK probably refers to the SP.  */
1413   if (argblock)
1414     NO_DEFER_POP;
1415
1416   /* Get the function to call, in the form of RTL.  */
1417   if (fndecl)
1418     /* Get a SYMBOL_REF rtx for the function address.  */
1419     funexp = XEXP (DECL_RTL (fndecl), 0);
1420   else
1421     /* Generate an rtx (probably a pseudo-register) for the address.  */
1422     {
1423       funexp = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1424       free_temp_slots ();       /* FUNEXP can't be BLKmode */
1425       emit_queue ();
1426     }
1427
1428   /* Figure out the register where the value, if any, will come back.  */
1429   valreg = 0;
1430   if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
1431       && ! structure_value_addr)
1432     {
1433       if (pcc_struct_value)
1434         valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
1435                                       fndecl);
1436       else
1437         valreg = hard_function_value (TREE_TYPE (exp), fndecl);
1438     }
1439
1440   /* Precompute all register parameters.  It isn't safe to compute anything
1441      once we have started filling any specific hard regs. */
1442   reg_parm_seen = 0;
1443   for (i = 0; i < num_actuals; i++)
1444     if (args[i].reg != 0 && ! args[i].pass_on_stack)
1445       {
1446         reg_parm_seen = 1;
1447
1448         if (args[i].value == 0)
1449           {
1450             args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
1451                                          VOIDmode, 0);
1452             preserve_temp_slots (args[i].value);
1453             free_temp_slots ();
1454
1455             /* ANSI doesn't require a sequence point here,
1456                but PCC has one, so this will avoid some problems.  */
1457             emit_queue ();
1458           }
1459
1460         /* If we are to promote the function arg to a wider mode,
1461            do it now.  */
1462
1463         if (GET_MODE (args[i].value) != VOIDmode
1464             && GET_MODE (args[i].value) != args[i].mode)
1465           args[i].value = convert_to_mode (args[i].mode, args[i].value,
1466                                            args[i].unsignedp);
1467       }
1468
1469 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1470   /* The argument list is the property of the called routine and it
1471      may clobber it.  If the fixed area has been used for previous
1472      parameters, we must save and restore it.
1473
1474      Here we compute the boundary of the that needs to be saved, if any.  */
1475
1476 #ifdef ARGS_GROW_DOWNWARD
1477   for (i = 0; i < reg_parm_stack_space + 1; i++)
1478 #else
1479   for (i = 0; i < reg_parm_stack_space; i++)
1480 #endif
1481     {
1482       if (i >=  highest_outgoing_arg_in_use
1483           || stack_usage_map[i] == 0)
1484         continue;
1485
1486       if (low_to_save == -1)
1487         low_to_save = i;
1488
1489       high_to_save = i;
1490     }
1491
1492   if (low_to_save >= 0)
1493     {
1494       int num_to_save = high_to_save - low_to_save + 1;
1495       enum machine_mode save_mode
1496         = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
1497       rtx stack_area;
1498
1499       /* If we don't have the required alignment, must do this in BLKmode.  */
1500       if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
1501                                BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
1502         save_mode = BLKmode;
1503
1504       stack_area = gen_rtx (MEM, save_mode,
1505                             memory_address (save_mode,
1506                                             
1507 #ifdef ARGS_GROW_DOWNWARD
1508                                             plus_constant (argblock,
1509                                                            - high_to_save)
1510 #else
1511                                             plus_constant (argblock,
1512                                                            low_to_save)
1513 #endif
1514                                             ));
1515       if (save_mode == BLKmode)
1516         {
1517           save_area = assign_stack_temp (BLKmode, num_to_save, 1);
1518           emit_block_move (validize_mem (save_area), stack_area,
1519                            GEN_INT (num_to_save),
1520                            PARM_BOUNDARY / BITS_PER_UNIT);
1521         }
1522       else
1523         {
1524           save_area = gen_reg_rtx (save_mode);
1525           emit_move_insn (save_area, stack_area);
1526         }
1527     }
1528 #endif
1529           
1530
1531   /* Now store (and compute if necessary) all non-register parms.
1532      These come before register parms, since they can require block-moves,
1533      which could clobber the registers used for register parms.
1534      Parms which have partial registers are not stored here,
1535      but we do preallocate space here if they want that.  */
1536
1537   for (i = 0; i < num_actuals; i++)
1538     if (args[i].reg == 0 || args[i].pass_on_stack)
1539       store_one_arg (&args[i], argblock, may_be_alloca,
1540                      args_size.var != 0, fndecl, reg_parm_stack_space);
1541
1542 #ifdef STRICT_ALIGNMENT
1543   /* If we have a parm that is passed in registers but not in memory
1544      and whose alignment does not permit a direct copy into registers,
1545      make a group of pseudos that correspond to each register that we
1546      will later fill.  */
1547
1548   for (i = 0; i < num_actuals; i++)
1549     if (args[i].reg != 0 && ! args[i].pass_on_stack
1550         && args[i].mode == BLKmode
1551         && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
1552             < MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
1553       {
1554         int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1555
1556         args[i].n_aligned_regs
1557           = args[i].partial ? args[i].partial
1558             : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
1559
1560         args[i].aligned_regs = (rtx *) alloca (sizeof (rtx)
1561                                                * args[i].n_aligned_regs);
1562
1563         for (j = 0; j < args[i].n_aligned_regs; j++)
1564           {
1565             rtx reg = gen_reg_rtx (word_mode);
1566             rtx word = operand_subword_force (args[i].value, j, BLKmode);
1567             int bitsize = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
1568             int bitpos;
1569
1570             args[i].aligned_regs[j] = reg;
1571
1572             /* Clobber REG and move each partword into it.  Ensure we don't
1573                go past the end of the structure.  Note that the loop below
1574                works because we've already verified that padding
1575                and endianness are compatible.  */
1576
1577             emit_insn (gen_rtx (CLOBBER, VOIDmode, reg));
1578
1579             for (bitpos = 0;
1580                  bitpos < BITS_PER_WORD && bytes >= 0;
1581                  bitpos += bitsize, bytes -= bitsize / BITS_PER_UNIT)
1582               {
1583                 int xbitpos = (BYTES_BIG_ENDIAN
1584                                ? bitpos = BITS_PER_WORD - bitpos - bitsize
1585                                : bitpos);
1586
1587                 store_bit_field (reg, bitsize, xbitpos, word_mode,
1588                                  extract_bit_field (word, bitsize, xbitpos, 1,
1589                                                     NULL_RTX, word_mode,
1590                                                     word_mode,
1591                                                     bitsize / BITS_PER_UNIT,
1592                                                     BITS_PER_WORD),
1593                                  bitsize / BITS_PER_UNIT, BITS_PER_WORD);
1594               }
1595           }
1596       }
1597 #endif
1598
1599   /* Now store any partially-in-registers parm.
1600      This is the last place a block-move can happen.  */
1601   if (reg_parm_seen)
1602     for (i = 0; i < num_actuals; i++)
1603       if (args[i].partial != 0 && ! args[i].pass_on_stack)
1604         store_one_arg (&args[i], argblock, may_be_alloca,
1605                        args_size.var != 0, fndecl, reg_parm_stack_space);
1606
1607 #ifndef PUSH_ARGS_REVERSED
1608 #ifdef STACK_BOUNDARY
1609   /* If we pushed args in forward order, perform stack alignment
1610      after pushing the last arg.  */
1611   if (argblock == 0)
1612     anti_adjust_stack (GEN_INT (args_size.constant
1613                                 - original_args_size.constant));
1614 #endif
1615 #endif
1616
1617   /* If register arguments require space on the stack and stack space
1618      was not preallocated, allocate stack space here for arguments
1619      passed in registers.  */
1620 #if ! defined(ALLOCATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
1621   if (must_preallocate == 0 && reg_parm_stack_space > 0)
1622     anti_adjust_stack (GEN_INT (reg_parm_stack_space));
1623 #endif
1624
1625   /* Pass the function the address in which to return a structure value.  */
1626   if (structure_value_addr && ! structure_value_addr_parm)
1627     {
1628       emit_move_insn (struct_value_rtx,
1629                       force_reg (Pmode,
1630                                  force_operand (structure_value_addr,
1631                                                 NULL_RTX)));
1632       if (GET_CODE (struct_value_rtx) == REG)
1633         {
1634           push_to_sequence (use_insns);
1635           emit_insn (gen_rtx (USE, VOIDmode, struct_value_rtx));
1636           use_insns = get_insns ();
1637           end_sequence ();
1638         }
1639     }
1640
1641   /* Now do the register loads required for any wholly-register parms or any
1642      parms which are passed both on the stack and in a register.  Their
1643      expressions were already evaluated. 
1644
1645      Mark all register-parms as living through the call, putting these USE
1646      insns in a list headed by USE_INSNS.  */
1647
1648   for (i = 0; i < num_actuals; i++)
1649     {
1650       rtx list = args[i].reg;
1651       int partial = args[i].partial;
1652
1653       while (list)
1654         {
1655           rtx reg;
1656           int nregs;
1657
1658           /* Process each register that needs to get this arg.  */
1659           if (GET_CODE (list) == EXPR_LIST)
1660             reg = XEXP (list, 0), list = XEXP (list, 1);
1661           else
1662             reg = list, list = 0;
1663
1664           /* Set to non-zero if must move a word at a time, even if just one
1665              word (e.g, partial == 1 && mode == DFmode).  Set to zero if
1666              we just use a normal move insn.  */
1667           nregs = (partial ? partial
1668                    : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1669                       ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1670                           + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1671                       : 0));
1672
1673           /* If simple case, just do move.  If normal partial, store_one_arg
1674              has already loaded the register for us.  In all other cases,
1675              load the register(s) from memory.  */
1676
1677           if (nregs == 0)
1678             emit_move_insn (reg, args[i].value);
1679
1680 #ifdef STRICT_ALIGNMENT
1681           /* If we have pre-computed the values to put in the registers in
1682              the case of non-aligned structures, copy them in now.  */
1683
1684           else if (args[i].n_aligned_regs != 0)
1685             for (j = 0; j < args[i].n_aligned_regs; j++)
1686               emit_move_insn (gen_rtx (REG, word_mode, REGNO (reg) + j),
1687                               args[i].aligned_regs[j]);
1688 #endif
1689
1690           else if (args[i].partial == 0 || args[i].pass_on_stack)
1691             move_block_to_reg (REGNO (reg),
1692                                validize_mem (args[i].value), nregs,
1693                                args[i].mode);
1694         
1695           push_to_sequence (use_insns);
1696           if (nregs == 0)
1697             emit_insn (gen_rtx (USE, VOIDmode, reg));
1698           else
1699             use_regs (REGNO (reg), nregs);
1700           use_insns = get_insns ();
1701           end_sequence ();
1702
1703           /* PARTIAL referred only to the first register, so clear it for the
1704              next time.  */
1705           partial = 0;
1706         }
1707     }
1708
1709   /* Perform postincrements before actually calling the function.  */
1710   emit_queue ();
1711
1712   /* All arguments and registers used for the call must be set up by now!  */
1713
1714   funexp = prepare_call_address (funexp, fndecl, &use_insns);
1715
1716   /* Generate the actual call instruction.  */
1717   emit_call_1 (funexp, funtype, args_size.constant, struct_value_size,
1718                FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
1719                valreg, old_inhibit_defer_pop, use_insns, is_const);
1720
1721   /* If call is cse'able, make appropriate pair of reg-notes around it.
1722      Test valreg so we don't crash; may safely ignore `const'
1723      if return type is void.  */
1724   if (is_const && valreg != 0)
1725     {
1726       rtx note = 0;
1727       rtx temp = gen_reg_rtx (GET_MODE (valreg));
1728       rtx insns;
1729
1730       /* Construct an "equal form" for the value which mentions all the
1731          arguments in order as well as the function name.  */
1732 #ifdef PUSH_ARGS_REVERSED
1733       for (i = 0; i < num_actuals; i++)
1734         note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1735 #else
1736       for (i = num_actuals - 1; i >= 0; i--)
1737         note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1738 #endif
1739       note = gen_rtx (EXPR_LIST, VOIDmode, funexp, note);
1740
1741       insns = get_insns ();
1742       end_sequence ();
1743
1744       emit_libcall_block (insns, temp, valreg, note);
1745
1746       valreg = temp;
1747     }
1748
1749   /* For calls to `setjmp', etc., inform flow.c it should complain
1750      if nonvolatile values are live.  */
1751
1752   if (returns_twice)
1753     {
1754       emit_note (name, NOTE_INSN_SETJMP);
1755       current_function_calls_setjmp = 1;
1756     }
1757
1758   if (is_longjmp)
1759     current_function_calls_longjmp = 1;
1760
1761   /* Notice functions that cannot return.
1762      If optimizing, insns emitted below will be dead.
1763      If not optimizing, they will exist, which is useful
1764      if the user uses the `return' command in the debugger.  */
1765
1766   if (is_volatile || is_longjmp)
1767     emit_barrier ();
1768
1769   /* If value type not void, return an rtx for the value.  */
1770
1771   /* If there are cleanups to be called, don't use a hard reg as target.  */
1772   if (cleanups_this_call != old_cleanups
1773       && target && REG_P (target)
1774       && REGNO (target) < FIRST_PSEUDO_REGISTER)
1775     target = 0;
1776
1777   if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
1778       || ignore)
1779     {
1780       target = const0_rtx;
1781     }
1782   else if (structure_value_addr)
1783     {
1784       if (target == 0 || GET_CODE (target) != MEM)
1785         {
1786           target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1787                             memory_address (TYPE_MODE (TREE_TYPE (exp)),
1788                                             structure_value_addr));
1789           MEM_IN_STRUCT_P (target)
1790             = (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1791                || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
1792                || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE);
1793         }
1794     }
1795   else if (pcc_struct_value)
1796     {
1797       if (target == 0)
1798         {
1799           target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1800                             copy_to_reg (valreg));
1801           MEM_IN_STRUCT_P (target)
1802             = (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1803                || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
1804                || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE);
1805         }
1806       else if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
1807         emit_move_insn (target, gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1808                                          copy_to_reg (valreg)));
1809       else
1810         emit_block_move (target, gen_rtx (MEM, BLKmode, copy_to_reg (valreg)),
1811                          expr_size (exp),
1812                          TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
1813     }
1814   else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
1815            && GET_MODE (target) == GET_MODE (valreg))
1816     /* TARGET and VALREG cannot be equal at this point because the latter
1817        would not have REG_FUNCTION_VALUE_P true, while the former would if
1818        it were referring to the same register.
1819
1820        If they refer to the same register, this move will be a no-op, except
1821        when function inlining is being done.  */
1822     emit_move_insn (target, valreg);
1823   else
1824     target = copy_to_reg (valreg);
1825
1826 #ifdef PROMOTE_FUNCTION_RETURN
1827   /* If we promoted this return value, make the proper SUBREG.  */
1828   if (GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
1829     {
1830       enum machine_mode mode = GET_MODE (target);
1831       int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
1832
1833       if (TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE
1834           || TREE_CODE (TREE_TYPE (exp)) == ENUMERAL_TYPE
1835           || TREE_CODE (TREE_TYPE (exp)) == BOOLEAN_TYPE
1836           || TREE_CODE (TREE_TYPE (exp)) == CHAR_TYPE
1837           || TREE_CODE (TREE_TYPE (exp)) == REAL_TYPE
1838           || TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE
1839           || TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE)
1840         {
1841           PROMOTE_MODE (mode, unsignedp, TREE_TYPE (exp));
1842         }
1843
1844       target = gen_rtx (SUBREG, TYPE_MODE (TREE_TYPE (exp)), target, 0);
1845       SUBREG_PROMOTED_VAR_P (target) = 1;
1846       SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
1847     }
1848 #endif
1849
1850   /* Perform all cleanups needed for the arguments of this call
1851      (i.e. destructors in C++).  */
1852   expand_cleanups_to (old_cleanups);
1853
1854   /* If size of args is variable or this was a constructor call for a stack
1855      argument, restore saved stack-pointer value.  */
1856
1857   if (old_stack_level)
1858     {
1859       emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
1860       pending_stack_adjust = old_pending_adj;
1861 #ifdef ACCUMULATE_OUTGOING_ARGS
1862       stack_arg_under_construction = old_stack_arg_under_construction;
1863       highest_outgoing_arg_in_use = initial_highest_arg_in_use;
1864       stack_usage_map = initial_stack_usage_map;
1865 #endif
1866     }
1867 #ifdef ACCUMULATE_OUTGOING_ARGS
1868   else
1869     {
1870 #ifdef REG_PARM_STACK_SPACE
1871       if (save_area)
1872         {
1873           enum machine_mode save_mode = GET_MODE (save_area);
1874           rtx stack_area
1875             = gen_rtx (MEM, save_mode,
1876                        memory_address (save_mode,
1877 #ifdef ARGS_GROW_DOWNWARD
1878                                        plus_constant (argblock, - high_to_save)
1879 #else
1880                                        plus_constant (argblock, low_to_save)
1881 #endif
1882                                        ));
1883
1884           if (save_mode != BLKmode)
1885             emit_move_insn (stack_area, save_area);
1886           else
1887             emit_block_move (stack_area, validize_mem (save_area),
1888                              GEN_INT (high_to_save - low_to_save + 1),
1889                              PARM_BOUNDARY / BITS_PER_UNIT);
1890         }
1891 #endif
1892           
1893       /* If we saved any argument areas, restore them.  */
1894       for (i = 0; i < num_actuals; i++)
1895         if (args[i].save_area)
1896           {
1897             enum machine_mode save_mode = GET_MODE (args[i].save_area);
1898             rtx stack_area
1899               = gen_rtx (MEM, save_mode,
1900                          memory_address (save_mode,
1901                                          XEXP (args[i].stack_slot, 0)));
1902
1903             if (save_mode != BLKmode)
1904               emit_move_insn (stack_area, args[i].save_area);
1905             else
1906               emit_block_move (stack_area, validize_mem (args[i].save_area),
1907                                GEN_INT (args[i].size.constant),
1908                                PARM_BOUNDARY / BITS_PER_UNIT);
1909           }
1910
1911       highest_outgoing_arg_in_use = initial_highest_arg_in_use;
1912       stack_usage_map = initial_stack_usage_map;
1913     }
1914 #endif
1915
1916   /* If this was alloca, record the new stack level for nonlocal gotos.  
1917      Check for the handler slots since we might not have a save area
1918      for non-local gotos. */
1919
1920   if (may_be_alloca && nonlocal_goto_handler_slot != 0)
1921     emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
1922
1923   pop_temp_slots ();
1924
1925   return target;
1926 }
1927 \f
1928 #if 0
1929 /* Return an rtx which represents a suitable home on the stack
1930    given TYPE, the type of the argument looking for a home.
1931    This is called only for BLKmode arguments.
1932
1933    SIZE is the size needed for this target.
1934    ARGS_ADDR is the address of the bottom of the argument block for this call.
1935    OFFSET describes this parameter's offset into ARGS_ADDR.  It is meaningless
1936    if this machine uses push insns.  */
1937
1938 static rtx
1939 target_for_arg (type, size, args_addr, offset)
1940      tree type;
1941      rtx size;
1942      rtx args_addr;
1943      struct args_size offset;
1944 {
1945   rtx target;
1946   rtx offset_rtx = ARGS_SIZE_RTX (offset);
1947
1948   /* We do not call memory_address if possible,
1949      because we want to address as close to the stack
1950      as possible.  For non-variable sized arguments,
1951      this will be stack-pointer relative addressing.  */
1952   if (GET_CODE (offset_rtx) == CONST_INT)
1953     target = plus_constant (args_addr, INTVAL (offset_rtx));
1954   else
1955     {
1956       /* I have no idea how to guarantee that this
1957          will work in the presence of register parameters.  */
1958       target = gen_rtx (PLUS, Pmode, args_addr, offset_rtx);
1959       target = memory_address (QImode, target);
1960     }
1961
1962   return gen_rtx (MEM, BLKmode, target);
1963 }
1964 #endif
1965 \f
1966 /* Store a single argument for a function call
1967    into the register or memory area where it must be passed.
1968    *ARG describes the argument value and where to pass it.
1969
1970    ARGBLOCK is the address of the stack-block for all the arguments,
1971    or 0 on a machine where arguments are pushed individually.
1972
1973    MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
1974    so must be careful about how the stack is used. 
1975
1976    VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
1977    argument stack.  This is used if ACCUMULATE_OUTGOING_ARGS to indicate
1978    that we need not worry about saving and restoring the stack.
1979
1980    FNDECL is the declaration of the function we are calling.  */
1981
1982 static void
1983 store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl,
1984                reg_parm_stack_space)
1985      struct arg_data *arg;
1986      rtx argblock;
1987      int may_be_alloca;
1988      int variable_size;
1989      tree fndecl;
1990      int reg_parm_stack_space;
1991 {
1992   register tree pval = arg->tree_value;
1993   rtx reg = 0;
1994   int partial = 0;
1995   int used = 0;
1996   int i, lower_bound, upper_bound;
1997
1998   if (TREE_CODE (pval) == ERROR_MARK)
1999     return;
2000
2001 #ifdef ACCUMULATE_OUTGOING_ARGS
2002   /* If this is being stored into a pre-allocated, fixed-size, stack area,
2003      save any previous data at that location.  */
2004   if (argblock && ! variable_size && arg->stack)
2005     {
2006 #ifdef ARGS_GROW_DOWNWARD
2007       /* stack_slot is negative, but we want to index stack_usage_map */
2008       /* with positive values. */
2009       if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
2010         upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
2011       else
2012         abort ();
2013
2014       lower_bound = upper_bound - arg->size.constant;
2015 #else
2016       if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
2017         lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
2018       else
2019         lower_bound = 0;
2020
2021       upper_bound = lower_bound + arg->size.constant;
2022 #endif
2023
2024       for (i = lower_bound; i < upper_bound; i++)
2025         if (stack_usage_map[i]
2026 #ifdef REG_PARM_STACK_SPACE
2027             /* Don't store things in the fixed argument area at this point;
2028                it has already been saved.  */
2029             && i > reg_parm_stack_space
2030 #endif
2031             )
2032           break;
2033
2034       if (i != upper_bound)
2035         {
2036           /* We need to make a save area.  See what mode we can make it.  */
2037           enum machine_mode save_mode
2038             = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
2039           rtx stack_area
2040             = gen_rtx (MEM, save_mode,
2041                        memory_address (save_mode, XEXP (arg->stack_slot, 0)));
2042
2043           if (save_mode == BLKmode)
2044             {
2045               arg->save_area = assign_stack_temp (BLKmode,
2046                                                   arg->size.constant, 1);
2047               emit_block_move (validize_mem (arg->save_area), stack_area,
2048                                GEN_INT (arg->size.constant),
2049                                PARM_BOUNDARY / BITS_PER_UNIT);
2050             }
2051           else
2052             {
2053               arg->save_area = gen_reg_rtx (save_mode);
2054               emit_move_insn (arg->save_area, stack_area);
2055             }
2056         }
2057     }
2058 #endif
2059
2060   /* If this isn't going to be placed on both the stack and in registers,
2061      set up the register and number of words.  */
2062   if (! arg->pass_on_stack)
2063     reg = arg->reg, partial = arg->partial;
2064
2065   if (reg != 0 && partial == 0)
2066     /* Being passed entirely in a register.  We shouldn't be called in
2067        this case.   */
2068     abort ();
2069
2070 #ifdef STRICT_ALIGNMENT
2071   /* If this arg needs special alignment, don't load the registers
2072      here.  */
2073   if (arg->n_aligned_regs != 0)
2074     reg = 0;
2075 #endif
2076   
2077   /* If this is being partially passed in a register, but multiple locations
2078      are specified, we assume that the one partially used is the one that is
2079      listed first.  */
2080   if (reg && GET_CODE (reg) == EXPR_LIST)
2081     reg = XEXP (reg, 0);
2082
2083   /* If this is being passed partially in a register, we can't evaluate
2084      it directly into its stack slot.  Otherwise, we can.  */
2085   if (arg->value == 0)
2086     {
2087 #ifdef ACCUMULATE_OUTGOING_ARGS
2088       /* stack_arg_under_construction is nonzero if a function argument is
2089          being evaluated directly into the outgoing argument list and
2090          expand_call must take special action to preserve the argument list
2091          if it is called recursively.
2092
2093          For scalar function arguments stack_usage_map is sufficient to
2094          determine which stack slots must be saved and restored.  Scalar
2095          arguments in general have pass_on_stack == 0.
2096
2097          If this argument is initialized by a function which takes the
2098          address of the argument (a C++ constructor or a C function
2099          returning a BLKmode structure), then stack_usage_map is
2100          insufficient and expand_call must push the stack around the
2101          function call.  Such arguments have pass_on_stack == 1.
2102
2103          Note that it is always safe to set stack_arg_under_construction,
2104          but this generates suboptimal code if set when not needed.  */
2105
2106       if (arg->pass_on_stack)
2107         stack_arg_under_construction++;
2108 #endif
2109       arg->value = expand_expr (pval, partial ? NULL_RTX : arg->stack,
2110                                 VOIDmode, 0);
2111
2112       /* If we are promoting object (or for any other reason) the mode
2113          doesn't agree, convert the mode.  */
2114
2115       if (GET_MODE (arg->value) != VOIDmode
2116           && GET_MODE (arg->value) != arg->mode)
2117         arg->value = convert_to_mode (arg->mode, arg->value, arg->unsignedp);
2118
2119 #ifdef ACCUMULATE_OUTGOING_ARGS
2120       if (arg->pass_on_stack)
2121         stack_arg_under_construction--;
2122 #endif
2123     }
2124
2125   /* Don't allow anything left on stack from computation
2126      of argument to alloca.  */
2127   if (may_be_alloca)
2128     do_pending_stack_adjust ();
2129
2130   if (arg->value == arg->stack)
2131     /* If the value is already in the stack slot, we are done.  */
2132     ;
2133   else if (arg->mode != BLKmode)
2134     {
2135       register int size;
2136
2137       /* Argument is a scalar, not entirely passed in registers.
2138          (If part is passed in registers, arg->partial says how much
2139          and emit_push_insn will take care of putting it there.)
2140          
2141          Push it, and if its size is less than the
2142          amount of space allocated to it,
2143          also bump stack pointer by the additional space.
2144          Note that in C the default argument promotions
2145          will prevent such mismatches.  */
2146
2147       size = GET_MODE_SIZE (arg->mode);
2148       /* Compute how much space the push instruction will push.
2149          On many machines, pushing a byte will advance the stack
2150          pointer by a halfword.  */
2151 #ifdef PUSH_ROUNDING
2152       size = PUSH_ROUNDING (size);
2153 #endif
2154       used = size;
2155
2156       /* Compute how much space the argument should get:
2157          round up to a multiple of the alignment for arguments.  */
2158       if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
2159         used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
2160                  / (PARM_BOUNDARY / BITS_PER_UNIT))
2161                 * (PARM_BOUNDARY / BITS_PER_UNIT));
2162
2163       /* This isn't already where we want it on the stack, so put it there.
2164          This can either be done with push or copy insns.  */
2165       emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), 0, 0, partial,
2166                       reg, used - size, argblock, ARGS_SIZE_RTX (arg->offset));
2167     }
2168   else
2169     {
2170       /* BLKmode, at least partly to be pushed.  */
2171
2172       register int excess;
2173       rtx size_rtx;
2174
2175       /* Pushing a nonscalar.
2176          If part is passed in registers, PARTIAL says how much
2177          and emit_push_insn will take care of putting it there.  */
2178
2179       /* Round its size up to a multiple
2180          of the allocation unit for arguments.  */
2181
2182       if (arg->size.var != 0)
2183         {
2184           excess = 0;
2185           size_rtx = ARGS_SIZE_RTX (arg->size);
2186         }
2187       else
2188         {
2189           register tree size = size_in_bytes (TREE_TYPE (pval));
2190           /* PUSH_ROUNDING has no effect on us, because
2191              emit_push_insn for BLKmode is careful to avoid it.  */
2192           excess = (arg->size.constant - TREE_INT_CST_LOW (size)
2193                     + partial * UNITS_PER_WORD);
2194           size_rtx = expand_expr (size, NULL_RTX, VOIDmode, 0);
2195         }
2196
2197       emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
2198                       TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
2199                       reg, excess, argblock, ARGS_SIZE_RTX (arg->offset));
2200     }
2201
2202
2203   /* Unless this is a partially-in-register argument, the argument is now
2204      in the stack. 
2205
2206      ??? Note that this can change arg->value from arg->stack to
2207      arg->stack_slot and it matters when they are not the same.
2208      It isn't totally clear that this is correct in all cases.  */
2209   if (partial == 0)
2210     arg->value = arg->stack_slot;
2211
2212   /* Once we have pushed something, pops can't safely
2213      be deferred during the rest of the arguments.  */
2214   NO_DEFER_POP;
2215
2216   /* ANSI doesn't require a sequence point here,
2217      but PCC has one, so this will avoid some problems.  */
2218   emit_queue ();
2219
2220   /* Free any temporary slots made in processing this argument.  */
2221   free_temp_slots ();
2222
2223 #ifdef ACCUMULATE_OUTGOING_ARGS
2224   /* Now mark the segment we just used.  */
2225   if (argblock && ! variable_size && arg->stack)
2226     for (i = lower_bound; i < upper_bound; i++)
2227       stack_usage_map[i] = 1;
2228 #endif
2229 }