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