]> gcc.gnu.org Git - gcc.git/blame - gcc/calls.c
check.c (gfc_check_getcwd_sub): Fix seg fault.
[gcc.git] / gcc / calls.c
CommitLineData
51bbfa0c 1/* Convert function calls to rtl insns, for GNU C compiler.
61f71b34 2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
d9221e01 3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
51bbfa0c 4
1322177d 5This file is part of GCC.
51bbfa0c 6
1322177d
LB
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
51bbfa0c 11
1322177d
LB
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
51bbfa0c
RS
16
17You should have received a copy of the GNU General Public License
1322177d
LB
18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
51bbfa0c
RS
21
22#include "config.h"
670ee920 23#include "system.h"
4977bab6
ZW
24#include "coretypes.h"
25#include "tm.h"
670ee920
KG
26#include "rtl.h"
27#include "tree.h"
28#include "flags.h"
29#include "expr.h"
6e985040 30#include "optabs.h"
e78d8e51 31#include "libfuncs.h"
49ad7cfa 32#include "function.h"
670ee920 33#include "regs.h"
5f6da302 34#include "toplev.h"
d6f4ec51 35#include "output.h"
b1474bb7 36#include "tm_p.h"
ea11ca7e 37#include "timevar.h"
c67846f2 38#include "sbitmap.h"
b0c48229 39#include "langhooks.h"
23626154 40#include "target.h"
b255a036 41#include "cgraph.h"
b2dd096b 42#include "except.h"
51bbfa0c 43
c795bca9
BS
44/* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
45#define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
51bbfa0c
RS
46
47/* Data structure and subroutines used within expand_call. */
48
49struct arg_data
50{
51 /* Tree node for this argument. */
52 tree tree_value;
1efe6448
RK
53 /* Mode for value; TYPE_MODE unless promoted. */
54 enum machine_mode mode;
51bbfa0c
RS
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
cacbd532 60 PARALLEL if the arg is to be copied into multiple non-contiguous
51bbfa0c
RS
61 registers. */
62 rtx reg;
099e9712
JH
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;
8df3dbb7
RH
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;
84b55618
RK
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;
51bbfa0c
RS
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;
da7d8304 76 /* Nonzero if argument must be passed on stack.
d64f5a78
RS
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. */
51bbfa0c 80 int pass_on_stack;
e7949876
AM
81 /* Some fields packaged up for locate_and_pad_parm. */
82 struct locate_and_pad_arg_data locate;
51bbfa0c
RS
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;
51bbfa0c
RS
90 /* Place that this stack area has been saved, if needed. */
91 rtx save_area;
4ab56118
RK
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;
51bbfa0c
RS
98};
99
da7d8304 100/* A vector of one char per byte of stack space. A byte if nonzero if
51bbfa0c
RS
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. */
104static char *stack_usage_map;
105
106/* Size of STACK_USAGE_MAP. */
107static int highest_outgoing_arg_in_use;
2f4aa534 108
c67846f2
JJ
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. */
114static sbitmap stored_args_map;
115
2f4aa534
RS
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. */
121int stack_arg_under_construction;
51bbfa0c 122
6de9cd9a 123static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT,
d329e058
AJ
124 HOST_WIDE_INT, rtx, rtx, int, rtx, int,
125 CUMULATIVE_ARGS *);
126static void precompute_register_parameters (int, struct arg_data *, int *);
127static int store_one_arg (struct arg_data *, rtx, int, int, int);
128static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
129static int finalize_must_preallocate (int, int, struct arg_data *,
130 struct args_size *);
131static void precompute_arguments (int, int, struct arg_data *);
132static int compute_argument_block_size (int, struct args_size *, int);
133static void initialize_argument_information (int, struct arg_data *,
134 struct args_size *, int, tree,
135 tree, CUMULATIVE_ARGS *, int,
dd292d0a 136 rtx *, int *, int *, int *,
6de9cd9a 137 bool *, bool);
d329e058
AJ
138static void compute_argument_addresses (struct arg_data *, rtx, int);
139static rtx rtx_for_function_call (tree, tree);
140static void load_register_parameters (struct arg_data *, int, rtx *, int,
141 int, int *);
142static rtx emit_library_call_value_1 (int, rtx, rtx, enum libcall_type,
143 enum machine_mode, int, va_list);
144static int special_function_p (tree, int);
d329e058
AJ
145static int check_sibcall_argument_overlap_1 (rtx);
146static int check_sibcall_argument_overlap (rtx, struct arg_data *, int);
147
148static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
95899b34 149 unsigned int);
c988af2b 150static bool shift_returned_value (tree, rtx *);
2f2b4a02
KH
151static tree split_complex_values (tree);
152static tree split_complex_types (tree);
21a3b983 153
f73ad30e 154#ifdef REG_PARM_STACK_SPACE
d329e058
AJ
155static rtx save_fixed_argument_area (int, rtx, int *, int *);
156static void restore_fixed_argument_area (rtx, rtx, int, int);
20efdf74 157#endif
51bbfa0c 158\f
51bbfa0c
RS
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.
162
77cac2f2
RK
163 CALL_FUSAGE points to a variable holding the prospective
164 CALL_INSN_FUNCTION_USAGE information. */
51bbfa0c 165
03dacb02 166rtx
6de9cd9a
DN
167prepare_call_address (rtx funexp, rtx static_chain_value,
168 rtx *call_fusage, int reg_parm_seen, int sibcallp)
51bbfa0c 169{
ba228239 170 /* Make a valid memory address and copy constants through pseudo-regs,
51bbfa0c
RS
171 but not for a constant address if -fno-function-cse. */
172 if (GET_CODE (funexp) != SYMBOL_REF)
01368078 173 /* If we are using registers for parameters, force the
e9a25f70
JL
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));
3affaf29 178 else if (! sibcallp)
51bbfa0c
RS
179 {
180#ifndef NO_FUNCTION_CSE
181 if (optimize && ! flag_no_function_cse)
082a099c 182 funexp = force_reg (Pmode, funexp);
51bbfa0c
RS
183#endif
184 }
185
186 if (static_chain_value != 0)
187 {
5e89a381 188 static_chain_value = convert_memory_address (Pmode, static_chain_value);
51bbfa0c
RS
189 emit_move_insn (static_chain_rtx, static_chain_value);
190
f8cfc6aa 191 if (REG_P (static_chain_rtx))
f991a240 192 use_reg (call_fusage, static_chain_rtx);
51bbfa0c
RS
193 }
194
195 return funexp;
196}
197
198/* Generate instructions to call function FUNEXP,
199 and optionally pop the results.
200 The CALL_INSN is the first insn generated.
201
607ea900 202 FNDECL is the declaration node of the function. This is given to the
2c8da025
RK
203 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
204
334c4f0f
RK
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.
51bbfa0c
RS
210
211 STACK_SIZE is the number of bytes of arguments on the stack,
c2732da3
JM
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.
51bbfa0c
RS
216
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.
219
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.
227
228 VALREG is a hard register in which a value is returned,
229 or 0 if the call does not return a value.
230
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.
234
94b25f81 235 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
6d2f8887 236 denote registers used by the called function. */
f725a3ec 237
322e3e34 238static void
6de9cd9a
DN
239emit_call_1 (rtx funexp, tree fntree, tree fndecl ATTRIBUTE_UNUSED,
240 tree funtype ATTRIBUTE_UNUSED,
d329e058
AJ
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)
51bbfa0c 247{
062e7fd8 248 rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
51bbfa0c
RS
249 rtx call_insn;
250 int already_popped = 0;
fb5eebb9 251 HOST_WIDE_INT n_popped = RETURN_POPS_ARGS (fndecl, funtype, stack_size);
f45c9d95
ZW
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
51bbfa0c 256
fa5322fa
AO
257#ifdef CALL_POPS_ARGS
258 n_popped += CALL_POPS_ARGS (* args_so_far);
259#endif
d329e058 260
51bbfa0c
RS
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);
266
0a1c58a2
JL
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
f132f529 270 && (n_popped > 0 || stack_size == 0))
0a1c58a2 271 {
8ac61af7 272 rtx n_pop = GEN_INT (n_popped);
0a1c58a2
JL
273 rtx pat;
274
275 /* If this subroutine pops its own args, record that in the call insn
276 if possible, for the sake of frame pointer elimination. */
277
278 if (valreg)
f45c9d95 279 pat = GEN_SIBCALL_VALUE_POP (valreg,
0a1c58a2
JL
280 gen_rtx_MEM (FUNCTION_MODE, funexp),
281 rounded_stack_size_rtx, next_arg_reg,
282 n_pop);
283 else
f45c9d95 284 pat = GEN_SIBCALL_POP (gen_rtx_MEM (FUNCTION_MODE, funexp),
0a1c58a2
JL
285 rounded_stack_size_rtx, next_arg_reg, n_pop);
286
287 emit_call_insn (pat);
288 already_popped = 1;
289 }
290 else
291#endif
292
51bbfa0c 293#if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
8ac61af7
RK
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. */
8bcafee3
JDA
298#if defined (HAVE_call) && defined (HAVE_call_value)
299 if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
7393c642 300 && n_popped > 0 && ! (ecf_flags & ECF_SP_DEPRESSED))
8bcafee3
JDA
301#else
302 if (HAVE_call_pop && HAVE_call_value_pop)
303#endif
51bbfa0c 304 {
fb5eebb9 305 rtx n_pop = GEN_INT (n_popped);
51bbfa0c
RS
306 rtx pat;
307
308 /* If this subroutine pops its own args, record that in the call insn
309 if possible, for the sake of frame pointer elimination. */
2c8da025 310
51bbfa0c 311 if (valreg)
f45c9d95 312 pat = GEN_CALL_VALUE_POP (valreg,
38a448ca 313 gen_rtx_MEM (FUNCTION_MODE, funexp),
062e7fd8 314 rounded_stack_size_rtx, next_arg_reg, n_pop);
51bbfa0c 315 else
f45c9d95 316 pat = GEN_CALL_POP (gen_rtx_MEM (FUNCTION_MODE, funexp),
062e7fd8 317 rounded_stack_size_rtx, next_arg_reg, n_pop);
51bbfa0c
RS
318
319 emit_call_insn (pat);
320 already_popped = 1;
321 }
322 else
323#endif
51bbfa0c 324
0a1c58a2
JL
325#if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
326 if ((ecf_flags & ECF_SIBCALL)
327 && HAVE_sibcall && HAVE_sibcall_value)
328 {
329 if (valreg)
f45c9d95 330 emit_call_insn (GEN_SIBCALL_VALUE (valreg,
0a1c58a2
JL
331 gen_rtx_MEM (FUNCTION_MODE, funexp),
332 rounded_stack_size_rtx,
333 next_arg_reg, NULL_RTX));
334 else
f45c9d95 335 emit_call_insn (GEN_SIBCALL (gen_rtx_MEM (FUNCTION_MODE, funexp),
0a1c58a2
JL
336 rounded_stack_size_rtx, next_arg_reg,
337 struct_value_size_rtx));
338 }
339 else
340#endif
341
51bbfa0c
RS
342#if defined (HAVE_call) && defined (HAVE_call_value)
343 if (HAVE_call && HAVE_call_value)
344 {
345 if (valreg)
f45c9d95 346 emit_call_insn (GEN_CALL_VALUE (valreg,
38a448ca 347 gen_rtx_MEM (FUNCTION_MODE, funexp),
062e7fd8 348 rounded_stack_size_rtx, next_arg_reg,
e992302c 349 NULL_RTX));
51bbfa0c 350 else
f45c9d95 351 emit_call_insn (GEN_CALL (gen_rtx_MEM (FUNCTION_MODE, funexp),
062e7fd8 352 rounded_stack_size_rtx, next_arg_reg,
51bbfa0c
RS
353 struct_value_size_rtx));
354 }
355 else
356#endif
366de0ce 357 gcc_unreachable ();
51bbfa0c 358
ee960939
OH
359 /* Find the call we just emitted. */
360 call_insn = last_call_insn ();
51bbfa0c 361
2a8f6b90
JH
362 /* Mark memory as used for "pure" function call. */
363 if (ecf_flags & ECF_PURE)
8ac61af7
RK
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);
2a8f6b90 370
ee960939
OH
371 /* Put the register usage information there. */
372 add_function_usage_to (call_insn, call_fusage);
51bbfa0c
RS
373
374 /* If this is a const call, then set the insn's unchanging bit. */
2a8f6b90 375 if (ecf_flags & (ECF_CONST | ECF_PURE))
24a28584 376 CONST_OR_PURE_CALL_P (call_insn) = 1;
51bbfa0c 377
12a22e76
JM
378 /* If this call can't throw, attach a REG_EH_REGION reg note to that
379 effect. */
0a1c58a2 380 if (ecf_flags & ECF_NOTHROW)
54cea123 381 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, const0_rtx,
12a22e76 382 REG_NOTES (call_insn));
b2dd096b 383 else
6de9cd9a
DN
384 {
385 int rn = lookup_stmt_eh_region (fntree);
386
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 ();
393 }
12a22e76 394
ca3920ad
JW
395 if (ecf_flags & ECF_NORETURN)
396 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_NORETURN, const0_rtx,
397 REG_NOTES (call_insn));
9d98f8f9
JH
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));
ca3920ad 401
570a98eb 402 if (ecf_flags & ECF_RETURNS_TWICE)
9defc9b7
RH
403 {
404 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_SETJMP, const0_rtx,
405 REG_NOTES (call_insn));
406 current_function_calls_setjmp = 1;
407 }
570a98eb 408
0a1c58a2
JL
409 SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
410
b1e64e0d
RS
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;
414
fb5eebb9 415 if (n_popped > 0)
51bbfa0c
RS
416 {
417 if (!already_popped)
e3da301d 418 CALL_INSN_FUNCTION_USAGE (call_insn)
38a448ca
RH
419 = gen_rtx_EXPR_LIST (VOIDmode,
420 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
421 CALL_INSN_FUNCTION_USAGE (call_insn));
fb5eebb9 422 rounded_stack_size -= n_popped;
062e7fd8 423 rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
1503a7ec 424 stack_pointer_delta -= n_popped;
51bbfa0c
RS
425 }
426
f73ad30e 427 if (!ACCUMULATE_OUTGOING_ARGS)
51bbfa0c 428 {
f73ad30e
JH
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.
432
433 If returning from the subroutine does pop the args, indicate that the
434 stack pointer will be changed. */
435
f79a65c0 436 if (rounded_stack_size != 0)
f73ad30e 437 {
f451eeef 438 if (ecf_flags & (ECF_SP_DEPRESSED | ECF_NORETURN | ECF_LONGJMP))
f79a65c0
RK
439 /* Just pretend we did the pop. */
440 stack_pointer_delta -= rounded_stack_size;
441 else if (flag_defer_pop && inhibit_defer_pop == 0
7393c642 442 && ! (ecf_flags & (ECF_CONST | ECF_PURE)))
f73ad30e
JH
443 pending_stack_adjust += rounded_stack_size;
444 else
445 adjust_stack (rounded_stack_size_rtx);
446 }
51bbfa0c 447 }
f73ad30e
JH
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.
453
454 ??? We may optimize similar to defer_pop above, but it is
455 probably not worthwhile.
f725a3ec 456
f73ad30e
JH
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));
51bbfa0c
RS
461}
462
20efdf74
JL
463/* Determine if the function identified by NAME and FNDECL is one with
464 special properties we wish to know about.
465
466 For example, if the function might return more than one time (setjmp), then
467 set RETURNS_TWICE to a nonzero value.
468
f2d33f13 469 Similarly set LONGJMP for if the function is in the longjmp family.
20efdf74 470
20efdf74
JL
471 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
472 space from the stack such as alloca. */
473
f2d33f13 474static int
d329e058 475special_function_p (tree fndecl, int flags)
20efdf74 476{
6de9cd9a 477 if (fndecl && DECL_NAME (fndecl)
140592a0 478 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
20efdf74
JL
479 /* Exclude functions not at the file scope, or not `extern',
480 since they are not the magic functions we would otherwise
d1bd0ded
GK
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. */
7ae4ad28 486 && (DECL_CONTEXT (fndecl) == NULL_TREE
d1bd0ded
GK
487 || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL)
488 && TREE_PUBLIC (fndecl))
20efdf74 489 {
63ad61ed
ZW
490 const char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
491 const char *tname = name;
20efdf74 492
ca54603f
JL
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. */
f2d33f13
JH
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;
ca54603f 503
20efdf74
JL
504 /* Disregard prefix _, __ or __x. */
505 if (name[0] == '_')
506 {
507 if (name[1] == '_' && name[2] == 'x')
508 tname += 3;
509 else if (name[1] == '_')
510 tname += 2;
511 else
512 tname += 1;
513 }
514
515 if (tname[0] == 's')
516 {
f2d33f13
JH
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;
525
20efdf74
JL
526 if (tname[1] == 'i'
527 && ! strcmp (tname, "siglongjmp"))
f2d33f13 528 flags |= ECF_LONGJMP;
20efdf74
JL
529 }
530 else if ((tname[0] == 'q' && tname[1] == 's'
531 && ! strcmp (tname, "qsetjmp"))
532 || (tname[0] == 'v' && tname[1] == 'f'
533 && ! strcmp (tname, "vfork")))
f2d33f13 534 flags |= ECF_RETURNS_TWICE;
20efdf74
JL
535
536 else if (tname[0] == 'l' && tname[1] == 'o'
537 && ! strcmp (tname, "longjmp"))
f2d33f13 538 flags |= ECF_LONGJMP;
20efdf74 539 }
d1c38823 540
f2d33f13 541 return flags;
20efdf74
JL
542}
543
f2d33f13 544/* Return nonzero when tree represent call to longjmp. */
7393c642 545
f2d33f13 546int
d329e058 547setjmp_call_p (tree fndecl)
f2d33f13
JH
548{
549 return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE;
550}
551
c986baf6
JH
552/* Return true when exp contains alloca call. */
553bool
d329e058 554alloca_call_p (tree exp)
c986baf6
JH
555{
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;
564}
565
b5cd4ed4 566/* Detect flags (function attributes) from the function decl or type node. */
7393c642 567
4977bab6 568int
d329e058 569flags_from_decl_or_type (tree exp)
f2d33f13
JH
570{
571 int flags = 0;
b5cd4ed4 572 tree type = exp;
36dbb93d 573
f2d33f13
JH
574 if (DECL_P (exp))
575 {
b255a036 576 struct cgraph_rtl_info *i = cgraph_rtl_info (exp);
b5cd4ed4
RK
577 type = TREE_TYPE (exp);
578
36dbb93d
RS
579 if (i)
580 {
581 if (i->pure_function)
582 flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
583 if (i->const_function)
584 flags |= ECF_CONST | ECF_LIBCALL_BLOCK;
585 }
b255a036 586
f2d33f13 587 /* The function exp may have the `malloc' attribute. */
36dbb93d 588 if (DECL_IS_MALLOC (exp))
f2d33f13
JH
589 flags |= ECF_MALLOC;
590
2a8f6b90 591 /* The function exp may have the `pure' attribute. */
36dbb93d 592 if (DECL_IS_PURE (exp))
53d4257f 593 flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
2a8f6b90 594
f2d33f13
JH
595 if (TREE_NOTHROW (exp))
596 flags |= ECF_NOTHROW;
2b187c63
MM
597
598 if (TREE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
4f976745 599 flags |= ECF_LIBCALL_BLOCK | ECF_CONST;
6de9cd9a
DN
600
601 flags = special_function_p (exp, flags);
f2d33f13 602 }
4f976745 603 else if (TYPE_P (exp) && TYPE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
2b187c63 604 flags |= ECF_CONST;
f2d33f13
JH
605
606 if (TREE_THIS_VOLATILE (exp))
607 flags |= ECF_NORETURN;
608
b5cd4ed4
RK
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))
612 {
613 flags |= ECF_SP_DEPRESSED;
53d4257f 614 flags &= ~(ECF_PURE | ECF_CONST | ECF_LIBCALL_BLOCK);
b5cd4ed4
RK
615 }
616
f2d33f13
JH
617 return flags;
618}
619
f027e0a2
JM
620/* Detect flags from a CALL_EXPR. */
621
622int
623call_expr_flags (tree t)
624{
625 int flags;
626 tree decl = get_callee_fndecl (t);
627
628 if (decl)
629 flags = flags_from_decl_or_type (decl);
630 else
631 {
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;
637 }
638
639 return flags;
640}
641
20efdf74
JL
642/* Precompute all register parameters as described by ARGS, storing values
643 into fields within the ARGS array.
644
645 NUM_ACTUALS indicates the total number elements in the ARGS array.
646
647 Set REG_PARM_SEEN if we encounter a register parameter. */
648
649static void
27e29549
RH
650precompute_register_parameters (int num_actuals, struct arg_data *args,
651 int *reg_parm_seen)
20efdf74
JL
652{
653 int i;
654
655 *reg_parm_seen = 0;
656
657 for (i = 0; i < num_actuals; i++)
658 if (args[i].reg != 0 && ! args[i].pass_on_stack)
659 {
660 *reg_parm_seen = 1;
661
662 if (args[i].value == 0)
663 {
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 ();
20efdf74
JL
669 }
670
fd1e5d25
RH
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);
676
20efdf74
JL
677 /* If we are to promote the function arg to a wider mode,
678 do it now. */
679
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);
685
27e29549
RH
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)
690 {
691 tree type = TREE_TYPE (args[i].tree_value);
8df3dbb7 692 args[i].parallel_value
27e29549
RH
693 = emit_group_load_into_temps (args[i].reg, args[i].value,
694 type, int_size_in_bytes (type));
695 }
696
f725a3ec 697 /* If the value is expensive, and we are inside an appropriately
20efdf74
JL
698 short loop, put the value into a pseudo and then put the pseudo
699 into the hard reg.
700
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. */
704
27e29549
RH
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))
20efdf74
JL
712 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
713 }
714}
715
f73ad30e 716#ifdef REG_PARM_STACK_SPACE
20efdf74
JL
717
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. */
3bdf5ad1 721
20efdf74 722static rtx
d329e058 723save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
20efdf74 724{
b820d2b8
AM
725 int low;
726 int high;
20efdf74 727
b820d2b8
AM
728 /* Compute the boundary of the area that needs to be saved, if any. */
729 high = reg_parm_stack_space;
20efdf74 730#ifdef ARGS_GROW_DOWNWARD
b820d2b8 731 high += 1;
20efdf74 732#endif
b820d2b8
AM
733 if (high > highest_outgoing_arg_in_use)
734 high = highest_outgoing_arg_in_use;
20efdf74 735
b820d2b8
AM
736 for (low = 0; low < high; low++)
737 if (stack_usage_map[low] != 0)
738 {
739 int num_to_save;
740 enum machine_mode save_mode;
741 int delta;
742 rtx stack_area;
743 rtx save_area;
20efdf74 744
b820d2b8
AM
745 while (stack_usage_map[--high] == 0)
746 ;
20efdf74 747
b820d2b8
AM
748 *low_to_save = low;
749 *high_to_save = high;
750
751 num_to_save = high - low + 1;
752 save_mode = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
20efdf74 753
b820d2b8
AM
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;
20efdf74
JL
759
760#ifdef ARGS_GROW_DOWNWARD
b820d2b8 761 delta = -high;
20efdf74 762#else
b820d2b8 763 delta = low;
20efdf74 764#endif
b820d2b8
AM
765 stack_area = gen_rtx_MEM (save_mode,
766 memory_address (save_mode,
767 plus_constant (argblock,
768 delta)));
8ac61af7 769
b820d2b8
AM
770 set_mem_align (stack_area, PARM_BOUNDARY);
771 if (save_mode == BLKmode)
772 {
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);
776 }
777 else
778 {
779 save_area = gen_reg_rtx (save_mode);
780 emit_move_insn (save_area, stack_area);
781 }
8ac61af7 782
b820d2b8
AM
783 return save_area;
784 }
785
786 return NULL_RTX;
20efdf74
JL
787}
788
789static void
d329e058 790restore_fixed_argument_area (rtx save_area, rtx argblock, int high_to_save, int low_to_save)
20efdf74
JL
791{
792 enum machine_mode save_mode = GET_MODE (save_area);
b820d2b8
AM
793 int delta;
794 rtx stack_area;
795
20efdf74 796#ifdef ARGS_GROW_DOWNWARD
b820d2b8 797 delta = -high_to_save;
20efdf74 798#else
b820d2b8 799 delta = low_to_save;
20efdf74 800#endif
b820d2b8
AM
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);
20efdf74
JL
805
806 if (save_mode != BLKmode)
807 emit_move_insn (stack_area, save_area);
808 else
44bb111a
RH
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);
20efdf74 812}
19652adf 813#endif /* REG_PARM_STACK_SPACE */
f725a3ec 814
20efdf74
JL
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
f725a3ec 818 which we will later copy into the appropriate hard registers.
8e6a59fe
MM
819
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. */
823
20efdf74 824static void
d329e058 825store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals)
20efdf74
JL
826{
827 int i, j;
f725a3ec 828
20efdf74
JL
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)))
834 {
835 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
6e985040
AM
836 int nregs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
837 int endian_correction = 0;
20efdf74 838
6e985040 839 args[i].n_aligned_regs = args[i].partial ? args[i].partial : nregs;
703ad42b 840 args[i].aligned_regs = xmalloc (sizeof (rtx) * args[i].n_aligned_regs);
20efdf74 841
6e985040
AM
842 /* Structures smaller than a word are normally aligned to the
843 least significant byte. On a BYTES_BIG_ENDIAN machine,
20efdf74
JL
844 this means we must skip the empty high order bytes when
845 calculating the bit offset. */
6e985040
AM
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
854 )
855 endian_correction = BITS_PER_WORD - bytes * BITS_PER_UNIT;
20efdf74
JL
856
857 for (j = 0; j < args[i].n_aligned_regs; j++)
858 {
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);
20efdf74
JL
862
863 args[i].aligned_regs[j] = reg;
6e985040 864 word = extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
b3520980 865 word_mode, word_mode);
20efdf74
JL
866
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.
870
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. */
877
878 emit_move_insn (reg, const0_rtx);
879
880 bytes -= bitsize / BITS_PER_UNIT;
6e985040 881 store_bit_field (reg, bitsize, endian_correction, word_mode,
b3520980 882 word);
20efdf74
JL
883 }
884 }
885}
886
d7cdf113 887/* Fill in ARGS_SIZE and ARGS array based on the parameters found in
f725a3ec 888 ACTPARMS.
d7cdf113
JL
889
890 NUM_ACTUALS is the total number of parameters.
891
892 N_NAMED_ARGS is the total number of named arguments.
893
894 FNDECL is the tree code for the target of this call (if known)
895
896 ARGS_SO_FAR holds state needed by the target to know where to place
897 the next argument.
898
899 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
900 for arguments which are passed in registers.
901
902 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
903 and may be modified by this routine.
904
f2d33f13 905 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
7ae4ad28 906 flags which may may be modified by this routine.
dd292d0a 907
6de9cd9a
DN
908 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
909 that requires allocation of stack space.
910
dd292d0a
MM
911 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
912 the thunked-to function. */
d7cdf113
JL
913
914static void
d329e058
AJ
915initialize_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,
dd292d0a 923 int *must_preallocate, int *ecf_flags,
6de9cd9a 924 bool *may_tailcall, bool call_from_thunk_p)
d7cdf113
JL
925{
926 /* 1 if scanning parms front to back, -1 if scanning back to front. */
927 int inc;
928
929 /* Count arg position in order args appear. */
930 int argpos;
931
932 int i;
933 tree p;
f725a3ec 934
d7cdf113
JL
935 args_size->constant = 0;
936 args_size->var = 0;
937
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. */
941
f73ad30e
JH
942 if (PUSH_ARGS_REVERSED)
943 {
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. */
947 }
948 else
949 {
950 i = 0, inc = 1;
951 }
d7cdf113
JL
952
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++)
955 {
956 tree type = TREE_TYPE (TREE_VALUE (p));
957 int unsignedp;
958 enum machine_mode mode;
959
960 args[i].tree_value = TREE_VALUE (p);
961
962 /* Replace erroneous argument with constant zero. */
d0f062fb 963 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
d7cdf113
JL
964 args[i].tree_value = integer_zero_node, type = integer_type_node;
965
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. */
2bf105ab 969 if (TREE_CODE (type) == UNION_TYPE && TYPE_TRANSPARENT_UNION (type))
d7cdf113
JL
970 type = TREE_TYPE (TYPE_FIELDS (type));
971
972 /* Decide where to pass this arg.
973
974 args[i].reg is nonzero if all or part is passed in registers.
975
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.
978
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.
982
983 These decisions are driven by the FUNCTION_... macros and must agree
984 with those made by function.c. */
985
986 /* See if this argument should be passed by invisible reference. */
0976078c
RH
987 if (pass_by_reference (args_so_far, TYPE_MODE (type),
988 type, argpos < n_named_args))
d7cdf113 989 {
9969aaf6
RH
990 bool callee_copies;
991 tree base;
992
993 callee_copies
6cdd5672
RH
994 = reference_callee_copied (args_so_far, TYPE_MODE (type),
995 type, argpos < n_named_args);
9969aaf6
RH
996
997 /* If we're compiling a thunk, pass through invisible references
998 instead of making a copy. */
dd292d0a 999 if (call_from_thunk_p
9969aaf6
RH
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)))))
d7cdf113 1004 {
9969aaf6
RH
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))
9fd47435
RS
1008 *may_tailcall = false;
1009
9969aaf6
RH
1010 args[i].tree_value = build_fold_addr_expr (args[i].tree_value);
1011 type = TREE_TYPE (args[i].tree_value);
1012
1013 *ecf_flags &= ~(ECF_CONST | ECF_LIBCALL_BLOCK);
f21add07 1014 }
d7cdf113
JL
1015 else
1016 {
1017 /* We make a copy of the object and pass the address to the
1018 function being called. */
1019 rtx copy;
1020
d0f062fb 1021 if (!COMPLETE_TYPE_P (type)
d7cdf113
JL
1022 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1023 || (flag_stack_check && ! STACK_CHECK_BUILTIN
05bccae2
RK
1024 && (0 < compare_tree_int (TYPE_SIZE_UNIT (type),
1025 STACK_CHECK_MAX_VAR_SIZE))))
d7cdf113
JL
1026 {
1027 /* This is a variable-sized object. Make space on the stack
1028 for it. */
1029 rtx size_rtx = expr_size (TREE_VALUE (p));
1030
1031 if (*old_stack_level == 0)
1032 {
1033 emit_stack_save (SAVE_BLOCK, old_stack_level, NULL_RTX);
1034 *old_pending_adj = pending_stack_adjust;
1035 pending_stack_adjust = 0;
1036 }
1037
1038 copy = gen_rtx_MEM (BLKmode,
3bdf5ad1
RK
1039 allocate_dynamic_stack_space
1040 (size_rtx, NULL_RTX, TYPE_ALIGN (type)));
1041 set_mem_attributes (copy, type, 1);
d7cdf113
JL
1042 }
1043 else
3bdf5ad1 1044 copy = assign_temp (type, 0, 1, 0);
d7cdf113
JL
1045
1046 store_expr (args[i].tree_value, copy, 0);
d7cdf113 1047
9969aaf6
RH
1048 if (callee_copies)
1049 *ecf_flags &= ~(ECF_CONST | ECF_LIBCALL_BLOCK);
1050 else
1051 *ecf_flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
1052
1053 args[i].tree_value
1054 = build_fold_addr_expr (make_tree (type, copy));
1055 type = TREE_TYPE (args[i].tree_value);
6de9cd9a 1056 *may_tailcall = false;
d7cdf113
JL
1057 }
1058 }
1059
1060 mode = TYPE_MODE (type);
8df83eae 1061 unsignedp = TYPE_UNSIGNED (type);
d7cdf113 1062
61f71b34
DD
1063 if (targetm.calls.promote_function_args (fndecl ? TREE_TYPE (fndecl) : 0))
1064 mode = promote_mode (type, mode, &unsignedp, 1);
d7cdf113
JL
1065
1066 args[i].unsignedp = unsignedp;
1067 args[i].mode = mode;
7d167afd 1068
099e9712
JH
1069 args[i].reg = FUNCTION_ARG (*args_so_far, mode, type,
1070 argpos < n_named_args);
7d167afd
JJ
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. */
099e9712 1075 args[i].tail_call_reg = FUNCTION_INCOMING_ARG (*args_so_far, mode, type,
f725a3ec 1076 argpos < n_named_args);
099e9712
JH
1077#else
1078 args[i].tail_call_reg = args[i].reg;
7d167afd 1079#endif
7d167afd 1080
d7cdf113
JL
1081 if (args[i].reg)
1082 args[i].partial
959f3a06 1083 = FUNCTION_ARG_PARTIAL_NREGS (*args_so_far, mode, type,
d7cdf113 1084 argpos < n_named_args);
d7cdf113 1085
fe984136 1086 args[i].pass_on_stack = targetm.calls.must_pass_in_stack (mode, type);
d7cdf113
JL
1087
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;
1094
1095 /* If this is an addressable type, we must preallocate the stack
1096 since we must evaluate the object into its final location.
1097
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;
1103
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))
53d4257f 1107 *ecf_flags &= ~ECF_LIBCALL_BLOCK;
d7cdf113
JL
1108
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
1115 1,
1116#else
1117 args[i].reg != 0,
1118#endif
e7949876
AM
1119 args[i].pass_on_stack ? 0 : args[i].partial,
1120 fndecl, args_size, &args[i].locate);
648bb159
RS
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
f725a3ec 1129
d7cdf113
JL
1130 /* Update ARGS_SIZE, the total stack space for args so far. */
1131
e7949876
AM
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);
d7cdf113
JL
1135
1136 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1137 have been used, etc. */
1138
959f3a06 1139 FUNCTION_ARG_ADVANCE (*args_so_far, TYPE_MODE (type), type,
d7cdf113
JL
1140 argpos < n_named_args);
1141 }
1142}
1143
599f37b6
JL
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.
1146
1147 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1148 for arguments passed in registers. */
1149
1150static int
d329e058
AJ
1151compute_argument_block_size (int reg_parm_stack_space,
1152 struct args_size *args_size,
1153 int preferred_stack_boundary ATTRIBUTE_UNUSED)
599f37b6
JL
1154{
1155 int unadjusted_args_size = args_size->constant;
1156
f73ad30e
JH
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
f5143c46 1159 backends from generating misaligned frame sizes. */
f73ad30e
JH
1160 if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY)
1161 preferred_stack_boundary = STACK_BOUNDARY;
f73ad30e 1162
599f37b6
JL
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. */
1166
1167 if (args_size->var)
1168 {
1169 args_size->var = ARGS_SIZE_TREE (*args_size);
1170 args_size->constant = 0;
1171
c2f8b491
JH
1172 preferred_stack_boundary /= BITS_PER_UNIT;
1173 if (preferred_stack_boundary > 1)
1503a7ec
JH
1174 {
1175 /* We don't handle this case yet. To handle it correctly we have
f5143c46 1176 to add the delta, round and subtract the delta.
1503a7ec 1177 Currently no machine description requires this support. */
366de0ce 1178 gcc_assert (!(stack_pointer_delta & (preferred_stack_boundary - 1)));
1503a7ec
JH
1179 args_size->var = round_up (args_size->var, preferred_stack_boundary);
1180 }
599f37b6
JL
1181
1182 if (reg_parm_stack_space > 0)
1183 {
1184 args_size->var
1185 = size_binop (MAX_EXPR, args_size->var,
fed3cef0 1186 ssize_int (reg_parm_stack_space));
599f37b6
JL
1187
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,
fed3cef0 1193 ssize_int (reg_parm_stack_space));
599f37b6
JL
1194#endif
1195 }
1196 }
1197 else
1198 {
c2f8b491 1199 preferred_stack_boundary /= BITS_PER_UNIT;
0a1c58a2
JL
1200 if (preferred_stack_boundary < 1)
1201 preferred_stack_boundary = 1;
fb5eebb9 1202 args_size->constant = (((args_size->constant
1503a7ec 1203 + stack_pointer_delta
c2f8b491
JH
1204 + preferred_stack_boundary - 1)
1205 / preferred_stack_boundary
1206 * preferred_stack_boundary)
1503a7ec 1207 - stack_pointer_delta);
599f37b6
JL
1208
1209 args_size->constant = MAX (args_size->constant,
1210 reg_parm_stack_space);
1211
599f37b6
JL
1212#ifndef OUTGOING_REG_PARM_STACK_SPACE
1213 args_size->constant -= reg_parm_stack_space;
1214#endif
1215 }
1216 return unadjusted_args_size;
1217}
1218
19832c77 1219/* Precompute parameters as needed for a function call.
cc0b1adc 1220
f2d33f13 1221 FLAGS is mask of ECF_* constants.
cc0b1adc 1222
cc0b1adc
JL
1223 NUM_ACTUALS is the number of arguments.
1224
f725a3ec
KH
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. */
cc0b1adc
JL
1228
1229static void
d329e058 1230precompute_arguments (int flags, int num_actuals, struct arg_data *args)
cc0b1adc
JL
1231{
1232 int i;
1233
3638733b 1234 /* If this is a libcall, then precompute all arguments so that we do not
82c82743
RH
1235 get extraneous instructions emitted as part of the libcall sequence. */
1236 if ((flags & ECF_LIBCALL_BLOCK) == 0)
1237 return;
7ae4ad28 1238
cc0b1adc 1239 for (i = 0; i < num_actuals; i++)
82c82743
RH
1240 {
1241 enum machine_mode mode;
ddef6bc7 1242
82c82743 1243 /* If this is an addressable type, we cannot pre-evaluate it. */
366de0ce 1244 gcc_assert (!TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)));
cc0b1adc 1245
82c82743 1246 args[i].initial_value = args[i].value
ad76cef8 1247 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
cc0b1adc 1248
82c82743
RH
1249 mode = TYPE_MODE (TREE_TYPE (args[i].tree_value));
1250 if (mode != args[i].mode)
1251 {
1252 args[i].value
1253 = convert_modes (args[i].mode, mode,
1254 args[i].value, args[i].unsignedp);
9e1622ed 1255#if defined(PROMOTE_FUNCTION_MODE) && !defined(PROMOTE_MODE)
82c82743
RH
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)
1261 {
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);
1267 }
47841d1b 1268#endif
82c82743
RH
1269 }
1270 }
cc0b1adc
JL
1271}
1272
0f9b3ea6
JL
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. */
1276
1277static int
d329e058 1278finalize_must_preallocate (int must_preallocate, int num_actuals, struct arg_data *args, struct args_size *args_size)
0f9b3ea6
JL
1279{
1280 /* See if we have or want to preallocate stack space.
1281
1282 If we would have to push a partially-in-regs parm
1283 before other stack parms, preallocate stack space instead.
1284
1285 If the size of some parm is not a multiple of the required stack
1286 alignment, we must preallocate.
1287
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.
1291
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. */
1298
1299 if (! must_preallocate)
1300 {
1301 int partial_seen = 0;
1302 int copy_to_evaluate_size = 0;
1303 int i;
1304
1305 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1306 {
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;
1311
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));
1319 }
1320
1321 if (copy_to_evaluate_size * 2 >= args_size->constant
1322 && args_size->constant > 0)
1323 must_preallocate = 1;
1324 }
1325 return must_preallocate;
1326}
599f37b6 1327
a45bdd02
JL
1328/* If we preallocated stack space, compute the address of each argument
1329 and store it into the ARGS array.
1330
f725a3ec 1331 We need not ensure it is a valid memory address here; it will be
a45bdd02
JL
1332 validized when it is used.
1333
1334 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1335
1336static void
d329e058 1337compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals)
a45bdd02
JL
1338{
1339 if (argblock)
1340 {
1341 rtx arg_reg = argblock;
1342 int i, arg_offset = 0;
1343
1344 if (GET_CODE (argblock) == PLUS)
1345 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1346
1347 for (i = 0; i < num_actuals; i++)
1348 {
e7949876
AM
1349 rtx offset = ARGS_SIZE_RTX (args[i].locate.offset);
1350 rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
a45bdd02
JL
1351 rtx addr;
1352
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;
1356
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);
1361
1362 addr = plus_constant (addr, arg_offset);
1363 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
d1a74aa7 1364 set_mem_align (args[i].stack, PARM_BOUNDARY);
3bdf5ad1
RK
1365 set_mem_attributes (args[i].stack,
1366 TREE_TYPE (args[i].tree_value), 1);
a45bdd02
JL
1367
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);
1372
1373 addr = plus_constant (addr, arg_offset);
1374 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
d1a74aa7 1375 set_mem_align (args[i].stack_slot, PARM_BOUNDARY);
3bdf5ad1
RK
1376 set_mem_attributes (args[i].stack_slot,
1377 TREE_TYPE (args[i].tree_value), 1);
7ab923cc
JJ
1378
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. */
ba4828e0
RK
1383 set_mem_alias_set (args[i].stack, 0);
1384 set_mem_alias_set (args[i].stack_slot, 0);
a45bdd02
JL
1385 }
1386 }
1387}
f725a3ec 1388
a45bdd02
JL
1389/* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1390 in a call instruction.
1391
1392 FNDECL is the tree node for the target function. For an indirect call
1393 FNDECL will be NULL_TREE.
1394
09e2bf48 1395 ADDR is the operand 0 of CALL_EXPR for this call. */
a45bdd02
JL
1396
1397static rtx
d329e058 1398rtx_for_function_call (tree fndecl, tree addr)
a45bdd02
JL
1399{
1400 rtx funexp;
1401
1402 /* Get the function to call, in the form of RTL. */
1403 if (fndecl)
1404 {
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))
1408 {
1409 assemble_external (fndecl);
1410 TREE_USED (fndecl) = 1;
1411 }
1412
1413 /* Get a SYMBOL_REF rtx for the function address. */
1414 funexp = XEXP (DECL_RTL (fndecl), 0);
1415 }
1416 else
1417 /* Generate an rtx (probably a pseudo-register) for the address. */
1418 {
1419 push_temp_slots ();
09e2bf48 1420 funexp = expand_expr (addr, NULL_RTX, VOIDmode, 0);
f725a3ec 1421 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
a45bdd02
JL
1422 }
1423 return funexp;
1424}
1425
21a3b983
JL
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
f725a3ec 1428 expressions were already evaluated.
21a3b983
JL
1429
1430 Mark all register-parms as living through the call, putting these USE
d329e058
AJ
1431 insns in the CALL_INSN_FUNCTION_USAGE field.
1432
0cdca92b
DJ
1433 When IS_SIBCALL, perform the check_sibcall_overlap_argument_overlap
1434 checking, setting *SIBCALL_FAILURE if appropriate. */
21a3b983
JL
1435
1436static void
d329e058
AJ
1437load_register_parameters (struct arg_data *args, int num_actuals,
1438 rtx *call_fusage, int flags, int is_sibcall,
1439 int *sibcall_failure)
21a3b983
JL
1440{
1441 int i, j;
1442
21a3b983 1443 for (i = 0; i < num_actuals; i++)
21a3b983 1444 {
099e9712
JH
1445 rtx reg = ((flags & ECF_SIBCALL)
1446 ? args[i].tail_call_reg : args[i].reg);
21a3b983
JL
1447 if (reg)
1448 {
6e985040
AM
1449 int partial = args[i].partial;
1450 int nregs;
1451 int size = 0;
0cdca92b 1452 rtx before_arg = get_last_insn ();
21a3b983
JL
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. */
6e985040
AM
1457 nregs = -1;
1458 if (partial)
1459 nregs = partial;
1460 else if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode)
1461 {
1462 size = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1463 nregs = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
1464 }
1465 else
1466 size = GET_MODE_SIZE (args[i].mode);
21a3b983
JL
1467
1468 /* Handle calls that pass values in multiple non-contiguous
1469 locations. The Irix 6 ABI has examples of this. */
1470
1471 if (GET_CODE (reg) == PARALLEL)
8df3dbb7 1472 emit_group_move (reg, args[i].parallel_value);
21a3b983
JL
1473
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. */
1477
9206d736
AM
1478 else if (nregs == -1)
1479 {
1480 emit_move_insn (reg, args[i].value);
6e985040 1481#ifdef BLOCK_REG_PADDING
9206d736
AM
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)))
1488 {
9206d736
AM
1489 rtx x;
1490 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
980f6e8e
AM
1491
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));
09b52670 1497 x = expand_shift (LSHIFT_EXPR, word_mode, reg,
7d60be94 1498 build_int_cst (NULL_TREE, shift),
4a90aeeb 1499 reg, 1);
980f6e8e
AM
1500 if (x != reg)
1501 emit_move_insn (reg, x);
9206d736 1502 }
6e985040 1503#endif
9206d736 1504 }
21a3b983
JL
1505
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. */
1508
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]);
1513
1514 else if (partial == 0 || args[i].pass_on_stack)
6e985040
AM
1515 {
1516 rtx mem = validize_mem (args[i].value);
1517
6e985040 1518 /* Handle a BLKmode that needs shifting. */
9206d736 1519 if (nregs == 1 && size < UNITS_PER_WORD
03ca1672
UW
1520#ifdef BLOCK_REG_PADDING
1521 && args[i].locate.where_pad == downward
1522#else
1523 && BYTES_BIG_ENDIAN
1524#endif
1525 )
6e985040
AM
1526 {
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;
09b52670
RS
1531 enum tree_code dir = BYTES_BIG_ENDIAN ? RSHIFT_EXPR
1532 : LSHIFT_EXPR;
6e985040
AM
1533
1534 emit_move_insn (x, tem);
09b52670 1535 x = expand_shift (dir, word_mode, x,
7d60be94 1536 build_int_cst (NULL_TREE, shift),
4a90aeeb 1537 ri, 1);
6e985040
AM
1538 if (x != ri)
1539 emit_move_insn (ri, x);
1540 }
1541 else
6e985040
AM
1542 move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode);
1543 }
21a3b983 1544
0cdca92b
DJ
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
32dd366d 1547 already clobbered. */
0cdca92b
DJ
1548 if (is_sibcall
1549 && check_sibcall_argument_overlap (before_arg, &args[i], 0))
1550 *sibcall_failure = 1;
1551
21a3b983
JL
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);
1560 }
1561 }
1562}
1563
739fb049
MM
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
ce48579b
RH
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. */
739fb049 1572
ce48579b 1573static int
d329e058
AJ
1574combine_pending_stack_adjustment_and_call (int unadjusted_args_size,
1575 struct args_size *args_size,
95899b34 1576 unsigned int preferred_unit_stack_boundary)
739fb049
MM
1577{
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. */
95899b34 1583 unsigned HOST_WIDE_INT unadjusted_alignment;
739fb049 1584
f725a3ec 1585 unadjusted_alignment
739fb049
MM
1586 = ((stack_pointer_delta + unadjusted_args_size)
1587 % preferred_unit_stack_boundary);
1588
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. */
1594
1595 /* Begin by trying to pop all the bytes. */
f725a3ec
KH
1596 unadjusted_alignment
1597 = (unadjusted_alignment
739fb049
MM
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. */
e079dcdb
HB
1602 if (preferred_unit_stack_boundary > 1)
1603 {
3e555c7d 1604 if (unadjusted_alignment > 0)
f725a3ec 1605 adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
e079dcdb 1606 else
f725a3ec 1607 adjustment += unadjusted_alignment;
e079dcdb 1608 }
f725a3ec 1609
739fb049
MM
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. */
f725a3ec 1614 args_size->constant
739fb049
MM
1615 = pending_stack_adjust - adjustment + unadjusted_args_size;
1616
ce48579b 1617 return adjustment;
739fb049
MM
1618}
1619
c67846f2
JJ
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).
da7d8304 1623 Return nonzero if X expression dereferences such argument slots,
c67846f2
JJ
1624 zero otherwise. */
1625
1626static int
d329e058 1627check_sibcall_argument_overlap_1 (rtx x)
c67846f2
JJ
1628{
1629 RTX_CODE code;
1630 int i, j;
1631 unsigned int k;
1632 const char *fmt;
1633
1634 if (x == NULL_RTX)
1635 return 0;
1636
1637 code = GET_CODE (x);
1638
1639 if (code == MEM)
1640 {
1641 if (XEXP (x, 0) == current_function_internal_arg_pointer)
1642 i = 0;
4c6b3b2a
JJ
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)
c67846f2
JJ
1647 i = INTVAL (XEXP (XEXP (x, 0), 1));
1648 else
01606a5a 1649 return 1;
c67846f2 1650
d60eab50
AO
1651#ifdef ARGS_GROW_DOWNWARD
1652 i = -i - GET_MODE_SIZE (GET_MODE (x));
1653#endif
1654
c67846f2
JJ
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;
1659
1660 return 0;
1661 }
1662
f725a3ec 1663 /* Scan all subexpressions. */
c67846f2
JJ
1664 fmt = GET_RTX_FORMAT (code);
1665 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
1666 {
1667 if (*fmt == 'e')
f725a3ec
KH
1668 {
1669 if (check_sibcall_argument_overlap_1 (XEXP (x, i)))
1670 return 1;
1671 }
c67846f2 1672 else if (*fmt == 'E')
f725a3ec
KH
1673 {
1674 for (j = 0; j < XVECLEN (x, i); j++)
1675 if (check_sibcall_argument_overlap_1 (XVECEXP (x, i, j)))
1676 return 1;
1677 }
c67846f2
JJ
1678 }
1679 return 0;
c67846f2
JJ
1680}
1681
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
0cdca92b
DJ
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. */
c67846f2
JJ
1688
1689static int
d329e058 1690check_sibcall_argument_overlap (rtx insn, struct arg_data *arg, int mark_stored_args_map)
f725a3ec 1691{
c67846f2
JJ
1692 int low, high;
1693
1694 if (insn == NULL_RTX)
1695 insn = get_insns ();
1696 else
1697 insn = NEXT_INSN (insn);
1698
1699 for (; insn; insn = NEXT_INSN (insn))
f725a3ec
KH
1700 if (INSN_P (insn)
1701 && check_sibcall_argument_overlap_1 (PATTERN (insn)))
c67846f2
JJ
1702 break;
1703
0cdca92b
DJ
1704 if (mark_stored_args_map)
1705 {
d60eab50 1706#ifdef ARGS_GROW_DOWNWARD
e7949876 1707 low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
d60eab50 1708#else
e7949876 1709 low = arg->locate.slot_offset.constant;
d60eab50
AO
1710#endif
1711
e7949876 1712 for (high = low + arg->locate.size.constant; low < high; low++)
0cdca92b
DJ
1713 SET_BIT (stored_args_map, low);
1714 }
c67846f2
JJ
1715 return insn != NULL_RTX;
1716}
1717
c988af2b
RS
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.
1721
1722 TYPE is the type of the function's return value, which is known not
1723 to have mode BLKmode. */
1724
1725static bool
1726shift_returned_value (tree type, rtx *value)
1727{
1728 if (targetm.calls.return_in_msb (type))
1729 {
1730 HOST_WIDE_INT shift;
1731
1732 shift = (GET_MODE_BITSIZE (GET_MODE (*value))
1733 - BITS_PER_UNIT * int_size_in_bytes (type));
1734 if (shift > 0)
1735 {
5a1f3953 1736 /* Shift the value into the low part of the register. */
c988af2b
RS
1737 *value = expand_binop (GET_MODE (*value), lshr_optab, *value,
1738 GEN_INT (shift), 0, 1, OPTAB_WIDEN);
5a1f3953
RS
1739
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);
1744
1745 /* Now convert it to the final form. */
1746 *value = gen_lowpart (TYPE_MODE (type), *value);
c988af2b
RS
1747 return true;
1748 }
1749 }
1750 return false;
1751}
1752
6de9cd9a
DN
1753/* Remove all REG_EQUIV notes found in the insn chain. */
1754
1755static void
1756purge_reg_equiv_notes (void)
1757{
1758 rtx insn;
1759
1760 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
1761 {
1762 while (1)
1763 {
1764 rtx note = find_reg_note (insn, REG_EQUIV, 0);
1765 if (note)
1766 {
1767 /* Remove the note and keep looking at the notes for
1768 this insn. */
1769 remove_note (insn, note);
1770 continue;
1771 }
1772 break;
1773 }
1774 }
1775}
1776
51bbfa0c
RS
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. */
1782
1783rtx
d329e058 1784expand_call (tree exp, rtx target, int ignore)
51bbfa0c 1785{
0a1c58a2
JL
1786 /* Nonzero if we are currently expanding a call. */
1787 static int currently_expanding_call = 0;
1788
51bbfa0c
RS
1789 /* List of actual parameters. */
1790 tree actparms = TREE_OPERAND (exp, 1);
1791 /* RTX for the function to be called. */
1792 rtx funexp;
0a1c58a2
JL
1793 /* Sequence of insns to perform a normal "call". */
1794 rtx normal_call_insns = NULL_RTX;
6de9cd9a 1795 /* Sequence of insns to perform a tail "call". */
0a1c58a2 1796 rtx tail_call_insns = NULL_RTX;
51bbfa0c
RS
1797 /* Data type of the function. */
1798 tree funtype;
ded9bf77 1799 tree type_arg_types;
51bbfa0c
RS
1800 /* Declaration of the function being called,
1801 or 0 if the function is computed (not known by name). */
1802 tree fndecl = 0;
57782ad8
MM
1803 /* The type of the function being called. */
1804 tree fntype;
6de9cd9a 1805 bool try_tail_call = CALL_EXPR_TAILCALL (exp);
0a1c58a2 1806 int pass;
51bbfa0c
RS
1807
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. */
e5e809f4 1821 HOST_WIDE_INT struct_value_size = 0;
51bbfa0c
RS
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;
61f71b34 1825 rtx struct_value = 0;
51bbfa0c
RS
1826
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;
51bbfa0c
RS
1832
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;
1837
1838 /* Total size in bytes of all the stack-parms scanned so far. */
1839 struct args_size args_size;
099e9712 1840 struct args_size adjusted_args_size;
51bbfa0c 1841 /* Size of arguments before any adjustments (such as rounding). */
599f37b6 1842 int unadjusted_args_size;
51bbfa0c
RS
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;
efd65a8b 1847 /* Nonzero if this is an indirect function call. */
51bbfa0c 1848
f725a3ec 1849 /* Nonzero if we must avoid push-insns in the args for this call.
51bbfa0c
RS
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). */
1854
f73ad30e 1855 int must_preallocate = !PUSH_ARGS;
51bbfa0c 1856
f72aed24 1857 /* Size of the stack reserved for parameter registers. */
6f90e075
JW
1858 int reg_parm_stack_space = 0;
1859
51bbfa0c
RS
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;
1863
f2d33f13
JH
1864 /* Mask of ECF_ flags. */
1865 int flags = 0;
f73ad30e 1866#ifdef REG_PARM_STACK_SPACE
51bbfa0c 1867 /* Define the boundary of the register parm stack space that needs to be
b820d2b8
AM
1868 saved, if any. */
1869 int low_to_save, high_to_save;
51bbfa0c
RS
1870 rtx save_area = 0; /* Place that it is saved */
1871#endif
1872
51bbfa0c
RS
1873 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
1874 char *initial_stack_usage_map = stack_usage_map;
51bbfa0c 1875
38afb23f
OH
1876 int old_stack_allocated;
1877
1878 /* State variables to track stack modifications. */
51bbfa0c 1879 rtx old_stack_level = 0;
38afb23f 1880 int old_stack_arg_under_construction = 0;
79be3418 1881 int old_pending_adj = 0;
51bbfa0c 1882 int old_inhibit_defer_pop = inhibit_defer_pop;
38afb23f
OH
1883
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. */
a259f218 1887 int old_stack_pointer_delta = 0;
38afb23f 1888
0a1c58a2 1889 rtx call_fusage;
b3694847 1890 tree p = TREE_OPERAND (exp, 0);
09e2bf48 1891 tree addr = TREE_OPERAND (exp, 0);
b3694847 1892 int i;
739fb049 1893 /* The alignment of the stack, in bits. */
95899b34 1894 unsigned HOST_WIDE_INT preferred_stack_boundary;
739fb049 1895 /* The alignment of the stack, in bytes. */
95899b34 1896 unsigned HOST_WIDE_INT preferred_unit_stack_boundary;
6de9cd9a
DN
1897 /* The static chain value to use for this call. */
1898 rtx static_chain_value;
f2d33f13
JH
1899 /* See if this is "nothrow" function call. */
1900 if (TREE_NOTHROW (exp))
1901 flags |= ECF_NOTHROW;
1902
6de9cd9a
DN
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. */
39b0dce7
JM
1905 fndecl = get_callee_fndecl (exp);
1906 if (fndecl)
51bbfa0c 1907 {
57782ad8 1908 fntype = TREE_TYPE (fndecl);
39b0dce7 1909 flags |= flags_from_decl_or_type (fndecl);
51bbfa0c 1910 }
39b0dce7 1911 else
72954a4f 1912 {
57782ad8 1913 fntype = TREE_TYPE (TREE_TYPE (p));
57782ad8 1914 flags |= flags_from_decl_or_type (fntype);
72954a4f 1915 }
7393c642 1916
57782ad8 1917 struct_value = targetm.calls.struct_value_rtx (fntype, 0);
61f71b34 1918
8c6a8269
RS
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");
1923
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))
1930 {
1931 bool volatilep = false;
1932 tree arg;
1933
1934 for (arg = actparms; arg; arg = TREE_CHAIN (arg))
1935 if (TREE_THIS_VOLATILE (TREE_VALUE (arg)))
1936 {
1937 volatilep = true;
1938 break;
1939 }
1940
1941 if (! volatilep)
1942 {
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;
1947 }
1948 }
1949
6f90e075 1950#ifdef REG_PARM_STACK_SPACE
6f90e075
JW
1951 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
1952#endif
6f90e075 1953
f73ad30e
JH
1954#ifndef OUTGOING_REG_PARM_STACK_SPACE
1955 if (reg_parm_stack_space > 0 && PUSH_ARGS)
e5e809f4
JL
1956 must_preallocate = 1;
1957#endif
1958
51bbfa0c
RS
1959 /* Set up a place to return a structure. */
1960
1961 /* Cater to broken compilers. */
61f71b34 1962 if (aggregate_value_p (exp, fndecl))
51bbfa0c
RS
1963 {
1964 /* This call returns a big structure. */
53d4257f 1965 flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
51bbfa0c
RS
1966
1967#ifdef PCC_STATIC_STRUCT_RETURN
9e7b1d0a
RS
1968 {
1969 pcc_struct_value = 1;
9e7b1d0a
RS
1970 }
1971#else /* not PCC_STATIC_STRUCT_RETURN */
1972 {
1973 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
51bbfa0c 1974
4977bab6 1975 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (exp))
89ea02fb 1976 {
f32ac70d
JM
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);
89ea02fb 1984 }
3c0cb5de 1985 else if (target && MEM_P (target))
9e7b1d0a
RS
1986 structure_value_addr = XEXP (target, 0);
1987 else
1988 {
9e7b1d0a
RS
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. */
1da68f56 1992 rtx d = assign_temp (TREE_TYPE (exp), 1, 1, 1);
51bbfa0c 1993
4361b41d
MM
1994 mark_temp_addr_taken (d);
1995 structure_value_addr = XEXP (d, 0);
9e7b1d0a
RS
1996 target = 0;
1997 }
1998 }
1999#endif /* not PCC_STATIC_STRUCT_RETURN */
51bbfa0c
RS
2000 }
2001
099e9712 2002 /* Figure out the amount to which the stack should be aligned. */
099e9712 2003 preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
b255a036
JH
2004 if (fndecl)
2005 {
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;
2009 }
099e9712
JH
2010
2011 /* Operand 0 is a pointer-to-function; get the type of the function. */
09e2bf48 2012 funtype = TREE_TYPE (addr);
366de0ce 2013 gcc_assert (POINTER_TYPE_P (funtype));
099e9712
JH
2014 funtype = TREE_TYPE (funtype);
2015
ded9bf77
AH
2016 /* Munge the tree to split complex arguments into their imaginary
2017 and real parts. */
42ba5130 2018 if (targetm.calls.split_complex_arg)
ded9bf77
AH
2019 {
2020 type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype));
2021 actparms = split_complex_values (actparms);
2022 }
2023 else
2024 type_arg_types = TYPE_ARG_TYPES (funtype);
2025
099e9712
JH
2026 if (flags & ECF_MAY_BE_ALLOCA)
2027 current_function_calls_alloca = 1;
2028
2029 /* If struct_value_rtx is 0, it means pass the address
2030 as if it were an extra parameter. */
61f71b34 2031 if (structure_value_addr && struct_value == 0)
099e9712
JH
2032 {
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. */
f8cfc6aa 2038 rtx temp = (!REG_P (structure_value_addr)
099e9712
JH
2039 || (ACCUMULATE_OUTGOING_ARGS
2040 && stack_arg_under_construction
2041 && structure_value_addr == virtual_outgoing_args_rtx)
7ae4ad28 2042 ? copy_addr_to_reg (convert_memory_address
57782ad8 2043 (Pmode, structure_value_addr))
099e9712
JH
2044 : structure_value_addr);
2045
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;
2052 }
2053
2054 /* Count the arguments and set NUM_ACTUALS. */
2055 for (p = actparms, num_actuals = 0; p; p = TREE_CHAIN (p))
2056 num_actuals++;
2057
2058 /* Compute number of named args.
3a4d587b
AM
2059 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2060
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;
2069
2070 /* Start updating where the next arg would go.
2071
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);
2077
2078 /* Now possibly adjust the number of named args.
099e9712 2079 Normally, don't include the last named arg if anonymous args follow.
3a179764
KH
2080 We do include the last named arg if
2081 targetm.calls.strict_argument_naming() returns nonzero.
099e9712
JH
2082 (If no anonymous args follow, the result of list_length is actually
2083 one too large. This is harmless.)
2084
4ac8340c 2085 If targetm.calls.pretend_outgoing_varargs_named() returns
3a179764
KH
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.
4ac8340c
KH
2091
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. */
099e9712 2095
3a4d587b
AM
2096 if (type_arg_types != 0
2097 && targetm.calls.strict_argument_naming (&args_so_far))
2098 ;
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;
099e9712 2103 else
3a4d587b 2104 /* Treat all args as named. */
099e9712
JH
2105 n_named_args = num_actuals;
2106
099e9712 2107 /* Make a vector to hold all the information about each arg. */
703ad42b
KG
2108 args = alloca (num_actuals * sizeof (struct arg_data));
2109 memset (args, 0, num_actuals * sizeof (struct arg_data));
099e9712 2110
d80d2d2a
KH
2111 /* Build up entries in the ARGS array, compute the size of the
2112 arguments into ARGS_SIZE, etc. */
099e9712
JH
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,
dd292d0a 2117 &must_preallocate, &flags,
6de9cd9a 2118 &try_tail_call, CALL_FROM_THUNK_P (exp));
099e9712
JH
2119
2120 if (args_size.var)
2121 {
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
6d2f8887 2125 what insns go in the cse'able block and which don't. */
099e9712 2126
53d4257f 2127 flags &= ~ECF_LIBCALL_BLOCK;
099e9712
JH
2128 must_preallocate = 1;
2129 }
2130
2131 /* Now make final decision about preallocating stack space. */
2132 must_preallocate = finalize_must_preallocate (must_preallocate,
2133 num_actuals, args,
2134 &args_size);
2135
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. */
2139
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);
0a1c58a2 2147
7ae4ad28 2148 /* Tail calls can make things harder to debug, and we've traditionally
194c7c45 2149 pushed these optimizations into -O2. Don't try if we're already
fb158467 2150 expanding a call, as that means we're an argument. Don't try if
3fbd86b1 2151 there's cleanups, as we know there's code to follow the call. */
0a1c58a2 2152
099e9712
JH
2153 if (currently_expanding_call++ != 0
2154 || !flag_optimize_sibling_calls
6de9cd9a
DN
2155 || args_size.var
2156 || lookup_stmt_eh_region (exp) >= 0)
2157 try_tail_call = 0;
099e9712
JH
2158
2159 /* Rest of purposes for tail call optimizations to fail. */
2160 if (
2161#ifdef HAVE_sibcall_epilogue
2162 !HAVE_sibcall_epilogue
2163#else
2164 1
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
4977bab6
ZW
2172 /* Check whether the target is able to optimize the call
2173 into a sibcall. */
5fd9b178 2174 || !targetm.function_ok_for_sibcall (fndecl, exp)
4977bab6
ZW
2175 /* Functions that do not return exactly once may not be sibcall
2176 optimized. */
db655634 2177 || (flags & (ECF_RETURNS_TWICE | ECF_LONGJMP | ECF_NORETURN))
09e2bf48 2178 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr)))
6a48df45
OH
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)
099e9712
JH
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. */
e076f71a
AH
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))
ae2bcd98 2192 || !lang_hooks.decls.ok_for_sibcall (fndecl))
e6f64875 2193 try_tail_call = 0;
497eb8c3 2194
c2f8b491
JH
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;
b255a036
JH
2201 if (fndecl == current_function_decl)
2202 cfun->recursive_call_emit = true;
c2f8b491 2203
099e9712 2204 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
497eb8c3 2205
0a1c58a2
JL
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. */
b820d2b8 2209 for (pass = try_tail_call ? 0 : 1; pass < 2; pass++)
0a1c58a2
JL
2210 {
2211 int sibcall_failure = 0;
f5143c46 2212 /* We want to emit any pending stack adjustments before the tail
0a1c58a2 2213 recursion "call". That way we know any adjustment after the tail
7ae4ad28 2214 recursion call can be ignored if we indeed use the tail
0a1c58a2 2215 call expansion. */
5ac9118e
KG
2216 int save_pending_stack_adjust = 0;
2217 int save_stack_pointer_delta = 0;
0a1c58a2 2218 rtx insns;
7d167afd 2219 rtx before_call, next_arg_reg;
39842893 2220
0a1c58a2
JL
2221 if (pass == 0)
2222 {
0a1c58a2
JL
2223 /* State variables we need to save and restore between
2224 iterations. */
2225 save_pending_stack_adjust = pending_stack_adjust;
1503a7ec 2226 save_stack_pointer_delta = stack_pointer_delta;
0a1c58a2 2227 }
f2d33f13
JH
2228 if (pass)
2229 flags &= ~ECF_SIBCALL;
2230 else
2231 flags |= ECF_SIBCALL;
51bbfa0c 2232
0a1c58a2 2233 /* Other state variables that we must reinitialize each time
f2d33f13 2234 through the loop (that are not initialized by the loop itself). */
0a1c58a2
JL
2235 argblock = 0;
2236 call_fusage = 0;
fa76d9e0 2237
f725a3ec 2238 /* Start a new sequence for the normal call case.
51bbfa0c 2239
0a1c58a2
JL
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 ();
eecb6f50 2243
0a1c58a2
JL
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
b5cd4ed4
RK
2247 call sequence or if we are calling a function that is to return
2248 with stack pointer depressed. */
0a1c58a2 2249 if (pending_stack_adjust >= 32
b5cd4ed4
RK
2250 || (pending_stack_adjust > 0
2251 && (flags & (ECF_MAY_BE_ALLOCA | ECF_SP_DEPRESSED)))
0a1c58a2
JL
2252 || pass == 0)
2253 do_pending_stack_adjust ();
51bbfa0c 2254
54fef245
RH
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. */
53d4257f 2257 if (pass && (flags & ECF_LIBCALL_BLOCK))
54fef245
RH
2258 NO_DEFER_POP;
2259
0a1c58a2 2260 /* Precompute any arguments as needed. */
f8a097cd
JH
2261 if (pass)
2262 precompute_arguments (flags, num_actuals, args);
51bbfa0c 2263
0a1c58a2
JL
2264 /* Now we are about to start emitting insns that can be deleted
2265 if a libcall is deleted. */
53d4257f 2266 if (pass && (flags & (ECF_LIBCALL_BLOCK | ECF_MALLOC)))
0a1c58a2 2267 start_sequence ();
51bbfa0c 2268
099e9712 2269 adjusted_args_size = args_size;
ce48579b
RH
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
f725a3ec
KH
2276 = compute_argument_block_size (reg_parm_stack_space,
2277 &adjusted_args_size,
ce48579b
RH
2278 (pass == 0 ? 0
2279 : preferred_stack_boundary));
2280
f725a3ec 2281 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
ce48579b 2282
f8a097cd
JH
2283 /* The argument block when performing a sibling call is the
2284 incoming argument block. */
2285 if (pass == 0)
c67846f2
JJ
2286 {
2287 argblock = virtual_incoming_args_rtx;
fcae219a
R
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
c67846f2
JJ
2294 stored_args_map = sbitmap_alloc (args_size.constant);
2295 sbitmap_zero (stored_args_map);
2296 }
ce48579b 2297
0a1c58a2
JL
2298 /* If we have no actual push instructions, or shouldn't use them,
2299 make space for all args right now. */
099e9712 2300 else if (adjusted_args_size.var != 0)
51bbfa0c 2301 {
0a1c58a2
JL
2302 if (old_stack_level == 0)
2303 {
2304 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
38afb23f 2305 old_stack_pointer_delta = stack_pointer_delta;
0a1c58a2
JL
2306 old_pending_adj = pending_stack_adjust;
2307 pending_stack_adjust = 0;
0a1c58a2
JL
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;
0a1c58a2 2313 }
099e9712 2314 argblock = push_block (ARGS_SIZE_RTX (adjusted_args_size), 0, 0);
51bbfa0c 2315 }
0a1c58a2
JL
2316 else
2317 {
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. */
26a258fe 2322
099e9712 2323 int needed = adjusted_args_size.constant;
51bbfa0c 2324
0a1c58a2
JL
2325 /* Store the maximum argument space used. It will be pushed by
2326 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2327 checking). */
51bbfa0c 2328
0a1c58a2
JL
2329 if (needed > current_function_outgoing_args_size)
2330 current_function_outgoing_args_size = needed;
51bbfa0c 2331
0a1c58a2
JL
2332 if (must_preallocate)
2333 {
f73ad30e
JH
2334 if (ACCUMULATE_OUTGOING_ARGS)
2335 {
f8a097cd
JH
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.
26a258fe 2341
f73ad30e 2342 Therefore, we save any area of the stack that was already
f8a097cd
JH
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
f725a3ec 2345 actual save will be done by store_one_arg.
26a258fe 2346
f73ad30e
JH
2347 Another approach might be to try to reorder the argument
2348 evaluations to avoid this conflicting stack usage. */
26a258fe 2349
e5e809f4 2350#ifndef OUTGOING_REG_PARM_STACK_SPACE
f8a097cd
JH
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. */
f73ad30e 2354 needed += reg_parm_stack_space;
51bbfa0c
RS
2355#endif
2356
2357#ifdef ARGS_GROW_DOWNWARD
f73ad30e
JH
2358 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2359 needed + 1);
51bbfa0c 2360#else
f73ad30e
JH
2361 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2362 needed);
51bbfa0c 2363#endif
703ad42b 2364 stack_usage_map = alloca (highest_outgoing_arg_in_use);
51bbfa0c 2365
f73ad30e 2366 if (initial_highest_arg_in_use)
2e09e75a
JM
2367 memcpy (stack_usage_map, initial_stack_usage_map,
2368 initial_highest_arg_in_use);
2f4aa534 2369
f73ad30e 2370 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
961192e1 2371 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
f73ad30e
JH
2372 (highest_outgoing_arg_in_use
2373 - initial_highest_arg_in_use));
2374 needed = 0;
2f4aa534 2375
f8a097cd
JH
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
f725a3ec 2379 allocate_dynamic_stack_space below. */
2f4aa534 2380
f73ad30e 2381 argblock = virtual_outgoing_args_rtx;
f725a3ec 2382 }
f73ad30e 2383 else
26a258fe 2384 {
f73ad30e 2385 if (inhibit_defer_pop == 0)
0a1c58a2 2386 {
f73ad30e 2387 /* Try to reuse some or all of the pending_stack_adjust
ce48579b
RH
2388 to get this space. */
2389 needed
f725a3ec 2390 = (combine_pending_stack_adjustment_and_call
ce48579b 2391 (unadjusted_args_size,
099e9712 2392 &adjusted_args_size,
ce48579b
RH
2393 preferred_unit_stack_boundary));
2394
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;
2400
2401 if (needed < 0)
f73ad30e 2402 {
ce48579b
RH
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 ();
f73ad30e
JH
2408 needed = 0;
2409 }
f725a3ec 2410 else
ce48579b
RH
2411 /* We need to allocate space. We'll do that in
2412 push_block below. */
2413 pending_stack_adjust = 0;
0a1c58a2 2414 }
ce48579b
RH
2415
2416 /* Special case this because overhead of `push_block' in
2417 this case is non-trivial. */
f73ad30e
JH
2418 if (needed == 0)
2419 argblock = virtual_outgoing_args_rtx;
0a1c58a2 2420 else
d892f288
DD
2421 {
2422 argblock = push_block (GEN_INT (needed), 0, 0);
2423#ifdef ARGS_GROW_DOWNWARD
2424 argblock = plus_constant (argblock, needed);
2425#endif
2426 }
f73ad30e 2427
f8a097cd
JH
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. */
f73ad30e 2435 argblock = copy_to_reg (argblock);
38afb23f
OH
2436 }
2437 }
2438 }
0a1c58a2 2439
38afb23f
OH
2440 if (ACCUMULATE_OUTGOING_ARGS)
2441 {
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)
2447 {
e5e809f4 2448#ifndef OUTGOING_REG_PARM_STACK_SPACE
38afb23f
OH
2449 rtx push_size = GEN_INT (reg_parm_stack_space
2450 + adjusted_args_size.constant);
bfbf933a 2451#else
38afb23f 2452 rtx push_size = GEN_INT (adjusted_args_size.constant);
bfbf933a 2453#endif
38afb23f
OH
2454 if (old_stack_level == 0)
2455 {
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. */
703ad42b 2469 stack_usage_map = alloca (highest_outgoing_arg_in_use);
38afb23f
OH
2470 memset (stack_usage_map, 0, highest_outgoing_arg_in_use);
2471 highest_outgoing_arg_in_use = 0;
f73ad30e 2472 }
38afb23f
OH
2473 allocate_dynamic_stack_space (push_size, NULL_RTX,
2474 BITS_PER_UNIT);
0a1c58a2 2475 }
bfbf933a 2476
38afb23f
OH
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)
2481 {
2482 argblock = copy_addr_to_reg (argblock);
2483 break;
2484 }
2485 }
d329e058 2486
0a1c58a2 2487 compute_argument_addresses (args, argblock, num_actuals);
bfbf933a 2488
0a1c58a2
JL
2489 /* If we push args individually in reverse order, perform stack alignment
2490 before the first push (the last arg). */
f73ad30e 2491 if (PUSH_ARGS_REVERSED && argblock == 0
099e9712 2492 && adjusted_args_size.constant != unadjusted_args_size)
4e217aed 2493 {
0a1c58a2
JL
2494 /* When the stack adjustment is pending, we get better code
2495 by combining the adjustments. */
f725a3ec 2496 if (pending_stack_adjust
53d4257f 2497 && ! (flags & ECF_LIBCALL_BLOCK)
0a1c58a2 2498 && ! inhibit_defer_pop)
ce48579b
RH
2499 {
2500 pending_stack_adjust
f725a3ec 2501 = (combine_pending_stack_adjustment_and_call
ce48579b 2502 (unadjusted_args_size,
099e9712 2503 &adjusted_args_size,
ce48579b
RH
2504 preferred_unit_stack_boundary));
2505 do_pending_stack_adjust ();
2506 }
0a1c58a2 2507 else if (argblock == 0)
099e9712 2508 anti_adjust_stack (GEN_INT (adjusted_args_size.constant
0a1c58a2 2509 - unadjusted_args_size));
0a1c58a2 2510 }
ebcd0b57
JH
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;
51bbfa0c 2514
09e2bf48 2515 funexp = rtx_for_function_call (fndecl, addr);
51bbfa0c 2516
0a1c58a2
JL
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)
2521 {
2522 if (pcc_struct_value)
2523 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
7d167afd 2524 fndecl, (pass == 0));
0a1c58a2 2525 else
7d167afd 2526 valreg = hard_function_value (TREE_TYPE (exp), fndecl, (pass == 0));
0a1c58a2 2527 }
51bbfa0c 2528
0a1c58a2
JL
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);
51bbfa0c 2532
6de9cd9a
DN
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;
2538
f73ad30e 2539#ifdef REG_PARM_STACK_SPACE
0a1c58a2
JL
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. */
f8a097cd 2542 if (ACCUMULATE_OUTGOING_ARGS && pass)
f73ad30e
JH
2543 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
2544 &low_to_save, &high_to_save);
b94301c2 2545#endif
51bbfa0c 2546
0a1c58a2
JL
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. */
51bbfa0c 2552
0a1c58a2
JL
2553 for (i = 0; i < num_actuals; i++)
2554 if (args[i].reg == 0 || args[i].pass_on_stack)
c67846f2
JJ
2555 {
2556 rtx before_arg = get_last_insn ();
2557
4c6b3b2a
JJ
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,
0cdca92b 2563 &args[i], 1)))
c67846f2 2564 sibcall_failure = 1;
2fabc3d6
JDA
2565
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);
c67846f2 2573 }
0a1c58a2
JL
2574
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);
2581
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)
c67846f2
JJ
2587 {
2588 rtx before_arg = get_last_insn ();
2589
4c6b3b2a
JJ
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,
0cdca92b 2595 &args[i], 1)))
c67846f2
JJ
2596 sibcall_failure = 1;
2597 }
51bbfa0c 2598
0a1c58a2
JL
2599 /* If we pushed args in forward order, perform stack alignment
2600 after pushing the last arg. */
f73ad30e 2601 if (!PUSH_ARGS_REVERSED && argblock == 0)
099e9712 2602 anti_adjust_stack (GEN_INT (adjusted_args_size.constant
0a1c58a2 2603 - unadjusted_args_size));
51bbfa0c 2604
0a1c58a2
JL
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. */
f73ad30e
JH
2608#ifdef OUTGOING_REG_PARM_STACK_SPACE
2609 if (!ACCUMULATE_OUTGOING_ARGS
f725a3ec 2610 && must_preallocate == 0 && reg_parm_stack_space > 0)
0a1c58a2 2611 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
756e0e12
RS
2612#endif
2613
0a1c58a2
JL
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)
2617 {
7ae4ad28 2618 structure_value_addr
5ae6cd0d 2619 = convert_memory_address (Pmode, structure_value_addr);
61f71b34 2620 emit_move_insn (struct_value,
0a1c58a2
JL
2621 force_reg (Pmode,
2622 force_operand (structure_value_addr,
2623 NULL_RTX)));
2624
f8cfc6aa 2625 if (REG_P (struct_value))
61f71b34 2626 use_reg (&call_fusage, struct_value);
0a1c58a2 2627 }
c2939b57 2628
6de9cd9a
DN
2629 funexp = prepare_call_address (funexp, static_chain_value,
2630 &call_fusage, reg_parm_seen, pass == 0);
51bbfa0c 2631
0cdca92b
DJ
2632 load_register_parameters (args, num_actuals, &call_fusage, flags,
2633 pass == 0, &sibcall_failure);
f725a3ec 2634
0a1c58a2
JL
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 ();
51bbfa0c 2638
7d167afd
JJ
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);
2649
0a1c58a2
JL
2650 /* All arguments and registers used for the call must be set up by
2651 now! */
2652
ce48579b 2653 /* Stack must be properly aligned now. */
366de0ce
NS
2654 gcc_assert (!pass
2655 || !(stack_pointer_delta % preferred_unit_stack_boundary));
ebcd0b57 2656
0a1c58a2 2657 /* Generate the actual call instruction. */
6de9cd9a 2658 emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,
099e9712 2659 adjusted_args_size.constant, struct_value_size,
7d167afd 2660 next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
fa5322fa 2661 flags, & args_so_far);
0a1c58a2
JL
2662
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. */
53d4257f 2667 if (pass && (flags & ECF_LIBCALL_BLOCK))
9ae8ffe7 2668 {
0a1c58a2 2669 rtx insns;
9778f2f8
JH
2670 rtx insn;
2671 bool failed = valreg == 0 || GET_CODE (valreg) == PARALLEL;
9ae8ffe7 2672
9778f2f8
JH
2673 insns = get_insns ();
2674
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))
4b4bf941 2678 if (JUMP_P (insn))
9778f2f8
JH
2679 failed = true;
2680
2681 if (failed)
e4abc3d5 2682 {
e4abc3d5 2683 end_sequence ();
2f937369 2684 emit_insn (insns);
e4abc3d5
RH
2685 }
2686 else
2687 {
2688 rtx note = 0;
2689 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2690
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))));
2695
e4abc3d5 2696 end_sequence ();
8f23fc81
MM
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))
7ae4ad28
EC
2703 note = gen_rtx_fmt_e (SQRT,
2704 GET_MODE (temp),
8f23fc81
MM
2705 args[0].initial_value);
2706 else
2707 {
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);
7ae4ad28 2715
8f23fc81
MM
2716 if (flags & ECF_PURE)
2717 note = gen_rtx_EXPR_LIST (VOIDmode,
e4abc3d5
RH
2718 gen_rtx_USE (VOIDmode,
2719 gen_rtx_MEM (BLKmode,
2720 gen_rtx_SCRATCH (VOIDmode))),
2721 note);
8f23fc81 2722 }
e4abc3d5
RH
2723 emit_libcall_block (insns, temp, valreg, note);
2724
2725 valreg = temp;
2726 }
0a1c58a2 2727 }
53d4257f 2728 else if (pass && (flags & ECF_MALLOC))
0a1c58a2
JL
2729 {
2730 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2731 rtx last, insns;
2732
f725a3ec 2733 /* The return value from a malloc-like function is a pointer. */
0a1c58a2 2734 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
bdb429a5 2735 mark_reg_pointer (temp, BIGGEST_ALIGNMENT);
0a1c58a2
JL
2736
2737 emit_move_insn (temp, valreg);
2738
2739 /* The return value from a malloc-like function can not alias
2740 anything else. */
2741 last = get_last_insn ();
f725a3ec 2742 REG_NOTES (last) =
0a1c58a2
JL
2743 gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));
2744
2745 /* Write out the sequence. */
2746 insns = get_insns ();
2747 end_sequence ();
2f937369 2748 emit_insn (insns);
0a1c58a2
JL
2749 valreg = temp;
2750 }
51bbfa0c 2751
0a1c58a2
JL
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. */
51bbfa0c 2755
570a98eb 2756 if ((flags & (ECF_NORETURN | ECF_LONGJMP)) || pass == 0)
c2939b57 2757 {
570a98eb 2758 /* The barrier must be emitted
0a1c58a2
JL
2759 immediately after the CALL_INSN. Some ports emit more
2760 than just a CALL_INSN above, so we must search for it here. */
51bbfa0c 2761
0a1c58a2 2762 rtx last = get_last_insn ();
4b4bf941 2763 while (!CALL_P (last))
0a1c58a2
JL
2764 {
2765 last = PREV_INSN (last);
2766 /* There was no CALL_INSN? */
366de0ce 2767 gcc_assert (last != before_call);
0a1c58a2 2768 }
51bbfa0c 2769
570a98eb 2770 emit_barrier_after (last);
8af61113 2771
f451eeef
JS
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)
2776 {
2777 stack_pointer_delta = old_stack_allocated;
2778 pending_stack_adjust = 0;
2779 }
0a1c58a2 2780 }
51bbfa0c 2781
f2d33f13 2782 if (flags & ECF_LONGJMP)
099e9712 2783 current_function_calls_longjmp = 1;
51bbfa0c 2784
0a1c58a2 2785 /* If value type not void, return an rtx for the value. */
51bbfa0c 2786
0a1c58a2
JL
2787 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
2788 || ignore)
b5cd4ed4 2789 target = const0_rtx;
0a1c58a2
JL
2790 else if (structure_value_addr)
2791 {
3c0cb5de 2792 if (target == 0 || !MEM_P (target))
0a1c58a2 2793 {
3bdf5ad1
RK
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);
0a1c58a2
JL
2799 }
2800 }
2801 else if (pcc_struct_value)
cacbd532 2802 {
0a1c58a2
JL
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));
3bdf5ad1 2808 set_mem_attributes (target, exp, 1);
cacbd532 2809 }
0a1c58a2
JL
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)
2813 {
6de9cd9a 2814 if (target == 0)
0a1c58a2 2815 {
1da68f56
RK
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));
2820
2821 target = assign_temp (nt, 0, 1, 1);
0a1c58a2
JL
2822 preserve_temp_slots (target);
2823 }
2824
2825 if (! rtx_equal_p (target, valreg))
6e985040 2826 emit_group_store (target, valreg, TREE_TYPE (exp),
04050c69 2827 int_size_in_bytes (TREE_TYPE (exp)));
19caa751 2828
0a1c58a2
JL
2829 /* We can not support sibling calls for this case. */
2830 sibcall_failure = 1;
2831 }
2832 else if (target
2833 && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2834 && GET_MODE (target) == GET_MODE (valreg))
2835 {
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.
2839
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);
0219237c
OH
2843
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. */
3c0cb5de 2847 if (MEM_P (target))
0219237c 2848 sibcall_failure = 1;
0a1c58a2
JL
2849 }
2850 else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
8eb99146
RH
2851 {
2852 target = copy_blkmode_from_reg (target, valreg, TREE_TYPE (exp));
2853
2854 /* We can not support sibling calls for this case. */
2855 sibcall_failure = 1;
2856 }
0a1c58a2 2857 else
c988af2b
RS
2858 {
2859 if (shift_returned_value (TREE_TYPE (exp), &valreg))
2860 sibcall_failure = 1;
2861
2862 target = copy_to_reg (valreg);
2863 }
51bbfa0c 2864
61f71b34
DD
2865 if (targetm.calls.promote_function_return(funtype))
2866 {
366de0ce
NS
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)))
2872 {
2873 tree type = TREE_TYPE (exp);
2874 int unsignedp = TYPE_UNSIGNED (type);
2875 int offset = 0;
2876 enum machine_mode pmode;
2877
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);
2881
2882 if ((WORDS_BIG_ENDIAN || BYTES_BIG_ENDIAN)
2883 && (GET_MODE_SIZE (GET_MODE (target))
2884 > GET_MODE_SIZE (TYPE_MODE (type))))
2885 {
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;
2892 }
2893 target = gen_rtx_SUBREG (TYPE_MODE (type), target, offset);
2894 SUBREG_PROMOTED_VAR_P (target) = 1;
2895 SUBREG_PROMOTED_UNSIGNED_SET (target, unsignedp);
2896 }
61f71b34 2897 }
84b55618 2898
0a1c58a2
JL
2899 /* If size of args is variable or this was a constructor call for a stack
2900 argument, restore saved stack-pointer value. */
51bbfa0c 2901
7393c642 2902 if (old_stack_level && ! (flags & ECF_SP_DEPRESSED))
0a1c58a2
JL
2903 {
2904 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
38afb23f 2905 stack_pointer_delta = old_stack_pointer_delta;
0a1c58a2 2906 pending_stack_adjust = old_pending_adj;
d25cee4d 2907 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
0a1c58a2
JL
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;
0a1c58a2
JL
2911 sibcall_failure = 1;
2912 }
f8a097cd 2913 else if (ACCUMULATE_OUTGOING_ARGS && pass)
0a1c58a2 2914 {
51bbfa0c 2915#ifdef REG_PARM_STACK_SPACE
0a1c58a2 2916 if (save_area)
b820d2b8
AM
2917 restore_fixed_argument_area (save_area, argblock,
2918 high_to_save, low_to_save);
b94301c2 2919#endif
51bbfa0c 2920
0a1c58a2
JL
2921 /* If we saved any argument areas, restore them. */
2922 for (i = 0; i < num_actuals; i++)
2923 if (args[i].save_area)
2924 {
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)));
2930
2931 if (save_mode != BLKmode)
2932 emit_move_insn (stack_area, args[i].save_area);
2933 else
44bb111a 2934 emit_block_move (stack_area, args[i].save_area,
e7949876 2935 GEN_INT (args[i].locate.size.constant),
44bb111a 2936 BLOCK_OP_CALL_PARM);
0a1c58a2 2937 }
51bbfa0c 2938
0a1c58a2
JL
2939 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2940 stack_usage_map = initial_stack_usage_map;
2941 }
51bbfa0c 2942
f725a3ec 2943 /* If this was alloca, record the new stack level for nonlocal gotos.
0a1c58a2
JL
2944 Check for the handler slots since we might not have a save area
2945 for non-local gotos. */
59257ff7 2946
6de9cd9a
DN
2947 if ((flags & ECF_MAY_BE_ALLOCA) && cfun->nonlocal_goto_save_area != 0)
2948 update_nonlocal_goto_save_area ();
51bbfa0c 2949
0a1c58a2
JL
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);
2954
2955 insns = get_insns ();
2956 end_sequence ();
2957
2958 if (pass == 0)
2959 {
2960 tail_call_insns = insns;
2961
0a1c58a2
JL
2962 /* Restore the pending stack adjustment now that we have
2963 finished generating the sibling call sequence. */
1503a7ec 2964
0a1c58a2 2965 pending_stack_adjust = save_pending_stack_adjust;
1503a7ec 2966 stack_pointer_delta = save_stack_pointer_delta;
099e9712
JH
2967
2968 /* Prepare arg structure for next iteration. */
f725a3ec 2969 for (i = 0; i < num_actuals; i++)
099e9712
JH
2970 {
2971 args[i].value = 0;
2972 args[i].aligned_regs = 0;
2973 args[i].stack = 0;
2974 }
c67846f2
JJ
2975
2976 sbitmap_free (stored_args_map);
0a1c58a2
JL
2977 }
2978 else
38afb23f
OH
2979 {
2980 normal_call_insns = insns;
2981
2982 /* Verify that we've deallocated all the stack we used. */
366de0ce
NS
2983 gcc_assert ((flags & (ECF_NORETURN | ECF_LONGJMP))
2984 || (old_stack_allocated
2985 == stack_pointer_delta - pending_stack_adjust));
38afb23f 2986 }
fadb729c
JJ
2987
2988 /* If something prevents making this a sibling call,
2989 zero out the sequence. */
2990 if (sibcall_failure)
2991 tail_call_insns = NULL_RTX;
6de9cd9a
DN
2992 else
2993 break;
0a1c58a2
JL
2994 }
2995
1ea7e6ad 2996 /* If tail call production succeeded, we need to remove REG_EQUIV notes on
6de9cd9a
DN
2997 arguments too, as argument area is now clobbered by the call. */
2998 if (tail_call_insns)
0a1c58a2 2999 {
6de9cd9a
DN
3000 emit_insn (tail_call_insns);
3001 cfun->tail_call_emit = true;
0a1c58a2
JL
3002 }
3003 else
2f937369 3004 emit_insn (normal_call_insns);
51bbfa0c 3005
0a1c58a2 3006 currently_expanding_call--;
8e6a59fe 3007
7393c642
RK
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)
3012 {
3013 clear_pending_stack_adjust ();
f84d109f 3014 emit_insn (gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx));
7393c642 3015 emit_move_insn (virtual_stack_dynamic_rtx, stack_pointer_rtx);
7393c642
RK
3016 }
3017
51bbfa0c
RS
3018 return target;
3019}
ded9bf77 3020
6de9cd9a
DN
3021/* A sibling call sequence invalidates any REG_EQUIV notes made for
3022 this function's incoming arguments.
3023
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.
3027
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. */
3031void
3032fixup_tail_calls (void)
3033{
6de9cd9a 3034 purge_reg_equiv_notes ();
6de9cd9a
DN
3035}
3036
ded9bf77
AH
3037/* Traverse an argument list in VALUES and expand all complex
3038 arguments into their components. */
2f2b4a02 3039static tree
ded9bf77
AH
3040split_complex_values (tree values)
3041{
3042 tree p;
3043
42ba5130
RH
3044 /* Before allocating memory, check for the common case of no complex. */
3045 for (p = values; p; p = TREE_CHAIN (p))
3046 {
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;
3051 }
3052 return values;
3053
3054 found:
ded9bf77
AH
3055 values = copy_list (values);
3056
3057 for (p = values; p; p = TREE_CHAIN (p))
3058 {
3059 tree complex_value = TREE_VALUE (p);
3060 tree complex_type;
3061
3062 complex_type = TREE_TYPE (complex_value);
3063 if (!complex_type)
3064 continue;
3065
42ba5130
RH
3066 if (TREE_CODE (complex_type) == COMPLEX_TYPE
3067 && targetm.calls.split_complex_arg (complex_type))
ded9bf77
AH
3068 {
3069 tree subtype;
3070 tree real, imag, next;
3071
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);
3076
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;
3082
3083 /* Skip the newly created node. */
3084 p = TREE_CHAIN (p);
3085 }
3086 }
3087
3088 return values;
3089}
3090
3091/* Traverse a list of TYPES and expand all complex types into their
3092 components. */
2f2b4a02 3093static tree
ded9bf77
AH
3094split_complex_types (tree types)
3095{
3096 tree p;
3097
42ba5130
RH
3098 /* Before allocating memory, check for the common case of no complex. */
3099 for (p = types; p; p = TREE_CHAIN (p))
3100 {
3101 tree type = TREE_VALUE (p);
3102 if (TREE_CODE (type) == COMPLEX_TYPE
3103 && targetm.calls.split_complex_arg (type))
3104 goto found;
3105 }
3106 return types;
3107
3108 found:
ded9bf77
AH
3109 types = copy_list (types);
3110
3111 for (p = types; p; p = TREE_CHAIN (p))
3112 {
3113 tree complex_type = TREE_VALUE (p);
3114
42ba5130
RH
3115 if (TREE_CODE (complex_type) == COMPLEX_TYPE
3116 && targetm.calls.split_complex_arg (complex_type))
ded9bf77
AH
3117 {
3118 tree next, imag;
3119
3120 /* Rewrite complex type with component type. */
3121 TREE_VALUE (p) = TREE_TYPE (complex_type);
3122 next = TREE_CHAIN (p);
3123
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;
3128
3129 /* Skip the newly created node. */
3130 p = TREE_CHAIN (p);
3131 }
3132 }
3133
3134 return types;
3135}
51bbfa0c 3136\f
de76b467 3137/* Output a library call to function FUN (a SYMBOL_REF rtx).
f725a3ec 3138 The RETVAL parameter specifies whether return value needs to be saved, other
0407c02b 3139 parameters are documented in the emit_library_call function below. */
8ac61af7 3140
de76b467 3141static rtx
d329e058
AJ
3142emit_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)
43bc5f13 3145{
3c0fca12
RH
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;
b3694847 3150 int argnum;
3c0fca12
RH
3151 rtx fun;
3152 int inc;
3153 int count;
3c0fca12
RH
3154 rtx argblock = 0;
3155 CUMULATIVE_ARGS args_so_far;
f725a3ec
KH
3156 struct arg
3157 {
3158 rtx value;
3159 enum machine_mode mode;
3160 rtx reg;
3161 int partial;
e7949876 3162 struct locate_and_pad_arg_data locate;
f725a3ec
KH
3163 rtx save_area;
3164 };
3c0fca12
RH
3165 struct arg *argvec;
3166 int old_inhibit_defer_pop = inhibit_defer_pop;
3167 rtx call_fusage = 0;
3168 rtx mem_value = 0;
5591ee6f 3169 rtx valreg;
3c0fca12
RH
3170 int pcc_struct_value = 0;
3171 int struct_value_size = 0;
52a11cbf 3172 int flags;
3c0fca12 3173 int reg_parm_stack_space = 0;
3c0fca12 3174 int needed;
695ee791 3175 rtx before_call;
b0c48229 3176 tree tfom; /* type_for_mode (outmode, 0) */
3c0fca12 3177
f73ad30e 3178#ifdef REG_PARM_STACK_SPACE
3c0fca12
RH
3179 /* Define the boundary of the register parm stack space that needs to be
3180 save, if any. */
b820d2b8 3181 int low_to_save, high_to_save;
f725a3ec 3182 rtx save_area = 0; /* Place that it is saved. */
3c0fca12
RH
3183#endif
3184
3c0fca12
RH
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;
3c0fca12 3188
61f71b34
DD
3189 rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
3190
3c0fca12 3191#ifdef REG_PARM_STACK_SPACE
3c0fca12 3192 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3c0fca12
RH
3193#endif
3194
9555a122 3195 /* By default, library functions can not throw. */
52a11cbf
RH
3196 flags = ECF_NOTHROW;
3197
9555a122
RH
3198 switch (fn_type)
3199 {
3200 case LCT_NORMAL:
53d4257f 3201 break;
9555a122 3202 case LCT_CONST:
53d4257f
JH
3203 flags |= ECF_CONST;
3204 break;
9555a122 3205 case LCT_PURE:
53d4257f 3206 flags |= ECF_PURE;
9555a122
RH
3207 break;
3208 case LCT_CONST_MAKE_BLOCK:
53d4257f 3209 flags |= ECF_CONST | ECF_LIBCALL_BLOCK;
9555a122
RH
3210 break;
3211 case LCT_PURE_MAKE_BLOCK:
53d4257f 3212 flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
9555a122
RH
3213 break;
3214 case LCT_NORETURN:
3215 flags |= ECF_NORETURN;
3216 break;
3217 case LCT_THROW:
3218 flags = ECF_NORETURN;
3219 break;
9d98f8f9
JH
3220 case LCT_ALWAYS_RETURN:
3221 flags = ECF_ALWAYS_RETURN;
3222 break;
9defc9b7
RH
3223 case LCT_RETURNS_TWICE:
3224 flags = ECF_RETURNS_TWICE;
3225 break;
9555a122 3226 }
3c0fca12
RH
3227 fun = orgfun;
3228
3c0fca12
RH
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;
3c0fca12
RH
3233
3234 /* If this kind of value comes back in memory,
3235 decide where in memory it should come back. */
b0c48229 3236 if (outmode != VOIDmode)
3c0fca12 3237 {
ae2bcd98 3238 tfom = lang_hooks.types.type_for_mode (outmode, 0);
61f71b34 3239 if (aggregate_value_p (tfom, 0))
b0c48229 3240 {
3c0fca12 3241#ifdef PCC_STATIC_STRUCT_RETURN
b0c48229
NB
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);
3c0fca12 3248#else /* not PCC_STATIC_STRUCT_RETURN */
b0c48229 3249 struct_value_size = GET_MODE_SIZE (outmode);
3c0cb5de 3250 if (value != 0 && MEM_P (value))
b0c48229
NB
3251 mem_value = value;
3252 else
3253 mem_value = assign_temp (tfom, 0, 1, 1);
3c0fca12 3254#endif
b0c48229
NB
3255 /* This call returns a big structure. */
3256 flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
3257 }
3c0fca12 3258 }
b0c48229
NB
3259 else
3260 tfom = void_type_node;
3c0fca12
RH
3261
3262 /* ??? Unfinished: must pass the memory address as an argument. */
3263
3264 /* Copy all the libcall-arguments out of the varargs data
3265 and into a vector ARGVEC.
3266
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. */
3270
703ad42b
KG
3271 argvec = alloca ((nargs + 1) * sizeof (struct arg));
3272 memset (argvec, 0, (nargs + 1) * sizeof (struct arg));
3c0fca12 3273
97fc4caf
AO
3274#ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3275 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far, outmode, fun);
3276#else
0f6937fe 3277 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0, nargs);
97fc4caf 3278#endif
3c0fca12
RH
3279
3280 args_size.constant = 0;
3281 args_size.var = 0;
3282
3283 count = 0;
3284
ebb1b59a
BS
3285 /* Now we are about to start emitting insns that can be deleted
3286 if a libcall is deleted. */
53d4257f 3287 if (flags & ECF_LIBCALL_BLOCK)
ebb1b59a
BS
3288 start_sequence ();
3289
3c0fca12
RH
3290 push_temp_slots ();
3291
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. */
61f71b34 3294 if (mem_value && struct_value == 0 && ! pcc_struct_value)
3c0fca12
RH
3295 {
3296 rtx addr = XEXP (mem_value, 0);
366de0ce
NS
3297 int partial;
3298
3c0fca12
RH
3299 nargs++;
3300
3301 /* Make sure it is a reasonable operand for a move or push insn. */
3c0cb5de 3302 if (!REG_P (addr) && !MEM_P (addr)
3c0fca12
RH
3303 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
3304 addr = force_operand (addr, NULL_RTX);
3305
3306 argvec[count].value = addr;
3307 argvec[count].mode = Pmode;
3308 argvec[count].partial = 0;
3309
3310 argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
366de0ce
NS
3311 partial = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1);
3312 gcc_assert (!partial);
3c0fca12
RH
3313
3314 locate_and_pad_parm (Pmode, NULL_TREE,
a4d5044f
CM
3315#ifdef STACK_PARMS_IN_REG_PARM_AREA
3316 1,
3317#else
3318 argvec[count].reg != 0,
3319#endif
e7949876 3320 0, NULL_TREE, &args_size, &argvec[count].locate);
3c0fca12 3321
3c0fca12
RH
3322 if (argvec[count].reg == 0 || argvec[count].partial != 0
3323 || reg_parm_stack_space > 0)
e7949876 3324 args_size.constant += argvec[count].locate.size.constant;
3c0fca12
RH
3325
3326 FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
3327
3328 count++;
3329 }
3330
3331 for (; count < nargs; count++)
3332 {
3333 rtx val = va_arg (p, rtx);
3334 enum machine_mode mode = va_arg (p, enum machine_mode);
3335
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. */
366de0ce
NS
3338 gcc_assert (mode != BLKmode
3339 && (GET_MODE (val) == mode || GET_MODE (val) == VOIDmode));
3c0fca12 3340
3c0fca12 3341 /* Make sure it is a reasonable operand for a move or push insn. */
3c0cb5de 3342 if (!REG_P (val) && !MEM_P (val)
3c0fca12
RH
3343 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
3344 val = force_operand (val, NULL_RTX);
3345
0976078c 3346 if (pass_by_reference (&args_so_far, mode, NULL_TREE, 1))
3c0fca12 3347 {
f474c6f8 3348 rtx slot;
6cdd5672
RH
3349 int must_copy
3350 = !reference_callee_copied (&args_so_far, mode, NULL_TREE, 1);
f474c6f8 3351
a0dc500c
R
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)
3355 {
3356 rtx insns = get_insns ();
3357 end_sequence ();
3358 emit_insn (insns);
3359 }
3360 flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
3361
99a32567
DM
3362 /* If this was a CONST function, it is now PURE since
3363 it now reads memory. */
3364 if (flags & ECF_CONST)
3365 {
3366 flags &= ~ECF_CONST;
3367 flags |= ECF_PURE;
3368 }
3369
9969aaf6 3370 if (GET_MODE (val) == MEM && !must_copy)
f474c6f8 3371 slot = val;
9969aaf6 3372 else
f474c6f8 3373 {
ae2bcd98 3374 slot = assign_temp (lang_hooks.types.type_for_mode (mode, 0),
b0c48229 3375 0, 1, 1);
f474c6f8
AO
3376 emit_move_insn (slot, val);
3377 }
1da68f56 3378
6b5273c3
AO
3379 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
3380 gen_rtx_USE (VOIDmode, slot),
3381 call_fusage);
f474c6f8
AO
3382 if (must_copy)
3383 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
3384 gen_rtx_CLOBBER (VOIDmode,
3385 slot),
3386 call_fusage);
3387
3c0fca12 3388 mode = Pmode;
f474c6f8 3389 val = force_operand (XEXP (slot, 0), NULL_RTX);
3c0fca12 3390 }
3c0fca12
RH
3391
3392 argvec[count].value = val;
3393 argvec[count].mode = mode;
3394
3395 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
3396
3c0fca12
RH
3397 argvec[count].partial
3398 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3c0fca12
RH
3399
3400 locate_and_pad_parm (mode, NULL_TREE,
a4d5044f 3401#ifdef STACK_PARMS_IN_REG_PARM_AREA
f725a3ec 3402 1,
a4d5044f
CM
3403#else
3404 argvec[count].reg != 0,
3405#endif
e7949876
AM
3406 argvec[count].partial,
3407 NULL_TREE, &args_size, &argvec[count].locate);
3c0fca12 3408
366de0ce 3409 gcc_assert (!argvec[count].locate.size.var);
3c0fca12 3410
3c0fca12
RH
3411 if (argvec[count].reg == 0 || argvec[count].partial != 0
3412 || reg_parm_stack_space > 0)
e7949876 3413 args_size.constant += argvec[count].locate.size.constant;
3c0fca12
RH
3414
3415 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3416 }
3c0fca12 3417
3c0fca12
RH
3418 /* If this machine requires an external definition for library
3419 functions, write one out. */
3420 assemble_external_libcall (fun);
3421
3422 original_args_size = args_size;
1503a7ec
JH
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);
3c0fca12
RH
3429
3430 args_size.constant = MAX (args_size.constant,
3431 reg_parm_stack_space);
3432
3433#ifndef OUTGOING_REG_PARM_STACK_SPACE
3434 args_size.constant -= reg_parm_stack_space;
3435#endif
3436
3437 if (args_size.constant > current_function_outgoing_args_size)
3438 current_function_outgoing_args_size = args_size.constant;
3439
f73ad30e
JH
3440 if (ACCUMULATE_OUTGOING_ARGS)
3441 {
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.
3c0fca12 3446
f73ad30e
JH
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.
3c0fca12 3450
f73ad30e
JH
3451 Another approach might be to try to reorder the argument
3452 evaluations to avoid this conflicting stack usage. */
3c0fca12 3453
f73ad30e 3454 needed = args_size.constant;
3c0fca12
RH
3455
3456#ifndef OUTGOING_REG_PARM_STACK_SPACE
f73ad30e
JH
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;
3c0fca12
RH
3461#endif
3462
3463#ifdef ARGS_GROW_DOWNWARD
f73ad30e
JH
3464 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3465 needed + 1);
3c0fca12 3466#else
f73ad30e
JH
3467 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3468 needed);
3c0fca12 3469#endif
703ad42b 3470 stack_usage_map = alloca (highest_outgoing_arg_in_use);
3c0fca12 3471
f73ad30e 3472 if (initial_highest_arg_in_use)
2e09e75a
JM
3473 memcpy (stack_usage_map, initial_stack_usage_map,
3474 initial_highest_arg_in_use);
3c0fca12 3475
f73ad30e 3476 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
961192e1 3477 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
f73ad30e
JH
3478 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3479 needed = 0;
3c0fca12 3480
c39ada04
DD
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. */
3c0fca12 3485
c39ada04
DD
3486 if (virtuals_instantiated)
3487 argblock = plus_constant (stack_pointer_rtx, STACK_POINTER_OFFSET);
3488 else
3489 argblock = virtual_outgoing_args_rtx;
f73ad30e
JH
3490 }
3491 else
3492 {
3493 if (!PUSH_ARGS)
3494 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3495 }
3c0fca12 3496
3c0fca12
RH
3497 /* If we push args individually in reverse order, perform stack alignment
3498 before the first push (the last arg). */
f73ad30e 3499 if (argblock == 0 && PUSH_ARGS_REVERSED)
3c0fca12
RH
3500 anti_adjust_stack (GEN_INT (args_size.constant
3501 - original_args_size.constant));
3c0fca12 3502
f73ad30e
JH
3503 if (PUSH_ARGS_REVERSED)
3504 {
3505 inc = -1;
3506 argnum = nargs - 1;
3507 }
3508 else
3509 {
3510 inc = 1;
3511 argnum = 0;
3512 }
3c0fca12 3513
f73ad30e
JH
3514#ifdef REG_PARM_STACK_SPACE
3515 if (ACCUMULATE_OUTGOING_ARGS)
3516 {
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
b820d2b8
AM
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);
3c0fca12
RH
3522 }
3523#endif
f725a3ec 3524
3c0fca12
RH
3525 /* Push the args that need to be pushed. */
3526
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)
3530 {
b3694847
SS
3531 enum machine_mode mode = argvec[argnum].mode;
3532 rtx val = argvec[argnum].value;
3c0fca12
RH
3533 rtx reg = argvec[argnum].reg;
3534 int partial = argvec[argnum].partial;
f73ad30e 3535 int lower_bound = 0, upper_bound = 0, i;
3c0fca12
RH
3536
3537 if (! (reg != 0 && partial == 0))
3538 {
f73ad30e
JH
3539 if (ACCUMULATE_OUTGOING_ARGS)
3540 {
f8a097cd
JH
3541 /* If this is being stored into a pre-allocated, fixed-size,
3542 stack area, save any previous data at that location. */
3c0fca12
RH
3543
3544#ifdef ARGS_GROW_DOWNWARD
f73ad30e
JH
3545 /* stack_slot is negative, but we want to index stack_usage_map
3546 with positive values. */
e7949876
AM
3547 upper_bound = -argvec[argnum].locate.offset.constant + 1;
3548 lower_bound = upper_bound - argvec[argnum].locate.size.constant;
3c0fca12 3549#else
e7949876
AM
3550 lower_bound = argvec[argnum].locate.offset.constant;
3551 upper_bound = lower_bound + argvec[argnum].locate.size.constant;
3c0fca12
RH
3552#endif
3553
546ff777
AM
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++;
3c0fca12 3561
546ff777 3562 if (i < upper_bound)
f73ad30e 3563 {
e7949876
AM
3564 /* We need to make a save area. */
3565 unsigned int size
3566 = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
f73ad30e 3567 enum machine_mode save_mode
e7949876
AM
3568 = mode_for_size (size, MODE_INT, 1);
3569 rtx adr
3570 = plus_constant (argblock,
3571 argvec[argnum].locate.offset.constant);
f73ad30e 3572 rtx stack_area
e7949876 3573 = gen_rtx_MEM (save_mode, memory_address (save_mode, adr));
f73ad30e 3574
9778f2f8
JH
3575 if (save_mode == BLKmode)
3576 {
3577 argvec[argnum].save_area
3578 = assign_stack_temp (BLKmode,
3579 argvec[argnum].locate.size.constant,
3580 0);
3581
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);
3586 }
3587 else
3588 {
3589 argvec[argnum].save_area = gen_reg_rtx (save_mode);
3590
3591 emit_move_insn (argvec[argnum].save_area, stack_area);
3592 }
f73ad30e 3593 }
3c0fca12 3594 }
19caa751 3595
44bb111a
RH
3596 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, PARM_BOUNDARY,
3597 partial, reg, 0, argblock,
e7949876
AM
3598 GEN_INT (argvec[argnum].locate.offset.constant),
3599 reg_parm_stack_space,
3600 ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad));
3c0fca12 3601
3c0fca12 3602 /* Now mark the segment we just used. */
f73ad30e
JH
3603 if (ACCUMULATE_OUTGOING_ARGS)
3604 for (i = lower_bound; i < upper_bound; i++)
3605 stack_usage_map[i] = 1;
3c0fca12
RH
3606
3607 NO_DEFER_POP;
3608 }
3609 }
3610
3c0fca12
RH
3611 /* If we pushed args in forward order, perform stack alignment
3612 after pushing the last arg. */
f73ad30e 3613 if (argblock == 0 && !PUSH_ARGS_REVERSED)
3c0fca12
RH
3614 anti_adjust_stack (GEN_INT (args_size.constant
3615 - original_args_size.constant));
3c0fca12 3616
f73ad30e
JH
3617 if (PUSH_ARGS_REVERSED)
3618 argnum = nargs - 1;
3619 else
3620 argnum = 0;
3c0fca12 3621
6de9cd9a 3622 fun = prepare_call_address (fun, NULL, &call_fusage, 0, 0);
3c0fca12
RH
3623
3624 /* Now load any reg parms into their regs. */
3625
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)
3629 {
ff15c351 3630 enum machine_mode mode = argvec[argnum].mode;
b3694847 3631 rtx val = argvec[argnum].value;
3c0fca12
RH
3632 rtx reg = argvec[argnum].reg;
3633 int partial = argvec[argnum].partial;
3634
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)
ff15c351 3638 emit_group_load (reg, val, NULL_TREE, GET_MODE_SIZE (mode));
3c0fca12
RH
3639 else if (reg != 0 && partial == 0)
3640 emit_move_insn (reg, val);
3641
3642 NO_DEFER_POP;
3643 }
3644
3c0fca12
RH
3645 /* Any regs containing parms remain in use through the call. */
3646 for (count = 0; count < nargs; count++)
3647 {
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);
3653 }
3654
3655 /* Pass the function the address in which to return a structure value. */
61f71b34 3656 if (mem_value != 0 && struct_value != 0 && ! pcc_struct_value)
3c0fca12 3657 {
61f71b34 3658 emit_move_insn (struct_value,
3c0fca12
RH
3659 force_reg (Pmode,
3660 force_operand (XEXP (mem_value, 0),
3661 NULL_RTX)));
f8cfc6aa 3662 if (REG_P (struct_value))
61f71b34 3663 use_reg (&call_fusage, struct_value);
3c0fca12
RH
3664 }
3665
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;
5591ee6f
JH
3669 valreg = (mem_value == 0 && outmode != VOIDmode
3670 ? hard_libcall_value (outmode) : NULL_RTX);
3c0fca12 3671
ce48579b 3672 /* Stack must be properly aligned now. */
366de0ce
NS
3673 gcc_assert (!(stack_pointer_delta
3674 & (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)));
ebcd0b57 3675
695ee791
RH
3676 before_call = get_last_insn ();
3677
3c0fca12
RH
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. */
de76b467
JH
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. */
3c0fca12 3684
6de9cd9a 3685 emit_call_1 (fun, NULL,
f725a3ec 3686 get_identifier (XSTR (orgfun, 0)),
b0c48229 3687 build_function_type (tfom, NULL_TREE),
f725a3ec 3688 original_args_size.constant, args_size.constant,
3c0fca12
RH
3689 struct_value_size,
3690 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
5591ee6f 3691 valreg,
fa5322fa 3692 old_inhibit_defer_pop + 1, call_fusage, flags, & args_so_far);
3c0fca12 3693
695ee791
RH
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. */
3697
570a98eb 3698 if (flags & (ECF_NORETURN | ECF_LONGJMP))
695ee791 3699 {
570a98eb 3700 /* The barrier note must be emitted
695ee791
RH
3701 immediately after the CALL_INSN. Some ports emit more than
3702 just a CALL_INSN above, so we must search for it here. */
3703
3704 rtx last = get_last_insn ();
4b4bf941 3705 while (!CALL_P (last))
695ee791
RH
3706 {
3707 last = PREV_INSN (last);
3708 /* There was no CALL_INSN? */
366de0ce 3709 gcc_assert (last != before_call);
695ee791
RH
3710 }
3711
570a98eb 3712 emit_barrier_after (last);
695ee791
RH
3713 }
3714
3c0fca12
RH
3715 /* Now restore inhibit_defer_pop to its actual original value. */
3716 OK_DEFER_POP;
3717
ebb1b59a
BS
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. */
53d4257f 3722 if (flags & ECF_LIBCALL_BLOCK)
ebb1b59a 3723 {
ebb1b59a 3724 rtx insns;
ebb1b59a 3725
c3297561 3726 if (valreg == 0)
e4abc3d5
RH
3727 {
3728 insns = get_insns ();
3729 end_sequence ();
2f937369 3730 emit_insn (insns);
e4abc3d5
RH
3731 }
3732 else
3733 {
3734 rtx note = 0;
c3297561 3735 rtx temp;
e4abc3d5 3736 int i;
ebb1b59a 3737
c3297561
AO
3738 if (GET_CODE (valreg) == PARALLEL)
3739 {
3740 temp = gen_reg_rtx (outmode);
7ae4ad28 3741 emit_group_store (temp, valreg, NULL_TREE,
643642eb 3742 GET_MODE_SIZE (outmode));
c3297561
AO
3743 valreg = temp;
3744 }
3745
3746 temp = gen_reg_rtx (GET_MODE (valreg));
3747
e4abc3d5
RH
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);
ebb1b59a 3753
e4abc3d5
RH
3754 insns = get_insns ();
3755 end_sequence ();
ebb1b59a 3756
e4abc3d5
RH
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);
3763
3764 emit_libcall_block (insns, temp, valreg, note);
ebb1b59a 3765
e4abc3d5
RH
3766 valreg = temp;
3767 }
ebb1b59a 3768 }
3c0fca12
RH
3769 pop_temp_slots ();
3770
3771 /* Copy the value to the right place. */
de76b467 3772 if (outmode != VOIDmode && retval)
3c0fca12
RH
3773 {
3774 if (mem_value)
3775 {
3776 if (value == 0)
3777 value = mem_value;
3778 if (value != mem_value)
3779 emit_move_insn (value, mem_value);
3780 }
c3297561
AO
3781 else if (GET_CODE (valreg) == PARALLEL)
3782 {
3783 if (value == 0)
3784 value = gen_reg_rtx (outmode);
643642eb 3785 emit_group_store (value, valreg, NULL_TREE, GET_MODE_SIZE (outmode));
c3297561 3786 }
3c0fca12 3787 else if (value != 0)
d57551c7 3788 emit_move_insn (value, valreg);
3c0fca12 3789 else
d57551c7 3790 value = valreg;
3c0fca12
RH
3791 }
3792
f73ad30e 3793 if (ACCUMULATE_OUTGOING_ARGS)
3c0fca12 3794 {
f73ad30e
JH
3795#ifdef REG_PARM_STACK_SPACE
3796 if (save_area)
b820d2b8
AM
3797 restore_fixed_argument_area (save_area, argblock,
3798 high_to_save, low_to_save);
3c0fca12 3799#endif
f725a3ec 3800
f73ad30e
JH
3801 /* If we saved any argument areas, restore them. */
3802 for (count = 0; count < nargs; count++)
3803 if (argvec[count].save_area)
3804 {
3805 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
e7949876
AM
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));
f73ad30e 3810
9778f2f8
JH
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);
f73ad30e 3818 }
3c0fca12 3819
f73ad30e
JH
3820 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3821 stack_usage_map = initial_stack_usage_map;
3822 }
43bc5f13 3823
de76b467
JH
3824 return value;
3825
3826}
3827\f
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.
de76b467 3833
1258ee80
JJ
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. */
de76b467
JH
3840
3841void
e34d07f2
KG
3842emit_library_call (rtx orgfun, enum libcall_type fn_type,
3843 enum machine_mode outmode, int nargs, ...)
de76b467 3844{
e34d07f2 3845 va_list p;
d329e058 3846
e34d07f2 3847 va_start (p, nargs);
2a8f6b90 3848 emit_library_call_value_1 (0, orgfun, NULL_RTX, fn_type, outmode, nargs, p);
e34d07f2 3849 va_end (p);
de76b467
JH
3850}
3851\f
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.
3856
3857 This function returns an rtx for where the value is to be found.
3858 If VALUE is nonzero, VALUE is returned. */
3859
3860rtx
e34d07f2
KG
3861emit_library_call_value (rtx orgfun, rtx value,
3862 enum libcall_type fn_type,
3863 enum machine_mode outmode, int nargs, ...)
de76b467 3864{
6268b922 3865 rtx result;
e34d07f2 3866 va_list p;
d329e058 3867
e34d07f2 3868 va_start (p, nargs);
6268b922
KG
3869 result = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode,
3870 nargs, p);
e34d07f2 3871 va_end (p);
de76b467 3872
6268b922 3873 return result;
322e3e34
RK
3874}
3875\f
51bbfa0c
RS
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.
3879
3880 ARGBLOCK is the address of the stack-block for all the arguments,
d45cf215 3881 or 0 on a machine where arguments are pushed individually.
51bbfa0c
RS
3882
3883 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
f725a3ec 3884 so must be careful about how the stack is used.
51bbfa0c
RS
3885
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.
3889
4c6b3b2a 3890 FNDECL is the declaration of the function we are calling.
f725a3ec 3891
da7d8304 3892 Return nonzero if this arg should cause sibcall failure,
4c6b3b2a 3893 zero otherwise. */
51bbfa0c 3894
4c6b3b2a 3895static int
d329e058
AJ
3896store_one_arg (struct arg_data *arg, rtx argblock, int flags,
3897 int variable_size ATTRIBUTE_UNUSED, int reg_parm_stack_space)
51bbfa0c 3898{
b3694847 3899 tree pval = arg->tree_value;
51bbfa0c
RS
3900 rtx reg = 0;
3901 int partial = 0;
3902 int used = 0;
6a651371 3903 int i, lower_bound = 0, upper_bound = 0;
4c6b3b2a 3904 int sibcall_failure = 0;
51bbfa0c
RS
3905
3906 if (TREE_CODE (pval) == ERROR_MARK)
4c6b3b2a 3907 return 1;
51bbfa0c 3908
cc79451b
RK
3909 /* Push a new temporary level for any temporaries we make for
3910 this argument. */
3911 push_temp_slots ();
3912
f8a097cd 3913 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL))
51bbfa0c 3914 {
f73ad30e
JH
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)
3918 {
51bbfa0c 3919#ifdef ARGS_GROW_DOWNWARD
f73ad30e
JH
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;
51bbfa0c 3926
e7949876 3927 lower_bound = upper_bound - arg->locate.size.constant;
51bbfa0c 3928#else
f73ad30e
JH
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;
51bbfa0c 3933
e7949876 3934 upper_bound = lower_bound + arg->locate.size.constant;
51bbfa0c
RS
3935#endif
3936
546ff777
AM
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++;
51bbfa0c 3944
546ff777 3945 if (i < upper_bound)
51bbfa0c 3946 {
e7949876
AM
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);
f73ad30e
JH
3952
3953 if (save_mode == BLKmode)
3954 {
1da68f56
RK
3955 tree ot = TREE_TYPE (arg->tree_value);
3956 tree nt = build_qualified_type (ot, (TYPE_QUALS (ot)
3957 | TYPE_QUAL_CONST));
3958
3959 arg->save_area = assign_temp (nt, 0, 1, 1);
f73ad30e
JH
3960 preserve_temp_slots (arg->save_area);
3961 emit_block_move (validize_mem (arg->save_area), stack_area,
44bb111a
RH
3962 expr_size (arg->tree_value),
3963 BLOCK_OP_CALL_PARM);
f73ad30e
JH
3964 }
3965 else
3966 {
3967 arg->save_area = gen_reg_rtx (save_mode);
3968 emit_move_insn (arg->save_area, stack_area);
3969 }
51bbfa0c
RS
3970 }
3971 }
3972 }
b564df06 3973
51bbfa0c
RS
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)
aa7634dd
DM
3977 {
3978 if (flags & ECF_SIBCALL)
3979 reg = arg->tail_call_reg;
3980 else
3981 reg = arg->reg;
3982 partial = arg->partial;
3983 }
51bbfa0c 3984
366de0ce
NS
3985 /* Being passed entirely in a register. We shouldn't be called in
3986 this case. */
3987 gcc_assert (reg == 0 || partial != 0);
3988
4ab56118
RK
3989 /* If this arg needs special alignment, don't load the registers
3990 here. */
3991 if (arg->n_aligned_regs != 0)
3992 reg = 0;
f725a3ec 3993
4ab56118 3994 /* If this is being passed partially in a register, we can't evaluate
51bbfa0c
RS
3995 it directly into its stack slot. Otherwise, we can. */
3996 if (arg->value == 0)
d64f5a78 3997 {
d64f5a78
RS
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.
4002
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.
4006
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.
4012
4013 Note that it is always safe to set stack_arg_under_construction,
4014 but this generates suboptimal code if set when not needed. */
4015
4016 if (arg->pass_on_stack)
4017 stack_arg_under_construction++;
f73ad30e 4018
3a08477a
RK
4019 arg->value = expand_expr (pval,
4020 (partial
4021 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
4022 ? NULL_RTX : arg->stack,
8403445a 4023 VOIDmode, EXPAND_STACK_PARM);
1efe6448
RK
4024
4025 /* If we are promoting object (or for any other reason) the mode
4026 doesn't agree, convert the mode. */
4027
7373d92d
RK
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);
1efe6448 4031
d64f5a78
RS
4032 if (arg->pass_on_stack)
4033 stack_arg_under_construction--;
d64f5a78 4034 }
51bbfa0c
RS
4035
4036 /* Don't allow anything left on stack from computation
4037 of argument to alloca. */
f8a097cd 4038 if (flags & ECF_MAY_BE_ALLOCA)
51bbfa0c
RS
4039 do_pending_stack_adjust ();
4040
4041 if (arg->value == arg->stack)
37a08a29
RK
4042 /* If the value is already in the stack slot, we are done. */
4043 ;
1efe6448 4044 else if (arg->mode != BLKmode)
51bbfa0c 4045 {
b3694847 4046 int size;
51bbfa0c
RS
4047
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.)
f725a3ec 4051
51bbfa0c
RS
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. */
4057
1efe6448 4058 size = GET_MODE_SIZE (arg->mode);
51bbfa0c
RS
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;
4066
4067 /* Compute how much space the argument should get:
4068 round up to a multiple of the alignment for arguments. */
1efe6448 4069 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
51bbfa0c
RS
4070 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4071 / (PARM_BOUNDARY / BITS_PER_UNIT))
4072 * (PARM_BOUNDARY / BITS_PER_UNIT));
4073
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. */
d329e058 4076 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
44bb111a 4077 PARM_BOUNDARY, partial, reg, used - size, argblock,
e7949876
AM
4078 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4079 ARGS_SIZE_RTX (arg->locate.alignment_pad));
841404cd
AO
4080
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;
51bbfa0c
RS
4085 }
4086 else
4087 {
4088 /* BLKmode, at least partly to be pushed. */
4089
1b1f20ca 4090 unsigned int parm_align;
b3694847 4091 int excess;
51bbfa0c
RS
4092 rtx size_rtx;
4093
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. */
4097
4098 /* Round its size up to a multiple
4099 of the allocation unit for arguments. */
4100
e7949876 4101 if (arg->locate.size.var != 0)
51bbfa0c
RS
4102 {
4103 excess = 0;
e7949876 4104 size_rtx = ARGS_SIZE_RTX (arg->locate.size);
51bbfa0c
RS
4105 }
4106 else
4107 {
51bbfa0c
RS
4108 /* PUSH_ROUNDING has no effect on us, because
4109 emit_push_insn for BLKmode is careful to avoid it. */
531547e9
FJ
4110 if (reg && GET_CODE (reg) == PARALLEL)
4111 {
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)));
7ae4ad28 4117 }
531547e9
FJ
4118 else
4119 excess = (arg->locate.size.constant
4120 - int_size_in_bytes (TREE_TYPE (pval))
4121 + partial * UNITS_PER_WORD);
db4c55f6
JM
4122 size_rtx = expand_expr (size_in_bytes (TREE_TYPE (pval)),
4123 NULL_RTX, TYPE_MODE (sizetype), 0);
51bbfa0c
RS
4124 }
4125
1b1f20ca
RH
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)));
4129
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)
4133 {
e7949876 4134 if (arg->locate.size.var)
1b1f20ca
RH
4135 parm_align = BITS_PER_UNIT;
4136 else if (excess)
4137 {
97d05bfd 4138 unsigned int excess_align = (excess & -excess) * BITS_PER_UNIT;
1b1f20ca
RH
4139 parm_align = MIN (parm_align, excess_align);
4140 }
4141 }
4142
3c0cb5de 4143 if ((flags & ECF_SIBCALL) && MEM_P (arg->value))
4c6b3b2a
JJ
4144 {
4145 /* emit_push_insn might not work properly if arg->value and
e7949876 4146 argblock + arg->locate.offset areas overlap. */
4c6b3b2a
JJ
4147 rtx x = arg->value;
4148 int i = 0;
4149
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))
4155 {
4156 if (XEXP (x, 0) != current_function_internal_arg_pointer)
4157 i = INTVAL (XEXP (XEXP (x, 0), 1));
4158
e0a21ab9 4159 /* expand_call should ensure this. */
366de0ce
NS
4160 gcc_assert (!arg->locate.offset.var
4161 && GET_CODE (size_rtx) == CONST_INT);
4c6b3b2a 4162
e7949876 4163 if (arg->locate.offset.constant > i)
4c6b3b2a 4164 {
e7949876 4165 if (arg->locate.offset.constant < i + INTVAL (size_rtx))
4c6b3b2a
JJ
4166 sibcall_failure = 1;
4167 }
e7949876 4168 else if (arg->locate.offset.constant < i)
4c6b3b2a 4169 {
e7949876 4170 if (i < arg->locate.offset.constant + INTVAL (size_rtx))
4c6b3b2a
JJ
4171 sibcall_failure = 1;
4172 }
4173 }
4174 }
4175
1efe6448 4176 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
1b1f20ca 4177 parm_align, partial, reg, excess, argblock,
e7949876
AM
4178 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4179 ARGS_SIZE_RTX (arg->locate.alignment_pad));
51bbfa0c 4180
841404cd
AO
4181 /* Unless this is a partially-in-register argument, the argument is now
4182 in the stack.
51bbfa0c 4183
841404cd
AO
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;
4191 }
8df3dbb7
RH
4192
4193 if (arg->reg && GET_CODE (arg->reg) == PARALLEL)
4194 {
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));
4199 }
51bbfa0c 4200
8403445a
AM
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;
4206
51bbfa0c
RS
4207 /* Once we have pushed something, pops can't safely
4208 be deferred during the rest of the arguments. */
4209 NO_DEFER_POP;
4210
db907e7b
RK
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);
51bbfa0c 4215 free_temp_slots ();
cc79451b 4216 pop_temp_slots ();
4c6b3b2a
JJ
4217
4218 return sibcall_failure;
51bbfa0c 4219}
a4b1b92a 4220
fe984136 4221/* Nonzero if we do not know how to pass TYPE solely in registers. */
a4b1b92a 4222
fe984136
RH
4223bool
4224must_pass_in_stack_var_size (enum machine_mode mode ATTRIBUTE_UNUSED,
4225 tree type)
4226{
4227 if (!type)
4228 return false;
4229
4230 /* If the type has variable size... */
4231 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4232 return true;
a4b1b92a 4233
fe984136
RH
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;
4238
4239 return false;
4240}
a4b1b92a 4241
7ae4ad28 4242/* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
fe984136
RH
4243 takes trailing padding of a structure into account. */
4244/* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
a4b1b92a
RH
4245
4246bool
fe984136 4247must_pass_in_stack_var_size_or_pad (enum machine_mode mode, tree type)
a4b1b92a
RH
4248{
4249 if (!type)
40cdfd5a 4250 return false;
a4b1b92a
RH
4251
4252 /* If the type has variable size... */
4253 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4254 return true;
4255
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;
4260
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;
4268
4269 return false;
4270}
This page took 2.076801 seconds and 5 git commands to generate.