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