OSDN Git Service

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