config/stormy16/stormy16.c (combine_bnp): Add code to handle zero_extension and
[official-gcc.git] / gcc / calls.c
blob720ffb7de76ac08cc36a8058afed15213215cecf
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.
5 This file is part of GCC.
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.
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.
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. */
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"
44 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
45 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
47 /* Data structure and subroutines used within expand_call. */
49 struct arg_data
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 is a PARALLEL, this is a copy of VALUE pulled into the correct
68 form for emit_group_move. */
69 rtx parallel_value;
70 /* If REG was promoted from the actual mode of the argument expression,
71 indicates whether the promotion is sign- or zero-extended. */
72 int unsignedp;
73 /* Number of registers to use. 0 means put the whole arg in registers.
74 Also 0 if not passed in registers. */
75 int partial;
76 /* Nonzero if argument must be passed on stack.
77 Note that some arguments may be passed on the stack
78 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
79 pass_on_stack identifies arguments that *cannot* go in registers. */
80 int pass_on_stack;
81 /* Some fields packaged up for locate_and_pad_parm. */
82 struct locate_and_pad_arg_data locate;
83 /* Location on the stack at which parameter should be stored. The store
84 has already been done if STACK == VALUE. */
85 rtx stack;
86 /* Location on the stack of the start of this argument slot. This can
87 differ from STACK if this arg pads downward. This location is known
88 to be aligned to FUNCTION_ARG_BOUNDARY. */
89 rtx stack_slot;
90 /* Place that this stack area has been saved, if needed. */
91 rtx save_area;
92 /* If an argument's alignment does not permit direct copying into registers,
93 copy in smaller-sized pieces into pseudos. These are stored in a
94 block pointed to by this field. The next field says how many
95 word-sized pseudos we made. */
96 rtx *aligned_regs;
97 int n_aligned_regs;
100 /* A vector of one char per byte of stack space. A byte if nonzero if
101 the corresponding stack location has been used.
102 This vector is used to prevent a function call within an argument from
103 clobbering any stack already set up. */
104 static char *stack_usage_map;
106 /* Size of STACK_USAGE_MAP. */
107 static int highest_outgoing_arg_in_use;
109 /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
110 stack location's tail call argument has been already stored into the stack.
111 This bitmap is used to prevent sibling call optimization if function tries
112 to use parent's incoming argument slots when they have been already
113 overwritten with tail call arguments. */
114 static sbitmap stored_args_map;
116 /* stack_arg_under_construction is nonzero when an argument may be
117 initialized with a constructor call (including a C function that
118 returns a BLKmode struct) and expand_call must take special action
119 to make sure the object being constructed does not overlap the
120 argument list for the constructor call. */
121 int stack_arg_under_construction;
123 static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT,
124 HOST_WIDE_INT, rtx, rtx, int, rtx, int,
125 CUMULATIVE_ARGS *);
126 static void precompute_register_parameters (int, struct arg_data *, int *);
127 static int store_one_arg (struct arg_data *, rtx, int, int, int);
128 static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
129 static int finalize_must_preallocate (int, int, struct arg_data *,
130 struct args_size *);
131 static void precompute_arguments (int, int, struct arg_data *);
132 static int compute_argument_block_size (int, struct args_size *, int);
133 static void initialize_argument_information (int, struct arg_data *,
134 struct args_size *, int, tree,
135 tree, CUMULATIVE_ARGS *, int,
136 rtx *, int *, int *, int *,
137 bool *, bool);
138 static void compute_argument_addresses (struct arg_data *, rtx, int);
139 static rtx rtx_for_function_call (tree, tree);
140 static void load_register_parameters (struct arg_data *, int, rtx *, int,
141 int, int *);
142 static rtx emit_library_call_value_1 (int, rtx, rtx, enum libcall_type,
143 enum machine_mode, int, va_list);
144 static int special_function_p (tree, int);
145 static int check_sibcall_argument_overlap_1 (rtx);
146 static int check_sibcall_argument_overlap (rtx, struct arg_data *, int);
148 static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
149 unsigned int);
150 static bool shift_returned_value (tree, rtx *);
151 static tree split_complex_values (tree);
152 static tree split_complex_types (tree);
154 #ifdef REG_PARM_STACK_SPACE
155 static rtx save_fixed_argument_area (int, rtx, int *, int *);
156 static void restore_fixed_argument_area (rtx, rtx, int, int);
157 #endif
159 /* Force FUNEXP into a form suitable for the address of a CALL,
160 and return that as an rtx. Also load the static chain register
161 if FNDECL is a nested function.
163 CALL_FUSAGE points to a variable holding the prospective
164 CALL_INSN_FUNCTION_USAGE information. */
167 prepare_call_address (rtx funexp, rtx static_chain_value,
168 rtx *call_fusage, int reg_parm_seen, int sibcallp)
170 /* Make a valid memory address and copy constants through pseudo-regs,
171 but not for a constant address if -fno-function-cse. */
172 if (GET_CODE (funexp) != SYMBOL_REF)
173 /* If we are using registers for parameters, force the
174 function address into a register now. */
175 funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
176 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
177 : memory_address (FUNCTION_MODE, funexp));
178 else if (! sibcallp)
180 #ifndef NO_FUNCTION_CSE
181 if (optimize && ! flag_no_function_cse)
182 funexp = force_reg (Pmode, funexp);
183 #endif
186 if (static_chain_value != 0)
188 static_chain_value = convert_memory_address (Pmode, static_chain_value);
189 emit_move_insn (static_chain_rtx, static_chain_value);
191 if (REG_P (static_chain_rtx))
192 use_reg (call_fusage, static_chain_rtx);
195 return funexp;
198 /* Generate instructions to call function FUNEXP,
199 and optionally pop the results.
200 The CALL_INSN is the first insn generated.
202 FNDECL is the declaration node of the function. This is given to the
203 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
205 FUNTYPE is the data type of the function. This is given to the macro
206 RETURN_POPS_ARGS to determine whether this function pops its own args.
207 We used to allow an identifier for library functions, but that doesn't
208 work when the return type is an aggregate type and the calling convention
209 says that the pointer to this aggregate is to be popped by the callee.
211 STACK_SIZE is the number of bytes of arguments on the stack,
212 ROUNDED_STACK_SIZE is that number rounded up to
213 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
214 both to put into the call insn and to generate explicit popping
215 code if necessary.
217 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
218 It is zero if this call doesn't want a structure value.
220 NEXT_ARG_REG is the rtx that results from executing
221 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
222 just after all the args have had their registers assigned.
223 This could be whatever you like, but normally it is the first
224 arg-register beyond those used for args in this call,
225 or 0 if all the arg-registers are used in this call.
226 It is passed on to `gen_call' so you can put this info in the call insn.
228 VALREG is a hard register in which a value is returned,
229 or 0 if the call does not return a value.
231 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
232 the args to this call were processed.
233 We restore `inhibit_defer_pop' to that value.
235 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
236 denote registers used by the called function. */
238 static void
239 emit_call_1 (rtx funexp, tree fntree, tree fndecl ATTRIBUTE_UNUSED,
240 tree funtype ATTRIBUTE_UNUSED,
241 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED,
242 HOST_WIDE_INT rounded_stack_size,
243 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED,
244 rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg,
245 int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags,
246 CUMULATIVE_ARGS *args_so_far ATTRIBUTE_UNUSED)
248 rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
249 rtx call_insn;
250 int already_popped = 0;
251 HOST_WIDE_INT n_popped = RETURN_POPS_ARGS (fndecl, funtype, stack_size);
252 #if defined (HAVE_call) && defined (HAVE_call_value)
253 rtx struct_value_size_rtx;
254 struct_value_size_rtx = GEN_INT (struct_value_size);
255 #endif
257 #ifdef CALL_POPS_ARGS
258 n_popped += CALL_POPS_ARGS (* args_so_far);
259 #endif
261 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
262 and we don't want to load it into a register as an optimization,
263 because prepare_call_address already did it if it should be done. */
264 if (GET_CODE (funexp) != SYMBOL_REF)
265 funexp = memory_address (FUNCTION_MODE, funexp);
267 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
268 if ((ecf_flags & ECF_SIBCALL)
269 && HAVE_sibcall_pop && HAVE_sibcall_value_pop
270 && (n_popped > 0 || stack_size == 0))
272 rtx n_pop = GEN_INT (n_popped);
273 rtx pat;
275 /* If this subroutine pops its own args, record that in the call insn
276 if possible, for the sake of frame pointer elimination. */
278 if (valreg)
279 pat = GEN_SIBCALL_VALUE_POP (valreg,
280 gen_rtx_MEM (FUNCTION_MODE, funexp),
281 rounded_stack_size_rtx, next_arg_reg,
282 n_pop);
283 else
284 pat = GEN_SIBCALL_POP (gen_rtx_MEM (FUNCTION_MODE, funexp),
285 rounded_stack_size_rtx, next_arg_reg, n_pop);
287 emit_call_insn (pat);
288 already_popped = 1;
290 else
291 #endif
293 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
294 /* If the target has "call" or "call_value" insns, then prefer them
295 if no arguments are actually popped. If the target does not have
296 "call" or "call_value" insns, then we must use the popping versions
297 even if the call has no arguments to pop. */
298 #if defined (HAVE_call) && defined (HAVE_call_value)
299 if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
300 && n_popped > 0 && ! (ecf_flags & ECF_SP_DEPRESSED))
301 #else
302 if (HAVE_call_pop && HAVE_call_value_pop)
303 #endif
305 rtx n_pop = GEN_INT (n_popped);
306 rtx pat;
308 /* If this subroutine pops its own args, record that in the call insn
309 if possible, for the sake of frame pointer elimination. */
311 if (valreg)
312 pat = GEN_CALL_VALUE_POP (valreg,
313 gen_rtx_MEM (FUNCTION_MODE, funexp),
314 rounded_stack_size_rtx, next_arg_reg, n_pop);
315 else
316 pat = GEN_CALL_POP (gen_rtx_MEM (FUNCTION_MODE, funexp),
317 rounded_stack_size_rtx, next_arg_reg, n_pop);
319 emit_call_insn (pat);
320 already_popped = 1;
322 else
323 #endif
325 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
326 if ((ecf_flags & ECF_SIBCALL)
327 && HAVE_sibcall && HAVE_sibcall_value)
329 if (valreg)
330 emit_call_insn (GEN_SIBCALL_VALUE (valreg,
331 gen_rtx_MEM (FUNCTION_MODE, funexp),
332 rounded_stack_size_rtx,
333 next_arg_reg, NULL_RTX));
334 else
335 emit_call_insn (GEN_SIBCALL (gen_rtx_MEM (FUNCTION_MODE, funexp),
336 rounded_stack_size_rtx, next_arg_reg,
337 struct_value_size_rtx));
339 else
340 #endif
342 #if defined (HAVE_call) && defined (HAVE_call_value)
343 if (HAVE_call && HAVE_call_value)
345 if (valreg)
346 emit_call_insn (GEN_CALL_VALUE (valreg,
347 gen_rtx_MEM (FUNCTION_MODE, funexp),
348 rounded_stack_size_rtx, next_arg_reg,
349 NULL_RTX));
350 else
351 emit_call_insn (GEN_CALL (gen_rtx_MEM (FUNCTION_MODE, funexp),
352 rounded_stack_size_rtx, next_arg_reg,
353 struct_value_size_rtx));
355 else
356 #endif
357 gcc_unreachable ();
359 /* Find the call we just emitted. */
360 call_insn = last_call_insn ();
362 /* Mark memory as used for "pure" function call. */
363 if (ecf_flags & ECF_PURE)
364 call_fusage
365 = gen_rtx_EXPR_LIST
366 (VOIDmode,
367 gen_rtx_USE (VOIDmode,
368 gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode))),
369 call_fusage);
371 /* Put the register usage information there. */
372 add_function_usage_to (call_insn, call_fusage);
374 /* If this is a const call, then set the insn's unchanging bit. */
375 if (ecf_flags & (ECF_CONST | ECF_PURE))
376 CONST_OR_PURE_CALL_P (call_insn) = 1;
378 /* If this call can't throw, attach a REG_EH_REGION reg note to that
379 effect. */
380 if (ecf_flags & ECF_NOTHROW)
381 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, const0_rtx,
382 REG_NOTES (call_insn));
383 else
385 int rn = lookup_stmt_eh_region (fntree);
387 /* If rn < 0, then either (1) tree-ssa not used or (2) doesn't
388 throw, which we already took care of. */
389 if (rn > 0)
390 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, GEN_INT (rn),
391 REG_NOTES (call_insn));
392 note_current_region_may_contain_throw ();
395 if (ecf_flags & ECF_NORETURN)
396 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_NORETURN, const0_rtx,
397 REG_NOTES (call_insn));
398 if (ecf_flags & ECF_ALWAYS_RETURN)
399 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_ALWAYS_RETURN, const0_rtx,
400 REG_NOTES (call_insn));
402 if (ecf_flags & ECF_RETURNS_TWICE)
404 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_SETJMP, const0_rtx,
405 REG_NOTES (call_insn));
406 current_function_calls_setjmp = 1;
409 SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
411 /* Restore this now, so that we do defer pops for this call's args
412 if the context of the call as a whole permits. */
413 inhibit_defer_pop = old_inhibit_defer_pop;
415 if (n_popped > 0)
417 if (!already_popped)
418 CALL_INSN_FUNCTION_USAGE (call_insn)
419 = gen_rtx_EXPR_LIST (VOIDmode,
420 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
421 CALL_INSN_FUNCTION_USAGE (call_insn));
422 rounded_stack_size -= n_popped;
423 rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
424 stack_pointer_delta -= n_popped;
427 if (!ACCUMULATE_OUTGOING_ARGS)
429 /* If returning from the subroutine does not automatically pop the args,
430 we need an instruction to pop them sooner or later.
431 Perhaps do it now; perhaps just record how much space to pop later.
433 If returning from the subroutine does pop the args, indicate that the
434 stack pointer will be changed. */
436 if (rounded_stack_size != 0)
438 if (ecf_flags & (ECF_SP_DEPRESSED | ECF_NORETURN | ECF_LONGJMP))
439 /* Just pretend we did the pop. */
440 stack_pointer_delta -= rounded_stack_size;
441 else if (flag_defer_pop && inhibit_defer_pop == 0
442 && ! (ecf_flags & (ECF_CONST | ECF_PURE)))
443 pending_stack_adjust += rounded_stack_size;
444 else
445 adjust_stack (rounded_stack_size_rtx);
448 /* When we accumulate outgoing args, we must avoid any stack manipulations.
449 Restore the stack pointer to its original value now. Usually
450 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
451 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
452 popping variants of functions exist as well.
454 ??? We may optimize similar to defer_pop above, but it is
455 probably not worthwhile.
457 ??? It will be worthwhile to enable combine_stack_adjustments even for
458 such machines. */
459 else if (n_popped)
460 anti_adjust_stack (GEN_INT (n_popped));
463 /* Determine if the function identified by NAME and FNDECL is one with
464 special properties we wish to know about.
466 For example, if the function might return more than one time (setjmp), then
467 set RETURNS_TWICE to a nonzero value.
469 Similarly set LONGJMP for if the function is in the longjmp family.
471 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
472 space from the stack such as alloca. */
474 static int
475 special_function_p (tree fndecl, int flags)
477 if (fndecl && DECL_NAME (fndecl)
478 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
479 /* Exclude functions not at the file scope, or not `extern',
480 since they are not the magic functions we would otherwise
481 think they are.
482 FIXME: this should be handled with attributes, not with this
483 hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
484 because you can declare fork() inside a function if you
485 wish. */
486 && (DECL_CONTEXT (fndecl) == NULL_TREE
487 || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL)
488 && TREE_PUBLIC (fndecl))
490 const char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
491 const char *tname = name;
493 /* We assume that alloca will always be called by name. It
494 makes no sense to pass it as a pointer-to-function to
495 anything that does not understand its behavior. */
496 if (((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
497 && name[0] == 'a'
498 && ! strcmp (name, "alloca"))
499 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
500 && name[0] == '_'
501 && ! strcmp (name, "__builtin_alloca"))))
502 flags |= ECF_MAY_BE_ALLOCA;
504 /* Disregard prefix _, __ or __x. */
505 if (name[0] == '_')
507 if (name[1] == '_' && name[2] == 'x')
508 tname += 3;
509 else if (name[1] == '_')
510 tname += 2;
511 else
512 tname += 1;
515 if (tname[0] == 's')
517 if ((tname[1] == 'e'
518 && (! strcmp (tname, "setjmp")
519 || ! strcmp (tname, "setjmp_syscall")))
520 || (tname[1] == 'i'
521 && ! strcmp (tname, "sigsetjmp"))
522 || (tname[1] == 'a'
523 && ! strcmp (tname, "savectx")))
524 flags |= ECF_RETURNS_TWICE;
526 if (tname[1] == 'i'
527 && ! strcmp (tname, "siglongjmp"))
528 flags |= ECF_LONGJMP;
530 else if ((tname[0] == 'q' && tname[1] == 's'
531 && ! strcmp (tname, "qsetjmp"))
532 || (tname[0] == 'v' && tname[1] == 'f'
533 && ! strcmp (tname, "vfork")))
534 flags |= ECF_RETURNS_TWICE;
536 else if (tname[0] == 'l' && tname[1] == 'o'
537 && ! strcmp (tname, "longjmp"))
538 flags |= ECF_LONGJMP;
541 return flags;
544 /* Return nonzero when tree represent call to longjmp. */
547 setjmp_call_p (tree fndecl)
549 return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE;
552 /* Return true when exp contains alloca call. */
553 bool
554 alloca_call_p (tree exp)
556 if (TREE_CODE (exp) == CALL_EXPR
557 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
558 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
559 == FUNCTION_DECL)
560 && (special_function_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
561 0) & ECF_MAY_BE_ALLOCA))
562 return true;
563 return false;
566 /* Detect flags (function attributes) from the function decl or type node. */
569 flags_from_decl_or_type (tree exp)
571 int flags = 0;
572 tree type = exp;
574 if (DECL_P (exp))
576 struct cgraph_rtl_info *i = cgraph_rtl_info (exp);
577 type = TREE_TYPE (exp);
579 if (i)
581 if (i->pure_function)
582 flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
583 if (i->const_function)
584 flags |= ECF_CONST | ECF_LIBCALL_BLOCK;
587 /* The function exp may have the `malloc' attribute. */
588 if (DECL_IS_MALLOC (exp))
589 flags |= ECF_MALLOC;
591 /* The function exp may have the `pure' attribute. */
592 if (DECL_IS_PURE (exp))
593 flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
595 if (TREE_NOTHROW (exp))
596 flags |= ECF_NOTHROW;
598 if (TREE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
599 flags |= ECF_LIBCALL_BLOCK | ECF_CONST;
601 flags = special_function_p (exp, flags);
603 else if (TYPE_P (exp) && TYPE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
604 flags |= ECF_CONST;
606 if (TREE_THIS_VOLATILE (exp))
607 flags |= ECF_NORETURN;
609 /* Mark if the function returns with the stack pointer depressed. We
610 cannot consider it pure or constant in that case. */
611 if (TREE_CODE (type) == FUNCTION_TYPE && TYPE_RETURNS_STACK_DEPRESSED (type))
613 flags |= ECF_SP_DEPRESSED;
614 flags &= ~(ECF_PURE | ECF_CONST | ECF_LIBCALL_BLOCK);
617 return flags;
620 /* Detect flags from a CALL_EXPR. */
623 call_expr_flags (tree t)
625 int flags;
626 tree decl = get_callee_fndecl (t);
628 if (decl)
629 flags = flags_from_decl_or_type (decl);
630 else
632 t = TREE_TYPE (TREE_OPERAND (t, 0));
633 if (t && TREE_CODE (t) == POINTER_TYPE)
634 flags = flags_from_decl_or_type (TREE_TYPE (t));
635 else
636 flags = 0;
639 return flags;
642 /* Precompute all register parameters as described by ARGS, storing values
643 into fields within the ARGS array.
645 NUM_ACTUALS indicates the total number elements in the ARGS array.
647 Set REG_PARM_SEEN if we encounter a register parameter. */
649 static void
650 precompute_register_parameters (int num_actuals, struct arg_data *args,
651 int *reg_parm_seen)
653 int i;
655 *reg_parm_seen = 0;
657 for (i = 0; i < num_actuals; i++)
658 if (args[i].reg != 0 && ! args[i].pass_on_stack)
660 *reg_parm_seen = 1;
662 if (args[i].value == 0)
664 push_temp_slots ();
665 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
666 VOIDmode, 0);
667 preserve_temp_slots (args[i].value);
668 pop_temp_slots ();
671 /* If the value is a non-legitimate constant, force it into a
672 pseudo now. TLS symbols sometimes need a call to resolve. */
673 if (CONSTANT_P (args[i].value)
674 && !LEGITIMATE_CONSTANT_P (args[i].value))
675 args[i].value = force_reg (args[i].mode, args[i].value);
677 /* If we are to promote the function arg to a wider mode,
678 do it now. */
680 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
681 args[i].value
682 = convert_modes (args[i].mode,
683 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
684 args[i].value, args[i].unsignedp);
686 /* If we're going to have to load the value by parts, pull the
687 parts into pseudos. The part extraction process can involve
688 non-trivial computation. */
689 if (GET_CODE (args[i].reg) == PARALLEL)
691 tree type = TREE_TYPE (args[i].tree_value);
692 args[i].parallel_value
693 = emit_group_load_into_temps (args[i].reg, args[i].value,
694 type, int_size_in_bytes (type));
697 /* If the value is expensive, and we are inside an appropriately
698 short loop, put the value into a pseudo and then put the pseudo
699 into the hard reg.
701 For small register classes, also do this if this call uses
702 register parameters. This is to avoid reload conflicts while
703 loading the parameters registers. */
705 else if ((! (REG_P (args[i].value)
706 || (GET_CODE (args[i].value) == SUBREG
707 && REG_P (SUBREG_REG (args[i].value)))))
708 && args[i].mode != BLKmode
709 && rtx_cost (args[i].value, SET) > COSTS_N_INSNS (1)
710 && ((SMALL_REGISTER_CLASSES && *reg_parm_seen)
711 || optimize))
712 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
716 #ifdef REG_PARM_STACK_SPACE
718 /* The argument list is the property of the called routine and it
719 may clobber it. If the fixed area has been used for previous
720 parameters, we must save and restore it. */
722 static rtx
723 save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
725 int low;
726 int high;
728 /* Compute the boundary of the area that needs to be saved, if any. */
729 high = reg_parm_stack_space;
730 #ifdef ARGS_GROW_DOWNWARD
731 high += 1;
732 #endif
733 if (high > highest_outgoing_arg_in_use)
734 high = highest_outgoing_arg_in_use;
736 for (low = 0; low < high; low++)
737 if (stack_usage_map[low] != 0)
739 int num_to_save;
740 enum machine_mode save_mode;
741 int delta;
742 rtx stack_area;
743 rtx save_area;
745 while (stack_usage_map[--high] == 0)
748 *low_to_save = low;
749 *high_to_save = high;
751 num_to_save = high - low + 1;
752 save_mode = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
754 /* If we don't have the required alignment, must do this
755 in BLKmode. */
756 if ((low & (MIN (GET_MODE_SIZE (save_mode),
757 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
758 save_mode = BLKmode;
760 #ifdef ARGS_GROW_DOWNWARD
761 delta = -high;
762 #else
763 delta = low;
764 #endif
765 stack_area = gen_rtx_MEM (save_mode,
766 memory_address (save_mode,
767 plus_constant (argblock,
768 delta)));
770 set_mem_align (stack_area, PARM_BOUNDARY);
771 if (save_mode == BLKmode)
773 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
774 emit_block_move (validize_mem (save_area), stack_area,
775 GEN_INT (num_to_save), BLOCK_OP_CALL_PARM);
777 else
779 save_area = gen_reg_rtx (save_mode);
780 emit_move_insn (save_area, stack_area);
783 return save_area;
786 return NULL_RTX;
789 static void
790 restore_fixed_argument_area (rtx save_area, rtx argblock, int high_to_save, int low_to_save)
792 enum machine_mode save_mode = GET_MODE (save_area);
793 int delta;
794 rtx stack_area;
796 #ifdef ARGS_GROW_DOWNWARD
797 delta = -high_to_save;
798 #else
799 delta = low_to_save;
800 #endif
801 stack_area = gen_rtx_MEM (save_mode,
802 memory_address (save_mode,
803 plus_constant (argblock, delta)));
804 set_mem_align (stack_area, PARM_BOUNDARY);
806 if (save_mode != BLKmode)
807 emit_move_insn (stack_area, save_area);
808 else
809 emit_block_move (stack_area, validize_mem (save_area),
810 GEN_INT (high_to_save - low_to_save + 1),
811 BLOCK_OP_CALL_PARM);
813 #endif /* REG_PARM_STACK_SPACE */
815 /* If any elements in ARGS refer to parameters that are to be passed in
816 registers, but not in memory, and whose alignment does not permit a
817 direct copy into registers. Copy the values into a group of pseudos
818 which we will later copy into the appropriate hard registers.
820 Pseudos for each unaligned argument will be stored into the array
821 args[argnum].aligned_regs. The caller is responsible for deallocating
822 the aligned_regs array if it is nonzero. */
824 static void
825 store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals)
827 int i, j;
829 for (i = 0; i < num_actuals; i++)
830 if (args[i].reg != 0 && ! args[i].pass_on_stack
831 && args[i].mode == BLKmode
832 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
833 < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
835 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
836 int nregs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
837 int endian_correction = 0;
839 args[i].n_aligned_regs = args[i].partial ? args[i].partial : nregs;
840 args[i].aligned_regs = xmalloc (sizeof (rtx) * args[i].n_aligned_regs);
842 /* Structures smaller than a word are normally aligned to the
843 least significant byte. On a BYTES_BIG_ENDIAN machine,
844 this means we must skip the empty high order bytes when
845 calculating the bit offset. */
846 if (bytes < UNITS_PER_WORD
847 #ifdef BLOCK_REG_PADDING
848 && (BLOCK_REG_PADDING (args[i].mode,
849 TREE_TYPE (args[i].tree_value), 1)
850 == downward)
851 #else
852 && BYTES_BIG_ENDIAN
853 #endif
855 endian_correction = BITS_PER_WORD - bytes * BITS_PER_UNIT;
857 for (j = 0; j < args[i].n_aligned_regs; j++)
859 rtx reg = gen_reg_rtx (word_mode);
860 rtx word = operand_subword_force (args[i].value, j, BLKmode);
861 int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
863 args[i].aligned_regs[j] = reg;
864 word = extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
865 word_mode, word_mode);
867 /* There is no need to restrict this code to loading items
868 in TYPE_ALIGN sized hunks. The bitfield instructions can
869 load up entire word sized registers efficiently.
871 ??? This may not be needed anymore.
872 We use to emit a clobber here but that doesn't let later
873 passes optimize the instructions we emit. By storing 0 into
874 the register later passes know the first AND to zero out the
875 bitfield being set in the register is unnecessary. The store
876 of 0 will be deleted as will at least the first AND. */
878 emit_move_insn (reg, const0_rtx);
880 bytes -= bitsize / BITS_PER_UNIT;
881 store_bit_field (reg, bitsize, endian_correction, word_mode,
882 word);
887 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
888 ACTPARMS.
890 NUM_ACTUALS is the total number of parameters.
892 N_NAMED_ARGS is the total number of named arguments.
894 FNDECL is the tree code for the target of this call (if known)
896 ARGS_SO_FAR holds state needed by the target to know where to place
897 the next argument.
899 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
900 for arguments which are passed in registers.
902 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
903 and may be modified by this routine.
905 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
906 flags which may may be modified by this routine.
908 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
909 that requires allocation of stack space.
911 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
912 the thunked-to function. */
914 static void
915 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
916 struct arg_data *args,
917 struct args_size *args_size,
918 int n_named_args ATTRIBUTE_UNUSED,
919 tree actparms, tree fndecl,
920 CUMULATIVE_ARGS *args_so_far,
921 int reg_parm_stack_space,
922 rtx *old_stack_level, int *old_pending_adj,
923 int *must_preallocate, int *ecf_flags,
924 bool *may_tailcall, bool call_from_thunk_p)
926 /* 1 if scanning parms front to back, -1 if scanning back to front. */
927 int inc;
929 /* Count arg position in order args appear. */
930 int argpos;
932 int i;
933 tree p;
935 args_size->constant = 0;
936 args_size->var = 0;
938 /* In this loop, we consider args in the order they are written.
939 We fill up ARGS from the front or from the back if necessary
940 so that in any case the first arg to be pushed ends up at the front. */
942 if (PUSH_ARGS_REVERSED)
944 i = num_actuals - 1, inc = -1;
945 /* In this case, must reverse order of args
946 so that we compute and push the last arg first. */
948 else
950 i = 0, inc = 1;
953 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
954 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
956 tree type = TREE_TYPE (TREE_VALUE (p));
957 int unsignedp;
958 enum machine_mode mode;
960 args[i].tree_value = TREE_VALUE (p);
962 /* Replace erroneous argument with constant zero. */
963 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
964 args[i].tree_value = integer_zero_node, type = integer_type_node;
966 /* If TYPE is a transparent union, pass things the way we would
967 pass the first field of the union. We have already verified that
968 the modes are the same. */
969 if (TREE_CODE (type) == UNION_TYPE && TYPE_TRANSPARENT_UNION (type))
970 type = TREE_TYPE (TYPE_FIELDS (type));
972 /* Decide where to pass this arg.
974 args[i].reg is nonzero if all or part is passed in registers.
976 args[i].partial is nonzero if part but not all is passed in registers,
977 and the exact value says how many words are passed in registers.
979 args[i].pass_on_stack is nonzero if the argument must at least be
980 computed on the stack. It may then be loaded back into registers
981 if args[i].reg is nonzero.
983 These decisions are driven by the FUNCTION_... macros and must agree
984 with those made by function.c. */
986 /* See if this argument should be passed by invisible reference. */
987 if (pass_by_reference (args_so_far, TYPE_MODE (type),
988 type, argpos < n_named_args))
990 bool callee_copies;
991 tree base;
993 callee_copies
994 = reference_callee_copied (args_so_far, TYPE_MODE (type),
995 type, argpos < n_named_args);
997 /* If we're compiling a thunk, pass through invisible references
998 instead of making a copy. */
999 if (call_from_thunk_p
1000 || (callee_copies
1001 && !TREE_ADDRESSABLE (type)
1002 && (base = get_base_address (args[i].tree_value))
1003 && (!DECL_P (base) || MEM_P (DECL_RTL (base)))))
1005 /* We can't use sibcalls if a callee-copied argument is
1006 stored in the current function's frame. */
1007 if (!call_from_thunk_p && DECL_P (base) && !TREE_STATIC (base))
1008 *may_tailcall = false;
1010 args[i].tree_value = build_fold_addr_expr (args[i].tree_value);
1011 type = TREE_TYPE (args[i].tree_value);
1013 *ecf_flags &= ~(ECF_CONST | ECF_LIBCALL_BLOCK);
1015 else
1017 /* We make a copy of the object and pass the address to the
1018 function being called. */
1019 rtx copy;
1021 if (!COMPLETE_TYPE_P (type)
1022 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1023 || (flag_stack_check && ! STACK_CHECK_BUILTIN
1024 && (0 < compare_tree_int (TYPE_SIZE_UNIT (type),
1025 STACK_CHECK_MAX_VAR_SIZE))))
1027 /* This is a variable-sized object. Make space on the stack
1028 for it. */
1029 rtx size_rtx = expr_size (TREE_VALUE (p));
1031 if (*old_stack_level == 0)
1033 emit_stack_save (SAVE_BLOCK, old_stack_level, NULL_RTX);
1034 *old_pending_adj = pending_stack_adjust;
1035 pending_stack_adjust = 0;
1038 copy = gen_rtx_MEM (BLKmode,
1039 allocate_dynamic_stack_space
1040 (size_rtx, NULL_RTX, TYPE_ALIGN (type)));
1041 set_mem_attributes (copy, type, 1);
1043 else
1044 copy = assign_temp (type, 0, 1, 0);
1046 store_expr (args[i].tree_value, copy, 0);
1048 if (callee_copies)
1049 *ecf_flags &= ~(ECF_CONST | ECF_LIBCALL_BLOCK);
1050 else
1051 *ecf_flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
1053 args[i].tree_value
1054 = build_fold_addr_expr (make_tree (type, copy));
1055 type = TREE_TYPE (args[i].tree_value);
1056 *may_tailcall = false;
1060 mode = TYPE_MODE (type);
1061 unsignedp = TYPE_UNSIGNED (type);
1063 if (targetm.calls.promote_function_args (fndecl ? TREE_TYPE (fndecl) : 0))
1064 mode = promote_mode (type, mode, &unsignedp, 1);
1066 args[i].unsignedp = unsignedp;
1067 args[i].mode = mode;
1069 args[i].reg = FUNCTION_ARG (*args_so_far, mode, type,
1070 argpos < n_named_args);
1071 #ifdef FUNCTION_INCOMING_ARG
1072 /* If this is a sibling call and the machine has register windows, the
1073 register window has to be unwinded before calling the routine, so
1074 arguments have to go into the incoming registers. */
1075 args[i].tail_call_reg = FUNCTION_INCOMING_ARG (*args_so_far, mode, type,
1076 argpos < n_named_args);
1077 #else
1078 args[i].tail_call_reg = args[i].reg;
1079 #endif
1081 if (args[i].reg)
1082 args[i].partial
1083 = FUNCTION_ARG_PARTIAL_NREGS (*args_so_far, mode, type,
1084 argpos < n_named_args);
1086 args[i].pass_on_stack = targetm.calls.must_pass_in_stack (mode, type);
1088 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1089 it means that we are to pass this arg in the register(s) designated
1090 by the PARALLEL, but also to pass it in the stack. */
1091 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1092 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1093 args[i].pass_on_stack = 1;
1095 /* If this is an addressable type, we must preallocate the stack
1096 since we must evaluate the object into its final location.
1098 If this is to be passed in both registers and the stack, it is simpler
1099 to preallocate. */
1100 if (TREE_ADDRESSABLE (type)
1101 || (args[i].pass_on_stack && args[i].reg != 0))
1102 *must_preallocate = 1;
1104 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1105 we cannot consider this function call constant. */
1106 if (TREE_ADDRESSABLE (type))
1107 *ecf_flags &= ~ECF_LIBCALL_BLOCK;
1109 /* Compute the stack-size of this argument. */
1110 if (args[i].reg == 0 || args[i].partial != 0
1111 || reg_parm_stack_space > 0
1112 || args[i].pass_on_stack)
1113 locate_and_pad_parm (mode, type,
1114 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1116 #else
1117 args[i].reg != 0,
1118 #endif
1119 args[i].pass_on_stack ? 0 : args[i].partial,
1120 fndecl, args_size, &args[i].locate);
1121 #ifdef BLOCK_REG_PADDING
1122 else
1123 /* The argument is passed entirely in registers. See at which
1124 end it should be padded. */
1125 args[i].locate.where_pad =
1126 BLOCK_REG_PADDING (mode, type,
1127 int_size_in_bytes (type) <= UNITS_PER_WORD);
1128 #endif
1130 /* Update ARGS_SIZE, the total stack space for args so far. */
1132 args_size->constant += args[i].locate.size.constant;
1133 if (args[i].locate.size.var)
1134 ADD_PARM_SIZE (*args_size, args[i].locate.size.var);
1136 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1137 have been used, etc. */
1139 FUNCTION_ARG_ADVANCE (*args_so_far, TYPE_MODE (type), type,
1140 argpos < n_named_args);
1144 /* Update ARGS_SIZE to contain the total size for the argument block.
1145 Return the original constant component of the argument block's size.
1147 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1148 for arguments passed in registers. */
1150 static int
1151 compute_argument_block_size (int reg_parm_stack_space,
1152 struct args_size *args_size,
1153 int preferred_stack_boundary ATTRIBUTE_UNUSED)
1155 int unadjusted_args_size = args_size->constant;
1157 /* For accumulate outgoing args mode we don't need to align, since the frame
1158 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1159 backends from generating misaligned frame sizes. */
1160 if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY)
1161 preferred_stack_boundary = STACK_BOUNDARY;
1163 /* Compute the actual size of the argument block required. The variable
1164 and constant sizes must be combined, the size may have to be rounded,
1165 and there may be a minimum required size. */
1167 if (args_size->var)
1169 args_size->var = ARGS_SIZE_TREE (*args_size);
1170 args_size->constant = 0;
1172 preferred_stack_boundary /= BITS_PER_UNIT;
1173 if (preferred_stack_boundary > 1)
1175 /* We don't handle this case yet. To handle it correctly we have
1176 to add the delta, round and subtract the delta.
1177 Currently no machine description requires this support. */
1178 gcc_assert (!(stack_pointer_delta & (preferred_stack_boundary - 1)));
1179 args_size->var = round_up (args_size->var, preferred_stack_boundary);
1182 if (reg_parm_stack_space > 0)
1184 args_size->var
1185 = size_binop (MAX_EXPR, args_size->var,
1186 ssize_int (reg_parm_stack_space));
1188 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1189 /* The area corresponding to register parameters is not to count in
1190 the size of the block we need. So make the adjustment. */
1191 args_size->var
1192 = size_binop (MINUS_EXPR, args_size->var,
1193 ssize_int (reg_parm_stack_space));
1194 #endif
1197 else
1199 preferred_stack_boundary /= BITS_PER_UNIT;
1200 if (preferred_stack_boundary < 1)
1201 preferred_stack_boundary = 1;
1202 args_size->constant = (((args_size->constant
1203 + stack_pointer_delta
1204 + preferred_stack_boundary - 1)
1205 / preferred_stack_boundary
1206 * preferred_stack_boundary)
1207 - stack_pointer_delta);
1209 args_size->constant = MAX (args_size->constant,
1210 reg_parm_stack_space);
1212 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1213 args_size->constant -= reg_parm_stack_space;
1214 #endif
1216 return unadjusted_args_size;
1219 /* Precompute parameters as needed for a function call.
1221 FLAGS is mask of ECF_* constants.
1223 NUM_ACTUALS is the number of arguments.
1225 ARGS is an array containing information for each argument; this
1226 routine fills in the INITIAL_VALUE and VALUE fields for each
1227 precomputed argument. */
1229 static void
1230 precompute_arguments (int flags, int num_actuals, struct arg_data *args)
1232 int i;
1234 /* If this is a libcall, then precompute all arguments so that we do not
1235 get extraneous instructions emitted as part of the libcall sequence. */
1236 if ((flags & ECF_LIBCALL_BLOCK) == 0)
1237 return;
1239 for (i = 0; i < num_actuals; i++)
1241 enum machine_mode mode;
1243 /* If this is an addressable type, we cannot pre-evaluate it. */
1244 gcc_assert (!TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)));
1246 args[i].initial_value = args[i].value
1247 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1249 mode = TYPE_MODE (TREE_TYPE (args[i].tree_value));
1250 if (mode != args[i].mode)
1252 args[i].value
1253 = convert_modes (args[i].mode, mode,
1254 args[i].value, args[i].unsignedp);
1255 #if defined(PROMOTE_FUNCTION_MODE) && !defined(PROMOTE_MODE)
1256 /* CSE will replace this only if it contains args[i].value
1257 pseudo, so convert it down to the declared mode using
1258 a SUBREG. */
1259 if (REG_P (args[i].value)
1260 && GET_MODE_CLASS (args[i].mode) == MODE_INT)
1262 args[i].initial_value
1263 = gen_lowpart_SUBREG (mode, args[i].value);
1264 SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1265 SUBREG_PROMOTED_UNSIGNED_SET (args[i].initial_value,
1266 args[i].unsignedp);
1268 #endif
1273 /* Given the current state of MUST_PREALLOCATE and information about
1274 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1275 compute and return the final value for MUST_PREALLOCATE. */
1277 static int
1278 finalize_must_preallocate (int must_preallocate, int num_actuals, struct arg_data *args, struct args_size *args_size)
1280 /* See if we have or want to preallocate stack space.
1282 If we would have to push a partially-in-regs parm
1283 before other stack parms, preallocate stack space instead.
1285 If the size of some parm is not a multiple of the required stack
1286 alignment, we must preallocate.
1288 If the total size of arguments that would otherwise create a copy in
1289 a temporary (such as a CALL) is more than half the total argument list
1290 size, preallocation is faster.
1292 Another reason to preallocate is if we have a machine (like the m88k)
1293 where stack alignment is required to be maintained between every
1294 pair of insns, not just when the call is made. However, we assume here
1295 that such machines either do not have push insns (and hence preallocation
1296 would occur anyway) or the problem is taken care of with
1297 PUSH_ROUNDING. */
1299 if (! must_preallocate)
1301 int partial_seen = 0;
1302 int copy_to_evaluate_size = 0;
1303 int i;
1305 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1307 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1308 partial_seen = 1;
1309 else if (partial_seen && args[i].reg == 0)
1310 must_preallocate = 1;
1312 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1313 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1314 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1315 || TREE_CODE (args[i].tree_value) == COND_EXPR
1316 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1317 copy_to_evaluate_size
1318 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1321 if (copy_to_evaluate_size * 2 >= args_size->constant
1322 && args_size->constant > 0)
1323 must_preallocate = 1;
1325 return must_preallocate;
1328 /* If we preallocated stack space, compute the address of each argument
1329 and store it into the ARGS array.
1331 We need not ensure it is a valid memory address here; it will be
1332 validized when it is used.
1334 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1336 static void
1337 compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals)
1339 if (argblock)
1341 rtx arg_reg = argblock;
1342 int i, arg_offset = 0;
1344 if (GET_CODE (argblock) == PLUS)
1345 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1347 for (i = 0; i < num_actuals; i++)
1349 rtx offset = ARGS_SIZE_RTX (args[i].locate.offset);
1350 rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
1351 rtx addr;
1353 /* Skip this parm if it will not be passed on the stack. */
1354 if (! args[i].pass_on_stack && args[i].reg != 0)
1355 continue;
1357 if (GET_CODE (offset) == CONST_INT)
1358 addr = plus_constant (arg_reg, INTVAL (offset));
1359 else
1360 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1362 addr = plus_constant (addr, arg_offset);
1363 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1364 set_mem_align (args[i].stack, PARM_BOUNDARY);
1365 set_mem_attributes (args[i].stack,
1366 TREE_TYPE (args[i].tree_value), 1);
1368 if (GET_CODE (slot_offset) == CONST_INT)
1369 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1370 else
1371 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1373 addr = plus_constant (addr, arg_offset);
1374 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1375 set_mem_align (args[i].stack_slot, PARM_BOUNDARY);
1376 set_mem_attributes (args[i].stack_slot,
1377 TREE_TYPE (args[i].tree_value), 1);
1379 /* Function incoming arguments may overlap with sibling call
1380 outgoing arguments and we cannot allow reordering of reads
1381 from function arguments with stores to outgoing arguments
1382 of sibling calls. */
1383 set_mem_alias_set (args[i].stack, 0);
1384 set_mem_alias_set (args[i].stack_slot, 0);
1389 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1390 in a call instruction.
1392 FNDECL is the tree node for the target function. For an indirect call
1393 FNDECL will be NULL_TREE.
1395 ADDR is the operand 0 of CALL_EXPR for this call. */
1397 static rtx
1398 rtx_for_function_call (tree fndecl, tree addr)
1400 rtx funexp;
1402 /* Get the function to call, in the form of RTL. */
1403 if (fndecl)
1405 /* If this is the first use of the function, see if we need to
1406 make an external definition for it. */
1407 if (! TREE_USED (fndecl))
1409 assemble_external (fndecl);
1410 TREE_USED (fndecl) = 1;
1413 /* Get a SYMBOL_REF rtx for the function address. */
1414 funexp = XEXP (DECL_RTL (fndecl), 0);
1416 else
1417 /* Generate an rtx (probably a pseudo-register) for the address. */
1419 push_temp_slots ();
1420 funexp = expand_expr (addr, NULL_RTX, VOIDmode, 0);
1421 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1423 return funexp;
1426 /* Do the register loads required for any wholly-register parms or any
1427 parms which are passed both on the stack and in a register. Their
1428 expressions were already evaluated.
1430 Mark all register-parms as living through the call, putting these USE
1431 insns in the CALL_INSN_FUNCTION_USAGE field.
1433 When IS_SIBCALL, perform the check_sibcall_overlap_argument_overlap
1434 checking, setting *SIBCALL_FAILURE if appropriate. */
1436 static void
1437 load_register_parameters (struct arg_data *args, int num_actuals,
1438 rtx *call_fusage, int flags, int is_sibcall,
1439 int *sibcall_failure)
1441 int i, j;
1443 for (i = 0; i < num_actuals; i++)
1445 rtx reg = ((flags & ECF_SIBCALL)
1446 ? args[i].tail_call_reg : args[i].reg);
1447 if (reg)
1449 int partial = args[i].partial;
1450 int nregs;
1451 int size = 0;
1452 rtx before_arg = get_last_insn ();
1453 /* Set to non-negative if must move a word at a time, even if just
1454 one word (e.g, partial == 1 && mode == DFmode). Set to -1 if
1455 we just use a normal move insn. This value can be zero if the
1456 argument is a zero size structure with no fields. */
1457 nregs = -1;
1458 if (partial)
1459 nregs = partial;
1460 else if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode)
1462 size = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1463 nregs = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
1465 else
1466 size = GET_MODE_SIZE (args[i].mode);
1468 /* Handle calls that pass values in multiple non-contiguous
1469 locations. The Irix 6 ABI has examples of this. */
1471 if (GET_CODE (reg) == PARALLEL)
1472 emit_group_move (reg, args[i].parallel_value);
1474 /* If simple case, just do move. If normal partial, store_one_arg
1475 has already loaded the register for us. In all other cases,
1476 load the register(s) from memory. */
1478 else if (nregs == -1)
1480 emit_move_insn (reg, args[i].value);
1481 #ifdef BLOCK_REG_PADDING
1482 /* Handle case where we have a value that needs shifting
1483 up to the msb. eg. a QImode value and we're padding
1484 upward on a BYTES_BIG_ENDIAN machine. */
1485 if (size < UNITS_PER_WORD
1486 && (args[i].locate.where_pad
1487 == (BYTES_BIG_ENDIAN ? upward : downward)))
1489 rtx x;
1490 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
1492 /* Assigning REG here rather than a temp makes CALL_FUSAGE
1493 report the whole reg as used. Strictly speaking, the
1494 call only uses SIZE bytes at the msb end, but it doesn't
1495 seem worth generating rtl to say that. */
1496 reg = gen_rtx_REG (word_mode, REGNO (reg));
1497 x = expand_shift (LSHIFT_EXPR, word_mode, reg,
1498 build_int_cst (NULL_TREE, shift),
1499 reg, 1);
1500 if (x != reg)
1501 emit_move_insn (reg, x);
1503 #endif
1506 /* If we have pre-computed the values to put in the registers in
1507 the case of non-aligned structures, copy them in now. */
1509 else if (args[i].n_aligned_regs != 0)
1510 for (j = 0; j < args[i].n_aligned_regs; j++)
1511 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
1512 args[i].aligned_regs[j]);
1514 else if (partial == 0 || args[i].pass_on_stack)
1516 rtx mem = validize_mem (args[i].value);
1518 /* Handle a BLKmode that needs shifting. */
1519 if (nregs == 1 && size < UNITS_PER_WORD
1520 #ifdef BLOCK_REG_PADDING
1521 && args[i].locate.where_pad == downward
1522 #else
1523 && BYTES_BIG_ENDIAN
1524 #endif
1527 rtx tem = operand_subword_force (mem, 0, args[i].mode);
1528 rtx ri = gen_rtx_REG (word_mode, REGNO (reg));
1529 rtx x = gen_reg_rtx (word_mode);
1530 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
1531 enum tree_code dir = BYTES_BIG_ENDIAN ? RSHIFT_EXPR
1532 : LSHIFT_EXPR;
1534 emit_move_insn (x, tem);
1535 x = expand_shift (dir, word_mode, x,
1536 build_int_cst (NULL_TREE, shift),
1537 ri, 1);
1538 if (x != ri)
1539 emit_move_insn (ri, x);
1541 else
1542 move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode);
1545 /* When a parameter is a block, and perhaps in other cases, it is
1546 possible that it did a load from an argument slot that was
1547 already clobbered. */
1548 if (is_sibcall
1549 && check_sibcall_argument_overlap (before_arg, &args[i], 0))
1550 *sibcall_failure = 1;
1552 /* Handle calls that pass values in multiple non-contiguous
1553 locations. The Irix 6 ABI has examples of this. */
1554 if (GET_CODE (reg) == PARALLEL)
1555 use_group_regs (call_fusage, reg);
1556 else if (nregs == -1)
1557 use_reg (call_fusage, reg);
1558 else
1559 use_regs (call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1564 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
1565 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
1566 bytes, then we would need to push some additional bytes to pad the
1567 arguments. So, we compute an adjust to the stack pointer for an
1568 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
1569 bytes. Then, when the arguments are pushed the stack will be perfectly
1570 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
1571 be popped after the call. Returns the adjustment. */
1573 static int
1574 combine_pending_stack_adjustment_and_call (int unadjusted_args_size,
1575 struct args_size *args_size,
1576 unsigned int preferred_unit_stack_boundary)
1578 /* The number of bytes to pop so that the stack will be
1579 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
1580 HOST_WIDE_INT adjustment;
1581 /* The alignment of the stack after the arguments are pushed, if we
1582 just pushed the arguments without adjust the stack here. */
1583 unsigned HOST_WIDE_INT unadjusted_alignment;
1585 unadjusted_alignment
1586 = ((stack_pointer_delta + unadjusted_args_size)
1587 % preferred_unit_stack_boundary);
1589 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
1590 as possible -- leaving just enough left to cancel out the
1591 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
1592 PENDING_STACK_ADJUST is non-negative, and congruent to
1593 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
1595 /* Begin by trying to pop all the bytes. */
1596 unadjusted_alignment
1597 = (unadjusted_alignment
1598 - (pending_stack_adjust % preferred_unit_stack_boundary));
1599 adjustment = pending_stack_adjust;
1600 /* Push enough additional bytes that the stack will be aligned
1601 after the arguments are pushed. */
1602 if (preferred_unit_stack_boundary > 1)
1604 if (unadjusted_alignment > 0)
1605 adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
1606 else
1607 adjustment += unadjusted_alignment;
1610 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
1611 bytes after the call. The right number is the entire
1612 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
1613 by the arguments in the first place. */
1614 args_size->constant
1615 = pending_stack_adjust - adjustment + unadjusted_args_size;
1617 return adjustment;
1620 /* Scan X expression if it does not dereference any argument slots
1621 we already clobbered by tail call arguments (as noted in stored_args_map
1622 bitmap).
1623 Return nonzero if X expression dereferences such argument slots,
1624 zero otherwise. */
1626 static int
1627 check_sibcall_argument_overlap_1 (rtx x)
1629 RTX_CODE code;
1630 int i, j;
1631 unsigned int k;
1632 const char *fmt;
1634 if (x == NULL_RTX)
1635 return 0;
1637 code = GET_CODE (x);
1639 if (code == MEM)
1641 if (XEXP (x, 0) == current_function_internal_arg_pointer)
1642 i = 0;
1643 else if (GET_CODE (XEXP (x, 0)) == PLUS
1644 && XEXP (XEXP (x, 0), 0) ==
1645 current_function_internal_arg_pointer
1646 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1647 i = INTVAL (XEXP (XEXP (x, 0), 1));
1648 else
1649 return 1;
1651 #ifdef ARGS_GROW_DOWNWARD
1652 i = -i - GET_MODE_SIZE (GET_MODE (x));
1653 #endif
1655 for (k = 0; k < GET_MODE_SIZE (GET_MODE (x)); k++)
1656 if (i + k < stored_args_map->n_bits
1657 && TEST_BIT (stored_args_map, i + k))
1658 return 1;
1660 return 0;
1663 /* Scan all subexpressions. */
1664 fmt = GET_RTX_FORMAT (code);
1665 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
1667 if (*fmt == 'e')
1669 if (check_sibcall_argument_overlap_1 (XEXP (x, i)))
1670 return 1;
1672 else if (*fmt == 'E')
1674 for (j = 0; j < XVECLEN (x, i); j++)
1675 if (check_sibcall_argument_overlap_1 (XVECEXP (x, i, j)))
1676 return 1;
1679 return 0;
1682 /* Scan sequence after INSN if it does not dereference any argument slots
1683 we already clobbered by tail call arguments (as noted in stored_args_map
1684 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
1685 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
1686 should be 0). Return nonzero if sequence after INSN dereferences such argument
1687 slots, zero otherwise. */
1689 static int
1690 check_sibcall_argument_overlap (rtx insn, struct arg_data *arg, int mark_stored_args_map)
1692 int low, high;
1694 if (insn == NULL_RTX)
1695 insn = get_insns ();
1696 else
1697 insn = NEXT_INSN (insn);
1699 for (; insn; insn = NEXT_INSN (insn))
1700 if (INSN_P (insn)
1701 && check_sibcall_argument_overlap_1 (PATTERN (insn)))
1702 break;
1704 if (mark_stored_args_map)
1706 #ifdef ARGS_GROW_DOWNWARD
1707 low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
1708 #else
1709 low = arg->locate.slot_offset.constant;
1710 #endif
1712 for (high = low + arg->locate.size.constant; low < high; low++)
1713 SET_BIT (stored_args_map, low);
1715 return insn != NULL_RTX;
1718 /* If function value *VALUE was returned at the most significant end of a
1719 register, shift it towards the least significant end and convert it to
1720 TYPE's mode. Return true and update *VALUE if some action was needed.
1722 TYPE is the type of the function's return value, which is known not
1723 to have mode BLKmode. */
1725 static bool
1726 shift_returned_value (tree type, rtx *value)
1728 if (targetm.calls.return_in_msb (type))
1730 HOST_WIDE_INT shift;
1732 shift = (GET_MODE_BITSIZE (GET_MODE (*value))
1733 - BITS_PER_UNIT * int_size_in_bytes (type));
1734 if (shift > 0)
1736 /* Shift the value into the low part of the register. */
1737 *value = expand_binop (GET_MODE (*value), lshr_optab, *value,
1738 GEN_INT (shift), 0, 1, OPTAB_WIDEN);
1740 /* Truncate it to the type's mode, or its integer equivalent.
1741 This is subject to TRULY_NOOP_TRUNCATION. */
1742 *value = convert_to_mode (int_mode_for_mode (TYPE_MODE (type)),
1743 *value, 0);
1745 /* Now convert it to the final form. */
1746 *value = gen_lowpart (TYPE_MODE (type), *value);
1747 return true;
1750 return false;
1753 /* Remove all REG_EQUIV notes found in the insn chain. */
1755 static void
1756 purge_reg_equiv_notes (void)
1758 rtx insn;
1760 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
1762 while (1)
1764 rtx note = find_reg_note (insn, REG_EQUIV, 0);
1765 if (note)
1767 /* Remove the note and keep looking at the notes for
1768 this insn. */
1769 remove_note (insn, note);
1770 continue;
1772 break;
1777 /* Generate all the code for a function call
1778 and return an rtx for its value.
1779 Store the value in TARGET (specified as an rtx) if convenient.
1780 If the value is stored in TARGET then TARGET is returned.
1781 If IGNORE is nonzero, then we ignore the value of the function call. */
1784 expand_call (tree exp, rtx target, int ignore)
1786 /* Nonzero if we are currently expanding a call. */
1787 static int currently_expanding_call = 0;
1789 /* List of actual parameters. */
1790 tree actparms = TREE_OPERAND (exp, 1);
1791 /* RTX for the function to be called. */
1792 rtx funexp;
1793 /* Sequence of insns to perform a normal "call". */
1794 rtx normal_call_insns = NULL_RTX;
1795 /* Sequence of insns to perform a tail "call". */
1796 rtx tail_call_insns = NULL_RTX;
1797 /* Data type of the function. */
1798 tree funtype;
1799 tree type_arg_types;
1800 /* Declaration of the function being called,
1801 or 0 if the function is computed (not known by name). */
1802 tree fndecl = 0;
1803 /* The type of the function being called. */
1804 tree fntype;
1805 bool try_tail_call = CALL_EXPR_TAILCALL (exp);
1806 int pass;
1808 /* Register in which non-BLKmode value will be returned,
1809 or 0 if no value or if value is BLKmode. */
1810 rtx valreg;
1811 /* Address where we should return a BLKmode value;
1812 0 if value not BLKmode. */
1813 rtx structure_value_addr = 0;
1814 /* Nonzero if that address is being passed by treating it as
1815 an extra, implicit first parameter. Otherwise,
1816 it is passed by being copied directly into struct_value_rtx. */
1817 int structure_value_addr_parm = 0;
1818 /* Size of aggregate value wanted, or zero if none wanted
1819 or if we are using the non-reentrant PCC calling convention
1820 or expecting the value in registers. */
1821 HOST_WIDE_INT struct_value_size = 0;
1822 /* Nonzero if called function returns an aggregate in memory PCC style,
1823 by returning the address of where to find it. */
1824 int pcc_struct_value = 0;
1825 rtx struct_value = 0;
1827 /* Number of actual parameters in this call, including struct value addr. */
1828 int num_actuals;
1829 /* Number of named args. Args after this are anonymous ones
1830 and they must all go on the stack. */
1831 int n_named_args;
1833 /* Vector of information about each argument.
1834 Arguments are numbered in the order they will be pushed,
1835 not the order they are written. */
1836 struct arg_data *args;
1838 /* Total size in bytes of all the stack-parms scanned so far. */
1839 struct args_size args_size;
1840 struct args_size adjusted_args_size;
1841 /* Size of arguments before any adjustments (such as rounding). */
1842 int unadjusted_args_size;
1843 /* Data on reg parms scanned so far. */
1844 CUMULATIVE_ARGS args_so_far;
1845 /* Nonzero if a reg parm has been scanned. */
1846 int reg_parm_seen;
1847 /* Nonzero if this is an indirect function call. */
1849 /* Nonzero if we must avoid push-insns in the args for this call.
1850 If stack space is allocated for register parameters, but not by the
1851 caller, then it is preallocated in the fixed part of the stack frame.
1852 So the entire argument block must then be preallocated (i.e., we
1853 ignore PUSH_ROUNDING in that case). */
1855 int must_preallocate = !PUSH_ARGS;
1857 /* Size of the stack reserved for parameter registers. */
1858 int reg_parm_stack_space = 0;
1860 /* Address of space preallocated for stack parms
1861 (on machines that lack push insns), or 0 if space not preallocated. */
1862 rtx argblock = 0;
1864 /* Mask of ECF_ flags. */
1865 int flags = 0;
1866 #ifdef REG_PARM_STACK_SPACE
1867 /* Define the boundary of the register parm stack space that needs to be
1868 saved, if any. */
1869 int low_to_save, high_to_save;
1870 rtx save_area = 0; /* Place that it is saved */
1871 #endif
1873 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
1874 char *initial_stack_usage_map = stack_usage_map;
1876 int old_stack_allocated;
1878 /* State variables to track stack modifications. */
1879 rtx old_stack_level = 0;
1880 int old_stack_arg_under_construction = 0;
1881 int old_pending_adj = 0;
1882 int old_inhibit_defer_pop = inhibit_defer_pop;
1884 /* Some stack pointer alterations we make are performed via
1885 allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
1886 which we then also need to save/restore along the way. */
1887 int old_stack_pointer_delta = 0;
1889 rtx call_fusage;
1890 tree p = TREE_OPERAND (exp, 0);
1891 tree addr = TREE_OPERAND (exp, 0);
1892 int i;
1893 /* The alignment of the stack, in bits. */
1894 unsigned HOST_WIDE_INT preferred_stack_boundary;
1895 /* The alignment of the stack, in bytes. */
1896 unsigned HOST_WIDE_INT preferred_unit_stack_boundary;
1897 /* The static chain value to use for this call. */
1898 rtx static_chain_value;
1899 /* See if this is "nothrow" function call. */
1900 if (TREE_NOTHROW (exp))
1901 flags |= ECF_NOTHROW;
1903 /* See if we can find a DECL-node for the actual function, and get the
1904 function attributes (flags) from the function decl or type node. */
1905 fndecl = get_callee_fndecl (exp);
1906 if (fndecl)
1908 fntype = TREE_TYPE (fndecl);
1909 flags |= flags_from_decl_or_type (fndecl);
1911 else
1913 fntype = TREE_TYPE (TREE_TYPE (p));
1914 flags |= flags_from_decl_or_type (fntype);
1917 struct_value = targetm.calls.struct_value_rtx (fntype, 0);
1919 /* Warn if this value is an aggregate type,
1920 regardless of which calling convention we are using for it. */
1921 if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
1922 warning ("function call has aggregate value");
1924 /* If the result of a pure or const function call is ignored (or void),
1925 and none of its arguments are volatile, we can avoid expanding the
1926 call and just evaluate the arguments for side-effects. */
1927 if ((flags & (ECF_CONST | ECF_PURE))
1928 && (ignore || target == const0_rtx
1929 || TYPE_MODE (TREE_TYPE (exp)) == VOIDmode))
1931 bool volatilep = false;
1932 tree arg;
1934 for (arg = actparms; arg; arg = TREE_CHAIN (arg))
1935 if (TREE_THIS_VOLATILE (TREE_VALUE (arg)))
1937 volatilep = true;
1938 break;
1941 if (! volatilep)
1943 for (arg = actparms; arg; arg = TREE_CHAIN (arg))
1944 expand_expr (TREE_VALUE (arg), const0_rtx,
1945 VOIDmode, EXPAND_NORMAL);
1946 return const0_rtx;
1950 #ifdef REG_PARM_STACK_SPACE
1951 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
1952 #endif
1954 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1955 if (reg_parm_stack_space > 0 && PUSH_ARGS)
1956 must_preallocate = 1;
1957 #endif
1959 /* Set up a place to return a structure. */
1961 /* Cater to broken compilers. */
1962 if (aggregate_value_p (exp, fndecl))
1964 /* This call returns a big structure. */
1965 flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
1967 #ifdef PCC_STATIC_STRUCT_RETURN
1969 pcc_struct_value = 1;
1971 #else /* not PCC_STATIC_STRUCT_RETURN */
1973 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
1975 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (exp))
1977 /* The structure value address arg is already in actparms.
1978 Pull it out. It might be nice to just leave it there, but
1979 we need to set structure_value_addr. */
1980 tree return_arg = TREE_VALUE (actparms);
1981 actparms = TREE_CHAIN (actparms);
1982 structure_value_addr = expand_expr (return_arg, NULL_RTX,
1983 VOIDmode, EXPAND_NORMAL);
1985 else if (target && MEM_P (target))
1986 structure_value_addr = XEXP (target, 0);
1987 else
1989 /* For variable-sized objects, we must be called with a target
1990 specified. If we were to allocate space on the stack here,
1991 we would have no way of knowing when to free it. */
1992 rtx d = assign_temp (TREE_TYPE (exp), 1, 1, 1);
1994 mark_temp_addr_taken (d);
1995 structure_value_addr = XEXP (d, 0);
1996 target = 0;
1999 #endif /* not PCC_STATIC_STRUCT_RETURN */
2002 /* Figure out the amount to which the stack should be aligned. */
2003 preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2004 if (fndecl)
2006 struct cgraph_rtl_info *i = cgraph_rtl_info (fndecl);
2007 if (i && i->preferred_incoming_stack_boundary)
2008 preferred_stack_boundary = i->preferred_incoming_stack_boundary;
2011 /* Operand 0 is a pointer-to-function; get the type of the function. */
2012 funtype = TREE_TYPE (addr);
2013 gcc_assert (POINTER_TYPE_P (funtype));
2014 funtype = TREE_TYPE (funtype);
2016 /* Munge the tree to split complex arguments into their imaginary
2017 and real parts. */
2018 if (targetm.calls.split_complex_arg)
2020 type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype));
2021 actparms = split_complex_values (actparms);
2023 else
2024 type_arg_types = TYPE_ARG_TYPES (funtype);
2026 if (flags & ECF_MAY_BE_ALLOCA)
2027 current_function_calls_alloca = 1;
2029 /* If struct_value_rtx is 0, it means pass the address
2030 as if it were an extra parameter. */
2031 if (structure_value_addr && struct_value == 0)
2033 /* If structure_value_addr is a REG other than
2034 virtual_outgoing_args_rtx, we can use always use it. If it
2035 is not a REG, we must always copy it into a register.
2036 If it is virtual_outgoing_args_rtx, we must copy it to another
2037 register in some cases. */
2038 rtx temp = (!REG_P (structure_value_addr)
2039 || (ACCUMULATE_OUTGOING_ARGS
2040 && stack_arg_under_construction
2041 && structure_value_addr == virtual_outgoing_args_rtx)
2042 ? copy_addr_to_reg (convert_memory_address
2043 (Pmode, structure_value_addr))
2044 : structure_value_addr);
2046 actparms
2047 = tree_cons (error_mark_node,
2048 make_tree (build_pointer_type (TREE_TYPE (funtype)),
2049 temp),
2050 actparms);
2051 structure_value_addr_parm = 1;
2054 /* Count the arguments and set NUM_ACTUALS. */
2055 for (p = actparms, num_actuals = 0; p; p = TREE_CHAIN (p))
2056 num_actuals++;
2058 /* Compute number of named args.
2059 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2061 if (type_arg_types != 0)
2062 n_named_args
2063 = (list_length (type_arg_types)
2064 /* Count the struct value address, if it is passed as a parm. */
2065 + structure_value_addr_parm);
2066 else
2067 /* If we know nothing, treat all args as named. */
2068 n_named_args = num_actuals;
2070 /* Start updating where the next arg would go.
2072 On some machines (such as the PA) indirect calls have a different
2073 calling convention than normal calls. The fourth argument in
2074 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2075 or not. */
2076 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, fndecl, n_named_args);
2078 /* Now possibly adjust the number of named args.
2079 Normally, don't include the last named arg if anonymous args follow.
2080 We do include the last named arg if
2081 targetm.calls.strict_argument_naming() returns nonzero.
2082 (If no anonymous args follow, the result of list_length is actually
2083 one too large. This is harmless.)
2085 If targetm.calls.pretend_outgoing_varargs_named() returns
2086 nonzero, and targetm.calls.strict_argument_naming() returns zero,
2087 this machine will be able to place unnamed args that were passed
2088 in registers into the stack. So treat all args as named. This
2089 allows the insns emitting for a specific argument list to be
2090 independent of the function declaration.
2092 If targetm.calls.pretend_outgoing_varargs_named() returns zero,
2093 we do not have any reliable way to pass unnamed args in
2094 registers, so we must force them into memory. */
2096 if (type_arg_types != 0
2097 && targetm.calls.strict_argument_naming (&args_so_far))
2099 else if (type_arg_types != 0
2100 && ! targetm.calls.pretend_outgoing_varargs_named (&args_so_far))
2101 /* Don't include the last named arg. */
2102 --n_named_args;
2103 else
2104 /* Treat all args as named. */
2105 n_named_args = num_actuals;
2107 /* Make a vector to hold all the information about each arg. */
2108 args = alloca (num_actuals * sizeof (struct arg_data));
2109 memset (args, 0, num_actuals * sizeof (struct arg_data));
2111 /* Build up entries in the ARGS array, compute the size of the
2112 arguments into ARGS_SIZE, etc. */
2113 initialize_argument_information (num_actuals, args, &args_size,
2114 n_named_args, actparms, fndecl,
2115 &args_so_far, reg_parm_stack_space,
2116 &old_stack_level, &old_pending_adj,
2117 &must_preallocate, &flags,
2118 &try_tail_call, CALL_FROM_THUNK_P (exp));
2120 if (args_size.var)
2122 /* If this function requires a variable-sized argument list, don't
2123 try to make a cse'able block for this call. We may be able to
2124 do this eventually, but it is too complicated to keep track of
2125 what insns go in the cse'able block and which don't. */
2127 flags &= ~ECF_LIBCALL_BLOCK;
2128 must_preallocate = 1;
2131 /* Now make final decision about preallocating stack space. */
2132 must_preallocate = finalize_must_preallocate (must_preallocate,
2133 num_actuals, args,
2134 &args_size);
2136 /* If the structure value address will reference the stack pointer, we
2137 must stabilize it. We don't need to do this if we know that we are
2138 not going to adjust the stack pointer in processing this call. */
2140 if (structure_value_addr
2141 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
2142 || reg_mentioned_p (virtual_outgoing_args_rtx,
2143 structure_value_addr))
2144 && (args_size.var
2145 || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant)))
2146 structure_value_addr = copy_to_reg (structure_value_addr);
2148 /* Tail calls can make things harder to debug, and we've traditionally
2149 pushed these optimizations into -O2. Don't try if we're already
2150 expanding a call, as that means we're an argument. Don't try if
2151 there's cleanups, as we know there's code to follow the call. */
2153 if (currently_expanding_call++ != 0
2154 || !flag_optimize_sibling_calls
2155 || args_size.var
2156 || lookup_stmt_eh_region (exp) >= 0)
2157 try_tail_call = 0;
2159 /* Rest of purposes for tail call optimizations to fail. */
2160 if (
2161 #ifdef HAVE_sibcall_epilogue
2162 !HAVE_sibcall_epilogue
2163 #else
2165 #endif
2166 || !try_tail_call
2167 /* Doing sibling call optimization needs some work, since
2168 structure_value_addr can be allocated on the stack.
2169 It does not seem worth the effort since few optimizable
2170 sibling calls will return a structure. */
2171 || structure_value_addr != NULL_RTX
2172 /* Check whether the target is able to optimize the call
2173 into a sibcall. */
2174 || !targetm.function_ok_for_sibcall (fndecl, exp)
2175 /* Functions that do not return exactly once may not be sibcall
2176 optimized. */
2177 || (flags & (ECF_RETURNS_TWICE | ECF_LONGJMP | ECF_NORETURN))
2178 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr)))
2179 /* If the called function is nested in the current one, it might access
2180 some of the caller's arguments, but could clobber them beforehand if
2181 the argument areas are shared. */
2182 || (fndecl && decl_function_context (fndecl) == current_function_decl)
2183 /* If this function requires more stack slots than the current
2184 function, we cannot change it into a sibling call. */
2185 || args_size.constant > current_function_args_size
2186 /* If the callee pops its own arguments, then it must pop exactly
2187 the same number of arguments as the current function. */
2188 || (RETURN_POPS_ARGS (fndecl, funtype, args_size.constant)
2189 != RETURN_POPS_ARGS (current_function_decl,
2190 TREE_TYPE (current_function_decl),
2191 current_function_args_size))
2192 || !lang_hooks.decls.ok_for_sibcall (fndecl))
2193 try_tail_call = 0;
2195 /* Ensure current function's preferred stack boundary is at least
2196 what we need. We don't have to increase alignment for recursive
2197 functions. */
2198 if (cfun->preferred_stack_boundary < preferred_stack_boundary
2199 && fndecl != current_function_decl)
2200 cfun->preferred_stack_boundary = preferred_stack_boundary;
2201 if (fndecl == current_function_decl)
2202 cfun->recursive_call_emit = true;
2204 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
2206 /* We want to make two insn chains; one for a sibling call, the other
2207 for a normal call. We will select one of the two chains after
2208 initial RTL generation is complete. */
2209 for (pass = try_tail_call ? 0 : 1; pass < 2; pass++)
2211 int sibcall_failure = 0;
2212 /* We want to emit any pending stack adjustments before the tail
2213 recursion "call". That way we know any adjustment after the tail
2214 recursion call can be ignored if we indeed use the tail
2215 call expansion. */
2216 int save_pending_stack_adjust = 0;
2217 int save_stack_pointer_delta = 0;
2218 rtx insns;
2219 rtx before_call, next_arg_reg;
2221 if (pass == 0)
2223 /* State variables we need to save and restore between
2224 iterations. */
2225 save_pending_stack_adjust = pending_stack_adjust;
2226 save_stack_pointer_delta = stack_pointer_delta;
2228 if (pass)
2229 flags &= ~ECF_SIBCALL;
2230 else
2231 flags |= ECF_SIBCALL;
2233 /* Other state variables that we must reinitialize each time
2234 through the loop (that are not initialized by the loop itself). */
2235 argblock = 0;
2236 call_fusage = 0;
2238 /* Start a new sequence for the normal call case.
2240 From this point on, if the sibling call fails, we want to set
2241 sibcall_failure instead of continuing the loop. */
2242 start_sequence ();
2244 /* Don't let pending stack adjusts add up to too much.
2245 Also, do all pending adjustments now if there is any chance
2246 this might be a call to alloca or if we are expanding a sibling
2247 call sequence or if we are calling a function that is to return
2248 with stack pointer depressed. */
2249 if (pending_stack_adjust >= 32
2250 || (pending_stack_adjust > 0
2251 && (flags & (ECF_MAY_BE_ALLOCA | ECF_SP_DEPRESSED)))
2252 || pass == 0)
2253 do_pending_stack_adjust ();
2255 /* When calling a const function, we must pop the stack args right away,
2256 so that the pop is deleted or moved with the call. */
2257 if (pass && (flags & ECF_LIBCALL_BLOCK))
2258 NO_DEFER_POP;
2260 /* Precompute any arguments as needed. */
2261 if (pass)
2262 precompute_arguments (flags, num_actuals, args);
2264 /* Now we are about to start emitting insns that can be deleted
2265 if a libcall is deleted. */
2266 if (pass && (flags & (ECF_LIBCALL_BLOCK | ECF_MALLOC)))
2267 start_sequence ();
2269 adjusted_args_size = args_size;
2270 /* Compute the actual size of the argument block required. The variable
2271 and constant sizes must be combined, the size may have to be rounded,
2272 and there may be a minimum required size. When generating a sibcall
2273 pattern, do not round up, since we'll be re-using whatever space our
2274 caller provided. */
2275 unadjusted_args_size
2276 = compute_argument_block_size (reg_parm_stack_space,
2277 &adjusted_args_size,
2278 (pass == 0 ? 0
2279 : preferred_stack_boundary));
2281 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
2283 /* The argument block when performing a sibling call is the
2284 incoming argument block. */
2285 if (pass == 0)
2287 argblock = virtual_incoming_args_rtx;
2288 argblock
2289 #ifdef STACK_GROWS_DOWNWARD
2290 = plus_constant (argblock, current_function_pretend_args_size);
2291 #else
2292 = plus_constant (argblock, -current_function_pretend_args_size);
2293 #endif
2294 stored_args_map = sbitmap_alloc (args_size.constant);
2295 sbitmap_zero (stored_args_map);
2298 /* If we have no actual push instructions, or shouldn't use them,
2299 make space for all args right now. */
2300 else if (adjusted_args_size.var != 0)
2302 if (old_stack_level == 0)
2304 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2305 old_stack_pointer_delta = stack_pointer_delta;
2306 old_pending_adj = pending_stack_adjust;
2307 pending_stack_adjust = 0;
2308 /* stack_arg_under_construction says whether a stack arg is
2309 being constructed at the old stack level. Pushing the stack
2310 gets a clean outgoing argument block. */
2311 old_stack_arg_under_construction = stack_arg_under_construction;
2312 stack_arg_under_construction = 0;
2314 argblock = push_block (ARGS_SIZE_RTX (adjusted_args_size), 0, 0);
2316 else
2318 /* Note that we must go through the motions of allocating an argument
2319 block even if the size is zero because we may be storing args
2320 in the area reserved for register arguments, which may be part of
2321 the stack frame. */
2323 int needed = adjusted_args_size.constant;
2325 /* Store the maximum argument space used. It will be pushed by
2326 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2327 checking). */
2329 if (needed > current_function_outgoing_args_size)
2330 current_function_outgoing_args_size = needed;
2332 if (must_preallocate)
2334 if (ACCUMULATE_OUTGOING_ARGS)
2336 /* Since the stack pointer will never be pushed, it is
2337 possible for the evaluation of a parm to clobber
2338 something we have already written to the stack.
2339 Since most function calls on RISC machines do not use
2340 the stack, this is uncommon, but must work correctly.
2342 Therefore, we save any area of the stack that was already
2343 written and that we are using. Here we set up to do this
2344 by making a new stack usage map from the old one. The
2345 actual save will be done by store_one_arg.
2347 Another approach might be to try to reorder the argument
2348 evaluations to avoid this conflicting stack usage. */
2350 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2351 /* Since we will be writing into the entire argument area,
2352 the map must be allocated for its entire size, not just
2353 the part that is the responsibility of the caller. */
2354 needed += reg_parm_stack_space;
2355 #endif
2357 #ifdef ARGS_GROW_DOWNWARD
2358 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2359 needed + 1);
2360 #else
2361 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2362 needed);
2363 #endif
2364 stack_usage_map = alloca (highest_outgoing_arg_in_use);
2366 if (initial_highest_arg_in_use)
2367 memcpy (stack_usage_map, initial_stack_usage_map,
2368 initial_highest_arg_in_use);
2370 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2371 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
2372 (highest_outgoing_arg_in_use
2373 - initial_highest_arg_in_use));
2374 needed = 0;
2376 /* The address of the outgoing argument list must not be
2377 copied to a register here, because argblock would be left
2378 pointing to the wrong place after the call to
2379 allocate_dynamic_stack_space below. */
2381 argblock = virtual_outgoing_args_rtx;
2383 else
2385 if (inhibit_defer_pop == 0)
2387 /* Try to reuse some or all of the pending_stack_adjust
2388 to get this space. */
2389 needed
2390 = (combine_pending_stack_adjustment_and_call
2391 (unadjusted_args_size,
2392 &adjusted_args_size,
2393 preferred_unit_stack_boundary));
2395 /* combine_pending_stack_adjustment_and_call computes
2396 an adjustment before the arguments are allocated.
2397 Account for them and see whether or not the stack
2398 needs to go up or down. */
2399 needed = unadjusted_args_size - needed;
2401 if (needed < 0)
2403 /* We're releasing stack space. */
2404 /* ??? We can avoid any adjustment at all if we're
2405 already aligned. FIXME. */
2406 pending_stack_adjust = -needed;
2407 do_pending_stack_adjust ();
2408 needed = 0;
2410 else
2411 /* We need to allocate space. We'll do that in
2412 push_block below. */
2413 pending_stack_adjust = 0;
2416 /* Special case this because overhead of `push_block' in
2417 this case is non-trivial. */
2418 if (needed == 0)
2419 argblock = virtual_outgoing_args_rtx;
2420 else
2422 argblock = push_block (GEN_INT (needed), 0, 0);
2423 #ifdef ARGS_GROW_DOWNWARD
2424 argblock = plus_constant (argblock, needed);
2425 #endif
2428 /* We only really need to call `copy_to_reg' in the case
2429 where push insns are going to be used to pass ARGBLOCK
2430 to a function call in ARGS. In that case, the stack
2431 pointer changes value from the allocation point to the
2432 call point, and hence the value of
2433 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
2434 as well always do it. */
2435 argblock = copy_to_reg (argblock);
2440 if (ACCUMULATE_OUTGOING_ARGS)
2442 /* The save/restore code in store_one_arg handles all
2443 cases except one: a constructor call (including a C
2444 function returning a BLKmode struct) to initialize
2445 an argument. */
2446 if (stack_arg_under_construction)
2448 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2449 rtx push_size = GEN_INT (reg_parm_stack_space
2450 + adjusted_args_size.constant);
2451 #else
2452 rtx push_size = GEN_INT (adjusted_args_size.constant);
2453 #endif
2454 if (old_stack_level == 0)
2456 emit_stack_save (SAVE_BLOCK, &old_stack_level,
2457 NULL_RTX);
2458 old_stack_pointer_delta = stack_pointer_delta;
2459 old_pending_adj = pending_stack_adjust;
2460 pending_stack_adjust = 0;
2461 /* stack_arg_under_construction says whether a stack
2462 arg is being constructed at the old stack level.
2463 Pushing the stack gets a clean outgoing argument
2464 block. */
2465 old_stack_arg_under_construction
2466 = stack_arg_under_construction;
2467 stack_arg_under_construction = 0;
2468 /* Make a new map for the new argument list. */
2469 stack_usage_map = alloca (highest_outgoing_arg_in_use);
2470 memset (stack_usage_map, 0, highest_outgoing_arg_in_use);
2471 highest_outgoing_arg_in_use = 0;
2473 allocate_dynamic_stack_space (push_size, NULL_RTX,
2474 BITS_PER_UNIT);
2477 /* If argument evaluation might modify the stack pointer,
2478 copy the address of the argument list to a register. */
2479 for (i = 0; i < num_actuals; i++)
2480 if (args[i].pass_on_stack)
2482 argblock = copy_addr_to_reg (argblock);
2483 break;
2487 compute_argument_addresses (args, argblock, num_actuals);
2489 /* If we push args individually in reverse order, perform stack alignment
2490 before the first push (the last arg). */
2491 if (PUSH_ARGS_REVERSED && argblock == 0
2492 && adjusted_args_size.constant != unadjusted_args_size)
2494 /* When the stack adjustment is pending, we get better code
2495 by combining the adjustments. */
2496 if (pending_stack_adjust
2497 && ! (flags & ECF_LIBCALL_BLOCK)
2498 && ! inhibit_defer_pop)
2500 pending_stack_adjust
2501 = (combine_pending_stack_adjustment_and_call
2502 (unadjusted_args_size,
2503 &adjusted_args_size,
2504 preferred_unit_stack_boundary));
2505 do_pending_stack_adjust ();
2507 else if (argblock == 0)
2508 anti_adjust_stack (GEN_INT (adjusted_args_size.constant
2509 - unadjusted_args_size));
2511 /* Now that the stack is properly aligned, pops can't safely
2512 be deferred during the evaluation of the arguments. */
2513 NO_DEFER_POP;
2515 funexp = rtx_for_function_call (fndecl, addr);
2517 /* Figure out the register where the value, if any, will come back. */
2518 valreg = 0;
2519 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
2520 && ! structure_value_addr)
2522 if (pcc_struct_value)
2523 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
2524 fndecl, (pass == 0));
2525 else
2526 valreg = hard_function_value (TREE_TYPE (exp), fndecl, (pass == 0));
2529 /* Precompute all register parameters. It isn't safe to compute anything
2530 once we have started filling any specific hard regs. */
2531 precompute_register_parameters (num_actuals, args, &reg_parm_seen);
2533 if (TREE_OPERAND (exp, 2))
2534 static_chain_value = expand_expr (TREE_OPERAND (exp, 2),
2535 NULL_RTX, VOIDmode, 0);
2536 else
2537 static_chain_value = 0;
2539 #ifdef REG_PARM_STACK_SPACE
2540 /* Save the fixed argument area if it's part of the caller's frame and
2541 is clobbered by argument setup for this call. */
2542 if (ACCUMULATE_OUTGOING_ARGS && pass)
2543 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
2544 &low_to_save, &high_to_save);
2545 #endif
2547 /* Now store (and compute if necessary) all non-register parms.
2548 These come before register parms, since they can require block-moves,
2549 which could clobber the registers used for register parms.
2550 Parms which have partial registers are not stored here,
2551 but we do preallocate space here if they want that. */
2553 for (i = 0; i < num_actuals; i++)
2554 if (args[i].reg == 0 || args[i].pass_on_stack)
2556 rtx before_arg = get_last_insn ();
2558 if (store_one_arg (&args[i], argblock, flags,
2559 adjusted_args_size.var != 0,
2560 reg_parm_stack_space)
2561 || (pass == 0
2562 && check_sibcall_argument_overlap (before_arg,
2563 &args[i], 1)))
2564 sibcall_failure = 1;
2566 if (flags & ECF_CONST
2567 && args[i].stack
2568 && args[i].value == args[i].stack)
2569 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
2570 gen_rtx_USE (VOIDmode,
2571 args[i].value),
2572 call_fusage);
2575 /* If we have a parm that is passed in registers but not in memory
2576 and whose alignment does not permit a direct copy into registers,
2577 make a group of pseudos that correspond to each register that we
2578 will later fill. */
2579 if (STRICT_ALIGNMENT)
2580 store_unaligned_arguments_into_pseudos (args, num_actuals);
2582 /* Now store any partially-in-registers parm.
2583 This is the last place a block-move can happen. */
2584 if (reg_parm_seen)
2585 for (i = 0; i < num_actuals; i++)
2586 if (args[i].partial != 0 && ! args[i].pass_on_stack)
2588 rtx before_arg = get_last_insn ();
2590 if (store_one_arg (&args[i], argblock, flags,
2591 adjusted_args_size.var != 0,
2592 reg_parm_stack_space)
2593 || (pass == 0
2594 && check_sibcall_argument_overlap (before_arg,
2595 &args[i], 1)))
2596 sibcall_failure = 1;
2599 /* If we pushed args in forward order, perform stack alignment
2600 after pushing the last arg. */
2601 if (!PUSH_ARGS_REVERSED && argblock == 0)
2602 anti_adjust_stack (GEN_INT (adjusted_args_size.constant
2603 - unadjusted_args_size));
2605 /* If register arguments require space on the stack and stack space
2606 was not preallocated, allocate stack space here for arguments
2607 passed in registers. */
2608 #ifdef OUTGOING_REG_PARM_STACK_SPACE
2609 if (!ACCUMULATE_OUTGOING_ARGS
2610 && must_preallocate == 0 && reg_parm_stack_space > 0)
2611 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
2612 #endif
2614 /* Pass the function the address in which to return a
2615 structure value. */
2616 if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
2618 structure_value_addr
2619 = convert_memory_address (Pmode, structure_value_addr);
2620 emit_move_insn (struct_value,
2621 force_reg (Pmode,
2622 force_operand (structure_value_addr,
2623 NULL_RTX)));
2625 if (REG_P (struct_value))
2626 use_reg (&call_fusage, struct_value);
2629 funexp = prepare_call_address (funexp, static_chain_value,
2630 &call_fusage, reg_parm_seen, pass == 0);
2632 load_register_parameters (args, num_actuals, &call_fusage, flags,
2633 pass == 0, &sibcall_failure);
2635 /* Save a pointer to the last insn before the call, so that we can
2636 later safely search backwards to find the CALL_INSN. */
2637 before_call = get_last_insn ();
2639 /* Set up next argument register. For sibling calls on machines
2640 with register windows this should be the incoming register. */
2641 #ifdef FUNCTION_INCOMING_ARG
2642 if (pass == 0)
2643 next_arg_reg = FUNCTION_INCOMING_ARG (args_so_far, VOIDmode,
2644 void_type_node, 1);
2645 else
2646 #endif
2647 next_arg_reg = FUNCTION_ARG (args_so_far, VOIDmode,
2648 void_type_node, 1);
2650 /* All arguments and registers used for the call must be set up by
2651 now! */
2653 /* Stack must be properly aligned now. */
2654 gcc_assert (!pass
2655 || !(stack_pointer_delta % preferred_unit_stack_boundary));
2657 /* Generate the actual call instruction. */
2658 emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,
2659 adjusted_args_size.constant, struct_value_size,
2660 next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
2661 flags, & args_so_far);
2663 /* If call is cse'able, make appropriate pair of reg-notes around it.
2664 Test valreg so we don't crash; may safely ignore `const'
2665 if return type is void. Disable for PARALLEL return values, because
2666 we have no way to move such values into a pseudo register. */
2667 if (pass && (flags & ECF_LIBCALL_BLOCK))
2669 rtx insns;
2670 rtx insn;
2671 bool failed = valreg == 0 || GET_CODE (valreg) == PARALLEL;
2673 insns = get_insns ();
2675 /* Expansion of block moves possibly introduced a loop that may
2676 not appear inside libcall block. */
2677 for (insn = insns; insn; insn = NEXT_INSN (insn))
2678 if (JUMP_P (insn))
2679 failed = true;
2681 if (failed)
2683 end_sequence ();
2684 emit_insn (insns);
2686 else
2688 rtx note = 0;
2689 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2691 /* Mark the return value as a pointer if needed. */
2692 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2693 mark_reg_pointer (temp,
2694 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp))));
2696 end_sequence ();
2697 if (flag_unsafe_math_optimizations
2698 && fndecl
2699 && DECL_BUILT_IN (fndecl)
2700 && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SQRT
2701 || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SQRTF
2702 || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SQRTL))
2703 note = gen_rtx_fmt_e (SQRT,
2704 GET_MODE (temp),
2705 args[0].initial_value);
2706 else
2708 /* Construct an "equal form" for the value which
2709 mentions all the arguments in order as well as
2710 the function name. */
2711 for (i = 0; i < num_actuals; i++)
2712 note = gen_rtx_EXPR_LIST (VOIDmode,
2713 args[i].initial_value, note);
2714 note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
2716 if (flags & ECF_PURE)
2717 note = gen_rtx_EXPR_LIST (VOIDmode,
2718 gen_rtx_USE (VOIDmode,
2719 gen_rtx_MEM (BLKmode,
2720 gen_rtx_SCRATCH (VOIDmode))),
2721 note);
2723 emit_libcall_block (insns, temp, valreg, note);
2725 valreg = temp;
2728 else if (pass && (flags & ECF_MALLOC))
2730 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2731 rtx last, insns;
2733 /* The return value from a malloc-like function is a pointer. */
2734 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2735 mark_reg_pointer (temp, BIGGEST_ALIGNMENT);
2737 emit_move_insn (temp, valreg);
2739 /* The return value from a malloc-like function can not alias
2740 anything else. */
2741 last = get_last_insn ();
2742 REG_NOTES (last) =
2743 gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));
2745 /* Write out the sequence. */
2746 insns = get_insns ();
2747 end_sequence ();
2748 emit_insn (insns);
2749 valreg = temp;
2752 /* For calls to `setjmp', etc., inform flow.c it should complain
2753 if nonvolatile values are live. For functions that cannot return,
2754 inform flow that control does not fall through. */
2756 if ((flags & (ECF_NORETURN | ECF_LONGJMP)) || pass == 0)
2758 /* The barrier must be emitted
2759 immediately after the CALL_INSN. Some ports emit more
2760 than just a CALL_INSN above, so we must search for it here. */
2762 rtx last = get_last_insn ();
2763 while (!CALL_P (last))
2765 last = PREV_INSN (last);
2766 /* There was no CALL_INSN? */
2767 gcc_assert (last != before_call);
2770 emit_barrier_after (last);
2772 /* Stack adjustments after a noreturn call are dead code.
2773 However when NO_DEFER_POP is in effect, we must preserve
2774 stack_pointer_delta. */
2775 if (inhibit_defer_pop == 0)
2777 stack_pointer_delta = old_stack_allocated;
2778 pending_stack_adjust = 0;
2782 if (flags & ECF_LONGJMP)
2783 current_function_calls_longjmp = 1;
2785 /* If value type not void, return an rtx for the value. */
2787 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
2788 || ignore)
2789 target = const0_rtx;
2790 else if (structure_value_addr)
2792 if (target == 0 || !MEM_P (target))
2794 target
2795 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2796 memory_address (TYPE_MODE (TREE_TYPE (exp)),
2797 structure_value_addr));
2798 set_mem_attributes (target, exp, 1);
2801 else if (pcc_struct_value)
2803 /* This is the special C++ case where we need to
2804 know what the true target was. We take care to
2805 never use this value more than once in one expression. */
2806 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2807 copy_to_reg (valreg));
2808 set_mem_attributes (target, exp, 1);
2810 /* Handle calls that return values in multiple non-contiguous locations.
2811 The Irix 6 ABI has examples of this. */
2812 else if (GET_CODE (valreg) == PARALLEL)
2814 if (target == 0)
2816 /* This will only be assigned once, so it can be readonly. */
2817 tree nt = build_qualified_type (TREE_TYPE (exp),
2818 (TYPE_QUALS (TREE_TYPE (exp))
2819 | TYPE_QUAL_CONST));
2821 target = assign_temp (nt, 0, 1, 1);
2822 preserve_temp_slots (target);
2825 if (! rtx_equal_p (target, valreg))
2826 emit_group_store (target, valreg, TREE_TYPE (exp),
2827 int_size_in_bytes (TREE_TYPE (exp)));
2829 /* We can not support sibling calls for this case. */
2830 sibcall_failure = 1;
2832 else if (target
2833 && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2834 && GET_MODE (target) == GET_MODE (valreg))
2836 /* TARGET and VALREG cannot be equal at this point because the
2837 latter would not have REG_FUNCTION_VALUE_P true, while the
2838 former would if it were referring to the same register.
2840 If they refer to the same register, this move will be a no-op,
2841 except when function inlining is being done. */
2842 emit_move_insn (target, valreg);
2844 /* If we are setting a MEM, this code must be executed. Since it is
2845 emitted after the call insn, sibcall optimization cannot be
2846 performed in that case. */
2847 if (MEM_P (target))
2848 sibcall_failure = 1;
2850 else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2852 target = copy_blkmode_from_reg (target, valreg, TREE_TYPE (exp));
2854 /* We can not support sibling calls for this case. */
2855 sibcall_failure = 1;
2857 else
2859 if (shift_returned_value (TREE_TYPE (exp), &valreg))
2860 sibcall_failure = 1;
2862 target = copy_to_reg (valreg);
2865 if (targetm.calls.promote_function_return(funtype))
2867 /* If we promoted this return value, make the proper SUBREG.
2868 TARGET might be const0_rtx here, so be careful. */
2869 if (REG_P (target)
2870 && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
2871 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
2873 tree type = TREE_TYPE (exp);
2874 int unsignedp = TYPE_UNSIGNED (type);
2875 int offset = 0;
2876 enum machine_mode pmode;
2878 pmode = promote_mode (type, TYPE_MODE (type), &unsignedp, 1);
2879 /* If we don't promote as expected, something is wrong. */
2880 gcc_assert (GET_MODE (target) == pmode);
2882 if ((WORDS_BIG_ENDIAN || BYTES_BIG_ENDIAN)
2883 && (GET_MODE_SIZE (GET_MODE (target))
2884 > GET_MODE_SIZE (TYPE_MODE (type))))
2886 offset = GET_MODE_SIZE (GET_MODE (target))
2887 - GET_MODE_SIZE (TYPE_MODE (type));
2888 if (! BYTES_BIG_ENDIAN)
2889 offset = (offset / UNITS_PER_WORD) * UNITS_PER_WORD;
2890 else if (! WORDS_BIG_ENDIAN)
2891 offset %= UNITS_PER_WORD;
2893 target = gen_rtx_SUBREG (TYPE_MODE (type), target, offset);
2894 SUBREG_PROMOTED_VAR_P (target) = 1;
2895 SUBREG_PROMOTED_UNSIGNED_SET (target, unsignedp);
2899 /* If size of args is variable or this was a constructor call for a stack
2900 argument, restore saved stack-pointer value. */
2902 if (old_stack_level && ! (flags & ECF_SP_DEPRESSED))
2904 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
2905 stack_pointer_delta = old_stack_pointer_delta;
2906 pending_stack_adjust = old_pending_adj;
2907 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
2908 stack_arg_under_construction = old_stack_arg_under_construction;
2909 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2910 stack_usage_map = initial_stack_usage_map;
2911 sibcall_failure = 1;
2913 else if (ACCUMULATE_OUTGOING_ARGS && pass)
2915 #ifdef REG_PARM_STACK_SPACE
2916 if (save_area)
2917 restore_fixed_argument_area (save_area, argblock,
2918 high_to_save, low_to_save);
2919 #endif
2921 /* If we saved any argument areas, restore them. */
2922 for (i = 0; i < num_actuals; i++)
2923 if (args[i].save_area)
2925 enum machine_mode save_mode = GET_MODE (args[i].save_area);
2926 rtx stack_area
2927 = gen_rtx_MEM (save_mode,
2928 memory_address (save_mode,
2929 XEXP (args[i].stack_slot, 0)));
2931 if (save_mode != BLKmode)
2932 emit_move_insn (stack_area, args[i].save_area);
2933 else
2934 emit_block_move (stack_area, args[i].save_area,
2935 GEN_INT (args[i].locate.size.constant),
2936 BLOCK_OP_CALL_PARM);
2939 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2940 stack_usage_map = initial_stack_usage_map;
2943 /* If this was alloca, record the new stack level for nonlocal gotos.
2944 Check for the handler slots since we might not have a save area
2945 for non-local gotos. */
2947 if ((flags & ECF_MAY_BE_ALLOCA) && cfun->nonlocal_goto_save_area != 0)
2948 update_nonlocal_goto_save_area ();
2950 /* Free up storage we no longer need. */
2951 for (i = 0; i < num_actuals; ++i)
2952 if (args[i].aligned_regs)
2953 free (args[i].aligned_regs);
2955 insns = get_insns ();
2956 end_sequence ();
2958 if (pass == 0)
2960 tail_call_insns = insns;
2962 /* Restore the pending stack adjustment now that we have
2963 finished generating the sibling call sequence. */
2965 pending_stack_adjust = save_pending_stack_adjust;
2966 stack_pointer_delta = save_stack_pointer_delta;
2968 /* Prepare arg structure for next iteration. */
2969 for (i = 0; i < num_actuals; i++)
2971 args[i].value = 0;
2972 args[i].aligned_regs = 0;
2973 args[i].stack = 0;
2976 sbitmap_free (stored_args_map);
2978 else
2980 normal_call_insns = insns;
2982 /* Verify that we've deallocated all the stack we used. */
2983 gcc_assert ((flags & (ECF_NORETURN | ECF_LONGJMP))
2984 || (old_stack_allocated
2985 == stack_pointer_delta - pending_stack_adjust));
2988 /* If something prevents making this a sibling call,
2989 zero out the sequence. */
2990 if (sibcall_failure)
2991 tail_call_insns = NULL_RTX;
2992 else
2993 break;
2996 /* If tail call production succeeded, we need to remove REG_EQUIV notes on
2997 arguments too, as argument area is now clobbered by the call. */
2998 if (tail_call_insns)
3000 emit_insn (tail_call_insns);
3001 cfun->tail_call_emit = true;
3003 else
3004 emit_insn (normal_call_insns);
3006 currently_expanding_call--;
3008 /* If this function returns with the stack pointer depressed, ensure
3009 this block saves and restores the stack pointer, show it was
3010 changed, and adjust for any outgoing arg space. */
3011 if (flags & ECF_SP_DEPRESSED)
3013 clear_pending_stack_adjust ();
3014 emit_insn (gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx));
3015 emit_move_insn (virtual_stack_dynamic_rtx, stack_pointer_rtx);
3018 return target;
3021 /* A sibling call sequence invalidates any REG_EQUIV notes made for
3022 this function's incoming arguments.
3024 At the start of RTL generation we know the only REG_EQUIV notes
3025 in the rtl chain are those for incoming arguments, so we can safely
3026 flush any REG_EQUIV note.
3028 This is (slight) overkill. We could keep track of the highest
3029 argument we clobber and be more selective in removing notes, but it
3030 does not seem to be worth the effort. */
3031 void
3032 fixup_tail_calls (void)
3034 purge_reg_equiv_notes ();
3037 /* Traverse an argument list in VALUES and expand all complex
3038 arguments into their components. */
3039 static tree
3040 split_complex_values (tree values)
3042 tree p;
3044 /* Before allocating memory, check for the common case of no complex. */
3045 for (p = values; p; p = TREE_CHAIN (p))
3047 tree type = TREE_TYPE (TREE_VALUE (p));
3048 if (type && TREE_CODE (type) == COMPLEX_TYPE
3049 && targetm.calls.split_complex_arg (type))
3050 goto found;
3052 return values;
3054 found:
3055 values = copy_list (values);
3057 for (p = values; p; p = TREE_CHAIN (p))
3059 tree complex_value = TREE_VALUE (p);
3060 tree complex_type;
3062 complex_type = TREE_TYPE (complex_value);
3063 if (!complex_type)
3064 continue;
3066 if (TREE_CODE (complex_type) == COMPLEX_TYPE
3067 && targetm.calls.split_complex_arg (complex_type))
3069 tree subtype;
3070 tree real, imag, next;
3072 subtype = TREE_TYPE (complex_type);
3073 complex_value = save_expr (complex_value);
3074 real = build1 (REALPART_EXPR, subtype, complex_value);
3075 imag = build1 (IMAGPART_EXPR, subtype, complex_value);
3077 TREE_VALUE (p) = real;
3078 next = TREE_CHAIN (p);
3079 imag = build_tree_list (NULL_TREE, imag);
3080 TREE_CHAIN (p) = imag;
3081 TREE_CHAIN (imag) = next;
3083 /* Skip the newly created node. */
3084 p = TREE_CHAIN (p);
3088 return values;
3091 /* Traverse a list of TYPES and expand all complex types into their
3092 components. */
3093 static tree
3094 split_complex_types (tree types)
3096 tree p;
3098 /* Before allocating memory, check for the common case of no complex. */
3099 for (p = types; p; p = TREE_CHAIN (p))
3101 tree type = TREE_VALUE (p);
3102 if (TREE_CODE (type) == COMPLEX_TYPE
3103 && targetm.calls.split_complex_arg (type))
3104 goto found;
3106 return types;
3108 found:
3109 types = copy_list (types);
3111 for (p = types; p; p = TREE_CHAIN (p))
3113 tree complex_type = TREE_VALUE (p);
3115 if (TREE_CODE (complex_type) == COMPLEX_TYPE
3116 && targetm.calls.split_complex_arg (complex_type))
3118 tree next, imag;
3120 /* Rewrite complex type with component type. */
3121 TREE_VALUE (p) = TREE_TYPE (complex_type);
3122 next = TREE_CHAIN (p);
3124 /* Add another component type for the imaginary part. */
3125 imag = build_tree_list (NULL_TREE, TREE_VALUE (p));
3126 TREE_CHAIN (p) = imag;
3127 TREE_CHAIN (imag) = next;
3129 /* Skip the newly created node. */
3130 p = TREE_CHAIN (p);
3134 return types;
3137 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3138 The RETVAL parameter specifies whether return value needs to be saved, other
3139 parameters are documented in the emit_library_call function below. */
3141 static rtx
3142 emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
3143 enum libcall_type fn_type,
3144 enum machine_mode outmode, int nargs, va_list p)
3146 /* Total size in bytes of all the stack-parms scanned so far. */
3147 struct args_size args_size;
3148 /* Size of arguments before any adjustments (such as rounding). */
3149 struct args_size original_args_size;
3150 int argnum;
3151 rtx fun;
3152 int inc;
3153 int count;
3154 rtx argblock = 0;
3155 CUMULATIVE_ARGS args_so_far;
3156 struct arg
3158 rtx value;
3159 enum machine_mode mode;
3160 rtx reg;
3161 int partial;
3162 struct locate_and_pad_arg_data locate;
3163 rtx save_area;
3165 struct arg *argvec;
3166 int old_inhibit_defer_pop = inhibit_defer_pop;
3167 rtx call_fusage = 0;
3168 rtx mem_value = 0;
3169 rtx valreg;
3170 int pcc_struct_value = 0;
3171 int struct_value_size = 0;
3172 int flags;
3173 int reg_parm_stack_space = 0;
3174 int needed;
3175 rtx before_call;
3176 tree tfom; /* type_for_mode (outmode, 0) */
3178 #ifdef REG_PARM_STACK_SPACE
3179 /* Define the boundary of the register parm stack space that needs to be
3180 save, if any. */
3181 int low_to_save, high_to_save;
3182 rtx save_area = 0; /* Place that it is saved. */
3183 #endif
3185 /* Size of the stack reserved for parameter registers. */
3186 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3187 char *initial_stack_usage_map = stack_usage_map;
3189 rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
3191 #ifdef REG_PARM_STACK_SPACE
3192 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3193 #endif
3195 /* By default, library functions can not throw. */
3196 flags = ECF_NOTHROW;
3198 switch (fn_type)
3200 case LCT_NORMAL:
3201 break;
3202 case LCT_CONST:
3203 flags |= ECF_CONST;
3204 break;
3205 case LCT_PURE:
3206 flags |= ECF_PURE;
3207 break;
3208 case LCT_CONST_MAKE_BLOCK:
3209 flags |= ECF_CONST | ECF_LIBCALL_BLOCK;
3210 break;
3211 case LCT_PURE_MAKE_BLOCK:
3212 flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
3213 break;
3214 case LCT_NORETURN:
3215 flags |= ECF_NORETURN;
3216 break;
3217 case LCT_THROW:
3218 flags = ECF_NORETURN;
3219 break;
3220 case LCT_ALWAYS_RETURN:
3221 flags = ECF_ALWAYS_RETURN;
3222 break;
3223 case LCT_RETURNS_TWICE:
3224 flags = ECF_RETURNS_TWICE;
3225 break;
3227 fun = orgfun;
3229 /* Ensure current function's preferred stack boundary is at least
3230 what we need. */
3231 if (cfun->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3232 cfun->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3234 /* If this kind of value comes back in memory,
3235 decide where in memory it should come back. */
3236 if (outmode != VOIDmode)
3238 tfom = lang_hooks.types.type_for_mode (outmode, 0);
3239 if (aggregate_value_p (tfom, 0))
3241 #ifdef PCC_STATIC_STRUCT_RETURN
3242 rtx pointer_reg
3243 = hard_function_value (build_pointer_type (tfom), 0, 0);
3244 mem_value = gen_rtx_MEM (outmode, pointer_reg);
3245 pcc_struct_value = 1;
3246 if (value == 0)
3247 value = gen_reg_rtx (outmode);
3248 #else /* not PCC_STATIC_STRUCT_RETURN */
3249 struct_value_size = GET_MODE_SIZE (outmode);
3250 if (value != 0 && MEM_P (value))
3251 mem_value = value;
3252 else
3253 mem_value = assign_temp (tfom, 0, 1, 1);
3254 #endif
3255 /* This call returns a big structure. */
3256 flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
3259 else
3260 tfom = void_type_node;
3262 /* ??? Unfinished: must pass the memory address as an argument. */
3264 /* Copy all the libcall-arguments out of the varargs data
3265 and into a vector ARGVEC.
3267 Compute how to pass each argument. We only support a very small subset
3268 of the full argument passing conventions to limit complexity here since
3269 library functions shouldn't have many args. */
3271 argvec = alloca ((nargs + 1) * sizeof (struct arg));
3272 memset (argvec, 0, (nargs + 1) * sizeof (struct arg));
3274 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3275 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far, outmode, fun);
3276 #else
3277 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0, nargs);
3278 #endif
3280 args_size.constant = 0;
3281 args_size.var = 0;
3283 count = 0;
3285 /* Now we are about to start emitting insns that can be deleted
3286 if a libcall is deleted. */
3287 if (flags & ECF_LIBCALL_BLOCK)
3288 start_sequence ();
3290 push_temp_slots ();
3292 /* If there's a structure value address to be passed,
3293 either pass it in the special place, or pass it as an extra argument. */
3294 if (mem_value && struct_value == 0 && ! pcc_struct_value)
3296 rtx addr = XEXP (mem_value, 0);
3297 int partial;
3299 nargs++;
3301 /* Make sure it is a reasonable operand for a move or push insn. */
3302 if (!REG_P (addr) && !MEM_P (addr)
3303 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
3304 addr = force_operand (addr, NULL_RTX);
3306 argvec[count].value = addr;
3307 argvec[count].mode = Pmode;
3308 argvec[count].partial = 0;
3310 argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
3311 partial = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1);
3312 gcc_assert (!partial);
3314 locate_and_pad_parm (Pmode, NULL_TREE,
3315 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3317 #else
3318 argvec[count].reg != 0,
3319 #endif
3320 0, NULL_TREE, &args_size, &argvec[count].locate);
3322 if (argvec[count].reg == 0 || argvec[count].partial != 0
3323 || reg_parm_stack_space > 0)
3324 args_size.constant += argvec[count].locate.size.constant;
3326 FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
3328 count++;
3331 for (; count < nargs; count++)
3333 rtx val = va_arg (p, rtx);
3334 enum machine_mode mode = va_arg (p, enum machine_mode);
3336 /* We cannot convert the arg value to the mode the library wants here;
3337 must do it earlier where we know the signedness of the arg. */
3338 gcc_assert (mode != BLKmode
3339 && (GET_MODE (val) == mode || GET_MODE (val) == VOIDmode));
3341 /* Make sure it is a reasonable operand for a move or push insn. */
3342 if (!REG_P (val) && !MEM_P (val)
3343 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
3344 val = force_operand (val, NULL_RTX);
3346 if (pass_by_reference (&args_so_far, mode, NULL_TREE, 1))
3348 rtx slot;
3349 int must_copy
3350 = !reference_callee_copied (&args_so_far, mode, NULL_TREE, 1);
3352 /* loop.c won't look at CALL_INSN_FUNCTION_USAGE of const/pure
3353 functions, so we have to pretend this isn't such a function. */
3354 if (flags & ECF_LIBCALL_BLOCK)
3356 rtx insns = get_insns ();
3357 end_sequence ();
3358 emit_insn (insns);
3360 flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
3362 /* If this was a CONST function, it is now PURE since
3363 it now reads memory. */
3364 if (flags & ECF_CONST)
3366 flags &= ~ECF_CONST;
3367 flags |= ECF_PURE;
3370 if (GET_MODE (val) == MEM && !must_copy)
3371 slot = val;
3372 else
3374 slot = assign_temp (lang_hooks.types.type_for_mode (mode, 0),
3375 0, 1, 1);
3376 emit_move_insn (slot, val);
3379 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
3380 gen_rtx_USE (VOIDmode, slot),
3381 call_fusage);
3382 if (must_copy)
3383 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
3384 gen_rtx_CLOBBER (VOIDmode,
3385 slot),
3386 call_fusage);
3388 mode = Pmode;
3389 val = force_operand (XEXP (slot, 0), NULL_RTX);
3392 argvec[count].value = val;
3393 argvec[count].mode = mode;
3395 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
3397 argvec[count].partial
3398 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3400 locate_and_pad_parm (mode, NULL_TREE,
3401 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3403 #else
3404 argvec[count].reg != 0,
3405 #endif
3406 argvec[count].partial,
3407 NULL_TREE, &args_size, &argvec[count].locate);
3409 gcc_assert (!argvec[count].locate.size.var);
3411 if (argvec[count].reg == 0 || argvec[count].partial != 0
3412 || reg_parm_stack_space > 0)
3413 args_size.constant += argvec[count].locate.size.constant;
3415 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3418 /* If this machine requires an external definition for library
3419 functions, write one out. */
3420 assemble_external_libcall (fun);
3422 original_args_size = args_size;
3423 args_size.constant = (((args_size.constant
3424 + stack_pointer_delta
3425 + STACK_BYTES - 1)
3426 / STACK_BYTES
3427 * STACK_BYTES)
3428 - stack_pointer_delta);
3430 args_size.constant = MAX (args_size.constant,
3431 reg_parm_stack_space);
3433 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3434 args_size.constant -= reg_parm_stack_space;
3435 #endif
3437 if (args_size.constant > current_function_outgoing_args_size)
3438 current_function_outgoing_args_size = args_size.constant;
3440 if (ACCUMULATE_OUTGOING_ARGS)
3442 /* Since the stack pointer will never be pushed, it is possible for
3443 the evaluation of a parm to clobber something we have already
3444 written to the stack. Since most function calls on RISC machines
3445 do not use the stack, this is uncommon, but must work correctly.
3447 Therefore, we save any area of the stack that was already written
3448 and that we are using. Here we set up to do this by making a new
3449 stack usage map from the old one.
3451 Another approach might be to try to reorder the argument
3452 evaluations to avoid this conflicting stack usage. */
3454 needed = args_size.constant;
3456 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3457 /* Since we will be writing into the entire argument area, the
3458 map must be allocated for its entire size, not just the part that
3459 is the responsibility of the caller. */
3460 needed += reg_parm_stack_space;
3461 #endif
3463 #ifdef ARGS_GROW_DOWNWARD
3464 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3465 needed + 1);
3466 #else
3467 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3468 needed);
3469 #endif
3470 stack_usage_map = alloca (highest_outgoing_arg_in_use);
3472 if (initial_highest_arg_in_use)
3473 memcpy (stack_usage_map, initial_stack_usage_map,
3474 initial_highest_arg_in_use);
3476 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3477 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
3478 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3479 needed = 0;
3481 /* We must be careful to use virtual regs before they're instantiated,
3482 and real regs afterwards. Loop optimization, for example, can create
3483 new libcalls after we've instantiated the virtual regs, and if we
3484 use virtuals anyway, they won't match the rtl patterns. */
3486 if (virtuals_instantiated)
3487 argblock = plus_constant (stack_pointer_rtx, STACK_POINTER_OFFSET);
3488 else
3489 argblock = virtual_outgoing_args_rtx;
3491 else
3493 if (!PUSH_ARGS)
3494 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3497 /* If we push args individually in reverse order, perform stack alignment
3498 before the first push (the last arg). */
3499 if (argblock == 0 && PUSH_ARGS_REVERSED)
3500 anti_adjust_stack (GEN_INT (args_size.constant
3501 - original_args_size.constant));
3503 if (PUSH_ARGS_REVERSED)
3505 inc = -1;
3506 argnum = nargs - 1;
3508 else
3510 inc = 1;
3511 argnum = 0;
3514 #ifdef REG_PARM_STACK_SPACE
3515 if (ACCUMULATE_OUTGOING_ARGS)
3517 /* The argument list is the property of the called routine and it
3518 may clobber it. If the fixed area has been used for previous
3519 parameters, we must save and restore it. */
3520 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
3521 &low_to_save, &high_to_save);
3523 #endif
3525 /* Push the args that need to be pushed. */
3527 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3528 are to be pushed. */
3529 for (count = 0; count < nargs; count++, argnum += inc)
3531 enum machine_mode mode = argvec[argnum].mode;
3532 rtx val = argvec[argnum].value;
3533 rtx reg = argvec[argnum].reg;
3534 int partial = argvec[argnum].partial;
3535 int lower_bound = 0, upper_bound = 0, i;
3537 if (! (reg != 0 && partial == 0))
3539 if (ACCUMULATE_OUTGOING_ARGS)
3541 /* If this is being stored into a pre-allocated, fixed-size,
3542 stack area, save any previous data at that location. */
3544 #ifdef ARGS_GROW_DOWNWARD
3545 /* stack_slot is negative, but we want to index stack_usage_map
3546 with positive values. */
3547 upper_bound = -argvec[argnum].locate.offset.constant + 1;
3548 lower_bound = upper_bound - argvec[argnum].locate.size.constant;
3549 #else
3550 lower_bound = argvec[argnum].locate.offset.constant;
3551 upper_bound = lower_bound + argvec[argnum].locate.size.constant;
3552 #endif
3554 i = lower_bound;
3555 /* Don't worry about things in the fixed argument area;
3556 it has already been saved. */
3557 if (i < reg_parm_stack_space)
3558 i = reg_parm_stack_space;
3559 while (i < upper_bound && stack_usage_map[i] == 0)
3560 i++;
3562 if (i < upper_bound)
3564 /* We need to make a save area. */
3565 unsigned int size
3566 = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
3567 enum machine_mode save_mode
3568 = mode_for_size (size, MODE_INT, 1);
3569 rtx adr
3570 = plus_constant (argblock,
3571 argvec[argnum].locate.offset.constant);
3572 rtx stack_area
3573 = gen_rtx_MEM (save_mode, memory_address (save_mode, adr));
3575 if (save_mode == BLKmode)
3577 argvec[argnum].save_area
3578 = assign_stack_temp (BLKmode,
3579 argvec[argnum].locate.size.constant,
3582 emit_block_move (validize_mem (argvec[argnum].save_area),
3583 stack_area,
3584 GEN_INT (argvec[argnum].locate.size.constant),
3585 BLOCK_OP_CALL_PARM);
3587 else
3589 argvec[argnum].save_area = gen_reg_rtx (save_mode);
3591 emit_move_insn (argvec[argnum].save_area, stack_area);
3596 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, PARM_BOUNDARY,
3597 partial, reg, 0, argblock,
3598 GEN_INT (argvec[argnum].locate.offset.constant),
3599 reg_parm_stack_space,
3600 ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad));
3602 /* Now mark the segment we just used. */
3603 if (ACCUMULATE_OUTGOING_ARGS)
3604 for (i = lower_bound; i < upper_bound; i++)
3605 stack_usage_map[i] = 1;
3607 NO_DEFER_POP;
3611 /* If we pushed args in forward order, perform stack alignment
3612 after pushing the last arg. */
3613 if (argblock == 0 && !PUSH_ARGS_REVERSED)
3614 anti_adjust_stack (GEN_INT (args_size.constant
3615 - original_args_size.constant));
3617 if (PUSH_ARGS_REVERSED)
3618 argnum = nargs - 1;
3619 else
3620 argnum = 0;
3622 fun = prepare_call_address (fun, NULL, &call_fusage, 0, 0);
3624 /* Now load any reg parms into their regs. */
3626 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3627 are to be pushed. */
3628 for (count = 0; count < nargs; count++, argnum += inc)
3630 enum machine_mode mode = argvec[argnum].mode;
3631 rtx val = argvec[argnum].value;
3632 rtx reg = argvec[argnum].reg;
3633 int partial = argvec[argnum].partial;
3635 /* Handle calls that pass values in multiple non-contiguous
3636 locations. The PA64 has examples of this for library calls. */
3637 if (reg != 0 && GET_CODE (reg) == PARALLEL)
3638 emit_group_load (reg, val, NULL_TREE, GET_MODE_SIZE (mode));
3639 else if (reg != 0 && partial == 0)
3640 emit_move_insn (reg, val);
3642 NO_DEFER_POP;
3645 /* Any regs containing parms remain in use through the call. */
3646 for (count = 0; count < nargs; count++)
3648 rtx reg = argvec[count].reg;
3649 if (reg != 0 && GET_CODE (reg) == PARALLEL)
3650 use_group_regs (&call_fusage, reg);
3651 else if (reg != 0)
3652 use_reg (&call_fusage, reg);
3655 /* Pass the function the address in which to return a structure value. */
3656 if (mem_value != 0 && struct_value != 0 && ! pcc_struct_value)
3658 emit_move_insn (struct_value,
3659 force_reg (Pmode,
3660 force_operand (XEXP (mem_value, 0),
3661 NULL_RTX)));
3662 if (REG_P (struct_value))
3663 use_reg (&call_fusage, struct_value);
3666 /* Don't allow popping to be deferred, since then
3667 cse'ing of library calls could delete a call and leave the pop. */
3668 NO_DEFER_POP;
3669 valreg = (mem_value == 0 && outmode != VOIDmode
3670 ? hard_libcall_value (outmode) : NULL_RTX);
3672 /* Stack must be properly aligned now. */
3673 gcc_assert (!(stack_pointer_delta
3674 & (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)));
3676 before_call = get_last_insn ();
3678 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3679 will set inhibit_defer_pop to that value. */
3680 /* The return type is needed to decide how many bytes the function pops.
3681 Signedness plays no role in that, so for simplicity, we pretend it's
3682 always signed. We also assume that the list of arguments passed has
3683 no impact, so we pretend it is unknown. */
3685 emit_call_1 (fun, NULL,
3686 get_identifier (XSTR (orgfun, 0)),
3687 build_function_type (tfom, NULL_TREE),
3688 original_args_size.constant, args_size.constant,
3689 struct_value_size,
3690 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3691 valreg,
3692 old_inhibit_defer_pop + 1, call_fusage, flags, & args_so_far);
3694 /* For calls to `setjmp', etc., inform flow.c it should complain
3695 if nonvolatile values are live. For functions that cannot return,
3696 inform flow that control does not fall through. */
3698 if (flags & (ECF_NORETURN | ECF_LONGJMP))
3700 /* The barrier note must be emitted
3701 immediately after the CALL_INSN. Some ports emit more than
3702 just a CALL_INSN above, so we must search for it here. */
3704 rtx last = get_last_insn ();
3705 while (!CALL_P (last))
3707 last = PREV_INSN (last);
3708 /* There was no CALL_INSN? */
3709 gcc_assert (last != before_call);
3712 emit_barrier_after (last);
3715 /* Now restore inhibit_defer_pop to its actual original value. */
3716 OK_DEFER_POP;
3718 /* If call is cse'able, make appropriate pair of reg-notes around it.
3719 Test valreg so we don't crash; may safely ignore `const'
3720 if return type is void. Disable for PARALLEL return values, because
3721 we have no way to move such values into a pseudo register. */
3722 if (flags & ECF_LIBCALL_BLOCK)
3724 rtx insns;
3726 if (valreg == 0)
3728 insns = get_insns ();
3729 end_sequence ();
3730 emit_insn (insns);
3732 else
3734 rtx note = 0;
3735 rtx temp;
3736 int i;
3738 if (GET_CODE (valreg) == PARALLEL)
3740 temp = gen_reg_rtx (outmode);
3741 emit_group_store (temp, valreg, NULL_TREE,
3742 GET_MODE_SIZE (outmode));
3743 valreg = temp;
3746 temp = gen_reg_rtx (GET_MODE (valreg));
3748 /* Construct an "equal form" for the value which mentions all the
3749 arguments in order as well as the function name. */
3750 for (i = 0; i < nargs; i++)
3751 note = gen_rtx_EXPR_LIST (VOIDmode, argvec[i].value, note);
3752 note = gen_rtx_EXPR_LIST (VOIDmode, fun, note);
3754 insns = get_insns ();
3755 end_sequence ();
3757 if (flags & ECF_PURE)
3758 note = gen_rtx_EXPR_LIST (VOIDmode,
3759 gen_rtx_USE (VOIDmode,
3760 gen_rtx_MEM (BLKmode,
3761 gen_rtx_SCRATCH (VOIDmode))),
3762 note);
3764 emit_libcall_block (insns, temp, valreg, note);
3766 valreg = temp;
3769 pop_temp_slots ();
3771 /* Copy the value to the right place. */
3772 if (outmode != VOIDmode && retval)
3774 if (mem_value)
3776 if (value == 0)
3777 value = mem_value;
3778 if (value != mem_value)
3779 emit_move_insn (value, mem_value);
3781 else if (GET_CODE (valreg) == PARALLEL)
3783 if (value == 0)
3784 value = gen_reg_rtx (outmode);
3785 emit_group_store (value, valreg, NULL_TREE, GET_MODE_SIZE (outmode));
3787 else if (value != 0)
3788 emit_move_insn (value, valreg);
3789 else
3790 value = valreg;
3793 if (ACCUMULATE_OUTGOING_ARGS)
3795 #ifdef REG_PARM_STACK_SPACE
3796 if (save_area)
3797 restore_fixed_argument_area (save_area, argblock,
3798 high_to_save, low_to_save);
3799 #endif
3801 /* If we saved any argument areas, restore them. */
3802 for (count = 0; count < nargs; count++)
3803 if (argvec[count].save_area)
3805 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3806 rtx adr = plus_constant (argblock,
3807 argvec[count].locate.offset.constant);
3808 rtx stack_area = gen_rtx_MEM (save_mode,
3809 memory_address (save_mode, adr));
3811 if (save_mode == BLKmode)
3812 emit_block_move (stack_area,
3813 validize_mem (argvec[count].save_area),
3814 GEN_INT (argvec[count].locate.size.constant),
3815 BLOCK_OP_CALL_PARM);
3816 else
3817 emit_move_insn (stack_area, argvec[count].save_area);
3820 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3821 stack_usage_map = initial_stack_usage_map;
3824 return value;
3828 /* Output a library call to function FUN (a SYMBOL_REF rtx)
3829 (emitting the queue unless NO_QUEUE is nonzero),
3830 for a value of mode OUTMODE,
3831 with NARGS different arguments, passed as alternating rtx values
3832 and machine_modes to convert them to.
3834 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for `const'
3835 calls, LCT_PURE for `pure' calls, LCT_CONST_MAKE_BLOCK for `const' calls
3836 which should be enclosed in REG_LIBCALL/REG_RETVAL notes,
3837 LCT_PURE_MAKE_BLOCK for `purep' calls which should be enclosed in
3838 REG_LIBCALL/REG_RETVAL notes with extra (use (memory (scratch)),
3839 or other LCT_ value for other types of library calls. */
3841 void
3842 emit_library_call (rtx orgfun, enum libcall_type fn_type,
3843 enum machine_mode outmode, int nargs, ...)
3845 va_list p;
3847 va_start (p, nargs);
3848 emit_library_call_value_1 (0, orgfun, NULL_RTX, fn_type, outmode, nargs, p);
3849 va_end (p);
3852 /* Like emit_library_call except that an extra argument, VALUE,
3853 comes second and says where to store the result.
3854 (If VALUE is zero, this function chooses a convenient way
3855 to return the value.
3857 This function returns an rtx for where the value is to be found.
3858 If VALUE is nonzero, VALUE is returned. */
3861 emit_library_call_value (rtx orgfun, rtx value,
3862 enum libcall_type fn_type,
3863 enum machine_mode outmode, int nargs, ...)
3865 rtx result;
3866 va_list p;
3868 va_start (p, nargs);
3869 result = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode,
3870 nargs, p);
3871 va_end (p);
3873 return result;
3876 /* Store a single argument for a function call
3877 into the register or memory area where it must be passed.
3878 *ARG describes the argument value and where to pass it.
3880 ARGBLOCK is the address of the stack-block for all the arguments,
3881 or 0 on a machine where arguments are pushed individually.
3883 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
3884 so must be careful about how the stack is used.
3886 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
3887 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
3888 that we need not worry about saving and restoring the stack.
3890 FNDECL is the declaration of the function we are calling.
3892 Return nonzero if this arg should cause sibcall failure,
3893 zero otherwise. */
3895 static int
3896 store_one_arg (struct arg_data *arg, rtx argblock, int flags,
3897 int variable_size ATTRIBUTE_UNUSED, int reg_parm_stack_space)
3899 tree pval = arg->tree_value;
3900 rtx reg = 0;
3901 int partial = 0;
3902 int used = 0;
3903 int i, lower_bound = 0, upper_bound = 0;
3904 int sibcall_failure = 0;
3906 if (TREE_CODE (pval) == ERROR_MARK)
3907 return 1;
3909 /* Push a new temporary level for any temporaries we make for
3910 this argument. */
3911 push_temp_slots ();
3913 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL))
3915 /* If this is being stored into a pre-allocated, fixed-size, stack area,
3916 save any previous data at that location. */
3917 if (argblock && ! variable_size && arg->stack)
3919 #ifdef ARGS_GROW_DOWNWARD
3920 /* stack_slot is negative, but we want to index stack_usage_map
3921 with positive values. */
3922 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3923 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
3924 else
3925 upper_bound = 0;
3927 lower_bound = upper_bound - arg->locate.size.constant;
3928 #else
3929 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3930 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
3931 else
3932 lower_bound = 0;
3934 upper_bound = lower_bound + arg->locate.size.constant;
3935 #endif
3937 i = lower_bound;
3938 /* Don't worry about things in the fixed argument area;
3939 it has already been saved. */
3940 if (i < reg_parm_stack_space)
3941 i = reg_parm_stack_space;
3942 while (i < upper_bound && stack_usage_map[i] == 0)
3943 i++;
3945 if (i < upper_bound)
3947 /* We need to make a save area. */
3948 unsigned int size = arg->locate.size.constant * BITS_PER_UNIT;
3949 enum machine_mode save_mode = mode_for_size (size, MODE_INT, 1);
3950 rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0));
3951 rtx stack_area = gen_rtx_MEM (save_mode, adr);
3953 if (save_mode == BLKmode)
3955 tree ot = TREE_TYPE (arg->tree_value);
3956 tree nt = build_qualified_type (ot, (TYPE_QUALS (ot)
3957 | TYPE_QUAL_CONST));
3959 arg->save_area = assign_temp (nt, 0, 1, 1);
3960 preserve_temp_slots (arg->save_area);
3961 emit_block_move (validize_mem (arg->save_area), stack_area,
3962 expr_size (arg->tree_value),
3963 BLOCK_OP_CALL_PARM);
3965 else
3967 arg->save_area = gen_reg_rtx (save_mode);
3968 emit_move_insn (arg->save_area, stack_area);
3974 /* If this isn't going to be placed on both the stack and in registers,
3975 set up the register and number of words. */
3976 if (! arg->pass_on_stack)
3978 if (flags & ECF_SIBCALL)
3979 reg = arg->tail_call_reg;
3980 else
3981 reg = arg->reg;
3982 partial = arg->partial;
3985 /* Being passed entirely in a register. We shouldn't be called in
3986 this case. */
3987 gcc_assert (reg == 0 || partial != 0);
3989 /* If this arg needs special alignment, don't load the registers
3990 here. */
3991 if (arg->n_aligned_regs != 0)
3992 reg = 0;
3994 /* If this is being passed partially in a register, we can't evaluate
3995 it directly into its stack slot. Otherwise, we can. */
3996 if (arg->value == 0)
3998 /* stack_arg_under_construction is nonzero if a function argument is
3999 being evaluated directly into the outgoing argument list and
4000 expand_call must take special action to preserve the argument list
4001 if it is called recursively.
4003 For scalar function arguments stack_usage_map is sufficient to
4004 determine which stack slots must be saved and restored. Scalar
4005 arguments in general have pass_on_stack == 0.
4007 If this argument is initialized by a function which takes the
4008 address of the argument (a C++ constructor or a C function
4009 returning a BLKmode structure), then stack_usage_map is
4010 insufficient and expand_call must push the stack around the
4011 function call. Such arguments have pass_on_stack == 1.
4013 Note that it is always safe to set stack_arg_under_construction,
4014 but this generates suboptimal code if set when not needed. */
4016 if (arg->pass_on_stack)
4017 stack_arg_under_construction++;
4019 arg->value = expand_expr (pval,
4020 (partial
4021 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
4022 ? NULL_RTX : arg->stack,
4023 VOIDmode, EXPAND_STACK_PARM);
4025 /* If we are promoting object (or for any other reason) the mode
4026 doesn't agree, convert the mode. */
4028 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
4029 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
4030 arg->value, arg->unsignedp);
4032 if (arg->pass_on_stack)
4033 stack_arg_under_construction--;
4036 /* Don't allow anything left on stack from computation
4037 of argument to alloca. */
4038 if (flags & ECF_MAY_BE_ALLOCA)
4039 do_pending_stack_adjust ();
4041 if (arg->value == arg->stack)
4042 /* If the value is already in the stack slot, we are done. */
4044 else if (arg->mode != BLKmode)
4046 int size;
4048 /* Argument is a scalar, not entirely passed in registers.
4049 (If part is passed in registers, arg->partial says how much
4050 and emit_push_insn will take care of putting it there.)
4052 Push it, and if its size is less than the
4053 amount of space allocated to it,
4054 also bump stack pointer by the additional space.
4055 Note that in C the default argument promotions
4056 will prevent such mismatches. */
4058 size = GET_MODE_SIZE (arg->mode);
4059 /* Compute how much space the push instruction will push.
4060 On many machines, pushing a byte will advance the stack
4061 pointer by a halfword. */
4062 #ifdef PUSH_ROUNDING
4063 size = PUSH_ROUNDING (size);
4064 #endif
4065 used = size;
4067 /* Compute how much space the argument should get:
4068 round up to a multiple of the alignment for arguments. */
4069 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
4070 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4071 / (PARM_BOUNDARY / BITS_PER_UNIT))
4072 * (PARM_BOUNDARY / BITS_PER_UNIT));
4074 /* This isn't already where we want it on the stack, so put it there.
4075 This can either be done with push or copy insns. */
4076 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
4077 PARM_BOUNDARY, partial, reg, used - size, argblock,
4078 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4079 ARGS_SIZE_RTX (arg->locate.alignment_pad));
4081 /* Unless this is a partially-in-register argument, the argument is now
4082 in the stack. */
4083 if (partial == 0)
4084 arg->value = arg->stack;
4086 else
4088 /* BLKmode, at least partly to be pushed. */
4090 unsigned int parm_align;
4091 int excess;
4092 rtx size_rtx;
4094 /* Pushing a nonscalar.
4095 If part is passed in registers, PARTIAL says how much
4096 and emit_push_insn will take care of putting it there. */
4098 /* Round its size up to a multiple
4099 of the allocation unit for arguments. */
4101 if (arg->locate.size.var != 0)
4103 excess = 0;
4104 size_rtx = ARGS_SIZE_RTX (arg->locate.size);
4106 else
4108 /* PUSH_ROUNDING has no effect on us, because
4109 emit_push_insn for BLKmode is careful to avoid it. */
4110 if (reg && GET_CODE (reg) == PARALLEL)
4112 /* Use the size of the elt to compute excess. */
4113 rtx elt = XEXP (XVECEXP (reg, 0, 0), 0);
4114 excess = (arg->locate.size.constant
4115 - int_size_in_bytes (TREE_TYPE (pval))
4116 + partial * GET_MODE_SIZE (GET_MODE (elt)));
4118 else
4119 excess = (arg->locate.size.constant
4120 - int_size_in_bytes (TREE_TYPE (pval))
4121 + partial * UNITS_PER_WORD);
4122 size_rtx = expand_expr (size_in_bytes (TREE_TYPE (pval)),
4123 NULL_RTX, TYPE_MODE (sizetype), 0);
4126 /* Some types will require stricter alignment, which will be
4127 provided for elsewhere in argument layout. */
4128 parm_align = MAX (PARM_BOUNDARY, TYPE_ALIGN (TREE_TYPE (pval)));
4130 /* When an argument is padded down, the block is aligned to
4131 PARM_BOUNDARY, but the actual argument isn't. */
4132 if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward)
4134 if (arg->locate.size.var)
4135 parm_align = BITS_PER_UNIT;
4136 else if (excess)
4138 unsigned int excess_align = (excess & -excess) * BITS_PER_UNIT;
4139 parm_align = MIN (parm_align, excess_align);
4143 if ((flags & ECF_SIBCALL) && MEM_P (arg->value))
4145 /* emit_push_insn might not work properly if arg->value and
4146 argblock + arg->locate.offset areas overlap. */
4147 rtx x = arg->value;
4148 int i = 0;
4150 if (XEXP (x, 0) == current_function_internal_arg_pointer
4151 || (GET_CODE (XEXP (x, 0)) == PLUS
4152 && XEXP (XEXP (x, 0), 0) ==
4153 current_function_internal_arg_pointer
4154 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))
4156 if (XEXP (x, 0) != current_function_internal_arg_pointer)
4157 i = INTVAL (XEXP (XEXP (x, 0), 1));
4159 /* expand_call should ensure this. */
4160 gcc_assert (!arg->locate.offset.var
4161 && GET_CODE (size_rtx) == CONST_INT);
4163 if (arg->locate.offset.constant > i)
4165 if (arg->locate.offset.constant < i + INTVAL (size_rtx))
4166 sibcall_failure = 1;
4168 else if (arg->locate.offset.constant < i)
4170 if (i < arg->locate.offset.constant + INTVAL (size_rtx))
4171 sibcall_failure = 1;
4176 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
4177 parm_align, partial, reg, excess, argblock,
4178 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4179 ARGS_SIZE_RTX (arg->locate.alignment_pad));
4181 /* Unless this is a partially-in-register argument, the argument is now
4182 in the stack.
4184 ??? Unlike the case above, in which we want the actual
4185 address of the data, so that we can load it directly into a
4186 register, here we want the address of the stack slot, so that
4187 it's properly aligned for word-by-word copying or something
4188 like that. It's not clear that this is always correct. */
4189 if (partial == 0)
4190 arg->value = arg->stack_slot;
4193 if (arg->reg && GET_CODE (arg->reg) == PARALLEL)
4195 tree type = TREE_TYPE (arg->tree_value);
4196 arg->parallel_value
4197 = emit_group_load_into_temps (arg->reg, arg->value, type,
4198 int_size_in_bytes (type));
4201 /* Mark all slots this store used. */
4202 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)
4203 && argblock && ! variable_size && arg->stack)
4204 for (i = lower_bound; i < upper_bound; i++)
4205 stack_usage_map[i] = 1;
4207 /* Once we have pushed something, pops can't safely
4208 be deferred during the rest of the arguments. */
4209 NO_DEFER_POP;
4211 /* Free any temporary slots made in processing this argument. Show
4212 that we might have taken the address of something and pushed that
4213 as an operand. */
4214 preserve_temp_slots (NULL_RTX);
4215 free_temp_slots ();
4216 pop_temp_slots ();
4218 return sibcall_failure;
4221 /* Nonzero if we do not know how to pass TYPE solely in registers. */
4223 bool
4224 must_pass_in_stack_var_size (enum machine_mode mode ATTRIBUTE_UNUSED,
4225 tree type)
4227 if (!type)
4228 return false;
4230 /* If the type has variable size... */
4231 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4232 return true;
4234 /* If the type is marked as addressable (it is required
4235 to be constructed into the stack)... */
4236 if (TREE_ADDRESSABLE (type))
4237 return true;
4239 return false;
4242 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
4243 takes trailing padding of a structure into account. */
4244 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
4246 bool
4247 must_pass_in_stack_var_size_or_pad (enum machine_mode mode, tree type)
4249 if (!type)
4250 return false;
4252 /* If the type has variable size... */
4253 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4254 return true;
4256 /* If the type is marked as addressable (it is required
4257 to be constructed into the stack)... */
4258 if (TREE_ADDRESSABLE (type))
4259 return true;
4261 /* If the padding and mode of the type is such that a copy into
4262 a register would put it into the wrong part of the register. */
4263 if (mode == BLKmode
4264 && int_size_in_bytes (type) % (PARM_BOUNDARY / BITS_PER_UNIT)
4265 && (FUNCTION_ARG_PADDING (mode, type)
4266 == (BYTES_BIG_ENDIAN ? upward : downward)))
4267 return true;
4269 return false;