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, 2004, 2005, 2007
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
39 #include "langhooks.h"
44 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
45 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
47 /* Data structure and subroutines used within expand_call. */
51 /* Tree node for this argument. */
53 /* Mode for value; TYPE_MODE unless promoted. */
54 enum machine_mode mode
;
55 /* Current RTL value for argument, or 0 if it isn't precomputed. */
57 /* Initially-compute RTL value for argument; only for const functions. */
59 /* Register to pass this argument in, 0 if passed on stack, or an
60 PARALLEL if the arg is to be copied into multiple non-contiguous
63 /* Register to pass this argument in when generating tail call sequence.
64 This is not the same register as for normal calls on machines with
67 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
68 form for emit_group_move. */
70 /* If REG was promoted from the actual mode of the argument expression,
71 indicates whether the promotion is sign- or zero-extended. */
73 /* Number of bytes to put in registers. 0 means put the whole arg
74 in registers. Also 0 if not passed in registers. */
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. */
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. */
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. */
90 /* Place that this stack area has been saved, if needed. */
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. */
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 static int stack_arg_under_construction
;
123 static void emit_call_1 (rtx
, tree
, tree
, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
,
124 HOST_WIDE_INT
, rtx
, rtx
, int, rtx
, int,
126 static void precompute_register_parameters (int, struct arg_data
*, int *);
127 static int store_one_arg (struct arg_data
*, rtx
, int, int, int);
128 static void store_unaligned_arguments_into_pseudos (struct arg_data
*, int);
129 static int finalize_must_preallocate (int, int, struct arg_data
*,
131 static void precompute_arguments (int, int, struct arg_data
*);
132 static int compute_argument_block_size (int, struct args_size
*, int);
133 static void initialize_argument_information (int, struct arg_data
*,
134 struct args_size
*, int, tree
,
135 tree
, CUMULATIVE_ARGS
*, int,
136 rtx
*, int *, int *, int *,
138 static void compute_argument_addresses (struct arg_data
*, rtx
, int);
139 static rtx
rtx_for_function_call (tree
, tree
);
140 static void load_register_parameters (struct arg_data
*, int, rtx
*, int,
142 static rtx
emit_library_call_value_1 (int, rtx
, rtx
, enum libcall_type
,
143 enum machine_mode
, int, va_list);
144 static int special_function_p (tree
, int);
145 static int check_sibcall_argument_overlap_1 (rtx
);
146 static int check_sibcall_argument_overlap (rtx
, struct arg_data
*, int);
148 static int combine_pending_stack_adjustment_and_call (int, struct args_size
*,
150 static tree
split_complex_values (tree
);
151 static tree
split_complex_types (tree
);
153 #ifdef REG_PARM_STACK_SPACE
154 static rtx
save_fixed_argument_area (int, rtx
, int *, int *);
155 static void restore_fixed_argument_area (rtx
, rtx
, int, int);
158 /* Force FUNEXP into a form suitable for the address of a CALL,
159 and return that as an rtx. Also load the static chain register
160 if FNDECL is a nested function.
162 CALL_FUSAGE points to a variable holding the prospective
163 CALL_INSN_FUNCTION_USAGE information. */
166 prepare_call_address (rtx funexp
, rtx static_chain_value
,
167 rtx
*call_fusage
, int reg_parm_seen
, int sibcallp
)
169 /* Make a valid memory address and copy constants through pseudo-regs,
170 but not for a constant address if -fno-function-cse. */
171 if (GET_CODE (funexp
) != SYMBOL_REF
)
172 /* If we are using registers for parameters, force the
173 function address into a register now. */
174 funexp
= ((SMALL_REGISTER_CLASSES
&& reg_parm_seen
)
175 ? force_not_mem (memory_address (FUNCTION_MODE
, funexp
))
176 : memory_address (FUNCTION_MODE
, funexp
));
179 #ifndef NO_FUNCTION_CSE
180 if (optimize
&& ! flag_no_function_cse
)
181 funexp
= force_reg (Pmode
, funexp
);
185 if (static_chain_value
!= 0)
187 static_chain_value
= convert_memory_address (Pmode
, static_chain_value
);
188 emit_move_insn (static_chain_rtx
, static_chain_value
);
190 if (REG_P (static_chain_rtx
))
191 use_reg (call_fusage
, static_chain_rtx
);
197 /* Generate instructions to call function FUNEXP,
198 and optionally pop the results.
199 The CALL_INSN is the first insn generated.
201 FNDECL is the declaration node of the function. This is given to the
202 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
204 FUNTYPE is the data type of the function. This is given to the macro
205 RETURN_POPS_ARGS to determine whether this function pops its own args.
206 We used to allow an identifier for library functions, but that doesn't
207 work when the return type is an aggregate type and the calling convention
208 says that the pointer to this aggregate is to be popped by the callee.
210 STACK_SIZE is the number of bytes of arguments on the stack,
211 ROUNDED_STACK_SIZE is that number rounded up to
212 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
213 both to put into the call insn and to generate explicit popping
216 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
217 It is zero if this call doesn't want a structure value.
219 NEXT_ARG_REG is the rtx that results from executing
220 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
221 just after all the args have had their registers assigned.
222 This could be whatever you like, but normally it is the first
223 arg-register beyond those used for args in this call,
224 or 0 if all the arg-registers are used in this call.
225 It is passed on to `gen_call' so you can put this info in the call insn.
227 VALREG is a hard register in which a value is returned,
228 or 0 if the call does not return a value.
230 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
231 the args to this call were processed.
232 We restore `inhibit_defer_pop' to that value.
234 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
235 denote registers used by the called function. */
238 emit_call_1 (rtx funexp
, tree fntree
, tree fndecl ATTRIBUTE_UNUSED
,
239 tree funtype ATTRIBUTE_UNUSED
,
240 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED
,
241 HOST_WIDE_INT rounded_stack_size
,
242 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED
,
243 rtx next_arg_reg ATTRIBUTE_UNUSED
, rtx valreg
,
244 int old_inhibit_defer_pop
, rtx call_fusage
, int ecf_flags
,
245 CUMULATIVE_ARGS
*args_so_far ATTRIBUTE_UNUSED
)
247 rtx rounded_stack_size_rtx
= GEN_INT (rounded_stack_size
);
249 int already_popped
= 0;
250 HOST_WIDE_INT n_popped
= RETURN_POPS_ARGS (fndecl
, funtype
, stack_size
);
251 #if defined (HAVE_call) && defined (HAVE_call_value)
252 rtx struct_value_size_rtx
;
253 struct_value_size_rtx
= GEN_INT (struct_value_size
);
256 #ifdef CALL_POPS_ARGS
257 n_popped
+= CALL_POPS_ARGS (* args_so_far
);
260 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
261 and we don't want to load it into a register as an optimization,
262 because prepare_call_address already did it if it should be done. */
263 if (GET_CODE (funexp
) != SYMBOL_REF
)
264 funexp
= memory_address (FUNCTION_MODE
, funexp
);
266 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
267 if ((ecf_flags
& ECF_SIBCALL
)
268 && HAVE_sibcall_pop
&& HAVE_sibcall_value_pop
269 && (n_popped
> 0 || stack_size
== 0))
271 rtx n_pop
= GEN_INT (n_popped
);
274 /* If this subroutine pops its own args, record that in the call insn
275 if possible, for the sake of frame pointer elimination. */
278 pat
= GEN_SIBCALL_VALUE_POP (valreg
,
279 gen_rtx_MEM (FUNCTION_MODE
, funexp
),
280 rounded_stack_size_rtx
, next_arg_reg
,
283 pat
= GEN_SIBCALL_POP (gen_rtx_MEM (FUNCTION_MODE
, funexp
),
284 rounded_stack_size_rtx
, next_arg_reg
, n_pop
);
286 emit_call_insn (pat
);
292 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
293 /* If the target has "call" or "call_value" insns, then prefer them
294 if no arguments are actually popped. If the target does not have
295 "call" or "call_value" insns, then we must use the popping versions
296 even if the call has no arguments to pop. */
297 #if defined (HAVE_call) && defined (HAVE_call_value)
298 if (HAVE_call
&& HAVE_call_value
&& HAVE_call_pop
&& HAVE_call_value_pop
299 && n_popped
> 0 && ! (ecf_flags
& ECF_SP_DEPRESSED
))
301 if (HAVE_call_pop
&& HAVE_call_value_pop
)
304 rtx n_pop
= GEN_INT (n_popped
);
307 /* If this subroutine pops its own args, record that in the call insn
308 if possible, for the sake of frame pointer elimination. */
311 pat
= GEN_CALL_VALUE_POP (valreg
,
312 gen_rtx_MEM (FUNCTION_MODE
, funexp
),
313 rounded_stack_size_rtx
, next_arg_reg
, n_pop
);
315 pat
= GEN_CALL_POP (gen_rtx_MEM (FUNCTION_MODE
, funexp
),
316 rounded_stack_size_rtx
, next_arg_reg
, n_pop
);
318 emit_call_insn (pat
);
324 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
325 if ((ecf_flags
& ECF_SIBCALL
)
326 && HAVE_sibcall
&& HAVE_sibcall_value
)
329 emit_call_insn (GEN_SIBCALL_VALUE (valreg
,
330 gen_rtx_MEM (FUNCTION_MODE
, funexp
),
331 rounded_stack_size_rtx
,
332 next_arg_reg
, NULL_RTX
));
334 emit_call_insn (GEN_SIBCALL (gen_rtx_MEM (FUNCTION_MODE
, funexp
),
335 rounded_stack_size_rtx
, next_arg_reg
,
336 struct_value_size_rtx
));
341 #if defined (HAVE_call) && defined (HAVE_call_value)
342 if (HAVE_call
&& HAVE_call_value
)
345 emit_call_insn (GEN_CALL_VALUE (valreg
,
346 gen_rtx_MEM (FUNCTION_MODE
, funexp
),
347 rounded_stack_size_rtx
, next_arg_reg
,
350 emit_call_insn (GEN_CALL (gen_rtx_MEM (FUNCTION_MODE
, funexp
),
351 rounded_stack_size_rtx
, next_arg_reg
,
352 struct_value_size_rtx
));
358 /* Find the call we just emitted. */
359 call_insn
= last_call_insn ();
361 /* Mark memory as used for "pure" function call. */
362 if (ecf_flags
& ECF_PURE
)
366 gen_rtx_USE (VOIDmode
,
367 gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
))),
370 /* Put the register usage information there. */
371 add_function_usage_to (call_insn
, call_fusage
);
373 /* If this is a const call, then set the insn's unchanging bit. */
374 if (ecf_flags
& (ECF_CONST
| ECF_PURE
))
375 CONST_OR_PURE_CALL_P (call_insn
) = 1;
377 /* If this call can't throw, attach a REG_EH_REGION reg note to that
379 if (ecf_flags
& ECF_NOTHROW
)
380 REG_NOTES (call_insn
) = gen_rtx_EXPR_LIST (REG_EH_REGION
, const0_rtx
,
381 REG_NOTES (call_insn
));
384 int rn
= lookup_stmt_eh_region (fntree
);
386 /* If rn < 0, then either (1) tree-ssa not used or (2) doesn't
387 throw, which we already took care of. */
389 REG_NOTES (call_insn
) = gen_rtx_EXPR_LIST (REG_EH_REGION
, GEN_INT (rn
),
390 REG_NOTES (call_insn
));
391 note_current_region_may_contain_throw ();
394 if (ecf_flags
& ECF_NORETURN
)
395 REG_NOTES (call_insn
) = gen_rtx_EXPR_LIST (REG_NORETURN
, const0_rtx
,
396 REG_NOTES (call_insn
));
398 if (ecf_flags
& ECF_RETURNS_TWICE
)
400 REG_NOTES (call_insn
) = gen_rtx_EXPR_LIST (REG_SETJMP
, const0_rtx
,
401 REG_NOTES (call_insn
));
402 current_function_calls_setjmp
= 1;
405 SIBLING_CALL_P (call_insn
) = ((ecf_flags
& ECF_SIBCALL
) != 0);
407 /* Restore this now, so that we do defer pops for this call's args
408 if the context of the call as a whole permits. */
409 inhibit_defer_pop
= old_inhibit_defer_pop
;
414 CALL_INSN_FUNCTION_USAGE (call_insn
)
415 = gen_rtx_EXPR_LIST (VOIDmode
,
416 gen_rtx_CLOBBER (VOIDmode
, stack_pointer_rtx
),
417 CALL_INSN_FUNCTION_USAGE (call_insn
));
418 rounded_stack_size
-= n_popped
;
419 rounded_stack_size_rtx
= GEN_INT (rounded_stack_size
);
420 stack_pointer_delta
-= n_popped
;
423 if (!ACCUMULATE_OUTGOING_ARGS
)
425 /* If returning from the subroutine does not automatically pop the args,
426 we need an instruction to pop them sooner or later.
427 Perhaps do it now; perhaps just record how much space to pop later.
429 If returning from the subroutine does pop the args, indicate that the
430 stack pointer will be changed. */
432 if (rounded_stack_size
!= 0)
434 if (ecf_flags
& (ECF_SP_DEPRESSED
| ECF_NORETURN
))
435 /* Just pretend we did the pop. */
436 stack_pointer_delta
-= rounded_stack_size
;
437 else if (flag_defer_pop
&& inhibit_defer_pop
== 0
438 && ! (ecf_flags
& (ECF_CONST
| ECF_PURE
)))
439 pending_stack_adjust
+= rounded_stack_size
;
441 adjust_stack (rounded_stack_size_rtx
);
444 /* When we accumulate outgoing args, we must avoid any stack manipulations.
445 Restore the stack pointer to its original value now. Usually
446 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
447 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
448 popping variants of functions exist as well.
450 ??? We may optimize similar to defer_pop above, but it is
451 probably not worthwhile.
453 ??? It will be worthwhile to enable combine_stack_adjustments even for
456 anti_adjust_stack (GEN_INT (n_popped
));
459 /* Determine if the function identified by NAME and FNDECL is one with
460 special properties we wish to know about.
462 For example, if the function might return more than one time (setjmp), then
463 set RETURNS_TWICE to a nonzero value.
465 Similarly set NORETURN if the function is in the longjmp family.
467 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
468 space from the stack such as alloca. */
471 special_function_p (tree fndecl
, int flags
)
473 if (fndecl
&& DECL_NAME (fndecl
)
474 && IDENTIFIER_LENGTH (DECL_NAME (fndecl
)) <= 17
475 /* Exclude functions not at the file scope, or not `extern',
476 since they are not the magic functions we would otherwise
478 FIXME: this should be handled with attributes, not with this
479 hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
480 because you can declare fork() inside a function if you
482 && (DECL_CONTEXT (fndecl
) == NULL_TREE
483 || TREE_CODE (DECL_CONTEXT (fndecl
)) == TRANSLATION_UNIT_DECL
)
484 && TREE_PUBLIC (fndecl
))
486 const char *name
= IDENTIFIER_POINTER (DECL_NAME (fndecl
));
487 const char *tname
= name
;
489 /* We assume that alloca will always be called by name. It
490 makes no sense to pass it as a pointer-to-function to
491 anything that does not understand its behavior. */
492 if (((IDENTIFIER_LENGTH (DECL_NAME (fndecl
)) == 6
494 && ! strcmp (name
, "alloca"))
495 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl
)) == 16
497 && ! strcmp (name
, "__builtin_alloca"))))
498 flags
|= ECF_MAY_BE_ALLOCA
;
500 /* Disregard prefix _, __ or __x. */
503 if (name
[1] == '_' && name
[2] == 'x')
505 else if (name
[1] == '_')
514 && (! strcmp (tname
, "setjmp")
515 || ! strcmp (tname
, "setjmp_syscall")))
517 && ! strcmp (tname
, "sigsetjmp"))
519 && ! strcmp (tname
, "savectx")))
520 flags
|= ECF_RETURNS_TWICE
;
523 && ! strcmp (tname
, "siglongjmp"))
524 flags
|= ECF_NORETURN
;
526 else if ((tname
[0] == 'q' && tname
[1] == 's'
527 && ! strcmp (tname
, "qsetjmp"))
528 || (tname
[0] == 'v' && tname
[1] == 'f'
529 && ! strcmp (tname
, "vfork"))
530 || (tname
[0] == 'g' && tname
[1] == 'e'
531 && !strcmp (tname
, "getcontext")))
532 flags
|= ECF_RETURNS_TWICE
;
534 else if (tname
[0] == 'l' && tname
[1] == 'o'
535 && ! strcmp (tname
, "longjmp"))
536 flags
|= ECF_NORETURN
;
542 /* Return nonzero when FNDECL represents a call to setjmp. */
545 setjmp_call_p (tree fndecl
)
547 return special_function_p (fndecl
, 0) & ECF_RETURNS_TWICE
;
550 /* Return true when exp contains alloca call. */
552 alloca_call_p (tree exp
)
554 if (TREE_CODE (exp
) == CALL_EXPR
555 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
556 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
558 && (special_function_p (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0),
559 0) & ECF_MAY_BE_ALLOCA
))
564 /* Detect flags (function attributes) from the function decl or type node. */
567 flags_from_decl_or_type (tree exp
)
574 type
= TREE_TYPE (exp
);
576 /* The function exp may have the `malloc' attribute. */
577 if (DECL_IS_MALLOC (exp
))
580 /* The function exp may have the `returns_twice' attribute. */
581 if (DECL_IS_RETURNS_TWICE (exp
))
582 flags
|= ECF_RETURNS_TWICE
;
584 /* The function exp may have the `pure' attribute. */
585 if (DECL_IS_PURE (exp
))
588 if (DECL_IS_NOVOPS (exp
))
591 if (TREE_NOTHROW (exp
))
592 flags
|= ECF_NOTHROW
;
594 if (TREE_READONLY (exp
) && ! TREE_THIS_VOLATILE (exp
))
597 flags
= special_function_p (exp
, flags
);
599 else if (TYPE_P (exp
) && TYPE_READONLY (exp
) && ! TREE_THIS_VOLATILE (exp
))
602 if (TREE_THIS_VOLATILE (exp
))
603 flags
|= ECF_NORETURN
;
605 /* Mark if the function returns with the stack pointer depressed. We
606 cannot consider it pure or constant in that case. */
607 if (TREE_CODE (type
) == FUNCTION_TYPE
&& TYPE_RETURNS_STACK_DEPRESSED (type
))
609 flags
|= ECF_SP_DEPRESSED
;
610 flags
&= ~(ECF_PURE
| ECF_CONST
);
616 /* Detect flags from a CALL_EXPR. */
619 call_expr_flags (tree t
)
622 tree decl
= get_callee_fndecl (t
);
625 flags
= flags_from_decl_or_type (decl
);
628 t
= TREE_TYPE (TREE_OPERAND (t
, 0));
629 if (t
&& TREE_CODE (t
) == POINTER_TYPE
)
630 flags
= flags_from_decl_or_type (TREE_TYPE (t
));
638 /* Precompute all register parameters as described by ARGS, storing values
639 into fields within the ARGS array.
641 NUM_ACTUALS indicates the total number elements in the ARGS array.
643 Set REG_PARM_SEEN if we encounter a register parameter. */
646 precompute_register_parameters (int num_actuals
, struct arg_data
*args
,
653 for (i
= 0; i
< num_actuals
; i
++)
654 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
)
658 if (args
[i
].value
== 0)
661 args
[i
].value
= expand_normal (args
[i
].tree_value
);
662 preserve_temp_slots (args
[i
].value
);
666 /* If the value is a non-legitimate constant, force it into a
667 pseudo now. TLS symbols sometimes need a call to resolve. */
668 if (CONSTANT_P (args
[i
].value
)
669 && !LEGITIMATE_CONSTANT_P (args
[i
].value
))
670 args
[i
].value
= force_reg (args
[i
].mode
, args
[i
].value
);
672 /* If we are to promote the function arg to a wider mode,
675 if (args
[i
].mode
!= TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)))
677 = convert_modes (args
[i
].mode
,
678 TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)),
679 args
[i
].value
, args
[i
].unsignedp
);
681 /* If we're going to have to load the value by parts, pull the
682 parts into pseudos. The part extraction process can involve
683 non-trivial computation. */
684 if (GET_CODE (args
[i
].reg
) == PARALLEL
)
686 tree type
= TREE_TYPE (args
[i
].tree_value
);
687 args
[i
].parallel_value
688 = emit_group_load_into_temps (args
[i
].reg
, args
[i
].value
,
689 type
, int_size_in_bytes (type
));
692 /* If the value is expensive, and we are inside an appropriately
693 short loop, put the value into a pseudo and then put the pseudo
696 For small register classes, also do this if this call uses
697 register parameters. This is to avoid reload conflicts while
698 loading the parameters registers. */
700 else if ((! (REG_P (args
[i
].value
)
701 || (GET_CODE (args
[i
].value
) == SUBREG
702 && REG_P (SUBREG_REG (args
[i
].value
)))))
703 && args
[i
].mode
!= BLKmode
704 && rtx_cost (args
[i
].value
, SET
) > COSTS_N_INSNS (1)
705 && ((SMALL_REGISTER_CLASSES
&& *reg_parm_seen
)
707 args
[i
].value
= copy_to_mode_reg (args
[i
].mode
, args
[i
].value
);
711 #ifdef REG_PARM_STACK_SPACE
713 /* The argument list is the property of the called routine and it
714 may clobber it. If the fixed area has been used for previous
715 parameters, we must save and restore it. */
718 save_fixed_argument_area (int reg_parm_stack_space
, rtx argblock
, int *low_to_save
, int *high_to_save
)
723 /* Compute the boundary of the area that needs to be saved, if any. */
724 high
= reg_parm_stack_space
;
725 #ifdef ARGS_GROW_DOWNWARD
728 if (high
> highest_outgoing_arg_in_use
)
729 high
= highest_outgoing_arg_in_use
;
731 for (low
= 0; low
< high
; low
++)
732 if (stack_usage_map
[low
] != 0)
735 enum machine_mode save_mode
;
740 while (stack_usage_map
[--high
] == 0)
744 *high_to_save
= high
;
746 num_to_save
= high
- low
+ 1;
747 save_mode
= mode_for_size (num_to_save
* BITS_PER_UNIT
, MODE_INT
, 1);
749 /* If we don't have the required alignment, must do this
751 if ((low
& (MIN (GET_MODE_SIZE (save_mode
),
752 BIGGEST_ALIGNMENT
/ UNITS_PER_WORD
) - 1)))
755 #ifdef ARGS_GROW_DOWNWARD
760 stack_area
= gen_rtx_MEM (save_mode
,
761 memory_address (save_mode
,
762 plus_constant (argblock
,
765 set_mem_align (stack_area
, PARM_BOUNDARY
);
766 if (save_mode
== BLKmode
)
768 save_area
= assign_stack_temp (BLKmode
, num_to_save
, 0);
769 emit_block_move (validize_mem (save_area
), stack_area
,
770 GEN_INT (num_to_save
), BLOCK_OP_CALL_PARM
);
774 save_area
= gen_reg_rtx (save_mode
);
775 emit_move_insn (save_area
, stack_area
);
785 restore_fixed_argument_area (rtx save_area
, rtx argblock
, int high_to_save
, int low_to_save
)
787 enum machine_mode save_mode
= GET_MODE (save_area
);
791 #ifdef ARGS_GROW_DOWNWARD
792 delta
= -high_to_save
;
796 stack_area
= gen_rtx_MEM (save_mode
,
797 memory_address (save_mode
,
798 plus_constant (argblock
, delta
)));
799 set_mem_align (stack_area
, PARM_BOUNDARY
);
801 if (save_mode
!= BLKmode
)
802 emit_move_insn (stack_area
, save_area
);
804 emit_block_move (stack_area
, validize_mem (save_area
),
805 GEN_INT (high_to_save
- low_to_save
+ 1),
808 #endif /* REG_PARM_STACK_SPACE */
810 /* If any elements in ARGS refer to parameters that are to be passed in
811 registers, but not in memory, and whose alignment does not permit a
812 direct copy into registers. Copy the values into a group of pseudos
813 which we will later copy into the appropriate hard registers.
815 Pseudos for each unaligned argument will be stored into the array
816 args[argnum].aligned_regs. The caller is responsible for deallocating
817 the aligned_regs array if it is nonzero. */
820 store_unaligned_arguments_into_pseudos (struct arg_data
*args
, int num_actuals
)
824 for (i
= 0; i
< num_actuals
; i
++)
825 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
826 && args
[i
].mode
== BLKmode
827 && (TYPE_ALIGN (TREE_TYPE (args
[i
].tree_value
))
828 < (unsigned int) MIN (BIGGEST_ALIGNMENT
, BITS_PER_WORD
)))
830 int bytes
= int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
831 int endian_correction
= 0;
835 gcc_assert (args
[i
].partial
% UNITS_PER_WORD
== 0);
836 args
[i
].n_aligned_regs
= args
[i
].partial
/ UNITS_PER_WORD
;
840 args
[i
].n_aligned_regs
841 = (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
844 args
[i
].aligned_regs
= XNEWVEC (rtx
, args
[i
].n_aligned_regs
);
846 /* Structures smaller than a word are normally aligned to the
847 least significant byte. On a BYTES_BIG_ENDIAN machine,
848 this means we must skip the empty high order bytes when
849 calculating the bit offset. */
850 if (bytes
< UNITS_PER_WORD
851 #ifdef BLOCK_REG_PADDING
852 && (BLOCK_REG_PADDING (args
[i
].mode
,
853 TREE_TYPE (args
[i
].tree_value
), 1)
859 endian_correction
= BITS_PER_WORD
- bytes
* BITS_PER_UNIT
;
861 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
863 rtx reg
= gen_reg_rtx (word_mode
);
864 rtx word
= operand_subword_force (args
[i
].value
, j
, BLKmode
);
865 int bitsize
= MIN (bytes
* BITS_PER_UNIT
, BITS_PER_WORD
);
867 args
[i
].aligned_regs
[j
] = reg
;
868 word
= extract_bit_field (word
, bitsize
, 0, 1, NULL_RTX
,
869 word_mode
, word_mode
);
871 /* There is no need to restrict this code to loading items
872 in TYPE_ALIGN sized hunks. The bitfield instructions can
873 load up entire word sized registers efficiently.
875 ??? This may not be needed anymore.
876 We use to emit a clobber here but that doesn't let later
877 passes optimize the instructions we emit. By storing 0 into
878 the register later passes know the first AND to zero out the
879 bitfield being set in the register is unnecessary. The store
880 of 0 will be deleted as will at least the first AND. */
882 emit_move_insn (reg
, const0_rtx
);
884 bytes
-= bitsize
/ BITS_PER_UNIT
;
885 store_bit_field (reg
, bitsize
, endian_correction
, word_mode
,
891 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
894 NUM_ACTUALS is the total number of parameters.
896 N_NAMED_ARGS is the total number of named arguments.
898 FNDECL is the tree code for the target of this call (if known)
900 ARGS_SO_FAR holds state needed by the target to know where to place
903 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
904 for arguments which are passed in registers.
906 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
907 and may be modified by this routine.
909 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
910 flags which may may be modified by this routine.
912 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
913 that requires allocation of stack space.
915 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
916 the thunked-to function. */
919 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED
,
920 struct arg_data
*args
,
921 struct args_size
*args_size
,
922 int n_named_args ATTRIBUTE_UNUSED
,
923 tree actparms
, tree fndecl
,
924 CUMULATIVE_ARGS
*args_so_far
,
925 int reg_parm_stack_space
,
926 rtx
*old_stack_level
, int *old_pending_adj
,
927 int *must_preallocate
, int *ecf_flags
,
928 bool *may_tailcall
, bool call_from_thunk_p
)
930 /* 1 if scanning parms front to back, -1 if scanning back to front. */
933 /* Count arg position in order args appear. */
939 args_size
->constant
= 0;
942 /* In this loop, we consider args in the order they are written.
943 We fill up ARGS from the front or from the back if necessary
944 so that in any case the first arg to be pushed ends up at the front. */
946 if (PUSH_ARGS_REVERSED
)
948 i
= num_actuals
- 1, inc
= -1;
949 /* In this case, must reverse order of args
950 so that we compute and push the last arg first. */
957 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
958 for (p
= actparms
, argpos
= 0; p
; p
= TREE_CHAIN (p
), i
+= inc
, argpos
++)
960 tree type
= TREE_TYPE (TREE_VALUE (p
));
962 enum machine_mode mode
;
964 args
[i
].tree_value
= TREE_VALUE (p
);
966 /* Replace erroneous argument with constant zero. */
967 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
968 args
[i
].tree_value
= integer_zero_node
, type
= integer_type_node
;
970 /* If TYPE is a transparent union, pass things the way we would
971 pass the first field of the union. We have already verified that
972 the modes are the same. */
973 if (TREE_CODE (type
) == UNION_TYPE
&& TYPE_TRANSPARENT_UNION (type
))
974 type
= TREE_TYPE (TYPE_FIELDS (type
));
976 /* Decide where to pass this arg.
978 args[i].reg is nonzero if all or part is passed in registers.
980 args[i].partial is nonzero if part but not all is passed in registers,
981 and the exact value says how many bytes are passed in registers.
983 args[i].pass_on_stack is nonzero if the argument must at least be
984 computed on the stack. It may then be loaded back into registers
985 if args[i].reg is nonzero.
987 These decisions are driven by the FUNCTION_... macros and must agree
988 with those made by function.c. */
990 /* See if this argument should be passed by invisible reference. */
991 if (pass_by_reference (args_so_far
, TYPE_MODE (type
),
992 type
, argpos
< n_named_args
))
998 = reference_callee_copied (args_so_far
, TYPE_MODE (type
),
999 type
, argpos
< n_named_args
);
1001 /* If we're compiling a thunk, pass through invisible references
1002 instead of making a copy. */
1003 if (call_from_thunk_p
1005 && !TREE_ADDRESSABLE (type
)
1006 && (base
= get_base_address (args
[i
].tree_value
))
1007 && (!DECL_P (base
) || MEM_P (DECL_RTL (base
)))))
1009 /* We can't use sibcalls if a callee-copied argument is
1010 stored in the current function's frame. */
1011 if (!call_from_thunk_p
&& DECL_P (base
) && !TREE_STATIC (base
))
1012 *may_tailcall
= false;
1014 args
[i
].tree_value
= build_fold_addr_expr (args
[i
].tree_value
);
1015 type
= TREE_TYPE (args
[i
].tree_value
);
1017 *ecf_flags
&= ~(ECF_CONST
| ECF_LIBCALL_BLOCK
);
1021 /* We make a copy of the object and pass the address to the
1022 function being called. */
1025 if (!COMPLETE_TYPE_P (type
)
1026 || TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
1027 || (flag_stack_check
&& ! STACK_CHECK_BUILTIN
1028 && (0 < compare_tree_int (TYPE_SIZE_UNIT (type
),
1029 STACK_CHECK_MAX_VAR_SIZE
))))
1031 /* This is a variable-sized object. Make space on the stack
1033 rtx size_rtx
= expr_size (TREE_VALUE (p
));
1035 if (*old_stack_level
== 0)
1037 emit_stack_save (SAVE_BLOCK
, old_stack_level
, NULL_RTX
);
1038 *old_pending_adj
= pending_stack_adjust
;
1039 pending_stack_adjust
= 0;
1042 copy
= gen_rtx_MEM (BLKmode
,
1043 allocate_dynamic_stack_space
1044 (size_rtx
, NULL_RTX
, TYPE_ALIGN (type
)));
1045 set_mem_attributes (copy
, type
, 1);
1048 copy
= assign_temp (type
, 0, 1, 0);
1050 store_expr (args
[i
].tree_value
, copy
, 0);
1053 *ecf_flags
&= ~(ECF_CONST
| ECF_LIBCALL_BLOCK
);
1055 *ecf_flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LIBCALL_BLOCK
);
1058 = build_fold_addr_expr (make_tree (type
, copy
));
1059 type
= TREE_TYPE (args
[i
].tree_value
);
1060 *may_tailcall
= false;
1064 mode
= TYPE_MODE (type
);
1065 unsignedp
= TYPE_UNSIGNED (type
);
1067 if (targetm
.calls
.promote_function_args (fndecl
? TREE_TYPE (fndecl
) : 0))
1068 mode
= promote_mode (type
, mode
, &unsignedp
, 1);
1070 args
[i
].unsignedp
= unsignedp
;
1071 args
[i
].mode
= mode
;
1073 args
[i
].reg
= FUNCTION_ARG (*args_so_far
, mode
, type
,
1074 argpos
< n_named_args
);
1075 #ifdef FUNCTION_INCOMING_ARG
1076 /* If this is a sibling call and the machine has register windows, the
1077 register window has to be unwinded before calling the routine, so
1078 arguments have to go into the incoming registers. */
1079 args
[i
].tail_call_reg
= FUNCTION_INCOMING_ARG (*args_so_far
, mode
, type
,
1080 argpos
< n_named_args
);
1082 args
[i
].tail_call_reg
= args
[i
].reg
;
1087 = targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, type
,
1088 argpos
< n_named_args
);
1090 args
[i
].pass_on_stack
= targetm
.calls
.must_pass_in_stack (mode
, type
);
1092 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1093 it means that we are to pass this arg in the register(s) designated
1094 by the PARALLEL, but also to pass it in the stack. */
1095 if (args
[i
].reg
&& GET_CODE (args
[i
].reg
) == PARALLEL
1096 && XEXP (XVECEXP (args
[i
].reg
, 0, 0), 0) == 0)
1097 args
[i
].pass_on_stack
= 1;
1099 /* If this is an addressable type, we must preallocate the stack
1100 since we must evaluate the object into its final location.
1102 If this is to be passed in both registers and the stack, it is simpler
1104 if (TREE_ADDRESSABLE (type
)
1105 || (args
[i
].pass_on_stack
&& args
[i
].reg
!= 0))
1106 *must_preallocate
= 1;
1108 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1109 we cannot consider this function call constant. */
1110 if (TREE_ADDRESSABLE (type
))
1111 *ecf_flags
&= ~ECF_LIBCALL_BLOCK
;
1113 /* Compute the stack-size of this argument. */
1114 if (args
[i
].reg
== 0 || args
[i
].partial
!= 0
1115 || reg_parm_stack_space
> 0
1116 || args
[i
].pass_on_stack
)
1117 locate_and_pad_parm (mode
, type
,
1118 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1123 args
[i
].pass_on_stack
? 0 : args
[i
].partial
,
1124 fndecl
, args_size
, &args
[i
].locate
);
1125 #ifdef BLOCK_REG_PADDING
1127 /* The argument is passed entirely in registers. See at which
1128 end it should be padded. */
1129 args
[i
].locate
.where_pad
=
1130 BLOCK_REG_PADDING (mode
, type
,
1131 int_size_in_bytes (type
) <= UNITS_PER_WORD
);
1134 /* Update ARGS_SIZE, the total stack space for args so far. */
1136 args_size
->constant
+= args
[i
].locate
.size
.constant
;
1137 if (args
[i
].locate
.size
.var
)
1138 ADD_PARM_SIZE (*args_size
, args
[i
].locate
.size
.var
);
1140 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1141 have been used, etc. */
1143 FUNCTION_ARG_ADVANCE (*args_so_far
, TYPE_MODE (type
), type
,
1144 argpos
< n_named_args
);
1148 /* Update ARGS_SIZE to contain the total size for the argument block.
1149 Return the original constant component of the argument block's size.
1151 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1152 for arguments passed in registers. */
1155 compute_argument_block_size (int reg_parm_stack_space
,
1156 struct args_size
*args_size
,
1157 int preferred_stack_boundary ATTRIBUTE_UNUSED
)
1159 int unadjusted_args_size
= args_size
->constant
;
1161 /* For accumulate outgoing args mode we don't need to align, since the frame
1162 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1163 backends from generating misaligned frame sizes. */
1164 if (ACCUMULATE_OUTGOING_ARGS
&& preferred_stack_boundary
> STACK_BOUNDARY
)
1165 preferred_stack_boundary
= STACK_BOUNDARY
;
1167 /* Compute the actual size of the argument block required. The variable
1168 and constant sizes must be combined, the size may have to be rounded,
1169 and there may be a minimum required size. */
1173 args_size
->var
= ARGS_SIZE_TREE (*args_size
);
1174 args_size
->constant
= 0;
1176 preferred_stack_boundary
/= BITS_PER_UNIT
;
1177 if (preferred_stack_boundary
> 1)
1179 /* We don't handle this case yet. To handle it correctly we have
1180 to add the delta, round and subtract the delta.
1181 Currently no machine description requires this support. */
1182 gcc_assert (!(stack_pointer_delta
& (preferred_stack_boundary
- 1)));
1183 args_size
->var
= round_up (args_size
->var
, preferred_stack_boundary
);
1186 if (reg_parm_stack_space
> 0)
1189 = size_binop (MAX_EXPR
, args_size
->var
,
1190 ssize_int (reg_parm_stack_space
));
1192 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1193 /* The area corresponding to register parameters is not to count in
1194 the size of the block we need. So make the adjustment. */
1196 = size_binop (MINUS_EXPR
, args_size
->var
,
1197 ssize_int (reg_parm_stack_space
));
1203 preferred_stack_boundary
/= BITS_PER_UNIT
;
1204 if (preferred_stack_boundary
< 1)
1205 preferred_stack_boundary
= 1;
1206 args_size
->constant
= (((args_size
->constant
1207 + stack_pointer_delta
1208 + preferred_stack_boundary
- 1)
1209 / preferred_stack_boundary
1210 * preferred_stack_boundary
)
1211 - stack_pointer_delta
);
1213 args_size
->constant
= MAX (args_size
->constant
,
1214 reg_parm_stack_space
);
1216 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1217 args_size
->constant
-= reg_parm_stack_space
;
1220 return unadjusted_args_size
;
1223 /* Precompute parameters as needed for a function call.
1225 FLAGS is mask of ECF_* constants.
1227 NUM_ACTUALS is the number of arguments.
1229 ARGS is an array containing information for each argument; this
1230 routine fills in the INITIAL_VALUE and VALUE fields for each
1231 precomputed argument. */
1234 precompute_arguments (int flags
, int num_actuals
, struct arg_data
*args
)
1238 /* If this is a libcall, then precompute all arguments so that we do not
1239 get extraneous instructions emitted as part of the libcall sequence. */
1241 /* If we preallocated the stack space, and some arguments must be passed
1242 on the stack, then we must precompute any parameter which contains a
1243 function call which will store arguments on the stack.
1244 Otherwise, evaluating the parameter may clobber previous parameters
1245 which have already been stored into the stack. (we have code to avoid
1246 such case by saving the outgoing stack arguments, but it results in
1248 if ((flags
& ECF_LIBCALL_BLOCK
) == 0 && !ACCUMULATE_OUTGOING_ARGS
)
1251 for (i
= 0; i
< num_actuals
; i
++)
1253 enum machine_mode mode
;
1255 if ((flags
& ECF_LIBCALL_BLOCK
) == 0
1256 && TREE_CODE (args
[i
].tree_value
) != CALL_EXPR
)
1259 /* If this is an addressable type, we cannot pre-evaluate it. */
1260 gcc_assert (!TREE_ADDRESSABLE (TREE_TYPE (args
[i
].tree_value
)));
1262 args
[i
].initial_value
= args
[i
].value
1263 = expand_normal (args
[i
].tree_value
);
1265 mode
= TYPE_MODE (TREE_TYPE (args
[i
].tree_value
));
1266 if (mode
!= args
[i
].mode
)
1269 = convert_modes (args
[i
].mode
, mode
,
1270 args
[i
].value
, args
[i
].unsignedp
);
1271 #if defined(PROMOTE_FUNCTION_MODE) && !defined(PROMOTE_MODE)
1272 /* CSE will replace this only if it contains args[i].value
1273 pseudo, so convert it down to the declared mode using
1275 if (REG_P (args
[i
].value
)
1276 && GET_MODE_CLASS (args
[i
].mode
) == MODE_INT
)
1278 args
[i
].initial_value
1279 = gen_lowpart_SUBREG (mode
, args
[i
].value
);
1280 SUBREG_PROMOTED_VAR_P (args
[i
].initial_value
) = 1;
1281 SUBREG_PROMOTED_UNSIGNED_SET (args
[i
].initial_value
,
1289 /* Given the current state of MUST_PREALLOCATE and information about
1290 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1291 compute and return the final value for MUST_PREALLOCATE. */
1294 finalize_must_preallocate (int must_preallocate
, int num_actuals
, struct arg_data
*args
, struct args_size
*args_size
)
1296 /* See if we have or want to preallocate stack space.
1298 If we would have to push a partially-in-regs parm
1299 before other stack parms, preallocate stack space instead.
1301 If the size of some parm is not a multiple of the required stack
1302 alignment, we must preallocate.
1304 If the total size of arguments that would otherwise create a copy in
1305 a temporary (such as a CALL) is more than half the total argument list
1306 size, preallocation is faster.
1308 Another reason to preallocate is if we have a machine (like the m88k)
1309 where stack alignment is required to be maintained between every
1310 pair of insns, not just when the call is made. However, we assume here
1311 that such machines either do not have push insns (and hence preallocation
1312 would occur anyway) or the problem is taken care of with
1315 if (! must_preallocate
)
1317 int partial_seen
= 0;
1318 int copy_to_evaluate_size
= 0;
1321 for (i
= 0; i
< num_actuals
&& ! must_preallocate
; i
++)
1323 if (args
[i
].partial
> 0 && ! args
[i
].pass_on_stack
)
1325 else if (partial_seen
&& args
[i
].reg
== 0)
1326 must_preallocate
= 1;
1328 if (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)) == BLKmode
1329 && (TREE_CODE (args
[i
].tree_value
) == CALL_EXPR
1330 || TREE_CODE (args
[i
].tree_value
) == TARGET_EXPR
1331 || TREE_CODE (args
[i
].tree_value
) == COND_EXPR
1332 || TREE_ADDRESSABLE (TREE_TYPE (args
[i
].tree_value
))))
1333 copy_to_evaluate_size
1334 += int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1337 if (copy_to_evaluate_size
* 2 >= args_size
->constant
1338 && args_size
->constant
> 0)
1339 must_preallocate
= 1;
1341 return must_preallocate
;
1344 /* If we preallocated stack space, compute the address of each argument
1345 and store it into the ARGS array.
1347 We need not ensure it is a valid memory address here; it will be
1348 validized when it is used.
1350 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1353 compute_argument_addresses (struct arg_data
*args
, rtx argblock
, int num_actuals
)
1357 rtx arg_reg
= argblock
;
1358 int i
, arg_offset
= 0;
1360 if (GET_CODE (argblock
) == PLUS
)
1361 arg_reg
= XEXP (argblock
, 0), arg_offset
= INTVAL (XEXP (argblock
, 1));
1363 for (i
= 0; i
< num_actuals
; i
++)
1365 rtx offset
= ARGS_SIZE_RTX (args
[i
].locate
.offset
);
1366 rtx slot_offset
= ARGS_SIZE_RTX (args
[i
].locate
.slot_offset
);
1368 unsigned int align
, boundary
;
1369 unsigned int units_on_stack
= 0;
1370 enum machine_mode partial_mode
= VOIDmode
;
1372 /* Skip this parm if it will not be passed on the stack. */
1373 if (! args
[i
].pass_on_stack
1375 && args
[i
].partial
== 0)
1378 if (GET_CODE (offset
) == CONST_INT
)
1379 addr
= plus_constant (arg_reg
, INTVAL (offset
));
1381 addr
= gen_rtx_PLUS (Pmode
, arg_reg
, offset
);
1383 addr
= plus_constant (addr
, arg_offset
);
1385 if (args
[i
].partial
!= 0)
1387 /* Only part of the parameter is being passed on the stack.
1388 Generate a simple memory reference of the correct size. */
1389 units_on_stack
= args
[i
].locate
.size
.constant
;
1390 partial_mode
= mode_for_size (units_on_stack
* BITS_PER_UNIT
,
1392 args
[i
].stack
= gen_rtx_MEM (partial_mode
, addr
);
1393 set_mem_size (args
[i
].stack
, GEN_INT (units_on_stack
));
1397 args
[i
].stack
= gen_rtx_MEM (args
[i
].mode
, addr
);
1398 set_mem_attributes (args
[i
].stack
,
1399 TREE_TYPE (args
[i
].tree_value
), 1);
1401 align
= BITS_PER_UNIT
;
1402 boundary
= args
[i
].locate
.boundary
;
1403 if (args
[i
].locate
.where_pad
!= downward
)
1405 else if (GET_CODE (offset
) == CONST_INT
)
1407 align
= INTVAL (offset
) * BITS_PER_UNIT
| boundary
;
1408 align
= align
& -align
;
1410 set_mem_align (args
[i
].stack
, align
);
1412 if (GET_CODE (slot_offset
) == CONST_INT
)
1413 addr
= plus_constant (arg_reg
, INTVAL (slot_offset
));
1415 addr
= gen_rtx_PLUS (Pmode
, arg_reg
, slot_offset
);
1417 addr
= plus_constant (addr
, arg_offset
);
1419 if (args
[i
].partial
!= 0)
1421 /* Only part of the parameter is being passed on the stack.
1422 Generate a simple memory reference of the correct size. */
1423 args
[i
].stack_slot
= gen_rtx_MEM (partial_mode
, addr
);
1424 set_mem_size (args
[i
].stack_slot
, GEN_INT (units_on_stack
));
1428 args
[i
].stack_slot
= gen_rtx_MEM (args
[i
].mode
, addr
);
1429 set_mem_attributes (args
[i
].stack_slot
,
1430 TREE_TYPE (args
[i
].tree_value
), 1);
1432 set_mem_align (args
[i
].stack_slot
, args
[i
].locate
.boundary
);
1434 /* Function incoming arguments may overlap with sibling call
1435 outgoing arguments and we cannot allow reordering of reads
1436 from function arguments with stores to outgoing arguments
1437 of sibling calls. */
1438 set_mem_alias_set (args
[i
].stack
, 0);
1439 set_mem_alias_set (args
[i
].stack_slot
, 0);
1444 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1445 in a call instruction.
1447 FNDECL is the tree node for the target function. For an indirect call
1448 FNDECL will be NULL_TREE.
1450 ADDR is the operand 0 of CALL_EXPR for this call. */
1453 rtx_for_function_call (tree fndecl
, tree addr
)
1457 /* Get the function to call, in the form of RTL. */
1460 /* If this is the first use of the function, see if we need to
1461 make an external definition for it. */
1462 if (! TREE_USED (fndecl
))
1464 assemble_external (fndecl
);
1465 TREE_USED (fndecl
) = 1;
1468 /* Get a SYMBOL_REF rtx for the function address. */
1469 funexp
= XEXP (DECL_RTL (fndecl
), 0);
1472 /* Generate an rtx (probably a pseudo-register) for the address. */
1475 funexp
= expand_normal (addr
);
1476 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1481 /* Return true if and only if SIZE storage units (usually bytes)
1482 starting from address ADDR overlap with already clobbered argument
1483 area. This function is used to determine if we should give up a
1487 mem_overlaps_already_clobbered_arg_p (rtx addr
, unsigned HOST_WIDE_INT size
)
1491 if (addr
== current_function_internal_arg_pointer
)
1493 else if (GET_CODE (addr
) == PLUS
1494 && XEXP (addr
, 0) == current_function_internal_arg_pointer
1495 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
1496 i
= INTVAL (XEXP (addr
, 1));
1497 /* Return true for arg pointer based indexed addressing. */
1498 else if (GET_CODE (addr
) == PLUS
1499 && (XEXP (addr
, 0) == current_function_internal_arg_pointer
1500 || XEXP (addr
, 1) == current_function_internal_arg_pointer
))
1505 #ifdef ARGS_GROW_DOWNWARD
1510 unsigned HOST_WIDE_INT k
;
1512 for (k
= 0; k
< size
; k
++)
1513 if (i
+ k
< stored_args_map
->n_bits
1514 && TEST_BIT (stored_args_map
, i
+ k
))
1521 /* Do the register loads required for any wholly-register parms or any
1522 parms which are passed both on the stack and in a register. Their
1523 expressions were already evaluated.
1525 Mark all register-parms as living through the call, putting these USE
1526 insns in the CALL_INSN_FUNCTION_USAGE field.
1528 When IS_SIBCALL, perform the check_sibcall_argument_overlap
1529 checking, setting *SIBCALL_FAILURE if appropriate. */
1532 load_register_parameters (struct arg_data
*args
, int num_actuals
,
1533 rtx
*call_fusage
, int flags
, int is_sibcall
,
1534 int *sibcall_failure
)
1538 for (i
= 0; i
< num_actuals
; i
++)
1540 rtx reg
= ((flags
& ECF_SIBCALL
)
1541 ? args
[i
].tail_call_reg
: args
[i
].reg
);
1544 int partial
= args
[i
].partial
;
1547 rtx before_arg
= get_last_insn ();
1548 /* Set non-negative if we must move a word at a time, even if
1549 just one word (e.g, partial == 4 && mode == DFmode). Set
1550 to -1 if we just use a normal move insn. This value can be
1551 zero if the argument is a zero size structure. */
1553 if (GET_CODE (reg
) == PARALLEL
)
1557 gcc_assert (partial
% UNITS_PER_WORD
== 0);
1558 nregs
= partial
/ UNITS_PER_WORD
;
1560 else if (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)) == BLKmode
)
1562 size
= int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1563 nregs
= (size
+ (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
1566 size
= GET_MODE_SIZE (args
[i
].mode
);
1568 /* Handle calls that pass values in multiple non-contiguous
1569 locations. The Irix 6 ABI has examples of this. */
1571 if (GET_CODE (reg
) == PARALLEL
)
1572 emit_group_move (reg
, args
[i
].parallel_value
);
1574 /* If simple case, just do move. If normal partial, store_one_arg
1575 has already loaded the register for us. In all other cases,
1576 load the register(s) from memory. */
1578 else if (nregs
== -1)
1580 emit_move_insn (reg
, args
[i
].value
);
1581 #ifdef BLOCK_REG_PADDING
1582 /* Handle case where we have a value that needs shifting
1583 up to the msb. eg. a QImode value and we're padding
1584 upward on a BYTES_BIG_ENDIAN machine. */
1585 if (size
< UNITS_PER_WORD
1586 && (args
[i
].locate
.where_pad
1587 == (BYTES_BIG_ENDIAN
? upward
: downward
)))
1590 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
1592 /* Assigning REG here rather than a temp makes CALL_FUSAGE
1593 report the whole reg as used. Strictly speaking, the
1594 call only uses SIZE bytes at the msb end, but it doesn't
1595 seem worth generating rtl to say that. */
1596 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
1597 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
,
1598 build_int_cst (NULL_TREE
, shift
),
1601 emit_move_insn (reg
, x
);
1606 /* If we have pre-computed the values to put in the registers in
1607 the case of non-aligned structures, copy them in now. */
1609 else if (args
[i
].n_aligned_regs
!= 0)
1610 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
1611 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
) + j
),
1612 args
[i
].aligned_regs
[j
]);
1614 else if (partial
== 0 || args
[i
].pass_on_stack
)
1616 rtx mem
= validize_mem (args
[i
].value
);
1618 /* Check for overlap with already clobbered argument area. */
1620 && mem_overlaps_already_clobbered_arg_p (XEXP (args
[i
].value
, 0),
1622 *sibcall_failure
= 1;
1624 /* Handle a BLKmode that needs shifting. */
1625 if (nregs
== 1 && size
< UNITS_PER_WORD
1626 #ifdef BLOCK_REG_PADDING
1627 && args
[i
].locate
.where_pad
== downward
1633 rtx tem
= operand_subword_force (mem
, 0, args
[i
].mode
);
1634 rtx ri
= gen_rtx_REG (word_mode
, REGNO (reg
));
1635 rtx x
= gen_reg_rtx (word_mode
);
1636 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
1637 enum tree_code dir
= BYTES_BIG_ENDIAN
? RSHIFT_EXPR
1640 emit_move_insn (x
, tem
);
1641 x
= expand_shift (dir
, word_mode
, x
,
1642 build_int_cst (NULL_TREE
, shift
),
1645 emit_move_insn (ri
, x
);
1648 move_block_to_reg (REGNO (reg
), mem
, nregs
, args
[i
].mode
);
1651 /* When a parameter is a block, and perhaps in other cases, it is
1652 possible that it did a load from an argument slot that was
1653 already clobbered. */
1655 && check_sibcall_argument_overlap (before_arg
, &args
[i
], 0))
1656 *sibcall_failure
= 1;
1658 /* Handle calls that pass values in multiple non-contiguous
1659 locations. The Irix 6 ABI has examples of this. */
1660 if (GET_CODE (reg
) == PARALLEL
)
1661 use_group_regs (call_fusage
, reg
);
1662 else if (nregs
== -1)
1663 use_reg (call_fusage
, reg
);
1665 use_regs (call_fusage
, REGNO (reg
), nregs
);
1670 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
1671 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
1672 bytes, then we would need to push some additional bytes to pad the
1673 arguments. So, we compute an adjust to the stack pointer for an
1674 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
1675 bytes. Then, when the arguments are pushed the stack will be perfectly
1676 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
1677 be popped after the call. Returns the adjustment. */
1680 combine_pending_stack_adjustment_and_call (int unadjusted_args_size
,
1681 struct args_size
*args_size
,
1682 unsigned int preferred_unit_stack_boundary
)
1684 /* The number of bytes to pop so that the stack will be
1685 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
1686 HOST_WIDE_INT adjustment
;
1687 /* The alignment of the stack after the arguments are pushed, if we
1688 just pushed the arguments without adjust the stack here. */
1689 unsigned HOST_WIDE_INT unadjusted_alignment
;
1691 unadjusted_alignment
1692 = ((stack_pointer_delta
+ unadjusted_args_size
)
1693 % preferred_unit_stack_boundary
);
1695 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
1696 as possible -- leaving just enough left to cancel out the
1697 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
1698 PENDING_STACK_ADJUST is non-negative, and congruent to
1699 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
1701 /* Begin by trying to pop all the bytes. */
1702 unadjusted_alignment
1703 = (unadjusted_alignment
1704 - (pending_stack_adjust
% preferred_unit_stack_boundary
));
1705 adjustment
= pending_stack_adjust
;
1706 /* Push enough additional bytes that the stack will be aligned
1707 after the arguments are pushed. */
1708 if (preferred_unit_stack_boundary
> 1)
1710 if (unadjusted_alignment
> 0)
1711 adjustment
-= preferred_unit_stack_boundary
- unadjusted_alignment
;
1713 adjustment
+= unadjusted_alignment
;
1716 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
1717 bytes after the call. The right number is the entire
1718 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
1719 by the arguments in the first place. */
1721 = pending_stack_adjust
- adjustment
+ unadjusted_args_size
;
1726 /* Scan X expression if it does not dereference any argument slots
1727 we already clobbered by tail call arguments (as noted in stored_args_map
1729 Return nonzero if X expression dereferences such argument slots,
1733 check_sibcall_argument_overlap_1 (rtx x
)
1742 code
= GET_CODE (x
);
1745 return mem_overlaps_already_clobbered_arg_p (XEXP (x
, 0),
1746 GET_MODE_SIZE (GET_MODE (x
)));
1748 /* Scan all subexpressions. */
1749 fmt
= GET_RTX_FORMAT (code
);
1750 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
1754 if (check_sibcall_argument_overlap_1 (XEXP (x
, i
)))
1757 else if (*fmt
== 'E')
1759 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1760 if (check_sibcall_argument_overlap_1 (XVECEXP (x
, i
, j
)))
1767 /* Scan sequence after INSN if it does not dereference any argument slots
1768 we already clobbered by tail call arguments (as noted in stored_args_map
1769 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
1770 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
1771 should be 0). Return nonzero if sequence after INSN dereferences such argument
1772 slots, zero otherwise. */
1775 check_sibcall_argument_overlap (rtx insn
, struct arg_data
*arg
, int mark_stored_args_map
)
1779 if (insn
== NULL_RTX
)
1780 insn
= get_insns ();
1782 insn
= NEXT_INSN (insn
);
1784 for (; insn
; insn
= NEXT_INSN (insn
))
1786 && check_sibcall_argument_overlap_1 (PATTERN (insn
)))
1789 if (mark_stored_args_map
)
1791 #ifdef ARGS_GROW_DOWNWARD
1792 low
= -arg
->locate
.slot_offset
.constant
- arg
->locate
.size
.constant
;
1794 low
= arg
->locate
.slot_offset
.constant
;
1797 for (high
= low
+ arg
->locate
.size
.constant
; low
< high
; low
++)
1798 SET_BIT (stored_args_map
, low
);
1800 return insn
!= NULL_RTX
;
1803 /* Given that a function returns a value of mode MODE at the most
1804 significant end of hard register VALUE, shift VALUE left or right
1805 as specified by LEFT_P. Return true if some action was needed. */
1808 shift_return_value (enum machine_mode mode
, bool left_p
, rtx value
)
1810 HOST_WIDE_INT shift
;
1812 gcc_assert (REG_P (value
) && HARD_REGISTER_P (value
));
1813 shift
= GET_MODE_BITSIZE (GET_MODE (value
)) - GET_MODE_BITSIZE (mode
);
1817 /* Use ashr rather than lshr for right shifts. This is for the benefit
1818 of the MIPS port, which requires SImode values to be sign-extended
1819 when stored in 64-bit registers. */
1820 if (!force_expand_binop (GET_MODE (value
), left_p
? ashl_optab
: ashr_optab
,
1821 value
, GEN_INT (shift
), value
, 1, OPTAB_WIDEN
))
1826 /* Generate all the code for a function call
1827 and return an rtx for its value.
1828 Store the value in TARGET (specified as an rtx) if convenient.
1829 If the value is stored in TARGET then TARGET is returned.
1830 If IGNORE is nonzero, then we ignore the value of the function call. */
1833 expand_call (tree exp
, rtx target
, int ignore
)
1835 /* Nonzero if we are currently expanding a call. */
1836 static int currently_expanding_call
= 0;
1838 /* List of actual parameters. */
1839 tree actparms
= TREE_OPERAND (exp
, 1);
1840 /* RTX for the function to be called. */
1842 /* Sequence of insns to perform a normal "call". */
1843 rtx normal_call_insns
= NULL_RTX
;
1844 /* Sequence of insns to perform a tail "call". */
1845 rtx tail_call_insns
= NULL_RTX
;
1846 /* Data type of the function. */
1848 tree type_arg_types
;
1849 /* Declaration of the function being called,
1850 or 0 if the function is computed (not known by name). */
1852 /* The type of the function being called. */
1854 bool try_tail_call
= CALL_EXPR_TAILCALL (exp
);
1857 /* Register in which non-BLKmode value will be returned,
1858 or 0 if no value or if value is BLKmode. */
1860 /* Address where we should return a BLKmode value;
1861 0 if value not BLKmode. */
1862 rtx structure_value_addr
= 0;
1863 /* Nonzero if that address is being passed by treating it as
1864 an extra, implicit first parameter. Otherwise,
1865 it is passed by being copied directly into struct_value_rtx. */
1866 int structure_value_addr_parm
= 0;
1867 /* Size of aggregate value wanted, or zero if none wanted
1868 or if we are using the non-reentrant PCC calling convention
1869 or expecting the value in registers. */
1870 HOST_WIDE_INT struct_value_size
= 0;
1871 /* Nonzero if called function returns an aggregate in memory PCC style,
1872 by returning the address of where to find it. */
1873 int pcc_struct_value
= 0;
1874 rtx struct_value
= 0;
1876 /* Number of actual parameters in this call, including struct value addr. */
1878 /* Number of named args. Args after this are anonymous ones
1879 and they must all go on the stack. */
1882 /* Vector of information about each argument.
1883 Arguments are numbered in the order they will be pushed,
1884 not the order they are written. */
1885 struct arg_data
*args
;
1887 /* Total size in bytes of all the stack-parms scanned so far. */
1888 struct args_size args_size
;
1889 struct args_size adjusted_args_size
;
1890 /* Size of arguments before any adjustments (such as rounding). */
1891 int unadjusted_args_size
;
1892 /* Data on reg parms scanned so far. */
1893 CUMULATIVE_ARGS args_so_far
;
1894 /* Nonzero if a reg parm has been scanned. */
1896 /* Nonzero if this is an indirect function call. */
1898 /* Nonzero if we must avoid push-insns in the args for this call.
1899 If stack space is allocated for register parameters, but not by the
1900 caller, then it is preallocated in the fixed part of the stack frame.
1901 So the entire argument block must then be preallocated (i.e., we
1902 ignore PUSH_ROUNDING in that case). */
1904 int must_preallocate
= !PUSH_ARGS
;
1906 /* Size of the stack reserved for parameter registers. */
1907 int reg_parm_stack_space
= 0;
1909 /* Address of space preallocated for stack parms
1910 (on machines that lack push insns), or 0 if space not preallocated. */
1913 /* Mask of ECF_ flags. */
1915 #ifdef REG_PARM_STACK_SPACE
1916 /* Define the boundary of the register parm stack space that needs to be
1918 int low_to_save
, high_to_save
;
1919 rtx save_area
= 0; /* Place that it is saved */
1922 int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
1923 char *initial_stack_usage_map
= stack_usage_map
;
1924 char *stack_usage_map_buf
= NULL
;
1926 int old_stack_allocated
;
1928 /* State variables to track stack modifications. */
1929 rtx old_stack_level
= 0;
1930 int old_stack_arg_under_construction
= 0;
1931 int old_pending_adj
= 0;
1932 int old_inhibit_defer_pop
= inhibit_defer_pop
;
1934 /* Some stack pointer alterations we make are performed via
1935 allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
1936 which we then also need to save/restore along the way. */
1937 int old_stack_pointer_delta
= 0;
1940 tree p
= TREE_OPERAND (exp
, 0);
1941 tree addr
= TREE_OPERAND (exp
, 0);
1943 /* The alignment of the stack, in bits. */
1944 unsigned HOST_WIDE_INT preferred_stack_boundary
;
1945 /* The alignment of the stack, in bytes. */
1946 unsigned HOST_WIDE_INT preferred_unit_stack_boundary
;
1947 /* The static chain value to use for this call. */
1948 rtx static_chain_value
;
1949 /* See if this is "nothrow" function call. */
1950 if (TREE_NOTHROW (exp
))
1951 flags
|= ECF_NOTHROW
;
1953 /* See if we can find a DECL-node for the actual function, and get the
1954 function attributes (flags) from the function decl or type node. */
1955 fndecl
= get_callee_fndecl (exp
);
1958 fntype
= TREE_TYPE (fndecl
);
1959 flags
|= flags_from_decl_or_type (fndecl
);
1963 fntype
= TREE_TYPE (TREE_TYPE (p
));
1964 flags
|= flags_from_decl_or_type (fntype
);
1967 struct_value
= targetm
.calls
.struct_value_rtx (fntype
, 0);
1969 /* Warn if this value is an aggregate type,
1970 regardless of which calling convention we are using for it. */
1971 if (AGGREGATE_TYPE_P (TREE_TYPE (exp
)))
1972 warning (OPT_Waggregate_return
, "function call has aggregate value");
1974 /* If the result of a pure or const function call is ignored (or void),
1975 and none of its arguments are volatile, we can avoid expanding the
1976 call and just evaluate the arguments for side-effects. */
1977 if ((flags
& (ECF_CONST
| ECF_PURE
))
1978 && (ignore
|| target
== const0_rtx
1979 || TYPE_MODE (TREE_TYPE (exp
)) == VOIDmode
))
1981 bool volatilep
= false;
1984 for (arg
= actparms
; arg
; arg
= TREE_CHAIN (arg
))
1985 if (TREE_THIS_VOLATILE (TREE_VALUE (arg
)))
1993 for (arg
= actparms
; arg
; arg
= TREE_CHAIN (arg
))
1994 expand_expr (TREE_VALUE (arg
), const0_rtx
,
1995 VOIDmode
, EXPAND_NORMAL
);
2000 #ifdef REG_PARM_STACK_SPACE
2001 reg_parm_stack_space
= REG_PARM_STACK_SPACE (fndecl
);
2004 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2005 if (reg_parm_stack_space
> 0 && PUSH_ARGS
)
2006 must_preallocate
= 1;
2009 /* Set up a place to return a structure. */
2011 /* Cater to broken compilers. */
2012 if (aggregate_value_p (exp
, fndecl
))
2014 /* This call returns a big structure. */
2015 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LIBCALL_BLOCK
);
2017 #ifdef PCC_STATIC_STRUCT_RETURN
2019 pcc_struct_value
= 1;
2021 #else /* not PCC_STATIC_STRUCT_RETURN */
2023 struct_value_size
= int_size_in_bytes (TREE_TYPE (exp
));
2025 if (target
&& MEM_P (target
) && CALL_EXPR_RETURN_SLOT_OPT (exp
))
2026 structure_value_addr
= XEXP (target
, 0);
2029 /* For variable-sized objects, we must be called with a target
2030 specified. If we were to allocate space on the stack here,
2031 we would have no way of knowing when to free it. */
2032 rtx d
= assign_temp (TREE_TYPE (exp
), 0, 1, 1);
2034 mark_temp_addr_taken (d
);
2035 structure_value_addr
= XEXP (d
, 0);
2039 #endif /* not PCC_STATIC_STRUCT_RETURN */
2042 /* Figure out the amount to which the stack should be aligned. */
2043 preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
2046 struct cgraph_rtl_info
*i
= cgraph_rtl_info (fndecl
);
2047 if (i
&& i
->preferred_incoming_stack_boundary
)
2048 preferred_stack_boundary
= i
->preferred_incoming_stack_boundary
;
2051 /* Operand 0 is a pointer-to-function; get the type of the function. */
2052 funtype
= TREE_TYPE (addr
);
2053 gcc_assert (POINTER_TYPE_P (funtype
));
2054 funtype
= TREE_TYPE (funtype
);
2056 /* Munge the tree to split complex arguments into their imaginary
2058 if (targetm
.calls
.split_complex_arg
)
2060 type_arg_types
= split_complex_types (TYPE_ARG_TYPES (funtype
));
2061 actparms
= split_complex_values (actparms
);
2064 type_arg_types
= TYPE_ARG_TYPES (funtype
);
2066 if (flags
& ECF_MAY_BE_ALLOCA
)
2067 current_function_calls_alloca
= 1;
2069 /* If struct_value_rtx is 0, it means pass the address
2070 as if it were an extra parameter. */
2071 if (structure_value_addr
&& struct_value
== 0)
2073 /* If structure_value_addr is a REG other than
2074 virtual_outgoing_args_rtx, we can use always use it. If it
2075 is not a REG, we must always copy it into a register.
2076 If it is virtual_outgoing_args_rtx, we must copy it to another
2077 register in some cases. */
2078 rtx temp
= (!REG_P (structure_value_addr
)
2079 || (ACCUMULATE_OUTGOING_ARGS
2080 && stack_arg_under_construction
2081 && structure_value_addr
== virtual_outgoing_args_rtx
)
2082 ? copy_addr_to_reg (convert_memory_address
2083 (Pmode
, structure_value_addr
))
2084 : structure_value_addr
);
2087 = tree_cons (error_mark_node
,
2088 make_tree (build_pointer_type (TREE_TYPE (funtype
)),
2091 structure_value_addr_parm
= 1;
2094 /* Count the arguments and set NUM_ACTUALS. */
2095 for (p
= actparms
, num_actuals
= 0; p
; p
= TREE_CHAIN (p
))
2098 /* Compute number of named args.
2099 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2101 if (type_arg_types
!= 0)
2103 = (list_length (type_arg_types
)
2104 /* Count the struct value address, if it is passed as a parm. */
2105 + structure_value_addr_parm
);
2107 /* If we know nothing, treat all args as named. */
2108 n_named_args
= num_actuals
;
2110 /* Start updating where the next arg would go.
2112 On some machines (such as the PA) indirect calls have a different
2113 calling convention than normal calls. The fourth argument in
2114 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2116 INIT_CUMULATIVE_ARGS (args_so_far
, funtype
, NULL_RTX
, fndecl
, n_named_args
);
2118 /* Now possibly adjust the number of named args.
2119 Normally, don't include the last named arg if anonymous args follow.
2120 We do include the last named arg if
2121 targetm.calls.strict_argument_naming() returns nonzero.
2122 (If no anonymous args follow, the result of list_length is actually
2123 one too large. This is harmless.)
2125 If targetm.calls.pretend_outgoing_varargs_named() returns
2126 nonzero, and targetm.calls.strict_argument_naming() returns zero,
2127 this machine will be able to place unnamed args that were passed
2128 in registers into the stack. So treat all args as named. This
2129 allows the insns emitting for a specific argument list to be
2130 independent of the function declaration.
2132 If targetm.calls.pretend_outgoing_varargs_named() returns zero,
2133 we do not have any reliable way to pass unnamed args in
2134 registers, so we must force them into memory. */
2136 if (type_arg_types
!= 0
2137 && targetm
.calls
.strict_argument_naming (&args_so_far
))
2139 else if (type_arg_types
!= 0
2140 && ! targetm
.calls
.pretend_outgoing_varargs_named (&args_so_far
))
2141 /* Don't include the last named arg. */
2144 /* Treat all args as named. */
2145 n_named_args
= num_actuals
;
2147 /* Make a vector to hold all the information about each arg. */
2148 args
= alloca (num_actuals
* sizeof (struct arg_data
));
2149 memset (args
, 0, num_actuals
* sizeof (struct arg_data
));
2151 /* Build up entries in the ARGS array, compute the size of the
2152 arguments into ARGS_SIZE, etc. */
2153 initialize_argument_information (num_actuals
, args
, &args_size
,
2154 n_named_args
, actparms
, fndecl
,
2155 &args_so_far
, reg_parm_stack_space
,
2156 &old_stack_level
, &old_pending_adj
,
2157 &must_preallocate
, &flags
,
2158 &try_tail_call
, CALL_FROM_THUNK_P (exp
));
2162 /* If this function requires a variable-sized argument list, don't
2163 try to make a cse'able block for this call. We may be able to
2164 do this eventually, but it is too complicated to keep track of
2165 what insns go in the cse'able block and which don't. */
2167 flags
&= ~ECF_LIBCALL_BLOCK
;
2168 must_preallocate
= 1;
2171 /* Now make final decision about preallocating stack space. */
2172 must_preallocate
= finalize_must_preallocate (must_preallocate
,
2176 /* If the structure value address will reference the stack pointer, we
2177 must stabilize it. We don't need to do this if we know that we are
2178 not going to adjust the stack pointer in processing this call. */
2180 if (structure_value_addr
2181 && (reg_mentioned_p (virtual_stack_dynamic_rtx
, structure_value_addr
)
2182 || reg_mentioned_p (virtual_outgoing_args_rtx
,
2183 structure_value_addr
))
2185 || (!ACCUMULATE_OUTGOING_ARGS
&& args_size
.constant
)))
2186 structure_value_addr
= copy_to_reg (structure_value_addr
);
2188 /* Tail calls can make things harder to debug, and we've traditionally
2189 pushed these optimizations into -O2. Don't try if we're already
2190 expanding a call, as that means we're an argument. Don't try if
2191 there's cleanups, as we know there's code to follow the call. */
2193 if (currently_expanding_call
++ != 0
2194 || !flag_optimize_sibling_calls
2196 || lookup_stmt_eh_region (exp
) >= 0)
2199 /* Rest of purposes for tail call optimizations to fail. */
2201 #ifdef HAVE_sibcall_epilogue
2202 !HAVE_sibcall_epilogue
2207 /* Doing sibling call optimization needs some work, since
2208 structure_value_addr can be allocated on the stack.
2209 It does not seem worth the effort since few optimizable
2210 sibling calls will return a structure. */
2211 || structure_value_addr
!= NULL_RTX
2212 /* Check whether the target is able to optimize the call
2214 || !targetm
.function_ok_for_sibcall (fndecl
, exp
)
2215 /* Functions that do not return exactly once may not be sibcall
2217 || (flags
& (ECF_RETURNS_TWICE
| ECF_NORETURN
))
2218 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr
)))
2219 /* If the called function is nested in the current one, it might access
2220 some of the caller's arguments, but could clobber them beforehand if
2221 the argument areas are shared. */
2222 || (fndecl
&& decl_function_context (fndecl
) == current_function_decl
)
2223 /* If this function requires more stack slots than the current
2224 function, we cannot change it into a sibling call.
2225 current_function_pretend_args_size is not part of the
2226 stack allocated by our caller. */
2227 || args_size
.constant
> (current_function_args_size
2228 - current_function_pretend_args_size
)
2229 /* If the callee pops its own arguments, then it must pop exactly
2230 the same number of arguments as the current function. */
2231 || (RETURN_POPS_ARGS (fndecl
, funtype
, args_size
.constant
)
2232 != RETURN_POPS_ARGS (current_function_decl
,
2233 TREE_TYPE (current_function_decl
),
2234 current_function_args_size
))
2235 || !lang_hooks
.decls
.ok_for_sibcall (fndecl
))
2238 /* Ensure current function's preferred stack boundary is at least
2239 what we need. We don't have to increase alignment for recursive
2241 if (cfun
->preferred_stack_boundary
< preferred_stack_boundary
2242 && fndecl
!= current_function_decl
)
2243 cfun
->preferred_stack_boundary
= preferred_stack_boundary
;
2244 if (fndecl
== current_function_decl
)
2245 cfun
->recursive_call_emit
= true;
2247 preferred_unit_stack_boundary
= preferred_stack_boundary
/ BITS_PER_UNIT
;
2249 /* We want to make two insn chains; one for a sibling call, the other
2250 for a normal call. We will select one of the two chains after
2251 initial RTL generation is complete. */
2252 for (pass
= try_tail_call
? 0 : 1; pass
< 2; pass
++)
2254 int sibcall_failure
= 0;
2255 /* We want to emit any pending stack adjustments before the tail
2256 recursion "call". That way we know any adjustment after the tail
2257 recursion call can be ignored if we indeed use the tail
2259 int save_pending_stack_adjust
= 0;
2260 int save_stack_pointer_delta
= 0;
2262 rtx before_call
, next_arg_reg
;
2266 /* State variables we need to save and restore between
2268 save_pending_stack_adjust
= pending_stack_adjust
;
2269 save_stack_pointer_delta
= stack_pointer_delta
;
2272 flags
&= ~ECF_SIBCALL
;
2274 flags
|= ECF_SIBCALL
;
2276 /* Other state variables that we must reinitialize each time
2277 through the loop (that are not initialized by the loop itself). */
2281 /* Start a new sequence for the normal call case.
2283 From this point on, if the sibling call fails, we want to set
2284 sibcall_failure instead of continuing the loop. */
2287 /* Don't let pending stack adjusts add up to too much.
2288 Also, do all pending adjustments now if there is any chance
2289 this might be a call to alloca or if we are expanding a sibling
2290 call sequence or if we are calling a function that is to return
2291 with stack pointer depressed.
2292 Also do the adjustments before a throwing call, otherwise
2293 exception handling can fail; PR 19225. */
2294 if (pending_stack_adjust
>= 32
2295 || (pending_stack_adjust
> 0
2296 && (flags
& (ECF_MAY_BE_ALLOCA
| ECF_SP_DEPRESSED
)))
2297 || (pending_stack_adjust
> 0
2298 && flag_exceptions
&& !(flags
& ECF_NOTHROW
))
2300 do_pending_stack_adjust ();
2302 /* When calling a const function, we must pop the stack args right away,
2303 so that the pop is deleted or moved with the call. */
2304 if (pass
&& (flags
& ECF_LIBCALL_BLOCK
))
2307 /* Precompute any arguments as needed. */
2309 precompute_arguments (flags
, num_actuals
, args
);
2311 /* Now we are about to start emitting insns that can be deleted
2312 if a libcall is deleted. */
2313 if (pass
&& (flags
& (ECF_LIBCALL_BLOCK
| ECF_MALLOC
)))
2316 if (pass
== 0 && cfun
->stack_protect_guard
)
2317 stack_protect_epilogue ();
2319 adjusted_args_size
= args_size
;
2320 /* Compute the actual size of the argument block required. The variable
2321 and constant sizes must be combined, the size may have to be rounded,
2322 and there may be a minimum required size. When generating a sibcall
2323 pattern, do not round up, since we'll be re-using whatever space our
2325 unadjusted_args_size
2326 = compute_argument_block_size (reg_parm_stack_space
,
2327 &adjusted_args_size
,
2329 : preferred_stack_boundary
));
2331 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
2333 /* The argument block when performing a sibling call is the
2334 incoming argument block. */
2337 argblock
= virtual_incoming_args_rtx
;
2339 #ifdef STACK_GROWS_DOWNWARD
2340 = plus_constant (argblock
, current_function_pretend_args_size
);
2342 = plus_constant (argblock
, -current_function_pretend_args_size
);
2344 stored_args_map
= sbitmap_alloc (args_size
.constant
);
2345 sbitmap_zero (stored_args_map
);
2348 /* If we have no actual push instructions, or shouldn't use them,
2349 make space for all args right now. */
2350 else if (adjusted_args_size
.var
!= 0)
2352 if (old_stack_level
== 0)
2354 emit_stack_save (SAVE_BLOCK
, &old_stack_level
, NULL_RTX
);
2355 old_stack_pointer_delta
= stack_pointer_delta
;
2356 old_pending_adj
= pending_stack_adjust
;
2357 pending_stack_adjust
= 0;
2358 /* stack_arg_under_construction says whether a stack arg is
2359 being constructed at the old stack level. Pushing the stack
2360 gets a clean outgoing argument block. */
2361 old_stack_arg_under_construction
= stack_arg_under_construction
;
2362 stack_arg_under_construction
= 0;
2364 argblock
= push_block (ARGS_SIZE_RTX (adjusted_args_size
), 0, 0);
2368 /* Note that we must go through the motions of allocating an argument
2369 block even if the size is zero because we may be storing args
2370 in the area reserved for register arguments, which may be part of
2373 int needed
= adjusted_args_size
.constant
;
2375 /* Store the maximum argument space used. It will be pushed by
2376 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2379 if (needed
> current_function_outgoing_args_size
)
2380 current_function_outgoing_args_size
= needed
;
2382 if (must_preallocate
)
2384 if (ACCUMULATE_OUTGOING_ARGS
)
2386 /* Since the stack pointer will never be pushed, it is
2387 possible for the evaluation of a parm to clobber
2388 something we have already written to the stack.
2389 Since most function calls on RISC machines do not use
2390 the stack, this is uncommon, but must work correctly.
2392 Therefore, we save any area of the stack that was already
2393 written and that we are using. Here we set up to do this
2394 by making a new stack usage map from the old one. The
2395 actual save will be done by store_one_arg.
2397 Another approach might be to try to reorder the argument
2398 evaluations to avoid this conflicting stack usage. */
2400 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2401 /* Since we will be writing into the entire argument area,
2402 the map must be allocated for its entire size, not just
2403 the part that is the responsibility of the caller. */
2404 needed
+= reg_parm_stack_space
;
2407 #ifdef ARGS_GROW_DOWNWARD
2408 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
2411 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
2414 if (stack_usage_map_buf
)
2415 free (stack_usage_map_buf
);
2416 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
2417 stack_usage_map
= stack_usage_map_buf
;
2419 if (initial_highest_arg_in_use
)
2420 memcpy (stack_usage_map
, initial_stack_usage_map
,
2421 initial_highest_arg_in_use
);
2423 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
2424 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
2425 (highest_outgoing_arg_in_use
2426 - initial_highest_arg_in_use
));
2429 /* The address of the outgoing argument list must not be
2430 copied to a register here, because argblock would be left
2431 pointing to the wrong place after the call to
2432 allocate_dynamic_stack_space below. */
2434 argblock
= virtual_outgoing_args_rtx
;
2438 if (inhibit_defer_pop
== 0)
2440 /* Try to reuse some or all of the pending_stack_adjust
2441 to get this space. */
2443 = (combine_pending_stack_adjustment_and_call
2444 (unadjusted_args_size
,
2445 &adjusted_args_size
,
2446 preferred_unit_stack_boundary
));
2448 /* combine_pending_stack_adjustment_and_call computes
2449 an adjustment before the arguments are allocated.
2450 Account for them and see whether or not the stack
2451 needs to go up or down. */
2452 needed
= unadjusted_args_size
- needed
;
2456 /* We're releasing stack space. */
2457 /* ??? We can avoid any adjustment at all if we're
2458 already aligned. FIXME. */
2459 pending_stack_adjust
= -needed
;
2460 do_pending_stack_adjust ();
2464 /* We need to allocate space. We'll do that in
2465 push_block below. */
2466 pending_stack_adjust
= 0;
2469 /* Special case this because overhead of `push_block' in
2470 this case is non-trivial. */
2472 argblock
= virtual_outgoing_args_rtx
;
2475 argblock
= push_block (GEN_INT (needed
), 0, 0);
2476 #ifdef ARGS_GROW_DOWNWARD
2477 argblock
= plus_constant (argblock
, needed
);
2481 /* We only really need to call `copy_to_reg' in the case
2482 where push insns are going to be used to pass ARGBLOCK
2483 to a function call in ARGS. In that case, the stack
2484 pointer changes value from the allocation point to the
2485 call point, and hence the value of
2486 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
2487 as well always do it. */
2488 argblock
= copy_to_reg (argblock
);
2493 if (ACCUMULATE_OUTGOING_ARGS
)
2495 /* The save/restore code in store_one_arg handles all
2496 cases except one: a constructor call (including a C
2497 function returning a BLKmode struct) to initialize
2499 if (stack_arg_under_construction
)
2501 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2502 rtx push_size
= GEN_INT (reg_parm_stack_space
2503 + adjusted_args_size
.constant
);
2505 rtx push_size
= GEN_INT (adjusted_args_size
.constant
);
2507 if (old_stack_level
== 0)
2509 emit_stack_save (SAVE_BLOCK
, &old_stack_level
,
2511 old_stack_pointer_delta
= stack_pointer_delta
;
2512 old_pending_adj
= pending_stack_adjust
;
2513 pending_stack_adjust
= 0;
2514 /* stack_arg_under_construction says whether a stack
2515 arg is being constructed at the old stack level.
2516 Pushing the stack gets a clean outgoing argument
2518 old_stack_arg_under_construction
2519 = stack_arg_under_construction
;
2520 stack_arg_under_construction
= 0;
2521 /* Make a new map for the new argument list. */
2522 if (stack_usage_map_buf
)
2523 free (stack_usage_map_buf
);
2524 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
2525 stack_usage_map
= stack_usage_map_buf
;
2526 memset (stack_usage_map
, 0, highest_outgoing_arg_in_use
);
2527 highest_outgoing_arg_in_use
= 0;
2529 allocate_dynamic_stack_space (push_size
, NULL_RTX
,
2533 /* If argument evaluation might modify the stack pointer,
2534 copy the address of the argument list to a register. */
2535 for (i
= 0; i
< num_actuals
; i
++)
2536 if (args
[i
].pass_on_stack
)
2538 argblock
= copy_addr_to_reg (argblock
);
2543 compute_argument_addresses (args
, argblock
, num_actuals
);
2545 /* If we push args individually in reverse order, perform stack alignment
2546 before the first push (the last arg). */
2547 if (PUSH_ARGS_REVERSED
&& argblock
== 0
2548 && adjusted_args_size
.constant
!= unadjusted_args_size
)
2550 /* When the stack adjustment is pending, we get better code
2551 by combining the adjustments. */
2552 if (pending_stack_adjust
2553 && ! (flags
& ECF_LIBCALL_BLOCK
)
2554 && ! inhibit_defer_pop
)
2556 pending_stack_adjust
2557 = (combine_pending_stack_adjustment_and_call
2558 (unadjusted_args_size
,
2559 &adjusted_args_size
,
2560 preferred_unit_stack_boundary
));
2561 do_pending_stack_adjust ();
2563 else if (argblock
== 0)
2564 anti_adjust_stack (GEN_INT (adjusted_args_size
.constant
2565 - unadjusted_args_size
));
2567 /* Now that the stack is properly aligned, pops can't safely
2568 be deferred during the evaluation of the arguments. */
2571 funexp
= rtx_for_function_call (fndecl
, addr
);
2573 /* Figure out the register where the value, if any, will come back. */
2575 if (TYPE_MODE (TREE_TYPE (exp
)) != VOIDmode
2576 && ! structure_value_addr
)
2578 if (pcc_struct_value
)
2579 valreg
= hard_function_value (build_pointer_type (TREE_TYPE (exp
)),
2580 fndecl
, NULL
, (pass
== 0));
2582 valreg
= hard_function_value (TREE_TYPE (exp
), fndecl
, fntype
,
2586 /* Precompute all register parameters. It isn't safe to compute anything
2587 once we have started filling any specific hard regs. */
2588 precompute_register_parameters (num_actuals
, args
, ®_parm_seen
);
2590 if (TREE_OPERAND (exp
, 2))
2591 static_chain_value
= expand_normal (TREE_OPERAND (exp
, 2));
2593 static_chain_value
= 0;
2595 #ifdef REG_PARM_STACK_SPACE
2596 /* Save the fixed argument area if it's part of the caller's frame and
2597 is clobbered by argument setup for this call. */
2598 if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
2599 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
2600 &low_to_save
, &high_to_save
);
2603 /* Now store (and compute if necessary) all non-register parms.
2604 These come before register parms, since they can require block-moves,
2605 which could clobber the registers used for register parms.
2606 Parms which have partial registers are not stored here,
2607 but we do preallocate space here if they want that. */
2609 for (i
= 0; i
< num_actuals
; i
++)
2610 if (args
[i
].reg
== 0 || args
[i
].pass_on_stack
)
2612 rtx before_arg
= get_last_insn ();
2614 if (store_one_arg (&args
[i
], argblock
, flags
,
2615 adjusted_args_size
.var
!= 0,
2616 reg_parm_stack_space
)
2618 && check_sibcall_argument_overlap (before_arg
,
2620 sibcall_failure
= 1;
2622 if (flags
& ECF_CONST
2624 && args
[i
].value
== args
[i
].stack
)
2625 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
2626 gen_rtx_USE (VOIDmode
,
2631 /* If we have a parm that is passed in registers but not in memory
2632 and whose alignment does not permit a direct copy into registers,
2633 make a group of pseudos that correspond to each register that we
2635 if (STRICT_ALIGNMENT
)
2636 store_unaligned_arguments_into_pseudos (args
, num_actuals
);
2638 /* Now store any partially-in-registers parm.
2639 This is the last place a block-move can happen. */
2641 for (i
= 0; i
< num_actuals
; i
++)
2642 if (args
[i
].partial
!= 0 && ! args
[i
].pass_on_stack
)
2644 rtx before_arg
= get_last_insn ();
2646 if (store_one_arg (&args
[i
], argblock
, flags
,
2647 adjusted_args_size
.var
!= 0,
2648 reg_parm_stack_space
)
2650 && check_sibcall_argument_overlap (before_arg
,
2652 sibcall_failure
= 1;
2655 /* If we pushed args in forward order, perform stack alignment
2656 after pushing the last arg. */
2657 if (!PUSH_ARGS_REVERSED
&& argblock
== 0)
2658 anti_adjust_stack (GEN_INT (adjusted_args_size
.constant
2659 - unadjusted_args_size
));
2661 /* If register arguments require space on the stack and stack space
2662 was not preallocated, allocate stack space here for arguments
2663 passed in registers. */
2664 #ifdef OUTGOING_REG_PARM_STACK_SPACE
2665 if (!ACCUMULATE_OUTGOING_ARGS
2666 && must_preallocate
== 0 && reg_parm_stack_space
> 0)
2667 anti_adjust_stack (GEN_INT (reg_parm_stack_space
));
2670 /* Pass the function the address in which to return a
2672 if (pass
!= 0 && structure_value_addr
&& ! structure_value_addr_parm
)
2674 structure_value_addr
2675 = convert_memory_address (Pmode
, structure_value_addr
);
2676 emit_move_insn (struct_value
,
2678 force_operand (structure_value_addr
,
2681 if (REG_P (struct_value
))
2682 use_reg (&call_fusage
, struct_value
);
2685 funexp
= prepare_call_address (funexp
, static_chain_value
,
2686 &call_fusage
, reg_parm_seen
, pass
== 0);
2688 load_register_parameters (args
, num_actuals
, &call_fusage
, flags
,
2689 pass
== 0, &sibcall_failure
);
2691 /* Save a pointer to the last insn before the call, so that we can
2692 later safely search backwards to find the CALL_INSN. */
2693 before_call
= get_last_insn ();
2695 /* Set up next argument register. For sibling calls on machines
2696 with register windows this should be the incoming register. */
2697 #ifdef FUNCTION_INCOMING_ARG
2699 next_arg_reg
= FUNCTION_INCOMING_ARG (args_so_far
, VOIDmode
,
2703 next_arg_reg
= FUNCTION_ARG (args_so_far
, VOIDmode
,
2706 /* All arguments and registers used for the call must be set up by
2709 /* Stack must be properly aligned now. */
2711 || !(stack_pointer_delta
% preferred_unit_stack_boundary
));
2713 /* Generate the actual call instruction. */
2714 emit_call_1 (funexp
, exp
, fndecl
, funtype
, unadjusted_args_size
,
2715 adjusted_args_size
.constant
, struct_value_size
,
2716 next_arg_reg
, valreg
, old_inhibit_defer_pop
, call_fusage
,
2717 flags
, & args_so_far
);
2719 /* If a non-BLKmode value is returned at the most significant end
2720 of a register, shift the register right by the appropriate amount
2721 and update VALREG accordingly. BLKmode values are handled by the
2722 group load/store machinery below. */
2723 if (!structure_value_addr
2724 && !pcc_struct_value
2725 && TYPE_MODE (TREE_TYPE (exp
)) != BLKmode
2726 && targetm
.calls
.return_in_msb (TREE_TYPE (exp
)))
2728 if (shift_return_value (TYPE_MODE (TREE_TYPE (exp
)), false, valreg
))
2729 sibcall_failure
= 1;
2730 valreg
= gen_rtx_REG (TYPE_MODE (TREE_TYPE (exp
)), REGNO (valreg
));
2733 /* If call is cse'able, make appropriate pair of reg-notes around it.
2734 Test valreg so we don't crash; may safely ignore `const'
2735 if return type is void. Disable for PARALLEL return values, because
2736 we have no way to move such values into a pseudo register. */
2737 if (pass
&& (flags
& ECF_LIBCALL_BLOCK
))
2741 bool failed
= valreg
== 0 || GET_CODE (valreg
) == PARALLEL
;
2743 insns
= get_insns ();
2745 /* Expansion of block moves possibly introduced a loop that may
2746 not appear inside libcall block. */
2747 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
2759 rtx temp
= gen_reg_rtx (GET_MODE (valreg
));
2761 /* Mark the return value as a pointer if needed. */
2762 if (TREE_CODE (TREE_TYPE (exp
)) == POINTER_TYPE
)
2763 mark_reg_pointer (temp
,
2764 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (exp
))));
2767 if (flag_unsafe_math_optimizations
2769 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
2770 && (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_SQRT
2771 || DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_SQRTF
2772 || DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_SQRTL
))
2773 note
= gen_rtx_fmt_e (SQRT
,
2775 args
[0].initial_value
);
2778 /* Construct an "equal form" for the value which
2779 mentions all the arguments in order as well as
2780 the function name. */
2781 for (i
= 0; i
< num_actuals
; i
++)
2782 note
= gen_rtx_EXPR_LIST (VOIDmode
,
2783 args
[i
].initial_value
, note
);
2784 note
= gen_rtx_EXPR_LIST (VOIDmode
, funexp
, note
);
2786 if (flags
& ECF_PURE
)
2787 note
= gen_rtx_EXPR_LIST (VOIDmode
,
2788 gen_rtx_USE (VOIDmode
,
2789 gen_rtx_MEM (BLKmode
,
2790 gen_rtx_SCRATCH (VOIDmode
))),
2793 emit_libcall_block (insns
, temp
, valreg
, note
);
2798 else if (pass
&& (flags
& ECF_MALLOC
))
2800 rtx temp
= gen_reg_rtx (GET_MODE (valreg
));
2803 /* The return value from a malloc-like function is a pointer. */
2804 if (TREE_CODE (TREE_TYPE (exp
)) == POINTER_TYPE
)
2805 mark_reg_pointer (temp
, BIGGEST_ALIGNMENT
);
2807 emit_move_insn (temp
, valreg
);
2809 /* The return value from a malloc-like function can not alias
2811 last
= get_last_insn ();
2813 gen_rtx_EXPR_LIST (REG_NOALIAS
, temp
, REG_NOTES (last
));
2815 /* Write out the sequence. */
2816 insns
= get_insns ();
2822 /* For calls to `setjmp', etc., inform flow.c it should complain
2823 if nonvolatile values are live. For functions that cannot return,
2824 inform flow that control does not fall through. */
2826 if ((flags
& ECF_NORETURN
) || pass
== 0)
2828 /* The barrier must be emitted
2829 immediately after the CALL_INSN. Some ports emit more
2830 than just a CALL_INSN above, so we must search for it here. */
2832 rtx last
= get_last_insn ();
2833 while (!CALL_P (last
))
2835 last
= PREV_INSN (last
);
2836 /* There was no CALL_INSN? */
2837 gcc_assert (last
!= before_call
);
2840 emit_barrier_after (last
);
2842 /* Stack adjustments after a noreturn call are dead code.
2843 However when NO_DEFER_POP is in effect, we must preserve
2844 stack_pointer_delta. */
2845 if (inhibit_defer_pop
== 0)
2847 stack_pointer_delta
= old_stack_allocated
;
2848 pending_stack_adjust
= 0;
2852 /* If value type not void, return an rtx for the value. */
2854 if (TYPE_MODE (TREE_TYPE (exp
)) == VOIDmode
2856 target
= const0_rtx
;
2857 else if (structure_value_addr
)
2859 if (target
== 0 || !MEM_P (target
))
2862 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)),
2863 memory_address (TYPE_MODE (TREE_TYPE (exp
)),
2864 structure_value_addr
));
2865 set_mem_attributes (target
, exp
, 1);
2868 else if (pcc_struct_value
)
2870 /* This is the special C++ case where we need to
2871 know what the true target was. We take care to
2872 never use this value more than once in one expression. */
2873 target
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)),
2874 copy_to_reg (valreg
));
2875 set_mem_attributes (target
, exp
, 1);
2877 /* Handle calls that return values in multiple non-contiguous locations.
2878 The Irix 6 ABI has examples of this. */
2879 else if (GET_CODE (valreg
) == PARALLEL
)
2883 /* This will only be assigned once, so it can be readonly. */
2884 tree nt
= build_qualified_type (TREE_TYPE (exp
),
2885 (TYPE_QUALS (TREE_TYPE (exp
))
2886 | TYPE_QUAL_CONST
));
2888 target
= assign_temp (nt
, 0, 1, 1);
2891 if (! rtx_equal_p (target
, valreg
))
2892 emit_group_store (target
, valreg
, TREE_TYPE (exp
),
2893 int_size_in_bytes (TREE_TYPE (exp
)));
2895 /* We can not support sibling calls for this case. */
2896 sibcall_failure
= 1;
2899 && GET_MODE (target
) == TYPE_MODE (TREE_TYPE (exp
))
2900 && GET_MODE (target
) == GET_MODE (valreg
))
2902 bool may_overlap
= false;
2904 /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
2905 reg to a plain register. */
2907 && HARD_REGISTER_P (valreg
)
2908 && CLASS_LIKELY_SPILLED_P (REGNO_REG_CLASS (REGNO (valreg
)))
2909 && !(REG_P (target
) && !HARD_REGISTER_P (target
)))
2910 valreg
= copy_to_reg (valreg
);
2912 /* If TARGET is a MEM in the argument area, and we have
2913 saved part of the argument area, then we can't store
2914 directly into TARGET as it may get overwritten when we
2915 restore the argument save area below. Don't work too
2916 hard though and simply force TARGET to a register if it
2917 is a MEM; the optimizer is quite likely to sort it out. */
2918 if (ACCUMULATE_OUTGOING_ARGS
&& pass
&& MEM_P (target
))
2919 for (i
= 0; i
< num_actuals
; i
++)
2920 if (args
[i
].save_area
)
2927 target
= copy_to_reg (valreg
);
2930 /* TARGET and VALREG cannot be equal at this point
2931 because the latter would not have
2932 REG_FUNCTION_VALUE_P true, while the former would if
2933 it were referring to the same register.
2935 If they refer to the same register, this move will be
2936 a no-op, except when function inlining is being
2938 emit_move_insn (target
, valreg
);
2940 /* If we are setting a MEM, this code must be executed.
2941 Since it is emitted after the call insn, sibcall
2942 optimization cannot be performed in that case. */
2944 sibcall_failure
= 1;
2947 else if (TYPE_MODE (TREE_TYPE (exp
)) == BLKmode
)
2949 target
= copy_blkmode_from_reg (target
, valreg
, TREE_TYPE (exp
));
2951 /* We can not support sibling calls for this case. */
2952 sibcall_failure
= 1;
2955 target
= copy_to_reg (valreg
);
2957 if (targetm
.calls
.promote_function_return(funtype
))
2959 /* If we promoted this return value, make the proper SUBREG.
2960 TARGET might be const0_rtx here, so be careful. */
2962 && TYPE_MODE (TREE_TYPE (exp
)) != BLKmode
2963 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
2965 tree type
= TREE_TYPE (exp
);
2966 int unsignedp
= TYPE_UNSIGNED (type
);
2968 enum machine_mode pmode
;
2970 pmode
= promote_mode (type
, TYPE_MODE (type
), &unsignedp
, 1);
2971 /* If we don't promote as expected, something is wrong. */
2972 gcc_assert (GET_MODE (target
) == pmode
);
2974 if ((WORDS_BIG_ENDIAN
|| BYTES_BIG_ENDIAN
)
2975 && (GET_MODE_SIZE (GET_MODE (target
))
2976 > GET_MODE_SIZE (TYPE_MODE (type
))))
2978 offset
= GET_MODE_SIZE (GET_MODE (target
))
2979 - GET_MODE_SIZE (TYPE_MODE (type
));
2980 if (! BYTES_BIG_ENDIAN
)
2981 offset
= (offset
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
2982 else if (! WORDS_BIG_ENDIAN
)
2983 offset
%= UNITS_PER_WORD
;
2985 target
= gen_rtx_SUBREG (TYPE_MODE (type
), target
, offset
);
2986 SUBREG_PROMOTED_VAR_P (target
) = 1;
2987 SUBREG_PROMOTED_UNSIGNED_SET (target
, unsignedp
);
2991 /* If size of args is variable or this was a constructor call for a stack
2992 argument, restore saved stack-pointer value. */
2994 if (old_stack_level
&& ! (flags
& ECF_SP_DEPRESSED
))
2996 emit_stack_restore (SAVE_BLOCK
, old_stack_level
, NULL_RTX
);
2997 stack_pointer_delta
= old_stack_pointer_delta
;
2998 pending_stack_adjust
= old_pending_adj
;
2999 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
3000 stack_arg_under_construction
= old_stack_arg_under_construction
;
3001 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3002 stack_usage_map
= initial_stack_usage_map
;
3003 sibcall_failure
= 1;
3005 else if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
3007 #ifdef REG_PARM_STACK_SPACE
3009 restore_fixed_argument_area (save_area
, argblock
,
3010 high_to_save
, low_to_save
);
3013 /* If we saved any argument areas, restore them. */
3014 for (i
= 0; i
< num_actuals
; i
++)
3015 if (args
[i
].save_area
)
3017 enum machine_mode save_mode
= GET_MODE (args
[i
].save_area
);
3019 = gen_rtx_MEM (save_mode
,
3020 memory_address (save_mode
,
3021 XEXP (args
[i
].stack_slot
, 0)));
3023 if (save_mode
!= BLKmode
)
3024 emit_move_insn (stack_area
, args
[i
].save_area
);
3026 emit_block_move (stack_area
, args
[i
].save_area
,
3027 GEN_INT (args
[i
].locate
.size
.constant
),
3028 BLOCK_OP_CALL_PARM
);
3031 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3032 stack_usage_map
= initial_stack_usage_map
;
3035 /* If this was alloca, record the new stack level for nonlocal gotos.
3036 Check for the handler slots since we might not have a save area
3037 for non-local gotos. */
3039 if ((flags
& ECF_MAY_BE_ALLOCA
) && cfun
->nonlocal_goto_save_area
!= 0)
3040 update_nonlocal_goto_save_area ();
3042 /* Free up storage we no longer need. */
3043 for (i
= 0; i
< num_actuals
; ++i
)
3044 if (args
[i
].aligned_regs
)
3045 free (args
[i
].aligned_regs
);
3047 insns
= get_insns ();
3052 tail_call_insns
= insns
;
3054 /* Restore the pending stack adjustment now that we have
3055 finished generating the sibling call sequence. */
3057 pending_stack_adjust
= save_pending_stack_adjust
;
3058 stack_pointer_delta
= save_stack_pointer_delta
;
3060 /* Prepare arg structure for next iteration. */
3061 for (i
= 0; i
< num_actuals
; i
++)
3064 args
[i
].aligned_regs
= 0;
3068 sbitmap_free (stored_args_map
);
3072 normal_call_insns
= insns
;
3074 /* Verify that we've deallocated all the stack we used. */
3075 gcc_assert ((flags
& ECF_NORETURN
)
3076 || (old_stack_allocated
3077 == stack_pointer_delta
- pending_stack_adjust
));
3080 /* If something prevents making this a sibling call,
3081 zero out the sequence. */
3082 if (sibcall_failure
)
3083 tail_call_insns
= NULL_RTX
;
3088 /* If tail call production succeeded, we need to remove REG_EQUIV notes on
3089 arguments too, as argument area is now clobbered by the call. */
3090 if (tail_call_insns
)
3092 emit_insn (tail_call_insns
);
3093 cfun
->tail_call_emit
= true;
3096 emit_insn (normal_call_insns
);
3098 currently_expanding_call
--;
3100 /* If this function returns with the stack pointer depressed, ensure
3101 this block saves and restores the stack pointer, show it was
3102 changed, and adjust for any outgoing arg space. */
3103 if (flags
& ECF_SP_DEPRESSED
)
3105 clear_pending_stack_adjust ();
3106 emit_insn (gen_rtx_CLOBBER (VOIDmode
, stack_pointer_rtx
));
3107 emit_move_insn (virtual_stack_dynamic_rtx
, stack_pointer_rtx
);
3110 if (stack_usage_map_buf
)
3111 free (stack_usage_map_buf
);
3116 /* A sibling call sequence invalidates any REG_EQUIV notes made for
3117 this function's incoming arguments.
3119 At the start of RTL generation we know the only REG_EQUIV notes
3120 in the rtl chain are those for incoming arguments, so we can look
3121 for REG_EQUIV notes between the start of the function and the
3122 NOTE_INSN_FUNCTION_BEG.
3124 This is (slight) overkill. We could keep track of the highest
3125 argument we clobber and be more selective in removing notes, but it
3126 does not seem to be worth the effort. */
3129 fixup_tail_calls (void)
3133 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3135 /* There are never REG_EQUIV notes for the incoming arguments
3136 after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
3138 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_FUNCTION_BEG
)
3143 rtx note
= find_reg_note (insn
, REG_EQUIV
, 0);
3146 /* Remove the note and keep looking at the notes for
3148 remove_note (insn
, note
);
3156 /* Traverse an argument list in VALUES and expand all complex
3157 arguments into their components. */
3159 split_complex_values (tree values
)
3163 /* Before allocating memory, check for the common case of no complex. */
3164 for (p
= values
; p
; p
= TREE_CHAIN (p
))
3166 tree type
= TREE_TYPE (TREE_VALUE (p
));
3167 if (type
&& TREE_CODE (type
) == COMPLEX_TYPE
3168 && targetm
.calls
.split_complex_arg (type
))
3174 values
= copy_list (values
);
3176 for (p
= values
; p
; p
= TREE_CHAIN (p
))
3178 tree complex_value
= TREE_VALUE (p
);
3181 complex_type
= TREE_TYPE (complex_value
);
3185 if (TREE_CODE (complex_type
) == COMPLEX_TYPE
3186 && targetm
.calls
.split_complex_arg (complex_type
))
3189 tree real
, imag
, next
;
3191 subtype
= TREE_TYPE (complex_type
);
3192 complex_value
= save_expr (complex_value
);
3193 real
= build1 (REALPART_EXPR
, subtype
, complex_value
);
3194 imag
= build1 (IMAGPART_EXPR
, subtype
, complex_value
);
3196 TREE_VALUE (p
) = real
;
3197 next
= TREE_CHAIN (p
);
3198 imag
= build_tree_list (NULL_TREE
, imag
);
3199 TREE_CHAIN (p
) = imag
;
3200 TREE_CHAIN (imag
) = next
;
3202 /* Skip the newly created node. */
3210 /* Traverse a list of TYPES and expand all complex types into their
3213 split_complex_types (tree types
)
3217 /* Before allocating memory, check for the common case of no complex. */
3218 for (p
= types
; p
; p
= TREE_CHAIN (p
))
3220 tree type
= TREE_VALUE (p
);
3221 if (TREE_CODE (type
) == COMPLEX_TYPE
3222 && targetm
.calls
.split_complex_arg (type
))
3228 types
= copy_list (types
);
3230 for (p
= types
; p
; p
= TREE_CHAIN (p
))
3232 tree complex_type
= TREE_VALUE (p
);
3234 if (TREE_CODE (complex_type
) == COMPLEX_TYPE
3235 && targetm
.calls
.split_complex_arg (complex_type
))
3239 /* Rewrite complex type with component type. */
3240 TREE_VALUE (p
) = TREE_TYPE (complex_type
);
3241 next
= TREE_CHAIN (p
);
3243 /* Add another component type for the imaginary part. */
3244 imag
= build_tree_list (NULL_TREE
, TREE_VALUE (p
));
3245 TREE_CHAIN (p
) = imag
;
3246 TREE_CHAIN (imag
) = next
;
3248 /* Skip the newly created node. */
3256 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3257 The RETVAL parameter specifies whether return value needs to be saved, other
3258 parameters are documented in the emit_library_call function below. */
3261 emit_library_call_value_1 (int retval
, rtx orgfun
, rtx value
,
3262 enum libcall_type fn_type
,
3263 enum machine_mode outmode
, int nargs
, va_list p
)
3265 /* Total size in bytes of all the stack-parms scanned so far. */
3266 struct args_size args_size
;
3267 /* Size of arguments before any adjustments (such as rounding). */
3268 struct args_size original_args_size
;
3274 CUMULATIVE_ARGS args_so_far
;
3278 enum machine_mode mode
;
3281 struct locate_and_pad_arg_data locate
;
3285 int old_inhibit_defer_pop
= inhibit_defer_pop
;
3286 rtx call_fusage
= 0;
3289 int pcc_struct_value
= 0;
3290 int struct_value_size
= 0;
3292 int reg_parm_stack_space
= 0;
3295 tree tfom
; /* type_for_mode (outmode, 0) */
3297 #ifdef REG_PARM_STACK_SPACE
3298 /* Define the boundary of the register parm stack space that needs to be
3300 int low_to_save
, high_to_save
;
3301 rtx save_area
= 0; /* Place that it is saved. */
3304 /* Size of the stack reserved for parameter registers. */
3305 int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
3306 char *initial_stack_usage_map
= stack_usage_map
;
3307 char *stack_usage_map_buf
= NULL
;
3309 rtx struct_value
= targetm
.calls
.struct_value_rtx (0, 0);
3311 #ifdef REG_PARM_STACK_SPACE
3312 reg_parm_stack_space
= REG_PARM_STACK_SPACE ((tree
) 0);
3315 /* By default, library functions can not throw. */
3316 flags
= ECF_NOTHROW
;
3328 case LCT_CONST_MAKE_BLOCK
:
3329 flags
|= ECF_CONST
| ECF_LIBCALL_BLOCK
;
3331 case LCT_PURE_MAKE_BLOCK
:
3332 flags
|= ECF_PURE
| ECF_LIBCALL_BLOCK
;
3335 flags
|= ECF_NORETURN
;
3338 flags
= ECF_NORETURN
;
3340 case LCT_RETURNS_TWICE
:
3341 flags
= ECF_RETURNS_TWICE
;
3346 /* Ensure current function's preferred stack boundary is at least
3348 if (cfun
->preferred_stack_boundary
< PREFERRED_STACK_BOUNDARY
)
3349 cfun
->preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
3351 /* If this kind of value comes back in memory,
3352 decide where in memory it should come back. */
3353 if (outmode
!= VOIDmode
)
3355 tfom
= lang_hooks
.types
.type_for_mode (outmode
, 0);
3356 if (aggregate_value_p (tfom
, 0))
3358 #ifdef PCC_STATIC_STRUCT_RETURN
3360 = hard_function_value (build_pointer_type (tfom
), 0, 0, 0);
3361 mem_value
= gen_rtx_MEM (outmode
, pointer_reg
);
3362 pcc_struct_value
= 1;
3364 value
= gen_reg_rtx (outmode
);
3365 #else /* not PCC_STATIC_STRUCT_RETURN */
3366 struct_value_size
= GET_MODE_SIZE (outmode
);
3367 if (value
!= 0 && MEM_P (value
))
3370 mem_value
= assign_temp (tfom
, 0, 1, 1);
3372 /* This call returns a big structure. */
3373 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LIBCALL_BLOCK
);
3377 tfom
= void_type_node
;
3379 /* ??? Unfinished: must pass the memory address as an argument. */
3381 /* Copy all the libcall-arguments out of the varargs data
3382 and into a vector ARGVEC.
3384 Compute how to pass each argument. We only support a very small subset
3385 of the full argument passing conventions to limit complexity here since
3386 library functions shouldn't have many args. */
3388 argvec
= alloca ((nargs
+ 1) * sizeof (struct arg
));
3389 memset (argvec
, 0, (nargs
+ 1) * sizeof (struct arg
));
3391 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3392 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far
, outmode
, fun
);
3394 INIT_CUMULATIVE_ARGS (args_so_far
, NULL_TREE
, fun
, 0, nargs
);
3397 args_size
.constant
= 0;
3402 /* Now we are about to start emitting insns that can be deleted
3403 if a libcall is deleted. */
3404 if (flags
& ECF_LIBCALL_BLOCK
)
3409 /* If there's a structure value address to be passed,
3410 either pass it in the special place, or pass it as an extra argument. */
3411 if (mem_value
&& struct_value
== 0 && ! pcc_struct_value
)
3413 rtx addr
= XEXP (mem_value
, 0);
3417 /* Make sure it is a reasonable operand for a move or push insn. */
3418 if (!REG_P (addr
) && !MEM_P (addr
)
3419 && ! (CONSTANT_P (addr
) && LEGITIMATE_CONSTANT_P (addr
)))
3420 addr
= force_operand (addr
, NULL_RTX
);
3422 argvec
[count
].value
= addr
;
3423 argvec
[count
].mode
= Pmode
;
3424 argvec
[count
].partial
= 0;
3426 argvec
[count
].reg
= FUNCTION_ARG (args_so_far
, Pmode
, NULL_TREE
, 1);
3427 gcc_assert (targetm
.calls
.arg_partial_bytes (&args_so_far
, Pmode
,
3428 NULL_TREE
, 1) == 0);
3430 locate_and_pad_parm (Pmode
, NULL_TREE
,
3431 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3434 argvec
[count
].reg
!= 0,
3436 0, NULL_TREE
, &args_size
, &argvec
[count
].locate
);
3438 if (argvec
[count
].reg
== 0 || argvec
[count
].partial
!= 0
3439 || reg_parm_stack_space
> 0)
3440 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
3442 FUNCTION_ARG_ADVANCE (args_so_far
, Pmode
, (tree
) 0, 1);
3447 for (; count
< nargs
; count
++)
3449 rtx val
= va_arg (p
, rtx
);
3450 enum machine_mode mode
= va_arg (p
, enum machine_mode
);
3452 /* We cannot convert the arg value to the mode the library wants here;
3453 must do it earlier where we know the signedness of the arg. */
3454 gcc_assert (mode
!= BLKmode
3455 && (GET_MODE (val
) == mode
|| GET_MODE (val
) == VOIDmode
));
3457 /* Make sure it is a reasonable operand for a move or push insn. */
3458 if (!REG_P (val
) && !MEM_P (val
)
3459 && ! (CONSTANT_P (val
) && LEGITIMATE_CONSTANT_P (val
)))
3460 val
= force_operand (val
, NULL_RTX
);
3462 if (pass_by_reference (&args_so_far
, mode
, NULL_TREE
, 1))
3466 = !reference_callee_copied (&args_so_far
, mode
, NULL_TREE
, 1);
3468 /* loop.c won't look at CALL_INSN_FUNCTION_USAGE of const/pure
3469 functions, so we have to pretend this isn't such a function. */
3470 if (flags
& ECF_LIBCALL_BLOCK
)
3472 rtx insns
= get_insns ();
3476 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LIBCALL_BLOCK
);
3478 /* If this was a CONST function, it is now PURE since
3479 it now reads memory. */
3480 if (flags
& ECF_CONST
)
3482 flags
&= ~ECF_CONST
;
3486 if (GET_MODE (val
) == MEM
&& !must_copy
)
3490 slot
= assign_temp (lang_hooks
.types
.type_for_mode (mode
, 0),
3492 emit_move_insn (slot
, val
);
3495 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
3496 gen_rtx_USE (VOIDmode
, slot
),
3499 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
3500 gen_rtx_CLOBBER (VOIDmode
,
3505 val
= force_operand (XEXP (slot
, 0), NULL_RTX
);
3508 argvec
[count
].value
= val
;
3509 argvec
[count
].mode
= mode
;
3511 argvec
[count
].reg
= FUNCTION_ARG (args_so_far
, mode
, NULL_TREE
, 1);
3513 argvec
[count
].partial
3514 = targetm
.calls
.arg_partial_bytes (&args_so_far
, mode
, NULL_TREE
, 1);
3516 locate_and_pad_parm (mode
, NULL_TREE
,
3517 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3520 argvec
[count
].reg
!= 0,
3522 argvec
[count
].partial
,
3523 NULL_TREE
, &args_size
, &argvec
[count
].locate
);
3525 gcc_assert (!argvec
[count
].locate
.size
.var
);
3527 if (argvec
[count
].reg
== 0 || argvec
[count
].partial
!= 0
3528 || reg_parm_stack_space
> 0)
3529 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
3531 FUNCTION_ARG_ADVANCE (args_so_far
, mode
, (tree
) 0, 1);
3534 /* If this machine requires an external definition for library
3535 functions, write one out. */
3536 assemble_external_libcall (fun
);
3538 original_args_size
= args_size
;
3539 args_size
.constant
= (((args_size
.constant
3540 + stack_pointer_delta
3544 - stack_pointer_delta
);
3546 args_size
.constant
= MAX (args_size
.constant
,
3547 reg_parm_stack_space
);
3549 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3550 args_size
.constant
-= reg_parm_stack_space
;
3553 if (args_size
.constant
> current_function_outgoing_args_size
)
3554 current_function_outgoing_args_size
= args_size
.constant
;
3556 if (ACCUMULATE_OUTGOING_ARGS
)
3558 /* Since the stack pointer will never be pushed, it is possible for
3559 the evaluation of a parm to clobber something we have already
3560 written to the stack. Since most function calls on RISC machines
3561 do not use the stack, this is uncommon, but must work correctly.
3563 Therefore, we save any area of the stack that was already written
3564 and that we are using. Here we set up to do this by making a new
3565 stack usage map from the old one.
3567 Another approach might be to try to reorder the argument
3568 evaluations to avoid this conflicting stack usage. */
3570 needed
= args_size
.constant
;
3572 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3573 /* Since we will be writing into the entire argument area, the
3574 map must be allocated for its entire size, not just the part that
3575 is the responsibility of the caller. */
3576 needed
+= reg_parm_stack_space
;
3579 #ifdef ARGS_GROW_DOWNWARD
3580 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
3583 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
3586 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
3587 stack_usage_map
= stack_usage_map_buf
;
3589 if (initial_highest_arg_in_use
)
3590 memcpy (stack_usage_map
, initial_stack_usage_map
,
3591 initial_highest_arg_in_use
);
3593 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
3594 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
3595 highest_outgoing_arg_in_use
- initial_highest_arg_in_use
);
3598 /* We must be careful to use virtual regs before they're instantiated,
3599 and real regs afterwards. Loop optimization, for example, can create
3600 new libcalls after we've instantiated the virtual regs, and if we
3601 use virtuals anyway, they won't match the rtl patterns. */
3603 if (virtuals_instantiated
)
3604 argblock
= plus_constant (stack_pointer_rtx
, STACK_POINTER_OFFSET
);
3606 argblock
= virtual_outgoing_args_rtx
;
3611 argblock
= push_block (GEN_INT (args_size
.constant
), 0, 0);
3614 /* If we push args individually in reverse order, perform stack alignment
3615 before the first push (the last arg). */
3616 if (argblock
== 0 && PUSH_ARGS_REVERSED
)
3617 anti_adjust_stack (GEN_INT (args_size
.constant
3618 - original_args_size
.constant
));
3620 if (PUSH_ARGS_REVERSED
)
3631 #ifdef REG_PARM_STACK_SPACE
3632 if (ACCUMULATE_OUTGOING_ARGS
)
3634 /* The argument list is the property of the called routine and it
3635 may clobber it. If the fixed area has been used for previous
3636 parameters, we must save and restore it. */
3637 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
3638 &low_to_save
, &high_to_save
);
3642 /* Push the args that need to be pushed. */
3644 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3645 are to be pushed. */
3646 for (count
= 0; count
< nargs
; count
++, argnum
+= inc
)
3648 enum machine_mode mode
= argvec
[argnum
].mode
;
3649 rtx val
= argvec
[argnum
].value
;
3650 rtx reg
= argvec
[argnum
].reg
;
3651 int partial
= argvec
[argnum
].partial
;
3652 int lower_bound
= 0, upper_bound
= 0, i
;
3654 if (! (reg
!= 0 && partial
== 0))
3656 if (ACCUMULATE_OUTGOING_ARGS
)
3658 /* If this is being stored into a pre-allocated, fixed-size,
3659 stack area, save any previous data at that location. */
3661 #ifdef ARGS_GROW_DOWNWARD
3662 /* stack_slot is negative, but we want to index stack_usage_map
3663 with positive values. */
3664 upper_bound
= -argvec
[argnum
].locate
.offset
.constant
+ 1;
3665 lower_bound
= upper_bound
- argvec
[argnum
].locate
.size
.constant
;
3667 lower_bound
= argvec
[argnum
].locate
.offset
.constant
;
3668 upper_bound
= lower_bound
+ argvec
[argnum
].locate
.size
.constant
;
3672 /* Don't worry about things in the fixed argument area;
3673 it has already been saved. */
3674 if (i
< reg_parm_stack_space
)
3675 i
= reg_parm_stack_space
;
3676 while (i
< upper_bound
&& stack_usage_map
[i
] == 0)
3679 if (i
< upper_bound
)
3681 /* We need to make a save area. */
3683 = argvec
[argnum
].locate
.size
.constant
* BITS_PER_UNIT
;
3684 enum machine_mode save_mode
3685 = mode_for_size (size
, MODE_INT
, 1);
3687 = plus_constant (argblock
,
3688 argvec
[argnum
].locate
.offset
.constant
);
3690 = gen_rtx_MEM (save_mode
, memory_address (save_mode
, adr
));
3692 if (save_mode
== BLKmode
)
3694 argvec
[argnum
].save_area
3695 = assign_stack_temp (BLKmode
,
3696 argvec
[argnum
].locate
.size
.constant
,
3699 emit_block_move (validize_mem (argvec
[argnum
].save_area
),
3701 GEN_INT (argvec
[argnum
].locate
.size
.constant
),
3702 BLOCK_OP_CALL_PARM
);
3706 argvec
[argnum
].save_area
= gen_reg_rtx (save_mode
);
3708 emit_move_insn (argvec
[argnum
].save_area
, stack_area
);
3713 emit_push_insn (val
, mode
, NULL_TREE
, NULL_RTX
, PARM_BOUNDARY
,
3714 partial
, reg
, 0, argblock
,
3715 GEN_INT (argvec
[argnum
].locate
.offset
.constant
),
3716 reg_parm_stack_space
,
3717 ARGS_SIZE_RTX (argvec
[argnum
].locate
.alignment_pad
));
3719 /* Now mark the segment we just used. */
3720 if (ACCUMULATE_OUTGOING_ARGS
)
3721 for (i
= lower_bound
; i
< upper_bound
; i
++)
3722 stack_usage_map
[i
] = 1;
3726 if (flags
& ECF_CONST
)
3730 /* Indicate argument access so that alias.c knows that these
3733 use
= plus_constant (argblock
,
3734 argvec
[argnum
].locate
.offset
.constant
);
3736 /* When arguments are pushed, trying to tell alias.c where
3737 exactly this argument is won't work, because the
3738 auto-increment causes confusion. So we merely indicate
3739 that we access something with a known mode somewhere on
3741 use
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3742 gen_rtx_SCRATCH (Pmode
));
3743 use
= gen_rtx_MEM (argvec
[argnum
].mode
, use
);
3744 use
= gen_rtx_USE (VOIDmode
, use
);
3745 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
, use
, call_fusage
);
3750 /* If we pushed args in forward order, perform stack alignment
3751 after pushing the last arg. */
3752 if (argblock
== 0 && !PUSH_ARGS_REVERSED
)
3753 anti_adjust_stack (GEN_INT (args_size
.constant
3754 - original_args_size
.constant
));
3756 if (PUSH_ARGS_REVERSED
)
3761 fun
= prepare_call_address (fun
, NULL
, &call_fusage
, 0, 0);
3763 /* Now load any reg parms into their regs. */
3765 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3766 are to be pushed. */
3767 for (count
= 0; count
< nargs
; count
++, argnum
+= inc
)
3769 enum machine_mode mode
= argvec
[argnum
].mode
;
3770 rtx val
= argvec
[argnum
].value
;
3771 rtx reg
= argvec
[argnum
].reg
;
3772 int partial
= argvec
[argnum
].partial
;
3774 /* Handle calls that pass values in multiple non-contiguous
3775 locations. The PA64 has examples of this for library calls. */
3776 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
3777 emit_group_load (reg
, val
, NULL_TREE
, GET_MODE_SIZE (mode
));
3778 else if (reg
!= 0 && partial
== 0)
3779 emit_move_insn (reg
, val
);
3784 /* Any regs containing parms remain in use through the call. */
3785 for (count
= 0; count
< nargs
; count
++)
3787 rtx reg
= argvec
[count
].reg
;
3788 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
3789 use_group_regs (&call_fusage
, reg
);
3791 use_reg (&call_fusage
, reg
);
3794 /* Pass the function the address in which to return a structure value. */
3795 if (mem_value
!= 0 && struct_value
!= 0 && ! pcc_struct_value
)
3797 emit_move_insn (struct_value
,
3799 force_operand (XEXP (mem_value
, 0),
3801 if (REG_P (struct_value
))
3802 use_reg (&call_fusage
, struct_value
);
3805 /* Don't allow popping to be deferred, since then
3806 cse'ing of library calls could delete a call and leave the pop. */
3808 valreg
= (mem_value
== 0 && outmode
!= VOIDmode
3809 ? hard_libcall_value (outmode
) : NULL_RTX
);
3811 /* Stack must be properly aligned now. */
3812 gcc_assert (!(stack_pointer_delta
3813 & (PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)));
3815 before_call
= get_last_insn ();
3817 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3818 will set inhibit_defer_pop to that value. */
3819 /* The return type is needed to decide how many bytes the function pops.
3820 Signedness plays no role in that, so for simplicity, we pretend it's
3821 always signed. We also assume that the list of arguments passed has
3822 no impact, so we pretend it is unknown. */
3824 emit_call_1 (fun
, NULL
,
3825 get_identifier (XSTR (orgfun
, 0)),
3826 build_function_type (tfom
, NULL_TREE
),
3827 original_args_size
.constant
, args_size
.constant
,
3829 FUNCTION_ARG (args_so_far
, VOIDmode
, void_type_node
, 1),
3831 old_inhibit_defer_pop
+ 1, call_fusage
, flags
, & args_so_far
);
3833 /* For calls to `setjmp', etc., inform flow.c it should complain
3834 if nonvolatile values are live. For functions that cannot return,
3835 inform flow that control does not fall through. */
3837 if (flags
& ECF_NORETURN
)
3839 /* The barrier note must be emitted
3840 immediately after the CALL_INSN. Some ports emit more than
3841 just a CALL_INSN above, so we must search for it here. */
3843 rtx last
= get_last_insn ();
3844 while (!CALL_P (last
))
3846 last
= PREV_INSN (last
);
3847 /* There was no CALL_INSN? */
3848 gcc_assert (last
!= before_call
);
3851 emit_barrier_after (last
);
3854 /* Now restore inhibit_defer_pop to its actual original value. */
3857 /* If call is cse'able, make appropriate pair of reg-notes around it.
3858 Test valreg so we don't crash; may safely ignore `const'
3859 if return type is void. Disable for PARALLEL return values, because
3860 we have no way to move such values into a pseudo register. */
3861 if (flags
& ECF_LIBCALL_BLOCK
)
3867 insns
= get_insns ();
3877 if (GET_CODE (valreg
) == PARALLEL
)
3879 temp
= gen_reg_rtx (outmode
);
3880 emit_group_store (temp
, valreg
, NULL_TREE
,
3881 GET_MODE_SIZE (outmode
));
3885 temp
= gen_reg_rtx (GET_MODE (valreg
));
3887 /* Construct an "equal form" for the value which mentions all the
3888 arguments in order as well as the function name. */
3889 for (i
= 0; i
< nargs
; i
++)
3890 note
= gen_rtx_EXPR_LIST (VOIDmode
, argvec
[i
].value
, note
);
3891 note
= gen_rtx_EXPR_LIST (VOIDmode
, fun
, note
);
3893 insns
= get_insns ();
3896 if (flags
& ECF_PURE
)
3897 note
= gen_rtx_EXPR_LIST (VOIDmode
,
3898 gen_rtx_USE (VOIDmode
,
3899 gen_rtx_MEM (BLKmode
,
3900 gen_rtx_SCRATCH (VOIDmode
))),
3903 emit_libcall_block (insns
, temp
, valreg
, note
);
3910 /* Copy the value to the right place. */
3911 if (outmode
!= VOIDmode
&& retval
)
3917 if (value
!= mem_value
)
3918 emit_move_insn (value
, mem_value
);
3920 else if (GET_CODE (valreg
) == PARALLEL
)
3923 value
= gen_reg_rtx (outmode
);
3924 emit_group_store (value
, valreg
, NULL_TREE
, GET_MODE_SIZE (outmode
));
3926 else if (value
!= 0)
3927 emit_move_insn (value
, valreg
);
3932 if (ACCUMULATE_OUTGOING_ARGS
)
3934 #ifdef REG_PARM_STACK_SPACE
3936 restore_fixed_argument_area (save_area
, argblock
,
3937 high_to_save
, low_to_save
);
3940 /* If we saved any argument areas, restore them. */
3941 for (count
= 0; count
< nargs
; count
++)
3942 if (argvec
[count
].save_area
)
3944 enum machine_mode save_mode
= GET_MODE (argvec
[count
].save_area
);
3945 rtx adr
= plus_constant (argblock
,
3946 argvec
[count
].locate
.offset
.constant
);
3947 rtx stack_area
= gen_rtx_MEM (save_mode
,
3948 memory_address (save_mode
, adr
));
3950 if (save_mode
== BLKmode
)
3951 emit_block_move (stack_area
,
3952 validize_mem (argvec
[count
].save_area
),
3953 GEN_INT (argvec
[count
].locate
.size
.constant
),
3954 BLOCK_OP_CALL_PARM
);
3956 emit_move_insn (stack_area
, argvec
[count
].save_area
);
3959 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3960 stack_usage_map
= initial_stack_usage_map
;
3963 if (stack_usage_map_buf
)
3964 free (stack_usage_map_buf
);
3970 /* Output a library call to function FUN (a SYMBOL_REF rtx)
3971 (emitting the queue unless NO_QUEUE is nonzero),
3972 for a value of mode OUTMODE,
3973 with NARGS different arguments, passed as alternating rtx values
3974 and machine_modes to convert them to.
3976 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for `const'
3977 calls, LCT_PURE for `pure' calls, LCT_CONST_MAKE_BLOCK for `const' calls
3978 which should be enclosed in REG_LIBCALL/REG_RETVAL notes,
3979 LCT_PURE_MAKE_BLOCK for `purep' calls which should be enclosed in
3980 REG_LIBCALL/REG_RETVAL notes with extra (use (memory (scratch)),
3981 or other LCT_ value for other types of library calls. */
3984 emit_library_call (rtx orgfun
, enum libcall_type fn_type
,
3985 enum machine_mode outmode
, int nargs
, ...)
3989 va_start (p
, nargs
);
3990 emit_library_call_value_1 (0, orgfun
, NULL_RTX
, fn_type
, outmode
, nargs
, p
);
3994 /* Like emit_library_call except that an extra argument, VALUE,
3995 comes second and says where to store the result.
3996 (If VALUE is zero, this function chooses a convenient way
3997 to return the value.
3999 This function returns an rtx for where the value is to be found.
4000 If VALUE is nonzero, VALUE is returned. */
4003 emit_library_call_value (rtx orgfun
, rtx value
,
4004 enum libcall_type fn_type
,
4005 enum machine_mode outmode
, int nargs
, ...)
4010 va_start (p
, nargs
);
4011 result
= emit_library_call_value_1 (1, orgfun
, value
, fn_type
, outmode
,
4018 /* Store a single argument for a function call
4019 into the register or memory area where it must be passed.
4020 *ARG describes the argument value and where to pass it.
4022 ARGBLOCK is the address of the stack-block for all the arguments,
4023 or 0 on a machine where arguments are pushed individually.
4025 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4026 so must be careful about how the stack is used.
4028 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4029 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4030 that we need not worry about saving and restoring the stack.
4032 FNDECL is the declaration of the function we are calling.
4034 Return nonzero if this arg should cause sibcall failure,
4038 store_one_arg (struct arg_data
*arg
, rtx argblock
, int flags
,
4039 int variable_size ATTRIBUTE_UNUSED
, int reg_parm_stack_space
)
4041 tree pval
= arg
->tree_value
;
4045 int i
, lower_bound
= 0, upper_bound
= 0;
4046 int sibcall_failure
= 0;
4048 if (TREE_CODE (pval
) == ERROR_MARK
)
4051 /* Push a new temporary level for any temporaries we make for
4055 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
))
4057 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4058 save any previous data at that location. */
4059 if (argblock
&& ! variable_size
&& arg
->stack
)
4061 #ifdef ARGS_GROW_DOWNWARD
4062 /* stack_slot is negative, but we want to index stack_usage_map
4063 with positive values. */
4064 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4065 upper_bound
= -INTVAL (XEXP (XEXP (arg
->stack_slot
, 0), 1)) + 1;
4069 lower_bound
= upper_bound
- arg
->locate
.size
.constant
;
4071 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4072 lower_bound
= INTVAL (XEXP (XEXP (arg
->stack_slot
, 0), 1));
4076 upper_bound
= lower_bound
+ arg
->locate
.size
.constant
;
4080 /* Don't worry about things in the fixed argument area;
4081 it has already been saved. */
4082 if (i
< reg_parm_stack_space
)
4083 i
= reg_parm_stack_space
;
4084 while (i
< upper_bound
&& stack_usage_map
[i
] == 0)
4087 if (i
< upper_bound
)
4089 /* We need to make a save area. */
4090 unsigned int size
= arg
->locate
.size
.constant
* BITS_PER_UNIT
;
4091 enum machine_mode save_mode
= mode_for_size (size
, MODE_INT
, 1);
4092 rtx adr
= memory_address (save_mode
, XEXP (arg
->stack_slot
, 0));
4093 rtx stack_area
= gen_rtx_MEM (save_mode
, adr
);
4095 if (save_mode
== BLKmode
)
4097 tree ot
= TREE_TYPE (arg
->tree_value
);
4098 tree nt
= build_qualified_type (ot
, (TYPE_QUALS (ot
)
4099 | TYPE_QUAL_CONST
));
4101 arg
->save_area
= assign_temp (nt
, 0, 1, 1);
4102 preserve_temp_slots (arg
->save_area
);
4103 emit_block_move (validize_mem (arg
->save_area
), stack_area
,
4104 GEN_INT (arg
->locate
.size
.constant
),
4105 BLOCK_OP_CALL_PARM
);
4109 arg
->save_area
= gen_reg_rtx (save_mode
);
4110 emit_move_insn (arg
->save_area
, stack_area
);
4116 /* If this isn't going to be placed on both the stack and in registers,
4117 set up the register and number of words. */
4118 if (! arg
->pass_on_stack
)
4120 if (flags
& ECF_SIBCALL
)
4121 reg
= arg
->tail_call_reg
;
4124 partial
= arg
->partial
;
4127 /* Being passed entirely in a register. We shouldn't be called in
4129 gcc_assert (reg
== 0 || partial
!= 0);
4131 /* If this arg needs special alignment, don't load the registers
4133 if (arg
->n_aligned_regs
!= 0)
4136 /* If this is being passed partially in a register, we can't evaluate
4137 it directly into its stack slot. Otherwise, we can. */
4138 if (arg
->value
== 0)
4140 /* stack_arg_under_construction is nonzero if a function argument is
4141 being evaluated directly into the outgoing argument list and
4142 expand_call must take special action to preserve the argument list
4143 if it is called recursively.
4145 For scalar function arguments stack_usage_map is sufficient to
4146 determine which stack slots must be saved and restored. Scalar
4147 arguments in general have pass_on_stack == 0.
4149 If this argument is initialized by a function which takes the
4150 address of the argument (a C++ constructor or a C function
4151 returning a BLKmode structure), then stack_usage_map is
4152 insufficient and expand_call must push the stack around the
4153 function call. Such arguments have pass_on_stack == 1.
4155 Note that it is always safe to set stack_arg_under_construction,
4156 but this generates suboptimal code if set when not needed. */
4158 if (arg
->pass_on_stack
)
4159 stack_arg_under_construction
++;
4161 arg
->value
= expand_expr (pval
,
4163 || TYPE_MODE (TREE_TYPE (pval
)) != arg
->mode
)
4164 ? NULL_RTX
: arg
->stack
,
4165 VOIDmode
, EXPAND_STACK_PARM
);
4167 /* If we are promoting object (or for any other reason) the mode
4168 doesn't agree, convert the mode. */
4170 if (arg
->mode
!= TYPE_MODE (TREE_TYPE (pval
)))
4171 arg
->value
= convert_modes (arg
->mode
, TYPE_MODE (TREE_TYPE (pval
)),
4172 arg
->value
, arg
->unsignedp
);
4174 if (arg
->pass_on_stack
)
4175 stack_arg_under_construction
--;
4178 /* Check for overlap with already clobbered argument area. */
4179 if ((flags
& ECF_SIBCALL
)
4180 && MEM_P (arg
->value
)
4181 && mem_overlaps_already_clobbered_arg_p (XEXP (arg
->value
, 0),
4182 arg
->locate
.size
.constant
))
4183 sibcall_failure
= 1;
4185 /* Don't allow anything left on stack from computation
4186 of argument to alloca. */
4187 if (flags
& ECF_MAY_BE_ALLOCA
)
4188 do_pending_stack_adjust ();
4190 if (arg
->value
== arg
->stack
)
4191 /* If the value is already in the stack slot, we are done. */
4193 else if (arg
->mode
!= BLKmode
)
4197 /* Argument is a scalar, not entirely passed in registers.
4198 (If part is passed in registers, arg->partial says how much
4199 and emit_push_insn will take care of putting it there.)
4201 Push it, and if its size is less than the
4202 amount of space allocated to it,
4203 also bump stack pointer by the additional space.
4204 Note that in C the default argument promotions
4205 will prevent such mismatches. */
4207 size
= GET_MODE_SIZE (arg
->mode
);
4208 /* Compute how much space the push instruction will push.
4209 On many machines, pushing a byte will advance the stack
4210 pointer by a halfword. */
4211 #ifdef PUSH_ROUNDING
4212 size
= PUSH_ROUNDING (size
);
4216 /* Compute how much space the argument should get:
4217 round up to a multiple of the alignment for arguments. */
4218 if (none
!= FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)))
4219 used
= (((size
+ PARM_BOUNDARY
/ BITS_PER_UNIT
- 1)
4220 / (PARM_BOUNDARY
/ BITS_PER_UNIT
))
4221 * (PARM_BOUNDARY
/ BITS_PER_UNIT
));
4223 /* This isn't already where we want it on the stack, so put it there.
4224 This can either be done with push or copy insns. */
4225 emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
), NULL_RTX
,
4226 PARM_BOUNDARY
, partial
, reg
, used
- size
, argblock
,
4227 ARGS_SIZE_RTX (arg
->locate
.offset
), reg_parm_stack_space
,
4228 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
));
4230 /* Unless this is a partially-in-register argument, the argument is now
4233 arg
->value
= arg
->stack
;
4237 /* BLKmode, at least partly to be pushed. */
4239 unsigned int parm_align
;
4243 /* Pushing a nonscalar.
4244 If part is passed in registers, PARTIAL says how much
4245 and emit_push_insn will take care of putting it there. */
4247 /* Round its size up to a multiple
4248 of the allocation unit for arguments. */
4250 if (arg
->locate
.size
.var
!= 0)
4253 size_rtx
= ARGS_SIZE_RTX (arg
->locate
.size
);
4257 /* PUSH_ROUNDING has no effect on us, because emit_push_insn
4258 for BLKmode is careful to avoid it. */
4259 excess
= (arg
->locate
.size
.constant
4260 - int_size_in_bytes (TREE_TYPE (pval
))
4262 size_rtx
= expand_expr (size_in_bytes (TREE_TYPE (pval
)),
4263 NULL_RTX
, TYPE_MODE (sizetype
), 0);
4266 parm_align
= arg
->locate
.boundary
;
4268 /* When an argument is padded down, the block is aligned to
4269 PARM_BOUNDARY, but the actual argument isn't. */
4270 if (FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)) == downward
)
4272 if (arg
->locate
.size
.var
)
4273 parm_align
= BITS_PER_UNIT
;
4276 unsigned int excess_align
= (excess
& -excess
) * BITS_PER_UNIT
;
4277 parm_align
= MIN (parm_align
, excess_align
);
4281 if ((flags
& ECF_SIBCALL
) && MEM_P (arg
->value
))
4283 /* emit_push_insn might not work properly if arg->value and
4284 argblock + arg->locate.offset areas overlap. */
4288 if (XEXP (x
, 0) == current_function_internal_arg_pointer
4289 || (GET_CODE (XEXP (x
, 0)) == PLUS
4290 && XEXP (XEXP (x
, 0), 0) ==
4291 current_function_internal_arg_pointer
4292 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
))
4294 if (XEXP (x
, 0) != current_function_internal_arg_pointer
)
4295 i
= INTVAL (XEXP (XEXP (x
, 0), 1));
4297 /* expand_call should ensure this. */
4298 gcc_assert (!arg
->locate
.offset
.var
4299 && GET_CODE (size_rtx
) == CONST_INT
);
4301 if (arg
->locate
.offset
.constant
> i
)
4303 if (arg
->locate
.offset
.constant
< i
+ INTVAL (size_rtx
))
4304 sibcall_failure
= 1;
4306 else if (arg
->locate
.offset
.constant
< i
)
4308 if (i
< arg
->locate
.offset
.constant
+ INTVAL (size_rtx
))
4309 sibcall_failure
= 1;
4314 emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
), size_rtx
,
4315 parm_align
, partial
, reg
, excess
, argblock
,
4316 ARGS_SIZE_RTX (arg
->locate
.offset
), reg_parm_stack_space
,
4317 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
));
4319 /* Unless this is a partially-in-register argument, the argument is now
4322 ??? Unlike the case above, in which we want the actual
4323 address of the data, so that we can load it directly into a
4324 register, here we want the address of the stack slot, so that
4325 it's properly aligned for word-by-word copying or something
4326 like that. It's not clear that this is always correct. */
4328 arg
->value
= arg
->stack_slot
;
4331 if (arg
->reg
&& GET_CODE (arg
->reg
) == PARALLEL
)
4333 tree type
= TREE_TYPE (arg
->tree_value
);
4335 = emit_group_load_into_temps (arg
->reg
, arg
->value
, type
,
4336 int_size_in_bytes (type
));
4339 /* Mark all slots this store used. */
4340 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
)
4341 && argblock
&& ! variable_size
&& arg
->stack
)
4342 for (i
= lower_bound
; i
< upper_bound
; i
++)
4343 stack_usage_map
[i
] = 1;
4345 /* Once we have pushed something, pops can't safely
4346 be deferred during the rest of the arguments. */
4349 /* Free any temporary slots made in processing this argument. Show
4350 that we might have taken the address of something and pushed that
4352 preserve_temp_slots (NULL_RTX
);
4356 return sibcall_failure
;
4359 /* Nonzero if we do not know how to pass TYPE solely in registers. */
4362 must_pass_in_stack_var_size (enum machine_mode mode ATTRIBUTE_UNUSED
,
4368 /* If the type has variable size... */
4369 if (TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
4372 /* If the type is marked as addressable (it is required
4373 to be constructed into the stack)... */
4374 if (TREE_ADDRESSABLE (type
))
4380 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
4381 takes trailing padding of a structure into account. */
4382 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
4385 must_pass_in_stack_var_size_or_pad (enum machine_mode mode
, tree type
)
4390 /* If the type has variable size... */
4391 if (TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
4394 /* If the type is marked as addressable (it is required
4395 to be constructed into the stack)... */
4396 if (TREE_ADDRESSABLE (type
))
4399 /* If the padding and mode of the type is such that a copy into
4400 a register would put it into the wrong part of the register. */
4402 && int_size_in_bytes (type
) % (PARM_BOUNDARY
/ BITS_PER_UNIT
)
4403 && (FUNCTION_ARG_PADDING (mode
, type
)
4404 == (BYTES_BIG_ENDIAN
? upward
: downward
)))