Fixed rare threading problem
[official-gcc.git] / gcc / calls.c
blob700564a33dbcb49dd775e78fee514dbaba26b072
1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998
3 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "flags.h"
29 #include "expr.h"
30 #include "libfuncs.h"
31 #include "function.h"
32 #include "regs.h"
33 #include "toplev.h"
34 #include "output.h"
35 #include "tm_p.h"
36 #include "timevar.h"
37 #include "sbitmap.h"
38 #include "langhooks.h"
39 #include "target.h"
40 #include "cgraph.h"
41 #include "except.h"
43 #ifndef STACK_POINTER_OFFSET
44 #define STACK_POINTER_OFFSET 0
45 #endif
47 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
48 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
50 /* Data structure and subroutines used within expand_call. */
52 struct arg_data
54 /* Tree node for this argument. */
55 tree tree_value;
56 /* Mode for value; TYPE_MODE unless promoted. */
57 enum machine_mode mode;
58 /* Current RTL value for argument, or 0 if it isn't precomputed. */
59 rtx value;
60 /* Initially-compute RTL value for argument; only for const functions. */
61 rtx initial_value;
62 /* Register to pass this argument in, 0 if passed on stack, or an
63 PARALLEL if the arg is to be copied into multiple non-contiguous
64 registers. */
65 rtx reg;
66 /* Register to pass this argument in when generating tail call sequence.
67 This is not the same register as for normal calls on machines with
68 register windows. */
69 rtx tail_call_reg;
70 /* If REG was promoted from the actual mode of the argument expression,
71 indicates whether the promotion is sign- or zero-extended. */
72 int unsignedp;
73 /* Number of registers to use. 0 means put the whole arg in registers.
74 Also 0 if not passed in registers. */
75 int partial;
76 /* Nonzero if argument must be passed on stack.
77 Note that some arguments may be passed on the stack
78 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
79 pass_on_stack identifies arguments that *cannot* go in registers. */
80 int pass_on_stack;
81 /* Some fields packaged up for locate_and_pad_parm. */
82 struct locate_and_pad_arg_data locate;
83 /* Location on the stack at which parameter should be stored. The store
84 has already been done if STACK == VALUE. */
85 rtx stack;
86 /* Location on the stack of the start of this argument slot. This can
87 differ from STACK if this arg pads downward. This location is known
88 to be aligned to FUNCTION_ARG_BOUNDARY. */
89 rtx stack_slot;
90 /* Place that this stack area has been saved, if needed. */
91 rtx save_area;
92 /* If an argument's alignment does not permit direct copying into registers,
93 copy in smaller-sized pieces into pseudos. These are stored in a
94 block pointed to by this field. The next field says how many
95 word-sized pseudos we made. */
96 rtx *aligned_regs;
97 int n_aligned_regs;
100 /* A vector of one char per byte of stack space. A byte if nonzero if
101 the corresponding stack location has been used.
102 This vector is used to prevent a function call within an argument from
103 clobbering any stack already set up. */
104 static char *stack_usage_map;
106 /* Size of STACK_USAGE_MAP. */
107 static int highest_outgoing_arg_in_use;
109 /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
110 stack location's tail call argument has been already stored into the stack.
111 This bitmap is used to prevent sibling call optimization if function tries
112 to use parent's incoming argument slots when they have been already
113 overwritten with tail call arguments. */
114 static sbitmap stored_args_map;
116 /* stack_arg_under_construction is nonzero when an argument may be
117 initialized with a constructor call (including a C function that
118 returns a BLKmode struct) and expand_call must take special action
119 to make sure the object being constructed does not overlap the
120 argument list for the constructor call. */
121 int stack_arg_under_construction;
123 static int calls_function (tree, int);
124 static int calls_function_1 (tree, int);
126 static void emit_call_1 (rtx, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT,
127 HOST_WIDE_INT, rtx, rtx, int, rtx, int,
128 CUMULATIVE_ARGS *);
129 static void precompute_register_parameters (int, struct arg_data *, int *);
130 static int store_one_arg (struct arg_data *, rtx, int, int, int);
131 static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
132 static int finalize_must_preallocate (int, int, struct arg_data *,
133 struct args_size *);
134 static void precompute_arguments (int, int, struct arg_data *);
135 static int compute_argument_block_size (int, struct args_size *, int);
136 static void initialize_argument_information (int, struct arg_data *,
137 struct args_size *, int, tree,
138 tree, CUMULATIVE_ARGS *, int,
139 rtx *, int *, int *, int *);
140 static void compute_argument_addresses (struct arg_data *, rtx, int);
141 static rtx rtx_for_function_call (tree, tree);
142 static void load_register_parameters (struct arg_data *, int, rtx *, int,
143 int, int *);
144 static rtx emit_library_call_value_1 (int, rtx, rtx, enum libcall_type,
145 enum machine_mode, int, va_list);
146 static int special_function_p (tree, int);
147 static rtx try_to_integrate (tree, tree, rtx, int, tree, rtx);
148 static int check_sibcall_argument_overlap_1 (rtx);
149 static int check_sibcall_argument_overlap (rtx, struct arg_data *, int);
151 static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
152 int);
153 static tree fix_unsafe_tree (tree);
155 #ifdef REG_PARM_STACK_SPACE
156 static rtx save_fixed_argument_area (int, rtx, int *, int *);
157 static void restore_fixed_argument_area (rtx, rtx, int, int);
158 #endif
160 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
161 `alloca'.
163 If WHICH is 0, return 1 if EXP contains a call to any function.
164 Actually, we only need return 1 if evaluating EXP would require pushing
165 arguments on the stack, but that is too difficult to compute, so we just
166 assume any function call might require the stack. */
168 static tree calls_function_save_exprs;
170 static int
171 calls_function (tree exp, int which)
173 int val;
175 calls_function_save_exprs = 0;
176 val = calls_function_1 (exp, which);
177 calls_function_save_exprs = 0;
178 return val;
181 /* Recursive function to do the work of above function. */
183 static int
184 calls_function_1 (tree exp, int which)
186 int i;
187 enum tree_code code = TREE_CODE (exp);
188 int class = TREE_CODE_CLASS (code);
189 int length = first_rtl_op (code);
191 /* If this code is language-specific, we don't know what it will do. */
192 if ((int) code >= NUM_TREE_CODES)
193 return 1;
195 switch (code)
197 case CALL_EXPR:
198 if (which == 0)
199 return 1;
200 else if ((TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))
201 == FUNCTION_TYPE)
202 && (TYPE_RETURNS_STACK_DEPRESSED
203 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))))
204 return 1;
205 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
206 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
207 == FUNCTION_DECL)
208 && (special_function_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
210 & ECF_MAY_BE_ALLOCA))
211 return 1;
213 break;
215 case CONSTRUCTOR:
217 tree tem;
219 for (tem = CONSTRUCTOR_ELTS (exp); tem != 0; tem = TREE_CHAIN (tem))
220 if (calls_function_1 (TREE_VALUE (tem), which))
221 return 1;
224 return 0;
226 case SAVE_EXPR:
227 if (SAVE_EXPR_RTL (exp) != 0)
228 return 0;
229 if (value_member (exp, calls_function_save_exprs))
230 return 0;
231 calls_function_save_exprs = tree_cons (NULL_TREE, exp,
232 calls_function_save_exprs);
233 return (TREE_OPERAND (exp, 0) != 0
234 && calls_function_1 (TREE_OPERAND (exp, 0), which));
236 case BLOCK:
238 tree local;
239 tree subblock;
241 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
242 if (DECL_INITIAL (local) != 0
243 && calls_function_1 (DECL_INITIAL (local), which))
244 return 1;
246 for (subblock = BLOCK_SUBBLOCKS (exp);
247 subblock;
248 subblock = TREE_CHAIN (subblock))
249 if (calls_function_1 (subblock, which))
250 return 1;
252 return 0;
254 case TREE_LIST:
255 for (; exp != 0; exp = TREE_CHAIN (exp))
256 if (calls_function_1 (TREE_VALUE (exp), which))
257 return 1;
258 return 0;
260 default:
261 break;
264 /* Only expressions, references, and blocks can contain calls. */
265 if (! IS_EXPR_CODE_CLASS (class) && class != 'r' && class != 'b')
266 return 0;
268 for (i = 0; i < length; i++)
269 if (TREE_OPERAND (exp, i) != 0
270 && calls_function_1 (TREE_OPERAND (exp, i), which))
271 return 1;
273 return 0;
276 /* Force FUNEXP into a form suitable for the address of a CALL,
277 and return that as an rtx. Also load the static chain register
278 if FNDECL is a nested function.
280 CALL_FUSAGE points to a variable holding the prospective
281 CALL_INSN_FUNCTION_USAGE information. */
284 prepare_call_address (rtx funexp, tree fndecl, rtx *call_fusage,
285 int reg_parm_seen, int sibcallp)
287 rtx static_chain_value = 0;
289 funexp = protect_from_queue (funexp, 0);
291 if (fndecl != 0)
292 /* Get possible static chain value for nested function in C. */
293 static_chain_value = lookup_static_chain (fndecl);
295 /* Make a valid memory address and copy constants thru pseudo-regs,
296 but not for a constant address if -fno-function-cse. */
297 if (GET_CODE (funexp) != SYMBOL_REF)
298 /* If we are using registers for parameters, force the
299 function address into a register now. */
300 funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
301 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
302 : memory_address (FUNCTION_MODE, funexp));
303 else if (! sibcallp)
305 #ifndef NO_FUNCTION_CSE
306 if (optimize && ! flag_no_function_cse)
307 #ifdef NO_RECURSIVE_FUNCTION_CSE
308 if (fndecl != current_function_decl)
309 #endif
310 funexp = force_reg (Pmode, funexp);
311 #endif
314 if (static_chain_value != 0)
316 emit_move_insn (static_chain_rtx, static_chain_value);
318 if (GET_CODE (static_chain_rtx) == REG)
319 use_reg (call_fusage, static_chain_rtx);
322 return funexp;
325 /* Generate instructions to call function FUNEXP,
326 and optionally pop the results.
327 The CALL_INSN is the first insn generated.
329 FNDECL is the declaration node of the function. This is given to the
330 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
332 FUNTYPE is the data type of the function. This is given to the macro
333 RETURN_POPS_ARGS to determine whether this function pops its own args.
334 We used to allow an identifier for library functions, but that doesn't
335 work when the return type is an aggregate type and the calling convention
336 says that the pointer to this aggregate is to be popped by the callee.
338 STACK_SIZE is the number of bytes of arguments on the stack,
339 ROUNDED_STACK_SIZE is that number rounded up to
340 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
341 both to put into the call insn and to generate explicit popping
342 code if necessary.
344 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
345 It is zero if this call doesn't want a structure value.
347 NEXT_ARG_REG is the rtx that results from executing
348 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
349 just after all the args have had their registers assigned.
350 This could be whatever you like, but normally it is the first
351 arg-register beyond those used for args in this call,
352 or 0 if all the arg-registers are used in this call.
353 It is passed on to `gen_call' so you can put this info in the call insn.
355 VALREG is a hard register in which a value is returned,
356 or 0 if the call does not return a value.
358 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
359 the args to this call were processed.
360 We restore `inhibit_defer_pop' to that value.
362 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
363 denote registers used by the called function. */
365 static void
366 emit_call_1 (rtx funexp, tree fndecl ATTRIBUTE_UNUSED, tree funtype ATTRIBUTE_UNUSED,
367 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED,
368 HOST_WIDE_INT rounded_stack_size,
369 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED,
370 rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg,
371 int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags,
372 CUMULATIVE_ARGS *args_so_far ATTRIBUTE_UNUSED)
374 rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
375 rtx call_insn;
376 int already_popped = 0;
377 HOST_WIDE_INT n_popped = RETURN_POPS_ARGS (fndecl, funtype, stack_size);
378 #if defined (HAVE_call) && defined (HAVE_call_value)
379 rtx struct_value_size_rtx;
380 struct_value_size_rtx = GEN_INT (struct_value_size);
381 #endif
383 #ifdef CALL_POPS_ARGS
384 n_popped += CALL_POPS_ARGS (* args_so_far);
385 #endif
387 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
388 and we don't want to load it into a register as an optimization,
389 because prepare_call_address already did it if it should be done. */
390 if (GET_CODE (funexp) != SYMBOL_REF)
391 funexp = memory_address (FUNCTION_MODE, funexp);
393 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
394 if ((ecf_flags & ECF_SIBCALL)
395 && HAVE_sibcall_pop && HAVE_sibcall_value_pop
396 && (n_popped > 0 || stack_size == 0))
398 rtx n_pop = GEN_INT (n_popped);
399 rtx pat;
401 /* If this subroutine pops its own args, record that in the call insn
402 if possible, for the sake of frame pointer elimination. */
404 if (valreg)
405 pat = GEN_SIBCALL_VALUE_POP (valreg,
406 gen_rtx_MEM (FUNCTION_MODE, funexp),
407 rounded_stack_size_rtx, next_arg_reg,
408 n_pop);
409 else
410 pat = GEN_SIBCALL_POP (gen_rtx_MEM (FUNCTION_MODE, funexp),
411 rounded_stack_size_rtx, next_arg_reg, n_pop);
413 emit_call_insn (pat);
414 already_popped = 1;
416 else
417 #endif
419 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
420 /* If the target has "call" or "call_value" insns, then prefer them
421 if no arguments are actually popped. If the target does not have
422 "call" or "call_value" insns, then we must use the popping versions
423 even if the call has no arguments to pop. */
424 #if defined (HAVE_call) && defined (HAVE_call_value)
425 if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
426 && n_popped > 0 && ! (ecf_flags & ECF_SP_DEPRESSED))
427 #else
428 if (HAVE_call_pop && HAVE_call_value_pop)
429 #endif
431 rtx n_pop = GEN_INT (n_popped);
432 rtx pat;
434 /* If this subroutine pops its own args, record that in the call insn
435 if possible, for the sake of frame pointer elimination. */
437 if (valreg)
438 pat = GEN_CALL_VALUE_POP (valreg,
439 gen_rtx_MEM (FUNCTION_MODE, funexp),
440 rounded_stack_size_rtx, next_arg_reg, n_pop);
441 else
442 pat = GEN_CALL_POP (gen_rtx_MEM (FUNCTION_MODE, funexp),
443 rounded_stack_size_rtx, next_arg_reg, n_pop);
445 emit_call_insn (pat);
446 already_popped = 1;
448 else
449 #endif
451 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
452 if ((ecf_flags & ECF_SIBCALL)
453 && HAVE_sibcall && HAVE_sibcall_value)
455 if (valreg)
456 emit_call_insn (GEN_SIBCALL_VALUE (valreg,
457 gen_rtx_MEM (FUNCTION_MODE, funexp),
458 rounded_stack_size_rtx,
459 next_arg_reg, NULL_RTX));
460 else
461 emit_call_insn (GEN_SIBCALL (gen_rtx_MEM (FUNCTION_MODE, funexp),
462 rounded_stack_size_rtx, next_arg_reg,
463 struct_value_size_rtx));
465 else
466 #endif
468 #if defined (HAVE_call) && defined (HAVE_call_value)
469 if (HAVE_call && HAVE_call_value)
471 if (valreg)
472 emit_call_insn (GEN_CALL_VALUE (valreg,
473 gen_rtx_MEM (FUNCTION_MODE, funexp),
474 rounded_stack_size_rtx, next_arg_reg,
475 NULL_RTX));
476 else
477 emit_call_insn (GEN_CALL (gen_rtx_MEM (FUNCTION_MODE, funexp),
478 rounded_stack_size_rtx, next_arg_reg,
479 struct_value_size_rtx));
481 else
482 #endif
483 abort ();
485 /* Find the call we just emitted. */
486 call_insn = last_call_insn ();
488 /* Mark memory as used for "pure" function call. */
489 if (ecf_flags & ECF_PURE)
490 call_fusage
491 = gen_rtx_EXPR_LIST
492 (VOIDmode,
493 gen_rtx_USE (VOIDmode,
494 gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode))),
495 call_fusage);
497 /* Put the register usage information there. */
498 add_function_usage_to (call_insn, call_fusage);
500 /* If this is a const call, then set the insn's unchanging bit. */
501 if (ecf_flags & (ECF_CONST | ECF_PURE))
502 CONST_OR_PURE_CALL_P (call_insn) = 1;
504 /* If this call can't throw, attach a REG_EH_REGION reg note to that
505 effect. */
506 if (ecf_flags & ECF_NOTHROW)
507 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_EH_REGION, const0_rtx,
508 REG_NOTES (call_insn));
509 else
510 note_eh_region_may_contain_throw ();
512 if (ecf_flags & ECF_NORETURN)
513 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_NORETURN, const0_rtx,
514 REG_NOTES (call_insn));
515 if (ecf_flags & ECF_ALWAYS_RETURN)
516 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_ALWAYS_RETURN, const0_rtx,
517 REG_NOTES (call_insn));
519 if (ecf_flags & ECF_RETURNS_TWICE)
521 REG_NOTES (call_insn) = gen_rtx_EXPR_LIST (REG_SETJMP, const0_rtx,
522 REG_NOTES (call_insn));
523 current_function_calls_setjmp = 1;
526 SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
528 /* Restore this now, so that we do defer pops for this call's args
529 if the context of the call as a whole permits. */
530 inhibit_defer_pop = old_inhibit_defer_pop;
532 /* Don't bother cleaning up after a noreturn function. */
533 if (ecf_flags & (ECF_NORETURN | ECF_LONGJMP))
534 return;
536 if (n_popped > 0)
538 if (!already_popped)
539 CALL_INSN_FUNCTION_USAGE (call_insn)
540 = gen_rtx_EXPR_LIST (VOIDmode,
541 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
542 CALL_INSN_FUNCTION_USAGE (call_insn));
543 rounded_stack_size -= n_popped;
544 rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
545 stack_pointer_delta -= n_popped;
548 if (!ACCUMULATE_OUTGOING_ARGS)
550 /* If returning from the subroutine does not automatically pop the args,
551 we need an instruction to pop them sooner or later.
552 Perhaps do it now; perhaps just record how much space to pop later.
554 If returning from the subroutine does pop the args, indicate that the
555 stack pointer will be changed. */
557 if (rounded_stack_size != 0)
559 if (ecf_flags & ECF_SP_DEPRESSED)
560 /* Just pretend we did the pop. */
561 stack_pointer_delta -= rounded_stack_size;
562 else if (flag_defer_pop && inhibit_defer_pop == 0
563 && ! (ecf_flags & (ECF_CONST | ECF_PURE)))
564 pending_stack_adjust += rounded_stack_size;
565 else
566 adjust_stack (rounded_stack_size_rtx);
569 /* When we accumulate outgoing args, we must avoid any stack manipulations.
570 Restore the stack pointer to its original value now. Usually
571 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
572 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
573 popping variants of functions exist as well.
575 ??? We may optimize similar to defer_pop above, but it is
576 probably not worthwhile.
578 ??? It will be worthwhile to enable combine_stack_adjustments even for
579 such machines. */
580 else if (n_popped)
581 anti_adjust_stack (GEN_INT (n_popped));
584 /* Determine if the function identified by NAME and FNDECL is one with
585 special properties we wish to know about.
587 For example, if the function might return more than one time (setjmp), then
588 set RETURNS_TWICE to a nonzero value.
590 Similarly set LONGJMP for if the function is in the longjmp family.
592 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
593 space from the stack such as alloca. */
595 static int
596 special_function_p (tree fndecl, int flags)
598 if (! (flags & ECF_MALLOC)
599 && fndecl && DECL_NAME (fndecl)
600 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
601 /* Exclude functions not at the file scope, or not `extern',
602 since they are not the magic functions we would otherwise
603 think they are. */
604 && DECL_CONTEXT (fndecl) == NULL_TREE && TREE_PUBLIC (fndecl))
606 const char *name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
607 const char *tname = name;
609 /* We assume that alloca will always be called by name. It
610 makes no sense to pass it as a pointer-to-function to
611 anything that does not understand its behavior. */
612 if (((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
613 && name[0] == 'a'
614 && ! strcmp (name, "alloca"))
615 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
616 && name[0] == '_'
617 && ! strcmp (name, "__builtin_alloca"))))
618 flags |= ECF_MAY_BE_ALLOCA;
620 /* Disregard prefix _, __ or __x. */
621 if (name[0] == '_')
623 if (name[1] == '_' && name[2] == 'x')
624 tname += 3;
625 else if (name[1] == '_')
626 tname += 2;
627 else
628 tname += 1;
631 if (tname[0] == 's')
633 if ((tname[1] == 'e'
634 && (! strcmp (tname, "setjmp")
635 || ! strcmp (tname, "setjmp_syscall")))
636 || (tname[1] == 'i'
637 && ! strcmp (tname, "sigsetjmp"))
638 || (tname[1] == 'a'
639 && ! strcmp (tname, "savectx")))
640 flags |= ECF_RETURNS_TWICE;
642 if (tname[1] == 'i'
643 && ! strcmp (tname, "siglongjmp"))
644 flags |= ECF_LONGJMP;
646 else if ((tname[0] == 'q' && tname[1] == 's'
647 && ! strcmp (tname, "qsetjmp"))
648 || (tname[0] == 'v' && tname[1] == 'f'
649 && ! strcmp (tname, "vfork")))
650 flags |= ECF_RETURNS_TWICE;
652 else if (tname[0] == 'l' && tname[1] == 'o'
653 && ! strcmp (tname, "longjmp"))
654 flags |= ECF_LONGJMP;
656 else if ((tname[0] == 'f' && tname[1] == 'o'
657 && ! strcmp (tname, "fork"))
658 /* Linux specific: __clone. check NAME to insist on the
659 leading underscores, to avoid polluting the ISO / POSIX
660 namespace. */
661 || (name[0] == '_' && name[1] == '_'
662 && ! strcmp (tname, "clone"))
663 || (tname[0] == 'e' && tname[1] == 'x' && tname[2] == 'e'
664 && tname[3] == 'c' && (tname[4] == 'l' || tname[4] == 'v')
665 && (tname[5] == '\0'
666 || ((tname[5] == 'p' || tname[5] == 'e')
667 && tname[6] == '\0'))))
668 flags |= ECF_FORK_OR_EXEC;
670 return flags;
673 /* Return nonzero when tree represent call to longjmp. */
676 setjmp_call_p (tree fndecl)
678 return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE;
681 /* Return true when exp contains alloca call. */
682 bool
683 alloca_call_p (tree exp)
685 if (TREE_CODE (exp) == CALL_EXPR
686 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
687 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
688 == FUNCTION_DECL)
689 && (special_function_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
690 0) & ECF_MAY_BE_ALLOCA))
691 return true;
692 return false;
695 /* Detect flags (function attributes) from the function decl or type node. */
698 flags_from_decl_or_type (tree exp)
700 int flags = 0;
701 tree type = exp;
703 if (DECL_P (exp))
705 struct cgraph_rtl_info *i = cgraph_rtl_info (exp);
706 type = TREE_TYPE (exp);
708 if (i)
710 if (i->pure_function)
711 flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
712 if (i->const_function)
713 flags |= ECF_CONST | ECF_LIBCALL_BLOCK;
716 /* The function exp may have the `malloc' attribute. */
717 if (DECL_IS_MALLOC (exp))
718 flags |= ECF_MALLOC;
720 /* The function exp may have the `pure' attribute. */
721 if (DECL_IS_PURE (exp))
722 flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
724 if (TREE_NOTHROW (exp))
725 flags |= ECF_NOTHROW;
728 if (TREE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
729 flags |= ECF_CONST | ECF_LIBCALL_BLOCK;
731 if (TREE_THIS_VOLATILE (exp))
732 flags |= ECF_NORETURN;
734 /* Mark if the function returns with the stack pointer depressed. We
735 cannot consider it pure or constant in that case. */
736 if (TREE_CODE (type) == FUNCTION_TYPE && TYPE_RETURNS_STACK_DEPRESSED (type))
738 flags |= ECF_SP_DEPRESSED;
739 flags &= ~(ECF_PURE | ECF_CONST | ECF_LIBCALL_BLOCK);
742 return flags;
745 /* Precompute all register parameters as described by ARGS, storing values
746 into fields within the ARGS array.
748 NUM_ACTUALS indicates the total number elements in the ARGS array.
750 Set REG_PARM_SEEN if we encounter a register parameter. */
752 static void
753 precompute_register_parameters (int num_actuals, struct arg_data *args, int *reg_parm_seen)
755 int i;
757 *reg_parm_seen = 0;
759 for (i = 0; i < num_actuals; i++)
760 if (args[i].reg != 0 && ! args[i].pass_on_stack)
762 *reg_parm_seen = 1;
764 if (args[i].value == 0)
766 push_temp_slots ();
767 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
768 VOIDmode, 0);
769 preserve_temp_slots (args[i].value);
770 pop_temp_slots ();
772 /* ANSI doesn't require a sequence point here,
773 but PCC has one, so this will avoid some problems. */
774 emit_queue ();
777 /* If the value is a non-legitimate constant, force it into a
778 pseudo now. TLS symbols sometimes need a call to resolve. */
779 if (CONSTANT_P (args[i].value)
780 && !LEGITIMATE_CONSTANT_P (args[i].value))
781 args[i].value = force_reg (args[i].mode, args[i].value);
783 /* If we are to promote the function arg to a wider mode,
784 do it now. */
786 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
787 args[i].value
788 = convert_modes (args[i].mode,
789 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
790 args[i].value, args[i].unsignedp);
792 /* If the value is expensive, and we are inside an appropriately
793 short loop, put the value into a pseudo and then put the pseudo
794 into the hard reg.
796 For small register classes, also do this if this call uses
797 register parameters. This is to avoid reload conflicts while
798 loading the parameters registers. */
800 if ((! (GET_CODE (args[i].value) == REG
801 || (GET_CODE (args[i].value) == SUBREG
802 && GET_CODE (SUBREG_REG (args[i].value)) == REG)))
803 && args[i].mode != BLKmode
804 && rtx_cost (args[i].value, SET) > COSTS_N_INSNS (1)
805 && ((SMALL_REGISTER_CLASSES && *reg_parm_seen)
806 || preserve_subexpressions_p ()))
807 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
811 #ifdef REG_PARM_STACK_SPACE
813 /* The argument list is the property of the called routine and it
814 may clobber it. If the fixed area has been used for previous
815 parameters, we must save and restore it. */
817 static rtx
818 save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
820 int low;
821 int high;
823 /* Compute the boundary of the area that needs to be saved, if any. */
824 high = reg_parm_stack_space;
825 #ifdef ARGS_GROW_DOWNWARD
826 high += 1;
827 #endif
828 if (high > highest_outgoing_arg_in_use)
829 high = highest_outgoing_arg_in_use;
831 for (low = 0; low < high; low++)
832 if (stack_usage_map[low] != 0)
834 int num_to_save;
835 enum machine_mode save_mode;
836 int delta;
837 rtx stack_area;
838 rtx save_area;
840 while (stack_usage_map[--high] == 0)
843 *low_to_save = low;
844 *high_to_save = high;
846 num_to_save = high - low + 1;
847 save_mode = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
849 /* If we don't have the required alignment, must do this
850 in BLKmode. */
851 if ((low & (MIN (GET_MODE_SIZE (save_mode),
852 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
853 save_mode = BLKmode;
855 #ifdef ARGS_GROW_DOWNWARD
856 delta = -high;
857 #else
858 delta = low;
859 #endif
860 stack_area = gen_rtx_MEM (save_mode,
861 memory_address (save_mode,
862 plus_constant (argblock,
863 delta)));
865 set_mem_align (stack_area, PARM_BOUNDARY);
866 if (save_mode == BLKmode)
868 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
869 emit_block_move (validize_mem (save_area), stack_area,
870 GEN_INT (num_to_save), BLOCK_OP_CALL_PARM);
872 else
874 save_area = gen_reg_rtx (save_mode);
875 emit_move_insn (save_area, stack_area);
878 return save_area;
881 return NULL_RTX;
884 static void
885 restore_fixed_argument_area (rtx save_area, rtx argblock, int high_to_save, int low_to_save)
887 enum machine_mode save_mode = GET_MODE (save_area);
888 int delta;
889 rtx stack_area;
891 #ifdef ARGS_GROW_DOWNWARD
892 delta = -high_to_save;
893 #else
894 delta = low_to_save;
895 #endif
896 stack_area = gen_rtx_MEM (save_mode,
897 memory_address (save_mode,
898 plus_constant (argblock, delta)));
899 set_mem_align (stack_area, PARM_BOUNDARY);
901 if (save_mode != BLKmode)
902 emit_move_insn (stack_area, save_area);
903 else
904 emit_block_move (stack_area, validize_mem (save_area),
905 GEN_INT (high_to_save - low_to_save + 1),
906 BLOCK_OP_CALL_PARM);
908 #endif /* REG_PARM_STACK_SPACE */
910 /* If any elements in ARGS refer to parameters that are to be passed in
911 registers, but not in memory, and whose alignment does not permit a
912 direct copy into registers. Copy the values into a group of pseudos
913 which we will later copy into the appropriate hard registers.
915 Pseudos for each unaligned argument will be stored into the array
916 args[argnum].aligned_regs. The caller is responsible for deallocating
917 the aligned_regs array if it is nonzero. */
919 static void
920 store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals)
922 int i, j;
924 for (i = 0; i < num_actuals; i++)
925 if (args[i].reg != 0 && ! args[i].pass_on_stack
926 && args[i].mode == BLKmode
927 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
928 < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
930 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
931 int big_endian_correction = 0;
933 args[i].n_aligned_regs
934 = args[i].partial ? args[i].partial
935 : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
937 args[i].aligned_regs = (rtx *) xmalloc (sizeof (rtx)
938 * args[i].n_aligned_regs);
940 /* Structures smaller than a word are aligned to the least
941 significant byte (to the right). On a BYTES_BIG_ENDIAN machine,
942 this means we must skip the empty high order bytes when
943 calculating the bit offset. */
944 if (BYTES_BIG_ENDIAN
945 && bytes < UNITS_PER_WORD)
946 big_endian_correction = (BITS_PER_WORD - (bytes * BITS_PER_UNIT));
948 for (j = 0; j < args[i].n_aligned_regs; j++)
950 rtx reg = gen_reg_rtx (word_mode);
951 rtx word = operand_subword_force (args[i].value, j, BLKmode);
952 int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
954 args[i].aligned_regs[j] = reg;
956 /* There is no need to restrict this code to loading items
957 in TYPE_ALIGN sized hunks. The bitfield instructions can
958 load up entire word sized registers efficiently.
960 ??? This may not be needed anymore.
961 We use to emit a clobber here but that doesn't let later
962 passes optimize the instructions we emit. By storing 0 into
963 the register later passes know the first AND to zero out the
964 bitfield being set in the register is unnecessary. The store
965 of 0 will be deleted as will at least the first AND. */
967 emit_move_insn (reg, const0_rtx);
969 bytes -= bitsize / BITS_PER_UNIT;
970 store_bit_field (reg, bitsize, big_endian_correction, word_mode,
971 extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
972 word_mode, word_mode,
973 BITS_PER_WORD),
974 BITS_PER_WORD);
979 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
980 ACTPARMS.
982 NUM_ACTUALS is the total number of parameters.
984 N_NAMED_ARGS is the total number of named arguments.
986 FNDECL is the tree code for the target of this call (if known)
988 ARGS_SO_FAR holds state needed by the target to know where to place
989 the next argument.
991 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
992 for arguments which are passed in registers.
994 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
995 and may be modified by this routine.
997 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
998 flags which may may be modified by this routine. */
1000 static void
1001 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
1002 struct arg_data *args,
1003 struct args_size *args_size,
1004 int n_named_args ATTRIBUTE_UNUSED,
1005 tree actparms, tree fndecl,
1006 CUMULATIVE_ARGS *args_so_far,
1007 int reg_parm_stack_space,
1008 rtx *old_stack_level, int *old_pending_adj,
1009 int *must_preallocate, int *ecf_flags)
1011 /* 1 if scanning parms front to back, -1 if scanning back to front. */
1012 int inc;
1014 /* Count arg position in order args appear. */
1015 int argpos;
1017 int i;
1018 tree p;
1020 args_size->constant = 0;
1021 args_size->var = 0;
1023 /* In this loop, we consider args in the order they are written.
1024 We fill up ARGS from the front or from the back if necessary
1025 so that in any case the first arg to be pushed ends up at the front. */
1027 if (PUSH_ARGS_REVERSED)
1029 i = num_actuals - 1, inc = -1;
1030 /* In this case, must reverse order of args
1031 so that we compute and push the last arg first. */
1033 else
1035 i = 0, inc = 1;
1038 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1039 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
1041 tree type = TREE_TYPE (TREE_VALUE (p));
1042 int unsignedp;
1043 enum machine_mode mode;
1045 args[i].tree_value = TREE_VALUE (p);
1047 /* Replace erroneous argument with constant zero. */
1048 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
1049 args[i].tree_value = integer_zero_node, type = integer_type_node;
1051 /* If TYPE is a transparent union, pass things the way we would
1052 pass the first field of the union. We have already verified that
1053 the modes are the same. */
1054 if (TREE_CODE (type) == UNION_TYPE && TYPE_TRANSPARENT_UNION (type))
1055 type = TREE_TYPE (TYPE_FIELDS (type));
1057 /* Decide where to pass this arg.
1059 args[i].reg is nonzero if all or part is passed in registers.
1061 args[i].partial is nonzero if part but not all is passed in registers,
1062 and the exact value says how many words are passed in registers.
1064 args[i].pass_on_stack is nonzero if the argument must at least be
1065 computed on the stack. It may then be loaded back into registers
1066 if args[i].reg is nonzero.
1068 These decisions are driven by the FUNCTION_... macros and must agree
1069 with those made by function.c. */
1071 /* See if this argument should be passed by invisible reference. */
1072 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
1073 || TREE_ADDRESSABLE (type)
1074 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1075 || FUNCTION_ARG_PASS_BY_REFERENCE (*args_so_far, TYPE_MODE (type),
1076 type, argpos < n_named_args)
1077 #endif
1080 /* If we're compiling a thunk, pass through invisible
1081 references instead of making a copy. */
1082 if (current_function_is_thunk
1083 #ifdef FUNCTION_ARG_CALLEE_COPIES
1084 || (FUNCTION_ARG_CALLEE_COPIES (*args_so_far, TYPE_MODE (type),
1085 type, argpos < n_named_args)
1086 /* If it's in a register, we must make a copy of it too. */
1087 /* ??? Is this a sufficient test? Is there a better one? */
1088 && !(TREE_CODE (args[i].tree_value) == VAR_DECL
1089 && REG_P (DECL_RTL (args[i].tree_value)))
1090 && ! TREE_ADDRESSABLE (type))
1091 #endif
1094 /* C++ uses a TARGET_EXPR to indicate that we want to make a
1095 new object from the argument. If we are passing by
1096 invisible reference, the callee will do that for us, so we
1097 can strip off the TARGET_EXPR. This is not always safe,
1098 but it is safe in the only case where this is a useful
1099 optimization; namely, when the argument is a plain object.
1100 In that case, the frontend is just asking the backend to
1101 make a bitwise copy of the argument. */
1103 if (TREE_CODE (args[i].tree_value) == TARGET_EXPR
1104 && (DECL_P (TREE_OPERAND (args[i].tree_value, 1)))
1105 && ! REG_P (DECL_RTL (TREE_OPERAND (args[i].tree_value, 1))))
1106 args[i].tree_value = TREE_OPERAND (args[i].tree_value, 1);
1108 args[i].tree_value = build1 (ADDR_EXPR,
1109 build_pointer_type (type),
1110 args[i].tree_value);
1111 type = build_pointer_type (type);
1113 else if (TREE_CODE (args[i].tree_value) == TARGET_EXPR)
1115 /* In the V3 C++ ABI, parameters are destroyed in the caller.
1116 We implement this by passing the address of the temporary
1117 rather than expanding it into another allocated slot. */
1118 args[i].tree_value = build1 (ADDR_EXPR,
1119 build_pointer_type (type),
1120 args[i].tree_value);
1121 type = build_pointer_type (type);
1123 else
1125 /* We make a copy of the object and pass the address to the
1126 function being called. */
1127 rtx copy;
1129 if (!COMPLETE_TYPE_P (type)
1130 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1131 || (flag_stack_check && ! STACK_CHECK_BUILTIN
1132 && (0 < compare_tree_int (TYPE_SIZE_UNIT (type),
1133 STACK_CHECK_MAX_VAR_SIZE))))
1135 /* This is a variable-sized object. Make space on the stack
1136 for it. */
1137 rtx size_rtx = expr_size (TREE_VALUE (p));
1139 if (*old_stack_level == 0)
1141 emit_stack_save (SAVE_BLOCK, old_stack_level, NULL_RTX);
1142 *old_pending_adj = pending_stack_adjust;
1143 pending_stack_adjust = 0;
1146 copy = gen_rtx_MEM (BLKmode,
1147 allocate_dynamic_stack_space
1148 (size_rtx, NULL_RTX, TYPE_ALIGN (type)));
1149 set_mem_attributes (copy, type, 1);
1151 else
1152 copy = assign_temp (type, 0, 1, 0);
1154 store_expr (args[i].tree_value, copy, 0);
1155 *ecf_flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
1157 args[i].tree_value = build1 (ADDR_EXPR,
1158 build_pointer_type (type),
1159 make_tree (type, copy));
1160 type = build_pointer_type (type);
1164 mode = TYPE_MODE (type);
1165 unsignedp = TREE_UNSIGNED (type);
1167 #ifdef PROMOTE_FUNCTION_ARGS
1168 mode = promote_mode (type, mode, &unsignedp, 1);
1169 #endif
1171 args[i].unsignedp = unsignedp;
1172 args[i].mode = mode;
1174 args[i].reg = FUNCTION_ARG (*args_so_far, mode, type,
1175 argpos < n_named_args);
1176 #ifdef FUNCTION_INCOMING_ARG
1177 /* If this is a sibling call and the machine has register windows, the
1178 register window has to be unwinded before calling the routine, so
1179 arguments have to go into the incoming registers. */
1180 args[i].tail_call_reg = FUNCTION_INCOMING_ARG (*args_so_far, mode, type,
1181 argpos < n_named_args);
1182 #else
1183 args[i].tail_call_reg = args[i].reg;
1184 #endif
1186 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1187 if (args[i].reg)
1188 args[i].partial
1189 = FUNCTION_ARG_PARTIAL_NREGS (*args_so_far, mode, type,
1190 argpos < n_named_args);
1191 #endif
1193 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
1195 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1196 it means that we are to pass this arg in the register(s) designated
1197 by the PARALLEL, but also to pass it in the stack. */
1198 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1199 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1200 args[i].pass_on_stack = 1;
1202 /* If this is an addressable type, we must preallocate the stack
1203 since we must evaluate the object into its final location.
1205 If this is to be passed in both registers and the stack, it is simpler
1206 to preallocate. */
1207 if (TREE_ADDRESSABLE (type)
1208 || (args[i].pass_on_stack && args[i].reg != 0))
1209 *must_preallocate = 1;
1211 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1212 we cannot consider this function call constant. */
1213 if (TREE_ADDRESSABLE (type))
1214 *ecf_flags &= ~ECF_LIBCALL_BLOCK;
1216 /* Compute the stack-size of this argument. */
1217 if (args[i].reg == 0 || args[i].partial != 0
1218 || reg_parm_stack_space > 0
1219 || args[i].pass_on_stack)
1220 locate_and_pad_parm (mode, type,
1221 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1223 #else
1224 args[i].reg != 0,
1225 #endif
1226 args[i].pass_on_stack ? 0 : args[i].partial,
1227 fndecl, args_size, &args[i].locate);
1229 /* Update ARGS_SIZE, the total stack space for args so far. */
1231 args_size->constant += args[i].locate.size.constant;
1232 if (args[i].locate.size.var)
1233 ADD_PARM_SIZE (*args_size, args[i].locate.size.var);
1235 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1236 have been used, etc. */
1238 FUNCTION_ARG_ADVANCE (*args_so_far, TYPE_MODE (type), type,
1239 argpos < n_named_args);
1243 /* Update ARGS_SIZE to contain the total size for the argument block.
1244 Return the original constant component of the argument block's size.
1246 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1247 for arguments passed in registers. */
1249 static int
1250 compute_argument_block_size (int reg_parm_stack_space,
1251 struct args_size *args_size,
1252 int preferred_stack_boundary ATTRIBUTE_UNUSED)
1254 int unadjusted_args_size = args_size->constant;
1256 /* For accumulate outgoing args mode we don't need to align, since the frame
1257 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1258 backends from generating misaligned frame sizes. */
1259 if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY)
1260 preferred_stack_boundary = STACK_BOUNDARY;
1262 /* Compute the actual size of the argument block required. The variable
1263 and constant sizes must be combined, the size may have to be rounded,
1264 and there may be a minimum required size. */
1266 if (args_size->var)
1268 args_size->var = ARGS_SIZE_TREE (*args_size);
1269 args_size->constant = 0;
1271 preferred_stack_boundary /= BITS_PER_UNIT;
1272 if (preferred_stack_boundary > 1)
1274 /* We don't handle this case yet. To handle it correctly we have
1275 to add the delta, round and subtract the delta.
1276 Currently no machine description requires this support. */
1277 if (stack_pointer_delta & (preferred_stack_boundary - 1))
1278 abort ();
1279 args_size->var = round_up (args_size->var, preferred_stack_boundary);
1282 if (reg_parm_stack_space > 0)
1284 args_size->var
1285 = size_binop (MAX_EXPR, args_size->var,
1286 ssize_int (reg_parm_stack_space));
1288 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1289 /* The area corresponding to register parameters is not to count in
1290 the size of the block we need. So make the adjustment. */
1291 args_size->var
1292 = size_binop (MINUS_EXPR, args_size->var,
1293 ssize_int (reg_parm_stack_space));
1294 #endif
1297 else
1299 preferred_stack_boundary /= BITS_PER_UNIT;
1300 if (preferred_stack_boundary < 1)
1301 preferred_stack_boundary = 1;
1302 args_size->constant = (((args_size->constant
1303 + stack_pointer_delta
1304 + preferred_stack_boundary - 1)
1305 / preferred_stack_boundary
1306 * preferred_stack_boundary)
1307 - stack_pointer_delta);
1309 args_size->constant = MAX (args_size->constant,
1310 reg_parm_stack_space);
1312 #ifdef MAYBE_REG_PARM_STACK_SPACE
1313 if (reg_parm_stack_space == 0)
1314 args_size->constant = 0;
1315 #endif
1317 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1318 args_size->constant -= reg_parm_stack_space;
1319 #endif
1321 return unadjusted_args_size;
1324 /* Precompute parameters as needed for a function call.
1326 FLAGS is mask of ECF_* constants.
1328 NUM_ACTUALS is the number of arguments.
1330 ARGS is an array containing information for each argument; this
1331 routine fills in the INITIAL_VALUE and VALUE fields for each
1332 precomputed argument. */
1334 static void
1335 precompute_arguments (int flags, int num_actuals, struct arg_data *args)
1337 int i;
1339 /* If this function call is cse'able, precompute all the parameters.
1340 Note that if the parameter is constructed into a temporary, this will
1341 cause an additional copy because the parameter will be constructed
1342 into a temporary location and then copied into the outgoing arguments.
1343 If a parameter contains a call to alloca and this function uses the
1344 stack, precompute the parameter. */
1346 /* If we preallocated the stack space, and some arguments must be passed
1347 on the stack, then we must precompute any parameter which contains a
1348 function call which will store arguments on the stack.
1349 Otherwise, evaluating the parameter may clobber previous parameters
1350 which have already been stored into the stack. (we have code to avoid
1351 such case by saving the outgoing stack arguments, but it results in
1352 worse code) */
1354 for (i = 0; i < num_actuals; i++)
1355 if ((flags & ECF_LIBCALL_BLOCK)
1356 || calls_function (args[i].tree_value, !ACCUMULATE_OUTGOING_ARGS))
1358 enum machine_mode mode;
1360 /* If this is an addressable type, we cannot pre-evaluate it. */
1361 if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))
1362 abort ();
1364 args[i].value
1365 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1367 /* ANSI doesn't require a sequence point here,
1368 but PCC has one, so this will avoid some problems. */
1369 emit_queue ();
1371 args[i].initial_value = args[i].value
1372 = protect_from_queue (args[i].value, 0);
1374 mode = TYPE_MODE (TREE_TYPE (args[i].tree_value));
1375 if (mode != args[i].mode)
1377 args[i].value
1378 = convert_modes (args[i].mode, mode,
1379 args[i].value, args[i].unsignedp);
1380 #ifdef PROMOTE_FOR_CALL_ONLY
1381 /* CSE will replace this only if it contains args[i].value
1382 pseudo, so convert it down to the declared mode using
1383 a SUBREG. */
1384 if (GET_CODE (args[i].value) == REG
1385 && GET_MODE_CLASS (args[i].mode) == MODE_INT)
1387 args[i].initial_value
1388 = gen_lowpart_SUBREG (mode, args[i].value);
1389 SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1390 SUBREG_PROMOTED_UNSIGNED_SET (args[i].initial_value,
1391 args[i].unsignedp);
1393 #endif
1398 /* Given the current state of MUST_PREALLOCATE and information about
1399 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1400 compute and return the final value for MUST_PREALLOCATE. */
1402 static int
1403 finalize_must_preallocate (int must_preallocate, int num_actuals, struct arg_data *args, struct args_size *args_size)
1405 /* See if we have or want to preallocate stack space.
1407 If we would have to push a partially-in-regs parm
1408 before other stack parms, preallocate stack space instead.
1410 If the size of some parm is not a multiple of the required stack
1411 alignment, we must preallocate.
1413 If the total size of arguments that would otherwise create a copy in
1414 a temporary (such as a CALL) is more than half the total argument list
1415 size, preallocation is faster.
1417 Another reason to preallocate is if we have a machine (like the m88k)
1418 where stack alignment is required to be maintained between every
1419 pair of insns, not just when the call is made. However, we assume here
1420 that such machines either do not have push insns (and hence preallocation
1421 would occur anyway) or the problem is taken care of with
1422 PUSH_ROUNDING. */
1424 if (! must_preallocate)
1426 int partial_seen = 0;
1427 int copy_to_evaluate_size = 0;
1428 int i;
1430 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1432 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1433 partial_seen = 1;
1434 else if (partial_seen && args[i].reg == 0)
1435 must_preallocate = 1;
1437 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1438 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1439 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1440 || TREE_CODE (args[i].tree_value) == COND_EXPR
1441 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1442 copy_to_evaluate_size
1443 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1446 if (copy_to_evaluate_size * 2 >= args_size->constant
1447 && args_size->constant > 0)
1448 must_preallocate = 1;
1450 return must_preallocate;
1453 /* If we preallocated stack space, compute the address of each argument
1454 and store it into the ARGS array.
1456 We need not ensure it is a valid memory address here; it will be
1457 validized when it is used.
1459 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1461 static void
1462 compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals)
1464 if (argblock)
1466 rtx arg_reg = argblock;
1467 int i, arg_offset = 0;
1469 if (GET_CODE (argblock) == PLUS)
1470 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1472 for (i = 0; i < num_actuals; i++)
1474 rtx offset = ARGS_SIZE_RTX (args[i].locate.offset);
1475 rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
1476 rtx addr;
1478 /* Skip this parm if it will not be passed on the stack. */
1479 if (! args[i].pass_on_stack && args[i].reg != 0)
1480 continue;
1482 if (GET_CODE (offset) == CONST_INT)
1483 addr = plus_constant (arg_reg, INTVAL (offset));
1484 else
1485 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1487 addr = plus_constant (addr, arg_offset);
1488 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1489 set_mem_align (args[i].stack, PARM_BOUNDARY);
1490 set_mem_attributes (args[i].stack,
1491 TREE_TYPE (args[i].tree_value), 1);
1493 if (GET_CODE (slot_offset) == CONST_INT)
1494 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1495 else
1496 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1498 addr = plus_constant (addr, arg_offset);
1499 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1500 set_mem_align (args[i].stack_slot, PARM_BOUNDARY);
1501 set_mem_attributes (args[i].stack_slot,
1502 TREE_TYPE (args[i].tree_value), 1);
1504 /* Function incoming arguments may overlap with sibling call
1505 outgoing arguments and we cannot allow reordering of reads
1506 from function arguments with stores to outgoing arguments
1507 of sibling calls. */
1508 set_mem_alias_set (args[i].stack, 0);
1509 set_mem_alias_set (args[i].stack_slot, 0);
1514 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1515 in a call instruction.
1517 FNDECL is the tree node for the target function. For an indirect call
1518 FNDECL will be NULL_TREE.
1520 ADDR is the operand 0 of CALL_EXPR for this call. */
1522 static rtx
1523 rtx_for_function_call (tree fndecl, tree addr)
1525 rtx funexp;
1527 /* Get the function to call, in the form of RTL. */
1528 if (fndecl)
1530 /* If this is the first use of the function, see if we need to
1531 make an external definition for it. */
1532 if (! TREE_USED (fndecl))
1534 assemble_external (fndecl);
1535 TREE_USED (fndecl) = 1;
1538 /* Get a SYMBOL_REF rtx for the function address. */
1539 funexp = XEXP (DECL_RTL (fndecl), 0);
1541 else
1542 /* Generate an rtx (probably a pseudo-register) for the address. */
1544 push_temp_slots ();
1545 funexp = expand_expr (addr, NULL_RTX, VOIDmode, 0);
1546 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1547 emit_queue ();
1549 return funexp;
1552 /* Do the register loads required for any wholly-register parms or any
1553 parms which are passed both on the stack and in a register. Their
1554 expressions were already evaluated.
1556 Mark all register-parms as living through the call, putting these USE
1557 insns in the CALL_INSN_FUNCTION_USAGE field.
1559 When IS_SIBCALL, perform the check_sibcall_overlap_argument_overlap
1560 checking, setting *SIBCALL_FAILURE if appropriate. */
1562 static void
1563 load_register_parameters (struct arg_data *args, int num_actuals,
1564 rtx *call_fusage, int flags, int is_sibcall,
1565 int *sibcall_failure)
1567 int i, j;
1569 #ifdef LOAD_ARGS_REVERSED
1570 for (i = num_actuals - 1; i >= 0; i--)
1571 #else
1572 for (i = 0; i < num_actuals; i++)
1573 #endif
1575 rtx reg = ((flags & ECF_SIBCALL)
1576 ? args[i].tail_call_reg : args[i].reg);
1577 int partial = args[i].partial;
1578 int nregs;
1580 if (reg)
1582 rtx before_arg = get_last_insn ();
1583 /* Set to non-negative if must move a word at a time, even if just
1584 one word (e.g, partial == 1 && mode == DFmode). Set to -1 if
1585 we just use a normal move insn. This value can be zero if the
1586 argument is a zero size structure with no fields. */
1587 nregs = (partial ? partial
1588 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1589 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1590 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1591 : -1));
1593 /* Handle calls that pass values in multiple non-contiguous
1594 locations. The Irix 6 ABI has examples of this. */
1596 if (GET_CODE (reg) == PARALLEL)
1597 emit_group_load (reg, args[i].value,
1598 int_size_in_bytes (TREE_TYPE (args[i].tree_value)));
1600 /* If simple case, just do move. If normal partial, store_one_arg
1601 has already loaded the register for us. In all other cases,
1602 load the register(s) from memory. */
1604 else if (nregs == -1)
1605 emit_move_insn (reg, args[i].value);
1607 /* If we have pre-computed the values to put in the registers in
1608 the case of non-aligned structures, copy them in now. */
1610 else if (args[i].n_aligned_regs != 0)
1611 for (j = 0; j < args[i].n_aligned_regs; j++)
1612 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
1613 args[i].aligned_regs[j]);
1615 else if (partial == 0 || args[i].pass_on_stack)
1616 move_block_to_reg (REGNO (reg),
1617 validize_mem (args[i].value), nregs,
1618 args[i].mode);
1620 /* When a parameter is a block, and perhaps in other cases, it is
1621 possible that it did a load from an argument slot that was
1622 already clobbered. */
1623 if (is_sibcall
1624 && check_sibcall_argument_overlap (before_arg, &args[i], 0))
1625 *sibcall_failure = 1;
1627 /* Handle calls that pass values in multiple non-contiguous
1628 locations. The Irix 6 ABI has examples of this. */
1629 if (GET_CODE (reg) == PARALLEL)
1630 use_group_regs (call_fusage, reg);
1631 else if (nregs == -1)
1632 use_reg (call_fusage, reg);
1633 else
1634 use_regs (call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1639 /* Try to integrate function. See expand_inline_function for documentation
1640 about the parameters. */
1642 static rtx
1643 try_to_integrate (tree fndecl, tree actparms, rtx target, int ignore,
1644 tree type, rtx structure_value_addr)
1646 rtx temp;
1647 rtx before_call;
1648 int i;
1649 rtx old_stack_level = 0;
1650 int reg_parm_stack_space = 0;
1652 #ifdef REG_PARM_STACK_SPACE
1653 #ifdef MAYBE_REG_PARM_STACK_SPACE
1654 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
1655 #else
1656 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
1657 #endif
1658 #endif
1660 before_call = get_last_insn ();
1662 timevar_push (TV_INTEGRATION);
1664 temp = expand_inline_function (fndecl, actparms, target,
1665 ignore, type,
1666 structure_value_addr);
1668 timevar_pop (TV_INTEGRATION);
1670 /* If inlining succeeded, return. */
1671 if (temp != (rtx) (size_t) - 1)
1673 if (ACCUMULATE_OUTGOING_ARGS)
1675 /* If the outgoing argument list must be preserved, push
1676 the stack before executing the inlined function if it
1677 makes any calls. */
1679 i = reg_parm_stack_space;
1680 if (i > highest_outgoing_arg_in_use)
1681 i = highest_outgoing_arg_in_use;
1682 while (--i >= 0 && stack_usage_map[i] == 0)
1685 if (stack_arg_under_construction || i >= 0)
1687 rtx first_insn
1688 = before_call ? NEXT_INSN (before_call) : get_insns ();
1689 rtx insn = NULL_RTX, seq;
1691 /* Look for a call in the inline function code.
1692 If DECL_SAVED_INSNS (fndecl)->outgoing_args_size is
1693 nonzero then there is a call and it is not necessary
1694 to scan the insns. */
1696 if (DECL_SAVED_INSNS (fndecl)->outgoing_args_size == 0)
1697 for (insn = first_insn; insn; insn = NEXT_INSN (insn))
1698 if (GET_CODE (insn) == CALL_INSN)
1699 break;
1701 if (insn)
1703 /* Reserve enough stack space so that the largest
1704 argument list of any function call in the inline
1705 function does not overlap the argument list being
1706 evaluated. This is usually an overestimate because
1707 allocate_dynamic_stack_space reserves space for an
1708 outgoing argument list in addition to the requested
1709 space, but there is no way to ask for stack space such
1710 that an argument list of a certain length can be
1711 safely constructed.
1713 Add the stack space reserved for register arguments, if
1714 any, in the inline function. What is really needed is the
1715 largest value of reg_parm_stack_space in the inline
1716 function, but that is not available. Using the current
1717 value of reg_parm_stack_space is wrong, but gives
1718 correct results on all supported machines. */
1720 int adjust = (DECL_SAVED_INSNS (fndecl)->outgoing_args_size
1721 + reg_parm_stack_space);
1723 start_sequence ();
1724 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1725 allocate_dynamic_stack_space (GEN_INT (adjust),
1726 NULL_RTX, BITS_PER_UNIT);
1727 seq = get_insns ();
1728 end_sequence ();
1729 emit_insn_before (seq, first_insn);
1730 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
1735 /* If the result is equivalent to TARGET, return TARGET to simplify
1736 checks in store_expr. They can be equivalent but not equal in the
1737 case of a function that returns BLKmode. */
1738 if (temp != target && rtx_equal_p (temp, target))
1739 return target;
1740 return temp;
1743 /* If inlining failed, mark FNDECL as needing to be compiled
1744 separately after all. If function was declared inline,
1745 give a warning. */
1746 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
1747 && optimize > 0 && !TREE_ADDRESSABLE (fndecl))
1749 warning_with_decl (fndecl, "inlining failed in call to `%s'");
1750 warning ("called from here");
1752 (*lang_hooks.mark_addressable) (fndecl);
1753 return (rtx) (size_t) - 1;
1756 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
1757 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
1758 bytes, then we would need to push some additional bytes to pad the
1759 arguments. So, we compute an adjust to the stack pointer for an
1760 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
1761 bytes. Then, when the arguments are pushed the stack will be perfectly
1762 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
1763 be popped after the call. Returns the adjustment. */
1765 static int
1766 combine_pending_stack_adjustment_and_call (int unadjusted_args_size,
1767 struct args_size *args_size,
1768 int preferred_unit_stack_boundary)
1770 /* The number of bytes to pop so that the stack will be
1771 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
1772 HOST_WIDE_INT adjustment;
1773 /* The alignment of the stack after the arguments are pushed, if we
1774 just pushed the arguments without adjust the stack here. */
1775 HOST_WIDE_INT unadjusted_alignment;
1777 unadjusted_alignment
1778 = ((stack_pointer_delta + unadjusted_args_size)
1779 % preferred_unit_stack_boundary);
1781 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
1782 as possible -- leaving just enough left to cancel out the
1783 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
1784 PENDING_STACK_ADJUST is non-negative, and congruent to
1785 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
1787 /* Begin by trying to pop all the bytes. */
1788 unadjusted_alignment
1789 = (unadjusted_alignment
1790 - (pending_stack_adjust % preferred_unit_stack_boundary));
1791 adjustment = pending_stack_adjust;
1792 /* Push enough additional bytes that the stack will be aligned
1793 after the arguments are pushed. */
1794 if (preferred_unit_stack_boundary > 1)
1796 if (unadjusted_alignment > 0)
1797 adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
1798 else
1799 adjustment += unadjusted_alignment;
1802 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
1803 bytes after the call. The right number is the entire
1804 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
1805 by the arguments in the first place. */
1806 args_size->constant
1807 = pending_stack_adjust - adjustment + unadjusted_args_size;
1809 return adjustment;
1812 /* Scan X expression if it does not dereference any argument slots
1813 we already clobbered by tail call arguments (as noted in stored_args_map
1814 bitmap).
1815 Return nonzero if X expression dereferences such argument slots,
1816 zero otherwise. */
1818 static int
1819 check_sibcall_argument_overlap_1 (rtx x)
1821 RTX_CODE code;
1822 int i, j;
1823 unsigned int k;
1824 const char *fmt;
1826 if (x == NULL_RTX)
1827 return 0;
1829 code = GET_CODE (x);
1831 if (code == MEM)
1833 if (XEXP (x, 0) == current_function_internal_arg_pointer)
1834 i = 0;
1835 else if (GET_CODE (XEXP (x, 0)) == PLUS
1836 && XEXP (XEXP (x, 0), 0) ==
1837 current_function_internal_arg_pointer
1838 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1839 i = INTVAL (XEXP (XEXP (x, 0), 1));
1840 else
1841 return 0;
1843 #ifdef ARGS_GROW_DOWNWARD
1844 i = -i - GET_MODE_SIZE (GET_MODE (x));
1845 #endif
1847 for (k = 0; k < GET_MODE_SIZE (GET_MODE (x)); k++)
1848 if (i + k < stored_args_map->n_bits
1849 && TEST_BIT (stored_args_map, i + k))
1850 return 1;
1852 return 0;
1855 /* Scan all subexpressions. */
1856 fmt = GET_RTX_FORMAT (code);
1857 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
1859 if (*fmt == 'e')
1861 if (check_sibcall_argument_overlap_1 (XEXP (x, i)))
1862 return 1;
1864 else if (*fmt == 'E')
1866 for (j = 0; j < XVECLEN (x, i); j++)
1867 if (check_sibcall_argument_overlap_1 (XVECEXP (x, i, j)))
1868 return 1;
1871 return 0;
1874 /* Scan sequence after INSN if it does not dereference any argument slots
1875 we already clobbered by tail call arguments (as noted in stored_args_map
1876 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
1877 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
1878 should be 0). Return nonzero if sequence after INSN dereferences such argument
1879 slots, zero otherwise. */
1881 static int
1882 check_sibcall_argument_overlap (rtx insn, struct arg_data *arg, int mark_stored_args_map)
1884 int low, high;
1886 if (insn == NULL_RTX)
1887 insn = get_insns ();
1888 else
1889 insn = NEXT_INSN (insn);
1891 for (; insn; insn = NEXT_INSN (insn))
1892 if (INSN_P (insn)
1893 && check_sibcall_argument_overlap_1 (PATTERN (insn)))
1894 break;
1896 if (mark_stored_args_map)
1898 #ifdef ARGS_GROW_DOWNWARD
1899 low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
1900 #else
1901 low = arg->locate.slot_offset.constant;
1902 #endif
1904 for (high = low + arg->locate.size.constant; low < high; low++)
1905 SET_BIT (stored_args_map, low);
1907 return insn != NULL_RTX;
1910 static tree
1911 fix_unsafe_tree (tree t)
1913 switch (unsafe_for_reeval (t))
1915 case 0: /* Safe. */
1916 break;
1918 case 1: /* Mildly unsafe. */
1919 t = unsave_expr (t);
1920 break;
1922 case 2: /* Wildly unsafe. */
1924 tree var = build_decl (VAR_DECL, NULL_TREE,
1925 TREE_TYPE (t));
1926 SET_DECL_RTL (var,
1927 expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL));
1928 t = var;
1930 break;
1932 default:
1933 abort ();
1935 return t;
1938 /* Generate all the code for a function call
1939 and return an rtx for its value.
1940 Store the value in TARGET (specified as an rtx) if convenient.
1941 If the value is stored in TARGET then TARGET is returned.
1942 If IGNORE is nonzero, then we ignore the value of the function call. */
1945 expand_call (tree exp, rtx target, int ignore)
1947 /* Nonzero if we are currently expanding a call. */
1948 static int currently_expanding_call = 0;
1950 /* List of actual parameters. */
1951 tree actparms = TREE_OPERAND (exp, 1);
1952 /* RTX for the function to be called. */
1953 rtx funexp;
1954 /* Sequence of insns to perform a tail recursive "call". */
1955 rtx tail_recursion_insns = NULL_RTX;
1956 /* Sequence of insns to perform a normal "call". */
1957 rtx normal_call_insns = NULL_RTX;
1958 /* Sequence of insns to perform a tail recursive "call". */
1959 rtx tail_call_insns = NULL_RTX;
1960 /* Data type of the function. */
1961 tree funtype;
1962 tree type_arg_types;
1963 /* Declaration of the function being called,
1964 or 0 if the function is computed (not known by name). */
1965 tree fndecl = 0;
1966 rtx insn;
1967 int try_tail_call = 1;
1968 int try_tail_recursion = 1;
1969 int pass;
1971 /* Register in which non-BLKmode value will be returned,
1972 or 0 if no value or if value is BLKmode. */
1973 rtx valreg;
1974 /* Address where we should return a BLKmode value;
1975 0 if value not BLKmode. */
1976 rtx structure_value_addr = 0;
1977 /* Nonzero if that address is being passed by treating it as
1978 an extra, implicit first parameter. Otherwise,
1979 it is passed by being copied directly into struct_value_rtx. */
1980 int structure_value_addr_parm = 0;
1981 /* Size of aggregate value wanted, or zero if none wanted
1982 or if we are using the non-reentrant PCC calling convention
1983 or expecting the value in registers. */
1984 HOST_WIDE_INT struct_value_size = 0;
1985 /* Nonzero if called function returns an aggregate in memory PCC style,
1986 by returning the address of where to find it. */
1987 int pcc_struct_value = 0;
1989 /* Number of actual parameters in this call, including struct value addr. */
1990 int num_actuals;
1991 /* Number of named args. Args after this are anonymous ones
1992 and they must all go on the stack. */
1993 int n_named_args;
1995 /* Vector of information about each argument.
1996 Arguments are numbered in the order they will be pushed,
1997 not the order they are written. */
1998 struct arg_data *args;
2000 /* Total size in bytes of all the stack-parms scanned so far. */
2001 struct args_size args_size;
2002 struct args_size adjusted_args_size;
2003 /* Size of arguments before any adjustments (such as rounding). */
2004 int unadjusted_args_size;
2005 /* Data on reg parms scanned so far. */
2006 CUMULATIVE_ARGS args_so_far;
2007 /* Nonzero if a reg parm has been scanned. */
2008 int reg_parm_seen;
2009 /* Nonzero if this is an indirect function call. */
2011 /* Nonzero if we must avoid push-insns in the args for this call.
2012 If stack space is allocated for register parameters, but not by the
2013 caller, then it is preallocated in the fixed part of the stack frame.
2014 So the entire argument block must then be preallocated (i.e., we
2015 ignore PUSH_ROUNDING in that case). */
2017 int must_preallocate = !PUSH_ARGS;
2019 /* Size of the stack reserved for parameter registers. */
2020 int reg_parm_stack_space = 0;
2022 /* Address of space preallocated for stack parms
2023 (on machines that lack push insns), or 0 if space not preallocated. */
2024 rtx argblock = 0;
2026 /* Mask of ECF_ flags. */
2027 int flags = 0;
2028 /* Nonzero if this is a call to an inline function. */
2029 int is_integrable = 0;
2030 #ifdef REG_PARM_STACK_SPACE
2031 /* Define the boundary of the register parm stack space that needs to be
2032 saved, if any. */
2033 int low_to_save, high_to_save;
2034 rtx save_area = 0; /* Place that it is saved */
2035 #endif
2037 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2038 char *initial_stack_usage_map = stack_usage_map;
2040 int old_stack_allocated;
2042 /* State variables to track stack modifications. */
2043 rtx old_stack_level = 0;
2044 int old_stack_arg_under_construction = 0;
2045 int old_pending_adj = 0;
2046 int old_inhibit_defer_pop = inhibit_defer_pop;
2048 /* Some stack pointer alterations we make are performed via
2049 allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
2050 which we then also need to save/restore along the way. */
2051 int old_stack_pointer_delta = 0;
2053 rtx call_fusage;
2054 tree p = TREE_OPERAND (exp, 0);
2055 tree addr = TREE_OPERAND (exp, 0);
2056 int i;
2057 /* The alignment of the stack, in bits. */
2058 HOST_WIDE_INT preferred_stack_boundary;
2059 /* The alignment of the stack, in bytes. */
2060 HOST_WIDE_INT preferred_unit_stack_boundary;
2062 /* See if this is "nothrow" function call. */
2063 if (TREE_NOTHROW (exp))
2064 flags |= ECF_NOTHROW;
2066 /* See if we can find a DECL-node for the actual function.
2067 As a result, decide whether this is a call to an integrable function. */
2069 fndecl = get_callee_fndecl (exp);
2070 if (fndecl)
2072 if (!flag_no_inline
2073 && fndecl != current_function_decl
2074 && DECL_INLINE (fndecl)
2075 && DECL_SAVED_INSNS (fndecl)
2076 && DECL_SAVED_INSNS (fndecl)->inlinable)
2077 is_integrable = 1;
2078 else if (! TREE_ADDRESSABLE (fndecl))
2080 /* In case this function later becomes inlinable,
2081 record that there was already a non-inline call to it.
2083 Use abstraction instead of setting TREE_ADDRESSABLE
2084 directly. */
2085 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
2086 && optimize > 0)
2088 warning_with_decl (fndecl, "can't inline call to `%s'");
2089 warning ("called from here");
2091 (*lang_hooks.mark_addressable) (fndecl);
2094 flags |= flags_from_decl_or_type (fndecl);
2097 /* If we don't have specific function to call, see if we have a
2098 attributes set in the type. */
2099 else
2100 flags |= flags_from_decl_or_type (TREE_TYPE (TREE_TYPE (p)));
2102 /* Warn if this value is an aggregate type,
2103 regardless of which calling convention we are using for it. */
2104 if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2105 warning ("function call has aggregate value");
2107 /* If the result of a pure or const function call is ignored (or void),
2108 and none of its arguments are volatile, we can avoid expanding the
2109 call and just evaluate the arguments for side-effects. */
2110 if ((flags & (ECF_CONST | ECF_PURE))
2111 && (ignore || target == const0_rtx
2112 || TYPE_MODE (TREE_TYPE (exp)) == VOIDmode))
2114 bool volatilep = false;
2115 tree arg;
2117 for (arg = actparms; arg; arg = TREE_CHAIN (arg))
2118 if (TREE_THIS_VOLATILE (TREE_VALUE (arg)))
2120 volatilep = true;
2121 break;
2124 if (! volatilep)
2126 for (arg = actparms; arg; arg = TREE_CHAIN (arg))
2127 expand_expr (TREE_VALUE (arg), const0_rtx,
2128 VOIDmode, EXPAND_NORMAL);
2129 return const0_rtx;
2133 #ifdef REG_PARM_STACK_SPACE
2134 #ifdef MAYBE_REG_PARM_STACK_SPACE
2135 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2136 #else
2137 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
2138 #endif
2139 #endif
2141 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2142 if (reg_parm_stack_space > 0 && PUSH_ARGS)
2143 must_preallocate = 1;
2144 #endif
2146 /* Set up a place to return a structure. */
2148 /* Cater to broken compilers. */
2149 if (aggregate_value_p (exp))
2151 /* This call returns a big structure. */
2152 flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
2154 #ifdef PCC_STATIC_STRUCT_RETURN
2156 pcc_struct_value = 1;
2157 /* Easier than making that case work right. */
2158 if (is_integrable)
2160 /* In case this is a static function, note that it has been
2161 used. */
2162 if (! TREE_ADDRESSABLE (fndecl))
2163 (*lang_hooks.mark_addressable) (fndecl);
2164 is_integrable = 0;
2167 #else /* not PCC_STATIC_STRUCT_RETURN */
2169 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
2171 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (exp))
2173 /* The structure value address arg is already in actparms.
2174 Pull it out. It might be nice to just leave it there, but
2175 we need to set structure_value_addr. */
2176 tree return_arg = TREE_VALUE (actparms);
2177 actparms = TREE_CHAIN (actparms);
2178 structure_value_addr = expand_expr (return_arg, NULL_RTX,
2179 VOIDmode, EXPAND_NORMAL);
2181 else if (target && GET_CODE (target) == MEM)
2182 structure_value_addr = XEXP (target, 0);
2183 else
2185 /* For variable-sized objects, we must be called with a target
2186 specified. If we were to allocate space on the stack here,
2187 we would have no way of knowing when to free it. */
2188 rtx d = assign_temp (TREE_TYPE (exp), 1, 1, 1);
2190 mark_temp_addr_taken (d);
2191 structure_value_addr = XEXP (d, 0);
2192 target = 0;
2195 #endif /* not PCC_STATIC_STRUCT_RETURN */
2198 /* If called function is inline, try to integrate it. */
2200 if (is_integrable)
2202 rtx temp = try_to_integrate (fndecl, actparms, target,
2203 ignore, TREE_TYPE (exp),
2204 structure_value_addr);
2205 if (temp != (rtx) (size_t) - 1)
2206 return temp;
2209 /* Figure out the amount to which the stack should be aligned. */
2210 preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2211 if (fndecl)
2213 struct cgraph_rtl_info *i = cgraph_rtl_info (fndecl);
2214 if (i && i->preferred_incoming_stack_boundary)
2215 preferred_stack_boundary = i->preferred_incoming_stack_boundary;
2218 /* Operand 0 is a pointer-to-function; get the type of the function. */
2219 funtype = TREE_TYPE (addr);
2220 if (! POINTER_TYPE_P (funtype))
2221 abort ();
2222 funtype = TREE_TYPE (funtype);
2224 /* Munge the tree to split complex arguments into their imaginary
2225 and real parts. */
2226 if (SPLIT_COMPLEX_ARGS)
2228 type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype));
2229 actparms = split_complex_values (actparms);
2231 else
2232 type_arg_types = TYPE_ARG_TYPES (funtype);
2234 /* See if this is a call to a function that can return more than once
2235 or a call to longjmp or malloc. */
2236 flags |= special_function_p (fndecl, flags);
2238 if (flags & ECF_MAY_BE_ALLOCA)
2239 current_function_calls_alloca = 1;
2241 /* If struct_value_rtx is 0, it means pass the address
2242 as if it were an extra parameter. */
2243 if (structure_value_addr && struct_value_rtx == 0)
2245 /* If structure_value_addr is a REG other than
2246 virtual_outgoing_args_rtx, we can use always use it. If it
2247 is not a REG, we must always copy it into a register.
2248 If it is virtual_outgoing_args_rtx, we must copy it to another
2249 register in some cases. */
2250 rtx temp = (GET_CODE (structure_value_addr) != REG
2251 || (ACCUMULATE_OUTGOING_ARGS
2252 && stack_arg_under_construction
2253 && structure_value_addr == virtual_outgoing_args_rtx)
2254 ? copy_addr_to_reg (structure_value_addr)
2255 : structure_value_addr);
2257 actparms
2258 = tree_cons (error_mark_node,
2259 make_tree (build_pointer_type (TREE_TYPE (funtype)),
2260 temp),
2261 actparms);
2262 structure_value_addr_parm = 1;
2265 /* Count the arguments and set NUM_ACTUALS. */
2266 for (p = actparms, num_actuals = 0; p; p = TREE_CHAIN (p))
2267 num_actuals++;
2269 /* Compute number of named args.
2270 Normally, don't include the last named arg if anonymous args follow.
2271 We do include the last named arg if STRICT_ARGUMENT_NAMING is nonzero.
2272 (If no anonymous args follow, the result of list_length is actually
2273 one too large. This is harmless.)
2275 If PRETEND_OUTGOING_VARARGS_NAMED is set and STRICT_ARGUMENT_NAMING is
2276 zero, this machine will be able to place unnamed args that were
2277 passed in registers into the stack. So treat all args as named.
2278 This allows the insns emitting for a specific argument list to be
2279 independent of the function declaration.
2281 If PRETEND_OUTGOING_VARARGS_NAMED is not set, we do not have any
2282 reliable way to pass unnamed args in registers, so we must force
2283 them into memory. */
2285 if ((STRICT_ARGUMENT_NAMING
2286 || ! PRETEND_OUTGOING_VARARGS_NAMED)
2287 && type_arg_types != 0)
2288 n_named_args
2289 = (list_length (type_arg_types)
2290 /* Don't include the last named arg. */
2291 - (STRICT_ARGUMENT_NAMING ? 0 : 1)
2292 /* Count the struct value address, if it is passed as a parm. */
2293 + structure_value_addr_parm);
2294 else
2295 /* If we know nothing, treat all args as named. */
2296 n_named_args = num_actuals;
2298 /* Start updating where the next arg would go.
2300 On some machines (such as the PA) indirect calls have a different
2301 calling convention than normal calls. The last argument in
2302 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2303 or not. */
2304 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, fndecl);
2306 /* Make a vector to hold all the information about each arg. */
2307 args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
2308 memset ((char *) args, 0, num_actuals * sizeof (struct arg_data));
2310 /* Build up entries in the ARGS array, compute the size of the
2311 arguments into ARGS_SIZE, etc. */
2312 initialize_argument_information (num_actuals, args, &args_size,
2313 n_named_args, actparms, fndecl,
2314 &args_so_far, reg_parm_stack_space,
2315 &old_stack_level, &old_pending_adj,
2316 &must_preallocate, &flags);
2318 if (args_size.var)
2320 /* If this function requires a variable-sized argument list, don't
2321 try to make a cse'able block for this call. We may be able to
2322 do this eventually, but it is too complicated to keep track of
2323 what insns go in the cse'able block and which don't. */
2325 flags &= ~ECF_LIBCALL_BLOCK;
2326 must_preallocate = 1;
2329 /* Now make final decision about preallocating stack space. */
2330 must_preallocate = finalize_must_preallocate (must_preallocate,
2331 num_actuals, args,
2332 &args_size);
2334 /* If the structure value address will reference the stack pointer, we
2335 must stabilize it. We don't need to do this if we know that we are
2336 not going to adjust the stack pointer in processing this call. */
2338 if (structure_value_addr
2339 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
2340 || reg_mentioned_p (virtual_outgoing_args_rtx,
2341 structure_value_addr))
2342 && (args_size.var
2343 || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant)))
2344 structure_value_addr = copy_to_reg (structure_value_addr);
2346 /* Tail calls can make things harder to debug, and we're traditionally
2347 pushed these optimizations into -O2. Don't try if we're already
2348 expanding a call, as that means we're an argument. Don't try if
2349 there's cleanups, as we know there's code to follow the call.
2351 If rtx_equal_function_value_matters is false, that means we've
2352 finished with regular parsing. Which means that some of the
2353 machinery we use to generate tail-calls is no longer in place.
2354 This is most often true of sjlj-exceptions, which we couldn't
2355 tail-call to anyway. */
2357 if (currently_expanding_call++ != 0
2358 || !flag_optimize_sibling_calls
2359 || !rtx_equal_function_value_matters
2360 || any_pending_cleanups ()
2361 || args_size.var)
2362 try_tail_call = try_tail_recursion = 0;
2364 /* Tail recursion fails, when we are not dealing with recursive calls. */
2365 if (!try_tail_recursion
2366 || TREE_CODE (addr) != ADDR_EXPR
2367 || TREE_OPERAND (addr, 0) != current_function_decl)
2368 try_tail_recursion = 0;
2370 /* Rest of purposes for tail call optimizations to fail. */
2371 if (
2372 #ifdef HAVE_sibcall_epilogue
2373 !HAVE_sibcall_epilogue
2374 #else
2376 #endif
2377 || !try_tail_call
2378 /* Doing sibling call optimization needs some work, since
2379 structure_value_addr can be allocated on the stack.
2380 It does not seem worth the effort since few optimizable
2381 sibling calls will return a structure. */
2382 || structure_value_addr != NULL_RTX
2383 /* Check whether the target is able to optimize the call
2384 into a sibcall. */
2385 || !(*targetm.function_ok_for_sibcall) (fndecl, exp)
2386 /* Functions that do not return exactly once may not be sibcall
2387 optimized. */
2388 || (flags & (ECF_RETURNS_TWICE | ECF_LONGJMP | ECF_NORETURN))
2389 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr)))
2390 /* If the called function is nested in the current one, it might access
2391 some of the caller's arguments, but could clobber them beforehand if
2392 the argument areas are shared. */
2393 || (fndecl && decl_function_context (fndecl) == current_function_decl)
2394 /* If this function requires more stack slots than the current
2395 function, we cannot change it into a sibling call. */
2396 || args_size.constant > current_function_args_size
2397 /* If the callee pops its own arguments, then it must pop exactly
2398 the same number of arguments as the current function. */
2399 || (RETURN_POPS_ARGS (fndecl, funtype, args_size.constant)
2400 != RETURN_POPS_ARGS (current_function_decl,
2401 TREE_TYPE (current_function_decl),
2402 current_function_args_size))
2403 || !(*lang_hooks.decls.ok_for_sibcall) (fndecl))
2404 try_tail_call = 0;
2406 if (try_tail_call || try_tail_recursion)
2408 int end, inc;
2409 actparms = NULL_TREE;
2410 /* Ok, we're going to give the tail call the old college try.
2411 This means we're going to evaluate the function arguments
2412 up to three times. There are two degrees of badness we can
2413 encounter, those that can be unsaved and those that can't.
2414 (See unsafe_for_reeval commentary for details.)
2416 Generate a new argument list. Pass safe arguments through
2417 unchanged. For the easy badness wrap them in UNSAVE_EXPRs.
2418 For hard badness, evaluate them now and put their resulting
2419 rtx in a temporary VAR_DECL.
2421 initialize_argument_information has ordered the array for the
2422 order to be pushed, and we must remember this when reconstructing
2423 the original argument order. */
2425 if (PUSH_ARGS_REVERSED)
2427 inc = 1;
2428 i = 0;
2429 end = num_actuals;
2431 else
2433 inc = -1;
2434 i = num_actuals - 1;
2435 end = -1;
2438 for (; i != end; i += inc)
2440 args[i].tree_value = fix_unsafe_tree (args[i].tree_value);
2441 /* We need to build actparms for optimize_tail_recursion. We can
2442 safely trash away TREE_PURPOSE, since it is unused by this
2443 function. */
2444 if (try_tail_recursion)
2445 actparms = tree_cons (NULL_TREE, args[i].tree_value, actparms);
2447 /* Do the same for the function address if it is an expression. */
2448 if (!fndecl)
2449 addr = fix_unsafe_tree (addr);
2450 /* Expanding one of those dangerous arguments could have added
2451 cleanups, but otherwise give it a whirl. */
2452 if (any_pending_cleanups ())
2453 try_tail_call = try_tail_recursion = 0;
2456 /* Generate a tail recursion sequence when calling ourselves. */
2458 if (try_tail_recursion)
2460 /* We want to emit any pending stack adjustments before the tail
2461 recursion "call". That way we know any adjustment after the tail
2462 recursion call can be ignored if we indeed use the tail recursion
2463 call expansion. */
2464 int save_pending_stack_adjust = pending_stack_adjust;
2465 int save_stack_pointer_delta = stack_pointer_delta;
2467 /* Emit any queued insns now; otherwise they would end up in
2468 only one of the alternates. */
2469 emit_queue ();
2471 /* Use a new sequence to hold any RTL we generate. We do not even
2472 know if we will use this RTL yet. The final decision can not be
2473 made until after RTL generation for the entire function is
2474 complete. */
2475 start_sequence ();
2476 /* If expanding any of the arguments creates cleanups, we can't
2477 do a tailcall. So, we'll need to pop the pending cleanups
2478 list. If, however, all goes well, and there are no cleanups
2479 then the call to expand_start_target_temps will have no
2480 effect. */
2481 expand_start_target_temps ();
2482 if (optimize_tail_recursion (actparms, get_last_insn ()))
2484 if (any_pending_cleanups ())
2485 try_tail_call = try_tail_recursion = 0;
2486 else
2487 tail_recursion_insns = get_insns ();
2489 expand_end_target_temps ();
2490 end_sequence ();
2492 /* Restore the original pending stack adjustment for the sibling and
2493 normal call cases below. */
2494 pending_stack_adjust = save_pending_stack_adjust;
2495 stack_pointer_delta = save_stack_pointer_delta;
2498 if (profile_arc_flag && (flags & ECF_FORK_OR_EXEC))
2500 /* A fork duplicates the profile information, and an exec discards
2501 it. We can't rely on fork/exec to be paired. So write out the
2502 profile information we have gathered so far, and clear it. */
2503 /* ??? When Linux's __clone is called with CLONE_VM set, profiling
2504 is subject to race conditions, just as with multithreaded
2505 programs. */
2507 emit_library_call (gcov_flush_libfunc, LCT_ALWAYS_RETURN, VOIDmode, 0);
2510 /* Ensure current function's preferred stack boundary is at least
2511 what we need. We don't have to increase alignment for recursive
2512 functions. */
2513 if (cfun->preferred_stack_boundary < preferred_stack_boundary
2514 && fndecl != current_function_decl)
2515 cfun->preferred_stack_boundary = preferred_stack_boundary;
2516 if (fndecl == current_function_decl)
2517 cfun->recursive_call_emit = true;
2519 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
2521 function_call_count++;
2523 /* We want to make two insn chains; one for a sibling call, the other
2524 for a normal call. We will select one of the two chains after
2525 initial RTL generation is complete. */
2526 for (pass = try_tail_call ? 0 : 1; pass < 2; pass++)
2528 int sibcall_failure = 0;
2529 /* We want to emit any pending stack adjustments before the tail
2530 recursion "call". That way we know any adjustment after the tail
2531 recursion call can be ignored if we indeed use the tail recursion
2532 call expansion. */
2533 int save_pending_stack_adjust = 0;
2534 int save_stack_pointer_delta = 0;
2535 rtx insns;
2536 rtx before_call, next_arg_reg;
2538 if (pass == 0)
2540 /* Emit any queued insns now; otherwise they would end up in
2541 only one of the alternates. */
2542 emit_queue ();
2544 /* State variables we need to save and restore between
2545 iterations. */
2546 save_pending_stack_adjust = pending_stack_adjust;
2547 save_stack_pointer_delta = stack_pointer_delta;
2549 if (pass)
2550 flags &= ~ECF_SIBCALL;
2551 else
2552 flags |= ECF_SIBCALL;
2554 /* Other state variables that we must reinitialize each time
2555 through the loop (that are not initialized by the loop itself). */
2556 argblock = 0;
2557 call_fusage = 0;
2559 /* Start a new sequence for the normal call case.
2561 From this point on, if the sibling call fails, we want to set
2562 sibcall_failure instead of continuing the loop. */
2563 start_sequence ();
2565 if (pass == 0)
2567 /* We know at this point that there are not currently any
2568 pending cleanups. If, however, in the process of evaluating
2569 the arguments we were to create some, we'll need to be
2570 able to get rid of them. */
2571 expand_start_target_temps ();
2574 /* Don't let pending stack adjusts add up to too much.
2575 Also, do all pending adjustments now if there is any chance
2576 this might be a call to alloca or if we are expanding a sibling
2577 call sequence or if we are calling a function that is to return
2578 with stack pointer depressed. */
2579 if (pending_stack_adjust >= 32
2580 || (pending_stack_adjust > 0
2581 && (flags & (ECF_MAY_BE_ALLOCA | ECF_SP_DEPRESSED)))
2582 || pass == 0)
2583 do_pending_stack_adjust ();
2585 /* When calling a const function, we must pop the stack args right away,
2586 so that the pop is deleted or moved with the call. */
2587 if (pass && (flags & ECF_LIBCALL_BLOCK))
2588 NO_DEFER_POP;
2590 #ifdef FINAL_REG_PARM_STACK_SPACE
2591 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2592 args_size.var);
2593 #endif
2594 /* Precompute any arguments as needed. */
2595 if (pass)
2596 precompute_arguments (flags, num_actuals, args);
2598 /* Now we are about to start emitting insns that can be deleted
2599 if a libcall is deleted. */
2600 if (pass && (flags & (ECF_LIBCALL_BLOCK | ECF_MALLOC)))
2601 start_sequence ();
2603 adjusted_args_size = args_size;
2604 /* Compute the actual size of the argument block required. The variable
2605 and constant sizes must be combined, the size may have to be rounded,
2606 and there may be a minimum required size. When generating a sibcall
2607 pattern, do not round up, since we'll be re-using whatever space our
2608 caller provided. */
2609 unadjusted_args_size
2610 = compute_argument_block_size (reg_parm_stack_space,
2611 &adjusted_args_size,
2612 (pass == 0 ? 0
2613 : preferred_stack_boundary));
2615 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
2617 /* The argument block when performing a sibling call is the
2618 incoming argument block. */
2619 if (pass == 0)
2621 argblock = virtual_incoming_args_rtx;
2622 argblock
2623 #ifdef STACK_GROWS_DOWNWARD
2624 = plus_constant (argblock, current_function_pretend_args_size);
2625 #else
2626 = plus_constant (argblock, -current_function_pretend_args_size);
2627 #endif
2628 stored_args_map = sbitmap_alloc (args_size.constant);
2629 sbitmap_zero (stored_args_map);
2632 /* If we have no actual push instructions, or shouldn't use them,
2633 make space for all args right now. */
2634 else if (adjusted_args_size.var != 0)
2636 if (old_stack_level == 0)
2638 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
2639 old_stack_pointer_delta = stack_pointer_delta;
2640 old_pending_adj = pending_stack_adjust;
2641 pending_stack_adjust = 0;
2642 /* stack_arg_under_construction says whether a stack arg is
2643 being constructed at the old stack level. Pushing the stack
2644 gets a clean outgoing argument block. */
2645 old_stack_arg_under_construction = stack_arg_under_construction;
2646 stack_arg_under_construction = 0;
2648 argblock = push_block (ARGS_SIZE_RTX (adjusted_args_size), 0, 0);
2650 else
2652 /* Note that we must go through the motions of allocating an argument
2653 block even if the size is zero because we may be storing args
2654 in the area reserved for register arguments, which may be part of
2655 the stack frame. */
2657 int needed = adjusted_args_size.constant;
2659 /* Store the maximum argument space used. It will be pushed by
2660 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2661 checking). */
2663 if (needed > current_function_outgoing_args_size)
2664 current_function_outgoing_args_size = needed;
2666 if (must_preallocate)
2668 if (ACCUMULATE_OUTGOING_ARGS)
2670 /* Since the stack pointer will never be pushed, it is
2671 possible for the evaluation of a parm to clobber
2672 something we have already written to the stack.
2673 Since most function calls on RISC machines do not use
2674 the stack, this is uncommon, but must work correctly.
2676 Therefore, we save any area of the stack that was already
2677 written and that we are using. Here we set up to do this
2678 by making a new stack usage map from the old one. The
2679 actual save will be done by store_one_arg.
2681 Another approach might be to try to reorder the argument
2682 evaluations to avoid this conflicting stack usage. */
2684 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2685 /* Since we will be writing into the entire argument area,
2686 the map must be allocated for its entire size, not just
2687 the part that is the responsibility of the caller. */
2688 needed += reg_parm_stack_space;
2689 #endif
2691 #ifdef ARGS_GROW_DOWNWARD
2692 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2693 needed + 1);
2694 #else
2695 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2696 needed);
2697 #endif
2698 stack_usage_map
2699 = (char *) alloca (highest_outgoing_arg_in_use);
2701 if (initial_highest_arg_in_use)
2702 memcpy (stack_usage_map, initial_stack_usage_map,
2703 initial_highest_arg_in_use);
2705 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2706 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
2707 (highest_outgoing_arg_in_use
2708 - initial_highest_arg_in_use));
2709 needed = 0;
2711 /* The address of the outgoing argument list must not be
2712 copied to a register here, because argblock would be left
2713 pointing to the wrong place after the call to
2714 allocate_dynamic_stack_space below. */
2716 argblock = virtual_outgoing_args_rtx;
2718 else
2720 if (inhibit_defer_pop == 0)
2722 /* Try to reuse some or all of the pending_stack_adjust
2723 to get this space. */
2724 needed
2725 = (combine_pending_stack_adjustment_and_call
2726 (unadjusted_args_size,
2727 &adjusted_args_size,
2728 preferred_unit_stack_boundary));
2730 /* combine_pending_stack_adjustment_and_call computes
2731 an adjustment before the arguments are allocated.
2732 Account for them and see whether or not the stack
2733 needs to go up or down. */
2734 needed = unadjusted_args_size - needed;
2736 if (needed < 0)
2738 /* We're releasing stack space. */
2739 /* ??? We can avoid any adjustment at all if we're
2740 already aligned. FIXME. */
2741 pending_stack_adjust = -needed;
2742 do_pending_stack_adjust ();
2743 needed = 0;
2745 else
2746 /* We need to allocate space. We'll do that in
2747 push_block below. */
2748 pending_stack_adjust = 0;
2751 /* Special case this because overhead of `push_block' in
2752 this case is non-trivial. */
2753 if (needed == 0)
2754 argblock = virtual_outgoing_args_rtx;
2755 else
2757 argblock = push_block (GEN_INT (needed), 0, 0);
2758 #ifdef ARGS_GROW_DOWNWARD
2759 argblock = plus_constant (argblock, needed);
2760 #endif
2763 /* We only really need to call `copy_to_reg' in the case
2764 where push insns are going to be used to pass ARGBLOCK
2765 to a function call in ARGS. In that case, the stack
2766 pointer changes value from the allocation point to the
2767 call point, and hence the value of
2768 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
2769 as well always do it. */
2770 argblock = copy_to_reg (argblock);
2775 if (ACCUMULATE_OUTGOING_ARGS)
2777 /* The save/restore code in store_one_arg handles all
2778 cases except one: a constructor call (including a C
2779 function returning a BLKmode struct) to initialize
2780 an argument. */
2781 if (stack_arg_under_construction)
2783 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2784 rtx push_size = GEN_INT (reg_parm_stack_space
2785 + adjusted_args_size.constant);
2786 #else
2787 rtx push_size = GEN_INT (adjusted_args_size.constant);
2788 #endif
2789 if (old_stack_level == 0)
2791 emit_stack_save (SAVE_BLOCK, &old_stack_level,
2792 NULL_RTX);
2793 old_stack_pointer_delta = stack_pointer_delta;
2794 old_pending_adj = pending_stack_adjust;
2795 pending_stack_adjust = 0;
2796 /* stack_arg_under_construction says whether a stack
2797 arg is being constructed at the old stack level.
2798 Pushing the stack gets a clean outgoing argument
2799 block. */
2800 old_stack_arg_under_construction
2801 = stack_arg_under_construction;
2802 stack_arg_under_construction = 0;
2803 /* Make a new map for the new argument list. */
2804 stack_usage_map = (char *)
2805 alloca (highest_outgoing_arg_in_use);
2806 memset (stack_usage_map, 0, highest_outgoing_arg_in_use);
2807 highest_outgoing_arg_in_use = 0;
2809 allocate_dynamic_stack_space (push_size, NULL_RTX,
2810 BITS_PER_UNIT);
2813 /* If argument evaluation might modify the stack pointer,
2814 copy the address of the argument list to a register. */
2815 for (i = 0; i < num_actuals; i++)
2816 if (args[i].pass_on_stack)
2818 argblock = copy_addr_to_reg (argblock);
2819 break;
2823 compute_argument_addresses (args, argblock, num_actuals);
2825 /* If we push args individually in reverse order, perform stack alignment
2826 before the first push (the last arg). */
2827 if (PUSH_ARGS_REVERSED && argblock == 0
2828 && adjusted_args_size.constant != unadjusted_args_size)
2830 /* When the stack adjustment is pending, we get better code
2831 by combining the adjustments. */
2832 if (pending_stack_adjust
2833 && ! (flags & ECF_LIBCALL_BLOCK)
2834 && ! inhibit_defer_pop)
2836 pending_stack_adjust
2837 = (combine_pending_stack_adjustment_and_call
2838 (unadjusted_args_size,
2839 &adjusted_args_size,
2840 preferred_unit_stack_boundary));
2841 do_pending_stack_adjust ();
2843 else if (argblock == 0)
2844 anti_adjust_stack (GEN_INT (adjusted_args_size.constant
2845 - unadjusted_args_size));
2847 /* Now that the stack is properly aligned, pops can't safely
2848 be deferred during the evaluation of the arguments. */
2849 NO_DEFER_POP;
2851 funexp = rtx_for_function_call (fndecl, addr);
2853 /* Figure out the register where the value, if any, will come back. */
2854 valreg = 0;
2855 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
2856 && ! structure_value_addr)
2858 if (pcc_struct_value)
2859 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
2860 fndecl, (pass == 0));
2861 else
2862 valreg = hard_function_value (TREE_TYPE (exp), fndecl, (pass == 0));
2865 /* Precompute all register parameters. It isn't safe to compute anything
2866 once we have started filling any specific hard regs. */
2867 precompute_register_parameters (num_actuals, args, &reg_parm_seen);
2869 #ifdef REG_PARM_STACK_SPACE
2870 /* Save the fixed argument area if it's part of the caller's frame and
2871 is clobbered by argument setup for this call. */
2872 if (ACCUMULATE_OUTGOING_ARGS && pass)
2873 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
2874 &low_to_save, &high_to_save);
2875 #endif
2877 /* Now store (and compute if necessary) all non-register parms.
2878 These come before register parms, since they can require block-moves,
2879 which could clobber the registers used for register parms.
2880 Parms which have partial registers are not stored here,
2881 but we do preallocate space here if they want that. */
2883 for (i = 0; i < num_actuals; i++)
2884 if (args[i].reg == 0 || args[i].pass_on_stack)
2886 rtx before_arg = get_last_insn ();
2888 if (store_one_arg (&args[i], argblock, flags,
2889 adjusted_args_size.var != 0,
2890 reg_parm_stack_space)
2891 || (pass == 0
2892 && check_sibcall_argument_overlap (before_arg,
2893 &args[i], 1)))
2894 sibcall_failure = 1;
2897 /* If we have a parm that is passed in registers but not in memory
2898 and whose alignment does not permit a direct copy into registers,
2899 make a group of pseudos that correspond to each register that we
2900 will later fill. */
2901 if (STRICT_ALIGNMENT)
2902 store_unaligned_arguments_into_pseudos (args, num_actuals);
2904 /* Now store any partially-in-registers parm.
2905 This is the last place a block-move can happen. */
2906 if (reg_parm_seen)
2907 for (i = 0; i < num_actuals; i++)
2908 if (args[i].partial != 0 && ! args[i].pass_on_stack)
2910 rtx before_arg = get_last_insn ();
2912 if (store_one_arg (&args[i], argblock, flags,
2913 adjusted_args_size.var != 0,
2914 reg_parm_stack_space)
2915 || (pass == 0
2916 && check_sibcall_argument_overlap (before_arg,
2917 &args[i], 1)))
2918 sibcall_failure = 1;
2921 /* If we pushed args in forward order, perform stack alignment
2922 after pushing the last arg. */
2923 if (!PUSH_ARGS_REVERSED && argblock == 0)
2924 anti_adjust_stack (GEN_INT (adjusted_args_size.constant
2925 - unadjusted_args_size));
2927 /* If register arguments require space on the stack and stack space
2928 was not preallocated, allocate stack space here for arguments
2929 passed in registers. */
2930 #ifdef OUTGOING_REG_PARM_STACK_SPACE
2931 if (!ACCUMULATE_OUTGOING_ARGS
2932 && must_preallocate == 0 && reg_parm_stack_space > 0)
2933 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
2934 #endif
2936 /* Pass the function the address in which to return a
2937 structure value. */
2938 if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
2940 #ifdef POINTERS_EXTEND_UNSIGNED
2941 if (GET_MODE (structure_value_addr) != Pmode)
2942 structure_value_addr = convert_memory_address
2943 (Pmode, structure_value_addr);
2944 #endif
2945 emit_move_insn (struct_value_rtx,
2946 force_reg (Pmode,
2947 force_operand (structure_value_addr,
2948 NULL_RTX)));
2950 if (GET_CODE (struct_value_rtx) == REG)
2951 use_reg (&call_fusage, struct_value_rtx);
2954 funexp = prepare_call_address (funexp, fndecl, &call_fusage,
2955 reg_parm_seen, pass == 0);
2957 load_register_parameters (args, num_actuals, &call_fusage, flags,
2958 pass == 0, &sibcall_failure);
2960 /* Perform postincrements before actually calling the function. */
2961 emit_queue ();
2963 /* Save a pointer to the last insn before the call, so that we can
2964 later safely search backwards to find the CALL_INSN. */
2965 before_call = get_last_insn ();
2967 /* Set up next argument register. For sibling calls on machines
2968 with register windows this should be the incoming register. */
2969 #ifdef FUNCTION_INCOMING_ARG
2970 if (pass == 0)
2971 next_arg_reg = FUNCTION_INCOMING_ARG (args_so_far, VOIDmode,
2972 void_type_node, 1);
2973 else
2974 #endif
2975 next_arg_reg = FUNCTION_ARG (args_so_far, VOIDmode,
2976 void_type_node, 1);
2978 /* All arguments and registers used for the call must be set up by
2979 now! */
2981 /* Stack must be properly aligned now. */
2982 if (pass && stack_pointer_delta % preferred_unit_stack_boundary)
2983 abort ();
2985 /* Generate the actual call instruction. */
2986 emit_call_1 (funexp, fndecl, funtype, unadjusted_args_size,
2987 adjusted_args_size.constant, struct_value_size,
2988 next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
2989 flags, & args_so_far);
2991 /* If call is cse'able, make appropriate pair of reg-notes around it.
2992 Test valreg so we don't crash; may safely ignore `const'
2993 if return type is void. Disable for PARALLEL return values, because
2994 we have no way to move such values into a pseudo register. */
2995 if (pass && (flags & ECF_LIBCALL_BLOCK))
2997 rtx insns;
2999 if (valreg == 0 || GET_CODE (valreg) == PARALLEL)
3001 insns = get_insns ();
3002 end_sequence ();
3003 emit_insn (insns);
3005 else
3007 rtx note = 0;
3008 rtx temp = gen_reg_rtx (GET_MODE (valreg));
3010 /* Mark the return value as a pointer if needed. */
3011 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
3012 mark_reg_pointer (temp,
3013 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp))));
3015 /* Construct an "equal form" for the value which mentions all the
3016 arguments in order as well as the function name. */
3017 for (i = 0; i < num_actuals; i++)
3018 note = gen_rtx_EXPR_LIST (VOIDmode,
3019 args[i].initial_value, note);
3020 note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
3022 insns = get_insns ();
3023 end_sequence ();
3025 if (flags & ECF_PURE)
3026 note = gen_rtx_EXPR_LIST (VOIDmode,
3027 gen_rtx_USE (VOIDmode,
3028 gen_rtx_MEM (BLKmode,
3029 gen_rtx_SCRATCH (VOIDmode))),
3030 note);
3032 emit_libcall_block (insns, temp, valreg, note);
3034 valreg = temp;
3037 else if (pass && (flags & ECF_MALLOC))
3039 rtx temp = gen_reg_rtx (GET_MODE (valreg));
3040 rtx last, insns;
3042 /* The return value from a malloc-like function is a pointer. */
3043 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
3044 mark_reg_pointer (temp, BIGGEST_ALIGNMENT);
3046 emit_move_insn (temp, valreg);
3048 /* The return value from a malloc-like function can not alias
3049 anything else. */
3050 last = get_last_insn ();
3051 REG_NOTES (last) =
3052 gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));
3054 /* Write out the sequence. */
3055 insns = get_insns ();
3056 end_sequence ();
3057 emit_insn (insns);
3058 valreg = temp;
3061 /* For calls to `setjmp', etc., inform flow.c it should complain
3062 if nonvolatile values are live. For functions that cannot return,
3063 inform flow that control does not fall through. */
3065 if ((flags & (ECF_NORETURN | ECF_LONGJMP)) || pass == 0)
3067 /* The barrier must be emitted
3068 immediately after the CALL_INSN. Some ports emit more
3069 than just a CALL_INSN above, so we must search for it here. */
3071 rtx last = get_last_insn ();
3072 while (GET_CODE (last) != CALL_INSN)
3074 last = PREV_INSN (last);
3075 /* There was no CALL_INSN? */
3076 if (last == before_call)
3077 abort ();
3080 emit_barrier_after (last);
3082 /* Stack adjustments after a noreturn call are dead code. */
3083 stack_pointer_delta = old_stack_allocated;
3084 pending_stack_adjust = 0;
3087 if (flags & ECF_LONGJMP)
3088 current_function_calls_longjmp = 1;
3090 /* If value type not void, return an rtx for the value. */
3092 /* If there are cleanups to be called, don't use a hard reg as target.
3093 We need to double check this and see if it matters anymore. */
3094 if (any_pending_cleanups ())
3096 if (target && REG_P (target)
3097 && REGNO (target) < FIRST_PSEUDO_REGISTER)
3098 target = 0;
3099 sibcall_failure = 1;
3102 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
3103 || ignore)
3104 target = const0_rtx;
3105 else if (structure_value_addr)
3107 if (target == 0 || GET_CODE (target) != MEM)
3109 target
3110 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3111 memory_address (TYPE_MODE (TREE_TYPE (exp)),
3112 structure_value_addr));
3113 set_mem_attributes (target, exp, 1);
3116 else if (pcc_struct_value)
3118 /* This is the special C++ case where we need to
3119 know what the true target was. We take care to
3120 never use this value more than once in one expression. */
3121 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3122 copy_to_reg (valreg));
3123 set_mem_attributes (target, exp, 1);
3125 /* Handle calls that return values in multiple non-contiguous locations.
3126 The Irix 6 ABI has examples of this. */
3127 else if (GET_CODE (valreg) == PARALLEL)
3129 if (target == 0)
3131 /* This will only be assigned once, so it can be readonly. */
3132 tree nt = build_qualified_type (TREE_TYPE (exp),
3133 (TYPE_QUALS (TREE_TYPE (exp))
3134 | TYPE_QUAL_CONST));
3136 target = assign_temp (nt, 0, 1, 1);
3137 preserve_temp_slots (target);
3140 if (! rtx_equal_p (target, valreg))
3141 emit_group_store (target, valreg,
3142 int_size_in_bytes (TREE_TYPE (exp)));
3144 /* We can not support sibling calls for this case. */
3145 sibcall_failure = 1;
3147 else if (target
3148 && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
3149 && GET_MODE (target) == GET_MODE (valreg))
3151 /* TARGET and VALREG cannot be equal at this point because the
3152 latter would not have REG_FUNCTION_VALUE_P true, while the
3153 former would if it were referring to the same register.
3155 If they refer to the same register, this move will be a no-op,
3156 except when function inlining is being done. */
3157 emit_move_insn (target, valreg);
3159 /* If we are setting a MEM, this code must be executed. Since it is
3160 emitted after the call insn, sibcall optimization cannot be
3161 performed in that case. */
3162 if (GET_CODE (target) == MEM)
3163 sibcall_failure = 1;
3165 else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
3167 target = copy_blkmode_from_reg (target, valreg, TREE_TYPE (exp));
3169 /* We can not support sibling calls for this case. */
3170 sibcall_failure = 1;
3172 else
3173 target = copy_to_reg (valreg);
3175 #ifdef PROMOTE_FUNCTION_RETURN
3176 /* If we promoted this return value, make the proper SUBREG. TARGET
3177 might be const0_rtx here, so be careful. */
3178 if (GET_CODE (target) == REG
3179 && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
3180 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
3182 tree type = TREE_TYPE (exp);
3183 int unsignedp = TREE_UNSIGNED (type);
3184 int offset = 0;
3186 /* If we don't promote as expected, something is wrong. */
3187 if (GET_MODE (target)
3188 != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
3189 abort ();
3191 if ((WORDS_BIG_ENDIAN || BYTES_BIG_ENDIAN)
3192 && GET_MODE_SIZE (GET_MODE (target))
3193 > GET_MODE_SIZE (TYPE_MODE (type)))
3195 offset = GET_MODE_SIZE (GET_MODE (target))
3196 - GET_MODE_SIZE (TYPE_MODE (type));
3197 if (! BYTES_BIG_ENDIAN)
3198 offset = (offset / UNITS_PER_WORD) * UNITS_PER_WORD;
3199 else if (! WORDS_BIG_ENDIAN)
3200 offset %= UNITS_PER_WORD;
3202 target = gen_rtx_SUBREG (TYPE_MODE (type), target, offset);
3203 SUBREG_PROMOTED_VAR_P (target) = 1;
3204 SUBREG_PROMOTED_UNSIGNED_SET (target, unsignedp);
3206 #endif
3208 /* If size of args is variable or this was a constructor call for a stack
3209 argument, restore saved stack-pointer value. */
3211 if (old_stack_level && ! (flags & ECF_SP_DEPRESSED))
3213 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
3214 stack_pointer_delta = old_stack_pointer_delta;
3215 pending_stack_adjust = old_pending_adj;
3216 stack_arg_under_construction = old_stack_arg_under_construction;
3217 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3218 stack_usage_map = initial_stack_usage_map;
3219 sibcall_failure = 1;
3221 else if (ACCUMULATE_OUTGOING_ARGS && pass)
3223 #ifdef REG_PARM_STACK_SPACE
3224 if (save_area)
3225 restore_fixed_argument_area (save_area, argblock,
3226 high_to_save, low_to_save);
3227 #endif
3229 /* If we saved any argument areas, restore them. */
3230 for (i = 0; i < num_actuals; i++)
3231 if (args[i].save_area)
3233 enum machine_mode save_mode = GET_MODE (args[i].save_area);
3234 rtx stack_area
3235 = gen_rtx_MEM (save_mode,
3236 memory_address (save_mode,
3237 XEXP (args[i].stack_slot, 0)));
3239 if (save_mode != BLKmode)
3240 emit_move_insn (stack_area, args[i].save_area);
3241 else
3242 emit_block_move (stack_area, args[i].save_area,
3243 GEN_INT (args[i].locate.size.constant),
3244 BLOCK_OP_CALL_PARM);
3247 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3248 stack_usage_map = initial_stack_usage_map;
3251 /* If this was alloca, record the new stack level for nonlocal gotos.
3252 Check for the handler slots since we might not have a save area
3253 for non-local gotos. */
3255 if ((flags & ECF_MAY_BE_ALLOCA) && nonlocal_goto_handler_slots != 0)
3256 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
3258 /* Free up storage we no longer need. */
3259 for (i = 0; i < num_actuals; ++i)
3260 if (args[i].aligned_regs)
3261 free (args[i].aligned_regs);
3263 if (pass == 0)
3265 /* Undo the fake expand_start_target_temps we did earlier. If
3266 there had been any cleanups created, we've already set
3267 sibcall_failure. */
3268 expand_end_target_temps ();
3271 /* If this function is returning into a memory location marked as
3272 readonly, it means it is initializing that location. We normally treat
3273 functions as not clobbering such locations, so we need to specify that
3274 this one does. We do this by adding the appropriate CLOBBER to the
3275 CALL_INSN function usage list. This cannot be done by emitting a
3276 standalone CLOBBER after the call because the latter would be ignored
3277 by at least the delay slot scheduling pass. We do this now instead of
3278 adding to call_fusage before the call to emit_call_1 because TARGET
3279 may be modified in the meantime. */
3280 if (structure_value_addr != 0 && target != 0
3281 && GET_CODE (target) == MEM && RTX_UNCHANGING_P (target))
3282 add_function_usage_to
3283 (last_call_insn (),
3284 gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_CLOBBER (VOIDmode, target),
3285 NULL_RTX));
3287 insns = get_insns ();
3288 end_sequence ();
3290 if (pass == 0)
3292 tail_call_insns = insns;
3294 /* Restore the pending stack adjustment now that we have
3295 finished generating the sibling call sequence. */
3297 pending_stack_adjust = save_pending_stack_adjust;
3298 stack_pointer_delta = save_stack_pointer_delta;
3300 /* Prepare arg structure for next iteration. */
3301 for (i = 0; i < num_actuals; i++)
3303 args[i].value = 0;
3304 args[i].aligned_regs = 0;
3305 args[i].stack = 0;
3308 sbitmap_free (stored_args_map);
3310 else
3312 normal_call_insns = insns;
3314 /* Verify that we've deallocated all the stack we used. */
3315 if (! (flags & (ECF_NORETURN | ECF_LONGJMP))
3316 && old_stack_allocated != stack_pointer_delta
3317 - pending_stack_adjust)
3318 abort ();
3321 /* If something prevents making this a sibling call,
3322 zero out the sequence. */
3323 if (sibcall_failure)
3324 tail_call_insns = NULL_RTX;
3327 /* The function optimize_sibling_and_tail_recursive_calls doesn't
3328 handle CALL_PLACEHOLDERs inside other CALL_PLACEHOLDERs. This
3329 can happen if the arguments to this function call an inline
3330 function who's expansion contains another CALL_PLACEHOLDER.
3332 If there are any C_Ps in any of these sequences, replace them
3333 with their normal call. */
3335 for (insn = normal_call_insns; insn; insn = NEXT_INSN (insn))
3336 if (GET_CODE (insn) == CALL_INSN
3337 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
3338 replace_call_placeholder (insn, sibcall_use_normal);
3340 for (insn = tail_call_insns; insn; insn = NEXT_INSN (insn))
3341 if (GET_CODE (insn) == CALL_INSN
3342 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
3343 replace_call_placeholder (insn, sibcall_use_normal);
3345 for (insn = tail_recursion_insns; insn; insn = NEXT_INSN (insn))
3346 if (GET_CODE (insn) == CALL_INSN
3347 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
3348 replace_call_placeholder (insn, sibcall_use_normal);
3350 /* If this was a potential tail recursion site, then emit a
3351 CALL_PLACEHOLDER with the normal and the tail recursion streams.
3352 One of them will be selected later. */
3353 if (tail_recursion_insns || tail_call_insns)
3355 /* The tail recursion label must be kept around. We could expose
3356 its use in the CALL_PLACEHOLDER, but that creates unwanted edges
3357 and makes determining true tail recursion sites difficult.
3359 So we set LABEL_PRESERVE_P here, then clear it when we select
3360 one of the call sequences after rtl generation is complete. */
3361 if (tail_recursion_insns)
3362 LABEL_PRESERVE_P (tail_recursion_label) = 1;
3363 emit_call_insn (gen_rtx_CALL_PLACEHOLDER (VOIDmode, normal_call_insns,
3364 tail_call_insns,
3365 tail_recursion_insns,
3366 tail_recursion_label));
3368 else
3369 emit_insn (normal_call_insns);
3371 currently_expanding_call--;
3373 /* If this function returns with the stack pointer depressed, ensure
3374 this block saves and restores the stack pointer, show it was
3375 changed, and adjust for any outgoing arg space. */
3376 if (flags & ECF_SP_DEPRESSED)
3378 clear_pending_stack_adjust ();
3379 emit_insn (gen_rtx (CLOBBER, VOIDmode, stack_pointer_rtx));
3380 emit_move_insn (virtual_stack_dynamic_rtx, stack_pointer_rtx);
3381 save_stack_pointer ();
3384 return target;
3387 /* Traverse an argument list in VALUES and expand all complex
3388 arguments into their components. */
3389 tree
3390 split_complex_values (tree values)
3392 tree p;
3394 values = copy_list (values);
3396 for (p = values; p; p = TREE_CHAIN (p))
3398 tree complex_value = TREE_VALUE (p);
3399 tree complex_type;
3401 complex_type = TREE_TYPE (complex_value);
3402 if (!complex_type)
3403 continue;
3405 if (TREE_CODE (complex_type) == COMPLEX_TYPE)
3407 tree subtype;
3408 tree real, imag, next;
3410 subtype = TREE_TYPE (complex_type);
3411 complex_value = save_expr (complex_value);
3412 real = build1 (REALPART_EXPR, subtype, complex_value);
3413 imag = build1 (IMAGPART_EXPR, subtype, complex_value);
3415 TREE_VALUE (p) = real;
3416 next = TREE_CHAIN (p);
3417 imag = build_tree_list (NULL_TREE, imag);
3418 TREE_CHAIN (p) = imag;
3419 TREE_CHAIN (imag) = next;
3421 /* Skip the newly created node. */
3422 p = TREE_CHAIN (p);
3426 return values;
3429 /* Traverse a list of TYPES and expand all complex types into their
3430 components. */
3431 tree
3432 split_complex_types (tree types)
3434 tree p;
3436 types = copy_list (types);
3438 for (p = types; p; p = TREE_CHAIN (p))
3440 tree complex_type = TREE_VALUE (p);
3442 if (TREE_CODE (complex_type) == COMPLEX_TYPE)
3444 tree next, imag;
3446 /* Rewrite complex type with component type. */
3447 TREE_VALUE (p) = TREE_TYPE (complex_type);
3448 next = TREE_CHAIN (p);
3450 /* Add another component type for the imaginary part. */
3451 imag = build_tree_list (NULL_TREE, TREE_VALUE (p));
3452 TREE_CHAIN (p) = imag;
3453 TREE_CHAIN (imag) = next;
3455 /* Skip the newly created node. */
3456 p = TREE_CHAIN (p);
3460 return types;
3463 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3464 The RETVAL parameter specifies whether return value needs to be saved, other
3465 parameters are documented in the emit_library_call function below. */
3467 static rtx
3468 emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
3469 enum libcall_type fn_type,
3470 enum machine_mode outmode, int nargs, va_list p)
3472 /* Total size in bytes of all the stack-parms scanned so far. */
3473 struct args_size args_size;
3474 /* Size of arguments before any adjustments (such as rounding). */
3475 struct args_size original_args_size;
3476 int argnum;
3477 rtx fun;
3478 int inc;
3479 int count;
3480 rtx argblock = 0;
3481 CUMULATIVE_ARGS args_so_far;
3482 struct arg
3484 rtx value;
3485 enum machine_mode mode;
3486 rtx reg;
3487 int partial;
3488 struct locate_and_pad_arg_data locate;
3489 rtx save_area;
3491 struct arg *argvec;
3492 int old_inhibit_defer_pop = inhibit_defer_pop;
3493 rtx call_fusage = 0;
3494 rtx mem_value = 0;
3495 rtx valreg;
3496 int pcc_struct_value = 0;
3497 int struct_value_size = 0;
3498 int flags;
3499 int reg_parm_stack_space = 0;
3500 int needed;
3501 rtx before_call;
3502 tree tfom; /* type_for_mode (outmode, 0) */
3504 #ifdef REG_PARM_STACK_SPACE
3505 /* Define the boundary of the register parm stack space that needs to be
3506 save, if any. */
3507 int low_to_save, high_to_save;
3508 rtx save_area = 0; /* Place that it is saved. */
3509 #endif
3511 /* Size of the stack reserved for parameter registers. */
3512 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3513 char *initial_stack_usage_map = stack_usage_map;
3515 #ifdef REG_PARM_STACK_SPACE
3516 #ifdef MAYBE_REG_PARM_STACK_SPACE
3517 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3518 #else
3519 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3520 #endif
3521 #endif
3523 /* By default, library functions can not throw. */
3524 flags = ECF_NOTHROW;
3526 switch (fn_type)
3528 case LCT_NORMAL:
3529 break;
3530 case LCT_CONST:
3531 flags |= ECF_CONST;
3532 break;
3533 case LCT_PURE:
3534 flags |= ECF_PURE;
3535 break;
3536 case LCT_CONST_MAKE_BLOCK:
3537 flags |= ECF_CONST | ECF_LIBCALL_BLOCK;
3538 break;
3539 case LCT_PURE_MAKE_BLOCK:
3540 flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
3541 break;
3542 case LCT_NORETURN:
3543 flags |= ECF_NORETURN;
3544 break;
3545 case LCT_THROW:
3546 flags = ECF_NORETURN;
3547 break;
3548 case LCT_ALWAYS_RETURN:
3549 flags = ECF_ALWAYS_RETURN;
3550 break;
3551 case LCT_RETURNS_TWICE:
3552 flags = ECF_RETURNS_TWICE;
3553 break;
3555 fun = orgfun;
3557 /* Ensure current function's preferred stack boundary is at least
3558 what we need. */
3559 if (cfun->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3560 cfun->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3562 /* If this kind of value comes back in memory,
3563 decide where in memory it should come back. */
3564 if (outmode != VOIDmode)
3566 tfom = (*lang_hooks.types.type_for_mode) (outmode, 0);
3567 if (aggregate_value_p (tfom))
3569 #ifdef PCC_STATIC_STRUCT_RETURN
3570 rtx pointer_reg
3571 = hard_function_value (build_pointer_type (tfom), 0, 0);
3572 mem_value = gen_rtx_MEM (outmode, pointer_reg);
3573 pcc_struct_value = 1;
3574 if (value == 0)
3575 value = gen_reg_rtx (outmode);
3576 #else /* not PCC_STATIC_STRUCT_RETURN */
3577 struct_value_size = GET_MODE_SIZE (outmode);
3578 if (value != 0 && GET_CODE (value) == MEM)
3579 mem_value = value;
3580 else
3581 mem_value = assign_temp (tfom, 0, 1, 1);
3582 #endif
3583 /* This call returns a big structure. */
3584 flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
3587 else
3588 tfom = void_type_node;
3590 /* ??? Unfinished: must pass the memory address as an argument. */
3592 /* Copy all the libcall-arguments out of the varargs data
3593 and into a vector ARGVEC.
3595 Compute how to pass each argument. We only support a very small subset
3596 of the full argument passing conventions to limit complexity here since
3597 library functions shouldn't have many args. */
3599 argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
3600 memset ((char *) argvec, 0, (nargs + 1) * sizeof (struct arg));
3602 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3603 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far, outmode, fun);
3604 #else
3605 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
3606 #endif
3608 args_size.constant = 0;
3609 args_size.var = 0;
3611 count = 0;
3613 /* Now we are about to start emitting insns that can be deleted
3614 if a libcall is deleted. */
3615 if (flags & ECF_LIBCALL_BLOCK)
3616 start_sequence ();
3618 push_temp_slots ();
3620 /* If there's a structure value address to be passed,
3621 either pass it in the special place, or pass it as an extra argument. */
3622 if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
3624 rtx addr = XEXP (mem_value, 0);
3625 nargs++;
3627 /* Make sure it is a reasonable operand for a move or push insn. */
3628 if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
3629 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
3630 addr = force_operand (addr, NULL_RTX);
3632 argvec[count].value = addr;
3633 argvec[count].mode = Pmode;
3634 argvec[count].partial = 0;
3636 argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
3637 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3638 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
3639 abort ();
3640 #endif
3642 locate_and_pad_parm (Pmode, NULL_TREE,
3643 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3645 #else
3646 argvec[count].reg != 0,
3647 #endif
3648 0, NULL_TREE, &args_size, &argvec[count].locate);
3650 if (argvec[count].reg == 0 || argvec[count].partial != 0
3651 || reg_parm_stack_space > 0)
3652 args_size.constant += argvec[count].locate.size.constant;
3654 FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
3656 count++;
3659 for (; count < nargs; count++)
3661 rtx val = va_arg (p, rtx);
3662 enum machine_mode mode = va_arg (p, enum machine_mode);
3664 /* We cannot convert the arg value to the mode the library wants here;
3665 must do it earlier where we know the signedness of the arg. */
3666 if (mode == BLKmode
3667 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
3668 abort ();
3670 /* On some machines, there's no way to pass a float to a library fcn.
3671 Pass it as a double instead. */
3672 #ifdef LIBGCC_NEEDS_DOUBLE
3673 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
3674 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
3675 #endif
3677 /* There's no need to call protect_from_queue, because
3678 either emit_move_insn or emit_push_insn will do that. */
3680 /* Make sure it is a reasonable operand for a move or push insn. */
3681 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
3682 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
3683 val = force_operand (val, NULL_RTX);
3685 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3686 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
3688 rtx slot;
3689 int must_copy = 1
3690 #ifdef FUNCTION_ARG_CALLEE_COPIES
3691 && ! FUNCTION_ARG_CALLEE_COPIES (args_so_far, mode,
3692 NULL_TREE, 1)
3693 #endif
3696 /* loop.c won't look at CALL_INSN_FUNCTION_USAGE of const/pure
3697 functions, so we have to pretend this isn't such a function. */
3698 if (flags & ECF_LIBCALL_BLOCK)
3700 rtx insns = get_insns ();
3701 end_sequence ();
3702 emit_insn (insns);
3704 flags &= ~(ECF_CONST | ECF_PURE | ECF_LIBCALL_BLOCK);
3706 /* If this was a CONST function, it is now PURE since
3707 it now reads memory. */
3708 if (flags & ECF_CONST)
3710 flags &= ~ECF_CONST;
3711 flags |= ECF_PURE;
3714 if (GET_MODE (val) == MEM && ! must_copy)
3715 slot = val;
3716 else if (must_copy)
3718 slot = assign_temp ((*lang_hooks.types.type_for_mode) (mode, 0),
3719 0, 1, 1);
3720 emit_move_insn (slot, val);
3722 else
3724 tree type = (*lang_hooks.types.type_for_mode) (mode, 0);
3726 slot
3727 = gen_rtx_MEM (mode,
3728 expand_expr (build1 (ADDR_EXPR,
3729 build_pointer_type (type),
3730 make_tree (type, val)),
3731 NULL_RTX, VOIDmode, 0));
3734 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
3735 gen_rtx_USE (VOIDmode, slot),
3736 call_fusage);
3737 if (must_copy)
3738 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
3739 gen_rtx_CLOBBER (VOIDmode,
3740 slot),
3741 call_fusage);
3743 mode = Pmode;
3744 val = force_operand (XEXP (slot, 0), NULL_RTX);
3746 #endif
3748 argvec[count].value = val;
3749 argvec[count].mode = mode;
3751 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
3753 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3754 argvec[count].partial
3755 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
3756 #else
3757 argvec[count].partial = 0;
3758 #endif
3760 locate_and_pad_parm (mode, NULL_TREE,
3761 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3763 #else
3764 argvec[count].reg != 0,
3765 #endif
3766 argvec[count].partial,
3767 NULL_TREE, &args_size, &argvec[count].locate);
3769 if (argvec[count].locate.size.var)
3770 abort ();
3772 if (argvec[count].reg == 0 || argvec[count].partial != 0
3773 || reg_parm_stack_space > 0)
3774 args_size.constant += argvec[count].locate.size.constant;
3776 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3779 #ifdef FINAL_REG_PARM_STACK_SPACE
3780 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
3781 args_size.var);
3782 #endif
3783 /* If this machine requires an external definition for library
3784 functions, write one out. */
3785 assemble_external_libcall (fun);
3787 original_args_size = args_size;
3788 args_size.constant = (((args_size.constant
3789 + stack_pointer_delta
3790 + STACK_BYTES - 1)
3791 / STACK_BYTES
3792 * STACK_BYTES)
3793 - stack_pointer_delta);
3795 args_size.constant = MAX (args_size.constant,
3796 reg_parm_stack_space);
3798 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3799 args_size.constant -= reg_parm_stack_space;
3800 #endif
3802 if (args_size.constant > current_function_outgoing_args_size)
3803 current_function_outgoing_args_size = args_size.constant;
3805 if (ACCUMULATE_OUTGOING_ARGS)
3807 /* Since the stack pointer will never be pushed, it is possible for
3808 the evaluation of a parm to clobber something we have already
3809 written to the stack. Since most function calls on RISC machines
3810 do not use the stack, this is uncommon, but must work correctly.
3812 Therefore, we save any area of the stack that was already written
3813 and that we are using. Here we set up to do this by making a new
3814 stack usage map from the old one.
3816 Another approach might be to try to reorder the argument
3817 evaluations to avoid this conflicting stack usage. */
3819 needed = args_size.constant;
3821 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3822 /* Since we will be writing into the entire argument area, the
3823 map must be allocated for its entire size, not just the part that
3824 is the responsibility of the caller. */
3825 needed += reg_parm_stack_space;
3826 #endif
3828 #ifdef ARGS_GROW_DOWNWARD
3829 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3830 needed + 1);
3831 #else
3832 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3833 needed);
3834 #endif
3835 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3837 if (initial_highest_arg_in_use)
3838 memcpy (stack_usage_map, initial_stack_usage_map,
3839 initial_highest_arg_in_use);
3841 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3842 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
3843 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3844 needed = 0;
3846 /* We must be careful to use virtual regs before they're instantiated,
3847 and real regs afterwards. Loop optimization, for example, can create
3848 new libcalls after we've instantiated the virtual regs, and if we
3849 use virtuals anyway, they won't match the rtl patterns. */
3851 if (virtuals_instantiated)
3852 argblock = plus_constant (stack_pointer_rtx, STACK_POINTER_OFFSET);
3853 else
3854 argblock = virtual_outgoing_args_rtx;
3856 else
3858 if (!PUSH_ARGS)
3859 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3862 /* If we push args individually in reverse order, perform stack alignment
3863 before the first push (the last arg). */
3864 if (argblock == 0 && PUSH_ARGS_REVERSED)
3865 anti_adjust_stack (GEN_INT (args_size.constant
3866 - original_args_size.constant));
3868 if (PUSH_ARGS_REVERSED)
3870 inc = -1;
3871 argnum = nargs - 1;
3873 else
3875 inc = 1;
3876 argnum = 0;
3879 #ifdef REG_PARM_STACK_SPACE
3880 if (ACCUMULATE_OUTGOING_ARGS)
3882 /* The argument list is the property of the called routine and it
3883 may clobber it. If the fixed area has been used for previous
3884 parameters, we must save and restore it. */
3885 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
3886 &low_to_save, &high_to_save);
3888 #endif
3890 /* Push the args that need to be pushed. */
3892 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3893 are to be pushed. */
3894 for (count = 0; count < nargs; count++, argnum += inc)
3896 enum machine_mode mode = argvec[argnum].mode;
3897 rtx val = argvec[argnum].value;
3898 rtx reg = argvec[argnum].reg;
3899 int partial = argvec[argnum].partial;
3900 int lower_bound = 0, upper_bound = 0, i;
3902 if (! (reg != 0 && partial == 0))
3904 if (ACCUMULATE_OUTGOING_ARGS)
3906 /* If this is being stored into a pre-allocated, fixed-size,
3907 stack area, save any previous data at that location. */
3909 #ifdef ARGS_GROW_DOWNWARD
3910 /* stack_slot is negative, but we want to index stack_usage_map
3911 with positive values. */
3912 upper_bound = -argvec[argnum].locate.offset.constant + 1;
3913 lower_bound = upper_bound - argvec[argnum].locate.size.constant;
3914 #else
3915 lower_bound = argvec[argnum].locate.offset.constant;
3916 upper_bound = lower_bound + argvec[argnum].locate.size.constant;
3917 #endif
3919 i = lower_bound;
3920 /* Don't worry about things in the fixed argument area;
3921 it has already been saved. */
3922 if (i < reg_parm_stack_space)
3923 i = reg_parm_stack_space;
3924 while (i < upper_bound && stack_usage_map[i] == 0)
3925 i++;
3927 if (i < upper_bound)
3929 /* We need to make a save area. */
3930 unsigned int size
3931 = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
3932 enum machine_mode save_mode
3933 = mode_for_size (size, MODE_INT, 1);
3934 rtx adr
3935 = plus_constant (argblock,
3936 argvec[argnum].locate.offset.constant);
3937 rtx stack_area
3938 = gen_rtx_MEM (save_mode, memory_address (save_mode, adr));
3939 argvec[argnum].save_area = gen_reg_rtx (save_mode);
3941 emit_move_insn (argvec[argnum].save_area, stack_area);
3945 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, PARM_BOUNDARY,
3946 partial, reg, 0, argblock,
3947 GEN_INT (argvec[argnum].locate.offset.constant),
3948 reg_parm_stack_space,
3949 ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad));
3951 /* Now mark the segment we just used. */
3952 if (ACCUMULATE_OUTGOING_ARGS)
3953 for (i = lower_bound; i < upper_bound; i++)
3954 stack_usage_map[i] = 1;
3956 NO_DEFER_POP;
3960 /* If we pushed args in forward order, perform stack alignment
3961 after pushing the last arg. */
3962 if (argblock == 0 && !PUSH_ARGS_REVERSED)
3963 anti_adjust_stack (GEN_INT (args_size.constant
3964 - original_args_size.constant));
3966 if (PUSH_ARGS_REVERSED)
3967 argnum = nargs - 1;
3968 else
3969 argnum = 0;
3971 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0, 0);
3973 /* Now load any reg parms into their regs. */
3975 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3976 are to be pushed. */
3977 for (count = 0; count < nargs; count++, argnum += inc)
3979 rtx val = argvec[argnum].value;
3980 rtx reg = argvec[argnum].reg;
3981 int partial = argvec[argnum].partial;
3983 /* Handle calls that pass values in multiple non-contiguous
3984 locations. The PA64 has examples of this for library calls. */
3985 if (reg != 0 && GET_CODE (reg) == PARALLEL)
3986 emit_group_load (reg, val, GET_MODE_SIZE (GET_MODE (val)));
3987 else if (reg != 0 && partial == 0)
3988 emit_move_insn (reg, val);
3990 NO_DEFER_POP;
3993 /* Any regs containing parms remain in use through the call. */
3994 for (count = 0; count < nargs; count++)
3996 rtx reg = argvec[count].reg;
3997 if (reg != 0 && GET_CODE (reg) == PARALLEL)
3998 use_group_regs (&call_fusage, reg);
3999 else if (reg != 0)
4000 use_reg (&call_fusage, reg);
4003 /* Pass the function the address in which to return a structure value. */
4004 if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
4006 emit_move_insn (struct_value_rtx,
4007 force_reg (Pmode,
4008 force_operand (XEXP (mem_value, 0),
4009 NULL_RTX)));
4010 if (GET_CODE (struct_value_rtx) == REG)
4011 use_reg (&call_fusage, struct_value_rtx);
4014 /* Don't allow popping to be deferred, since then
4015 cse'ing of library calls could delete a call and leave the pop. */
4016 NO_DEFER_POP;
4017 valreg = (mem_value == 0 && outmode != VOIDmode
4018 ? hard_libcall_value (outmode) : NULL_RTX);
4020 /* Stack must be properly aligned now. */
4021 if (stack_pointer_delta & (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1))
4022 abort ();
4024 before_call = get_last_insn ();
4026 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4027 will set inhibit_defer_pop to that value. */
4028 /* The return type is needed to decide how many bytes the function pops.
4029 Signedness plays no role in that, so for simplicity, we pretend it's
4030 always signed. We also assume that the list of arguments passed has
4031 no impact, so we pretend it is unknown. */
4033 emit_call_1 (fun,
4034 get_identifier (XSTR (orgfun, 0)),
4035 build_function_type (tfom, NULL_TREE),
4036 original_args_size.constant, args_size.constant,
4037 struct_value_size,
4038 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
4039 valreg,
4040 old_inhibit_defer_pop + 1, call_fusage, flags, & args_so_far);
4042 /* For calls to `setjmp', etc., inform flow.c it should complain
4043 if nonvolatile values are live. For functions that cannot return,
4044 inform flow that control does not fall through. */
4046 if (flags & (ECF_NORETURN | ECF_LONGJMP))
4048 /* The barrier note must be emitted
4049 immediately after the CALL_INSN. Some ports emit more than
4050 just a CALL_INSN above, so we must search for it here. */
4052 rtx last = get_last_insn ();
4053 while (GET_CODE (last) != CALL_INSN)
4055 last = PREV_INSN (last);
4056 /* There was no CALL_INSN? */
4057 if (last == before_call)
4058 abort ();
4061 emit_barrier_after (last);
4064 /* Now restore inhibit_defer_pop to its actual original value. */
4065 OK_DEFER_POP;
4067 /* If call is cse'able, make appropriate pair of reg-notes around it.
4068 Test valreg so we don't crash; may safely ignore `const'
4069 if return type is void. Disable for PARALLEL return values, because
4070 we have no way to move such values into a pseudo register. */
4071 if (flags & ECF_LIBCALL_BLOCK)
4073 rtx insns;
4075 if (valreg == 0)
4077 insns = get_insns ();
4078 end_sequence ();
4079 emit_insn (insns);
4081 else
4083 rtx note = 0;
4084 rtx temp;
4085 int i;
4087 if (GET_CODE (valreg) == PARALLEL)
4089 temp = gen_reg_rtx (outmode);
4090 emit_group_store (temp, valreg, outmode);
4091 valreg = temp;
4094 temp = gen_reg_rtx (GET_MODE (valreg));
4096 /* Construct an "equal form" for the value which mentions all the
4097 arguments in order as well as the function name. */
4098 for (i = 0; i < nargs; i++)
4099 note = gen_rtx_EXPR_LIST (VOIDmode, argvec[i].value, note);
4100 note = gen_rtx_EXPR_LIST (VOIDmode, fun, note);
4102 insns = get_insns ();
4103 end_sequence ();
4105 if (flags & ECF_PURE)
4106 note = gen_rtx_EXPR_LIST (VOIDmode,
4107 gen_rtx_USE (VOIDmode,
4108 gen_rtx_MEM (BLKmode,
4109 gen_rtx_SCRATCH (VOIDmode))),
4110 note);
4112 emit_libcall_block (insns, temp, valreg, note);
4114 valreg = temp;
4117 pop_temp_slots ();
4119 /* Copy the value to the right place. */
4120 if (outmode != VOIDmode && retval)
4122 if (mem_value)
4124 if (value == 0)
4125 value = mem_value;
4126 if (value != mem_value)
4127 emit_move_insn (value, mem_value);
4129 else if (GET_CODE (valreg) == PARALLEL)
4131 if (value == 0)
4132 value = gen_reg_rtx (outmode);
4133 emit_group_store (value, valreg, outmode);
4135 else if (value != 0)
4136 emit_move_insn (value, valreg);
4137 else
4138 value = valreg;
4141 if (ACCUMULATE_OUTGOING_ARGS)
4143 #ifdef REG_PARM_STACK_SPACE
4144 if (save_area)
4145 restore_fixed_argument_area (save_area, argblock,
4146 high_to_save, low_to_save);
4147 #endif
4149 /* If we saved any argument areas, restore them. */
4150 for (count = 0; count < nargs; count++)
4151 if (argvec[count].save_area)
4153 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
4154 rtx adr = plus_constant (argblock,
4155 argvec[count].locate.offset.constant);
4156 rtx stack_area = gen_rtx_MEM (save_mode,
4157 memory_address (save_mode, adr));
4159 emit_move_insn (stack_area, argvec[count].save_area);
4162 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
4163 stack_usage_map = initial_stack_usage_map;
4166 return value;
4170 /* Output a library call to function FUN (a SYMBOL_REF rtx)
4171 (emitting the queue unless NO_QUEUE is nonzero),
4172 for a value of mode OUTMODE,
4173 with NARGS different arguments, passed as alternating rtx values
4174 and machine_modes to convert them to.
4175 The rtx values should have been passed through protect_from_queue already.
4177 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for `const'
4178 calls, LCT_PURE for `pure' calls, LCT_CONST_MAKE_BLOCK for `const' calls
4179 which should be enclosed in REG_LIBCALL/REG_RETVAL notes,
4180 LCT_PURE_MAKE_BLOCK for `purep' calls which should be enclosed in
4181 REG_LIBCALL/REG_RETVAL notes with extra (use (memory (scratch)),
4182 or other LCT_ value for other types of library calls. */
4184 void
4185 emit_library_call (rtx orgfun, enum libcall_type fn_type,
4186 enum machine_mode outmode, int nargs, ...)
4188 va_list p;
4190 va_start (p, nargs);
4191 emit_library_call_value_1 (0, orgfun, NULL_RTX, fn_type, outmode, nargs, p);
4192 va_end (p);
4195 /* Like emit_library_call except that an extra argument, VALUE,
4196 comes second and says where to store the result.
4197 (If VALUE is zero, this function chooses a convenient way
4198 to return the value.
4200 This function returns an rtx for where the value is to be found.
4201 If VALUE is nonzero, VALUE is returned. */
4204 emit_library_call_value (rtx orgfun, rtx value,
4205 enum libcall_type fn_type,
4206 enum machine_mode outmode, int nargs, ...)
4208 rtx result;
4209 va_list p;
4211 va_start (p, nargs);
4212 result = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode,
4213 nargs, p);
4214 va_end (p);
4216 return result;
4219 /* Store a single argument for a function call
4220 into the register or memory area where it must be passed.
4221 *ARG describes the argument value and where to pass it.
4223 ARGBLOCK is the address of the stack-block for all the arguments,
4224 or 0 on a machine where arguments are pushed individually.
4226 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4227 so must be careful about how the stack is used.
4229 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4230 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4231 that we need not worry about saving and restoring the stack.
4233 FNDECL is the declaration of the function we are calling.
4235 Return nonzero if this arg should cause sibcall failure,
4236 zero otherwise. */
4238 static int
4239 store_one_arg (struct arg_data *arg, rtx argblock, int flags,
4240 int variable_size ATTRIBUTE_UNUSED, int reg_parm_stack_space)
4242 tree pval = arg->tree_value;
4243 rtx reg = 0;
4244 int partial = 0;
4245 int used = 0;
4246 int i, lower_bound = 0, upper_bound = 0;
4247 int sibcall_failure = 0;
4249 if (TREE_CODE (pval) == ERROR_MARK)
4250 return 1;
4252 /* Push a new temporary level for any temporaries we make for
4253 this argument. */
4254 push_temp_slots ();
4256 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL))
4258 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4259 save any previous data at that location. */
4260 if (argblock && ! variable_size && arg->stack)
4262 #ifdef ARGS_GROW_DOWNWARD
4263 /* stack_slot is negative, but we want to index stack_usage_map
4264 with positive values. */
4265 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4266 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
4267 else
4268 upper_bound = 0;
4270 lower_bound = upper_bound - arg->locate.size.constant;
4271 #else
4272 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4273 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
4274 else
4275 lower_bound = 0;
4277 upper_bound = lower_bound + arg->locate.size.constant;
4278 #endif
4280 i = lower_bound;
4281 /* Don't worry about things in the fixed argument area;
4282 it has already been saved. */
4283 if (i < reg_parm_stack_space)
4284 i = reg_parm_stack_space;
4285 while (i < upper_bound && stack_usage_map[i] == 0)
4286 i++;
4288 if (i < upper_bound)
4290 /* We need to make a save area. */
4291 unsigned int size = arg->locate.size.constant * BITS_PER_UNIT;
4292 enum machine_mode save_mode = mode_for_size (size, MODE_INT, 1);
4293 rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0));
4294 rtx stack_area = gen_rtx_MEM (save_mode, adr);
4296 if (save_mode == BLKmode)
4298 tree ot = TREE_TYPE (arg->tree_value);
4299 tree nt = build_qualified_type (ot, (TYPE_QUALS (ot)
4300 | TYPE_QUAL_CONST));
4302 arg->save_area = assign_temp (nt, 0, 1, 1);
4303 preserve_temp_slots (arg->save_area);
4304 emit_block_move (validize_mem (arg->save_area), stack_area,
4305 expr_size (arg->tree_value),
4306 BLOCK_OP_CALL_PARM);
4308 else
4310 arg->save_area = gen_reg_rtx (save_mode);
4311 emit_move_insn (arg->save_area, stack_area);
4317 /* If this isn't going to be placed on both the stack and in registers,
4318 set up the register and number of words. */
4319 if (! arg->pass_on_stack)
4321 if (flags & ECF_SIBCALL)
4322 reg = arg->tail_call_reg;
4323 else
4324 reg = arg->reg;
4325 partial = arg->partial;
4328 if (reg != 0 && partial == 0)
4329 /* Being passed entirely in a register. We shouldn't be called in
4330 this case. */
4331 abort ();
4333 /* If this arg needs special alignment, don't load the registers
4334 here. */
4335 if (arg->n_aligned_regs != 0)
4336 reg = 0;
4338 /* If this is being passed partially in a register, we can't evaluate
4339 it directly into its stack slot. Otherwise, we can. */
4340 if (arg->value == 0)
4342 /* stack_arg_under_construction is nonzero if a function argument is
4343 being evaluated directly into the outgoing argument list and
4344 expand_call must take special action to preserve the argument list
4345 if it is called recursively.
4347 For scalar function arguments stack_usage_map is sufficient to
4348 determine which stack slots must be saved and restored. Scalar
4349 arguments in general have pass_on_stack == 0.
4351 If this argument is initialized by a function which takes the
4352 address of the argument (a C++ constructor or a C function
4353 returning a BLKmode structure), then stack_usage_map is
4354 insufficient and expand_call must push the stack around the
4355 function call. Such arguments have pass_on_stack == 1.
4357 Note that it is always safe to set stack_arg_under_construction,
4358 but this generates suboptimal code if set when not needed. */
4360 if (arg->pass_on_stack)
4361 stack_arg_under_construction++;
4363 arg->value = expand_expr (pval,
4364 (partial
4365 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
4366 ? NULL_RTX : arg->stack,
4367 VOIDmode, EXPAND_STACK_PARM);
4369 /* If we are promoting object (or for any other reason) the mode
4370 doesn't agree, convert the mode. */
4372 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
4373 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
4374 arg->value, arg->unsignedp);
4376 if (arg->pass_on_stack)
4377 stack_arg_under_construction--;
4380 /* Don't allow anything left on stack from computation
4381 of argument to alloca. */
4382 if (flags & ECF_MAY_BE_ALLOCA)
4383 do_pending_stack_adjust ();
4385 if (arg->value == arg->stack)
4386 /* If the value is already in the stack slot, we are done. */
4388 else if (arg->mode != BLKmode)
4390 int size;
4392 /* Argument is a scalar, not entirely passed in registers.
4393 (If part is passed in registers, arg->partial says how much
4394 and emit_push_insn will take care of putting it there.)
4396 Push it, and if its size is less than the
4397 amount of space allocated to it,
4398 also bump stack pointer by the additional space.
4399 Note that in C the default argument promotions
4400 will prevent such mismatches. */
4402 size = GET_MODE_SIZE (arg->mode);
4403 /* Compute how much space the push instruction will push.
4404 On many machines, pushing a byte will advance the stack
4405 pointer by a halfword. */
4406 #ifdef PUSH_ROUNDING
4407 size = PUSH_ROUNDING (size);
4408 #endif
4409 used = size;
4411 /* Compute how much space the argument should get:
4412 round up to a multiple of the alignment for arguments. */
4413 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
4414 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4415 / (PARM_BOUNDARY / BITS_PER_UNIT))
4416 * (PARM_BOUNDARY / BITS_PER_UNIT));
4418 /* This isn't already where we want it on the stack, so put it there.
4419 This can either be done with push or copy insns. */
4420 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
4421 PARM_BOUNDARY, partial, reg, used - size, argblock,
4422 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4423 ARGS_SIZE_RTX (arg->locate.alignment_pad));
4425 /* Unless this is a partially-in-register argument, the argument is now
4426 in the stack. */
4427 if (partial == 0)
4428 arg->value = arg->stack;
4430 else
4432 /* BLKmode, at least partly to be pushed. */
4434 unsigned int parm_align;
4435 int excess;
4436 rtx size_rtx;
4438 /* Pushing a nonscalar.
4439 If part is passed in registers, PARTIAL says how much
4440 and emit_push_insn will take care of putting it there. */
4442 /* Round its size up to a multiple
4443 of the allocation unit for arguments. */
4445 if (arg->locate.size.var != 0)
4447 excess = 0;
4448 size_rtx = ARGS_SIZE_RTX (arg->locate.size);
4450 else
4452 /* PUSH_ROUNDING has no effect on us, because
4453 emit_push_insn for BLKmode is careful to avoid it. */
4454 excess = (arg->locate.size.constant
4455 - int_size_in_bytes (TREE_TYPE (pval))
4456 + partial * UNITS_PER_WORD);
4457 size_rtx = expand_expr (size_in_bytes (TREE_TYPE (pval)),
4458 NULL_RTX, TYPE_MODE (sizetype), 0);
4461 /* Some types will require stricter alignment, which will be
4462 provided for elsewhere in argument layout. */
4463 parm_align = MAX (PARM_BOUNDARY, TYPE_ALIGN (TREE_TYPE (pval)));
4465 /* When an argument is padded down, the block is aligned to
4466 PARM_BOUNDARY, but the actual argument isn't. */
4467 if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward)
4469 if (arg->locate.size.var)
4470 parm_align = BITS_PER_UNIT;
4471 else if (excess)
4473 unsigned int excess_align = (excess & -excess) * BITS_PER_UNIT;
4474 parm_align = MIN (parm_align, excess_align);
4478 if ((flags & ECF_SIBCALL) && GET_CODE (arg->value) == MEM)
4480 /* emit_push_insn might not work properly if arg->value and
4481 argblock + arg->locate.offset areas overlap. */
4482 rtx x = arg->value;
4483 int i = 0;
4485 if (XEXP (x, 0) == current_function_internal_arg_pointer
4486 || (GET_CODE (XEXP (x, 0)) == PLUS
4487 && XEXP (XEXP (x, 0), 0) ==
4488 current_function_internal_arg_pointer
4489 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))
4491 if (XEXP (x, 0) != current_function_internal_arg_pointer)
4492 i = INTVAL (XEXP (XEXP (x, 0), 1));
4494 /* expand_call should ensure this */
4495 if (arg->locate.offset.var || GET_CODE (size_rtx) != CONST_INT)
4496 abort ();
4498 if (arg->locate.offset.constant > i)
4500 if (arg->locate.offset.constant < i + INTVAL (size_rtx))
4501 sibcall_failure = 1;
4503 else if (arg->locate.offset.constant < i)
4505 if (i < arg->locate.offset.constant + INTVAL (size_rtx))
4506 sibcall_failure = 1;
4511 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
4512 parm_align, partial, reg, excess, argblock,
4513 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4514 ARGS_SIZE_RTX (arg->locate.alignment_pad));
4516 /* Unless this is a partially-in-register argument, the argument is now
4517 in the stack.
4519 ??? Unlike the case above, in which we want the actual
4520 address of the data, so that we can load it directly into a
4521 register, here we want the address of the stack slot, so that
4522 it's properly aligned for word-by-word copying or something
4523 like that. It's not clear that this is always correct. */
4524 if (partial == 0)
4525 arg->value = arg->stack_slot;
4528 /* Mark all slots this store used. */
4529 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)
4530 && argblock && ! variable_size && arg->stack)
4531 for (i = lower_bound; i < upper_bound; i++)
4532 stack_usage_map[i] = 1;
4534 /* Once we have pushed something, pops can't safely
4535 be deferred during the rest of the arguments. */
4536 NO_DEFER_POP;
4538 /* ANSI doesn't require a sequence point here,
4539 but PCC has one, so this will avoid some problems. */
4540 emit_queue ();
4542 /* Free any temporary slots made in processing this argument. Show
4543 that we might have taken the address of something and pushed that
4544 as an operand. */
4545 preserve_temp_slots (NULL_RTX);
4546 free_temp_slots ();
4547 pop_temp_slots ();
4549 return sibcall_failure;
4552 /* Nonzero if we do not know how to pass TYPE solely in registers.
4553 We cannot do so in the following cases:
4555 - if the type has variable size
4556 - if the type is marked as addressable (it is required to be constructed
4557 into the stack)
4558 - if the padding and mode of the type is such that a copy into a register
4559 would put it into the wrong part of the register.
4561 Which padding can't be supported depends on the byte endianness.
4563 A value in a register is implicitly padded at the most significant end.
4564 On a big-endian machine, that is the lower end in memory.
4565 So a value padded in memory at the upper end can't go in a register.
4566 For a little-endian machine, the reverse is true. */
4568 bool
4569 default_must_pass_in_stack (enum machine_mode mode, tree type)
4571 if (!type)
4572 return false;
4574 /* If the type has variable size... */
4575 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4576 return true;
4578 /* If the type is marked as addressable (it is required
4579 to be constructed into the stack)... */
4580 if (TREE_ADDRESSABLE (type))
4581 return true;
4583 /* If the padding and mode of the type is such that a copy into
4584 a register would put it into the wrong part of the register. */
4585 if (mode == BLKmode
4586 && int_size_in_bytes (type) % (PARM_BOUNDARY / BITS_PER_UNIT)
4587 && (FUNCTION_ARG_PADDING (mode, type)
4588 == (BYTES_BIG_ENDIAN ? upward : downward)))
4589 return true;
4591 return false;