1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989-2014 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"
26 #include "stor-layout.h"
28 #include "stringpool.h"
35 #include "hard-reg-set.h"
38 #include "basic-block.h"
39 #include "tree-ssa-alias.h"
40 #include "internal-fn.h"
41 #include "gimple-expr.h"
46 #include "insn-codes.h"
50 #include "diagnostic-core.h"
56 #include "langhooks.h"
59 #include "plugin-api.h"
65 #include "tree-chkp.h"
68 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
69 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
71 /* Data structure and subroutines used within expand_call. */
75 /* Tree node for this argument. */
77 /* Mode for value; TYPE_MODE unless promoted. */
79 /* Current RTL value for argument, or 0 if it isn't precomputed. */
81 /* Initially-compute RTL value for argument; only for const functions. */
83 /* Register to pass this argument in, 0 if passed on stack, or an
84 PARALLEL if the arg is to be copied into multiple non-contiguous
87 /* Register to pass this argument in when generating tail call sequence.
88 This is not the same register as for normal calls on machines with
91 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
92 form for emit_group_move. */
94 /* If value is passed in neither reg nor stack, this field holds a number
95 of a special slot to be used. */
97 /* For pointer bounds hold an index of parm bounds are bound to. -1 if
98 there is no such pointer. */
100 /* If pointer_arg refers a structure, then pointer_offset holds an offset
101 of a pointer in this structure. */
103 /* If REG was promoted from the actual mode of the argument expression,
104 indicates whether the promotion is sign- or zero-extended. */
106 /* Number of bytes to put in registers. 0 means put the whole arg
107 in registers. Also 0 if not passed in registers. */
109 /* Nonzero if argument must be passed on stack.
110 Note that some arguments may be passed on the stack
111 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
112 pass_on_stack identifies arguments that *cannot* go in registers. */
114 /* Some fields packaged up for locate_and_pad_parm. */
115 struct locate_and_pad_arg_data locate
;
116 /* Location on the stack at which parameter should be stored. The store
117 has already been done if STACK == VALUE. */
119 /* Location on the stack of the start of this argument slot. This can
120 differ from STACK if this arg pads downward. This location is known
121 to be aligned to TARGET_FUNCTION_ARG_BOUNDARY. */
123 /* Place that this stack area has been saved, if needed. */
125 /* If an argument's alignment does not permit direct copying into registers,
126 copy in smaller-sized pieces into pseudos. These are stored in a
127 block pointed to by this field. The next field says how many
128 word-sized pseudos we made. */
133 /* A vector of one char per byte of stack space. A byte if nonzero if
134 the corresponding stack location has been used.
135 This vector is used to prevent a function call within an argument from
136 clobbering any stack already set up. */
137 static char *stack_usage_map
;
139 /* Size of STACK_USAGE_MAP. */
140 static int highest_outgoing_arg_in_use
;
142 /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
143 stack location's tail call argument has been already stored into the stack.
144 This bitmap is used to prevent sibling call optimization if function tries
145 to use parent's incoming argument slots when they have been already
146 overwritten with tail call arguments. */
147 static sbitmap stored_args_map
;
149 /* stack_arg_under_construction is nonzero when an argument may be
150 initialized with a constructor call (including a C function that
151 returns a BLKmode struct) and expand_call must take special action
152 to make sure the object being constructed does not overlap the
153 argument list for the constructor call. */
154 static int stack_arg_under_construction
;
156 static void emit_call_1 (rtx
, tree
, tree
, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
,
157 HOST_WIDE_INT
, rtx
, rtx
, int, rtx
, int,
159 static void precompute_register_parameters (int, struct arg_data
*, int *);
160 static void store_bounds (struct arg_data
*, struct arg_data
*);
161 static int store_one_arg (struct arg_data
*, rtx
, int, int, int);
162 static void store_unaligned_arguments_into_pseudos (struct arg_data
*, int);
163 static int finalize_must_preallocate (int, int, struct arg_data
*,
165 static void precompute_arguments (int, struct arg_data
*);
166 static int compute_argument_block_size (int, struct args_size
*, tree
, tree
, int);
167 static void initialize_argument_information (int, struct arg_data
*,
168 struct args_size
*, int,
170 tree
, tree
, cumulative_args_t
, int,
171 rtx
*, int *, int *, int *,
173 static void compute_argument_addresses (struct arg_data
*, rtx
, int);
174 static rtx
rtx_for_function_call (tree
, tree
);
175 static void load_register_parameters (struct arg_data
*, int, rtx
*, int,
177 static rtx
emit_library_call_value_1 (int, rtx
, rtx
, enum libcall_type
,
178 machine_mode
, int, va_list);
179 static int special_function_p (const_tree
, int);
180 static int check_sibcall_argument_overlap_1 (rtx
);
181 static int check_sibcall_argument_overlap (rtx_insn
*, struct arg_data
*, int);
183 static int combine_pending_stack_adjustment_and_call (int, struct args_size
*,
185 static tree
split_complex_types (tree
);
187 #ifdef REG_PARM_STACK_SPACE
188 static rtx
save_fixed_argument_area (int, rtx
, int *, int *);
189 static void restore_fixed_argument_area (rtx
, rtx
, int, int);
192 /* Force FUNEXP into a form suitable for the address of a CALL,
193 and return that as an rtx. Also load the static chain register
194 if FNDECL is a nested function.
196 CALL_FUSAGE points to a variable holding the prospective
197 CALL_INSN_FUNCTION_USAGE information. */
200 prepare_call_address (tree fndecl_or_type
, rtx funexp
, rtx static_chain_value
,
201 rtx
*call_fusage
, int reg_parm_seen
, int sibcallp
)
203 /* Make a valid memory address and copy constants through pseudo-regs,
204 but not for a constant address if -fno-function-cse. */
205 if (GET_CODE (funexp
) != SYMBOL_REF
)
206 /* If we are using registers for parameters, force the
207 function address into a register now. */
208 funexp
= ((reg_parm_seen
209 && targetm
.small_register_classes_for_mode_p (FUNCTION_MODE
))
210 ? force_not_mem (memory_address (FUNCTION_MODE
, funexp
))
211 : memory_address (FUNCTION_MODE
, funexp
));
214 #ifndef NO_FUNCTION_CSE
215 if (optimize
&& ! flag_no_function_cse
)
216 funexp
= force_reg (Pmode
, funexp
);
220 if (static_chain_value
!= 0
221 && (TREE_CODE (fndecl_or_type
) != FUNCTION_DECL
222 || DECL_STATIC_CHAIN (fndecl_or_type
)))
226 chain
= targetm
.calls
.static_chain (fndecl_or_type
, false);
227 static_chain_value
= convert_memory_address (Pmode
, static_chain_value
);
229 emit_move_insn (chain
, static_chain_value
);
231 use_reg (call_fusage
, chain
);
237 /* Generate instructions to call function FUNEXP,
238 and optionally pop the results.
239 The CALL_INSN is the first insn generated.
241 FNDECL is the declaration node of the function. This is given to the
242 hook TARGET_RETURN_POPS_ARGS to determine whether this function pops
245 FUNTYPE is the data type of the function. This is given to the hook
246 TARGET_RETURN_POPS_ARGS to determine whether this function pops its
247 own args. We used to allow an identifier for library functions, but
248 that doesn't work when the return type is an aggregate type and the
249 calling convention says that the pointer to this aggregate is to be
250 popped by the callee.
252 STACK_SIZE is the number of bytes of arguments on the stack,
253 ROUNDED_STACK_SIZE is that number rounded up to
254 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
255 both to put into the call insn and to generate explicit popping
258 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
259 It is zero if this call doesn't want a structure value.
261 NEXT_ARG_REG is the rtx that results from executing
262 targetm.calls.function_arg (&args_so_far, VOIDmode, void_type_node, true)
263 just after all the args have had their registers assigned.
264 This could be whatever you like, but normally it is the first
265 arg-register beyond those used for args in this call,
266 or 0 if all the arg-registers are used in this call.
267 It is passed on to `gen_call' so you can put this info in the call insn.
269 VALREG is a hard register in which a value is returned,
270 or 0 if the call does not return a value.
272 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
273 the args to this call were processed.
274 We restore `inhibit_defer_pop' to that value.
276 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
277 denote registers used by the called function. */
280 emit_call_1 (rtx funexp
, tree fntree ATTRIBUTE_UNUSED
, tree fndecl ATTRIBUTE_UNUSED
,
281 tree funtype ATTRIBUTE_UNUSED
,
282 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED
,
283 HOST_WIDE_INT rounded_stack_size
,
284 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED
,
285 rtx next_arg_reg ATTRIBUTE_UNUSED
, rtx valreg
,
286 int old_inhibit_defer_pop
, rtx call_fusage
, int ecf_flags
,
287 cumulative_args_t args_so_far ATTRIBUTE_UNUSED
)
289 rtx rounded_stack_size_rtx
= GEN_INT (rounded_stack_size
);
292 int already_popped
= 0;
293 HOST_WIDE_INT n_popped
294 = targetm
.calls
.return_pops_args (fndecl
, funtype
, stack_size
);
296 #ifdef CALL_POPS_ARGS
297 n_popped
+= CALL_POPS_ARGS (*get_cumulative_args (args_so_far
));
300 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
301 and we don't want to load it into a register as an optimization,
302 because prepare_call_address already did it if it should be done. */
303 if (GET_CODE (funexp
) != SYMBOL_REF
)
304 funexp
= memory_address (FUNCTION_MODE
, funexp
);
306 funmem
= gen_rtx_MEM (FUNCTION_MODE
, funexp
);
307 if (fndecl
&& TREE_CODE (fndecl
) == FUNCTION_DECL
)
311 /* Although a built-in FUNCTION_DECL and its non-__builtin
312 counterpart compare equal and get a shared mem_attrs, they
313 produce different dump output in compare-debug compilations,
314 if an entry gets garbage collected in one compilation, then
315 adds a different (but equivalent) entry, while the other
316 doesn't run the garbage collector at the same spot and then
317 shares the mem_attr with the equivalent entry. */
318 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
)
320 tree t2
= builtin_decl_explicit (DECL_FUNCTION_CODE (t
));
325 set_mem_expr (funmem
, t
);
328 set_mem_expr (funmem
, build_simple_mem_ref (CALL_EXPR_FN (fntree
)));
330 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
331 if ((ecf_flags
& ECF_SIBCALL
)
332 && HAVE_sibcall_pop
&& HAVE_sibcall_value_pop
333 && (n_popped
> 0 || stack_size
== 0))
335 rtx n_pop
= GEN_INT (n_popped
);
338 /* If this subroutine pops its own args, record that in the call insn
339 if possible, for the sake of frame pointer elimination. */
342 pat
= GEN_SIBCALL_VALUE_POP (valreg
, funmem
, rounded_stack_size_rtx
,
343 next_arg_reg
, n_pop
);
345 pat
= GEN_SIBCALL_POP (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
348 emit_call_insn (pat
);
354 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
355 /* If the target has "call" or "call_value" insns, then prefer them
356 if no arguments are actually popped. If the target does not have
357 "call" or "call_value" insns, then we must use the popping versions
358 even if the call has no arguments to pop. */
359 #if defined (HAVE_call) && defined (HAVE_call_value)
360 if (HAVE_call
&& HAVE_call_value
&& HAVE_call_pop
&& HAVE_call_value_pop
363 if (HAVE_call_pop
&& HAVE_call_value_pop
)
366 rtx n_pop
= GEN_INT (n_popped
);
369 /* If this subroutine pops its own args, record that in the call insn
370 if possible, for the sake of frame pointer elimination. */
373 pat
= GEN_CALL_VALUE_POP (valreg
, funmem
, rounded_stack_size_rtx
,
374 next_arg_reg
, n_pop
);
376 pat
= GEN_CALL_POP (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
379 emit_call_insn (pat
);
385 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
386 if ((ecf_flags
& ECF_SIBCALL
)
387 && HAVE_sibcall
&& HAVE_sibcall_value
)
390 emit_call_insn (GEN_SIBCALL_VALUE (valreg
, funmem
,
391 rounded_stack_size_rtx
,
392 next_arg_reg
, NULL_RTX
));
394 emit_call_insn (GEN_SIBCALL (funmem
, rounded_stack_size_rtx
,
396 GEN_INT (struct_value_size
)));
401 #if defined (HAVE_call) && defined (HAVE_call_value)
402 if (HAVE_call
&& HAVE_call_value
)
405 emit_call_insn (GEN_CALL_VALUE (valreg
, funmem
, rounded_stack_size_rtx
,
406 next_arg_reg
, NULL_RTX
));
408 emit_call_insn (GEN_CALL (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
409 GEN_INT (struct_value_size
)));
415 /* Find the call we just emitted. */
416 call_insn
= last_call_insn ();
418 /* Some target create a fresh MEM instead of reusing the one provided
419 above. Set its MEM_EXPR. */
420 call
= get_call_rtx_from (call_insn
);
422 && MEM_EXPR (XEXP (call
, 0)) == NULL_TREE
423 && MEM_EXPR (funmem
) != NULL_TREE
)
424 set_mem_expr (XEXP (call
, 0), MEM_EXPR (funmem
));
426 /* Mark instrumented calls. */
428 CALL_EXPR_WITH_BOUNDS_P (call
) = CALL_WITH_BOUNDS_P (fntree
);
430 /* Put the register usage information there. */
431 add_function_usage_to (call_insn
, call_fusage
);
433 /* If this is a const call, then set the insn's unchanging bit. */
434 if (ecf_flags
& ECF_CONST
)
435 RTL_CONST_CALL_P (call_insn
) = 1;
437 /* If this is a pure call, then set the insn's unchanging bit. */
438 if (ecf_flags
& ECF_PURE
)
439 RTL_PURE_CALL_P (call_insn
) = 1;
441 /* If this is a const call, then set the insn's unchanging bit. */
442 if (ecf_flags
& ECF_LOOPING_CONST_OR_PURE
)
443 RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn
) = 1;
445 /* Create a nothrow REG_EH_REGION note, if needed. */
446 make_reg_eh_region_note (call_insn
, ecf_flags
, 0);
448 if (ecf_flags
& ECF_NORETURN
)
449 add_reg_note (call_insn
, REG_NORETURN
, const0_rtx
);
451 if (ecf_flags
& ECF_RETURNS_TWICE
)
453 add_reg_note (call_insn
, REG_SETJMP
, const0_rtx
);
454 cfun
->calls_setjmp
= 1;
457 SIBLING_CALL_P (call_insn
) = ((ecf_flags
& ECF_SIBCALL
) != 0);
459 /* Restore this now, so that we do defer pops for this call's args
460 if the context of the call as a whole permits. */
461 inhibit_defer_pop
= old_inhibit_defer_pop
;
466 CALL_INSN_FUNCTION_USAGE (call_insn
)
467 = gen_rtx_EXPR_LIST (VOIDmode
,
468 gen_rtx_CLOBBER (VOIDmode
, stack_pointer_rtx
),
469 CALL_INSN_FUNCTION_USAGE (call_insn
));
470 rounded_stack_size
-= n_popped
;
471 rounded_stack_size_rtx
= GEN_INT (rounded_stack_size
);
472 stack_pointer_delta
-= n_popped
;
474 add_reg_note (call_insn
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
476 /* If popup is needed, stack realign must use DRAP */
477 if (SUPPORTS_STACK_ALIGNMENT
)
478 crtl
->need_drap
= true;
480 /* For noreturn calls when not accumulating outgoing args force
481 REG_ARGS_SIZE note to prevent crossjumping of calls with different
483 else if (!ACCUMULATE_OUTGOING_ARGS
&& (ecf_flags
& ECF_NORETURN
) != 0)
484 add_reg_note (call_insn
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
486 if (!ACCUMULATE_OUTGOING_ARGS
)
488 /* If returning from the subroutine does not automatically pop the args,
489 we need an instruction to pop them sooner or later.
490 Perhaps do it now; perhaps just record how much space to pop later.
492 If returning from the subroutine does pop the args, indicate that the
493 stack pointer will be changed. */
495 if (rounded_stack_size
!= 0)
497 if (ecf_flags
& ECF_NORETURN
)
498 /* Just pretend we did the pop. */
499 stack_pointer_delta
-= rounded_stack_size
;
500 else if (flag_defer_pop
&& inhibit_defer_pop
== 0
501 && ! (ecf_flags
& (ECF_CONST
| ECF_PURE
)))
502 pending_stack_adjust
+= rounded_stack_size
;
504 adjust_stack (rounded_stack_size_rtx
);
507 /* When we accumulate outgoing args, we must avoid any stack manipulations.
508 Restore the stack pointer to its original value now. Usually
509 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
510 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
511 popping variants of functions exist as well.
513 ??? We may optimize similar to defer_pop above, but it is
514 probably not worthwhile.
516 ??? It will be worthwhile to enable combine_stack_adjustments even for
519 anti_adjust_stack (GEN_INT (n_popped
));
522 /* Determine if the function identified by NAME and FNDECL is one with
523 special properties we wish to know about.
525 For example, if the function might return more than one time (setjmp), then
526 set RETURNS_TWICE to a nonzero value.
528 Similarly set NORETURN if the function is in the longjmp family.
530 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
531 space from the stack such as alloca. */
534 special_function_p (const_tree fndecl
, int flags
)
536 tree name_decl
= DECL_NAME (fndecl
);
538 /* For instrumentation clones we want to derive flags
539 from the original name. */
540 if (cgraph_node::get (fndecl
)
541 && cgraph_node::get (fndecl
)->instrumentation_clone
)
542 name_decl
= DECL_NAME (cgraph_node::get (fndecl
)->orig_decl
);
544 if (fndecl
&& name_decl
545 && IDENTIFIER_LENGTH (name_decl
) <= 17
546 /* Exclude functions not at the file scope, or not `extern',
547 since they are not the magic functions we would otherwise
549 FIXME: this should be handled with attributes, not with this
550 hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
551 because you can declare fork() inside a function if you
553 && (DECL_CONTEXT (fndecl
) == NULL_TREE
554 || TREE_CODE (DECL_CONTEXT (fndecl
)) == TRANSLATION_UNIT_DECL
)
555 && TREE_PUBLIC (fndecl
))
557 const char *name
= IDENTIFIER_POINTER (name_decl
);
558 const char *tname
= name
;
560 /* We assume that alloca will always be called by name. It
561 makes no sense to pass it as a pointer-to-function to
562 anything that does not understand its behavior. */
563 if (((IDENTIFIER_LENGTH (name_decl
) == 6
565 && ! strcmp (name
, "alloca"))
566 || (IDENTIFIER_LENGTH (name_decl
) == 16
568 && ! strcmp (name
, "__builtin_alloca"))))
569 flags
|= ECF_MAY_BE_ALLOCA
;
571 /* Disregard prefix _, __, __x or __builtin_. */
576 && !strncmp (name
+ 3, "uiltin_", 7))
578 else if (name
[1] == '_' && name
[2] == 'x')
580 else if (name
[1] == '_')
589 && (! strcmp (tname
, "setjmp")
590 || ! strcmp (tname
, "setjmp_syscall")))
592 && ! strcmp (tname
, "sigsetjmp"))
594 && ! strcmp (tname
, "savectx")))
595 flags
|= ECF_RETURNS_TWICE
| ECF_LEAF
;
598 && ! strcmp (tname
, "siglongjmp"))
599 flags
|= ECF_NORETURN
;
601 else if ((tname
[0] == 'q' && tname
[1] == 's'
602 && ! strcmp (tname
, "qsetjmp"))
603 || (tname
[0] == 'v' && tname
[1] == 'f'
604 && ! strcmp (tname
, "vfork"))
605 || (tname
[0] == 'g' && tname
[1] == 'e'
606 && !strcmp (tname
, "getcontext")))
607 flags
|= ECF_RETURNS_TWICE
| ECF_LEAF
;
609 else if (tname
[0] == 'l' && tname
[1] == 'o'
610 && ! strcmp (tname
, "longjmp"))
611 flags
|= ECF_NORETURN
;
617 /* Similar to special_function_p; return a set of ERF_ flags for the
620 decl_return_flags (tree fndecl
)
623 tree type
= TREE_TYPE (fndecl
);
627 attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
631 attr
= TREE_VALUE (TREE_VALUE (attr
));
632 if (!attr
|| TREE_STRING_LENGTH (attr
) < 1)
635 switch (TREE_STRING_POINTER (attr
)[0])
641 return ERF_RETURNS_ARG
| (TREE_STRING_POINTER (attr
)[0] - '1');
652 /* Return nonzero when FNDECL represents a call to setjmp. */
655 setjmp_call_p (const_tree fndecl
)
657 if (DECL_IS_RETURNS_TWICE (fndecl
))
658 return ECF_RETURNS_TWICE
;
659 return special_function_p (fndecl
, 0) & ECF_RETURNS_TWICE
;
663 /* Return true if STMT is an alloca call. */
666 gimple_alloca_call_p (const_gimple stmt
)
670 if (!is_gimple_call (stmt
))
673 fndecl
= gimple_call_fndecl (stmt
);
674 if (fndecl
&& (special_function_p (fndecl
, 0) & ECF_MAY_BE_ALLOCA
))
680 /* Return true when exp contains alloca call. */
683 alloca_call_p (const_tree exp
)
686 if (TREE_CODE (exp
) == CALL_EXPR
687 && (fndecl
= get_callee_fndecl (exp
))
688 && (special_function_p (fndecl
, 0) & ECF_MAY_BE_ALLOCA
))
693 /* Return TRUE if FNDECL is either a TM builtin or a TM cloned
694 function. Return FALSE otherwise. */
697 is_tm_builtin (const_tree fndecl
)
702 if (decl_is_tm_clone (fndecl
))
705 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
)
707 switch (DECL_FUNCTION_CODE (fndecl
))
709 case BUILT_IN_TM_COMMIT
:
710 case BUILT_IN_TM_COMMIT_EH
:
711 case BUILT_IN_TM_ABORT
:
712 case BUILT_IN_TM_IRREVOCABLE
:
713 case BUILT_IN_TM_GETTMCLONE_IRR
:
714 case BUILT_IN_TM_MEMCPY
:
715 case BUILT_IN_TM_MEMMOVE
:
716 case BUILT_IN_TM_MEMSET
:
717 CASE_BUILT_IN_TM_STORE (1):
718 CASE_BUILT_IN_TM_STORE (2):
719 CASE_BUILT_IN_TM_STORE (4):
720 CASE_BUILT_IN_TM_STORE (8):
721 CASE_BUILT_IN_TM_STORE (FLOAT
):
722 CASE_BUILT_IN_TM_STORE (DOUBLE
):
723 CASE_BUILT_IN_TM_STORE (LDOUBLE
):
724 CASE_BUILT_IN_TM_STORE (M64
):
725 CASE_BUILT_IN_TM_STORE (M128
):
726 CASE_BUILT_IN_TM_STORE (M256
):
727 CASE_BUILT_IN_TM_LOAD (1):
728 CASE_BUILT_IN_TM_LOAD (2):
729 CASE_BUILT_IN_TM_LOAD (4):
730 CASE_BUILT_IN_TM_LOAD (8):
731 CASE_BUILT_IN_TM_LOAD (FLOAT
):
732 CASE_BUILT_IN_TM_LOAD (DOUBLE
):
733 CASE_BUILT_IN_TM_LOAD (LDOUBLE
):
734 CASE_BUILT_IN_TM_LOAD (M64
):
735 CASE_BUILT_IN_TM_LOAD (M128
):
736 CASE_BUILT_IN_TM_LOAD (M256
):
737 case BUILT_IN_TM_LOG
:
738 case BUILT_IN_TM_LOG_1
:
739 case BUILT_IN_TM_LOG_2
:
740 case BUILT_IN_TM_LOG_4
:
741 case BUILT_IN_TM_LOG_8
:
742 case BUILT_IN_TM_LOG_FLOAT
:
743 case BUILT_IN_TM_LOG_DOUBLE
:
744 case BUILT_IN_TM_LOG_LDOUBLE
:
745 case BUILT_IN_TM_LOG_M64
:
746 case BUILT_IN_TM_LOG_M128
:
747 case BUILT_IN_TM_LOG_M256
:
756 /* Detect flags (function attributes) from the function decl or type node. */
759 flags_from_decl_or_type (const_tree exp
)
765 /* The function exp may have the `malloc' attribute. */
766 if (DECL_IS_MALLOC (exp
))
769 /* The function exp may have the `returns_twice' attribute. */
770 if (DECL_IS_RETURNS_TWICE (exp
))
771 flags
|= ECF_RETURNS_TWICE
;
773 /* Process the pure and const attributes. */
774 if (TREE_READONLY (exp
))
776 if (DECL_PURE_P (exp
))
778 if (DECL_LOOPING_CONST_OR_PURE_P (exp
))
779 flags
|= ECF_LOOPING_CONST_OR_PURE
;
781 if (DECL_IS_NOVOPS (exp
))
783 if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp
)))
786 if (TREE_NOTHROW (exp
))
787 flags
|= ECF_NOTHROW
;
791 if (is_tm_builtin (exp
))
792 flags
|= ECF_TM_BUILTIN
;
793 else if ((flags
& (ECF_CONST
|ECF_NOVOPS
)) != 0
794 || lookup_attribute ("transaction_pure",
795 TYPE_ATTRIBUTES (TREE_TYPE (exp
))))
796 flags
|= ECF_TM_PURE
;
799 flags
= special_function_p (exp
, flags
);
801 else if (TYPE_P (exp
))
803 if (TYPE_READONLY (exp
))
807 && ((flags
& ECF_CONST
) != 0
808 || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp
))))
809 flags
|= ECF_TM_PURE
;
814 if (TREE_THIS_VOLATILE (exp
))
816 flags
|= ECF_NORETURN
;
817 if (flags
& (ECF_CONST
|ECF_PURE
))
818 flags
|= ECF_LOOPING_CONST_OR_PURE
;
824 /* Detect flags from a CALL_EXPR. */
827 call_expr_flags (const_tree t
)
830 tree decl
= get_callee_fndecl (t
);
833 flags
= flags_from_decl_or_type (decl
);
836 t
= TREE_TYPE (CALL_EXPR_FN (t
));
837 if (t
&& TREE_CODE (t
) == POINTER_TYPE
)
838 flags
= flags_from_decl_or_type (TREE_TYPE (t
));
846 /* Precompute all register parameters as described by ARGS, storing values
847 into fields within the ARGS array.
849 NUM_ACTUALS indicates the total number elements in the ARGS array.
851 Set REG_PARM_SEEN if we encounter a register parameter. */
854 precompute_register_parameters (int num_actuals
, struct arg_data
*args
,
861 for (i
= 0; i
< num_actuals
; i
++)
862 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
)
866 if (args
[i
].value
== 0)
869 args
[i
].value
= expand_normal (args
[i
].tree_value
);
870 preserve_temp_slots (args
[i
].value
);
874 /* If we are to promote the function arg to a wider mode,
877 if (args
[i
].mode
!= TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)))
879 = convert_modes (args
[i
].mode
,
880 TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)),
881 args
[i
].value
, args
[i
].unsignedp
);
883 /* If the value is a non-legitimate constant, force it into a
884 pseudo now. TLS symbols sometimes need a call to resolve. */
885 if (CONSTANT_P (args
[i
].value
)
886 && !targetm
.legitimate_constant_p (args
[i
].mode
, args
[i
].value
))
887 args
[i
].value
= force_reg (args
[i
].mode
, args
[i
].value
);
889 /* If we're going to have to load the value by parts, pull the
890 parts into pseudos. The part extraction process can involve
891 non-trivial computation. */
892 if (GET_CODE (args
[i
].reg
) == PARALLEL
)
894 tree type
= TREE_TYPE (args
[i
].tree_value
);
895 args
[i
].parallel_value
896 = emit_group_load_into_temps (args
[i
].reg
, args
[i
].value
,
897 type
, int_size_in_bytes (type
));
900 /* If the value is expensive, and we are inside an appropriately
901 short loop, put the value into a pseudo and then put the pseudo
904 For small register classes, also do this if this call uses
905 register parameters. This is to avoid reload conflicts while
906 loading the parameters registers. */
908 else if ((! (REG_P (args
[i
].value
)
909 || (GET_CODE (args
[i
].value
) == SUBREG
910 && REG_P (SUBREG_REG (args
[i
].value
)))))
911 && args
[i
].mode
!= BLKmode
912 && set_src_cost (args
[i
].value
, optimize_insn_for_speed_p ())
915 && targetm
.small_register_classes_for_mode_p (args
[i
].mode
))
917 args
[i
].value
= copy_to_mode_reg (args
[i
].mode
, args
[i
].value
);
921 #ifdef REG_PARM_STACK_SPACE
923 /* The argument list is the property of the called routine and it
924 may clobber it. If the fixed area has been used for previous
925 parameters, we must save and restore it. */
928 save_fixed_argument_area (int reg_parm_stack_space
, rtx argblock
, int *low_to_save
, int *high_to_save
)
933 /* Compute the boundary of the area that needs to be saved, if any. */
934 high
= reg_parm_stack_space
;
935 #ifdef ARGS_GROW_DOWNWARD
938 if (high
> highest_outgoing_arg_in_use
)
939 high
= highest_outgoing_arg_in_use
;
941 for (low
= 0; low
< high
; low
++)
942 if (stack_usage_map
[low
] != 0)
945 machine_mode save_mode
;
951 while (stack_usage_map
[--high
] == 0)
955 *high_to_save
= high
;
957 num_to_save
= high
- low
+ 1;
958 save_mode
= mode_for_size (num_to_save
* BITS_PER_UNIT
, MODE_INT
, 1);
960 /* If we don't have the required alignment, must do this
962 if ((low
& (MIN (GET_MODE_SIZE (save_mode
),
963 BIGGEST_ALIGNMENT
/ UNITS_PER_WORD
) - 1)))
966 #ifdef ARGS_GROW_DOWNWARD
971 addr
= plus_constant (Pmode
, argblock
, delta
);
972 stack_area
= gen_rtx_MEM (save_mode
, memory_address (save_mode
, addr
));
974 set_mem_align (stack_area
, PARM_BOUNDARY
);
975 if (save_mode
== BLKmode
)
977 save_area
= assign_stack_temp (BLKmode
, num_to_save
);
978 emit_block_move (validize_mem (save_area
), stack_area
,
979 GEN_INT (num_to_save
), BLOCK_OP_CALL_PARM
);
983 save_area
= gen_reg_rtx (save_mode
);
984 emit_move_insn (save_area
, stack_area
);
994 restore_fixed_argument_area (rtx save_area
, rtx argblock
, int high_to_save
, int low_to_save
)
996 machine_mode save_mode
= GET_MODE (save_area
);
998 rtx addr
, stack_area
;
1000 #ifdef ARGS_GROW_DOWNWARD
1001 delta
= -high_to_save
;
1003 delta
= low_to_save
;
1005 addr
= plus_constant (Pmode
, argblock
, delta
);
1006 stack_area
= gen_rtx_MEM (save_mode
, memory_address (save_mode
, addr
));
1007 set_mem_align (stack_area
, PARM_BOUNDARY
);
1009 if (save_mode
!= BLKmode
)
1010 emit_move_insn (stack_area
, save_area
);
1012 emit_block_move (stack_area
, validize_mem (save_area
),
1013 GEN_INT (high_to_save
- low_to_save
+ 1),
1014 BLOCK_OP_CALL_PARM
);
1016 #endif /* REG_PARM_STACK_SPACE */
1018 /* If any elements in ARGS refer to parameters that are to be passed in
1019 registers, but not in memory, and whose alignment does not permit a
1020 direct copy into registers. Copy the values into a group of pseudos
1021 which we will later copy into the appropriate hard registers.
1023 Pseudos for each unaligned argument will be stored into the array
1024 args[argnum].aligned_regs. The caller is responsible for deallocating
1025 the aligned_regs array if it is nonzero. */
1028 store_unaligned_arguments_into_pseudos (struct arg_data
*args
, int num_actuals
)
1032 for (i
= 0; i
< num_actuals
; i
++)
1033 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
1034 && GET_CODE (args
[i
].reg
) != PARALLEL
1035 && args
[i
].mode
== BLKmode
1036 && MEM_P (args
[i
].value
)
1037 && (MEM_ALIGN (args
[i
].value
)
1038 < (unsigned int) MIN (BIGGEST_ALIGNMENT
, BITS_PER_WORD
)))
1040 int bytes
= int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1041 int endian_correction
= 0;
1043 if (args
[i
].partial
)
1045 gcc_assert (args
[i
].partial
% UNITS_PER_WORD
== 0);
1046 args
[i
].n_aligned_regs
= args
[i
].partial
/ UNITS_PER_WORD
;
1050 args
[i
].n_aligned_regs
1051 = (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
1054 args
[i
].aligned_regs
= XNEWVEC (rtx
, args
[i
].n_aligned_regs
);
1056 /* Structures smaller than a word are normally aligned to the
1057 least significant byte. On a BYTES_BIG_ENDIAN machine,
1058 this means we must skip the empty high order bytes when
1059 calculating the bit offset. */
1060 if (bytes
< UNITS_PER_WORD
1061 #ifdef BLOCK_REG_PADDING
1062 && (BLOCK_REG_PADDING (args
[i
].mode
,
1063 TREE_TYPE (args
[i
].tree_value
), 1)
1069 endian_correction
= BITS_PER_WORD
- bytes
* BITS_PER_UNIT
;
1071 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
1073 rtx reg
= gen_reg_rtx (word_mode
);
1074 rtx word
= operand_subword_force (args
[i
].value
, j
, BLKmode
);
1075 int bitsize
= MIN (bytes
* BITS_PER_UNIT
, BITS_PER_WORD
);
1077 args
[i
].aligned_regs
[j
] = reg
;
1078 word
= extract_bit_field (word
, bitsize
, 0, 1, NULL_RTX
,
1079 word_mode
, word_mode
);
1081 /* There is no need to restrict this code to loading items
1082 in TYPE_ALIGN sized hunks. The bitfield instructions can
1083 load up entire word sized registers efficiently.
1085 ??? This may not be needed anymore.
1086 We use to emit a clobber here but that doesn't let later
1087 passes optimize the instructions we emit. By storing 0 into
1088 the register later passes know the first AND to zero out the
1089 bitfield being set in the register is unnecessary. The store
1090 of 0 will be deleted as will at least the first AND. */
1092 emit_move_insn (reg
, const0_rtx
);
1094 bytes
-= bitsize
/ BITS_PER_UNIT
;
1095 store_bit_field (reg
, bitsize
, endian_correction
, 0, 0,
1101 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
1104 NUM_ACTUALS is the total number of parameters.
1106 N_NAMED_ARGS is the total number of named arguments.
1108 STRUCT_VALUE_ADDR_VALUE is the implicit argument for a struct return
1111 FNDECL is the tree code for the target of this call (if known)
1113 ARGS_SO_FAR holds state needed by the target to know where to place
1116 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
1117 for arguments which are passed in registers.
1119 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
1120 and may be modified by this routine.
1122 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
1123 flags which may may be modified by this routine.
1125 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
1126 that requires allocation of stack space.
1128 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
1129 the thunked-to function. */
1132 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED
,
1133 struct arg_data
*args
,
1134 struct args_size
*args_size
,
1135 int n_named_args ATTRIBUTE_UNUSED
,
1136 tree exp
, tree struct_value_addr_value
,
1137 tree fndecl
, tree fntype
,
1138 cumulative_args_t args_so_far
,
1139 int reg_parm_stack_space
,
1140 rtx
*old_stack_level
, int *old_pending_adj
,
1141 int *must_preallocate
, int *ecf_flags
,
1142 bool *may_tailcall
, bool call_from_thunk_p
)
1144 CUMULATIVE_ARGS
*args_so_far_pnt
= get_cumulative_args (args_so_far
);
1145 location_t loc
= EXPR_LOCATION (exp
);
1147 /* Count arg position in order args appear. */
1152 args_size
->constant
= 0;
1155 bitmap_obstack_initialize (NULL
);
1157 /* In this loop, we consider args in the order they are written.
1158 We fill up ARGS from the back. */
1160 i
= num_actuals
- 1;
1162 int j
= i
, ptr_arg
= -1;
1163 call_expr_arg_iterator iter
;
1165 bitmap slots
= NULL
;
1167 if (struct_value_addr_value
)
1169 args
[j
].tree_value
= struct_value_addr_value
;
1172 /* If we pass structure address then we need to
1173 create bounds for it. Since created bounds is
1174 a call statement, we expand it right here to avoid
1175 fixing all other places where it may be expanded. */
1176 if (CALL_WITH_BOUNDS_P (exp
))
1178 args
[j
].value
= gen_reg_rtx (targetm
.chkp_bound_mode ());
1180 = chkp_make_bounds_for_struct_addr (struct_value_addr_value
);
1181 expand_expr_real (args
[j
].tree_value
, args
[j
].value
, VOIDmode
,
1182 EXPAND_NORMAL
, 0, false);
1183 args
[j
].pointer_arg
= j
+ 1;
1187 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
1189 tree argtype
= TREE_TYPE (arg
);
1191 /* Remember last param with pointer and associate it
1192 with following pointer bounds. */
1193 if (CALL_WITH_BOUNDS_P (exp
)
1194 && chkp_type_has_pointer (argtype
))
1197 BITMAP_FREE (slots
);
1199 if (!BOUNDED_TYPE_P (argtype
))
1201 slots
= BITMAP_ALLOC (NULL
);
1202 chkp_find_bound_slots (argtype
, slots
);
1205 else if (POINTER_BOUNDS_TYPE_P (argtype
))
1207 /* We expect bounds in instrumented calls only.
1208 Otherwise it is a sign we lost flag due to some optimization
1209 and may emit call args incorrectly. */
1210 gcc_assert (CALL_WITH_BOUNDS_P (exp
));
1212 /* For structures look for the next available pointer. */
1213 if (ptr_arg
!= -1 && slots
)
1215 unsigned bnd_no
= bitmap_first_set_bit (slots
);
1216 args
[j
].pointer_offset
=
1217 bnd_no
* POINTER_SIZE
/ BITS_PER_UNIT
;
1219 bitmap_clear_bit (slots
, bnd_no
);
1221 /* Check we have no more pointers in the structure. */
1222 if (bitmap_empty_p (slots
))
1223 BITMAP_FREE (slots
);
1225 args
[j
].pointer_arg
= ptr_arg
;
1227 /* Check we covered all pointers in the previous
1235 if (targetm
.calls
.split_complex_arg
1237 && TREE_CODE (argtype
) == COMPLEX_TYPE
1238 && targetm
.calls
.split_complex_arg (argtype
))
1240 tree subtype
= TREE_TYPE (argtype
);
1241 args
[j
].tree_value
= build1 (REALPART_EXPR
, subtype
, arg
);
1243 args
[j
].tree_value
= build1 (IMAGPART_EXPR
, subtype
, arg
);
1246 args
[j
].tree_value
= arg
;
1251 BITMAP_FREE (slots
);
1254 bitmap_obstack_release (NULL
);
1256 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1257 for (argpos
= 0; argpos
< num_actuals
; i
--, argpos
++)
1259 tree type
= TREE_TYPE (args
[i
].tree_value
);
1263 /* Replace erroneous argument with constant zero. */
1264 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
1265 args
[i
].tree_value
= integer_zero_node
, type
= integer_type_node
;
1267 /* If TYPE is a transparent union or record, pass things the way
1268 we would pass the first field of the union or record. We have
1269 already verified that the modes are the same. */
1270 if ((TREE_CODE (type
) == UNION_TYPE
|| TREE_CODE (type
) == RECORD_TYPE
)
1271 && TYPE_TRANSPARENT_AGGR (type
))
1272 type
= TREE_TYPE (first_field (type
));
1274 /* Decide where to pass this arg.
1276 args[i].reg is nonzero if all or part is passed in registers.
1278 args[i].partial is nonzero if part but not all is passed in registers,
1279 and the exact value says how many bytes are passed in registers.
1281 args[i].pass_on_stack is nonzero if the argument must at least be
1282 computed on the stack. It may then be loaded back into registers
1283 if args[i].reg is nonzero.
1285 These decisions are driven by the FUNCTION_... macros and must agree
1286 with those made by function.c. */
1288 /* See if this argument should be passed by invisible reference. */
1289 if (pass_by_reference (args_so_far_pnt
, TYPE_MODE (type
),
1290 type
, argpos
< n_named_args
))
1293 tree base
= NULL_TREE
;
1296 = reference_callee_copied (args_so_far_pnt
, TYPE_MODE (type
),
1297 type
, argpos
< n_named_args
);
1299 /* If we're compiling a thunk, pass through invisible references
1300 instead of making a copy. */
1301 if (call_from_thunk_p
1303 && !TREE_ADDRESSABLE (type
)
1304 && (base
= get_base_address (args
[i
].tree_value
))
1305 && TREE_CODE (base
) != SSA_NAME
1306 && (!DECL_P (base
) || MEM_P (DECL_RTL (base
)))))
1308 /* Argument setup code may have copied the value to register. We
1309 revert that optimization now because the tail call code must
1310 use the original location. */
1311 if (TREE_CODE (args
[i
].tree_value
) == PARM_DECL
1312 && !MEM_P (DECL_RTL (args
[i
].tree_value
))
1313 && DECL_INCOMING_RTL (args
[i
].tree_value
)
1314 && MEM_P (DECL_INCOMING_RTL (args
[i
].tree_value
)))
1315 set_decl_rtl (args
[i
].tree_value
,
1316 DECL_INCOMING_RTL (args
[i
].tree_value
));
1318 mark_addressable (args
[i
].tree_value
);
1320 /* We can't use sibcalls if a callee-copied argument is
1321 stored in the current function's frame. */
1322 if (!call_from_thunk_p
&& DECL_P (base
) && !TREE_STATIC (base
))
1323 *may_tailcall
= false;
1325 args
[i
].tree_value
= build_fold_addr_expr_loc (loc
,
1326 args
[i
].tree_value
);
1327 type
= TREE_TYPE (args
[i
].tree_value
);
1329 if (*ecf_flags
& ECF_CONST
)
1330 *ecf_flags
&= ~(ECF_CONST
| ECF_LOOPING_CONST_OR_PURE
);
1334 /* We make a copy of the object and pass the address to the
1335 function being called. */
1338 if (!COMPLETE_TYPE_P (type
)
1339 || TREE_CODE (TYPE_SIZE_UNIT (type
)) != INTEGER_CST
1340 || (flag_stack_check
== GENERIC_STACK_CHECK
1341 && compare_tree_int (TYPE_SIZE_UNIT (type
),
1342 STACK_CHECK_MAX_VAR_SIZE
) > 0))
1344 /* This is a variable-sized object. Make space on the stack
1346 rtx size_rtx
= expr_size (args
[i
].tree_value
);
1348 if (*old_stack_level
== 0)
1350 emit_stack_save (SAVE_BLOCK
, old_stack_level
);
1351 *old_pending_adj
= pending_stack_adjust
;
1352 pending_stack_adjust
= 0;
1355 /* We can pass TRUE as the 4th argument because we just
1356 saved the stack pointer and will restore it right after
1358 copy
= allocate_dynamic_stack_space (size_rtx
,
1362 copy
= gen_rtx_MEM (BLKmode
, copy
);
1363 set_mem_attributes (copy
, type
, 1);
1366 copy
= assign_temp (type
, 1, 0);
1368 store_expr (args
[i
].tree_value
, copy
, 0, false);
1370 /* Just change the const function to pure and then let
1371 the next test clear the pure based on
1373 if (*ecf_flags
& ECF_CONST
)
1375 *ecf_flags
&= ~ECF_CONST
;
1376 *ecf_flags
|= ECF_PURE
;
1379 if (!callee_copies
&& *ecf_flags
& ECF_PURE
)
1380 *ecf_flags
&= ~(ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
1383 = build_fold_addr_expr_loc (loc
, make_tree (type
, copy
));
1384 type
= TREE_TYPE (args
[i
].tree_value
);
1385 *may_tailcall
= false;
1389 unsignedp
= TYPE_UNSIGNED (type
);
1390 mode
= promote_function_mode (type
, TYPE_MODE (type
), &unsignedp
,
1391 fndecl
? TREE_TYPE (fndecl
) : fntype
, 0);
1393 args
[i
].unsignedp
= unsignedp
;
1394 args
[i
].mode
= mode
;
1396 args
[i
].reg
= targetm
.calls
.function_arg (args_so_far
, mode
, type
,
1397 argpos
< n_named_args
);
1399 if (args
[i
].reg
&& CONST_INT_P (args
[i
].reg
))
1401 args
[i
].special_slot
= args
[i
].reg
;
1405 /* If this is a sibling call and the machine has register windows, the
1406 register window has to be unwinded before calling the routine, so
1407 arguments have to go into the incoming registers. */
1408 if (targetm
.calls
.function_incoming_arg
!= targetm
.calls
.function_arg
)
1409 args
[i
].tail_call_reg
1410 = targetm
.calls
.function_incoming_arg (args_so_far
, mode
, type
,
1411 argpos
< n_named_args
);
1413 args
[i
].tail_call_reg
= args
[i
].reg
;
1417 = targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, type
,
1418 argpos
< n_named_args
);
1420 args
[i
].pass_on_stack
= targetm
.calls
.must_pass_in_stack (mode
, type
);
1422 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1423 it means that we are to pass this arg in the register(s) designated
1424 by the PARALLEL, but also to pass it in the stack. */
1425 if (args
[i
].reg
&& GET_CODE (args
[i
].reg
) == PARALLEL
1426 && XEXP (XVECEXP (args
[i
].reg
, 0, 0), 0) == 0)
1427 args
[i
].pass_on_stack
= 1;
1429 /* If this is an addressable type, we must preallocate the stack
1430 since we must evaluate the object into its final location.
1432 If this is to be passed in both registers and the stack, it is simpler
1434 if (TREE_ADDRESSABLE (type
)
1435 || (args
[i
].pass_on_stack
&& args
[i
].reg
!= 0))
1436 *must_preallocate
= 1;
1438 /* No stack allocation and padding for bounds. */
1439 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
1441 /* Compute the stack-size of this argument. */
1442 else if (args
[i
].reg
== 0 || args
[i
].partial
!= 0
1443 || reg_parm_stack_space
> 0
1444 || args
[i
].pass_on_stack
)
1445 locate_and_pad_parm (mode
, type
,
1446 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1451 reg_parm_stack_space
,
1452 args
[i
].pass_on_stack
? 0 : args
[i
].partial
,
1453 fndecl
, args_size
, &args
[i
].locate
);
1454 #ifdef BLOCK_REG_PADDING
1456 /* The argument is passed entirely in registers. See at which
1457 end it should be padded. */
1458 args
[i
].locate
.where_pad
=
1459 BLOCK_REG_PADDING (mode
, type
,
1460 int_size_in_bytes (type
) <= UNITS_PER_WORD
);
1463 /* Update ARGS_SIZE, the total stack space for args so far. */
1465 args_size
->constant
+= args
[i
].locate
.size
.constant
;
1466 if (args
[i
].locate
.size
.var
)
1467 ADD_PARM_SIZE (*args_size
, args
[i
].locate
.size
.var
);
1469 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1470 have been used, etc. */
1472 targetm
.calls
.function_arg_advance (args_so_far
, TYPE_MODE (type
),
1473 type
, argpos
< n_named_args
);
1477 /* Update ARGS_SIZE to contain the total size for the argument block.
1478 Return the original constant component of the argument block's size.
1480 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1481 for arguments passed in registers. */
1484 compute_argument_block_size (int reg_parm_stack_space
,
1485 struct args_size
*args_size
,
1486 tree fndecl ATTRIBUTE_UNUSED
,
1487 tree fntype ATTRIBUTE_UNUSED
,
1488 int preferred_stack_boundary ATTRIBUTE_UNUSED
)
1490 int unadjusted_args_size
= args_size
->constant
;
1492 /* For accumulate outgoing args mode we don't need to align, since the frame
1493 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1494 backends from generating misaligned frame sizes. */
1495 if (ACCUMULATE_OUTGOING_ARGS
&& preferred_stack_boundary
> STACK_BOUNDARY
)
1496 preferred_stack_boundary
= STACK_BOUNDARY
;
1498 /* Compute the actual size of the argument block required. The variable
1499 and constant sizes must be combined, the size may have to be rounded,
1500 and there may be a minimum required size. */
1504 args_size
->var
= ARGS_SIZE_TREE (*args_size
);
1505 args_size
->constant
= 0;
1507 preferred_stack_boundary
/= BITS_PER_UNIT
;
1508 if (preferred_stack_boundary
> 1)
1510 /* We don't handle this case yet. To handle it correctly we have
1511 to add the delta, round and subtract the delta.
1512 Currently no machine description requires this support. */
1513 gcc_assert (!(stack_pointer_delta
& (preferred_stack_boundary
- 1)));
1514 args_size
->var
= round_up (args_size
->var
, preferred_stack_boundary
);
1517 if (reg_parm_stack_space
> 0)
1520 = size_binop (MAX_EXPR
, args_size
->var
,
1521 ssize_int (reg_parm_stack_space
));
1523 /* The area corresponding to register parameters is not to count in
1524 the size of the block we need. So make the adjustment. */
1525 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
1527 = size_binop (MINUS_EXPR
, args_size
->var
,
1528 ssize_int (reg_parm_stack_space
));
1533 preferred_stack_boundary
/= BITS_PER_UNIT
;
1534 if (preferred_stack_boundary
< 1)
1535 preferred_stack_boundary
= 1;
1536 args_size
->constant
= (((args_size
->constant
1537 + stack_pointer_delta
1538 + preferred_stack_boundary
- 1)
1539 / preferred_stack_boundary
1540 * preferred_stack_boundary
)
1541 - stack_pointer_delta
);
1543 args_size
->constant
= MAX (args_size
->constant
,
1544 reg_parm_stack_space
);
1546 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
1547 args_size
->constant
-= reg_parm_stack_space
;
1549 return unadjusted_args_size
;
1552 /* Precompute parameters as needed for a function call.
1554 FLAGS is mask of ECF_* constants.
1556 NUM_ACTUALS is the number of arguments.
1558 ARGS is an array containing information for each argument; this
1559 routine fills in the INITIAL_VALUE and VALUE fields for each
1560 precomputed argument. */
1563 precompute_arguments (int num_actuals
, struct arg_data
*args
)
1567 /* If this is a libcall, then precompute all arguments so that we do not
1568 get extraneous instructions emitted as part of the libcall sequence. */
1570 /* If we preallocated the stack space, and some arguments must be passed
1571 on the stack, then we must precompute any parameter which contains a
1572 function call which will store arguments on the stack.
1573 Otherwise, evaluating the parameter may clobber previous parameters
1574 which have already been stored into the stack. (we have code to avoid
1575 such case by saving the outgoing stack arguments, but it results in
1577 if (!ACCUMULATE_OUTGOING_ARGS
)
1580 for (i
= 0; i
< num_actuals
; i
++)
1585 if (TREE_CODE (args
[i
].tree_value
) != CALL_EXPR
)
1588 /* If this is an addressable type, we cannot pre-evaluate it. */
1589 type
= TREE_TYPE (args
[i
].tree_value
);
1590 gcc_assert (!TREE_ADDRESSABLE (type
));
1592 args
[i
].initial_value
= args
[i
].value
1593 = expand_normal (args
[i
].tree_value
);
1595 mode
= TYPE_MODE (type
);
1596 if (mode
!= args
[i
].mode
)
1598 int unsignedp
= args
[i
].unsignedp
;
1600 = convert_modes (args
[i
].mode
, mode
,
1601 args
[i
].value
, args
[i
].unsignedp
);
1603 /* CSE will replace this only if it contains args[i].value
1604 pseudo, so convert it down to the declared mode using
1606 if (REG_P (args
[i
].value
)
1607 && GET_MODE_CLASS (args
[i
].mode
) == MODE_INT
1608 && promote_mode (type
, mode
, &unsignedp
) != args
[i
].mode
)
1610 args
[i
].initial_value
1611 = gen_lowpart_SUBREG (mode
, args
[i
].value
);
1612 SUBREG_PROMOTED_VAR_P (args
[i
].initial_value
) = 1;
1613 SUBREG_PROMOTED_SET (args
[i
].initial_value
, args
[i
].unsignedp
);
1619 /* Given the current state of MUST_PREALLOCATE and information about
1620 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1621 compute and return the final value for MUST_PREALLOCATE. */
1624 finalize_must_preallocate (int must_preallocate
, int num_actuals
,
1625 struct arg_data
*args
, struct args_size
*args_size
)
1627 /* See if we have or want to preallocate stack space.
1629 If we would have to push a partially-in-regs parm
1630 before other stack parms, preallocate stack space instead.
1632 If the size of some parm is not a multiple of the required stack
1633 alignment, we must preallocate.
1635 If the total size of arguments that would otherwise create a copy in
1636 a temporary (such as a CALL) is more than half the total argument list
1637 size, preallocation is faster.
1639 Another reason to preallocate is if we have a machine (like the m88k)
1640 where stack alignment is required to be maintained between every
1641 pair of insns, not just when the call is made. However, we assume here
1642 that such machines either do not have push insns (and hence preallocation
1643 would occur anyway) or the problem is taken care of with
1646 if (! must_preallocate
)
1648 int partial_seen
= 0;
1649 int copy_to_evaluate_size
= 0;
1652 for (i
= 0; i
< num_actuals
&& ! must_preallocate
; i
++)
1654 if (args
[i
].partial
> 0 && ! args
[i
].pass_on_stack
)
1656 else if (partial_seen
&& args
[i
].reg
== 0)
1657 must_preallocate
= 1;
1658 /* We preallocate in case there are bounds passed
1659 in the bounds table to have precomputed address
1660 for bounds association. */
1661 else if (POINTER_BOUNDS_P (args
[i
].tree_value
)
1663 must_preallocate
= 1;
1665 if (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)) == BLKmode
1666 && (TREE_CODE (args
[i
].tree_value
) == CALL_EXPR
1667 || TREE_CODE (args
[i
].tree_value
) == TARGET_EXPR
1668 || TREE_CODE (args
[i
].tree_value
) == COND_EXPR
1669 || TREE_ADDRESSABLE (TREE_TYPE (args
[i
].tree_value
))))
1670 copy_to_evaluate_size
1671 += int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1674 if (copy_to_evaluate_size
* 2 >= args_size
->constant
1675 && args_size
->constant
> 0)
1676 must_preallocate
= 1;
1678 return must_preallocate
;
1681 /* If we preallocated stack space, compute the address of each argument
1682 and store it into the ARGS array.
1684 We need not ensure it is a valid memory address here; it will be
1685 validized when it is used.
1687 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1690 compute_argument_addresses (struct arg_data
*args
, rtx argblock
, int num_actuals
)
1694 rtx arg_reg
= argblock
;
1695 int i
, arg_offset
= 0;
1697 if (GET_CODE (argblock
) == PLUS
)
1698 arg_reg
= XEXP (argblock
, 0), arg_offset
= INTVAL (XEXP (argblock
, 1));
1700 for (i
= 0; i
< num_actuals
; i
++)
1702 rtx offset
= ARGS_SIZE_RTX (args
[i
].locate
.offset
);
1703 rtx slot_offset
= ARGS_SIZE_RTX (args
[i
].locate
.slot_offset
);
1705 unsigned int align
, boundary
;
1706 unsigned int units_on_stack
= 0;
1707 machine_mode partial_mode
= VOIDmode
;
1709 /* Skip this parm if it will not be passed on the stack. */
1710 if (! args
[i
].pass_on_stack
1712 && args
[i
].partial
== 0)
1715 /* Pointer Bounds are never passed on the stack. */
1716 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
1719 if (CONST_INT_P (offset
))
1720 addr
= plus_constant (Pmode
, arg_reg
, INTVAL (offset
));
1722 addr
= gen_rtx_PLUS (Pmode
, arg_reg
, offset
);
1724 addr
= plus_constant (Pmode
, addr
, arg_offset
);
1726 if (args
[i
].partial
!= 0)
1728 /* Only part of the parameter is being passed on the stack.
1729 Generate a simple memory reference of the correct size. */
1730 units_on_stack
= args
[i
].locate
.size
.constant
;
1731 partial_mode
= mode_for_size (units_on_stack
* BITS_PER_UNIT
,
1733 args
[i
].stack
= gen_rtx_MEM (partial_mode
, addr
);
1734 set_mem_size (args
[i
].stack
, units_on_stack
);
1738 args
[i
].stack
= gen_rtx_MEM (args
[i
].mode
, addr
);
1739 set_mem_attributes (args
[i
].stack
,
1740 TREE_TYPE (args
[i
].tree_value
), 1);
1742 align
= BITS_PER_UNIT
;
1743 boundary
= args
[i
].locate
.boundary
;
1744 if (args
[i
].locate
.where_pad
!= downward
)
1746 else if (CONST_INT_P (offset
))
1748 align
= INTVAL (offset
) * BITS_PER_UNIT
| boundary
;
1749 align
= align
& -align
;
1751 set_mem_align (args
[i
].stack
, align
);
1753 if (CONST_INT_P (slot_offset
))
1754 addr
= plus_constant (Pmode
, arg_reg
, INTVAL (slot_offset
));
1756 addr
= gen_rtx_PLUS (Pmode
, arg_reg
, slot_offset
);
1758 addr
= plus_constant (Pmode
, addr
, arg_offset
);
1760 if (args
[i
].partial
!= 0)
1762 /* Only part of the parameter is being passed on the stack.
1763 Generate a simple memory reference of the correct size.
1765 args
[i
].stack_slot
= gen_rtx_MEM (partial_mode
, addr
);
1766 set_mem_size (args
[i
].stack_slot
, units_on_stack
);
1770 args
[i
].stack_slot
= gen_rtx_MEM (args
[i
].mode
, addr
);
1771 set_mem_attributes (args
[i
].stack_slot
,
1772 TREE_TYPE (args
[i
].tree_value
), 1);
1774 set_mem_align (args
[i
].stack_slot
, args
[i
].locate
.boundary
);
1776 /* Function incoming arguments may overlap with sibling call
1777 outgoing arguments and we cannot allow reordering of reads
1778 from function arguments with stores to outgoing arguments
1779 of sibling calls. */
1780 set_mem_alias_set (args
[i
].stack
, 0);
1781 set_mem_alias_set (args
[i
].stack_slot
, 0);
1786 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1787 in a call instruction.
1789 FNDECL is the tree node for the target function. For an indirect call
1790 FNDECL will be NULL_TREE.
1792 ADDR is the operand 0 of CALL_EXPR for this call. */
1795 rtx_for_function_call (tree fndecl
, tree addr
)
1799 /* Get the function to call, in the form of RTL. */
1802 if (!TREE_USED (fndecl
) && fndecl
!= current_function_decl
)
1803 TREE_USED (fndecl
) = 1;
1805 /* Get a SYMBOL_REF rtx for the function address. */
1806 funexp
= XEXP (DECL_RTL (fndecl
), 0);
1809 /* Generate an rtx (probably a pseudo-register) for the address. */
1812 funexp
= expand_normal (addr
);
1813 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1818 /* Internal state for internal_arg_pointer_based_exp and its helpers. */
1821 /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan,
1822 or NULL_RTX if none has been scanned yet. */
1823 rtx_insn
*scan_start
;
1824 /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is
1825 based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the
1826 pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it
1827 with fixed offset, or PC if this is with variable or unknown offset. */
1829 } internal_arg_pointer_exp_state
;
1831 static rtx
internal_arg_pointer_based_exp (const_rtx
, bool);
1833 /* Helper function for internal_arg_pointer_based_exp. Scan insns in
1834 the tail call sequence, starting with first insn that hasn't been
1835 scanned yet, and note for each pseudo on the LHS whether it is based
1836 on crtl->args.internal_arg_pointer or not, and what offset from that
1837 that pointer it has. */
1840 internal_arg_pointer_based_exp_scan (void)
1842 rtx_insn
*insn
, *scan_start
= internal_arg_pointer_exp_state
.scan_start
;
1844 if (scan_start
== NULL_RTX
)
1845 insn
= get_insns ();
1847 insn
= NEXT_INSN (scan_start
);
1851 rtx set
= single_set (insn
);
1852 if (set
&& REG_P (SET_DEST (set
)) && !HARD_REGISTER_P (SET_DEST (set
)))
1855 unsigned int idx
= REGNO (SET_DEST (set
)) - FIRST_PSEUDO_REGISTER
;
1856 /* Punt on pseudos set multiple times. */
1857 if (idx
< internal_arg_pointer_exp_state
.cache
.length ()
1858 && (internal_arg_pointer_exp_state
.cache
[idx
]
1862 val
= internal_arg_pointer_based_exp (SET_SRC (set
), false);
1863 if (val
!= NULL_RTX
)
1865 if (idx
>= internal_arg_pointer_exp_state
.cache
.length ())
1866 internal_arg_pointer_exp_state
.cache
1867 .safe_grow_cleared (idx
+ 1);
1868 internal_arg_pointer_exp_state
.cache
[idx
] = val
;
1871 if (NEXT_INSN (insn
) == NULL_RTX
)
1873 insn
= NEXT_INSN (insn
);
1876 internal_arg_pointer_exp_state
.scan_start
= scan_start
;
1879 /* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return
1880 NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on
1881 it with fixed offset, or PC if this is with variable or unknown offset.
1882 TOPLEVEL is true if the function is invoked at the topmost level. */
1885 internal_arg_pointer_based_exp (const_rtx rtl
, bool toplevel
)
1887 if (CONSTANT_P (rtl
))
1890 if (rtl
== crtl
->args
.internal_arg_pointer
)
1893 if (REG_P (rtl
) && HARD_REGISTER_P (rtl
))
1896 if (GET_CODE (rtl
) == PLUS
&& CONST_INT_P (XEXP (rtl
, 1)))
1898 rtx val
= internal_arg_pointer_based_exp (XEXP (rtl
, 0), toplevel
);
1899 if (val
== NULL_RTX
|| val
== pc_rtx
)
1901 return plus_constant (Pmode
, val
, INTVAL (XEXP (rtl
, 1)));
1904 /* When called at the topmost level, scan pseudo assignments in between the
1905 last scanned instruction in the tail call sequence and the latest insn
1906 in that sequence. */
1908 internal_arg_pointer_based_exp_scan ();
1912 unsigned int idx
= REGNO (rtl
) - FIRST_PSEUDO_REGISTER
;
1913 if (idx
< internal_arg_pointer_exp_state
.cache
.length ())
1914 return internal_arg_pointer_exp_state
.cache
[idx
];
1919 subrtx_iterator::array_type array
;
1920 FOR_EACH_SUBRTX (iter
, array
, rtl
, NONCONST
)
1922 const_rtx x
= *iter
;
1923 if (REG_P (x
) && internal_arg_pointer_based_exp (x
, false) != NULL_RTX
)
1926 iter
.skip_subrtxes ();
1932 /* Return true if and only if SIZE storage units (usually bytes)
1933 starting from address ADDR overlap with already clobbered argument
1934 area. This function is used to determine if we should give up a
1938 mem_overlaps_already_clobbered_arg_p (rtx addr
, unsigned HOST_WIDE_INT size
)
1943 if (bitmap_empty_p (stored_args_map
))
1945 val
= internal_arg_pointer_based_exp (addr
, true);
1946 if (val
== NULL_RTX
)
1948 else if (val
== pc_rtx
)
1952 #ifdef STACK_GROWS_DOWNWARD
1953 i
-= crtl
->args
.pretend_args_size
;
1955 i
+= crtl
->args
.pretend_args_size
;
1958 #ifdef ARGS_GROW_DOWNWARD
1963 unsigned HOST_WIDE_INT k
;
1965 for (k
= 0; k
< size
; k
++)
1966 if (i
+ k
< SBITMAP_SIZE (stored_args_map
)
1967 && bitmap_bit_p (stored_args_map
, i
+ k
))
1974 /* Do the register loads required for any wholly-register parms or any
1975 parms which are passed both on the stack and in a register. Their
1976 expressions were already evaluated.
1978 Mark all register-parms as living through the call, putting these USE
1979 insns in the CALL_INSN_FUNCTION_USAGE field.
1981 When IS_SIBCALL, perform the check_sibcall_argument_overlap
1982 checking, setting *SIBCALL_FAILURE if appropriate. */
1985 load_register_parameters (struct arg_data
*args
, int num_actuals
,
1986 rtx
*call_fusage
, int flags
, int is_sibcall
,
1987 int *sibcall_failure
)
1991 for (i
= 0; i
< num_actuals
; i
++)
1993 rtx reg
= ((flags
& ECF_SIBCALL
)
1994 ? args
[i
].tail_call_reg
: args
[i
].reg
);
1997 int partial
= args
[i
].partial
;
2000 rtx_insn
*before_arg
= get_last_insn ();
2001 /* Set non-negative if we must move a word at a time, even if
2002 just one word (e.g, partial == 4 && mode == DFmode). Set
2003 to -1 if we just use a normal move insn. This value can be
2004 zero if the argument is a zero size structure. */
2006 if (GET_CODE (reg
) == PARALLEL
)
2010 gcc_assert (partial
% UNITS_PER_WORD
== 0);
2011 nregs
= partial
/ UNITS_PER_WORD
;
2013 else if (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)) == BLKmode
)
2015 size
= int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
2016 nregs
= (size
+ (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
2019 size
= GET_MODE_SIZE (args
[i
].mode
);
2021 /* Handle calls that pass values in multiple non-contiguous
2022 locations. The Irix 6 ABI has examples of this. */
2024 if (GET_CODE (reg
) == PARALLEL
)
2025 emit_group_move (reg
, args
[i
].parallel_value
);
2027 /* If simple case, just do move. If normal partial, store_one_arg
2028 has already loaded the register for us. In all other cases,
2029 load the register(s) from memory. */
2031 else if (nregs
== -1)
2033 emit_move_insn (reg
, args
[i
].value
);
2034 #ifdef BLOCK_REG_PADDING
2035 /* Handle case where we have a value that needs shifting
2036 up to the msb. eg. a QImode value and we're padding
2037 upward on a BYTES_BIG_ENDIAN machine. */
2038 if (size
< UNITS_PER_WORD
2039 && (args
[i
].locate
.where_pad
2040 == (BYTES_BIG_ENDIAN
? upward
: downward
)))
2043 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
2045 /* Assigning REG here rather than a temp makes CALL_FUSAGE
2046 report the whole reg as used. Strictly speaking, the
2047 call only uses SIZE bytes at the msb end, but it doesn't
2048 seem worth generating rtl to say that. */
2049 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
2050 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, shift
, reg
, 1);
2052 emit_move_insn (reg
, x
);
2057 /* If we have pre-computed the values to put in the registers in
2058 the case of non-aligned structures, copy them in now. */
2060 else if (args
[i
].n_aligned_regs
!= 0)
2061 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
2062 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
) + j
),
2063 args
[i
].aligned_regs
[j
]);
2065 else if (partial
== 0 || args
[i
].pass_on_stack
)
2067 rtx mem
= validize_mem (copy_rtx (args
[i
].value
));
2069 /* Check for overlap with already clobbered argument area,
2070 providing that this has non-zero size. */
2073 || mem_overlaps_already_clobbered_arg_p
2074 (XEXP (args
[i
].value
, 0), size
)))
2075 *sibcall_failure
= 1;
2077 /* Handle a BLKmode that needs shifting. */
2078 if (nregs
== 1 && size
< UNITS_PER_WORD
2079 #ifdef BLOCK_REG_PADDING
2080 && args
[i
].locate
.where_pad
== downward
2086 rtx tem
= operand_subword_force (mem
, 0, args
[i
].mode
);
2087 rtx ri
= gen_rtx_REG (word_mode
, REGNO (reg
));
2088 rtx x
= gen_reg_rtx (word_mode
);
2089 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
2090 enum tree_code dir
= BYTES_BIG_ENDIAN
? RSHIFT_EXPR
2093 emit_move_insn (x
, tem
);
2094 x
= expand_shift (dir
, word_mode
, x
, shift
, ri
, 1);
2096 emit_move_insn (ri
, x
);
2099 move_block_to_reg (REGNO (reg
), mem
, nregs
, args
[i
].mode
);
2102 /* When a parameter is a block, and perhaps in other cases, it is
2103 possible that it did a load from an argument slot that was
2104 already clobbered. */
2106 && check_sibcall_argument_overlap (before_arg
, &args
[i
], 0))
2107 *sibcall_failure
= 1;
2109 /* Handle calls that pass values in multiple non-contiguous
2110 locations. The Irix 6 ABI has examples of this. */
2111 if (GET_CODE (reg
) == PARALLEL
)
2112 use_group_regs (call_fusage
, reg
);
2113 else if (nregs
== -1)
2114 use_reg_mode (call_fusage
, reg
,
2115 TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)));
2117 use_regs (call_fusage
, REGNO (reg
), nregs
);
2122 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
2123 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
2124 bytes, then we would need to push some additional bytes to pad the
2125 arguments. So, we compute an adjust to the stack pointer for an
2126 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
2127 bytes. Then, when the arguments are pushed the stack will be perfectly
2128 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
2129 be popped after the call. Returns the adjustment. */
2132 combine_pending_stack_adjustment_and_call (int unadjusted_args_size
,
2133 struct args_size
*args_size
,
2134 unsigned int preferred_unit_stack_boundary
)
2136 /* The number of bytes to pop so that the stack will be
2137 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
2138 HOST_WIDE_INT adjustment
;
2139 /* The alignment of the stack after the arguments are pushed, if we
2140 just pushed the arguments without adjust the stack here. */
2141 unsigned HOST_WIDE_INT unadjusted_alignment
;
2143 unadjusted_alignment
2144 = ((stack_pointer_delta
+ unadjusted_args_size
)
2145 % preferred_unit_stack_boundary
);
2147 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
2148 as possible -- leaving just enough left to cancel out the
2149 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
2150 PENDING_STACK_ADJUST is non-negative, and congruent to
2151 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
2153 /* Begin by trying to pop all the bytes. */
2154 unadjusted_alignment
2155 = (unadjusted_alignment
2156 - (pending_stack_adjust
% preferred_unit_stack_boundary
));
2157 adjustment
= pending_stack_adjust
;
2158 /* Push enough additional bytes that the stack will be aligned
2159 after the arguments are pushed. */
2160 if (preferred_unit_stack_boundary
> 1)
2162 if (unadjusted_alignment
> 0)
2163 adjustment
-= preferred_unit_stack_boundary
- unadjusted_alignment
;
2165 adjustment
+= unadjusted_alignment
;
2168 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
2169 bytes after the call. The right number is the entire
2170 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
2171 by the arguments in the first place. */
2173 = pending_stack_adjust
- adjustment
+ unadjusted_args_size
;
2178 /* Scan X expression if it does not dereference any argument slots
2179 we already clobbered by tail call arguments (as noted in stored_args_map
2181 Return nonzero if X expression dereferences such argument slots,
2185 check_sibcall_argument_overlap_1 (rtx x
)
2194 code
= GET_CODE (x
);
2196 /* We need not check the operands of the CALL expression itself. */
2201 return mem_overlaps_already_clobbered_arg_p (XEXP (x
, 0),
2202 GET_MODE_SIZE (GET_MODE (x
)));
2204 /* Scan all subexpressions. */
2205 fmt
= GET_RTX_FORMAT (code
);
2206 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
2210 if (check_sibcall_argument_overlap_1 (XEXP (x
, i
)))
2213 else if (*fmt
== 'E')
2215 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2216 if (check_sibcall_argument_overlap_1 (XVECEXP (x
, i
, j
)))
2223 /* Scan sequence after INSN if it does not dereference any argument slots
2224 we already clobbered by tail call arguments (as noted in stored_args_map
2225 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
2226 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
2227 should be 0). Return nonzero if sequence after INSN dereferences such argument
2228 slots, zero otherwise. */
2231 check_sibcall_argument_overlap (rtx_insn
*insn
, struct arg_data
*arg
,
2232 int mark_stored_args_map
)
2236 if (insn
== NULL_RTX
)
2237 insn
= get_insns ();
2239 insn
= NEXT_INSN (insn
);
2241 for (; insn
; insn
= NEXT_INSN (insn
))
2243 && check_sibcall_argument_overlap_1 (PATTERN (insn
)))
2246 if (mark_stored_args_map
)
2248 #ifdef ARGS_GROW_DOWNWARD
2249 low
= -arg
->locate
.slot_offset
.constant
- arg
->locate
.size
.constant
;
2251 low
= arg
->locate
.slot_offset
.constant
;
2254 for (high
= low
+ arg
->locate
.size
.constant
; low
< high
; low
++)
2255 bitmap_set_bit (stored_args_map
, low
);
2257 return insn
!= NULL_RTX
;
2260 /* Given that a function returns a value of mode MODE at the most
2261 significant end of hard register VALUE, shift VALUE left or right
2262 as specified by LEFT_P. Return true if some action was needed. */
2265 shift_return_value (machine_mode mode
, bool left_p
, rtx value
)
2267 HOST_WIDE_INT shift
;
2269 gcc_assert (REG_P (value
) && HARD_REGISTER_P (value
));
2270 shift
= GET_MODE_BITSIZE (GET_MODE (value
)) - GET_MODE_BITSIZE (mode
);
2274 /* Use ashr rather than lshr for right shifts. This is for the benefit
2275 of the MIPS port, which requires SImode values to be sign-extended
2276 when stored in 64-bit registers. */
2277 if (!force_expand_binop (GET_MODE (value
), left_p
? ashl_optab
: ashr_optab
,
2278 value
, GEN_INT (shift
), value
, 1, OPTAB_WIDEN
))
2283 /* If X is a likely-spilled register value, copy it to a pseudo
2284 register and return that register. Return X otherwise. */
2287 avoid_likely_spilled_reg (rtx x
)
2292 && HARD_REGISTER_P (x
)
2293 && targetm
.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x
))))
2295 /* Make sure that we generate a REG rather than a CONCAT.
2296 Moves into CONCATs can need nontrivial instructions,
2297 and the whole point of this function is to avoid
2298 using the hard register directly in such a situation. */
2299 generating_concat_p
= 0;
2300 new_rtx
= gen_reg_rtx (GET_MODE (x
));
2301 generating_concat_p
= 1;
2302 emit_move_insn (new_rtx
, x
);
2308 /* Generate all the code for a CALL_EXPR exp
2309 and return an rtx for its value.
2310 Store the value in TARGET (specified as an rtx) if convenient.
2311 If the value is stored in TARGET then TARGET is returned.
2312 If IGNORE is nonzero, then we ignore the value of the function call. */
2315 expand_call (tree exp
, rtx target
, int ignore
)
2317 /* Nonzero if we are currently expanding a call. */
2318 static int currently_expanding_call
= 0;
2320 /* RTX for the function to be called. */
2322 /* Sequence of insns to perform a normal "call". */
2323 rtx_insn
*normal_call_insns
= NULL
;
2324 /* Sequence of insns to perform a tail "call". */
2325 rtx_insn
*tail_call_insns
= NULL
;
2326 /* Data type of the function. */
2328 tree type_arg_types
;
2330 /* Declaration of the function being called,
2331 or 0 if the function is computed (not known by name). */
2333 /* The type of the function being called. */
2335 bool try_tail_call
= CALL_EXPR_TAILCALL (exp
);
2338 /* Register in which non-BLKmode value will be returned,
2339 or 0 if no value or if value is BLKmode. */
2341 /* Register(s) in which bounds are returned. */
2343 /* Address where we should return a BLKmode value;
2344 0 if value not BLKmode. */
2345 rtx structure_value_addr
= 0;
2346 /* Nonzero if that address is being passed by treating it as
2347 an extra, implicit first parameter. Otherwise,
2348 it is passed by being copied directly into struct_value_rtx. */
2349 int structure_value_addr_parm
= 0;
2350 /* Holds the value of implicit argument for the struct value. */
2351 tree structure_value_addr_value
= NULL_TREE
;
2352 /* Size of aggregate value wanted, or zero if none wanted
2353 or if we are using the non-reentrant PCC calling convention
2354 or expecting the value in registers. */
2355 HOST_WIDE_INT struct_value_size
= 0;
2356 /* Nonzero if called function returns an aggregate in memory PCC style,
2357 by returning the address of where to find it. */
2358 int pcc_struct_value
= 0;
2359 rtx struct_value
= 0;
2361 /* Number of actual parameters in this call, including struct value addr. */
2363 /* Number of named args. Args after this are anonymous ones
2364 and they must all go on the stack. */
2366 /* Number of complex actual arguments that need to be split. */
2367 int num_complex_actuals
= 0;
2369 /* Vector of information about each argument.
2370 Arguments are numbered in the order they will be pushed,
2371 not the order they are written. */
2372 struct arg_data
*args
;
2374 /* Total size in bytes of all the stack-parms scanned so far. */
2375 struct args_size args_size
;
2376 struct args_size adjusted_args_size
;
2377 /* Size of arguments before any adjustments (such as rounding). */
2378 int unadjusted_args_size
;
2379 /* Data on reg parms scanned so far. */
2380 CUMULATIVE_ARGS args_so_far_v
;
2381 cumulative_args_t args_so_far
;
2382 /* Nonzero if a reg parm has been scanned. */
2384 /* Nonzero if this is an indirect function call. */
2386 /* Nonzero if we must avoid push-insns in the args for this call.
2387 If stack space is allocated for register parameters, but not by the
2388 caller, then it is preallocated in the fixed part of the stack frame.
2389 So the entire argument block must then be preallocated (i.e., we
2390 ignore PUSH_ROUNDING in that case). */
2392 int must_preallocate
= !PUSH_ARGS
;
2394 /* Size of the stack reserved for parameter registers. */
2395 int reg_parm_stack_space
= 0;
2397 /* Address of space preallocated for stack parms
2398 (on machines that lack push insns), or 0 if space not preallocated. */
2401 /* Mask of ECF_ and ERF_ flags. */
2403 int return_flags
= 0;
2404 #ifdef REG_PARM_STACK_SPACE
2405 /* Define the boundary of the register parm stack space that needs to be
2407 int low_to_save
, high_to_save
;
2408 rtx save_area
= 0; /* Place that it is saved */
2411 int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
2412 char *initial_stack_usage_map
= stack_usage_map
;
2413 char *stack_usage_map_buf
= NULL
;
2415 int old_stack_allocated
;
2417 /* State variables to track stack modifications. */
2418 rtx old_stack_level
= 0;
2419 int old_stack_arg_under_construction
= 0;
2420 int old_pending_adj
= 0;
2421 int old_inhibit_defer_pop
= inhibit_defer_pop
;
2423 /* Some stack pointer alterations we make are performed via
2424 allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
2425 which we then also need to save/restore along the way. */
2426 int old_stack_pointer_delta
= 0;
2429 tree addr
= CALL_EXPR_FN (exp
);
2431 /* The alignment of the stack, in bits. */
2432 unsigned HOST_WIDE_INT preferred_stack_boundary
;
2433 /* The alignment of the stack, in bytes. */
2434 unsigned HOST_WIDE_INT preferred_unit_stack_boundary
;
2435 /* The static chain value to use for this call. */
2436 rtx static_chain_value
;
2437 /* See if this is "nothrow" function call. */
2438 if (TREE_NOTHROW (exp
))
2439 flags
|= ECF_NOTHROW
;
2441 /* See if we can find a DECL-node for the actual function, and get the
2442 function attributes (flags) from the function decl or type node. */
2443 fndecl
= get_callee_fndecl (exp
);
2446 fntype
= TREE_TYPE (fndecl
);
2447 flags
|= flags_from_decl_or_type (fndecl
);
2448 return_flags
|= decl_return_flags (fndecl
);
2452 fntype
= TREE_TYPE (TREE_TYPE (addr
));
2453 flags
|= flags_from_decl_or_type (fntype
);
2455 rettype
= TREE_TYPE (exp
);
2457 struct_value
= targetm
.calls
.struct_value_rtx (fntype
, 0);
2459 /* Warn if this value is an aggregate type,
2460 regardless of which calling convention we are using for it. */
2461 if (AGGREGATE_TYPE_P (rettype
))
2462 warning (OPT_Waggregate_return
, "function call has aggregate value");
2464 /* If the result of a non looping pure or const function call is
2465 ignored (or void), and none of its arguments are volatile, we can
2466 avoid expanding the call and just evaluate the arguments for
2468 if ((flags
& (ECF_CONST
| ECF_PURE
))
2469 && (!(flags
& ECF_LOOPING_CONST_OR_PURE
))
2470 && (ignore
|| target
== const0_rtx
2471 || TYPE_MODE (rettype
) == VOIDmode
))
2473 bool volatilep
= false;
2475 call_expr_arg_iterator iter
;
2477 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2478 if (TREE_THIS_VOLATILE (arg
))
2486 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2487 expand_expr (arg
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
2492 #ifdef REG_PARM_STACK_SPACE
2493 reg_parm_stack_space
= REG_PARM_STACK_SPACE (!fndecl
? fntype
: fndecl
);
2496 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
)))
2497 && reg_parm_stack_space
> 0 && PUSH_ARGS
)
2498 must_preallocate
= 1;
2500 /* Set up a place to return a structure. */
2502 /* Cater to broken compilers. */
2503 if (aggregate_value_p (exp
, fntype
))
2505 /* This call returns a big structure. */
2506 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
2508 #ifdef PCC_STATIC_STRUCT_RETURN
2510 pcc_struct_value
= 1;
2512 #else /* not PCC_STATIC_STRUCT_RETURN */
2514 struct_value_size
= int_size_in_bytes (rettype
);
2516 /* Even if it is semantically safe to use the target as the return
2517 slot, it may be not sufficiently aligned for the return type. */
2518 if (CALL_EXPR_RETURN_SLOT_OPT (exp
)
2521 && !(MEM_ALIGN (target
) < TYPE_ALIGN (rettype
)
2522 && SLOW_UNALIGNED_ACCESS (TYPE_MODE (rettype
),
2523 MEM_ALIGN (target
))))
2524 structure_value_addr
= XEXP (target
, 0);
2527 /* For variable-sized objects, we must be called with a target
2528 specified. If we were to allocate space on the stack here,
2529 we would have no way of knowing when to free it. */
2530 rtx d
= assign_temp (rettype
, 1, 1);
2531 structure_value_addr
= XEXP (d
, 0);
2535 #endif /* not PCC_STATIC_STRUCT_RETURN */
2538 /* Figure out the amount to which the stack should be aligned. */
2539 preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
2542 struct cgraph_rtl_info
*i
= cgraph_node::rtl_info (fndecl
);
2543 /* Without automatic stack alignment, we can't increase preferred
2544 stack boundary. With automatic stack alignment, it is
2545 unnecessary since unless we can guarantee that all callers will
2546 align the outgoing stack properly, callee has to align its
2549 && i
->preferred_incoming_stack_boundary
2550 && i
->preferred_incoming_stack_boundary
< preferred_stack_boundary
)
2551 preferred_stack_boundary
= i
->preferred_incoming_stack_boundary
;
2554 /* Operand 0 is a pointer-to-function; get the type of the function. */
2555 funtype
= TREE_TYPE (addr
);
2556 gcc_assert (POINTER_TYPE_P (funtype
));
2557 funtype
= TREE_TYPE (funtype
);
2559 /* Count whether there are actual complex arguments that need to be split
2560 into their real and imaginary parts. Munge the type_arg_types
2561 appropriately here as well. */
2562 if (targetm
.calls
.split_complex_arg
)
2564 call_expr_arg_iterator iter
;
2566 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2568 tree type
= TREE_TYPE (arg
);
2569 if (type
&& TREE_CODE (type
) == COMPLEX_TYPE
2570 && targetm
.calls
.split_complex_arg (type
))
2571 num_complex_actuals
++;
2573 type_arg_types
= split_complex_types (TYPE_ARG_TYPES (funtype
));
2576 type_arg_types
= TYPE_ARG_TYPES (funtype
);
2578 if (flags
& ECF_MAY_BE_ALLOCA
)
2579 cfun
->calls_alloca
= 1;
2581 /* If struct_value_rtx is 0, it means pass the address
2582 as if it were an extra parameter. Put the argument expression
2583 in structure_value_addr_value. */
2584 if (structure_value_addr
&& struct_value
== 0)
2586 /* If structure_value_addr is a REG other than
2587 virtual_outgoing_args_rtx, we can use always use it. If it
2588 is not a REG, we must always copy it into a register.
2589 If it is virtual_outgoing_args_rtx, we must copy it to another
2590 register in some cases. */
2591 rtx temp
= (!REG_P (structure_value_addr
)
2592 || (ACCUMULATE_OUTGOING_ARGS
2593 && stack_arg_under_construction
2594 && structure_value_addr
== virtual_outgoing_args_rtx
)
2595 ? copy_addr_to_reg (convert_memory_address
2596 (Pmode
, structure_value_addr
))
2597 : structure_value_addr
);
2599 structure_value_addr_value
=
2600 make_tree (build_pointer_type (TREE_TYPE (funtype
)), temp
);
2601 structure_value_addr_parm
= CALL_WITH_BOUNDS_P (exp
) ? 2 : 1;
2604 /* Count the arguments and set NUM_ACTUALS. */
2606 call_expr_nargs (exp
) + num_complex_actuals
+ structure_value_addr_parm
;
2608 /* Compute number of named args.
2609 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2611 if (type_arg_types
!= 0)
2613 = (list_length (type_arg_types
)
2614 /* Count the struct value address, if it is passed as a parm. */
2615 + structure_value_addr_parm
);
2617 /* If we know nothing, treat all args as named. */
2618 n_named_args
= num_actuals
;
2620 /* Start updating where the next arg would go.
2622 On some machines (such as the PA) indirect calls have a different
2623 calling convention than normal calls. The fourth argument in
2624 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2626 INIT_CUMULATIVE_ARGS (args_so_far_v
, funtype
, NULL_RTX
, fndecl
, n_named_args
);
2627 args_so_far
= pack_cumulative_args (&args_so_far_v
);
2629 /* Now possibly adjust the number of named args.
2630 Normally, don't include the last named arg if anonymous args follow.
2631 We do include the last named arg if
2632 targetm.calls.strict_argument_naming() returns nonzero.
2633 (If no anonymous args follow, the result of list_length is actually
2634 one too large. This is harmless.)
2636 If targetm.calls.pretend_outgoing_varargs_named() returns
2637 nonzero, and targetm.calls.strict_argument_naming() returns zero,
2638 this machine will be able to place unnamed args that were passed
2639 in registers into the stack. So treat all args as named. This
2640 allows the insns emitting for a specific argument list to be
2641 independent of the function declaration.
2643 If targetm.calls.pretend_outgoing_varargs_named() returns zero,
2644 we do not have any reliable way to pass unnamed args in
2645 registers, so we must force them into memory. */
2647 if (type_arg_types
!= 0
2648 && targetm
.calls
.strict_argument_naming (args_so_far
))
2650 else if (type_arg_types
!= 0
2651 && ! targetm
.calls
.pretend_outgoing_varargs_named (args_so_far
))
2652 /* Don't include the last named arg. */
2655 /* Treat all args as named. */
2656 n_named_args
= num_actuals
;
2658 /* Make a vector to hold all the information about each arg. */
2659 args
= XALLOCAVEC (struct arg_data
, num_actuals
);
2660 memset (args
, 0, num_actuals
* sizeof (struct arg_data
));
2662 /* Build up entries in the ARGS array, compute the size of the
2663 arguments into ARGS_SIZE, etc. */
2664 initialize_argument_information (num_actuals
, args
, &args_size
,
2666 structure_value_addr_value
, fndecl
, fntype
,
2667 args_so_far
, reg_parm_stack_space
,
2668 &old_stack_level
, &old_pending_adj
,
2669 &must_preallocate
, &flags
,
2670 &try_tail_call
, CALL_FROM_THUNK_P (exp
));
2673 must_preallocate
= 1;
2675 /* Now make final decision about preallocating stack space. */
2676 must_preallocate
= finalize_must_preallocate (must_preallocate
,
2680 /* If the structure value address will reference the stack pointer, we
2681 must stabilize it. We don't need to do this if we know that we are
2682 not going to adjust the stack pointer in processing this call. */
2684 if (structure_value_addr
2685 && (reg_mentioned_p (virtual_stack_dynamic_rtx
, structure_value_addr
)
2686 || reg_mentioned_p (virtual_outgoing_args_rtx
,
2687 structure_value_addr
))
2689 || (!ACCUMULATE_OUTGOING_ARGS
&& args_size
.constant
)))
2690 structure_value_addr
= copy_to_reg (structure_value_addr
);
2692 /* Tail calls can make things harder to debug, and we've traditionally
2693 pushed these optimizations into -O2. Don't try if we're already
2694 expanding a call, as that means we're an argument. Don't try if
2695 there's cleanups, as we know there's code to follow the call. */
2697 if (currently_expanding_call
++ != 0
2698 || !flag_optimize_sibling_calls
2700 || dbg_cnt (tail_call
) == false)
2703 /* Rest of purposes for tail call optimizations to fail. */
2705 #ifdef HAVE_sibcall_epilogue
2706 !HAVE_sibcall_epilogue
2711 /* Doing sibling call optimization needs some work, since
2712 structure_value_addr can be allocated on the stack.
2713 It does not seem worth the effort since few optimizable
2714 sibling calls will return a structure. */
2715 || structure_value_addr
!= NULL_RTX
2716 #ifdef REG_PARM_STACK_SPACE
2717 /* If outgoing reg parm stack space changes, we can not do sibcall. */
2718 || (OUTGOING_REG_PARM_STACK_SPACE (funtype
)
2719 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl
)))
2720 || (reg_parm_stack_space
!= REG_PARM_STACK_SPACE (current_function_decl
))
2722 /* Check whether the target is able to optimize the call
2724 || !targetm
.function_ok_for_sibcall (fndecl
, exp
)
2725 /* Functions that do not return exactly once may not be sibcall
2727 || (flags
& (ECF_RETURNS_TWICE
| ECF_NORETURN
))
2728 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr
)))
2729 /* If the called function is nested in the current one, it might access
2730 some of the caller's arguments, but could clobber them beforehand if
2731 the argument areas are shared. */
2732 || (fndecl
&& decl_function_context (fndecl
) == current_function_decl
)
2733 /* If this function requires more stack slots than the current
2734 function, we cannot change it into a sibling call.
2735 crtl->args.pretend_args_size is not part of the
2736 stack allocated by our caller. */
2737 || args_size
.constant
> (crtl
->args
.size
2738 - crtl
->args
.pretend_args_size
)
2739 /* If the callee pops its own arguments, then it must pop exactly
2740 the same number of arguments as the current function. */
2741 || (targetm
.calls
.return_pops_args (fndecl
, funtype
, args_size
.constant
)
2742 != targetm
.calls
.return_pops_args (current_function_decl
,
2743 TREE_TYPE (current_function_decl
),
2745 || !lang_hooks
.decls
.ok_for_sibcall (fndecl
))
2748 /* Check if caller and callee disagree in promotion of function
2752 machine_mode caller_mode
, caller_promoted_mode
;
2753 machine_mode callee_mode
, callee_promoted_mode
;
2754 int caller_unsignedp
, callee_unsignedp
;
2755 tree caller_res
= DECL_RESULT (current_function_decl
);
2757 caller_unsignedp
= TYPE_UNSIGNED (TREE_TYPE (caller_res
));
2758 caller_mode
= DECL_MODE (caller_res
);
2759 callee_unsignedp
= TYPE_UNSIGNED (TREE_TYPE (funtype
));
2760 callee_mode
= TYPE_MODE (TREE_TYPE (funtype
));
2761 caller_promoted_mode
2762 = promote_function_mode (TREE_TYPE (caller_res
), caller_mode
,
2764 TREE_TYPE (current_function_decl
), 1);
2765 callee_promoted_mode
2766 = promote_function_mode (TREE_TYPE (funtype
), callee_mode
,
2769 if (caller_mode
!= VOIDmode
2770 && (caller_promoted_mode
!= callee_promoted_mode
2771 || ((caller_mode
!= caller_promoted_mode
2772 || callee_mode
!= callee_promoted_mode
)
2773 && (caller_unsignedp
!= callee_unsignedp
2774 || GET_MODE_BITSIZE (caller_mode
)
2775 < GET_MODE_BITSIZE (callee_mode
)))))
2779 /* Ensure current function's preferred stack boundary is at least
2780 what we need. Stack alignment may also increase preferred stack
2782 if (crtl
->preferred_stack_boundary
< preferred_stack_boundary
)
2783 crtl
->preferred_stack_boundary
= preferred_stack_boundary
;
2785 preferred_stack_boundary
= crtl
->preferred_stack_boundary
;
2787 preferred_unit_stack_boundary
= preferred_stack_boundary
/ BITS_PER_UNIT
;
2789 /* We want to make two insn chains; one for a sibling call, the other
2790 for a normal call. We will select one of the two chains after
2791 initial RTL generation is complete. */
2792 for (pass
= try_tail_call
? 0 : 1; pass
< 2; pass
++)
2794 int sibcall_failure
= 0;
2795 /* We want to emit any pending stack adjustments before the tail
2796 recursion "call". That way we know any adjustment after the tail
2797 recursion call can be ignored if we indeed use the tail
2799 saved_pending_stack_adjust save
;
2800 rtx_insn
*insns
, *before_call
, *after_args
;
2805 /* State variables we need to save and restore between
2807 save_pending_stack_adjust (&save
);
2810 flags
&= ~ECF_SIBCALL
;
2812 flags
|= ECF_SIBCALL
;
2814 /* Other state variables that we must reinitialize each time
2815 through the loop (that are not initialized by the loop itself). */
2819 /* Start a new sequence for the normal call case.
2821 From this point on, if the sibling call fails, we want to set
2822 sibcall_failure instead of continuing the loop. */
2825 /* Don't let pending stack adjusts add up to too much.
2826 Also, do all pending adjustments now if there is any chance
2827 this might be a call to alloca or if we are expanding a sibling
2829 Also do the adjustments before a throwing call, otherwise
2830 exception handling can fail; PR 19225. */
2831 if (pending_stack_adjust
>= 32
2832 || (pending_stack_adjust
> 0
2833 && (flags
& ECF_MAY_BE_ALLOCA
))
2834 || (pending_stack_adjust
> 0
2835 && flag_exceptions
&& !(flags
& ECF_NOTHROW
))
2837 do_pending_stack_adjust ();
2839 /* Precompute any arguments as needed. */
2841 precompute_arguments (num_actuals
, args
);
2843 /* Now we are about to start emitting insns that can be deleted
2844 if a libcall is deleted. */
2845 if (pass
&& (flags
& ECF_MALLOC
))
2848 if (pass
== 0 && crtl
->stack_protect_guard
)
2849 stack_protect_epilogue ();
2851 adjusted_args_size
= args_size
;
2852 /* Compute the actual size of the argument block required. The variable
2853 and constant sizes must be combined, the size may have to be rounded,
2854 and there may be a minimum required size. When generating a sibcall
2855 pattern, do not round up, since we'll be re-using whatever space our
2857 unadjusted_args_size
2858 = compute_argument_block_size (reg_parm_stack_space
,
2859 &adjusted_args_size
,
2862 : preferred_stack_boundary
));
2864 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
2866 /* The argument block when performing a sibling call is the
2867 incoming argument block. */
2870 argblock
= crtl
->args
.internal_arg_pointer
;
2872 #ifdef STACK_GROWS_DOWNWARD
2873 = plus_constant (Pmode
, argblock
, crtl
->args
.pretend_args_size
);
2875 = plus_constant (Pmode
, argblock
, -crtl
->args
.pretend_args_size
);
2877 stored_args_map
= sbitmap_alloc (args_size
.constant
);
2878 bitmap_clear (stored_args_map
);
2881 /* If we have no actual push instructions, or shouldn't use them,
2882 make space for all args right now. */
2883 else if (adjusted_args_size
.var
!= 0)
2885 if (old_stack_level
== 0)
2887 emit_stack_save (SAVE_BLOCK
, &old_stack_level
);
2888 old_stack_pointer_delta
= stack_pointer_delta
;
2889 old_pending_adj
= pending_stack_adjust
;
2890 pending_stack_adjust
= 0;
2891 /* stack_arg_under_construction says whether a stack arg is
2892 being constructed at the old stack level. Pushing the stack
2893 gets a clean outgoing argument block. */
2894 old_stack_arg_under_construction
= stack_arg_under_construction
;
2895 stack_arg_under_construction
= 0;
2897 argblock
= push_block (ARGS_SIZE_RTX (adjusted_args_size
), 0, 0);
2898 if (flag_stack_usage_info
)
2899 current_function_has_unbounded_dynamic_stack_size
= 1;
2903 /* Note that we must go through the motions of allocating an argument
2904 block even if the size is zero because we may be storing args
2905 in the area reserved for register arguments, which may be part of
2908 int needed
= adjusted_args_size
.constant
;
2910 /* Store the maximum argument space used. It will be pushed by
2911 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2914 if (needed
> crtl
->outgoing_args_size
)
2915 crtl
->outgoing_args_size
= needed
;
2917 if (must_preallocate
)
2919 if (ACCUMULATE_OUTGOING_ARGS
)
2921 /* Since the stack pointer will never be pushed, it is
2922 possible for the evaluation of a parm to clobber
2923 something we have already written to the stack.
2924 Since most function calls on RISC machines do not use
2925 the stack, this is uncommon, but must work correctly.
2927 Therefore, we save any area of the stack that was already
2928 written and that we are using. Here we set up to do this
2929 by making a new stack usage map from the old one. The
2930 actual save will be done by store_one_arg.
2932 Another approach might be to try to reorder the argument
2933 evaluations to avoid this conflicting stack usage. */
2935 /* Since we will be writing into the entire argument area,
2936 the map must be allocated for its entire size, not just
2937 the part that is the responsibility of the caller. */
2938 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
2939 needed
+= reg_parm_stack_space
;
2941 #ifdef ARGS_GROW_DOWNWARD
2942 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
2945 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
2948 free (stack_usage_map_buf
);
2949 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
2950 stack_usage_map
= stack_usage_map_buf
;
2952 if (initial_highest_arg_in_use
)
2953 memcpy (stack_usage_map
, initial_stack_usage_map
,
2954 initial_highest_arg_in_use
);
2956 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
2957 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
2958 (highest_outgoing_arg_in_use
2959 - initial_highest_arg_in_use
));
2962 /* The address of the outgoing argument list must not be
2963 copied to a register here, because argblock would be left
2964 pointing to the wrong place after the call to
2965 allocate_dynamic_stack_space below. */
2967 argblock
= virtual_outgoing_args_rtx
;
2971 if (inhibit_defer_pop
== 0)
2973 /* Try to reuse some or all of the pending_stack_adjust
2974 to get this space. */
2976 = (combine_pending_stack_adjustment_and_call
2977 (unadjusted_args_size
,
2978 &adjusted_args_size
,
2979 preferred_unit_stack_boundary
));
2981 /* combine_pending_stack_adjustment_and_call computes
2982 an adjustment before the arguments are allocated.
2983 Account for them and see whether or not the stack
2984 needs to go up or down. */
2985 needed
= unadjusted_args_size
- needed
;
2989 /* We're releasing stack space. */
2990 /* ??? We can avoid any adjustment at all if we're
2991 already aligned. FIXME. */
2992 pending_stack_adjust
= -needed
;
2993 do_pending_stack_adjust ();
2997 /* We need to allocate space. We'll do that in
2998 push_block below. */
2999 pending_stack_adjust
= 0;
3002 /* Special case this because overhead of `push_block' in
3003 this case is non-trivial. */
3005 argblock
= virtual_outgoing_args_rtx
;
3008 argblock
= push_block (GEN_INT (needed
), 0, 0);
3009 #ifdef ARGS_GROW_DOWNWARD
3010 argblock
= plus_constant (Pmode
, argblock
, needed
);
3014 /* We only really need to call `copy_to_reg' in the case
3015 where push insns are going to be used to pass ARGBLOCK
3016 to a function call in ARGS. In that case, the stack
3017 pointer changes value from the allocation point to the
3018 call point, and hence the value of
3019 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
3020 as well always do it. */
3021 argblock
= copy_to_reg (argblock
);
3026 if (ACCUMULATE_OUTGOING_ARGS
)
3028 /* The save/restore code in store_one_arg handles all
3029 cases except one: a constructor call (including a C
3030 function returning a BLKmode struct) to initialize
3032 if (stack_arg_under_construction
)
3035 = GEN_INT (adjusted_args_size
.constant
3036 + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
3037 : TREE_TYPE (fndecl
))) ? 0
3038 : reg_parm_stack_space
));
3039 if (old_stack_level
== 0)
3041 emit_stack_save (SAVE_BLOCK
, &old_stack_level
);
3042 old_stack_pointer_delta
= stack_pointer_delta
;
3043 old_pending_adj
= pending_stack_adjust
;
3044 pending_stack_adjust
= 0;
3045 /* stack_arg_under_construction says whether a stack
3046 arg is being constructed at the old stack level.
3047 Pushing the stack gets a clean outgoing argument
3049 old_stack_arg_under_construction
3050 = stack_arg_under_construction
;
3051 stack_arg_under_construction
= 0;
3052 /* Make a new map for the new argument list. */
3053 free (stack_usage_map_buf
);
3054 stack_usage_map_buf
= XCNEWVEC (char, highest_outgoing_arg_in_use
);
3055 stack_usage_map
= stack_usage_map_buf
;
3056 highest_outgoing_arg_in_use
= 0;
3058 /* We can pass TRUE as the 4th argument because we just
3059 saved the stack pointer and will restore it right after
3061 allocate_dynamic_stack_space (push_size
, 0,
3062 BIGGEST_ALIGNMENT
, true);
3065 /* If argument evaluation might modify the stack pointer,
3066 copy the address of the argument list to a register. */
3067 for (i
= 0; i
< num_actuals
; i
++)
3068 if (args
[i
].pass_on_stack
)
3070 argblock
= copy_addr_to_reg (argblock
);
3075 compute_argument_addresses (args
, argblock
, num_actuals
);
3077 /* Perform stack alignment before the first push (the last arg). */
3079 && adjusted_args_size
.constant
> reg_parm_stack_space
3080 && adjusted_args_size
.constant
!= unadjusted_args_size
)
3082 /* When the stack adjustment is pending, we get better code
3083 by combining the adjustments. */
3084 if (pending_stack_adjust
3085 && ! inhibit_defer_pop
)
3087 pending_stack_adjust
3088 = (combine_pending_stack_adjustment_and_call
3089 (unadjusted_args_size
,
3090 &adjusted_args_size
,
3091 preferred_unit_stack_boundary
));
3092 do_pending_stack_adjust ();
3094 else if (argblock
== 0)
3095 anti_adjust_stack (GEN_INT (adjusted_args_size
.constant
3096 - unadjusted_args_size
));
3098 /* Now that the stack is properly aligned, pops can't safely
3099 be deferred during the evaluation of the arguments. */
3102 /* Record the maximum pushed stack space size. We need to delay
3103 doing it this far to take into account the optimization done
3104 by combine_pending_stack_adjustment_and_call. */
3105 if (flag_stack_usage_info
3106 && !ACCUMULATE_OUTGOING_ARGS
3108 && adjusted_args_size
.var
== 0)
3110 int pushed
= adjusted_args_size
.constant
+ pending_stack_adjust
;
3111 if (pushed
> current_function_pushed_stack_size
)
3112 current_function_pushed_stack_size
= pushed
;
3115 funexp
= rtx_for_function_call (fndecl
, addr
);
3117 /* Precompute all register parameters. It isn't safe to compute anything
3118 once we have started filling any specific hard regs. */
3119 precompute_register_parameters (num_actuals
, args
, ®_parm_seen
);
3121 if (CALL_EXPR_STATIC_CHAIN (exp
))
3122 static_chain_value
= expand_normal (CALL_EXPR_STATIC_CHAIN (exp
));
3124 static_chain_value
= 0;
3126 #ifdef REG_PARM_STACK_SPACE
3127 /* Save the fixed argument area if it's part of the caller's frame and
3128 is clobbered by argument setup for this call. */
3129 if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
3130 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
3131 &low_to_save
, &high_to_save
);
3134 /* Now store (and compute if necessary) all non-register parms.
3135 These come before register parms, since they can require block-moves,
3136 which could clobber the registers used for register parms.
3137 Parms which have partial registers are not stored here,
3138 but we do preallocate space here if they want that. */
3140 for (i
= 0; i
< num_actuals
; i
++)
3142 /* Delay bounds until all other args are stored. */
3143 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
3145 else if (args
[i
].reg
== 0 || args
[i
].pass_on_stack
)
3147 rtx_insn
*before_arg
= get_last_insn ();
3149 /* We don't allow passing huge (> 2^30 B) arguments
3150 by value. It would cause an overflow later on. */
3151 if (adjusted_args_size
.constant
3152 >= (1 << (HOST_BITS_PER_INT
- 2)))
3154 sorry ("passing too large argument on stack");
3158 if (store_one_arg (&args
[i
], argblock
, flags
,
3159 adjusted_args_size
.var
!= 0,
3160 reg_parm_stack_space
)
3162 && check_sibcall_argument_overlap (before_arg
,
3164 sibcall_failure
= 1;
3169 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)),
3170 gen_rtx_USE (VOIDmode
, args
[i
].stack
),
3174 /* If we have a parm that is passed in registers but not in memory
3175 and whose alignment does not permit a direct copy into registers,
3176 make a group of pseudos that correspond to each register that we
3178 if (STRICT_ALIGNMENT
)
3179 store_unaligned_arguments_into_pseudos (args
, num_actuals
);
3181 /* Now store any partially-in-registers parm.
3182 This is the last place a block-move can happen. */
3184 for (i
= 0; i
< num_actuals
; i
++)
3185 if (args
[i
].partial
!= 0 && ! args
[i
].pass_on_stack
)
3187 rtx_insn
*before_arg
= get_last_insn ();
3189 if (store_one_arg (&args
[i
], argblock
, flags
,
3190 adjusted_args_size
.var
!= 0,
3191 reg_parm_stack_space
)
3193 && check_sibcall_argument_overlap (before_arg
,
3195 sibcall_failure
= 1;
3198 bool any_regs
= false;
3199 for (i
= 0; i
< num_actuals
; i
++)
3200 if (args
[i
].reg
!= NULL_RTX
)
3203 targetm
.calls
.call_args (args
[i
].reg
, funtype
);
3206 targetm
.calls
.call_args (pc_rtx
, funtype
);
3208 /* Figure out the register where the value, if any, will come back. */
3211 if (TYPE_MODE (rettype
) != VOIDmode
3212 && ! structure_value_addr
)
3214 if (pcc_struct_value
)
3216 valreg
= hard_function_value (build_pointer_type (rettype
),
3217 fndecl
, NULL
, (pass
== 0));
3218 if (CALL_WITH_BOUNDS_P (exp
))
3219 valbnd
= targetm
.calls
.
3220 chkp_function_value_bounds (build_pointer_type (rettype
),
3221 fndecl
, (pass
== 0));
3225 valreg
= hard_function_value (rettype
, fndecl
, fntype
,
3227 if (CALL_WITH_BOUNDS_P (exp
))
3228 valbnd
= targetm
.calls
.chkp_function_value_bounds (rettype
,
3233 /* If VALREG is a PARALLEL whose first member has a zero
3234 offset, use that. This is for targets such as m68k that
3235 return the same value in multiple places. */
3236 if (GET_CODE (valreg
) == PARALLEL
)
3238 rtx elem
= XVECEXP (valreg
, 0, 0);
3239 rtx where
= XEXP (elem
, 0);
3240 rtx offset
= XEXP (elem
, 1);
3241 if (offset
== const0_rtx
3242 && GET_MODE (where
) == GET_MODE (valreg
))
3247 /* Store all bounds not passed in registers. */
3248 for (i
= 0; i
< num_actuals
; i
++)
3250 if (POINTER_BOUNDS_P (args
[i
].tree_value
)
3252 store_bounds (&args
[i
],
3253 args
[i
].pointer_arg
== -1
3255 : &args
[args
[i
].pointer_arg
]);
3258 /* If register arguments require space on the stack and stack space
3259 was not preallocated, allocate stack space here for arguments
3260 passed in registers. */
3261 if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
)))
3262 && !ACCUMULATE_OUTGOING_ARGS
3263 && must_preallocate
== 0 && reg_parm_stack_space
> 0)
3264 anti_adjust_stack (GEN_INT (reg_parm_stack_space
));
3266 /* Pass the function the address in which to return a
3268 if (pass
!= 0 && structure_value_addr
&& ! structure_value_addr_parm
)
3270 structure_value_addr
3271 = convert_memory_address (Pmode
, structure_value_addr
);
3272 emit_move_insn (struct_value
,
3274 force_operand (structure_value_addr
,
3277 if (REG_P (struct_value
))
3278 use_reg (&call_fusage
, struct_value
);
3281 after_args
= get_last_insn ();
3282 funexp
= prepare_call_address (fndecl
? fndecl
: fntype
, funexp
,
3283 static_chain_value
, &call_fusage
,
3284 reg_parm_seen
, pass
== 0);
3286 load_register_parameters (args
, num_actuals
, &call_fusage
, flags
,
3287 pass
== 0, &sibcall_failure
);
3289 /* Save a pointer to the last insn before the call, so that we can
3290 later safely search backwards to find the CALL_INSN. */
3291 before_call
= get_last_insn ();
3293 /* Set up next argument register. For sibling calls on machines
3294 with register windows this should be the incoming register. */
3296 next_arg_reg
= targetm
.calls
.function_incoming_arg (args_so_far
,
3301 next_arg_reg
= targetm
.calls
.function_arg (args_so_far
,
3302 VOIDmode
, void_type_node
,
3305 if (pass
== 1 && (return_flags
& ERF_RETURNS_ARG
))
3307 int arg_nr
= return_flags
& ERF_RETURN_ARG_MASK
;
3308 arg_nr
= num_actuals
- arg_nr
- 1;
3310 && arg_nr
< num_actuals
3314 && GET_MODE (args
[arg_nr
].reg
) == GET_MODE (valreg
))
3316 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args
[arg_nr
].tree_value
)),
3317 gen_rtx_SET (VOIDmode
, valreg
, args
[arg_nr
].reg
),
3320 /* All arguments and registers used for the call must be set up by
3323 /* Stack must be properly aligned now. */
3325 || !(stack_pointer_delta
% preferred_unit_stack_boundary
));
3327 /* Generate the actual call instruction. */
3328 emit_call_1 (funexp
, exp
, fndecl
, funtype
, unadjusted_args_size
,
3329 adjusted_args_size
.constant
, struct_value_size
,
3330 next_arg_reg
, valreg
, old_inhibit_defer_pop
, call_fusage
,
3331 flags
, args_so_far
);
3335 rtx_call_insn
*last
;
3336 rtx datum
= NULL_RTX
;
3337 if (fndecl
!= NULL_TREE
)
3339 datum
= XEXP (DECL_RTL (fndecl
), 0);
3340 gcc_assert (datum
!= NULL_RTX
3341 && GET_CODE (datum
) == SYMBOL_REF
);
3343 last
= last_call_insn ();
3344 add_reg_note (last
, REG_CALL_DECL
, datum
);
3347 /* If the call setup or the call itself overlaps with anything
3348 of the argument setup we probably clobbered our call address.
3349 In that case we can't do sibcalls. */
3351 && check_sibcall_argument_overlap (after_args
, 0, 0))
3352 sibcall_failure
= 1;
3354 /* If a non-BLKmode value is returned at the most significant end
3355 of a register, shift the register right by the appropriate amount
3356 and update VALREG accordingly. BLKmode values are handled by the
3357 group load/store machinery below. */
3358 if (!structure_value_addr
3359 && !pcc_struct_value
3360 && TYPE_MODE (rettype
) != VOIDmode
3361 && TYPE_MODE (rettype
) != BLKmode
3363 && targetm
.calls
.return_in_msb (rettype
))
3365 if (shift_return_value (TYPE_MODE (rettype
), false, valreg
))
3366 sibcall_failure
= 1;
3367 valreg
= gen_rtx_REG (TYPE_MODE (rettype
), REGNO (valreg
));
3370 if (pass
&& (flags
& ECF_MALLOC
))
3372 rtx temp
= gen_reg_rtx (GET_MODE (valreg
));
3373 rtx_insn
*last
, *insns
;
3375 /* The return value from a malloc-like function is a pointer. */
3376 if (TREE_CODE (rettype
) == POINTER_TYPE
)
3377 mark_reg_pointer (temp
, MALLOC_ABI_ALIGNMENT
);
3379 emit_move_insn (temp
, valreg
);
3381 /* The return value from a malloc-like function can not alias
3383 last
= get_last_insn ();
3384 add_reg_note (last
, REG_NOALIAS
, temp
);
3386 /* Write out the sequence. */
3387 insns
= get_insns ();
3393 /* For calls to `setjmp', etc., inform
3394 function.c:setjmp_warnings that it should complain if
3395 nonvolatile values are live. For functions that cannot
3396 return, inform flow that control does not fall through. */
3398 if ((flags
& ECF_NORETURN
) || pass
== 0)
3400 /* The barrier must be emitted
3401 immediately after the CALL_INSN. Some ports emit more
3402 than just a CALL_INSN above, so we must search for it here. */
3404 rtx_insn
*last
= get_last_insn ();
3405 while (!CALL_P (last
))
3407 last
= PREV_INSN (last
);
3408 /* There was no CALL_INSN? */
3409 gcc_assert (last
!= before_call
);
3412 emit_barrier_after (last
);
3414 /* Stack adjustments after a noreturn call are dead code.
3415 However when NO_DEFER_POP is in effect, we must preserve
3416 stack_pointer_delta. */
3417 if (inhibit_defer_pop
== 0)
3419 stack_pointer_delta
= old_stack_allocated
;
3420 pending_stack_adjust
= 0;
3424 /* If value type not void, return an rtx for the value. */
3426 if (TYPE_MODE (rettype
) == VOIDmode
3428 target
= const0_rtx
;
3429 else if (structure_value_addr
)
3431 if (target
== 0 || !MEM_P (target
))
3434 = gen_rtx_MEM (TYPE_MODE (rettype
),
3435 memory_address (TYPE_MODE (rettype
),
3436 structure_value_addr
));
3437 set_mem_attributes (target
, rettype
, 1);
3440 else if (pcc_struct_value
)
3442 /* This is the special C++ case where we need to
3443 know what the true target was. We take care to
3444 never use this value more than once in one expression. */
3445 target
= gen_rtx_MEM (TYPE_MODE (rettype
),
3446 copy_to_reg (valreg
));
3447 set_mem_attributes (target
, rettype
, 1);
3449 /* Handle calls that return values in multiple non-contiguous locations.
3450 The Irix 6 ABI has examples of this. */
3451 else if (GET_CODE (valreg
) == PARALLEL
)
3454 target
= emit_group_move_into_temps (valreg
);
3455 else if (rtx_equal_p (target
, valreg
))
3457 else if (GET_CODE (target
) == PARALLEL
)
3458 /* Handle the result of a emit_group_move_into_temps
3459 call in the previous pass. */
3460 emit_group_move (target
, valreg
);
3462 emit_group_store (target
, valreg
, rettype
,
3463 int_size_in_bytes (rettype
));
3466 && GET_MODE (target
) == TYPE_MODE (rettype
)
3467 && GET_MODE (target
) == GET_MODE (valreg
))
3469 bool may_overlap
= false;
3471 /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
3472 reg to a plain register. */
3473 if (!REG_P (target
) || HARD_REGISTER_P (target
))
3474 valreg
= avoid_likely_spilled_reg (valreg
);
3476 /* If TARGET is a MEM in the argument area, and we have
3477 saved part of the argument area, then we can't store
3478 directly into TARGET as it may get overwritten when we
3479 restore the argument save area below. Don't work too
3480 hard though and simply force TARGET to a register if it
3481 is a MEM; the optimizer is quite likely to sort it out. */
3482 if (ACCUMULATE_OUTGOING_ARGS
&& pass
&& MEM_P (target
))
3483 for (i
= 0; i
< num_actuals
; i
++)
3484 if (args
[i
].save_area
)
3491 target
= copy_to_reg (valreg
);
3494 /* TARGET and VALREG cannot be equal at this point
3495 because the latter would not have
3496 REG_FUNCTION_VALUE_P true, while the former would if
3497 it were referring to the same register.
3499 If they refer to the same register, this move will be
3500 a no-op, except when function inlining is being
3502 emit_move_insn (target
, valreg
);
3504 /* If we are setting a MEM, this code must be executed.
3505 Since it is emitted after the call insn, sibcall
3506 optimization cannot be performed in that case. */
3508 sibcall_failure
= 1;
3512 target
= copy_to_reg (avoid_likely_spilled_reg (valreg
));
3514 /* If we promoted this return value, make the proper SUBREG.
3515 TARGET might be const0_rtx here, so be careful. */
3517 && TYPE_MODE (rettype
) != BLKmode
3518 && GET_MODE (target
) != TYPE_MODE (rettype
))
3520 tree type
= rettype
;
3521 int unsignedp
= TYPE_UNSIGNED (type
);
3525 /* Ensure we promote as expected, and get the new unsignedness. */
3526 pmode
= promote_function_mode (type
, TYPE_MODE (type
), &unsignedp
,
3528 gcc_assert (GET_MODE (target
) == pmode
);
3530 if ((WORDS_BIG_ENDIAN
|| BYTES_BIG_ENDIAN
)
3531 && (GET_MODE_SIZE (GET_MODE (target
))
3532 > GET_MODE_SIZE (TYPE_MODE (type
))))
3534 offset
= GET_MODE_SIZE (GET_MODE (target
))
3535 - GET_MODE_SIZE (TYPE_MODE (type
));
3536 if (! BYTES_BIG_ENDIAN
)
3537 offset
= (offset
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3538 else if (! WORDS_BIG_ENDIAN
)
3539 offset
%= UNITS_PER_WORD
;
3542 target
= gen_rtx_SUBREG (TYPE_MODE (type
), target
, offset
);
3543 SUBREG_PROMOTED_VAR_P (target
) = 1;
3544 SUBREG_PROMOTED_SET (target
, unsignedp
);
3547 /* If size of args is variable or this was a constructor call for a stack
3548 argument, restore saved stack-pointer value. */
3550 if (old_stack_level
)
3552 rtx_insn
*prev
= get_last_insn ();
3554 emit_stack_restore (SAVE_BLOCK
, old_stack_level
);
3555 stack_pointer_delta
= old_stack_pointer_delta
;
3557 fixup_args_size_notes (prev
, get_last_insn (), stack_pointer_delta
);
3559 pending_stack_adjust
= old_pending_adj
;
3560 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
3561 stack_arg_under_construction
= old_stack_arg_under_construction
;
3562 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3563 stack_usage_map
= initial_stack_usage_map
;
3564 sibcall_failure
= 1;
3566 else if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
3568 #ifdef REG_PARM_STACK_SPACE
3570 restore_fixed_argument_area (save_area
, argblock
,
3571 high_to_save
, low_to_save
);
3574 /* If we saved any argument areas, restore them. */
3575 for (i
= 0; i
< num_actuals
; i
++)
3576 if (args
[i
].save_area
)
3578 machine_mode save_mode
= GET_MODE (args
[i
].save_area
);
3580 = gen_rtx_MEM (save_mode
,
3581 memory_address (save_mode
,
3582 XEXP (args
[i
].stack_slot
, 0)));
3584 if (save_mode
!= BLKmode
)
3585 emit_move_insn (stack_area
, args
[i
].save_area
);
3587 emit_block_move (stack_area
, args
[i
].save_area
,
3588 GEN_INT (args
[i
].locate
.size
.constant
),
3589 BLOCK_OP_CALL_PARM
);
3592 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3593 stack_usage_map
= initial_stack_usage_map
;
3596 /* If this was alloca, record the new stack level for nonlocal gotos.
3597 Check for the handler slots since we might not have a save area
3598 for non-local gotos. */
3600 if ((flags
& ECF_MAY_BE_ALLOCA
) && cfun
->nonlocal_goto_save_area
!= 0)
3601 update_nonlocal_goto_save_area ();
3603 /* Free up storage we no longer need. */
3604 for (i
= 0; i
< num_actuals
; ++i
)
3605 free (args
[i
].aligned_regs
);
3607 targetm
.calls
.end_call_args ();
3609 insns
= get_insns ();
3614 tail_call_insns
= insns
;
3616 /* Restore the pending stack adjustment now that we have
3617 finished generating the sibling call sequence. */
3619 restore_pending_stack_adjust (&save
);
3621 /* Prepare arg structure for next iteration. */
3622 for (i
= 0; i
< num_actuals
; i
++)
3625 args
[i
].aligned_regs
= 0;
3629 sbitmap_free (stored_args_map
);
3630 internal_arg_pointer_exp_state
.scan_start
= NULL
;
3631 internal_arg_pointer_exp_state
.cache
.release ();
3635 normal_call_insns
= insns
;
3637 /* Verify that we've deallocated all the stack we used. */
3638 gcc_assert ((flags
& ECF_NORETURN
)
3639 || (old_stack_allocated
3640 == stack_pointer_delta
- pending_stack_adjust
));
3643 /* If something prevents making this a sibling call,
3644 zero out the sequence. */
3645 if (sibcall_failure
)
3646 tail_call_insns
= NULL
;
3651 /* If tail call production succeeded, we need to remove REG_EQUIV notes on
3652 arguments too, as argument area is now clobbered by the call. */
3653 if (tail_call_insns
)
3655 emit_insn (tail_call_insns
);
3656 crtl
->tail_call_emit
= true;
3659 emit_insn (normal_call_insns
);
3661 currently_expanding_call
--;
3663 free (stack_usage_map_buf
);
3665 /* Join result with returned bounds so caller may use them if needed. */
3666 target
= chkp_join_splitted_slot (target
, valbnd
);
3671 /* A sibling call sequence invalidates any REG_EQUIV notes made for
3672 this function's incoming arguments.
3674 At the start of RTL generation we know the only REG_EQUIV notes
3675 in the rtl chain are those for incoming arguments, so we can look
3676 for REG_EQUIV notes between the start of the function and the
3677 NOTE_INSN_FUNCTION_BEG.
3679 This is (slight) overkill. We could keep track of the highest
3680 argument we clobber and be more selective in removing notes, but it
3681 does not seem to be worth the effort. */
3684 fixup_tail_calls (void)
3688 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3692 /* There are never REG_EQUIV notes for the incoming arguments
3693 after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
3695 && NOTE_KIND (insn
) == NOTE_INSN_FUNCTION_BEG
)
3698 note
= find_reg_note (insn
, REG_EQUIV
, 0);
3700 remove_note (insn
, note
);
3701 note
= find_reg_note (insn
, REG_EQUIV
, 0);
3706 /* Traverse a list of TYPES and expand all complex types into their
3709 split_complex_types (tree types
)
3713 /* Before allocating memory, check for the common case of no complex. */
3714 for (p
= types
; p
; p
= TREE_CHAIN (p
))
3716 tree type
= TREE_VALUE (p
);
3717 if (TREE_CODE (type
) == COMPLEX_TYPE
3718 && targetm
.calls
.split_complex_arg (type
))
3724 types
= copy_list (types
);
3726 for (p
= types
; p
; p
= TREE_CHAIN (p
))
3728 tree complex_type
= TREE_VALUE (p
);
3730 if (TREE_CODE (complex_type
) == COMPLEX_TYPE
3731 && targetm
.calls
.split_complex_arg (complex_type
))
3735 /* Rewrite complex type with component type. */
3736 TREE_VALUE (p
) = TREE_TYPE (complex_type
);
3737 next
= TREE_CHAIN (p
);
3739 /* Add another component type for the imaginary part. */
3740 imag
= build_tree_list (NULL_TREE
, TREE_VALUE (p
));
3741 TREE_CHAIN (p
) = imag
;
3742 TREE_CHAIN (imag
) = next
;
3744 /* Skip the newly created node. */
3752 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3753 The RETVAL parameter specifies whether return value needs to be saved, other
3754 parameters are documented in the emit_library_call function below. */
3757 emit_library_call_value_1 (int retval
, rtx orgfun
, rtx value
,
3758 enum libcall_type fn_type
,
3759 machine_mode outmode
, int nargs
, va_list p
)
3761 /* Total size in bytes of all the stack-parms scanned so far. */
3762 struct args_size args_size
;
3763 /* Size of arguments before any adjustments (such as rounding). */
3764 struct args_size original_args_size
;
3767 /* Todo, choose the correct decl type of orgfun. Sadly this information
3768 isn't present here, so we default to native calling abi here. */
3769 tree fndecl ATTRIBUTE_UNUSED
= NULL_TREE
; /* library calls default to host calling abi ? */
3770 tree fntype ATTRIBUTE_UNUSED
= NULL_TREE
; /* library calls default to host calling abi ? */
3773 CUMULATIVE_ARGS args_so_far_v
;
3774 cumulative_args_t args_so_far
;
3781 struct locate_and_pad_arg_data locate
;
3785 int old_inhibit_defer_pop
= inhibit_defer_pop
;
3786 rtx call_fusage
= 0;
3789 int pcc_struct_value
= 0;
3790 int struct_value_size
= 0;
3792 int reg_parm_stack_space
= 0;
3794 rtx_insn
*before_call
;
3795 tree tfom
; /* type_for_mode (outmode, 0) */
3797 #ifdef REG_PARM_STACK_SPACE
3798 /* Define the boundary of the register parm stack space that needs to be
3800 int low_to_save
= 0, high_to_save
= 0;
3801 rtx save_area
= 0; /* Place that it is saved. */
3804 /* Size of the stack reserved for parameter registers. */
3805 int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
3806 char *initial_stack_usage_map
= stack_usage_map
;
3807 char *stack_usage_map_buf
= NULL
;
3809 rtx struct_value
= targetm
.calls
.struct_value_rtx (0, 0);
3811 #ifdef REG_PARM_STACK_SPACE
3812 reg_parm_stack_space
= REG_PARM_STACK_SPACE ((tree
) 0);
3815 /* By default, library functions can not throw. */
3816 flags
= ECF_NOTHROW
;
3829 flags
|= ECF_NORETURN
;
3832 flags
= ECF_NORETURN
;
3834 case LCT_RETURNS_TWICE
:
3835 flags
= ECF_RETURNS_TWICE
;
3840 /* Ensure current function's preferred stack boundary is at least
3842 if (crtl
->preferred_stack_boundary
< PREFERRED_STACK_BOUNDARY
)
3843 crtl
->preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
3845 /* If this kind of value comes back in memory,
3846 decide where in memory it should come back. */
3847 if (outmode
!= VOIDmode
)
3849 tfom
= lang_hooks
.types
.type_for_mode (outmode
, 0);
3850 if (aggregate_value_p (tfom
, 0))
3852 #ifdef PCC_STATIC_STRUCT_RETURN
3854 = hard_function_value (build_pointer_type (tfom
), 0, 0, 0);
3855 mem_value
= gen_rtx_MEM (outmode
, pointer_reg
);
3856 pcc_struct_value
= 1;
3858 value
= gen_reg_rtx (outmode
);
3859 #else /* not PCC_STATIC_STRUCT_RETURN */
3860 struct_value_size
= GET_MODE_SIZE (outmode
);
3861 if (value
!= 0 && MEM_P (value
))
3864 mem_value
= assign_temp (tfom
, 1, 1);
3866 /* This call returns a big structure. */
3867 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
3871 tfom
= void_type_node
;
3873 /* ??? Unfinished: must pass the memory address as an argument. */
3875 /* Copy all the libcall-arguments out of the varargs data
3876 and into a vector ARGVEC.
3878 Compute how to pass each argument. We only support a very small subset
3879 of the full argument passing conventions to limit complexity here since
3880 library functions shouldn't have many args. */
3882 argvec
= XALLOCAVEC (struct arg
, nargs
+ 1);
3883 memset (argvec
, 0, (nargs
+ 1) * sizeof (struct arg
));
3885 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3886 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v
, outmode
, fun
);
3888 INIT_CUMULATIVE_ARGS (args_so_far_v
, NULL_TREE
, fun
, 0, nargs
);
3890 args_so_far
= pack_cumulative_args (&args_so_far_v
);
3892 args_size
.constant
= 0;
3899 /* If there's a structure value address to be passed,
3900 either pass it in the special place, or pass it as an extra argument. */
3901 if (mem_value
&& struct_value
== 0 && ! pcc_struct_value
)
3903 rtx addr
= XEXP (mem_value
, 0);
3907 /* Make sure it is a reasonable operand for a move or push insn. */
3908 if (!REG_P (addr
) && !MEM_P (addr
)
3909 && !(CONSTANT_P (addr
)
3910 && targetm
.legitimate_constant_p (Pmode
, addr
)))
3911 addr
= force_operand (addr
, NULL_RTX
);
3913 argvec
[count
].value
= addr
;
3914 argvec
[count
].mode
= Pmode
;
3915 argvec
[count
].partial
= 0;
3917 argvec
[count
].reg
= targetm
.calls
.function_arg (args_so_far
,
3918 Pmode
, NULL_TREE
, true);
3919 gcc_assert (targetm
.calls
.arg_partial_bytes (args_so_far
, Pmode
,
3920 NULL_TREE
, 1) == 0);
3922 locate_and_pad_parm (Pmode
, NULL_TREE
,
3923 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3926 argvec
[count
].reg
!= 0,
3928 reg_parm_stack_space
, 0,
3929 NULL_TREE
, &args_size
, &argvec
[count
].locate
);
3931 if (argvec
[count
].reg
== 0 || argvec
[count
].partial
!= 0
3932 || reg_parm_stack_space
> 0)
3933 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
3935 targetm
.calls
.function_arg_advance (args_so_far
, Pmode
, (tree
) 0, true);
3940 for (; count
< nargs
; count
++)
3942 rtx val
= va_arg (p
, rtx
);
3943 machine_mode mode
= (machine_mode
) va_arg (p
, int);
3946 /* We cannot convert the arg value to the mode the library wants here;
3947 must do it earlier where we know the signedness of the arg. */
3948 gcc_assert (mode
!= BLKmode
3949 && (GET_MODE (val
) == mode
|| GET_MODE (val
) == VOIDmode
));
3951 /* Make sure it is a reasonable operand for a move or push insn. */
3952 if (!REG_P (val
) && !MEM_P (val
)
3953 && !(CONSTANT_P (val
) && targetm
.legitimate_constant_p (mode
, val
)))
3954 val
= force_operand (val
, NULL_RTX
);
3956 if (pass_by_reference (&args_so_far_v
, mode
, NULL_TREE
, 1))
3960 = !reference_callee_copied (&args_so_far_v
, mode
, NULL_TREE
, 1);
3962 /* If this was a CONST function, it is now PURE since it now
3964 if (flags
& ECF_CONST
)
3966 flags
&= ~ECF_CONST
;
3970 if (MEM_P (val
) && !must_copy
)
3972 tree val_expr
= MEM_EXPR (val
);
3974 mark_addressable (val_expr
);
3979 slot
= assign_temp (lang_hooks
.types
.type_for_mode (mode
, 0),
3981 emit_move_insn (slot
, val
);
3984 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
3985 gen_rtx_USE (VOIDmode
, slot
),
3988 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
3989 gen_rtx_CLOBBER (VOIDmode
,
3994 val
= force_operand (XEXP (slot
, 0), NULL_RTX
);
3997 mode
= promote_function_mode (NULL_TREE
, mode
, &unsigned_p
, NULL_TREE
, 0);
3998 argvec
[count
].mode
= mode
;
3999 argvec
[count
].value
= convert_modes (mode
, GET_MODE (val
), val
, unsigned_p
);
4000 argvec
[count
].reg
= targetm
.calls
.function_arg (args_so_far
, mode
,
4003 argvec
[count
].partial
4004 = targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL_TREE
, 1);
4006 if (argvec
[count
].reg
== 0
4007 || argvec
[count
].partial
!= 0
4008 || reg_parm_stack_space
> 0)
4010 locate_and_pad_parm (mode
, NULL_TREE
,
4011 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4014 argvec
[count
].reg
!= 0,
4016 reg_parm_stack_space
, argvec
[count
].partial
,
4017 NULL_TREE
, &args_size
, &argvec
[count
].locate
);
4018 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
4019 gcc_assert (!argvec
[count
].locate
.size
.var
);
4021 #ifdef BLOCK_REG_PADDING
4023 /* The argument is passed entirely in registers. See at which
4024 end it should be padded. */
4025 argvec
[count
].locate
.where_pad
=
4026 BLOCK_REG_PADDING (mode
, NULL_TREE
,
4027 GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
);
4030 targetm
.calls
.function_arg_advance (args_so_far
, mode
, (tree
) 0, true);
4033 /* If this machine requires an external definition for library
4034 functions, write one out. */
4035 assemble_external_libcall (fun
);
4037 original_args_size
= args_size
;
4038 args_size
.constant
= (((args_size
.constant
4039 + stack_pointer_delta
4043 - stack_pointer_delta
);
4045 args_size
.constant
= MAX (args_size
.constant
,
4046 reg_parm_stack_space
);
4048 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
4049 args_size
.constant
-= reg_parm_stack_space
;
4051 if (args_size
.constant
> crtl
->outgoing_args_size
)
4052 crtl
->outgoing_args_size
= args_size
.constant
;
4054 if (flag_stack_usage_info
&& !ACCUMULATE_OUTGOING_ARGS
)
4056 int pushed
= args_size
.constant
+ pending_stack_adjust
;
4057 if (pushed
> current_function_pushed_stack_size
)
4058 current_function_pushed_stack_size
= pushed
;
4061 if (ACCUMULATE_OUTGOING_ARGS
)
4063 /* Since the stack pointer will never be pushed, it is possible for
4064 the evaluation of a parm to clobber something we have already
4065 written to the stack. Since most function calls on RISC machines
4066 do not use the stack, this is uncommon, but must work correctly.
4068 Therefore, we save any area of the stack that was already written
4069 and that we are using. Here we set up to do this by making a new
4070 stack usage map from the old one.
4072 Another approach might be to try to reorder the argument
4073 evaluations to avoid this conflicting stack usage. */
4075 needed
= args_size
.constant
;
4077 /* Since we will be writing into the entire argument area, the
4078 map must be allocated for its entire size, not just the part that
4079 is the responsibility of the caller. */
4080 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
4081 needed
+= reg_parm_stack_space
;
4083 #ifdef ARGS_GROW_DOWNWARD
4084 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
4087 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
4090 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
4091 stack_usage_map
= stack_usage_map_buf
;
4093 if (initial_highest_arg_in_use
)
4094 memcpy (stack_usage_map
, initial_stack_usage_map
,
4095 initial_highest_arg_in_use
);
4097 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
4098 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
4099 highest_outgoing_arg_in_use
- initial_highest_arg_in_use
);
4102 /* We must be careful to use virtual regs before they're instantiated,
4103 and real regs afterwards. Loop optimization, for example, can create
4104 new libcalls after we've instantiated the virtual regs, and if we
4105 use virtuals anyway, they won't match the rtl patterns. */
4107 if (virtuals_instantiated
)
4108 argblock
= plus_constant (Pmode
, stack_pointer_rtx
,
4109 STACK_POINTER_OFFSET
);
4111 argblock
= virtual_outgoing_args_rtx
;
4116 argblock
= push_block (GEN_INT (args_size
.constant
), 0, 0);
4119 /* We push args individually in reverse order, perform stack alignment
4120 before the first push (the last arg). */
4122 anti_adjust_stack (GEN_INT (args_size
.constant
4123 - original_args_size
.constant
));
4127 #ifdef REG_PARM_STACK_SPACE
4128 if (ACCUMULATE_OUTGOING_ARGS
)
4130 /* The argument list is the property of the called routine and it
4131 may clobber it. If the fixed area has been used for previous
4132 parameters, we must save and restore it. */
4133 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
4134 &low_to_save
, &high_to_save
);
4138 /* When expanding a normal call, args are stored in push order,
4139 which is the reverse of what we have here. */
4140 bool any_regs
= false;
4141 for (int i
= nargs
; i
-- > 0; )
4142 if (argvec
[i
].reg
!= NULL_RTX
)
4144 targetm
.calls
.call_args (argvec
[i
].reg
, NULL_TREE
);
4148 targetm
.calls
.call_args (pc_rtx
, NULL_TREE
);
4150 /* Push the args that need to be pushed. */
4152 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4153 are to be pushed. */
4154 for (count
= 0; count
< nargs
; count
++, argnum
--)
4156 machine_mode mode
= argvec
[argnum
].mode
;
4157 rtx val
= argvec
[argnum
].value
;
4158 rtx reg
= argvec
[argnum
].reg
;
4159 int partial
= argvec
[argnum
].partial
;
4160 unsigned int parm_align
= argvec
[argnum
].locate
.boundary
;
4161 int lower_bound
= 0, upper_bound
= 0, i
;
4163 if (! (reg
!= 0 && partial
== 0))
4167 if (ACCUMULATE_OUTGOING_ARGS
)
4169 /* If this is being stored into a pre-allocated, fixed-size,
4170 stack area, save any previous data at that location. */
4172 #ifdef ARGS_GROW_DOWNWARD
4173 /* stack_slot is negative, but we want to index stack_usage_map
4174 with positive values. */
4175 upper_bound
= -argvec
[argnum
].locate
.slot_offset
.constant
+ 1;
4176 lower_bound
= upper_bound
- argvec
[argnum
].locate
.size
.constant
;
4178 lower_bound
= argvec
[argnum
].locate
.slot_offset
.constant
;
4179 upper_bound
= lower_bound
+ argvec
[argnum
].locate
.size
.constant
;
4183 /* Don't worry about things in the fixed argument area;
4184 it has already been saved. */
4185 if (i
< reg_parm_stack_space
)
4186 i
= reg_parm_stack_space
;
4187 while (i
< upper_bound
&& stack_usage_map
[i
] == 0)
4190 if (i
< upper_bound
)
4192 /* We need to make a save area. */
4194 = argvec
[argnum
].locate
.size
.constant
* BITS_PER_UNIT
;
4195 machine_mode save_mode
4196 = mode_for_size (size
, MODE_INT
, 1);
4198 = plus_constant (Pmode
, argblock
,
4199 argvec
[argnum
].locate
.offset
.constant
);
4201 = gen_rtx_MEM (save_mode
, memory_address (save_mode
, adr
));
4203 if (save_mode
== BLKmode
)
4205 argvec
[argnum
].save_area
4206 = assign_stack_temp (BLKmode
,
4207 argvec
[argnum
].locate
.size
.constant
4210 emit_block_move (validize_mem
4211 (copy_rtx (argvec
[argnum
].save_area
)),
4213 GEN_INT (argvec
[argnum
].locate
.size
.constant
),
4214 BLOCK_OP_CALL_PARM
);
4218 argvec
[argnum
].save_area
= gen_reg_rtx (save_mode
);
4220 emit_move_insn (argvec
[argnum
].save_area
, stack_area
);
4225 emit_push_insn (val
, mode
, NULL_TREE
, NULL_RTX
, parm_align
,
4226 partial
, reg
, 0, argblock
,
4227 GEN_INT (argvec
[argnum
].locate
.offset
.constant
),
4228 reg_parm_stack_space
,
4229 ARGS_SIZE_RTX (argvec
[argnum
].locate
.alignment_pad
));
4231 /* Now mark the segment we just used. */
4232 if (ACCUMULATE_OUTGOING_ARGS
)
4233 for (i
= lower_bound
; i
< upper_bound
; i
++)
4234 stack_usage_map
[i
] = 1;
4238 /* Indicate argument access so that alias.c knows that these
4241 use
= plus_constant (Pmode
, argblock
,
4242 argvec
[argnum
].locate
.offset
.constant
);
4244 /* When arguments are pushed, trying to tell alias.c where
4245 exactly this argument is won't work, because the
4246 auto-increment causes confusion. So we merely indicate
4247 that we access something with a known mode somewhere on
4249 use
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
4250 gen_rtx_SCRATCH (Pmode
));
4251 use
= gen_rtx_MEM (argvec
[argnum
].mode
, use
);
4252 use
= gen_rtx_USE (VOIDmode
, use
);
4253 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
, use
, call_fusage
);
4259 fun
= prepare_call_address (NULL
, fun
, NULL
, &call_fusage
, 0, 0);
4261 /* Now load any reg parms into their regs. */
4263 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4264 are to be pushed. */
4265 for (count
= 0; count
< nargs
; count
++, argnum
--)
4267 machine_mode mode
= argvec
[argnum
].mode
;
4268 rtx val
= argvec
[argnum
].value
;
4269 rtx reg
= argvec
[argnum
].reg
;
4270 int partial
= argvec
[argnum
].partial
;
4271 #ifdef BLOCK_REG_PADDING
4275 /* Handle calls that pass values in multiple non-contiguous
4276 locations. The PA64 has examples of this for library calls. */
4277 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
4278 emit_group_load (reg
, val
, NULL_TREE
, GET_MODE_SIZE (mode
));
4279 else if (reg
!= 0 && partial
== 0)
4281 emit_move_insn (reg
, val
);
4282 #ifdef BLOCK_REG_PADDING
4283 size
= GET_MODE_SIZE (argvec
[argnum
].mode
);
4285 /* Copied from load_register_parameters. */
4287 /* Handle case where we have a value that needs shifting
4288 up to the msb. eg. a QImode value and we're padding
4289 upward on a BYTES_BIG_ENDIAN machine. */
4290 if (size
< UNITS_PER_WORD
4291 && (argvec
[argnum
].locate
.where_pad
4292 == (BYTES_BIG_ENDIAN
? upward
: downward
)))
4295 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
4297 /* Assigning REG here rather than a temp makes CALL_FUSAGE
4298 report the whole reg as used. Strictly speaking, the
4299 call only uses SIZE bytes at the msb end, but it doesn't
4300 seem worth generating rtl to say that. */
4301 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
4302 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, shift
, reg
, 1);
4304 emit_move_insn (reg
, x
);
4312 /* Any regs containing parms remain in use through the call. */
4313 for (count
= 0; count
< nargs
; count
++)
4315 rtx reg
= argvec
[count
].reg
;
4316 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
4317 use_group_regs (&call_fusage
, reg
);
4320 int partial
= argvec
[count
].partial
;
4324 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4325 nregs
= partial
/ UNITS_PER_WORD
;
4326 use_regs (&call_fusage
, REGNO (reg
), nregs
);
4329 use_reg (&call_fusage
, reg
);
4333 /* Pass the function the address in which to return a structure value. */
4334 if (mem_value
!= 0 && struct_value
!= 0 && ! pcc_struct_value
)
4336 emit_move_insn (struct_value
,
4338 force_operand (XEXP (mem_value
, 0),
4340 if (REG_P (struct_value
))
4341 use_reg (&call_fusage
, struct_value
);
4344 /* Don't allow popping to be deferred, since then
4345 cse'ing of library calls could delete a call and leave the pop. */
4347 valreg
= (mem_value
== 0 && outmode
!= VOIDmode
4348 ? hard_libcall_value (outmode
, orgfun
) : NULL_RTX
);
4350 /* Stack must be properly aligned now. */
4351 gcc_assert (!(stack_pointer_delta
4352 & (PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)));
4354 before_call
= get_last_insn ();
4356 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4357 will set inhibit_defer_pop to that value. */
4358 /* The return type is needed to decide how many bytes the function pops.
4359 Signedness plays no role in that, so for simplicity, we pretend it's
4360 always signed. We also assume that the list of arguments passed has
4361 no impact, so we pretend it is unknown. */
4363 emit_call_1 (fun
, NULL
,
4364 get_identifier (XSTR (orgfun
, 0)),
4365 build_function_type (tfom
, NULL_TREE
),
4366 original_args_size
.constant
, args_size
.constant
,
4368 targetm
.calls
.function_arg (args_so_far
,
4369 VOIDmode
, void_type_node
, true),
4371 old_inhibit_defer_pop
+ 1, call_fusage
, flags
, args_so_far
);
4375 rtx last
, datum
= orgfun
;
4376 gcc_assert (GET_CODE (datum
) == SYMBOL_REF
);
4377 last
= last_call_insn ();
4378 add_reg_note (last
, REG_CALL_DECL
, datum
);
4381 /* Right-shift returned value if necessary. */
4382 if (!pcc_struct_value
4383 && TYPE_MODE (tfom
) != BLKmode
4384 && targetm
.calls
.return_in_msb (tfom
))
4386 shift_return_value (TYPE_MODE (tfom
), false, valreg
);
4387 valreg
= gen_rtx_REG (TYPE_MODE (tfom
), REGNO (valreg
));
4390 targetm
.calls
.end_call_args ();
4392 /* For calls to `setjmp', etc., inform function.c:setjmp_warnings
4393 that it should complain if nonvolatile values are live. For
4394 functions that cannot return, inform flow that control does not
4396 if (flags
& ECF_NORETURN
)
4398 /* The barrier note must be emitted
4399 immediately after the CALL_INSN. Some ports emit more than
4400 just a CALL_INSN above, so we must search for it here. */
4401 rtx_insn
*last
= get_last_insn ();
4402 while (!CALL_P (last
))
4404 last
= PREV_INSN (last
);
4405 /* There was no CALL_INSN? */
4406 gcc_assert (last
!= before_call
);
4409 emit_barrier_after (last
);
4412 /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW
4413 and LCT_RETURNS_TWICE, cannot perform non-local gotos. */
4414 if (flags
& ECF_NOTHROW
)
4416 rtx_insn
*last
= get_last_insn ();
4417 while (!CALL_P (last
))
4419 last
= PREV_INSN (last
);
4420 /* There was no CALL_INSN? */
4421 gcc_assert (last
!= before_call
);
4424 make_reg_eh_region_note_nothrow_nononlocal (last
);
4427 /* Now restore inhibit_defer_pop to its actual original value. */
4432 /* Copy the value to the right place. */
4433 if (outmode
!= VOIDmode
&& retval
)
4439 if (value
!= mem_value
)
4440 emit_move_insn (value
, mem_value
);
4442 else if (GET_CODE (valreg
) == PARALLEL
)
4445 value
= gen_reg_rtx (outmode
);
4446 emit_group_store (value
, valreg
, NULL_TREE
, GET_MODE_SIZE (outmode
));
4450 /* Convert to the proper mode if a promotion has been active. */
4451 if (GET_MODE (valreg
) != outmode
)
4453 int unsignedp
= TYPE_UNSIGNED (tfom
);
4455 gcc_assert (promote_function_mode (tfom
, outmode
, &unsignedp
,
4456 fndecl
? TREE_TYPE (fndecl
) : fntype
, 1)
4457 == GET_MODE (valreg
));
4458 valreg
= convert_modes (outmode
, GET_MODE (valreg
), valreg
, 0);
4462 emit_move_insn (value
, valreg
);
4468 if (ACCUMULATE_OUTGOING_ARGS
)
4470 #ifdef REG_PARM_STACK_SPACE
4472 restore_fixed_argument_area (save_area
, argblock
,
4473 high_to_save
, low_to_save
);
4476 /* If we saved any argument areas, restore them. */
4477 for (count
= 0; count
< nargs
; count
++)
4478 if (argvec
[count
].save_area
)
4480 machine_mode save_mode
= GET_MODE (argvec
[count
].save_area
);
4481 rtx adr
= plus_constant (Pmode
, argblock
,
4482 argvec
[count
].locate
.offset
.constant
);
4483 rtx stack_area
= gen_rtx_MEM (save_mode
,
4484 memory_address (save_mode
, adr
));
4486 if (save_mode
== BLKmode
)
4487 emit_block_move (stack_area
,
4489 (copy_rtx (argvec
[count
].save_area
)),
4490 GEN_INT (argvec
[count
].locate
.size
.constant
),
4491 BLOCK_OP_CALL_PARM
);
4493 emit_move_insn (stack_area
, argvec
[count
].save_area
);
4496 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
4497 stack_usage_map
= initial_stack_usage_map
;
4500 free (stack_usage_map_buf
);
4506 /* Output a library call to function FUN (a SYMBOL_REF rtx)
4507 (emitting the queue unless NO_QUEUE is nonzero),
4508 for a value of mode OUTMODE,
4509 with NARGS different arguments, passed as alternating rtx values
4510 and machine_modes to convert them to.
4512 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for
4513 `const' calls, LCT_PURE for `pure' calls, or other LCT_ value for
4514 other types of library calls. */
4517 emit_library_call (rtx orgfun
, enum libcall_type fn_type
,
4518 machine_mode outmode
, int nargs
, ...)
4522 va_start (p
, nargs
);
4523 emit_library_call_value_1 (0, orgfun
, NULL_RTX
, fn_type
, outmode
, nargs
, p
);
4527 /* Like emit_library_call except that an extra argument, VALUE,
4528 comes second and says where to store the result.
4529 (If VALUE is zero, this function chooses a convenient way
4530 to return the value.
4532 This function returns an rtx for where the value is to be found.
4533 If VALUE is nonzero, VALUE is returned. */
4536 emit_library_call_value (rtx orgfun
, rtx value
,
4537 enum libcall_type fn_type
,
4538 machine_mode outmode
, int nargs
, ...)
4543 va_start (p
, nargs
);
4544 result
= emit_library_call_value_1 (1, orgfun
, value
, fn_type
, outmode
,
4552 /* Store pointer bounds argument ARG into Bounds Table entry
4553 associated with PARM. */
4555 store_bounds (struct arg_data
*arg
, struct arg_data
*parm
)
4557 rtx slot
= NULL
, ptr
= NULL
, addr
= NULL
;
4559 /* We may pass bounds not associated with any pointer. */
4562 gcc_assert (arg
->special_slot
);
4563 slot
= arg
->special_slot
;
4566 /* Find pointer associated with bounds and where it is
4572 gcc_assert (!arg
->special_slot
);
4574 addr
= adjust_address (parm
->stack
, Pmode
, arg
->pointer_offset
);
4576 else if (REG_P (parm
->reg
))
4578 gcc_assert (arg
->special_slot
);
4579 slot
= arg
->special_slot
;
4581 if (MEM_P (parm
->value
))
4582 addr
= adjust_address (parm
->value
, Pmode
, arg
->pointer_offset
);
4583 else if (REG_P (parm
->value
))
4584 ptr
= gen_rtx_SUBREG (Pmode
, parm
->value
, arg
->pointer_offset
);
4587 gcc_assert (!arg
->pointer_offset
);
4593 gcc_assert (GET_CODE (parm
->reg
) == PARALLEL
);
4595 gcc_assert (arg
->special_slot
);
4596 slot
= arg
->special_slot
;
4598 if (parm
->parallel_value
)
4599 ptr
= chkp_get_value_with_offs (parm
->parallel_value
,
4600 GEN_INT (arg
->pointer_offset
));
4606 /* Expand bounds. */
4608 arg
->value
= expand_normal (arg
->tree_value
);
4610 targetm
.calls
.store_bounds_for_arg (ptr
, addr
, arg
->value
, slot
);
4613 /* Store a single argument for a function call
4614 into the register or memory area where it must be passed.
4615 *ARG describes the argument value and where to pass it.
4617 ARGBLOCK is the address of the stack-block for all the arguments,
4618 or 0 on a machine where arguments are pushed individually.
4620 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4621 so must be careful about how the stack is used.
4623 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4624 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4625 that we need not worry about saving and restoring the stack.
4627 FNDECL is the declaration of the function we are calling.
4629 Return nonzero if this arg should cause sibcall failure,
4633 store_one_arg (struct arg_data
*arg
, rtx argblock
, int flags
,
4634 int variable_size ATTRIBUTE_UNUSED
, int reg_parm_stack_space
)
4636 tree pval
= arg
->tree_value
;
4640 int i
, lower_bound
= 0, upper_bound
= 0;
4641 int sibcall_failure
= 0;
4643 if (TREE_CODE (pval
) == ERROR_MARK
)
4646 /* Push a new temporary level for any temporaries we make for
4650 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
))
4652 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4653 save any previous data at that location. */
4654 if (argblock
&& ! variable_size
&& arg
->stack
)
4656 #ifdef ARGS_GROW_DOWNWARD
4657 /* stack_slot is negative, but we want to index stack_usage_map
4658 with positive values. */
4659 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4660 upper_bound
= -INTVAL (XEXP (XEXP (arg
->stack_slot
, 0), 1)) + 1;
4664 lower_bound
= upper_bound
- arg
->locate
.size
.constant
;
4666 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4667 lower_bound
= INTVAL (XEXP (XEXP (arg
->stack_slot
, 0), 1));
4671 upper_bound
= lower_bound
+ arg
->locate
.size
.constant
;
4675 /* Don't worry about things in the fixed argument area;
4676 it has already been saved. */
4677 if (i
< reg_parm_stack_space
)
4678 i
= reg_parm_stack_space
;
4679 while (i
< upper_bound
&& stack_usage_map
[i
] == 0)
4682 if (i
< upper_bound
)
4684 /* We need to make a save area. */
4685 unsigned int size
= arg
->locate
.size
.constant
* BITS_PER_UNIT
;
4686 machine_mode save_mode
= mode_for_size (size
, MODE_INT
, 1);
4687 rtx adr
= memory_address (save_mode
, XEXP (arg
->stack_slot
, 0));
4688 rtx stack_area
= gen_rtx_MEM (save_mode
, adr
);
4690 if (save_mode
== BLKmode
)
4693 = assign_temp (TREE_TYPE (arg
->tree_value
), 1, 1);
4694 preserve_temp_slots (arg
->save_area
);
4695 emit_block_move (validize_mem (copy_rtx (arg
->save_area
)),
4697 GEN_INT (arg
->locate
.size
.constant
),
4698 BLOCK_OP_CALL_PARM
);
4702 arg
->save_area
= gen_reg_rtx (save_mode
);
4703 emit_move_insn (arg
->save_area
, stack_area
);
4709 /* If this isn't going to be placed on both the stack and in registers,
4710 set up the register and number of words. */
4711 if (! arg
->pass_on_stack
)
4713 if (flags
& ECF_SIBCALL
)
4714 reg
= arg
->tail_call_reg
;
4717 partial
= arg
->partial
;
4720 /* Being passed entirely in a register. We shouldn't be called in
4722 gcc_assert (reg
== 0 || partial
!= 0);
4724 /* If this arg needs special alignment, don't load the registers
4726 if (arg
->n_aligned_regs
!= 0)
4729 /* If this is being passed partially in a register, we can't evaluate
4730 it directly into its stack slot. Otherwise, we can. */
4731 if (arg
->value
== 0)
4733 /* stack_arg_under_construction is nonzero if a function argument is
4734 being evaluated directly into the outgoing argument list and
4735 expand_call must take special action to preserve the argument list
4736 if it is called recursively.
4738 For scalar function arguments stack_usage_map is sufficient to
4739 determine which stack slots must be saved and restored. Scalar
4740 arguments in general have pass_on_stack == 0.
4742 If this argument is initialized by a function which takes the
4743 address of the argument (a C++ constructor or a C function
4744 returning a BLKmode structure), then stack_usage_map is
4745 insufficient and expand_call must push the stack around the
4746 function call. Such arguments have pass_on_stack == 1.
4748 Note that it is always safe to set stack_arg_under_construction,
4749 but this generates suboptimal code if set when not needed. */
4751 if (arg
->pass_on_stack
)
4752 stack_arg_under_construction
++;
4754 arg
->value
= expand_expr (pval
,
4756 || TYPE_MODE (TREE_TYPE (pval
)) != arg
->mode
)
4757 ? NULL_RTX
: arg
->stack
,
4758 VOIDmode
, EXPAND_STACK_PARM
);
4760 /* If we are promoting object (or for any other reason) the mode
4761 doesn't agree, convert the mode. */
4763 if (arg
->mode
!= TYPE_MODE (TREE_TYPE (pval
)))
4764 arg
->value
= convert_modes (arg
->mode
, TYPE_MODE (TREE_TYPE (pval
)),
4765 arg
->value
, arg
->unsignedp
);
4767 if (arg
->pass_on_stack
)
4768 stack_arg_under_construction
--;
4771 /* Check for overlap with already clobbered argument area. */
4772 if ((flags
& ECF_SIBCALL
)
4773 && MEM_P (arg
->value
)
4774 && mem_overlaps_already_clobbered_arg_p (XEXP (arg
->value
, 0),
4775 arg
->locate
.size
.constant
))
4776 sibcall_failure
= 1;
4778 /* Don't allow anything left on stack from computation
4779 of argument to alloca. */
4780 if (flags
& ECF_MAY_BE_ALLOCA
)
4781 do_pending_stack_adjust ();
4783 if (arg
->value
== arg
->stack
)
4784 /* If the value is already in the stack slot, we are done. */
4786 else if (arg
->mode
!= BLKmode
)
4789 unsigned int parm_align
;
4791 /* Argument is a scalar, not entirely passed in registers.
4792 (If part is passed in registers, arg->partial says how much
4793 and emit_push_insn will take care of putting it there.)
4795 Push it, and if its size is less than the
4796 amount of space allocated to it,
4797 also bump stack pointer by the additional space.
4798 Note that in C the default argument promotions
4799 will prevent such mismatches. */
4801 size
= GET_MODE_SIZE (arg
->mode
);
4802 /* Compute how much space the push instruction will push.
4803 On many machines, pushing a byte will advance the stack
4804 pointer by a halfword. */
4805 #ifdef PUSH_ROUNDING
4806 size
= PUSH_ROUNDING (size
);
4810 /* Compute how much space the argument should get:
4811 round up to a multiple of the alignment for arguments. */
4812 if (none
!= FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)))
4813 used
= (((size
+ PARM_BOUNDARY
/ BITS_PER_UNIT
- 1)
4814 / (PARM_BOUNDARY
/ BITS_PER_UNIT
))
4815 * (PARM_BOUNDARY
/ BITS_PER_UNIT
));
4817 /* Compute the alignment of the pushed argument. */
4818 parm_align
= arg
->locate
.boundary
;
4819 if (FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)) == downward
)
4821 int pad
= used
- size
;
4824 unsigned int pad_align
= (pad
& -pad
) * BITS_PER_UNIT
;
4825 parm_align
= MIN (parm_align
, pad_align
);
4829 /* This isn't already where we want it on the stack, so put it there.
4830 This can either be done with push or copy insns. */
4831 emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
), NULL_RTX
,
4832 parm_align
, partial
, reg
, used
- size
, argblock
,
4833 ARGS_SIZE_RTX (arg
->locate
.offset
), reg_parm_stack_space
,
4834 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
));
4836 /* Unless this is a partially-in-register argument, the argument is now
4839 arg
->value
= arg
->stack
;
4843 /* BLKmode, at least partly to be pushed. */
4845 unsigned int parm_align
;
4849 /* Pushing a nonscalar.
4850 If part is passed in registers, PARTIAL says how much
4851 and emit_push_insn will take care of putting it there. */
4853 /* Round its size up to a multiple
4854 of the allocation unit for arguments. */
4856 if (arg
->locate
.size
.var
!= 0)
4859 size_rtx
= ARGS_SIZE_RTX (arg
->locate
.size
);
4863 /* PUSH_ROUNDING has no effect on us, because emit_push_insn
4864 for BLKmode is careful to avoid it. */
4865 excess
= (arg
->locate
.size
.constant
4866 - int_size_in_bytes (TREE_TYPE (pval
))
4868 size_rtx
= expand_expr (size_in_bytes (TREE_TYPE (pval
)),
4869 NULL_RTX
, TYPE_MODE (sizetype
),
4873 parm_align
= arg
->locate
.boundary
;
4875 /* When an argument is padded down, the block is aligned to
4876 PARM_BOUNDARY, but the actual argument isn't. */
4877 if (FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)) == downward
)
4879 if (arg
->locate
.size
.var
)
4880 parm_align
= BITS_PER_UNIT
;
4883 unsigned int excess_align
= (excess
& -excess
) * BITS_PER_UNIT
;
4884 parm_align
= MIN (parm_align
, excess_align
);
4888 if ((flags
& ECF_SIBCALL
) && MEM_P (arg
->value
))
4890 /* emit_push_insn might not work properly if arg->value and
4891 argblock + arg->locate.offset areas overlap. */
4895 if (XEXP (x
, 0) == crtl
->args
.internal_arg_pointer
4896 || (GET_CODE (XEXP (x
, 0)) == PLUS
4897 && XEXP (XEXP (x
, 0), 0) ==
4898 crtl
->args
.internal_arg_pointer
4899 && CONST_INT_P (XEXP (XEXP (x
, 0), 1))))
4901 if (XEXP (x
, 0) != crtl
->args
.internal_arg_pointer
)
4902 i
= INTVAL (XEXP (XEXP (x
, 0), 1));
4904 /* expand_call should ensure this. */
4905 gcc_assert (!arg
->locate
.offset
.var
4906 && arg
->locate
.size
.var
== 0
4907 && CONST_INT_P (size_rtx
));
4909 if (arg
->locate
.offset
.constant
> i
)
4911 if (arg
->locate
.offset
.constant
< i
+ INTVAL (size_rtx
))
4912 sibcall_failure
= 1;
4914 else if (arg
->locate
.offset
.constant
< i
)
4916 /* Use arg->locate.size.constant instead of size_rtx
4917 because we only care about the part of the argument
4919 if (i
< (arg
->locate
.offset
.constant
4920 + arg
->locate
.size
.constant
))
4921 sibcall_failure
= 1;
4925 /* Even though they appear to be at the same location,
4926 if part of the outgoing argument is in registers,
4927 they aren't really at the same location. Check for
4928 this by making sure that the incoming size is the
4929 same as the outgoing size. */
4930 if (arg
->locate
.size
.constant
!= INTVAL (size_rtx
))
4931 sibcall_failure
= 1;
4936 emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
), size_rtx
,
4937 parm_align
, partial
, reg
, excess
, argblock
,
4938 ARGS_SIZE_RTX (arg
->locate
.offset
), reg_parm_stack_space
,
4939 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
));
4941 /* Unless this is a partially-in-register argument, the argument is now
4944 ??? Unlike the case above, in which we want the actual
4945 address of the data, so that we can load it directly into a
4946 register, here we want the address of the stack slot, so that
4947 it's properly aligned for word-by-word copying or something
4948 like that. It's not clear that this is always correct. */
4950 arg
->value
= arg
->stack_slot
;
4953 if (arg
->reg
&& GET_CODE (arg
->reg
) == PARALLEL
)
4955 tree type
= TREE_TYPE (arg
->tree_value
);
4957 = emit_group_load_into_temps (arg
->reg
, arg
->value
, type
,
4958 int_size_in_bytes (type
));
4961 /* Mark all slots this store used. */
4962 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
)
4963 && argblock
&& ! variable_size
&& arg
->stack
)
4964 for (i
= lower_bound
; i
< upper_bound
; i
++)
4965 stack_usage_map
[i
] = 1;
4967 /* Once we have pushed something, pops can't safely
4968 be deferred during the rest of the arguments. */
4971 /* Free any temporary slots made in processing this argument. */
4974 return sibcall_failure
;
4977 /* Nonzero if we do not know how to pass TYPE solely in registers. */
4980 must_pass_in_stack_var_size (machine_mode mode ATTRIBUTE_UNUSED
,
4986 /* If the type has variable size... */
4987 if (TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
4990 /* If the type is marked as addressable (it is required
4991 to be constructed into the stack)... */
4992 if (TREE_ADDRESSABLE (type
))
4998 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
4999 takes trailing padding of a structure into account. */
5000 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
5003 must_pass_in_stack_var_size_or_pad (machine_mode mode
, const_tree type
)
5008 /* If the type has variable size... */
5009 if (TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
5012 /* If the type is marked as addressable (it is required
5013 to be constructed into the stack)... */
5014 if (TREE_ADDRESSABLE (type
))
5017 /* If the padding and mode of the type is such that a copy into
5018 a register would put it into the wrong part of the register. */
5020 && int_size_in_bytes (type
) % (PARM_BOUNDARY
/ BITS_PER_UNIT
)
5021 && (FUNCTION_ARG_PADDING (mode
, type
)
5022 == (BYTES_BIG_ENDIAN
? upward
: downward
)))