1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989-2015 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"
28 #include "double-int.h"
35 #include "fold-const.h"
36 #include "stor-layout.h"
38 #include "stringpool.h"
42 #include "hard-reg-set.h"
44 #include "basic-block.h"
45 #include "tree-ssa-alias.h"
46 #include "internal-fn.h"
47 #include "gimple-expr.h"
51 #include "statistics.h"
53 #include "fixed-value.h"
54 #include "insn-config.h"
62 #include "insn-codes.h"
66 #include "diagnostic-core.h"
72 #include "langhooks.h"
75 #include "plugin-api.h"
81 #include "tree-chkp.h"
85 /* Redefine STACK_GROWS_DOWNWARD in terms of 0 or 1. */
86 #ifdef STACK_GROWS_DOWNWARD
87 # undef STACK_GROWS_DOWNWARD
88 # define STACK_GROWS_DOWNWARD 1
90 # define STACK_GROWS_DOWNWARD 0
93 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
94 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
96 /* Data structure and subroutines used within expand_call. */
100 /* Tree node for this argument. */
102 /* Mode for value; TYPE_MODE unless promoted. */
104 /* Current RTL value for argument, or 0 if it isn't precomputed. */
106 /* Initially-compute RTL value for argument; only for const functions. */
108 /* Register to pass this argument in, 0 if passed on stack, or an
109 PARALLEL if the arg is to be copied into multiple non-contiguous
112 /* Register to pass this argument in when generating tail call sequence.
113 This is not the same register as for normal calls on machines with
116 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
117 form for emit_group_move. */
119 /* If value is passed in neither reg nor stack, this field holds a number
120 of a special slot to be used. */
122 /* For pointer bounds hold an index of parm bounds are bound to. -1 if
123 there is no such pointer. */
125 /* If pointer_arg refers a structure, then pointer_offset holds an offset
126 of a pointer in this structure. */
128 /* If REG was promoted from the actual mode of the argument expression,
129 indicates whether the promotion is sign- or zero-extended. */
131 /* Number of bytes to put in registers. 0 means put the whole arg
132 in registers. Also 0 if not passed in registers. */
134 /* Nonzero if argument must be passed on stack.
135 Note that some arguments may be passed on the stack
136 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
137 pass_on_stack identifies arguments that *cannot* go in registers. */
139 /* Some fields packaged up for locate_and_pad_parm. */
140 struct locate_and_pad_arg_data locate
;
141 /* Location on the stack at which parameter should be stored. The store
142 has already been done if STACK == VALUE. */
144 /* Location on the stack of the start of this argument slot. This can
145 differ from STACK if this arg pads downward. This location is known
146 to be aligned to TARGET_FUNCTION_ARG_BOUNDARY. */
148 /* Place that this stack area has been saved, if needed. */
150 /* If an argument's alignment does not permit direct copying into registers,
151 copy in smaller-sized pieces into pseudos. These are stored in a
152 block pointed to by this field. The next field says how many
153 word-sized pseudos we made. */
158 /* A vector of one char per byte of stack space. A byte if nonzero if
159 the corresponding stack location has been used.
160 This vector is used to prevent a function call within an argument from
161 clobbering any stack already set up. */
162 static char *stack_usage_map
;
164 /* Size of STACK_USAGE_MAP. */
165 static int highest_outgoing_arg_in_use
;
167 /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
168 stack location's tail call argument has been already stored into the stack.
169 This bitmap is used to prevent sibling call optimization if function tries
170 to use parent's incoming argument slots when they have been already
171 overwritten with tail call arguments. */
172 static sbitmap stored_args_map
;
174 /* stack_arg_under_construction is nonzero when an argument may be
175 initialized with a constructor call (including a C function that
176 returns a BLKmode struct) and expand_call must take special action
177 to make sure the object being constructed does not overlap the
178 argument list for the constructor call. */
179 static int stack_arg_under_construction
;
181 static void emit_call_1 (rtx
, tree
, tree
, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
,
182 HOST_WIDE_INT
, rtx
, rtx
, int, rtx
, int,
184 static void precompute_register_parameters (int, struct arg_data
*, int *);
185 static void store_bounds (struct arg_data
*, struct arg_data
*);
186 static int store_one_arg (struct arg_data
*, rtx
, int, int, int);
187 static void store_unaligned_arguments_into_pseudos (struct arg_data
*, int);
188 static int finalize_must_preallocate (int, int, struct arg_data
*,
190 static void precompute_arguments (int, struct arg_data
*);
191 static int compute_argument_block_size (int, struct args_size
*, tree
, tree
, int);
192 static void initialize_argument_information (int, struct arg_data
*,
193 struct args_size
*, int,
195 tree
, tree
, cumulative_args_t
, int,
196 rtx
*, int *, int *, int *,
198 static void compute_argument_addresses (struct arg_data
*, rtx
, int);
199 static rtx
rtx_for_function_call (tree
, tree
);
200 static void load_register_parameters (struct arg_data
*, int, rtx
*, int,
202 static rtx
emit_library_call_value_1 (int, rtx
, rtx
, enum libcall_type
,
203 machine_mode
, int, va_list);
204 static int special_function_p (const_tree
, int);
205 static int check_sibcall_argument_overlap_1 (rtx
);
206 static int check_sibcall_argument_overlap (rtx_insn
*, struct arg_data
*, int);
208 static int combine_pending_stack_adjustment_and_call (int, struct args_size
*,
210 static tree
split_complex_types (tree
);
212 #ifdef REG_PARM_STACK_SPACE
213 static rtx
save_fixed_argument_area (int, rtx
, int *, int *);
214 static void restore_fixed_argument_area (rtx
, rtx
, int, int);
217 /* Force FUNEXP into a form suitable for the address of a CALL,
218 and return that as an rtx. Also load the static chain register
219 if FNDECL is a nested function.
221 CALL_FUSAGE points to a variable holding the prospective
222 CALL_INSN_FUNCTION_USAGE information. */
225 prepare_call_address (tree fndecl_or_type
, rtx funexp
, rtx static_chain_value
,
226 rtx
*call_fusage
, int reg_parm_seen
, int sibcallp
)
228 /* Make a valid memory address and copy constants through pseudo-regs,
229 but not for a constant address if -fno-function-cse. */
230 if (GET_CODE (funexp
) != SYMBOL_REF
)
231 /* If we are using registers for parameters, force the
232 function address into a register now. */
233 funexp
= ((reg_parm_seen
234 && targetm
.small_register_classes_for_mode_p (FUNCTION_MODE
))
235 ? force_not_mem (memory_address (FUNCTION_MODE
, funexp
))
236 : memory_address (FUNCTION_MODE
, funexp
));
237 else if (flag_pic
&& !flag_plt
&& fndecl_or_type
238 && TREE_CODE (fndecl_or_type
) == FUNCTION_DECL
239 && !targetm
.binds_local_p (fndecl_or_type
))
241 funexp
= force_reg (Pmode
, funexp
);
245 if (!NO_FUNCTION_CSE
&& optimize
&& ! flag_no_function_cse
)
246 funexp
= force_reg (Pmode
, funexp
);
249 if (static_chain_value
!= 0
250 && (TREE_CODE (fndecl_or_type
) != FUNCTION_DECL
251 || DECL_STATIC_CHAIN (fndecl_or_type
)))
255 chain
= targetm
.calls
.static_chain (fndecl_or_type
, false);
256 static_chain_value
= convert_memory_address (Pmode
, static_chain_value
);
258 emit_move_insn (chain
, static_chain_value
);
260 use_reg (call_fusage
, chain
);
266 /* Generate instructions to call function FUNEXP,
267 and optionally pop the results.
268 The CALL_INSN is the first insn generated.
270 FNDECL is the declaration node of the function. This is given to the
271 hook TARGET_RETURN_POPS_ARGS to determine whether this function pops
274 FUNTYPE is the data type of the function. This is given to the hook
275 TARGET_RETURN_POPS_ARGS to determine whether this function pops its
276 own args. We used to allow an identifier for library functions, but
277 that doesn't work when the return type is an aggregate type and the
278 calling convention says that the pointer to this aggregate is to be
279 popped by the callee.
281 STACK_SIZE is the number of bytes of arguments on the stack,
282 ROUNDED_STACK_SIZE is that number rounded up to
283 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
284 both to put into the call insn and to generate explicit popping
287 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
288 It is zero if this call doesn't want a structure value.
290 NEXT_ARG_REG is the rtx that results from executing
291 targetm.calls.function_arg (&args_so_far, VOIDmode, void_type_node, true)
292 just after all the args have had their registers assigned.
293 This could be whatever you like, but normally it is the first
294 arg-register beyond those used for args in this call,
295 or 0 if all the arg-registers are used in this call.
296 It is passed on to `gen_call' so you can put this info in the call insn.
298 VALREG is a hard register in which a value is returned,
299 or 0 if the call does not return a value.
301 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
302 the args to this call were processed.
303 We restore `inhibit_defer_pop' to that value.
305 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
306 denote registers used by the called function. */
309 emit_call_1 (rtx funexp
, tree fntree ATTRIBUTE_UNUSED
, tree fndecl ATTRIBUTE_UNUSED
,
310 tree funtype ATTRIBUTE_UNUSED
,
311 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED
,
312 HOST_WIDE_INT rounded_stack_size
,
313 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED
,
314 rtx next_arg_reg ATTRIBUTE_UNUSED
, rtx valreg
,
315 int old_inhibit_defer_pop
, rtx call_fusage
, int ecf_flags
,
316 cumulative_args_t args_so_far ATTRIBUTE_UNUSED
)
318 rtx rounded_stack_size_rtx
= GEN_INT (rounded_stack_size
);
321 int already_popped
= 0;
322 HOST_WIDE_INT n_popped
323 = targetm
.calls
.return_pops_args (fndecl
, funtype
, stack_size
);
325 #ifdef CALL_POPS_ARGS
326 n_popped
+= CALL_POPS_ARGS (*get_cumulative_args (args_so_far
));
329 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
330 and we don't want to load it into a register as an optimization,
331 because prepare_call_address already did it if it should be done. */
332 if (GET_CODE (funexp
) != SYMBOL_REF
)
333 funexp
= memory_address (FUNCTION_MODE
, funexp
);
335 funmem
= gen_rtx_MEM (FUNCTION_MODE
, funexp
);
336 if (fndecl
&& TREE_CODE (fndecl
) == FUNCTION_DECL
)
340 /* Although a built-in FUNCTION_DECL and its non-__builtin
341 counterpart compare equal and get a shared mem_attrs, they
342 produce different dump output in compare-debug compilations,
343 if an entry gets garbage collected in one compilation, then
344 adds a different (but equivalent) entry, while the other
345 doesn't run the garbage collector at the same spot and then
346 shares the mem_attr with the equivalent entry. */
347 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
)
349 tree t2
= builtin_decl_explicit (DECL_FUNCTION_CODE (t
));
354 set_mem_expr (funmem
, t
);
357 set_mem_expr (funmem
, build_simple_mem_ref (CALL_EXPR_FN (fntree
)));
359 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
360 if ((ecf_flags
& ECF_SIBCALL
)
361 && HAVE_sibcall_pop
&& HAVE_sibcall_value_pop
362 && (n_popped
> 0 || stack_size
== 0))
364 rtx n_pop
= GEN_INT (n_popped
);
367 /* If this subroutine pops its own args, record that in the call insn
368 if possible, for the sake of frame pointer elimination. */
371 pat
= GEN_SIBCALL_VALUE_POP (valreg
, funmem
, rounded_stack_size_rtx
,
372 next_arg_reg
, n_pop
);
374 pat
= GEN_SIBCALL_POP (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
377 emit_call_insn (pat
);
383 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
384 /* If the target has "call" or "call_value" insns, then prefer them
385 if no arguments are actually popped. If the target does not have
386 "call" or "call_value" insns, then we must use the popping versions
387 even if the call has no arguments to pop. */
388 #if defined (HAVE_call) && defined (HAVE_call_value)
389 if (HAVE_call
&& HAVE_call_value
&& HAVE_call_pop
&& HAVE_call_value_pop
392 if (HAVE_call_pop
&& HAVE_call_value_pop
)
395 rtx n_pop
= GEN_INT (n_popped
);
398 /* If this subroutine pops its own args, record that in the call insn
399 if possible, for the sake of frame pointer elimination. */
402 pat
= GEN_CALL_VALUE_POP (valreg
, funmem
, rounded_stack_size_rtx
,
403 next_arg_reg
, n_pop
);
405 pat
= GEN_CALL_POP (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
408 emit_call_insn (pat
);
414 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
415 if ((ecf_flags
& ECF_SIBCALL
)
416 && HAVE_sibcall
&& HAVE_sibcall_value
)
419 emit_call_insn (GEN_SIBCALL_VALUE (valreg
, funmem
,
420 rounded_stack_size_rtx
,
421 next_arg_reg
, NULL_RTX
));
423 emit_call_insn (GEN_SIBCALL (funmem
, rounded_stack_size_rtx
,
425 GEN_INT (struct_value_size
)));
430 #if defined (HAVE_call) && defined (HAVE_call_value)
431 if (HAVE_call
&& HAVE_call_value
)
434 emit_call_insn (GEN_CALL_VALUE (valreg
, funmem
, rounded_stack_size_rtx
,
435 next_arg_reg
, NULL_RTX
));
437 emit_call_insn (GEN_CALL (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
438 GEN_INT (struct_value_size
)));
444 /* Find the call we just emitted. */
445 call_insn
= last_call_insn ();
447 /* Some target create a fresh MEM instead of reusing the one provided
448 above. Set its MEM_EXPR. */
449 call
= get_call_rtx_from (call_insn
);
451 && MEM_EXPR (XEXP (call
, 0)) == NULL_TREE
452 && MEM_EXPR (funmem
) != NULL_TREE
)
453 set_mem_expr (XEXP (call
, 0), MEM_EXPR (funmem
));
455 /* Mark instrumented calls. */
457 CALL_EXPR_WITH_BOUNDS_P (call
) = CALL_WITH_BOUNDS_P (fntree
);
459 /* Put the register usage information there. */
460 add_function_usage_to (call_insn
, call_fusage
);
462 /* If this is a const call, then set the insn's unchanging bit. */
463 if (ecf_flags
& ECF_CONST
)
464 RTL_CONST_CALL_P (call_insn
) = 1;
466 /* If this is a pure call, then set the insn's unchanging bit. */
467 if (ecf_flags
& ECF_PURE
)
468 RTL_PURE_CALL_P (call_insn
) = 1;
470 /* If this is a const call, then set the insn's unchanging bit. */
471 if (ecf_flags
& ECF_LOOPING_CONST_OR_PURE
)
472 RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn
) = 1;
474 /* Create a nothrow REG_EH_REGION note, if needed. */
475 make_reg_eh_region_note (call_insn
, ecf_flags
, 0);
477 if (ecf_flags
& ECF_NORETURN
)
478 add_reg_note (call_insn
, REG_NORETURN
, const0_rtx
);
480 if (ecf_flags
& ECF_RETURNS_TWICE
)
482 add_reg_note (call_insn
, REG_SETJMP
, const0_rtx
);
483 cfun
->calls_setjmp
= 1;
486 SIBLING_CALL_P (call_insn
) = ((ecf_flags
& ECF_SIBCALL
) != 0);
488 /* Restore this now, so that we do defer pops for this call's args
489 if the context of the call as a whole permits. */
490 inhibit_defer_pop
= old_inhibit_defer_pop
;
495 CALL_INSN_FUNCTION_USAGE (call_insn
)
496 = gen_rtx_EXPR_LIST (VOIDmode
,
497 gen_rtx_CLOBBER (VOIDmode
, stack_pointer_rtx
),
498 CALL_INSN_FUNCTION_USAGE (call_insn
));
499 rounded_stack_size
-= n_popped
;
500 rounded_stack_size_rtx
= GEN_INT (rounded_stack_size
);
501 stack_pointer_delta
-= n_popped
;
503 add_reg_note (call_insn
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
505 /* If popup is needed, stack realign must use DRAP */
506 if (SUPPORTS_STACK_ALIGNMENT
)
507 crtl
->need_drap
= true;
509 /* For noreturn calls when not accumulating outgoing args force
510 REG_ARGS_SIZE note to prevent crossjumping of calls with different
512 else if (!ACCUMULATE_OUTGOING_ARGS
&& (ecf_flags
& ECF_NORETURN
) != 0)
513 add_reg_note (call_insn
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
515 if (!ACCUMULATE_OUTGOING_ARGS
)
517 /* If returning from the subroutine does not automatically pop the args,
518 we need an instruction to pop them sooner or later.
519 Perhaps do it now; perhaps just record how much space to pop later.
521 If returning from the subroutine does pop the args, indicate that the
522 stack pointer will be changed. */
524 if (rounded_stack_size
!= 0)
526 if (ecf_flags
& ECF_NORETURN
)
527 /* Just pretend we did the pop. */
528 stack_pointer_delta
-= rounded_stack_size
;
529 else if (flag_defer_pop
&& inhibit_defer_pop
== 0
530 && ! (ecf_flags
& (ECF_CONST
| ECF_PURE
)))
531 pending_stack_adjust
+= rounded_stack_size
;
533 adjust_stack (rounded_stack_size_rtx
);
536 /* When we accumulate outgoing args, we must avoid any stack manipulations.
537 Restore the stack pointer to its original value now. Usually
538 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
539 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
540 popping variants of functions exist as well.
542 ??? We may optimize similar to defer_pop above, but it is
543 probably not worthwhile.
545 ??? It will be worthwhile to enable combine_stack_adjustments even for
548 anti_adjust_stack (GEN_INT (n_popped
));
551 /* Determine if the function identified by NAME and FNDECL is one with
552 special properties we wish to know about.
554 For example, if the function might return more than one time (setjmp), then
555 set RETURNS_TWICE to a nonzero value.
557 Similarly set NORETURN if the function is in the longjmp family.
559 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
560 space from the stack such as alloca. */
563 special_function_p (const_tree fndecl
, int flags
)
565 tree name_decl
= DECL_NAME (fndecl
);
567 /* For instrumentation clones we want to derive flags
568 from the original name. */
569 if (cgraph_node::get (fndecl
)
570 && cgraph_node::get (fndecl
)->instrumentation_clone
)
571 name_decl
= DECL_NAME (cgraph_node::get (fndecl
)->orig_decl
);
573 if (fndecl
&& name_decl
574 && IDENTIFIER_LENGTH (name_decl
) <= 17
575 /* Exclude functions not at the file scope, or not `extern',
576 since they are not the magic functions we would otherwise
578 FIXME: this should be handled with attributes, not with this
579 hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
580 because you can declare fork() inside a function if you
582 && (DECL_CONTEXT (fndecl
) == NULL_TREE
583 || TREE_CODE (DECL_CONTEXT (fndecl
)) == TRANSLATION_UNIT_DECL
)
584 && TREE_PUBLIC (fndecl
))
586 const char *name
= IDENTIFIER_POINTER (name_decl
);
587 const char *tname
= name
;
589 /* We assume that alloca will always be called by name. It
590 makes no sense to pass it as a pointer-to-function to
591 anything that does not understand its behavior. */
592 if (((IDENTIFIER_LENGTH (name_decl
) == 6
594 && ! strcmp (name
, "alloca"))
595 || (IDENTIFIER_LENGTH (name_decl
) == 16
597 && ! strcmp (name
, "__builtin_alloca"))))
598 flags
|= ECF_MAY_BE_ALLOCA
;
600 /* Disregard prefix _, __, __x or __builtin_. */
605 && !strncmp (name
+ 3, "uiltin_", 7))
607 else if (name
[1] == '_' && name
[2] == 'x')
609 else if (name
[1] == '_')
618 && (! strcmp (tname
, "setjmp")
619 || ! strcmp (tname
, "setjmp_syscall")))
621 && ! strcmp (tname
, "sigsetjmp"))
623 && ! strcmp (tname
, "savectx")))
624 flags
|= ECF_RETURNS_TWICE
| ECF_LEAF
;
627 && ! strcmp (tname
, "siglongjmp"))
628 flags
|= ECF_NORETURN
;
630 else if ((tname
[0] == 'q' && tname
[1] == 's'
631 && ! strcmp (tname
, "qsetjmp"))
632 || (tname
[0] == 'v' && tname
[1] == 'f'
633 && ! strcmp (tname
, "vfork"))
634 || (tname
[0] == 'g' && tname
[1] == 'e'
635 && !strcmp (tname
, "getcontext")))
636 flags
|= ECF_RETURNS_TWICE
| ECF_LEAF
;
638 else if (tname
[0] == 'l' && tname
[1] == 'o'
639 && ! strcmp (tname
, "longjmp"))
640 flags
|= ECF_NORETURN
;
646 /* Similar to special_function_p; return a set of ERF_ flags for the
649 decl_return_flags (tree fndecl
)
652 tree type
= TREE_TYPE (fndecl
);
656 attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
660 attr
= TREE_VALUE (TREE_VALUE (attr
));
661 if (!attr
|| TREE_STRING_LENGTH (attr
) < 1)
664 switch (TREE_STRING_POINTER (attr
)[0])
670 return ERF_RETURNS_ARG
| (TREE_STRING_POINTER (attr
)[0] - '1');
681 /* Return nonzero when FNDECL represents a call to setjmp. */
684 setjmp_call_p (const_tree fndecl
)
686 if (DECL_IS_RETURNS_TWICE (fndecl
))
687 return ECF_RETURNS_TWICE
;
688 return special_function_p (fndecl
, 0) & ECF_RETURNS_TWICE
;
692 /* Return true if STMT is an alloca call. */
695 gimple_alloca_call_p (const_gimple stmt
)
699 if (!is_gimple_call (stmt
))
702 fndecl
= gimple_call_fndecl (stmt
);
703 if (fndecl
&& (special_function_p (fndecl
, 0) & ECF_MAY_BE_ALLOCA
))
709 /* Return true when exp contains alloca call. */
712 alloca_call_p (const_tree exp
)
715 if (TREE_CODE (exp
) == CALL_EXPR
716 && (fndecl
= get_callee_fndecl (exp
))
717 && (special_function_p (fndecl
, 0) & ECF_MAY_BE_ALLOCA
))
722 /* Return TRUE if FNDECL is either a TM builtin or a TM cloned
723 function. Return FALSE otherwise. */
726 is_tm_builtin (const_tree fndecl
)
731 if (decl_is_tm_clone (fndecl
))
734 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
)
736 switch (DECL_FUNCTION_CODE (fndecl
))
738 case BUILT_IN_TM_COMMIT
:
739 case BUILT_IN_TM_COMMIT_EH
:
740 case BUILT_IN_TM_ABORT
:
741 case BUILT_IN_TM_IRREVOCABLE
:
742 case BUILT_IN_TM_GETTMCLONE_IRR
:
743 case BUILT_IN_TM_MEMCPY
:
744 case BUILT_IN_TM_MEMMOVE
:
745 case BUILT_IN_TM_MEMSET
:
746 CASE_BUILT_IN_TM_STORE (1):
747 CASE_BUILT_IN_TM_STORE (2):
748 CASE_BUILT_IN_TM_STORE (4):
749 CASE_BUILT_IN_TM_STORE (8):
750 CASE_BUILT_IN_TM_STORE (FLOAT
):
751 CASE_BUILT_IN_TM_STORE (DOUBLE
):
752 CASE_BUILT_IN_TM_STORE (LDOUBLE
):
753 CASE_BUILT_IN_TM_STORE (M64
):
754 CASE_BUILT_IN_TM_STORE (M128
):
755 CASE_BUILT_IN_TM_STORE (M256
):
756 CASE_BUILT_IN_TM_LOAD (1):
757 CASE_BUILT_IN_TM_LOAD (2):
758 CASE_BUILT_IN_TM_LOAD (4):
759 CASE_BUILT_IN_TM_LOAD (8):
760 CASE_BUILT_IN_TM_LOAD (FLOAT
):
761 CASE_BUILT_IN_TM_LOAD (DOUBLE
):
762 CASE_BUILT_IN_TM_LOAD (LDOUBLE
):
763 CASE_BUILT_IN_TM_LOAD (M64
):
764 CASE_BUILT_IN_TM_LOAD (M128
):
765 CASE_BUILT_IN_TM_LOAD (M256
):
766 case BUILT_IN_TM_LOG
:
767 case BUILT_IN_TM_LOG_1
:
768 case BUILT_IN_TM_LOG_2
:
769 case BUILT_IN_TM_LOG_4
:
770 case BUILT_IN_TM_LOG_8
:
771 case BUILT_IN_TM_LOG_FLOAT
:
772 case BUILT_IN_TM_LOG_DOUBLE
:
773 case BUILT_IN_TM_LOG_LDOUBLE
:
774 case BUILT_IN_TM_LOG_M64
:
775 case BUILT_IN_TM_LOG_M128
:
776 case BUILT_IN_TM_LOG_M256
:
785 /* Detect flags (function attributes) from the function decl or type node. */
788 flags_from_decl_or_type (const_tree exp
)
794 /* The function exp may have the `malloc' attribute. */
795 if (DECL_IS_MALLOC (exp
))
798 /* The function exp may have the `returns_twice' attribute. */
799 if (DECL_IS_RETURNS_TWICE (exp
))
800 flags
|= ECF_RETURNS_TWICE
;
802 /* Process the pure and const attributes. */
803 if (TREE_READONLY (exp
))
805 if (DECL_PURE_P (exp
))
807 if (DECL_LOOPING_CONST_OR_PURE_P (exp
))
808 flags
|= ECF_LOOPING_CONST_OR_PURE
;
810 if (DECL_IS_NOVOPS (exp
))
812 if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp
)))
815 if (TREE_NOTHROW (exp
))
816 flags
|= ECF_NOTHROW
;
820 if (is_tm_builtin (exp
))
821 flags
|= ECF_TM_BUILTIN
;
822 else if ((flags
& (ECF_CONST
|ECF_NOVOPS
)) != 0
823 || lookup_attribute ("transaction_pure",
824 TYPE_ATTRIBUTES (TREE_TYPE (exp
))))
825 flags
|= ECF_TM_PURE
;
828 flags
= special_function_p (exp
, flags
);
830 else if (TYPE_P (exp
))
832 if (TYPE_READONLY (exp
))
836 && ((flags
& ECF_CONST
) != 0
837 || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp
))))
838 flags
|= ECF_TM_PURE
;
843 if (TREE_THIS_VOLATILE (exp
))
845 flags
|= ECF_NORETURN
;
846 if (flags
& (ECF_CONST
|ECF_PURE
))
847 flags
|= ECF_LOOPING_CONST_OR_PURE
;
853 /* Detect flags from a CALL_EXPR. */
856 call_expr_flags (const_tree t
)
859 tree decl
= get_callee_fndecl (t
);
862 flags
= flags_from_decl_or_type (decl
);
863 else if (CALL_EXPR_FN (t
) == NULL_TREE
)
864 flags
= internal_fn_flags (CALL_EXPR_IFN (t
));
867 t
= TREE_TYPE (CALL_EXPR_FN (t
));
868 if (t
&& TREE_CODE (t
) == POINTER_TYPE
)
869 flags
= flags_from_decl_or_type (TREE_TYPE (t
));
877 /* Precompute all register parameters as described by ARGS, storing values
878 into fields within the ARGS array.
880 NUM_ACTUALS indicates the total number elements in the ARGS array.
882 Set REG_PARM_SEEN if we encounter a register parameter. */
885 precompute_register_parameters (int num_actuals
, struct arg_data
*args
,
892 for (i
= 0; i
< num_actuals
; i
++)
893 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
)
897 if (args
[i
].value
== 0)
900 args
[i
].value
= expand_normal (args
[i
].tree_value
);
901 preserve_temp_slots (args
[i
].value
);
905 /* If we are to promote the function arg to a wider mode,
908 if (args
[i
].mode
!= TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)))
910 = convert_modes (args
[i
].mode
,
911 TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)),
912 args
[i
].value
, args
[i
].unsignedp
);
914 /* If the value is a non-legitimate constant, force it into a
915 pseudo now. TLS symbols sometimes need a call to resolve. */
916 if (CONSTANT_P (args
[i
].value
)
917 && !targetm
.legitimate_constant_p (args
[i
].mode
, args
[i
].value
))
918 args
[i
].value
= force_reg (args
[i
].mode
, args
[i
].value
);
920 /* If we're going to have to load the value by parts, pull the
921 parts into pseudos. The part extraction process can involve
922 non-trivial computation. */
923 if (GET_CODE (args
[i
].reg
) == PARALLEL
)
925 tree type
= TREE_TYPE (args
[i
].tree_value
);
926 args
[i
].parallel_value
927 = emit_group_load_into_temps (args
[i
].reg
, args
[i
].value
,
928 type
, int_size_in_bytes (type
));
931 /* If the value is expensive, and we are inside an appropriately
932 short loop, put the value into a pseudo and then put the pseudo
935 For small register classes, also do this if this call uses
936 register parameters. This is to avoid reload conflicts while
937 loading the parameters registers. */
939 else if ((! (REG_P (args
[i
].value
)
940 || (GET_CODE (args
[i
].value
) == SUBREG
941 && REG_P (SUBREG_REG (args
[i
].value
)))))
942 && args
[i
].mode
!= BLKmode
943 && set_src_cost (args
[i
].value
, optimize_insn_for_speed_p ())
946 && targetm
.small_register_classes_for_mode_p (args
[i
].mode
))
948 args
[i
].value
= copy_to_mode_reg (args
[i
].mode
, args
[i
].value
);
952 #ifdef REG_PARM_STACK_SPACE
954 /* The argument list is the property of the called routine and it
955 may clobber it. If the fixed area has been used for previous
956 parameters, we must save and restore it. */
959 save_fixed_argument_area (int reg_parm_stack_space
, rtx argblock
, int *low_to_save
, int *high_to_save
)
964 /* Compute the boundary of the area that needs to be saved, if any. */
965 high
= reg_parm_stack_space
;
966 if (ARGS_GROW_DOWNWARD
)
969 if (high
> highest_outgoing_arg_in_use
)
970 high
= highest_outgoing_arg_in_use
;
972 for (low
= 0; low
< high
; low
++)
973 if (stack_usage_map
[low
] != 0)
976 machine_mode save_mode
;
982 while (stack_usage_map
[--high
] == 0)
986 *high_to_save
= high
;
988 num_to_save
= high
- low
+ 1;
989 save_mode
= mode_for_size (num_to_save
* BITS_PER_UNIT
, MODE_INT
, 1);
991 /* If we don't have the required alignment, must do this
993 if ((low
& (MIN (GET_MODE_SIZE (save_mode
),
994 BIGGEST_ALIGNMENT
/ UNITS_PER_WORD
) - 1)))
997 if (ARGS_GROW_DOWNWARD
)
1002 addr
= plus_constant (Pmode
, argblock
, delta
);
1003 stack_area
= gen_rtx_MEM (save_mode
, memory_address (save_mode
, addr
));
1005 set_mem_align (stack_area
, PARM_BOUNDARY
);
1006 if (save_mode
== BLKmode
)
1008 save_area
= assign_stack_temp (BLKmode
, num_to_save
);
1009 emit_block_move (validize_mem (save_area
), stack_area
,
1010 GEN_INT (num_to_save
), BLOCK_OP_CALL_PARM
);
1014 save_area
= gen_reg_rtx (save_mode
);
1015 emit_move_insn (save_area
, stack_area
);
1025 restore_fixed_argument_area (rtx save_area
, rtx argblock
, int high_to_save
, int low_to_save
)
1027 machine_mode save_mode
= GET_MODE (save_area
);
1029 rtx addr
, stack_area
;
1031 if (ARGS_GROW_DOWNWARD
)
1032 delta
= -high_to_save
;
1034 delta
= low_to_save
;
1036 addr
= plus_constant (Pmode
, argblock
, delta
);
1037 stack_area
= gen_rtx_MEM (save_mode
, memory_address (save_mode
, addr
));
1038 set_mem_align (stack_area
, PARM_BOUNDARY
);
1040 if (save_mode
!= BLKmode
)
1041 emit_move_insn (stack_area
, save_area
);
1043 emit_block_move (stack_area
, validize_mem (save_area
),
1044 GEN_INT (high_to_save
- low_to_save
+ 1),
1045 BLOCK_OP_CALL_PARM
);
1047 #endif /* REG_PARM_STACK_SPACE */
1049 /* If any elements in ARGS refer to parameters that are to be passed in
1050 registers, but not in memory, and whose alignment does not permit a
1051 direct copy into registers. Copy the values into a group of pseudos
1052 which we will later copy into the appropriate hard registers.
1054 Pseudos for each unaligned argument will be stored into the array
1055 args[argnum].aligned_regs. The caller is responsible for deallocating
1056 the aligned_regs array if it is nonzero. */
1059 store_unaligned_arguments_into_pseudos (struct arg_data
*args
, int num_actuals
)
1063 for (i
= 0; i
< num_actuals
; i
++)
1064 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
1065 && GET_CODE (args
[i
].reg
) != PARALLEL
1066 && args
[i
].mode
== BLKmode
1067 && MEM_P (args
[i
].value
)
1068 && (MEM_ALIGN (args
[i
].value
)
1069 < (unsigned int) MIN (BIGGEST_ALIGNMENT
, BITS_PER_WORD
)))
1071 int bytes
= int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1072 int endian_correction
= 0;
1074 if (args
[i
].partial
)
1076 gcc_assert (args
[i
].partial
% UNITS_PER_WORD
== 0);
1077 args
[i
].n_aligned_regs
= args
[i
].partial
/ UNITS_PER_WORD
;
1081 args
[i
].n_aligned_regs
1082 = (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
1085 args
[i
].aligned_regs
= XNEWVEC (rtx
, args
[i
].n_aligned_regs
);
1087 /* Structures smaller than a word are normally aligned to the
1088 least significant byte. On a BYTES_BIG_ENDIAN machine,
1089 this means we must skip the empty high order bytes when
1090 calculating the bit offset. */
1091 if (bytes
< UNITS_PER_WORD
1092 #ifdef BLOCK_REG_PADDING
1093 && (BLOCK_REG_PADDING (args
[i
].mode
,
1094 TREE_TYPE (args
[i
].tree_value
), 1)
1100 endian_correction
= BITS_PER_WORD
- bytes
* BITS_PER_UNIT
;
1102 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
1104 rtx reg
= gen_reg_rtx (word_mode
);
1105 rtx word
= operand_subword_force (args
[i
].value
, j
, BLKmode
);
1106 int bitsize
= MIN (bytes
* BITS_PER_UNIT
, BITS_PER_WORD
);
1108 args
[i
].aligned_regs
[j
] = reg
;
1109 word
= extract_bit_field (word
, bitsize
, 0, 1, NULL_RTX
,
1110 word_mode
, word_mode
);
1112 /* There is no need to restrict this code to loading items
1113 in TYPE_ALIGN sized hunks. The bitfield instructions can
1114 load up entire word sized registers efficiently.
1116 ??? This may not be needed anymore.
1117 We use to emit a clobber here but that doesn't let later
1118 passes optimize the instructions we emit. By storing 0 into
1119 the register later passes know the first AND to zero out the
1120 bitfield being set in the register is unnecessary. The store
1121 of 0 will be deleted as will at least the first AND. */
1123 emit_move_insn (reg
, const0_rtx
);
1125 bytes
-= bitsize
/ BITS_PER_UNIT
;
1126 store_bit_field (reg
, bitsize
, endian_correction
, 0, 0,
1132 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
1135 NUM_ACTUALS is the total number of parameters.
1137 N_NAMED_ARGS is the total number of named arguments.
1139 STRUCT_VALUE_ADDR_VALUE is the implicit argument for a struct return
1142 FNDECL is the tree code for the target of this call (if known)
1144 ARGS_SO_FAR holds state needed by the target to know where to place
1147 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
1148 for arguments which are passed in registers.
1150 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
1151 and may be modified by this routine.
1153 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
1154 flags which may may be modified by this routine.
1156 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
1157 that requires allocation of stack space.
1159 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
1160 the thunked-to function. */
1163 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED
,
1164 struct arg_data
*args
,
1165 struct args_size
*args_size
,
1166 int n_named_args ATTRIBUTE_UNUSED
,
1167 tree exp
, tree struct_value_addr_value
,
1168 tree fndecl
, tree fntype
,
1169 cumulative_args_t args_so_far
,
1170 int reg_parm_stack_space
,
1171 rtx
*old_stack_level
, int *old_pending_adj
,
1172 int *must_preallocate
, int *ecf_flags
,
1173 bool *may_tailcall
, bool call_from_thunk_p
)
1175 CUMULATIVE_ARGS
*args_so_far_pnt
= get_cumulative_args (args_so_far
);
1176 location_t loc
= EXPR_LOCATION (exp
);
1178 /* Count arg position in order args appear. */
1183 args_size
->constant
= 0;
1186 bitmap_obstack_initialize (NULL
);
1188 /* In this loop, we consider args in the order they are written.
1189 We fill up ARGS from the back. */
1191 i
= num_actuals
- 1;
1193 int j
= i
, ptr_arg
= -1;
1194 call_expr_arg_iterator iter
;
1196 bitmap slots
= NULL
;
1198 if (struct_value_addr_value
)
1200 args
[j
].tree_value
= struct_value_addr_value
;
1203 /* If we pass structure address then we need to
1204 create bounds for it. Since created bounds is
1205 a call statement, we expand it right here to avoid
1206 fixing all other places where it may be expanded. */
1207 if (CALL_WITH_BOUNDS_P (exp
))
1209 args
[j
].value
= gen_reg_rtx (targetm
.chkp_bound_mode ());
1211 = chkp_make_bounds_for_struct_addr (struct_value_addr_value
);
1212 expand_expr_real (args
[j
].tree_value
, args
[j
].value
, VOIDmode
,
1213 EXPAND_NORMAL
, 0, false);
1214 args
[j
].pointer_arg
= j
+ 1;
1218 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
1220 tree argtype
= TREE_TYPE (arg
);
1222 /* Remember last param with pointer and associate it
1223 with following pointer bounds. */
1224 if (CALL_WITH_BOUNDS_P (exp
)
1225 && chkp_type_has_pointer (argtype
))
1228 BITMAP_FREE (slots
);
1230 if (!BOUNDED_TYPE_P (argtype
))
1232 slots
= BITMAP_ALLOC (NULL
);
1233 chkp_find_bound_slots (argtype
, slots
);
1236 else if (POINTER_BOUNDS_TYPE_P (argtype
))
1238 /* We expect bounds in instrumented calls only.
1239 Otherwise it is a sign we lost flag due to some optimization
1240 and may emit call args incorrectly. */
1241 gcc_assert (CALL_WITH_BOUNDS_P (exp
));
1243 /* For structures look for the next available pointer. */
1244 if (ptr_arg
!= -1 && slots
)
1246 unsigned bnd_no
= bitmap_first_set_bit (slots
);
1247 args
[j
].pointer_offset
=
1248 bnd_no
* POINTER_SIZE
/ BITS_PER_UNIT
;
1250 bitmap_clear_bit (slots
, bnd_no
);
1252 /* Check we have no more pointers in the structure. */
1253 if (bitmap_empty_p (slots
))
1254 BITMAP_FREE (slots
);
1256 args
[j
].pointer_arg
= ptr_arg
;
1258 /* Check we covered all pointers in the previous
1266 if (targetm
.calls
.split_complex_arg
1268 && TREE_CODE (argtype
) == COMPLEX_TYPE
1269 && targetm
.calls
.split_complex_arg (argtype
))
1271 tree subtype
= TREE_TYPE (argtype
);
1272 args
[j
].tree_value
= build1 (REALPART_EXPR
, subtype
, arg
);
1274 args
[j
].tree_value
= build1 (IMAGPART_EXPR
, subtype
, arg
);
1277 args
[j
].tree_value
= arg
;
1282 BITMAP_FREE (slots
);
1285 bitmap_obstack_release (NULL
);
1287 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1288 for (argpos
= 0; argpos
< num_actuals
; i
--, argpos
++)
1290 tree type
= TREE_TYPE (args
[i
].tree_value
);
1294 /* Replace erroneous argument with constant zero. */
1295 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
1296 args
[i
].tree_value
= integer_zero_node
, type
= integer_type_node
;
1298 /* If TYPE is a transparent union or record, pass things the way
1299 we would pass the first field of the union or record. We have
1300 already verified that the modes are the same. */
1301 if ((TREE_CODE (type
) == UNION_TYPE
|| TREE_CODE (type
) == RECORD_TYPE
)
1302 && TYPE_TRANSPARENT_AGGR (type
))
1303 type
= TREE_TYPE (first_field (type
));
1305 /* Decide where to pass this arg.
1307 args[i].reg is nonzero if all or part is passed in registers.
1309 args[i].partial is nonzero if part but not all is passed in registers,
1310 and the exact value says how many bytes are passed in registers.
1312 args[i].pass_on_stack is nonzero if the argument must at least be
1313 computed on the stack. It may then be loaded back into registers
1314 if args[i].reg is nonzero.
1316 These decisions are driven by the FUNCTION_... macros and must agree
1317 with those made by function.c. */
1319 /* See if this argument should be passed by invisible reference. */
1320 if (pass_by_reference (args_so_far_pnt
, TYPE_MODE (type
),
1321 type
, argpos
< n_named_args
))
1324 tree base
= NULL_TREE
;
1327 = reference_callee_copied (args_so_far_pnt
, TYPE_MODE (type
),
1328 type
, argpos
< n_named_args
);
1330 /* If we're compiling a thunk, pass through invisible references
1331 instead of making a copy. */
1332 if (call_from_thunk_p
1334 && !TREE_ADDRESSABLE (type
)
1335 && (base
= get_base_address (args
[i
].tree_value
))
1336 && TREE_CODE (base
) != SSA_NAME
1337 && (!DECL_P (base
) || MEM_P (DECL_RTL (base
)))))
1339 /* We may have turned the parameter value into an SSA name.
1340 Go back to the original parameter so we can take the
1342 if (TREE_CODE (args
[i
].tree_value
) == SSA_NAME
)
1344 gcc_assert (SSA_NAME_IS_DEFAULT_DEF (args
[i
].tree_value
));
1345 args
[i
].tree_value
= SSA_NAME_VAR (args
[i
].tree_value
);
1346 gcc_assert (TREE_CODE (args
[i
].tree_value
) == PARM_DECL
);
1348 /* Argument setup code may have copied the value to register. We
1349 revert that optimization now because the tail call code must
1350 use the original location. */
1351 if (TREE_CODE (args
[i
].tree_value
) == PARM_DECL
1352 && !MEM_P (DECL_RTL (args
[i
].tree_value
))
1353 && DECL_INCOMING_RTL (args
[i
].tree_value
)
1354 && MEM_P (DECL_INCOMING_RTL (args
[i
].tree_value
)))
1355 set_decl_rtl (args
[i
].tree_value
,
1356 DECL_INCOMING_RTL (args
[i
].tree_value
));
1358 mark_addressable (args
[i
].tree_value
);
1360 /* We can't use sibcalls if a callee-copied argument is
1361 stored in the current function's frame. */
1362 if (!call_from_thunk_p
&& DECL_P (base
) && !TREE_STATIC (base
))
1363 *may_tailcall
= false;
1365 args
[i
].tree_value
= build_fold_addr_expr_loc (loc
,
1366 args
[i
].tree_value
);
1367 type
= TREE_TYPE (args
[i
].tree_value
);
1369 if (*ecf_flags
& ECF_CONST
)
1370 *ecf_flags
&= ~(ECF_CONST
| ECF_LOOPING_CONST_OR_PURE
);
1374 /* We make a copy of the object and pass the address to the
1375 function being called. */
1378 if (!COMPLETE_TYPE_P (type
)
1379 || TREE_CODE (TYPE_SIZE_UNIT (type
)) != INTEGER_CST
1380 || (flag_stack_check
== GENERIC_STACK_CHECK
1381 && compare_tree_int (TYPE_SIZE_UNIT (type
),
1382 STACK_CHECK_MAX_VAR_SIZE
) > 0))
1384 /* This is a variable-sized object. Make space on the stack
1386 rtx size_rtx
= expr_size (args
[i
].tree_value
);
1388 if (*old_stack_level
== 0)
1390 emit_stack_save (SAVE_BLOCK
, old_stack_level
);
1391 *old_pending_adj
= pending_stack_adjust
;
1392 pending_stack_adjust
= 0;
1395 /* We can pass TRUE as the 4th argument because we just
1396 saved the stack pointer and will restore it right after
1398 copy
= allocate_dynamic_stack_space (size_rtx
,
1402 copy
= gen_rtx_MEM (BLKmode
, copy
);
1403 set_mem_attributes (copy
, type
, 1);
1406 copy
= assign_temp (type
, 1, 0);
1408 store_expr (args
[i
].tree_value
, copy
, 0, false);
1410 /* Just change the const function to pure and then let
1411 the next test clear the pure based on
1413 if (*ecf_flags
& ECF_CONST
)
1415 *ecf_flags
&= ~ECF_CONST
;
1416 *ecf_flags
|= ECF_PURE
;
1419 if (!callee_copies
&& *ecf_flags
& ECF_PURE
)
1420 *ecf_flags
&= ~(ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
1423 = build_fold_addr_expr_loc (loc
, make_tree (type
, copy
));
1424 type
= TREE_TYPE (args
[i
].tree_value
);
1425 *may_tailcall
= false;
1429 unsignedp
= TYPE_UNSIGNED (type
);
1430 mode
= promote_function_mode (type
, TYPE_MODE (type
), &unsignedp
,
1431 fndecl
? TREE_TYPE (fndecl
) : fntype
, 0);
1433 args
[i
].unsignedp
= unsignedp
;
1434 args
[i
].mode
= mode
;
1436 args
[i
].reg
= targetm
.calls
.function_arg (args_so_far
, mode
, type
,
1437 argpos
< n_named_args
);
1439 if (args
[i
].reg
&& CONST_INT_P (args
[i
].reg
))
1441 args
[i
].special_slot
= args
[i
].reg
;
1445 /* If this is a sibling call and the machine has register windows, the
1446 register window has to be unwinded before calling the routine, so
1447 arguments have to go into the incoming registers. */
1448 if (targetm
.calls
.function_incoming_arg
!= targetm
.calls
.function_arg
)
1449 args
[i
].tail_call_reg
1450 = targetm
.calls
.function_incoming_arg (args_so_far
, mode
, type
,
1451 argpos
< n_named_args
);
1453 args
[i
].tail_call_reg
= args
[i
].reg
;
1457 = targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, type
,
1458 argpos
< n_named_args
);
1460 args
[i
].pass_on_stack
= targetm
.calls
.must_pass_in_stack (mode
, type
);
1462 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1463 it means that we are to pass this arg in the register(s) designated
1464 by the PARALLEL, but also to pass it in the stack. */
1465 if (args
[i
].reg
&& GET_CODE (args
[i
].reg
) == PARALLEL
1466 && XEXP (XVECEXP (args
[i
].reg
, 0, 0), 0) == 0)
1467 args
[i
].pass_on_stack
= 1;
1469 /* If this is an addressable type, we must preallocate the stack
1470 since we must evaluate the object into its final location.
1472 If this is to be passed in both registers and the stack, it is simpler
1474 if (TREE_ADDRESSABLE (type
)
1475 || (args
[i
].pass_on_stack
&& args
[i
].reg
!= 0))
1476 *must_preallocate
= 1;
1478 /* No stack allocation and padding for bounds. */
1479 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
1481 /* Compute the stack-size of this argument. */
1482 else if (args
[i
].reg
== 0 || args
[i
].partial
!= 0
1483 || reg_parm_stack_space
> 0
1484 || args
[i
].pass_on_stack
)
1485 locate_and_pad_parm (mode
, type
,
1486 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1491 reg_parm_stack_space
,
1492 args
[i
].pass_on_stack
? 0 : args
[i
].partial
,
1493 fndecl
, args_size
, &args
[i
].locate
);
1494 #ifdef BLOCK_REG_PADDING
1496 /* The argument is passed entirely in registers. See at which
1497 end it should be padded. */
1498 args
[i
].locate
.where_pad
=
1499 BLOCK_REG_PADDING (mode
, type
,
1500 int_size_in_bytes (type
) <= UNITS_PER_WORD
);
1503 /* Update ARGS_SIZE, the total stack space for args so far. */
1505 args_size
->constant
+= args
[i
].locate
.size
.constant
;
1506 if (args
[i
].locate
.size
.var
)
1507 ADD_PARM_SIZE (*args_size
, args
[i
].locate
.size
.var
);
1509 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1510 have been used, etc. */
1512 targetm
.calls
.function_arg_advance (args_so_far
, TYPE_MODE (type
),
1513 type
, argpos
< n_named_args
);
1517 /* Update ARGS_SIZE to contain the total size for the argument block.
1518 Return the original constant component of the argument block's size.
1520 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1521 for arguments passed in registers. */
1524 compute_argument_block_size (int reg_parm_stack_space
,
1525 struct args_size
*args_size
,
1526 tree fndecl ATTRIBUTE_UNUSED
,
1527 tree fntype ATTRIBUTE_UNUSED
,
1528 int preferred_stack_boundary ATTRIBUTE_UNUSED
)
1530 int unadjusted_args_size
= args_size
->constant
;
1532 /* For accumulate outgoing args mode we don't need to align, since the frame
1533 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1534 backends from generating misaligned frame sizes. */
1535 if (ACCUMULATE_OUTGOING_ARGS
&& preferred_stack_boundary
> STACK_BOUNDARY
)
1536 preferred_stack_boundary
= STACK_BOUNDARY
;
1538 /* Compute the actual size of the argument block required. The variable
1539 and constant sizes must be combined, the size may have to be rounded,
1540 and there may be a minimum required size. */
1544 args_size
->var
= ARGS_SIZE_TREE (*args_size
);
1545 args_size
->constant
= 0;
1547 preferred_stack_boundary
/= BITS_PER_UNIT
;
1548 if (preferred_stack_boundary
> 1)
1550 /* We don't handle this case yet. To handle it correctly we have
1551 to add the delta, round and subtract the delta.
1552 Currently no machine description requires this support. */
1553 gcc_assert (!(stack_pointer_delta
& (preferred_stack_boundary
- 1)));
1554 args_size
->var
= round_up (args_size
->var
, preferred_stack_boundary
);
1557 if (reg_parm_stack_space
> 0)
1560 = size_binop (MAX_EXPR
, args_size
->var
,
1561 ssize_int (reg_parm_stack_space
));
1563 /* The area corresponding to register parameters is not to count in
1564 the size of the block we need. So make the adjustment. */
1565 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
1567 = size_binop (MINUS_EXPR
, args_size
->var
,
1568 ssize_int (reg_parm_stack_space
));
1573 preferred_stack_boundary
/= BITS_PER_UNIT
;
1574 if (preferred_stack_boundary
< 1)
1575 preferred_stack_boundary
= 1;
1576 args_size
->constant
= (((args_size
->constant
1577 + stack_pointer_delta
1578 + preferred_stack_boundary
- 1)
1579 / preferred_stack_boundary
1580 * preferred_stack_boundary
)
1581 - stack_pointer_delta
);
1583 args_size
->constant
= MAX (args_size
->constant
,
1584 reg_parm_stack_space
);
1586 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
1587 args_size
->constant
-= reg_parm_stack_space
;
1589 return unadjusted_args_size
;
1592 /* Precompute parameters as needed for a function call.
1594 FLAGS is mask of ECF_* constants.
1596 NUM_ACTUALS is the number of arguments.
1598 ARGS is an array containing information for each argument; this
1599 routine fills in the INITIAL_VALUE and VALUE fields for each
1600 precomputed argument. */
1603 precompute_arguments (int num_actuals
, struct arg_data
*args
)
1607 /* If this is a libcall, then precompute all arguments so that we do not
1608 get extraneous instructions emitted as part of the libcall sequence. */
1610 /* If we preallocated the stack space, and some arguments must be passed
1611 on the stack, then we must precompute any parameter which contains a
1612 function call which will store arguments on the stack.
1613 Otherwise, evaluating the parameter may clobber previous parameters
1614 which have already been stored into the stack. (we have code to avoid
1615 such case by saving the outgoing stack arguments, but it results in
1617 if (!ACCUMULATE_OUTGOING_ARGS
)
1620 for (i
= 0; i
< num_actuals
; i
++)
1625 if (TREE_CODE (args
[i
].tree_value
) != CALL_EXPR
)
1628 /* If this is an addressable type, we cannot pre-evaluate it. */
1629 type
= TREE_TYPE (args
[i
].tree_value
);
1630 gcc_assert (!TREE_ADDRESSABLE (type
));
1632 args
[i
].initial_value
= args
[i
].value
1633 = expand_normal (args
[i
].tree_value
);
1635 mode
= TYPE_MODE (type
);
1636 if (mode
!= args
[i
].mode
)
1638 int unsignedp
= args
[i
].unsignedp
;
1640 = convert_modes (args
[i
].mode
, mode
,
1641 args
[i
].value
, args
[i
].unsignedp
);
1643 /* CSE will replace this only if it contains args[i].value
1644 pseudo, so convert it down to the declared mode using
1646 if (REG_P (args
[i
].value
)
1647 && GET_MODE_CLASS (args
[i
].mode
) == MODE_INT
1648 && promote_mode (type
, mode
, &unsignedp
) != args
[i
].mode
)
1650 args
[i
].initial_value
1651 = gen_lowpart_SUBREG (mode
, args
[i
].value
);
1652 SUBREG_PROMOTED_VAR_P (args
[i
].initial_value
) = 1;
1653 SUBREG_PROMOTED_SET (args
[i
].initial_value
, args
[i
].unsignedp
);
1659 /* Given the current state of MUST_PREALLOCATE and information about
1660 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1661 compute and return the final value for MUST_PREALLOCATE. */
1664 finalize_must_preallocate (int must_preallocate
, int num_actuals
,
1665 struct arg_data
*args
, struct args_size
*args_size
)
1667 /* See if we have or want to preallocate stack space.
1669 If we would have to push a partially-in-regs parm
1670 before other stack parms, preallocate stack space instead.
1672 If the size of some parm is not a multiple of the required stack
1673 alignment, we must preallocate.
1675 If the total size of arguments that would otherwise create a copy in
1676 a temporary (such as a CALL) is more than half the total argument list
1677 size, preallocation is faster.
1679 Another reason to preallocate is if we have a machine (like the m88k)
1680 where stack alignment is required to be maintained between every
1681 pair of insns, not just when the call is made. However, we assume here
1682 that such machines either do not have push insns (and hence preallocation
1683 would occur anyway) or the problem is taken care of with
1686 if (! must_preallocate
)
1688 int partial_seen
= 0;
1689 int copy_to_evaluate_size
= 0;
1692 for (i
= 0; i
< num_actuals
&& ! must_preallocate
; i
++)
1694 if (args
[i
].partial
> 0 && ! args
[i
].pass_on_stack
)
1696 else if (partial_seen
&& args
[i
].reg
== 0)
1697 must_preallocate
= 1;
1698 /* We preallocate in case there are bounds passed
1699 in the bounds table to have precomputed address
1700 for bounds association. */
1701 else if (POINTER_BOUNDS_P (args
[i
].tree_value
)
1703 must_preallocate
= 1;
1705 if (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)) == BLKmode
1706 && (TREE_CODE (args
[i
].tree_value
) == CALL_EXPR
1707 || TREE_CODE (args
[i
].tree_value
) == TARGET_EXPR
1708 || TREE_CODE (args
[i
].tree_value
) == COND_EXPR
1709 || TREE_ADDRESSABLE (TREE_TYPE (args
[i
].tree_value
))))
1710 copy_to_evaluate_size
1711 += int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1714 if (copy_to_evaluate_size
* 2 >= args_size
->constant
1715 && args_size
->constant
> 0)
1716 must_preallocate
= 1;
1718 return must_preallocate
;
1721 /* If we preallocated stack space, compute the address of each argument
1722 and store it into the ARGS array.
1724 We need not ensure it is a valid memory address here; it will be
1725 validized when it is used.
1727 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1730 compute_argument_addresses (struct arg_data
*args
, rtx argblock
, int num_actuals
)
1734 rtx arg_reg
= argblock
;
1735 int i
, arg_offset
= 0;
1737 if (GET_CODE (argblock
) == PLUS
)
1738 arg_reg
= XEXP (argblock
, 0), arg_offset
= INTVAL (XEXP (argblock
, 1));
1740 for (i
= 0; i
< num_actuals
; i
++)
1742 rtx offset
= ARGS_SIZE_RTX (args
[i
].locate
.offset
);
1743 rtx slot_offset
= ARGS_SIZE_RTX (args
[i
].locate
.slot_offset
);
1745 unsigned int align
, boundary
;
1746 unsigned int units_on_stack
= 0;
1747 machine_mode partial_mode
= VOIDmode
;
1749 /* Skip this parm if it will not be passed on the stack. */
1750 if (! args
[i
].pass_on_stack
1752 && args
[i
].partial
== 0)
1755 /* Pointer Bounds are never passed on the stack. */
1756 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
1759 if (CONST_INT_P (offset
))
1760 addr
= plus_constant (Pmode
, arg_reg
, INTVAL (offset
));
1762 addr
= gen_rtx_PLUS (Pmode
, arg_reg
, offset
);
1764 addr
= plus_constant (Pmode
, addr
, arg_offset
);
1766 if (args
[i
].partial
!= 0)
1768 /* Only part of the parameter is being passed on the stack.
1769 Generate a simple memory reference of the correct size. */
1770 units_on_stack
= args
[i
].locate
.size
.constant
;
1771 partial_mode
= mode_for_size (units_on_stack
* BITS_PER_UNIT
,
1773 args
[i
].stack
= gen_rtx_MEM (partial_mode
, addr
);
1774 set_mem_size (args
[i
].stack
, units_on_stack
);
1778 args
[i
].stack
= gen_rtx_MEM (args
[i
].mode
, addr
);
1779 set_mem_attributes (args
[i
].stack
,
1780 TREE_TYPE (args
[i
].tree_value
), 1);
1782 align
= BITS_PER_UNIT
;
1783 boundary
= args
[i
].locate
.boundary
;
1784 if (args
[i
].locate
.where_pad
!= downward
)
1786 else if (CONST_INT_P (offset
))
1788 align
= INTVAL (offset
) * BITS_PER_UNIT
| boundary
;
1789 align
= align
& -align
;
1791 set_mem_align (args
[i
].stack
, align
);
1793 if (CONST_INT_P (slot_offset
))
1794 addr
= plus_constant (Pmode
, arg_reg
, INTVAL (slot_offset
));
1796 addr
= gen_rtx_PLUS (Pmode
, arg_reg
, slot_offset
);
1798 addr
= plus_constant (Pmode
, addr
, arg_offset
);
1800 if (args
[i
].partial
!= 0)
1802 /* Only part of the parameter is being passed on the stack.
1803 Generate a simple memory reference of the correct size.
1805 args
[i
].stack_slot
= gen_rtx_MEM (partial_mode
, addr
);
1806 set_mem_size (args
[i
].stack_slot
, units_on_stack
);
1810 args
[i
].stack_slot
= gen_rtx_MEM (args
[i
].mode
, addr
);
1811 set_mem_attributes (args
[i
].stack_slot
,
1812 TREE_TYPE (args
[i
].tree_value
), 1);
1814 set_mem_align (args
[i
].stack_slot
, args
[i
].locate
.boundary
);
1816 /* Function incoming arguments may overlap with sibling call
1817 outgoing arguments and we cannot allow reordering of reads
1818 from function arguments with stores to outgoing arguments
1819 of sibling calls. */
1820 set_mem_alias_set (args
[i
].stack
, 0);
1821 set_mem_alias_set (args
[i
].stack_slot
, 0);
1826 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1827 in a call instruction.
1829 FNDECL is the tree node for the target function. For an indirect call
1830 FNDECL will be NULL_TREE.
1832 ADDR is the operand 0 of CALL_EXPR for this call. */
1835 rtx_for_function_call (tree fndecl
, tree addr
)
1839 /* Get the function to call, in the form of RTL. */
1842 if (!TREE_USED (fndecl
) && fndecl
!= current_function_decl
)
1843 TREE_USED (fndecl
) = 1;
1845 /* Get a SYMBOL_REF rtx for the function address. */
1846 funexp
= XEXP (DECL_RTL (fndecl
), 0);
1849 /* Generate an rtx (probably a pseudo-register) for the address. */
1852 funexp
= expand_normal (addr
);
1853 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1858 /* Internal state for internal_arg_pointer_based_exp and its helpers. */
1861 /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan,
1862 or NULL_RTX if none has been scanned yet. */
1863 rtx_insn
*scan_start
;
1864 /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is
1865 based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the
1866 pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it
1867 with fixed offset, or PC if this is with variable or unknown offset. */
1869 } internal_arg_pointer_exp_state
;
1871 static rtx
internal_arg_pointer_based_exp (const_rtx
, bool);
1873 /* Helper function for internal_arg_pointer_based_exp. Scan insns in
1874 the tail call sequence, starting with first insn that hasn't been
1875 scanned yet, and note for each pseudo on the LHS whether it is based
1876 on crtl->args.internal_arg_pointer or not, and what offset from that
1877 that pointer it has. */
1880 internal_arg_pointer_based_exp_scan (void)
1882 rtx_insn
*insn
, *scan_start
= internal_arg_pointer_exp_state
.scan_start
;
1884 if (scan_start
== NULL_RTX
)
1885 insn
= get_insns ();
1887 insn
= NEXT_INSN (scan_start
);
1891 rtx set
= single_set (insn
);
1892 if (set
&& REG_P (SET_DEST (set
)) && !HARD_REGISTER_P (SET_DEST (set
)))
1895 unsigned int idx
= REGNO (SET_DEST (set
)) - FIRST_PSEUDO_REGISTER
;
1896 /* Punt on pseudos set multiple times. */
1897 if (idx
< internal_arg_pointer_exp_state
.cache
.length ()
1898 && (internal_arg_pointer_exp_state
.cache
[idx
]
1902 val
= internal_arg_pointer_based_exp (SET_SRC (set
), false);
1903 if (val
!= NULL_RTX
)
1905 if (idx
>= internal_arg_pointer_exp_state
.cache
.length ())
1906 internal_arg_pointer_exp_state
.cache
1907 .safe_grow_cleared (idx
+ 1);
1908 internal_arg_pointer_exp_state
.cache
[idx
] = val
;
1911 if (NEXT_INSN (insn
) == NULL_RTX
)
1913 insn
= NEXT_INSN (insn
);
1916 internal_arg_pointer_exp_state
.scan_start
= scan_start
;
1919 /* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return
1920 NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on
1921 it with fixed offset, or PC if this is with variable or unknown offset.
1922 TOPLEVEL is true if the function is invoked at the topmost level. */
1925 internal_arg_pointer_based_exp (const_rtx rtl
, bool toplevel
)
1927 if (CONSTANT_P (rtl
))
1930 if (rtl
== crtl
->args
.internal_arg_pointer
)
1933 if (REG_P (rtl
) && HARD_REGISTER_P (rtl
))
1936 if (GET_CODE (rtl
) == PLUS
&& CONST_INT_P (XEXP (rtl
, 1)))
1938 rtx val
= internal_arg_pointer_based_exp (XEXP (rtl
, 0), toplevel
);
1939 if (val
== NULL_RTX
|| val
== pc_rtx
)
1941 return plus_constant (Pmode
, val
, INTVAL (XEXP (rtl
, 1)));
1944 /* When called at the topmost level, scan pseudo assignments in between the
1945 last scanned instruction in the tail call sequence and the latest insn
1946 in that sequence. */
1948 internal_arg_pointer_based_exp_scan ();
1952 unsigned int idx
= REGNO (rtl
) - FIRST_PSEUDO_REGISTER
;
1953 if (idx
< internal_arg_pointer_exp_state
.cache
.length ())
1954 return internal_arg_pointer_exp_state
.cache
[idx
];
1959 subrtx_iterator::array_type array
;
1960 FOR_EACH_SUBRTX (iter
, array
, rtl
, NONCONST
)
1962 const_rtx x
= *iter
;
1963 if (REG_P (x
) && internal_arg_pointer_based_exp (x
, false) != NULL_RTX
)
1966 iter
.skip_subrtxes ();
1972 /* Return true if and only if SIZE storage units (usually bytes)
1973 starting from address ADDR overlap with already clobbered argument
1974 area. This function is used to determine if we should give up a
1978 mem_overlaps_already_clobbered_arg_p (rtx addr
, unsigned HOST_WIDE_INT size
)
1983 if (bitmap_empty_p (stored_args_map
))
1985 val
= internal_arg_pointer_based_exp (addr
, true);
1986 if (val
== NULL_RTX
)
1988 else if (val
== pc_rtx
)
1993 if (STACK_GROWS_DOWNWARD
)
1994 i
-= crtl
->args
.pretend_args_size
;
1996 i
+= crtl
->args
.pretend_args_size
;
1999 if (ARGS_GROW_DOWNWARD
)
2004 unsigned HOST_WIDE_INT k
;
2006 for (k
= 0; k
< size
; k
++)
2007 if (i
+ k
< SBITMAP_SIZE (stored_args_map
)
2008 && bitmap_bit_p (stored_args_map
, i
+ k
))
2015 /* Do the register loads required for any wholly-register parms or any
2016 parms which are passed both on the stack and in a register. Their
2017 expressions were already evaluated.
2019 Mark all register-parms as living through the call, putting these USE
2020 insns in the CALL_INSN_FUNCTION_USAGE field.
2022 When IS_SIBCALL, perform the check_sibcall_argument_overlap
2023 checking, setting *SIBCALL_FAILURE if appropriate. */
2026 load_register_parameters (struct arg_data
*args
, int num_actuals
,
2027 rtx
*call_fusage
, int flags
, int is_sibcall
,
2028 int *sibcall_failure
)
2032 for (i
= 0; i
< num_actuals
; i
++)
2034 rtx reg
= ((flags
& ECF_SIBCALL
)
2035 ? args
[i
].tail_call_reg
: args
[i
].reg
);
2038 int partial
= args
[i
].partial
;
2041 rtx_insn
*before_arg
= get_last_insn ();
2042 /* Set non-negative if we must move a word at a time, even if
2043 just one word (e.g, partial == 4 && mode == DFmode). Set
2044 to -1 if we just use a normal move insn. This value can be
2045 zero if the argument is a zero size structure. */
2047 if (GET_CODE (reg
) == PARALLEL
)
2051 gcc_assert (partial
% UNITS_PER_WORD
== 0);
2052 nregs
= partial
/ UNITS_PER_WORD
;
2054 else if (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)) == BLKmode
)
2056 size
= int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
2057 nregs
= (size
+ (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
2060 size
= GET_MODE_SIZE (args
[i
].mode
);
2062 /* Handle calls that pass values in multiple non-contiguous
2063 locations. The Irix 6 ABI has examples of this. */
2065 if (GET_CODE (reg
) == PARALLEL
)
2066 emit_group_move (reg
, args
[i
].parallel_value
);
2068 /* If simple case, just do move. If normal partial, store_one_arg
2069 has already loaded the register for us. In all other cases,
2070 load the register(s) from memory. */
2072 else if (nregs
== -1)
2074 emit_move_insn (reg
, args
[i
].value
);
2075 #ifdef BLOCK_REG_PADDING
2076 /* Handle case where we have a value that needs shifting
2077 up to the msb. eg. a QImode value and we're padding
2078 upward on a BYTES_BIG_ENDIAN machine. */
2079 if (size
< UNITS_PER_WORD
2080 && (args
[i
].locate
.where_pad
2081 == (BYTES_BIG_ENDIAN
? upward
: downward
)))
2084 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
2086 /* Assigning REG here rather than a temp makes CALL_FUSAGE
2087 report the whole reg as used. Strictly speaking, the
2088 call only uses SIZE bytes at the msb end, but it doesn't
2089 seem worth generating rtl to say that. */
2090 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
2091 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, shift
, reg
, 1);
2093 emit_move_insn (reg
, x
);
2098 /* If we have pre-computed the values to put in the registers in
2099 the case of non-aligned structures, copy them in now. */
2101 else if (args
[i
].n_aligned_regs
!= 0)
2102 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
2103 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
) + j
),
2104 args
[i
].aligned_regs
[j
]);
2106 else if (partial
== 0 || args
[i
].pass_on_stack
)
2108 rtx mem
= validize_mem (copy_rtx (args
[i
].value
));
2110 /* Check for overlap with already clobbered argument area,
2111 providing that this has non-zero size. */
2114 || mem_overlaps_already_clobbered_arg_p
2115 (XEXP (args
[i
].value
, 0), size
)))
2116 *sibcall_failure
= 1;
2118 if (size
% UNITS_PER_WORD
== 0
2119 || MEM_ALIGN (mem
) % BITS_PER_WORD
== 0)
2120 move_block_to_reg (REGNO (reg
), mem
, nregs
, args
[i
].mode
);
2124 move_block_to_reg (REGNO (reg
), mem
, nregs
- 1,
2126 rtx dest
= gen_rtx_REG (word_mode
, REGNO (reg
) + nregs
- 1);
2127 unsigned int bitoff
= (nregs
- 1) * BITS_PER_WORD
;
2128 unsigned int bitsize
= size
* BITS_PER_UNIT
- bitoff
;
2129 rtx x
= extract_bit_field (mem
, bitsize
, bitoff
, 1,
2130 dest
, word_mode
, word_mode
);
2131 if (BYTES_BIG_ENDIAN
)
2132 x
= expand_shift (LSHIFT_EXPR
, word_mode
, x
,
2133 BITS_PER_WORD
- bitsize
, dest
, 1);
2135 emit_move_insn (dest
, x
);
2138 /* Handle a BLKmode that needs shifting. */
2139 if (nregs
== 1 && size
< UNITS_PER_WORD
2140 #ifdef BLOCK_REG_PADDING
2141 && args
[i
].locate
.where_pad
== downward
2147 rtx dest
= gen_rtx_REG (word_mode
, REGNO (reg
));
2148 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
2149 enum tree_code dir
= (BYTES_BIG_ENDIAN
2150 ? RSHIFT_EXPR
: LSHIFT_EXPR
);
2153 x
= expand_shift (dir
, word_mode
, dest
, shift
, dest
, 1);
2155 emit_move_insn (dest
, x
);
2159 /* When a parameter is a block, and perhaps in other cases, it is
2160 possible that it did a load from an argument slot that was
2161 already clobbered. */
2163 && check_sibcall_argument_overlap (before_arg
, &args
[i
], 0))
2164 *sibcall_failure
= 1;
2166 /* Handle calls that pass values in multiple non-contiguous
2167 locations. The Irix 6 ABI has examples of this. */
2168 if (GET_CODE (reg
) == PARALLEL
)
2169 use_group_regs (call_fusage
, reg
);
2170 else if (nregs
== -1)
2171 use_reg_mode (call_fusage
, reg
,
2172 TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)));
2174 use_regs (call_fusage
, REGNO (reg
), nregs
);
2179 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
2180 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
2181 bytes, then we would need to push some additional bytes to pad the
2182 arguments. So, we compute an adjust to the stack pointer for an
2183 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
2184 bytes. Then, when the arguments are pushed the stack will be perfectly
2185 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
2186 be popped after the call. Returns the adjustment. */
2189 combine_pending_stack_adjustment_and_call (int unadjusted_args_size
,
2190 struct args_size
*args_size
,
2191 unsigned int preferred_unit_stack_boundary
)
2193 /* The number of bytes to pop so that the stack will be
2194 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
2195 HOST_WIDE_INT adjustment
;
2196 /* The alignment of the stack after the arguments are pushed, if we
2197 just pushed the arguments without adjust the stack here. */
2198 unsigned HOST_WIDE_INT unadjusted_alignment
;
2200 unadjusted_alignment
2201 = ((stack_pointer_delta
+ unadjusted_args_size
)
2202 % preferred_unit_stack_boundary
);
2204 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
2205 as possible -- leaving just enough left to cancel out the
2206 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
2207 PENDING_STACK_ADJUST is non-negative, and congruent to
2208 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
2210 /* Begin by trying to pop all the bytes. */
2211 unadjusted_alignment
2212 = (unadjusted_alignment
2213 - (pending_stack_adjust
% preferred_unit_stack_boundary
));
2214 adjustment
= pending_stack_adjust
;
2215 /* Push enough additional bytes that the stack will be aligned
2216 after the arguments are pushed. */
2217 if (preferred_unit_stack_boundary
> 1)
2219 if (unadjusted_alignment
> 0)
2220 adjustment
-= preferred_unit_stack_boundary
- unadjusted_alignment
;
2222 adjustment
+= unadjusted_alignment
;
2225 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
2226 bytes after the call. The right number is the entire
2227 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
2228 by the arguments in the first place. */
2230 = pending_stack_adjust
- adjustment
+ unadjusted_args_size
;
2235 /* Scan X expression if it does not dereference any argument slots
2236 we already clobbered by tail call arguments (as noted in stored_args_map
2238 Return nonzero if X expression dereferences such argument slots,
2242 check_sibcall_argument_overlap_1 (rtx x
)
2251 code
= GET_CODE (x
);
2253 /* We need not check the operands of the CALL expression itself. */
2258 return mem_overlaps_already_clobbered_arg_p (XEXP (x
, 0),
2259 GET_MODE_SIZE (GET_MODE (x
)));
2261 /* Scan all subexpressions. */
2262 fmt
= GET_RTX_FORMAT (code
);
2263 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
2267 if (check_sibcall_argument_overlap_1 (XEXP (x
, i
)))
2270 else if (*fmt
== 'E')
2272 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2273 if (check_sibcall_argument_overlap_1 (XVECEXP (x
, i
, j
)))
2280 /* Scan sequence after INSN if it does not dereference any argument slots
2281 we already clobbered by tail call arguments (as noted in stored_args_map
2282 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
2283 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
2284 should be 0). Return nonzero if sequence after INSN dereferences such argument
2285 slots, zero otherwise. */
2288 check_sibcall_argument_overlap (rtx_insn
*insn
, struct arg_data
*arg
,
2289 int mark_stored_args_map
)
2293 if (insn
== NULL_RTX
)
2294 insn
= get_insns ();
2296 insn
= NEXT_INSN (insn
);
2298 for (; insn
; insn
= NEXT_INSN (insn
))
2300 && check_sibcall_argument_overlap_1 (PATTERN (insn
)))
2303 if (mark_stored_args_map
)
2305 if (ARGS_GROW_DOWNWARD
)
2306 low
= -arg
->locate
.slot_offset
.constant
- arg
->locate
.size
.constant
;
2308 low
= arg
->locate
.slot_offset
.constant
;
2310 for (high
= low
+ arg
->locate
.size
.constant
; low
< high
; low
++)
2311 bitmap_set_bit (stored_args_map
, low
);
2313 return insn
!= NULL_RTX
;
2316 /* Given that a function returns a value of mode MODE at the most
2317 significant end of hard register VALUE, shift VALUE left or right
2318 as specified by LEFT_P. Return true if some action was needed. */
2321 shift_return_value (machine_mode mode
, bool left_p
, rtx value
)
2323 HOST_WIDE_INT shift
;
2325 gcc_assert (REG_P (value
) && HARD_REGISTER_P (value
));
2326 shift
= GET_MODE_BITSIZE (GET_MODE (value
)) - GET_MODE_BITSIZE (mode
);
2330 /* Use ashr rather than lshr for right shifts. This is for the benefit
2331 of the MIPS port, which requires SImode values to be sign-extended
2332 when stored in 64-bit registers. */
2333 if (!force_expand_binop (GET_MODE (value
), left_p
? ashl_optab
: ashr_optab
,
2334 value
, GEN_INT (shift
), value
, 1, OPTAB_WIDEN
))
2339 /* If X is a likely-spilled register value, copy it to a pseudo
2340 register and return that register. Return X otherwise. */
2343 avoid_likely_spilled_reg (rtx x
)
2348 && HARD_REGISTER_P (x
)
2349 && targetm
.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x
))))
2351 /* Make sure that we generate a REG rather than a CONCAT.
2352 Moves into CONCATs can need nontrivial instructions,
2353 and the whole point of this function is to avoid
2354 using the hard register directly in such a situation. */
2355 generating_concat_p
= 0;
2356 new_rtx
= gen_reg_rtx (GET_MODE (x
));
2357 generating_concat_p
= 1;
2358 emit_move_insn (new_rtx
, x
);
2364 /* Generate all the code for a CALL_EXPR exp
2365 and return an rtx for its value.
2366 Store the value in TARGET (specified as an rtx) if convenient.
2367 If the value is stored in TARGET then TARGET is returned.
2368 If IGNORE is nonzero, then we ignore the value of the function call. */
2371 expand_call (tree exp
, rtx target
, int ignore
)
2373 /* Nonzero if we are currently expanding a call. */
2374 static int currently_expanding_call
= 0;
2376 /* RTX for the function to be called. */
2378 /* Sequence of insns to perform a normal "call". */
2379 rtx_insn
*normal_call_insns
= NULL
;
2380 /* Sequence of insns to perform a tail "call". */
2381 rtx_insn
*tail_call_insns
= NULL
;
2382 /* Data type of the function. */
2384 tree type_arg_types
;
2386 /* Declaration of the function being called,
2387 or 0 if the function is computed (not known by name). */
2389 /* The type of the function being called. */
2391 bool try_tail_call
= CALL_EXPR_TAILCALL (exp
);
2394 /* Register in which non-BLKmode value will be returned,
2395 or 0 if no value or if value is BLKmode. */
2397 /* Register(s) in which bounds are returned. */
2399 /* Address where we should return a BLKmode value;
2400 0 if value not BLKmode. */
2401 rtx structure_value_addr
= 0;
2402 /* Nonzero if that address is being passed by treating it as
2403 an extra, implicit first parameter. Otherwise,
2404 it is passed by being copied directly into struct_value_rtx. */
2405 int structure_value_addr_parm
= 0;
2406 /* Holds the value of implicit argument for the struct value. */
2407 tree structure_value_addr_value
= NULL_TREE
;
2408 /* Size of aggregate value wanted, or zero if none wanted
2409 or if we are using the non-reentrant PCC calling convention
2410 or expecting the value in registers. */
2411 HOST_WIDE_INT struct_value_size
= 0;
2412 /* Nonzero if called function returns an aggregate in memory PCC style,
2413 by returning the address of where to find it. */
2414 int pcc_struct_value
= 0;
2415 rtx struct_value
= 0;
2417 /* Number of actual parameters in this call, including struct value addr. */
2419 /* Number of named args. Args after this are anonymous ones
2420 and they must all go on the stack. */
2422 /* Number of complex actual arguments that need to be split. */
2423 int num_complex_actuals
= 0;
2425 /* Vector of information about each argument.
2426 Arguments are numbered in the order they will be pushed,
2427 not the order they are written. */
2428 struct arg_data
*args
;
2430 /* Total size in bytes of all the stack-parms scanned so far. */
2431 struct args_size args_size
;
2432 struct args_size adjusted_args_size
;
2433 /* Size of arguments before any adjustments (such as rounding). */
2434 int unadjusted_args_size
;
2435 /* Data on reg parms scanned so far. */
2436 CUMULATIVE_ARGS args_so_far_v
;
2437 cumulative_args_t args_so_far
;
2438 /* Nonzero if a reg parm has been scanned. */
2440 /* Nonzero if this is an indirect function call. */
2442 /* Nonzero if we must avoid push-insns in the args for this call.
2443 If stack space is allocated for register parameters, but not by the
2444 caller, then it is preallocated in the fixed part of the stack frame.
2445 So the entire argument block must then be preallocated (i.e., we
2446 ignore PUSH_ROUNDING in that case). */
2448 int must_preallocate
= !PUSH_ARGS
;
2450 /* Size of the stack reserved for parameter registers. */
2451 int reg_parm_stack_space
= 0;
2453 /* Address of space preallocated for stack parms
2454 (on machines that lack push insns), or 0 if space not preallocated. */
2457 /* Mask of ECF_ and ERF_ flags. */
2459 int return_flags
= 0;
2460 #ifdef REG_PARM_STACK_SPACE
2461 /* Define the boundary of the register parm stack space that needs to be
2463 int low_to_save
, high_to_save
;
2464 rtx save_area
= 0; /* Place that it is saved */
2467 int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
2468 char *initial_stack_usage_map
= stack_usage_map
;
2469 char *stack_usage_map_buf
= NULL
;
2471 int old_stack_allocated
;
2473 /* State variables to track stack modifications. */
2474 rtx old_stack_level
= 0;
2475 int old_stack_arg_under_construction
= 0;
2476 int old_pending_adj
= 0;
2477 int old_inhibit_defer_pop
= inhibit_defer_pop
;
2479 /* Some stack pointer alterations we make are performed via
2480 allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
2481 which we then also need to save/restore along the way. */
2482 int old_stack_pointer_delta
= 0;
2485 tree addr
= CALL_EXPR_FN (exp
);
2487 /* The alignment of the stack, in bits. */
2488 unsigned HOST_WIDE_INT preferred_stack_boundary
;
2489 /* The alignment of the stack, in bytes. */
2490 unsigned HOST_WIDE_INT preferred_unit_stack_boundary
;
2491 /* The static chain value to use for this call. */
2492 rtx static_chain_value
;
2493 /* See if this is "nothrow" function call. */
2494 if (TREE_NOTHROW (exp
))
2495 flags
|= ECF_NOTHROW
;
2497 /* See if we can find a DECL-node for the actual function, and get the
2498 function attributes (flags) from the function decl or type node. */
2499 fndecl
= get_callee_fndecl (exp
);
2502 fntype
= TREE_TYPE (fndecl
);
2503 flags
|= flags_from_decl_or_type (fndecl
);
2504 return_flags
|= decl_return_flags (fndecl
);
2508 fntype
= TREE_TYPE (TREE_TYPE (addr
));
2509 flags
|= flags_from_decl_or_type (fntype
);
2511 rettype
= TREE_TYPE (exp
);
2513 struct_value
= targetm
.calls
.struct_value_rtx (fntype
, 0);
2515 /* Warn if this value is an aggregate type,
2516 regardless of which calling convention we are using for it. */
2517 if (AGGREGATE_TYPE_P (rettype
))
2518 warning (OPT_Waggregate_return
, "function call has aggregate value");
2520 /* If the result of a non looping pure or const function call is
2521 ignored (or void), and none of its arguments are volatile, we can
2522 avoid expanding the call and just evaluate the arguments for
2524 if ((flags
& (ECF_CONST
| ECF_PURE
))
2525 && (!(flags
& ECF_LOOPING_CONST_OR_PURE
))
2526 && (ignore
|| target
== const0_rtx
2527 || TYPE_MODE (rettype
) == VOIDmode
))
2529 bool volatilep
= false;
2531 call_expr_arg_iterator iter
;
2533 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2534 if (TREE_THIS_VOLATILE (arg
))
2542 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2543 expand_expr (arg
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
2548 #ifdef REG_PARM_STACK_SPACE
2549 reg_parm_stack_space
= REG_PARM_STACK_SPACE (!fndecl
? fntype
: fndecl
);
2552 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
)))
2553 && reg_parm_stack_space
> 0 && PUSH_ARGS
)
2554 must_preallocate
= 1;
2556 /* Set up a place to return a structure. */
2558 /* Cater to broken compilers. */
2559 if (aggregate_value_p (exp
, fntype
))
2561 /* This call returns a big structure. */
2562 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
2564 #ifdef PCC_STATIC_STRUCT_RETURN
2566 pcc_struct_value
= 1;
2568 #else /* not PCC_STATIC_STRUCT_RETURN */
2570 struct_value_size
= int_size_in_bytes (rettype
);
2572 /* Even if it is semantically safe to use the target as the return
2573 slot, it may be not sufficiently aligned for the return type. */
2574 if (CALL_EXPR_RETURN_SLOT_OPT (exp
)
2577 && !(MEM_ALIGN (target
) < TYPE_ALIGN (rettype
)
2578 && SLOW_UNALIGNED_ACCESS (TYPE_MODE (rettype
),
2579 MEM_ALIGN (target
))))
2580 structure_value_addr
= XEXP (target
, 0);
2583 /* For variable-sized objects, we must be called with a target
2584 specified. If we were to allocate space on the stack here,
2585 we would have no way of knowing when to free it. */
2586 rtx d
= assign_temp (rettype
, 1, 1);
2587 structure_value_addr
= XEXP (d
, 0);
2591 #endif /* not PCC_STATIC_STRUCT_RETURN */
2594 /* Figure out the amount to which the stack should be aligned. */
2595 preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
2598 struct cgraph_rtl_info
*i
= cgraph_node::rtl_info (fndecl
);
2599 /* Without automatic stack alignment, we can't increase preferred
2600 stack boundary. With automatic stack alignment, it is
2601 unnecessary since unless we can guarantee that all callers will
2602 align the outgoing stack properly, callee has to align its
2605 && i
->preferred_incoming_stack_boundary
2606 && i
->preferred_incoming_stack_boundary
< preferred_stack_boundary
)
2607 preferred_stack_boundary
= i
->preferred_incoming_stack_boundary
;
2610 /* Operand 0 is a pointer-to-function; get the type of the function. */
2611 funtype
= TREE_TYPE (addr
);
2612 gcc_assert (POINTER_TYPE_P (funtype
));
2613 funtype
= TREE_TYPE (funtype
);
2615 /* Count whether there are actual complex arguments that need to be split
2616 into their real and imaginary parts. Munge the type_arg_types
2617 appropriately here as well. */
2618 if (targetm
.calls
.split_complex_arg
)
2620 call_expr_arg_iterator iter
;
2622 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2624 tree type
= TREE_TYPE (arg
);
2625 if (type
&& TREE_CODE (type
) == COMPLEX_TYPE
2626 && targetm
.calls
.split_complex_arg (type
))
2627 num_complex_actuals
++;
2629 type_arg_types
= split_complex_types (TYPE_ARG_TYPES (funtype
));
2632 type_arg_types
= TYPE_ARG_TYPES (funtype
);
2634 if (flags
& ECF_MAY_BE_ALLOCA
)
2635 cfun
->calls_alloca
= 1;
2637 /* If struct_value_rtx is 0, it means pass the address
2638 as if it were an extra parameter. Put the argument expression
2639 in structure_value_addr_value. */
2640 if (structure_value_addr
&& struct_value
== 0)
2642 /* If structure_value_addr is a REG other than
2643 virtual_outgoing_args_rtx, we can use always use it. If it
2644 is not a REG, we must always copy it into a register.
2645 If it is virtual_outgoing_args_rtx, we must copy it to another
2646 register in some cases. */
2647 rtx temp
= (!REG_P (structure_value_addr
)
2648 || (ACCUMULATE_OUTGOING_ARGS
2649 && stack_arg_under_construction
2650 && structure_value_addr
== virtual_outgoing_args_rtx
)
2651 ? copy_addr_to_reg (convert_memory_address
2652 (Pmode
, structure_value_addr
))
2653 : structure_value_addr
);
2655 structure_value_addr_value
=
2656 make_tree (build_pointer_type (TREE_TYPE (funtype
)), temp
);
2657 structure_value_addr_parm
= CALL_WITH_BOUNDS_P (exp
) ? 2 : 1;
2660 /* Count the arguments and set NUM_ACTUALS. */
2662 call_expr_nargs (exp
) + num_complex_actuals
+ structure_value_addr_parm
;
2664 /* Compute number of named args.
2665 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2667 if (type_arg_types
!= 0)
2669 = (list_length (type_arg_types
)
2670 /* Count the struct value address, if it is passed as a parm. */
2671 + structure_value_addr_parm
);
2673 /* If we know nothing, treat all args as named. */
2674 n_named_args
= num_actuals
;
2676 /* Start updating where the next arg would go.
2678 On some machines (such as the PA) indirect calls have a different
2679 calling convention than normal calls. The fourth argument in
2680 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2682 INIT_CUMULATIVE_ARGS (args_so_far_v
, funtype
, NULL_RTX
, fndecl
, n_named_args
);
2683 args_so_far
= pack_cumulative_args (&args_so_far_v
);
2685 /* Now possibly adjust the number of named args.
2686 Normally, don't include the last named arg if anonymous args follow.
2687 We do include the last named arg if
2688 targetm.calls.strict_argument_naming() returns nonzero.
2689 (If no anonymous args follow, the result of list_length is actually
2690 one too large. This is harmless.)
2692 If targetm.calls.pretend_outgoing_varargs_named() returns
2693 nonzero, and targetm.calls.strict_argument_naming() returns zero,
2694 this machine will be able to place unnamed args that were passed
2695 in registers into the stack. So treat all args as named. This
2696 allows the insns emitting for a specific argument list to be
2697 independent of the function declaration.
2699 If targetm.calls.pretend_outgoing_varargs_named() returns zero,
2700 we do not have any reliable way to pass unnamed args in
2701 registers, so we must force them into memory. */
2703 if (type_arg_types
!= 0
2704 && targetm
.calls
.strict_argument_naming (args_so_far
))
2706 else if (type_arg_types
!= 0
2707 && ! targetm
.calls
.pretend_outgoing_varargs_named (args_so_far
))
2708 /* Don't include the last named arg. */
2711 /* Treat all args as named. */
2712 n_named_args
= num_actuals
;
2714 /* Make a vector to hold all the information about each arg. */
2715 args
= XALLOCAVEC (struct arg_data
, num_actuals
);
2716 memset (args
, 0, num_actuals
* sizeof (struct arg_data
));
2718 /* Build up entries in the ARGS array, compute the size of the
2719 arguments into ARGS_SIZE, etc. */
2720 initialize_argument_information (num_actuals
, args
, &args_size
,
2722 structure_value_addr_value
, fndecl
, fntype
,
2723 args_so_far
, reg_parm_stack_space
,
2724 &old_stack_level
, &old_pending_adj
,
2725 &must_preallocate
, &flags
,
2726 &try_tail_call
, CALL_FROM_THUNK_P (exp
));
2729 must_preallocate
= 1;
2731 /* Now make final decision about preallocating stack space. */
2732 must_preallocate
= finalize_must_preallocate (must_preallocate
,
2736 /* If the structure value address will reference the stack pointer, we
2737 must stabilize it. We don't need to do this if we know that we are
2738 not going to adjust the stack pointer in processing this call. */
2740 if (structure_value_addr
2741 && (reg_mentioned_p (virtual_stack_dynamic_rtx
, structure_value_addr
)
2742 || reg_mentioned_p (virtual_outgoing_args_rtx
,
2743 structure_value_addr
))
2745 || (!ACCUMULATE_OUTGOING_ARGS
&& args_size
.constant
)))
2746 structure_value_addr
= copy_to_reg (structure_value_addr
);
2748 /* Tail calls can make things harder to debug, and we've traditionally
2749 pushed these optimizations into -O2. Don't try if we're already
2750 expanding a call, as that means we're an argument. Don't try if
2751 there's cleanups, as we know there's code to follow the call. */
2753 if (currently_expanding_call
++ != 0
2754 || !flag_optimize_sibling_calls
2756 || dbg_cnt (tail_call
) == false)
2759 /* Rest of purposes for tail call optimizations to fail. */
2761 #ifdef HAVE_sibcall_epilogue
2762 !HAVE_sibcall_epilogue
2767 /* Doing sibling call optimization needs some work, since
2768 structure_value_addr can be allocated on the stack.
2769 It does not seem worth the effort since few optimizable
2770 sibling calls will return a structure. */
2771 || structure_value_addr
!= NULL_RTX
2772 #ifdef REG_PARM_STACK_SPACE
2773 /* If outgoing reg parm stack space changes, we can not do sibcall. */
2774 || (OUTGOING_REG_PARM_STACK_SPACE (funtype
)
2775 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl
)))
2776 || (reg_parm_stack_space
!= REG_PARM_STACK_SPACE (current_function_decl
))
2778 /* Check whether the target is able to optimize the call
2780 || !targetm
.function_ok_for_sibcall (fndecl
, exp
)
2781 /* Functions that do not return exactly once may not be sibcall
2783 || (flags
& (ECF_RETURNS_TWICE
| ECF_NORETURN
))
2784 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr
)))
2785 /* If the called function is nested in the current one, it might access
2786 some of the caller's arguments, but could clobber them beforehand if
2787 the argument areas are shared. */
2788 || (fndecl
&& decl_function_context (fndecl
) == current_function_decl
)
2789 /* If this function requires more stack slots than the current
2790 function, we cannot change it into a sibling call.
2791 crtl->args.pretend_args_size is not part of the
2792 stack allocated by our caller. */
2793 || args_size
.constant
> (crtl
->args
.size
2794 - crtl
->args
.pretend_args_size
)
2795 /* If the callee pops its own arguments, then it must pop exactly
2796 the same number of arguments as the current function. */
2797 || (targetm
.calls
.return_pops_args (fndecl
, funtype
, args_size
.constant
)
2798 != targetm
.calls
.return_pops_args (current_function_decl
,
2799 TREE_TYPE (current_function_decl
),
2801 || !lang_hooks
.decls
.ok_for_sibcall (fndecl
))
2804 /* Check if caller and callee disagree in promotion of function
2808 machine_mode caller_mode
, caller_promoted_mode
;
2809 machine_mode callee_mode
, callee_promoted_mode
;
2810 int caller_unsignedp
, callee_unsignedp
;
2811 tree caller_res
= DECL_RESULT (current_function_decl
);
2813 caller_unsignedp
= TYPE_UNSIGNED (TREE_TYPE (caller_res
));
2814 caller_mode
= DECL_MODE (caller_res
);
2815 callee_unsignedp
= TYPE_UNSIGNED (TREE_TYPE (funtype
));
2816 callee_mode
= TYPE_MODE (TREE_TYPE (funtype
));
2817 caller_promoted_mode
2818 = promote_function_mode (TREE_TYPE (caller_res
), caller_mode
,
2820 TREE_TYPE (current_function_decl
), 1);
2821 callee_promoted_mode
2822 = promote_function_mode (TREE_TYPE (funtype
), callee_mode
,
2825 if (caller_mode
!= VOIDmode
2826 && (caller_promoted_mode
!= callee_promoted_mode
2827 || ((caller_mode
!= caller_promoted_mode
2828 || callee_mode
!= callee_promoted_mode
)
2829 && (caller_unsignedp
!= callee_unsignedp
2830 || GET_MODE_BITSIZE (caller_mode
)
2831 < GET_MODE_BITSIZE (callee_mode
)))))
2835 /* Ensure current function's preferred stack boundary is at least
2836 what we need. Stack alignment may also increase preferred stack
2838 if (crtl
->preferred_stack_boundary
< preferred_stack_boundary
)
2839 crtl
->preferred_stack_boundary
= preferred_stack_boundary
;
2841 preferred_stack_boundary
= crtl
->preferred_stack_boundary
;
2843 preferred_unit_stack_boundary
= preferred_stack_boundary
/ BITS_PER_UNIT
;
2845 /* We want to make two insn chains; one for a sibling call, the other
2846 for a normal call. We will select one of the two chains after
2847 initial RTL generation is complete. */
2848 for (pass
= try_tail_call
? 0 : 1; pass
< 2; pass
++)
2850 int sibcall_failure
= 0;
2851 /* We want to emit any pending stack adjustments before the tail
2852 recursion "call". That way we know any adjustment after the tail
2853 recursion call can be ignored if we indeed use the tail
2855 saved_pending_stack_adjust save
;
2856 rtx_insn
*insns
, *before_call
, *after_args
;
2861 /* State variables we need to save and restore between
2863 save_pending_stack_adjust (&save
);
2866 flags
&= ~ECF_SIBCALL
;
2868 flags
|= ECF_SIBCALL
;
2870 /* Other state variables that we must reinitialize each time
2871 through the loop (that are not initialized by the loop itself). */
2875 /* Start a new sequence for the normal call case.
2877 From this point on, if the sibling call fails, we want to set
2878 sibcall_failure instead of continuing the loop. */
2881 /* Don't let pending stack adjusts add up to too much.
2882 Also, do all pending adjustments now if there is any chance
2883 this might be a call to alloca or if we are expanding a sibling
2885 Also do the adjustments before a throwing call, otherwise
2886 exception handling can fail; PR 19225. */
2887 if (pending_stack_adjust
>= 32
2888 || (pending_stack_adjust
> 0
2889 && (flags
& ECF_MAY_BE_ALLOCA
))
2890 || (pending_stack_adjust
> 0
2891 && flag_exceptions
&& !(flags
& ECF_NOTHROW
))
2893 do_pending_stack_adjust ();
2895 /* Precompute any arguments as needed. */
2897 precompute_arguments (num_actuals
, args
);
2899 /* Now we are about to start emitting insns that can be deleted
2900 if a libcall is deleted. */
2901 if (pass
&& (flags
& ECF_MALLOC
))
2904 if (pass
== 0 && crtl
->stack_protect_guard
)
2905 stack_protect_epilogue ();
2907 adjusted_args_size
= args_size
;
2908 /* Compute the actual size of the argument block required. The variable
2909 and constant sizes must be combined, the size may have to be rounded,
2910 and there may be a minimum required size. When generating a sibcall
2911 pattern, do not round up, since we'll be re-using whatever space our
2913 unadjusted_args_size
2914 = compute_argument_block_size (reg_parm_stack_space
,
2915 &adjusted_args_size
,
2918 : preferred_stack_boundary
));
2920 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
2922 /* The argument block when performing a sibling call is the
2923 incoming argument block. */
2926 argblock
= crtl
->args
.internal_arg_pointer
;
2927 if (STACK_GROWS_DOWNWARD
)
2929 = plus_constant (Pmode
, argblock
, crtl
->args
.pretend_args_size
);
2932 = plus_constant (Pmode
, argblock
, -crtl
->args
.pretend_args_size
);
2934 stored_args_map
= sbitmap_alloc (args_size
.constant
);
2935 bitmap_clear (stored_args_map
);
2938 /* If we have no actual push instructions, or shouldn't use them,
2939 make space for all args right now. */
2940 else if (adjusted_args_size
.var
!= 0)
2942 if (old_stack_level
== 0)
2944 emit_stack_save (SAVE_BLOCK
, &old_stack_level
);
2945 old_stack_pointer_delta
= stack_pointer_delta
;
2946 old_pending_adj
= pending_stack_adjust
;
2947 pending_stack_adjust
= 0;
2948 /* stack_arg_under_construction says whether a stack arg is
2949 being constructed at the old stack level. Pushing the stack
2950 gets a clean outgoing argument block. */
2951 old_stack_arg_under_construction
= stack_arg_under_construction
;
2952 stack_arg_under_construction
= 0;
2954 argblock
= push_block (ARGS_SIZE_RTX (adjusted_args_size
), 0, 0);
2955 if (flag_stack_usage_info
)
2956 current_function_has_unbounded_dynamic_stack_size
= 1;
2960 /* Note that we must go through the motions of allocating an argument
2961 block even if the size is zero because we may be storing args
2962 in the area reserved for register arguments, which may be part of
2965 int needed
= adjusted_args_size
.constant
;
2967 /* Store the maximum argument space used. It will be pushed by
2968 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2971 if (needed
> crtl
->outgoing_args_size
)
2972 crtl
->outgoing_args_size
= needed
;
2974 if (must_preallocate
)
2976 if (ACCUMULATE_OUTGOING_ARGS
)
2978 /* Since the stack pointer will never be pushed, it is
2979 possible for the evaluation of a parm to clobber
2980 something we have already written to the stack.
2981 Since most function calls on RISC machines do not use
2982 the stack, this is uncommon, but must work correctly.
2984 Therefore, we save any area of the stack that was already
2985 written and that we are using. Here we set up to do this
2986 by making a new stack usage map from the old one. The
2987 actual save will be done by store_one_arg.
2989 Another approach might be to try to reorder the argument
2990 evaluations to avoid this conflicting stack usage. */
2992 /* Since we will be writing into the entire argument area,
2993 the map must be allocated for its entire size, not just
2994 the part that is the responsibility of the caller. */
2995 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
2996 needed
+= reg_parm_stack_space
;
2998 if (ARGS_GROW_DOWNWARD
)
2999 highest_outgoing_arg_in_use
3000 = MAX (initial_highest_arg_in_use
, needed
+ 1);
3002 highest_outgoing_arg_in_use
3003 = MAX (initial_highest_arg_in_use
, needed
);
3005 free (stack_usage_map_buf
);
3006 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
3007 stack_usage_map
= stack_usage_map_buf
;
3009 if (initial_highest_arg_in_use
)
3010 memcpy (stack_usage_map
, initial_stack_usage_map
,
3011 initial_highest_arg_in_use
);
3013 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
3014 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
3015 (highest_outgoing_arg_in_use
3016 - initial_highest_arg_in_use
));
3019 /* The address of the outgoing argument list must not be
3020 copied to a register here, because argblock would be left
3021 pointing to the wrong place after the call to
3022 allocate_dynamic_stack_space below. */
3024 argblock
= virtual_outgoing_args_rtx
;
3028 if (inhibit_defer_pop
== 0)
3030 /* Try to reuse some or all of the pending_stack_adjust
3031 to get this space. */
3033 = (combine_pending_stack_adjustment_and_call
3034 (unadjusted_args_size
,
3035 &adjusted_args_size
,
3036 preferred_unit_stack_boundary
));
3038 /* combine_pending_stack_adjustment_and_call computes
3039 an adjustment before the arguments are allocated.
3040 Account for them and see whether or not the stack
3041 needs to go up or down. */
3042 needed
= unadjusted_args_size
- needed
;
3046 /* We're releasing stack space. */
3047 /* ??? We can avoid any adjustment at all if we're
3048 already aligned. FIXME. */
3049 pending_stack_adjust
= -needed
;
3050 do_pending_stack_adjust ();
3054 /* We need to allocate space. We'll do that in
3055 push_block below. */
3056 pending_stack_adjust
= 0;
3059 /* Special case this because overhead of `push_block' in
3060 this case is non-trivial. */
3062 argblock
= virtual_outgoing_args_rtx
;
3065 argblock
= push_block (GEN_INT (needed
), 0, 0);
3066 if (ARGS_GROW_DOWNWARD
)
3067 argblock
= plus_constant (Pmode
, argblock
, needed
);
3070 /* We only really need to call `copy_to_reg' in the case
3071 where push insns are going to be used to pass ARGBLOCK
3072 to a function call in ARGS. In that case, the stack
3073 pointer changes value from the allocation point to the
3074 call point, and hence the value of
3075 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
3076 as well always do it. */
3077 argblock
= copy_to_reg (argblock
);
3082 if (ACCUMULATE_OUTGOING_ARGS
)
3084 /* The save/restore code in store_one_arg handles all
3085 cases except one: a constructor call (including a C
3086 function returning a BLKmode struct) to initialize
3088 if (stack_arg_under_construction
)
3091 = GEN_INT (adjusted_args_size
.constant
3092 + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
3093 : TREE_TYPE (fndecl
))) ? 0
3094 : reg_parm_stack_space
));
3095 if (old_stack_level
== 0)
3097 emit_stack_save (SAVE_BLOCK
, &old_stack_level
);
3098 old_stack_pointer_delta
= stack_pointer_delta
;
3099 old_pending_adj
= pending_stack_adjust
;
3100 pending_stack_adjust
= 0;
3101 /* stack_arg_under_construction says whether a stack
3102 arg is being constructed at the old stack level.
3103 Pushing the stack gets a clean outgoing argument
3105 old_stack_arg_under_construction
3106 = stack_arg_under_construction
;
3107 stack_arg_under_construction
= 0;
3108 /* Make a new map for the new argument list. */
3109 free (stack_usage_map_buf
);
3110 stack_usage_map_buf
= XCNEWVEC (char, highest_outgoing_arg_in_use
);
3111 stack_usage_map
= stack_usage_map_buf
;
3112 highest_outgoing_arg_in_use
= 0;
3114 /* We can pass TRUE as the 4th argument because we just
3115 saved the stack pointer and will restore it right after
3117 allocate_dynamic_stack_space (push_size
, 0,
3118 BIGGEST_ALIGNMENT
, true);
3121 /* If argument evaluation might modify the stack pointer,
3122 copy the address of the argument list to a register. */
3123 for (i
= 0; i
< num_actuals
; i
++)
3124 if (args
[i
].pass_on_stack
)
3126 argblock
= copy_addr_to_reg (argblock
);
3131 compute_argument_addresses (args
, argblock
, num_actuals
);
3133 /* Perform stack alignment before the first push (the last arg). */
3135 && adjusted_args_size
.constant
> reg_parm_stack_space
3136 && adjusted_args_size
.constant
!= unadjusted_args_size
)
3138 /* When the stack adjustment is pending, we get better code
3139 by combining the adjustments. */
3140 if (pending_stack_adjust
3141 && ! inhibit_defer_pop
)
3143 pending_stack_adjust
3144 = (combine_pending_stack_adjustment_and_call
3145 (unadjusted_args_size
,
3146 &adjusted_args_size
,
3147 preferred_unit_stack_boundary
));
3148 do_pending_stack_adjust ();
3150 else if (argblock
== 0)
3151 anti_adjust_stack (GEN_INT (adjusted_args_size
.constant
3152 - unadjusted_args_size
));
3154 /* Now that the stack is properly aligned, pops can't safely
3155 be deferred during the evaluation of the arguments. */
3158 /* Record the maximum pushed stack space size. We need to delay
3159 doing it this far to take into account the optimization done
3160 by combine_pending_stack_adjustment_and_call. */
3161 if (flag_stack_usage_info
3162 && !ACCUMULATE_OUTGOING_ARGS
3164 && adjusted_args_size
.var
== 0)
3166 int pushed
= adjusted_args_size
.constant
+ pending_stack_adjust
;
3167 if (pushed
> current_function_pushed_stack_size
)
3168 current_function_pushed_stack_size
= pushed
;
3171 funexp
= rtx_for_function_call (fndecl
, addr
);
3173 /* Precompute all register parameters. It isn't safe to compute anything
3174 once we have started filling any specific hard regs. */
3175 precompute_register_parameters (num_actuals
, args
, ®_parm_seen
);
3177 if (CALL_EXPR_STATIC_CHAIN (exp
))
3178 static_chain_value
= expand_normal (CALL_EXPR_STATIC_CHAIN (exp
));
3180 static_chain_value
= 0;
3182 #ifdef REG_PARM_STACK_SPACE
3183 /* Save the fixed argument area if it's part of the caller's frame and
3184 is clobbered by argument setup for this call. */
3185 if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
3186 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
3187 &low_to_save
, &high_to_save
);
3190 /* Now store (and compute if necessary) all non-register parms.
3191 These come before register parms, since they can require block-moves,
3192 which could clobber the registers used for register parms.
3193 Parms which have partial registers are not stored here,
3194 but we do preallocate space here if they want that. */
3196 for (i
= 0; i
< num_actuals
; i
++)
3198 /* Delay bounds until all other args are stored. */
3199 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
3201 else if (args
[i
].reg
== 0 || args
[i
].pass_on_stack
)
3203 rtx_insn
*before_arg
= get_last_insn ();
3205 /* We don't allow passing huge (> 2^30 B) arguments
3206 by value. It would cause an overflow later on. */
3207 if (adjusted_args_size
.constant
3208 >= (1 << (HOST_BITS_PER_INT
- 2)))
3210 sorry ("passing too large argument on stack");
3214 if (store_one_arg (&args
[i
], argblock
, flags
,
3215 adjusted_args_size
.var
!= 0,
3216 reg_parm_stack_space
)
3218 && check_sibcall_argument_overlap (before_arg
,
3220 sibcall_failure
= 1;
3225 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)),
3226 gen_rtx_USE (VOIDmode
, args
[i
].stack
),
3230 /* If we have a parm that is passed in registers but not in memory
3231 and whose alignment does not permit a direct copy into registers,
3232 make a group of pseudos that correspond to each register that we
3234 if (STRICT_ALIGNMENT
)
3235 store_unaligned_arguments_into_pseudos (args
, num_actuals
);
3237 /* Now store any partially-in-registers parm.
3238 This is the last place a block-move can happen. */
3240 for (i
= 0; i
< num_actuals
; i
++)
3241 if (args
[i
].partial
!= 0 && ! args
[i
].pass_on_stack
)
3243 rtx_insn
*before_arg
= get_last_insn ();
3245 if (store_one_arg (&args
[i
], argblock
, flags
,
3246 adjusted_args_size
.var
!= 0,
3247 reg_parm_stack_space
)
3249 && check_sibcall_argument_overlap (before_arg
,
3251 sibcall_failure
= 1;
3254 bool any_regs
= false;
3255 for (i
= 0; i
< num_actuals
; i
++)
3256 if (args
[i
].reg
!= NULL_RTX
)
3259 targetm
.calls
.call_args (args
[i
].reg
, funtype
);
3262 targetm
.calls
.call_args (pc_rtx
, funtype
);
3264 /* Figure out the register where the value, if any, will come back. */
3267 if (TYPE_MODE (rettype
) != VOIDmode
3268 && ! structure_value_addr
)
3270 if (pcc_struct_value
)
3272 valreg
= hard_function_value (build_pointer_type (rettype
),
3273 fndecl
, NULL
, (pass
== 0));
3274 if (CALL_WITH_BOUNDS_P (exp
))
3275 valbnd
= targetm
.calls
.
3276 chkp_function_value_bounds (build_pointer_type (rettype
),
3277 fndecl
, (pass
== 0));
3281 valreg
= hard_function_value (rettype
, fndecl
, fntype
,
3283 if (CALL_WITH_BOUNDS_P (exp
))
3284 valbnd
= targetm
.calls
.chkp_function_value_bounds (rettype
,
3289 /* If VALREG is a PARALLEL whose first member has a zero
3290 offset, use that. This is for targets such as m68k that
3291 return the same value in multiple places. */
3292 if (GET_CODE (valreg
) == PARALLEL
)
3294 rtx elem
= XVECEXP (valreg
, 0, 0);
3295 rtx where
= XEXP (elem
, 0);
3296 rtx offset
= XEXP (elem
, 1);
3297 if (offset
== const0_rtx
3298 && GET_MODE (where
) == GET_MODE (valreg
))
3303 /* Store all bounds not passed in registers. */
3304 for (i
= 0; i
< num_actuals
; i
++)
3306 if (POINTER_BOUNDS_P (args
[i
].tree_value
)
3308 store_bounds (&args
[i
],
3309 args
[i
].pointer_arg
== -1
3311 : &args
[args
[i
].pointer_arg
]);
3314 /* If register arguments require space on the stack and stack space
3315 was not preallocated, allocate stack space here for arguments
3316 passed in registers. */
3317 if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
)))
3318 && !ACCUMULATE_OUTGOING_ARGS
3319 && must_preallocate
== 0 && reg_parm_stack_space
> 0)
3320 anti_adjust_stack (GEN_INT (reg_parm_stack_space
));
3322 /* Pass the function the address in which to return a
3324 if (pass
!= 0 && structure_value_addr
&& ! structure_value_addr_parm
)
3326 structure_value_addr
3327 = convert_memory_address (Pmode
, structure_value_addr
);
3328 emit_move_insn (struct_value
,
3330 force_operand (structure_value_addr
,
3333 if (REG_P (struct_value
))
3334 use_reg (&call_fusage
, struct_value
);
3337 after_args
= get_last_insn ();
3338 funexp
= prepare_call_address (fndecl
? fndecl
: fntype
, funexp
,
3339 static_chain_value
, &call_fusage
,
3340 reg_parm_seen
, pass
== 0);
3342 load_register_parameters (args
, num_actuals
, &call_fusage
, flags
,
3343 pass
== 0, &sibcall_failure
);
3345 /* Save a pointer to the last insn before the call, so that we can
3346 later safely search backwards to find the CALL_INSN. */
3347 before_call
= get_last_insn ();
3349 /* Set up next argument register. For sibling calls on machines
3350 with register windows this should be the incoming register. */
3352 next_arg_reg
= targetm
.calls
.function_incoming_arg (args_so_far
,
3357 next_arg_reg
= targetm
.calls
.function_arg (args_so_far
,
3358 VOIDmode
, void_type_node
,
3361 if (pass
== 1 && (return_flags
& ERF_RETURNS_ARG
))
3363 int arg_nr
= return_flags
& ERF_RETURN_ARG_MASK
;
3364 arg_nr
= num_actuals
- arg_nr
- 1;
3366 && arg_nr
< num_actuals
3370 && GET_MODE (args
[arg_nr
].reg
) == GET_MODE (valreg
))
3372 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args
[arg_nr
].tree_value
)),
3373 gen_rtx_SET (valreg
, args
[arg_nr
].reg
),
3376 /* All arguments and registers used for the call must be set up by
3379 /* Stack must be properly aligned now. */
3381 || !(stack_pointer_delta
% preferred_unit_stack_boundary
));
3383 /* Generate the actual call instruction. */
3384 emit_call_1 (funexp
, exp
, fndecl
, funtype
, unadjusted_args_size
,
3385 adjusted_args_size
.constant
, struct_value_size
,
3386 next_arg_reg
, valreg
, old_inhibit_defer_pop
, call_fusage
,
3387 flags
, args_so_far
);
3391 rtx_call_insn
*last
;
3392 rtx datum
= NULL_RTX
;
3393 if (fndecl
!= NULL_TREE
)
3395 datum
= XEXP (DECL_RTL (fndecl
), 0);
3396 gcc_assert (datum
!= NULL_RTX
3397 && GET_CODE (datum
) == SYMBOL_REF
);
3399 last
= last_call_insn ();
3400 add_reg_note (last
, REG_CALL_DECL
, datum
);
3403 /* If the call setup or the call itself overlaps with anything
3404 of the argument setup we probably clobbered our call address.
3405 In that case we can't do sibcalls. */
3407 && check_sibcall_argument_overlap (after_args
, 0, 0))
3408 sibcall_failure
= 1;
3410 /* If a non-BLKmode value is returned at the most significant end
3411 of a register, shift the register right by the appropriate amount
3412 and update VALREG accordingly. BLKmode values are handled by the
3413 group load/store machinery below. */
3414 if (!structure_value_addr
3415 && !pcc_struct_value
3416 && TYPE_MODE (rettype
) != VOIDmode
3417 && TYPE_MODE (rettype
) != BLKmode
3419 && targetm
.calls
.return_in_msb (rettype
))
3421 if (shift_return_value (TYPE_MODE (rettype
), false, valreg
))
3422 sibcall_failure
= 1;
3423 valreg
= gen_rtx_REG (TYPE_MODE (rettype
), REGNO (valreg
));
3426 if (pass
&& (flags
& ECF_MALLOC
))
3428 rtx temp
= gen_reg_rtx (GET_MODE (valreg
));
3429 rtx_insn
*last
, *insns
;
3431 /* The return value from a malloc-like function is a pointer. */
3432 if (TREE_CODE (rettype
) == POINTER_TYPE
)
3433 mark_reg_pointer (temp
, MALLOC_ABI_ALIGNMENT
);
3435 emit_move_insn (temp
, valreg
);
3437 /* The return value from a malloc-like function can not alias
3439 last
= get_last_insn ();
3440 add_reg_note (last
, REG_NOALIAS
, temp
);
3442 /* Write out the sequence. */
3443 insns
= get_insns ();
3449 /* For calls to `setjmp', etc., inform
3450 function.c:setjmp_warnings that it should complain if
3451 nonvolatile values are live. For functions that cannot
3452 return, inform flow that control does not fall through. */
3454 if ((flags
& ECF_NORETURN
) || pass
== 0)
3456 /* The barrier must be emitted
3457 immediately after the CALL_INSN. Some ports emit more
3458 than just a CALL_INSN above, so we must search for it here. */
3460 rtx_insn
*last
= get_last_insn ();
3461 while (!CALL_P (last
))
3463 last
= PREV_INSN (last
);
3464 /* There was no CALL_INSN? */
3465 gcc_assert (last
!= before_call
);
3468 emit_barrier_after (last
);
3470 /* Stack adjustments after a noreturn call are dead code.
3471 However when NO_DEFER_POP is in effect, we must preserve
3472 stack_pointer_delta. */
3473 if (inhibit_defer_pop
== 0)
3475 stack_pointer_delta
= old_stack_allocated
;
3476 pending_stack_adjust
= 0;
3480 /* If value type not void, return an rtx for the value. */
3482 if (TYPE_MODE (rettype
) == VOIDmode
3484 target
= const0_rtx
;
3485 else if (structure_value_addr
)
3487 if (target
== 0 || !MEM_P (target
))
3490 = gen_rtx_MEM (TYPE_MODE (rettype
),
3491 memory_address (TYPE_MODE (rettype
),
3492 structure_value_addr
));
3493 set_mem_attributes (target
, rettype
, 1);
3496 else if (pcc_struct_value
)
3498 /* This is the special C++ case where we need to
3499 know what the true target was. We take care to
3500 never use this value more than once in one expression. */
3501 target
= gen_rtx_MEM (TYPE_MODE (rettype
),
3502 copy_to_reg (valreg
));
3503 set_mem_attributes (target
, rettype
, 1);
3505 /* Handle calls that return values in multiple non-contiguous locations.
3506 The Irix 6 ABI has examples of this. */
3507 else if (GET_CODE (valreg
) == PARALLEL
)
3510 target
= emit_group_move_into_temps (valreg
);
3511 else if (rtx_equal_p (target
, valreg
))
3513 else if (GET_CODE (target
) == PARALLEL
)
3514 /* Handle the result of a emit_group_move_into_temps
3515 call in the previous pass. */
3516 emit_group_move (target
, valreg
);
3518 emit_group_store (target
, valreg
, rettype
,
3519 int_size_in_bytes (rettype
));
3522 && GET_MODE (target
) == TYPE_MODE (rettype
)
3523 && GET_MODE (target
) == GET_MODE (valreg
))
3525 bool may_overlap
= false;
3527 /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
3528 reg to a plain register. */
3529 if (!REG_P (target
) || HARD_REGISTER_P (target
))
3530 valreg
= avoid_likely_spilled_reg (valreg
);
3532 /* If TARGET is a MEM in the argument area, and we have
3533 saved part of the argument area, then we can't store
3534 directly into TARGET as it may get overwritten when we
3535 restore the argument save area below. Don't work too
3536 hard though and simply force TARGET to a register if it
3537 is a MEM; the optimizer is quite likely to sort it out. */
3538 if (ACCUMULATE_OUTGOING_ARGS
&& pass
&& MEM_P (target
))
3539 for (i
= 0; i
< num_actuals
; i
++)
3540 if (args
[i
].save_area
)
3547 target
= copy_to_reg (valreg
);
3550 /* TARGET and VALREG cannot be equal at this point
3551 because the latter would not have
3552 REG_FUNCTION_VALUE_P true, while the former would if
3553 it were referring to the same register.
3555 If they refer to the same register, this move will be
3556 a no-op, except when function inlining is being
3558 emit_move_insn (target
, valreg
);
3560 /* If we are setting a MEM, this code must be executed.
3561 Since it is emitted after the call insn, sibcall
3562 optimization cannot be performed in that case. */
3564 sibcall_failure
= 1;
3568 target
= copy_to_reg (avoid_likely_spilled_reg (valreg
));
3570 /* If we promoted this return value, make the proper SUBREG.
3571 TARGET might be const0_rtx here, so be careful. */
3573 && TYPE_MODE (rettype
) != BLKmode
3574 && GET_MODE (target
) != TYPE_MODE (rettype
))
3576 tree type
= rettype
;
3577 int unsignedp
= TYPE_UNSIGNED (type
);
3581 /* Ensure we promote as expected, and get the new unsignedness. */
3582 pmode
= promote_function_mode (type
, TYPE_MODE (type
), &unsignedp
,
3584 gcc_assert (GET_MODE (target
) == pmode
);
3586 if ((WORDS_BIG_ENDIAN
|| BYTES_BIG_ENDIAN
)
3587 && (GET_MODE_SIZE (GET_MODE (target
))
3588 > GET_MODE_SIZE (TYPE_MODE (type
))))
3590 offset
= GET_MODE_SIZE (GET_MODE (target
))
3591 - GET_MODE_SIZE (TYPE_MODE (type
));
3592 if (! BYTES_BIG_ENDIAN
)
3593 offset
= (offset
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3594 else if (! WORDS_BIG_ENDIAN
)
3595 offset
%= UNITS_PER_WORD
;
3598 target
= gen_rtx_SUBREG (TYPE_MODE (type
), target
, offset
);
3599 SUBREG_PROMOTED_VAR_P (target
) = 1;
3600 SUBREG_PROMOTED_SET (target
, unsignedp
);
3603 /* If size of args is variable or this was a constructor call for a stack
3604 argument, restore saved stack-pointer value. */
3606 if (old_stack_level
)
3608 rtx_insn
*prev
= get_last_insn ();
3610 emit_stack_restore (SAVE_BLOCK
, old_stack_level
);
3611 stack_pointer_delta
= old_stack_pointer_delta
;
3613 fixup_args_size_notes (prev
, get_last_insn (), stack_pointer_delta
);
3615 pending_stack_adjust
= old_pending_adj
;
3616 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
3617 stack_arg_under_construction
= old_stack_arg_under_construction
;
3618 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3619 stack_usage_map
= initial_stack_usage_map
;
3620 sibcall_failure
= 1;
3622 else if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
3624 #ifdef REG_PARM_STACK_SPACE
3626 restore_fixed_argument_area (save_area
, argblock
,
3627 high_to_save
, low_to_save
);
3630 /* If we saved any argument areas, restore them. */
3631 for (i
= 0; i
< num_actuals
; i
++)
3632 if (args
[i
].save_area
)
3634 machine_mode save_mode
= GET_MODE (args
[i
].save_area
);
3636 = gen_rtx_MEM (save_mode
,
3637 memory_address (save_mode
,
3638 XEXP (args
[i
].stack_slot
, 0)));
3640 if (save_mode
!= BLKmode
)
3641 emit_move_insn (stack_area
, args
[i
].save_area
);
3643 emit_block_move (stack_area
, args
[i
].save_area
,
3644 GEN_INT (args
[i
].locate
.size
.constant
),
3645 BLOCK_OP_CALL_PARM
);
3648 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3649 stack_usage_map
= initial_stack_usage_map
;
3652 /* If this was alloca, record the new stack level. */
3653 if (flags
& ECF_MAY_BE_ALLOCA
)
3654 record_new_stack_level ();
3656 /* Free up storage we no longer need. */
3657 for (i
= 0; i
< num_actuals
; ++i
)
3658 free (args
[i
].aligned_regs
);
3660 targetm
.calls
.end_call_args ();
3662 insns
= get_insns ();
3667 tail_call_insns
= insns
;
3669 /* Restore the pending stack adjustment now that we have
3670 finished generating the sibling call sequence. */
3672 restore_pending_stack_adjust (&save
);
3674 /* Prepare arg structure for next iteration. */
3675 for (i
= 0; i
< num_actuals
; i
++)
3678 args
[i
].aligned_regs
= 0;
3682 sbitmap_free (stored_args_map
);
3683 internal_arg_pointer_exp_state
.scan_start
= NULL
;
3684 internal_arg_pointer_exp_state
.cache
.release ();
3688 normal_call_insns
= insns
;
3690 /* Verify that we've deallocated all the stack we used. */
3691 gcc_assert ((flags
& ECF_NORETURN
)
3692 || (old_stack_allocated
3693 == stack_pointer_delta
- pending_stack_adjust
));
3696 /* If something prevents making this a sibling call,
3697 zero out the sequence. */
3698 if (sibcall_failure
)
3699 tail_call_insns
= NULL
;
3704 /* If tail call production succeeded, we need to remove REG_EQUIV notes on
3705 arguments too, as argument area is now clobbered by the call. */
3706 if (tail_call_insns
)
3708 emit_insn (tail_call_insns
);
3709 crtl
->tail_call_emit
= true;
3712 emit_insn (normal_call_insns
);
3714 currently_expanding_call
--;
3716 free (stack_usage_map_buf
);
3718 /* Join result with returned bounds so caller may use them if needed. */
3719 target
= chkp_join_splitted_slot (target
, valbnd
);
3724 /* A sibling call sequence invalidates any REG_EQUIV notes made for
3725 this function's incoming arguments.
3727 At the start of RTL generation we know the only REG_EQUIV notes
3728 in the rtl chain are those for incoming arguments, so we can look
3729 for REG_EQUIV notes between the start of the function and the
3730 NOTE_INSN_FUNCTION_BEG.
3732 This is (slight) overkill. We could keep track of the highest
3733 argument we clobber and be more selective in removing notes, but it
3734 does not seem to be worth the effort. */
3737 fixup_tail_calls (void)
3741 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3745 /* There are never REG_EQUIV notes for the incoming arguments
3746 after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
3748 && NOTE_KIND (insn
) == NOTE_INSN_FUNCTION_BEG
)
3751 note
= find_reg_note (insn
, REG_EQUIV
, 0);
3753 remove_note (insn
, note
);
3754 note
= find_reg_note (insn
, REG_EQUIV
, 0);
3759 /* Traverse a list of TYPES and expand all complex types into their
3762 split_complex_types (tree types
)
3766 /* Before allocating memory, check for the common case of no complex. */
3767 for (p
= types
; p
; p
= TREE_CHAIN (p
))
3769 tree type
= TREE_VALUE (p
);
3770 if (TREE_CODE (type
) == COMPLEX_TYPE
3771 && targetm
.calls
.split_complex_arg (type
))
3777 types
= copy_list (types
);
3779 for (p
= types
; p
; p
= TREE_CHAIN (p
))
3781 tree complex_type
= TREE_VALUE (p
);
3783 if (TREE_CODE (complex_type
) == COMPLEX_TYPE
3784 && targetm
.calls
.split_complex_arg (complex_type
))
3788 /* Rewrite complex type with component type. */
3789 TREE_VALUE (p
) = TREE_TYPE (complex_type
);
3790 next
= TREE_CHAIN (p
);
3792 /* Add another component type for the imaginary part. */
3793 imag
= build_tree_list (NULL_TREE
, TREE_VALUE (p
));
3794 TREE_CHAIN (p
) = imag
;
3795 TREE_CHAIN (imag
) = next
;
3797 /* Skip the newly created node. */
3805 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3806 The RETVAL parameter specifies whether return value needs to be saved, other
3807 parameters are documented in the emit_library_call function below. */
3810 emit_library_call_value_1 (int retval
, rtx orgfun
, rtx value
,
3811 enum libcall_type fn_type
,
3812 machine_mode outmode
, int nargs
, va_list p
)
3814 /* Total size in bytes of all the stack-parms scanned so far. */
3815 struct args_size args_size
;
3816 /* Size of arguments before any adjustments (such as rounding). */
3817 struct args_size original_args_size
;
3820 /* Todo, choose the correct decl type of orgfun. Sadly this information
3821 isn't present here, so we default to native calling abi here. */
3822 tree fndecl ATTRIBUTE_UNUSED
= NULL_TREE
; /* library calls default to host calling abi ? */
3823 tree fntype ATTRIBUTE_UNUSED
= NULL_TREE
; /* library calls default to host calling abi ? */
3826 CUMULATIVE_ARGS args_so_far_v
;
3827 cumulative_args_t args_so_far
;
3834 struct locate_and_pad_arg_data locate
;
3838 int old_inhibit_defer_pop
= inhibit_defer_pop
;
3839 rtx call_fusage
= 0;
3842 int pcc_struct_value
= 0;
3843 int struct_value_size
= 0;
3845 int reg_parm_stack_space
= 0;
3847 rtx_insn
*before_call
;
3848 bool have_push_fusage
;
3849 tree tfom
; /* type_for_mode (outmode, 0) */
3851 #ifdef REG_PARM_STACK_SPACE
3852 /* Define the boundary of the register parm stack space that needs to be
3854 int low_to_save
= 0, high_to_save
= 0;
3855 rtx save_area
= 0; /* Place that it is saved. */
3858 /* Size of the stack reserved for parameter registers. */
3859 int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
3860 char *initial_stack_usage_map
= stack_usage_map
;
3861 char *stack_usage_map_buf
= NULL
;
3863 rtx struct_value
= targetm
.calls
.struct_value_rtx (0, 0);
3865 #ifdef REG_PARM_STACK_SPACE
3866 reg_parm_stack_space
= REG_PARM_STACK_SPACE ((tree
) 0);
3869 /* By default, library functions can not throw. */
3870 flags
= ECF_NOTHROW
;
3883 flags
|= ECF_NORETURN
;
3886 flags
= ECF_NORETURN
;
3888 case LCT_RETURNS_TWICE
:
3889 flags
= ECF_RETURNS_TWICE
;
3894 /* Ensure current function's preferred stack boundary is at least
3896 if (crtl
->preferred_stack_boundary
< PREFERRED_STACK_BOUNDARY
)
3897 crtl
->preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
3899 /* If this kind of value comes back in memory,
3900 decide where in memory it should come back. */
3901 if (outmode
!= VOIDmode
)
3903 tfom
= lang_hooks
.types
.type_for_mode (outmode
, 0);
3904 if (aggregate_value_p (tfom
, 0))
3906 #ifdef PCC_STATIC_STRUCT_RETURN
3908 = hard_function_value (build_pointer_type (tfom
), 0, 0, 0);
3909 mem_value
= gen_rtx_MEM (outmode
, pointer_reg
);
3910 pcc_struct_value
= 1;
3912 value
= gen_reg_rtx (outmode
);
3913 #else /* not PCC_STATIC_STRUCT_RETURN */
3914 struct_value_size
= GET_MODE_SIZE (outmode
);
3915 if (value
!= 0 && MEM_P (value
))
3918 mem_value
= assign_temp (tfom
, 1, 1);
3920 /* This call returns a big structure. */
3921 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
3925 tfom
= void_type_node
;
3927 /* ??? Unfinished: must pass the memory address as an argument. */
3929 /* Copy all the libcall-arguments out of the varargs data
3930 and into a vector ARGVEC.
3932 Compute how to pass each argument. We only support a very small subset
3933 of the full argument passing conventions to limit complexity here since
3934 library functions shouldn't have many args. */
3936 argvec
= XALLOCAVEC (struct arg
, nargs
+ 1);
3937 memset (argvec
, 0, (nargs
+ 1) * sizeof (struct arg
));
3939 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3940 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v
, outmode
, fun
);
3942 INIT_CUMULATIVE_ARGS (args_so_far_v
, NULL_TREE
, fun
, 0, nargs
);
3944 args_so_far
= pack_cumulative_args (&args_so_far_v
);
3946 args_size
.constant
= 0;
3953 /* If there's a structure value address to be passed,
3954 either pass it in the special place, or pass it as an extra argument. */
3955 if (mem_value
&& struct_value
== 0 && ! pcc_struct_value
)
3957 rtx addr
= XEXP (mem_value
, 0);
3961 /* Make sure it is a reasonable operand for a move or push insn. */
3962 if (!REG_P (addr
) && !MEM_P (addr
)
3963 && !(CONSTANT_P (addr
)
3964 && targetm
.legitimate_constant_p (Pmode
, addr
)))
3965 addr
= force_operand (addr
, NULL_RTX
);
3967 argvec
[count
].value
= addr
;
3968 argvec
[count
].mode
= Pmode
;
3969 argvec
[count
].partial
= 0;
3971 argvec
[count
].reg
= targetm
.calls
.function_arg (args_so_far
,
3972 Pmode
, NULL_TREE
, true);
3973 gcc_assert (targetm
.calls
.arg_partial_bytes (args_so_far
, Pmode
,
3974 NULL_TREE
, 1) == 0);
3976 locate_and_pad_parm (Pmode
, NULL_TREE
,
3977 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3980 argvec
[count
].reg
!= 0,
3982 reg_parm_stack_space
, 0,
3983 NULL_TREE
, &args_size
, &argvec
[count
].locate
);
3985 if (argvec
[count
].reg
== 0 || argvec
[count
].partial
!= 0
3986 || reg_parm_stack_space
> 0)
3987 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
3989 targetm
.calls
.function_arg_advance (args_so_far
, Pmode
, (tree
) 0, true);
3994 for (; count
< nargs
; count
++)
3996 rtx val
= va_arg (p
, rtx
);
3997 machine_mode mode
= (machine_mode
) va_arg (p
, int);
4000 /* We cannot convert the arg value to the mode the library wants here;
4001 must do it earlier where we know the signedness of the arg. */
4002 gcc_assert (mode
!= BLKmode
4003 && (GET_MODE (val
) == mode
|| GET_MODE (val
) == VOIDmode
));
4005 /* Make sure it is a reasonable operand for a move or push insn. */
4006 if (!REG_P (val
) && !MEM_P (val
)
4007 && !(CONSTANT_P (val
) && targetm
.legitimate_constant_p (mode
, val
)))
4008 val
= force_operand (val
, NULL_RTX
);
4010 if (pass_by_reference (&args_so_far_v
, mode
, NULL_TREE
, 1))
4014 = !reference_callee_copied (&args_so_far_v
, mode
, NULL_TREE
, 1);
4016 /* If this was a CONST function, it is now PURE since it now
4018 if (flags
& ECF_CONST
)
4020 flags
&= ~ECF_CONST
;
4024 if (MEM_P (val
) && !must_copy
)
4026 tree val_expr
= MEM_EXPR (val
);
4028 mark_addressable (val_expr
);
4033 slot
= assign_temp (lang_hooks
.types
.type_for_mode (mode
, 0),
4035 emit_move_insn (slot
, val
);
4038 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
4039 gen_rtx_USE (VOIDmode
, slot
),
4042 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
4043 gen_rtx_CLOBBER (VOIDmode
,
4048 val
= force_operand (XEXP (slot
, 0), NULL_RTX
);
4051 mode
= promote_function_mode (NULL_TREE
, mode
, &unsigned_p
, NULL_TREE
, 0);
4052 argvec
[count
].mode
= mode
;
4053 argvec
[count
].value
= convert_modes (mode
, GET_MODE (val
), val
, unsigned_p
);
4054 argvec
[count
].reg
= targetm
.calls
.function_arg (args_so_far
, mode
,
4057 argvec
[count
].partial
4058 = targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL_TREE
, 1);
4060 if (argvec
[count
].reg
== 0
4061 || argvec
[count
].partial
!= 0
4062 || reg_parm_stack_space
> 0)
4064 locate_and_pad_parm (mode
, NULL_TREE
,
4065 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4068 argvec
[count
].reg
!= 0,
4070 reg_parm_stack_space
, argvec
[count
].partial
,
4071 NULL_TREE
, &args_size
, &argvec
[count
].locate
);
4072 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
4073 gcc_assert (!argvec
[count
].locate
.size
.var
);
4075 #ifdef BLOCK_REG_PADDING
4077 /* The argument is passed entirely in registers. See at which
4078 end it should be padded. */
4079 argvec
[count
].locate
.where_pad
=
4080 BLOCK_REG_PADDING (mode
, NULL_TREE
,
4081 GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
);
4084 targetm
.calls
.function_arg_advance (args_so_far
, mode
, (tree
) 0, true);
4087 /* If this machine requires an external definition for library
4088 functions, write one out. */
4089 assemble_external_libcall (fun
);
4091 original_args_size
= args_size
;
4092 args_size
.constant
= (((args_size
.constant
4093 + stack_pointer_delta
4097 - stack_pointer_delta
);
4099 args_size
.constant
= MAX (args_size
.constant
,
4100 reg_parm_stack_space
);
4102 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
4103 args_size
.constant
-= reg_parm_stack_space
;
4105 if (args_size
.constant
> crtl
->outgoing_args_size
)
4106 crtl
->outgoing_args_size
= args_size
.constant
;
4108 if (flag_stack_usage_info
&& !ACCUMULATE_OUTGOING_ARGS
)
4110 int pushed
= args_size
.constant
+ pending_stack_adjust
;
4111 if (pushed
> current_function_pushed_stack_size
)
4112 current_function_pushed_stack_size
= pushed
;
4115 if (ACCUMULATE_OUTGOING_ARGS
)
4117 /* Since the stack pointer will never be pushed, it is possible for
4118 the evaluation of a parm to clobber something we have already
4119 written to the stack. Since most function calls on RISC machines
4120 do not use the stack, this is uncommon, but must work correctly.
4122 Therefore, we save any area of the stack that was already written
4123 and that we are using. Here we set up to do this by making a new
4124 stack usage map from the old one.
4126 Another approach might be to try to reorder the argument
4127 evaluations to avoid this conflicting stack usage. */
4129 needed
= args_size
.constant
;
4131 /* Since we will be writing into the entire argument area, the
4132 map must be allocated for its entire size, not just the part that
4133 is the responsibility of the caller. */
4134 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
4135 needed
+= reg_parm_stack_space
;
4137 if (ARGS_GROW_DOWNWARD
)
4138 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
4141 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
, needed
);
4143 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
4144 stack_usage_map
= stack_usage_map_buf
;
4146 if (initial_highest_arg_in_use
)
4147 memcpy (stack_usage_map
, initial_stack_usage_map
,
4148 initial_highest_arg_in_use
);
4150 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
4151 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
4152 highest_outgoing_arg_in_use
- initial_highest_arg_in_use
);
4155 /* We must be careful to use virtual regs before they're instantiated,
4156 and real regs afterwards. Loop optimization, for example, can create
4157 new libcalls after we've instantiated the virtual regs, and if we
4158 use virtuals anyway, they won't match the rtl patterns. */
4160 if (virtuals_instantiated
)
4161 argblock
= plus_constant (Pmode
, stack_pointer_rtx
,
4162 STACK_POINTER_OFFSET
);
4164 argblock
= virtual_outgoing_args_rtx
;
4169 argblock
= push_block (GEN_INT (args_size
.constant
), 0, 0);
4172 /* We push args individually in reverse order, perform stack alignment
4173 before the first push (the last arg). */
4175 anti_adjust_stack (GEN_INT (args_size
.constant
4176 - original_args_size
.constant
));
4180 #ifdef REG_PARM_STACK_SPACE
4181 if (ACCUMULATE_OUTGOING_ARGS
)
4183 /* The argument list is the property of the called routine and it
4184 may clobber it. If the fixed area has been used for previous
4185 parameters, we must save and restore it. */
4186 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
4187 &low_to_save
, &high_to_save
);
4191 /* When expanding a normal call, args are stored in push order,
4192 which is the reverse of what we have here. */
4193 bool any_regs
= false;
4194 for (int i
= nargs
; i
-- > 0; )
4195 if (argvec
[i
].reg
!= NULL_RTX
)
4197 targetm
.calls
.call_args (argvec
[i
].reg
, NULL_TREE
);
4201 targetm
.calls
.call_args (pc_rtx
, NULL_TREE
);
4203 /* Push the args that need to be pushed. */
4205 have_push_fusage
= false;
4207 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4208 are to be pushed. */
4209 for (count
= 0; count
< nargs
; count
++, argnum
--)
4211 machine_mode mode
= argvec
[argnum
].mode
;
4212 rtx val
= argvec
[argnum
].value
;
4213 rtx reg
= argvec
[argnum
].reg
;
4214 int partial
= argvec
[argnum
].partial
;
4215 unsigned int parm_align
= argvec
[argnum
].locate
.boundary
;
4216 int lower_bound
= 0, upper_bound
= 0, i
;
4218 if (! (reg
!= 0 && partial
== 0))
4222 if (ACCUMULATE_OUTGOING_ARGS
)
4224 /* If this is being stored into a pre-allocated, fixed-size,
4225 stack area, save any previous data at that location. */
4227 if (ARGS_GROW_DOWNWARD
)
4229 /* stack_slot is negative, but we want to index stack_usage_map
4230 with positive values. */
4231 upper_bound
= -argvec
[argnum
].locate
.slot_offset
.constant
+ 1;
4232 lower_bound
= upper_bound
- argvec
[argnum
].locate
.size
.constant
;
4236 lower_bound
= argvec
[argnum
].locate
.slot_offset
.constant
;
4237 upper_bound
= lower_bound
+ argvec
[argnum
].locate
.size
.constant
;
4241 /* Don't worry about things in the fixed argument area;
4242 it has already been saved. */
4243 if (i
< reg_parm_stack_space
)
4244 i
= reg_parm_stack_space
;
4245 while (i
< upper_bound
&& stack_usage_map
[i
] == 0)
4248 if (i
< upper_bound
)
4250 /* We need to make a save area. */
4252 = argvec
[argnum
].locate
.size
.constant
* BITS_PER_UNIT
;
4253 machine_mode save_mode
4254 = mode_for_size (size
, MODE_INT
, 1);
4256 = plus_constant (Pmode
, argblock
,
4257 argvec
[argnum
].locate
.offset
.constant
);
4259 = gen_rtx_MEM (save_mode
, memory_address (save_mode
, adr
));
4261 if (save_mode
== BLKmode
)
4263 argvec
[argnum
].save_area
4264 = assign_stack_temp (BLKmode
,
4265 argvec
[argnum
].locate
.size
.constant
4268 emit_block_move (validize_mem
4269 (copy_rtx (argvec
[argnum
].save_area
)),
4271 GEN_INT (argvec
[argnum
].locate
.size
.constant
),
4272 BLOCK_OP_CALL_PARM
);
4276 argvec
[argnum
].save_area
= gen_reg_rtx (save_mode
);
4278 emit_move_insn (argvec
[argnum
].save_area
, stack_area
);
4283 emit_push_insn (val
, mode
, NULL_TREE
, NULL_RTX
, parm_align
,
4284 partial
, reg
, 0, argblock
,
4285 GEN_INT (argvec
[argnum
].locate
.offset
.constant
),
4286 reg_parm_stack_space
,
4287 ARGS_SIZE_RTX (argvec
[argnum
].locate
.alignment_pad
));
4289 /* Now mark the segment we just used. */
4290 if (ACCUMULATE_OUTGOING_ARGS
)
4291 for (i
= lower_bound
; i
< upper_bound
; i
++)
4292 stack_usage_map
[i
] = 1;
4296 /* Indicate argument access so that alias.c knows that these
4299 use
= plus_constant (Pmode
, argblock
,
4300 argvec
[argnum
].locate
.offset
.constant
);
4301 else if (have_push_fusage
)
4305 /* When arguments are pushed, trying to tell alias.c where
4306 exactly this argument is won't work, because the
4307 auto-increment causes confusion. So we merely indicate
4308 that we access something with a known mode somewhere on
4310 use
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4311 gen_rtx_SCRATCH (Pmode
));
4312 have_push_fusage
= true;
4314 use
= gen_rtx_MEM (argvec
[argnum
].mode
, use
);
4315 use
= gen_rtx_USE (VOIDmode
, use
);
4316 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
, use
, call_fusage
);
4322 fun
= prepare_call_address (NULL
, fun
, NULL
, &call_fusage
, 0, 0);
4324 /* Now load any reg parms into their regs. */
4326 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4327 are to be pushed. */
4328 for (count
= 0; count
< nargs
; count
++, argnum
--)
4330 machine_mode mode
= argvec
[argnum
].mode
;
4331 rtx val
= argvec
[argnum
].value
;
4332 rtx reg
= argvec
[argnum
].reg
;
4333 int partial
= argvec
[argnum
].partial
;
4334 #ifdef BLOCK_REG_PADDING
4338 /* Handle calls that pass values in multiple non-contiguous
4339 locations. The PA64 has examples of this for library calls. */
4340 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
4341 emit_group_load (reg
, val
, NULL_TREE
, GET_MODE_SIZE (mode
));
4342 else if (reg
!= 0 && partial
== 0)
4344 emit_move_insn (reg
, val
);
4345 #ifdef BLOCK_REG_PADDING
4346 size
= GET_MODE_SIZE (argvec
[argnum
].mode
);
4348 /* Copied from load_register_parameters. */
4350 /* Handle case where we have a value that needs shifting
4351 up to the msb. eg. a QImode value and we're padding
4352 upward on a BYTES_BIG_ENDIAN machine. */
4353 if (size
< UNITS_PER_WORD
4354 && (argvec
[argnum
].locate
.where_pad
4355 == (BYTES_BIG_ENDIAN
? upward
: downward
)))
4358 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
4360 /* Assigning REG here rather than a temp makes CALL_FUSAGE
4361 report the whole reg as used. Strictly speaking, the
4362 call only uses SIZE bytes at the msb end, but it doesn't
4363 seem worth generating rtl to say that. */
4364 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
4365 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, shift
, reg
, 1);
4367 emit_move_insn (reg
, x
);
4375 /* Any regs containing parms remain in use through the call. */
4376 for (count
= 0; count
< nargs
; count
++)
4378 rtx reg
= argvec
[count
].reg
;
4379 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
4380 use_group_regs (&call_fusage
, reg
);
4383 int partial
= argvec
[count
].partial
;
4387 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4388 nregs
= partial
/ UNITS_PER_WORD
;
4389 use_regs (&call_fusage
, REGNO (reg
), nregs
);
4392 use_reg (&call_fusage
, reg
);
4396 /* Pass the function the address in which to return a structure value. */
4397 if (mem_value
!= 0 && struct_value
!= 0 && ! pcc_struct_value
)
4399 emit_move_insn (struct_value
,
4401 force_operand (XEXP (mem_value
, 0),
4403 if (REG_P (struct_value
))
4404 use_reg (&call_fusage
, struct_value
);
4407 /* Don't allow popping to be deferred, since then
4408 cse'ing of library calls could delete a call and leave the pop. */
4410 valreg
= (mem_value
== 0 && outmode
!= VOIDmode
4411 ? hard_libcall_value (outmode
, orgfun
) : NULL_RTX
);
4413 /* Stack must be properly aligned now. */
4414 gcc_assert (!(stack_pointer_delta
4415 & (PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)));
4417 before_call
= get_last_insn ();
4419 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4420 will set inhibit_defer_pop to that value. */
4421 /* The return type is needed to decide how many bytes the function pops.
4422 Signedness plays no role in that, so for simplicity, we pretend it's
4423 always signed. We also assume that the list of arguments passed has
4424 no impact, so we pretend it is unknown. */
4426 emit_call_1 (fun
, NULL
,
4427 get_identifier (XSTR (orgfun
, 0)),
4428 build_function_type (tfom
, NULL_TREE
),
4429 original_args_size
.constant
, args_size
.constant
,
4431 targetm
.calls
.function_arg (args_so_far
,
4432 VOIDmode
, void_type_node
, true),
4434 old_inhibit_defer_pop
+ 1, call_fusage
, flags
, args_so_far
);
4438 rtx last
, datum
= orgfun
;
4439 gcc_assert (GET_CODE (datum
) == SYMBOL_REF
);
4440 last
= last_call_insn ();
4441 add_reg_note (last
, REG_CALL_DECL
, datum
);
4444 /* Right-shift returned value if necessary. */
4445 if (!pcc_struct_value
4446 && TYPE_MODE (tfom
) != BLKmode
4447 && targetm
.calls
.return_in_msb (tfom
))
4449 shift_return_value (TYPE_MODE (tfom
), false, valreg
);
4450 valreg
= gen_rtx_REG (TYPE_MODE (tfom
), REGNO (valreg
));
4453 targetm
.calls
.end_call_args ();
4455 /* For calls to `setjmp', etc., inform function.c:setjmp_warnings
4456 that it should complain if nonvolatile values are live. For
4457 functions that cannot return, inform flow that control does not
4459 if (flags
& ECF_NORETURN
)
4461 /* The barrier note must be emitted
4462 immediately after the CALL_INSN. Some ports emit more than
4463 just a CALL_INSN above, so we must search for it here. */
4464 rtx_insn
*last
= get_last_insn ();
4465 while (!CALL_P (last
))
4467 last
= PREV_INSN (last
);
4468 /* There was no CALL_INSN? */
4469 gcc_assert (last
!= before_call
);
4472 emit_barrier_after (last
);
4475 /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW
4476 and LCT_RETURNS_TWICE, cannot perform non-local gotos. */
4477 if (flags
& ECF_NOTHROW
)
4479 rtx_insn
*last
= get_last_insn ();
4480 while (!CALL_P (last
))
4482 last
= PREV_INSN (last
);
4483 /* There was no CALL_INSN? */
4484 gcc_assert (last
!= before_call
);
4487 make_reg_eh_region_note_nothrow_nononlocal (last
);
4490 /* Now restore inhibit_defer_pop to its actual original value. */
4495 /* Copy the value to the right place. */
4496 if (outmode
!= VOIDmode
&& retval
)
4502 if (value
!= mem_value
)
4503 emit_move_insn (value
, mem_value
);
4505 else if (GET_CODE (valreg
) == PARALLEL
)
4508 value
= gen_reg_rtx (outmode
);
4509 emit_group_store (value
, valreg
, NULL_TREE
, GET_MODE_SIZE (outmode
));
4513 /* Convert to the proper mode if a promotion has been active. */
4514 if (GET_MODE (valreg
) != outmode
)
4516 int unsignedp
= TYPE_UNSIGNED (tfom
);
4518 gcc_assert (promote_function_mode (tfom
, outmode
, &unsignedp
,
4519 fndecl
? TREE_TYPE (fndecl
) : fntype
, 1)
4520 == GET_MODE (valreg
));
4521 valreg
= convert_modes (outmode
, GET_MODE (valreg
), valreg
, 0);
4525 emit_move_insn (value
, valreg
);
4531 if (ACCUMULATE_OUTGOING_ARGS
)
4533 #ifdef REG_PARM_STACK_SPACE
4535 restore_fixed_argument_area (save_area
, argblock
,
4536 high_to_save
, low_to_save
);
4539 /* If we saved any argument areas, restore them. */
4540 for (count
= 0; count
< nargs
; count
++)
4541 if (argvec
[count
].save_area
)
4543 machine_mode save_mode
= GET_MODE (argvec
[count
].save_area
);
4544 rtx adr
= plus_constant (Pmode
, argblock
,
4545 argvec
[count
].locate
.offset
.constant
);
4546 rtx stack_area
= gen_rtx_MEM (save_mode
,
4547 memory_address (save_mode
, adr
));
4549 if (save_mode
== BLKmode
)
4550 emit_block_move (stack_area
,
4552 (copy_rtx (argvec
[count
].save_area
)),
4553 GEN_INT (argvec
[count
].locate
.size
.constant
),
4554 BLOCK_OP_CALL_PARM
);
4556 emit_move_insn (stack_area
, argvec
[count
].save_area
);
4559 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
4560 stack_usage_map
= initial_stack_usage_map
;
4563 free (stack_usage_map_buf
);
4569 /* Output a library call to function FUN (a SYMBOL_REF rtx)
4570 (emitting the queue unless NO_QUEUE is nonzero),
4571 for a value of mode OUTMODE,
4572 with NARGS different arguments, passed as alternating rtx values
4573 and machine_modes to convert them to.
4575 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for
4576 `const' calls, LCT_PURE for `pure' calls, or other LCT_ value for
4577 other types of library calls. */
4580 emit_library_call (rtx orgfun
, enum libcall_type fn_type
,
4581 machine_mode outmode
, int nargs
, ...)
4585 va_start (p
, nargs
);
4586 emit_library_call_value_1 (0, orgfun
, NULL_RTX
, fn_type
, outmode
, nargs
, p
);
4590 /* Like emit_library_call except that an extra argument, VALUE,
4591 comes second and says where to store the result.
4592 (If VALUE is zero, this function chooses a convenient way
4593 to return the value.
4595 This function returns an rtx for where the value is to be found.
4596 If VALUE is nonzero, VALUE is returned. */
4599 emit_library_call_value (rtx orgfun
, rtx value
,
4600 enum libcall_type fn_type
,
4601 machine_mode outmode
, int nargs
, ...)
4606 va_start (p
, nargs
);
4607 result
= emit_library_call_value_1 (1, orgfun
, value
, fn_type
, outmode
,
4615 /* Store pointer bounds argument ARG into Bounds Table entry
4616 associated with PARM. */
4618 store_bounds (struct arg_data
*arg
, struct arg_data
*parm
)
4620 rtx slot
= NULL
, ptr
= NULL
, addr
= NULL
;
4622 /* We may pass bounds not associated with any pointer. */
4625 gcc_assert (arg
->special_slot
);
4626 slot
= arg
->special_slot
;
4629 /* Find pointer associated with bounds and where it is
4635 gcc_assert (!arg
->special_slot
);
4637 addr
= adjust_address (parm
->stack
, Pmode
, arg
->pointer_offset
);
4639 else if (REG_P (parm
->reg
))
4641 gcc_assert (arg
->special_slot
);
4642 slot
= arg
->special_slot
;
4644 if (MEM_P (parm
->value
))
4645 addr
= adjust_address (parm
->value
, Pmode
, arg
->pointer_offset
);
4646 else if (REG_P (parm
->value
))
4647 ptr
= gen_rtx_SUBREG (Pmode
, parm
->value
, arg
->pointer_offset
);
4650 gcc_assert (!arg
->pointer_offset
);
4656 gcc_assert (GET_CODE (parm
->reg
) == PARALLEL
);
4658 gcc_assert (arg
->special_slot
);
4659 slot
= arg
->special_slot
;
4661 if (parm
->parallel_value
)
4662 ptr
= chkp_get_value_with_offs (parm
->parallel_value
,
4663 GEN_INT (arg
->pointer_offset
));
4669 /* Expand bounds. */
4671 arg
->value
= expand_normal (arg
->tree_value
);
4673 targetm
.calls
.store_bounds_for_arg (ptr
, addr
, arg
->value
, slot
);
4676 /* Store a single argument for a function call
4677 into the register or memory area where it must be passed.
4678 *ARG describes the argument value and where to pass it.
4680 ARGBLOCK is the address of the stack-block for all the arguments,
4681 or 0 on a machine where arguments are pushed individually.
4683 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4684 so must be careful about how the stack is used.
4686 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4687 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4688 that we need not worry about saving and restoring the stack.
4690 FNDECL is the declaration of the function we are calling.
4692 Return nonzero if this arg should cause sibcall failure,
4696 store_one_arg (struct arg_data
*arg
, rtx argblock
, int flags
,
4697 int variable_size ATTRIBUTE_UNUSED
, int reg_parm_stack_space
)
4699 tree pval
= arg
->tree_value
;
4703 int i
, lower_bound
= 0, upper_bound
= 0;
4704 int sibcall_failure
= 0;
4706 if (TREE_CODE (pval
) == ERROR_MARK
)
4709 /* Push a new temporary level for any temporaries we make for
4713 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
))
4715 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4716 save any previous data at that location. */
4717 if (argblock
&& ! variable_size
&& arg
->stack
)
4719 if (ARGS_GROW_DOWNWARD
)
4721 /* stack_slot is negative, but we want to index stack_usage_map
4722 with positive values. */
4723 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4724 upper_bound
= -INTVAL (XEXP (XEXP (arg
->stack_slot
, 0), 1)) + 1;
4728 lower_bound
= upper_bound
- arg
->locate
.size
.constant
;
4732 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4733 lower_bound
= INTVAL (XEXP (XEXP (arg
->stack_slot
, 0), 1));
4737 upper_bound
= lower_bound
+ arg
->locate
.size
.constant
;
4741 /* Don't worry about things in the fixed argument area;
4742 it has already been saved. */
4743 if (i
< reg_parm_stack_space
)
4744 i
= reg_parm_stack_space
;
4745 while (i
< upper_bound
&& stack_usage_map
[i
] == 0)
4748 if (i
< upper_bound
)
4750 /* We need to make a save area. */
4751 unsigned int size
= arg
->locate
.size
.constant
* BITS_PER_UNIT
;
4752 machine_mode save_mode
= mode_for_size (size
, MODE_INT
, 1);
4753 rtx adr
= memory_address (save_mode
, XEXP (arg
->stack_slot
, 0));
4754 rtx stack_area
= gen_rtx_MEM (save_mode
, adr
);
4756 if (save_mode
== BLKmode
)
4759 = assign_temp (TREE_TYPE (arg
->tree_value
), 1, 1);
4760 preserve_temp_slots (arg
->save_area
);
4761 emit_block_move (validize_mem (copy_rtx (arg
->save_area
)),
4763 GEN_INT (arg
->locate
.size
.constant
),
4764 BLOCK_OP_CALL_PARM
);
4768 arg
->save_area
= gen_reg_rtx (save_mode
);
4769 emit_move_insn (arg
->save_area
, stack_area
);
4775 /* If this isn't going to be placed on both the stack and in registers,
4776 set up the register and number of words. */
4777 if (! arg
->pass_on_stack
)
4779 if (flags
& ECF_SIBCALL
)
4780 reg
= arg
->tail_call_reg
;
4783 partial
= arg
->partial
;
4786 /* Being passed entirely in a register. We shouldn't be called in
4788 gcc_assert (reg
== 0 || partial
!= 0);
4790 /* If this arg needs special alignment, don't load the registers
4792 if (arg
->n_aligned_regs
!= 0)
4795 /* If this is being passed partially in a register, we can't evaluate
4796 it directly into its stack slot. Otherwise, we can. */
4797 if (arg
->value
== 0)
4799 /* stack_arg_under_construction is nonzero if a function argument is
4800 being evaluated directly into the outgoing argument list and
4801 expand_call must take special action to preserve the argument list
4802 if it is called recursively.
4804 For scalar function arguments stack_usage_map is sufficient to
4805 determine which stack slots must be saved and restored. Scalar
4806 arguments in general have pass_on_stack == 0.
4808 If this argument is initialized by a function which takes the
4809 address of the argument (a C++ constructor or a C function
4810 returning a BLKmode structure), then stack_usage_map is
4811 insufficient and expand_call must push the stack around the
4812 function call. Such arguments have pass_on_stack == 1.
4814 Note that it is always safe to set stack_arg_under_construction,
4815 but this generates suboptimal code if set when not needed. */
4817 if (arg
->pass_on_stack
)
4818 stack_arg_under_construction
++;
4820 arg
->value
= expand_expr (pval
,
4822 || TYPE_MODE (TREE_TYPE (pval
)) != arg
->mode
)
4823 ? NULL_RTX
: arg
->stack
,
4824 VOIDmode
, EXPAND_STACK_PARM
);
4826 /* If we are promoting object (or for any other reason) the mode
4827 doesn't agree, convert the mode. */
4829 if (arg
->mode
!= TYPE_MODE (TREE_TYPE (pval
)))
4830 arg
->value
= convert_modes (arg
->mode
, TYPE_MODE (TREE_TYPE (pval
)),
4831 arg
->value
, arg
->unsignedp
);
4833 if (arg
->pass_on_stack
)
4834 stack_arg_under_construction
--;
4837 /* Check for overlap with already clobbered argument area. */
4838 if ((flags
& ECF_SIBCALL
)
4839 && MEM_P (arg
->value
)
4840 && mem_overlaps_already_clobbered_arg_p (XEXP (arg
->value
, 0),
4841 arg
->locate
.size
.constant
))
4842 sibcall_failure
= 1;
4844 /* Don't allow anything left on stack from computation
4845 of argument to alloca. */
4846 if (flags
& ECF_MAY_BE_ALLOCA
)
4847 do_pending_stack_adjust ();
4849 if (arg
->value
== arg
->stack
)
4850 /* If the value is already in the stack slot, we are done. */
4852 else if (arg
->mode
!= BLKmode
)
4855 unsigned int parm_align
;
4857 /* Argument is a scalar, not entirely passed in registers.
4858 (If part is passed in registers, arg->partial says how much
4859 and emit_push_insn will take care of putting it there.)
4861 Push it, and if its size is less than the
4862 amount of space allocated to it,
4863 also bump stack pointer by the additional space.
4864 Note that in C the default argument promotions
4865 will prevent such mismatches. */
4867 size
= GET_MODE_SIZE (arg
->mode
);
4868 /* Compute how much space the push instruction will push.
4869 On many machines, pushing a byte will advance the stack
4870 pointer by a halfword. */
4871 #ifdef PUSH_ROUNDING
4872 size
= PUSH_ROUNDING (size
);
4876 /* Compute how much space the argument should get:
4877 round up to a multiple of the alignment for arguments. */
4878 if (none
!= FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)))
4879 used
= (((size
+ PARM_BOUNDARY
/ BITS_PER_UNIT
- 1)
4880 / (PARM_BOUNDARY
/ BITS_PER_UNIT
))
4881 * (PARM_BOUNDARY
/ BITS_PER_UNIT
));
4883 /* Compute the alignment of the pushed argument. */
4884 parm_align
= arg
->locate
.boundary
;
4885 if (FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)) == downward
)
4887 int pad
= used
- size
;
4890 unsigned int pad_align
= (pad
& -pad
) * BITS_PER_UNIT
;
4891 parm_align
= MIN (parm_align
, pad_align
);
4895 /* This isn't already where we want it on the stack, so put it there.
4896 This can either be done with push or copy insns. */
4897 emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
), NULL_RTX
,
4898 parm_align
, partial
, reg
, used
- size
, argblock
,
4899 ARGS_SIZE_RTX (arg
->locate
.offset
), reg_parm_stack_space
,
4900 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
));
4902 /* Unless this is a partially-in-register argument, the argument is now
4905 arg
->value
= arg
->stack
;
4909 /* BLKmode, at least partly to be pushed. */
4911 unsigned int parm_align
;
4915 /* Pushing a nonscalar.
4916 If part is passed in registers, PARTIAL says how much
4917 and emit_push_insn will take care of putting it there. */
4919 /* Round its size up to a multiple
4920 of the allocation unit for arguments. */
4922 if (arg
->locate
.size
.var
!= 0)
4925 size_rtx
= ARGS_SIZE_RTX (arg
->locate
.size
);
4929 /* PUSH_ROUNDING has no effect on us, because emit_push_insn
4930 for BLKmode is careful to avoid it. */
4931 excess
= (arg
->locate
.size
.constant
4932 - int_size_in_bytes (TREE_TYPE (pval
))
4934 size_rtx
= expand_expr (size_in_bytes (TREE_TYPE (pval
)),
4935 NULL_RTX
, TYPE_MODE (sizetype
),
4939 parm_align
= arg
->locate
.boundary
;
4941 /* When an argument is padded down, the block is aligned to
4942 PARM_BOUNDARY, but the actual argument isn't. */
4943 if (FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)) == downward
)
4945 if (arg
->locate
.size
.var
)
4946 parm_align
= BITS_PER_UNIT
;
4949 unsigned int excess_align
= (excess
& -excess
) * BITS_PER_UNIT
;
4950 parm_align
= MIN (parm_align
, excess_align
);
4954 if ((flags
& ECF_SIBCALL
) && MEM_P (arg
->value
))
4956 /* emit_push_insn might not work properly if arg->value and
4957 argblock + arg->locate.offset areas overlap. */
4961 if (XEXP (x
, 0) == crtl
->args
.internal_arg_pointer
4962 || (GET_CODE (XEXP (x
, 0)) == PLUS
4963 && XEXP (XEXP (x
, 0), 0) ==
4964 crtl
->args
.internal_arg_pointer
4965 && CONST_INT_P (XEXP (XEXP (x
, 0), 1))))
4967 if (XEXP (x
, 0) != crtl
->args
.internal_arg_pointer
)
4968 i
= INTVAL (XEXP (XEXP (x
, 0), 1));
4970 /* expand_call should ensure this. */
4971 gcc_assert (!arg
->locate
.offset
.var
4972 && arg
->locate
.size
.var
== 0
4973 && CONST_INT_P (size_rtx
));
4975 if (arg
->locate
.offset
.constant
> i
)
4977 if (arg
->locate
.offset
.constant
< i
+ INTVAL (size_rtx
))
4978 sibcall_failure
= 1;
4980 else if (arg
->locate
.offset
.constant
< i
)
4982 /* Use arg->locate.size.constant instead of size_rtx
4983 because we only care about the part of the argument
4985 if (i
< (arg
->locate
.offset
.constant
4986 + arg
->locate
.size
.constant
))
4987 sibcall_failure
= 1;
4991 /* Even though they appear to be at the same location,
4992 if part of the outgoing argument is in registers,
4993 they aren't really at the same location. Check for
4994 this by making sure that the incoming size is the
4995 same as the outgoing size. */
4996 if (arg
->locate
.size
.constant
!= INTVAL (size_rtx
))
4997 sibcall_failure
= 1;
5002 emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
), size_rtx
,
5003 parm_align
, partial
, reg
, excess
, argblock
,
5004 ARGS_SIZE_RTX (arg
->locate
.offset
), reg_parm_stack_space
,
5005 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
));
5007 /* Unless this is a partially-in-register argument, the argument is now
5010 ??? Unlike the case above, in which we want the actual
5011 address of the data, so that we can load it directly into a
5012 register, here we want the address of the stack slot, so that
5013 it's properly aligned for word-by-word copying or something
5014 like that. It's not clear that this is always correct. */
5016 arg
->value
= arg
->stack_slot
;
5019 if (arg
->reg
&& GET_CODE (arg
->reg
) == PARALLEL
)
5021 tree type
= TREE_TYPE (arg
->tree_value
);
5023 = emit_group_load_into_temps (arg
->reg
, arg
->value
, type
,
5024 int_size_in_bytes (type
));
5027 /* Mark all slots this store used. */
5028 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
)
5029 && argblock
&& ! variable_size
&& arg
->stack
)
5030 for (i
= lower_bound
; i
< upper_bound
; i
++)
5031 stack_usage_map
[i
] = 1;
5033 /* Once we have pushed something, pops can't safely
5034 be deferred during the rest of the arguments. */
5037 /* Free any temporary slots made in processing this argument. */
5040 return sibcall_failure
;
5043 /* Nonzero if we do not know how to pass TYPE solely in registers. */
5046 must_pass_in_stack_var_size (machine_mode mode ATTRIBUTE_UNUSED
,
5052 /* If the type has variable size... */
5053 if (TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
5056 /* If the type is marked as addressable (it is required
5057 to be constructed into the stack)... */
5058 if (TREE_ADDRESSABLE (type
))
5064 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
5065 takes trailing padding of a structure into account. */
5066 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
5069 must_pass_in_stack_var_size_or_pad (machine_mode mode
, const_tree type
)
5074 /* If the type has variable size... */
5075 if (TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
5078 /* If the type is marked as addressable (it is required
5079 to be constructed into the stack)... */
5080 if (TREE_ADDRESSABLE (type
))
5083 /* If the padding and mode of the type is such that a copy into
5084 a register would put it into the wrong part of the register. */
5086 && int_size_in_bytes (type
) % (PARM_BOUNDARY
/ BITS_PER_UNIT
)
5087 && (FUNCTION_ARG_PADDING (mode
, type
)
5088 == (BYTES_BIG_ENDIAN
? upward
: downward
)))