OSDN Git Service

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