OSDN Git Service

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