1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989-2023 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
31 #include "stringpool.h"
36 #include "diagnostic-core.h"
37 #include "fold-const.h"
38 #include "stor-layout.h"
40 #include "internal-fn.h"
46 #include "langhooks.h"
51 #include "tree-ssanames.h"
53 #include "stringpool.h"
55 #include "hash-traits.h"
58 #include "gimple-iterator.h"
59 #include "gimple-fold.h"
60 #include "attr-fnspec.h"
61 #include "value-query.h"
62 #include "tree-pretty-print.h"
65 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
66 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
68 /* Data structure and subroutines used within expand_call. */
72 /* Tree node for this argument. */
74 /* Mode for value; TYPE_MODE unless promoted. */
76 /* Current RTL value for argument, or 0 if it isn't precomputed. */
78 /* Initially-compute RTL value for argument; only for const functions. */
80 /* Register to pass this argument in, 0 if passed on stack, or an
81 PARALLEL if the arg is to be copied into multiple non-contiguous
84 /* Register to pass this argument in when generating tail call sequence.
85 This is not the same register as for normal calls on machines with
88 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
89 form for emit_group_move. */
91 /* If REG was promoted from the actual mode of the argument expression,
92 indicates whether the promotion is sign- or zero-extended. */
94 /* Number of bytes to put in registers. 0 means put the whole arg
95 in registers. Also 0 if not passed in registers. */
97 /* Nonzero if argument must be passed on stack.
98 Note that some arguments may be passed on the stack
99 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
100 pass_on_stack identifies arguments that *cannot* go in registers. */
102 /* Some fields packaged up for locate_and_pad_parm. */
103 struct locate_and_pad_arg_data locate
;
104 /* Location on the stack at which parameter should be stored. The store
105 has already been done if STACK == VALUE. */
107 /* Location on the stack of the start of this argument slot. This can
108 differ from STACK if this arg pads downward. This location is known
109 to be aligned to TARGET_FUNCTION_ARG_BOUNDARY. */
111 /* Place that this stack area has been saved, if needed. */
113 /* If an argument's alignment does not permit direct copying into registers,
114 copy in smaller-sized pieces into pseudos. These are stored in a
115 block pointed to by this field. The next field says how many
116 word-sized pseudos we made. */
121 /* A vector of one char per byte of stack space. A byte if nonzero if
122 the corresponding stack location has been used.
123 This vector is used to prevent a function call within an argument from
124 clobbering any stack already set up. */
125 static char *stack_usage_map
;
127 /* Size of STACK_USAGE_MAP. */
128 static unsigned int highest_outgoing_arg_in_use
;
130 /* Assume that any stack location at this byte index is used,
131 without checking the contents of stack_usage_map. */
132 static unsigned HOST_WIDE_INT stack_usage_watermark
= HOST_WIDE_INT_M1U
;
134 /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
135 stack location's tail call argument has been already stored into the stack.
136 This bitmap is used to prevent sibling call optimization if function tries
137 to use parent's incoming argument slots when they have been already
138 overwritten with tail call arguments. */
139 static sbitmap stored_args_map
;
141 /* Assume that any virtual-incoming location at this byte index has been
142 stored, without checking the contents of stored_args_map. */
143 static unsigned HOST_WIDE_INT stored_args_watermark
;
145 /* stack_arg_under_construction is nonzero when an argument may be
146 initialized with a constructor call (including a C function that
147 returns a BLKmode struct) and expand_call must take special action
148 to make sure the object being constructed does not overlap the
149 argument list for the constructor call. */
150 static int stack_arg_under_construction
;
152 static void precompute_register_parameters (int, struct arg_data
*, int *);
153 static int store_one_arg (struct arg_data
*, rtx
, int, int, int);
154 static void store_unaligned_arguments_into_pseudos (struct arg_data
*, int);
155 static int finalize_must_preallocate (int, int, struct arg_data
*,
157 static void precompute_arguments (int, struct arg_data
*);
158 static void compute_argument_addresses (struct arg_data
*, rtx
, int);
159 static rtx
rtx_for_function_call (tree
, tree
);
160 static void load_register_parameters (struct arg_data
*, int, rtx
*, int,
162 static int special_function_p (const_tree
, int);
163 static int check_sibcall_argument_overlap_1 (rtx
);
164 static int check_sibcall_argument_overlap (rtx_insn
*, struct arg_data
*, int);
166 static tree
split_complex_types (tree
);
168 #ifdef REG_PARM_STACK_SPACE
169 static rtx
save_fixed_argument_area (int, rtx
, int *, int *);
170 static void restore_fixed_argument_area (rtx
, rtx
, int, int);
173 /* Return true if bytes [LOWER_BOUND, UPPER_BOUND) of the outgoing
174 stack region might already be in use. */
177 stack_region_maybe_used_p (poly_uint64 lower_bound
, poly_uint64 upper_bound
,
178 unsigned int reg_parm_stack_space
)
180 unsigned HOST_WIDE_INT const_lower
, const_upper
;
181 const_lower
= constant_lower_bound (lower_bound
);
182 if (!upper_bound
.is_constant (&const_upper
))
183 const_upper
= HOST_WIDE_INT_M1U
;
185 if (const_upper
> stack_usage_watermark
)
188 /* Don't worry about things in the fixed argument area;
189 it has already been saved. */
190 const_lower
= MAX (const_lower
, reg_parm_stack_space
);
191 const_upper
= MIN (const_upper
, highest_outgoing_arg_in_use
);
192 for (unsigned HOST_WIDE_INT i
= const_lower
; i
< const_upper
; ++i
)
193 if (stack_usage_map
[i
])
198 /* Record that bytes [LOWER_BOUND, UPPER_BOUND) of the outgoing
199 stack region are now in use. */
202 mark_stack_region_used (poly_uint64 lower_bound
, poly_uint64 upper_bound
)
204 unsigned HOST_WIDE_INT const_lower
, const_upper
;
205 const_lower
= constant_lower_bound (lower_bound
);
206 if (upper_bound
.is_constant (&const_upper
)
207 && const_upper
<= highest_outgoing_arg_in_use
)
208 for (unsigned HOST_WIDE_INT i
= const_lower
; i
< const_upper
; ++i
)
209 stack_usage_map
[i
] = 1;
211 stack_usage_watermark
= MIN (stack_usage_watermark
, const_lower
);
214 /* Force FUNEXP into a form suitable for the address of a CALL,
215 and return that as an rtx. Also load the static chain register
216 if FNDECL is a nested function.
218 CALL_FUSAGE points to a variable holding the prospective
219 CALL_INSN_FUNCTION_USAGE information. */
222 prepare_call_address (tree fndecl_or_type
, rtx funexp
, rtx static_chain_value
,
223 rtx
*call_fusage
, int reg_parm_seen
, int flags
)
225 /* Make a valid memory address and copy constants through pseudo-regs,
226 but not for a constant address if -fno-function-cse. */
227 if (GET_CODE (funexp
) != SYMBOL_REF
)
229 /* If it's an indirect call by descriptor, generate code to perform
230 runtime identification of the pointer and load the descriptor. */
231 if ((flags
& ECF_BY_DESCRIPTOR
) && !flag_trampolines
)
233 const int bit_val
= targetm
.calls
.custom_function_descriptors
;
234 rtx call_lab
= gen_label_rtx ();
236 gcc_assert (fndecl_or_type
&& TYPE_P (fndecl_or_type
));
238 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
240 DECL_STATIC_CHAIN (fndecl_or_type
) = 1;
241 rtx chain
= targetm
.calls
.static_chain (fndecl_or_type
, false);
243 if (GET_MODE (funexp
) != Pmode
)
244 funexp
= convert_memory_address (Pmode
, funexp
);
246 /* Avoid long live ranges around function calls. */
247 funexp
= copy_to_mode_reg (Pmode
, funexp
);
250 emit_insn (gen_rtx_CLOBBER (VOIDmode
, chain
));
252 /* Emit the runtime identification pattern. */
253 rtx mask
= gen_rtx_AND (Pmode
, funexp
, GEN_INT (bit_val
));
254 emit_cmp_and_jump_insns (mask
, const0_rtx
, EQ
, NULL_RTX
, Pmode
, 1,
257 /* Statically predict the branch to very likely taken. */
258 rtx_insn
*insn
= get_last_insn ();
260 predict_insn_def (insn
, PRED_BUILTIN_EXPECT
, TAKEN
);
262 /* Load the descriptor. */
263 rtx mem
= gen_rtx_MEM (ptr_mode
,
264 plus_constant (Pmode
, funexp
, - bit_val
));
265 MEM_NOTRAP_P (mem
) = 1;
266 mem
= convert_memory_address (Pmode
, mem
);
267 emit_move_insn (chain
, mem
);
269 mem
= gen_rtx_MEM (ptr_mode
,
270 plus_constant (Pmode
, funexp
,
271 POINTER_SIZE
/ BITS_PER_UNIT
273 MEM_NOTRAP_P (mem
) = 1;
274 mem
= convert_memory_address (Pmode
, mem
);
275 emit_move_insn (funexp
, mem
);
277 emit_label (call_lab
);
281 use_reg (call_fusage
, chain
);
282 STATIC_CHAIN_REG_P (chain
) = 1;
285 /* Make sure we're not going to be overwritten below. */
286 gcc_assert (!static_chain_value
);
289 /* If we are using registers for parameters, force the
290 function address into a register now. */
291 funexp
= ((reg_parm_seen
292 && targetm
.small_register_classes_for_mode_p (FUNCTION_MODE
))
293 ? force_not_mem (memory_address (FUNCTION_MODE
, funexp
))
294 : memory_address (FUNCTION_MODE
, funexp
));
298 /* funexp could be a SYMBOL_REF represents a function pointer which is
299 of ptr_mode. In this case, it should be converted into address mode
300 to be a valid address for memory rtx pattern. See PR 64971. */
301 if (GET_MODE (funexp
) != Pmode
)
302 funexp
= convert_memory_address (Pmode
, funexp
);
304 if (!(flags
& ECF_SIBCALL
))
306 if (!NO_FUNCTION_CSE
&& optimize
&& ! flag_no_function_cse
)
307 funexp
= force_reg (Pmode
, funexp
);
311 if (static_chain_value
!= 0
312 && (TREE_CODE (fndecl_or_type
) != FUNCTION_DECL
313 || DECL_STATIC_CHAIN (fndecl_or_type
)))
317 chain
= targetm
.calls
.static_chain (fndecl_or_type
, false);
318 static_chain_value
= convert_memory_address (Pmode
, static_chain_value
);
320 emit_move_insn (chain
, static_chain_value
);
323 use_reg (call_fusage
, chain
);
324 STATIC_CHAIN_REG_P (chain
) = 1;
331 /* Generate instructions to call function FUNEXP,
332 and optionally pop the results.
333 The CALL_INSN is the first insn generated.
335 FNDECL is the declaration node of the function. This is given to the
336 hook TARGET_RETURN_POPS_ARGS to determine whether this function pops
339 FUNTYPE is the data type of the function. This is given to the hook
340 TARGET_RETURN_POPS_ARGS to determine whether this function pops its
341 own args. We used to allow an identifier for library functions, but
342 that doesn't work when the return type is an aggregate type and the
343 calling convention says that the pointer to this aggregate is to be
344 popped by the callee.
346 STACK_SIZE is the number of bytes of arguments on the stack,
347 ROUNDED_STACK_SIZE is that number rounded up to
348 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
349 both to put into the call insn and to generate explicit popping
352 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
353 It is zero if this call doesn't want a structure value.
355 NEXT_ARG_REG is the rtx that results from executing
356 targetm.calls.function_arg (&args_so_far,
357 function_arg_info::end_marker ());
358 just after all the args have had their registers assigned.
359 This could be whatever you like, but normally it is the first
360 arg-register beyond those used for args in this call,
361 or 0 if all the arg-registers are used in this call.
362 It is passed on to `gen_call' so you can put this info in the call insn.
364 VALREG is a hard register in which a value is returned,
365 or 0 if the call does not return a value.
367 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
368 the args to this call were processed.
369 We restore `inhibit_defer_pop' to that value.
371 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
372 denote registers used by the called function. */
375 emit_call_1 (rtx funexp
, tree fntree ATTRIBUTE_UNUSED
, tree fndecl ATTRIBUTE_UNUSED
,
376 tree funtype ATTRIBUTE_UNUSED
,
377 poly_int64 stack_size ATTRIBUTE_UNUSED
,
378 poly_int64 rounded_stack_size
,
379 poly_int64 struct_value_size ATTRIBUTE_UNUSED
,
380 rtx next_arg_reg ATTRIBUTE_UNUSED
, rtx valreg
,
381 int old_inhibit_defer_pop
, rtx call_fusage
, int ecf_flags
,
382 cumulative_args_t args_so_far ATTRIBUTE_UNUSED
)
384 rtx rounded_stack_size_rtx
= gen_int_mode (rounded_stack_size
, Pmode
);
385 rtx call
, funmem
, pat
;
386 int already_popped
= 0;
387 poly_int64 n_popped
= 0;
389 /* Sibling call patterns never pop arguments (no sibcall(_value)_pop
390 patterns exist). Any popping that the callee does on return will
391 be from our caller's frame rather than ours. */
392 if (!(ecf_flags
& ECF_SIBCALL
))
394 n_popped
+= targetm
.calls
.return_pops_args (fndecl
, funtype
, stack_size
);
396 #ifdef CALL_POPS_ARGS
397 n_popped
+= CALL_POPS_ARGS (*get_cumulative_args (args_so_far
));
401 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
402 and we don't want to load it into a register as an optimization,
403 because prepare_call_address already did it if it should be done. */
404 if (GET_CODE (funexp
) != SYMBOL_REF
)
405 funexp
= memory_address (FUNCTION_MODE
, funexp
);
407 funmem
= gen_rtx_MEM (FUNCTION_MODE
, funexp
);
408 if (fndecl
&& TREE_CODE (fndecl
) == FUNCTION_DECL
)
412 /* Although a built-in FUNCTION_DECL and its non-__builtin
413 counterpart compare equal and get a shared mem_attrs, they
414 produce different dump output in compare-debug compilations,
415 if an entry gets garbage collected in one compilation, then
416 adds a different (but equivalent) entry, while the other
417 doesn't run the garbage collector at the same spot and then
418 shares the mem_attr with the equivalent entry. */
419 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
)
421 tree t2
= builtin_decl_explicit (DECL_FUNCTION_CODE (t
));
426 set_mem_expr (funmem
, t
);
429 set_mem_expr (funmem
, build_simple_mem_ref (CALL_EXPR_FN (fntree
)));
431 if (ecf_flags
& ECF_SIBCALL
)
434 pat
= targetm
.gen_sibcall_value (valreg
, funmem
,
435 rounded_stack_size_rtx
,
436 next_arg_reg
, NULL_RTX
);
438 pat
= targetm
.gen_sibcall (funmem
, rounded_stack_size_rtx
,
440 gen_int_mode (struct_value_size
, Pmode
));
442 /* If the target has "call" or "call_value" insns, then prefer them
443 if no arguments are actually popped. If the target does not have
444 "call" or "call_value" insns, then we must use the popping versions
445 even if the call has no arguments to pop. */
446 else if (maybe_ne (n_popped
, 0)
448 ? targetm
.have_call_value ()
449 : targetm
.have_call ()))
451 rtx n_pop
= gen_int_mode (n_popped
, Pmode
);
453 /* If this subroutine pops its own args, record that in the call insn
454 if possible, for the sake of frame pointer elimination. */
457 pat
= targetm
.gen_call_value_pop (valreg
, funmem
,
458 rounded_stack_size_rtx
,
459 next_arg_reg
, n_pop
);
461 pat
= targetm
.gen_call_pop (funmem
, rounded_stack_size_rtx
,
462 next_arg_reg
, n_pop
);
469 pat
= targetm
.gen_call_value (valreg
, funmem
, rounded_stack_size_rtx
,
470 next_arg_reg
, NULL_RTX
);
472 pat
= targetm
.gen_call (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
473 gen_int_mode (struct_value_size
, Pmode
));
477 /* Find the call we just emitted. */
478 rtx_call_insn
*call_insn
= last_call_insn ();
480 /* Some target create a fresh MEM instead of reusing the one provided
481 above. Set its MEM_EXPR. */
482 call
= get_call_rtx_from (call_insn
);
484 && MEM_EXPR (XEXP (call
, 0)) == NULL_TREE
485 && MEM_EXPR (funmem
) != NULL_TREE
)
486 set_mem_expr (XEXP (call
, 0), MEM_EXPR (funmem
));
488 /* Put the register usage information there. */
489 add_function_usage_to (call_insn
, call_fusage
);
491 /* If this is a const call, then set the insn's unchanging bit. */
492 if (ecf_flags
& ECF_CONST
)
493 RTL_CONST_CALL_P (call_insn
) = 1;
495 /* If this is a pure call, then set the insn's unchanging bit. */
496 if (ecf_flags
& ECF_PURE
)
497 RTL_PURE_CALL_P (call_insn
) = 1;
499 /* If this is a const call, then set the insn's unchanging bit. */
500 if (ecf_flags
& ECF_LOOPING_CONST_OR_PURE
)
501 RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn
) = 1;
503 /* Create a nothrow REG_EH_REGION note, if needed. */
504 make_reg_eh_region_note (call_insn
, ecf_flags
, 0);
506 if (ecf_flags
& ECF_NORETURN
)
507 add_reg_note (call_insn
, REG_NORETURN
, const0_rtx
);
509 if (ecf_flags
& ECF_RETURNS_TWICE
)
511 add_reg_note (call_insn
, REG_SETJMP
, const0_rtx
);
512 cfun
->calls_setjmp
= 1;
515 SIBLING_CALL_P (call_insn
) = ((ecf_flags
& ECF_SIBCALL
) != 0);
517 /* Restore this now, so that we do defer pops for this call's args
518 if the context of the call as a whole permits. */
519 inhibit_defer_pop
= old_inhibit_defer_pop
;
521 if (maybe_ne (n_popped
, 0))
524 CALL_INSN_FUNCTION_USAGE (call_insn
)
525 = gen_rtx_EXPR_LIST (VOIDmode
,
526 gen_rtx_CLOBBER (VOIDmode
, stack_pointer_rtx
),
527 CALL_INSN_FUNCTION_USAGE (call_insn
));
528 rounded_stack_size
-= n_popped
;
529 rounded_stack_size_rtx
= gen_int_mode (rounded_stack_size
, Pmode
);
530 stack_pointer_delta
-= n_popped
;
532 add_args_size_note (call_insn
, stack_pointer_delta
);
534 /* If popup is needed, stack realign must use DRAP */
535 if (SUPPORTS_STACK_ALIGNMENT
)
536 crtl
->need_drap
= true;
538 /* For noreturn calls when not accumulating outgoing args force
539 REG_ARGS_SIZE note to prevent crossjumping of calls with different
541 else if (!ACCUMULATE_OUTGOING_ARGS
&& (ecf_flags
& ECF_NORETURN
) != 0)
542 add_args_size_note (call_insn
, stack_pointer_delta
);
544 if (!ACCUMULATE_OUTGOING_ARGS
)
546 /* If returning from the subroutine does not automatically pop the args,
547 we need an instruction to pop them sooner or later.
548 Perhaps do it now; perhaps just record how much space to pop later.
550 If returning from the subroutine does pop the args, indicate that the
551 stack pointer will be changed. */
553 if (maybe_ne (rounded_stack_size
, 0))
555 if (ecf_flags
& ECF_NORETURN
)
556 /* Just pretend we did the pop. */
557 stack_pointer_delta
-= rounded_stack_size
;
558 else if (flag_defer_pop
&& inhibit_defer_pop
== 0
559 && ! (ecf_flags
& (ECF_CONST
| ECF_PURE
)))
560 pending_stack_adjust
+= rounded_stack_size
;
562 adjust_stack (rounded_stack_size_rtx
);
565 /* When we accumulate outgoing args, we must avoid any stack manipulations.
566 Restore the stack pointer to its original value now. Usually
567 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
568 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
569 popping variants of functions exist as well.
571 ??? We may optimize similar to defer_pop above, but it is
572 probably not worthwhile.
574 ??? It will be worthwhile to enable combine_stack_adjustments even for
576 else if (maybe_ne (n_popped
, 0))
577 anti_adjust_stack (gen_int_mode (n_popped
, Pmode
));
580 /* Determine if the function identified by FNDECL is one with
581 special properties we wish to know about. Modify FLAGS accordingly.
583 For example, if the function might return more than one time (setjmp), then
584 set ECF_RETURNS_TWICE.
586 Set ECF_MAY_BE_ALLOCA for any memory allocation function that might allocate
587 space from the stack such as alloca. */
590 special_function_p (const_tree fndecl
, int flags
)
592 tree name_decl
= DECL_NAME (fndecl
);
594 if (maybe_special_function_p (fndecl
)
595 && IDENTIFIER_LENGTH (name_decl
) <= 11)
597 const char *name
= IDENTIFIER_POINTER (name_decl
);
598 const char *tname
= name
;
600 /* We assume that alloca will always be called by name. It
601 makes no sense to pass it as a pointer-to-function to
602 anything that does not understand its behavior. */
603 if (IDENTIFIER_LENGTH (name_decl
) == 6
605 && ! strcmp (name
, "alloca"))
606 flags
|= ECF_MAY_BE_ALLOCA
;
608 /* Disregard prefix _ or __. */
617 /* ECF_RETURNS_TWICE is safe even for -ffreestanding. */
618 if (! strcmp (tname
, "setjmp")
619 || ! strcmp (tname
, "sigsetjmp")
620 || ! strcmp (name
, "savectx")
621 || ! strcmp (name
, "vfork")
622 || ! strcmp (name
, "getcontext"))
623 flags
|= ECF_RETURNS_TWICE
;
626 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
627 && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (fndecl
)))
628 flags
|= ECF_MAY_BE_ALLOCA
;
633 /* Return fnspec for DECL. */
636 decl_fnspec (tree fndecl
)
639 tree type
= TREE_TYPE (fndecl
);
642 attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
645 return TREE_VALUE (TREE_VALUE (attr
));
648 if (fndecl_built_in_p (fndecl
, BUILT_IN_NORMAL
))
649 return builtin_fnspec (fndecl
);
653 /* Similar to special_function_p; return a set of ERF_ flags for the
656 decl_return_flags (tree fndecl
)
658 attr_fnspec fnspec
= decl_fnspec (fndecl
);
661 if (fnspec
.returns_arg (&arg
))
662 return ERF_RETURNS_ARG
| arg
;
664 if (fnspec
.returns_noalias_p ())
669 /* Return nonzero when FNDECL represents a call to setjmp. */
672 setjmp_call_p (const_tree fndecl
)
674 if (DECL_IS_RETURNS_TWICE (fndecl
))
675 return ECF_RETURNS_TWICE
;
676 return special_function_p (fndecl
, 0) & ECF_RETURNS_TWICE
;
680 /* Return true if STMT may be an alloca call. */
683 gimple_maybe_alloca_call_p (const gimple
*stmt
)
687 if (!is_gimple_call (stmt
))
690 fndecl
= gimple_call_fndecl (stmt
);
691 if (fndecl
&& (special_function_p (fndecl
, 0) & ECF_MAY_BE_ALLOCA
))
697 /* Return true if STMT is a builtin alloca call. */
700 gimple_alloca_call_p (const gimple
*stmt
)
704 if (!is_gimple_call (stmt
))
707 fndecl
= gimple_call_fndecl (stmt
);
708 if (fndecl
&& fndecl_built_in_p (fndecl
, BUILT_IN_NORMAL
))
709 switch (DECL_FUNCTION_CODE (fndecl
))
711 CASE_BUILT_IN_ALLOCA
:
712 return gimple_call_num_args (stmt
) > 0;
720 /* Return true when exp contains a builtin alloca call. */
723 alloca_call_p (const_tree exp
)
726 if (TREE_CODE (exp
) == CALL_EXPR
727 && (fndecl
= get_callee_fndecl (exp
))
728 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
)
729 switch (DECL_FUNCTION_CODE (fndecl
))
731 CASE_BUILT_IN_ALLOCA
:
740 /* Return TRUE if FNDECL is either a TM builtin or a TM cloned
741 function. Return FALSE otherwise. */
744 is_tm_builtin (const_tree fndecl
)
749 if (decl_is_tm_clone (fndecl
))
752 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
)
754 switch (DECL_FUNCTION_CODE (fndecl
))
756 case BUILT_IN_TM_COMMIT
:
757 case BUILT_IN_TM_COMMIT_EH
:
758 case BUILT_IN_TM_ABORT
:
759 case BUILT_IN_TM_IRREVOCABLE
:
760 case BUILT_IN_TM_GETTMCLONE_IRR
:
761 case BUILT_IN_TM_MEMCPY
:
762 case BUILT_IN_TM_MEMMOVE
:
763 case BUILT_IN_TM_MEMSET
:
764 CASE_BUILT_IN_TM_STORE (1):
765 CASE_BUILT_IN_TM_STORE (2):
766 CASE_BUILT_IN_TM_STORE (4):
767 CASE_BUILT_IN_TM_STORE (8):
768 CASE_BUILT_IN_TM_STORE (FLOAT
):
769 CASE_BUILT_IN_TM_STORE (DOUBLE
):
770 CASE_BUILT_IN_TM_STORE (LDOUBLE
):
771 CASE_BUILT_IN_TM_STORE (M64
):
772 CASE_BUILT_IN_TM_STORE (M128
):
773 CASE_BUILT_IN_TM_STORE (M256
):
774 CASE_BUILT_IN_TM_LOAD (1):
775 CASE_BUILT_IN_TM_LOAD (2):
776 CASE_BUILT_IN_TM_LOAD (4):
777 CASE_BUILT_IN_TM_LOAD (8):
778 CASE_BUILT_IN_TM_LOAD (FLOAT
):
779 CASE_BUILT_IN_TM_LOAD (DOUBLE
):
780 CASE_BUILT_IN_TM_LOAD (LDOUBLE
):
781 CASE_BUILT_IN_TM_LOAD (M64
):
782 CASE_BUILT_IN_TM_LOAD (M128
):
783 CASE_BUILT_IN_TM_LOAD (M256
):
784 case BUILT_IN_TM_LOG
:
785 case BUILT_IN_TM_LOG_1
:
786 case BUILT_IN_TM_LOG_2
:
787 case BUILT_IN_TM_LOG_4
:
788 case BUILT_IN_TM_LOG_8
:
789 case BUILT_IN_TM_LOG_FLOAT
:
790 case BUILT_IN_TM_LOG_DOUBLE
:
791 case BUILT_IN_TM_LOG_LDOUBLE
:
792 case BUILT_IN_TM_LOG_M64
:
793 case BUILT_IN_TM_LOG_M128
:
794 case BUILT_IN_TM_LOG_M256
:
803 /* Detect flags (function attributes) from the function decl or type node. */
806 flags_from_decl_or_type (const_tree exp
)
812 /* The function exp may have the `malloc' attribute. */
813 if (DECL_IS_MALLOC (exp
))
816 /* The function exp may have the `returns_twice' attribute. */
817 if (DECL_IS_RETURNS_TWICE (exp
))
818 flags
|= ECF_RETURNS_TWICE
;
820 /* Process the pure and const attributes. */
821 if (TREE_READONLY (exp
))
823 if (DECL_PURE_P (exp
))
825 if (DECL_LOOPING_CONST_OR_PURE_P (exp
))
826 flags
|= ECF_LOOPING_CONST_OR_PURE
;
828 if (DECL_IS_NOVOPS (exp
))
830 if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp
)))
832 if (lookup_attribute ("cold", DECL_ATTRIBUTES (exp
)))
835 if (TREE_NOTHROW (exp
))
836 flags
|= ECF_NOTHROW
;
840 if (is_tm_builtin (exp
))
841 flags
|= ECF_TM_BUILTIN
;
842 else if ((flags
& (ECF_CONST
|ECF_NOVOPS
)) != 0
843 || lookup_attribute ("transaction_pure",
844 TYPE_ATTRIBUTES (TREE_TYPE (exp
))))
845 flags
|= ECF_TM_PURE
;
848 flags
= special_function_p (exp
, flags
);
850 else if (TYPE_P (exp
))
852 if (TYPE_READONLY (exp
))
856 && ((flags
& ECF_CONST
) != 0
857 || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp
))))
858 flags
|= ECF_TM_PURE
;
863 if (TREE_THIS_VOLATILE (exp
))
865 flags
|= ECF_NORETURN
;
866 if (flags
& (ECF_CONST
|ECF_PURE
))
867 flags
|= ECF_LOOPING_CONST_OR_PURE
;
873 /* Detect flags from a CALL_EXPR. */
876 call_expr_flags (const_tree t
)
879 tree decl
= get_callee_fndecl (t
);
882 flags
= flags_from_decl_or_type (decl
);
883 else if (CALL_EXPR_FN (t
) == NULL_TREE
)
884 flags
= internal_fn_flags (CALL_EXPR_IFN (t
));
887 tree type
= TREE_TYPE (CALL_EXPR_FN (t
));
888 if (type
&& TREE_CODE (type
) == POINTER_TYPE
)
889 flags
= flags_from_decl_or_type (TREE_TYPE (type
));
892 if (CALL_EXPR_BY_DESCRIPTOR (t
))
893 flags
|= ECF_BY_DESCRIPTOR
;
899 /* Return true if ARG should be passed by invisible reference. */
902 pass_by_reference (CUMULATIVE_ARGS
*ca
, function_arg_info arg
)
904 if (tree type
= arg
.type
)
906 /* If this type contains non-trivial constructors, then it is
907 forbidden for the middle-end to create any new copies. */
908 if (TREE_ADDRESSABLE (type
))
911 /* GCC post 3.4 passes *all* variable sized types by reference. */
912 if (!TYPE_SIZE (type
) || !poly_int_tree_p (TYPE_SIZE (type
)))
915 /* If a record type should be passed the same as its first (and only)
916 member, use the type and mode of that member. */
917 if (TREE_CODE (type
) == RECORD_TYPE
&& TYPE_TRANSPARENT_AGGR (type
))
919 arg
.type
= TREE_TYPE (first_field (type
));
920 arg
.mode
= TYPE_MODE (arg
.type
);
924 return targetm
.calls
.pass_by_reference (pack_cumulative_args (ca
), arg
);
927 /* Return true if TYPE should be passed by reference when passed to
928 the "..." arguments of a function. */
931 pass_va_arg_by_reference (tree type
)
933 return pass_by_reference (NULL
, function_arg_info (type
, /*named=*/false));
936 /* Decide whether ARG, which occurs in the state described by CA,
937 should be passed by reference. Return true if so and update
941 apply_pass_by_reference_rules (CUMULATIVE_ARGS
*ca
, function_arg_info
&arg
)
943 if (pass_by_reference (ca
, arg
))
945 arg
.type
= build_pointer_type (arg
.type
);
946 arg
.mode
= TYPE_MODE (arg
.type
);
947 arg
.pass_by_reference
= true;
953 /* Return true if ARG, which is passed by reference, should be callee
954 copied instead of caller copied. */
957 reference_callee_copied (CUMULATIVE_ARGS
*ca
, const function_arg_info
&arg
)
959 if (arg
.type
&& TREE_ADDRESSABLE (arg
.type
))
961 return targetm
.calls
.callee_copies (pack_cumulative_args (ca
), arg
);
965 /* Precompute all register parameters as described by ARGS, storing values
966 into fields within the ARGS array.
968 NUM_ACTUALS indicates the total number elements in the ARGS array.
970 Set REG_PARM_SEEN if we encounter a register parameter. */
973 precompute_register_parameters (int num_actuals
, struct arg_data
*args
,
980 for (i
= 0; i
< num_actuals
; i
++)
981 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
)
985 if (args
[i
].value
== 0)
988 args
[i
].value
= expand_normal (args
[i
].tree_value
);
989 preserve_temp_slots (args
[i
].value
);
993 /* If we are to promote the function arg to a wider mode,
996 machine_mode old_mode
= TYPE_MODE (TREE_TYPE (args
[i
].tree_value
));
998 /* Some ABIs require scalar floating point modes to be returned
999 in a wider scalar integer mode. We need to explicitly
1000 reinterpret to an integer mode of the correct precision
1001 before extending to the desired result. */
1002 if (SCALAR_INT_MODE_P (args
[i
].mode
)
1003 && SCALAR_FLOAT_MODE_P (old_mode
)
1004 && known_gt (GET_MODE_SIZE (args
[i
].mode
),
1005 GET_MODE_SIZE (old_mode
)))
1006 args
[i
].value
= convert_float_to_wider_int (args
[i
].mode
, old_mode
,
1008 else if (args
[i
].mode
!= old_mode
)
1009 args
[i
].value
= convert_modes (args
[i
].mode
, old_mode
,
1010 args
[i
].value
, args
[i
].unsignedp
);
1012 /* If the value is a non-legitimate constant, force it into a
1013 pseudo now. TLS symbols sometimes need a call to resolve. */
1014 if (CONSTANT_P (args
[i
].value
)
1015 && (!targetm
.legitimate_constant_p (args
[i
].mode
, args
[i
].value
)
1016 || targetm
.precompute_tls_p (args
[i
].mode
, args
[i
].value
)))
1017 args
[i
].value
= force_reg (args
[i
].mode
, args
[i
].value
);
1019 /* If we're going to have to load the value by parts, pull the
1020 parts into pseudos. The part extraction process can involve
1021 non-trivial computation. */
1022 if (GET_CODE (args
[i
].reg
) == PARALLEL
)
1024 tree type
= TREE_TYPE (args
[i
].tree_value
);
1025 args
[i
].parallel_value
1026 = emit_group_load_into_temps (args
[i
].reg
, args
[i
].value
,
1027 type
, int_size_in_bytes (type
));
1030 /* If the value is expensive, and we are inside an appropriately
1031 short loop, put the value into a pseudo and then put the pseudo
1034 For small register classes, also do this if this call uses
1035 register parameters. This is to avoid reload conflicts while
1036 loading the parameters registers. */
1038 else if ((! (REG_P (args
[i
].value
)
1039 || (GET_CODE (args
[i
].value
) == SUBREG
1040 && REG_P (SUBREG_REG (args
[i
].value
)))))
1041 && args
[i
].mode
!= BLKmode
1042 && (set_src_cost (args
[i
].value
, args
[i
].mode
,
1043 optimize_insn_for_speed_p ())
1044 > COSTS_N_INSNS (1))
1046 && targetm
.small_register_classes_for_mode_p (args
[i
].mode
))
1048 args
[i
].value
= copy_to_mode_reg (args
[i
].mode
, args
[i
].value
);
1052 #ifdef REG_PARM_STACK_SPACE
1054 /* The argument list is the property of the called routine and it
1055 may clobber it. If the fixed area has been used for previous
1056 parameters, we must save and restore it. */
1059 save_fixed_argument_area (int reg_parm_stack_space
, rtx argblock
, int *low_to_save
, int *high_to_save
)
1064 /* Compute the boundary of the area that needs to be saved, if any. */
1065 high
= reg_parm_stack_space
;
1066 if (ARGS_GROW_DOWNWARD
)
1069 if (high
> highest_outgoing_arg_in_use
)
1070 high
= highest_outgoing_arg_in_use
;
1072 for (low
= 0; low
< high
; low
++)
1073 if (stack_usage_map
[low
] != 0 || low
>= stack_usage_watermark
)
1076 machine_mode save_mode
;
1082 while (stack_usage_map
[--high
] == 0)
1086 *high_to_save
= high
;
1088 num_to_save
= high
- low
+ 1;
1090 /* If we don't have the required alignment, must do this
1092 scalar_int_mode imode
;
1093 if (int_mode_for_size (num_to_save
* BITS_PER_UNIT
, 1).exists (&imode
)
1094 && (low
& (MIN (GET_MODE_SIZE (imode
),
1095 BIGGEST_ALIGNMENT
/ UNITS_PER_WORD
) - 1)) == 0)
1098 save_mode
= BLKmode
;
1100 if (ARGS_GROW_DOWNWARD
)
1105 addr
= plus_constant (Pmode
, argblock
, delta
);
1106 stack_area
= gen_rtx_MEM (save_mode
, memory_address (save_mode
, addr
));
1108 set_mem_align (stack_area
, PARM_BOUNDARY
);
1109 if (save_mode
== BLKmode
)
1111 save_area
= assign_stack_temp (BLKmode
, num_to_save
);
1112 emit_block_move (validize_mem (save_area
), stack_area
,
1113 GEN_INT (num_to_save
), BLOCK_OP_CALL_PARM
);
1117 save_area
= gen_reg_rtx (save_mode
);
1118 emit_move_insn (save_area
, stack_area
);
1128 restore_fixed_argument_area (rtx save_area
, rtx argblock
, int high_to_save
, int low_to_save
)
1130 machine_mode save_mode
= GET_MODE (save_area
);
1132 rtx addr
, stack_area
;
1134 if (ARGS_GROW_DOWNWARD
)
1135 delta
= -high_to_save
;
1137 delta
= low_to_save
;
1139 addr
= plus_constant (Pmode
, argblock
, delta
);
1140 stack_area
= gen_rtx_MEM (save_mode
, memory_address (save_mode
, addr
));
1141 set_mem_align (stack_area
, PARM_BOUNDARY
);
1143 if (save_mode
!= BLKmode
)
1144 emit_move_insn (stack_area
, save_area
);
1146 emit_block_move (stack_area
, validize_mem (save_area
),
1147 GEN_INT (high_to_save
- low_to_save
+ 1),
1148 BLOCK_OP_CALL_PARM
);
1150 #endif /* REG_PARM_STACK_SPACE */
1152 /* If any elements in ARGS refer to parameters that are to be passed in
1153 registers, but not in memory, and whose alignment does not permit a
1154 direct copy into registers. Copy the values into a group of pseudos
1155 which we will later copy into the appropriate hard registers.
1157 Pseudos for each unaligned argument will be stored into the array
1158 args[argnum].aligned_regs. The caller is responsible for deallocating
1159 the aligned_regs array if it is nonzero. */
1162 store_unaligned_arguments_into_pseudos (struct arg_data
*args
, int num_actuals
)
1166 for (i
= 0; i
< num_actuals
; i
++)
1167 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
1168 && GET_CODE (args
[i
].reg
) != PARALLEL
1169 && args
[i
].mode
== BLKmode
1170 && MEM_P (args
[i
].value
)
1171 && (MEM_ALIGN (args
[i
].value
)
1172 < (unsigned int) MIN (BIGGEST_ALIGNMENT
, BITS_PER_WORD
)))
1174 int bytes
= int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1175 int endian_correction
= 0;
1177 if (args
[i
].partial
)
1179 gcc_assert (args
[i
].partial
% UNITS_PER_WORD
== 0);
1180 args
[i
].n_aligned_regs
= args
[i
].partial
/ UNITS_PER_WORD
;
1184 args
[i
].n_aligned_regs
1185 = (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
1188 args
[i
].aligned_regs
= XNEWVEC (rtx
, args
[i
].n_aligned_regs
);
1190 /* Structures smaller than a word are normally aligned to the
1191 least significant byte. On a BYTES_BIG_ENDIAN machine,
1192 this means we must skip the empty high order bytes when
1193 calculating the bit offset. */
1194 if (bytes
< UNITS_PER_WORD
1195 #ifdef BLOCK_REG_PADDING
1196 && (BLOCK_REG_PADDING (args
[i
].mode
,
1197 TREE_TYPE (args
[i
].tree_value
), 1)
1203 endian_correction
= BITS_PER_WORD
- bytes
* BITS_PER_UNIT
;
1205 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
1207 rtx reg
= gen_reg_rtx (word_mode
);
1208 rtx word
= operand_subword_force (args
[i
].value
, j
, BLKmode
);
1209 int bitsize
= MIN (bytes
* BITS_PER_UNIT
, BITS_PER_WORD
);
1211 args
[i
].aligned_regs
[j
] = reg
;
1212 word
= extract_bit_field (word
, bitsize
, 0, 1, NULL_RTX
,
1213 word_mode
, word_mode
, false, NULL
);
1215 /* There is no need to restrict this code to loading items
1216 in TYPE_ALIGN sized hunks. The bitfield instructions can
1217 load up entire word sized registers efficiently.
1219 ??? This may not be needed anymore.
1220 We use to emit a clobber here but that doesn't let later
1221 passes optimize the instructions we emit. By storing 0 into
1222 the register later passes know the first AND to zero out the
1223 bitfield being set in the register is unnecessary. The store
1224 of 0 will be deleted as will at least the first AND. */
1226 emit_move_insn (reg
, const0_rtx
);
1228 bytes
-= bitsize
/ BITS_PER_UNIT
;
1229 store_bit_field (reg
, bitsize
, endian_correction
, 0, 0,
1230 word_mode
, word
, false, false);
1235 /* Issue an error if CALL_EXPR was flagged as requiring
1236 tall-call optimization. */
1239 maybe_complain_about_tail_call (tree call_expr
, const char *reason
)
1241 gcc_assert (TREE_CODE (call_expr
) == CALL_EXPR
);
1242 if (!CALL_EXPR_MUST_TAIL_CALL (call_expr
))
1245 error_at (EXPR_LOCATION (call_expr
), "cannot tail-call: %s", reason
);
1248 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
1251 NUM_ACTUALS is the total number of parameters.
1253 N_NAMED_ARGS is the total number of named arguments.
1255 STRUCT_VALUE_ADDR_VALUE is the implicit argument for a struct return
1258 FNDECL is the tree code for the target of this call (if known)
1260 ARGS_SO_FAR holds state needed by the target to know where to place
1263 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
1264 for arguments which are passed in registers.
1266 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
1267 and may be modified by this routine.
1269 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
1270 flags which may be modified by this routine.
1272 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
1273 that requires allocation of stack space.
1275 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
1276 the thunked-to function. */
1279 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED
,
1280 struct arg_data
*args
,
1281 struct args_size
*args_size
,
1282 int n_named_args ATTRIBUTE_UNUSED
,
1283 tree exp
, tree struct_value_addr_value
,
1284 tree fndecl
, tree fntype
,
1285 cumulative_args_t args_so_far
,
1286 int reg_parm_stack_space
,
1287 rtx
*old_stack_level
,
1288 poly_int64_pod
*old_pending_adj
,
1289 int *must_preallocate
, int *ecf_flags
,
1290 bool *may_tailcall
, bool call_from_thunk_p
)
1292 CUMULATIVE_ARGS
*args_so_far_pnt
= get_cumulative_args (args_so_far
);
1293 location_t loc
= EXPR_LOCATION (exp
);
1295 /* Count arg position in order args appear. */
1300 args_size
->constant
= 0;
1303 /* In this loop, we consider args in the order they are written.
1304 We fill up ARGS from the back. */
1306 i
= num_actuals
- 1;
1309 call_expr_arg_iterator iter
;
1312 if (struct_value_addr_value
)
1314 args
[j
].tree_value
= struct_value_addr_value
;
1318 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
1320 tree argtype
= TREE_TYPE (arg
);
1322 if (targetm
.calls
.split_complex_arg
1324 && TREE_CODE (argtype
) == COMPLEX_TYPE
1325 && targetm
.calls
.split_complex_arg (argtype
))
1327 tree subtype
= TREE_TYPE (argtype
);
1328 args
[j
].tree_value
= build1 (REALPART_EXPR
, subtype
, arg
);
1330 args
[j
].tree_value
= build1 (IMAGPART_EXPR
, subtype
, arg
);
1333 args
[j
].tree_value
= arg
;
1339 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1340 for (argpos
= 0; argpos
< num_actuals
; i
--, argpos
++)
1342 tree type
= TREE_TYPE (args
[i
].tree_value
);
1345 /* Replace erroneous argument with constant zero. */
1346 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
1347 args
[i
].tree_value
= integer_zero_node
, type
= integer_type_node
;
1349 /* If TYPE is a transparent union or record, pass things the way
1350 we would pass the first field of the union or record. We have
1351 already verified that the modes are the same. */
1352 if (RECORD_OR_UNION_TYPE_P (type
) && TYPE_TRANSPARENT_AGGR (type
))
1353 type
= TREE_TYPE (first_field (type
));
1355 /* Decide where to pass this arg.
1357 args[i].reg is nonzero if all or part is passed in registers.
1359 args[i].partial is nonzero if part but not all is passed in registers,
1360 and the exact value says how many bytes are passed in registers.
1362 args[i].pass_on_stack is nonzero if the argument must at least be
1363 computed on the stack. It may then be loaded back into registers
1364 if args[i].reg is nonzero.
1366 These decisions are driven by the FUNCTION_... macros and must agree
1367 with those made by function.cc. */
1369 /* See if this argument should be passed by invisible reference. */
1370 function_arg_info
arg (type
, argpos
< n_named_args
);
1371 if (pass_by_reference (args_so_far_pnt
, arg
))
1373 const bool callee_copies
1374 = reference_callee_copied (args_so_far_pnt
, arg
);
1377 /* If we're compiling a thunk, pass directly the address of an object
1378 already in memory, instead of making a copy. Likewise if we want
1379 to make the copy in the callee instead of the caller. */
1380 if ((call_from_thunk_p
|| callee_copies
)
1381 && TREE_CODE (args
[i
].tree_value
) != WITH_SIZE_EXPR
1382 && ((base
= get_base_address (args
[i
].tree_value
)), true)
1383 && TREE_CODE (base
) != SSA_NAME
1384 && (!DECL_P (base
) || MEM_P (DECL_RTL (base
))))
1386 /* We may have turned the parameter value into an SSA name.
1387 Go back to the original parameter so we can take the
1389 if (TREE_CODE (args
[i
].tree_value
) == SSA_NAME
)
1391 gcc_assert (SSA_NAME_IS_DEFAULT_DEF (args
[i
].tree_value
));
1392 args
[i
].tree_value
= SSA_NAME_VAR (args
[i
].tree_value
);
1393 gcc_assert (TREE_CODE (args
[i
].tree_value
) == PARM_DECL
);
1395 /* Argument setup code may have copied the value to register. We
1396 revert that optimization now because the tail call code must
1397 use the original location. */
1398 if (TREE_CODE (args
[i
].tree_value
) == PARM_DECL
1399 && !MEM_P (DECL_RTL (args
[i
].tree_value
))
1400 && DECL_INCOMING_RTL (args
[i
].tree_value
)
1401 && MEM_P (DECL_INCOMING_RTL (args
[i
].tree_value
)))
1402 set_decl_rtl (args
[i
].tree_value
,
1403 DECL_INCOMING_RTL (args
[i
].tree_value
));
1405 mark_addressable (args
[i
].tree_value
);
1407 /* We can't use sibcalls if a callee-copied argument is
1408 stored in the current function's frame. */
1409 if (!call_from_thunk_p
&& DECL_P (base
) && !TREE_STATIC (base
))
1411 *may_tailcall
= false;
1412 maybe_complain_about_tail_call (exp
,
1413 "a callee-copied argument is"
1414 " stored in the current"
1415 " function's frame");
1418 args
[i
].tree_value
= build_fold_addr_expr_loc (loc
,
1419 args
[i
].tree_value
);
1420 type
= TREE_TYPE (args
[i
].tree_value
);
1422 if (*ecf_flags
& ECF_CONST
)
1423 *ecf_flags
&= ~(ECF_CONST
| ECF_LOOPING_CONST_OR_PURE
);
1427 /* We make a copy of the object and pass the address to the
1428 function being called. */
1431 if (!COMPLETE_TYPE_P (type
)
1432 || TREE_CODE (TYPE_SIZE_UNIT (type
)) != INTEGER_CST
1433 || (flag_stack_check
== GENERIC_STACK_CHECK
1434 && compare_tree_int (TYPE_SIZE_UNIT (type
),
1435 STACK_CHECK_MAX_VAR_SIZE
) > 0))
1437 /* This is a variable-sized object. Make space on the stack
1439 rtx size_rtx
= expr_size (args
[i
].tree_value
);
1441 if (*old_stack_level
== 0)
1443 emit_stack_save (SAVE_BLOCK
, old_stack_level
);
1444 *old_pending_adj
= pending_stack_adjust
;
1445 pending_stack_adjust
= 0;
1448 /* We can pass TRUE as the 4th argument because we just
1449 saved the stack pointer and will restore it right after
1451 copy
= allocate_dynamic_stack_space (size_rtx
,
1454 max_int_size_in_bytes
1457 copy
= gen_rtx_MEM (BLKmode
, copy
);
1458 set_mem_attributes (copy
, type
, 1);
1461 copy
= assign_temp (type
, 1, 0);
1463 store_expr (args
[i
].tree_value
, copy
, 0, false, false);
1465 /* Just change the const function to pure and then let
1466 the next test clear the pure based on
1468 if (*ecf_flags
& ECF_CONST
)
1470 *ecf_flags
&= ~ECF_CONST
;
1471 *ecf_flags
|= ECF_PURE
;
1474 if (!callee_copies
&& *ecf_flags
& ECF_PURE
)
1475 *ecf_flags
&= ~(ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
1478 = build_fold_addr_expr_loc (loc
, make_tree (type
, copy
));
1479 type
= TREE_TYPE (args
[i
].tree_value
);
1480 *may_tailcall
= false;
1481 maybe_complain_about_tail_call (exp
,
1482 "argument must be passed"
1485 arg
.pass_by_reference
= true;
1488 unsignedp
= TYPE_UNSIGNED (type
);
1491 = promote_function_mode (type
, TYPE_MODE (type
), &unsignedp
,
1492 fndecl
? TREE_TYPE (fndecl
) : fntype
, 0);
1494 args
[i
].unsignedp
= unsignedp
;
1495 args
[i
].mode
= arg
.mode
;
1497 targetm
.calls
.warn_parameter_passing_abi (args_so_far
, type
);
1499 args
[i
].reg
= targetm
.calls
.function_arg (args_so_far
, arg
);
1501 /* If this is a sibling call and the machine has register windows, the
1502 register window has to be unwinded before calling the routine, so
1503 arguments have to go into the incoming registers. */
1504 if (targetm
.calls
.function_incoming_arg
!= targetm
.calls
.function_arg
)
1505 args
[i
].tail_call_reg
1506 = targetm
.calls
.function_incoming_arg (args_so_far
, arg
);
1508 args
[i
].tail_call_reg
= args
[i
].reg
;
1511 args
[i
].partial
= targetm
.calls
.arg_partial_bytes (args_so_far
, arg
);
1513 args
[i
].pass_on_stack
= targetm
.calls
.must_pass_in_stack (arg
);
1515 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1516 it means that we are to pass this arg in the register(s) designated
1517 by the PARALLEL, but also to pass it in the stack. */
1518 if (args
[i
].reg
&& GET_CODE (args
[i
].reg
) == PARALLEL
1519 && XEXP (XVECEXP (args
[i
].reg
, 0, 0), 0) == 0)
1520 args
[i
].pass_on_stack
= 1;
1522 /* If this is an addressable type, we must preallocate the stack
1523 since we must evaluate the object into its final location.
1525 If this is to be passed in both registers and the stack, it is simpler
1527 if (TREE_ADDRESSABLE (type
)
1528 || (args
[i
].pass_on_stack
&& args
[i
].reg
!= 0))
1529 *must_preallocate
= 1;
1531 /* Compute the stack-size of this argument. */
1532 if (args
[i
].reg
== 0 || args
[i
].partial
!= 0
1533 || reg_parm_stack_space
> 0
1534 || args
[i
].pass_on_stack
)
1535 locate_and_pad_parm (arg
.mode
, type
,
1536 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1541 reg_parm_stack_space
,
1542 args
[i
].pass_on_stack
? 0 : args
[i
].partial
,
1543 fndecl
, args_size
, &args
[i
].locate
);
1544 #ifdef BLOCK_REG_PADDING
1546 /* The argument is passed entirely in registers. See at which
1547 end it should be padded. */
1548 args
[i
].locate
.where_pad
=
1549 BLOCK_REG_PADDING (arg
.mode
, type
,
1550 int_size_in_bytes (type
) <= UNITS_PER_WORD
);
1553 /* Update ARGS_SIZE, the total stack space for args so far. */
1555 args_size
->constant
+= args
[i
].locate
.size
.constant
;
1556 if (args
[i
].locate
.size
.var
)
1557 ADD_PARM_SIZE (*args_size
, args
[i
].locate
.size
.var
);
1559 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1560 have been used, etc. */
1562 /* ??? Traditionally we've passed TYPE_MODE here, instead of the
1563 promoted_mode used for function_arg above. However, the
1564 corresponding handling of incoming arguments in function.cc
1565 does pass the promoted mode. */
1566 arg
.mode
= TYPE_MODE (type
);
1567 targetm
.calls
.function_arg_advance (args_so_far
, arg
);
1571 /* Update ARGS_SIZE to contain the total size for the argument block.
1572 Return the original constant component of the argument block's size.
1574 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1575 for arguments passed in registers. */
1578 compute_argument_block_size (int reg_parm_stack_space
,
1579 struct args_size
*args_size
,
1580 tree fndecl ATTRIBUTE_UNUSED
,
1581 tree fntype ATTRIBUTE_UNUSED
,
1582 int preferred_stack_boundary ATTRIBUTE_UNUSED
)
1584 poly_int64 unadjusted_args_size
= args_size
->constant
;
1586 /* For accumulate outgoing args mode we don't need to align, since the frame
1587 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1588 backends from generating misaligned frame sizes. */
1589 if (ACCUMULATE_OUTGOING_ARGS
&& preferred_stack_boundary
> STACK_BOUNDARY
)
1590 preferred_stack_boundary
= STACK_BOUNDARY
;
1592 /* Compute the actual size of the argument block required. The variable
1593 and constant sizes must be combined, the size may have to be rounded,
1594 and there may be a minimum required size. */
1598 args_size
->var
= ARGS_SIZE_TREE (*args_size
);
1599 args_size
->constant
= 0;
1601 preferred_stack_boundary
/= BITS_PER_UNIT
;
1602 if (preferred_stack_boundary
> 1)
1604 /* We don't handle this case yet. To handle it correctly we have
1605 to add the delta, round and subtract the delta.
1606 Currently no machine description requires this support. */
1607 gcc_assert (multiple_p (stack_pointer_delta
,
1608 preferred_stack_boundary
));
1609 args_size
->var
= round_up (args_size
->var
, preferred_stack_boundary
);
1612 if (reg_parm_stack_space
> 0)
1615 = size_binop (MAX_EXPR
, args_size
->var
,
1616 ssize_int (reg_parm_stack_space
));
1618 /* The area corresponding to register parameters is not to count in
1619 the size of the block we need. So make the adjustment. */
1620 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
1622 = size_binop (MINUS_EXPR
, args_size
->var
,
1623 ssize_int (reg_parm_stack_space
));
1628 preferred_stack_boundary
/= BITS_PER_UNIT
;
1629 if (preferred_stack_boundary
< 1)
1630 preferred_stack_boundary
= 1;
1631 args_size
->constant
= (aligned_upper_bound (args_size
->constant
1632 + stack_pointer_delta
,
1633 preferred_stack_boundary
)
1634 - stack_pointer_delta
);
1636 args_size
->constant
= upper_bound (args_size
->constant
,
1637 reg_parm_stack_space
);
1639 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
1640 args_size
->constant
-= reg_parm_stack_space
;
1642 return unadjusted_args_size
;
1645 /* Precompute parameters as needed for a function call.
1647 FLAGS is mask of ECF_* constants.
1649 NUM_ACTUALS is the number of arguments.
1651 ARGS is an array containing information for each argument; this
1652 routine fills in the INITIAL_VALUE and VALUE fields for each
1653 precomputed argument. */
1656 precompute_arguments (int num_actuals
, struct arg_data
*args
)
1660 /* If this is a libcall, then precompute all arguments so that we do not
1661 get extraneous instructions emitted as part of the libcall sequence. */
1663 /* If we preallocated the stack space, and some arguments must be passed
1664 on the stack, then we must precompute any parameter which contains a
1665 function call which will store arguments on the stack.
1666 Otherwise, evaluating the parameter may clobber previous parameters
1667 which have already been stored into the stack. (we have code to avoid
1668 such case by saving the outgoing stack arguments, but it results in
1670 if (!ACCUMULATE_OUTGOING_ARGS
)
1673 for (i
= 0; i
< num_actuals
; i
++)
1678 if (TREE_CODE (args
[i
].tree_value
) != CALL_EXPR
)
1681 /* If this is an addressable type, we cannot pre-evaluate it. */
1682 type
= TREE_TYPE (args
[i
].tree_value
);
1683 gcc_assert (!TREE_ADDRESSABLE (type
));
1685 args
[i
].initial_value
= args
[i
].value
1686 = expand_normal (args
[i
].tree_value
);
1688 mode
= TYPE_MODE (type
);
1689 if (mode
!= args
[i
].mode
)
1691 int unsignedp
= args
[i
].unsignedp
;
1693 = convert_modes (args
[i
].mode
, mode
,
1694 args
[i
].value
, args
[i
].unsignedp
);
1696 /* CSE will replace this only if it contains args[i].value
1697 pseudo, so convert it down to the declared mode using
1699 if (REG_P (args
[i
].value
)
1700 && GET_MODE_CLASS (args
[i
].mode
) == MODE_INT
1701 && promote_mode (type
, mode
, &unsignedp
) != args
[i
].mode
)
1703 args
[i
].initial_value
1704 = gen_lowpart_SUBREG (mode
, args
[i
].value
);
1705 SUBREG_PROMOTED_VAR_P (args
[i
].initial_value
) = 1;
1706 SUBREG_PROMOTED_SET (args
[i
].initial_value
, args
[i
].unsignedp
);
1712 /* Given the current state of MUST_PREALLOCATE and information about
1713 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1714 compute and return the final value for MUST_PREALLOCATE. */
1717 finalize_must_preallocate (int must_preallocate
, int num_actuals
,
1718 struct arg_data
*args
, struct args_size
*args_size
)
1720 /* See if we have or want to preallocate stack space.
1722 If we would have to push a partially-in-regs parm
1723 before other stack parms, preallocate stack space instead.
1725 If the size of some parm is not a multiple of the required stack
1726 alignment, we must preallocate.
1728 If the total size of arguments that would otherwise create a copy in
1729 a temporary (such as a CALL) is more than half the total argument list
1730 size, preallocation is faster.
1732 Another reason to preallocate is if we have a machine (like the m88k)
1733 where stack alignment is required to be maintained between every
1734 pair of insns, not just when the call is made. However, we assume here
1735 that such machines either do not have push insns (and hence preallocation
1736 would occur anyway) or the problem is taken care of with
1739 if (! must_preallocate
)
1741 int partial_seen
= 0;
1742 poly_int64 copy_to_evaluate_size
= 0;
1745 for (i
= 0; i
< num_actuals
&& ! must_preallocate
; i
++)
1747 if (args
[i
].partial
> 0 && ! args
[i
].pass_on_stack
)
1749 else if (partial_seen
&& args
[i
].reg
== 0)
1750 must_preallocate
= 1;
1752 if (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)) == BLKmode
1753 && (TREE_CODE (args
[i
].tree_value
) == CALL_EXPR
1754 || TREE_CODE (args
[i
].tree_value
) == TARGET_EXPR
1755 || TREE_CODE (args
[i
].tree_value
) == COND_EXPR
1756 || TREE_ADDRESSABLE (TREE_TYPE (args
[i
].tree_value
))))
1757 copy_to_evaluate_size
1758 += int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1761 if (maybe_ne (args_size
->constant
, 0)
1762 && maybe_ge (copy_to_evaluate_size
* 2, args_size
->constant
))
1763 must_preallocate
= 1;
1765 return must_preallocate
;
1768 /* If we preallocated stack space, compute the address of each argument
1769 and store it into the ARGS array.
1771 We need not ensure it is a valid memory address here; it will be
1772 validized when it is used.
1774 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1777 compute_argument_addresses (struct arg_data
*args
, rtx argblock
, int num_actuals
)
1781 rtx arg_reg
= argblock
;
1783 poly_int64 arg_offset
= 0;
1785 if (GET_CODE (argblock
) == PLUS
)
1787 arg_reg
= XEXP (argblock
, 0);
1788 arg_offset
= rtx_to_poly_int64 (XEXP (argblock
, 1));
1791 for (i
= 0; i
< num_actuals
; i
++)
1793 rtx offset
= ARGS_SIZE_RTX (args
[i
].locate
.offset
);
1794 rtx slot_offset
= ARGS_SIZE_RTX (args
[i
].locate
.slot_offset
);
1796 unsigned int align
, boundary
;
1797 poly_uint64 units_on_stack
= 0;
1798 machine_mode partial_mode
= VOIDmode
;
1800 /* Skip this parm if it will not be passed on the stack. */
1801 if (! args
[i
].pass_on_stack
1803 && args
[i
].partial
== 0)
1806 if (TYPE_EMPTY_P (TREE_TYPE (args
[i
].tree_value
)))
1809 addr
= simplify_gen_binary (PLUS
, Pmode
, arg_reg
, offset
);
1810 addr
= plus_constant (Pmode
, addr
, arg_offset
);
1812 if (args
[i
].partial
!= 0)
1814 /* Only part of the parameter is being passed on the stack.
1815 Generate a simple memory reference of the correct size. */
1816 units_on_stack
= args
[i
].locate
.size
.constant
;
1817 poly_uint64 bits_on_stack
= units_on_stack
* BITS_PER_UNIT
;
1818 partial_mode
= int_mode_for_size (bits_on_stack
, 1).else_blk ();
1819 args
[i
].stack
= gen_rtx_MEM (partial_mode
, addr
);
1820 set_mem_size (args
[i
].stack
, units_on_stack
);
1824 args
[i
].stack
= gen_rtx_MEM (args
[i
].mode
, addr
);
1825 set_mem_attributes (args
[i
].stack
,
1826 TREE_TYPE (args
[i
].tree_value
), 1);
1828 align
= BITS_PER_UNIT
;
1829 boundary
= args
[i
].locate
.boundary
;
1830 poly_int64 offset_val
;
1831 if (args
[i
].locate
.where_pad
!= PAD_DOWNWARD
)
1833 else if (poly_int_rtx_p (offset
, &offset_val
))
1835 align
= least_bit_hwi (boundary
);
1836 unsigned int offset_align
1837 = known_alignment (offset_val
) * BITS_PER_UNIT
;
1838 if (offset_align
!= 0)
1839 align
= MIN (align
, offset_align
);
1841 set_mem_align (args
[i
].stack
, align
);
1843 addr
= simplify_gen_binary (PLUS
, Pmode
, arg_reg
, slot_offset
);
1844 addr
= plus_constant (Pmode
, addr
, arg_offset
);
1846 if (args
[i
].partial
!= 0)
1848 /* Only part of the parameter is being passed on the stack.
1849 Generate a simple memory reference of the correct size.
1851 args
[i
].stack_slot
= gen_rtx_MEM (partial_mode
, addr
);
1852 set_mem_size (args
[i
].stack_slot
, units_on_stack
);
1856 args
[i
].stack_slot
= gen_rtx_MEM (args
[i
].mode
, addr
);
1857 set_mem_attributes (args
[i
].stack_slot
,
1858 TREE_TYPE (args
[i
].tree_value
), 1);
1860 set_mem_align (args
[i
].stack_slot
, args
[i
].locate
.boundary
);
1862 /* Function incoming arguments may overlap with sibling call
1863 outgoing arguments and we cannot allow reordering of reads
1864 from function arguments with stores to outgoing arguments
1865 of sibling calls. */
1866 set_mem_alias_set (args
[i
].stack
, 0);
1867 set_mem_alias_set (args
[i
].stack_slot
, 0);
1872 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1873 in a call instruction.
1875 FNDECL is the tree node for the target function. For an indirect call
1876 FNDECL will be NULL_TREE.
1878 ADDR is the operand 0 of CALL_EXPR for this call. */
1881 rtx_for_function_call (tree fndecl
, tree addr
)
1885 /* Get the function to call, in the form of RTL. */
1888 if (!TREE_USED (fndecl
) && fndecl
!= current_function_decl
)
1889 TREE_USED (fndecl
) = 1;
1891 /* Get a SYMBOL_REF rtx for the function address. */
1892 funexp
= XEXP (DECL_RTL (fndecl
), 0);
1895 /* Generate an rtx (probably a pseudo-register) for the address. */
1898 funexp
= expand_normal (addr
);
1899 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1904 /* Return the static chain for this function, if any. */
1907 rtx_for_static_chain (const_tree fndecl_or_type
, bool incoming_p
)
1909 if (DECL_P (fndecl_or_type
) && !DECL_STATIC_CHAIN (fndecl_or_type
))
1912 return targetm
.calls
.static_chain (fndecl_or_type
, incoming_p
);
1915 /* Internal state for internal_arg_pointer_based_exp and its helpers. */
1918 /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan,
1919 or NULL_RTX if none has been scanned yet. */
1920 rtx_insn
*scan_start
;
1921 /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is
1922 based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the
1923 pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it
1924 with fixed offset, or PC if this is with variable or unknown offset. */
1926 } internal_arg_pointer_exp_state
;
1928 static rtx
internal_arg_pointer_based_exp (const_rtx
, bool);
1930 /* Helper function for internal_arg_pointer_based_exp. Scan insns in
1931 the tail call sequence, starting with first insn that hasn't been
1932 scanned yet, and note for each pseudo on the LHS whether it is based
1933 on crtl->args.internal_arg_pointer or not, and what offset from that
1934 that pointer it has. */
1937 internal_arg_pointer_based_exp_scan (void)
1939 rtx_insn
*insn
, *scan_start
= internal_arg_pointer_exp_state
.scan_start
;
1941 if (scan_start
== NULL_RTX
)
1942 insn
= get_insns ();
1944 insn
= NEXT_INSN (scan_start
);
1948 rtx set
= single_set (insn
);
1949 if (set
&& REG_P (SET_DEST (set
)) && !HARD_REGISTER_P (SET_DEST (set
)))
1952 unsigned int idx
= REGNO (SET_DEST (set
)) - FIRST_PSEUDO_REGISTER
;
1953 /* Punt on pseudos set multiple times. */
1954 if (idx
< internal_arg_pointer_exp_state
.cache
.length ()
1955 && (internal_arg_pointer_exp_state
.cache
[idx
]
1959 val
= internal_arg_pointer_based_exp (SET_SRC (set
), false);
1960 if (val
!= NULL_RTX
)
1962 if (idx
>= internal_arg_pointer_exp_state
.cache
.length ())
1963 internal_arg_pointer_exp_state
.cache
1964 .safe_grow_cleared (idx
+ 1, true);
1965 internal_arg_pointer_exp_state
.cache
[idx
] = val
;
1968 if (NEXT_INSN (insn
) == NULL_RTX
)
1970 insn
= NEXT_INSN (insn
);
1973 internal_arg_pointer_exp_state
.scan_start
= scan_start
;
1976 /* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return
1977 NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on
1978 it with fixed offset, or PC if this is with variable or unknown offset.
1979 TOPLEVEL is true if the function is invoked at the topmost level. */
1982 internal_arg_pointer_based_exp (const_rtx rtl
, bool toplevel
)
1984 if (CONSTANT_P (rtl
))
1987 if (rtl
== crtl
->args
.internal_arg_pointer
)
1990 if (REG_P (rtl
) && HARD_REGISTER_P (rtl
))
1994 if (GET_CODE (rtl
) == PLUS
&& poly_int_rtx_p (XEXP (rtl
, 1), &offset
))
1996 rtx val
= internal_arg_pointer_based_exp (XEXP (rtl
, 0), toplevel
);
1997 if (val
== NULL_RTX
|| val
== pc_rtx
)
1999 return plus_constant (Pmode
, val
, offset
);
2002 /* When called at the topmost level, scan pseudo assignments in between the
2003 last scanned instruction in the tail call sequence and the latest insn
2004 in that sequence. */
2006 internal_arg_pointer_based_exp_scan ();
2010 unsigned int idx
= REGNO (rtl
) - FIRST_PSEUDO_REGISTER
;
2011 if (idx
< internal_arg_pointer_exp_state
.cache
.length ())
2012 return internal_arg_pointer_exp_state
.cache
[idx
];
2017 subrtx_iterator::array_type array
;
2018 FOR_EACH_SUBRTX (iter
, array
, rtl
, NONCONST
)
2020 const_rtx x
= *iter
;
2021 if (REG_P (x
) && internal_arg_pointer_based_exp (x
, false) != NULL_RTX
)
2024 iter
.skip_subrtxes ();
2030 /* Return true if SIZE bytes starting from address ADDR might overlap an
2031 already-clobbered argument area. This function is used to determine
2032 if we should give up a sibcall. */
2035 mem_might_overlap_already_clobbered_arg_p (rtx addr
, poly_uint64 size
)
2038 unsigned HOST_WIDE_INT start
, end
;
2041 if (bitmap_empty_p (stored_args_map
)
2042 && stored_args_watermark
== HOST_WIDE_INT_M1U
)
2044 val
= internal_arg_pointer_based_exp (addr
, true);
2045 if (val
== NULL_RTX
)
2047 else if (!poly_int_rtx_p (val
, &i
))
2050 if (known_eq (size
, 0U))
2053 if (STACK_GROWS_DOWNWARD
)
2054 i
-= crtl
->args
.pretend_args_size
;
2056 i
+= crtl
->args
.pretend_args_size
;
2058 if (ARGS_GROW_DOWNWARD
)
2061 /* We can ignore any references to the function's pretend args,
2062 which at this point would manifest as negative values of I. */
2063 if (known_le (i
, 0) && known_le (size
, poly_uint64 (-i
)))
2066 start
= maybe_lt (i
, 0) ? 0 : constant_lower_bound (i
);
2067 if (!(i
+ size
).is_constant (&end
))
2068 end
= HOST_WIDE_INT_M1U
;
2070 if (end
> stored_args_watermark
)
2073 end
= MIN (end
, SBITMAP_SIZE (stored_args_map
));
2074 for (unsigned HOST_WIDE_INT k
= start
; k
< end
; ++k
)
2075 if (bitmap_bit_p (stored_args_map
, k
))
2081 /* Do the register loads required for any wholly-register parms or any
2082 parms which are passed both on the stack and in a register. Their
2083 expressions were already evaluated.
2085 Mark all register-parms as living through the call, putting these USE
2086 insns in the CALL_INSN_FUNCTION_USAGE field.
2088 When IS_SIBCALL, perform the check_sibcall_argument_overlap
2089 checking, setting *SIBCALL_FAILURE if appropriate. */
2092 load_register_parameters (struct arg_data
*args
, int num_actuals
,
2093 rtx
*call_fusage
, int flags
, int is_sibcall
,
2094 int *sibcall_failure
)
2098 for (i
= 0; i
< num_actuals
; i
++)
2100 rtx reg
= ((flags
& ECF_SIBCALL
)
2101 ? args
[i
].tail_call_reg
: args
[i
].reg
);
2104 int partial
= args
[i
].partial
;
2106 poly_int64 size
= 0;
2107 HOST_WIDE_INT const_size
= 0;
2108 rtx_insn
*before_arg
= get_last_insn ();
2109 tree tree_value
= args
[i
].tree_value
;
2110 tree type
= TREE_TYPE (tree_value
);
2111 if (RECORD_OR_UNION_TYPE_P (type
) && TYPE_TRANSPARENT_AGGR (type
))
2112 type
= TREE_TYPE (first_field (type
));
2113 /* Set non-negative if we must move a word at a time, even if
2114 just one word (e.g, partial == 4 && mode == DFmode). Set
2115 to -1 if we just use a normal move insn. This value can be
2116 zero if the argument is a zero size structure. */
2118 if (GET_CODE (reg
) == PARALLEL
)
2122 gcc_assert (partial
% UNITS_PER_WORD
== 0);
2123 nregs
= partial
/ UNITS_PER_WORD
;
2125 else if (TYPE_MODE (type
) == BLKmode
)
2127 /* Variable-sized parameters should be described by a
2128 PARALLEL instead. */
2129 const_size
= int_size_in_bytes (type
);
2130 gcc_assert (const_size
>= 0);
2131 nregs
= (const_size
+ (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
2135 size
= GET_MODE_SIZE (args
[i
].mode
);
2137 /* Handle calls that pass values in multiple non-contiguous
2138 locations. The Irix 6 ABI has examples of this. */
2140 if (GET_CODE (reg
) == PARALLEL
)
2141 emit_group_move (reg
, args
[i
].parallel_value
);
2143 /* If simple case, just do move. If normal partial, store_one_arg
2144 has already loaded the register for us. In all other cases,
2145 load the register(s) from memory. */
2147 else if (nregs
== -1)
2149 emit_move_insn (reg
, args
[i
].value
);
2150 #ifdef BLOCK_REG_PADDING
2151 /* Handle case where we have a value that needs shifting
2152 up to the msb. eg. a QImode value and we're padding
2153 upward on a BYTES_BIG_ENDIAN machine. */
2154 if (args
[i
].locate
.where_pad
2155 == (BYTES_BIG_ENDIAN
? PAD_UPWARD
: PAD_DOWNWARD
))
2157 gcc_checking_assert (ordered_p (size
, UNITS_PER_WORD
));
2158 if (maybe_lt (size
, UNITS_PER_WORD
))
2162 = (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
2164 /* Assigning REG here rather than a temp makes
2165 CALL_FUSAGE report the whole reg as used.
2166 Strictly speaking, the call only uses SIZE
2167 bytes at the msb end, but it doesn't seem worth
2168 generating rtl to say that. */
2169 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
2170 x
= expand_shift (LSHIFT_EXPR
, word_mode
,
2171 reg
, shift
, reg
, 1);
2173 emit_move_insn (reg
, x
);
2179 /* If we have pre-computed the values to put in the registers in
2180 the case of non-aligned structures, copy them in now. */
2182 else if (args
[i
].n_aligned_regs
!= 0)
2183 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
2184 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
) + j
),
2185 args
[i
].aligned_regs
[j
]);
2187 /* If we need a single register and the source is a constant
2188 VAR_DECL with a simple constructor, expand that constructor
2189 via a pseudo rather than read from (possibly misaligned)
2190 memory. PR middle-end/95126. */
2193 && !args
[i
].pass_on_stack
2194 && VAR_P (tree_value
)
2195 && TREE_READONLY (tree_value
)
2196 && !TREE_SIDE_EFFECTS (tree_value
)
2197 && immediate_const_ctor_p (DECL_INITIAL (tree_value
)))
2199 rtx target
= gen_reg_rtx (word_mode
);
2200 store_constructor (DECL_INITIAL (tree_value
), target
, 0,
2201 int_expr_size (DECL_INITIAL (tree_value
)),
2203 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
2204 emit_move_insn (reg
, target
);
2206 else if (partial
== 0 || args
[i
].pass_on_stack
)
2208 /* SIZE and CONST_SIZE are 0 for partial arguments and
2209 the size of a BLKmode type otherwise. */
2210 gcc_checking_assert (known_eq (size
, const_size
));
2211 rtx mem
= validize_mem (copy_rtx (args
[i
].value
));
2213 /* Check for overlap with already clobbered argument area,
2214 providing that this has non-zero size. */
2217 && (mem_might_overlap_already_clobbered_arg_p
2218 (XEXP (args
[i
].value
, 0), const_size
)))
2219 *sibcall_failure
= 1;
2221 if (const_size
% UNITS_PER_WORD
== 0
2222 || MEM_ALIGN (mem
) % BITS_PER_WORD
== 0)
2223 move_block_to_reg (REGNO (reg
), mem
, nregs
, args
[i
].mode
);
2227 move_block_to_reg (REGNO (reg
), mem
, nregs
- 1,
2229 rtx dest
= gen_rtx_REG (word_mode
, REGNO (reg
) + nregs
- 1);
2230 unsigned int bitoff
= (nregs
- 1) * BITS_PER_WORD
;
2231 unsigned int bitsize
= const_size
* BITS_PER_UNIT
- bitoff
;
2232 rtx x
= extract_bit_field (mem
, bitsize
, bitoff
, 1, dest
,
2233 word_mode
, word_mode
, false,
2235 if (BYTES_BIG_ENDIAN
)
2236 x
= expand_shift (LSHIFT_EXPR
, word_mode
, x
,
2237 BITS_PER_WORD
- bitsize
, dest
, 1);
2239 emit_move_insn (dest
, x
);
2242 /* Handle a BLKmode that needs shifting. */
2243 if (nregs
== 1 && const_size
< UNITS_PER_WORD
2244 #ifdef BLOCK_REG_PADDING
2245 && args
[i
].locate
.where_pad
== PAD_DOWNWARD
2251 rtx dest
= gen_rtx_REG (word_mode
, REGNO (reg
));
2252 int shift
= (UNITS_PER_WORD
- const_size
) * BITS_PER_UNIT
;
2253 enum tree_code dir
= (BYTES_BIG_ENDIAN
2254 ? RSHIFT_EXPR
: LSHIFT_EXPR
);
2257 x
= expand_shift (dir
, word_mode
, dest
, shift
, dest
, 1);
2259 emit_move_insn (dest
, x
);
2263 /* When a parameter is a block, and perhaps in other cases, it is
2264 possible that it did a load from an argument slot that was
2265 already clobbered. */
2267 && check_sibcall_argument_overlap (before_arg
, &args
[i
], 0))
2268 *sibcall_failure
= 1;
2270 /* Handle calls that pass values in multiple non-contiguous
2271 locations. The Irix 6 ABI has examples of this. */
2272 if (GET_CODE (reg
) == PARALLEL
)
2273 use_group_regs (call_fusage
, reg
);
2274 else if (nregs
== -1)
2275 use_reg_mode (call_fusage
, reg
, TYPE_MODE (type
));
2277 use_regs (call_fusage
, REGNO (reg
), nregs
);
2282 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
2283 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
2284 bytes, then we would need to push some additional bytes to pad the
2285 arguments. So, we try to compute an adjust to the stack pointer for an
2286 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
2287 bytes. Then, when the arguments are pushed the stack will be perfectly
2290 Return true if this optimization is possible, storing the adjustment
2291 in ADJUSTMENT_OUT and setting ARGS_SIZE->CONSTANT to the number of
2292 bytes that should be popped after the call. */
2295 combine_pending_stack_adjustment_and_call (poly_int64_pod
*adjustment_out
,
2296 poly_int64 unadjusted_args_size
,
2297 struct args_size
*args_size
,
2298 unsigned int preferred_unit_stack_boundary
)
2300 /* The number of bytes to pop so that the stack will be
2301 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
2302 poly_int64 adjustment
;
2303 /* The alignment of the stack after the arguments are pushed, if we
2304 just pushed the arguments without adjust the stack here. */
2305 unsigned HOST_WIDE_INT unadjusted_alignment
;
2307 if (!known_misalignment (stack_pointer_delta
+ unadjusted_args_size
,
2308 preferred_unit_stack_boundary
,
2309 &unadjusted_alignment
))
2312 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
2313 as possible -- leaving just enough left to cancel out the
2314 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
2315 PENDING_STACK_ADJUST is non-negative, and congruent to
2316 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
2318 /* Begin by trying to pop all the bytes. */
2319 unsigned HOST_WIDE_INT tmp_misalignment
;
2320 if (!known_misalignment (pending_stack_adjust
,
2321 preferred_unit_stack_boundary
,
2324 unadjusted_alignment
-= tmp_misalignment
;
2325 adjustment
= pending_stack_adjust
;
2326 /* Push enough additional bytes that the stack will be aligned
2327 after the arguments are pushed. */
2328 if (preferred_unit_stack_boundary
> 1 && unadjusted_alignment
)
2329 adjustment
-= preferred_unit_stack_boundary
- unadjusted_alignment
;
2331 /* We need to know whether the adjusted argument size
2332 (UNADJUSTED_ARGS_SIZE - ADJUSTMENT) constitutes an allocation
2333 or a deallocation. */
2334 if (!ordered_p (adjustment
, unadjusted_args_size
))
2337 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
2338 bytes after the call. The right number is the entire
2339 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
2340 by the arguments in the first place. */
2342 = pending_stack_adjust
- adjustment
+ unadjusted_args_size
;
2344 *adjustment_out
= adjustment
;
2348 /* Scan X expression if it does not dereference any argument slots
2349 we already clobbered by tail call arguments (as noted in stored_args_map
2351 Return nonzero if X expression dereferences such argument slots,
2355 check_sibcall_argument_overlap_1 (rtx x
)
2364 code
= GET_CODE (x
);
2366 /* We need not check the operands of the CALL expression itself. */
2371 return (mem_might_overlap_already_clobbered_arg_p
2372 (XEXP (x
, 0), GET_MODE_SIZE (GET_MODE (x
))));
2374 /* Scan all subexpressions. */
2375 fmt
= GET_RTX_FORMAT (code
);
2376 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
2380 if (check_sibcall_argument_overlap_1 (XEXP (x
, i
)))
2383 else if (*fmt
== 'E')
2385 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2386 if (check_sibcall_argument_overlap_1 (XVECEXP (x
, i
, j
)))
2393 /* Scan sequence after INSN if it does not dereference any argument slots
2394 we already clobbered by tail call arguments (as noted in stored_args_map
2395 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
2396 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
2397 should be 0). Return nonzero if sequence after INSN dereferences such argument
2398 slots, zero otherwise. */
2401 check_sibcall_argument_overlap (rtx_insn
*insn
, struct arg_data
*arg
,
2402 int mark_stored_args_map
)
2404 poly_uint64 low
, high
;
2405 unsigned HOST_WIDE_INT const_low
, const_high
;
2407 if (insn
== NULL_RTX
)
2408 insn
= get_insns ();
2410 insn
= NEXT_INSN (insn
);
2412 for (; insn
; insn
= NEXT_INSN (insn
))
2414 && check_sibcall_argument_overlap_1 (PATTERN (insn
)))
2417 if (mark_stored_args_map
)
2419 if (ARGS_GROW_DOWNWARD
)
2420 low
= -arg
->locate
.slot_offset
.constant
- arg
->locate
.size
.constant
;
2422 low
= arg
->locate
.slot_offset
.constant
;
2423 high
= low
+ arg
->locate
.size
.constant
;
2425 const_low
= constant_lower_bound (low
);
2426 if (high
.is_constant (&const_high
))
2427 for (unsigned HOST_WIDE_INT i
= const_low
; i
< const_high
; ++i
)
2428 bitmap_set_bit (stored_args_map
, i
);
2430 stored_args_watermark
= MIN (stored_args_watermark
, const_low
);
2432 return insn
!= NULL_RTX
;
2435 /* Given that a function returns a value of mode MODE at the most
2436 significant end of hard register VALUE, shift VALUE left or right
2437 as specified by LEFT_P. Return true if some action was needed. */
2440 shift_return_value (machine_mode mode
, bool left_p
, rtx value
)
2442 gcc_assert (REG_P (value
) && HARD_REGISTER_P (value
));
2443 machine_mode value_mode
= GET_MODE (value
);
2444 poly_int64 shift
= GET_MODE_BITSIZE (value_mode
) - GET_MODE_BITSIZE (mode
);
2446 if (known_eq (shift
, 0))
2449 /* Use ashr rather than lshr for right shifts. This is for the benefit
2450 of the MIPS port, which requires SImode values to be sign-extended
2451 when stored in 64-bit registers. */
2452 if (!force_expand_binop (value_mode
, left_p
? ashl_optab
: ashr_optab
,
2453 value
, gen_int_shift_amount (value_mode
, shift
),
2454 value
, 1, OPTAB_WIDEN
))
2459 /* If X is a likely-spilled register value, copy it to a pseudo
2460 register and return that register. Return X otherwise. */
2463 avoid_likely_spilled_reg (rtx x
)
2468 && HARD_REGISTER_P (x
)
2469 && targetm
.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x
))))
2471 /* Make sure that we generate a REG rather than a CONCAT.
2472 Moves into CONCATs can need nontrivial instructions,
2473 and the whole point of this function is to avoid
2474 using the hard register directly in such a situation. */
2475 generating_concat_p
= 0;
2476 new_rtx
= gen_reg_rtx (GET_MODE (x
));
2477 generating_concat_p
= 1;
2478 emit_move_insn (new_rtx
, x
);
2484 /* Helper function for expand_call.
2485 Return false is EXP is not implementable as a sibling call. */
2488 can_implement_as_sibling_call_p (tree exp
,
2489 rtx structure_value_addr
,
2494 const args_size
&args_size
)
2496 if (!targetm
.have_sibcall_epilogue ())
2498 maybe_complain_about_tail_call
2500 "machine description does not have"
2501 " a sibcall_epilogue instruction pattern");
2505 /* Doing sibling call optimization needs some work, since
2506 structure_value_addr can be allocated on the stack.
2507 It does not seem worth the effort since few optimizable
2508 sibling calls will return a structure. */
2509 if (structure_value_addr
!= NULL_RTX
)
2511 maybe_complain_about_tail_call (exp
, "callee returns a structure");
2515 /* Check whether the target is able to optimize the call
2517 if (!targetm
.function_ok_for_sibcall (fndecl
, exp
))
2519 maybe_complain_about_tail_call (exp
,
2520 "target is not able to optimize the"
2521 " call into a sibling call");
2525 /* Functions that do not return exactly once may not be sibcall
2527 if (flags
& ECF_RETURNS_TWICE
)
2529 maybe_complain_about_tail_call (exp
, "callee returns twice");
2532 if (flags
& ECF_NORETURN
)
2534 maybe_complain_about_tail_call (exp
, "callee does not return");
2538 if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr
))))
2540 maybe_complain_about_tail_call (exp
, "volatile function type");
2544 /* __sanitizer_cov_trace_pc is supposed to inspect its return address
2545 to identify the caller, and therefore should not be tailcalled. */
2546 if (fndecl
&& DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
2547 && DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_SANITIZER_COV_TRACE_PC
)
2549 /* No need for maybe_complain_about_tail_call here:
2550 the call is synthesized by the compiler. */
2554 /* If the called function is nested in the current one, it might access
2555 some of the caller's arguments, but could clobber them beforehand if
2556 the argument areas are shared. */
2557 if (fndecl
&& decl_function_context (fndecl
) == current_function_decl
)
2559 maybe_complain_about_tail_call (exp
, "nested function");
2563 /* If this function requires more stack slots than the current
2564 function, we cannot change it into a sibling call.
2565 crtl->args.pretend_args_size is not part of the
2566 stack allocated by our caller. */
2567 if (maybe_gt (args_size
.constant
,
2568 crtl
->args
.size
- crtl
->args
.pretend_args_size
))
2570 maybe_complain_about_tail_call (exp
,
2571 "callee required more stack slots"
2572 " than the caller");
2576 /* If the callee pops its own arguments, then it must pop exactly
2577 the same number of arguments as the current function. */
2578 if (maybe_ne (targetm
.calls
.return_pops_args (fndecl
, funtype
,
2579 args_size
.constant
),
2580 targetm
.calls
.return_pops_args (current_function_decl
,
2582 (current_function_decl
),
2585 maybe_complain_about_tail_call (exp
,
2586 "inconsistent number of"
2587 " popped arguments");
2591 if (!lang_hooks
.decls
.ok_for_sibcall (fndecl
))
2593 maybe_complain_about_tail_call (exp
, "frontend does not support"
2598 /* All checks passed. */
2602 /* Update stack alignment when the parameter is passed in the stack
2603 since the outgoing parameter requires extra alignment on the calling
2607 update_stack_alignment_for_call (struct locate_and_pad_arg_data
*locate
)
2609 if (crtl
->stack_alignment_needed
< locate
->boundary
)
2610 crtl
->stack_alignment_needed
= locate
->boundary
;
2611 if (crtl
->preferred_stack_boundary
< locate
->boundary
)
2612 crtl
->preferred_stack_boundary
= locate
->boundary
;
2615 /* Generate all the code for a CALL_EXPR exp
2616 and return an rtx for its value.
2617 Store the value in TARGET (specified as an rtx) if convenient.
2618 If the value is stored in TARGET then TARGET is returned.
2619 If IGNORE is nonzero, then we ignore the value of the function call. */
2622 expand_call (tree exp
, rtx target
, int ignore
)
2624 /* Nonzero if we are currently expanding a call. */
2625 static int currently_expanding_call
= 0;
2627 /* RTX for the function to be called. */
2629 /* Sequence of insns to perform a normal "call". */
2630 rtx_insn
*normal_call_insns
= NULL
;
2631 /* Sequence of insns to perform a tail "call". */
2632 rtx_insn
*tail_call_insns
= NULL
;
2633 /* Data type of the function. */
2635 tree type_arg_types
;
2637 /* Declaration of the function being called,
2638 or 0 if the function is computed (not known by name). */
2640 /* The type of the function being called. */
2642 bool try_tail_call
= CALL_EXPR_TAILCALL (exp
);
2643 bool must_tail_call
= CALL_EXPR_MUST_TAIL_CALL (exp
);
2646 /* Register in which non-BLKmode value will be returned,
2647 or 0 if no value or if value is BLKmode. */
2649 /* Address where we should return a BLKmode value;
2650 0 if value not BLKmode. */
2651 rtx structure_value_addr
= 0;
2652 /* Nonzero if that address is being passed by treating it as
2653 an extra, implicit first parameter. Otherwise,
2654 it is passed by being copied directly into struct_value_rtx. */
2655 int structure_value_addr_parm
= 0;
2656 /* Holds the value of implicit argument for the struct value. */
2657 tree structure_value_addr_value
= NULL_TREE
;
2658 /* Size of aggregate value wanted, or zero if none wanted
2659 or if we are using the non-reentrant PCC calling convention
2660 or expecting the value in registers. */
2661 poly_int64 struct_value_size
= 0;
2662 /* Nonzero if called function returns an aggregate in memory PCC style,
2663 by returning the address of where to find it. */
2664 int pcc_struct_value
= 0;
2665 rtx struct_value
= 0;
2667 /* Number of actual parameters in this call, including struct value addr. */
2669 /* Number of named args. Args after this are anonymous ones
2670 and they must all go on the stack. */
2672 /* Number of complex actual arguments that need to be split. */
2673 int num_complex_actuals
= 0;
2675 /* Vector of information about each argument.
2676 Arguments are numbered in the order they will be pushed,
2677 not the order they are written. */
2678 struct arg_data
*args
;
2680 /* Total size in bytes of all the stack-parms scanned so far. */
2681 struct args_size args_size
;
2682 struct args_size adjusted_args_size
;
2683 /* Size of arguments before any adjustments (such as rounding). */
2684 poly_int64 unadjusted_args_size
;
2685 /* Data on reg parms scanned so far. */
2686 CUMULATIVE_ARGS args_so_far_v
;
2687 cumulative_args_t args_so_far
;
2688 /* Nonzero if a reg parm has been scanned. */
2690 /* Nonzero if this is an indirect function call. */
2692 /* Nonzero if we must avoid push-insns in the args for this call.
2693 If stack space is allocated for register parameters, but not by the
2694 caller, then it is preallocated in the fixed part of the stack frame.
2695 So the entire argument block must then be preallocated (i.e., we
2696 ignore PUSH_ROUNDING in that case). */
2698 int must_preallocate
= !targetm
.calls
.push_argument (0);
2700 /* Size of the stack reserved for parameter registers. */
2701 int reg_parm_stack_space
= 0;
2703 /* Address of space preallocated for stack parms
2704 (on machines that lack push insns), or 0 if space not preallocated. */
2707 /* Mask of ECF_ and ERF_ flags. */
2709 int return_flags
= 0;
2710 #ifdef REG_PARM_STACK_SPACE
2711 /* Define the boundary of the register parm stack space that needs to be
2713 int low_to_save
, high_to_save
;
2714 rtx save_area
= 0; /* Place that it is saved */
2717 unsigned int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
2718 char *initial_stack_usage_map
= stack_usage_map
;
2719 unsigned HOST_WIDE_INT initial_stack_usage_watermark
= stack_usage_watermark
;
2720 char *stack_usage_map_buf
= NULL
;
2722 poly_int64 old_stack_allocated
;
2724 /* State variables to track stack modifications. */
2725 rtx old_stack_level
= 0;
2726 int old_stack_arg_under_construction
= 0;
2727 poly_int64 old_pending_adj
= 0;
2728 int old_inhibit_defer_pop
= inhibit_defer_pop
;
2730 /* Some stack pointer alterations we make are performed via
2731 allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
2732 which we then also need to save/restore along the way. */
2733 poly_int64 old_stack_pointer_delta
= 0;
2736 tree addr
= CALL_EXPR_FN (exp
);
2738 /* The alignment of the stack, in bits. */
2739 unsigned HOST_WIDE_INT preferred_stack_boundary
;
2740 /* The alignment of the stack, in bytes. */
2741 unsigned HOST_WIDE_INT preferred_unit_stack_boundary
;
2742 /* The static chain value to use for this call. */
2743 rtx static_chain_value
;
2744 /* See if this is "nothrow" function call. */
2745 if (TREE_NOTHROW (exp
))
2746 flags
|= ECF_NOTHROW
;
2748 /* See if we can find a DECL-node for the actual function, and get the
2749 function attributes (flags) from the function decl or type node. */
2750 fndecl
= get_callee_fndecl (exp
);
2753 fntype
= TREE_TYPE (fndecl
);
2754 flags
|= flags_from_decl_or_type (fndecl
);
2755 return_flags
|= decl_return_flags (fndecl
);
2759 fntype
= TREE_TYPE (TREE_TYPE (addr
));
2760 flags
|= flags_from_decl_or_type (fntype
);
2761 if (CALL_EXPR_BY_DESCRIPTOR (exp
))
2762 flags
|= ECF_BY_DESCRIPTOR
;
2764 rettype
= TREE_TYPE (exp
);
2766 struct_value
= targetm
.calls
.struct_value_rtx (fntype
, 0);
2768 /* Warn if this value is an aggregate type,
2769 regardless of which calling convention we are using for it. */
2770 if (AGGREGATE_TYPE_P (rettype
))
2771 warning (OPT_Waggregate_return
, "function call has aggregate value");
2773 /* If the result of a non looping pure or const function call is
2774 ignored (or void), and none of its arguments are volatile, we can
2775 avoid expanding the call and just evaluate the arguments for
2777 if ((flags
& (ECF_CONST
| ECF_PURE
))
2778 && (!(flags
& ECF_LOOPING_CONST_OR_PURE
))
2779 && (flags
& ECF_NOTHROW
)
2780 && (ignore
|| target
== const0_rtx
2781 || TYPE_MODE (rettype
) == VOIDmode
))
2783 bool volatilep
= false;
2785 call_expr_arg_iterator iter
;
2787 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2788 if (TREE_THIS_VOLATILE (arg
))
2796 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2797 expand_expr (arg
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
2802 #ifdef REG_PARM_STACK_SPACE
2803 reg_parm_stack_space
= REG_PARM_STACK_SPACE (!fndecl
? fntype
: fndecl
);
2806 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
)))
2807 && reg_parm_stack_space
> 0 && targetm
.calls
.push_argument (0))
2808 must_preallocate
= 1;
2810 /* Set up a place to return a structure. */
2812 /* Cater to broken compilers. */
2813 if (aggregate_value_p (exp
, fntype
))
2815 /* This call returns a big structure. */
2816 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
2818 #ifdef PCC_STATIC_STRUCT_RETURN
2820 pcc_struct_value
= 1;
2822 #else /* not PCC_STATIC_STRUCT_RETURN */
2824 if (!poly_int_tree_p (TYPE_SIZE_UNIT (rettype
), &struct_value_size
))
2825 struct_value_size
= -1;
2827 /* Even if it is semantically safe to use the target as the return
2828 slot, it may be not sufficiently aligned for the return type. */
2829 if (CALL_EXPR_RETURN_SLOT_OPT (exp
)
2832 /* If rettype is addressable, we may not create a temporary.
2833 If target is properly aligned at runtime and the compiler
2834 just doesn't know about it, it will work fine, otherwise it
2836 && (TREE_ADDRESSABLE (rettype
)
2837 || !(MEM_ALIGN (target
) < TYPE_ALIGN (rettype
)
2838 && targetm
.slow_unaligned_access (TYPE_MODE (rettype
),
2839 MEM_ALIGN (target
)))))
2840 structure_value_addr
= XEXP (target
, 0);
2843 /* For variable-sized objects, we must be called with a target
2844 specified. If we were to allocate space on the stack here,
2845 we would have no way of knowing when to free it. */
2846 rtx d
= assign_temp (rettype
, 1, 1);
2847 structure_value_addr
= XEXP (d
, 0);
2851 #endif /* not PCC_STATIC_STRUCT_RETURN */
2854 /* Figure out the amount to which the stack should be aligned. */
2855 preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
2858 struct cgraph_rtl_info
*i
= cgraph_node::rtl_info (fndecl
);
2859 /* Without automatic stack alignment, we can't increase preferred
2860 stack boundary. With automatic stack alignment, it is
2861 unnecessary since unless we can guarantee that all callers will
2862 align the outgoing stack properly, callee has to align its
2865 && i
->preferred_incoming_stack_boundary
2866 && i
->preferred_incoming_stack_boundary
< preferred_stack_boundary
)
2867 preferred_stack_boundary
= i
->preferred_incoming_stack_boundary
;
2870 /* Operand 0 is a pointer-to-function; get the type of the function. */
2871 funtype
= TREE_TYPE (addr
);
2872 gcc_assert (POINTER_TYPE_P (funtype
));
2873 funtype
= TREE_TYPE (funtype
);
2875 /* Count whether there are actual complex arguments that need to be split
2876 into their real and imaginary parts. Munge the type_arg_types
2877 appropriately here as well. */
2878 if (targetm
.calls
.split_complex_arg
)
2880 call_expr_arg_iterator iter
;
2882 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2884 tree type
= TREE_TYPE (arg
);
2885 if (type
&& TREE_CODE (type
) == COMPLEX_TYPE
2886 && targetm
.calls
.split_complex_arg (type
))
2887 num_complex_actuals
++;
2889 type_arg_types
= split_complex_types (TYPE_ARG_TYPES (funtype
));
2892 type_arg_types
= TYPE_ARG_TYPES (funtype
);
2894 if (flags
& ECF_MAY_BE_ALLOCA
)
2895 cfun
->calls_alloca
= 1;
2897 /* If struct_value_rtx is 0, it means pass the address
2898 as if it were an extra parameter. Put the argument expression
2899 in structure_value_addr_value. */
2900 if (structure_value_addr
&& struct_value
== 0)
2902 /* If structure_value_addr is a REG other than
2903 virtual_outgoing_args_rtx, we can use always use it. If it
2904 is not a REG, we must always copy it into a register.
2905 If it is virtual_outgoing_args_rtx, we must copy it to another
2906 register in some cases. */
2907 rtx temp
= (!REG_P (structure_value_addr
)
2908 || (ACCUMULATE_OUTGOING_ARGS
2909 && stack_arg_under_construction
2910 && structure_value_addr
== virtual_outgoing_args_rtx
)
2911 ? copy_addr_to_reg (convert_memory_address
2912 (Pmode
, structure_value_addr
))
2913 : structure_value_addr
);
2915 structure_value_addr_value
=
2916 make_tree (build_pointer_type (TREE_TYPE (funtype
)), temp
);
2917 structure_value_addr_parm
= 1;
2920 /* Count the arguments and set NUM_ACTUALS. */
2922 = call_expr_nargs (exp
) + num_complex_actuals
+ structure_value_addr_parm
;
2924 /* Compute number of named args.
2925 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2927 if (type_arg_types
!= 0)
2929 = (list_length (type_arg_types
)
2930 /* Count the struct value address, if it is passed as a parm. */
2931 + structure_value_addr_parm
);
2932 else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype
))
2935 /* If we know nothing, treat all args as named. */
2936 n_named_args
= num_actuals
;
2938 /* Start updating where the next arg would go.
2940 On some machines (such as the PA) indirect calls have a different
2941 calling convention than normal calls. The fourth argument in
2942 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2944 INIT_CUMULATIVE_ARGS (args_so_far_v
, funtype
, NULL_RTX
, fndecl
, n_named_args
);
2945 args_so_far
= pack_cumulative_args (&args_so_far_v
);
2947 /* Now possibly adjust the number of named args.
2948 Normally, don't include the last named arg if anonymous args follow.
2949 We do include the last named arg if
2950 targetm.calls.strict_argument_naming() returns nonzero.
2951 (If no anonymous args follow, the result of list_length is actually
2952 one too large. This is harmless.)
2954 If targetm.calls.pretend_outgoing_varargs_named() returns
2955 nonzero, and targetm.calls.strict_argument_naming() returns zero,
2956 this machine will be able to place unnamed args that were passed
2957 in registers into the stack. So treat all args as named. This
2958 allows the insns emitting for a specific argument list to be
2959 independent of the function declaration.
2961 If targetm.calls.pretend_outgoing_varargs_named() returns zero,
2962 we do not have any reliable way to pass unnamed args in
2963 registers, so we must force them into memory. */
2965 if (type_arg_types
!= 0
2966 && targetm
.calls
.strict_argument_naming (args_so_far
))
2968 else if (type_arg_types
!= 0
2969 && ! targetm
.calls
.pretend_outgoing_varargs_named (args_so_far
))
2970 /* Don't include the last named arg. */
2972 else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype
))
2975 /* Treat all args as named. */
2976 n_named_args
= num_actuals
;
2978 /* Make a vector to hold all the information about each arg. */
2979 args
= XCNEWVEC (struct arg_data
, num_actuals
);
2981 /* Build up entries in the ARGS array, compute the size of the
2982 arguments into ARGS_SIZE, etc. */
2983 initialize_argument_information (num_actuals
, args
, &args_size
,
2985 structure_value_addr_value
, fndecl
, fntype
,
2986 args_so_far
, reg_parm_stack_space
,
2987 &old_stack_level
, &old_pending_adj
,
2988 &must_preallocate
, &flags
,
2989 &try_tail_call
, CALL_FROM_THUNK_P (exp
));
2992 must_preallocate
= 1;
2994 /* Now make final decision about preallocating stack space. */
2995 must_preallocate
= finalize_must_preallocate (must_preallocate
,
2999 /* If the structure value address will reference the stack pointer, we
3000 must stabilize it. We don't need to do this if we know that we are
3001 not going to adjust the stack pointer in processing this call. */
3003 if (structure_value_addr
3004 && (reg_mentioned_p (virtual_stack_dynamic_rtx
, structure_value_addr
)
3005 || reg_mentioned_p (virtual_outgoing_args_rtx
,
3006 structure_value_addr
))
3008 || (!ACCUMULATE_OUTGOING_ARGS
3009 && maybe_ne (args_size
.constant
, 0))))
3010 structure_value_addr
= copy_to_reg (structure_value_addr
);
3012 /* Tail calls can make things harder to debug, and we've traditionally
3013 pushed these optimizations into -O2. Don't try if we're already
3014 expanding a call, as that means we're an argument. Don't try if
3015 there's cleanups, as we know there's code to follow the call. */
3016 if (currently_expanding_call
++ != 0
3017 || (!flag_optimize_sibling_calls
&& !CALL_FROM_THUNK_P (exp
))
3019 || dbg_cnt (tail_call
) == false)
3022 /* Workaround buggy C/C++ wrappers around Fortran routines with
3023 character(len=constant) arguments if the hidden string length arguments
3024 are passed on the stack; if the callers forget to pass those arguments,
3025 attempting to tail call in such routines leads to stack corruption.
3026 Avoid tail calls in functions where at least one such hidden string
3027 length argument is passed (partially or fully) on the stack in the
3028 caller and the callee needs to pass any arguments on the stack.
3030 if (try_tail_call
&& maybe_ne (args_size
.constant
, 0))
3031 for (tree arg
= DECL_ARGUMENTS (current_function_decl
);
3032 arg
; arg
= DECL_CHAIN (arg
))
3033 if (DECL_HIDDEN_STRING_LENGTH (arg
) && DECL_INCOMING_RTL (arg
))
3035 subrtx_iterator::array_type array
;
3036 FOR_EACH_SUBRTX (iter
, array
, DECL_INCOMING_RTL (arg
), NONCONST
)
3044 /* If the user has marked the function as requiring tail-call
3045 optimization, attempt it. */
3049 /* Rest of purposes for tail call optimizations to fail. */
3051 try_tail_call
= can_implement_as_sibling_call_p (exp
,
3052 structure_value_addr
,
3055 flags
, addr
, args_size
);
3057 /* Check if caller and callee disagree in promotion of function
3061 machine_mode caller_mode
, caller_promoted_mode
;
3062 machine_mode callee_mode
, callee_promoted_mode
;
3063 int caller_unsignedp
, callee_unsignedp
;
3064 tree caller_res
= DECL_RESULT (current_function_decl
);
3066 caller_unsignedp
= TYPE_UNSIGNED (TREE_TYPE (caller_res
));
3067 caller_mode
= DECL_MODE (caller_res
);
3068 callee_unsignedp
= TYPE_UNSIGNED (TREE_TYPE (funtype
));
3069 callee_mode
= TYPE_MODE (TREE_TYPE (funtype
));
3070 caller_promoted_mode
3071 = promote_function_mode (TREE_TYPE (caller_res
), caller_mode
,
3073 TREE_TYPE (current_function_decl
), 1);
3074 callee_promoted_mode
3075 = promote_function_mode (TREE_TYPE (funtype
), callee_mode
,
3078 if (caller_mode
!= VOIDmode
3079 && (caller_promoted_mode
!= callee_promoted_mode
3080 || ((caller_mode
!= caller_promoted_mode
3081 || callee_mode
!= callee_promoted_mode
)
3082 && (caller_unsignedp
!= callee_unsignedp
3083 || partial_subreg_p (caller_mode
, callee_mode
)))))
3086 maybe_complain_about_tail_call (exp
,
3087 "caller and callee disagree in"
3088 " promotion of function"
3093 /* Ensure current function's preferred stack boundary is at least
3094 what we need. Stack alignment may also increase preferred stack
3096 for (i
= 0; i
< num_actuals
; i
++)
3097 if (reg_parm_stack_space
> 0
3099 || args
[i
].partial
!= 0
3100 || args
[i
].pass_on_stack
)
3101 update_stack_alignment_for_call (&args
[i
].locate
);
3102 if (crtl
->preferred_stack_boundary
< preferred_stack_boundary
)
3103 crtl
->preferred_stack_boundary
= preferred_stack_boundary
;
3105 preferred_stack_boundary
= crtl
->preferred_stack_boundary
;
3107 preferred_unit_stack_boundary
= preferred_stack_boundary
/ BITS_PER_UNIT
;
3109 if (flag_callgraph_info
)
3110 record_final_call (fndecl
, EXPR_LOCATION (exp
));
3112 /* We want to make two insn chains; one for a sibling call, the other
3113 for a normal call. We will select one of the two chains after
3114 initial RTL generation is complete. */
3115 for (pass
= try_tail_call
? 0 : 1; pass
< 2; pass
++)
3117 int sibcall_failure
= 0;
3118 bool normal_failure
= false;
3119 /* We want to emit any pending stack adjustments before the tail
3120 recursion "call". That way we know any adjustment after the tail
3121 recursion call can be ignored if we indeed use the tail
3123 saved_pending_stack_adjust save
;
3124 rtx_insn
*insns
, *before_call
, *after_args
;
3129 /* State variables we need to save and restore between
3131 save_pending_stack_adjust (&save
);
3134 flags
&= ~ECF_SIBCALL
;
3136 flags
|= ECF_SIBCALL
;
3138 /* Other state variables that we must reinitialize each time
3139 through the loop (that are not initialized by the loop itself). */
3143 /* Start a new sequence for the normal call case.
3145 From this point on, if the sibling call fails, we want to set
3146 sibcall_failure instead of continuing the loop. */
3149 /* Don't let pending stack adjusts add up to too much.
3150 Also, do all pending adjustments now if there is any chance
3151 this might be a call to alloca or if we are expanding a sibling
3153 Also do the adjustments before a throwing call, otherwise
3154 exception handling can fail; PR 19225. */
3155 if (maybe_ge (pending_stack_adjust
, 32)
3156 || (maybe_ne (pending_stack_adjust
, 0)
3157 && (flags
& ECF_MAY_BE_ALLOCA
))
3158 || (maybe_ne (pending_stack_adjust
, 0)
3159 && flag_exceptions
&& !(flags
& ECF_NOTHROW
))
3161 do_pending_stack_adjust ();
3163 /* Precompute any arguments as needed. */
3165 precompute_arguments (num_actuals
, args
);
3167 /* Now we are about to start emitting insns that can be deleted
3168 if a libcall is deleted. */
3169 if (pass
&& (flags
& ECF_MALLOC
))
3172 /* Check the canary value for sibcall or function which doesn't
3173 return and could throw. */
3175 || ((flags
& ECF_NORETURN
) != 0 && tree_could_throw_p (exp
)))
3176 && crtl
->stack_protect_guard
3177 && targetm
.stack_protect_runtime_enabled_p ())
3178 stack_protect_epilogue ();
3180 adjusted_args_size
= args_size
;
3181 /* Compute the actual size of the argument block required. The variable
3182 and constant sizes must be combined, the size may have to be rounded,
3183 and there may be a minimum required size. When generating a sibcall
3184 pattern, do not round up, since we'll be re-using whatever space our
3186 unadjusted_args_size
3187 = compute_argument_block_size (reg_parm_stack_space
,
3188 &adjusted_args_size
,
3191 : preferred_stack_boundary
));
3193 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
3195 /* The argument block when performing a sibling call is the
3196 incoming argument block. */
3199 argblock
= crtl
->args
.internal_arg_pointer
;
3200 if (STACK_GROWS_DOWNWARD
)
3202 = plus_constant (Pmode
, argblock
, crtl
->args
.pretend_args_size
);
3205 = plus_constant (Pmode
, argblock
, -crtl
->args
.pretend_args_size
);
3207 HOST_WIDE_INT map_size
= constant_lower_bound (args_size
.constant
);
3208 stored_args_map
= sbitmap_alloc (map_size
);
3209 bitmap_clear (stored_args_map
);
3210 stored_args_watermark
= HOST_WIDE_INT_M1U
;
3213 /* If we have no actual push instructions, or shouldn't use them,
3214 make space for all args right now. */
3215 else if (adjusted_args_size
.var
!= 0)
3217 if (old_stack_level
== 0)
3219 emit_stack_save (SAVE_BLOCK
, &old_stack_level
);
3220 old_stack_pointer_delta
= stack_pointer_delta
;
3221 old_pending_adj
= pending_stack_adjust
;
3222 pending_stack_adjust
= 0;
3223 /* stack_arg_under_construction says whether a stack arg is
3224 being constructed at the old stack level. Pushing the stack
3225 gets a clean outgoing argument block. */
3226 old_stack_arg_under_construction
= stack_arg_under_construction
;
3227 stack_arg_under_construction
= 0;
3229 argblock
= push_block (ARGS_SIZE_RTX (adjusted_args_size
), 0, 0);
3230 if (flag_stack_usage_info
)
3231 current_function_has_unbounded_dynamic_stack_size
= 1;
3235 /* Note that we must go through the motions of allocating an argument
3236 block even if the size is zero because we may be storing args
3237 in the area reserved for register arguments, which may be part of
3240 poly_int64 needed
= adjusted_args_size
.constant
;
3242 /* Store the maximum argument space used. It will be pushed by
3243 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
3246 crtl
->outgoing_args_size
= upper_bound (crtl
->outgoing_args_size
,
3249 if (must_preallocate
)
3251 if (ACCUMULATE_OUTGOING_ARGS
)
3253 /* Since the stack pointer will never be pushed, it is
3254 possible for the evaluation of a parm to clobber
3255 something we have already written to the stack.
3256 Since most function calls on RISC machines do not use
3257 the stack, this is uncommon, but must work correctly.
3259 Therefore, we save any area of the stack that was already
3260 written and that we are using. Here we set up to do this
3261 by making a new stack usage map from the old one. The
3262 actual save will be done by store_one_arg.
3264 Another approach might be to try to reorder the argument
3265 evaluations to avoid this conflicting stack usage. */
3267 /* Since we will be writing into the entire argument area,
3268 the map must be allocated for its entire size, not just
3269 the part that is the responsibility of the caller. */
3270 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
3271 needed
+= reg_parm_stack_space
;
3273 poly_int64 limit
= needed
;
3274 if (ARGS_GROW_DOWNWARD
)
3277 /* For polynomial sizes, this is the maximum possible
3278 size needed for arguments with a constant size
3280 HOST_WIDE_INT const_limit
= constant_lower_bound (limit
);
3281 highest_outgoing_arg_in_use
3282 = MAX (initial_highest_arg_in_use
, const_limit
);
3284 free (stack_usage_map_buf
);
3285 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
3286 stack_usage_map
= stack_usage_map_buf
;
3288 if (initial_highest_arg_in_use
)
3289 memcpy (stack_usage_map
, initial_stack_usage_map
,
3290 initial_highest_arg_in_use
);
3292 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
3293 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
3294 (highest_outgoing_arg_in_use
3295 - initial_highest_arg_in_use
));
3298 /* The address of the outgoing argument list must not be
3299 copied to a register here, because argblock would be left
3300 pointing to the wrong place after the call to
3301 allocate_dynamic_stack_space below. */
3303 argblock
= virtual_outgoing_args_rtx
;
3307 /* Try to reuse some or all of the pending_stack_adjust
3308 to get this space. */
3309 if (inhibit_defer_pop
== 0
3310 && (combine_pending_stack_adjustment_and_call
3312 unadjusted_args_size
,
3313 &adjusted_args_size
,
3314 preferred_unit_stack_boundary
)))
3316 /* combine_pending_stack_adjustment_and_call computes
3317 an adjustment before the arguments are allocated.
3318 Account for them and see whether or not the stack
3319 needs to go up or down. */
3320 needed
= unadjusted_args_size
- needed
;
3323 combine_pending_stack_adjustment_and_call. */
3324 gcc_checking_assert (ordered_p (needed
, 0));
3325 if (maybe_lt (needed
, 0))
3327 /* We're releasing stack space. */
3328 /* ??? We can avoid any adjustment at all if we're
3329 already aligned. FIXME. */
3330 pending_stack_adjust
= -needed
;
3331 do_pending_stack_adjust ();
3335 /* We need to allocate space. We'll do that in
3336 push_block below. */
3337 pending_stack_adjust
= 0;
3340 /* Special case this because overhead of `push_block' in
3341 this case is non-trivial. */
3342 if (known_eq (needed
, 0))
3343 argblock
= virtual_outgoing_args_rtx
;
3346 rtx needed_rtx
= gen_int_mode (needed
, Pmode
);
3347 argblock
= push_block (needed_rtx
, 0, 0);
3348 if (ARGS_GROW_DOWNWARD
)
3349 argblock
= plus_constant (Pmode
, argblock
, needed
);
3352 /* We only really need to call `copy_to_reg' in the case
3353 where push insns are going to be used to pass ARGBLOCK
3354 to a function call in ARGS. In that case, the stack
3355 pointer changes value from the allocation point to the
3356 call point, and hence the value of
3357 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
3358 as well always do it. */
3359 argblock
= copy_to_reg (argblock
);
3364 if (ACCUMULATE_OUTGOING_ARGS
)
3366 /* The save/restore code in store_one_arg handles all
3367 cases except one: a constructor call (including a C
3368 function returning a BLKmode struct) to initialize
3370 if (stack_arg_under_construction
)
3374 (adjusted_args_size
.constant
3375 + (OUTGOING_REG_PARM_STACK_SPACE (!fndecl
? fntype
3376 : TREE_TYPE (fndecl
))
3377 ? 0 : reg_parm_stack_space
), Pmode
));
3378 if (old_stack_level
== 0)
3380 emit_stack_save (SAVE_BLOCK
, &old_stack_level
);
3381 old_stack_pointer_delta
= stack_pointer_delta
;
3382 old_pending_adj
= pending_stack_adjust
;
3383 pending_stack_adjust
= 0;
3384 /* stack_arg_under_construction says whether a stack
3385 arg is being constructed at the old stack level.
3386 Pushing the stack gets a clean outgoing argument
3388 old_stack_arg_under_construction
3389 = stack_arg_under_construction
;
3390 stack_arg_under_construction
= 0;
3391 /* Make a new map for the new argument list. */
3392 free (stack_usage_map_buf
);
3393 stack_usage_map_buf
= XCNEWVEC (char, highest_outgoing_arg_in_use
);
3394 stack_usage_map
= stack_usage_map_buf
;
3395 highest_outgoing_arg_in_use
= 0;
3396 stack_usage_watermark
= HOST_WIDE_INT_M1U
;
3398 /* We can pass TRUE as the 4th argument because we just
3399 saved the stack pointer and will restore it right after
3401 allocate_dynamic_stack_space (push_size
, 0, BIGGEST_ALIGNMENT
,
3405 /* If argument evaluation might modify the stack pointer,
3406 copy the address of the argument list to a register. */
3407 for (i
= 0; i
< num_actuals
; i
++)
3408 if (args
[i
].pass_on_stack
)
3410 argblock
= copy_addr_to_reg (argblock
);
3415 compute_argument_addresses (args
, argblock
, num_actuals
);
3417 /* Stack is properly aligned, pops can't safely be deferred during
3418 the evaluation of the arguments. */
3421 /* Precompute all register parameters. It isn't safe to compute
3422 anything once we have started filling any specific hard regs.
3423 TLS symbols sometimes need a call to resolve. Precompute
3424 register parameters before any stack pointer manipulation
3425 to avoid unaligned stack in the called function. */
3426 precompute_register_parameters (num_actuals
, args
, ®_parm_seen
);
3430 /* Perform stack alignment before the first push (the last arg). */
3432 && maybe_gt (adjusted_args_size
.constant
, reg_parm_stack_space
)
3433 && maybe_ne (adjusted_args_size
.constant
, unadjusted_args_size
))
3435 /* When the stack adjustment is pending, we get better code
3436 by combining the adjustments. */
3437 if (maybe_ne (pending_stack_adjust
, 0)
3438 && ! inhibit_defer_pop
3439 && (combine_pending_stack_adjustment_and_call
3440 (&pending_stack_adjust
,
3441 unadjusted_args_size
,
3442 &adjusted_args_size
,
3443 preferred_unit_stack_boundary
)))
3444 do_pending_stack_adjust ();
3445 else if (argblock
== 0)
3446 anti_adjust_stack (gen_int_mode (adjusted_args_size
.constant
3447 - unadjusted_args_size
,
3450 /* Now that the stack is properly aligned, pops can't safely
3451 be deferred during the evaluation of the arguments. */
3454 /* Record the maximum pushed stack space size. We need to delay
3455 doing it this far to take into account the optimization done
3456 by combine_pending_stack_adjustment_and_call. */
3457 if (flag_stack_usage_info
3458 && !ACCUMULATE_OUTGOING_ARGS
3460 && adjusted_args_size
.var
== 0)
3462 poly_int64 pushed
= (adjusted_args_size
.constant
3463 + pending_stack_adjust
);
3464 current_function_pushed_stack_size
3465 = upper_bound (current_function_pushed_stack_size
, pushed
);
3468 funexp
= rtx_for_function_call (fndecl
, addr
);
3470 if (CALL_EXPR_STATIC_CHAIN (exp
))
3471 static_chain_value
= expand_normal (CALL_EXPR_STATIC_CHAIN (exp
));
3473 static_chain_value
= 0;
3475 #ifdef REG_PARM_STACK_SPACE
3476 /* Save the fixed argument area if it's part of the caller's frame and
3477 is clobbered by argument setup for this call. */
3478 if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
3479 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
3480 &low_to_save
, &high_to_save
);
3483 /* Now store (and compute if necessary) all non-register parms.
3484 These come before register parms, since they can require block-moves,
3485 which could clobber the registers used for register parms.
3486 Parms which have partial registers are not stored here,
3487 but we do preallocate space here if they want that. */
3489 for (i
= 0; i
< num_actuals
; i
++)
3491 if (args
[i
].reg
== 0 || args
[i
].pass_on_stack
)
3493 rtx_insn
*before_arg
= get_last_insn ();
3495 /* We don't allow passing huge (> 2^30 B) arguments
3496 by value. It would cause an overflow later on. */
3497 if (constant_lower_bound (adjusted_args_size
.constant
)
3498 >= (1 << (HOST_BITS_PER_INT
- 2)))
3500 sorry ("passing too large argument on stack");
3501 /* Don't worry about stack clean-up. */
3503 sibcall_failure
= 1;
3505 normal_failure
= true;
3509 if (store_one_arg (&args
[i
], argblock
, flags
,
3510 adjusted_args_size
.var
!= 0,
3511 reg_parm_stack_space
)
3513 && check_sibcall_argument_overlap (before_arg
,
3515 sibcall_failure
= 1;
3520 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)),
3521 gen_rtx_USE (VOIDmode
, args
[i
].stack
),
3525 /* If we have a parm that is passed in registers but not in memory
3526 and whose alignment does not permit a direct copy into registers,
3527 make a group of pseudos that correspond to each register that we
3529 if (STRICT_ALIGNMENT
)
3530 store_unaligned_arguments_into_pseudos (args
, num_actuals
);
3532 /* Now store any partially-in-registers parm.
3533 This is the last place a block-move can happen. */
3535 for (i
= 0; i
< num_actuals
; i
++)
3536 if (args
[i
].partial
!= 0 && ! args
[i
].pass_on_stack
)
3538 rtx_insn
*before_arg
= get_last_insn ();
3540 /* On targets with weird calling conventions (e.g. PA) it's
3541 hard to ensure that all cases of argument overlap between
3542 stack and registers work. Play it safe and bail out. */
3543 if (ARGS_GROW_DOWNWARD
&& !STACK_GROWS_DOWNWARD
)
3545 sibcall_failure
= 1;
3549 if (store_one_arg (&args
[i
], argblock
, flags
,
3550 adjusted_args_size
.var
!= 0,
3551 reg_parm_stack_space
)
3553 && check_sibcall_argument_overlap (before_arg
,
3555 sibcall_failure
= 1;
3558 bool any_regs
= false;
3559 for (i
= 0; i
< num_actuals
; i
++)
3560 if (args
[i
].reg
!= NULL_RTX
)
3563 targetm
.calls
.call_args (args
[i
].reg
, funtype
);
3566 targetm
.calls
.call_args (pc_rtx
, funtype
);
3568 /* Figure out the register where the value, if any, will come back. */
3570 if (TYPE_MODE (rettype
) != VOIDmode
3571 && ! structure_value_addr
)
3573 if (pcc_struct_value
)
3574 valreg
= hard_function_value (build_pointer_type (rettype
),
3575 fndecl
, NULL
, (pass
== 0));
3577 valreg
= hard_function_value (rettype
, fndecl
, fntype
,
3580 /* If VALREG is a PARALLEL whose first member has a zero
3581 offset, use that. This is for targets such as m68k that
3582 return the same value in multiple places. */
3583 if (GET_CODE (valreg
) == PARALLEL
)
3585 rtx elem
= XVECEXP (valreg
, 0, 0);
3586 rtx where
= XEXP (elem
, 0);
3587 rtx offset
= XEXP (elem
, 1);
3588 if (offset
== const0_rtx
3589 && GET_MODE (where
) == GET_MODE (valreg
))
3594 /* If register arguments require space on the stack and stack space
3595 was not preallocated, allocate stack space here for arguments
3596 passed in registers. */
3597 if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
)))
3598 && !ACCUMULATE_OUTGOING_ARGS
3599 && must_preallocate
== 0 && reg_parm_stack_space
> 0)
3600 anti_adjust_stack (GEN_INT (reg_parm_stack_space
));
3602 /* Pass the function the address in which to return a
3604 if (pass
!= 0 && structure_value_addr
&& ! structure_value_addr_parm
)
3606 structure_value_addr
3607 = convert_memory_address (Pmode
, structure_value_addr
);
3608 emit_move_insn (struct_value
,
3610 force_operand (structure_value_addr
,
3613 if (REG_P (struct_value
))
3614 use_reg (&call_fusage
, struct_value
);
3617 after_args
= get_last_insn ();
3618 funexp
= prepare_call_address (fndecl
? fndecl
: fntype
, funexp
,
3619 static_chain_value
, &call_fusage
,
3620 reg_parm_seen
, flags
);
3622 load_register_parameters (args
, num_actuals
, &call_fusage
, flags
,
3623 pass
== 0, &sibcall_failure
);
3625 /* Save a pointer to the last insn before the call, so that we can
3626 later safely search backwards to find the CALL_INSN. */
3627 before_call
= get_last_insn ();
3629 /* Set up next argument register. For sibling calls on machines
3630 with register windows this should be the incoming register. */
3632 next_arg_reg
= targetm
.calls
.function_incoming_arg
3633 (args_so_far
, function_arg_info::end_marker ());
3635 next_arg_reg
= targetm
.calls
.function_arg
3636 (args_so_far
, function_arg_info::end_marker ());
3638 if (pass
== 1 && (return_flags
& ERF_RETURNS_ARG
))
3640 int arg_nr
= return_flags
& ERF_RETURN_ARG_MASK
;
3641 arg_nr
= num_actuals
- arg_nr
- 1;
3643 && arg_nr
< num_actuals
3647 && GET_MODE (args
[arg_nr
].reg
) == GET_MODE (valreg
))
3649 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args
[arg_nr
].tree_value
)),
3650 gen_rtx_SET (valreg
, args
[arg_nr
].reg
),
3653 /* All arguments and registers used for the call must be set up by
3656 /* Stack must be properly aligned now. */
3658 || multiple_p (stack_pointer_delta
,
3659 preferred_unit_stack_boundary
));
3661 /* Generate the actual call instruction. */
3662 emit_call_1 (funexp
, exp
, fndecl
, funtype
, unadjusted_args_size
,
3663 adjusted_args_size
.constant
, struct_value_size
,
3664 next_arg_reg
, valreg
, old_inhibit_defer_pop
, call_fusage
,
3665 flags
, args_so_far
);
3669 rtx_call_insn
*last
;
3670 rtx datum
= NULL_RTX
;
3671 if (fndecl
!= NULL_TREE
)
3673 datum
= XEXP (DECL_RTL (fndecl
), 0);
3674 gcc_assert (datum
!= NULL_RTX
3675 && GET_CODE (datum
) == SYMBOL_REF
);
3677 last
= last_call_insn ();
3678 add_reg_note (last
, REG_CALL_DECL
, datum
);
3681 /* If the call setup or the call itself overlaps with anything
3682 of the argument setup we probably clobbered our call address.
3683 In that case we can't do sibcalls. */
3685 && check_sibcall_argument_overlap (after_args
, 0, 0))
3686 sibcall_failure
= 1;
3688 /* If a non-BLKmode value is returned at the most significant end
3689 of a register, shift the register right by the appropriate amount
3690 and update VALREG accordingly. BLKmode values are handled by the
3691 group load/store machinery below. */
3692 if (!structure_value_addr
3693 && !pcc_struct_value
3694 && TYPE_MODE (rettype
) != VOIDmode
3695 && TYPE_MODE (rettype
) != BLKmode
3697 && targetm
.calls
.return_in_msb (rettype
))
3699 if (shift_return_value (TYPE_MODE (rettype
), false, valreg
))
3700 sibcall_failure
= 1;
3701 valreg
= gen_rtx_REG (TYPE_MODE (rettype
), REGNO (valreg
));
3704 if (pass
&& (flags
& ECF_MALLOC
))
3706 rtx temp
= gen_reg_rtx (GET_MODE (valreg
));
3707 rtx_insn
*last
, *insns
;
3709 /* The return value from a malloc-like function is a pointer. */
3710 if (TREE_CODE (rettype
) == POINTER_TYPE
)
3711 mark_reg_pointer (temp
, MALLOC_ABI_ALIGNMENT
);
3713 emit_move_insn (temp
, valreg
);
3715 /* The return value from a malloc-like function cannot alias
3717 last
= get_last_insn ();
3718 add_reg_note (last
, REG_NOALIAS
, temp
);
3720 /* Write out the sequence. */
3721 insns
= get_insns ();
3727 /* For calls to `setjmp', etc., inform
3728 function.cc:setjmp_warnings that it should complain if
3729 nonvolatile values are live. For functions that cannot
3730 return, inform flow that control does not fall through. */
3732 if ((flags
& ECF_NORETURN
) || pass
== 0)
3734 /* The barrier must be emitted
3735 immediately after the CALL_INSN. Some ports emit more
3736 than just a CALL_INSN above, so we must search for it here. */
3738 rtx_insn
*last
= get_last_insn ();
3739 while (!CALL_P (last
))
3741 last
= PREV_INSN (last
);
3742 /* There was no CALL_INSN? */
3743 gcc_assert (last
!= before_call
);
3746 emit_barrier_after (last
);
3748 /* Stack adjustments after a noreturn call are dead code.
3749 However when NO_DEFER_POP is in effect, we must preserve
3750 stack_pointer_delta. */
3751 if (inhibit_defer_pop
== 0)
3753 stack_pointer_delta
= old_stack_allocated
;
3754 pending_stack_adjust
= 0;
3758 /* If value type not void, return an rtx for the value. */
3760 if (TYPE_MODE (rettype
) == VOIDmode
3762 target
= const0_rtx
;
3763 else if (structure_value_addr
)
3765 if (target
== 0 || !MEM_P (target
))
3768 = gen_rtx_MEM (TYPE_MODE (rettype
),
3769 memory_address (TYPE_MODE (rettype
),
3770 structure_value_addr
));
3771 set_mem_attributes (target
, rettype
, 1);
3774 else if (pcc_struct_value
)
3776 /* This is the special C++ case where we need to
3777 know what the true target was. We take care to
3778 never use this value more than once in one expression. */
3779 target
= gen_rtx_MEM (TYPE_MODE (rettype
),
3780 copy_to_reg (valreg
));
3781 set_mem_attributes (target
, rettype
, 1);
3783 /* Handle calls that return values in multiple non-contiguous locations.
3784 The Irix 6 ABI has examples of this. */
3785 else if (GET_CODE (valreg
) == PARALLEL
)
3788 target
= emit_group_move_into_temps (valreg
);
3789 else if (rtx_equal_p (target
, valreg
))
3791 else if (GET_CODE (target
) == PARALLEL
)
3792 /* Handle the result of a emit_group_move_into_temps
3793 call in the previous pass. */
3794 emit_group_move (target
, valreg
);
3796 emit_group_store (target
, valreg
, rettype
,
3797 int_size_in_bytes (rettype
));
3800 && GET_MODE (target
) == TYPE_MODE (rettype
)
3801 && GET_MODE (target
) == GET_MODE (valreg
))
3803 bool may_overlap
= false;
3805 /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
3806 reg to a plain register. */
3807 if (!REG_P (target
) || HARD_REGISTER_P (target
))
3808 valreg
= avoid_likely_spilled_reg (valreg
);
3810 /* If TARGET is a MEM in the argument area, and we have
3811 saved part of the argument area, then we can't store
3812 directly into TARGET as it may get overwritten when we
3813 restore the argument save area below. Don't work too
3814 hard though and simply force TARGET to a register if it
3815 is a MEM; the optimizer is quite likely to sort it out. */
3816 if (ACCUMULATE_OUTGOING_ARGS
&& pass
&& MEM_P (target
))
3817 for (i
= 0; i
< num_actuals
; i
++)
3818 if (args
[i
].save_area
)
3825 target
= copy_to_reg (valreg
);
3828 /* TARGET and VALREG cannot be equal at this point
3829 because the latter would not have
3830 REG_FUNCTION_VALUE_P true, while the former would if
3831 it were referring to the same register.
3833 If they refer to the same register, this move will be
3834 a no-op, except when function inlining is being
3836 emit_move_insn (target
, valreg
);
3838 /* If we are setting a MEM, this code must be executed.
3839 Since it is emitted after the call insn, sibcall
3840 optimization cannot be performed in that case. */
3842 sibcall_failure
= 1;
3846 target
= copy_to_reg (avoid_likely_spilled_reg (valreg
));
3848 /* If we promoted this return value, make the proper SUBREG.
3849 TARGET might be const0_rtx here, so be careful. */
3851 && TYPE_MODE (rettype
) != BLKmode
3852 && GET_MODE (target
) != TYPE_MODE (rettype
))
3854 tree type
= rettype
;
3855 int unsignedp
= TYPE_UNSIGNED (type
);
3856 machine_mode ret_mode
= TYPE_MODE (type
);
3859 /* Ensure we promote as expected, and get the new unsignedness. */
3860 pmode
= promote_function_mode (type
, ret_mode
, &unsignedp
,
3862 gcc_assert (GET_MODE (target
) == pmode
);
3864 if (SCALAR_INT_MODE_P (pmode
)
3865 && SCALAR_FLOAT_MODE_P (ret_mode
)
3866 && known_gt (GET_MODE_SIZE (pmode
), GET_MODE_SIZE (ret_mode
)))
3867 target
= convert_wider_int_to_float (ret_mode
, pmode
, target
);
3870 target
= gen_lowpart_SUBREG (ret_mode
, target
);
3871 SUBREG_PROMOTED_VAR_P (target
) = 1;
3872 SUBREG_PROMOTED_SET (target
, unsignedp
);
3876 /* If size of args is variable or this was a constructor call for a stack
3877 argument, restore saved stack-pointer value. */
3879 if (old_stack_level
)
3881 rtx_insn
*prev
= get_last_insn ();
3883 emit_stack_restore (SAVE_BLOCK
, old_stack_level
);
3884 stack_pointer_delta
= old_stack_pointer_delta
;
3886 fixup_args_size_notes (prev
, get_last_insn (), stack_pointer_delta
);
3888 pending_stack_adjust
= old_pending_adj
;
3889 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
3890 stack_arg_under_construction
= old_stack_arg_under_construction
;
3891 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3892 stack_usage_map
= initial_stack_usage_map
;
3893 stack_usage_watermark
= initial_stack_usage_watermark
;
3894 sibcall_failure
= 1;
3896 else if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
3898 #ifdef REG_PARM_STACK_SPACE
3900 restore_fixed_argument_area (save_area
, argblock
,
3901 high_to_save
, low_to_save
);
3904 /* If we saved any argument areas, restore them. */
3905 for (i
= 0; i
< num_actuals
; i
++)
3906 if (args
[i
].save_area
)
3908 machine_mode save_mode
= GET_MODE (args
[i
].save_area
);
3910 = gen_rtx_MEM (save_mode
,
3911 memory_address (save_mode
,
3912 XEXP (args
[i
].stack_slot
, 0)));
3914 if (save_mode
!= BLKmode
)
3915 emit_move_insn (stack_area
, args
[i
].save_area
);
3917 emit_block_move (stack_area
, args
[i
].save_area
,
3919 (args
[i
].locate
.size
.constant
, Pmode
)),
3920 BLOCK_OP_CALL_PARM
);
3923 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3924 stack_usage_map
= initial_stack_usage_map
;
3925 stack_usage_watermark
= initial_stack_usage_watermark
;
3928 /* If this was alloca, record the new stack level. */
3929 if (flags
& ECF_MAY_BE_ALLOCA
)
3930 record_new_stack_level ();
3932 /* Free up storage we no longer need. */
3933 for (i
= 0; i
< num_actuals
; ++i
)
3934 free (args
[i
].aligned_regs
);
3936 targetm
.calls
.end_call_args ();
3938 insns
= get_insns ();
3943 tail_call_insns
= insns
;
3945 /* Restore the pending stack adjustment now that we have
3946 finished generating the sibling call sequence. */
3948 restore_pending_stack_adjust (&save
);
3950 /* Prepare arg structure for next iteration. */
3951 for (i
= 0; i
< num_actuals
; i
++)
3954 args
[i
].aligned_regs
= 0;
3958 sbitmap_free (stored_args_map
);
3959 internal_arg_pointer_exp_state
.scan_start
= NULL
;
3960 internal_arg_pointer_exp_state
.cache
.release ();
3964 normal_call_insns
= insns
;
3966 /* Verify that we've deallocated all the stack we used. */
3967 gcc_assert ((flags
& ECF_NORETURN
)
3969 || known_eq (old_stack_allocated
,
3971 - pending_stack_adjust
));
3973 normal_call_insns
= NULL
;
3976 /* If something prevents making this a sibling call,
3977 zero out the sequence. */
3978 if (sibcall_failure
)
3979 tail_call_insns
= NULL
;
3984 /* If tail call production succeeded, we need to remove REG_EQUIV notes on
3985 arguments too, as argument area is now clobbered by the call. */
3986 if (tail_call_insns
)
3988 emit_insn (tail_call_insns
);
3989 crtl
->tail_call_emit
= true;
3993 emit_insn (normal_call_insns
);
3995 /* Ideally we'd emit a message for all of the ways that it could
3997 maybe_complain_about_tail_call (exp
, "tail call production failed");
4000 currently_expanding_call
--;
4002 free (stack_usage_map_buf
);
4007 /* A sibling call sequence invalidates any REG_EQUIV notes made for
4008 this function's incoming arguments.
4010 At the start of RTL generation we know the only REG_EQUIV notes
4011 in the rtl chain are those for incoming arguments, so we can look
4012 for REG_EQUIV notes between the start of the function and the
4013 NOTE_INSN_FUNCTION_BEG.
4015 This is (slight) overkill. We could keep track of the highest
4016 argument we clobber and be more selective in removing notes, but it
4017 does not seem to be worth the effort. */
4020 fixup_tail_calls (void)
4024 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4028 /* There are never REG_EQUIV notes for the incoming arguments
4029 after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
4031 && NOTE_KIND (insn
) == NOTE_INSN_FUNCTION_BEG
)
4034 note
= find_reg_note (insn
, REG_EQUIV
, 0);
4036 remove_note (insn
, note
);
4037 note
= find_reg_note (insn
, REG_EQUIV
, 0);
4042 /* Traverse a list of TYPES and expand all complex types into their
4045 split_complex_types (tree types
)
4049 /* Before allocating memory, check for the common case of no complex. */
4050 for (p
= types
; p
; p
= TREE_CHAIN (p
))
4052 tree type
= TREE_VALUE (p
);
4053 if (TREE_CODE (type
) == COMPLEX_TYPE
4054 && targetm
.calls
.split_complex_arg (type
))
4060 types
= copy_list (types
);
4062 for (p
= types
; p
; p
= TREE_CHAIN (p
))
4064 tree complex_type
= TREE_VALUE (p
);
4066 if (TREE_CODE (complex_type
) == COMPLEX_TYPE
4067 && targetm
.calls
.split_complex_arg (complex_type
))
4071 /* Rewrite complex type with component type. */
4072 TREE_VALUE (p
) = TREE_TYPE (complex_type
);
4073 next
= TREE_CHAIN (p
);
4075 /* Add another component type for the imaginary part. */
4076 imag
= build_tree_list (NULL_TREE
, TREE_VALUE (p
));
4077 TREE_CHAIN (p
) = imag
;
4078 TREE_CHAIN (imag
) = next
;
4080 /* Skip the newly created node. */
4088 /* Output a library call to function ORGFUN (a SYMBOL_REF rtx)
4089 for a value of mode OUTMODE,
4090 with NARGS different arguments, passed as ARGS.
4091 Store the return value if RETVAL is nonzero: store it in VALUE if
4092 VALUE is nonnull, otherwise pick a convenient location. In either
4093 case return the location of the stored value.
4095 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for
4096 `const' calls, LCT_PURE for `pure' calls, or another LCT_ value for
4097 other types of library calls. */
4100 emit_library_call_value_1 (int retval
, rtx orgfun
, rtx value
,
4101 enum libcall_type fn_type
,
4102 machine_mode outmode
, int nargs
, rtx_mode_t
*args
)
4104 /* Total size in bytes of all the stack-parms scanned so far. */
4105 struct args_size args_size
;
4106 /* Size of arguments before any adjustments (such as rounding). */
4107 struct args_size original_args_size
;
4110 /* Todo, choose the correct decl type of orgfun. Sadly this information
4111 isn't present here, so we default to native calling abi here. */
4112 tree fndecl ATTRIBUTE_UNUSED
= NULL_TREE
; /* library calls default to host calling abi ? */
4113 tree fntype ATTRIBUTE_UNUSED
= NULL_TREE
; /* library calls default to host calling abi ? */
4116 CUMULATIVE_ARGS args_so_far_v
;
4117 cumulative_args_t args_so_far
;
4124 struct locate_and_pad_arg_data locate
;
4128 int old_inhibit_defer_pop
= inhibit_defer_pop
;
4129 rtx call_fusage
= 0;
4132 int pcc_struct_value
= 0;
4133 poly_int64 struct_value_size
= 0;
4135 int reg_parm_stack_space
= 0;
4137 rtx_insn
*before_call
;
4138 bool have_push_fusage
;
4139 tree tfom
; /* type_for_mode (outmode, 0) */
4141 #ifdef REG_PARM_STACK_SPACE
4142 /* Define the boundary of the register parm stack space that needs to be
4144 int low_to_save
= 0, high_to_save
= 0;
4145 rtx save_area
= 0; /* Place that it is saved. */
4148 /* Size of the stack reserved for parameter registers. */
4149 unsigned int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
4150 char *initial_stack_usage_map
= stack_usage_map
;
4151 unsigned HOST_WIDE_INT initial_stack_usage_watermark
= stack_usage_watermark
;
4152 char *stack_usage_map_buf
= NULL
;
4154 rtx struct_value
= targetm
.calls
.struct_value_rtx (0, 0);
4156 #ifdef REG_PARM_STACK_SPACE
4157 reg_parm_stack_space
= REG_PARM_STACK_SPACE ((tree
) 0);
4160 /* By default, library functions cannot throw. */
4161 flags
= ECF_NOTHROW
;
4174 flags
|= ECF_NORETURN
;
4177 flags
&= ~ECF_NOTHROW
;
4179 case LCT_RETURNS_TWICE
:
4180 flags
= ECF_RETURNS_TWICE
;
4185 /* Ensure current function's preferred stack boundary is at least
4187 if (crtl
->preferred_stack_boundary
< PREFERRED_STACK_BOUNDARY
)
4188 crtl
->preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
4190 /* If this kind of value comes back in memory,
4191 decide where in memory it should come back. */
4192 if (outmode
!= VOIDmode
)
4194 tfom
= lang_hooks
.types
.type_for_mode (outmode
, 0);
4195 if (aggregate_value_p (tfom
, 0))
4197 #ifdef PCC_STATIC_STRUCT_RETURN
4199 = hard_function_value (build_pointer_type (tfom
), 0, 0, 0);
4200 mem_value
= gen_rtx_MEM (outmode
, pointer_reg
);
4201 pcc_struct_value
= 1;
4203 value
= gen_reg_rtx (outmode
);
4204 #else /* not PCC_STATIC_STRUCT_RETURN */
4205 struct_value_size
= GET_MODE_SIZE (outmode
);
4206 if (value
!= 0 && MEM_P (value
))
4209 mem_value
= assign_temp (tfom
, 1, 1);
4211 /* This call returns a big structure. */
4212 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
4216 tfom
= void_type_node
;
4218 /* ??? Unfinished: must pass the memory address as an argument. */
4220 /* Copy all the libcall-arguments out of the varargs data
4221 and into a vector ARGVEC.
4223 Compute how to pass each argument. We only support a very small subset
4224 of the full argument passing conventions to limit complexity here since
4225 library functions shouldn't have many args. */
4227 argvec
= XALLOCAVEC (struct arg
, nargs
+ 1);
4228 memset (argvec
, 0, (nargs
+ 1) * sizeof (struct arg
));
4230 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
4231 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v
, outmode
, fun
);
4233 INIT_CUMULATIVE_ARGS (args_so_far_v
, NULL_TREE
, fun
, 0, nargs
);
4235 args_so_far
= pack_cumulative_args (&args_so_far_v
);
4237 args_size
.constant
= 0;
4244 /* If there's a structure value address to be passed,
4245 either pass it in the special place, or pass it as an extra argument. */
4246 if (mem_value
&& struct_value
== 0 && ! pcc_struct_value
)
4248 rtx addr
= XEXP (mem_value
, 0);
4252 /* Make sure it is a reasonable operand for a move or push insn. */
4253 if (!REG_P (addr
) && !MEM_P (addr
)
4254 && !(CONSTANT_P (addr
)
4255 && targetm
.legitimate_constant_p (Pmode
, addr
)))
4256 addr
= force_operand (addr
, NULL_RTX
);
4258 argvec
[count
].value
= addr
;
4259 argvec
[count
].mode
= Pmode
;
4260 argvec
[count
].partial
= 0;
4262 function_arg_info
ptr_arg (Pmode
, /*named=*/true);
4263 argvec
[count
].reg
= targetm
.calls
.function_arg (args_so_far
, ptr_arg
);
4264 gcc_assert (targetm
.calls
.arg_partial_bytes (args_so_far
, ptr_arg
) == 0);
4266 locate_and_pad_parm (Pmode
, NULL_TREE
,
4267 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4270 argvec
[count
].reg
!= 0,
4272 reg_parm_stack_space
, 0,
4273 NULL_TREE
, &args_size
, &argvec
[count
].locate
);
4275 if (argvec
[count
].reg
== 0 || argvec
[count
].partial
!= 0
4276 || reg_parm_stack_space
> 0)
4277 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
4279 targetm
.calls
.function_arg_advance (args_so_far
, ptr_arg
);
4284 for (unsigned int i
= 0; count
< nargs
; i
++, count
++)
4286 rtx val
= args
[i
].first
;
4287 function_arg_info
arg (args
[i
].second
, /*named=*/true);
4290 /* We cannot convert the arg value to the mode the library wants here;
4291 must do it earlier where we know the signedness of the arg. */
4292 gcc_assert (arg
.mode
!= BLKmode
4293 && (GET_MODE (val
) == arg
.mode
4294 || GET_MODE (val
) == VOIDmode
));
4296 /* Make sure it is a reasonable operand for a move or push insn. */
4297 if (!REG_P (val
) && !MEM_P (val
)
4298 && !(CONSTANT_P (val
)
4299 && targetm
.legitimate_constant_p (arg
.mode
, val
)))
4300 val
= force_operand (val
, NULL_RTX
);
4302 if (pass_by_reference (&args_so_far_v
, arg
))
4305 int must_copy
= !reference_callee_copied (&args_so_far_v
, arg
);
4307 /* If this was a CONST function, it is now PURE since it now
4309 if (flags
& ECF_CONST
)
4311 flags
&= ~ECF_CONST
;
4315 if (MEM_P (val
) && !must_copy
)
4317 tree val_expr
= MEM_EXPR (val
);
4319 mark_addressable (val_expr
);
4324 slot
= assign_temp (lang_hooks
.types
.type_for_mode (arg
.mode
, 0),
4326 emit_move_insn (slot
, val
);
4329 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
4330 gen_rtx_USE (VOIDmode
, slot
),
4333 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
4334 gen_rtx_CLOBBER (VOIDmode
,
4339 arg
.pass_by_reference
= true;
4340 val
= force_operand (XEXP (slot
, 0), NULL_RTX
);
4343 arg
.mode
= promote_function_mode (NULL_TREE
, arg
.mode
, &unsigned_p
,
4345 argvec
[count
].mode
= arg
.mode
;
4346 argvec
[count
].value
= convert_modes (arg
.mode
, GET_MODE (val
), val
,
4348 argvec
[count
].reg
= targetm
.calls
.function_arg (args_so_far
, arg
);
4350 argvec
[count
].partial
4351 = targetm
.calls
.arg_partial_bytes (args_so_far
, arg
);
4353 if (argvec
[count
].reg
== 0
4354 || argvec
[count
].partial
!= 0
4355 || reg_parm_stack_space
> 0)
4357 locate_and_pad_parm (arg
.mode
, NULL_TREE
,
4358 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4361 argvec
[count
].reg
!= 0,
4363 reg_parm_stack_space
, argvec
[count
].partial
,
4364 NULL_TREE
, &args_size
, &argvec
[count
].locate
);
4365 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
4366 gcc_assert (!argvec
[count
].locate
.size
.var
);
4368 #ifdef BLOCK_REG_PADDING
4370 /* The argument is passed entirely in registers. See at which
4371 end it should be padded. */
4372 argvec
[count
].locate
.where_pad
=
4373 BLOCK_REG_PADDING (arg
.mode
, NULL_TREE
,
4374 known_le (GET_MODE_SIZE (arg
.mode
),
4378 targetm
.calls
.function_arg_advance (args_so_far
, arg
);
4381 for (int i
= 0; i
< nargs
; i
++)
4382 if (reg_parm_stack_space
> 0
4383 || argvec
[i
].reg
== 0
4384 || argvec
[i
].partial
!= 0)
4385 update_stack_alignment_for_call (&argvec
[i
].locate
);
4387 /* If this machine requires an external definition for library
4388 functions, write one out. */
4389 assemble_external_libcall (fun
);
4391 original_args_size
= args_size
;
4392 args_size
.constant
= (aligned_upper_bound (args_size
.constant
4393 + stack_pointer_delta
,
4395 - stack_pointer_delta
);
4397 args_size
.constant
= upper_bound (args_size
.constant
,
4398 reg_parm_stack_space
);
4400 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
4401 args_size
.constant
-= reg_parm_stack_space
;
4403 crtl
->outgoing_args_size
= upper_bound (crtl
->outgoing_args_size
,
4404 args_size
.constant
);
4406 if (flag_stack_usage_info
&& !ACCUMULATE_OUTGOING_ARGS
)
4408 poly_int64 pushed
= args_size
.constant
+ pending_stack_adjust
;
4409 current_function_pushed_stack_size
4410 = upper_bound (current_function_pushed_stack_size
, pushed
);
4413 if (ACCUMULATE_OUTGOING_ARGS
)
4415 /* Since the stack pointer will never be pushed, it is possible for
4416 the evaluation of a parm to clobber something we have already
4417 written to the stack. Since most function calls on RISC machines
4418 do not use the stack, this is uncommon, but must work correctly.
4420 Therefore, we save any area of the stack that was already written
4421 and that we are using. Here we set up to do this by making a new
4422 stack usage map from the old one.
4424 Another approach might be to try to reorder the argument
4425 evaluations to avoid this conflicting stack usage. */
4427 needed
= args_size
.constant
;
4429 /* Since we will be writing into the entire argument area, the
4430 map must be allocated for its entire size, not just the part that
4431 is the responsibility of the caller. */
4432 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
4433 needed
+= reg_parm_stack_space
;
4435 poly_int64 limit
= needed
;
4436 if (ARGS_GROW_DOWNWARD
)
4439 /* For polynomial sizes, this is the maximum possible size needed
4440 for arguments with a constant size and offset. */
4441 HOST_WIDE_INT const_limit
= constant_lower_bound (limit
);
4442 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
4445 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
4446 stack_usage_map
= stack_usage_map_buf
;
4448 if (initial_highest_arg_in_use
)
4449 memcpy (stack_usage_map
, initial_stack_usage_map
,
4450 initial_highest_arg_in_use
);
4452 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
4453 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
4454 highest_outgoing_arg_in_use
- initial_highest_arg_in_use
);
4457 /* We must be careful to use virtual regs before they're instantiated,
4458 and real regs afterwards. Loop optimization, for example, can create
4459 new libcalls after we've instantiated the virtual regs, and if we
4460 use virtuals anyway, they won't match the rtl patterns. */
4462 if (virtuals_instantiated
)
4463 argblock
= plus_constant (Pmode
, stack_pointer_rtx
,
4464 STACK_POINTER_OFFSET
);
4466 argblock
= virtual_outgoing_args_rtx
;
4470 if (!targetm
.calls
.push_argument (0))
4471 argblock
= push_block (gen_int_mode (args_size
.constant
, Pmode
), 0, 0);
4474 /* We push args individually in reverse order, perform stack alignment
4475 before the first push (the last arg). */
4477 anti_adjust_stack (gen_int_mode (args_size
.constant
4478 - original_args_size
.constant
,
4483 #ifdef REG_PARM_STACK_SPACE
4484 if (ACCUMULATE_OUTGOING_ARGS
)
4486 /* The argument list is the property of the called routine and it
4487 may clobber it. If the fixed area has been used for previous
4488 parameters, we must save and restore it. */
4489 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
4490 &low_to_save
, &high_to_save
);
4494 /* When expanding a normal call, args are stored in push order,
4495 which is the reverse of what we have here. */
4496 bool any_regs
= false;
4497 for (int i
= nargs
; i
-- > 0; )
4498 if (argvec
[i
].reg
!= NULL_RTX
)
4500 targetm
.calls
.call_args (argvec
[i
].reg
, NULL_TREE
);
4504 targetm
.calls
.call_args (pc_rtx
, NULL_TREE
);
4506 /* Push the args that need to be pushed. */
4508 have_push_fusage
= false;
4510 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4511 are to be pushed. */
4512 for (count
= 0; count
< nargs
; count
++, argnum
--)
4514 machine_mode mode
= argvec
[argnum
].mode
;
4515 rtx val
= argvec
[argnum
].value
;
4516 rtx reg
= argvec
[argnum
].reg
;
4517 int partial
= argvec
[argnum
].partial
;
4518 unsigned int parm_align
= argvec
[argnum
].locate
.boundary
;
4519 poly_int64 lower_bound
= 0, upper_bound
= 0;
4521 if (! (reg
!= 0 && partial
== 0))
4525 if (ACCUMULATE_OUTGOING_ARGS
)
4527 /* If this is being stored into a pre-allocated, fixed-size,
4528 stack area, save any previous data at that location. */
4530 if (ARGS_GROW_DOWNWARD
)
4532 /* stack_slot is negative, but we want to index stack_usage_map
4533 with positive values. */
4534 upper_bound
= -argvec
[argnum
].locate
.slot_offset
.constant
+ 1;
4535 lower_bound
= upper_bound
- argvec
[argnum
].locate
.size
.constant
;
4539 lower_bound
= argvec
[argnum
].locate
.slot_offset
.constant
;
4540 upper_bound
= lower_bound
+ argvec
[argnum
].locate
.size
.constant
;
4543 if (stack_region_maybe_used_p (lower_bound
, upper_bound
,
4544 reg_parm_stack_space
))
4546 /* We need to make a save area. */
4548 = argvec
[argnum
].locate
.size
.constant
* BITS_PER_UNIT
;
4549 machine_mode save_mode
4550 = int_mode_for_size (size
, 1).else_blk ();
4552 = plus_constant (Pmode
, argblock
,
4553 argvec
[argnum
].locate
.offset
.constant
);
4555 = gen_rtx_MEM (save_mode
, memory_address (save_mode
, adr
));
4557 if (save_mode
== BLKmode
)
4559 argvec
[argnum
].save_area
4560 = assign_stack_temp (BLKmode
,
4561 argvec
[argnum
].locate
.size
.constant
4564 emit_block_move (validize_mem
4565 (copy_rtx (argvec
[argnum
].save_area
)),
4568 (argvec
[argnum
].locate
.size
.constant
,
4570 BLOCK_OP_CALL_PARM
);
4574 argvec
[argnum
].save_area
= gen_reg_rtx (save_mode
);
4576 emit_move_insn (argvec
[argnum
].save_area
, stack_area
);
4581 emit_push_insn (val
, mode
, NULL_TREE
, NULL_RTX
, parm_align
,
4582 partial
, reg
, 0, argblock
,
4584 (argvec
[argnum
].locate
.offset
.constant
, Pmode
)),
4585 reg_parm_stack_space
,
4586 ARGS_SIZE_RTX (argvec
[argnum
].locate
.alignment_pad
), false);
4588 /* Now mark the segment we just used. */
4589 if (ACCUMULATE_OUTGOING_ARGS
)
4590 mark_stack_region_used (lower_bound
, upper_bound
);
4594 /* Indicate argument access so that alias.cc knows that these
4597 use
= plus_constant (Pmode
, argblock
,
4598 argvec
[argnum
].locate
.offset
.constant
);
4599 else if (have_push_fusage
)
4603 /* When arguments are pushed, trying to tell alias.cc where
4604 exactly this argument is won't work, because the
4605 auto-increment causes confusion. So we merely indicate
4606 that we access something with a known mode somewhere on
4608 use
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4609 gen_rtx_SCRATCH (Pmode
));
4610 have_push_fusage
= true;
4612 use
= gen_rtx_MEM (argvec
[argnum
].mode
, use
);
4613 use
= gen_rtx_USE (VOIDmode
, use
);
4614 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
, use
, call_fusage
);
4620 fun
= prepare_call_address (NULL
, fun
, NULL
, &call_fusage
, 0, 0);
4622 /* Now load any reg parms into their regs. */
4624 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4625 are to be pushed. */
4626 for (count
= 0; count
< nargs
; count
++, argnum
--)
4628 machine_mode mode
= argvec
[argnum
].mode
;
4629 rtx val
= argvec
[argnum
].value
;
4630 rtx reg
= argvec
[argnum
].reg
;
4631 int partial
= argvec
[argnum
].partial
;
4633 /* Handle calls that pass values in multiple non-contiguous
4634 locations. The PA64 has examples of this for library calls. */
4635 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
4636 emit_group_load (reg
, val
, NULL_TREE
, GET_MODE_SIZE (mode
));
4637 else if (reg
!= 0 && partial
== 0)
4639 emit_move_insn (reg
, val
);
4640 #ifdef BLOCK_REG_PADDING
4641 poly_int64 size
= GET_MODE_SIZE (argvec
[argnum
].mode
);
4643 /* Copied from load_register_parameters. */
4645 /* Handle case where we have a value that needs shifting
4646 up to the msb. eg. a QImode value and we're padding
4647 upward on a BYTES_BIG_ENDIAN machine. */
4648 if (known_lt (size
, UNITS_PER_WORD
)
4649 && (argvec
[argnum
].locate
.where_pad
4650 == (BYTES_BIG_ENDIAN
? PAD_UPWARD
: PAD_DOWNWARD
)))
4653 poly_int64 shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
4655 /* Assigning REG here rather than a temp makes CALL_FUSAGE
4656 report the whole reg as used. Strictly speaking, the
4657 call only uses SIZE bytes at the msb end, but it doesn't
4658 seem worth generating rtl to say that. */
4659 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
4660 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, shift
, reg
, 1);
4662 emit_move_insn (reg
, x
);
4670 /* Any regs containing parms remain in use through the call. */
4671 for (count
= 0; count
< nargs
; count
++)
4673 rtx reg
= argvec
[count
].reg
;
4674 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
4675 use_group_regs (&call_fusage
, reg
);
4678 int partial
= argvec
[count
].partial
;
4682 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4683 nregs
= partial
/ UNITS_PER_WORD
;
4684 use_regs (&call_fusage
, REGNO (reg
), nregs
);
4687 use_reg (&call_fusage
, reg
);
4691 /* Pass the function the address in which to return a structure value. */
4692 if (mem_value
!= 0 && struct_value
!= 0 && ! pcc_struct_value
)
4694 emit_move_insn (struct_value
,
4696 force_operand (XEXP (mem_value
, 0),
4698 if (REG_P (struct_value
))
4699 use_reg (&call_fusage
, struct_value
);
4702 /* Don't allow popping to be deferred, since then
4703 cse'ing of library calls could delete a call and leave the pop. */
4705 valreg
= (mem_value
== 0 && outmode
!= VOIDmode
4706 ? hard_libcall_value (outmode
, orgfun
) : NULL_RTX
);
4708 /* Stack must be properly aligned now. */
4709 gcc_assert (multiple_p (stack_pointer_delta
,
4710 PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
));
4712 before_call
= get_last_insn ();
4714 if (flag_callgraph_info
)
4715 record_final_call (SYMBOL_REF_DECL (orgfun
), UNKNOWN_LOCATION
);
4717 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4718 will set inhibit_defer_pop to that value. */
4719 /* The return type is needed to decide how many bytes the function pops.
4720 Signedness plays no role in that, so for simplicity, we pretend it's
4721 always signed. We also assume that the list of arguments passed has
4722 no impact, so we pretend it is unknown. */
4724 emit_call_1 (fun
, NULL
,
4725 get_identifier (XSTR (orgfun
, 0)),
4726 build_function_type (tfom
, NULL_TREE
),
4727 original_args_size
.constant
, args_size
.constant
,
4729 targetm
.calls
.function_arg (args_so_far
,
4730 function_arg_info::end_marker ()),
4732 old_inhibit_defer_pop
+ 1, call_fusage
, flags
, args_so_far
);
4737 gcc_assert (GET_CODE (datum
) == SYMBOL_REF
);
4738 rtx_call_insn
*last
= last_call_insn ();
4739 add_reg_note (last
, REG_CALL_DECL
, datum
);
4742 /* Right-shift returned value if necessary. */
4743 if (!pcc_struct_value
4744 && TYPE_MODE (tfom
) != BLKmode
4745 && targetm
.calls
.return_in_msb (tfom
))
4747 shift_return_value (TYPE_MODE (tfom
), false, valreg
);
4748 valreg
= gen_rtx_REG (TYPE_MODE (tfom
), REGNO (valreg
));
4751 targetm
.calls
.end_call_args ();
4753 /* For calls to `setjmp', etc., inform function.cc:setjmp_warnings
4754 that it should complain if nonvolatile values are live. For
4755 functions that cannot return, inform flow that control does not
4757 if (flags
& ECF_NORETURN
)
4759 /* The barrier note must be emitted
4760 immediately after the CALL_INSN. Some ports emit more than
4761 just a CALL_INSN above, so we must search for it here. */
4762 rtx_insn
*last
= get_last_insn ();
4763 while (!CALL_P (last
))
4765 last
= PREV_INSN (last
);
4766 /* There was no CALL_INSN? */
4767 gcc_assert (last
!= before_call
);
4770 emit_barrier_after (last
);
4773 /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW
4774 and LCT_RETURNS_TWICE, cannot perform non-local gotos. */
4775 if (flags
& ECF_NOTHROW
)
4777 rtx_insn
*last
= get_last_insn ();
4778 while (!CALL_P (last
))
4780 last
= PREV_INSN (last
);
4781 /* There was no CALL_INSN? */
4782 gcc_assert (last
!= before_call
);
4785 make_reg_eh_region_note_nothrow_nononlocal (last
);
4788 /* Now restore inhibit_defer_pop to its actual original value. */
4793 /* Copy the value to the right place. */
4794 if (outmode
!= VOIDmode
&& retval
)
4800 if (value
!= mem_value
)
4801 emit_move_insn (value
, mem_value
);
4803 else if (GET_CODE (valreg
) == PARALLEL
)
4806 value
= gen_reg_rtx (outmode
);
4807 emit_group_store (value
, valreg
, NULL_TREE
, GET_MODE_SIZE (outmode
));
4811 /* Convert to the proper mode if a promotion has been active. */
4812 if (GET_MODE (valreg
) != outmode
)
4814 int unsignedp
= TYPE_UNSIGNED (tfom
);
4816 gcc_assert (promote_function_mode (tfom
, outmode
, &unsignedp
,
4817 fndecl
? TREE_TYPE (fndecl
) : fntype
, 1)
4818 == GET_MODE (valreg
));
4819 valreg
= convert_modes (outmode
, GET_MODE (valreg
), valreg
, 0);
4823 emit_move_insn (value
, valreg
);
4829 if (ACCUMULATE_OUTGOING_ARGS
)
4831 #ifdef REG_PARM_STACK_SPACE
4833 restore_fixed_argument_area (save_area
, argblock
,
4834 high_to_save
, low_to_save
);
4837 /* If we saved any argument areas, restore them. */
4838 for (count
= 0; count
< nargs
; count
++)
4839 if (argvec
[count
].save_area
)
4841 machine_mode save_mode
= GET_MODE (argvec
[count
].save_area
);
4842 rtx adr
= plus_constant (Pmode
, argblock
,
4843 argvec
[count
].locate
.offset
.constant
);
4844 rtx stack_area
= gen_rtx_MEM (save_mode
,
4845 memory_address (save_mode
, adr
));
4847 if (save_mode
== BLKmode
)
4848 emit_block_move (stack_area
,
4850 (copy_rtx (argvec
[count
].save_area
)),
4852 (argvec
[count
].locate
.size
.constant
, Pmode
)),
4853 BLOCK_OP_CALL_PARM
);
4855 emit_move_insn (stack_area
, argvec
[count
].save_area
);
4858 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
4859 stack_usage_map
= initial_stack_usage_map
;
4860 stack_usage_watermark
= initial_stack_usage_watermark
;
4863 free (stack_usage_map_buf
);
4870 /* Store a single argument for a function call
4871 into the register or memory area where it must be passed.
4872 *ARG describes the argument value and where to pass it.
4874 ARGBLOCK is the address of the stack-block for all the arguments,
4875 or 0 on a machine where arguments are pushed individually.
4877 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4878 so must be careful about how the stack is used.
4880 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4881 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4882 that we need not worry about saving and restoring the stack.
4884 FNDECL is the declaration of the function we are calling.
4886 Return nonzero if this arg should cause sibcall failure,
4890 store_one_arg (struct arg_data
*arg
, rtx argblock
, int flags
,
4891 int variable_size ATTRIBUTE_UNUSED
, int reg_parm_stack_space
)
4893 tree pval
= arg
->tree_value
;
4896 poly_int64 used
= 0;
4897 poly_int64 lower_bound
= 0, upper_bound
= 0;
4898 int sibcall_failure
= 0;
4900 if (TREE_CODE (pval
) == ERROR_MARK
)
4903 /* Push a new temporary level for any temporaries we make for
4907 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
))
4909 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4910 save any previous data at that location. */
4911 if (argblock
&& ! variable_size
&& arg
->stack
)
4913 if (ARGS_GROW_DOWNWARD
)
4915 /* stack_slot is negative, but we want to index stack_usage_map
4916 with positive values. */
4917 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4919 rtx offset
= XEXP (XEXP (arg
->stack_slot
, 0), 1);
4920 upper_bound
= -rtx_to_poly_int64 (offset
) + 1;
4925 lower_bound
= upper_bound
- arg
->locate
.size
.constant
;
4929 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4931 rtx offset
= XEXP (XEXP (arg
->stack_slot
, 0), 1);
4932 lower_bound
= rtx_to_poly_int64 (offset
);
4937 upper_bound
= lower_bound
+ arg
->locate
.size
.constant
;
4940 if (stack_region_maybe_used_p (lower_bound
, upper_bound
,
4941 reg_parm_stack_space
))
4943 /* We need to make a save area. */
4944 poly_uint64 size
= arg
->locate
.size
.constant
* BITS_PER_UNIT
;
4945 machine_mode save_mode
4946 = int_mode_for_size (size
, 1).else_blk ();
4947 rtx adr
= memory_address (save_mode
, XEXP (arg
->stack_slot
, 0));
4948 rtx stack_area
= gen_rtx_MEM (save_mode
, adr
);
4950 if (save_mode
== BLKmode
)
4953 = assign_temp (TREE_TYPE (arg
->tree_value
), 1, 1);
4954 preserve_temp_slots (arg
->save_area
);
4955 emit_block_move (validize_mem (copy_rtx (arg
->save_area
)),
4958 (arg
->locate
.size
.constant
, Pmode
)),
4959 BLOCK_OP_CALL_PARM
);
4963 arg
->save_area
= gen_reg_rtx (save_mode
);
4964 emit_move_insn (arg
->save_area
, stack_area
);
4970 /* If this isn't going to be placed on both the stack and in registers,
4971 set up the register and number of words. */
4972 if (! arg
->pass_on_stack
)
4974 if (flags
& ECF_SIBCALL
)
4975 reg
= arg
->tail_call_reg
;
4978 partial
= arg
->partial
;
4981 /* Being passed entirely in a register. We shouldn't be called in
4983 gcc_assert (reg
== 0 || partial
!= 0);
4985 /* If this arg needs special alignment, don't load the registers
4987 if (arg
->n_aligned_regs
!= 0)
4990 /* If this is being passed partially in a register, we can't evaluate
4991 it directly into its stack slot. Otherwise, we can. */
4992 if (arg
->value
== 0)
4994 /* stack_arg_under_construction is nonzero if a function argument is
4995 being evaluated directly into the outgoing argument list and
4996 expand_call must take special action to preserve the argument list
4997 if it is called recursively.
4999 For scalar function arguments stack_usage_map is sufficient to
5000 determine which stack slots must be saved and restored. Scalar
5001 arguments in general have pass_on_stack == 0.
5003 If this argument is initialized by a function which takes the
5004 address of the argument (a C++ constructor or a C function
5005 returning a BLKmode structure), then stack_usage_map is
5006 insufficient and expand_call must push the stack around the
5007 function call. Such arguments have pass_on_stack == 1.
5009 Note that it is always safe to set stack_arg_under_construction,
5010 but this generates suboptimal code if set when not needed. */
5012 if (arg
->pass_on_stack
)
5013 stack_arg_under_construction
++;
5015 arg
->value
= expand_expr (pval
,
5017 || TYPE_MODE (TREE_TYPE (pval
)) != arg
->mode
)
5018 ? NULL_RTX
: arg
->stack
,
5019 VOIDmode
, EXPAND_STACK_PARM
);
5021 /* If we are promoting object (or for any other reason) the mode
5022 doesn't agree, convert the mode. */
5024 if (arg
->mode
!= TYPE_MODE (TREE_TYPE (pval
)))
5025 arg
->value
= convert_modes (arg
->mode
, TYPE_MODE (TREE_TYPE (pval
)),
5026 arg
->value
, arg
->unsignedp
);
5028 if (arg
->pass_on_stack
)
5029 stack_arg_under_construction
--;
5032 /* Check for overlap with already clobbered argument area. */
5033 if ((flags
& ECF_SIBCALL
)
5034 && MEM_P (arg
->value
)
5035 && mem_might_overlap_already_clobbered_arg_p (XEXP (arg
->value
, 0),
5036 arg
->locate
.size
.constant
))
5037 sibcall_failure
= 1;
5039 /* Don't allow anything left on stack from computation
5040 of argument to alloca. */
5041 if (flags
& ECF_MAY_BE_ALLOCA
)
5042 do_pending_stack_adjust ();
5044 if (arg
->value
== arg
->stack
)
5045 /* If the value is already in the stack slot, we are done. */
5047 else if (arg
->mode
!= BLKmode
)
5049 unsigned int parm_align
;
5051 /* Argument is a scalar, not entirely passed in registers.
5052 (If part is passed in registers, arg->partial says how much
5053 and emit_push_insn will take care of putting it there.)
5055 Push it, and if its size is less than the
5056 amount of space allocated to it,
5057 also bump stack pointer by the additional space.
5058 Note that in C the default argument promotions
5059 will prevent such mismatches. */
5061 poly_int64 size
= (TYPE_EMPTY_P (TREE_TYPE (pval
))
5062 ? 0 : GET_MODE_SIZE (arg
->mode
));
5064 /* Compute how much space the push instruction will push.
5065 On many machines, pushing a byte will advance the stack
5066 pointer by a halfword. */
5067 #ifdef PUSH_ROUNDING
5068 size
= PUSH_ROUNDING (size
);
5072 /* Compute how much space the argument should get:
5073 round up to a multiple of the alignment for arguments. */
5074 if (targetm
.calls
.function_arg_padding (arg
->mode
, TREE_TYPE (pval
))
5076 /* At the moment we don't (need to) support ABIs for which the
5077 padding isn't known at compile time. In principle it should
5078 be easy to add though. */
5079 used
= force_align_up (size
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
5081 /* Compute the alignment of the pushed argument. */
5082 parm_align
= arg
->locate
.boundary
;
5083 if (targetm
.calls
.function_arg_padding (arg
->mode
, TREE_TYPE (pval
))
5086 poly_int64 pad
= used
- size
;
5087 unsigned int pad_align
= known_alignment (pad
) * BITS_PER_UNIT
;
5089 parm_align
= MIN (parm_align
, pad_align
);
5092 /* This isn't already where we want it on the stack, so put it there.
5093 This can either be done with push or copy insns. */
5094 if (maybe_ne (used
, 0)
5095 && !emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
),
5096 NULL_RTX
, parm_align
, partial
, reg
, used
- size
,
5097 argblock
, ARGS_SIZE_RTX (arg
->locate
.offset
),
5098 reg_parm_stack_space
,
5099 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
), true))
5100 sibcall_failure
= 1;
5102 /* Unless this is a partially-in-register argument, the argument is now
5105 arg
->value
= arg
->stack
;
5109 /* BLKmode, at least partly to be pushed. */
5111 unsigned int parm_align
;
5115 /* Pushing a nonscalar.
5116 If part is passed in registers, PARTIAL says how much
5117 and emit_push_insn will take care of putting it there. */
5119 /* Round its size up to a multiple
5120 of the allocation unit for arguments. */
5122 if (arg
->locate
.size
.var
!= 0)
5125 size_rtx
= ARGS_SIZE_RTX (arg
->locate
.size
);
5129 /* PUSH_ROUNDING has no effect on us, because emit_push_insn
5130 for BLKmode is careful to avoid it. */
5131 excess
= (arg
->locate
.size
.constant
5132 - arg_int_size_in_bytes (TREE_TYPE (pval
))
5134 size_rtx
= expand_expr (arg_size_in_bytes (TREE_TYPE (pval
)),
5135 NULL_RTX
, TYPE_MODE (sizetype
),
5139 parm_align
= arg
->locate
.boundary
;
5141 /* When an argument is padded down, the block is aligned to
5142 PARM_BOUNDARY, but the actual argument isn't. */
5143 if (targetm
.calls
.function_arg_padding (arg
->mode
, TREE_TYPE (pval
))
5146 if (arg
->locate
.size
.var
)
5147 parm_align
= BITS_PER_UNIT
;
5150 unsigned int excess_align
5151 = known_alignment (excess
) * BITS_PER_UNIT
;
5152 if (excess_align
!= 0)
5153 parm_align
= MIN (parm_align
, excess_align
);
5157 if ((flags
& ECF_SIBCALL
) && MEM_P (arg
->value
))
5159 /* emit_push_insn might not work properly if arg->value and
5160 argblock + arg->locate.offset areas overlap. */
5164 if (strip_offset (XEXP (x
, 0), &i
)
5165 == crtl
->args
.internal_arg_pointer
)
5167 /* arg.locate doesn't contain the pretend_args_size offset,
5168 it's part of argblock. Ensure we don't count it in I. */
5169 if (STACK_GROWS_DOWNWARD
)
5170 i
-= crtl
->args
.pretend_args_size
;
5172 i
+= crtl
->args
.pretend_args_size
;
5174 /* expand_call should ensure this. */
5175 gcc_assert (!arg
->locate
.offset
.var
5176 && arg
->locate
.size
.var
== 0);
5177 poly_int64 size_val
= rtx_to_poly_int64 (size_rtx
);
5179 if (known_eq (arg
->locate
.offset
.constant
, i
))
5181 /* Even though they appear to be at the same location,
5182 if part of the outgoing argument is in registers,
5183 they aren't really at the same location. Check for
5184 this by making sure that the incoming size is the
5185 same as the outgoing size. */
5186 if (maybe_ne (arg
->locate
.size
.constant
, size_val
))
5187 sibcall_failure
= 1;
5189 else if (maybe_in_range_p (arg
->locate
.offset
.constant
,
5191 sibcall_failure
= 1;
5192 /* Use arg->locate.size.constant instead of size_rtx
5193 because we only care about the part of the argument
5195 else if (maybe_in_range_p (i
, arg
->locate
.offset
.constant
,
5196 arg
->locate
.size
.constant
))
5197 sibcall_failure
= 1;
5201 if (!CONST_INT_P (size_rtx
) || INTVAL (size_rtx
) != 0)
5202 emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
), size_rtx
,
5203 parm_align
, partial
, reg
, excess
, argblock
,
5204 ARGS_SIZE_RTX (arg
->locate
.offset
),
5205 reg_parm_stack_space
,
5206 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
), false);
5207 /* If we bypass emit_push_insn because it is a zero sized argument,
5208 we still might need to adjust stack if such argument requires
5209 extra alignment. See PR104558. */
5210 else if ((arg
->locate
.alignment_pad
.var
5211 || maybe_ne (arg
->locate
.alignment_pad
.constant
, 0))
5213 anti_adjust_stack (ARGS_SIZE_RTX (arg
->locate
.alignment_pad
));
5215 /* Unless this is a partially-in-register argument, the argument is now
5218 ??? Unlike the case above, in which we want the actual
5219 address of the data, so that we can load it directly into a
5220 register, here we want the address of the stack slot, so that
5221 it's properly aligned for word-by-word copying or something
5222 like that. It's not clear that this is always correct. */
5224 arg
->value
= arg
->stack_slot
;
5227 if (arg
->reg
&& GET_CODE (arg
->reg
) == PARALLEL
)
5229 tree type
= TREE_TYPE (arg
->tree_value
);
5231 = emit_group_load_into_temps (arg
->reg
, arg
->value
, type
,
5232 int_size_in_bytes (type
));
5235 /* Mark all slots this store used. */
5236 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
)
5237 && argblock
&& ! variable_size
&& arg
->stack
)
5238 mark_stack_region_used (lower_bound
, upper_bound
);
5240 /* Once we have pushed something, pops can't safely
5241 be deferred during the rest of the arguments. */
5244 /* Free any temporary slots made in processing this argument. */
5247 return sibcall_failure
;
5250 /* Nonzero if we do not know how to pass ARG solely in registers. */
5253 must_pass_in_stack_var_size (const function_arg_info
&arg
)
5258 /* If the type has variable size... */
5259 if (!poly_int_tree_p (TYPE_SIZE (arg
.type
)))
5262 /* If the type is marked as addressable (it is required
5263 to be constructed into the stack)... */
5264 if (TREE_ADDRESSABLE (arg
.type
))
5270 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
5271 takes trailing padding of a structure into account. */
5272 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
5275 must_pass_in_stack_var_size_or_pad (const function_arg_info
&arg
)
5280 /* If the type has variable size... */
5281 if (TREE_CODE (TYPE_SIZE (arg
.type
)) != INTEGER_CST
)
5284 /* If the type is marked as addressable (it is required
5285 to be constructed into the stack)... */
5286 if (TREE_ADDRESSABLE (arg
.type
))
5289 if (TYPE_EMPTY_P (arg
.type
))
5292 /* If the padding and mode of the type is such that a copy into
5293 a register would put it into the wrong part of the register. */
5294 if (arg
.mode
== BLKmode
5295 && int_size_in_bytes (arg
.type
) % (PARM_BOUNDARY
/ BITS_PER_UNIT
)
5296 && (targetm
.calls
.function_arg_padding (arg
.mode
, arg
.type
)
5297 == (BYTES_BIG_ENDIAN
? PAD_UPWARD
: PAD_DOWNWARD
)))
5303 /* Return true if TYPE must be passed on the stack when passed to
5304 the "..." arguments of a function. */
5307 must_pass_va_arg_in_stack (tree type
)
5309 function_arg_info
arg (type
, /*named=*/false);
5310 return targetm
.calls
.must_pass_in_stack (arg
);
5313 /* Return true if FIELD is the C++17 empty base field that should
5314 be ignored for ABI calling convention decisions in order to
5315 maintain ABI compatibility between C++14 and earlier, which doesn't
5316 add this FIELD to classes with empty bases, and C++17 and later
5320 cxx17_empty_base_field_p (const_tree field
)
5322 return (DECL_FIELD_ABI_IGNORED (field
)
5323 && DECL_ARTIFICIAL (field
)
5324 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field
))
5325 && !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (field
)));