source: trunk/third/gcc/calls.c @ 11288

Revision 11288, 117.0 KB checked in by ghudson, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r11287, which included commits to RCS files with non-trunk default branches.
Line 
1/* Convert function calls to rtl insns, for GNU C compiler.
2   Copyright (C) 1989, 92-97, 1998 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING.  If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA.  */
20
21#include "config.h"
22#include <stdio.h>
23#include "rtl.h"
24#include "tree.h"
25#include "flags.h"
26#include "expr.h"
27#include "regs.h"
28#ifdef __STDC__
29#include <stdarg.h>
30#else
31#include <varargs.h>
32#endif
33#include "insn-flags.h"
34
35/* Decide whether a function's arguments should be processed
36   from first to last or from last to first.
37
38   They should if the stack and args grow in opposite directions, but
39   only if we have push insns.  */
40
41#ifdef PUSH_ROUNDING
42
43#if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
44#define PUSH_ARGS_REVERSED      /* If it's last to first */
45#endif
46
47#endif
48
49/* Like STACK_BOUNDARY but in units of bytes, not bits.  */
50#define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
51
52/* Data structure and subroutines used within expand_call.  */
53
54struct arg_data
55{
56  /* Tree node for this argument.  */
57  tree tree_value;
58  /* Mode for value; TYPE_MODE unless promoted.  */
59  enum machine_mode mode;
60  /* Current RTL value for argument, or 0 if it isn't precomputed.  */
61  rtx value;
62  /* Initially-compute RTL value for argument; only for const functions.  */
63  rtx initial_value;
64  /* Register to pass this argument in, 0 if passed on stack, or an
65     PARALLEL if the arg is to be copied into multiple non-contiguous
66     registers.  */
67  rtx reg;
68  /* If REG was promoted from the actual mode of the argument expression,
69     indicates whether the promotion is sign- or zero-extended.  */
70  int unsignedp;
71  /* Number of registers to use.  0 means put the whole arg in registers.
72     Also 0 if not passed in registers.  */
73  int partial;
74  /* Non-zero if argument must be passed on stack.
75     Note that some arguments may be passed on the stack
76     even though pass_on_stack is zero, just because FUNCTION_ARG says so.
77     pass_on_stack identifies arguments that *cannot* go in registers.  */
78  int pass_on_stack;
79  /* Offset of this argument from beginning of stack-args.  */
80  struct args_size offset;
81  /* Similar, but offset to the start of the stack slot.  Different from
82     OFFSET if this arg pads downward.  */
83  struct args_size slot_offset;
84  /* Size of this argument on the stack, rounded up for any padding it gets,
85     parts of the argument passed in registers do not count.
86     If REG_PARM_STACK_SPACE is defined, then register parms
87     are counted here as well.  */
88  struct args_size size;
89  /* Location on the stack at which parameter should be stored.  The store
90     has already been done if STACK == VALUE.  */
91  rtx stack;
92  /* Location on the stack of the start of this argument slot.  This can
93     differ from STACK if this arg pads downward.  This location is known
94     to be aligned to FUNCTION_ARG_BOUNDARY.  */
95  rtx stack_slot;
96#ifdef ACCUMULATE_OUTGOING_ARGS
97  /* Place that this stack area has been saved, if needed.  */
98  rtx save_area;
99#endif
100  /* If an argument's alignment does not permit direct copying into registers,
101     copy in smaller-sized pieces into pseudos.  These are stored in a
102     block pointed to by this field.  The next field says how many
103     word-sized pseudos we made.  */
104  rtx *aligned_regs;
105  int n_aligned_regs;
106};
107
108#ifdef ACCUMULATE_OUTGOING_ARGS
109/* A vector of one char per byte of stack space.  A byte if non-zero if
110   the corresponding stack location has been used.
111   This vector is used to prevent a function call within an argument from
112   clobbering any stack already set up.  */
113static char *stack_usage_map;
114
115/* Size of STACK_USAGE_MAP.  */
116static int highest_outgoing_arg_in_use;
117
118/* stack_arg_under_construction is nonzero when an argument may be
119   initialized with a constructor call (including a C function that
120   returns a BLKmode struct) and expand_call must take special action
121   to make sure the object being constructed does not overlap the
122   argument list for the constructor call.  */
123int stack_arg_under_construction;
124#endif
125
126static int calls_function       PROTO((tree, int));
127static int calls_function_1     PROTO((tree, int));
128static void emit_call_1         PROTO((rtx, tree, tree, HOST_WIDE_INT,
129                                       HOST_WIDE_INT, rtx, rtx,
130                                       int, rtx, int));
131static void store_one_arg       PROTO ((struct arg_data *, rtx, int, int,
132                                        tree, int));
133
134/* If WHICH is 1, return 1 if EXP contains a call to the built-in function
135   `alloca'.
136
137   If WHICH is 0, return 1 if EXP contains a call to any function.
138   Actually, we only need return 1 if evaluating EXP would require pushing
139   arguments on the stack, but that is too difficult to compute, so we just
140   assume any function call might require the stack.  */
141
142static tree calls_function_save_exprs;
143
144static int
145calls_function (exp, which)
146     tree exp;
147     int which;
148{
149  int val;
150  calls_function_save_exprs = 0;
151  val = calls_function_1 (exp, which);
152  calls_function_save_exprs = 0;
153  return val;
154}
155
156static int
157calls_function_1 (exp, which)
158     tree exp;
159     int which;
160{
161  register int i;
162  enum tree_code code = TREE_CODE (exp);
163  int type = TREE_CODE_CLASS (code);
164  int length = tree_code_length[(int) code];
165
166  /* If this code is language-specific, we don't know what it will do.  */
167  if ((int) code >= NUM_TREE_CODES)
168    return 1;
169
170  /* Only expressions and references can contain calls.  */
171  if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
172      && type != 'b')
173    return 0;
174
175  switch (code)
176    {
177    case CALL_EXPR:
178      if (which == 0)
179        return 1;
180      else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
181               && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
182                   == FUNCTION_DECL))
183        {
184          tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
185
186          if ((DECL_BUILT_IN (fndecl)
187               && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA)
188              || (DECL_SAVED_INSNS (fndecl)
189                  && (FUNCTION_FLAGS (DECL_SAVED_INSNS (fndecl))
190                      & FUNCTION_FLAGS_CALLS_ALLOCA)))
191            return 1;
192        }
193
194      /* Third operand is RTL.  */
195      length = 2;
196      break;
197
198    case SAVE_EXPR:
199      if (SAVE_EXPR_RTL (exp) != 0)
200        return 0;
201      if (value_member (exp, calls_function_save_exprs))
202        return 0;
203      calls_function_save_exprs = tree_cons (NULL_TREE, exp,
204                                             calls_function_save_exprs);
205      return (TREE_OPERAND (exp, 0) != 0
206              && calls_function_1 (TREE_OPERAND (exp, 0), which));
207
208    case BLOCK:
209      {
210        register tree local;
211
212        for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
213          if (DECL_INITIAL (local) != 0
214              && calls_function_1 (DECL_INITIAL (local), which))
215            return 1;
216      }
217      {
218        register tree subblock;
219
220        for (subblock = BLOCK_SUBBLOCKS (exp);
221             subblock;
222             subblock = TREE_CHAIN (subblock))
223          if (calls_function_1 (subblock, which))
224            return 1;
225      }
226      return 0;
227
228    case METHOD_CALL_EXPR:
229      length = 3;
230      break;
231
232    case WITH_CLEANUP_EXPR:
233      length = 1;
234      break;
235
236    case RTL_EXPR:
237      return 0;
238     
239    default:
240      break;
241    }
242
243  for (i = 0; i < length; i++)
244    if (TREE_OPERAND (exp, i) != 0
245        && calls_function_1 (TREE_OPERAND (exp, i), which))
246      return 1;
247
248  return 0;
249}
250
251/* Force FUNEXP into a form suitable for the address of a CALL,
252   and return that as an rtx.  Also load the static chain register
253   if FNDECL is a nested function.
254
255   CALL_FUSAGE points to a variable holding the prospective
256   CALL_INSN_FUNCTION_USAGE information.  */
257
258rtx
259prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen)
260     rtx funexp;
261     tree fndecl;
262     rtx *call_fusage;
263     int reg_parm_seen;
264{
265  rtx static_chain_value = 0;
266
267  funexp = protect_from_queue (funexp, 0);
268
269  if (fndecl != 0)
270    /* Get possible static chain value for nested function in C.  */
271    static_chain_value = lookup_static_chain (fndecl);
272
273  /* Make a valid memory address and copy constants thru pseudo-regs,
274     but not for a constant address if -fno-function-cse.  */
275  if (GET_CODE (funexp) != SYMBOL_REF)
276    /* If we are using registers for parameters, force the
277       function address into a register now.  */
278    funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
279              ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
280              : memory_address (FUNCTION_MODE, funexp));
281  else
282    {
283#ifndef NO_FUNCTION_CSE
284      if (optimize && ! flag_no_function_cse)
285#ifdef NO_RECURSIVE_FUNCTION_CSE
286        if (fndecl != current_function_decl)
287#endif
288          funexp = force_reg (Pmode, funexp);
289#endif
290    }
291
292  if (static_chain_value != 0)
293    {
294      emit_move_insn (static_chain_rtx, static_chain_value);
295
296      if (GET_CODE (static_chain_rtx) == REG)
297        use_reg (call_fusage, static_chain_rtx);
298    }
299
300  return funexp;
301}
302
303/* Generate instructions to call function FUNEXP,
304   and optionally pop the results.
305   The CALL_INSN is the first insn generated.
306
307   FNDECL is the declaration node of the function.  This is given to the
308   macro RETURN_POPS_ARGS to determine whether this function pops its own args.
309
310   FUNTYPE is the data type of the function.  This is given to the macro
311   RETURN_POPS_ARGS to determine whether this function pops its own args.
312   We used to allow an identifier for library functions, but that doesn't
313   work when the return type is an aggregate type and the calling convention
314   says that the pointer to this aggregate is to be popped by the callee.
315
316   STACK_SIZE is the number of bytes of arguments on the stack,
317   rounded up to STACK_BOUNDARY; zero if the size is variable.
318   This is both to put into the call insn and
319   to generate explicit popping code if necessary.
320
321   STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
322   It is zero if this call doesn't want a structure value.
323
324   NEXT_ARG_REG is the rtx that results from executing
325     FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
326   just after all the args have had their registers assigned.
327   This could be whatever you like, but normally it is the first
328   arg-register beyond those used for args in this call,
329   or 0 if all the arg-registers are used in this call.
330   It is passed on to `gen_call' so you can put this info in the call insn.
331
332   VALREG is a hard register in which a value is returned,
333   or 0 if the call does not return a value.
334
335   OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
336   the args to this call were processed.
337   We restore `inhibit_defer_pop' to that value.
338
339   CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
340   denote registers used by the called function.
341
342   IS_CONST is true if this is a `const' call.  */
343
344static void
345emit_call_1 (funexp, fndecl, funtype, stack_size, struct_value_size,
346             next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
347             is_const)
348     rtx funexp;
349     tree fndecl;
350     tree funtype;
351     HOST_WIDE_INT stack_size;
352     HOST_WIDE_INT struct_value_size;
353     rtx next_arg_reg;
354     rtx valreg;
355     int old_inhibit_defer_pop;
356     rtx call_fusage;
357     int is_const;
358{
359  rtx stack_size_rtx = GEN_INT (stack_size);
360  rtx struct_value_size_rtx = GEN_INT (struct_value_size);
361  rtx call_insn;
362  int already_popped = 0;
363
364  /* Ensure address is valid.  SYMBOL_REF is already valid, so no need,
365     and we don't want to load it into a register as an optimization,
366     because prepare_call_address already did it if it should be done.  */
367  if (GET_CODE (funexp) != SYMBOL_REF)
368    funexp = memory_address (FUNCTION_MODE, funexp);
369
370#ifndef ACCUMULATE_OUTGOING_ARGS
371#if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
372  if (HAVE_call_pop && HAVE_call_value_pop
373      && (RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0
374          || stack_size == 0))
375    {
376      rtx n_pop = GEN_INT (RETURN_POPS_ARGS (fndecl, funtype, stack_size));
377      rtx pat;
378
379      /* If this subroutine pops its own args, record that in the call insn
380         if possible, for the sake of frame pointer elimination.  */
381
382      if (valreg)
383        pat = gen_call_value_pop (valreg,
384                                  gen_rtx (MEM, FUNCTION_MODE, funexp),
385                                  stack_size_rtx, next_arg_reg, n_pop);
386      else
387        pat = gen_call_pop (gen_rtx (MEM, FUNCTION_MODE, funexp),
388                            stack_size_rtx, next_arg_reg, n_pop);
389
390      emit_call_insn (pat);
391      already_popped = 1;
392    }
393  else
394#endif
395#endif
396
397#if defined (HAVE_call) && defined (HAVE_call_value)
398  if (HAVE_call && HAVE_call_value)
399    {
400      if (valreg)
401        emit_call_insn (gen_call_value (valreg,
402                                        gen_rtx (MEM, FUNCTION_MODE, funexp),
403                                        stack_size_rtx, next_arg_reg,
404                                        NULL_RTX));
405      else
406        emit_call_insn (gen_call (gen_rtx (MEM, FUNCTION_MODE, funexp),
407                                  stack_size_rtx, next_arg_reg,
408                                  struct_value_size_rtx));
409    }
410  else
411#endif
412    abort ();
413
414  /* Find the CALL insn we just emitted.  */
415  for (call_insn = get_last_insn ();
416       call_insn && GET_CODE (call_insn) != CALL_INSN;
417       call_insn = PREV_INSN (call_insn))
418    ;
419
420  if (! call_insn)
421    abort ();
422
423  /* Put the register usage information on the CALL.  If there is already
424     some usage information, put ours at the end.  */
425  if (CALL_INSN_FUNCTION_USAGE (call_insn))
426    {
427      rtx link;
428
429      for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
430           link = XEXP (link, 1))
431        ;
432
433      XEXP (link, 1) = call_fusage;
434    }
435  else
436    CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
437
438  /* If this is a const call, then set the insn's unchanging bit.  */
439  if (is_const)
440    CONST_CALL_P (call_insn) = 1;
441
442  /* Restore this now, so that we do defer pops for this call's args
443     if the context of the call as a whole permits.  */
444  inhibit_defer_pop = old_inhibit_defer_pop;
445
446#ifndef ACCUMULATE_OUTGOING_ARGS
447  /* If returning from the subroutine does not automatically pop the args,
448     we need an instruction to pop them sooner or later.
449     Perhaps do it now; perhaps just record how much space to pop later.
450
451     If returning from the subroutine does pop the args, indicate that the
452     stack pointer will be changed.  */
453
454  if (stack_size != 0 && RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0)
455    {
456      if (!already_popped)
457        CALL_INSN_FUNCTION_USAGE (call_insn)
458          = gen_rtx (EXPR_LIST, VOIDmode,
459                     gen_rtx (CLOBBER, VOIDmode, stack_pointer_rtx),
460                     CALL_INSN_FUNCTION_USAGE (call_insn));
461      stack_size -= RETURN_POPS_ARGS (fndecl, funtype, stack_size);
462      stack_size_rtx = GEN_INT (stack_size);
463    }
464
465  if (stack_size != 0)
466    {
467      if (flag_defer_pop && inhibit_defer_pop == 0 && !is_const)
468        pending_stack_adjust += stack_size;
469      else
470        adjust_stack (stack_size_rtx);
471    }
472#endif
473}
474
475/* Generate all the code for a function call
476   and return an rtx for its value.
477   Store the value in TARGET (specified as an rtx) if convenient.
478   If the value is stored in TARGET then TARGET is returned.
479   If IGNORE is nonzero, then we ignore the value of the function call.  */
480
481rtx
482expand_call (exp, target, ignore)
483     tree exp;
484     rtx target;
485     int ignore;
486{
487  /* List of actual parameters.  */
488  tree actparms = TREE_OPERAND (exp, 1);
489  /* RTX for the function to be called.  */
490  rtx funexp;
491  /* Tree node for the function to be called (not the address!).  */
492  tree funtree;
493  /* Data type of the function.  */
494  tree funtype;
495  /* Declaration of the function being called,
496     or 0 if the function is computed (not known by name).  */
497  tree fndecl = 0;
498  char *name = 0;
499
500  /* Register in which non-BLKmode value will be returned,
501     or 0 if no value or if value is BLKmode.  */
502  rtx valreg;
503  /* Address where we should return a BLKmode value;
504     0 if value not BLKmode.  */
505  rtx structure_value_addr = 0;
506  /* Nonzero if that address is being passed by treating it as
507     an extra, implicit first parameter.  Otherwise,
508     it is passed by being copied directly into struct_value_rtx.  */
509  int structure_value_addr_parm = 0;
510  /* Size of aggregate value wanted, or zero if none wanted
511     or if we are using the non-reentrant PCC calling convention
512     or expecting the value in registers.  */
513  HOST_WIDE_INT struct_value_size = 0;
514  /* Nonzero if called function returns an aggregate in memory PCC style,
515     by returning the address of where to find it.  */
516  int pcc_struct_value = 0;
517
518  /* Number of actual parameters in this call, including struct value addr.  */
519  int num_actuals;
520  /* Number of named args.  Args after this are anonymous ones
521     and they must all go on the stack.  */
522  int n_named_args;
523  /* Count arg position in order args appear.  */
524  int argpos;
525
526  /* Vector of information about each argument.
527     Arguments are numbered in the order they will be pushed,
528     not the order they are written.  */
529  struct arg_data *args;
530
531  /* Total size in bytes of all the stack-parms scanned so far.  */
532  struct args_size args_size;
533  /* Size of arguments before any adjustments (such as rounding).  */
534  struct args_size original_args_size;
535  /* Data on reg parms scanned so far.  */
536  CUMULATIVE_ARGS args_so_far;
537  /* Nonzero if a reg parm has been scanned.  */
538  int reg_parm_seen;
539  /* Nonzero if this is an indirect function call.  */
540
541  /* Nonzero if we must avoid push-insns in the args for this call.
542     If stack space is allocated for register parameters, but not by the
543     caller, then it is preallocated in the fixed part of the stack frame.
544     So the entire argument block must then be preallocated (i.e., we
545     ignore PUSH_ROUNDING in that case).  */
546
547#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
548  int must_preallocate = 1;
549#else
550#ifdef PUSH_ROUNDING
551  int must_preallocate = 0;
552#else
553  int must_preallocate = 1;
554#endif
555#endif
556
557  /* Size of the stack reserved for parameter registers.  */
558  int reg_parm_stack_space = 0;
559
560  /* 1 if scanning parms front to back, -1 if scanning back to front.  */
561  int inc;
562  /* Address of space preallocated for stack parms
563     (on machines that lack push insns), or 0 if space not preallocated.  */
564  rtx argblock = 0;
565
566  /* Nonzero if it is plausible that this is a call to alloca.  */
567  int may_be_alloca;
568  /* Nonzero if this is a call to setjmp or a related function.  */
569  int returns_twice;
570  /* Nonzero if this is a call to `longjmp'.  */
571  int is_longjmp;
572  /* Nonzero if this is a call to an inline function.  */
573  int is_integrable = 0;
574  /* Nonzero if this is a call to a `const' function.
575     Note that only explicitly named functions are handled as `const' here.  */
576  int is_const = 0;
577  /* Nonzero if this is a call to a `volatile' function.  */
578  int is_volatile = 0;
579#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
580  /* Define the boundary of the register parm stack space that needs to be
581     save, if any.  */
582  int low_to_save = -1, high_to_save;
583  rtx save_area = 0;            /* Place that it is saved */
584#endif
585
586#ifdef ACCUMULATE_OUTGOING_ARGS
587  int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
588  char *initial_stack_usage_map = stack_usage_map;
589#endif
590
591  rtx old_stack_level = 0;
592  int old_pending_adj = 0;
593  int old_stack_arg_under_construction;
594  int old_inhibit_defer_pop = inhibit_defer_pop;
595  rtx call_fusage = 0;
596  register tree p;
597  register int i, j;
598
599  /* The value of the function call can be put in a hard register.  But
600     if -fcheck-memory-usage, code which invokes functions (and thus
601     damages some hard registers) can be inserted before using the value.
602     So, target is always a pseudo-register in that case.  */
603  if (flag_check_memory_usage)
604    target = 0;
605
606  /* See if we can find a DECL-node for the actual function.
607     As a result, decide whether this is a call to an integrable function.  */
608
609  p = TREE_OPERAND (exp, 0);
610  if (TREE_CODE (p) == ADDR_EXPR)
611    {
612      fndecl = TREE_OPERAND (p, 0);
613      if (TREE_CODE (fndecl) != FUNCTION_DECL)
614        fndecl = 0;
615      else
616        {
617          if (!flag_no_inline
618              && fndecl != current_function_decl
619              && DECL_INLINE (fndecl)
620              && DECL_SAVED_INSNS (fndecl)
621              && RTX_INTEGRATED_P (DECL_SAVED_INSNS (fndecl)))
622            is_integrable = 1;
623          else if (! TREE_ADDRESSABLE (fndecl))
624            {
625              /* In case this function later becomes inlinable,
626                 record that there was already a non-inline call to it.
627
628                 Use abstraction instead of setting TREE_ADDRESSABLE
629                 directly.  */
630              if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
631                  && optimize > 0)
632                {
633                  warning_with_decl (fndecl, "can't inline call to `%s'");
634                  warning ("called from here");
635                }
636              mark_addressable (fndecl);
637            }
638
639          if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
640              && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
641            is_const = 1;
642
643          if (TREE_THIS_VOLATILE (fndecl))
644            is_volatile = 1;
645        }
646    }
647
648  /* If we don't have specific function to call, see if we have a
649     constant or `noreturn' function from the type.  */
650  if (fndecl == 0)
651    {
652      is_const = TREE_READONLY (TREE_TYPE (TREE_TYPE (p)));
653      is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
654    }
655
656#ifdef REG_PARM_STACK_SPACE
657#ifdef MAYBE_REG_PARM_STACK_SPACE
658  reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
659#else
660  reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
661#endif
662#endif
663
664  /* Warn if this value is an aggregate type,
665     regardless of which calling convention we are using for it.  */
666  if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
667    warning ("function call has aggregate value");
668
669  /* Set up a place to return a structure.  */
670
671  /* Cater to broken compilers.  */
672  if (aggregate_value_p (exp))
673    {
674      /* This call returns a big structure.  */
675      is_const = 0;
676
677#ifdef PCC_STATIC_STRUCT_RETURN
678      {
679        pcc_struct_value = 1;
680        /* Easier than making that case work right.  */
681        if (is_integrable)
682          {
683            /* In case this is a static function, note that it has been
684               used.  */
685            if (! TREE_ADDRESSABLE (fndecl))
686              mark_addressable (fndecl);
687            is_integrable = 0;
688          }
689      }
690#else /* not PCC_STATIC_STRUCT_RETURN */
691      {
692        struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
693
694        if (target && GET_CODE (target) == MEM)
695          structure_value_addr = XEXP (target, 0);
696        else
697          {
698            /* Assign a temporary to hold the value.  */
699            tree d;
700
701            /* For variable-sized objects, we must be called with a target
702               specified.  If we were to allocate space on the stack here,
703               we would have no way of knowing when to free it.  */
704
705            if (struct_value_size < 0)
706              abort ();
707
708            /* This DECL is just something to feed to mark_addressable;
709               it doesn't get pushed.  */
710            d = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (exp));
711            DECL_RTL (d) = assign_temp (TREE_TYPE (exp), 1, 0, 1);
712            mark_addressable (d);
713            structure_value_addr = XEXP (DECL_RTL (d), 0);
714            TREE_USED (d) = 1;
715            target = 0;
716          }
717      }
718#endif /* not PCC_STATIC_STRUCT_RETURN */
719    }
720
721  /* If called function is inline, try to integrate it.  */
722
723  if (is_integrable)
724    {
725      rtx temp;
726      rtx before_call = get_last_insn ();
727
728      temp = expand_inline_function (fndecl, actparms, target,
729                                     ignore, TREE_TYPE (exp),
730                                     structure_value_addr);
731
732      /* If inlining succeeded, return.  */
733      if ((HOST_WIDE_INT) temp != -1)
734        {
735#ifdef ACCUMULATE_OUTGOING_ARGS
736          /* If the outgoing argument list must be preserved, push
737             the stack before executing the inlined function if it
738             makes any calls.  */
739
740          for (i = reg_parm_stack_space - 1; i >= 0; i--)
741            if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
742              break;
743
744          if (stack_arg_under_construction || i >= 0)
745            {
746              rtx first_insn
747                = before_call ? NEXT_INSN (before_call) : get_insns ();
748              rtx insn, seq;
749
750              /* Look for a call in the inline function code.
751                 If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is
752                 nonzero then there is a call and it is not necessary
753                 to scan the insns.  */
754
755              if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0)
756                for (insn = first_insn; insn; insn = NEXT_INSN (insn))
757                  if (GET_CODE (insn) == CALL_INSN)
758                    break;
759
760              if (insn)
761                {
762                  /* Reserve enough stack space so that the largest
763                     argument list of any function call in the inline
764                     function does not overlap the argument list being
765                     evaluated.  This is usually an overestimate because
766                     allocate_dynamic_stack_space reserves space for an
767                     outgoing argument list in addition to the requested
768                     space, but there is no way to ask for stack space such
769                     that an argument list of a certain length can be
770                     safely constructed.  */
771
772                  int adjust = OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl));
773#ifdef REG_PARM_STACK_SPACE
774                  /* Add the stack space reserved for register arguments
775                     in the inline function.  What is really needed is the
776                     largest value of reg_parm_stack_space in the inline
777                     function, but that is not available.  Using the current
778                     value of reg_parm_stack_space is wrong, but gives
779                     correct results on all supported machines.  */
780                  adjust += reg_parm_stack_space;
781#endif
782                  start_sequence ();
783                  emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
784                  allocate_dynamic_stack_space (GEN_INT (adjust),
785                                                NULL_RTX, BITS_PER_UNIT);
786                  seq = get_insns ();
787                  end_sequence ();
788                  emit_insns_before (seq, first_insn);
789                  emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
790                }
791            }
792#endif
793
794          /* If the result is equivalent to TARGET, return TARGET to simplify
795             checks in store_expr.  They can be equivalent but not equal in the
796             case of a function that returns BLKmode.  */
797          if (temp != target && rtx_equal_p (temp, target))
798            return target;
799          return temp;
800        }
801
802      /* If inlining failed, mark FNDECL as needing to be compiled
803         separately after all.  If function was declared inline,
804         give a warning.  */
805      if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
806          && optimize > 0 && ! TREE_ADDRESSABLE (fndecl))
807        {
808          warning_with_decl (fndecl, "inlining failed in call to `%s'");
809          warning ("called from here");
810        }
811      mark_addressable (fndecl);
812    }
813
814  /* When calling a const function, we must pop the stack args right away,
815     so that the pop is deleted or moved with the call.  */
816  if (is_const)
817    NO_DEFER_POP;
818
819  function_call_count++;
820
821  if (fndecl && DECL_NAME (fndecl))
822    name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
823
824#if 0
825  /* Unless it's a call to a specific function that isn't alloca,
826     if it has one argument, we must assume it might be alloca.  */
827
828  may_be_alloca
829    = (!(fndecl != 0 && strcmp (name, "alloca"))
830       && actparms != 0
831       && TREE_CHAIN (actparms) == 0);
832#else
833  /* We assume that alloca will always be called by name.  It
834     makes no sense to pass it as a pointer-to-function to
835     anything that does not understand its behavior.  */
836  may_be_alloca
837    = (name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
838                 && name[0] == 'a'
839                 && ! strcmp (name, "alloca"))
840                || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
841                    && name[0] == '_'
842                    && ! strcmp (name, "__builtin_alloca"))));
843#endif
844
845  /* See if this is a call to a function that can return more than once
846     or a call to longjmp.  */
847
848  returns_twice = 0;
849  is_longjmp = 0;
850
851  if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 15)
852    {
853      char *tname = name;
854
855      /* Disregard prefix _, __ or __x.  */
856      if (name[0] == '_')
857        {
858          if (name[1] == '_' && name[2] == 'x')
859            tname += 3;
860          else if (name[1] == '_')
861            tname += 2;
862          else
863            tname += 1;
864        }
865
866      if (tname[0] == 's')
867        {
868          returns_twice
869            = ((tname[1] == 'e'
870                && (! strcmp (tname, "setjmp")
871                    || ! strcmp (tname, "setjmp_syscall")))
872               || (tname[1] == 'i'
873                   && ! strcmp (tname, "sigsetjmp"))
874               || (tname[1] == 'a'
875                   && ! strcmp (tname, "savectx")));
876          if (tname[1] == 'i'
877              && ! strcmp (tname, "siglongjmp"))
878            is_longjmp = 1;
879        }
880      else if ((tname[0] == 'q' && tname[1] == 's'
881                && ! strcmp (tname, "qsetjmp"))
882               || (tname[0] == 'v' && tname[1] == 'f'
883                   && ! strcmp (tname, "vfork")))
884        returns_twice = 1;
885
886      else if (tname[0] == 'l' && tname[1] == 'o'
887               && ! strcmp (tname, "longjmp"))
888        is_longjmp = 1;
889    }
890
891  if (may_be_alloca)
892    current_function_calls_alloca = 1;
893
894  /* Don't let pending stack adjusts add up to too much.
895     Also, do all pending adjustments now
896     if there is any chance this might be a call to alloca.  */
897
898  if (pending_stack_adjust >= 32
899      || (pending_stack_adjust > 0 && may_be_alloca))
900    do_pending_stack_adjust ();
901
902  /* Operand 0 is a pointer-to-function; get the type of the function.  */
903  funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
904  if (TREE_CODE (funtype) != POINTER_TYPE)
905    abort ();
906  funtype = TREE_TYPE (funtype);
907
908  /* Push the temporary stack slot level so that we can free any temporaries
909     we make.  */
910  push_temp_slots ();
911
912  /* Start updating where the next arg would go.
913
914     On some machines (such as the PA) indirect calls have a different
915     calling convention than normal calls.  The last argument in
916     INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
917     or not.  */
918  INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, (fndecl == 0));
919
920  /* If struct_value_rtx is 0, it means pass the address
921     as if it were an extra parameter.  */
922  if (structure_value_addr && struct_value_rtx == 0)
923    {
924      /* If structure_value_addr is a REG other than
925         virtual_outgoing_args_rtx, we can use always use it.  If it
926         is not a REG, we must always copy it into a register.
927         If it is virtual_outgoing_args_rtx, we must copy it to another
928         register in some cases.  */
929      rtx temp = (GET_CODE (structure_value_addr) != REG
930#ifdef ACCUMULATE_OUTGOING_ARGS
931                  || (stack_arg_under_construction
932                      && structure_value_addr == virtual_outgoing_args_rtx)
933#endif
934                  ? copy_addr_to_reg (structure_value_addr)
935                  : structure_value_addr);
936
937      actparms
938        = tree_cons (error_mark_node,
939                     make_tree (build_pointer_type (TREE_TYPE (funtype)),
940                                temp),
941                     actparms);
942      structure_value_addr_parm = 1;
943    }
944
945  /* Count the arguments and set NUM_ACTUALS.  */
946  for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
947  num_actuals = i;
948
949  /* Compute number of named args.
950     Normally, don't include the last named arg if anonymous args follow.
951     We do include the last named arg if STRICT_ARGUMENT_NAMING is defined.
952     (If no anonymous args follow, the result of list_length is actually
953     one too large.  This is harmless.)
954
955     If SETUP_INCOMING_VARARGS is defined and STRICT_ARGUMENT_NAMING is not,
956     this machine will be able to place unnamed args that were passed in
957     registers into the stack.  So treat all args as named.  This allows the
958     insns emitting for a specific argument list to be independent of the
959     function declaration.
960
961     If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable
962     way to pass unnamed args in registers, so we must force them into
963     memory.  */
964#if !defined(SETUP_INCOMING_VARARGS) || defined(STRICT_ARGUMENT_NAMING)
965  if (TYPE_ARG_TYPES (funtype) != 0)
966    n_named_args
967      = (list_length (TYPE_ARG_TYPES (funtype))
968#ifndef STRICT_ARGUMENT_NAMING
969         /* Don't include the last named arg.  */
970         - 1
971#endif
972         /* Count the struct value address, if it is passed as a parm.  */
973         + structure_value_addr_parm);
974  else
975#endif
976    /* If we know nothing, treat all args as named.  */
977    n_named_args = num_actuals;
978
979  /* Make a vector to hold all the information about each arg.  */
980  args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
981  bzero ((char *) args, num_actuals * sizeof (struct arg_data));
982
983  args_size.constant = 0;
984  args_size.var = 0;
985
986  /* In this loop, we consider args in the order they are written.
987     We fill up ARGS from the front or from the back if necessary
988     so that in any case the first arg to be pushed ends up at the front.  */
989
990#ifdef PUSH_ARGS_REVERSED
991  i = num_actuals - 1, inc = -1;
992  /* In this case, must reverse order of args
993     so that we compute and push the last arg first.  */
994#else
995  i = 0, inc = 1;
996#endif
997
998  /* I counts args in order (to be) pushed; ARGPOS counts in order written.  */
999  for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
1000    {
1001      tree type = TREE_TYPE (TREE_VALUE (p));
1002      int unsignedp;
1003      enum machine_mode mode;
1004
1005      args[i].tree_value = TREE_VALUE (p);
1006
1007      /* Replace erroneous argument with constant zero.  */
1008      if (type == error_mark_node || TYPE_SIZE (type) == 0)
1009        args[i].tree_value = integer_zero_node, type = integer_type_node;
1010
1011      /* If TYPE is a transparent union, pass things the way we would
1012         pass the first field of the union.  We have already verified that
1013         the modes are the same.  */
1014      if (TYPE_TRANSPARENT_UNION (type))
1015        type = TREE_TYPE (TYPE_FIELDS (type));
1016
1017      /* Decide where to pass this arg.
1018
1019         args[i].reg is nonzero if all or part is passed in registers.
1020
1021         args[i].partial is nonzero if part but not all is passed in registers,
1022         and the exact value says how many words are passed in registers.
1023
1024         args[i].pass_on_stack is nonzero if the argument must at least be
1025         computed on the stack.  It may then be loaded back into registers
1026         if args[i].reg is nonzero.
1027
1028         These decisions are driven by the FUNCTION_... macros and must agree
1029         with those made by function.c.  */
1030
1031      /* See if this argument should be passed by invisible reference.  */
1032      if ((TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1033           && contains_placeholder_p (TYPE_SIZE (type)))
1034          || TREE_ADDRESSABLE (type)
1035#ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1036          || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, TYPE_MODE (type),
1037                                             type, argpos < n_named_args)
1038#endif
1039          )
1040        {
1041          /* If we're compiling a thunk, pass through invisible
1042             references instead of making a copy.  */
1043          if (current_function_is_thunk
1044#ifdef FUNCTION_ARG_CALLEE_COPIES
1045              || (FUNCTION_ARG_CALLEE_COPIES (args_so_far, TYPE_MODE (type),
1046                                             type, argpos < n_named_args)
1047                  /* If it's in a register, we must make a copy of it too.  */
1048                  /* ??? Is this a sufficient test?  Is there a better one? */
1049                  && !(TREE_CODE (args[i].tree_value) == VAR_DECL
1050                       && REG_P (DECL_RTL (args[i].tree_value)))
1051                  && ! TREE_ADDRESSABLE (type))
1052#endif
1053              )
1054            {
1055              args[i].tree_value = build1 (ADDR_EXPR,
1056                                           build_pointer_type (type),
1057                                           args[i].tree_value);
1058              type = build_pointer_type (type);
1059            }
1060          else
1061            {
1062              /* We make a copy of the object and pass the address to the
1063                 function being called.  */
1064              rtx copy;
1065
1066              if (TYPE_SIZE (type) == 0
1067                  || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1068                  || (flag_stack_check && ! STACK_CHECK_BUILTIN
1069                      && (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0
1070                          || (TREE_INT_CST_LOW (TYPE_SIZE (type))
1071                              > STACK_CHECK_MAX_VAR_SIZE * BITS_PER_UNIT))))
1072                {
1073                  /* This is a variable-sized object.  Make space on the stack
1074                     for it.  */
1075                  rtx size_rtx = expr_size (TREE_VALUE (p));
1076
1077                  if (old_stack_level == 0)
1078                    {
1079                      emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1080                      old_pending_adj = pending_stack_adjust;
1081                      pending_stack_adjust = 0;
1082                    }
1083
1084                  copy = gen_rtx (MEM, BLKmode,
1085                                  allocate_dynamic_stack_space (size_rtx,
1086                                                                NULL_RTX,
1087                                                                TYPE_ALIGN (type)));
1088                }
1089              else
1090                {
1091                  int size = int_size_in_bytes (type);
1092                  copy = assign_stack_temp (TYPE_MODE (type), size, 0);
1093                }
1094
1095              MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
1096
1097              store_expr (args[i].tree_value, copy, 0);
1098              is_const = 0;
1099
1100              args[i].tree_value = build1 (ADDR_EXPR,
1101                                           build_pointer_type (type),
1102                                           make_tree (type, copy));
1103              type = build_pointer_type (type);
1104            }
1105        }
1106
1107      mode = TYPE_MODE (type);
1108      unsignedp = TREE_UNSIGNED (type);
1109
1110#ifdef PROMOTE_FUNCTION_ARGS
1111      mode = promote_mode (type, mode, &unsignedp, 1);
1112#endif
1113
1114      args[i].unsignedp = unsignedp;
1115      args[i].mode = mode;
1116      args[i].reg = FUNCTION_ARG (args_so_far, mode, type,
1117                                  argpos < n_named_args);
1118#ifdef FUNCTION_ARG_PARTIAL_NREGS
1119      if (args[i].reg)
1120        args[i].partial
1121          = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, type,
1122                                        argpos < n_named_args);
1123#endif
1124
1125      args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
1126
1127      /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1128         it means that we are to pass this arg in the register(s) designated
1129         by the PARALLEL, but also to pass it in the stack.  */
1130      if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1131          && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1132        args[i].pass_on_stack = 1;
1133
1134      /* If this is an addressable type, we must preallocate the stack
1135         since we must evaluate the object into its final location.
1136
1137         If this is to be passed in both registers and the stack, it is simpler
1138         to preallocate.  */
1139      if (TREE_ADDRESSABLE (type)
1140          || (args[i].pass_on_stack && args[i].reg != 0))
1141        must_preallocate = 1;
1142
1143      /* If this is an addressable type, we cannot pre-evaluate it.  Thus,
1144         we cannot consider this function call constant.  */
1145      if (TREE_ADDRESSABLE (type))
1146        is_const = 0;
1147
1148      /* Compute the stack-size of this argument.  */
1149      if (args[i].reg == 0 || args[i].partial != 0
1150#ifdef REG_PARM_STACK_SPACE
1151          || reg_parm_stack_space > 0
1152#endif
1153          || args[i].pass_on_stack)
1154        locate_and_pad_parm (mode, type,
1155#ifdef STACK_PARMS_IN_REG_PARM_AREA
1156                             1,
1157#else
1158                             args[i].reg != 0,
1159#endif
1160                             fndecl, &args_size, &args[i].offset,
1161                             &args[i].size);
1162
1163#ifndef ARGS_GROW_DOWNWARD
1164      args[i].slot_offset = args_size;
1165#endif
1166
1167#ifndef REG_PARM_STACK_SPACE
1168      /* If a part of the arg was put into registers,
1169         don't include that part in the amount pushed.  */
1170      if (! args[i].pass_on_stack)
1171        args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1172                                  / (PARM_BOUNDARY / BITS_PER_UNIT)
1173                                  * (PARM_BOUNDARY / BITS_PER_UNIT));
1174#endif
1175     
1176      /* Update ARGS_SIZE, the total stack space for args so far.  */
1177
1178      args_size.constant += args[i].size.constant;
1179      if (args[i].size.var)
1180        {
1181          ADD_PARM_SIZE (args_size, args[i].size.var);
1182        }
1183
1184      /* Since the slot offset points to the bottom of the slot,
1185         we must record it after incrementing if the args grow down.  */
1186#ifdef ARGS_GROW_DOWNWARD
1187      args[i].slot_offset = args_size;
1188
1189      args[i].slot_offset.constant = -args_size.constant;
1190      if (args_size.var)
1191        {
1192          SUB_PARM_SIZE (args[i].slot_offset, args_size.var);
1193        }
1194#endif
1195
1196      /* Increment ARGS_SO_FAR, which has info about which arg-registers
1197         have been used, etc.  */
1198
1199      FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type,
1200                            argpos < n_named_args);
1201    }
1202
1203#ifdef FINAL_REG_PARM_STACK_SPACE
1204  reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
1205                                                     args_size.var);
1206#endif
1207     
1208  /* Compute the actual size of the argument block required.  The variable
1209     and constant sizes must be combined, the size may have to be rounded,
1210     and there may be a minimum required size.  */
1211
1212  original_args_size = args_size;
1213  if (args_size.var)
1214    {
1215      /* If this function requires a variable-sized argument list, don't try to
1216         make a cse'able block for this call.  We may be able to do this
1217         eventually, but it is too complicated to keep track of what insns go
1218         in the cse'able block and which don't.  */
1219
1220      is_const = 0;
1221      must_preallocate = 1;
1222
1223      args_size.var = ARGS_SIZE_TREE (args_size);
1224      args_size.constant = 0;
1225
1226#ifdef STACK_BOUNDARY
1227      if (STACK_BOUNDARY != BITS_PER_UNIT)
1228        args_size.var = round_up (args_size.var, STACK_BYTES);
1229#endif
1230
1231#ifdef REG_PARM_STACK_SPACE
1232      if (reg_parm_stack_space > 0)
1233        {
1234          args_size.var
1235            = size_binop (MAX_EXPR, args_size.var,
1236                          size_int (REG_PARM_STACK_SPACE (fndecl)));
1237
1238#ifndef OUTGOING_REG_PARM_STACK_SPACE
1239          /* The area corresponding to register parameters is not to count in
1240             the size of the block we need.  So make the adjustment.  */
1241          args_size.var
1242            = size_binop (MINUS_EXPR, args_size.var,
1243                          size_int (reg_parm_stack_space));
1244#endif
1245        }
1246#endif
1247    }
1248  else
1249    {
1250#ifdef STACK_BOUNDARY
1251      args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
1252                             / STACK_BYTES) * STACK_BYTES);
1253#endif
1254
1255#ifdef REG_PARM_STACK_SPACE
1256      args_size.constant = MAX (args_size.constant,
1257                                reg_parm_stack_space);
1258#ifdef MAYBE_REG_PARM_STACK_SPACE
1259      if (reg_parm_stack_space == 0)
1260        args_size.constant = 0;
1261#endif
1262#ifndef OUTGOING_REG_PARM_STACK_SPACE
1263      args_size.constant -= reg_parm_stack_space;
1264#endif
1265#endif
1266    }
1267
1268  /* See if we have or want to preallocate stack space.
1269
1270     If we would have to push a partially-in-regs parm
1271     before other stack parms, preallocate stack space instead.
1272
1273     If the size of some parm is not a multiple of the required stack
1274     alignment, we must preallocate.
1275
1276     If the total size of arguments that would otherwise create a copy in
1277     a temporary (such as a CALL) is more than half the total argument list
1278     size, preallocation is faster.
1279
1280     Another reason to preallocate is if we have a machine (like the m88k)
1281     where stack alignment is required to be maintained between every
1282     pair of insns, not just when the call is made.  However, we assume here
1283     that such machines either do not have push insns (and hence preallocation
1284     would occur anyway) or the problem is taken care of with
1285     PUSH_ROUNDING.  */
1286
1287  if (! must_preallocate)
1288    {
1289      int partial_seen = 0;
1290      int copy_to_evaluate_size = 0;
1291
1292      for (i = 0; i < num_actuals && ! must_preallocate; i++)
1293        {
1294          if (args[i].partial > 0 && ! args[i].pass_on_stack)
1295            partial_seen = 1;
1296          else if (partial_seen && args[i].reg == 0)
1297            must_preallocate = 1;
1298
1299          if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1300              && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1301                  || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1302                  || TREE_CODE (args[i].tree_value) == COND_EXPR
1303                  || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1304            copy_to_evaluate_size
1305              += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1306        }
1307
1308      if (copy_to_evaluate_size * 2 >= args_size.constant
1309          && args_size.constant > 0)
1310        must_preallocate = 1;
1311    }
1312
1313  /* If the structure value address will reference the stack pointer, we must
1314     stabilize it.  We don't need to do this if we know that we are not going
1315     to adjust the stack pointer in processing this call.  */
1316
1317  if (structure_value_addr
1318      && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
1319       || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr))
1320      && (args_size.var
1321#ifndef ACCUMULATE_OUTGOING_ARGS
1322          || args_size.constant
1323#endif
1324          ))
1325    structure_value_addr = copy_to_reg (structure_value_addr);
1326
1327  /* If this function call is cse'able, precompute all the parameters.
1328     Note that if the parameter is constructed into a temporary, this will
1329     cause an additional copy because the parameter will be constructed
1330     into a temporary location and then copied into the outgoing arguments.
1331     If a parameter contains a call to alloca and this function uses the
1332     stack, precompute the parameter.  */
1333
1334  /* If we preallocated the stack space, and some arguments must be passed
1335     on the stack, then we must precompute any parameter which contains a
1336     function call which will store arguments on the stack.
1337     Otherwise, evaluating the parameter may clobber previous parameters
1338     which have already been stored into the stack.  */
1339
1340  for (i = 0; i < num_actuals; i++)
1341    if (is_const
1342        || ((args_size.var != 0 || args_size.constant != 0)
1343            && calls_function (args[i].tree_value, 1))
1344        || (must_preallocate && (args_size.var != 0 || args_size.constant != 0)
1345            && calls_function (args[i].tree_value, 0)))
1346      {
1347        /* If this is an addressable type, we cannot pre-evaluate it.  */
1348        if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))
1349          abort ();
1350
1351        push_temp_slots ();
1352
1353        args[i].initial_value = args[i].value
1354          = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1355
1356        preserve_temp_slots (args[i].value);
1357        pop_temp_slots ();
1358
1359        /* ANSI doesn't require a sequence point here,
1360           but PCC has one, so this will avoid some problems.  */
1361        emit_queue ();
1362
1363        args[i].initial_value = args[i].value
1364          = protect_from_queue (args[i].initial_value, 0);
1365
1366        if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != args[i].mode)
1367          args[i].value
1368            = convert_modes (args[i].mode,
1369                             TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1370                             args[i].value, args[i].unsignedp);
1371      }
1372
1373  /* Now we are about to start emitting insns that can be deleted
1374     if a libcall is deleted.  */
1375  if (is_const)
1376    start_sequence ();
1377
1378  /* If we have no actual push instructions, or shouldn't use them,
1379     make space for all args right now.  */
1380
1381  if (args_size.var != 0)
1382    {
1383      if (old_stack_level == 0)
1384        {
1385          emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1386          old_pending_adj = pending_stack_adjust;
1387          pending_stack_adjust = 0;
1388#ifdef ACCUMULATE_OUTGOING_ARGS
1389          /* stack_arg_under_construction says whether a stack arg is
1390             being constructed at the old stack level.  Pushing the stack
1391             gets a clean outgoing argument block.  */
1392          old_stack_arg_under_construction = stack_arg_under_construction;
1393          stack_arg_under_construction = 0;
1394#endif
1395        }
1396      argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
1397    }
1398  else
1399    {
1400      /* Note that we must go through the motions of allocating an argument
1401         block even if the size is zero because we may be storing args
1402         in the area reserved for register arguments, which may be part of
1403         the stack frame.  */
1404
1405      int needed = args_size.constant;
1406
1407      /* Store the maximum argument space used.  It will be pushed by
1408         the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
1409         checking).  */
1410
1411      if (needed > current_function_outgoing_args_size)
1412        current_function_outgoing_args_size = needed;
1413
1414      if (must_preallocate)
1415        {
1416#ifdef ACCUMULATE_OUTGOING_ARGS
1417          /* Since the stack pointer will never be pushed, it is possible for
1418             the evaluation of a parm to clobber something we have already
1419             written to the stack.  Since most function calls on RISC machines
1420             do not use the stack, this is uncommon, but must work correctly.
1421
1422             Therefore, we save any area of the stack that was already written
1423             and that we are using.  Here we set up to do this by making a new
1424             stack usage map from the old one.  The actual save will be done
1425             by store_one_arg.
1426
1427             Another approach might be to try to reorder the argument
1428             evaluations to avoid this conflicting stack usage.  */
1429
1430#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1431          /* Since we will be writing into the entire argument area, the
1432             map must be allocated for its entire size, not just the part that
1433             is the responsibility of the caller.  */
1434          needed += reg_parm_stack_space;
1435#endif
1436
1437#ifdef ARGS_GROW_DOWNWARD
1438          highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1439                                             needed + 1);
1440#else
1441          highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1442                                             needed);
1443#endif
1444          stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
1445
1446          if (initial_highest_arg_in_use)
1447            bcopy (initial_stack_usage_map, stack_usage_map,
1448                   initial_highest_arg_in_use);
1449
1450          if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
1451            bzero (&stack_usage_map[initial_highest_arg_in_use],
1452                   highest_outgoing_arg_in_use - initial_highest_arg_in_use);
1453          needed = 0;
1454
1455          /* The address of the outgoing argument list must not be copied to a
1456             register here, because argblock would be left pointing to the
1457             wrong place after the call to allocate_dynamic_stack_space below.
1458             */
1459
1460          argblock = virtual_outgoing_args_rtx;
1461
1462#else /* not ACCUMULATE_OUTGOING_ARGS */
1463          if (inhibit_defer_pop == 0)
1464            {
1465              /* Try to reuse some or all of the pending_stack_adjust
1466                 to get this space.  Maybe we can avoid any pushing.  */
1467              if (needed > pending_stack_adjust)
1468                {
1469                  needed -= pending_stack_adjust;
1470                  pending_stack_adjust = 0;
1471                }
1472              else
1473                {
1474                  pending_stack_adjust -= needed;
1475                  needed = 0;
1476                }
1477            }
1478          /* Special case this because overhead of `push_block' in this
1479             case is non-trivial.  */
1480          if (needed == 0)
1481            argblock = virtual_outgoing_args_rtx;
1482          else
1483            argblock = push_block (GEN_INT (needed), 0, 0);
1484
1485          /* We only really need to call `copy_to_reg' in the case where push
1486             insns are going to be used to pass ARGBLOCK to a function
1487             call in ARGS.  In that case, the stack pointer changes value
1488             from the allocation point to the call point, and hence
1489             the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
1490             But might as well always do it.  */
1491          argblock = copy_to_reg (argblock);
1492#endif /* not ACCUMULATE_OUTGOING_ARGS */
1493        }
1494    }
1495
1496#ifdef ACCUMULATE_OUTGOING_ARGS
1497  /* The save/restore code in store_one_arg handles all cases except one:
1498     a constructor call (including a C function returning a BLKmode struct)
1499     to initialize an argument.  */
1500  if (stack_arg_under_construction)
1501    {
1502#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1503      rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
1504#else
1505      rtx push_size = GEN_INT (args_size.constant);
1506#endif
1507      if (old_stack_level == 0)
1508        {
1509          emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1510          old_pending_adj = pending_stack_adjust;
1511          pending_stack_adjust = 0;
1512          /* stack_arg_under_construction says whether a stack arg is
1513             being constructed at the old stack level.  Pushing the stack
1514             gets a clean outgoing argument block.  */
1515          old_stack_arg_under_construction = stack_arg_under_construction;
1516          stack_arg_under_construction = 0;
1517          /* Make a new map for the new argument list.  */
1518          stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
1519          bzero (stack_usage_map, highest_outgoing_arg_in_use);
1520          highest_outgoing_arg_in_use = 0;
1521        }
1522      allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
1523    }
1524  /* If argument evaluation might modify the stack pointer, copy the
1525     address of the argument list to a register.  */
1526  for (i = 0; i < num_actuals; i++)
1527    if (args[i].pass_on_stack)
1528      {
1529        argblock = copy_addr_to_reg (argblock);
1530        break;
1531      }
1532#endif
1533
1534
1535  /* If we preallocated stack space, compute the address of each argument.
1536     We need not ensure it is a valid memory address here; it will be
1537     validized when it is used.  */
1538  if (argblock)
1539    {
1540      rtx arg_reg = argblock;
1541      int arg_offset = 0;
1542
1543      if (GET_CODE (argblock) == PLUS)
1544        arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1545
1546      for (i = 0; i < num_actuals; i++)
1547        {
1548          rtx offset = ARGS_SIZE_RTX (args[i].offset);
1549          rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1550          rtx addr;
1551
1552          /* Skip this parm if it will not be passed on the stack.  */
1553          if (! args[i].pass_on_stack && args[i].reg != 0)
1554            continue;
1555
1556          if (GET_CODE (offset) == CONST_INT)
1557            addr = plus_constant (arg_reg, INTVAL (offset));
1558          else
1559            addr = gen_rtx (PLUS, Pmode, arg_reg, offset);
1560
1561          addr = plus_constant (addr, arg_offset);
1562          args[i].stack = gen_rtx (MEM, args[i].mode, addr);
1563          MEM_IN_STRUCT_P (args[i].stack)
1564            = AGGREGATE_TYPE_P (TREE_TYPE (args[i].tree_value));
1565
1566          if (GET_CODE (slot_offset) == CONST_INT)
1567            addr = plus_constant (arg_reg, INTVAL (slot_offset));
1568          else
1569            addr = gen_rtx (PLUS, Pmode, arg_reg, slot_offset);
1570
1571          addr = plus_constant (addr, arg_offset);
1572          args[i].stack_slot = gen_rtx (MEM, args[i].mode, addr);
1573        }
1574    }
1575                                               
1576#ifdef PUSH_ARGS_REVERSED
1577#ifdef STACK_BOUNDARY
1578  /* If we push args individually in reverse order, perform stack alignment
1579     before the first push (the last arg).  */
1580  if (argblock == 0)
1581    anti_adjust_stack (GEN_INT (args_size.constant
1582                                - original_args_size.constant));
1583#endif
1584#endif
1585
1586  /* Don't try to defer pops if preallocating, not even from the first arg,
1587     since ARGBLOCK probably refers to the SP.  */
1588  if (argblock)
1589    NO_DEFER_POP;
1590
1591  /* Get the function to call, in the form of RTL.  */
1592  if (fndecl)
1593    {
1594      /* If this is the first use of the function, see if we need to
1595         make an external definition for it.  */
1596      if (! TREE_USED (fndecl))
1597        {
1598          assemble_external (fndecl);
1599          TREE_USED (fndecl) = 1;
1600        }
1601
1602      /* Get a SYMBOL_REF rtx for the function address.  */
1603      funexp = XEXP (DECL_RTL (fndecl), 0);
1604    }
1605  else
1606    /* Generate an rtx (probably a pseudo-register) for the address.  */
1607    {
1608      push_temp_slots ();
1609      funexp = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1610      pop_temp_slots ();        /* FUNEXP can't be BLKmode */
1611
1612      /* Check the function is executable.  */
1613      if (flag_check_memory_usage)
1614        emit_library_call (chkr_check_exec_libfunc, 1,
1615                           VOIDmode, 1,
1616                           funexp, ptr_mode);
1617      emit_queue ();
1618    }
1619
1620  /* Figure out the register where the value, if any, will come back.  */
1621  valreg = 0;
1622  if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
1623      && ! structure_value_addr)
1624    {
1625      if (pcc_struct_value)
1626        valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
1627                                      fndecl);
1628      else
1629        valreg = hard_function_value (TREE_TYPE (exp), fndecl);
1630    }
1631
1632  /* Precompute all register parameters.  It isn't safe to compute anything
1633     once we have started filling any specific hard regs.  */
1634  reg_parm_seen = 0;
1635  for (i = 0; i < num_actuals; i++)
1636    if (args[i].reg != 0 && ! args[i].pass_on_stack)
1637      {
1638        reg_parm_seen = 1;
1639
1640        if (args[i].value == 0)
1641          {
1642            push_temp_slots ();
1643            args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
1644                                         VOIDmode, 0);
1645            preserve_temp_slots (args[i].value);
1646            pop_temp_slots ();
1647
1648            /* ANSI doesn't require a sequence point here,
1649               but PCC has one, so this will avoid some problems.  */
1650            emit_queue ();
1651          }
1652
1653        /* If we are to promote the function arg to a wider mode,
1654           do it now.  */
1655
1656        if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
1657          args[i].value
1658            = convert_modes (args[i].mode,
1659                             TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1660                             args[i].value, args[i].unsignedp);
1661
1662        /* If the value is expensive, and we are inside an appropriately
1663           short loop, put the value into a pseudo and then put the pseudo
1664           into the hard reg.
1665
1666           For small register classes, also do this if this call uses
1667           register parameters.  This is to avoid reload conflicts while
1668           loading the parameters registers.  */
1669
1670        if ((! (GET_CODE (args[i].value) == REG
1671                || (GET_CODE (args[i].value) == SUBREG
1672                    && GET_CODE (SUBREG_REG (args[i].value)) == REG)))
1673            && args[i].mode != BLKmode
1674            && rtx_cost (args[i].value, SET) > 2
1675            && ((SMALL_REGISTER_CLASSES && reg_parm_seen)
1676                || preserve_subexpressions_p ()))
1677          args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
1678      }
1679
1680#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1681  /* The argument list is the property of the called routine and it
1682     may clobber it.  If the fixed area has been used for previous
1683     parameters, we must save and restore it.
1684
1685     Here we compute the boundary of the that needs to be saved, if any.  */
1686
1687#ifdef ARGS_GROW_DOWNWARD
1688  for (i = 0; i < reg_parm_stack_space + 1; i++)
1689#else
1690  for (i = 0; i < reg_parm_stack_space; i++)
1691#endif
1692    {
1693      if (i >=  highest_outgoing_arg_in_use
1694          || stack_usage_map[i] == 0)
1695        continue;
1696
1697      if (low_to_save == -1)
1698        low_to_save = i;
1699
1700      high_to_save = i;
1701    }
1702
1703  if (low_to_save >= 0)
1704    {
1705      int num_to_save = high_to_save - low_to_save + 1;
1706      enum machine_mode save_mode
1707        = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
1708      rtx stack_area;
1709
1710      /* If we don't have the required alignment, must do this in BLKmode.  */
1711      if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
1712                               BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
1713        save_mode = BLKmode;
1714
1715      stack_area = gen_rtx (MEM, save_mode,
1716                            memory_address (save_mode,
1717                                           
1718#ifdef ARGS_GROW_DOWNWARD
1719                                            plus_constant (argblock,
1720                                                           - high_to_save)
1721#else
1722                                            plus_constant (argblock,
1723                                                           low_to_save)
1724#endif
1725                                            ));
1726      if (save_mode == BLKmode)
1727        {
1728          save_area = assign_stack_temp (BLKmode, num_to_save, 0);
1729          MEM_IN_STRUCT_P (save_area) = 0;
1730          emit_block_move (validize_mem (save_area), stack_area,
1731                           GEN_INT (num_to_save),
1732                           PARM_BOUNDARY / BITS_PER_UNIT);
1733        }
1734      else
1735        {
1736          save_area = gen_reg_rtx (save_mode);
1737          emit_move_insn (save_area, stack_area);
1738        }
1739    }
1740#endif
1741         
1742
1743  /* Now store (and compute if necessary) all non-register parms.
1744     These come before register parms, since they can require block-moves,
1745     which could clobber the registers used for register parms.
1746     Parms which have partial registers are not stored here,
1747     but we do preallocate space here if they want that.  */
1748
1749  for (i = 0; i < num_actuals; i++)
1750    if (args[i].reg == 0 || args[i].pass_on_stack)
1751      store_one_arg (&args[i], argblock, may_be_alloca,
1752                     args_size.var != 0, fndecl, reg_parm_stack_space);
1753
1754  /* If we have a parm that is passed in registers but not in memory
1755     and whose alignment does not permit a direct copy into registers,
1756     make a group of pseudos that correspond to each register that we
1757     will later fill.  */
1758
1759  if (STRICT_ALIGNMENT)
1760    for (i = 0; i < num_actuals; i++)
1761      if (args[i].reg != 0 && ! args[i].pass_on_stack
1762        && args[i].mode == BLKmode
1763          && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
1764              < MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
1765        {
1766          int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1767          int big_endian_correction = 0;
1768
1769          args[i].n_aligned_regs
1770            = args[i].partial ? args[i].partial
1771              : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
1772
1773          args[i].aligned_regs = (rtx *) alloca (sizeof (rtx)
1774                                                 * args[i].n_aligned_regs);
1775
1776          /* Structures smaller than a word are aligned to the least
1777             significant byte (to the right).  On a BYTES_BIG_ENDIAN machine,
1778             this means we must skip the empty high order bytes when
1779             calculating the bit offset.  */
1780          if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD)
1781            big_endian_correction = (BITS_PER_WORD  - (bytes * BITS_PER_UNIT));
1782
1783          for (j = 0; j < args[i].n_aligned_regs; j++)
1784            {
1785              rtx reg = gen_reg_rtx (word_mode);
1786              rtx word = operand_subword_force (args[i].value, j, BLKmode);
1787              int bitsize = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
1788              int bitpos;
1789
1790              args[i].aligned_regs[j] = reg;
1791
1792              /* Clobber REG and move each partword into it.  Ensure we don't
1793                 go past the end of the structure.  Note that the loop below
1794                 works because we've already verified that padding
1795                 and endianness are compatible.
1796
1797                 We use to emit a clobber here but that doesn't let later
1798                 passes optimize the instructions we emit.  By storing 0 into
1799                 the register later passes know the first AND to zero out the
1800                 bitfield being set in the register is unnecessary.  The store
1801                 of 0 will be deleted as will at least the first AND.  */
1802
1803              emit_move_insn (reg, const0_rtx);
1804
1805              for (bitpos = 0;
1806                   bitpos < BITS_PER_WORD && bytes > 0;
1807                   bitpos += bitsize, bytes -= bitsize / BITS_PER_UNIT)
1808                {
1809                  int xbitpos = bitpos + big_endian_correction;
1810
1811                  store_bit_field (reg, bitsize, xbitpos, word_mode,
1812                                   extract_bit_field (word, bitsize, bitpos, 1,
1813                                                      NULL_RTX, word_mode,
1814                                                      word_mode,
1815                                                      bitsize / BITS_PER_UNIT,
1816                                                      BITS_PER_WORD),
1817                                   bitsize / BITS_PER_UNIT, BITS_PER_WORD);
1818                }
1819            }
1820        }
1821
1822  /* Now store any partially-in-registers parm.
1823     This is the last place a block-move can happen.  */
1824  if (reg_parm_seen)
1825    for (i = 0; i < num_actuals; i++)
1826      if (args[i].partial != 0 && ! args[i].pass_on_stack)
1827        store_one_arg (&args[i], argblock, may_be_alloca,
1828                       args_size.var != 0, fndecl, reg_parm_stack_space);
1829
1830#ifndef PUSH_ARGS_REVERSED
1831#ifdef STACK_BOUNDARY
1832  /* If we pushed args in forward order, perform stack alignment
1833     after pushing the last arg.  */
1834  if (argblock == 0)
1835    anti_adjust_stack (GEN_INT (args_size.constant
1836                                - original_args_size.constant));
1837#endif
1838#endif
1839
1840  /* If register arguments require space on the stack and stack space
1841     was not preallocated, allocate stack space here for arguments
1842     passed in registers.  */
1843#if ! defined(ACCUMULATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
1844  if (must_preallocate == 0 && reg_parm_stack_space > 0)
1845    anti_adjust_stack (GEN_INT (reg_parm_stack_space));
1846#endif
1847
1848  /* Pass the function the address in which to return a structure value.  */
1849  if (structure_value_addr && ! structure_value_addr_parm)
1850    {
1851      emit_move_insn (struct_value_rtx,
1852                      force_reg (Pmode,
1853                                 force_operand (structure_value_addr,
1854                                                NULL_RTX)));
1855
1856      /* Mark the memory for the aggregate as write-only.  */
1857      if (flag_check_memory_usage)
1858        emit_library_call (chkr_set_right_libfunc, 1,
1859                           VOIDmode, 3,
1860                           structure_value_addr, ptr_mode,
1861                           GEN_INT (struct_value_size), TYPE_MODE (sizetype),
1862                           GEN_INT (MEMORY_USE_WO),
1863                           TYPE_MODE (integer_type_node));
1864
1865      if (GET_CODE (struct_value_rtx) == REG)
1866          use_reg (&call_fusage, struct_value_rtx);
1867    }
1868
1869  funexp = prepare_call_address (funexp, fndecl, &call_fusage, reg_parm_seen);
1870
1871  /* Now do the register loads required for any wholly-register parms or any
1872     parms which are passed both on the stack and in a register.  Their
1873     expressions were already evaluated.
1874
1875     Mark all register-parms as living through the call, putting these USE
1876     insns in the CALL_INSN_FUNCTION_USAGE field.  */
1877
1878  for (i = 0; i < num_actuals; i++)
1879    {
1880      rtx reg = args[i].reg;
1881      int partial = args[i].partial;
1882      int nregs;
1883
1884      if (reg)
1885        {
1886          /* Set to non-negative if must move a word at a time, even if just
1887             one word (e.g, partial == 1 && mode == DFmode).  Set to -1 if
1888             we just use a normal move insn.  This value can be zero if the
1889             argument is a zero size structure with no fields.  */
1890          nregs = (partial ? partial
1891                   : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1892                      ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1893                          + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1894                      : -1));
1895
1896          /* Handle calls that pass values in multiple non-contiguous
1897             locations.  The Irix 6 ABI has examples of this.  */
1898
1899          if (GET_CODE (reg) == PARALLEL)
1900            emit_group_load (reg, args[i].value);
1901
1902          /* If simple case, just do move.  If normal partial, store_one_arg
1903             has already loaded the register for us.  In all other cases,
1904             load the register(s) from memory.  */
1905
1906          else if (nregs == -1)
1907            emit_move_insn (reg, args[i].value);
1908
1909          /* If we have pre-computed the values to put in the registers in
1910             the case of non-aligned structures, copy them in now.  */
1911
1912          else if (args[i].n_aligned_regs != 0)
1913            for (j = 0; j < args[i].n_aligned_regs; j++)
1914              emit_move_insn (gen_rtx (REG, word_mode, REGNO (reg) + j),
1915                              args[i].aligned_regs[j]);
1916
1917          else if (partial == 0 || args[i].pass_on_stack)
1918            move_block_to_reg (REGNO (reg),
1919                               validize_mem (args[i].value), nregs,
1920                               args[i].mode);
1921
1922          /* Handle calls that pass values in multiple non-contiguous
1923             locations.  The Irix 6 ABI has examples of this.  */
1924          if (GET_CODE (reg) == PARALLEL)
1925            use_group_regs (&call_fusage, reg);
1926          else if (nregs == -1)
1927            use_reg (&call_fusage, reg);
1928          else
1929            use_regs (&call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1930        }
1931    }
1932
1933  /* Perform postincrements before actually calling the function.  */
1934  emit_queue ();
1935
1936  /* All arguments and registers used for the call must be set up by now!  */
1937
1938  /* Generate the actual call instruction.  */
1939  emit_call_1 (funexp, fndecl, funtype, args_size.constant, struct_value_size,
1940               FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
1941               valreg, old_inhibit_defer_pop, call_fusage, is_const);
1942
1943  /* If call is cse'able, make appropriate pair of reg-notes around it.
1944     Test valreg so we don't crash; may safely ignore `const'
1945     if return type is void.  Disable for PARALLEL return values, because
1946     we have no way to move such values into a pseudo register.  */
1947  if (is_const && valreg != 0 && GET_CODE (valreg) != PARALLEL)
1948    {
1949      rtx note = 0;
1950      rtx temp = gen_reg_rtx (GET_MODE (valreg));
1951      rtx insns;
1952
1953      /* Construct an "equal form" for the value which mentions all the
1954         arguments in order as well as the function name.  */
1955#ifdef PUSH_ARGS_REVERSED
1956      for (i = 0; i < num_actuals; i++)
1957        note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1958#else
1959      for (i = num_actuals - 1; i >= 0; i--)
1960        note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1961#endif
1962      note = gen_rtx (EXPR_LIST, VOIDmode, funexp, note);
1963
1964      insns = get_insns ();
1965      end_sequence ();
1966
1967      emit_libcall_block (insns, temp, valreg, note);
1968
1969      valreg = temp;
1970    }
1971  else if (is_const)
1972    {
1973      /* Otherwise, just write out the sequence without a note.  */
1974      rtx insns = get_insns ();
1975
1976      end_sequence ();
1977      emit_insns (insns);
1978    }
1979
1980  /* For calls to `setjmp', etc., inform flow.c it should complain
1981     if nonvolatile values are live.  */
1982
1983  if (returns_twice)
1984    {
1985      emit_note (name, NOTE_INSN_SETJMP);
1986      current_function_calls_setjmp = 1;
1987    }
1988
1989  if (is_longjmp)
1990    current_function_calls_longjmp = 1;
1991
1992  /* Notice functions that cannot return.
1993     If optimizing, insns emitted below will be dead.
1994     If not optimizing, they will exist, which is useful
1995     if the user uses the `return' command in the debugger.  */
1996
1997  if (is_volatile || is_longjmp)
1998    emit_barrier ();
1999
2000  /* If value type not void, return an rtx for the value.  */
2001
2002  /* If there are cleanups to be called, don't use a hard reg as target.
2003     We need to double check this and see if it matters anymore.  */
2004  if (any_pending_cleanups (1)
2005      && target && REG_P (target)
2006      && REGNO (target) < FIRST_PSEUDO_REGISTER)
2007    target = 0;
2008
2009  if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
2010      || ignore)
2011    {
2012      target = const0_rtx;
2013    }
2014  else if (structure_value_addr)
2015    {
2016      if (target == 0 || GET_CODE (target) != MEM)
2017        {
2018          target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
2019                            memory_address (TYPE_MODE (TREE_TYPE (exp)),
2020                                            structure_value_addr));
2021          MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2022        }
2023    }
2024  else if (pcc_struct_value)
2025    {
2026      if (target == 0)
2027        {
2028          /* We used leave the value in the location that it is
2029             returned in, but that causes problems if it is used more
2030             than once in one expression.  Rather than trying to track
2031             when a copy is required, we always copy when TARGET is
2032             not specified.  This calling sequence is only used on
2033             a few machines and TARGET is usually nonzero.  */
2034          if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2035            {
2036              target = assign_stack_temp (BLKmode,
2037                                          int_size_in_bytes (TREE_TYPE (exp)),
2038                                          0);
2039
2040              MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2041
2042              /* Save this temp slot around the pop below.  */
2043              preserve_temp_slots (target);
2044            }
2045          else
2046            target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
2047        }
2048
2049      if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
2050        emit_move_insn (target, gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
2051                                         copy_to_reg (valreg)));
2052      else
2053        emit_block_move (target, gen_rtx (MEM, BLKmode, copy_to_reg (valreg)),
2054                         expr_size (exp),
2055                         TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
2056    }
2057  /* Handle calls that return values in multiple non-contiguous locations.
2058     The Irix 6 ABI has examples of this.  */
2059  else if (GET_CODE (valreg) == PARALLEL)
2060    {
2061      if (target == 0)
2062        {
2063          int bytes = int_size_in_bytes (TREE_TYPE (exp));
2064          target = assign_stack_temp (TYPE_MODE (TREE_TYPE (exp)), bytes, 0);
2065          MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2066          preserve_temp_slots (target);
2067        }
2068
2069      emit_group_store (target, valreg);
2070    }
2071  else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2072           && GET_MODE (target) == GET_MODE (valreg))
2073    /* TARGET and VALREG cannot be equal at this point because the latter
2074       would not have REG_FUNCTION_VALUE_P true, while the former would if
2075       it were referring to the same register.
2076
2077       If they refer to the same register, this move will be a no-op, except
2078       when function inlining is being done.  */
2079    emit_move_insn (target, valreg);
2080  else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2081    {
2082      /* Some machines (the PA for example) want to return all small
2083         structures in registers regardless of the structure's alignment.
2084         
2085         Deal with them explicitly by copying from the return registers
2086         into the target MEM locations.  */
2087      int bytes = int_size_in_bytes (TREE_TYPE (exp));
2088      int n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2089      int i;
2090      enum machine_mode tmpmode;
2091      rtx src, dst;
2092      int bitsize = MIN (TYPE_ALIGN (TREE_TYPE (exp)), BITS_PER_WORD);
2093      int bitpos, xbitpos, big_endian_correction = 0;
2094     
2095      if (target == 0)
2096        {
2097          target = assign_stack_temp (BLKmode, bytes, 0);
2098          MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2099          preserve_temp_slots (target);
2100        }
2101
2102      /* This code assumes valreg is at least a full word.  If it isn't,
2103         copy it into a new pseudo which is a full word.  */
2104      if (GET_MODE (valreg) != BLKmode
2105          && GET_MODE_SIZE (GET_MODE (valreg)) < UNITS_PER_WORD)
2106        valreg = convert_to_mode (word_mode, valreg,
2107                                  TREE_UNSIGNED (TREE_TYPE (exp)));
2108
2109      /* Structures whose size is not a multiple of a word are aligned
2110         to the least significant byte (to the right).  On a BYTES_BIG_ENDIAN
2111         machine, this means we must skip the empty high order bytes when
2112         calculating the bit offset.  */
2113      if (BYTES_BIG_ENDIAN && bytes % UNITS_PER_WORD)
2114        big_endian_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2115                                                  * BITS_PER_UNIT));
2116
2117      /* Copy the structure BITSIZE bites at a time.
2118
2119         We could probably emit more efficient code for machines
2120         which do not use strict alignment, but it doesn't seem
2121         worth the effort at the current time.  */
2122      for (bitpos = 0, xbitpos = big_endian_correction;
2123           bitpos < bytes * BITS_PER_UNIT;
2124           bitpos += bitsize, xbitpos += bitsize)
2125        {
2126
2127          /* We need a new source operand each time xbitpos is on a
2128             word boundary and when xbitpos == big_endian_correction
2129             (the first time through).  */
2130          if (xbitpos % BITS_PER_WORD == 0
2131              || xbitpos == big_endian_correction)
2132            src = operand_subword_force (valreg,
2133                                         xbitpos / BITS_PER_WORD,
2134                                         BLKmode);
2135
2136          /* We need a new destination operand each time bitpos is on
2137             a word boundary.  */
2138          if (bitpos % BITS_PER_WORD == 0)
2139            dst = operand_subword (target, bitpos / BITS_PER_WORD, 1, BLKmode);
2140             
2141          /* Use xbitpos for the source extraction (right justified) and
2142             xbitpos for the destination store (left justified).  */
2143          store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, word_mode,
2144                           extract_bit_field (src, bitsize,
2145                                              xbitpos % BITS_PER_WORD, 1,
2146                                              NULL_RTX, word_mode,
2147                                              word_mode,
2148                                              bitsize / BITS_PER_UNIT,
2149                                              BITS_PER_WORD),
2150                           bitsize / BITS_PER_UNIT, BITS_PER_WORD);
2151        }
2152    }
2153  else
2154    target = copy_to_reg (valreg);
2155
2156#ifdef PROMOTE_FUNCTION_RETURN
2157  /* If we promoted this return value, make the proper SUBREG.  TARGET
2158     might be const0_rtx here, so be careful.  */
2159  if (GET_CODE (target) == REG
2160      && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
2161      && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
2162    {
2163      tree type = TREE_TYPE (exp);
2164      int unsignedp = TREE_UNSIGNED (type);
2165
2166      /* If we don't promote as expected, something is wrong.  */
2167      if (GET_MODE (target)
2168          != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
2169        abort ();
2170
2171      target = gen_rtx (SUBREG, TYPE_MODE (type), target, 0);
2172      SUBREG_PROMOTED_VAR_P (target) = 1;
2173      SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
2174    }
2175#endif
2176
2177  /* If size of args is variable or this was a constructor call for a stack
2178     argument, restore saved stack-pointer value.  */
2179
2180  if (old_stack_level)
2181    {
2182      emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
2183      pending_stack_adjust = old_pending_adj;
2184#ifdef ACCUMULATE_OUTGOING_ARGS
2185      stack_arg_under_construction = old_stack_arg_under_construction;
2186      highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2187      stack_usage_map = initial_stack_usage_map;
2188#endif
2189    }
2190#ifdef ACCUMULATE_OUTGOING_ARGS
2191  else
2192    {
2193#ifdef REG_PARM_STACK_SPACE
2194      if (save_area)
2195        {
2196          enum machine_mode save_mode = GET_MODE (save_area);
2197          rtx stack_area
2198            = gen_rtx (MEM, save_mode,
2199                       memory_address (save_mode,
2200#ifdef ARGS_GROW_DOWNWARD
2201                                       plus_constant (argblock, - high_to_save)
2202#else
2203                                       plus_constant (argblock, low_to_save)
2204#endif
2205                                       ));
2206
2207          if (save_mode != BLKmode)
2208            emit_move_insn (stack_area, save_area);
2209          else
2210            emit_block_move (stack_area, validize_mem (save_area),
2211                             GEN_INT (high_to_save - low_to_save + 1),
2212                             PARM_BOUNDARY / BITS_PER_UNIT);
2213        }
2214#endif
2215         
2216      /* If we saved any argument areas, restore them.  */
2217      for (i = 0; i < num_actuals; i++)
2218        if (args[i].save_area)
2219          {
2220            enum machine_mode save_mode = GET_MODE (args[i].save_area);
2221            rtx stack_area
2222              = gen_rtx (MEM, save_mode,
2223                         memory_address (save_mode,
2224                                         XEXP (args[i].stack_slot, 0)));
2225
2226            if (save_mode != BLKmode)
2227              emit_move_insn (stack_area, args[i].save_area);
2228            else
2229              emit_block_move (stack_area, validize_mem (args[i].save_area),
2230                               GEN_INT (args[i].size.constant),
2231                               PARM_BOUNDARY / BITS_PER_UNIT);
2232          }
2233
2234      highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2235      stack_usage_map = initial_stack_usage_map;
2236    }
2237#endif
2238
2239  /* If this was alloca, record the new stack level for nonlocal gotos. 
2240     Check for the handler slots since we might not have a save area
2241     for non-local gotos.  */
2242
2243  if (may_be_alloca && nonlocal_goto_handler_slot != 0)
2244    emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
2245
2246  pop_temp_slots ();
2247
2248  return target;
2249}
2250
2251/* Output a library call to function FUN (a SYMBOL_REF rtx)
2252   (emitting the queue unless NO_QUEUE is nonzero),
2253   for a value of mode OUTMODE,
2254   with NARGS different arguments, passed as alternating rtx values
2255   and machine_modes to convert them to.
2256   The rtx values should have been passed through protect_from_queue already.
2257
2258   NO_QUEUE will be true if and only if the library call is a `const' call
2259   which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent
2260   to the variable is_const in expand_call.
2261
2262   NO_QUEUE must be true for const calls, because if it isn't, then
2263   any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes,
2264   and will be lost if the libcall sequence is optimized away.
2265
2266   NO_QUEUE must be false for non-const calls, because if it isn't, the
2267   call insn will have its CONST_CALL_P bit set, and it will be incorrectly
2268   optimized.  For instance, the instruction scheduler may incorrectly
2269   move memory references across the non-const call.  */
2270
2271void
2272emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
2273                          int nargs, ...))
2274{
2275#ifndef __STDC__
2276  rtx orgfun;
2277  int no_queue;
2278  enum machine_mode outmode;
2279  int nargs;
2280#endif
2281  va_list p;
2282  /* Total size in bytes of all the stack-parms scanned so far.  */
2283  struct args_size args_size;
2284  /* Size of arguments before any adjustments (such as rounding).  */
2285  struct args_size original_args_size;
2286  register int argnum;
2287  rtx fun;
2288  int inc;
2289  int count;
2290  rtx argblock = 0;
2291  CUMULATIVE_ARGS args_so_far;
2292  struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2293               struct args_size offset; struct args_size size; rtx save_area; };
2294  struct arg *argvec;
2295  int old_inhibit_defer_pop = inhibit_defer_pop;
2296  rtx call_fusage = 0;
2297  /* Size of the stack reserved for parameter registers.  */
2298  int reg_parm_stack_space = 0;
2299#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2300  /* Define the boundary of the register parm stack space that needs to be
2301     save, if any.  */
2302  int low_to_save = -1, high_to_save;
2303  rtx save_area = 0;            /* Place that it is saved */
2304#endif
2305
2306#ifdef ACCUMULATE_OUTGOING_ARGS
2307  int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2308  char *initial_stack_usage_map = stack_usage_map;
2309  int needed;
2310#endif
2311
2312#ifdef REG_PARM_STACK_SPACE
2313#ifdef MAYBE_REG_PARM_STACK_SPACE
2314  reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2315#else
2316  reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
2317#endif
2318#endif
2319
2320  VA_START (p, nargs);
2321
2322#ifndef __STDC__
2323  orgfun = va_arg (p, rtx);
2324  no_queue = va_arg (p, int);
2325  outmode = va_arg (p, enum machine_mode);
2326  nargs = va_arg (p, int);
2327#endif
2328
2329  fun = orgfun;
2330
2331  /* Copy all the libcall-arguments out of the varargs data
2332     and into a vector ARGVEC.
2333
2334     Compute how to pass each argument.  We only support a very small subset
2335     of the full argument passing conventions to limit complexity here since
2336     library functions shouldn't have many args.  */
2337
2338  argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
2339  bzero ((char *) argvec, nargs * sizeof (struct arg));
2340
2341
2342  INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
2343
2344  args_size.constant = 0;
2345  args_size.var = 0;
2346
2347  push_temp_slots ();
2348
2349  for (count = 0; count < nargs; count++)
2350    {
2351      rtx val = va_arg (p, rtx);
2352      enum machine_mode mode = va_arg (p, enum machine_mode);
2353
2354      /* We cannot convert the arg value to the mode the library wants here;
2355         must do it earlier where we know the signedness of the arg.  */
2356      if (mode == BLKmode
2357          || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2358        abort ();
2359
2360      /* On some machines, there's no way to pass a float to a library fcn.
2361         Pass it as a double instead.  */
2362#ifdef LIBGCC_NEEDS_DOUBLE
2363      if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2364        val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
2365#endif
2366
2367      /* There's no need to call protect_from_queue, because
2368         either emit_move_insn or emit_push_insn will do that.  */
2369
2370      /* Make sure it is a reasonable operand for a move or push insn.  */
2371      if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2372          && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2373        val = force_operand (val, NULL_RTX);
2374
2375#ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2376      if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2377        {
2378          /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2379             be viewed as just an efficiency improvement.  */
2380          rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2381          emit_move_insn (slot, val);
2382          val = force_operand (XEXP (slot, 0), NULL_RTX);
2383          mode = Pmode;
2384        }
2385#endif
2386
2387      argvec[count].value = val;
2388      argvec[count].mode = mode;
2389
2390      argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2391      if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
2392        abort ();
2393#ifdef FUNCTION_ARG_PARTIAL_NREGS
2394      argvec[count].partial
2395        = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2396#else
2397      argvec[count].partial = 0;
2398#endif
2399
2400      locate_and_pad_parm (mode, NULL_TREE,
2401                           argvec[count].reg && argvec[count].partial == 0,
2402                           NULL_TREE, &args_size, &argvec[count].offset,
2403                           &argvec[count].size);
2404
2405      if (argvec[count].size.var)
2406        abort ();
2407
2408#ifndef REG_PARM_STACK_SPACE
2409      if (argvec[count].partial)
2410        argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2411#endif
2412
2413      if (argvec[count].reg == 0 || argvec[count].partial != 0
2414#ifdef REG_PARM_STACK_SPACE
2415          || 1
2416#endif
2417          )
2418        args_size.constant += argvec[count].size.constant;
2419
2420      FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
2421    }
2422  va_end (p);
2423
2424#ifdef FINAL_REG_PARM_STACK_SPACE
2425  reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2426                                                     args_size.var);
2427#endif
2428     
2429  /* If this machine requires an external definition for library
2430     functions, write one out.  */
2431  assemble_external_libcall (fun);
2432
2433  original_args_size = args_size;
2434#ifdef STACK_BOUNDARY
2435  args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2436                         / STACK_BYTES) * STACK_BYTES);
2437#endif
2438
2439#ifdef REG_PARM_STACK_SPACE
2440  args_size.constant = MAX (args_size.constant,
2441                            reg_parm_stack_space);
2442#ifndef OUTGOING_REG_PARM_STACK_SPACE
2443  args_size.constant -= reg_parm_stack_space;
2444#endif
2445#endif
2446
2447  if (args_size.constant > current_function_outgoing_args_size)
2448    current_function_outgoing_args_size = args_size.constant;
2449
2450#ifdef ACCUMULATE_OUTGOING_ARGS
2451  /* Since the stack pointer will never be pushed, it is possible for
2452     the evaluation of a parm to clobber something we have already
2453     written to the stack.  Since most function calls on RISC machines
2454     do not use the stack, this is uncommon, but must work correctly.
2455
2456     Therefore, we save any area of the stack that was already written
2457     and that we are using.  Here we set up to do this by making a new
2458     stack usage map from the old one.
2459
2460     Another approach might be to try to reorder the argument
2461     evaluations to avoid this conflicting stack usage.  */
2462
2463  needed = args_size.constant;
2464#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2465  /* Since we will be writing into the entire argument area, the
2466     map must be allocated for its entire size, not just the part that
2467     is the responsibility of the caller.  */
2468  needed += reg_parm_stack_space;
2469#endif
2470
2471#ifdef ARGS_GROW_DOWNWARD
2472  highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2473                                     needed + 1);
2474#else
2475  highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2476                                     needed);
2477#endif
2478  stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
2479
2480  if (initial_highest_arg_in_use)
2481    bcopy (initial_stack_usage_map, stack_usage_map,
2482           initial_highest_arg_in_use);
2483
2484  if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2485    bzero (&stack_usage_map[initial_highest_arg_in_use],
2486           highest_outgoing_arg_in_use - initial_highest_arg_in_use);
2487  needed = 0;
2488
2489  /* The address of the outgoing argument list must not be copied to a
2490     register here, because argblock would be left pointing to the
2491     wrong place after the call to allocate_dynamic_stack_space below.
2492     */
2493
2494  argblock = virtual_outgoing_args_rtx;
2495#else /* not ACCUMULATE_OUTGOING_ARGS */
2496#ifndef PUSH_ROUNDING
2497  argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2498#endif
2499#endif
2500
2501#ifdef PUSH_ARGS_REVERSED
2502#ifdef STACK_BOUNDARY
2503  /* If we push args individually in reverse order, perform stack alignment
2504     before the first push (the last arg).  */
2505  if (argblock == 0)
2506    anti_adjust_stack (GEN_INT (args_size.constant
2507                                - original_args_size.constant));
2508#endif
2509#endif
2510
2511#ifdef PUSH_ARGS_REVERSED
2512  inc = -1;
2513  argnum = nargs - 1;
2514#else
2515  inc = 1;
2516  argnum = 0;
2517#endif
2518
2519#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2520  /* The argument list is the property of the called routine and it
2521     may clobber it.  If the fixed area has been used for previous
2522     parameters, we must save and restore it.
2523
2524     Here we compute the boundary of the that needs to be saved, if any.  */
2525
2526#ifdef ARGS_GROW_DOWNWARD
2527  for (count = 0; count < reg_parm_stack_space + 1; count++)
2528#else
2529  for (count = 0; count < reg_parm_stack_space; count++)
2530#endif
2531    {
2532      if (count >=  highest_outgoing_arg_in_use
2533          || stack_usage_map[count] == 0)
2534        continue;
2535
2536      if (low_to_save == -1)
2537        low_to_save = count;
2538
2539      high_to_save = count;
2540    }
2541
2542  if (low_to_save >= 0)
2543    {
2544      int num_to_save = high_to_save - low_to_save + 1;
2545      enum machine_mode save_mode
2546        = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
2547      rtx stack_area;
2548
2549      /* If we don't have the required alignment, must do this in BLKmode.  */
2550      if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
2551                               BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
2552        save_mode = BLKmode;
2553
2554      stack_area = gen_rtx (MEM, save_mode,
2555                            memory_address (save_mode,
2556                                           
2557#ifdef ARGS_GROW_DOWNWARD
2558                                            plus_constant (argblock,
2559                                                           - high_to_save)
2560#else
2561                                            plus_constant (argblock,
2562                                                           low_to_save)
2563#endif
2564                                            ));
2565      if (save_mode == BLKmode)
2566        {
2567          save_area = assign_stack_temp (BLKmode, num_to_save, 0);
2568          MEM_IN_STRUCT_P (save_area) = 0;
2569          emit_block_move (validize_mem (save_area), stack_area,
2570                           GEN_INT (num_to_save),
2571                           PARM_BOUNDARY / BITS_PER_UNIT);
2572        }
2573      else
2574        {
2575          save_area = gen_reg_rtx (save_mode);
2576          emit_move_insn (save_area, stack_area);
2577        }
2578    }
2579#endif
2580         
2581  /* Push the args that need to be pushed.  */
2582
2583  /* ARGNUM indexes the ARGVEC array in the order in which the arguments
2584     are to be pushed.  */
2585  for (count = 0; count < nargs; count++, argnum += inc)
2586    {
2587      register enum machine_mode mode = argvec[argnum].mode;
2588      register rtx val = argvec[argnum].value;
2589      rtx reg = argvec[argnum].reg;
2590      int partial = argvec[argnum].partial;
2591      int lower_bound, upper_bound, i;
2592
2593      if (! (reg != 0 && partial == 0))
2594        {
2595#ifdef ACCUMULATE_OUTGOING_ARGS
2596          /* If this is being stored into a pre-allocated, fixed-size, stack
2597             area, save any previous data at that location.  */
2598
2599#ifdef ARGS_GROW_DOWNWARD
2600          /* stack_slot is negative, but we want to index stack_usage_map
2601             with positive values.  */
2602          upper_bound = -argvec[argnum].offset.constant + 1;
2603          lower_bound = upper_bound - argvec[argnum].size.constant;
2604#else
2605          lower_bound = argvec[argnum].offset.constant;
2606          upper_bound = lower_bound + argvec[argnum].size.constant;
2607#endif
2608
2609          for (i = lower_bound; i < upper_bound; i++)
2610            if (stack_usage_map[i]
2611#ifdef REG_PARM_STACK_SPACE
2612                /* Don't store things in the fixed argument area at this point;
2613                   it has already been saved.  */
2614                && i > reg_parm_stack_space
2615#endif
2616                )
2617              break;
2618
2619          if (i != upper_bound)
2620            {
2621              /* We need to make a save area.  See what mode we can make it.  */
2622              enum machine_mode save_mode
2623                = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
2624                                 MODE_INT, 1);
2625              rtx stack_area
2626                = gen_rtx (MEM, save_mode,
2627                           memory_address (save_mode, plus_constant (argblock,
2628                                           argvec[argnum].offset.constant)));
2629              argvec[argnum].save_area = gen_reg_rtx (save_mode);
2630              emit_move_insn (argvec[argnum].save_area, stack_area);
2631            }
2632#endif
2633          emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
2634                          argblock, GEN_INT (argvec[argnum].offset.constant));
2635
2636#ifdef ACCUMULATE_OUTGOING_ARGS
2637          /* Now mark the segment we just used.  */
2638          for (i = lower_bound; i < upper_bound; i++)
2639            stack_usage_map[i] = 1;
2640#endif
2641
2642          NO_DEFER_POP;
2643        }
2644    }
2645
2646#ifndef PUSH_ARGS_REVERSED
2647#ifdef STACK_BOUNDARY
2648  /* If we pushed args in forward order, perform stack alignment
2649     after pushing the last arg.  */
2650  if (argblock == 0)
2651    anti_adjust_stack (GEN_INT (args_size.constant
2652                                - original_args_size.constant));
2653#endif
2654#endif
2655
2656#ifdef PUSH_ARGS_REVERSED
2657  argnum = nargs - 1;
2658#else
2659  argnum = 0;
2660#endif
2661
2662  fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
2663
2664  /* Now load any reg parms into their regs.  */
2665
2666  /* ARGNUM indexes the ARGVEC array in the order in which the arguments
2667     are to be pushed.  */
2668  for (count = 0; count < nargs; count++, argnum += inc)
2669    {
2670      register enum machine_mode mode = argvec[argnum].mode;
2671      register rtx val = argvec[argnum].value;
2672      rtx reg = argvec[argnum].reg;
2673      int partial = argvec[argnum].partial;
2674
2675      if (reg != 0 && partial == 0)
2676        emit_move_insn (reg, val);
2677      NO_DEFER_POP;
2678    }
2679
2680  /* For version 1.37, try deleting this entirely.  */
2681  if (! no_queue)
2682    emit_queue ();
2683
2684  /* Any regs containing parms remain in use through the call.  */
2685  for (count = 0; count < nargs; count++)
2686    if (argvec[count].reg != 0)
2687       use_reg (&call_fusage, argvec[count].reg);
2688
2689  /* Don't allow popping to be deferred, since then
2690     cse'ing of library calls could delete a call and leave the pop.  */
2691  NO_DEFER_POP;
2692
2693  /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
2694     will set inhibit_defer_pop to that value.  */
2695
2696  /* The return type is needed to decide how many bytes the function pops.
2697     Signedness plays no role in that, so for simplicity, we pretend it's
2698     always signed.  We also assume that the list of arguments passed has
2699     no impact, so we pretend it is unknown.  */
2700
2701  emit_call_1 (fun,
2702               get_identifier (XSTR (orgfun, 0)),
2703               build_function_type (outmode == VOIDmode ? void_type_node
2704                                    : type_for_mode (outmode, 0), NULL_TREE),
2705               args_size.constant, 0,
2706               FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2707               outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
2708               old_inhibit_defer_pop + 1, call_fusage, no_queue);
2709
2710  pop_temp_slots ();
2711
2712  /* Now restore inhibit_defer_pop to its actual original value.  */
2713  OK_DEFER_POP;
2714
2715#ifdef ACCUMULATE_OUTGOING_ARGS
2716#ifdef REG_PARM_STACK_SPACE
2717  if (save_area)
2718    {
2719      enum machine_mode save_mode = GET_MODE (save_area);
2720      rtx stack_area
2721        = gen_rtx (MEM, save_mode,
2722                   memory_address (save_mode,
2723#ifdef ARGS_GROW_DOWNWARD
2724                                   plus_constant (argblock, - high_to_save)
2725#else
2726                                   plus_constant (argblock, low_to_save)
2727#endif
2728                                   ));
2729
2730      if (save_mode != BLKmode)
2731        emit_move_insn (stack_area, save_area);
2732      else
2733        emit_block_move (stack_area, validize_mem (save_area),
2734                         GEN_INT (high_to_save - low_to_save + 1),
2735                         PARM_BOUNDARY / BITS_PER_UNIT);
2736    }
2737#endif
2738         
2739  /* If we saved any argument areas, restore them.  */
2740  for (count = 0; count < nargs; count++)
2741    if (argvec[count].save_area)
2742      {
2743        enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
2744        rtx stack_area
2745          = gen_rtx (MEM, save_mode,
2746                     memory_address (save_mode, plus_constant (argblock,
2747                                     argvec[count].offset.constant)));
2748
2749        emit_move_insn (stack_area, argvec[count].save_area);
2750      }
2751
2752  highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2753  stack_usage_map = initial_stack_usage_map;
2754#endif
2755}
2756
2757/* Like emit_library_call except that an extra argument, VALUE,
2758   comes second and says where to store the result.
2759   (If VALUE is zero, this function chooses a convenient way
2760   to return the value.
2761
2762   This function returns an rtx for where the value is to be found.
2763   If VALUE is nonzero, VALUE is returned.  */
2764
2765rtx
2766emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
2767                                enum machine_mode outmode, int nargs, ...))
2768{
2769#ifndef __STDC__
2770  rtx orgfun;
2771  rtx value;
2772  int no_queue;
2773  enum machine_mode outmode;
2774  int nargs;
2775#endif
2776  va_list p;
2777  /* Total size in bytes of all the stack-parms scanned so far.  */
2778  struct args_size args_size;
2779  /* Size of arguments before any adjustments (such as rounding).  */
2780  struct args_size original_args_size;
2781  register int argnum;
2782  rtx fun;
2783  int inc;
2784  int count;
2785  rtx argblock = 0;
2786  CUMULATIVE_ARGS args_so_far;
2787  struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2788               struct args_size offset; struct args_size size; rtx save_area; };
2789  struct arg *argvec;
2790  int old_inhibit_defer_pop = inhibit_defer_pop;
2791  rtx call_fusage = 0;
2792  /* Size of the stack reserved for parameter registers.  */
2793  int reg_parm_stack_space = 0;
2794  rtx mem_value = 0;
2795  int pcc_struct_value = 0;
2796  int struct_value_size = 0;
2797  int is_const;
2798  int needed;
2799
2800#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2801  /* Define the boundary of the register parm stack space that needs to be
2802     save, if any.  */
2803  int low_to_save = -1, high_to_save;
2804  rtx save_area = 0;            /* Place that it is saved */
2805#endif
2806
2807#ifdef ACCUMULATE_OUTGOING_ARGS
2808  int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2809  char *initial_stack_usage_map = stack_usage_map;
2810#endif
2811
2812#ifdef REG_PARM_STACK_SPACE
2813#ifdef MAYBE_REG_PARM_STACK_SPACE
2814  reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2815#else
2816  reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
2817#endif
2818#endif
2819
2820  VA_START (p, nargs);
2821
2822#ifndef __STDC__
2823  orgfun = va_arg (p, rtx);
2824  value = va_arg (p, rtx);
2825  no_queue = va_arg (p, int);
2826  outmode = va_arg (p, enum machine_mode);
2827  nargs = va_arg (p, int);
2828#endif
2829
2830  is_const = no_queue;
2831  fun = orgfun;
2832
2833  /* If this kind of value comes back in memory,
2834     decide where in memory it should come back.  */
2835  if (aggregate_value_p (type_for_mode (outmode, 0)))
2836    {
2837#ifdef PCC_STATIC_STRUCT_RETURN
2838      rtx pointer_reg
2839        = hard_function_value (build_pointer_type (type_for_mode (outmode, 0)),
2840                               0);
2841      mem_value = gen_rtx (MEM, outmode, pointer_reg);
2842      pcc_struct_value = 1;
2843      if (value == 0)
2844        value = gen_reg_rtx (outmode);
2845#else /* not PCC_STATIC_STRUCT_RETURN */
2846      struct_value_size = GET_MODE_SIZE (outmode);
2847      if (value != 0 && GET_CODE (value) == MEM)
2848        mem_value = value;
2849      else
2850        mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
2851#endif
2852
2853      /* This call returns a big structure.  */
2854      is_const = 0;
2855    }
2856
2857  /* ??? Unfinished: must pass the memory address as an argument.  */
2858
2859  /* Copy all the libcall-arguments out of the varargs data
2860     and into a vector ARGVEC.
2861
2862     Compute how to pass each argument.  We only support a very small subset
2863     of the full argument passing conventions to limit complexity here since
2864     library functions shouldn't have many args.  */
2865
2866  argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
2867  bzero ((char *) argvec, (nargs + 1) * sizeof (struct arg));
2868
2869  INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
2870
2871  args_size.constant = 0;
2872  args_size.var = 0;
2873
2874  count = 0;
2875
2876  push_temp_slots ();
2877
2878  /* If there's a structure value address to be passed,
2879     either pass it in the special place, or pass it as an extra argument.  */
2880  if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
2881    {
2882      rtx addr = XEXP (mem_value, 0);
2883      nargs++;
2884
2885      /* Make sure it is a reasonable operand for a move or push insn.  */
2886      if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
2887          && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
2888        addr = force_operand (addr, NULL_RTX);
2889
2890      argvec[count].value = addr;
2891      argvec[count].mode = Pmode;
2892      argvec[count].partial = 0;
2893
2894      argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
2895#ifdef FUNCTION_ARG_PARTIAL_NREGS
2896      if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
2897        abort ();
2898#endif
2899
2900      locate_and_pad_parm (Pmode, NULL_TREE,
2901                           argvec[count].reg && argvec[count].partial == 0,
2902                           NULL_TREE, &args_size, &argvec[count].offset,
2903                           &argvec[count].size);
2904
2905
2906      if (argvec[count].reg == 0 || argvec[count].partial != 0
2907#ifdef REG_PARM_STACK_SPACE
2908          || 1
2909#endif
2910          )
2911        args_size.constant += argvec[count].size.constant;
2912
2913      FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
2914
2915      count++;
2916    }
2917
2918  for (; count < nargs; count++)
2919    {
2920      rtx val = va_arg (p, rtx);
2921      enum machine_mode mode = va_arg (p, enum machine_mode);
2922
2923      /* We cannot convert the arg value to the mode the library wants here;
2924         must do it earlier where we know the signedness of the arg.  */
2925      if (mode == BLKmode
2926          || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2927        abort ();
2928
2929      /* On some machines, there's no way to pass a float to a library fcn.
2930         Pass it as a double instead.  */
2931#ifdef LIBGCC_NEEDS_DOUBLE
2932      if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2933        val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
2934#endif
2935
2936      /* There's no need to call protect_from_queue, because
2937         either emit_move_insn or emit_push_insn will do that.  */
2938
2939      /* Make sure it is a reasonable operand for a move or push insn.  */
2940      if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2941          && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2942        val = force_operand (val, NULL_RTX);
2943
2944#ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2945      if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2946        {
2947          /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2948             be viewed as just an efficiency improvement.  */
2949          rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2950          emit_move_insn (slot, val);
2951          val = XEXP (slot, 0);
2952          mode = Pmode;
2953        }
2954#endif
2955
2956      argvec[count].value = val;
2957      argvec[count].mode = mode;
2958
2959      argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2960      if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
2961        abort ();
2962#ifdef FUNCTION_ARG_PARTIAL_NREGS
2963      argvec[count].partial
2964        = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2965#else
2966      argvec[count].partial = 0;
2967#endif
2968
2969      locate_and_pad_parm (mode, NULL_TREE,
2970                           argvec[count].reg && argvec[count].partial == 0,
2971                           NULL_TREE, &args_size, &argvec[count].offset,
2972                           &argvec[count].size);
2973
2974      if (argvec[count].size.var)
2975        abort ();
2976
2977#ifndef REG_PARM_STACK_SPACE
2978      if (argvec[count].partial)
2979        argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2980#endif
2981
2982      if (argvec[count].reg == 0 || argvec[count].partial != 0
2983#ifdef REG_PARM_STACK_SPACE
2984          || 1
2985#endif
2986          )
2987        args_size.constant += argvec[count].size.constant;
2988
2989      FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
2990    }
2991  va_end (p);
2992
2993#ifdef FINAL_REG_PARM_STACK_SPACE
2994  reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2995                                                     args_size.var);
2996#endif
2997  /* If this machine requires an external definition for library
2998     functions, write one out.  */
2999  assemble_external_libcall (fun);
3000
3001  original_args_size = args_size;
3002#ifdef STACK_BOUNDARY
3003  args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
3004                         / STACK_BYTES) * STACK_BYTES);
3005#endif
3006
3007#ifdef REG_PARM_STACK_SPACE
3008  args_size.constant = MAX (args_size.constant,
3009                            reg_parm_stack_space);
3010#ifndef OUTGOING_REG_PARM_STACK_SPACE
3011  args_size.constant -= reg_parm_stack_space;
3012#endif
3013#endif
3014
3015  if (args_size.constant > current_function_outgoing_args_size)
3016    current_function_outgoing_args_size = args_size.constant;
3017
3018#ifdef ACCUMULATE_OUTGOING_ARGS
3019  /* Since the stack pointer will never be pushed, it is possible for
3020     the evaluation of a parm to clobber something we have already
3021     written to the stack.  Since most function calls on RISC machines
3022     do not use the stack, this is uncommon, but must work correctly.
3023
3024     Therefore, we save any area of the stack that was already written
3025     and that we are using.  Here we set up to do this by making a new
3026     stack usage map from the old one.
3027
3028     Another approach might be to try to reorder the argument
3029     evaluations to avoid this conflicting stack usage.  */
3030
3031  needed = args_size.constant;
3032#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
3033  /* Since we will be writing into the entire argument area, the
3034     map must be allocated for its entire size, not just the part that
3035     is the responsibility of the caller.  */
3036  needed += reg_parm_stack_space;
3037#endif
3038
3039#ifdef ARGS_GROW_DOWNWARD
3040  highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3041                                     needed + 1);
3042#else
3043  highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3044                                     needed);
3045#endif
3046  stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3047
3048  if (initial_highest_arg_in_use)
3049    bcopy (initial_stack_usage_map, stack_usage_map,
3050           initial_highest_arg_in_use);
3051
3052  if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3053    bzero (&stack_usage_map[initial_highest_arg_in_use],
3054           highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3055  needed = 0;
3056
3057  /* The address of the outgoing argument list must not be copied to a
3058     register here, because argblock would be left pointing to the
3059     wrong place after the call to allocate_dynamic_stack_space below.
3060     */
3061
3062  argblock = virtual_outgoing_args_rtx;
3063#else /* not ACCUMULATE_OUTGOING_ARGS */
3064#ifndef PUSH_ROUNDING
3065  argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3066#endif
3067#endif
3068
3069#ifdef PUSH_ARGS_REVERSED
3070#ifdef STACK_BOUNDARY
3071  /* If we push args individually in reverse order, perform stack alignment
3072     before the first push (the last arg).  */
3073  if (argblock == 0)
3074    anti_adjust_stack (GEN_INT (args_size.constant
3075                                - original_args_size.constant));
3076#endif
3077#endif
3078
3079#ifdef PUSH_ARGS_REVERSED
3080  inc = -1;
3081  argnum = nargs - 1;
3082#else
3083  inc = 1;
3084  argnum = 0;
3085#endif
3086
3087#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3088  /* The argument list is the property of the called routine and it
3089     may clobber it.  If the fixed area has been used for previous
3090     parameters, we must save and restore it.
3091
3092     Here we compute the boundary of the that needs to be saved, if any.  */
3093
3094#ifdef ARGS_GROW_DOWNWARD
3095  for (count = 0; count < reg_parm_stack_space + 1; count++)
3096#else
3097  for (count = 0; count < reg_parm_stack_space; count++)
3098#endif
3099    {
3100      if (count >=  highest_outgoing_arg_in_use
3101          || stack_usage_map[count] == 0)
3102        continue;
3103
3104      if (low_to_save == -1)
3105        low_to_save = count;
3106
3107      high_to_save = count;
3108    }
3109
3110  if (low_to_save >= 0)
3111    {
3112      int num_to_save = high_to_save - low_to_save + 1;
3113      enum machine_mode save_mode
3114        = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
3115      rtx stack_area;
3116
3117      /* If we don't have the required alignment, must do this in BLKmode.  */
3118      if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
3119                               BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
3120        save_mode = BLKmode;
3121
3122      stack_area = gen_rtx (MEM, save_mode,
3123                            memory_address (save_mode,
3124                                           
3125#ifdef ARGS_GROW_DOWNWARD
3126                                            plus_constant (argblock,
3127                                                           - high_to_save)
3128#else
3129                                            plus_constant (argblock,
3130                                                           low_to_save)
3131#endif
3132                                            ));
3133      if (save_mode == BLKmode)
3134        {
3135          save_area = assign_stack_temp (BLKmode, num_to_save, 0);
3136          MEM_IN_STRUCT_P (save_area) = 0;
3137          emit_block_move (validize_mem (save_area), stack_area,
3138                           GEN_INT (num_to_save),
3139                           PARM_BOUNDARY / BITS_PER_UNIT);
3140        }
3141      else
3142        {
3143          save_area = gen_reg_rtx (save_mode);
3144          emit_move_insn (save_area, stack_area);
3145        }
3146    }
3147#endif
3148         
3149  /* Push the args that need to be pushed.  */
3150
3151  /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3152     are to be pushed.  */
3153  for (count = 0; count < nargs; count++, argnum += inc)
3154    {
3155      register enum machine_mode mode = argvec[argnum].mode;
3156      register rtx val = argvec[argnum].value;
3157      rtx reg = argvec[argnum].reg;
3158      int partial = argvec[argnum].partial;
3159      int lower_bound, upper_bound, i;
3160
3161      if (! (reg != 0 && partial == 0))
3162        {
3163#ifdef ACCUMULATE_OUTGOING_ARGS
3164          /* If this is being stored into a pre-allocated, fixed-size, stack
3165             area, save any previous data at that location.  */
3166
3167#ifdef ARGS_GROW_DOWNWARD
3168          /* stack_slot is negative, but we want to index stack_usage_map
3169             with positive values.  */
3170          upper_bound = -argvec[argnum].offset.constant + 1;
3171          lower_bound = upper_bound - argvec[argnum].size.constant;
3172#else
3173          lower_bound = argvec[argnum].offset.constant;
3174          upper_bound = lower_bound + argvec[argnum].size.constant;
3175#endif
3176
3177          for (i = lower_bound; i < upper_bound; i++)
3178            if (stack_usage_map[i]
3179#ifdef REG_PARM_STACK_SPACE
3180                /* Don't store things in the fixed argument area at this point;
3181                   it has already been saved.  */
3182                && i > reg_parm_stack_space
3183#endif
3184                )
3185              break;
3186
3187          if (i != upper_bound)
3188            {
3189              /* We need to make a save area.  See what mode we can make it.  */
3190              enum machine_mode save_mode
3191                = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
3192                                 MODE_INT, 1);
3193              rtx stack_area
3194                = gen_rtx (MEM, save_mode,
3195                           memory_address (save_mode, plus_constant (argblock,
3196                                           argvec[argnum].offset.constant)));
3197              argvec[argnum].save_area = gen_reg_rtx (save_mode);
3198              emit_move_insn (argvec[argnum].save_area, stack_area);
3199            }
3200#endif
3201          emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
3202                          argblock, GEN_INT (argvec[argnum].offset.constant));
3203
3204#ifdef ACCUMULATE_OUTGOING_ARGS
3205          /* Now mark the segment we just used.  */
3206          for (i = lower_bound; i < upper_bound; i++)
3207            stack_usage_map[i] = 1;
3208#endif
3209
3210          NO_DEFER_POP;
3211        }
3212    }
3213
3214#ifndef PUSH_ARGS_REVERSED
3215#ifdef STACK_BOUNDARY
3216  /* If we pushed args in forward order, perform stack alignment
3217     after pushing the last arg.  */
3218  if (argblock == 0)
3219    anti_adjust_stack (GEN_INT (args_size.constant
3220                                - original_args_size.constant));
3221#endif
3222#endif
3223
3224#ifdef PUSH_ARGS_REVERSED
3225  argnum = nargs - 1;
3226#else
3227  argnum = 0;
3228#endif
3229
3230  fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
3231
3232  /* Now load any reg parms into their regs.  */
3233
3234  /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3235     are to be pushed.  */
3236  for (count = 0; count < nargs; count++, argnum += inc)
3237    {
3238      register enum machine_mode mode = argvec[argnum].mode;
3239      register rtx val = argvec[argnum].value;
3240      rtx reg = argvec[argnum].reg;
3241      int partial = argvec[argnum].partial;
3242
3243      if (reg != 0 && partial == 0)
3244        emit_move_insn (reg, val);
3245      NO_DEFER_POP;
3246    }
3247
3248#if 0
3249  /* For version 1.37, try deleting this entirely.  */
3250  if (! no_queue)
3251    emit_queue ();
3252#endif
3253
3254  /* Any regs containing parms remain in use through the call.  */
3255  for (count = 0; count < nargs; count++)
3256    if (argvec[count].reg != 0)
3257       use_reg (&call_fusage, argvec[count].reg);
3258
3259  /* Pass the function the address in which to return a structure value.  */
3260  if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
3261    {
3262      emit_move_insn (struct_value_rtx,
3263                      force_reg (Pmode,
3264                                 force_operand (XEXP (mem_value, 0),
3265                                                NULL_RTX)));
3266      if (GET_CODE (struct_value_rtx) == REG)
3267          use_reg (&call_fusage, struct_value_rtx);
3268    }
3269
3270  /* Don't allow popping to be deferred, since then
3271     cse'ing of library calls could delete a call and leave the pop.  */
3272  NO_DEFER_POP;
3273
3274  /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3275     will set inhibit_defer_pop to that value.  */
3276  /* See the comment in emit_library_call about the function type we build
3277     and pass here.  */
3278
3279  emit_call_1 (fun,
3280               get_identifier (XSTR (orgfun, 0)),
3281               build_function_type (type_for_mode (outmode, 0), NULL_TREE),
3282               args_size.constant, struct_value_size,
3283               FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3284               mem_value == 0 ? hard_libcall_value (outmode) : NULL_RTX,
3285               old_inhibit_defer_pop + 1, call_fusage, is_const);
3286
3287  /* Now restore inhibit_defer_pop to its actual original value.  */
3288  OK_DEFER_POP;
3289
3290  pop_temp_slots ();
3291
3292  /* Copy the value to the right place.  */
3293  if (outmode != VOIDmode)
3294    {
3295      if (mem_value)
3296        {
3297          if (value == 0)
3298            value = mem_value;
3299          if (value != mem_value)
3300            emit_move_insn (value, mem_value);
3301        }
3302      else if (value != 0)
3303        emit_move_insn (value, hard_libcall_value (outmode));
3304      else
3305        value = hard_libcall_value (outmode);
3306    }
3307
3308#ifdef ACCUMULATE_OUTGOING_ARGS
3309#ifdef REG_PARM_STACK_SPACE
3310  if (save_area)
3311    {
3312      enum machine_mode save_mode = GET_MODE (save_area);
3313      rtx stack_area
3314        = gen_rtx (MEM, save_mode,
3315                   memory_address (save_mode,
3316#ifdef ARGS_GROW_DOWNWARD
3317                                   plus_constant (argblock, - high_to_save)
3318#else
3319                                   plus_constant (argblock, low_to_save)
3320#endif
3321                                   ));
3322
3323      if (save_mode != BLKmode)
3324        emit_move_insn (stack_area, save_area);
3325      else
3326        emit_block_move (stack_area, validize_mem (save_area),
3327                         GEN_INT (high_to_save - low_to_save + 1),
3328                             PARM_BOUNDARY / BITS_PER_UNIT);
3329    }
3330#endif
3331         
3332  /* If we saved any argument areas, restore them.  */
3333  for (count = 0; count < nargs; count++)
3334    if (argvec[count].save_area)
3335      {
3336        enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3337        rtx stack_area
3338          = gen_rtx (MEM, save_mode,
3339                     memory_address (save_mode, plus_constant (argblock,
3340                                     argvec[count].offset.constant)));
3341
3342        emit_move_insn (stack_area, argvec[count].save_area);
3343      }
3344
3345  highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3346  stack_usage_map = initial_stack_usage_map;
3347#endif
3348
3349  return value;
3350}
3351
3352#if 0
3353/* Return an rtx which represents a suitable home on the stack
3354   given TYPE, the type of the argument looking for a home.
3355   This is called only for BLKmode arguments.
3356
3357   SIZE is the size needed for this target.
3358   ARGS_ADDR is the address of the bottom of the argument block for this call.
3359   OFFSET describes this parameter's offset into ARGS_ADDR.  It is meaningless
3360   if this machine uses push insns.  */
3361
3362static rtx
3363target_for_arg (type, size, args_addr, offset)
3364     tree type;
3365     rtx size;
3366     rtx args_addr;
3367     struct args_size offset;
3368{
3369  rtx target;
3370  rtx offset_rtx = ARGS_SIZE_RTX (offset);
3371
3372  /* We do not call memory_address if possible,
3373     because we want to address as close to the stack
3374     as possible.  For non-variable sized arguments,
3375     this will be stack-pointer relative addressing.  */
3376  if (GET_CODE (offset_rtx) == CONST_INT)
3377    target = plus_constant (args_addr, INTVAL (offset_rtx));
3378  else
3379    {
3380      /* I have no idea how to guarantee that this
3381         will work in the presence of register parameters.  */
3382      target = gen_rtx (PLUS, Pmode, args_addr, offset_rtx);
3383      target = memory_address (QImode, target);
3384    }
3385
3386  return gen_rtx (MEM, BLKmode, target);
3387}
3388#endif
3389
3390/* Store a single argument for a function call
3391   into the register or memory area where it must be passed.
3392   *ARG describes the argument value and where to pass it.
3393
3394   ARGBLOCK is the address of the stack-block for all the arguments,
3395   or 0 on a machine where arguments are pushed individually.
3396
3397   MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
3398   so must be careful about how the stack is used.
3399
3400   VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
3401   argument stack.  This is used if ACCUMULATE_OUTGOING_ARGS to indicate
3402   that we need not worry about saving and restoring the stack.
3403
3404   FNDECL is the declaration of the function we are calling.  */
3405
3406static void
3407store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl,
3408               reg_parm_stack_space)
3409     struct arg_data *arg;
3410     rtx argblock;
3411     int may_be_alloca;
3412     int variable_size;
3413     tree fndecl;
3414     int reg_parm_stack_space;
3415{
3416  register tree pval = arg->tree_value;
3417  rtx reg = 0;
3418  int partial = 0;
3419  int used = 0;
3420  int i, lower_bound, upper_bound;
3421
3422  if (TREE_CODE (pval) == ERROR_MARK)
3423    return;
3424
3425  /* Push a new temporary level for any temporaries we make for
3426     this argument.  */
3427  push_temp_slots ();
3428
3429#ifdef ACCUMULATE_OUTGOING_ARGS
3430  /* If this is being stored into a pre-allocated, fixed-size, stack area,
3431     save any previous data at that location.  */
3432  if (argblock && ! variable_size && arg->stack)
3433    {
3434#ifdef ARGS_GROW_DOWNWARD
3435      /* stack_slot is negative, but we want to index stack_usage_map
3436         with positive values.  */
3437      if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3438        upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
3439      else
3440        upper_bound = 0;
3441
3442      lower_bound = upper_bound - arg->size.constant;
3443#else
3444      if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3445        lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
3446      else
3447        lower_bound = 0;
3448
3449      upper_bound = lower_bound + arg->size.constant;
3450#endif
3451
3452      for (i = lower_bound; i < upper_bound; i++)
3453        if (stack_usage_map[i]
3454#ifdef REG_PARM_STACK_SPACE
3455            /* Don't store things in the fixed argument area at this point;
3456               it has already been saved.  */
3457            && i > reg_parm_stack_space
3458#endif
3459            )
3460          break;
3461
3462      if (i != upper_bound)
3463        {
3464          /* We need to make a save area.  See what mode we can make it.  */
3465          enum machine_mode save_mode
3466            = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
3467          rtx stack_area
3468            = gen_rtx (MEM, save_mode,
3469                       memory_address (save_mode, XEXP (arg->stack_slot, 0)));
3470
3471          if (save_mode == BLKmode)
3472            {
3473              arg->save_area = assign_stack_temp (BLKmode,
3474                                                  arg->size.constant, 0);
3475              MEM_IN_STRUCT_P (arg->save_area)
3476                = AGGREGATE_TYPE_P (TREE_TYPE (arg->tree_value));
3477              preserve_temp_slots (arg->save_area);
3478              emit_block_move (validize_mem (arg->save_area), stack_area,
3479                               GEN_INT (arg->size.constant),
3480                               PARM_BOUNDARY / BITS_PER_UNIT);
3481            }
3482          else
3483            {
3484              arg->save_area = gen_reg_rtx (save_mode);
3485              emit_move_insn (arg->save_area, stack_area);
3486            }
3487        }
3488    }
3489#endif
3490
3491  /* If this isn't going to be placed on both the stack and in registers,
3492     set up the register and number of words.  */
3493  if (! arg->pass_on_stack)
3494    reg = arg->reg, partial = arg->partial;
3495
3496  if (reg != 0 && partial == 0)
3497    /* Being passed entirely in a register.  We shouldn't be called in
3498       this case.   */
3499    abort ();
3500
3501  /* If this arg needs special alignment, don't load the registers
3502     here.  */
3503  if (arg->n_aligned_regs != 0)
3504    reg = 0;
3505 
3506  /* If this is being passed partially in a register, we can't evaluate
3507     it directly into its stack slot.  Otherwise, we can.  */
3508  if (arg->value == 0)
3509    {
3510#ifdef ACCUMULATE_OUTGOING_ARGS
3511      /* stack_arg_under_construction is nonzero if a function argument is
3512         being evaluated directly into the outgoing argument list and
3513         expand_call must take special action to preserve the argument list
3514         if it is called recursively.
3515
3516         For scalar function arguments stack_usage_map is sufficient to
3517         determine which stack slots must be saved and restored.  Scalar
3518         arguments in general have pass_on_stack == 0.
3519
3520         If this argument is initialized by a function which takes the
3521         address of the argument (a C++ constructor or a C function
3522         returning a BLKmode structure), then stack_usage_map is
3523         insufficient and expand_call must push the stack around the
3524         function call.  Such arguments have pass_on_stack == 1.
3525
3526         Note that it is always safe to set stack_arg_under_construction,
3527         but this generates suboptimal code if set when not needed.  */
3528
3529      if (arg->pass_on_stack)
3530        stack_arg_under_construction++;
3531#endif
3532      arg->value = expand_expr (pval,
3533                                (partial
3534                                 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
3535                                ? NULL_RTX : arg->stack,
3536                                VOIDmode, 0);
3537
3538      /* If we are promoting object (or for any other reason) the mode
3539         doesn't agree, convert the mode.  */
3540
3541      if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
3542        arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
3543                                    arg->value, arg->unsignedp);
3544
3545#ifdef ACCUMULATE_OUTGOING_ARGS
3546      if (arg->pass_on_stack)
3547        stack_arg_under_construction--;
3548#endif
3549    }
3550
3551  /* Don't allow anything left on stack from computation
3552     of argument to alloca.  */
3553  if (may_be_alloca)
3554    do_pending_stack_adjust ();
3555
3556  if (arg->value == arg->stack)
3557    {
3558      /* If the value is already in the stack slot, we are done.  */
3559      if (flag_check_memory_usage && GET_CODE (arg->stack) == MEM)
3560        {
3561          if (arg->mode == BLKmode)
3562            abort ();
3563
3564          emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
3565                             XEXP (arg->stack, 0), ptr_mode,
3566                             GEN_INT (GET_MODE_SIZE (arg->mode)),
3567                             TYPE_MODE (sizetype),
3568                             GEN_INT (MEMORY_USE_RW),
3569                             TYPE_MODE (integer_type_node));
3570        }
3571    }
3572  else if (arg->mode != BLKmode)
3573    {
3574      register int size;
3575
3576      /* Argument is a scalar, not entirely passed in registers.
3577         (If part is passed in registers, arg->partial says how much
3578         and emit_push_insn will take care of putting it there.)
3579         
3580         Push it, and if its size is less than the
3581         amount of space allocated to it,
3582         also bump stack pointer by the additional space.
3583         Note that in C the default argument promotions
3584         will prevent such mismatches.  */
3585
3586      size = GET_MODE_SIZE (arg->mode);
3587      /* Compute how much space the push instruction will push.
3588         On many machines, pushing a byte will advance the stack
3589         pointer by a halfword.  */
3590#ifdef PUSH_ROUNDING
3591      size = PUSH_ROUNDING (size);
3592#endif
3593      used = size;
3594
3595      /* Compute how much space the argument should get:
3596         round up to a multiple of the alignment for arguments.  */
3597      if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
3598        used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
3599                 / (PARM_BOUNDARY / BITS_PER_UNIT))
3600                * (PARM_BOUNDARY / BITS_PER_UNIT));
3601
3602      /* This isn't already where we want it on the stack, so put it there.
3603         This can either be done with push or copy insns.  */
3604      emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
3605                      0, partial, reg, used - size,
3606                      argblock, ARGS_SIZE_RTX (arg->offset));
3607    }
3608  else
3609    {
3610      /* BLKmode, at least partly to be pushed.  */
3611
3612      register int excess;
3613      rtx size_rtx;
3614
3615      /* Pushing a nonscalar.
3616         If part is passed in registers, PARTIAL says how much
3617         and emit_push_insn will take care of putting it there.  */
3618
3619      /* Round its size up to a multiple
3620         of the allocation unit for arguments.  */
3621
3622      if (arg->size.var != 0)
3623        {
3624          excess = 0;
3625          size_rtx = ARGS_SIZE_RTX (arg->size);
3626        }
3627      else
3628        {
3629          /* PUSH_ROUNDING has no effect on us, because
3630             emit_push_insn for BLKmode is careful to avoid it.  */
3631          excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
3632                    + partial * UNITS_PER_WORD);
3633          size_rtx = expr_size (pval);
3634        }
3635
3636      emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
3637                      TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
3638                      reg, excess, argblock, ARGS_SIZE_RTX (arg->offset));
3639    }
3640
3641
3642  /* Unless this is a partially-in-register argument, the argument is now
3643     in the stack.
3644
3645     ??? Note that this can change arg->value from arg->stack to
3646     arg->stack_slot and it matters when they are not the same.
3647     It isn't totally clear that this is correct in all cases.  */
3648  if (partial == 0)
3649    arg->value = arg->stack_slot;
3650
3651  /* Once we have pushed something, pops can't safely
3652     be deferred during the rest of the arguments.  */
3653  NO_DEFER_POP;
3654
3655  /* ANSI doesn't require a sequence point here,
3656     but PCC has one, so this will avoid some problems.  */
3657  emit_queue ();
3658
3659  /* Free any temporary slots made in processing this argument.  Show
3660     that we might have taken the address of something and pushed that
3661     as an operand.  */
3662  preserve_temp_slots (NULL_RTX);
3663  free_temp_slots ();
3664  pop_temp_slots ();
3665
3666#ifdef ACCUMULATE_OUTGOING_ARGS
3667  /* Now mark the segment we just used.  */
3668  if (argblock && ! variable_size && arg->stack)
3669    for (i = lower_bound; i < upper_bound; i++)
3670      stack_usage_map[i] = 1;
3671#endif
3672}
Note: See TracBrowser for help on using the repository browser.