1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
28 #include "double-int.h"
35 #include "fold-const.h"
36 #include "stor-layout.h"
38 #include "stringpool.h"
45 #include "hard-reg-set.h"
48 #include "basic-block.h"
49 #include "tree-ssa-alias.h"
50 #include "internal-fn.h"
51 #include "gimple-expr.h"
56 #include "insn-codes.h"
60 #include "diagnostic-core.h"
66 #include "langhooks.h"
69 #include "plugin-api.h"
75 #include "tree-chkp.h"
78 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
79 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
81 /* Data structure and subroutines used within expand_call. */
85 /* Tree node for this argument. */
87 /* Mode for value; TYPE_MODE unless promoted. */
89 /* Current RTL value for argument, or 0 if it isn't precomputed. */
91 /* Initially-compute RTL value for argument; only for const functions. */
93 /* Register to pass this argument in, 0 if passed on stack, or an
94 PARALLEL if the arg is to be copied into multiple non-contiguous
97 /* Register to pass this argument in when generating tail call sequence.
98 This is not the same register as for normal calls on machines with
101 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
102 form for emit_group_move. */
104 /* If value is passed in neither reg nor stack, this field holds a number
105 of a special slot to be used. */
107 /* For pointer bounds hold an index of parm bounds are bound to. -1 if
108 there is no such pointer. */
110 /* If pointer_arg refers a structure, then pointer_offset holds an offset
111 of a pointer in this structure. */
113 /* If REG was promoted from the actual mode of the argument expression,
114 indicates whether the promotion is sign- or zero-extended. */
116 /* Number of bytes to put in registers. 0 means put the whole arg
117 in registers. Also 0 if not passed in registers. */
119 /* Nonzero if argument must be passed on stack.
120 Note that some arguments may be passed on the stack
121 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
122 pass_on_stack identifies arguments that *cannot* go in registers. */
124 /* Some fields packaged up for locate_and_pad_parm. */
125 struct locate_and_pad_arg_data locate
;
126 /* Location on the stack at which parameter should be stored. The store
127 has already been done if STACK == VALUE. */
129 /* Location on the stack of the start of this argument slot. This can
130 differ from STACK if this arg pads downward. This location is known
131 to be aligned to TARGET_FUNCTION_ARG_BOUNDARY. */
133 /* Place that this stack area has been saved, if needed. */
135 /* If an argument's alignment does not permit direct copying into registers,
136 copy in smaller-sized pieces into pseudos. These are stored in a
137 block pointed to by this field. The next field says how many
138 word-sized pseudos we made. */
143 /* A vector of one char per byte of stack space. A byte if nonzero if
144 the corresponding stack location has been used.
145 This vector is used to prevent a function call within an argument from
146 clobbering any stack already set up. */
147 static char *stack_usage_map
;
149 /* Size of STACK_USAGE_MAP. */
150 static int highest_outgoing_arg_in_use
;
152 /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
153 stack location's tail call argument has been already stored into the stack.
154 This bitmap is used to prevent sibling call optimization if function tries
155 to use parent's incoming argument slots when they have been already
156 overwritten with tail call arguments. */
157 static sbitmap stored_args_map
;
159 /* stack_arg_under_construction is nonzero when an argument may be
160 initialized with a constructor call (including a C function that
161 returns a BLKmode struct) and expand_call must take special action
162 to make sure the object being constructed does not overlap the
163 argument list for the constructor call. */
164 static int stack_arg_under_construction
;
166 static void emit_call_1 (rtx
, tree
, tree
, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
,
167 HOST_WIDE_INT
, rtx
, rtx
, int, rtx
, int,
169 static void precompute_register_parameters (int, struct arg_data
*, int *);
170 static void store_bounds (struct arg_data
*, struct arg_data
*);
171 static int store_one_arg (struct arg_data
*, rtx
, int, int, int);
172 static void store_unaligned_arguments_into_pseudos (struct arg_data
*, int);
173 static int finalize_must_preallocate (int, int, struct arg_data
*,
175 static void precompute_arguments (int, struct arg_data
*);
176 static int compute_argument_block_size (int, struct args_size
*, tree
, tree
, int);
177 static void initialize_argument_information (int, struct arg_data
*,
178 struct args_size
*, int,
180 tree
, tree
, cumulative_args_t
, int,
181 rtx
*, int *, int *, int *,
183 static void compute_argument_addresses (struct arg_data
*, rtx
, int);
184 static rtx
rtx_for_function_call (tree
, tree
);
185 static void load_register_parameters (struct arg_data
*, int, rtx
*, int,
187 static rtx
emit_library_call_value_1 (int, rtx
, rtx
, enum libcall_type
,
188 machine_mode
, int, va_list);
189 static int special_function_p (const_tree
, int);
190 static int check_sibcall_argument_overlap_1 (rtx
);
191 static int check_sibcall_argument_overlap (rtx_insn
*, struct arg_data
*, int);
193 static int combine_pending_stack_adjustment_and_call (int, struct args_size
*,
195 static tree
split_complex_types (tree
);
197 #ifdef REG_PARM_STACK_SPACE
198 static rtx
save_fixed_argument_area (int, rtx
, int *, int *);
199 static void restore_fixed_argument_area (rtx
, rtx
, int, int);
202 /* Force FUNEXP into a form suitable for the address of a CALL,
203 and return that as an rtx. Also load the static chain register
204 if FNDECL is a nested function.
206 CALL_FUSAGE points to a variable holding the prospective
207 CALL_INSN_FUNCTION_USAGE information. */
210 prepare_call_address (tree fndecl_or_type
, rtx funexp
, rtx static_chain_value
,
211 rtx
*call_fusage
, int reg_parm_seen
, int sibcallp
)
213 /* Make a valid memory address and copy constants through pseudo-regs,
214 but not for a constant address if -fno-function-cse. */
215 if (GET_CODE (funexp
) != SYMBOL_REF
)
216 /* If we are using registers for parameters, force the
217 function address into a register now. */
218 funexp
= ((reg_parm_seen
219 && targetm
.small_register_classes_for_mode_p (FUNCTION_MODE
))
220 ? force_not_mem (memory_address (FUNCTION_MODE
, funexp
))
221 : memory_address (FUNCTION_MODE
, funexp
));
224 #ifndef NO_FUNCTION_CSE
225 if (optimize
&& ! flag_no_function_cse
)
226 funexp
= force_reg (Pmode
, funexp
);
230 if (static_chain_value
!= 0
231 && (TREE_CODE (fndecl_or_type
) != FUNCTION_DECL
232 || DECL_STATIC_CHAIN (fndecl_or_type
)))
236 chain
= targetm
.calls
.static_chain (fndecl_or_type
, false);
237 static_chain_value
= convert_memory_address (Pmode
, static_chain_value
);
239 emit_move_insn (chain
, static_chain_value
);
241 use_reg (call_fusage
, chain
);
247 /* Generate instructions to call function FUNEXP,
248 and optionally pop the results.
249 The CALL_INSN is the first insn generated.
251 FNDECL is the declaration node of the function. This is given to the
252 hook TARGET_RETURN_POPS_ARGS to determine whether this function pops
255 FUNTYPE is the data type of the function. This is given to the hook
256 TARGET_RETURN_POPS_ARGS to determine whether this function pops its
257 own args. We used to allow an identifier for library functions, but
258 that doesn't work when the return type is an aggregate type and the
259 calling convention says that the pointer to this aggregate is to be
260 popped by the callee.
262 STACK_SIZE is the number of bytes of arguments on the stack,
263 ROUNDED_STACK_SIZE is that number rounded up to
264 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
265 both to put into the call insn and to generate explicit popping
268 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
269 It is zero if this call doesn't want a structure value.
271 NEXT_ARG_REG is the rtx that results from executing
272 targetm.calls.function_arg (&args_so_far, VOIDmode, void_type_node, true)
273 just after all the args have had their registers assigned.
274 This could be whatever you like, but normally it is the first
275 arg-register beyond those used for args in this call,
276 or 0 if all the arg-registers are used in this call.
277 It is passed on to `gen_call' so you can put this info in the call insn.
279 VALREG is a hard register in which a value is returned,
280 or 0 if the call does not return a value.
282 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
283 the args to this call were processed.
284 We restore `inhibit_defer_pop' to that value.
286 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
287 denote registers used by the called function. */
290 emit_call_1 (rtx funexp
, tree fntree ATTRIBUTE_UNUSED
, tree fndecl ATTRIBUTE_UNUSED
,
291 tree funtype ATTRIBUTE_UNUSED
,
292 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED
,
293 HOST_WIDE_INT rounded_stack_size
,
294 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED
,
295 rtx next_arg_reg ATTRIBUTE_UNUSED
, rtx valreg
,
296 int old_inhibit_defer_pop
, rtx call_fusage
, int ecf_flags
,
297 cumulative_args_t args_so_far ATTRIBUTE_UNUSED
)
299 rtx rounded_stack_size_rtx
= GEN_INT (rounded_stack_size
);
302 int already_popped
= 0;
303 HOST_WIDE_INT n_popped
304 = targetm
.calls
.return_pops_args (fndecl
, funtype
, stack_size
);
306 #ifdef CALL_POPS_ARGS
307 n_popped
+= CALL_POPS_ARGS (*get_cumulative_args (args_so_far
));
310 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
311 and we don't want to load it into a register as an optimization,
312 because prepare_call_address already did it if it should be done. */
313 if (GET_CODE (funexp
) != SYMBOL_REF
)
314 funexp
= memory_address (FUNCTION_MODE
, funexp
);
316 funmem
= gen_rtx_MEM (FUNCTION_MODE
, funexp
);
317 if (fndecl
&& TREE_CODE (fndecl
) == FUNCTION_DECL
)
321 /* Although a built-in FUNCTION_DECL and its non-__builtin
322 counterpart compare equal and get a shared mem_attrs, they
323 produce different dump output in compare-debug compilations,
324 if an entry gets garbage collected in one compilation, then
325 adds a different (but equivalent) entry, while the other
326 doesn't run the garbage collector at the same spot and then
327 shares the mem_attr with the equivalent entry. */
328 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
)
330 tree t2
= builtin_decl_explicit (DECL_FUNCTION_CODE (t
));
335 set_mem_expr (funmem
, t
);
338 set_mem_expr (funmem
, build_simple_mem_ref (CALL_EXPR_FN (fntree
)));
340 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
341 if ((ecf_flags
& ECF_SIBCALL
)
342 && HAVE_sibcall_pop
&& HAVE_sibcall_value_pop
343 && (n_popped
> 0 || stack_size
== 0))
345 rtx n_pop
= GEN_INT (n_popped
);
348 /* If this subroutine pops its own args, record that in the call insn
349 if possible, for the sake of frame pointer elimination. */
352 pat
= GEN_SIBCALL_VALUE_POP (valreg
, funmem
, rounded_stack_size_rtx
,
353 next_arg_reg
, n_pop
);
355 pat
= GEN_SIBCALL_POP (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
358 emit_call_insn (pat
);
364 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
365 /* If the target has "call" or "call_value" insns, then prefer them
366 if no arguments are actually popped. If the target does not have
367 "call" or "call_value" insns, then we must use the popping versions
368 even if the call has no arguments to pop. */
369 #if defined (HAVE_call) && defined (HAVE_call_value)
370 if (HAVE_call
&& HAVE_call_value
&& HAVE_call_pop
&& HAVE_call_value_pop
373 if (HAVE_call_pop
&& HAVE_call_value_pop
)
376 rtx n_pop
= GEN_INT (n_popped
);
379 /* If this subroutine pops its own args, record that in the call insn
380 if possible, for the sake of frame pointer elimination. */
383 pat
= GEN_CALL_VALUE_POP (valreg
, funmem
, rounded_stack_size_rtx
,
384 next_arg_reg
, n_pop
);
386 pat
= GEN_CALL_POP (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
389 emit_call_insn (pat
);
395 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
396 if ((ecf_flags
& ECF_SIBCALL
)
397 && HAVE_sibcall
&& HAVE_sibcall_value
)
400 emit_call_insn (GEN_SIBCALL_VALUE (valreg
, funmem
,
401 rounded_stack_size_rtx
,
402 next_arg_reg
, NULL_RTX
));
404 emit_call_insn (GEN_SIBCALL (funmem
, rounded_stack_size_rtx
,
406 GEN_INT (struct_value_size
)));
411 #if defined (HAVE_call) && defined (HAVE_call_value)
412 if (HAVE_call
&& HAVE_call_value
)
415 emit_call_insn (GEN_CALL_VALUE (valreg
, funmem
, rounded_stack_size_rtx
,
416 next_arg_reg
, NULL_RTX
));
418 emit_call_insn (GEN_CALL (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
419 GEN_INT (struct_value_size
)));
425 /* Find the call we just emitted. */
426 call_insn
= last_call_insn ();
428 /* Some target create a fresh MEM instead of reusing the one provided
429 above. Set its MEM_EXPR. */
430 call
= get_call_rtx_from (call_insn
);
432 && MEM_EXPR (XEXP (call
, 0)) == NULL_TREE
433 && MEM_EXPR (funmem
) != NULL_TREE
)
434 set_mem_expr (XEXP (call
, 0), MEM_EXPR (funmem
));
436 /* Mark instrumented calls. */
438 CALL_EXPR_WITH_BOUNDS_P (call
) = CALL_WITH_BOUNDS_P (fntree
);
440 /* Put the register usage information there. */
441 add_function_usage_to (call_insn
, call_fusage
);
443 /* If this is a const call, then set the insn's unchanging bit. */
444 if (ecf_flags
& ECF_CONST
)
445 RTL_CONST_CALL_P (call_insn
) = 1;
447 /* If this is a pure call, then set the insn's unchanging bit. */
448 if (ecf_flags
& ECF_PURE
)
449 RTL_PURE_CALL_P (call_insn
) = 1;
451 /* If this is a const call, then set the insn's unchanging bit. */
452 if (ecf_flags
& ECF_LOOPING_CONST_OR_PURE
)
453 RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn
) = 1;
455 /* Create a nothrow REG_EH_REGION note, if needed. */
456 make_reg_eh_region_note (call_insn
, ecf_flags
, 0);
458 if (ecf_flags
& ECF_NORETURN
)
459 add_reg_note (call_insn
, REG_NORETURN
, const0_rtx
);
461 if (ecf_flags
& ECF_RETURNS_TWICE
)
463 add_reg_note (call_insn
, REG_SETJMP
, const0_rtx
);
464 cfun
->calls_setjmp
= 1;
467 SIBLING_CALL_P (call_insn
) = ((ecf_flags
& ECF_SIBCALL
) != 0);
469 /* Restore this now, so that we do defer pops for this call's args
470 if the context of the call as a whole permits. */
471 inhibit_defer_pop
= old_inhibit_defer_pop
;
476 CALL_INSN_FUNCTION_USAGE (call_insn
)
477 = gen_rtx_EXPR_LIST (VOIDmode
,
478 gen_rtx_CLOBBER (VOIDmode
, stack_pointer_rtx
),
479 CALL_INSN_FUNCTION_USAGE (call_insn
));
480 rounded_stack_size
-= n_popped
;
481 rounded_stack_size_rtx
= GEN_INT (rounded_stack_size
);
482 stack_pointer_delta
-= n_popped
;
484 add_reg_note (call_insn
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
486 /* If popup is needed, stack realign must use DRAP */
487 if (SUPPORTS_STACK_ALIGNMENT
)
488 crtl
->need_drap
= true;
490 /* For noreturn calls when not accumulating outgoing args force
491 REG_ARGS_SIZE note to prevent crossjumping of calls with different
493 else if (!ACCUMULATE_OUTGOING_ARGS
&& (ecf_flags
& ECF_NORETURN
) != 0)
494 add_reg_note (call_insn
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
496 if (!ACCUMULATE_OUTGOING_ARGS
)
498 /* If returning from the subroutine does not automatically pop the args,
499 we need an instruction to pop them sooner or later.
500 Perhaps do it now; perhaps just record how much space to pop later.
502 If returning from the subroutine does pop the args, indicate that the
503 stack pointer will be changed. */
505 if (rounded_stack_size
!= 0)
507 if (ecf_flags
& ECF_NORETURN
)
508 /* Just pretend we did the pop. */
509 stack_pointer_delta
-= rounded_stack_size
;
510 else if (flag_defer_pop
&& inhibit_defer_pop
== 0
511 && ! (ecf_flags
& (ECF_CONST
| ECF_PURE
)))
512 pending_stack_adjust
+= rounded_stack_size
;
514 adjust_stack (rounded_stack_size_rtx
);
517 /* When we accumulate outgoing args, we must avoid any stack manipulations.
518 Restore the stack pointer to its original value now. Usually
519 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
520 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
521 popping variants of functions exist as well.
523 ??? We may optimize similar to defer_pop above, but it is
524 probably not worthwhile.
526 ??? It will be worthwhile to enable combine_stack_adjustments even for
529 anti_adjust_stack (GEN_INT (n_popped
));
532 /* Determine if the function identified by NAME and FNDECL is one with
533 special properties we wish to know about.
535 For example, if the function might return more than one time (setjmp), then
536 set RETURNS_TWICE to a nonzero value.
538 Similarly set NORETURN if the function is in the longjmp family.
540 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
541 space from the stack such as alloca. */
544 special_function_p (const_tree fndecl
, int flags
)
546 tree name_decl
= DECL_NAME (fndecl
);
548 /* For instrumentation clones we want to derive flags
549 from the original name. */
550 if (cgraph_node::get (fndecl
)
551 && cgraph_node::get (fndecl
)->instrumentation_clone
)
552 name_decl
= DECL_NAME (cgraph_node::get (fndecl
)->orig_decl
);
554 if (fndecl
&& name_decl
555 && IDENTIFIER_LENGTH (name_decl
) <= 17
556 /* Exclude functions not at the file scope, or not `extern',
557 since they are not the magic functions we would otherwise
559 FIXME: this should be handled with attributes, not with this
560 hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
561 because you can declare fork() inside a function if you
563 && (DECL_CONTEXT (fndecl
) == NULL_TREE
564 || TREE_CODE (DECL_CONTEXT (fndecl
)) == TRANSLATION_UNIT_DECL
)
565 && TREE_PUBLIC (fndecl
))
567 const char *name
= IDENTIFIER_POINTER (name_decl
);
568 const char *tname
= name
;
570 /* We assume that alloca will always be called by name. It
571 makes no sense to pass it as a pointer-to-function to
572 anything that does not understand its behavior. */
573 if (((IDENTIFIER_LENGTH (name_decl
) == 6
575 && ! strcmp (name
, "alloca"))
576 || (IDENTIFIER_LENGTH (name_decl
) == 16
578 && ! strcmp (name
, "__builtin_alloca"))))
579 flags
|= ECF_MAY_BE_ALLOCA
;
581 /* Disregard prefix _, __, __x or __builtin_. */
586 && !strncmp (name
+ 3, "uiltin_", 7))
588 else if (name
[1] == '_' && name
[2] == 'x')
590 else if (name
[1] == '_')
599 && (! strcmp (tname
, "setjmp")
600 || ! strcmp (tname
, "setjmp_syscall")))
602 && ! strcmp (tname
, "sigsetjmp"))
604 && ! strcmp (tname
, "savectx")))
605 flags
|= ECF_RETURNS_TWICE
| ECF_LEAF
;
608 && ! strcmp (tname
, "siglongjmp"))
609 flags
|= ECF_NORETURN
;
611 else if ((tname
[0] == 'q' && tname
[1] == 's'
612 && ! strcmp (tname
, "qsetjmp"))
613 || (tname
[0] == 'v' && tname
[1] == 'f'
614 && ! strcmp (tname
, "vfork"))
615 || (tname
[0] == 'g' && tname
[1] == 'e'
616 && !strcmp (tname
, "getcontext")))
617 flags
|= ECF_RETURNS_TWICE
| ECF_LEAF
;
619 else if (tname
[0] == 'l' && tname
[1] == 'o'
620 && ! strcmp (tname
, "longjmp"))
621 flags
|= ECF_NORETURN
;
627 /* Similar to special_function_p; return a set of ERF_ flags for the
630 decl_return_flags (tree fndecl
)
633 tree type
= TREE_TYPE (fndecl
);
637 attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
641 attr
= TREE_VALUE (TREE_VALUE (attr
));
642 if (!attr
|| TREE_STRING_LENGTH (attr
) < 1)
645 switch (TREE_STRING_POINTER (attr
)[0])
651 return ERF_RETURNS_ARG
| (TREE_STRING_POINTER (attr
)[0] - '1');
662 /* Return nonzero when FNDECL represents a call to setjmp. */
665 setjmp_call_p (const_tree fndecl
)
667 if (DECL_IS_RETURNS_TWICE (fndecl
))
668 return ECF_RETURNS_TWICE
;
669 return special_function_p (fndecl
, 0) & ECF_RETURNS_TWICE
;
673 /* Return true if STMT is an alloca call. */
676 gimple_alloca_call_p (const_gimple stmt
)
680 if (!is_gimple_call (stmt
))
683 fndecl
= gimple_call_fndecl (stmt
);
684 if (fndecl
&& (special_function_p (fndecl
, 0) & ECF_MAY_BE_ALLOCA
))
690 /* Return true when exp contains alloca call. */
693 alloca_call_p (const_tree exp
)
696 if (TREE_CODE (exp
) == CALL_EXPR
697 && (fndecl
= get_callee_fndecl (exp
))
698 && (special_function_p (fndecl
, 0) & ECF_MAY_BE_ALLOCA
))
703 /* Return TRUE if FNDECL is either a TM builtin or a TM cloned
704 function. Return FALSE otherwise. */
707 is_tm_builtin (const_tree fndecl
)
712 if (decl_is_tm_clone (fndecl
))
715 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
)
717 switch (DECL_FUNCTION_CODE (fndecl
))
719 case BUILT_IN_TM_COMMIT
:
720 case BUILT_IN_TM_COMMIT_EH
:
721 case BUILT_IN_TM_ABORT
:
722 case BUILT_IN_TM_IRREVOCABLE
:
723 case BUILT_IN_TM_GETTMCLONE_IRR
:
724 case BUILT_IN_TM_MEMCPY
:
725 case BUILT_IN_TM_MEMMOVE
:
726 case BUILT_IN_TM_MEMSET
:
727 CASE_BUILT_IN_TM_STORE (1):
728 CASE_BUILT_IN_TM_STORE (2):
729 CASE_BUILT_IN_TM_STORE (4):
730 CASE_BUILT_IN_TM_STORE (8):
731 CASE_BUILT_IN_TM_STORE (FLOAT
):
732 CASE_BUILT_IN_TM_STORE (DOUBLE
):
733 CASE_BUILT_IN_TM_STORE (LDOUBLE
):
734 CASE_BUILT_IN_TM_STORE (M64
):
735 CASE_BUILT_IN_TM_STORE (M128
):
736 CASE_BUILT_IN_TM_STORE (M256
):
737 CASE_BUILT_IN_TM_LOAD (1):
738 CASE_BUILT_IN_TM_LOAD (2):
739 CASE_BUILT_IN_TM_LOAD (4):
740 CASE_BUILT_IN_TM_LOAD (8):
741 CASE_BUILT_IN_TM_LOAD (FLOAT
):
742 CASE_BUILT_IN_TM_LOAD (DOUBLE
):
743 CASE_BUILT_IN_TM_LOAD (LDOUBLE
):
744 CASE_BUILT_IN_TM_LOAD (M64
):
745 CASE_BUILT_IN_TM_LOAD (M128
):
746 CASE_BUILT_IN_TM_LOAD (M256
):
747 case BUILT_IN_TM_LOG
:
748 case BUILT_IN_TM_LOG_1
:
749 case BUILT_IN_TM_LOG_2
:
750 case BUILT_IN_TM_LOG_4
:
751 case BUILT_IN_TM_LOG_8
:
752 case BUILT_IN_TM_LOG_FLOAT
:
753 case BUILT_IN_TM_LOG_DOUBLE
:
754 case BUILT_IN_TM_LOG_LDOUBLE
:
755 case BUILT_IN_TM_LOG_M64
:
756 case BUILT_IN_TM_LOG_M128
:
757 case BUILT_IN_TM_LOG_M256
:
766 /* Detect flags (function attributes) from the function decl or type node. */
769 flags_from_decl_or_type (const_tree exp
)
775 /* The function exp may have the `malloc' attribute. */
776 if (DECL_IS_MALLOC (exp
))
779 /* The function exp may have the `returns_twice' attribute. */
780 if (DECL_IS_RETURNS_TWICE (exp
))
781 flags
|= ECF_RETURNS_TWICE
;
783 /* Process the pure and const attributes. */
784 if (TREE_READONLY (exp
))
786 if (DECL_PURE_P (exp
))
788 if (DECL_LOOPING_CONST_OR_PURE_P (exp
))
789 flags
|= ECF_LOOPING_CONST_OR_PURE
;
791 if (DECL_IS_NOVOPS (exp
))
793 if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp
)))
796 if (TREE_NOTHROW (exp
))
797 flags
|= ECF_NOTHROW
;
801 if (is_tm_builtin (exp
))
802 flags
|= ECF_TM_BUILTIN
;
803 else if ((flags
& (ECF_CONST
|ECF_NOVOPS
)) != 0
804 || lookup_attribute ("transaction_pure",
805 TYPE_ATTRIBUTES (TREE_TYPE (exp
))))
806 flags
|= ECF_TM_PURE
;
809 flags
= special_function_p (exp
, flags
);
811 else if (TYPE_P (exp
))
813 if (TYPE_READONLY (exp
))
817 && ((flags
& ECF_CONST
) != 0
818 || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp
))))
819 flags
|= ECF_TM_PURE
;
824 if (TREE_THIS_VOLATILE (exp
))
826 flags
|= ECF_NORETURN
;
827 if (flags
& (ECF_CONST
|ECF_PURE
))
828 flags
|= ECF_LOOPING_CONST_OR_PURE
;
834 /* Detect flags from a CALL_EXPR. */
837 call_expr_flags (const_tree t
)
840 tree decl
= get_callee_fndecl (t
);
843 flags
= flags_from_decl_or_type (decl
);
846 t
= TREE_TYPE (CALL_EXPR_FN (t
));
847 if (t
&& TREE_CODE (t
) == POINTER_TYPE
)
848 flags
= flags_from_decl_or_type (TREE_TYPE (t
));
856 /* Precompute all register parameters as described by ARGS, storing values
857 into fields within the ARGS array.
859 NUM_ACTUALS indicates the total number elements in the ARGS array.
861 Set REG_PARM_SEEN if we encounter a register parameter. */
864 precompute_register_parameters (int num_actuals
, struct arg_data
*args
,
871 for (i
= 0; i
< num_actuals
; i
++)
872 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
)
876 if (args
[i
].value
== 0)
879 args
[i
].value
= expand_normal (args
[i
].tree_value
);
880 preserve_temp_slots (args
[i
].value
);
884 /* If we are to promote the function arg to a wider mode,
887 if (args
[i
].mode
!= TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)))
889 = convert_modes (args
[i
].mode
,
890 TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)),
891 args
[i
].value
, args
[i
].unsignedp
);
893 /* If the value is a non-legitimate constant, force it into a
894 pseudo now. TLS symbols sometimes need a call to resolve. */
895 if (CONSTANT_P (args
[i
].value
)
896 && !targetm
.legitimate_constant_p (args
[i
].mode
, args
[i
].value
))
897 args
[i
].value
= force_reg (args
[i
].mode
, args
[i
].value
);
899 /* If we're going to have to load the value by parts, pull the
900 parts into pseudos. The part extraction process can involve
901 non-trivial computation. */
902 if (GET_CODE (args
[i
].reg
) == PARALLEL
)
904 tree type
= TREE_TYPE (args
[i
].tree_value
);
905 args
[i
].parallel_value
906 = emit_group_load_into_temps (args
[i
].reg
, args
[i
].value
,
907 type
, int_size_in_bytes (type
));
910 /* If the value is expensive, and we are inside an appropriately
911 short loop, put the value into a pseudo and then put the pseudo
914 For small register classes, also do this if this call uses
915 register parameters. This is to avoid reload conflicts while
916 loading the parameters registers. */
918 else if ((! (REG_P (args
[i
].value
)
919 || (GET_CODE (args
[i
].value
) == SUBREG
920 && REG_P (SUBREG_REG (args
[i
].value
)))))
921 && args
[i
].mode
!= BLKmode
922 && set_src_cost (args
[i
].value
, optimize_insn_for_speed_p ())
925 && targetm
.small_register_classes_for_mode_p (args
[i
].mode
))
927 args
[i
].value
= copy_to_mode_reg (args
[i
].mode
, args
[i
].value
);
931 #ifdef REG_PARM_STACK_SPACE
933 /* The argument list is the property of the called routine and it
934 may clobber it. If the fixed area has been used for previous
935 parameters, we must save and restore it. */
938 save_fixed_argument_area (int reg_parm_stack_space
, rtx argblock
, int *low_to_save
, int *high_to_save
)
943 /* Compute the boundary of the area that needs to be saved, if any. */
944 high
= reg_parm_stack_space
;
945 #ifdef ARGS_GROW_DOWNWARD
948 if (high
> highest_outgoing_arg_in_use
)
949 high
= highest_outgoing_arg_in_use
;
951 for (low
= 0; low
< high
; low
++)
952 if (stack_usage_map
[low
] != 0)
955 machine_mode save_mode
;
961 while (stack_usage_map
[--high
] == 0)
965 *high_to_save
= high
;
967 num_to_save
= high
- low
+ 1;
968 save_mode
= mode_for_size (num_to_save
* BITS_PER_UNIT
, MODE_INT
, 1);
970 /* If we don't have the required alignment, must do this
972 if ((low
& (MIN (GET_MODE_SIZE (save_mode
),
973 BIGGEST_ALIGNMENT
/ UNITS_PER_WORD
) - 1)))
976 #ifdef ARGS_GROW_DOWNWARD
981 addr
= plus_constant (Pmode
, argblock
, delta
);
982 stack_area
= gen_rtx_MEM (save_mode
, memory_address (save_mode
, addr
));
984 set_mem_align (stack_area
, PARM_BOUNDARY
);
985 if (save_mode
== BLKmode
)
987 save_area
= assign_stack_temp (BLKmode
, num_to_save
);
988 emit_block_move (validize_mem (save_area
), stack_area
,
989 GEN_INT (num_to_save
), BLOCK_OP_CALL_PARM
);
993 save_area
= gen_reg_rtx (save_mode
);
994 emit_move_insn (save_area
, stack_area
);
1004 restore_fixed_argument_area (rtx save_area
, rtx argblock
, int high_to_save
, int low_to_save
)
1006 machine_mode save_mode
= GET_MODE (save_area
);
1008 rtx addr
, stack_area
;
1010 #ifdef ARGS_GROW_DOWNWARD
1011 delta
= -high_to_save
;
1013 delta
= low_to_save
;
1015 addr
= plus_constant (Pmode
, argblock
, delta
);
1016 stack_area
= gen_rtx_MEM (save_mode
, memory_address (save_mode
, addr
));
1017 set_mem_align (stack_area
, PARM_BOUNDARY
);
1019 if (save_mode
!= BLKmode
)
1020 emit_move_insn (stack_area
, save_area
);
1022 emit_block_move (stack_area
, validize_mem (save_area
),
1023 GEN_INT (high_to_save
- low_to_save
+ 1),
1024 BLOCK_OP_CALL_PARM
);
1026 #endif /* REG_PARM_STACK_SPACE */
1028 /* If any elements in ARGS refer to parameters that are to be passed in
1029 registers, but not in memory, and whose alignment does not permit a
1030 direct copy into registers. Copy the values into a group of pseudos
1031 which we will later copy into the appropriate hard registers.
1033 Pseudos for each unaligned argument will be stored into the array
1034 args[argnum].aligned_regs. The caller is responsible for deallocating
1035 the aligned_regs array if it is nonzero. */
1038 store_unaligned_arguments_into_pseudos (struct arg_data
*args
, int num_actuals
)
1042 for (i
= 0; i
< num_actuals
; i
++)
1043 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
1044 && GET_CODE (args
[i
].reg
) != PARALLEL
1045 && args
[i
].mode
== BLKmode
1046 && MEM_P (args
[i
].value
)
1047 && (MEM_ALIGN (args
[i
].value
)
1048 < (unsigned int) MIN (BIGGEST_ALIGNMENT
, BITS_PER_WORD
)))
1050 int bytes
= int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1051 int endian_correction
= 0;
1053 if (args
[i
].partial
)
1055 gcc_assert (args
[i
].partial
% UNITS_PER_WORD
== 0);
1056 args
[i
].n_aligned_regs
= args
[i
].partial
/ UNITS_PER_WORD
;
1060 args
[i
].n_aligned_regs
1061 = (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
1064 args
[i
].aligned_regs
= XNEWVEC (rtx
, args
[i
].n_aligned_regs
);
1066 /* Structures smaller than a word are normally aligned to the
1067 least significant byte. On a BYTES_BIG_ENDIAN machine,
1068 this means we must skip the empty high order bytes when
1069 calculating the bit offset. */
1070 if (bytes
< UNITS_PER_WORD
1071 #ifdef BLOCK_REG_PADDING
1072 && (BLOCK_REG_PADDING (args
[i
].mode
,
1073 TREE_TYPE (args
[i
].tree_value
), 1)
1079 endian_correction
= BITS_PER_WORD
- bytes
* BITS_PER_UNIT
;
1081 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
1083 rtx reg
= gen_reg_rtx (word_mode
);
1084 rtx word
= operand_subword_force (args
[i
].value
, j
, BLKmode
);
1085 int bitsize
= MIN (bytes
* BITS_PER_UNIT
, BITS_PER_WORD
);
1087 args
[i
].aligned_regs
[j
] = reg
;
1088 word
= extract_bit_field (word
, bitsize
, 0, 1, NULL_RTX
,
1089 word_mode
, word_mode
);
1091 /* There is no need to restrict this code to loading items
1092 in TYPE_ALIGN sized hunks. The bitfield instructions can
1093 load up entire word sized registers efficiently.
1095 ??? This may not be needed anymore.
1096 We use to emit a clobber here but that doesn't let later
1097 passes optimize the instructions we emit. By storing 0 into
1098 the register later passes know the first AND to zero out the
1099 bitfield being set in the register is unnecessary. The store
1100 of 0 will be deleted as will at least the first AND. */
1102 emit_move_insn (reg
, const0_rtx
);
1104 bytes
-= bitsize
/ BITS_PER_UNIT
;
1105 store_bit_field (reg
, bitsize
, endian_correction
, 0, 0,
1111 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
1114 NUM_ACTUALS is the total number of parameters.
1116 N_NAMED_ARGS is the total number of named arguments.
1118 STRUCT_VALUE_ADDR_VALUE is the implicit argument for a struct return
1121 FNDECL is the tree code for the target of this call (if known)
1123 ARGS_SO_FAR holds state needed by the target to know where to place
1126 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
1127 for arguments which are passed in registers.
1129 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
1130 and may be modified by this routine.
1132 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
1133 flags which may may be modified by this routine.
1135 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
1136 that requires allocation of stack space.
1138 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
1139 the thunked-to function. */
1142 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED
,
1143 struct arg_data
*args
,
1144 struct args_size
*args_size
,
1145 int n_named_args ATTRIBUTE_UNUSED
,
1146 tree exp
, tree struct_value_addr_value
,
1147 tree fndecl
, tree fntype
,
1148 cumulative_args_t args_so_far
,
1149 int reg_parm_stack_space
,
1150 rtx
*old_stack_level
, int *old_pending_adj
,
1151 int *must_preallocate
, int *ecf_flags
,
1152 bool *may_tailcall
, bool call_from_thunk_p
)
1154 CUMULATIVE_ARGS
*args_so_far_pnt
= get_cumulative_args (args_so_far
);
1155 location_t loc
= EXPR_LOCATION (exp
);
1157 /* Count arg position in order args appear. */
1162 args_size
->constant
= 0;
1165 bitmap_obstack_initialize (NULL
);
1167 /* In this loop, we consider args in the order they are written.
1168 We fill up ARGS from the back. */
1170 i
= num_actuals
- 1;
1172 int j
= i
, ptr_arg
= -1;
1173 call_expr_arg_iterator iter
;
1175 bitmap slots
= NULL
;
1177 if (struct_value_addr_value
)
1179 args
[j
].tree_value
= struct_value_addr_value
;
1182 /* If we pass structure address then we need to
1183 create bounds for it. Since created bounds is
1184 a call statement, we expand it right here to avoid
1185 fixing all other places where it may be expanded. */
1186 if (CALL_WITH_BOUNDS_P (exp
))
1188 args
[j
].value
= gen_reg_rtx (targetm
.chkp_bound_mode ());
1190 = chkp_make_bounds_for_struct_addr (struct_value_addr_value
);
1191 expand_expr_real (args
[j
].tree_value
, args
[j
].value
, VOIDmode
,
1192 EXPAND_NORMAL
, 0, false);
1193 args
[j
].pointer_arg
= j
+ 1;
1197 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
1199 tree argtype
= TREE_TYPE (arg
);
1201 /* Remember last param with pointer and associate it
1202 with following pointer bounds. */
1203 if (CALL_WITH_BOUNDS_P (exp
)
1204 && chkp_type_has_pointer (argtype
))
1207 BITMAP_FREE (slots
);
1209 if (!BOUNDED_TYPE_P (argtype
))
1211 slots
= BITMAP_ALLOC (NULL
);
1212 chkp_find_bound_slots (argtype
, slots
);
1215 else if (POINTER_BOUNDS_TYPE_P (argtype
))
1217 /* We expect bounds in instrumented calls only.
1218 Otherwise it is a sign we lost flag due to some optimization
1219 and may emit call args incorrectly. */
1220 gcc_assert (CALL_WITH_BOUNDS_P (exp
));
1222 /* For structures look for the next available pointer. */
1223 if (ptr_arg
!= -1 && slots
)
1225 unsigned bnd_no
= bitmap_first_set_bit (slots
);
1226 args
[j
].pointer_offset
=
1227 bnd_no
* POINTER_SIZE
/ BITS_PER_UNIT
;
1229 bitmap_clear_bit (slots
, bnd_no
);
1231 /* Check we have no more pointers in the structure. */
1232 if (bitmap_empty_p (slots
))
1233 BITMAP_FREE (slots
);
1235 args
[j
].pointer_arg
= ptr_arg
;
1237 /* Check we covered all pointers in the previous
1245 if (targetm
.calls
.split_complex_arg
1247 && TREE_CODE (argtype
) == COMPLEX_TYPE
1248 && targetm
.calls
.split_complex_arg (argtype
))
1250 tree subtype
= TREE_TYPE (argtype
);
1251 args
[j
].tree_value
= build1 (REALPART_EXPR
, subtype
, arg
);
1253 args
[j
].tree_value
= build1 (IMAGPART_EXPR
, subtype
, arg
);
1256 args
[j
].tree_value
= arg
;
1261 BITMAP_FREE (slots
);
1264 bitmap_obstack_release (NULL
);
1266 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1267 for (argpos
= 0; argpos
< num_actuals
; i
--, argpos
++)
1269 tree type
= TREE_TYPE (args
[i
].tree_value
);
1273 /* Replace erroneous argument with constant zero. */
1274 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
1275 args
[i
].tree_value
= integer_zero_node
, type
= integer_type_node
;
1277 /* If TYPE is a transparent union or record, pass things the way
1278 we would pass the first field of the union or record. We have
1279 already verified that the modes are the same. */
1280 if ((TREE_CODE (type
) == UNION_TYPE
|| TREE_CODE (type
) == RECORD_TYPE
)
1281 && TYPE_TRANSPARENT_AGGR (type
))
1282 type
= TREE_TYPE (first_field (type
));
1284 /* Decide where to pass this arg.
1286 args[i].reg is nonzero if all or part is passed in registers.
1288 args[i].partial is nonzero if part but not all is passed in registers,
1289 and the exact value says how many bytes are passed in registers.
1291 args[i].pass_on_stack is nonzero if the argument must at least be
1292 computed on the stack. It may then be loaded back into registers
1293 if args[i].reg is nonzero.
1295 These decisions are driven by the FUNCTION_... macros and must agree
1296 with those made by function.c. */
1298 /* See if this argument should be passed by invisible reference. */
1299 if (pass_by_reference (args_so_far_pnt
, TYPE_MODE (type
),
1300 type
, argpos
< n_named_args
))
1303 tree base
= NULL_TREE
;
1306 = reference_callee_copied (args_so_far_pnt
, TYPE_MODE (type
),
1307 type
, argpos
< n_named_args
);
1309 /* If we're compiling a thunk, pass through invisible references
1310 instead of making a copy. */
1311 if (call_from_thunk_p
1313 && !TREE_ADDRESSABLE (type
)
1314 && (base
= get_base_address (args
[i
].tree_value
))
1315 && TREE_CODE (base
) != SSA_NAME
1316 && (!DECL_P (base
) || MEM_P (DECL_RTL (base
)))))
1318 /* Argument setup code may have copied the value to register. We
1319 revert that optimization now because the tail call code must
1320 use the original location. */
1321 if (TREE_CODE (args
[i
].tree_value
) == PARM_DECL
1322 && !MEM_P (DECL_RTL (args
[i
].tree_value
))
1323 && DECL_INCOMING_RTL (args
[i
].tree_value
)
1324 && MEM_P (DECL_INCOMING_RTL (args
[i
].tree_value
)))
1325 set_decl_rtl (args
[i
].tree_value
,
1326 DECL_INCOMING_RTL (args
[i
].tree_value
));
1328 mark_addressable (args
[i
].tree_value
);
1330 /* We can't use sibcalls if a callee-copied argument is
1331 stored in the current function's frame. */
1332 if (!call_from_thunk_p
&& DECL_P (base
) && !TREE_STATIC (base
))
1333 *may_tailcall
= false;
1335 args
[i
].tree_value
= build_fold_addr_expr_loc (loc
,
1336 args
[i
].tree_value
);
1337 type
= TREE_TYPE (args
[i
].tree_value
);
1339 if (*ecf_flags
& ECF_CONST
)
1340 *ecf_flags
&= ~(ECF_CONST
| ECF_LOOPING_CONST_OR_PURE
);
1344 /* We make a copy of the object and pass the address to the
1345 function being called. */
1348 if (!COMPLETE_TYPE_P (type
)
1349 || TREE_CODE (TYPE_SIZE_UNIT (type
)) != INTEGER_CST
1350 || (flag_stack_check
== GENERIC_STACK_CHECK
1351 && compare_tree_int (TYPE_SIZE_UNIT (type
),
1352 STACK_CHECK_MAX_VAR_SIZE
) > 0))
1354 /* This is a variable-sized object. Make space on the stack
1356 rtx size_rtx
= expr_size (args
[i
].tree_value
);
1358 if (*old_stack_level
== 0)
1360 emit_stack_save (SAVE_BLOCK
, old_stack_level
);
1361 *old_pending_adj
= pending_stack_adjust
;
1362 pending_stack_adjust
= 0;
1365 /* We can pass TRUE as the 4th argument because we just
1366 saved the stack pointer and will restore it right after
1368 copy
= allocate_dynamic_stack_space (size_rtx
,
1372 copy
= gen_rtx_MEM (BLKmode
, copy
);
1373 set_mem_attributes (copy
, type
, 1);
1376 copy
= assign_temp (type
, 1, 0);
1378 store_expr (args
[i
].tree_value
, copy
, 0, false);
1380 /* Just change the const function to pure and then let
1381 the next test clear the pure based on
1383 if (*ecf_flags
& ECF_CONST
)
1385 *ecf_flags
&= ~ECF_CONST
;
1386 *ecf_flags
|= ECF_PURE
;
1389 if (!callee_copies
&& *ecf_flags
& ECF_PURE
)
1390 *ecf_flags
&= ~(ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
1393 = build_fold_addr_expr_loc (loc
, make_tree (type
, copy
));
1394 type
= TREE_TYPE (args
[i
].tree_value
);
1395 *may_tailcall
= false;
1399 unsignedp
= TYPE_UNSIGNED (type
);
1400 mode
= promote_function_mode (type
, TYPE_MODE (type
), &unsignedp
,
1401 fndecl
? TREE_TYPE (fndecl
) : fntype
, 0);
1403 args
[i
].unsignedp
= unsignedp
;
1404 args
[i
].mode
= mode
;
1406 args
[i
].reg
= targetm
.calls
.function_arg (args_so_far
, mode
, type
,
1407 argpos
< n_named_args
);
1409 if (args
[i
].reg
&& CONST_INT_P (args
[i
].reg
))
1411 args
[i
].special_slot
= args
[i
].reg
;
1415 /* If this is a sibling call and the machine has register windows, the
1416 register window has to be unwinded before calling the routine, so
1417 arguments have to go into the incoming registers. */
1418 if (targetm
.calls
.function_incoming_arg
!= targetm
.calls
.function_arg
)
1419 args
[i
].tail_call_reg
1420 = targetm
.calls
.function_incoming_arg (args_so_far
, mode
, type
,
1421 argpos
< n_named_args
);
1423 args
[i
].tail_call_reg
= args
[i
].reg
;
1427 = targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, type
,
1428 argpos
< n_named_args
);
1430 args
[i
].pass_on_stack
= targetm
.calls
.must_pass_in_stack (mode
, type
);
1432 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1433 it means that we are to pass this arg in the register(s) designated
1434 by the PARALLEL, but also to pass it in the stack. */
1435 if (args
[i
].reg
&& GET_CODE (args
[i
].reg
) == PARALLEL
1436 && XEXP (XVECEXP (args
[i
].reg
, 0, 0), 0) == 0)
1437 args
[i
].pass_on_stack
= 1;
1439 /* If this is an addressable type, we must preallocate the stack
1440 since we must evaluate the object into its final location.
1442 If this is to be passed in both registers and the stack, it is simpler
1444 if (TREE_ADDRESSABLE (type
)
1445 || (args
[i
].pass_on_stack
&& args
[i
].reg
!= 0))
1446 *must_preallocate
= 1;
1448 /* No stack allocation and padding for bounds. */
1449 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
1451 /* Compute the stack-size of this argument. */
1452 else if (args
[i
].reg
== 0 || args
[i
].partial
!= 0
1453 || reg_parm_stack_space
> 0
1454 || args
[i
].pass_on_stack
)
1455 locate_and_pad_parm (mode
, type
,
1456 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1461 reg_parm_stack_space
,
1462 args
[i
].pass_on_stack
? 0 : args
[i
].partial
,
1463 fndecl
, args_size
, &args
[i
].locate
);
1464 #ifdef BLOCK_REG_PADDING
1466 /* The argument is passed entirely in registers. See at which
1467 end it should be padded. */
1468 args
[i
].locate
.where_pad
=
1469 BLOCK_REG_PADDING (mode
, type
,
1470 int_size_in_bytes (type
) <= UNITS_PER_WORD
);
1473 /* Update ARGS_SIZE, the total stack space for args so far. */
1475 args_size
->constant
+= args
[i
].locate
.size
.constant
;
1476 if (args
[i
].locate
.size
.var
)
1477 ADD_PARM_SIZE (*args_size
, args
[i
].locate
.size
.var
);
1479 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1480 have been used, etc. */
1482 targetm
.calls
.function_arg_advance (args_so_far
, TYPE_MODE (type
),
1483 type
, argpos
< n_named_args
);
1487 /* Update ARGS_SIZE to contain the total size for the argument block.
1488 Return the original constant component of the argument block's size.
1490 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1491 for arguments passed in registers. */
1494 compute_argument_block_size (int reg_parm_stack_space
,
1495 struct args_size
*args_size
,
1496 tree fndecl ATTRIBUTE_UNUSED
,
1497 tree fntype ATTRIBUTE_UNUSED
,
1498 int preferred_stack_boundary ATTRIBUTE_UNUSED
)
1500 int unadjusted_args_size
= args_size
->constant
;
1502 /* For accumulate outgoing args mode we don't need to align, since the frame
1503 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1504 backends from generating misaligned frame sizes. */
1505 if (ACCUMULATE_OUTGOING_ARGS
&& preferred_stack_boundary
> STACK_BOUNDARY
)
1506 preferred_stack_boundary
= STACK_BOUNDARY
;
1508 /* Compute the actual size of the argument block required. The variable
1509 and constant sizes must be combined, the size may have to be rounded,
1510 and there may be a minimum required size. */
1514 args_size
->var
= ARGS_SIZE_TREE (*args_size
);
1515 args_size
->constant
= 0;
1517 preferred_stack_boundary
/= BITS_PER_UNIT
;
1518 if (preferred_stack_boundary
> 1)
1520 /* We don't handle this case yet. To handle it correctly we have
1521 to add the delta, round and subtract the delta.
1522 Currently no machine description requires this support. */
1523 gcc_assert (!(stack_pointer_delta
& (preferred_stack_boundary
- 1)));
1524 args_size
->var
= round_up (args_size
->var
, preferred_stack_boundary
);
1527 if (reg_parm_stack_space
> 0)
1530 = size_binop (MAX_EXPR
, args_size
->var
,
1531 ssize_int (reg_parm_stack_space
));
1533 /* The area corresponding to register parameters is not to count in
1534 the size of the block we need. So make the adjustment. */
1535 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
1537 = size_binop (MINUS_EXPR
, args_size
->var
,
1538 ssize_int (reg_parm_stack_space
));
1543 preferred_stack_boundary
/= BITS_PER_UNIT
;
1544 if (preferred_stack_boundary
< 1)
1545 preferred_stack_boundary
= 1;
1546 args_size
->constant
= (((args_size
->constant
1547 + stack_pointer_delta
1548 + preferred_stack_boundary
- 1)
1549 / preferred_stack_boundary
1550 * preferred_stack_boundary
)
1551 - stack_pointer_delta
);
1553 args_size
->constant
= MAX (args_size
->constant
,
1554 reg_parm_stack_space
);
1556 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
1557 args_size
->constant
-= reg_parm_stack_space
;
1559 return unadjusted_args_size
;
1562 /* Precompute parameters as needed for a function call.
1564 FLAGS is mask of ECF_* constants.
1566 NUM_ACTUALS is the number of arguments.
1568 ARGS is an array containing information for each argument; this
1569 routine fills in the INITIAL_VALUE and VALUE fields for each
1570 precomputed argument. */
1573 precompute_arguments (int num_actuals
, struct arg_data
*args
)
1577 /* If this is a libcall, then precompute all arguments so that we do not
1578 get extraneous instructions emitted as part of the libcall sequence. */
1580 /* If we preallocated the stack space, and some arguments must be passed
1581 on the stack, then we must precompute any parameter which contains a
1582 function call which will store arguments on the stack.
1583 Otherwise, evaluating the parameter may clobber previous parameters
1584 which have already been stored into the stack. (we have code to avoid
1585 such case by saving the outgoing stack arguments, but it results in
1587 if (!ACCUMULATE_OUTGOING_ARGS
)
1590 for (i
= 0; i
< num_actuals
; i
++)
1595 if (TREE_CODE (args
[i
].tree_value
) != CALL_EXPR
)
1598 /* If this is an addressable type, we cannot pre-evaluate it. */
1599 type
= TREE_TYPE (args
[i
].tree_value
);
1600 gcc_assert (!TREE_ADDRESSABLE (type
));
1602 args
[i
].initial_value
= args
[i
].value
1603 = expand_normal (args
[i
].tree_value
);
1605 mode
= TYPE_MODE (type
);
1606 if (mode
!= args
[i
].mode
)
1608 int unsignedp
= args
[i
].unsignedp
;
1610 = convert_modes (args
[i
].mode
, mode
,
1611 args
[i
].value
, args
[i
].unsignedp
);
1613 /* CSE will replace this only if it contains args[i].value
1614 pseudo, so convert it down to the declared mode using
1616 if (REG_P (args
[i
].value
)
1617 && GET_MODE_CLASS (args
[i
].mode
) == MODE_INT
1618 && promote_mode (type
, mode
, &unsignedp
) != args
[i
].mode
)
1620 args
[i
].initial_value
1621 = gen_lowpart_SUBREG (mode
, args
[i
].value
);
1622 SUBREG_PROMOTED_VAR_P (args
[i
].initial_value
) = 1;
1623 SUBREG_PROMOTED_SET (args
[i
].initial_value
, args
[i
].unsignedp
);
1629 /* Given the current state of MUST_PREALLOCATE and information about
1630 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1631 compute and return the final value for MUST_PREALLOCATE. */
1634 finalize_must_preallocate (int must_preallocate
, int num_actuals
,
1635 struct arg_data
*args
, struct args_size
*args_size
)
1637 /* See if we have or want to preallocate stack space.
1639 If we would have to push a partially-in-regs parm
1640 before other stack parms, preallocate stack space instead.
1642 If the size of some parm is not a multiple of the required stack
1643 alignment, we must preallocate.
1645 If the total size of arguments that would otherwise create a copy in
1646 a temporary (such as a CALL) is more than half the total argument list
1647 size, preallocation is faster.
1649 Another reason to preallocate is if we have a machine (like the m88k)
1650 where stack alignment is required to be maintained between every
1651 pair of insns, not just when the call is made. However, we assume here
1652 that such machines either do not have push insns (and hence preallocation
1653 would occur anyway) or the problem is taken care of with
1656 if (! must_preallocate
)
1658 int partial_seen
= 0;
1659 int copy_to_evaluate_size
= 0;
1662 for (i
= 0; i
< num_actuals
&& ! must_preallocate
; i
++)
1664 if (args
[i
].partial
> 0 && ! args
[i
].pass_on_stack
)
1666 else if (partial_seen
&& args
[i
].reg
== 0)
1667 must_preallocate
= 1;
1668 /* We preallocate in case there are bounds passed
1669 in the bounds table to have precomputed address
1670 for bounds association. */
1671 else if (POINTER_BOUNDS_P (args
[i
].tree_value
)
1673 must_preallocate
= 1;
1675 if (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)) == BLKmode
1676 && (TREE_CODE (args
[i
].tree_value
) == CALL_EXPR
1677 || TREE_CODE (args
[i
].tree_value
) == TARGET_EXPR
1678 || TREE_CODE (args
[i
].tree_value
) == COND_EXPR
1679 || TREE_ADDRESSABLE (TREE_TYPE (args
[i
].tree_value
))))
1680 copy_to_evaluate_size
1681 += int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1684 if (copy_to_evaluate_size
* 2 >= args_size
->constant
1685 && args_size
->constant
> 0)
1686 must_preallocate
= 1;
1688 return must_preallocate
;
1691 /* If we preallocated stack space, compute the address of each argument
1692 and store it into the ARGS array.
1694 We need not ensure it is a valid memory address here; it will be
1695 validized when it is used.
1697 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1700 compute_argument_addresses (struct arg_data
*args
, rtx argblock
, int num_actuals
)
1704 rtx arg_reg
= argblock
;
1705 int i
, arg_offset
= 0;
1707 if (GET_CODE (argblock
) == PLUS
)
1708 arg_reg
= XEXP (argblock
, 0), arg_offset
= INTVAL (XEXP (argblock
, 1));
1710 for (i
= 0; i
< num_actuals
; i
++)
1712 rtx offset
= ARGS_SIZE_RTX (args
[i
].locate
.offset
);
1713 rtx slot_offset
= ARGS_SIZE_RTX (args
[i
].locate
.slot_offset
);
1715 unsigned int align
, boundary
;
1716 unsigned int units_on_stack
= 0;
1717 machine_mode partial_mode
= VOIDmode
;
1719 /* Skip this parm if it will not be passed on the stack. */
1720 if (! args
[i
].pass_on_stack
1722 && args
[i
].partial
== 0)
1725 /* Pointer Bounds are never passed on the stack. */
1726 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
1729 if (CONST_INT_P (offset
))
1730 addr
= plus_constant (Pmode
, arg_reg
, INTVAL (offset
));
1732 addr
= gen_rtx_PLUS (Pmode
, arg_reg
, offset
);
1734 addr
= plus_constant (Pmode
, addr
, arg_offset
);
1736 if (args
[i
].partial
!= 0)
1738 /* Only part of the parameter is being passed on the stack.
1739 Generate a simple memory reference of the correct size. */
1740 units_on_stack
= args
[i
].locate
.size
.constant
;
1741 partial_mode
= mode_for_size (units_on_stack
* BITS_PER_UNIT
,
1743 args
[i
].stack
= gen_rtx_MEM (partial_mode
, addr
);
1744 set_mem_size (args
[i
].stack
, units_on_stack
);
1748 args
[i
].stack
= gen_rtx_MEM (args
[i
].mode
, addr
);
1749 set_mem_attributes (args
[i
].stack
,
1750 TREE_TYPE (args
[i
].tree_value
), 1);
1752 align
= BITS_PER_UNIT
;
1753 boundary
= args
[i
].locate
.boundary
;
1754 if (args
[i
].locate
.where_pad
!= downward
)
1756 else if (CONST_INT_P (offset
))
1758 align
= INTVAL (offset
) * BITS_PER_UNIT
| boundary
;
1759 align
= align
& -align
;
1761 set_mem_align (args
[i
].stack
, align
);
1763 if (CONST_INT_P (slot_offset
))
1764 addr
= plus_constant (Pmode
, arg_reg
, INTVAL (slot_offset
));
1766 addr
= gen_rtx_PLUS (Pmode
, arg_reg
, slot_offset
);
1768 addr
= plus_constant (Pmode
, addr
, arg_offset
);
1770 if (args
[i
].partial
!= 0)
1772 /* Only part of the parameter is being passed on the stack.
1773 Generate a simple memory reference of the correct size.
1775 args
[i
].stack_slot
= gen_rtx_MEM (partial_mode
, addr
);
1776 set_mem_size (args
[i
].stack_slot
, units_on_stack
);
1780 args
[i
].stack_slot
= gen_rtx_MEM (args
[i
].mode
, addr
);
1781 set_mem_attributes (args
[i
].stack_slot
,
1782 TREE_TYPE (args
[i
].tree_value
), 1);
1784 set_mem_align (args
[i
].stack_slot
, args
[i
].locate
.boundary
);
1786 /* Function incoming arguments may overlap with sibling call
1787 outgoing arguments and we cannot allow reordering of reads
1788 from function arguments with stores to outgoing arguments
1789 of sibling calls. */
1790 set_mem_alias_set (args
[i
].stack
, 0);
1791 set_mem_alias_set (args
[i
].stack_slot
, 0);
1796 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1797 in a call instruction.
1799 FNDECL is the tree node for the target function. For an indirect call
1800 FNDECL will be NULL_TREE.
1802 ADDR is the operand 0 of CALL_EXPR for this call. */
1805 rtx_for_function_call (tree fndecl
, tree addr
)
1809 /* Get the function to call, in the form of RTL. */
1812 if (!TREE_USED (fndecl
) && fndecl
!= current_function_decl
)
1813 TREE_USED (fndecl
) = 1;
1815 /* Get a SYMBOL_REF rtx for the function address. */
1816 funexp
= XEXP (DECL_RTL (fndecl
), 0);
1819 /* Generate an rtx (probably a pseudo-register) for the address. */
1822 funexp
= expand_normal (addr
);
1823 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1828 /* Internal state for internal_arg_pointer_based_exp and its helpers. */
1831 /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan,
1832 or NULL_RTX if none has been scanned yet. */
1833 rtx_insn
*scan_start
;
1834 /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is
1835 based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the
1836 pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it
1837 with fixed offset, or PC if this is with variable or unknown offset. */
1839 } internal_arg_pointer_exp_state
;
1841 static rtx
internal_arg_pointer_based_exp (const_rtx
, bool);
1843 /* Helper function for internal_arg_pointer_based_exp. Scan insns in
1844 the tail call sequence, starting with first insn that hasn't been
1845 scanned yet, and note for each pseudo on the LHS whether it is based
1846 on crtl->args.internal_arg_pointer or not, and what offset from that
1847 that pointer it has. */
1850 internal_arg_pointer_based_exp_scan (void)
1852 rtx_insn
*insn
, *scan_start
= internal_arg_pointer_exp_state
.scan_start
;
1854 if (scan_start
== NULL_RTX
)
1855 insn
= get_insns ();
1857 insn
= NEXT_INSN (scan_start
);
1861 rtx set
= single_set (insn
);
1862 if (set
&& REG_P (SET_DEST (set
)) && !HARD_REGISTER_P (SET_DEST (set
)))
1865 unsigned int idx
= REGNO (SET_DEST (set
)) - FIRST_PSEUDO_REGISTER
;
1866 /* Punt on pseudos set multiple times. */
1867 if (idx
< internal_arg_pointer_exp_state
.cache
.length ()
1868 && (internal_arg_pointer_exp_state
.cache
[idx
]
1872 val
= internal_arg_pointer_based_exp (SET_SRC (set
), false);
1873 if (val
!= NULL_RTX
)
1875 if (idx
>= internal_arg_pointer_exp_state
.cache
.length ())
1876 internal_arg_pointer_exp_state
.cache
1877 .safe_grow_cleared (idx
+ 1);
1878 internal_arg_pointer_exp_state
.cache
[idx
] = val
;
1881 if (NEXT_INSN (insn
) == NULL_RTX
)
1883 insn
= NEXT_INSN (insn
);
1886 internal_arg_pointer_exp_state
.scan_start
= scan_start
;
1889 /* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return
1890 NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on
1891 it with fixed offset, or PC if this is with variable or unknown offset.
1892 TOPLEVEL is true if the function is invoked at the topmost level. */
1895 internal_arg_pointer_based_exp (const_rtx rtl
, bool toplevel
)
1897 if (CONSTANT_P (rtl
))
1900 if (rtl
== crtl
->args
.internal_arg_pointer
)
1903 if (REG_P (rtl
) && HARD_REGISTER_P (rtl
))
1906 if (GET_CODE (rtl
) == PLUS
&& CONST_INT_P (XEXP (rtl
, 1)))
1908 rtx val
= internal_arg_pointer_based_exp (XEXP (rtl
, 0), toplevel
);
1909 if (val
== NULL_RTX
|| val
== pc_rtx
)
1911 return plus_constant (Pmode
, val
, INTVAL (XEXP (rtl
, 1)));
1914 /* When called at the topmost level, scan pseudo assignments in between the
1915 last scanned instruction in the tail call sequence and the latest insn
1916 in that sequence. */
1918 internal_arg_pointer_based_exp_scan ();
1922 unsigned int idx
= REGNO (rtl
) - FIRST_PSEUDO_REGISTER
;
1923 if (idx
< internal_arg_pointer_exp_state
.cache
.length ())
1924 return internal_arg_pointer_exp_state
.cache
[idx
];
1929 subrtx_iterator::array_type array
;
1930 FOR_EACH_SUBRTX (iter
, array
, rtl
, NONCONST
)
1932 const_rtx x
= *iter
;
1933 if (REG_P (x
) && internal_arg_pointer_based_exp (x
, false) != NULL_RTX
)
1936 iter
.skip_subrtxes ();
1942 /* Return true if and only if SIZE storage units (usually bytes)
1943 starting from address ADDR overlap with already clobbered argument
1944 area. This function is used to determine if we should give up a
1948 mem_overlaps_already_clobbered_arg_p (rtx addr
, unsigned HOST_WIDE_INT size
)
1953 if (bitmap_empty_p (stored_args_map
))
1955 val
= internal_arg_pointer_based_exp (addr
, true);
1956 if (val
== NULL_RTX
)
1958 else if (val
== pc_rtx
)
1962 #ifdef STACK_GROWS_DOWNWARD
1963 i
-= crtl
->args
.pretend_args_size
;
1965 i
+= crtl
->args
.pretend_args_size
;
1968 #ifdef ARGS_GROW_DOWNWARD
1973 unsigned HOST_WIDE_INT k
;
1975 for (k
= 0; k
< size
; k
++)
1976 if (i
+ k
< SBITMAP_SIZE (stored_args_map
)
1977 && bitmap_bit_p (stored_args_map
, i
+ k
))
1984 /* Do the register loads required for any wholly-register parms or any
1985 parms which are passed both on the stack and in a register. Their
1986 expressions were already evaluated.
1988 Mark all register-parms as living through the call, putting these USE
1989 insns in the CALL_INSN_FUNCTION_USAGE field.
1991 When IS_SIBCALL, perform the check_sibcall_argument_overlap
1992 checking, setting *SIBCALL_FAILURE if appropriate. */
1995 load_register_parameters (struct arg_data
*args
, int num_actuals
,
1996 rtx
*call_fusage
, int flags
, int is_sibcall
,
1997 int *sibcall_failure
)
2001 for (i
= 0; i
< num_actuals
; i
++)
2003 rtx reg
= ((flags
& ECF_SIBCALL
)
2004 ? args
[i
].tail_call_reg
: args
[i
].reg
);
2007 int partial
= args
[i
].partial
;
2010 rtx_insn
*before_arg
= get_last_insn ();
2011 /* Set non-negative if we must move a word at a time, even if
2012 just one word (e.g, partial == 4 && mode == DFmode). Set
2013 to -1 if we just use a normal move insn. This value can be
2014 zero if the argument is a zero size structure. */
2016 if (GET_CODE (reg
) == PARALLEL
)
2020 gcc_assert (partial
% UNITS_PER_WORD
== 0);
2021 nregs
= partial
/ UNITS_PER_WORD
;
2023 else if (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)) == BLKmode
)
2025 size
= int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
2026 nregs
= (size
+ (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
2029 size
= GET_MODE_SIZE (args
[i
].mode
);
2031 /* Handle calls that pass values in multiple non-contiguous
2032 locations. The Irix 6 ABI has examples of this. */
2034 if (GET_CODE (reg
) == PARALLEL
)
2035 emit_group_move (reg
, args
[i
].parallel_value
);
2037 /* If simple case, just do move. If normal partial, store_one_arg
2038 has already loaded the register for us. In all other cases,
2039 load the register(s) from memory. */
2041 else if (nregs
== -1)
2043 emit_move_insn (reg
, args
[i
].value
);
2044 #ifdef BLOCK_REG_PADDING
2045 /* Handle case where we have a value that needs shifting
2046 up to the msb. eg. a QImode value and we're padding
2047 upward on a BYTES_BIG_ENDIAN machine. */
2048 if (size
< UNITS_PER_WORD
2049 && (args
[i
].locate
.where_pad
2050 == (BYTES_BIG_ENDIAN
? upward
: downward
)))
2053 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
2055 /* Assigning REG here rather than a temp makes CALL_FUSAGE
2056 report the whole reg as used. Strictly speaking, the
2057 call only uses SIZE bytes at the msb end, but it doesn't
2058 seem worth generating rtl to say that. */
2059 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
2060 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, shift
, reg
, 1);
2062 emit_move_insn (reg
, x
);
2067 /* If we have pre-computed the values to put in the registers in
2068 the case of non-aligned structures, copy them in now. */
2070 else if (args
[i
].n_aligned_regs
!= 0)
2071 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
2072 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
) + j
),
2073 args
[i
].aligned_regs
[j
]);
2075 else if (partial
== 0 || args
[i
].pass_on_stack
)
2077 rtx mem
= validize_mem (copy_rtx (args
[i
].value
));
2079 /* Check for overlap with already clobbered argument area,
2080 providing that this has non-zero size. */
2083 || mem_overlaps_already_clobbered_arg_p
2084 (XEXP (args
[i
].value
, 0), size
)))
2085 *sibcall_failure
= 1;
2087 /* Handle a BLKmode that needs shifting. */
2088 if (nregs
== 1 && size
< UNITS_PER_WORD
2089 #ifdef BLOCK_REG_PADDING
2090 && args
[i
].locate
.where_pad
== downward
2096 rtx tem
= operand_subword_force (mem
, 0, args
[i
].mode
);
2097 rtx ri
= gen_rtx_REG (word_mode
, REGNO (reg
));
2098 rtx x
= gen_reg_rtx (word_mode
);
2099 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
2100 enum tree_code dir
= BYTES_BIG_ENDIAN
? RSHIFT_EXPR
2103 emit_move_insn (x
, tem
);
2104 x
= expand_shift (dir
, word_mode
, x
, shift
, ri
, 1);
2106 emit_move_insn (ri
, x
);
2109 move_block_to_reg (REGNO (reg
), mem
, nregs
, args
[i
].mode
);
2112 /* When a parameter is a block, and perhaps in other cases, it is
2113 possible that it did a load from an argument slot that was
2114 already clobbered. */
2116 && check_sibcall_argument_overlap (before_arg
, &args
[i
], 0))
2117 *sibcall_failure
= 1;
2119 /* Handle calls that pass values in multiple non-contiguous
2120 locations. The Irix 6 ABI has examples of this. */
2121 if (GET_CODE (reg
) == PARALLEL
)
2122 use_group_regs (call_fusage
, reg
);
2123 else if (nregs
== -1)
2124 use_reg_mode (call_fusage
, reg
,
2125 TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)));
2127 use_regs (call_fusage
, REGNO (reg
), nregs
);
2132 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
2133 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
2134 bytes, then we would need to push some additional bytes to pad the
2135 arguments. So, we compute an adjust to the stack pointer for an
2136 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
2137 bytes. Then, when the arguments are pushed the stack will be perfectly
2138 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
2139 be popped after the call. Returns the adjustment. */
2142 combine_pending_stack_adjustment_and_call (int unadjusted_args_size
,
2143 struct args_size
*args_size
,
2144 unsigned int preferred_unit_stack_boundary
)
2146 /* The number of bytes to pop so that the stack will be
2147 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
2148 HOST_WIDE_INT adjustment
;
2149 /* The alignment of the stack after the arguments are pushed, if we
2150 just pushed the arguments without adjust the stack here. */
2151 unsigned HOST_WIDE_INT unadjusted_alignment
;
2153 unadjusted_alignment
2154 = ((stack_pointer_delta
+ unadjusted_args_size
)
2155 % preferred_unit_stack_boundary
);
2157 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
2158 as possible -- leaving just enough left to cancel out the
2159 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
2160 PENDING_STACK_ADJUST is non-negative, and congruent to
2161 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
2163 /* Begin by trying to pop all the bytes. */
2164 unadjusted_alignment
2165 = (unadjusted_alignment
2166 - (pending_stack_adjust
% preferred_unit_stack_boundary
));
2167 adjustment
= pending_stack_adjust
;
2168 /* Push enough additional bytes that the stack will be aligned
2169 after the arguments are pushed. */
2170 if (preferred_unit_stack_boundary
> 1)
2172 if (unadjusted_alignment
> 0)
2173 adjustment
-= preferred_unit_stack_boundary
- unadjusted_alignment
;
2175 adjustment
+= unadjusted_alignment
;
2178 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
2179 bytes after the call. The right number is the entire
2180 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
2181 by the arguments in the first place. */
2183 = pending_stack_adjust
- adjustment
+ unadjusted_args_size
;
2188 /* Scan X expression if it does not dereference any argument slots
2189 we already clobbered by tail call arguments (as noted in stored_args_map
2191 Return nonzero if X expression dereferences such argument slots,
2195 check_sibcall_argument_overlap_1 (rtx x
)
2204 code
= GET_CODE (x
);
2206 /* We need not check the operands of the CALL expression itself. */
2211 return mem_overlaps_already_clobbered_arg_p (XEXP (x
, 0),
2212 GET_MODE_SIZE (GET_MODE (x
)));
2214 /* Scan all subexpressions. */
2215 fmt
= GET_RTX_FORMAT (code
);
2216 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
2220 if (check_sibcall_argument_overlap_1 (XEXP (x
, i
)))
2223 else if (*fmt
== 'E')
2225 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2226 if (check_sibcall_argument_overlap_1 (XVECEXP (x
, i
, j
)))
2233 /* Scan sequence after INSN if it does not dereference any argument slots
2234 we already clobbered by tail call arguments (as noted in stored_args_map
2235 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
2236 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
2237 should be 0). Return nonzero if sequence after INSN dereferences such argument
2238 slots, zero otherwise. */
2241 check_sibcall_argument_overlap (rtx_insn
*insn
, struct arg_data
*arg
,
2242 int mark_stored_args_map
)
2246 if (insn
== NULL_RTX
)
2247 insn
= get_insns ();
2249 insn
= NEXT_INSN (insn
);
2251 for (; insn
; insn
= NEXT_INSN (insn
))
2253 && check_sibcall_argument_overlap_1 (PATTERN (insn
)))
2256 if (mark_stored_args_map
)
2258 #ifdef ARGS_GROW_DOWNWARD
2259 low
= -arg
->locate
.slot_offset
.constant
- arg
->locate
.size
.constant
;
2261 low
= arg
->locate
.slot_offset
.constant
;
2264 for (high
= low
+ arg
->locate
.size
.constant
; low
< high
; low
++)
2265 bitmap_set_bit (stored_args_map
, low
);
2267 return insn
!= NULL_RTX
;
2270 /* Given that a function returns a value of mode MODE at the most
2271 significant end of hard register VALUE, shift VALUE left or right
2272 as specified by LEFT_P. Return true if some action was needed. */
2275 shift_return_value (machine_mode mode
, bool left_p
, rtx value
)
2277 HOST_WIDE_INT shift
;
2279 gcc_assert (REG_P (value
) && HARD_REGISTER_P (value
));
2280 shift
= GET_MODE_BITSIZE (GET_MODE (value
)) - GET_MODE_BITSIZE (mode
);
2284 /* Use ashr rather than lshr for right shifts. This is for the benefit
2285 of the MIPS port, which requires SImode values to be sign-extended
2286 when stored in 64-bit registers. */
2287 if (!force_expand_binop (GET_MODE (value
), left_p
? ashl_optab
: ashr_optab
,
2288 value
, GEN_INT (shift
), value
, 1, OPTAB_WIDEN
))
2293 /* If X is a likely-spilled register value, copy it to a pseudo
2294 register and return that register. Return X otherwise. */
2297 avoid_likely_spilled_reg (rtx x
)
2302 && HARD_REGISTER_P (x
)
2303 && targetm
.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x
))))
2305 /* Make sure that we generate a REG rather than a CONCAT.
2306 Moves into CONCATs can need nontrivial instructions,
2307 and the whole point of this function is to avoid
2308 using the hard register directly in such a situation. */
2309 generating_concat_p
= 0;
2310 new_rtx
= gen_reg_rtx (GET_MODE (x
));
2311 generating_concat_p
= 1;
2312 emit_move_insn (new_rtx
, x
);
2318 /* Generate all the code for a CALL_EXPR exp
2319 and return an rtx for its value.
2320 Store the value in TARGET (specified as an rtx) if convenient.
2321 If the value is stored in TARGET then TARGET is returned.
2322 If IGNORE is nonzero, then we ignore the value of the function call. */
2325 expand_call (tree exp
, rtx target
, int ignore
)
2327 /* Nonzero if we are currently expanding a call. */
2328 static int currently_expanding_call
= 0;
2330 /* RTX for the function to be called. */
2332 /* Sequence of insns to perform a normal "call". */
2333 rtx_insn
*normal_call_insns
= NULL
;
2334 /* Sequence of insns to perform a tail "call". */
2335 rtx_insn
*tail_call_insns
= NULL
;
2336 /* Data type of the function. */
2338 tree type_arg_types
;
2340 /* Declaration of the function being called,
2341 or 0 if the function is computed (not known by name). */
2343 /* The type of the function being called. */
2345 bool try_tail_call
= CALL_EXPR_TAILCALL (exp
);
2348 /* Register in which non-BLKmode value will be returned,
2349 or 0 if no value or if value is BLKmode. */
2351 /* Register(s) in which bounds are returned. */
2353 /* Address where we should return a BLKmode value;
2354 0 if value not BLKmode. */
2355 rtx structure_value_addr
= 0;
2356 /* Nonzero if that address is being passed by treating it as
2357 an extra, implicit first parameter. Otherwise,
2358 it is passed by being copied directly into struct_value_rtx. */
2359 int structure_value_addr_parm
= 0;
2360 /* Holds the value of implicit argument for the struct value. */
2361 tree structure_value_addr_value
= NULL_TREE
;
2362 /* Size of aggregate value wanted, or zero if none wanted
2363 or if we are using the non-reentrant PCC calling convention
2364 or expecting the value in registers. */
2365 HOST_WIDE_INT struct_value_size
= 0;
2366 /* Nonzero if called function returns an aggregate in memory PCC style,
2367 by returning the address of where to find it. */
2368 int pcc_struct_value
= 0;
2369 rtx struct_value
= 0;
2371 /* Number of actual parameters in this call, including struct value addr. */
2373 /* Number of named args. Args after this are anonymous ones
2374 and they must all go on the stack. */
2376 /* Number of complex actual arguments that need to be split. */
2377 int num_complex_actuals
= 0;
2379 /* Vector of information about each argument.
2380 Arguments are numbered in the order they will be pushed,
2381 not the order they are written. */
2382 struct arg_data
*args
;
2384 /* Total size in bytes of all the stack-parms scanned so far. */
2385 struct args_size args_size
;
2386 struct args_size adjusted_args_size
;
2387 /* Size of arguments before any adjustments (such as rounding). */
2388 int unadjusted_args_size
;
2389 /* Data on reg parms scanned so far. */
2390 CUMULATIVE_ARGS args_so_far_v
;
2391 cumulative_args_t args_so_far
;
2392 /* Nonzero if a reg parm has been scanned. */
2394 /* Nonzero if this is an indirect function call. */
2396 /* Nonzero if we must avoid push-insns in the args for this call.
2397 If stack space is allocated for register parameters, but not by the
2398 caller, then it is preallocated in the fixed part of the stack frame.
2399 So the entire argument block must then be preallocated (i.e., we
2400 ignore PUSH_ROUNDING in that case). */
2402 int must_preallocate
= !PUSH_ARGS
;
2404 /* Size of the stack reserved for parameter registers. */
2405 int reg_parm_stack_space
= 0;
2407 /* Address of space preallocated for stack parms
2408 (on machines that lack push insns), or 0 if space not preallocated. */
2411 /* Mask of ECF_ and ERF_ flags. */
2413 int return_flags
= 0;
2414 #ifdef REG_PARM_STACK_SPACE
2415 /* Define the boundary of the register parm stack space that needs to be
2417 int low_to_save
, high_to_save
;
2418 rtx save_area
= 0; /* Place that it is saved */
2421 int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
2422 char *initial_stack_usage_map
= stack_usage_map
;
2423 char *stack_usage_map_buf
= NULL
;
2425 int old_stack_allocated
;
2427 /* State variables to track stack modifications. */
2428 rtx old_stack_level
= 0;
2429 int old_stack_arg_under_construction
= 0;
2430 int old_pending_adj
= 0;
2431 int old_inhibit_defer_pop
= inhibit_defer_pop
;
2433 /* Some stack pointer alterations we make are performed via
2434 allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
2435 which we then also need to save/restore along the way. */
2436 int old_stack_pointer_delta
= 0;
2439 tree addr
= CALL_EXPR_FN (exp
);
2441 /* The alignment of the stack, in bits. */
2442 unsigned HOST_WIDE_INT preferred_stack_boundary
;
2443 /* The alignment of the stack, in bytes. */
2444 unsigned HOST_WIDE_INT preferred_unit_stack_boundary
;
2445 /* The static chain value to use for this call. */
2446 rtx static_chain_value
;
2447 /* See if this is "nothrow" function call. */
2448 if (TREE_NOTHROW (exp
))
2449 flags
|= ECF_NOTHROW
;
2451 /* See if we can find a DECL-node for the actual function, and get the
2452 function attributes (flags) from the function decl or type node. */
2453 fndecl
= get_callee_fndecl (exp
);
2456 fntype
= TREE_TYPE (fndecl
);
2457 flags
|= flags_from_decl_or_type (fndecl
);
2458 return_flags
|= decl_return_flags (fndecl
);
2462 fntype
= TREE_TYPE (TREE_TYPE (addr
));
2463 flags
|= flags_from_decl_or_type (fntype
);
2465 rettype
= TREE_TYPE (exp
);
2467 struct_value
= targetm
.calls
.struct_value_rtx (fntype
, 0);
2469 /* Warn if this value is an aggregate type,
2470 regardless of which calling convention we are using for it. */
2471 if (AGGREGATE_TYPE_P (rettype
))
2472 warning (OPT_Waggregate_return
, "function call has aggregate value");
2474 /* If the result of a non looping pure or const function call is
2475 ignored (or void), and none of its arguments are volatile, we can
2476 avoid expanding the call and just evaluate the arguments for
2478 if ((flags
& (ECF_CONST
| ECF_PURE
))
2479 && (!(flags
& ECF_LOOPING_CONST_OR_PURE
))
2480 && (ignore
|| target
== const0_rtx
2481 || TYPE_MODE (rettype
) == VOIDmode
))
2483 bool volatilep
= false;
2485 call_expr_arg_iterator iter
;
2487 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2488 if (TREE_THIS_VOLATILE (arg
))
2496 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2497 expand_expr (arg
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
2502 #ifdef REG_PARM_STACK_SPACE
2503 reg_parm_stack_space
= REG_PARM_STACK_SPACE (!fndecl
? fntype
: fndecl
);
2506 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
)))
2507 && reg_parm_stack_space
> 0 && PUSH_ARGS
)
2508 must_preallocate
= 1;
2510 /* Set up a place to return a structure. */
2512 /* Cater to broken compilers. */
2513 if (aggregate_value_p (exp
, fntype
))
2515 /* This call returns a big structure. */
2516 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
2518 #ifdef PCC_STATIC_STRUCT_RETURN
2520 pcc_struct_value
= 1;
2522 #else /* not PCC_STATIC_STRUCT_RETURN */
2524 struct_value_size
= int_size_in_bytes (rettype
);
2526 /* Even if it is semantically safe to use the target as the return
2527 slot, it may be not sufficiently aligned for the return type. */
2528 if (CALL_EXPR_RETURN_SLOT_OPT (exp
)
2531 && !(MEM_ALIGN (target
) < TYPE_ALIGN (rettype
)
2532 && SLOW_UNALIGNED_ACCESS (TYPE_MODE (rettype
),
2533 MEM_ALIGN (target
))))
2534 structure_value_addr
= XEXP (target
, 0);
2537 /* For variable-sized objects, we must be called with a target
2538 specified. If we were to allocate space on the stack here,
2539 we would have no way of knowing when to free it. */
2540 rtx d
= assign_temp (rettype
, 1, 1);
2541 structure_value_addr
= XEXP (d
, 0);
2545 #endif /* not PCC_STATIC_STRUCT_RETURN */
2548 /* Figure out the amount to which the stack should be aligned. */
2549 preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
2552 struct cgraph_rtl_info
*i
= cgraph_node::rtl_info (fndecl
);
2553 /* Without automatic stack alignment, we can't increase preferred
2554 stack boundary. With automatic stack alignment, it is
2555 unnecessary since unless we can guarantee that all callers will
2556 align the outgoing stack properly, callee has to align its
2559 && i
->preferred_incoming_stack_boundary
2560 && i
->preferred_incoming_stack_boundary
< preferred_stack_boundary
)
2561 preferred_stack_boundary
= i
->preferred_incoming_stack_boundary
;
2564 /* Operand 0 is a pointer-to-function; get the type of the function. */
2565 funtype
= TREE_TYPE (addr
);
2566 gcc_assert (POINTER_TYPE_P (funtype
));
2567 funtype
= TREE_TYPE (funtype
);
2569 /* Count whether there are actual complex arguments that need to be split
2570 into their real and imaginary parts. Munge the type_arg_types
2571 appropriately here as well. */
2572 if (targetm
.calls
.split_complex_arg
)
2574 call_expr_arg_iterator iter
;
2576 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2578 tree type
= TREE_TYPE (arg
);
2579 if (type
&& TREE_CODE (type
) == COMPLEX_TYPE
2580 && targetm
.calls
.split_complex_arg (type
))
2581 num_complex_actuals
++;
2583 type_arg_types
= split_complex_types (TYPE_ARG_TYPES (funtype
));
2586 type_arg_types
= TYPE_ARG_TYPES (funtype
);
2588 if (flags
& ECF_MAY_BE_ALLOCA
)
2589 cfun
->calls_alloca
= 1;
2591 /* If struct_value_rtx is 0, it means pass the address
2592 as if it were an extra parameter. Put the argument expression
2593 in structure_value_addr_value. */
2594 if (structure_value_addr
&& struct_value
== 0)
2596 /* If structure_value_addr is a REG other than
2597 virtual_outgoing_args_rtx, we can use always use it. If it
2598 is not a REG, we must always copy it into a register.
2599 If it is virtual_outgoing_args_rtx, we must copy it to another
2600 register in some cases. */
2601 rtx temp
= (!REG_P (structure_value_addr
)
2602 || (ACCUMULATE_OUTGOING_ARGS
2603 && stack_arg_under_construction
2604 && structure_value_addr
== virtual_outgoing_args_rtx
)
2605 ? copy_addr_to_reg (convert_memory_address
2606 (Pmode
, structure_value_addr
))
2607 : structure_value_addr
);
2609 structure_value_addr_value
=
2610 make_tree (build_pointer_type (TREE_TYPE (funtype
)), temp
);
2611 structure_value_addr_parm
= CALL_WITH_BOUNDS_P (exp
) ? 2 : 1;
2614 /* Count the arguments and set NUM_ACTUALS. */
2616 call_expr_nargs (exp
) + num_complex_actuals
+ structure_value_addr_parm
;
2618 /* Compute number of named args.
2619 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2621 if (type_arg_types
!= 0)
2623 = (list_length (type_arg_types
)
2624 /* Count the struct value address, if it is passed as a parm. */
2625 + structure_value_addr_parm
);
2627 /* If we know nothing, treat all args as named. */
2628 n_named_args
= num_actuals
;
2630 /* Start updating where the next arg would go.
2632 On some machines (such as the PA) indirect calls have a different
2633 calling convention than normal calls. The fourth argument in
2634 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2636 INIT_CUMULATIVE_ARGS (args_so_far_v
, funtype
, NULL_RTX
, fndecl
, n_named_args
);
2637 args_so_far
= pack_cumulative_args (&args_so_far_v
);
2639 /* Now possibly adjust the number of named args.
2640 Normally, don't include the last named arg if anonymous args follow.
2641 We do include the last named arg if
2642 targetm.calls.strict_argument_naming() returns nonzero.
2643 (If no anonymous args follow, the result of list_length is actually
2644 one too large. This is harmless.)
2646 If targetm.calls.pretend_outgoing_varargs_named() returns
2647 nonzero, and targetm.calls.strict_argument_naming() returns zero,
2648 this machine will be able to place unnamed args that were passed
2649 in registers into the stack. So treat all args as named. This
2650 allows the insns emitting for a specific argument list to be
2651 independent of the function declaration.
2653 If targetm.calls.pretend_outgoing_varargs_named() returns zero,
2654 we do not have any reliable way to pass unnamed args in
2655 registers, so we must force them into memory. */
2657 if (type_arg_types
!= 0
2658 && targetm
.calls
.strict_argument_naming (args_so_far
))
2660 else if (type_arg_types
!= 0
2661 && ! targetm
.calls
.pretend_outgoing_varargs_named (args_so_far
))
2662 /* Don't include the last named arg. */
2665 /* Treat all args as named. */
2666 n_named_args
= num_actuals
;
2668 /* Make a vector to hold all the information about each arg. */
2669 args
= XALLOCAVEC (struct arg_data
, num_actuals
);
2670 memset (args
, 0, num_actuals
* sizeof (struct arg_data
));
2672 /* Build up entries in the ARGS array, compute the size of the
2673 arguments into ARGS_SIZE, etc. */
2674 initialize_argument_information (num_actuals
, args
, &args_size
,
2676 structure_value_addr_value
, fndecl
, fntype
,
2677 args_so_far
, reg_parm_stack_space
,
2678 &old_stack_level
, &old_pending_adj
,
2679 &must_preallocate
, &flags
,
2680 &try_tail_call
, CALL_FROM_THUNK_P (exp
));
2683 must_preallocate
= 1;
2685 /* Now make final decision about preallocating stack space. */
2686 must_preallocate
= finalize_must_preallocate (must_preallocate
,
2690 /* If the structure value address will reference the stack pointer, we
2691 must stabilize it. We don't need to do this if we know that we are
2692 not going to adjust the stack pointer in processing this call. */
2694 if (structure_value_addr
2695 && (reg_mentioned_p (virtual_stack_dynamic_rtx
, structure_value_addr
)
2696 || reg_mentioned_p (virtual_outgoing_args_rtx
,
2697 structure_value_addr
))
2699 || (!ACCUMULATE_OUTGOING_ARGS
&& args_size
.constant
)))
2700 structure_value_addr
= copy_to_reg (structure_value_addr
);
2702 /* Tail calls can make things harder to debug, and we've traditionally
2703 pushed these optimizations into -O2. Don't try if we're already
2704 expanding a call, as that means we're an argument. Don't try if
2705 there's cleanups, as we know there's code to follow the call. */
2707 if (currently_expanding_call
++ != 0
2708 || !flag_optimize_sibling_calls
2710 || dbg_cnt (tail_call
) == false)
2713 /* Rest of purposes for tail call optimizations to fail. */
2715 #ifdef HAVE_sibcall_epilogue
2716 !HAVE_sibcall_epilogue
2721 /* Doing sibling call optimization needs some work, since
2722 structure_value_addr can be allocated on the stack.
2723 It does not seem worth the effort since few optimizable
2724 sibling calls will return a structure. */
2725 || structure_value_addr
!= NULL_RTX
2726 #ifdef REG_PARM_STACK_SPACE
2727 /* If outgoing reg parm stack space changes, we can not do sibcall. */
2728 || (OUTGOING_REG_PARM_STACK_SPACE (funtype
)
2729 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl
)))
2730 || (reg_parm_stack_space
!= REG_PARM_STACK_SPACE (current_function_decl
))
2732 /* Check whether the target is able to optimize the call
2734 || !targetm
.function_ok_for_sibcall (fndecl
, exp
)
2735 /* Functions that do not return exactly once may not be sibcall
2737 || (flags
& (ECF_RETURNS_TWICE
| ECF_NORETURN
))
2738 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr
)))
2739 /* If the called function is nested in the current one, it might access
2740 some of the caller's arguments, but could clobber them beforehand if
2741 the argument areas are shared. */
2742 || (fndecl
&& decl_function_context (fndecl
) == current_function_decl
)
2743 /* If this function requires more stack slots than the current
2744 function, we cannot change it into a sibling call.
2745 crtl->args.pretend_args_size is not part of the
2746 stack allocated by our caller. */
2747 || args_size
.constant
> (crtl
->args
.size
2748 - crtl
->args
.pretend_args_size
)
2749 /* If the callee pops its own arguments, then it must pop exactly
2750 the same number of arguments as the current function. */
2751 || (targetm
.calls
.return_pops_args (fndecl
, funtype
, args_size
.constant
)
2752 != targetm
.calls
.return_pops_args (current_function_decl
,
2753 TREE_TYPE (current_function_decl
),
2755 || !lang_hooks
.decls
.ok_for_sibcall (fndecl
))
2758 /* Check if caller and callee disagree in promotion of function
2762 machine_mode caller_mode
, caller_promoted_mode
;
2763 machine_mode callee_mode
, callee_promoted_mode
;
2764 int caller_unsignedp
, callee_unsignedp
;
2765 tree caller_res
= DECL_RESULT (current_function_decl
);
2767 caller_unsignedp
= TYPE_UNSIGNED (TREE_TYPE (caller_res
));
2768 caller_mode
= DECL_MODE (caller_res
);
2769 callee_unsignedp
= TYPE_UNSIGNED (TREE_TYPE (funtype
));
2770 callee_mode
= TYPE_MODE (TREE_TYPE (funtype
));
2771 caller_promoted_mode
2772 = promote_function_mode (TREE_TYPE (caller_res
), caller_mode
,
2774 TREE_TYPE (current_function_decl
), 1);
2775 callee_promoted_mode
2776 = promote_function_mode (TREE_TYPE (funtype
), callee_mode
,
2779 if (caller_mode
!= VOIDmode
2780 && (caller_promoted_mode
!= callee_promoted_mode
2781 || ((caller_mode
!= caller_promoted_mode
2782 || callee_mode
!= callee_promoted_mode
)
2783 && (caller_unsignedp
!= callee_unsignedp
2784 || GET_MODE_BITSIZE (caller_mode
)
2785 < GET_MODE_BITSIZE (callee_mode
)))))
2789 /* Ensure current function's preferred stack boundary is at least
2790 what we need. Stack alignment may also increase preferred stack
2792 if (crtl
->preferred_stack_boundary
< preferred_stack_boundary
)
2793 crtl
->preferred_stack_boundary
= preferred_stack_boundary
;
2795 preferred_stack_boundary
= crtl
->preferred_stack_boundary
;
2797 preferred_unit_stack_boundary
= preferred_stack_boundary
/ BITS_PER_UNIT
;
2799 /* We want to make two insn chains; one for a sibling call, the other
2800 for a normal call. We will select one of the two chains after
2801 initial RTL generation is complete. */
2802 for (pass
= try_tail_call
? 0 : 1; pass
< 2; pass
++)
2804 int sibcall_failure
= 0;
2805 /* We want to emit any pending stack adjustments before the tail
2806 recursion "call". That way we know any adjustment after the tail
2807 recursion call can be ignored if we indeed use the tail
2809 saved_pending_stack_adjust save
;
2810 rtx_insn
*insns
, *before_call
, *after_args
;
2815 /* State variables we need to save and restore between
2817 save_pending_stack_adjust (&save
);
2820 flags
&= ~ECF_SIBCALL
;
2822 flags
|= ECF_SIBCALL
;
2824 /* Other state variables that we must reinitialize each time
2825 through the loop (that are not initialized by the loop itself). */
2829 /* Start a new sequence for the normal call case.
2831 From this point on, if the sibling call fails, we want to set
2832 sibcall_failure instead of continuing the loop. */
2835 /* Don't let pending stack adjusts add up to too much.
2836 Also, do all pending adjustments now if there is any chance
2837 this might be a call to alloca or if we are expanding a sibling
2839 Also do the adjustments before a throwing call, otherwise
2840 exception handling can fail; PR 19225. */
2841 if (pending_stack_adjust
>= 32
2842 || (pending_stack_adjust
> 0
2843 && (flags
& ECF_MAY_BE_ALLOCA
))
2844 || (pending_stack_adjust
> 0
2845 && flag_exceptions
&& !(flags
& ECF_NOTHROW
))
2847 do_pending_stack_adjust ();
2849 /* Precompute any arguments as needed. */
2851 precompute_arguments (num_actuals
, args
);
2853 /* Now we are about to start emitting insns that can be deleted
2854 if a libcall is deleted. */
2855 if (pass
&& (flags
& ECF_MALLOC
))
2858 if (pass
== 0 && crtl
->stack_protect_guard
)
2859 stack_protect_epilogue ();
2861 adjusted_args_size
= args_size
;
2862 /* Compute the actual size of the argument block required. The variable
2863 and constant sizes must be combined, the size may have to be rounded,
2864 and there may be a minimum required size. When generating a sibcall
2865 pattern, do not round up, since we'll be re-using whatever space our
2867 unadjusted_args_size
2868 = compute_argument_block_size (reg_parm_stack_space
,
2869 &adjusted_args_size
,
2872 : preferred_stack_boundary
));
2874 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
2876 /* The argument block when performing a sibling call is the
2877 incoming argument block. */
2880 argblock
= crtl
->args
.internal_arg_pointer
;
2882 #ifdef STACK_GROWS_DOWNWARD
2883 = plus_constant (Pmode
, argblock
, crtl
->args
.pretend_args_size
);
2885 = plus_constant (Pmode
, argblock
, -crtl
->args
.pretend_args_size
);
2887 stored_args_map
= sbitmap_alloc (args_size
.constant
);
2888 bitmap_clear (stored_args_map
);
2891 /* If we have no actual push instructions, or shouldn't use them,
2892 make space for all args right now. */
2893 else if (adjusted_args_size
.var
!= 0)
2895 if (old_stack_level
== 0)
2897 emit_stack_save (SAVE_BLOCK
, &old_stack_level
);
2898 old_stack_pointer_delta
= stack_pointer_delta
;
2899 old_pending_adj
= pending_stack_adjust
;
2900 pending_stack_adjust
= 0;
2901 /* stack_arg_under_construction says whether a stack arg is
2902 being constructed at the old stack level. Pushing the stack
2903 gets a clean outgoing argument block. */
2904 old_stack_arg_under_construction
= stack_arg_under_construction
;
2905 stack_arg_under_construction
= 0;
2907 argblock
= push_block (ARGS_SIZE_RTX (adjusted_args_size
), 0, 0);
2908 if (flag_stack_usage_info
)
2909 current_function_has_unbounded_dynamic_stack_size
= 1;
2913 /* Note that we must go through the motions of allocating an argument
2914 block even if the size is zero because we may be storing args
2915 in the area reserved for register arguments, which may be part of
2918 int needed
= adjusted_args_size
.constant
;
2920 /* Store the maximum argument space used. It will be pushed by
2921 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2924 if (needed
> crtl
->outgoing_args_size
)
2925 crtl
->outgoing_args_size
= needed
;
2927 if (must_preallocate
)
2929 if (ACCUMULATE_OUTGOING_ARGS
)
2931 /* Since the stack pointer will never be pushed, it is
2932 possible for the evaluation of a parm to clobber
2933 something we have already written to the stack.
2934 Since most function calls on RISC machines do not use
2935 the stack, this is uncommon, but must work correctly.
2937 Therefore, we save any area of the stack that was already
2938 written and that we are using. Here we set up to do this
2939 by making a new stack usage map from the old one. The
2940 actual save will be done by store_one_arg.
2942 Another approach might be to try to reorder the argument
2943 evaluations to avoid this conflicting stack usage. */
2945 /* Since we will be writing into the entire argument area,
2946 the map must be allocated for its entire size, not just
2947 the part that is the responsibility of the caller. */
2948 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
2949 needed
+= reg_parm_stack_space
;
2951 #ifdef ARGS_GROW_DOWNWARD
2952 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
2955 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
2958 free (stack_usage_map_buf
);
2959 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
2960 stack_usage_map
= stack_usage_map_buf
;
2962 if (initial_highest_arg_in_use
)
2963 memcpy (stack_usage_map
, initial_stack_usage_map
,
2964 initial_highest_arg_in_use
);
2966 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
2967 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
2968 (highest_outgoing_arg_in_use
2969 - initial_highest_arg_in_use
));
2972 /* The address of the outgoing argument list must not be
2973 copied to a register here, because argblock would be left
2974 pointing to the wrong place after the call to
2975 allocate_dynamic_stack_space below. */
2977 argblock
= virtual_outgoing_args_rtx
;
2981 if (inhibit_defer_pop
== 0)
2983 /* Try to reuse some or all of the pending_stack_adjust
2984 to get this space. */
2986 = (combine_pending_stack_adjustment_and_call
2987 (unadjusted_args_size
,
2988 &adjusted_args_size
,
2989 preferred_unit_stack_boundary
));
2991 /* combine_pending_stack_adjustment_and_call computes
2992 an adjustment before the arguments are allocated.
2993 Account for them and see whether or not the stack
2994 needs to go up or down. */
2995 needed
= unadjusted_args_size
- needed
;
2999 /* We're releasing stack space. */
3000 /* ??? We can avoid any adjustment at all if we're
3001 already aligned. FIXME. */
3002 pending_stack_adjust
= -needed
;
3003 do_pending_stack_adjust ();
3007 /* We need to allocate space. We'll do that in
3008 push_block below. */
3009 pending_stack_adjust
= 0;
3012 /* Special case this because overhead of `push_block' in
3013 this case is non-trivial. */
3015 argblock
= virtual_outgoing_args_rtx
;
3018 argblock
= push_block (GEN_INT (needed
), 0, 0);
3019 #ifdef ARGS_GROW_DOWNWARD
3020 argblock
= plus_constant (Pmode
, argblock
, needed
);
3024 /* We only really need to call `copy_to_reg' in the case
3025 where push insns are going to be used to pass ARGBLOCK
3026 to a function call in ARGS. In that case, the stack
3027 pointer changes value from the allocation point to the
3028 call point, and hence the value of
3029 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
3030 as well always do it. */
3031 argblock
= copy_to_reg (argblock
);
3036 if (ACCUMULATE_OUTGOING_ARGS
)
3038 /* The save/restore code in store_one_arg handles all
3039 cases except one: a constructor call (including a C
3040 function returning a BLKmode struct) to initialize
3042 if (stack_arg_under_construction
)
3045 = GEN_INT (adjusted_args_size
.constant
3046 + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
3047 : TREE_TYPE (fndecl
))) ? 0
3048 : reg_parm_stack_space
));
3049 if (old_stack_level
== 0)
3051 emit_stack_save (SAVE_BLOCK
, &old_stack_level
);
3052 old_stack_pointer_delta
= stack_pointer_delta
;
3053 old_pending_adj
= pending_stack_adjust
;
3054 pending_stack_adjust
= 0;
3055 /* stack_arg_under_construction says whether a stack
3056 arg is being constructed at the old stack level.
3057 Pushing the stack gets a clean outgoing argument
3059 old_stack_arg_under_construction
3060 = stack_arg_under_construction
;
3061 stack_arg_under_construction
= 0;
3062 /* Make a new map for the new argument list. */
3063 free (stack_usage_map_buf
);
3064 stack_usage_map_buf
= XCNEWVEC (char, highest_outgoing_arg_in_use
);
3065 stack_usage_map
= stack_usage_map_buf
;
3066 highest_outgoing_arg_in_use
= 0;
3068 /* We can pass TRUE as the 4th argument because we just
3069 saved the stack pointer and will restore it right after
3071 allocate_dynamic_stack_space (push_size
, 0,
3072 BIGGEST_ALIGNMENT
, true);
3075 /* If argument evaluation might modify the stack pointer,
3076 copy the address of the argument list to a register. */
3077 for (i
= 0; i
< num_actuals
; i
++)
3078 if (args
[i
].pass_on_stack
)
3080 argblock
= copy_addr_to_reg (argblock
);
3085 compute_argument_addresses (args
, argblock
, num_actuals
);
3087 /* Perform stack alignment before the first push (the last arg). */
3089 && adjusted_args_size
.constant
> reg_parm_stack_space
3090 && adjusted_args_size
.constant
!= unadjusted_args_size
)
3092 /* When the stack adjustment is pending, we get better code
3093 by combining the adjustments. */
3094 if (pending_stack_adjust
3095 && ! inhibit_defer_pop
)
3097 pending_stack_adjust
3098 = (combine_pending_stack_adjustment_and_call
3099 (unadjusted_args_size
,
3100 &adjusted_args_size
,
3101 preferred_unit_stack_boundary
));
3102 do_pending_stack_adjust ();
3104 else if (argblock
== 0)
3105 anti_adjust_stack (GEN_INT (adjusted_args_size
.constant
3106 - unadjusted_args_size
));
3108 /* Now that the stack is properly aligned, pops can't safely
3109 be deferred during the evaluation of the arguments. */
3112 /* Record the maximum pushed stack space size. We need to delay
3113 doing it this far to take into account the optimization done
3114 by combine_pending_stack_adjustment_and_call. */
3115 if (flag_stack_usage_info
3116 && !ACCUMULATE_OUTGOING_ARGS
3118 && adjusted_args_size
.var
== 0)
3120 int pushed
= adjusted_args_size
.constant
+ pending_stack_adjust
;
3121 if (pushed
> current_function_pushed_stack_size
)
3122 current_function_pushed_stack_size
= pushed
;
3125 funexp
= rtx_for_function_call (fndecl
, addr
);
3127 /* Precompute all register parameters. It isn't safe to compute anything
3128 once we have started filling any specific hard regs. */
3129 precompute_register_parameters (num_actuals
, args
, ®_parm_seen
);
3131 if (CALL_EXPR_STATIC_CHAIN (exp
))
3132 static_chain_value
= expand_normal (CALL_EXPR_STATIC_CHAIN (exp
));
3134 static_chain_value
= 0;
3136 #ifdef REG_PARM_STACK_SPACE
3137 /* Save the fixed argument area if it's part of the caller's frame and
3138 is clobbered by argument setup for this call. */
3139 if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
3140 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
3141 &low_to_save
, &high_to_save
);
3144 /* Now store (and compute if necessary) all non-register parms.
3145 These come before register parms, since they can require block-moves,
3146 which could clobber the registers used for register parms.
3147 Parms which have partial registers are not stored here,
3148 but we do preallocate space here if they want that. */
3150 for (i
= 0; i
< num_actuals
; i
++)
3152 /* Delay bounds until all other args are stored. */
3153 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
3155 else if (args
[i
].reg
== 0 || args
[i
].pass_on_stack
)
3157 rtx_insn
*before_arg
= get_last_insn ();
3159 /* We don't allow passing huge (> 2^30 B) arguments
3160 by value. It would cause an overflow later on. */
3161 if (adjusted_args_size
.constant
3162 >= (1 << (HOST_BITS_PER_INT
- 2)))
3164 sorry ("passing too large argument on stack");
3168 if (store_one_arg (&args
[i
], argblock
, flags
,
3169 adjusted_args_size
.var
!= 0,
3170 reg_parm_stack_space
)
3172 && check_sibcall_argument_overlap (before_arg
,
3174 sibcall_failure
= 1;
3179 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)),
3180 gen_rtx_USE (VOIDmode
, args
[i
].stack
),
3184 /* If we have a parm that is passed in registers but not in memory
3185 and whose alignment does not permit a direct copy into registers,
3186 make a group of pseudos that correspond to each register that we
3188 if (STRICT_ALIGNMENT
)
3189 store_unaligned_arguments_into_pseudos (args
, num_actuals
);
3191 /* Now store any partially-in-registers parm.
3192 This is the last place a block-move can happen. */
3194 for (i
= 0; i
< num_actuals
; i
++)
3195 if (args
[i
].partial
!= 0 && ! args
[i
].pass_on_stack
)
3197 rtx_insn
*before_arg
= get_last_insn ();
3199 if (store_one_arg (&args
[i
], argblock
, flags
,
3200 adjusted_args_size
.var
!= 0,
3201 reg_parm_stack_space
)
3203 && check_sibcall_argument_overlap (before_arg
,
3205 sibcall_failure
= 1;
3208 bool any_regs
= false;
3209 for (i
= 0; i
< num_actuals
; i
++)
3210 if (args
[i
].reg
!= NULL_RTX
)
3213 targetm
.calls
.call_args (args
[i
].reg
, funtype
);
3216 targetm
.calls
.call_args (pc_rtx
, funtype
);
3218 /* Figure out the register where the value, if any, will come back. */
3221 if (TYPE_MODE (rettype
) != VOIDmode
3222 && ! structure_value_addr
)
3224 if (pcc_struct_value
)
3226 valreg
= hard_function_value (build_pointer_type (rettype
),
3227 fndecl
, NULL
, (pass
== 0));
3228 if (CALL_WITH_BOUNDS_P (exp
))
3229 valbnd
= targetm
.calls
.
3230 chkp_function_value_bounds (build_pointer_type (rettype
),
3231 fndecl
, (pass
== 0));
3235 valreg
= hard_function_value (rettype
, fndecl
, fntype
,
3237 if (CALL_WITH_BOUNDS_P (exp
))
3238 valbnd
= targetm
.calls
.chkp_function_value_bounds (rettype
,
3243 /* If VALREG is a PARALLEL whose first member has a zero
3244 offset, use that. This is for targets such as m68k that
3245 return the same value in multiple places. */
3246 if (GET_CODE (valreg
) == PARALLEL
)
3248 rtx elem
= XVECEXP (valreg
, 0, 0);
3249 rtx where
= XEXP (elem
, 0);
3250 rtx offset
= XEXP (elem
, 1);
3251 if (offset
== const0_rtx
3252 && GET_MODE (where
) == GET_MODE (valreg
))
3257 /* Store all bounds not passed in registers. */
3258 for (i
= 0; i
< num_actuals
; i
++)
3260 if (POINTER_BOUNDS_P (args
[i
].tree_value
)
3262 store_bounds (&args
[i
],
3263 args
[i
].pointer_arg
== -1
3265 : &args
[args
[i
].pointer_arg
]);
3268 /* If register arguments require space on the stack and stack space
3269 was not preallocated, allocate stack space here for arguments
3270 passed in registers. */
3271 if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
)))
3272 && !ACCUMULATE_OUTGOING_ARGS
3273 && must_preallocate
== 0 && reg_parm_stack_space
> 0)
3274 anti_adjust_stack (GEN_INT (reg_parm_stack_space
));
3276 /* Pass the function the address in which to return a
3278 if (pass
!= 0 && structure_value_addr
&& ! structure_value_addr_parm
)
3280 structure_value_addr
3281 = convert_memory_address (Pmode
, structure_value_addr
);
3282 emit_move_insn (struct_value
,
3284 force_operand (structure_value_addr
,
3287 if (REG_P (struct_value
))
3288 use_reg (&call_fusage
, struct_value
);
3291 after_args
= get_last_insn ();
3292 funexp
= prepare_call_address (fndecl
? fndecl
: fntype
, funexp
,
3293 static_chain_value
, &call_fusage
,
3294 reg_parm_seen
, pass
== 0);
3296 load_register_parameters (args
, num_actuals
, &call_fusage
, flags
,
3297 pass
== 0, &sibcall_failure
);
3299 /* Save a pointer to the last insn before the call, so that we can
3300 later safely search backwards to find the CALL_INSN. */
3301 before_call
= get_last_insn ();
3303 /* Set up next argument register. For sibling calls on machines
3304 with register windows this should be the incoming register. */
3306 next_arg_reg
= targetm
.calls
.function_incoming_arg (args_so_far
,
3311 next_arg_reg
= targetm
.calls
.function_arg (args_so_far
,
3312 VOIDmode
, void_type_node
,
3315 if (pass
== 1 && (return_flags
& ERF_RETURNS_ARG
))
3317 int arg_nr
= return_flags
& ERF_RETURN_ARG_MASK
;
3318 arg_nr
= num_actuals
- arg_nr
- 1;
3320 && arg_nr
< num_actuals
3324 && GET_MODE (args
[arg_nr
].reg
) == GET_MODE (valreg
))
3326 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args
[arg_nr
].tree_value
)),
3327 gen_rtx_SET (VOIDmode
, valreg
, args
[arg_nr
].reg
),
3330 /* All arguments and registers used for the call must be set up by
3333 /* Stack must be properly aligned now. */
3335 || !(stack_pointer_delta
% preferred_unit_stack_boundary
));
3337 /* Generate the actual call instruction. */
3338 emit_call_1 (funexp
, exp
, fndecl
, funtype
, unadjusted_args_size
,
3339 adjusted_args_size
.constant
, struct_value_size
,
3340 next_arg_reg
, valreg
, old_inhibit_defer_pop
, call_fusage
,
3341 flags
, args_so_far
);
3345 rtx_call_insn
*last
;
3346 rtx datum
= NULL_RTX
;
3347 if (fndecl
!= NULL_TREE
)
3349 datum
= XEXP (DECL_RTL (fndecl
), 0);
3350 gcc_assert (datum
!= NULL_RTX
3351 && GET_CODE (datum
) == SYMBOL_REF
);
3353 last
= last_call_insn ();
3354 add_reg_note (last
, REG_CALL_DECL
, datum
);
3357 /* If the call setup or the call itself overlaps with anything
3358 of the argument setup we probably clobbered our call address.
3359 In that case we can't do sibcalls. */
3361 && check_sibcall_argument_overlap (after_args
, 0, 0))
3362 sibcall_failure
= 1;
3364 /* If a non-BLKmode value is returned at the most significant end
3365 of a register, shift the register right by the appropriate amount
3366 and update VALREG accordingly. BLKmode values are handled by the
3367 group load/store machinery below. */
3368 if (!structure_value_addr
3369 && !pcc_struct_value
3370 && TYPE_MODE (rettype
) != VOIDmode
3371 && TYPE_MODE (rettype
) != BLKmode
3373 && targetm
.calls
.return_in_msb (rettype
))
3375 if (shift_return_value (TYPE_MODE (rettype
), false, valreg
))
3376 sibcall_failure
= 1;
3377 valreg
= gen_rtx_REG (TYPE_MODE (rettype
), REGNO (valreg
));
3380 if (pass
&& (flags
& ECF_MALLOC
))
3382 rtx temp
= gen_reg_rtx (GET_MODE (valreg
));
3383 rtx_insn
*last
, *insns
;
3385 /* The return value from a malloc-like function is a pointer. */
3386 if (TREE_CODE (rettype
) == POINTER_TYPE
)
3387 mark_reg_pointer (temp
, MALLOC_ABI_ALIGNMENT
);
3389 emit_move_insn (temp
, valreg
);
3391 /* The return value from a malloc-like function can not alias
3393 last
= get_last_insn ();
3394 add_reg_note (last
, REG_NOALIAS
, temp
);
3396 /* Write out the sequence. */
3397 insns
= get_insns ();
3403 /* For calls to `setjmp', etc., inform
3404 function.c:setjmp_warnings that it should complain if
3405 nonvolatile values are live. For functions that cannot
3406 return, inform flow that control does not fall through. */
3408 if ((flags
& ECF_NORETURN
) || pass
== 0)
3410 /* The barrier must be emitted
3411 immediately after the CALL_INSN. Some ports emit more
3412 than just a CALL_INSN above, so we must search for it here. */
3414 rtx_insn
*last
= get_last_insn ();
3415 while (!CALL_P (last
))
3417 last
= PREV_INSN (last
);
3418 /* There was no CALL_INSN? */
3419 gcc_assert (last
!= before_call
);
3422 emit_barrier_after (last
);
3424 /* Stack adjustments after a noreturn call are dead code.
3425 However when NO_DEFER_POP is in effect, we must preserve
3426 stack_pointer_delta. */
3427 if (inhibit_defer_pop
== 0)
3429 stack_pointer_delta
= old_stack_allocated
;
3430 pending_stack_adjust
= 0;
3434 /* If value type not void, return an rtx for the value. */
3436 if (TYPE_MODE (rettype
) == VOIDmode
3438 target
= const0_rtx
;
3439 else if (structure_value_addr
)
3441 if (target
== 0 || !MEM_P (target
))
3444 = gen_rtx_MEM (TYPE_MODE (rettype
),
3445 memory_address (TYPE_MODE (rettype
),
3446 structure_value_addr
));
3447 set_mem_attributes (target
, rettype
, 1);
3450 else if (pcc_struct_value
)
3452 /* This is the special C++ case where we need to
3453 know what the true target was. We take care to
3454 never use this value more than once in one expression. */
3455 target
= gen_rtx_MEM (TYPE_MODE (rettype
),
3456 copy_to_reg (valreg
));
3457 set_mem_attributes (target
, rettype
, 1);
3459 /* Handle calls that return values in multiple non-contiguous locations.
3460 The Irix 6 ABI has examples of this. */
3461 else if (GET_CODE (valreg
) == PARALLEL
)
3464 target
= emit_group_move_into_temps (valreg
);
3465 else if (rtx_equal_p (target
, valreg
))
3467 else if (GET_CODE (target
) == PARALLEL
)
3468 /* Handle the result of a emit_group_move_into_temps
3469 call in the previous pass. */
3470 emit_group_move (target
, valreg
);
3472 emit_group_store (target
, valreg
, rettype
,
3473 int_size_in_bytes (rettype
));
3476 && GET_MODE (target
) == TYPE_MODE (rettype
)
3477 && GET_MODE (target
) == GET_MODE (valreg
))
3479 bool may_overlap
= false;
3481 /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
3482 reg to a plain register. */
3483 if (!REG_P (target
) || HARD_REGISTER_P (target
))
3484 valreg
= avoid_likely_spilled_reg (valreg
);
3486 /* If TARGET is a MEM in the argument area, and we have
3487 saved part of the argument area, then we can't store
3488 directly into TARGET as it may get overwritten when we
3489 restore the argument save area below. Don't work too
3490 hard though and simply force TARGET to a register if it
3491 is a MEM; the optimizer is quite likely to sort it out. */
3492 if (ACCUMULATE_OUTGOING_ARGS
&& pass
&& MEM_P (target
))
3493 for (i
= 0; i
< num_actuals
; i
++)
3494 if (args
[i
].save_area
)
3501 target
= copy_to_reg (valreg
);
3504 /* TARGET and VALREG cannot be equal at this point
3505 because the latter would not have
3506 REG_FUNCTION_VALUE_P true, while the former would if
3507 it were referring to the same register.
3509 If they refer to the same register, this move will be
3510 a no-op, except when function inlining is being
3512 emit_move_insn (target
, valreg
);
3514 /* If we are setting a MEM, this code must be executed.
3515 Since it is emitted after the call insn, sibcall
3516 optimization cannot be performed in that case. */
3518 sibcall_failure
= 1;
3522 target
= copy_to_reg (avoid_likely_spilled_reg (valreg
));
3524 /* If we promoted this return value, make the proper SUBREG.
3525 TARGET might be const0_rtx here, so be careful. */
3527 && TYPE_MODE (rettype
) != BLKmode
3528 && GET_MODE (target
) != TYPE_MODE (rettype
))
3530 tree type
= rettype
;
3531 int unsignedp
= TYPE_UNSIGNED (type
);
3535 /* Ensure we promote as expected, and get the new unsignedness. */
3536 pmode
= promote_function_mode (type
, TYPE_MODE (type
), &unsignedp
,
3538 gcc_assert (GET_MODE (target
) == pmode
);
3540 if ((WORDS_BIG_ENDIAN
|| BYTES_BIG_ENDIAN
)
3541 && (GET_MODE_SIZE (GET_MODE (target
))
3542 > GET_MODE_SIZE (TYPE_MODE (type
))))
3544 offset
= GET_MODE_SIZE (GET_MODE (target
))
3545 - GET_MODE_SIZE (TYPE_MODE (type
));
3546 if (! BYTES_BIG_ENDIAN
)
3547 offset
= (offset
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3548 else if (! WORDS_BIG_ENDIAN
)
3549 offset
%= UNITS_PER_WORD
;
3552 target
= gen_rtx_SUBREG (TYPE_MODE (type
), target
, offset
);
3553 SUBREG_PROMOTED_VAR_P (target
) = 1;
3554 SUBREG_PROMOTED_SET (target
, unsignedp
);
3557 /* If size of args is variable or this was a constructor call for a stack
3558 argument, restore saved stack-pointer value. */
3560 if (old_stack_level
)
3562 rtx_insn
*prev
= get_last_insn ();
3564 emit_stack_restore (SAVE_BLOCK
, old_stack_level
);
3565 stack_pointer_delta
= old_stack_pointer_delta
;
3567 fixup_args_size_notes (prev
, get_last_insn (), stack_pointer_delta
);
3569 pending_stack_adjust
= old_pending_adj
;
3570 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
3571 stack_arg_under_construction
= old_stack_arg_under_construction
;
3572 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3573 stack_usage_map
= initial_stack_usage_map
;
3574 sibcall_failure
= 1;
3576 else if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
3578 #ifdef REG_PARM_STACK_SPACE
3580 restore_fixed_argument_area (save_area
, argblock
,
3581 high_to_save
, low_to_save
);
3584 /* If we saved any argument areas, restore them. */
3585 for (i
= 0; i
< num_actuals
; i
++)
3586 if (args
[i
].save_area
)
3588 machine_mode save_mode
= GET_MODE (args
[i
].save_area
);
3590 = gen_rtx_MEM (save_mode
,
3591 memory_address (save_mode
,
3592 XEXP (args
[i
].stack_slot
, 0)));
3594 if (save_mode
!= BLKmode
)
3595 emit_move_insn (stack_area
, args
[i
].save_area
);
3597 emit_block_move (stack_area
, args
[i
].save_area
,
3598 GEN_INT (args
[i
].locate
.size
.constant
),
3599 BLOCK_OP_CALL_PARM
);
3602 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3603 stack_usage_map
= initial_stack_usage_map
;
3606 /* If this was alloca, record the new stack level for nonlocal gotos.
3607 Check for the handler slots since we might not have a save area
3608 for non-local gotos. */
3610 if ((flags
& ECF_MAY_BE_ALLOCA
) && cfun
->nonlocal_goto_save_area
!= 0)
3611 update_nonlocal_goto_save_area ();
3613 /* Free up storage we no longer need. */
3614 for (i
= 0; i
< num_actuals
; ++i
)
3615 free (args
[i
].aligned_regs
);
3617 targetm
.calls
.end_call_args ();
3619 insns
= get_insns ();
3624 tail_call_insns
= insns
;
3626 /* Restore the pending stack adjustment now that we have
3627 finished generating the sibling call sequence. */
3629 restore_pending_stack_adjust (&save
);
3631 /* Prepare arg structure for next iteration. */
3632 for (i
= 0; i
< num_actuals
; i
++)
3635 args
[i
].aligned_regs
= 0;
3639 sbitmap_free (stored_args_map
);
3640 internal_arg_pointer_exp_state
.scan_start
= NULL
;
3641 internal_arg_pointer_exp_state
.cache
.release ();
3645 normal_call_insns
= insns
;
3647 /* Verify that we've deallocated all the stack we used. */
3648 gcc_assert ((flags
& ECF_NORETURN
)
3649 || (old_stack_allocated
3650 == stack_pointer_delta
- pending_stack_adjust
));
3653 /* If something prevents making this a sibling call,
3654 zero out the sequence. */
3655 if (sibcall_failure
)
3656 tail_call_insns
= NULL
;
3661 /* If tail call production succeeded, we need to remove REG_EQUIV notes on
3662 arguments too, as argument area is now clobbered by the call. */
3663 if (tail_call_insns
)
3665 emit_insn (tail_call_insns
);
3666 crtl
->tail_call_emit
= true;
3669 emit_insn (normal_call_insns
);
3671 currently_expanding_call
--;
3673 free (stack_usage_map_buf
);
3675 /* Join result with returned bounds so caller may use them if needed. */
3676 target
= chkp_join_splitted_slot (target
, valbnd
);
3681 /* A sibling call sequence invalidates any REG_EQUIV notes made for
3682 this function's incoming arguments.
3684 At the start of RTL generation we know the only REG_EQUIV notes
3685 in the rtl chain are those for incoming arguments, so we can look
3686 for REG_EQUIV notes between the start of the function and the
3687 NOTE_INSN_FUNCTION_BEG.
3689 This is (slight) overkill. We could keep track of the highest
3690 argument we clobber and be more selective in removing notes, but it
3691 does not seem to be worth the effort. */
3694 fixup_tail_calls (void)
3698 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3702 /* There are never REG_EQUIV notes for the incoming arguments
3703 after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
3705 && NOTE_KIND (insn
) == NOTE_INSN_FUNCTION_BEG
)
3708 note
= find_reg_note (insn
, REG_EQUIV
, 0);
3710 remove_note (insn
, note
);
3711 note
= find_reg_note (insn
, REG_EQUIV
, 0);
3716 /* Traverse a list of TYPES and expand all complex types into their
3719 split_complex_types (tree types
)
3723 /* Before allocating memory, check for the common case of no complex. */
3724 for (p
= types
; p
; p
= TREE_CHAIN (p
))
3726 tree type
= TREE_VALUE (p
);
3727 if (TREE_CODE (type
) == COMPLEX_TYPE
3728 && targetm
.calls
.split_complex_arg (type
))
3734 types
= copy_list (types
);
3736 for (p
= types
; p
; p
= TREE_CHAIN (p
))
3738 tree complex_type
= TREE_VALUE (p
);
3740 if (TREE_CODE (complex_type
) == COMPLEX_TYPE
3741 && targetm
.calls
.split_complex_arg (complex_type
))
3745 /* Rewrite complex type with component type. */
3746 TREE_VALUE (p
) = TREE_TYPE (complex_type
);
3747 next
= TREE_CHAIN (p
);
3749 /* Add another component type for the imaginary part. */
3750 imag
= build_tree_list (NULL_TREE
, TREE_VALUE (p
));
3751 TREE_CHAIN (p
) = imag
;
3752 TREE_CHAIN (imag
) = next
;
3754 /* Skip the newly created node. */
3762 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3763 The RETVAL parameter specifies whether return value needs to be saved, other
3764 parameters are documented in the emit_library_call function below. */
3767 emit_library_call_value_1 (int retval
, rtx orgfun
, rtx value
,
3768 enum libcall_type fn_type
,
3769 machine_mode outmode
, int nargs
, va_list p
)
3771 /* Total size in bytes of all the stack-parms scanned so far. */
3772 struct args_size args_size
;
3773 /* Size of arguments before any adjustments (such as rounding). */
3774 struct args_size original_args_size
;
3777 /* Todo, choose the correct decl type of orgfun. Sadly this information
3778 isn't present here, so we default to native calling abi here. */
3779 tree fndecl ATTRIBUTE_UNUSED
= NULL_TREE
; /* library calls default to host calling abi ? */
3780 tree fntype ATTRIBUTE_UNUSED
= NULL_TREE
; /* library calls default to host calling abi ? */
3783 CUMULATIVE_ARGS args_so_far_v
;
3784 cumulative_args_t args_so_far
;
3791 struct locate_and_pad_arg_data locate
;
3795 int old_inhibit_defer_pop
= inhibit_defer_pop
;
3796 rtx call_fusage
= 0;
3799 int pcc_struct_value
= 0;
3800 int struct_value_size
= 0;
3802 int reg_parm_stack_space
= 0;
3804 rtx_insn
*before_call
;
3805 tree tfom
; /* type_for_mode (outmode, 0) */
3807 #ifdef REG_PARM_STACK_SPACE
3808 /* Define the boundary of the register parm stack space that needs to be
3810 int low_to_save
= 0, high_to_save
= 0;
3811 rtx save_area
= 0; /* Place that it is saved. */
3814 /* Size of the stack reserved for parameter registers. */
3815 int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
3816 char *initial_stack_usage_map
= stack_usage_map
;
3817 char *stack_usage_map_buf
= NULL
;
3819 rtx struct_value
= targetm
.calls
.struct_value_rtx (0, 0);
3821 #ifdef REG_PARM_STACK_SPACE
3822 reg_parm_stack_space
= REG_PARM_STACK_SPACE ((tree
) 0);
3825 /* By default, library functions can not throw. */
3826 flags
= ECF_NOTHROW
;
3839 flags
|= ECF_NORETURN
;
3842 flags
= ECF_NORETURN
;
3844 case LCT_RETURNS_TWICE
:
3845 flags
= ECF_RETURNS_TWICE
;
3850 /* Ensure current function's preferred stack boundary is at least
3852 if (crtl
->preferred_stack_boundary
< PREFERRED_STACK_BOUNDARY
)
3853 crtl
->preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
3855 /* If this kind of value comes back in memory,
3856 decide where in memory it should come back. */
3857 if (outmode
!= VOIDmode
)
3859 tfom
= lang_hooks
.types
.type_for_mode (outmode
, 0);
3860 if (aggregate_value_p (tfom
, 0))
3862 #ifdef PCC_STATIC_STRUCT_RETURN
3864 = hard_function_value (build_pointer_type (tfom
), 0, 0, 0);
3865 mem_value
= gen_rtx_MEM (outmode
, pointer_reg
);
3866 pcc_struct_value
= 1;
3868 value
= gen_reg_rtx (outmode
);
3869 #else /* not PCC_STATIC_STRUCT_RETURN */
3870 struct_value_size
= GET_MODE_SIZE (outmode
);
3871 if (value
!= 0 && MEM_P (value
))
3874 mem_value
= assign_temp (tfom
, 1, 1);
3876 /* This call returns a big structure. */
3877 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
3881 tfom
= void_type_node
;
3883 /* ??? Unfinished: must pass the memory address as an argument. */
3885 /* Copy all the libcall-arguments out of the varargs data
3886 and into a vector ARGVEC.
3888 Compute how to pass each argument. We only support a very small subset
3889 of the full argument passing conventions to limit complexity here since
3890 library functions shouldn't have many args. */
3892 argvec
= XALLOCAVEC (struct arg
, nargs
+ 1);
3893 memset (argvec
, 0, (nargs
+ 1) * sizeof (struct arg
));
3895 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3896 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v
, outmode
, fun
);
3898 INIT_CUMULATIVE_ARGS (args_so_far_v
, NULL_TREE
, fun
, 0, nargs
);
3900 args_so_far
= pack_cumulative_args (&args_so_far_v
);
3902 args_size
.constant
= 0;
3909 /* If there's a structure value address to be passed,
3910 either pass it in the special place, or pass it as an extra argument. */
3911 if (mem_value
&& struct_value
== 0 && ! pcc_struct_value
)
3913 rtx addr
= XEXP (mem_value
, 0);
3917 /* Make sure it is a reasonable operand for a move or push insn. */
3918 if (!REG_P (addr
) && !MEM_P (addr
)
3919 && !(CONSTANT_P (addr
)
3920 && targetm
.legitimate_constant_p (Pmode
, addr
)))
3921 addr
= force_operand (addr
, NULL_RTX
);
3923 argvec
[count
].value
= addr
;
3924 argvec
[count
].mode
= Pmode
;
3925 argvec
[count
].partial
= 0;
3927 argvec
[count
].reg
= targetm
.calls
.function_arg (args_so_far
,
3928 Pmode
, NULL_TREE
, true);
3929 gcc_assert (targetm
.calls
.arg_partial_bytes (args_so_far
, Pmode
,
3930 NULL_TREE
, 1) == 0);
3932 locate_and_pad_parm (Pmode
, NULL_TREE
,
3933 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3936 argvec
[count
].reg
!= 0,
3938 reg_parm_stack_space
, 0,
3939 NULL_TREE
, &args_size
, &argvec
[count
].locate
);
3941 if (argvec
[count
].reg
== 0 || argvec
[count
].partial
!= 0
3942 || reg_parm_stack_space
> 0)
3943 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
3945 targetm
.calls
.function_arg_advance (args_so_far
, Pmode
, (tree
) 0, true);
3950 for (; count
< nargs
; count
++)
3952 rtx val
= va_arg (p
, rtx
);
3953 machine_mode mode
= (machine_mode
) va_arg (p
, int);
3956 /* We cannot convert the arg value to the mode the library wants here;
3957 must do it earlier where we know the signedness of the arg. */
3958 gcc_assert (mode
!= BLKmode
3959 && (GET_MODE (val
) == mode
|| GET_MODE (val
) == VOIDmode
));
3961 /* Make sure it is a reasonable operand for a move or push insn. */
3962 if (!REG_P (val
) && !MEM_P (val
)
3963 && !(CONSTANT_P (val
) && targetm
.legitimate_constant_p (mode
, val
)))
3964 val
= force_operand (val
, NULL_RTX
);
3966 if (pass_by_reference (&args_so_far_v
, mode
, NULL_TREE
, 1))
3970 = !reference_callee_copied (&args_so_far_v
, mode
, NULL_TREE
, 1);
3972 /* If this was a CONST function, it is now PURE since it now
3974 if (flags
& ECF_CONST
)
3976 flags
&= ~ECF_CONST
;
3980 if (MEM_P (val
) && !must_copy
)
3982 tree val_expr
= MEM_EXPR (val
);
3984 mark_addressable (val_expr
);
3989 slot
= assign_temp (lang_hooks
.types
.type_for_mode (mode
, 0),
3991 emit_move_insn (slot
, val
);
3994 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
3995 gen_rtx_USE (VOIDmode
, slot
),
3998 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
3999 gen_rtx_CLOBBER (VOIDmode
,
4004 val
= force_operand (XEXP (slot
, 0), NULL_RTX
);
4007 mode
= promote_function_mode (NULL_TREE
, mode
, &unsigned_p
, NULL_TREE
, 0);
4008 argvec
[count
].mode
= mode
;
4009 argvec
[count
].value
= convert_modes (mode
, GET_MODE (val
), val
, unsigned_p
);
4010 argvec
[count
].reg
= targetm
.calls
.function_arg (args_so_far
, mode
,
4013 argvec
[count
].partial
4014 = targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL_TREE
, 1);
4016 if (argvec
[count
].reg
== 0
4017 || argvec
[count
].partial
!= 0
4018 || reg_parm_stack_space
> 0)
4020 locate_and_pad_parm (mode
, NULL_TREE
,
4021 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4024 argvec
[count
].reg
!= 0,
4026 reg_parm_stack_space
, argvec
[count
].partial
,
4027 NULL_TREE
, &args_size
, &argvec
[count
].locate
);
4028 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
4029 gcc_assert (!argvec
[count
].locate
.size
.var
);
4031 #ifdef BLOCK_REG_PADDING
4033 /* The argument is passed entirely in registers. See at which
4034 end it should be padded. */
4035 argvec
[count
].locate
.where_pad
=
4036 BLOCK_REG_PADDING (mode
, NULL_TREE
,
4037 GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
);
4040 targetm
.calls
.function_arg_advance (args_so_far
, mode
, (tree
) 0, true);
4043 /* If this machine requires an external definition for library
4044 functions, write one out. */
4045 assemble_external_libcall (fun
);
4047 original_args_size
= args_size
;
4048 args_size
.constant
= (((args_size
.constant
4049 + stack_pointer_delta
4053 - stack_pointer_delta
);
4055 args_size
.constant
= MAX (args_size
.constant
,
4056 reg_parm_stack_space
);
4058 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
4059 args_size
.constant
-= reg_parm_stack_space
;
4061 if (args_size
.constant
> crtl
->outgoing_args_size
)
4062 crtl
->outgoing_args_size
= args_size
.constant
;
4064 if (flag_stack_usage_info
&& !ACCUMULATE_OUTGOING_ARGS
)
4066 int pushed
= args_size
.constant
+ pending_stack_adjust
;
4067 if (pushed
> current_function_pushed_stack_size
)
4068 current_function_pushed_stack_size
= pushed
;
4071 if (ACCUMULATE_OUTGOING_ARGS
)
4073 /* Since the stack pointer will never be pushed, it is possible for
4074 the evaluation of a parm to clobber something we have already
4075 written to the stack. Since most function calls on RISC machines
4076 do not use the stack, this is uncommon, but must work correctly.
4078 Therefore, we save any area of the stack that was already written
4079 and that we are using. Here we set up to do this by making a new
4080 stack usage map from the old one.
4082 Another approach might be to try to reorder the argument
4083 evaluations to avoid this conflicting stack usage. */
4085 needed
= args_size
.constant
;
4087 /* Since we will be writing into the entire argument area, the
4088 map must be allocated for its entire size, not just the part that
4089 is the responsibility of the caller. */
4090 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
4091 needed
+= reg_parm_stack_space
;
4093 #ifdef ARGS_GROW_DOWNWARD
4094 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
4097 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
4100 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
4101 stack_usage_map
= stack_usage_map_buf
;
4103 if (initial_highest_arg_in_use
)
4104 memcpy (stack_usage_map
, initial_stack_usage_map
,
4105 initial_highest_arg_in_use
);
4107 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
4108 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
4109 highest_outgoing_arg_in_use
- initial_highest_arg_in_use
);
4112 /* We must be careful to use virtual regs before they're instantiated,
4113 and real regs afterwards. Loop optimization, for example, can create
4114 new libcalls after we've instantiated the virtual regs, and if we
4115 use virtuals anyway, they won't match the rtl patterns. */
4117 if (virtuals_instantiated
)
4118 argblock
= plus_constant (Pmode
, stack_pointer_rtx
,
4119 STACK_POINTER_OFFSET
);
4121 argblock
= virtual_outgoing_args_rtx
;
4126 argblock
= push_block (GEN_INT (args_size
.constant
), 0, 0);
4129 /* We push args individually in reverse order, perform stack alignment
4130 before the first push (the last arg). */
4132 anti_adjust_stack (GEN_INT (args_size
.constant
4133 - original_args_size
.constant
));
4137 #ifdef REG_PARM_STACK_SPACE
4138 if (ACCUMULATE_OUTGOING_ARGS
)
4140 /* The argument list is the property of the called routine and it
4141 may clobber it. If the fixed area has been used for previous
4142 parameters, we must save and restore it. */
4143 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
4144 &low_to_save
, &high_to_save
);
4148 /* When expanding a normal call, args are stored in push order,
4149 which is the reverse of what we have here. */
4150 bool any_regs
= false;
4151 for (int i
= nargs
; i
-- > 0; )
4152 if (argvec
[i
].reg
!= NULL_RTX
)
4154 targetm
.calls
.call_args (argvec
[i
].reg
, NULL_TREE
);
4158 targetm
.calls
.call_args (pc_rtx
, NULL_TREE
);
4160 /* Push the args that need to be pushed. */
4162 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4163 are to be pushed. */
4164 for (count
= 0; count
< nargs
; count
++, argnum
--)
4166 machine_mode mode
= argvec
[argnum
].mode
;
4167 rtx val
= argvec
[argnum
].value
;
4168 rtx reg
= argvec
[argnum
].reg
;
4169 int partial
= argvec
[argnum
].partial
;
4170 unsigned int parm_align
= argvec
[argnum
].locate
.boundary
;
4171 int lower_bound
= 0, upper_bound
= 0, i
;
4173 if (! (reg
!= 0 && partial
== 0))
4177 if (ACCUMULATE_OUTGOING_ARGS
)
4179 /* If this is being stored into a pre-allocated, fixed-size,
4180 stack area, save any previous data at that location. */
4182 #ifdef ARGS_GROW_DOWNWARD
4183 /* stack_slot is negative, but we want to index stack_usage_map
4184 with positive values. */
4185 upper_bound
= -argvec
[argnum
].locate
.slot_offset
.constant
+ 1;
4186 lower_bound
= upper_bound
- argvec
[argnum
].locate
.size
.constant
;
4188 lower_bound
= argvec
[argnum
].locate
.slot_offset
.constant
;
4189 upper_bound
= lower_bound
+ argvec
[argnum
].locate
.size
.constant
;
4193 /* Don't worry about things in the fixed argument area;
4194 it has already been saved. */
4195 if (i
< reg_parm_stack_space
)
4196 i
= reg_parm_stack_space
;
4197 while (i
< upper_bound
&& stack_usage_map
[i
] == 0)
4200 if (i
< upper_bound
)
4202 /* We need to make a save area. */
4204 = argvec
[argnum
].locate
.size
.constant
* BITS_PER_UNIT
;
4205 machine_mode save_mode
4206 = mode_for_size (size
, MODE_INT
, 1);
4208 = plus_constant (Pmode
, argblock
,
4209 argvec
[argnum
].locate
.offset
.constant
);
4211 = gen_rtx_MEM (save_mode
, memory_address (save_mode
, adr
));
4213 if (save_mode
== BLKmode
)
4215 argvec
[argnum
].save_area
4216 = assign_stack_temp (BLKmode
,
4217 argvec
[argnum
].locate
.size
.constant
4220 emit_block_move (validize_mem
4221 (copy_rtx (argvec
[argnum
].save_area
)),
4223 GEN_INT (argvec
[argnum
].locate
.size
.constant
),
4224 BLOCK_OP_CALL_PARM
);
4228 argvec
[argnum
].save_area
= gen_reg_rtx (save_mode
);
4230 emit_move_insn (argvec
[argnum
].save_area
, stack_area
);
4235 emit_push_insn (val
, mode
, NULL_TREE
, NULL_RTX
, parm_align
,
4236 partial
, reg
, 0, argblock
,
4237 GEN_INT (argvec
[argnum
].locate
.offset
.constant
),
4238 reg_parm_stack_space
,
4239 ARGS_SIZE_RTX (argvec
[argnum
].locate
.alignment_pad
));
4241 /* Now mark the segment we just used. */
4242 if (ACCUMULATE_OUTGOING_ARGS
)
4243 for (i
= lower_bound
; i
< upper_bound
; i
++)
4244 stack_usage_map
[i
] = 1;
4248 /* Indicate argument access so that alias.c knows that these
4251 use
= plus_constant (Pmode
, argblock
,
4252 argvec
[argnum
].locate
.offset
.constant
);
4254 /* When arguments are pushed, trying to tell alias.c where
4255 exactly this argument is won't work, because the
4256 auto-increment causes confusion. So we merely indicate
4257 that we access something with a known mode somewhere on
4259 use
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
4260 gen_rtx_SCRATCH (Pmode
));
4261 use
= gen_rtx_MEM (argvec
[argnum
].mode
, use
);
4262 use
= gen_rtx_USE (VOIDmode
, use
);
4263 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
, use
, call_fusage
);
4269 fun
= prepare_call_address (NULL
, fun
, NULL
, &call_fusage
, 0, 0);
4271 /* Now load any reg parms into their regs. */
4273 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4274 are to be pushed. */
4275 for (count
= 0; count
< nargs
; count
++, argnum
--)
4277 machine_mode mode
= argvec
[argnum
].mode
;
4278 rtx val
= argvec
[argnum
].value
;
4279 rtx reg
= argvec
[argnum
].reg
;
4280 int partial
= argvec
[argnum
].partial
;
4281 #ifdef BLOCK_REG_PADDING
4285 /* Handle calls that pass values in multiple non-contiguous
4286 locations. The PA64 has examples of this for library calls. */
4287 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
4288 emit_group_load (reg
, val
, NULL_TREE
, GET_MODE_SIZE (mode
));
4289 else if (reg
!= 0 && partial
== 0)
4291 emit_move_insn (reg
, val
);
4292 #ifdef BLOCK_REG_PADDING
4293 size
= GET_MODE_SIZE (argvec
[argnum
].mode
);
4295 /* Copied from load_register_parameters. */
4297 /* Handle case where we have a value that needs shifting
4298 up to the msb. eg. a QImode value and we're padding
4299 upward on a BYTES_BIG_ENDIAN machine. */
4300 if (size
< UNITS_PER_WORD
4301 && (argvec
[argnum
].locate
.where_pad
4302 == (BYTES_BIG_ENDIAN
? upward
: downward
)))
4305 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
4307 /* Assigning REG here rather than a temp makes CALL_FUSAGE
4308 report the whole reg as used. Strictly speaking, the
4309 call only uses SIZE bytes at the msb end, but it doesn't
4310 seem worth generating rtl to say that. */
4311 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
4312 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, shift
, reg
, 1);
4314 emit_move_insn (reg
, x
);
4322 /* Any regs containing parms remain in use through the call. */
4323 for (count
= 0; count
< nargs
; count
++)
4325 rtx reg
= argvec
[count
].reg
;
4326 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
4327 use_group_regs (&call_fusage
, reg
);
4330 int partial
= argvec
[count
].partial
;
4334 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4335 nregs
= partial
/ UNITS_PER_WORD
;
4336 use_regs (&call_fusage
, REGNO (reg
), nregs
);
4339 use_reg (&call_fusage
, reg
);
4343 /* Pass the function the address in which to return a structure value. */
4344 if (mem_value
!= 0 && struct_value
!= 0 && ! pcc_struct_value
)
4346 emit_move_insn (struct_value
,
4348 force_operand (XEXP (mem_value
, 0),
4350 if (REG_P (struct_value
))
4351 use_reg (&call_fusage
, struct_value
);
4354 /* Don't allow popping to be deferred, since then
4355 cse'ing of library calls could delete a call and leave the pop. */
4357 valreg
= (mem_value
== 0 && outmode
!= VOIDmode
4358 ? hard_libcall_value (outmode
, orgfun
) : NULL_RTX
);
4360 /* Stack must be properly aligned now. */
4361 gcc_assert (!(stack_pointer_delta
4362 & (PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)));
4364 before_call
= get_last_insn ();
4366 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4367 will set inhibit_defer_pop to that value. */
4368 /* The return type is needed to decide how many bytes the function pops.
4369 Signedness plays no role in that, so for simplicity, we pretend it's
4370 always signed. We also assume that the list of arguments passed has
4371 no impact, so we pretend it is unknown. */
4373 emit_call_1 (fun
, NULL
,
4374 get_identifier (XSTR (orgfun
, 0)),
4375 build_function_type (tfom
, NULL_TREE
),
4376 original_args_size
.constant
, args_size
.constant
,
4378 targetm
.calls
.function_arg (args_so_far
,
4379 VOIDmode
, void_type_node
, true),
4381 old_inhibit_defer_pop
+ 1, call_fusage
, flags
, args_so_far
);
4385 rtx last
, datum
= orgfun
;
4386 gcc_assert (GET_CODE (datum
) == SYMBOL_REF
);
4387 last
= last_call_insn ();
4388 add_reg_note (last
, REG_CALL_DECL
, datum
);
4391 /* Right-shift returned value if necessary. */
4392 if (!pcc_struct_value
4393 && TYPE_MODE (tfom
) != BLKmode
4394 && targetm
.calls
.return_in_msb (tfom
))
4396 shift_return_value (TYPE_MODE (tfom
), false, valreg
);
4397 valreg
= gen_rtx_REG (TYPE_MODE (tfom
), REGNO (valreg
));
4400 targetm
.calls
.end_call_args ();
4402 /* For calls to `setjmp', etc., inform function.c:setjmp_warnings
4403 that it should complain if nonvolatile values are live. For
4404 functions that cannot return, inform flow that control does not
4406 if (flags
& ECF_NORETURN
)
4408 /* The barrier note must be emitted
4409 immediately after the CALL_INSN. Some ports emit more than
4410 just a CALL_INSN above, so we must search for it here. */
4411 rtx_insn
*last
= get_last_insn ();
4412 while (!CALL_P (last
))
4414 last
= PREV_INSN (last
);
4415 /* There was no CALL_INSN? */
4416 gcc_assert (last
!= before_call
);
4419 emit_barrier_after (last
);
4422 /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW
4423 and LCT_RETURNS_TWICE, cannot perform non-local gotos. */
4424 if (flags
& ECF_NOTHROW
)
4426 rtx_insn
*last
= get_last_insn ();
4427 while (!CALL_P (last
))
4429 last
= PREV_INSN (last
);
4430 /* There was no CALL_INSN? */
4431 gcc_assert (last
!= before_call
);
4434 make_reg_eh_region_note_nothrow_nononlocal (last
);
4437 /* Now restore inhibit_defer_pop to its actual original value. */
4442 /* Copy the value to the right place. */
4443 if (outmode
!= VOIDmode
&& retval
)
4449 if (value
!= mem_value
)
4450 emit_move_insn (value
, mem_value
);
4452 else if (GET_CODE (valreg
) == PARALLEL
)
4455 value
= gen_reg_rtx (outmode
);
4456 emit_group_store (value
, valreg
, NULL_TREE
, GET_MODE_SIZE (outmode
));
4460 /* Convert to the proper mode if a promotion has been active. */
4461 if (GET_MODE (valreg
) != outmode
)
4463 int unsignedp
= TYPE_UNSIGNED (tfom
);
4465 gcc_assert (promote_function_mode (tfom
, outmode
, &unsignedp
,
4466 fndecl
? TREE_TYPE (fndecl
) : fntype
, 1)
4467 == GET_MODE (valreg
));
4468 valreg
= convert_modes (outmode
, GET_MODE (valreg
), valreg
, 0);
4472 emit_move_insn (value
, valreg
);
4478 if (ACCUMULATE_OUTGOING_ARGS
)
4480 #ifdef REG_PARM_STACK_SPACE
4482 restore_fixed_argument_area (save_area
, argblock
,
4483 high_to_save
, low_to_save
);
4486 /* If we saved any argument areas, restore them. */
4487 for (count
= 0; count
< nargs
; count
++)
4488 if (argvec
[count
].save_area
)
4490 machine_mode save_mode
= GET_MODE (argvec
[count
].save_area
);
4491 rtx adr
= plus_constant (Pmode
, argblock
,
4492 argvec
[count
].locate
.offset
.constant
);
4493 rtx stack_area
= gen_rtx_MEM (save_mode
,
4494 memory_address (save_mode
, adr
));
4496 if (save_mode
== BLKmode
)
4497 emit_block_move (stack_area
,
4499 (copy_rtx (argvec
[count
].save_area
)),
4500 GEN_INT (argvec
[count
].locate
.size
.constant
),
4501 BLOCK_OP_CALL_PARM
);
4503 emit_move_insn (stack_area
, argvec
[count
].save_area
);
4506 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
4507 stack_usage_map
= initial_stack_usage_map
;
4510 free (stack_usage_map_buf
);
4516 /* Output a library call to function FUN (a SYMBOL_REF rtx)
4517 (emitting the queue unless NO_QUEUE is nonzero),
4518 for a value of mode OUTMODE,
4519 with NARGS different arguments, passed as alternating rtx values
4520 and machine_modes to convert them to.
4522 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for
4523 `const' calls, LCT_PURE for `pure' calls, or other LCT_ value for
4524 other types of library calls. */
4527 emit_library_call (rtx orgfun
, enum libcall_type fn_type
,
4528 machine_mode outmode
, int nargs
, ...)
4532 va_start (p
, nargs
);
4533 emit_library_call_value_1 (0, orgfun
, NULL_RTX
, fn_type
, outmode
, nargs
, p
);
4537 /* Like emit_library_call except that an extra argument, VALUE,
4538 comes second and says where to store the result.
4539 (If VALUE is zero, this function chooses a convenient way
4540 to return the value.
4542 This function returns an rtx for where the value is to be found.
4543 If VALUE is nonzero, VALUE is returned. */
4546 emit_library_call_value (rtx orgfun
, rtx value
,
4547 enum libcall_type fn_type
,
4548 machine_mode outmode
, int nargs
, ...)
4553 va_start (p
, nargs
);
4554 result
= emit_library_call_value_1 (1, orgfun
, value
, fn_type
, outmode
,
4562 /* Store pointer bounds argument ARG into Bounds Table entry
4563 associated with PARM. */
4565 store_bounds (struct arg_data
*arg
, struct arg_data
*parm
)
4567 rtx slot
= NULL
, ptr
= NULL
, addr
= NULL
;
4569 /* We may pass bounds not associated with any pointer. */
4572 gcc_assert (arg
->special_slot
);
4573 slot
= arg
->special_slot
;
4576 /* Find pointer associated with bounds and where it is
4582 gcc_assert (!arg
->special_slot
);
4584 addr
= adjust_address (parm
->stack
, Pmode
, arg
->pointer_offset
);
4586 else if (REG_P (parm
->reg
))
4588 gcc_assert (arg
->special_slot
);
4589 slot
= arg
->special_slot
;
4591 if (MEM_P (parm
->value
))
4592 addr
= adjust_address (parm
->value
, Pmode
, arg
->pointer_offset
);
4593 else if (REG_P (parm
->value
))
4594 ptr
= gen_rtx_SUBREG (Pmode
, parm
->value
, arg
->pointer_offset
);
4597 gcc_assert (!arg
->pointer_offset
);
4603 gcc_assert (GET_CODE (parm
->reg
) == PARALLEL
);
4605 gcc_assert (arg
->special_slot
);
4606 slot
= arg
->special_slot
;
4608 if (parm
->parallel_value
)
4609 ptr
= chkp_get_value_with_offs (parm
->parallel_value
,
4610 GEN_INT (arg
->pointer_offset
));
4616 /* Expand bounds. */
4618 arg
->value
= expand_normal (arg
->tree_value
);
4620 targetm
.calls
.store_bounds_for_arg (ptr
, addr
, arg
->value
, slot
);
4623 /* Store a single argument for a function call
4624 into the register or memory area where it must be passed.
4625 *ARG describes the argument value and where to pass it.
4627 ARGBLOCK is the address of the stack-block for all the arguments,
4628 or 0 on a machine where arguments are pushed individually.
4630 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4631 so must be careful about how the stack is used.
4633 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4634 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4635 that we need not worry about saving and restoring the stack.
4637 FNDECL is the declaration of the function we are calling.
4639 Return nonzero if this arg should cause sibcall failure,
4643 store_one_arg (struct arg_data
*arg
, rtx argblock
, int flags
,
4644 int variable_size ATTRIBUTE_UNUSED
, int reg_parm_stack_space
)
4646 tree pval
= arg
->tree_value
;
4650 int i
, lower_bound
= 0, upper_bound
= 0;
4651 int sibcall_failure
= 0;
4653 if (TREE_CODE (pval
) == ERROR_MARK
)
4656 /* Push a new temporary level for any temporaries we make for
4660 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
))
4662 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4663 save any previous data at that location. */
4664 if (argblock
&& ! variable_size
&& arg
->stack
)
4666 #ifdef ARGS_GROW_DOWNWARD
4667 /* stack_slot is negative, but we want to index stack_usage_map
4668 with positive values. */
4669 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4670 upper_bound
= -INTVAL (XEXP (XEXP (arg
->stack_slot
, 0), 1)) + 1;
4674 lower_bound
= upper_bound
- arg
->locate
.size
.constant
;
4676 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4677 lower_bound
= INTVAL (XEXP (XEXP (arg
->stack_slot
, 0), 1));
4681 upper_bound
= lower_bound
+ arg
->locate
.size
.constant
;
4685 /* Don't worry about things in the fixed argument area;
4686 it has already been saved. */
4687 if (i
< reg_parm_stack_space
)
4688 i
= reg_parm_stack_space
;
4689 while (i
< upper_bound
&& stack_usage_map
[i
] == 0)
4692 if (i
< upper_bound
)
4694 /* We need to make a save area. */
4695 unsigned int size
= arg
->locate
.size
.constant
* BITS_PER_UNIT
;
4696 machine_mode save_mode
= mode_for_size (size
, MODE_INT
, 1);
4697 rtx adr
= memory_address (save_mode
, XEXP (arg
->stack_slot
, 0));
4698 rtx stack_area
= gen_rtx_MEM (save_mode
, adr
);
4700 if (save_mode
== BLKmode
)
4703 = assign_temp (TREE_TYPE (arg
->tree_value
), 1, 1);
4704 preserve_temp_slots (arg
->save_area
);
4705 emit_block_move (validize_mem (copy_rtx (arg
->save_area
)),
4707 GEN_INT (arg
->locate
.size
.constant
),
4708 BLOCK_OP_CALL_PARM
);
4712 arg
->save_area
= gen_reg_rtx (save_mode
);
4713 emit_move_insn (arg
->save_area
, stack_area
);
4719 /* If this isn't going to be placed on both the stack and in registers,
4720 set up the register and number of words. */
4721 if (! arg
->pass_on_stack
)
4723 if (flags
& ECF_SIBCALL
)
4724 reg
= arg
->tail_call_reg
;
4727 partial
= arg
->partial
;
4730 /* Being passed entirely in a register. We shouldn't be called in
4732 gcc_assert (reg
== 0 || partial
!= 0);
4734 /* If this arg needs special alignment, don't load the registers
4736 if (arg
->n_aligned_regs
!= 0)
4739 /* If this is being passed partially in a register, we can't evaluate
4740 it directly into its stack slot. Otherwise, we can. */
4741 if (arg
->value
== 0)
4743 /* stack_arg_under_construction is nonzero if a function argument is
4744 being evaluated directly into the outgoing argument list and
4745 expand_call must take special action to preserve the argument list
4746 if it is called recursively.
4748 For scalar function arguments stack_usage_map is sufficient to
4749 determine which stack slots must be saved and restored. Scalar
4750 arguments in general have pass_on_stack == 0.
4752 If this argument is initialized by a function which takes the
4753 address of the argument (a C++ constructor or a C function
4754 returning a BLKmode structure), then stack_usage_map is
4755 insufficient and expand_call must push the stack around the
4756 function call. Such arguments have pass_on_stack == 1.
4758 Note that it is always safe to set stack_arg_under_construction,
4759 but this generates suboptimal code if set when not needed. */
4761 if (arg
->pass_on_stack
)
4762 stack_arg_under_construction
++;
4764 arg
->value
= expand_expr (pval
,
4766 || TYPE_MODE (TREE_TYPE (pval
)) != arg
->mode
)
4767 ? NULL_RTX
: arg
->stack
,
4768 VOIDmode
, EXPAND_STACK_PARM
);
4770 /* If we are promoting object (or for any other reason) the mode
4771 doesn't agree, convert the mode. */
4773 if (arg
->mode
!= TYPE_MODE (TREE_TYPE (pval
)))
4774 arg
->value
= convert_modes (arg
->mode
, TYPE_MODE (TREE_TYPE (pval
)),
4775 arg
->value
, arg
->unsignedp
);
4777 if (arg
->pass_on_stack
)
4778 stack_arg_under_construction
--;
4781 /* Check for overlap with already clobbered argument area. */
4782 if ((flags
& ECF_SIBCALL
)
4783 && MEM_P (arg
->value
)
4784 && mem_overlaps_already_clobbered_arg_p (XEXP (arg
->value
, 0),
4785 arg
->locate
.size
.constant
))
4786 sibcall_failure
= 1;
4788 /* Don't allow anything left on stack from computation
4789 of argument to alloca. */
4790 if (flags
& ECF_MAY_BE_ALLOCA
)
4791 do_pending_stack_adjust ();
4793 if (arg
->value
== arg
->stack
)
4794 /* If the value is already in the stack slot, we are done. */
4796 else if (arg
->mode
!= BLKmode
)
4799 unsigned int parm_align
;
4801 /* Argument is a scalar, not entirely passed in registers.
4802 (If part is passed in registers, arg->partial says how much
4803 and emit_push_insn will take care of putting it there.)
4805 Push it, and if its size is less than the
4806 amount of space allocated to it,
4807 also bump stack pointer by the additional space.
4808 Note that in C the default argument promotions
4809 will prevent such mismatches. */
4811 size
= GET_MODE_SIZE (arg
->mode
);
4812 /* Compute how much space the push instruction will push.
4813 On many machines, pushing a byte will advance the stack
4814 pointer by a halfword. */
4815 #ifdef PUSH_ROUNDING
4816 size
= PUSH_ROUNDING (size
);
4820 /* Compute how much space the argument should get:
4821 round up to a multiple of the alignment for arguments. */
4822 if (none
!= FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)))
4823 used
= (((size
+ PARM_BOUNDARY
/ BITS_PER_UNIT
- 1)
4824 / (PARM_BOUNDARY
/ BITS_PER_UNIT
))
4825 * (PARM_BOUNDARY
/ BITS_PER_UNIT
));
4827 /* Compute the alignment of the pushed argument. */
4828 parm_align
= arg
->locate
.boundary
;
4829 if (FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)) == downward
)
4831 int pad
= used
- size
;
4834 unsigned int pad_align
= (pad
& -pad
) * BITS_PER_UNIT
;
4835 parm_align
= MIN (parm_align
, pad_align
);
4839 /* This isn't already where we want it on the stack, so put it there.
4840 This can either be done with push or copy insns. */
4841 emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
), NULL_RTX
,
4842 parm_align
, partial
, reg
, used
- size
, argblock
,
4843 ARGS_SIZE_RTX (arg
->locate
.offset
), reg_parm_stack_space
,
4844 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
));
4846 /* Unless this is a partially-in-register argument, the argument is now
4849 arg
->value
= arg
->stack
;
4853 /* BLKmode, at least partly to be pushed. */
4855 unsigned int parm_align
;
4859 /* Pushing a nonscalar.
4860 If part is passed in registers, PARTIAL says how much
4861 and emit_push_insn will take care of putting it there. */
4863 /* Round its size up to a multiple
4864 of the allocation unit for arguments. */
4866 if (arg
->locate
.size
.var
!= 0)
4869 size_rtx
= ARGS_SIZE_RTX (arg
->locate
.size
);
4873 /* PUSH_ROUNDING has no effect on us, because emit_push_insn
4874 for BLKmode is careful to avoid it. */
4875 excess
= (arg
->locate
.size
.constant
4876 - int_size_in_bytes (TREE_TYPE (pval
))
4878 size_rtx
= expand_expr (size_in_bytes (TREE_TYPE (pval
)),
4879 NULL_RTX
, TYPE_MODE (sizetype
),
4883 parm_align
= arg
->locate
.boundary
;
4885 /* When an argument is padded down, the block is aligned to
4886 PARM_BOUNDARY, but the actual argument isn't. */
4887 if (FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)) == downward
)
4889 if (arg
->locate
.size
.var
)
4890 parm_align
= BITS_PER_UNIT
;
4893 unsigned int excess_align
= (excess
& -excess
) * BITS_PER_UNIT
;
4894 parm_align
= MIN (parm_align
, excess_align
);
4898 if ((flags
& ECF_SIBCALL
) && MEM_P (arg
->value
))
4900 /* emit_push_insn might not work properly if arg->value and
4901 argblock + arg->locate.offset areas overlap. */
4905 if (XEXP (x
, 0) == crtl
->args
.internal_arg_pointer
4906 || (GET_CODE (XEXP (x
, 0)) == PLUS
4907 && XEXP (XEXP (x
, 0), 0) ==
4908 crtl
->args
.internal_arg_pointer
4909 && CONST_INT_P (XEXP (XEXP (x
, 0), 1))))
4911 if (XEXP (x
, 0) != crtl
->args
.internal_arg_pointer
)
4912 i
= INTVAL (XEXP (XEXP (x
, 0), 1));
4914 /* expand_call should ensure this. */
4915 gcc_assert (!arg
->locate
.offset
.var
4916 && arg
->locate
.size
.var
== 0
4917 && CONST_INT_P (size_rtx
));
4919 if (arg
->locate
.offset
.constant
> i
)
4921 if (arg
->locate
.offset
.constant
< i
+ INTVAL (size_rtx
))
4922 sibcall_failure
= 1;
4924 else if (arg
->locate
.offset
.constant
< i
)
4926 /* Use arg->locate.size.constant instead of size_rtx
4927 because we only care about the part of the argument
4929 if (i
< (arg
->locate
.offset
.constant
4930 + arg
->locate
.size
.constant
))
4931 sibcall_failure
= 1;
4935 /* Even though they appear to be at the same location,
4936 if part of the outgoing argument is in registers,
4937 they aren't really at the same location. Check for
4938 this by making sure that the incoming size is the
4939 same as the outgoing size. */
4940 if (arg
->locate
.size
.constant
!= INTVAL (size_rtx
))
4941 sibcall_failure
= 1;
4946 emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
), size_rtx
,
4947 parm_align
, partial
, reg
, excess
, argblock
,
4948 ARGS_SIZE_RTX (arg
->locate
.offset
), reg_parm_stack_space
,
4949 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
));
4951 /* Unless this is a partially-in-register argument, the argument is now
4954 ??? Unlike the case above, in which we want the actual
4955 address of the data, so that we can load it directly into a
4956 register, here we want the address of the stack slot, so that
4957 it's properly aligned for word-by-word copying or something
4958 like that. It's not clear that this is always correct. */
4960 arg
->value
= arg
->stack_slot
;
4963 if (arg
->reg
&& GET_CODE (arg
->reg
) == PARALLEL
)
4965 tree type
= TREE_TYPE (arg
->tree_value
);
4967 = emit_group_load_into_temps (arg
->reg
, arg
->value
, type
,
4968 int_size_in_bytes (type
));
4971 /* Mark all slots this store used. */
4972 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
)
4973 && argblock
&& ! variable_size
&& arg
->stack
)
4974 for (i
= lower_bound
; i
< upper_bound
; i
++)
4975 stack_usage_map
[i
] = 1;
4977 /* Once we have pushed something, pops can't safely
4978 be deferred during the rest of the arguments. */
4981 /* Free any temporary slots made in processing this argument. */
4984 return sibcall_failure
;
4987 /* Nonzero if we do not know how to pass TYPE solely in registers. */
4990 must_pass_in_stack_var_size (machine_mode mode ATTRIBUTE_UNUSED
,
4996 /* If the type has variable size... */
4997 if (TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
5000 /* If the type is marked as addressable (it is required
5001 to be constructed into the stack)... */
5002 if (TREE_ADDRESSABLE (type
))
5008 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
5009 takes trailing padding of a structure into account. */
5010 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
5013 must_pass_in_stack_var_size_or_pad (machine_mode mode
, const_tree type
)
5018 /* If the type has variable size... */
5019 if (TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
5022 /* If the type is marked as addressable (it is required
5023 to be constructed into the stack)... */
5024 if (TREE_ADDRESSABLE (type
))
5027 /* If the padding and mode of the type is such that a copy into
5028 a register would put it into the wrong part of the register. */
5030 && int_size_in_bytes (type
) % (PARM_BOUNDARY
/ BITS_PER_UNIT
)
5031 && (FUNCTION_ARG_PADDING (mode
, type
)
5032 == (BYTES_BIG_ENDIAN
? upward
: downward
)))