OSDN Git Service

* tree-def (WITH_SIZE_EXPR): New.
[pf3gnuchains/gcc-fork.git] / gcc / calls.c
1 /* Convert function calls to rtl insns, for GNU C compiler.
2    Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "flags.h"
29 #include "expr.h"
30 #include "optabs.h"
31 #include "libfuncs.h"
32 #include "function.h"
33 #include "regs.h"
34 #include "toplev.h"
35 #include "output.h"
36 #include "tm_p.h"
37 #include "timevar.h"
38 #include "sbitmap.h"
39 #include "langhooks.h"
40 #include "target.h"
41 #include "cgraph.h"
42 #include "except.h"
43
44 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits.  */
45 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
46
47 /* Data structure and subroutines used within expand_call.  */
48
49 struct arg_data
50 {
51   /* Tree node for this argument.  */
52   tree tree_value;
53   /* Mode for value; TYPE_MODE unless promoted.  */
54   enum machine_mode mode;
55   /* Current RTL value for argument, or 0 if it isn't precomputed.  */
56   rtx value;
57   /* Initially-compute RTL value for argument; only for const functions.  */
58   rtx initial_value;
59   /* Register to pass this argument in, 0 if passed on stack, or an
60      PARALLEL if the arg is to be copied into multiple non-contiguous
61      registers.  */
62   rtx reg;
63   /* Register to pass this argument in when generating tail call sequence.
64      This is not the same register as for normal calls on machines with
65      register windows.  */
66   rtx tail_call_reg;
67   /* If REG was promoted from the actual mode of the argument expression,
68      indicates whether the promotion is sign- or zero-extended.  */
69   int unsignedp;
70   /* Number of registers to use.  0 means put the whole arg in registers.
71      Also 0 if not passed in registers.  */
72   int partial;
73   /* Nonzero if argument must be passed on stack.
74      Note that some arguments may be passed on the stack
75      even though pass_on_stack is zero, just because FUNCTION_ARG says so.
76      pass_on_stack identifies arguments that *cannot* go in registers.  */
77   int pass_on_stack;
78   /* Some fields packaged up for locate_and_pad_parm.  */
79   struct locate_and_pad_arg_data locate;
80   /* Location on the stack at which parameter should be stored.  The store
81      has already been done if STACK == VALUE.  */
82   rtx stack;
83   /* Location on the stack of the start of this argument slot.  This can
84      differ from STACK if this arg pads downward.  This location is known
85      to be aligned to FUNCTION_ARG_BOUNDARY.  */
86   rtx stack_slot;
87   /* Place that this stack area has been saved, if needed.  */
88   rtx save_area;
89   /* If an argument's alignment does not permit direct copying into registers,
90      copy in smaller-sized pieces into pseudos.  These are stored in a
91      block pointed to by this field.  The next field says how many
92      word-sized pseudos we made.  */
93   rtx *aligned_regs;
94   int n_aligned_regs;
95 };
96
97 /* A vector of one char per byte of stack space.  A byte if nonzero if
98    the corresponding stack location has been used.
99    This vector is used to prevent a function call within an argument from
100    clobbering any stack already set up.  */
101 static char *stack_usage_map;
102
103 /* Size of STACK_USAGE_MAP.  */
104 static int highest_outgoing_arg_in_use;
105
106 /* A bitmap of virtual-incoming stack space.  Bit is set if the corresponding
107    stack location's tail call argument has been already stored into the stack.
108    This bitmap is used to prevent sibling call optimization if function tries
109    to use parent's incoming argument slots when they have been already
110    overwritten with tail call arguments.  */
111 static sbitmap stored_args_map;
112
113 /* stack_arg_under_construction is nonzero when an argument may be
114    initialized with a constructor call (including a C function that
115    returns a BLKmode struct) and expand_call must take special action
116    to make sure the object being constructed does not overlap the
117    argument list for the constructor call.  */
118 int stack_arg_under_construction;
119
120 static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT,
121                          HOST_WIDE_INT, rtx, rtx, int, rtx, int,
122                          CUMULATIVE_ARGS *);
123 static void precompute_register_parameters (int, struct arg_data *, int *);
124 static int store_one_arg (struct arg_data *, rtx, int, int, int);
125 static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
126 static int finalize_must_preallocate (int, int, struct arg_data *,
127                                       struct args_size *);
128 static void precompute_arguments (int, int, struct arg_data *);
129 static int compute_argument_block_size (int, struct args_size *, int);
130 static void initialize_argument_information (int, struct arg_data *,
131                                              struct args_size *, int, tree,
132                                              tree, CUMULATIVE_ARGS *, int,
133                                              rtx *, int *, int *, int *,
134                                              bool *, bool);
135 static void compute_argument_addresses (struct arg_data *, rtx, int);
136 static rtx rtx_for_function_call (tree, tree);
137 static void load_register_parameters (struct arg_data *, int, rtx *, int,
138                                       int, int *);
139 static rtx emit_library_call_value_1 (int, rtx, rtx, enum libcall_type,
140                                       enum machine_mode, int, va_list);
141 static int special_function_p (tree, int);
142 static int check_sibcall_argument_overlap_1 (rtx);
143 static int check_sibcall_argument_overlap (rtx, struct arg_data *, int);
144
145 static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
146                                                       int);
147 static tree fix_unsafe_tree (tree);
148 static bool shift_returned_value (tree, rtx *);
149
150 #ifdef REG_PARM_STACK_SPACE
151 static rtx save_fixed_argument_area (int, rtx, int *, int *);
152 static void restore_fixed_argument_area (rtx, rtx, int, int);
153 #endif
154 \f
155 /* Force FUNEXP into a form suitable for the address of a CALL,
156    and return that as an rtx.  Also load the static chain register
157    if FNDECL is a nested function.
158
159    CALL_FUSAGE points to a variable holding the prospective
160    CALL_INSN_FUNCTION_USAGE information.  */
161
162 rtx
163 prepare_call_address (rtx funexp, rtx static_chain_value,
164                       rtx *call_fusage, int reg_parm_seen, int sibcallp)
165 {
166   /* Make a valid memory address and copy constants through pseudo-regs,
167      but not for a constant address if -fno-function-cse.  */
168   if (GET_CODE (funexp) != SYMBOL_REF)
169     /* If we are using registers for parameters, force the
170        function address into a register now.  */
171     funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
172               ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
173               : memory_address (FUNCTION_MODE, funexp));
174   else if (! sibcallp)
175     {
176 #ifndef NO_FUNCTION_CSE
177       if (optimize && ! flag_no_function_cse)
178         funexp = force_reg (Pmode, funexp);
179 #endif
180     }
181
182   if (static_chain_value != 0)
183     {
184       static_chain_value = convert_memory_address (Pmode, static_chain_value);
185       emit_move_insn (static_chain_rtx, static_chain_value);
186
187       if (REG_P (static_chain_rtx))
188         use_reg (call_fusage, static_chain_rtx);
189     }
190
191   return funexp;
192 }
193
194 /* Generate instructions to call function FUNEXP,
195    and optionally pop the results.
196    The CALL_INSN is the first insn generated.
197
198    FNDECL is the declaration node of the function.  This is given to the
199    macro RETURN_POPS_ARGS to determine whether this function pops its own args.
200
201    FUNTYPE is the data type of the function.  This is given to the macro
202    RETURN_POPS_ARGS to determine whether this function pops its own args.
203    We used to allow an identifier for library functions, but that doesn't
204    work when the return type is an aggregate type and the calling convention
205    says that the pointer to this aggregate is to be popped by the callee.
206
207    STACK_SIZE is the number of bytes of arguments on the stack,
208    ROUNDED_STACK_SIZE is that number rounded up to
209    PREFERRED_STACK_BOUNDARY; zero if the size is variable.  This is
210    both to put into the call insn and to generate explicit popping
211    code if necessary.
212
213    STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
214    It is zero if this call doesn't want a structure value.
215
216    NEXT_ARG_REG is the rtx that results from executing
217      FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
218    just after all the args have had their registers assigned.
219    This could be whatever you like, but normally it is the first
220    arg-register beyond those used for args in this call,
221    or 0 if all the arg-registers are used in this call.
222    It is passed on to `gen_call' so you can put this info in the call insn.
223
224    VALREG is a hard register in which a value is returned,
225    or 0 if the call does not return a value.
226
227    OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
228    the args to this call were processed.
229    We restore `inhibit_defer_pop' to that value.
230
231    CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
232    denote registers used by the called function.  */
233
234 static void
235 emit_call_1 (rtx funexp, tree fntree, tree fndecl ATTRIBUTE_UNUSED,
236              tree funtype ATTRIBUTE_UNUSED,
237              HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED,
238              HOST_WIDE_INT rounded_stack_size,
239              HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED,
240              rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg,
241              int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags,
242              CUMULATIVE_ARGS *args_so_far ATTRIBUTE_UNUSED)
243 {
244   rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
245   rtx call_insn;
246   int already_popped = 0;
247   HOST_WIDE_INT n_popped = RETURN_POPS_ARGS (fndecl, funtype, stack_size);
248 #if defined (HAVE_call) && defined (HAVE_call_value)
249   rtx struct_value_size_rtx;
250   struct_value_size_rtx = GEN_INT (struct_value_size);
251 #endif
252
253 #ifdef CALL_POPS_ARGS
254   n_popped += CALL_POPS_ARGS (* args_so_far);
255 #endif
256
257   /* Ensure address is valid.  SYMBOL_REF is already valid, so no need,
258      and we don't want to load it into a register as an optimization,
259      because prepare_call_address already did it if it should be done.  */
260   if (GET_CODE (funexp) != SYMBOL_REF)
261     funexp = memory_address (FUNCTION_MODE, funexp);
262
263 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
264   if ((ecf_flags & ECF_SIBCALL)
265       && HAVE_sibcall_pop && HAVE_sibcall_value_pop
266       && (n_popped > 0 || stack_size == 0))
267     {
268       rtx n_pop = GEN_INT (n_popped);
269       rtx pat;
270
271       /* If this subroutine pops its own args, record that in the call insn
272          if possible, for the sake of frame pointer elimination.  */
273
274       if (valreg)
275         pat = GEN_SIBCALL_VALUE_POP (valreg,
276                                      gen_rtx_MEM (FUNCTION_MODE, funexp),
277                                      rounded_stack_size_rtx, next_arg_reg,
278                                      n_pop);
279       else
280         pat = GEN_SIBCALL_POP (gen_rtx_MEM (FUNCTION_MODE, funexp),
281                                rounded_stack_size_rtx, next_arg_reg, n_pop);
282
283       emit_call_insn (pat);
284       already_popped = 1;
285     }
286   else
287 #endif
288
289 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
290   /* If the target has "call" or "call_value" insns, then prefer them
291      if no arguments are actually popped.  If the target does not have
292      "call" or "call_value" insns, then we must use the popping versions
293      even if the call has no arguments to pop.  */
294 #if defined (HAVE_call) && defined (HAVE_call_value)
295   if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
296       && n_popped > 0 && ! (ecf_flags & ECF_SP_DEPRESSED))
297 #else
298   if (HAVE_call_pop && HAVE_call_value_pop)
299 #endif
300     {
301       rtx n_pop = GEN_INT (n_popped);
302       rtx pat;
303
304       /* If this subroutine pops its own args, record that in the call insn
305          if possible, for the sake of frame pointer elimination.  */
306
307       if (valreg)
308         pat = GEN_CALL_VALUE_POP (valreg,
309                                   gen_rtx_MEM (FUNCTION_MODE, funexp),
310                                   rounded_stack_size_rtx, next_arg_reg, n_pop);
311       else
312         pat = GEN_CALL_POP (gen_rtx_MEM (FUNCTION_MODE, funexp),
313                             rounded_stack_size_rtx, next_arg_reg, n_pop);
314
315       emit_call_insn (pat);
316       already_popped = 1;
317     }
318   else
319 #endif
320
321 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
322   if ((ecf_flags & ECF_SIBCALL)
323       && HAVE_sibcall && HAVE_sibcall_value)
324     {
325       if (valreg)
326         emit_call_insn (GEN_SIBCALL_VALUE (valreg,
327                                            gen_rtx_MEM (FUNCTION_MODE, funexp),
328                                            rounded_stack_size_rtx,
329                                            next_arg_reg, NULL_RTX));
330       else
331         emit_call_insn (GEN_SIBCALL (gen_rtx_MEM (FUNCTION_MODE, funexp),
332                                      rounded_stack_size_rtx, next_arg_reg,
333                                      struct_value_size_rtx));
334     }
335   else
336 #endif
337
338 #if defined (HAVE_call) && defined (HAVE_call_value)
339   if (HAVE_call && HAVE_call_value)
340     {
341       if (valreg)
342         emit_call_insn (GEN_CALL_VALUE (valreg,
343                                         gen_rtx_MEM (FUNCTION_MODE, funexp),
344                                         rounded_stack_size_rtx, next_arg_reg,
345                                         NULL_RTX));
346       else
347         emit_call_insn (GEN_CALL (gen_rtx_MEM (FUNCTION_MODE, funexp),
348                                   rounded_stack_size_rtx, next_arg_reg,
349                                   struct_value_size_rtx));
350     }
351   else
352 #endif
353     abort ();
354
355   /* Find the call we just emitted.  */
356   call_insn = last_call_insn ();
357
358   /* Mark memory as used for "pure" function call.  */
359   if (ecf_flags & ECF_PURE)
360     call_fusage
361       = gen_rtx_EXPR_LIST
362         (VOIDmode,
363          gen_rtx_USE (VOIDmode,
364                       gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode))),
365          call_fusage);
366
367   /* Put the register usage information there.  */
368   add_function_usage_to (call_insn, call_fusage);
369
370   /* If this is a const call, then set the insn's unchanging bit.  */
371   if (ecf_flags & (ECF_CONST | ECF_PURE))
372     CONST_OR_PURE_CALL_P (call_insn) = 1;
373
374   /* If this call can't throw, attach a REG_EH_REGION reg note to that
375      effect.  */
376   if (ecf_flags & ECF_NOTHROW)
377     REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, const0_rtx,
378                                                REG_NOTES (call_insn));
379   else
380     {
381       int rn = lookup_stmt_eh_region (fntree);
382
383       /* If rn < 0, then either (1) tree-ssa not used or (2) doesn't
384          throw, which we already took care of.  */
385       if (rn > 0)
386         REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, GEN_INT (rn),
387                                                    REG_NOTES (call_insn));
388       note_current_region_may_contain_throw ();
389     }
390
391   if (ecf_flags & ECF_NORETURN)
392     REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_NORETURN, const0_rtx,
393                                                REG_NOTES (call_insn));
394   if (ecf_flags & ECF_ALWAYS_RETURN)
395     REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_ALWAYS_RETURN, const0_rtx,
396                                                REG_NOTES (call_insn));
397
398   if (ecf_flags & ECF_RETURNS_TWICE)
399     {
400       REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_SETJMP, const0_rtx,
401                                                  REG_NOTES (call_insn));
402       current_function_calls_setjmp = 1;
403     }
404
405   SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
406
407   /* Restore this now, so that we do defer pops for this call's args
408      if the context of the call as a whole permits.  */
409   inhibit_defer_pop = old_inhibit_defer_pop;
410
411   if (n_popped > 0)
412     {
413       if (!already_popped)
414         CALL_INSN_FUNCTION_USAGE (call_insn)
415           = gen_rtx_EXPR_LIST (VOIDmode,
416                                gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
417                                CALL_INSN_FUNCTION_USAGE (call_insn));
418       rounded_stack_size -= n_popped;
419       rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
420       stack_pointer_delta -= n_popped;
421     }
422
423   if (!ACCUMULATE_OUTGOING_ARGS)
424     {
425       /* If returning from the subroutine does not automatically pop the args,
426          we need an instruction to pop them sooner or later.
427          Perhaps do it now; perhaps just record how much space to pop later.
428
429          If returning from the subroutine does pop the args, indicate that the
430          stack pointer will be changed.  */
431
432       if (rounded_stack_size != 0)
433         {
434           if (ecf_flags & (ECF_SP_DEPRESSED | ECF_NORETURN | ECF_LONGJMP))
435             /* Just pretend we did the pop.  */
436             stack_pointer_delta -= rounded_stack_size;
437           else if (flag_defer_pop && inhibit_defer_pop == 0
438               && ! (ecf_flags & (ECF_CONST | ECF_PURE)))
439             pending_stack_adjust += rounded_stack_size;
440           else
441             adjust_stack (rounded_stack_size_rtx);
442         }
443     }
444   /* When we accumulate outgoing args, we must avoid any stack manipulations.
445      Restore the stack pointer to its original value now.  Usually
446      ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
447      On  i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
448      popping variants of functions exist as well.
449
450      ??? We may optimize similar to defer_pop above, but it is
451      probably not worthwhile.
452
453      ??? It will be worthwhile to enable combine_stack_adjustments even for
454      such machines.  */
455   else if (n_popped)
456     anti_adjust_stack (GEN_INT (n_popped));
457 }
458
459 /* Determine if the function identified by NAME and FNDECL is one with
460    special properties we wish to know about.
461
462    For example, if the function might return more than one time (setjmp), then
463    set RETURNS_TWICE to a nonzero value.
464
465    Similarly set LONGJMP for if the function is in the longjmp family.
466
467    Set MAY_BE_ALLOCA for any memory allocation function that might allocate
468    space from the stack such as alloca.  */
469
470 static int
471 special_function_p (tree fndecl, int flags)
472 {
473   if (fndecl && DECL_NAME (fndecl)
474       && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
475       /* Exclude functions not at the file scope, or not `extern',
476          since they are not the magic functions we would otherwise
477          think they are.
478          FIXME: this should be handled with attributes, not with this
479          hacky imitation of DECL_ASSEMBLER_NAME.  It's (also) wrong
480          because you can declare fork() inside a function if you
481          wish.  */
482       && (DECL_CONTEXT (fndecl) == NULL_TREE
483           || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL)
484       && TREE_PUBLIC (fndecl))
485     {
486       const char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
487       const char *tname = name;
488
489       /* We assume that alloca will always be called by name.  It
490          makes no sense to pass it as a pointer-to-function to
491          anything that does not understand its behavior.  */
492       if (((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
493             && name[0] == 'a'
494             && ! strcmp (name, "alloca"))
495            || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
496                && name[0] == '_'
497                && ! strcmp (name, "__builtin_alloca"))))
498         flags |= ECF_MAY_BE_ALLOCA;
499
500       /* Disregard prefix _, __ or __x.  */
501       if (name[0] == '_')
502         {
503           if (name[1] == '_' && name[2] == 'x')
504             tname += 3;
505           else if (name[1] == '_')
506             tname += 2;
507           else
508             tname += 1;
509         }
510
511       if (tname[0] == 's')
512         {
513           if ((tname[1] == 'e'
514                && (! strcmp (tname, "setjmp")
515                    || ! strcmp (tname, "setjmp_syscall")))
516               || (tname[1] == 'i'
517                   && ! strcmp (tname, "sigsetjmp"))
518               || (tname[1] == 'a'
519                   && ! strcmp (tname, "savectx")))
520             flags |= ECF_RETURNS_TWICE;
521
522           if (tname[1] == 'i'
523               && ! strcmp (tname, "siglongjmp"))
524             flags |= ECF_LONGJMP;
525         }
526       else if ((tname[0] == 'q' && tname[1] == 's'
527                 && ! strcmp (tname, "qsetjmp"))
528                || (tname[0] == 'v' && tname[1] == 'f'
529                    && ! strcmp (tname, "vfork")))
530         flags |= ECF_RETURNS_TWICE;
531
532       else if (tname[0] == 'l' && tname[1] == 'o'
533                && ! strcmp (tname, "longjmp"))
534         flags |= ECF_LONGJMP;
535     }
536
537   return flags;
538 }
539
540 /* Return nonzero when tree represent call to longjmp.  */
541
542 int
543 setjmp_call_p (tree fndecl)
544 {
545   return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE;
546 }
547
548 /* Return true when exp contains alloca call.  */
549 bool
550 alloca_call_p (tree exp)
551 {
552   if (TREE_CODE (exp) == CALL_EXPR
553       && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
554       && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
555           == FUNCTION_DECL)
556       && (special_function_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
557                               0) & ECF_MAY_BE_ALLOCA))
558     return true;
559   return false;
560 }
561
562 /* Detect flags (function attributes) from the function decl or type node.  */
563
564 int
565 flags_from_decl_or_type (tree exp)
566 {
567   int flags = 0;
568   tree type = exp;
569
570   if (DECL_P (exp))
571     {
572       struct cgraph_rtl_info *i = cgraph_rtl_info (exp);
573       type = TREE_TYPE (exp);
574
575       if (i)
576         {
577           if (i->pure_function)
578             flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
579           if (i->const_function)
580             flags |= ECF_CONST | ECF_LIBCALL_BLOCK;
581         }
582
583       /* The function exp may have the `malloc' attribute.  */
584       if (DECL_IS_MALLOC (exp))
585         flags |= ECF_MALLOC;
586
587       /* The function exp may have the `pure' attribute.  */
588       if (DECL_IS_PURE (exp))
589         flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
590
591       if (TREE_NOTHROW (exp))
592         flags |= ECF_NOTHROW;
593
594       if (TREE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
595         flags |= ECF_LIBCALL_BLOCK | ECF_CONST;
596
597       flags = special_function_p (exp, flags);
598     }
599   else if (TYPE_P (exp) && TYPE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
600     flags |= ECF_CONST;
601
602   if (TREE_THIS_VOLATILE (exp))
603     flags |= ECF_NORETURN;
604
605   /* Mark if the function returns with the stack pointer depressed.   We
606      cannot consider it pure or constant in that case.  */
607   if (TREE_CODE (type) == FUNCTION_TYPE && TYPE_RETURNS_STACK_DEPRESSED (type))
608     {
609       flags |= ECF_SP_DEPRESSED;
610       flags &= ~(ECF_PURE | ECF_CONST | ECF_LIBCALL_BLOCK);
611     }
612
613   return flags;
614 }
615
616 /* Detect flags from a CALL_EXPR.  */
617
618 int
619 call_expr_flags (tree t)
620 {
621   int flags;
622   tree decl = get_callee_fndecl (t);
623
624   if (decl)
625     flags = flags_from_decl_or_type (decl);
626   else
627     {
628       t = TREE_TYPE (TREE_OPERAND (t, 0));
629       if (t && TREE_CODE (t) == POINTER_TYPE)
630         flags = flags_from_decl_or_type (TREE_TYPE (t));
631       else
632         flags = 0;
633     }
634
635   return flags;
636 }
637
638 /* Precompute all register parameters as described by ARGS, storing values
639    into fields within the ARGS array.
640
641    NUM_ACTUALS indicates the total number elements in the ARGS array.
642
643    Set REG_PARM_SEEN if we encounter a register parameter.  */
644
645 static void
646 precompute_register_parameters (int num_actuals, struct arg_data *args, int *reg_parm_seen)
647 {
648   int i;
649
650   *reg_parm_seen = 0;
651
652   for (i = 0; i < num_actuals; i++)
653     if (args[i].reg != 0 && ! args[i].pass_on_stack)
654       {
655         *reg_parm_seen = 1;
656
657         if (args[i].value == 0)
658           {
659             push_temp_slots ();
660             args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
661                                          VOIDmode, 0);
662             preserve_temp_slots (args[i].value);
663             pop_temp_slots ();
664           }
665
666         /* If the value is a non-legitimate constant, force it into a
667            pseudo now.  TLS symbols sometimes need a call to resolve.  */
668         if (CONSTANT_P (args[i].value)
669             && !LEGITIMATE_CONSTANT_P (args[i].value))
670           args[i].value = force_reg (args[i].mode, args[i].value);
671
672         /* If we are to promote the function arg to a wider mode,
673            do it now.  */
674
675         if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
676           args[i].value
677             = convert_modes (args[i].mode,
678                              TYPE_MODE (TREE_TYPE (args[i].tree_value)),
679                              args[i].value, args[i].unsignedp);
680
681         /* If the value is expensive, and we are inside an appropriately
682            short loop, put the value into a pseudo and then put the pseudo
683            into the hard reg.
684
685            For small register classes, also do this if this call uses
686            register parameters.  This is to avoid reload conflicts while
687            loading the parameters registers.  */
688
689         if ((! (REG_P (args[i].value)
690                 || (GET_CODE (args[i].value) == SUBREG
691                     && REG_P (SUBREG_REG (args[i].value)))))
692             && args[i].mode != BLKmode
693             && rtx_cost (args[i].value, SET) > COSTS_N_INSNS (1)
694             && ((SMALL_REGISTER_CLASSES && *reg_parm_seen)
695                 || preserve_subexpressions_p ()))
696           args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
697       }
698 }
699
700 #ifdef REG_PARM_STACK_SPACE
701
702   /* The argument list is the property of the called routine and it
703      may clobber it.  If the fixed area has been used for previous
704      parameters, we must save and restore it.  */
705
706 static rtx
707 save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
708 {
709   int low;
710   int high;
711
712   /* Compute the boundary of the area that needs to be saved, if any.  */
713   high = reg_parm_stack_space;
714 #ifdef ARGS_GROW_DOWNWARD
715   high += 1;
716 #endif
717   if (high > highest_outgoing_arg_in_use)
718     high = highest_outgoing_arg_in_use;
719
720   for (low = 0; low < high; low++)
721     if (stack_usage_map[low] != 0)
722       {
723         int num_to_save;
724         enum machine_mode save_mode;
725         int delta;
726         rtx stack_area;
727         rtx save_area;
728
729         while (stack_usage_map[--high] == 0)
730           ;
731
732         *low_to_save = low;
733         *high_to_save = high;
734
735         num_to_save = high - low + 1;
736         save_mode = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
737
738         /* If we don't have the required alignment, must do this
739            in BLKmode.  */
740         if ((low & (MIN (GET_MODE_SIZE (save_mode),
741                          BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
742           save_mode = BLKmode;
743
744 #ifdef ARGS_GROW_DOWNWARD
745         delta = -high;
746 #else
747         delta = low;
748 #endif
749         stack_area = gen_rtx_MEM (save_mode,
750                                   memory_address (save_mode,
751                                                   plus_constant (argblock,
752                                                                  delta)));
753
754         set_mem_align (stack_area, PARM_BOUNDARY);
755         if (save_mode == BLKmode)
756           {
757             save_area = assign_stack_temp (BLKmode, num_to_save, 0);
758             emit_block_move (validize_mem (save_area), stack_area,
759                              GEN_INT (num_to_save), BLOCK_OP_CALL_PARM);
760           }
761         else
762           {
763             save_area = gen_reg_rtx (save_mode);
764             emit_move_insn (save_area, stack_area);
765           }
766
767         return save_area;
768       }
769
770   return NULL_RTX;
771 }
772
773 static void
774 restore_fixed_argument_area (rtx save_area, rtx argblock, int high_to_save, int low_to_save)
775 {
776   enum machine_mode save_mode = GET_MODE (save_area);
777   int delta;
778   rtx stack_area;
779
780 #ifdef ARGS_GROW_DOWNWARD
781   delta = -high_to_save;
782 #else
783   delta = low_to_save;
784 #endif
785   stack_area = gen_rtx_MEM (save_mode,
786                             memory_address (save_mode,
787                                             plus_constant (argblock, delta)));
788   set_mem_align (stack_area, PARM_BOUNDARY);
789
790   if (save_mode != BLKmode)
791     emit_move_insn (stack_area, save_area);
792   else
793     emit_block_move (stack_area, validize_mem (save_area),
794                      GEN_INT (high_to_save - low_to_save + 1),
795                      BLOCK_OP_CALL_PARM);
796 }
797 #endif /* REG_PARM_STACK_SPACE */
798
799 /* If any elements in ARGS refer to parameters that are to be passed in
800    registers, but not in memory, and whose alignment does not permit a
801    direct copy into registers.  Copy the values into a group of pseudos
802    which we will later copy into the appropriate hard registers.
803
804    Pseudos for each unaligned argument will be stored into the array
805    args[argnum].aligned_regs.  The caller is responsible for deallocating
806    the aligned_regs array if it is nonzero.  */
807
808 static void
809 store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals)
810 {
811   int i, j;
812
813   for (i = 0; i < num_actuals; i++)
814     if (args[i].reg != 0 && ! args[i].pass_on_stack
815         && args[i].mode == BLKmode
816         && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
817             < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
818       {
819         int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
820         int nregs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
821         int endian_correction = 0;
822
823         args[i].n_aligned_regs = args[i].partial ? args[i].partial : nregs;
824         args[i].aligned_regs = xmalloc (sizeof (rtx) * args[i].n_aligned_regs);
825
826         /* Structures smaller than a word are normally aligned to the
827            least significant byte.  On a BYTES_BIG_ENDIAN machine,
828            this means we must skip the empty high order bytes when
829            calculating the bit offset.  */
830         if (bytes < UNITS_PER_WORD
831 #ifdef BLOCK_REG_PADDING
832             && (BLOCK_REG_PADDING (args[i].mode,
833                                    TREE_TYPE (args[i].tree_value), 1)
834                 == downward)
835 #else
836             && BYTES_BIG_ENDIAN
837 #endif
838             )
839           endian_correction = BITS_PER_WORD - bytes * BITS_PER_UNIT;
840
841         for (j = 0; j < args[i].n_aligned_regs; j++)
842           {
843             rtx reg = gen_reg_rtx (word_mode);
844             rtx word = operand_subword_force (args[i].value, j, BLKmode);
845             int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
846
847             args[i].aligned_regs[j] = reg;
848             word = extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
849                                       word_mode, word_mode);
850
851             /* There is no need to restrict this code to loading items
852                in TYPE_ALIGN sized hunks.  The bitfield instructions can
853                load up entire word sized registers efficiently.
854
855                ??? This may not be needed anymore.
856                We use to emit a clobber here but that doesn't let later
857                passes optimize the instructions we emit.  By storing 0 into
858                the register later passes know the first AND to zero out the
859                bitfield being set in the register is unnecessary.  The store
860                of 0 will be deleted as will at least the first AND.  */
861
862             emit_move_insn (reg, const0_rtx);
863
864             bytes -= bitsize / BITS_PER_UNIT;
865             store_bit_field (reg, bitsize, endian_correction, word_mode,
866                              word);
867           }
868       }
869 }
870
871 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
872    ACTPARMS.
873
874    NUM_ACTUALS is the total number of parameters.
875
876    N_NAMED_ARGS is the total number of named arguments.
877
878    FNDECL is the tree code for the target of this call (if known)
879
880    ARGS_SO_FAR holds state needed by the target to know where to place
881    the next argument.
882
883    REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
884    for arguments which are passed in registers.
885
886    OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
887    and may be modified by this routine.
888
889    OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
890    flags which may may be modified by this routine.
891
892    MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
893    that requires allocation of stack space.
894
895    CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
896    the thunked-to function.  */
897
898 static void
899 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
900                                  struct arg_data *args,
901                                  struct args_size *args_size,
902                                  int n_named_args ATTRIBUTE_UNUSED,
903                                  tree actparms, tree fndecl,
904                                  CUMULATIVE_ARGS *args_so_far,
905                                  int reg_parm_stack_space,
906                                  rtx *old_stack_level, int *old_pending_adj,
907                                  int *must_preallocate, int *ecf_flags,
908                                  bool *may_tailcall, bool call_from_thunk_p)
909 {
910   /* 1 if scanning parms front to back, -1 if scanning back to front.  */
911   int inc;
912
913   /* Count arg position in order args appear.  */
914   int argpos;
915
916   int i;
917   tree p;
918
919   args_size->constant = 0;
920   args_size->var = 0;
921
922   /* In this loop, we consider args in the order they are written.
923      We fill up ARGS from the front or from the back if necessary
924      so that in any case the first arg to be pushed ends up at the front.  */
925
926   if (PUSH_ARGS_REVERSED)
927     {
928       i = num_actuals - 1, inc = -1;
929       /* In this case, must reverse order of args
930          so that we compute and push the last arg first.  */
931     }
932   else
933     {
934       i = 0, inc = 1;
935     }
936
937   /* I counts args in order (to be) pushed; ARGPOS counts in order written.  */
938   for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
939     {
940       tree type = TREE_TYPE (TREE_VALUE (p));
941       int unsignedp;
942       enum machine_mode mode;
943
944       args[i].tree_value = TREE_VALUE (p);
945
946       /* Replace erroneous argument with constant zero.  */
947       if (type == error_mark_node || !COMPLETE_TYPE_P (type))
948         args[i].tree_value = integer_zero_node, type = integer_type_node;
949
950       /* If TYPE is a transparent union, pass things the way we would
951          pass the first field of the union.  We have already verified that
952          the modes are the same.  */
953       if (TREE_CODE (type) == UNION_TYPE && TYPE_TRANSPARENT_UNION (type))
954         type = TREE_TYPE (TYPE_FIELDS (type));
955
956       /* Decide where to pass this arg.
957
958          args[i].reg is nonzero if all or part is passed in registers.
959
960          args[i].partial is nonzero if part but not all is passed in registers,
961          and the exact value says how many words are passed in registers.
962
963          args[i].pass_on_stack is nonzero if the argument must at least be
964          computed on the stack.  It may then be loaded back into registers
965          if args[i].reg is nonzero.
966
967          These decisions are driven by the FUNCTION_... macros and must agree
968          with those made by function.c.  */
969
970       /* See if this argument should be passed by invisible reference.  */
971       if (pass_by_reference (args_so_far, TYPE_MODE (type),
972                              type, argpos < n_named_args))
973         {
974           /* If we're compiling a thunk, pass through invisible
975              references instead of making a copy.  */
976           if (call_from_thunk_p
977               || (FUNCTION_ARG_CALLEE_COPIES (*args_so_far, TYPE_MODE (type),
978                                              type, argpos < n_named_args)
979                   /* If it's in a register, we must make a copy of it too.  */
980                   /* ??? Is this a sufficient test?  Is there a better one? */
981                   && !(TREE_CODE (args[i].tree_value) == VAR_DECL
982                        && REG_P (DECL_RTL (args[i].tree_value)))
983                   && ! TREE_ADDRESSABLE (type))
984               )
985             {
986               /* C++ uses a TARGET_EXPR to indicate that we want to make a
987                  new object from the argument.  If we are passing by
988                  invisible reference, the callee will do that for us, so we
989                  can strip off the TARGET_EXPR.  This is not always safe,
990                  but it is safe in the only case where this is a useful
991                  optimization; namely, when the argument is a plain object.
992                  In that case, the frontend is just asking the backend to
993                  make a bitwise copy of the argument.  */
994
995               if (TREE_CODE (args[i].tree_value) == TARGET_EXPR
996                   && (DECL_P (TREE_OPERAND (args[i].tree_value, 1)))
997                   && ! REG_P (DECL_RTL (TREE_OPERAND (args[i].tree_value, 1))))
998                 args[i].tree_value = TREE_OPERAND (args[i].tree_value, 1);
999
1000               /* We can't use sibcalls if a callee-copied argument is stored
1001                  in the current function's frame.  */
1002               if (!call_from_thunk_p
1003                   && (!DECL_P (args[i].tree_value)
1004                       || !TREE_STATIC (args[i].tree_value)))
1005                 *may_tailcall = false;
1006
1007               args[i].tree_value = build1 (ADDR_EXPR,
1008                                            build_pointer_type (type),
1009                                            args[i].tree_value);
1010               type = build_pointer_type (type);
1011             }
1012           else if (TREE_CODE (args[i].tree_value) == TARGET_EXPR)
1013             {
1014               /* In the V3 C++ ABI, parameters are destroyed in the caller.
1015                  We implement this by passing the address of the temporary
1016                  rather than expanding it into another allocated slot.  */
1017               args[i].tree_value = build1 (ADDR_EXPR,
1018                                            build_pointer_type (type),
1019                                            args[i].tree_value);
1020               type = build_pointer_type (type);
1021               *may_tailcall = false;
1022             }
1023           else
1024             {
1025               /* We make a copy of the object and pass the address to the
1026                  function being called.  */
1027               rtx copy;
1028
1029               if (!COMPLETE_TYPE_P (type)
1030                   || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1031                   || (flag_stack_check && ! STACK_CHECK_BUILTIN
1032                       && (0 < compare_tree_int (TYPE_SIZE_UNIT (type),
1033                                                 STACK_CHECK_MAX_VAR_SIZE))))
1034                 {
1035                   /* This is a variable-sized object.  Make space on the stack
1036                      for it.  */
1037                   rtx size_rtx = expr_size (TREE_VALUE (p));
1038
1039                   if (*old_stack_level == 0)
1040                     {
1041                       emit_stack_save (SAVE_BLOCK, old_stack_level, NULL_RTX);
1042                       *old_pending_adj = pending_stack_adjust;
1043                       pending_stack_adjust = 0;
1044                     }
1045
1046                   copy = gen_rtx_MEM (BLKmode,
1047                                       allocate_dynamic_stack_space
1048                                       (size_rtx, NULL_RTX, TYPE_ALIGN (type)));
1049                   set_mem_attributes (copy, type, 1);
1050                 }
1051               else
1052                 copy = assign_temp (type, 0, 1, 0);
1053
1054               store_expr (args[i].tree_value, copy, 0);
1055               *ecf_flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
1056
1057               args[i].tree_value = build1 (ADDR_EXPR,
1058                                            build_pointer_type (type),
1059                                            make_tree (type, copy));
1060               type = build_pointer_type (type);
1061               *may_tailcall = false;
1062             }
1063         }
1064
1065       mode = TYPE_MODE (type);
1066       unsignedp = TYPE_UNSIGNED (type);
1067
1068       if (targetm.calls.promote_function_args (fndecl ? TREE_TYPE (fndecl) : 0))
1069         mode = promote_mode (type, mode, &unsignedp, 1);
1070
1071       args[i].unsignedp = unsignedp;
1072       args[i].mode = mode;
1073
1074       args[i].reg = FUNCTION_ARG (*args_so_far, mode, type,
1075                                   argpos < n_named_args);
1076 #ifdef FUNCTION_INCOMING_ARG
1077       /* If this is a sibling call and the machine has register windows, the
1078          register window has to be unwinded before calling the routine, so
1079          arguments have to go into the incoming registers.  */
1080       args[i].tail_call_reg = FUNCTION_INCOMING_ARG (*args_so_far, mode, type,
1081                                                      argpos < n_named_args);
1082 #else
1083       args[i].tail_call_reg = args[i].reg;
1084 #endif
1085
1086       if (args[i].reg)
1087         args[i].partial
1088           = FUNCTION_ARG_PARTIAL_NREGS (*args_so_far, mode, type,
1089                                         argpos < n_named_args);
1090
1091       args[i].pass_on_stack = targetm.calls.must_pass_in_stack (mode, type);
1092
1093       /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1094          it means that we are to pass this arg in the register(s) designated
1095          by the PARALLEL, but also to pass it in the stack.  */
1096       if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1097           && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1098         args[i].pass_on_stack = 1;
1099
1100       /* If this is an addressable type, we must preallocate the stack
1101          since we must evaluate the object into its final location.
1102
1103          If this is to be passed in both registers and the stack, it is simpler
1104          to preallocate.  */
1105       if (TREE_ADDRESSABLE (type)
1106           || (args[i].pass_on_stack && args[i].reg != 0))
1107         *must_preallocate = 1;
1108
1109       /* If this is an addressable type, we cannot pre-evaluate it.  Thus,
1110          we cannot consider this function call constant.  */
1111       if (TREE_ADDRESSABLE (type))
1112         *ecf_flags &= ~ECF_LIBCALL_BLOCK;
1113
1114       /* Compute the stack-size of this argument.  */
1115       if (args[i].reg == 0 || args[i].partial != 0
1116           || reg_parm_stack_space > 0
1117           || args[i].pass_on_stack)
1118         locate_and_pad_parm (mode, type,
1119 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1120                              1,
1121 #else
1122                              args[i].reg != 0,
1123 #endif
1124                              args[i].pass_on_stack ? 0 : args[i].partial,
1125                              fndecl, args_size, &args[i].locate);
1126 #ifdef BLOCK_REG_PADDING
1127       else
1128         /* The argument is passed entirely in registers.  See at which
1129            end it should be padded.  */
1130         args[i].locate.where_pad =
1131           BLOCK_REG_PADDING (mode, type,
1132                              int_size_in_bytes (type) <= UNITS_PER_WORD);
1133 #endif
1134
1135       /* Update ARGS_SIZE, the total stack space for args so far.  */
1136
1137       args_size->constant += args[i].locate.size.constant;
1138       if (args[i].locate.size.var)
1139         ADD_PARM_SIZE (*args_size, args[i].locate.size.var);
1140
1141       /* Increment ARGS_SO_FAR, which has info about which arg-registers
1142          have been used, etc.  */
1143
1144       FUNCTION_ARG_ADVANCE (*args_so_far, TYPE_MODE (type), type,
1145                             argpos < n_named_args);
1146     }
1147 }
1148
1149 /* Update ARGS_SIZE to contain the total size for the argument block.
1150    Return the original constant component of the argument block's size.
1151
1152    REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1153    for arguments passed in registers.  */
1154
1155 static int
1156 compute_argument_block_size (int reg_parm_stack_space,
1157                              struct args_size *args_size,
1158                              int preferred_stack_boundary ATTRIBUTE_UNUSED)
1159 {
1160   int unadjusted_args_size = args_size->constant;
1161
1162   /* For accumulate outgoing args mode we don't need to align, since the frame
1163      will be already aligned.  Align to STACK_BOUNDARY in order to prevent
1164      backends from generating misaligned frame sizes.  */
1165   if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY)
1166     preferred_stack_boundary = STACK_BOUNDARY;
1167
1168   /* Compute the actual size of the argument block required.  The variable
1169      and constant sizes must be combined, the size may have to be rounded,
1170      and there may be a minimum required size.  */
1171
1172   if (args_size->var)
1173     {
1174       args_size->var = ARGS_SIZE_TREE (*args_size);
1175       args_size->constant = 0;
1176
1177       preferred_stack_boundary /= BITS_PER_UNIT;
1178       if (preferred_stack_boundary > 1)
1179         {
1180           /* We don't handle this case yet.  To handle it correctly we have
1181              to add the delta, round and subtract the delta.
1182              Currently no machine description requires this support.  */
1183           if (stack_pointer_delta & (preferred_stack_boundary - 1))
1184             abort ();
1185           args_size->var = round_up (args_size->var, preferred_stack_boundary);
1186         }
1187
1188       if (reg_parm_stack_space > 0)
1189         {
1190           args_size->var
1191             = size_binop (MAX_EXPR, args_size->var,
1192                           ssize_int (reg_parm_stack_space));
1193
1194 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1195           /* The area corresponding to register parameters is not to count in
1196              the size of the block we need.  So make the adjustment.  */
1197           args_size->var
1198             = size_binop (MINUS_EXPR, args_size->var,
1199                           ssize_int (reg_parm_stack_space));
1200 #endif
1201         }
1202     }
1203   else
1204     {
1205       preferred_stack_boundary /= BITS_PER_UNIT;
1206       if (preferred_stack_boundary < 1)
1207         preferred_stack_boundary = 1;
1208       args_size->constant = (((args_size->constant
1209                                + stack_pointer_delta
1210                                + preferred_stack_boundary - 1)
1211                               / preferred_stack_boundary
1212                               * preferred_stack_boundary)
1213                              - stack_pointer_delta);
1214
1215       args_size->constant = MAX (args_size->constant,
1216                                  reg_parm_stack_space);
1217
1218 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1219       args_size->constant -= reg_parm_stack_space;
1220 #endif
1221     }
1222   return unadjusted_args_size;
1223 }
1224
1225 /* Precompute parameters as needed for a function call.
1226
1227    FLAGS is mask of ECF_* constants.
1228
1229    NUM_ACTUALS is the number of arguments.
1230
1231    ARGS is an array containing information for each argument; this
1232    routine fills in the INITIAL_VALUE and VALUE fields for each
1233    precomputed argument.  */
1234
1235 static void
1236 precompute_arguments (int flags, int num_actuals, struct arg_data *args)
1237 {
1238   int i;
1239
1240   /* If this is a libcall, then precompute all arguments so that we do not
1241      get extraneous instructions emitted as part of the libcall sequence.  */
1242   if ((flags & ECF_LIBCALL_BLOCK) == 0)
1243     return;
1244
1245   for (i = 0; i < num_actuals; i++)
1246     {
1247       enum machine_mode mode;
1248
1249       /* If this is an addressable type, we cannot pre-evaluate it.  */
1250       if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))
1251         abort ();
1252
1253       args[i].initial_value = args[i].value
1254         = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1255
1256       mode = TYPE_MODE (TREE_TYPE (args[i].tree_value));
1257       if (mode != args[i].mode)
1258         {
1259           args[i].value
1260             = convert_modes (args[i].mode, mode,
1261                              args[i].value, args[i].unsignedp);
1262 #if defined(PROMOTE_FUNCTION_MODE) && !defined(PROMOTE_MODE)
1263           /* CSE will replace this only if it contains args[i].value
1264              pseudo, so convert it down to the declared mode using
1265              a SUBREG.  */
1266           if (REG_P (args[i].value)
1267               && GET_MODE_CLASS (args[i].mode) == MODE_INT)
1268             {
1269               args[i].initial_value
1270                 = gen_lowpart_SUBREG (mode, args[i].value);
1271               SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1272               SUBREG_PROMOTED_UNSIGNED_SET (args[i].initial_value,
1273                                             args[i].unsignedp);
1274             }
1275 #endif
1276         }
1277     }
1278 }
1279
1280 /* Given the current state of MUST_PREALLOCATE and information about
1281    arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1282    compute and return the final value for MUST_PREALLOCATE.  */
1283
1284 static int
1285 finalize_must_preallocate (int must_preallocate, int num_actuals, struct arg_data *args, struct args_size *args_size)
1286 {
1287   /* See if we have or want to preallocate stack space.
1288
1289      If we would have to push a partially-in-regs parm
1290      before other stack parms, preallocate stack space instead.
1291
1292      If the size of some parm is not a multiple of the required stack
1293      alignment, we must preallocate.
1294
1295      If the total size of arguments that would otherwise create a copy in
1296      a temporary (such as a CALL) is more than half the total argument list
1297      size, preallocation is faster.
1298
1299      Another reason to preallocate is if we have a machine (like the m88k)
1300      where stack alignment is required to be maintained between every
1301      pair of insns, not just when the call is made.  However, we assume here
1302      that such machines either do not have push insns (and hence preallocation
1303      would occur anyway) or the problem is taken care of with
1304      PUSH_ROUNDING.  */
1305
1306   if (! must_preallocate)
1307     {
1308       int partial_seen = 0;
1309       int copy_to_evaluate_size = 0;
1310       int i;
1311
1312       for (i = 0; i < num_actuals && ! must_preallocate; i++)
1313         {
1314           if (args[i].partial > 0 && ! args[i].pass_on_stack)
1315             partial_seen = 1;
1316           else if (partial_seen && args[i].reg == 0)
1317             must_preallocate = 1;
1318
1319           if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1320               && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1321                   || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1322                   || TREE_CODE (args[i].tree_value) == COND_EXPR
1323                   || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1324             copy_to_evaluate_size
1325               += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1326         }
1327
1328       if (copy_to_evaluate_size * 2 >= args_size->constant
1329           && args_size->constant > 0)
1330         must_preallocate = 1;
1331     }
1332   return must_preallocate;
1333 }
1334
1335 /* If we preallocated stack space, compute the address of each argument
1336    and store it into the ARGS array.
1337
1338    We need not ensure it is a valid memory address here; it will be
1339    validized when it is used.
1340
1341    ARGBLOCK is an rtx for the address of the outgoing arguments.  */
1342
1343 static void
1344 compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals)
1345 {
1346   if (argblock)
1347     {
1348       rtx arg_reg = argblock;
1349       int i, arg_offset = 0;
1350
1351       if (GET_CODE (argblock) == PLUS)
1352         arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1353
1354       for (i = 0; i < num_actuals; i++)
1355         {
1356           rtx offset = ARGS_SIZE_RTX (args[i].locate.offset);
1357           rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
1358           rtx addr;
1359
1360           /* Skip this parm if it will not be passed on the stack.  */
1361           if (! args[i].pass_on_stack && args[i].reg != 0)
1362             continue;
1363
1364           if (GET_CODE (offset) == CONST_INT)
1365             addr = plus_constant (arg_reg, INTVAL (offset));
1366           else
1367             addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1368
1369           addr = plus_constant (addr, arg_offset);
1370           args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1371           set_mem_align (args[i].stack, PARM_BOUNDARY);
1372           set_mem_attributes (args[i].stack,
1373                               TREE_TYPE (args[i].tree_value), 1);
1374
1375           if (GET_CODE (slot_offset) == CONST_INT)
1376             addr = plus_constant (arg_reg, INTVAL (slot_offset));
1377           else
1378             addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1379
1380           addr = plus_constant (addr, arg_offset);
1381           args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1382           set_mem_align (args[i].stack_slot, PARM_BOUNDARY);
1383           set_mem_attributes (args[i].stack_slot,
1384                               TREE_TYPE (args[i].tree_value), 1);
1385
1386           /* Function incoming arguments may overlap with sibling call
1387              outgoing arguments and we cannot allow reordering of reads
1388              from function arguments with stores to outgoing arguments
1389              of sibling calls.  */
1390           set_mem_alias_set (args[i].stack, 0);
1391           set_mem_alias_set (args[i].stack_slot, 0);
1392         }
1393     }
1394 }
1395
1396 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1397    in a call instruction.
1398
1399    FNDECL is the tree node for the target function.  For an indirect call
1400    FNDECL will be NULL_TREE.
1401
1402    ADDR is the operand 0 of CALL_EXPR for this call.  */
1403
1404 static rtx
1405 rtx_for_function_call (tree fndecl, tree addr)
1406 {
1407   rtx funexp;
1408
1409   /* Get the function to call, in the form of RTL.  */
1410   if (fndecl)
1411     {
1412       /* If this is the first use of the function, see if we need to
1413          make an external definition for it.  */
1414       if (! TREE_USED (fndecl))
1415         {
1416           assemble_external (fndecl);
1417           TREE_USED (fndecl) = 1;
1418         }
1419
1420       /* Get a SYMBOL_REF rtx for the function address.  */
1421       funexp = XEXP (DECL_RTL (fndecl), 0);
1422     }
1423   else
1424     /* Generate an rtx (probably a pseudo-register) for the address.  */
1425     {
1426       push_temp_slots ();
1427       funexp = expand_expr (addr, NULL_RTX, VOIDmode, 0);
1428       pop_temp_slots ();        /* FUNEXP can't be BLKmode.  */
1429     }
1430   return funexp;
1431 }
1432
1433 /* Do the register loads required for any wholly-register parms or any
1434    parms which are passed both on the stack and in a register.  Their
1435    expressions were already evaluated.
1436
1437    Mark all register-parms as living through the call, putting these USE
1438    insns in the CALL_INSN_FUNCTION_USAGE field.
1439
1440    When IS_SIBCALL, perform the check_sibcall_overlap_argument_overlap
1441    checking, setting *SIBCALL_FAILURE if appropriate.  */
1442
1443 static void
1444 load_register_parameters (struct arg_data *args, int num_actuals,
1445                           rtx *call_fusage, int flags, int is_sibcall,
1446                           int *sibcall_failure)
1447 {
1448   int i, j;
1449
1450   for (i = 0; i < num_actuals; i++)
1451     {
1452       rtx reg = ((flags & ECF_SIBCALL)
1453                  ? args[i].tail_call_reg : args[i].reg);
1454       if (reg)
1455         {
1456           int partial = args[i].partial;
1457           int nregs;
1458           int size = 0;
1459           rtx before_arg = get_last_insn ();
1460           /* Set to non-negative if must move a word at a time, even if just
1461              one word (e.g, partial == 1 && mode == DFmode).  Set to -1 if
1462              we just use a normal move insn.  This value can be zero if the
1463              argument is a zero size structure with no fields.  */
1464           nregs = -1;
1465           if (partial)
1466             nregs = partial;
1467           else if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode)
1468             {
1469               size = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1470               nregs = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
1471             }
1472           else
1473             size = GET_MODE_SIZE (args[i].mode);
1474
1475           /* Handle calls that pass values in multiple non-contiguous
1476              locations.  The Irix 6 ABI has examples of this.  */
1477
1478           if (GET_CODE (reg) == PARALLEL)
1479             {
1480               tree type = TREE_TYPE (args[i].tree_value);
1481               emit_group_load (reg, args[i].value, type,
1482                                int_size_in_bytes (type));
1483             }
1484
1485           /* If simple case, just do move.  If normal partial, store_one_arg
1486              has already loaded the register for us.  In all other cases,
1487              load the register(s) from memory.  */
1488
1489           else if (nregs == -1)
1490             {
1491               emit_move_insn (reg, args[i].value);
1492 #ifdef BLOCK_REG_PADDING
1493               /* Handle case where we have a value that needs shifting
1494                  up to the msb.  eg. a QImode value and we're padding
1495                  upward on a BYTES_BIG_ENDIAN machine.  */
1496               if (size < UNITS_PER_WORD
1497                   && (args[i].locate.where_pad
1498                       == (BYTES_BIG_ENDIAN ? upward : downward)))
1499                 {
1500                   rtx x;
1501                   int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
1502
1503                   /* Assigning REG here rather than a temp makes CALL_FUSAGE
1504                      report the whole reg as used.  Strictly speaking, the
1505                      call only uses SIZE bytes at the msb end, but it doesn't
1506                      seem worth generating rtl to say that.  */
1507                   reg = gen_rtx_REG (word_mode, REGNO (reg));
1508                   x = expand_shift (LSHIFT_EXPR, word_mode, reg,
1509                                     build_int_2 (shift, 0), reg, 1);
1510                   if (x != reg)
1511                     emit_move_insn (reg, x);
1512                 }
1513 #endif
1514             }
1515
1516           /* If we have pre-computed the values to put in the registers in
1517              the case of non-aligned structures, copy them in now.  */
1518
1519           else if (args[i].n_aligned_regs != 0)
1520             for (j = 0; j < args[i].n_aligned_regs; j++)
1521               emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
1522                               args[i].aligned_regs[j]);
1523
1524           else if (partial == 0 || args[i].pass_on_stack)
1525             {
1526               rtx mem = validize_mem (args[i].value);
1527
1528               /* Handle a BLKmode that needs shifting.  */
1529               if (nregs == 1 && size < UNITS_PER_WORD
1530 #ifdef BLOCK_REG_PADDING
1531                   && args[i].locate.where_pad == downward
1532 #else
1533                   && BYTES_BIG_ENDIAN
1534 #endif
1535                  )
1536                 {
1537                   rtx tem = operand_subword_force (mem, 0, args[i].mode);
1538                   rtx ri = gen_rtx_REG (word_mode, REGNO (reg));
1539                   rtx x = gen_reg_rtx (word_mode);
1540                   int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
1541                   enum tree_code dir = BYTES_BIG_ENDIAN ? RSHIFT_EXPR
1542                                                         : LSHIFT_EXPR;
1543
1544                   emit_move_insn (x, tem);
1545                   x = expand_shift (dir, word_mode, x,
1546                                     build_int_2 (shift, 0), ri, 1);
1547                   if (x != ri)
1548                     emit_move_insn (ri, x);
1549                 }
1550               else
1551                 move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode);
1552             }
1553
1554           /* When a parameter is a block, and perhaps in other cases, it is
1555              possible that it did a load from an argument slot that was
1556              already clobbered.  */
1557           if (is_sibcall
1558               && check_sibcall_argument_overlap (before_arg, &args[i], 0))
1559             *sibcall_failure = 1;
1560
1561           /* Handle calls that pass values in multiple non-contiguous
1562              locations.  The Irix 6 ABI has examples of this.  */
1563           if (GET_CODE (reg) == PARALLEL)
1564             use_group_regs (call_fusage, reg);
1565           else if (nregs == -1)
1566             use_reg (call_fusage, reg);
1567           else
1568             use_regs (call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1569         }
1570     }
1571 }
1572
1573 /* We need to pop PENDING_STACK_ADJUST bytes.  But, if the arguments
1574    wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
1575    bytes, then we would need to push some additional bytes to pad the
1576    arguments.  So, we compute an adjust to the stack pointer for an
1577    amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
1578    bytes.  Then, when the arguments are pushed the stack will be perfectly
1579    aligned.  ARGS_SIZE->CONSTANT is set to the number of bytes that should
1580    be popped after the call.  Returns the adjustment.  */
1581
1582 static int
1583 combine_pending_stack_adjustment_and_call (int unadjusted_args_size,
1584                                            struct args_size *args_size,
1585                                            int preferred_unit_stack_boundary)
1586 {
1587   /* The number of bytes to pop so that the stack will be
1588      under-aligned by UNADJUSTED_ARGS_SIZE bytes.  */
1589   HOST_WIDE_INT adjustment;
1590   /* The alignment of the stack after the arguments are pushed, if we
1591      just pushed the arguments without adjust the stack here.  */
1592   HOST_WIDE_INT unadjusted_alignment;
1593
1594   unadjusted_alignment
1595     = ((stack_pointer_delta + unadjusted_args_size)
1596        % preferred_unit_stack_boundary);
1597
1598   /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
1599      as possible -- leaving just enough left to cancel out the
1600      UNADJUSTED_ALIGNMENT.  In other words, we want to ensure that the
1601      PENDING_STACK_ADJUST is non-negative, and congruent to
1602      -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY.  */
1603
1604   /* Begin by trying to pop all the bytes.  */
1605   unadjusted_alignment
1606     = (unadjusted_alignment
1607        - (pending_stack_adjust % preferred_unit_stack_boundary));
1608   adjustment = pending_stack_adjust;
1609   /* Push enough additional bytes that the stack will be aligned
1610      after the arguments are pushed.  */
1611   if (preferred_unit_stack_boundary > 1)
1612     {
1613       if (unadjusted_alignment > 0)
1614         adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
1615       else
1616         adjustment += unadjusted_alignment;
1617     }
1618
1619   /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
1620      bytes after the call.  The right number is the entire
1621      PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
1622      by the arguments in the first place.  */
1623   args_size->constant
1624     = pending_stack_adjust - adjustment + unadjusted_args_size;
1625
1626   return adjustment;
1627 }
1628
1629 /* Scan X expression if it does not dereference any argument slots
1630    we already clobbered by tail call arguments (as noted in stored_args_map
1631    bitmap).
1632    Return nonzero if X expression dereferences such argument slots,
1633    zero otherwise.  */
1634
1635 static int
1636 check_sibcall_argument_overlap_1 (rtx x)
1637 {
1638   RTX_CODE code;
1639   int i, j;
1640   unsigned int k;
1641   const char *fmt;
1642
1643   if (x == NULL_RTX)
1644     return 0;
1645
1646   code = GET_CODE (x);
1647
1648   if (code == MEM)
1649     {
1650       if (XEXP (x, 0) == current_function_internal_arg_pointer)
1651         i = 0;
1652       else if (GET_CODE (XEXP (x, 0)) == PLUS
1653                && XEXP (XEXP (x, 0), 0) ==
1654                   current_function_internal_arg_pointer
1655                && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1656         i = INTVAL (XEXP (XEXP (x, 0), 1));
1657       else
1658         return 1;
1659
1660 #ifdef ARGS_GROW_DOWNWARD
1661       i = -i - GET_MODE_SIZE (GET_MODE (x));
1662 #endif
1663
1664       for (k = 0; k < GET_MODE_SIZE (GET_MODE (x)); k++)
1665         if (i + k < stored_args_map->n_bits
1666             && TEST_BIT (stored_args_map, i + k))
1667           return 1;
1668
1669       return 0;
1670     }
1671
1672   /* Scan all subexpressions.  */
1673   fmt = GET_RTX_FORMAT (code);
1674   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
1675     {
1676       if (*fmt == 'e')
1677         {
1678           if (check_sibcall_argument_overlap_1 (XEXP (x, i)))
1679             return 1;
1680         }
1681       else if (*fmt == 'E')
1682         {
1683           for (j = 0; j < XVECLEN (x, i); j++)
1684             if (check_sibcall_argument_overlap_1 (XVECEXP (x, i, j)))
1685               return 1;
1686         }
1687     }
1688   return 0;
1689 }
1690
1691 /* Scan sequence after INSN if it does not dereference any argument slots
1692    we already clobbered by tail call arguments (as noted in stored_args_map
1693    bitmap).  If MARK_STORED_ARGS_MAP, add stack slots for ARG to
1694    stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
1695    should be 0).  Return nonzero if sequence after INSN dereferences such argument
1696    slots, zero otherwise.  */
1697
1698 static int
1699 check_sibcall_argument_overlap (rtx insn, struct arg_data *arg, int mark_stored_args_map)
1700 {
1701   int low, high;
1702
1703   if (insn == NULL_RTX)
1704     insn = get_insns ();
1705   else
1706     insn = NEXT_INSN (insn);
1707
1708   for (; insn; insn = NEXT_INSN (insn))
1709     if (INSN_P (insn)
1710         && check_sibcall_argument_overlap_1 (PATTERN (insn)))
1711       break;
1712
1713   if (mark_stored_args_map)
1714     {
1715 #ifdef ARGS_GROW_DOWNWARD
1716       low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
1717 #else
1718       low = arg->locate.slot_offset.constant;
1719 #endif
1720
1721       for (high = low + arg->locate.size.constant; low < high; low++)
1722         SET_BIT (stored_args_map, low);
1723     }
1724   return insn != NULL_RTX;
1725 }
1726
1727 static tree
1728 fix_unsafe_tree (tree t)
1729 {
1730   switch (unsafe_for_reeval (t))
1731     {
1732     case 0: /* Safe.  */
1733       break;
1734
1735     case 1: /* Mildly unsafe.  */
1736       t = unsave_expr (t);
1737       break;
1738
1739     case 2: /* Wildly unsafe.  */
1740       {
1741         tree var = build_decl (VAR_DECL, NULL_TREE,
1742                                TREE_TYPE (t));
1743         SET_DECL_RTL (var,
1744                       expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL));
1745         t = var;
1746       }
1747       break;
1748
1749     default:
1750       abort ();
1751     }
1752   return t;
1753 }
1754
1755
1756 /* If function value *VALUE was returned at the most significant end of a
1757    register, shift it towards the least significant end and convert it to
1758    TYPE's mode.  Return true and update *VALUE if some action was needed.
1759
1760    TYPE is the type of the function's return value, which is known not
1761    to have mode BLKmode.  */
1762
1763 static bool
1764 shift_returned_value (tree type, rtx *value)
1765 {
1766   if (targetm.calls.return_in_msb (type))
1767     {
1768       HOST_WIDE_INT shift;
1769
1770       shift = (GET_MODE_BITSIZE (GET_MODE (*value))
1771                - BITS_PER_UNIT * int_size_in_bytes (type));
1772       if (shift > 0)
1773         {
1774           /* Shift the value into the low part of the register.  */
1775           *value = expand_binop (GET_MODE (*value), lshr_optab, *value,
1776                                  GEN_INT (shift), 0, 1, OPTAB_WIDEN);
1777
1778           /* Truncate it to the type's mode, or its integer equivalent.
1779              This is subject to TRULY_NOOP_TRUNCATION.  */
1780           *value = convert_to_mode (int_mode_for_mode (TYPE_MODE (type)),
1781                                     *value, 0);
1782
1783           /* Now convert it to the final form.  */
1784           *value = gen_lowpart (TYPE_MODE (type), *value);
1785           return true;
1786         }
1787     }
1788   return false;
1789 }
1790
1791 /* Remove all REG_EQUIV notes found in the insn chain.  */
1792
1793 static void
1794 purge_reg_equiv_notes (void)
1795 {
1796   rtx insn;
1797
1798   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
1799     {
1800       while (1)
1801         {
1802           rtx note = find_reg_note (insn, REG_EQUIV, 0);
1803           if (note)
1804             {
1805               /* Remove the note and keep looking at the notes for
1806                  this insn.  */
1807               remove_note (insn, note);
1808               continue;
1809             }
1810           break;
1811         }
1812     }
1813 }
1814
1815 /* Clear RTX_UNCHANGING_P flag of incoming argument MEMs.  */
1816
1817 static void
1818 purge_mem_unchanging_flag (rtx x)
1819 {
1820   RTX_CODE code;
1821   int i, j;
1822   const char *fmt;
1823
1824   if (x == NULL_RTX)
1825     return;
1826
1827   code = GET_CODE (x);
1828
1829   if (code == MEM)
1830     {
1831       if (RTX_UNCHANGING_P (x)
1832           && (XEXP (x, 0) == current_function_internal_arg_pointer
1833               || (GET_CODE (XEXP (x, 0)) == PLUS
1834                   && XEXP (XEXP (x, 0), 0) ==
1835                      current_function_internal_arg_pointer
1836                   && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)))
1837         RTX_UNCHANGING_P (x) = 0;
1838       return;
1839     }
1840
1841   /* Scan all subexpressions.  */
1842   fmt = GET_RTX_FORMAT (code);
1843   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
1844     {
1845       if (*fmt == 'e')
1846         purge_mem_unchanging_flag (XEXP (x, i));
1847       else if (*fmt == 'E')
1848         for (j = 0; j < XVECLEN (x, i); j++)
1849           purge_mem_unchanging_flag (XVECEXP (x, i, j));
1850     }
1851 }
1852
1853
1854 /* Generate all the code for a function call
1855    and return an rtx for its value.
1856    Store the value in TARGET (specified as an rtx) if convenient.
1857    If the value is stored in TARGET then TARGET is returned.
1858    If IGNORE is nonzero, then we ignore the value of the function call.  */
1859
1860 rtx
1861 expand_call (tree exp, rtx target, int ignore)
1862 {
1863   /* Nonzero if we are currently expanding a call.  */
1864   static int currently_expanding_call = 0;
1865
1866   /* List of actual parameters.  */
1867   tree actparms = TREE_OPERAND (exp, 1);
1868   /* RTX for the function to be called.  */
1869   rtx funexp;
1870   /* Sequence of insns to perform a normal "call".  */
1871   rtx normal_call_insns = NULL_RTX;
1872   /* Sequence of insns to perform a tail "call".  */
1873   rtx tail_call_insns = NULL_RTX;
1874   /* Data type of the function.  */
1875   tree funtype;
1876   tree type_arg_types;
1877   /* Declaration of the function being called,
1878      or 0 if the function is computed (not known by name).  */
1879   tree fndecl = 0;
1880   /* The type of the function being called.  */
1881   tree fntype;
1882   bool try_tail_call = CALL_EXPR_TAILCALL (exp);
1883   int pass;
1884
1885   /* Register in which non-BLKmode value will be returned,
1886      or 0 if no value or if value is BLKmode.  */
1887   rtx valreg;
1888   /* Address where we should return a BLKmode value;
1889      0 if value not BLKmode.  */
1890   rtx structure_value_addr = 0;
1891   /* Nonzero if that address is being passed by treating it as
1892      an extra, implicit first parameter.  Otherwise,
1893      it is passed by being copied directly into struct_value_rtx.  */
1894   int structure_value_addr_parm = 0;
1895   /* Size of aggregate value wanted, or zero if none wanted
1896      or if we are using the non-reentrant PCC calling convention
1897      or expecting the value in registers.  */
1898   HOST_WIDE_INT struct_value_size = 0;
1899   /* Nonzero if called function returns an aggregate in memory PCC style,
1900      by returning the address of where to find it.  */
1901   int pcc_struct_value = 0;
1902   rtx struct_value = 0;
1903
1904   /* Number of actual parameters in this call, including struct value addr.  */
1905   int num_actuals;
1906   /* Number of named args.  Args after this are anonymous ones
1907      and they must all go on the stack.  */
1908   int n_named_args;
1909
1910   /* Vector of information about each argument.
1911      Arguments are numbered in the order they will be pushed,
1912      not the order they are written.  */
1913   struct arg_data *args;
1914
1915   /* Total size in bytes of all the stack-parms scanned so far.  */
1916   struct args_size args_size;
1917   struct args_size adjusted_args_size;
1918   /* Size of arguments before any adjustments (such as rounding).  */
1919   int unadjusted_args_size;
1920   /* Data on reg parms scanned so far.  */
1921   CUMULATIVE_ARGS args_so_far;
1922   /* Nonzero if a reg parm has been scanned.  */
1923   int reg_parm_seen;
1924   /* Nonzero if this is an indirect function call.  */
1925
1926   /* Nonzero if we must avoid push-insns in the args for this call.
1927      If stack space is allocated for register parameters, but not by the
1928      caller, then it is preallocated in the fixed part of the stack frame.
1929      So the entire argument block must then be preallocated (i.e., we
1930      ignore PUSH_ROUNDING in that case).  */
1931
1932   int must_preallocate = !PUSH_ARGS;
1933
1934   /* Size of the stack reserved for parameter registers.  */
1935   int reg_parm_stack_space = 0;
1936
1937   /* Address of space preallocated for stack parms
1938      (on machines that lack push insns), or 0 if space not preallocated.  */
1939   rtx argblock = 0;
1940
1941   /* Mask of ECF_ flags.  */
1942   int flags = 0;
1943 #ifdef REG_PARM_STACK_SPACE
1944   /* Define the boundary of the register parm stack space that needs to be
1945      saved, if any.  */
1946   int low_to_save, high_to_save;
1947   rtx save_area = 0;            /* Place that it is saved */
1948 #endif
1949
1950   int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
1951   char *initial_stack_usage_map = stack_usage_map;
1952
1953   int old_stack_allocated;
1954
1955   /* State variables to track stack modifications.  */
1956   rtx old_stack_level = 0;
1957   int old_stack_arg_under_construction = 0;
1958   int old_pending_adj = 0;
1959   int old_inhibit_defer_pop = inhibit_defer_pop;
1960
1961   /* Some stack pointer alterations we make are performed via
1962      allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
1963      which we then also need to save/restore along the way.  */
1964   int old_stack_pointer_delta = 0;
1965
1966   rtx call_fusage;
1967   tree p = TREE_OPERAND (exp, 0);
1968   tree addr = TREE_OPERAND (exp, 0);
1969   int i;
1970   /* The alignment of the stack, in bits.  */
1971   HOST_WIDE_INT preferred_stack_boundary;
1972   /* The alignment of the stack, in bytes.  */
1973   HOST_WIDE_INT preferred_unit_stack_boundary;
1974   /* The static chain value to use for this call.  */
1975   rtx static_chain_value;
1976   /* See if this is "nothrow" function call.  */
1977   if (TREE_NOTHROW (exp))
1978     flags |= ECF_NOTHROW;
1979
1980   /* See if we can find a DECL-node for the actual function, and get the
1981      function attributes (flags) from the function decl or type node.  */
1982   fndecl = get_callee_fndecl (exp);
1983   if (fndecl)
1984     {
1985       fntype = TREE_TYPE (fndecl);
1986       flags |= flags_from_decl_or_type (fndecl);
1987     }
1988   else
1989     {
1990       fntype = TREE_TYPE (TREE_TYPE (p));
1991       flags |= flags_from_decl_or_type (fntype);
1992     }
1993
1994   struct_value = targetm.calls.struct_value_rtx (fntype, 0);
1995
1996   /* Warn if this value is an aggregate type,
1997      regardless of which calling convention we are using for it.  */
1998   if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
1999     warning ("function call has aggregate value");
2000
2001   /* If the result of a pure or const function call is ignored (or void),
2002      and none of its arguments are volatile, we can avoid expanding the
2003      call and just evaluate the arguments for side-effects.  */
2004   if ((flags & (ECF_CONST | ECF_PURE))
2005       && (ignore || target == const0_rtx
2006           || TYPE_MODE (TREE_TYPE (exp)) == VOIDmode))
2007     {
2008       bool volatilep = false;
2009       tree arg;
2010
2011       for (arg = actparms; arg; arg = TREE_CHAIN (arg))
2012         if (TREE_THIS_VOLATILE (TREE_VALUE (arg)))
2013           {
2014             volatilep = true;
2015             break;
2016           }
2017
2018       if (! volatilep)
2019         {
2020           for (arg = actparms; arg; arg = TREE_CHAIN (arg))
2021             expand_expr (TREE_VALUE (arg), const0_rtx,
2022                          VOIDmode, EXPAND_NORMAL);
2023           return const0_rtx;
2024         }
2025     }
2026
2027 #ifdef REG_PARM_STACK_SPACE
2028   reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
2029 #endif
2030
2031 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2032   if (reg_parm_stack_space > 0 && PUSH_ARGS)
2033     must_preallocate = 1;
2034 #endif
2035
2036   /* Set up a place to return a structure.  */
2037
2038   /* Cater to broken compilers.  */
2039   if (aggregate_value_p (exp, fndecl))
2040     {
2041       /* This call returns a big structure.  */
2042       flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
2043
2044 #ifdef PCC_STATIC_STRUCT_RETURN
2045       {
2046         pcc_struct_value = 1;
2047       }
2048 #else /* not PCC_STATIC_STRUCT_RETURN */
2049       {
2050         struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
2051
2052         if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (exp))
2053           {
2054             /* The structure value address arg is already in actparms.
2055                Pull it out.  It might be nice to just leave it there, but
2056                we need to set structure_value_addr.  */
2057             tree return_arg = TREE_VALUE (actparms);
2058             actparms = TREE_CHAIN (actparms);
2059             structure_value_addr = expand_expr (return_arg, NULL_RTX,
2060                                                 VOIDmode, EXPAND_NORMAL);
2061           }
2062         else if (target && MEM_P (target))
2063           structure_value_addr = XEXP (target, 0);
2064         else
2065           {
2066             /* For variable-sized objects, we must be called with a target
2067                specified.  If we were to allocate space on the stack here,
2068                we would have no way of knowing when to free it.  */
2069             rtx d = assign_temp (TREE_TYPE (exp), 1, 1, 1);
2070
2071             mark_temp_addr_taken (d);
2072             structure_value_addr = XEXP (d, 0);
2073             target = 0;
2074           }
2075       }
2076 #endif /* not PCC_STATIC_STRUCT_RETURN */
2077     }
2078
2079   /* Figure out the amount to which the stack should be aligned.  */
2080   preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2081   if (fndecl)
2082     {
2083       struct cgraph_rtl_info *i = cgraph_rtl_info (fndecl);
2084       if (i && i->preferred_incoming_stack_boundary)
2085         preferred_stack_boundary = i->preferred_incoming_stack_boundary;
2086     }
2087
2088   /* Operand 0 is a pointer-to-function; get the type of the function.  */
2089   funtype = TREE_TYPE (addr);
2090   if (! POINTER_TYPE_P (funtype))
2091     abort ();
2092   funtype = TREE_TYPE (funtype);
2093
2094   /* Munge the tree to split complex arguments into their imaginary
2095      and real parts.  */
2096   if (targetm.calls.split_complex_arg)
2097     {
2098       type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype));
2099       actparms = split_complex_values (actparms);
2100     }
2101   else
2102     type_arg_types = TYPE_ARG_TYPES (funtype);
2103
2104   if (flags & ECF_MAY_BE_ALLOCA)
2105     current_function_calls_alloca = 1;
2106
2107   /* If struct_value_rtx is 0, it means pass the address
2108      as if it were an extra parameter.  */
2109   if (structure_value_addr && struct_value == 0)
2110     {
2111       /* If structure_value_addr is a REG other than
2112          virtual_outgoing_args_rtx, we can use always use it.  If it
2113          is not a REG, we must always copy it into a register.
2114          If it is virtual_outgoing_args_rtx, we must copy it to another
2115          register in some cases.  */
2116       rtx temp = (!REG_P (structure_value_addr)
2117                   || (ACCUMULATE_OUTGOING_ARGS
2118                       && stack_arg_under_construction
2119                       && structure_value_addr == virtual_outgoing_args_rtx)
2120                   ? copy_addr_to_reg (convert_memory_address
2121                                       (Pmode, structure_value_addr))
2122                   : structure_value_addr);
2123
2124       actparms
2125         = tree_cons (error_mark_node,
2126                      make_tree (build_pointer_type (TREE_TYPE (funtype)),
2127                                 temp),
2128                      actparms);
2129       structure_value_addr_parm = 1;
2130     }
2131
2132   /* Count the arguments and set NUM_ACTUALS.  */
2133   for (p = actparms, num_actuals = 0; p; p = TREE_CHAIN (p))
2134     num_actuals++;
2135
2136   /* Compute number of named args.
2137      First, do a raw count of the args for INIT_CUMULATIVE_ARGS.  */
2138
2139   if (type_arg_types != 0)
2140     n_named_args
2141       = (list_length (type_arg_types)
2142          /* Count the struct value address, if it is passed as a parm.  */
2143          + structure_value_addr_parm);
2144   else
2145     /* If we know nothing, treat all args as named.  */
2146     n_named_args = num_actuals;
2147
2148   /* Start updating where the next arg would go.
2149
2150      On some machines (such as the PA) indirect calls have a different
2151      calling convention than normal calls.  The fourth argument in
2152      INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2153      or not.  */
2154   INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, fndecl, n_named_args);
2155
2156   /* Now possibly adjust the number of named args.
2157      Normally, don't include the last named arg if anonymous args follow.
2158      We do include the last named arg if
2159      targetm.calls.strict_argument_naming() returns nonzero.
2160      (If no anonymous args follow, the result of list_length is actually
2161      one too large.  This is harmless.)
2162
2163      If targetm.calls.pretend_outgoing_varargs_named() returns
2164      nonzero, and targetm.calls.strict_argument_naming() returns zero,
2165      this machine will be able to place unnamed args that were passed
2166      in registers into the stack.  So treat all args as named.  This
2167      allows the insns emitting for a specific argument list to be
2168      independent of the function declaration.
2169
2170      If targetm.calls.pretend_outgoing_varargs_named() returns zero,
2171      we do not have any reliable way to pass unnamed args in
2172      registers, so we must force them into memory.  */
2173
2174   if (type_arg_types != 0
2175       && targetm.calls.strict_argument_naming (&args_so_far))
2176     ;
2177   else if (type_arg_types != 0
2178            && ! targetm.calls.pretend_outgoing_varargs_named (&args_so_far))
2179     /* Don't include the last named arg.  */
2180     --n_named_args;
2181   else
2182     /* Treat all args as named.  */
2183     n_named_args = num_actuals;
2184
2185   /* Make a vector to hold all the information about each arg.  */
2186   args = alloca (num_actuals * sizeof (struct arg_data));
2187   memset (args, 0, num_actuals * sizeof (struct arg_data));
2188
2189   /* Build up entries in the ARGS array, compute the size of the
2190      arguments into ARGS_SIZE, etc.  */
2191   initialize_argument_information (num_actuals, args, &args_size,
2192                                    n_named_args, actparms, fndecl,
2193                                    &args_so_far, reg_parm_stack_space,
2194                                    &old_stack_level, &old_pending_adj,
2195                                    &must_preallocate, &flags,
2196                                    &try_tail_call, CALL_FROM_THUNK_P (exp));
2197
2198   if (args_size.var)
2199     {
2200       /* If this function requires a variable-sized argument list, don't
2201          try to make a cse'able block for this call.  We may be able to
2202          do this eventually, but it is too complicated to keep track of
2203          what insns go in the cse'able block and which don't.  */
2204
2205       flags &= ~ECF_LIBCALL_BLOCK;
2206       must_preallocate = 1;
2207     }
2208
2209   /* Now make final decision about preallocating stack space.  */
2210   must_preallocate = finalize_must_preallocate (must_preallocate,
2211                                                 num_actuals, args,
2212                                                 &args_size);
2213
2214   /* If the structure value address will reference the stack pointer, we
2215      must stabilize it.  We don't need to do this if we know that we are
2216      not going to adjust the stack pointer in processing this call.  */
2217
2218   if (structure_value_addr
2219       && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
2220           || reg_mentioned_p (virtual_outgoing_args_rtx,
2221                               structure_value_addr))
2222       && (args_size.var
2223           || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant)))
2224     structure_value_addr = copy_to_reg (structure_value_addr);
2225
2226   /* Tail calls can make things harder to debug, and we've traditionally
2227      pushed these optimizations into -O2.  Don't try if we're already
2228      expanding a call, as that means we're an argument.  Don't try if
2229      there's cleanups, as we know there's code to follow the call.
2230
2231      If rtx_equal_function_value_matters is false, that means we've
2232      finished with regular parsing.  Which means that some of the
2233      machinery we use to generate tail-calls is no longer in place.
2234      This is most often true of sjlj-exceptions, which we couldn't
2235      tail-call to anyway.
2236
2237      If current_nesting_level () == 0, we're being called after
2238      the function body has been expanded.  This can happen when
2239      setting up trampolines in expand_function_end.  */
2240   if (currently_expanding_call++ != 0
2241       || !flag_optimize_sibling_calls
2242       || !rtx_equal_function_value_matters
2243       || current_nesting_level () == 0
2244       || args_size.var
2245       || lookup_stmt_eh_region (exp) >= 0)
2246     try_tail_call = 0;
2247
2248   /*  Rest of purposes for tail call optimizations to fail.  */
2249   if (
2250 #ifdef HAVE_sibcall_epilogue
2251       !HAVE_sibcall_epilogue
2252 #else
2253       1
2254 #endif
2255       || !try_tail_call
2256       /* Doing sibling call optimization needs some work, since
2257          structure_value_addr can be allocated on the stack.
2258          It does not seem worth the effort since few optimizable
2259          sibling calls will return a structure.  */
2260       || structure_value_addr != NULL_RTX
2261       /* Check whether the target is able to optimize the call
2262          into a sibcall.  */
2263       || !targetm.function_ok_for_sibcall (fndecl, exp)
2264       /* Functions that do not return exactly once may not be sibcall
2265          optimized.  */
2266       || (flags & (ECF_RETURNS_TWICE | ECF_LONGJMP | ECF_NORETURN))
2267       || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr)))
2268       /* If the called function is nested in the current one, it might access
2269          some of the caller's arguments, but could clobber them beforehand if
2270          the argument areas are shared.  */
2271       || (fndecl && decl_function_context (fndecl) == current_function_decl)
2272       /* If this function requires more stack slots than the current
2273          function, we cannot change it into a sibling call.  */
2274       || args_size.constant > current_function_args_size
2275       /* If the callee pops its own arguments, then it must pop exactly
2276          the same number of arguments as the current function.  */
2277       || (RETURN_POPS_ARGS (fndecl, funtype, args_size.constant)
2278           != RETURN_POPS_ARGS (current_function_decl,
2279                                TREE_TYPE (current_function_decl),
2280                                current_function_args_size))
2281       || !lang_hooks.decls.ok_for_sibcall (fndecl))
2282     try_tail_call = 0;
2283
2284   if (try_tail_call)
2285     {
2286       int end, inc;
2287       actparms = NULL_TREE;
2288       /* Ok, we're going to give the tail call the old college try.
2289          This means we're going to evaluate the function arguments
2290          up to three times.  There are two degrees of badness we can
2291          encounter, those that can be unsaved and those that can't.
2292          (See unsafe_for_reeval commentary for details.)
2293
2294          Generate a new argument list.  Pass safe arguments through
2295          unchanged.  For the easy badness wrap them in UNSAVE_EXPRs.
2296          For hard badness, evaluate them now and put their resulting
2297          rtx in a temporary VAR_DECL.
2298
2299          initialize_argument_information has ordered the array for the
2300          order to be pushed, and we must remember this when reconstructing
2301          the original argument order.  */
2302
2303       if (PUSH_ARGS_REVERSED)
2304         {
2305           inc = 1;
2306           i = 0;
2307           end = num_actuals;
2308         }
2309       else
2310         {
2311           inc = -1;
2312           i = num_actuals - 1;
2313           end = -1;
2314         }
2315
2316       for (; i != end; i += inc)
2317         {
2318           args[i].tree_value = fix_unsafe_tree (args[i].tree_value);
2319         }
2320       /* Do the same for the function address if it is an expression.  */
2321       if (!fndecl)
2322         addr = fix_unsafe_tree (addr);
2323     }
2324
2325
2326   /* Ensure current function's preferred stack boundary is at least
2327      what we need.  We don't have to increase alignment for recursive
2328      functions.  */
2329   if (cfun->preferred_stack_boundary < preferred_stack_boundary
2330       && fndecl != current_function_decl)
2331     cfun->preferred_stack_boundary = preferred_stack_boundary;
2332   if (fndecl == current_function_decl)
2333     cfun->recursive_call_emit = true;
2334
2335   preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
2336
2337   /* We want to make two insn chains; one for a sibling call, the other
2338      for a normal call.  We will select one of the two chains after
2339      initial RTL generation is complete.  */
2340   for (pass = try_tail_call ? 0 : 1; pass < 2; pass++)
2341     {
2342       int sibcall_failure = 0;
2343       /* We want to emit any pending stack adjustments before the tail
2344          recursion "call".  That way we know any adjustment after the tail
2345          recursion call can be ignored if we indeed use the tail
2346          call expansion.  */
2347       int save_pending_stack_adjust = 0;
2348       int save_stack_pointer_delta = 0;
2349       rtx insns;
2350       rtx before_call, next_arg_reg;
2351
2352       if (pass == 0)
2353         {
2354           /* State variables we need to save and restore between
2355              iterations.  */
2356           save_pending_stack_adjust = pending_stack_adjust;
2357           save_stack_pointer_delta = stack_pointer_delta;
2358         }
2359       if (pass)
2360         flags &= ~ECF_SIBCALL;
2361       else
2362         flags |= ECF_SIBCALL;
2363
2364       /* Other state variables that we must reinitialize each time
2365          through the loop (that are not initialized by the loop itself).  */
2366       argblock = 0;
2367       call_fusage = 0;
2368
2369       /* Start a new sequence for the normal call case.
2370
2371          From this point on, if the sibling call fails, we want to set
2372          sibcall_failure instead of continuing the loop.  */
2373       start_sequence ();
2374
2375       if (pass == 0)
2376         {
2377           /* We know at this point that there are not currently any
2378              pending cleanups.  If, however, in the process of evaluating
2379              the arguments we were to create some, we'll need to be
2380              able to get rid of them.  */
2381           expand_start_target_temps ();
2382         }
2383
2384       /* Don't let pending stack adjusts add up to too much.
2385          Also, do all pending adjustments now if there is any chance
2386          this might be a call to alloca or if we are expanding a sibling
2387          call sequence or if we are calling a function that is to return
2388          with stack pointer depressed.  */
2389       if (pending_stack_adjust >= 32
2390           || (pending_stack_adjust > 0
2391               && (flags & (ECF_MAY_BE_ALLOCA | ECF_SP_DEPRESSED)))
2392           || pass == 0)
2393         do_pending_stack_adjust ();
2394
2395       /* When calling a const function, we must pop the stack args right away,
2396          so that the pop is deleted or moved with the call.  */
2397       if (pass && (flags & ECF_LIBCALL_BLOCK))
2398         NO_DEFER_POP;
2399
2400       /* Precompute any arguments as needed.  */
2401       if (pass)
2402         precompute_arguments (flags, num_actuals, args);
2403
2404       /* Now we are about to start emitting insns that can be deleted
2405          if a libcall is deleted.  */
2406       if (pass && (flags & (ECF_LIBCALL_BLOCK | ECF_MALLOC)))
2407         start_sequence ();
2408
2409       adjusted_args_size = args_size;
2410       /* Compute the actual size of the argument block required.  The variable
2411          and constant sizes must be combined, the size may have to be rounded,
2412          and there may be a minimum required size.  When generating a sibcall
2413          pattern, do not round up, since we'll be re-using whatever space our
2414          caller provided.  */
2415       unadjusted_args_size
2416         = compute_argument_block_size (reg_parm_stack_space,
2417                                        &adjusted_args_size,
2418                                        (pass == 0 ? 0
2419                                         : preferred_stack_boundary));
2420
2421       old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
2422
2423       /* The argument block when performing a sibling call is the
2424          incoming argument block.  */
2425       if (pass == 0)
2426         {
2427           argblock = virtual_incoming_args_rtx;
2428           argblock
2429 #ifdef STACK_GROWS_DOWNWARD
2430             = plus_constant (argblock, current_function_pretend_args_size);
2431 #else
2432             = plus_constant (argblock, -current_function_pretend_args_size);
2433 #endif
2434           stored_args_map = sbitmap_alloc (args_size.constant);
2435           sbitmap_zero (stored_args_map);
2436         }
2437
2438       /* If we have no actual push instructions, or shouldn't use them,
2439          make space for all args right now.  */
2440       else if (adjusted_args_size.var != 0)
2441         {
2442           if (old_stack_level == 0)
2443             {
2444               emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2445               old_stack_pointer_delta = stack_pointer_delta;
2446               old_pending_adj = pending_stack_adjust;
2447               pending_stack_adjust = 0;
2448               /* stack_arg_under_construction says whether a stack arg is
2449                  being constructed at the old stack level.  Pushing the stack
2450                  gets a clean outgoing argument block.  */
2451               old_stack_arg_under_construction = stack_arg_under_construction;
2452               stack_arg_under_construction = 0;
2453             }
2454           argblock = push_block (ARGS_SIZE_RTX (adjusted_args_size), 0, 0);
2455         }
2456       else
2457         {
2458           /* Note that we must go through the motions of allocating an argument
2459              block even if the size is zero because we may be storing args
2460              in the area reserved for register arguments, which may be part of
2461              the stack frame.  */
2462
2463           int needed = adjusted_args_size.constant;
2464
2465           /* Store the maximum argument space used.  It will be pushed by
2466              the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2467              checking).  */
2468
2469           if (needed > current_function_outgoing_args_size)
2470             current_function_outgoing_args_size = needed;
2471
2472           if (must_preallocate)
2473             {
2474               if (ACCUMULATE_OUTGOING_ARGS)
2475                 {
2476                   /* Since the stack pointer will never be pushed, it is
2477                      possible for the evaluation of a parm to clobber
2478                      something we have already written to the stack.
2479                      Since most function calls on RISC machines do not use
2480                      the stack, this is uncommon, but must work correctly.
2481
2482                      Therefore, we save any area of the stack that was already
2483                      written and that we are using.  Here we set up to do this
2484                      by making a new stack usage map from the old one.  The
2485                      actual save will be done by store_one_arg.
2486
2487                      Another approach might be to try to reorder the argument
2488                      evaluations to avoid this conflicting stack usage.  */
2489
2490 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2491                   /* Since we will be writing into the entire argument area,
2492                      the map must be allocated for its entire size, not just
2493                      the part that is the responsibility of the caller.  */
2494                   needed += reg_parm_stack_space;
2495 #endif
2496
2497 #ifdef ARGS_GROW_DOWNWARD
2498                   highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2499                                                      needed + 1);
2500 #else
2501                   highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2502                                                      needed);
2503 #endif
2504                   stack_usage_map = alloca (highest_outgoing_arg_in_use);
2505
2506                   if (initial_highest_arg_in_use)
2507                     memcpy (stack_usage_map, initial_stack_usage_map,
2508                             initial_highest_arg_in_use);
2509
2510                   if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2511                     memset (&stack_usage_map[initial_highest_arg_in_use], 0,
2512                            (highest_outgoing_arg_in_use
2513                             - initial_highest_arg_in_use));
2514                   needed = 0;
2515
2516                   /* The address of the outgoing argument list must not be
2517                      copied to a register here, because argblock would be left
2518                      pointing to the wrong place after the call to
2519                      allocate_dynamic_stack_space below.  */
2520
2521                   argblock = virtual_outgoing_args_rtx;
2522                 }
2523               else
2524                 {
2525                   if (inhibit_defer_pop == 0)
2526                     {
2527                       /* Try to reuse some or all of the pending_stack_adjust
2528                          to get this space.  */
2529                       needed
2530                         = (combine_pending_stack_adjustment_and_call
2531                            (unadjusted_args_size,
2532                             &adjusted_args_size,
2533                             preferred_unit_stack_boundary));
2534
2535                       /* combine_pending_stack_adjustment_and_call computes
2536                          an adjustment before the arguments are allocated.
2537                          Account for them and see whether or not the stack
2538                          needs to go up or down.  */
2539                       needed = unadjusted_args_size - needed;
2540
2541                       if (needed < 0)
2542                         {
2543                           /* We're releasing stack space.  */
2544                           /* ??? We can avoid any adjustment at all if we're
2545                              already aligned.  FIXME.  */
2546                           pending_stack_adjust = -needed;
2547                           do_pending_stack_adjust ();
2548                           needed = 0;
2549                         }
2550                       else
2551                         /* We need to allocate space.  We'll do that in
2552                            push_block below.  */
2553                         pending_stack_adjust = 0;
2554                     }
2555
2556                   /* Special case this because overhead of `push_block' in
2557                      this case is non-trivial.  */
2558                   if (needed == 0)
2559                     argblock = virtual_outgoing_args_rtx;
2560                   else
2561                     {
2562                       argblock = push_block (GEN_INT (needed), 0, 0);
2563 #ifdef ARGS_GROW_DOWNWARD
2564                       argblock = plus_constant (argblock, needed);
2565 #endif
2566                     }
2567
2568                   /* We only really need to call `copy_to_reg' in the case
2569                      where push insns are going to be used to pass ARGBLOCK
2570                      to a function call in ARGS.  In that case, the stack
2571                      pointer changes value from the allocation point to the
2572                      call point, and hence the value of
2573                      VIRTUAL_OUTGOING_ARGS_RTX changes as well.  But might
2574                      as well always do it.  */
2575                   argblock = copy_to_reg (argblock);
2576                 }
2577             }
2578         }
2579
2580       if (ACCUMULATE_OUTGOING_ARGS)
2581         {
2582           /* The save/restore code in store_one_arg handles all
2583              cases except one: a constructor call (including a C
2584              function returning a BLKmode struct) to initialize
2585              an argument.  */
2586           if (stack_arg_under_construction)
2587             {
2588 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2589               rtx push_size = GEN_INT (reg_parm_stack_space
2590                                        + adjusted_args_size.constant);
2591 #else
2592               rtx push_size = GEN_INT (adjusted_args_size.constant);
2593 #endif
2594               if (old_stack_level == 0)
2595                 {
2596                   emit_stack_save (SAVE_BLOCK, &old_stack_level,
2597                                    NULL_RTX);
2598                   old_stack_pointer_delta = stack_pointer_delta;
2599                   old_pending_adj = pending_stack_adjust;
2600                   pending_stack_adjust = 0;
2601                   /* stack_arg_under_construction says whether a stack
2602                      arg is being constructed at the old stack level.
2603                      Pushing the stack gets a clean outgoing argument
2604                      block.  */
2605                   old_stack_arg_under_construction
2606                     = stack_arg_under_construction;
2607                   stack_arg_under_construction = 0;
2608                   /* Make a new map for the new argument list.  */
2609                   stack_usage_map = alloca (highest_outgoing_arg_in_use);
2610                   memset (stack_usage_map, 0, highest_outgoing_arg_in_use);
2611                   highest_outgoing_arg_in_use = 0;
2612                 }
2613               allocate_dynamic_stack_space (push_size, NULL_RTX,
2614                                             BITS_PER_UNIT);
2615             }
2616
2617           /* If argument evaluation might modify the stack pointer,
2618              copy the address of the argument list to a register.  */
2619           for (i = 0; i < num_actuals; i++)
2620             if (args[i].pass_on_stack)
2621               {
2622                 argblock = copy_addr_to_reg (argblock);
2623                 break;
2624               }
2625         }
2626
2627       compute_argument_addresses (args, argblock, num_actuals);
2628
2629       /* If we push args individually in reverse order, perform stack alignment
2630          before the first push (the last arg).  */
2631       if (PUSH_ARGS_REVERSED && argblock == 0
2632           && adjusted_args_size.constant != unadjusted_args_size)
2633         {
2634           /* When the stack adjustment is pending, we get better code
2635              by combining the adjustments.  */
2636           if (pending_stack_adjust
2637               && ! (flags & ECF_LIBCALL_BLOCK)
2638               && ! inhibit_defer_pop)
2639             {
2640               pending_stack_adjust
2641                 = (combine_pending_stack_adjustment_and_call
2642                    (unadjusted_args_size,
2643                     &adjusted_args_size,
2644                     preferred_unit_stack_boundary));
2645               do_pending_stack_adjust ();
2646             }
2647           else if (argblock == 0)
2648             anti_adjust_stack (GEN_INT (adjusted_args_size.constant
2649                                         - unadjusted_args_size));
2650         }
2651       /* Now that the stack is properly aligned, pops can't safely
2652          be deferred during the evaluation of the arguments.  */
2653       NO_DEFER_POP;
2654
2655       funexp = rtx_for_function_call (fndecl, addr);
2656
2657       /* Figure out the register where the value, if any, will come back.  */
2658       valreg = 0;
2659       if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
2660           && ! structure_value_addr)
2661         {
2662           if (pcc_struct_value)
2663             valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
2664                                           fndecl, (pass == 0));
2665           else
2666             valreg = hard_function_value (TREE_TYPE (exp), fndecl, (pass == 0));
2667         }
2668
2669       /* Precompute all register parameters.  It isn't safe to compute anything
2670          once we have started filling any specific hard regs.  */
2671       precompute_register_parameters (num_actuals, args, &reg_parm_seen);
2672
2673       if (TREE_OPERAND (exp, 2))
2674         static_chain_value = expand_expr (TREE_OPERAND (exp, 2),
2675                                           NULL_RTX, VOIDmode, 0);
2676       else
2677         static_chain_value = 0;
2678
2679 #ifdef REG_PARM_STACK_SPACE
2680       /* Save the fixed argument area if it's part of the caller's frame and
2681          is clobbered by argument setup for this call.  */
2682       if (ACCUMULATE_OUTGOING_ARGS && pass)
2683         save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
2684                                               &low_to_save, &high_to_save);
2685 #endif
2686
2687       /* Now store (and compute if necessary) all non-register parms.
2688          These come before register parms, since they can require block-moves,
2689          which could clobber the registers used for register parms.
2690          Parms which have partial registers are not stored here,
2691          but we do preallocate space here if they want that.  */
2692
2693       for (i = 0; i < num_actuals; i++)
2694         if (args[i].reg == 0 || args[i].pass_on_stack)
2695           {
2696             rtx before_arg = get_last_insn ();
2697
2698             if (store_one_arg (&args[i], argblock, flags,
2699                                adjusted_args_size.var != 0,
2700                                reg_parm_stack_space)
2701                 || (pass == 0
2702                     && check_sibcall_argument_overlap (before_arg,
2703                                                        &args[i], 1)))
2704               sibcall_failure = 1;
2705
2706             if (flags & ECF_CONST
2707                 && args[i].stack
2708                 && args[i].value == args[i].stack)
2709               call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
2710                                                gen_rtx_USE (VOIDmode,
2711                                                             args[i].value),
2712                                                call_fusage);
2713           }
2714
2715       /* If we have a parm that is passed in registers but not in memory
2716          and whose alignment does not permit a direct copy into registers,
2717          make a group of pseudos that correspond to each register that we
2718          will later fill.  */
2719       if (STRICT_ALIGNMENT)
2720         store_unaligned_arguments_into_pseudos (args, num_actuals);
2721
2722       /* Now store any partially-in-registers parm.
2723          This is the last place a block-move can happen.  */
2724       if (reg_parm_seen)
2725         for (i = 0; i < num_actuals; i++)
2726           if (args[i].partial != 0 && ! args[i].pass_on_stack)
2727             {
2728               rtx before_arg = get_last_insn ();
2729
2730               if (store_one_arg (&args[i], argblock, flags,
2731                                  adjusted_args_size.var != 0,
2732                                  reg_parm_stack_space)
2733                   || (pass == 0
2734                       && check_sibcall_argument_overlap (before_arg,
2735                                                          &args[i], 1)))
2736                 sibcall_failure = 1;
2737             }
2738
2739       /* If we pushed args in forward order, perform stack alignment
2740          after pushing the last arg.  */
2741       if (!PUSH_ARGS_REVERSED && argblock == 0)
2742         anti_adjust_stack (GEN_INT (adjusted_args_size.constant
2743                                     - unadjusted_args_size));
2744
2745       /* If register arguments require space on the stack and stack space
2746          was not preallocated, allocate stack space here for arguments
2747          passed in registers.  */
2748 #ifdef OUTGOING_REG_PARM_STACK_SPACE
2749       if (!ACCUMULATE_OUTGOING_ARGS
2750           && must_preallocate == 0 && reg_parm_stack_space > 0)
2751         anti_adjust_stack (GEN_INT (reg_parm_stack_space));
2752 #endif
2753
2754       /* Pass the function the address in which to return a
2755          structure value.  */
2756       if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
2757         {
2758           structure_value_addr
2759             = convert_memory_address (Pmode, structure_value_addr);
2760           emit_move_insn (struct_value,
2761                           force_reg (Pmode,
2762                                      force_operand (structure_value_addr,
2763                                                     NULL_RTX)));
2764
2765           if (REG_P (struct_value))
2766             use_reg (&call_fusage, struct_value);
2767         }
2768
2769       funexp = prepare_call_address (funexp, static_chain_value,
2770                                      &call_fusage, reg_parm_seen, pass == 0);
2771
2772       load_register_parameters (args, num_actuals, &call_fusage, flags,
2773                                 pass == 0, &sibcall_failure);
2774
2775       /* Save a pointer to the last insn before the call, so that we can
2776          later safely search backwards to find the CALL_INSN.  */
2777       before_call = get_last_insn ();
2778
2779       /* Set up next argument register.  For sibling calls on machines
2780          with register windows this should be the incoming register.  */
2781 #ifdef FUNCTION_INCOMING_ARG
2782       if (pass == 0)
2783         next_arg_reg = FUNCTION_INCOMING_ARG (args_so_far, VOIDmode,
2784                                               void_type_node, 1);
2785       else
2786 #endif
2787         next_arg_reg = FUNCTION_ARG (args_so_far, VOIDmode,
2788                                      void_type_node, 1);
2789
2790       /* All arguments and registers used for the call must be set up by
2791          now!  */
2792
2793       /* Stack must be properly aligned now.  */
2794       if (pass && stack_pointer_delta % preferred_unit_stack_boundary)
2795         abort ();
2796
2797       /* Generate the actual call instruction.  */
2798       emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,
2799                    adjusted_args_size.constant, struct_value_size,
2800                    next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
2801                    flags, & args_so_far);
2802
2803       /* If call is cse'able, make appropriate pair of reg-notes around it.
2804          Test valreg so we don't crash; may safely ignore `const'
2805          if return type is void.  Disable for PARALLEL return values, because
2806          we have no way to move such values into a pseudo register.  */
2807       if (pass && (flags & ECF_LIBCALL_BLOCK))
2808         {
2809           rtx insns;
2810           rtx insn;
2811           bool failed = valreg == 0 || GET_CODE (valreg) == PARALLEL;
2812
2813           insns = get_insns ();
2814
2815           /* Expansion of block moves possibly introduced a loop that may
2816              not appear inside libcall block.  */
2817           for (insn = insns; insn; insn = NEXT_INSN (insn))
2818             if (JUMP_P (insn))
2819               failed = true;
2820
2821           if (failed)
2822             {
2823               end_sequence ();
2824               emit_insn (insns);
2825             }
2826           else
2827             {
2828               rtx note = 0;
2829               rtx temp = gen_reg_rtx (GET_MODE (valreg));
2830
2831               /* Mark the return value as a pointer if needed.  */
2832               if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2833                 mark_reg_pointer (temp,
2834                                   TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp))));
2835
2836               end_sequence ();
2837               if (flag_unsafe_math_optimizations
2838                   && fndecl
2839                   && DECL_BUILT_IN (fndecl)
2840                   && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SQRT
2841                       || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SQRTF
2842                       || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SQRTL))
2843                 note = gen_rtx_fmt_e (SQRT,
2844                                       GET_MODE (temp),
2845                                       args[0].initial_value);
2846               else
2847                 {
2848                   /* Construct an "equal form" for the value which
2849                      mentions all the arguments in order as well as
2850                      the function name.  */
2851                   for (i = 0; i < num_actuals; i++)
2852                     note = gen_rtx_EXPR_LIST (VOIDmode,
2853                                               args[i].initial_value, note);
2854                   note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
2855
2856                   if (flags & ECF_PURE)
2857                     note = gen_rtx_EXPR_LIST (VOIDmode,
2858                         gen_rtx_USE (VOIDmode,
2859                                      gen_rtx_MEM (BLKmode,
2860                                                   gen_rtx_SCRATCH (VOIDmode))),
2861                         note);
2862                 }
2863               emit_libcall_block (insns, temp, valreg, note);
2864
2865               valreg = temp;
2866             }
2867         }
2868       else if (pass && (flags & ECF_MALLOC))
2869         {
2870           rtx temp = gen_reg_rtx (GET_MODE (valreg));
2871           rtx last, insns;
2872
2873           /* The return value from a malloc-like function is a pointer.  */
2874           if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2875             mark_reg_pointer (temp, BIGGEST_ALIGNMENT);
2876
2877           emit_move_insn (temp, valreg);
2878
2879           /* The return value from a malloc-like function can not alias
2880              anything else.  */
2881           last = get_last_insn ();
2882           REG_NOTES (last) =
2883             gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));
2884
2885           /* Write out the sequence.  */
2886           insns = get_insns ();
2887           end_sequence ();
2888           emit_insn (insns);
2889           valreg = temp;
2890         }
2891
2892       /* For calls to `setjmp', etc., inform flow.c it should complain
2893          if nonvolatile values are live.  For functions that cannot return,
2894          inform flow that control does not fall through.  */
2895
2896       if ((flags & (ECF_NORETURN | ECF_LONGJMP)) || pass == 0)
2897         {
2898           /* The barrier must be emitted
2899              immediately after the CALL_INSN.  Some ports emit more
2900              than just a CALL_INSN above, so we must search for it here.  */
2901
2902           rtx last = get_last_insn ();
2903           while (!CALL_P (last))
2904             {
2905               last = PREV_INSN (last);
2906               /* There was no CALL_INSN?  */
2907               if (last == before_call)
2908                 abort ();
2909             }
2910
2911           emit_barrier_after (last);
2912
2913           /* Stack adjustments after a noreturn call are dead code.
2914              However when NO_DEFER_POP is in effect, we must preserve
2915              stack_pointer_delta.  */
2916           if (inhibit_defer_pop == 0)
2917             {
2918               stack_pointer_delta = old_stack_allocated;
2919               pending_stack_adjust = 0;
2920             }
2921         }
2922
2923       if (flags & ECF_LONGJMP)
2924         current_function_calls_longjmp = 1;
2925
2926       /* If value type not void, return an rtx for the value.  */
2927
2928       if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
2929           || ignore)
2930         target = const0_rtx;
2931       else if (structure_value_addr)
2932         {
2933           if (target == 0 || !MEM_P (target))
2934             {
2935               target
2936                 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2937                                memory_address (TYPE_MODE (TREE_TYPE (exp)),
2938                                                structure_value_addr));
2939               set_mem_attributes (target, exp, 1);
2940             }
2941         }
2942       else if (pcc_struct_value)
2943         {
2944           /* This is the special C++ case where we need to
2945              know what the true target was.  We take care to
2946              never use this value more than once in one expression.  */
2947           target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2948                                 copy_to_reg (valreg));
2949           set_mem_attributes (target, exp, 1);
2950         }
2951       /* Handle calls that return values in multiple non-contiguous locations.
2952          The Irix 6 ABI has examples of this.  */
2953       else if (GET_CODE (valreg) == PARALLEL)
2954         {
2955           if (target == 0)
2956             {
2957               /* This will only be assigned once, so it can be readonly.  */
2958               tree nt = build_qualified_type (TREE_TYPE (exp),
2959                                               (TYPE_QUALS (TREE_TYPE (exp))
2960                                                | TYPE_QUAL_CONST));
2961
2962               target = assign_temp (nt, 0, 1, 1);
2963               preserve_temp_slots (target);
2964             }
2965
2966           if (! rtx_equal_p (target, valreg))
2967             emit_group_store (target, valreg, TREE_TYPE (exp),
2968                               int_size_in_bytes (TREE_TYPE (exp)));
2969
2970           /* We can not support sibling calls for this case.  */
2971           sibcall_failure = 1;
2972         }
2973       else if (target
2974                && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2975                && GET_MODE (target) == GET_MODE (valreg))
2976         {
2977           /* TARGET and VALREG cannot be equal at this point because the
2978              latter would not have REG_FUNCTION_VALUE_P true, while the
2979              former would if it were referring to the same register.
2980
2981              If they refer to the same register, this move will be a no-op,
2982              except when function inlining is being done.  */
2983           emit_move_insn (target, valreg);
2984
2985           /* If we are setting a MEM, this code must be executed.  Since it is
2986              emitted after the call insn, sibcall optimization cannot be
2987              performed in that case.  */
2988           if (MEM_P (target))
2989             sibcall_failure = 1;
2990         }
2991       else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2992         {
2993           target = copy_blkmode_from_reg (target, valreg, TREE_TYPE (exp));
2994
2995           /* We can not support sibling calls for this case.  */
2996           sibcall_failure = 1;
2997         }
2998       else
2999         {
3000           if (shift_returned_value (TREE_TYPE (exp), &valreg))
3001             sibcall_failure = 1;
3002
3003           target = copy_to_reg (valreg);
3004         }
3005
3006       if (targetm.calls.promote_function_return(funtype))
3007         {
3008       /* If we promoted this return value, make the proper SUBREG.  TARGET
3009          might be const0_rtx here, so be careful.  */
3010       if (REG_P (target)
3011           && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
3012           && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
3013         {
3014           tree type = TREE_TYPE (exp);
3015           int unsignedp = TYPE_UNSIGNED (type);
3016           int offset = 0;
3017
3018           /* If we don't promote as expected, something is wrong.  */
3019           if (GET_MODE (target)
3020               != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
3021             abort ();
3022
3023         if ((WORDS_BIG_ENDIAN || BYTES_BIG_ENDIAN)
3024             && GET_MODE_SIZE (GET_MODE (target))
3025                > GET_MODE_SIZE (TYPE_MODE (type)))
3026           {
3027             offset = GET_MODE_SIZE (GET_MODE (target))
3028                      - GET_MODE_SIZE (TYPE_MODE (type));
3029             if (! BYTES_BIG_ENDIAN)
3030               offset = (offset / UNITS_PER_WORD) * UNITS_PER_WORD;
3031             else if (! WORDS_BIG_ENDIAN)
3032               offset %= UNITS_PER_WORD;
3033           }
3034           target = gen_rtx_SUBREG (TYPE_MODE (type), target, offset);
3035           SUBREG_PROMOTED_VAR_P (target) = 1;
3036           SUBREG_PROMOTED_UNSIGNED_SET (target, unsignedp);
3037         }
3038         }
3039
3040       /* If size of args is variable or this was a constructor call for a stack
3041          argument, restore saved stack-pointer value.  */
3042
3043       if (old_stack_level && ! (flags & ECF_SP_DEPRESSED))
3044         {
3045           emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
3046           stack_pointer_delta = old_stack_pointer_delta;
3047           pending_stack_adjust = old_pending_adj;
3048           old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
3049           stack_arg_under_construction = old_stack_arg_under_construction;
3050           highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3051           stack_usage_map = initial_stack_usage_map;
3052           sibcall_failure = 1;
3053         }
3054       else if (ACCUMULATE_OUTGOING_ARGS && pass)
3055         {
3056 #ifdef REG_PARM_STACK_SPACE
3057           if (save_area)
3058             restore_fixed_argument_area (save_area, argblock,
3059                                          high_to_save, low_to_save);
3060 #endif
3061
3062           /* If we saved any argument areas, restore them.  */
3063           for (i = 0; i < num_actuals; i++)
3064             if (args[i].save_area)
3065               {
3066                 enum machine_mode save_mode = GET_MODE (args[i].save_area);
3067                 rtx stack_area
3068                   = gen_rtx_MEM (save_mode,
3069                                  memory_address (save_mode,
3070                                                  XEXP (args[i].stack_slot, 0)));
3071
3072                 if (save_mode != BLKmode)
3073                   emit_move_insn (stack_area, args[i].save_area);
3074                 else
3075                   emit_block_move (stack_area, args[i].save_area,
3076                                    GEN_INT (args[i].locate.size.constant),
3077                                    BLOCK_OP_CALL_PARM);
3078               }
3079
3080           highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3081           stack_usage_map = initial_stack_usage_map;
3082         }
3083
3084       /* If this was alloca, record the new stack level for nonlocal gotos.
3085          Check for the handler slots since we might not have a save area
3086          for non-local gotos.  */
3087
3088       if ((flags & ECF_MAY_BE_ALLOCA) && cfun->nonlocal_goto_save_area != 0)
3089         update_nonlocal_goto_save_area ();
3090
3091       /* Free up storage we no longer need.  */
3092       for (i = 0; i < num_actuals; ++i)
3093         if (args[i].aligned_regs)
3094           free (args[i].aligned_regs);
3095
3096       if (pass == 0)
3097         {
3098           /* Undo the fake expand_start_target_temps we did earlier.  If
3099              there had been any cleanups created, we've already set
3100              sibcall_failure.  */
3101           expand_end_target_temps ();
3102         }
3103
3104       /* If this function is returning into a memory location marked as
3105          readonly, it means it is initializing that location. We normally treat
3106          functions as not clobbering such locations, so we need to specify that
3107          this one does. We do this by adding the appropriate CLOBBER to the
3108          CALL_INSN function usage list.  This cannot be done by emitting a
3109          standalone CLOBBER after the call because the latter would be ignored
3110          by at least the delay slot scheduling pass. We do this now instead of
3111          adding to call_fusage before the call to emit_call_1 because TARGET
3112          may be modified in the meantime.  */
3113       if (structure_value_addr != 0 && target != 0
3114           && MEM_P (target) && RTX_UNCHANGING_P (target))
3115         add_function_usage_to
3116           (last_call_insn (),
3117            gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_CLOBBER (VOIDmode, target),
3118                               NULL_RTX));
3119
3120       insns = get_insns ();
3121       end_sequence ();
3122
3123       if (pass == 0)
3124         {
3125           tail_call_insns = insns;
3126
3127           /* Restore the pending stack adjustment now that we have
3128              finished generating the sibling call sequence.  */
3129
3130           pending_stack_adjust = save_pending_stack_adjust;
3131           stack_pointer_delta = save_stack_pointer_delta;
3132
3133           /* Prepare arg structure for next iteration.  */
3134           for (i = 0; i < num_actuals; i++)
3135             {
3136               args[i].value = 0;
3137               args[i].aligned_regs = 0;
3138               args[i].stack = 0;
3139             }
3140
3141           sbitmap_free (stored_args_map);
3142         }
3143       else
3144         {
3145           normal_call_insns = insns;
3146
3147           /* Verify that we've deallocated all the stack we used.  */
3148           if (! (flags & (ECF_NORETURN | ECF_LONGJMP))
3149               && old_stack_allocated != stack_pointer_delta
3150                                         - pending_stack_adjust)
3151             abort ();
3152         }
3153
3154       /* If something prevents making this a sibling call,
3155          zero out the sequence.  */
3156       if (sibcall_failure)
3157         tail_call_insns = NULL_RTX;
3158       else
3159         break;
3160     }
3161
3162   /* If tail call production succeeded, we need to remove REG_EQUIV notes on
3163      arguments too, as argument area is now clobbered by the call.  */
3164   if (tail_call_insns)
3165     {
3166       emit_insn (tail_call_insns);
3167       cfun->tail_call_emit = true;
3168     }
3169   else
3170     emit_insn (normal_call_insns);
3171
3172   currently_expanding_call--;
3173
3174   /* If this function returns with the stack pointer depressed, ensure
3175      this block saves and restores the stack pointer, show it was
3176      changed, and adjust for any outgoing arg space.  */
3177   if (flags & ECF_SP_DEPRESSED)
3178     {
3179       clear_pending_stack_adjust ();
3180       emit_insn (gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx));
3181       emit_move_insn (virtual_stack_dynamic_rtx, stack_pointer_rtx);
3182     }
3183
3184   return target;
3185 }
3186
3187 /* A sibling call sequence invalidates any REG_EQUIV notes made for
3188    this function's incoming arguments.
3189
3190    At the start of RTL generation we know the only REG_EQUIV notes
3191    in the rtl chain are those for incoming arguments, so we can safely
3192    flush any REG_EQUIV note.
3193
3194    This is (slight) overkill.  We could keep track of the highest
3195    argument we clobber and be more selective in removing notes, but it
3196    does not seem to be worth the effort.  */
3197 void
3198 fixup_tail_calls (void)
3199 {
3200   rtx insn;
3201   tree arg;
3202
3203   purge_reg_equiv_notes ();
3204
3205   /* A sibling call sequence also may invalidate RTX_UNCHANGING_P
3206      flag of some incoming arguments MEM RTLs, because it can write into
3207      those slots.  We clear all those bits now.
3208
3209      This is (slight) overkill, we could keep track of which arguments
3210      we actually write into.  */
3211   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3212     {
3213       if (INSN_P (insn))
3214         purge_mem_unchanging_flag (PATTERN (insn));
3215     }
3216
3217   /* Similarly, invalidate RTX_UNCHANGING_P for any incoming
3218      arguments passed in registers.  */
3219   for (arg = DECL_ARGUMENTS (current_function_decl);
3220        arg;
3221        arg = TREE_CHAIN (arg))
3222     {
3223       if (REG_P (DECL_RTL (arg)))
3224         RTX_UNCHANGING_P (DECL_RTL (arg)) = false;
3225     }
3226 }
3227
3228 /* Traverse an argument list in VALUES and expand all complex
3229    arguments into their components.  */
3230 tree
3231 split_complex_values (tree values)
3232 {
3233   tree p;
3234
3235   /* Before allocating memory, check for the common case of no complex.  */
3236   for (p = values; p; p = TREE_CHAIN (p))
3237     {
3238       tree type = TREE_TYPE (TREE_VALUE (p));
3239       if (type && TREE_CODE (type) == COMPLEX_TYPE
3240           && targetm.calls.split_complex_arg (type))
3241         goto found;
3242     }
3243   return values;
3244
3245  found:
3246   values = copy_list (values);
3247
3248   for (p = values; p; p = TREE_CHAIN (p))
3249     {
3250       tree complex_value = TREE_VALUE (p);
3251       tree complex_type;
3252
3253       complex_type = TREE_TYPE (complex_value);
3254       if (!complex_type)
3255         continue;
3256
3257       if (TREE_CODE (complex_type) == COMPLEX_TYPE
3258           && targetm.calls.split_complex_arg (complex_type))
3259         {
3260           tree subtype;
3261           tree real, imag, next;
3262
3263           subtype = TREE_TYPE (complex_type);
3264           complex_value = save_expr (complex_value);
3265           real = build1 (REALPART_EXPR, subtype, complex_value);
3266           imag = build1 (IMAGPART_EXPR, subtype, complex_value);
3267
3268           TREE_VALUE (p) = real;
3269           next = TREE_CHAIN (p);
3270           imag = build_tree_list (NULL_TREE, imag);
3271           TREE_CHAIN (p) = imag;
3272           TREE_CHAIN (imag) = next;
3273
3274           /* Skip the newly created node.  */
3275           p = TREE_CHAIN (p);
3276         }
3277     }
3278
3279   return values;
3280 }
3281
3282 /* Traverse a list of TYPES and expand all complex types into their
3283    components.  */
3284 tree
3285 split_complex_types (tree types)
3286 {
3287   tree p;
3288
3289   /* Before allocating memory, check for the common case of no complex.  */
3290   for (p = types; p; p = TREE_CHAIN (p))
3291     {
3292       tree type = TREE_VALUE (p);
3293       if (TREE_CODE (type) == COMPLEX_TYPE
3294           && targetm.calls.split_complex_arg (type))
3295         goto found;
3296     }
3297   return types;
3298
3299  found:
3300   types = copy_list (types);
3301
3302   for (p = types; p; p = TREE_CHAIN (p))
3303     {
3304       tree complex_type = TREE_VALUE (p);
3305
3306       if (TREE_CODE (complex_type) == COMPLEX_TYPE
3307           && targetm.calls.split_complex_arg (complex_type))
3308         {
3309           tree next, imag;
3310
3311           /* Rewrite complex type with component type.  */
3312           TREE_VALUE (p) = TREE_TYPE (complex_type);
3313           next = TREE_CHAIN (p);
3314
3315           /* Add another component type for the imaginary part.  */
3316           imag = build_tree_list (NULL_TREE, TREE_VALUE (p));
3317           TREE_CHAIN (p) = imag;
3318           TREE_CHAIN (imag) = next;
3319
3320           /* Skip the newly created node.  */
3321           p = TREE_CHAIN (p);
3322         }
3323     }
3324
3325   return types;
3326 }
3327 \f
3328 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3329    The RETVAL parameter specifies whether return value needs to be saved, other
3330    parameters are documented in the emit_library_call function below.  */
3331
3332 static rtx
3333 emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
3334                            enum libcall_type fn_type,
3335                            enum machine_mode outmode, int nargs, va_list p)
3336 {
3337   /* Total size in bytes of all the stack-parms scanned so far.  */
3338   struct args_size args_size;
3339   /* Size of arguments before any adjustments (such as rounding).  */
3340   struct args_size original_args_size;
3341   int argnum;
3342   rtx fun;
3343   int inc;
3344   int count;
3345   rtx argblock = 0;
3346   CUMULATIVE_ARGS args_so_far;
3347   struct arg
3348   {
3349     rtx value;
3350     enum machine_mode mode;
3351     rtx reg;
3352     int partial;
3353     struct locate_and_pad_arg_data locate;
3354     rtx save_area;
3355   };
3356   struct arg *argvec;
3357   int old_inhibit_defer_pop = inhibit_defer_pop;
3358   rtx call_fusage = 0;
3359   rtx mem_value = 0;
3360   rtx valreg;
3361   int pcc_struct_value = 0;
3362   int struct_value_size = 0;
3363   int flags;
3364   int reg_parm_stack_space = 0;
3365   int needed;
3366   rtx before_call;
3367   tree tfom;                    /* type_for_mode (outmode, 0) */
3368
3369 #ifdef REG_PARM_STACK_SPACE
3370   /* Define the boundary of the register parm stack space that needs to be
3371      save, if any.  */
3372   int low_to_save, high_to_save;
3373   rtx save_area = 0;            /* Place that it is saved.  */
3374 #endif
3375
3376   /* Size of the stack reserved for parameter registers.  */
3377   int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3378   char *initial_stack_usage_map = stack_usage_map;
3379
3380   rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
3381
3382 #ifdef REG_PARM_STACK_SPACE
3383   reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3384 #endif
3385
3386   /* By default, library functions can not throw.  */
3387   flags = ECF_NOTHROW;
3388
3389   switch (fn_type)
3390     {
3391     case LCT_NORMAL:
3392       break;
3393     case LCT_CONST:
3394       flags |= ECF_CONST;
3395       break;
3396     case LCT_PURE:
3397       flags |= ECF_PURE;
3398       break;
3399     case LCT_CONST_MAKE_BLOCK:
3400       flags |= ECF_CONST | ECF_LIBCALL_BLOCK;
3401       break;
3402     case LCT_PURE_MAKE_BLOCK:
3403       flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
3404       break;
3405     case LCT_NORETURN:
3406       flags |= ECF_NORETURN;
3407       break;
3408     case LCT_THROW:
3409       flags = ECF_NORETURN;
3410       break;
3411     case LCT_ALWAYS_RETURN:
3412       flags = ECF_ALWAYS_RETURN;
3413       break;
3414     case LCT_RETURNS_TWICE:
3415       flags = ECF_RETURNS_TWICE;
3416       break;
3417     }
3418   fun = orgfun;
3419
3420   /* Ensure current function's preferred stack boundary is at least
3421      what we need.  */
3422   if (cfun->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3423     cfun->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3424
3425   /* If this kind of value comes back in memory,
3426      decide where in memory it should come back.  */
3427   if (outmode != VOIDmode)
3428     {
3429       tfom = lang_hooks.types.type_for_mode (outmode, 0);
3430       if (aggregate_value_p (tfom, 0))
3431         {
3432 #ifdef PCC_STATIC_STRUCT_RETURN
3433           rtx pointer_reg
3434             = hard_function_value (build_pointer_type (tfom), 0, 0);
3435           mem_value = gen_rtx_MEM (outmode, pointer_reg);
3436           pcc_struct_value = 1;
3437           if (value == 0)
3438             value = gen_reg_rtx (outmode);
3439 #else /* not PCC_STATIC_STRUCT_RETURN */
3440           struct_value_size = GET_MODE_SIZE (outmode);
3441           if (value != 0 && MEM_P (value))
3442             mem_value = value;
3443           else
3444             mem_value = assign_temp (tfom, 0, 1, 1);
3445 #endif
3446           /* This call returns a big structure.  */
3447           flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
3448         }
3449     }
3450   else
3451     tfom = void_type_node;
3452
3453   /* ??? Unfinished: must pass the memory address as an argument.  */
3454
3455   /* Copy all the libcall-arguments out of the varargs data
3456      and into a vector ARGVEC.
3457
3458      Compute how to pass each argument.  We only support a very small subset
3459      of the full argument passing conventions to limit complexity here since
3460      library functions shouldn't have many args.  */
3461
3462   argvec = alloca ((nargs + 1) * sizeof (struct arg));
3463   memset (argvec, 0, (nargs + 1) * sizeof (struct arg));
3464
3465 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3466   INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far, outmode, fun);
3467 #else
3468   INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0, nargs);
3469 #endif
3470
3471   args_size.constant = 0;
3472   args_size.var = 0;
3473
3474   count = 0;
3475
3476   /* Now we are about to start emitting insns that can be deleted
3477      if a libcall is deleted.  */
3478   if (flags & ECF_LIBCALL_BLOCK)
3479     start_sequence ();
3480
3481   push_temp_slots ();
3482
3483   /* If there's a structure value address to be passed,
3484      either pass it in the special place, or pass it as an extra argument.  */
3485   if (mem_value && struct_value == 0 && ! pcc_struct_value)
3486     {
3487       rtx addr = XEXP (mem_value, 0);
3488       nargs++;
3489
3490       /* Make sure it is a reasonable operand for a move or push insn.  */
3491       if (!REG_P (addr) && !MEM_P (addr)
3492           && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
3493         addr = force_operand (addr, NULL_RTX);
3494
3495       argvec[count].value = addr;
3496       argvec[count].mode = Pmode;
3497       argvec[count].partial = 0;
3498
3499       argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
3500       if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
3501         abort ();
3502
3503       locate_and_pad_parm (Pmode, NULL_TREE,
3504 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3505                            1,
3506 #else
3507                            argvec[count].reg != 0,
3508 #endif
3509                            0, NULL_TREE, &args_size, &argvec[count].locate);
3510
3511       if (argvec[count].reg == 0 || argvec[count].partial != 0
3512           || reg_parm_stack_space > 0)
3513         args_size.constant += argvec[count].locate.size.constant;
3514
3515       FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
3516
3517       count++;
3518     }
3519
3520   for (; count < nargs; count++)
3521     {
3522       rtx val = va_arg (p, rtx);
3523       enum machine_mode mode = va_arg (p, enum machine_mode);
3524
3525       /* We cannot convert the arg value to the mode the library wants here;
3526          must do it earlier where we know the signedness of the arg.  */
3527       if (mode == BLKmode
3528           || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
3529         abort ();
3530
3531       /* Make sure it is a reasonable operand for a move or push insn.  */
3532       if (!REG_P (val) && !MEM_P (val)
3533           && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
3534         val = force_operand (val, NULL_RTX);
3535
3536       if (pass_by_reference (&args_so_far, mode, NULL_TREE, 1))
3537         {
3538           rtx slot;
3539           int must_copy = ! FUNCTION_ARG_CALLEE_COPIES (args_so_far, mode,
3540                                                         NULL_TREE, 1);
3541
3542           /* loop.c won't look at CALL_INSN_FUNCTION_USAGE of const/pure
3543              functions, so we have to pretend this isn't such a function.  */
3544           if (flags & ECF_LIBCALL_BLOCK)
3545             {
3546               rtx insns = get_insns ();
3547               end_sequence ();
3548               emit_insn (insns);
3549             }
3550           flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
3551
3552           /* If this was a CONST function, it is now PURE since
3553              it now reads memory.  */
3554           if (flags & ECF_CONST)
3555             {
3556               flags &= ~ECF_CONST;
3557               flags |= ECF_PURE;
3558             }
3559
3560           if (GET_MODE (val) == MEM && ! must_copy)
3561             slot = val;
3562           else if (must_copy)
3563             {
3564               slot = assign_temp (lang_hooks.types.type_for_mode (mode, 0),
3565                                   0, 1, 1);
3566               emit_move_insn (slot, val);
3567             }
3568           else
3569             {
3570               tree type = lang_hooks.types.type_for_mode (mode, 0);
3571
3572               slot
3573                 = gen_rtx_MEM (mode,
3574                                expand_expr (build1 (ADDR_EXPR,
3575                                                     build_pointer_type (type),
3576                                                     make_tree (type, val)),
3577                                             NULL_RTX, VOIDmode, 0));
3578             }
3579
3580           call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
3581                                            gen_rtx_USE (VOIDmode, slot),
3582                                            call_fusage);
3583           if (must_copy)
3584             call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
3585                                              gen_rtx_CLOBBER (VOIDmode,
3586                                                               slot),
3587                                              call_fusage);
3588
3589           mode = Pmode;
3590           val = force_operand (XEXP (slot, 0), NULL_RTX);
3591         }
3592
3593       argvec[count].value = val;
3594       argvec[count].mode = mode;
3595
3596       argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
3597
3598       argvec[count].partial
3599         = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3600
3601       locate_and_pad_parm (mode, NULL_TREE,
3602 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3603                            1,
3604 #else
3605                            argvec[count].reg != 0,
3606 #endif
3607                            argvec[count].partial,
3608                            NULL_TREE, &args_size, &argvec[count].locate);
3609
3610       if (argvec[count].locate.size.var)
3611         abort ();
3612
3613       if (argvec[count].reg == 0 || argvec[count].partial != 0
3614           || reg_parm_stack_space > 0)
3615         args_size.constant += argvec[count].locate.size.constant;
3616
3617       FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3618     }
3619
3620   /* If this machine requires an external definition for library
3621      functions, write one out.  */
3622   assemble_external_libcall (fun);
3623
3624   original_args_size = args_size;
3625   args_size.constant = (((args_size.constant
3626                           + stack_pointer_delta
3627                           + STACK_BYTES - 1)
3628                           / STACK_BYTES
3629                           * STACK_BYTES)
3630                          - stack_pointer_delta);
3631
3632   args_size.constant = MAX (args_size.constant,
3633                             reg_parm_stack_space);
3634
3635 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3636   args_size.constant -= reg_parm_stack_space;
3637 #endif
3638
3639   if (args_size.constant > current_function_outgoing_args_size)
3640     current_function_outgoing_args_size = args_size.constant;
3641
3642   if (ACCUMULATE_OUTGOING_ARGS)
3643     {
3644       /* Since the stack pointer will never be pushed, it is possible for
3645          the evaluation of a parm to clobber something we have already
3646          written to the stack.  Since most function calls on RISC machines
3647          do not use the stack, this is uncommon, but must work correctly.
3648
3649          Therefore, we save any area of the stack that was already written
3650          and that we are using.  Here we set up to do this by making a new
3651          stack usage map from the old one.
3652
3653          Another approach might be to try to reorder the argument
3654          evaluations to avoid this conflicting stack usage.  */
3655
3656       needed = args_size.constant;
3657
3658 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3659       /* Since we will be writing into the entire argument area, the
3660          map must be allocated for its entire size, not just the part that
3661          is the responsibility of the caller.  */
3662       needed += reg_parm_stack_space;
3663 #endif
3664
3665 #ifdef ARGS_GROW_DOWNWARD
3666       highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3667                                          needed + 1);
3668 #else
3669       highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3670                                          needed);
3671 #endif
3672       stack_usage_map = alloca (highest_outgoing_arg_in_use);
3673
3674       if (initial_highest_arg_in_use)
3675         memcpy (stack_usage_map, initial_stack_usage_map,
3676                 initial_highest_arg_in_use);
3677
3678       if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3679         memset (&stack_usage_map[initial_highest_arg_in_use], 0,
3680                highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3681       needed = 0;
3682
3683       /* We must be careful to use virtual regs before they're instantiated,
3684          and real regs afterwards.  Loop optimization, for example, can create
3685          new libcalls after we've instantiated the virtual regs, and if we
3686          use virtuals anyway, they won't match the rtl patterns.  */
3687
3688       if (virtuals_instantiated)
3689         argblock = plus_constant (stack_pointer_rtx, STACK_POINTER_OFFSET);
3690       else
3691         argblock = virtual_outgoing_args_rtx;
3692     }
3693   else
3694     {
3695       if (!PUSH_ARGS)
3696         argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3697     }
3698
3699   /* If we push args individually in reverse order, perform stack alignment
3700      before the first push (the last arg).  */
3701   if (argblock == 0 && PUSH_ARGS_REVERSED)
3702     anti_adjust_stack (GEN_INT (args_size.constant
3703                                 - original_args_size.constant));
3704
3705   if (PUSH_ARGS_REVERSED)
3706     {
3707       inc = -1;
3708       argnum = nargs - 1;
3709     }
3710   else
3711     {
3712       inc = 1;
3713       argnum = 0;
3714     }
3715
3716 #ifdef REG_PARM_STACK_SPACE
3717   if (ACCUMULATE_OUTGOING_ARGS)
3718     {
3719       /* The argument list is the property of the called routine and it
3720          may clobber it.  If the fixed area has been used for previous
3721          parameters, we must save and restore it.  */
3722       save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
3723                                             &low_to_save, &high_to_save);
3724     }
3725 #endif
3726
3727   /* Push the args that need to be pushed.  */
3728
3729   /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3730      are to be pushed.  */
3731   for (count = 0; count < nargs; count++, argnum += inc)
3732     {
3733       enum machine_mode mode = argvec[argnum].mode;
3734       rtx val = argvec[argnum].value;
3735       rtx reg = argvec[argnum].reg;
3736       int partial = argvec[argnum].partial;
3737       int lower_bound = 0, upper_bound = 0, i;
3738
3739       if (! (reg != 0 && partial == 0))
3740         {
3741           if (ACCUMULATE_OUTGOING_ARGS)
3742             {
3743               /* If this is being stored into a pre-allocated, fixed-size,
3744                  stack area, save any previous data at that location.  */
3745
3746 #ifdef ARGS_GROW_DOWNWARD
3747               /* stack_slot is negative, but we want to index stack_usage_map
3748                  with positive values.  */
3749               upper_bound = -argvec[argnum].locate.offset.constant + 1;
3750               lower_bound = upper_bound - argvec[argnum].locate.size.constant;
3751 #else
3752               lower_bound = argvec[argnum].locate.offset.constant;
3753               upper_bound = lower_bound + argvec[argnum].locate.size.constant;
3754 #endif
3755
3756               i = lower_bound;
3757               /* Don't worry about things in the fixed argument area;
3758                  it has already been saved.  */
3759               if (i < reg_parm_stack_space)
3760                 i = reg_parm_stack_space;
3761               while (i < upper_bound && stack_usage_map[i] == 0)
3762                 i++;
3763
3764               if (i < upper_bound)
3765                 {
3766                   /* We need to make a save area.  */
3767                   unsigned int size
3768                     = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
3769                   enum machine_mode save_mode
3770                     = mode_for_size (size, MODE_INT, 1);
3771                   rtx adr
3772                     = plus_constant (argblock,
3773                                      argvec[argnum].locate.offset.constant);
3774                   rtx stack_area
3775                     = gen_rtx_MEM (save_mode, memory_address (save_mode, adr));
3776
3777                   if (save_mode == BLKmode)
3778                     {
3779                       argvec[argnum].save_area
3780                         = assign_stack_temp (BLKmode,
3781                                              argvec[argnum].locate.size.constant,
3782                                              0);
3783
3784                       emit_block_move (validize_mem (argvec[argnum].save_area),
3785                                        stack_area,
3786                                        GEN_INT (argvec[argnum].locate.size.constant),
3787                                        BLOCK_OP_CALL_PARM);
3788                     }
3789                   else
3790                     {
3791                       argvec[argnum].save_area = gen_reg_rtx (save_mode);
3792
3793                       emit_move_insn (argvec[argnum].save_area, stack_area);
3794                     }
3795                 }
3796             }
3797
3798           emit_push_insn (val, mode, NULL_TREE, NULL_RTX, PARM_BOUNDARY,
3799                           partial, reg, 0, argblock,
3800                           GEN_INT (argvec[argnum].locate.offset.constant),
3801                           reg_parm_stack_space,
3802                           ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad));
3803
3804           /* Now mark the segment we just used.  */
3805           if (ACCUMULATE_OUTGOING_ARGS)
3806             for (i = lower_bound; i < upper_bound; i++)
3807               stack_usage_map[i] = 1;
3808
3809           NO_DEFER_POP;
3810         }
3811     }
3812
3813   /* If we pushed args in forward order, perform stack alignment
3814      after pushing the last arg.  */
3815   if (argblock == 0 && !PUSH_ARGS_REVERSED)
3816     anti_adjust_stack (GEN_INT (args_size.constant
3817                                 - original_args_size.constant));
3818
3819   if (PUSH_ARGS_REVERSED)
3820     argnum = nargs - 1;
3821   else
3822     argnum = 0;
3823
3824   fun = prepare_call_address (fun, NULL, &call_fusage, 0, 0);
3825
3826   /* Now load any reg parms into their regs.  */
3827
3828   /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3829      are to be pushed.  */
3830   for (count = 0; count < nargs; count++, argnum += inc)
3831     {
3832       enum machine_mode mode = argvec[argnum].mode;
3833       rtx val = argvec[argnum].value;
3834       rtx reg = argvec[argnum].reg;
3835       int partial = argvec[argnum].partial;
3836
3837       /* Handle calls that pass values in multiple non-contiguous
3838          locations.  The PA64 has examples of this for library calls.  */
3839       if (reg != 0 && GET_CODE (reg) == PARALLEL)
3840         emit_group_load (reg, val, NULL_TREE, GET_MODE_SIZE (mode));
3841       else if (reg != 0 && partial == 0)
3842         emit_move_insn (reg, val);
3843
3844       NO_DEFER_POP;
3845     }
3846
3847   /* Any regs containing parms remain in use through the call.  */
3848   for (count = 0; count < nargs; count++)
3849     {
3850       rtx reg = argvec[count].reg;
3851       if (reg != 0 && GET_CODE (reg) == PARALLEL)
3852         use_group_regs (&call_fusage, reg);
3853       else if (reg != 0)
3854         use_reg (&call_fusage, reg);
3855     }
3856
3857   /* Pass the function the address in which to return a structure value.  */
3858   if (mem_value != 0 && struct_value != 0 && ! pcc_struct_value)
3859     {
3860       emit_move_insn (struct_value,
3861                       force_reg (Pmode,
3862                                  force_operand (XEXP (mem_value, 0),
3863                                                 NULL_RTX)));
3864       if (REG_P (struct_value))
3865         use_reg (&call_fusage, struct_value);
3866     }
3867
3868   /* Don't allow popping to be deferred, since then
3869      cse'ing of library calls could delete a call and leave the pop.  */
3870   NO_DEFER_POP;
3871   valreg = (mem_value == 0 && outmode != VOIDmode
3872             ? hard_libcall_value (outmode) : NULL_RTX);
3873
3874   /* Stack must be properly aligned now.  */
3875   if (stack_pointer_delta & (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1))
3876     abort ();
3877
3878   before_call = get_last_insn ();
3879
3880   /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3881      will set inhibit_defer_pop to that value.  */
3882   /* The return type is needed to decide how many bytes the function pops.
3883      Signedness plays no role in that, so for simplicity, we pretend it's
3884      always signed.  We also assume that the list of arguments passed has
3885      no impact, so we pretend it is unknown.  */
3886
3887   emit_call_1 (fun, NULL,
3888                get_identifier (XSTR (orgfun, 0)),
3889                build_function_type (tfom, NULL_TREE),
3890                original_args_size.constant, args_size.constant,
3891                struct_value_size,
3892                FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3893                valreg,
3894                old_inhibit_defer_pop + 1, call_fusage, flags, & args_so_far);
3895
3896   /* For calls to `setjmp', etc., inform flow.c it should complain
3897      if nonvolatile values are live.  For functions that cannot return,
3898      inform flow that control does not fall through.  */
3899
3900   if (flags & (ECF_NORETURN | ECF_LONGJMP))
3901     {
3902       /* The barrier note must be emitted
3903          immediately after the CALL_INSN.  Some ports emit more than
3904          just a CALL_INSN above, so we must search for it here.  */
3905
3906       rtx last = get_last_insn ();
3907       while (!CALL_P (last))
3908         {
3909           last = PREV_INSN (last);
3910           /* There was no CALL_INSN?  */
3911           if (last == before_call)
3912             abort ();
3913         }
3914
3915       emit_barrier_after (last);
3916     }
3917
3918   /* Now restore inhibit_defer_pop to its actual original value.  */
3919   OK_DEFER_POP;
3920
3921   /* If call is cse'able, make appropriate pair of reg-notes around it.
3922      Test valreg so we don't crash; may safely ignore `const'
3923      if return type is void.  Disable for PARALLEL return values, because
3924      we have no way to move such values into a pseudo register.  */
3925   if (flags & ECF_LIBCALL_BLOCK)
3926     {
3927       rtx insns;
3928
3929       if (valreg == 0)
3930         {
3931           insns = get_insns ();
3932           end_sequence ();
3933           emit_insn (insns);
3934         }
3935       else
3936         {
3937           rtx note = 0;
3938           rtx temp;
3939           int i;
3940
3941           if (GET_CODE (valreg) == PARALLEL)
3942             {
3943               temp = gen_reg_rtx (outmode);
3944               emit_group_store (temp, valreg, NULL_TREE,
3945                                 GET_MODE_SIZE (outmode));
3946               valreg = temp;
3947             }
3948
3949           temp = gen_reg_rtx (GET_MODE (valreg));
3950
3951           /* Construct an "equal form" for the value which mentions all the
3952              arguments in order as well as the function name.  */
3953           for (i = 0; i < nargs; i++)
3954             note = gen_rtx_EXPR_LIST (VOIDmode, argvec[i].value, note);
3955           note = gen_rtx_EXPR_LIST (VOIDmode, fun, note);
3956
3957           insns = get_insns ();
3958           end_sequence ();
3959
3960           if (flags & ECF_PURE)
3961             note = gen_rtx_EXPR_LIST (VOIDmode,
3962                         gen_rtx_USE (VOIDmode,
3963                                      gen_rtx_MEM (BLKmode,
3964                                                   gen_rtx_SCRATCH (VOIDmode))),
3965                         note);
3966
3967           emit_libcall_block (insns, temp, valreg, note);
3968
3969           valreg = temp;
3970         }
3971     }
3972   pop_temp_slots ();
3973
3974   /* Copy the value to the right place.  */
3975   if (outmode != VOIDmode && retval)
3976     {
3977       if (mem_value)
3978         {
3979           if (value == 0)
3980             value = mem_value;
3981           if (value != mem_value)
3982             emit_move_insn (value, mem_value);
3983         }
3984       else if (GET_CODE (valreg) == PARALLEL)
3985         {
3986           if (value == 0)
3987             value = gen_reg_rtx (outmode);
3988           emit_group_store (value, valreg, NULL_TREE, GET_MODE_SIZE (outmode));
3989         }
3990       else if (value != 0)
3991         emit_move_insn (value, valreg);
3992       else
3993         value = valreg;
3994     }
3995
3996   if (ACCUMULATE_OUTGOING_ARGS)
3997     {
3998 #ifdef REG_PARM_STACK_SPACE
3999       if (save_area)
4000         restore_fixed_argument_area (save_area, argblock,
4001                                      high_to_save, low_to_save);
4002 #endif
4003
4004       /* If we saved any argument areas, restore them.  */
4005       for (count = 0; count < nargs; count++)
4006         if (argvec[count].save_area)
4007           {
4008             enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
4009             rtx adr = plus_constant (argblock,
4010                                      argvec[count].locate.offset.constant);
4011             rtx stack_area = gen_rtx_MEM (save_mode,
4012                                           memory_address (save_mode, adr));
4013
4014             if (save_mode == BLKmode)
4015               emit_block_move (stack_area,
4016                                validize_mem (argvec[count].save_area),
4017                                GEN_INT (argvec[count].locate.size.constant),
4018                                BLOCK_OP_CALL_PARM);
4019             else
4020               emit_move_insn (stack_area, argvec[count].save_area);
4021           }
4022
4023       highest_outgoing_arg_in_use = initial_highest_arg_in_use;
4024       stack_usage_map = initial_stack_usage_map;
4025     }
4026
4027   return value;
4028
4029 }
4030 \f
4031 /* Output a library call to function FUN (a SYMBOL_REF rtx)
4032    (emitting the queue unless NO_QUEUE is nonzero),
4033    for a value of mode OUTMODE,
4034    with NARGS different arguments, passed as alternating rtx values
4035    and machine_modes to convert them to.
4036
4037    FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for `const'
4038    calls, LCT_PURE for `pure' calls, LCT_CONST_MAKE_BLOCK for `const' calls
4039    which should be enclosed in REG_LIBCALL/REG_RETVAL notes,
4040    LCT_PURE_MAKE_BLOCK for `purep' calls which should be enclosed in
4041    REG_LIBCALL/REG_RETVAL notes with extra (use (memory (scratch)),
4042    or other LCT_ value for other types of library calls.  */
4043
4044 void
4045 emit_library_call (rtx orgfun, enum libcall_type fn_type,
4046                    enum machine_mode outmode, int nargs, ...)
4047 {
4048   va_list p;
4049
4050   va_start (p, nargs);
4051   emit_library_call_value_1 (0, orgfun, NULL_RTX, fn_type, outmode, nargs, p);
4052   va_end (p);
4053 }
4054 \f
4055 /* Like emit_library_call except that an extra argument, VALUE,
4056    comes second and says where to store the result.
4057    (If VALUE is zero, this function chooses a convenient way
4058    to return the value.
4059
4060    This function returns an rtx for where the value is to be found.
4061    If VALUE is nonzero, VALUE is returned.  */
4062
4063 rtx
4064 emit_library_call_value (rtx orgfun, rtx value,
4065                          enum libcall_type fn_type,
4066                          enum machine_mode outmode, int nargs, ...)
4067 {
4068   rtx result;
4069   va_list p;
4070
4071   va_start (p, nargs);
4072   result = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode,
4073                                       nargs, p);
4074   va_end (p);
4075
4076   return result;
4077 }
4078 \f
4079 /* Store a single argument for a function call
4080    into the register or memory area where it must be passed.
4081    *ARG describes the argument value and where to pass it.
4082
4083    ARGBLOCK is the address of the stack-block for all the arguments,
4084    or 0 on a machine where arguments are pushed individually.
4085
4086    MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4087    so must be careful about how the stack is used.
4088
4089    VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4090    argument stack.  This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4091    that we need not worry about saving and restoring the stack.
4092
4093    FNDECL is the declaration of the function we are calling.
4094
4095    Return nonzero if this arg should cause sibcall failure,
4096    zero otherwise.  */
4097
4098 static int
4099 store_one_arg (struct arg_data *arg, rtx argblock, int flags,
4100                int variable_size ATTRIBUTE_UNUSED, int reg_parm_stack_space)
4101 {
4102   tree pval = arg->tree_value;
4103   rtx reg = 0;
4104   int partial = 0;
4105   int used = 0;
4106   int i, lower_bound = 0, upper_bound = 0;
4107   int sibcall_failure = 0;
4108
4109   if (TREE_CODE (pval) == ERROR_MARK)
4110     return 1;
4111
4112   /* Push a new temporary level for any temporaries we make for
4113      this argument.  */
4114   push_temp_slots ();
4115
4116   if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL))
4117     {
4118       /* If this is being stored into a pre-allocated, fixed-size, stack area,
4119          save any previous data at that location.  */
4120       if (argblock && ! variable_size && arg->stack)
4121         {
4122 #ifdef ARGS_GROW_DOWNWARD
4123           /* stack_slot is negative, but we want to index stack_usage_map
4124              with positive values.  */
4125           if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4126             upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
4127           else
4128             upper_bound = 0;
4129
4130           lower_bound = upper_bound - arg->locate.size.constant;
4131 #else
4132           if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4133             lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
4134           else
4135             lower_bound = 0;
4136
4137           upper_bound = lower_bound + arg->locate.size.constant;
4138 #endif
4139
4140           i = lower_bound;
4141           /* Don't worry about things in the fixed argument area;
4142              it has already been saved.  */
4143           if (i < reg_parm_stack_space)
4144             i = reg_parm_stack_space;
4145           while (i < upper_bound && stack_usage_map[i] == 0)
4146             i++;
4147
4148           if (i < upper_bound)
4149             {
4150               /* We need to make a save area.  */
4151               unsigned int size = arg->locate.size.constant * BITS_PER_UNIT;
4152               enum machine_mode save_mode = mode_for_size (size, MODE_INT, 1);
4153               rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0));
4154               rtx stack_area = gen_rtx_MEM (save_mode, adr);
4155
4156               if (save_mode == BLKmode)
4157                 {
4158                   tree ot = TREE_TYPE (arg->tree_value);
4159                   tree nt = build_qualified_type (ot, (TYPE_QUALS (ot)
4160                                                        | TYPE_QUAL_CONST));
4161
4162                   arg->save_area = assign_temp (nt, 0, 1, 1);
4163                   preserve_temp_slots (arg->save_area);
4164                   emit_block_move (validize_mem (arg->save_area), stack_area,
4165                                    expr_size (arg->tree_value),
4166                                    BLOCK_OP_CALL_PARM);
4167                 }
4168               else
4169                 {
4170                   arg->save_area = gen_reg_rtx (save_mode);
4171                   emit_move_insn (arg->save_area, stack_area);
4172                 }
4173             }
4174         }
4175     }
4176
4177   /* If this isn't going to be placed on both the stack and in registers,
4178      set up the register and number of words.  */
4179   if (! arg->pass_on_stack)
4180     {
4181       if (flags & ECF_SIBCALL)
4182         reg = arg->tail_call_reg;
4183       else
4184         reg = arg->reg;
4185       partial = arg->partial;
4186     }
4187
4188   if (reg != 0 && partial == 0)
4189     /* Being passed entirely in a register.  We shouldn't be called in
4190        this case.  */
4191     abort ();
4192
4193   /* If this arg needs special alignment, don't load the registers
4194      here.  */
4195   if (arg->n_aligned_regs != 0)
4196     reg = 0;
4197
4198   /* If this is being passed partially in a register, we can't evaluate
4199      it directly into its stack slot.  Otherwise, we can.  */
4200   if (arg->value == 0)
4201     {
4202       /* stack_arg_under_construction is nonzero if a function argument is
4203          being evaluated directly into the outgoing argument list and
4204          expand_call must take special action to preserve the argument list
4205          if it is called recursively.
4206
4207          For scalar function arguments stack_usage_map is sufficient to
4208          determine which stack slots must be saved and restored.  Scalar
4209          arguments in general have pass_on_stack == 0.
4210
4211          If this argument is initialized by a function which takes the
4212          address of the argument (a C++ constructor or a C function
4213          returning a BLKmode structure), then stack_usage_map is
4214          insufficient and expand_call must push the stack around the
4215          function call.  Such arguments have pass_on_stack == 1.
4216
4217          Note that it is always safe to set stack_arg_under_construction,
4218          but this generates suboptimal code if set when not needed.  */
4219
4220       if (arg->pass_on_stack)
4221         stack_arg_under_construction++;
4222
4223       arg->value = expand_expr (pval,
4224                                 (partial
4225                                  || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
4226                                 ? NULL_RTX : arg->stack,
4227                                 VOIDmode, EXPAND_STACK_PARM);
4228
4229       /* If we are promoting object (or for any other reason) the mode
4230          doesn't agree, convert the mode.  */
4231
4232       if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
4233         arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
4234                                     arg->value, arg->unsignedp);
4235
4236       if (arg->pass_on_stack)
4237         stack_arg_under_construction--;
4238     }
4239
4240   /* Don't allow anything left on stack from computation
4241      of argument to alloca.  */
4242   if (flags & ECF_MAY_BE_ALLOCA)
4243     do_pending_stack_adjust ();
4244
4245   if (arg->value == arg->stack)
4246     /* If the value is already in the stack slot, we are done.  */
4247     ;
4248   else if (arg->mode != BLKmode)
4249     {
4250       int size;
4251
4252       /* Argument is a scalar, not entirely passed in registers.
4253          (If part is passed in registers, arg->partial says how much
4254          and emit_push_insn will take care of putting it there.)
4255
4256          Push it, and if its size is less than the
4257          amount of space allocated to it,
4258          also bump stack pointer by the additional space.
4259          Note that in C the default argument promotions
4260          will prevent such mismatches.  */
4261
4262       size = GET_MODE_SIZE (arg->mode);
4263       /* Compute how much space the push instruction will push.
4264          On many machines, pushing a byte will advance the stack
4265          pointer by a halfword.  */
4266 #ifdef PUSH_ROUNDING
4267       size = PUSH_ROUNDING (size);
4268 #endif
4269       used = size;
4270
4271       /* Compute how much space the argument should get:
4272          round up to a multiple of the alignment for arguments.  */
4273       if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
4274         used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4275                  / (PARM_BOUNDARY / BITS_PER_UNIT))
4276                 * (PARM_BOUNDARY / BITS_PER_UNIT));
4277
4278       /* This isn't already where we want it on the stack, so put it there.
4279          This can either be done with push or copy insns.  */
4280       emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
4281                       PARM_BOUNDARY, partial, reg, used - size, argblock,
4282                       ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4283                       ARGS_SIZE_RTX (arg->locate.alignment_pad));
4284
4285       /* Unless this is a partially-in-register argument, the argument is now
4286          in the stack.  */
4287       if (partial == 0)
4288         arg->value = arg->stack;
4289     }
4290   else
4291     {
4292       /* BLKmode, at least partly to be pushed.  */
4293
4294       unsigned int parm_align;
4295       int excess;
4296       rtx size_rtx;
4297
4298       /* Pushing a nonscalar.
4299          If part is passed in registers, PARTIAL says how much
4300          and emit_push_insn will take care of putting it there.  */
4301
4302       /* Round its size up to a multiple
4303          of the allocation unit for arguments.  */
4304
4305       if (arg->locate.size.var != 0)
4306         {
4307           excess = 0;
4308           size_rtx = ARGS_SIZE_RTX (arg->locate.size);
4309         }
4310       else
4311         {
4312           /* PUSH_ROUNDING has no effect on us, because
4313              emit_push_insn for BLKmode is careful to avoid it.  */
4314           if (reg && GET_CODE (reg) == PARALLEL)
4315           {
4316             /* Use the size of the elt to compute excess.  */
4317             rtx elt = XEXP (XVECEXP (reg, 0, 0), 0);
4318             excess = (arg->locate.size.constant
4319                       - int_size_in_bytes (TREE_TYPE (pval))
4320                       + partial * GET_MODE_SIZE (GET_MODE (elt)));
4321           }
4322           else
4323             excess = (arg->locate.size.constant
4324                       - int_size_in_bytes (TREE_TYPE (pval))
4325                       + partial * UNITS_PER_WORD);
4326           size_rtx = expand_expr (size_in_bytes (TREE_TYPE (pval)),
4327                                   NULL_RTX, TYPE_MODE (sizetype), 0);
4328         }
4329
4330       /* Some types will require stricter alignment, which will be
4331          provided for elsewhere in argument layout.  */
4332       parm_align = MAX (PARM_BOUNDARY, TYPE_ALIGN (TREE_TYPE (pval)));
4333
4334       /* When an argument is padded down, the block is aligned to
4335          PARM_BOUNDARY, but the actual argument isn't.  */
4336       if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward)
4337         {
4338           if (arg->locate.size.var)
4339             parm_align = BITS_PER_UNIT;
4340           else if (excess)
4341             {
4342               unsigned int excess_align = (excess & -excess) * BITS_PER_UNIT;
4343               parm_align = MIN (parm_align, excess_align);
4344             }
4345         }
4346
4347       if ((flags & ECF_SIBCALL) && MEM_P (arg->value))
4348         {
4349           /* emit_push_insn might not work properly if arg->value and
4350              argblock + arg->locate.offset areas overlap.  */
4351           rtx x = arg->value;
4352           int i = 0;
4353
4354           if (XEXP (x, 0) == current_function_internal_arg_pointer
4355               || (GET_CODE (XEXP (x, 0)) == PLUS
4356                   && XEXP (XEXP (x, 0), 0) ==
4357                      current_function_internal_arg_pointer
4358                   && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))
4359             {
4360               if (XEXP (x, 0) != current_function_internal_arg_pointer)
4361                 i = INTVAL (XEXP (XEXP (x, 0), 1));
4362
4363               /* expand_call should ensure this.  */
4364               if (arg->locate.offset.var || GET_CODE (size_rtx) != CONST_INT)
4365                 abort ();
4366
4367               if (arg->locate.offset.constant > i)
4368                 {
4369                   if (arg->locate.offset.constant < i + INTVAL (size_rtx))
4370                     sibcall_failure = 1;
4371                 }
4372               else if (arg->locate.offset.constant < i)
4373                 {
4374                   if (i < arg->locate.offset.constant + INTVAL (size_rtx))
4375                     sibcall_failure = 1;
4376                 }
4377             }
4378         }
4379
4380       emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
4381                       parm_align, partial, reg, excess, argblock,
4382                       ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4383                       ARGS_SIZE_RTX (arg->locate.alignment_pad));
4384
4385       /* Unless this is a partially-in-register argument, the argument is now
4386          in the stack.
4387
4388          ??? Unlike the case above, in which we want the actual
4389          address of the data, so that we can load it directly into a
4390          register, here we want the address of the stack slot, so that
4391          it's properly aligned for word-by-word copying or something
4392          like that.  It's not clear that this is always correct.  */
4393       if (partial == 0)
4394         arg->value = arg->stack_slot;
4395     }
4396
4397   /* Mark all slots this store used.  */
4398   if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)
4399       && argblock && ! variable_size && arg->stack)
4400     for (i = lower_bound; i < upper_bound; i++)
4401       stack_usage_map[i] = 1;
4402
4403   /* Once we have pushed something, pops can't safely
4404      be deferred during the rest of the arguments.  */
4405   NO_DEFER_POP;
4406
4407   /* Free any temporary slots made in processing this argument.  Show
4408      that we might have taken the address of something and pushed that
4409      as an operand.  */
4410   preserve_temp_slots (NULL_RTX);
4411   free_temp_slots ();
4412   pop_temp_slots ();
4413
4414   return sibcall_failure;
4415 }
4416
4417 /* Nonzero if we do not know how to pass TYPE solely in registers.  */
4418
4419 bool
4420 must_pass_in_stack_var_size (enum machine_mode mode ATTRIBUTE_UNUSED,
4421                              tree type)
4422 {
4423   if (!type)
4424     return false;
4425
4426   /* If the type has variable size...  */
4427   if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4428     return true;
4429
4430   /* If the type is marked as addressable (it is required
4431      to be constructed into the stack)...  */
4432   if (TREE_ADDRESSABLE (type))
4433     return true;
4434
4435   return false;
4436 }
4437
4438 /* Another version of the TARGET_MUST_PASS_IN_STACK hook.  This one
4439    takes trailing padding of a structure into account.  */
4440 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING.  */
4441
4442 bool
4443 must_pass_in_stack_var_size_or_pad (enum machine_mode mode, tree type)
4444 {
4445   if (!type)
4446     return false;
4447
4448   /* If the type has variable size...  */
4449   if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4450     return true;
4451
4452   /* If the type is marked as addressable (it is required
4453      to be constructed into the stack)...  */
4454   if (TREE_ADDRESSABLE (type))
4455     return true;
4456
4457   /* If the padding and mode of the type is such that a copy into
4458      a register would put it into the wrong part of the register.  */
4459   if (mode == BLKmode
4460       && int_size_in_bytes (type) % (PARM_BOUNDARY / BITS_PER_UNIT)
4461       && (FUNCTION_ARG_PADDING (mode, type)
4462           == (BYTES_BIG_ENDIAN ? upward : downward)))
4463     return true;
4464
4465   return false;
4466 }