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