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"
32 #include "fold-const.h"
33 #include "stor-layout.h"
35 #include "stringpool.h"
39 #include "hard-reg-set.h"
41 #include "basic-block.h"
42 #include "tree-ssa-alias.h"
43 #include "internal-fn.h"
44 #include "gimple-expr.h"
48 #include "statistics.h"
49 #include "insn-config.h"
57 #include "insn-codes.h"
61 #include "diagnostic-core.h"
67 #include "langhooks.h"
70 #include "plugin-api.h"
76 #include "tree-chkp.h"
80 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
81 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
83 /* Data structure and subroutines used within expand_call. */
87 /* Tree node for this argument. */
89 /* Mode for value; TYPE_MODE unless promoted. */
91 /* Current RTL value for argument, or 0 if it isn't precomputed. */
93 /* Initially-compute RTL value for argument; only for const functions. */
95 /* Register to pass this argument in, 0 if passed on stack, or an
96 PARALLEL if the arg is to be copied into multiple non-contiguous
99 /* Register to pass this argument in when generating tail call sequence.
100 This is not the same register as for normal calls on machines with
103 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
104 form for emit_group_move. */
106 /* If value is passed in neither reg nor stack, this field holds a number
107 of a special slot to be used. */
109 /* For pointer bounds hold an index of parm bounds are bound to. -1 if
110 there is no such pointer. */
112 /* If pointer_arg refers a structure, then pointer_offset holds an offset
113 of a pointer in this structure. */
115 /* If REG was promoted from the actual mode of the argument expression,
116 indicates whether the promotion is sign- or zero-extended. */
118 /* Number of bytes to put in registers. 0 means put the whole arg
119 in registers. Also 0 if not passed in registers. */
121 /* Nonzero if argument must be passed on stack.
122 Note that some arguments may be passed on the stack
123 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
124 pass_on_stack identifies arguments that *cannot* go in registers. */
126 /* Some fields packaged up for locate_and_pad_parm. */
127 struct locate_and_pad_arg_data locate
;
128 /* Location on the stack at which parameter should be stored. The store
129 has already been done if STACK == VALUE. */
131 /* Location on the stack of the start of this argument slot. This can
132 differ from STACK if this arg pads downward. This location is known
133 to be aligned to TARGET_FUNCTION_ARG_BOUNDARY. */
135 /* Place that this stack area has been saved, if needed. */
137 /* If an argument's alignment does not permit direct copying into registers,
138 copy in smaller-sized pieces into pseudos. These are stored in a
139 block pointed to by this field. The next field says how many
140 word-sized pseudos we made. */
145 /* A vector of one char per byte of stack space. A byte if nonzero if
146 the corresponding stack location has been used.
147 This vector is used to prevent a function call within an argument from
148 clobbering any stack already set up. */
149 static char *stack_usage_map
;
151 /* Size of STACK_USAGE_MAP. */
152 static int highest_outgoing_arg_in_use
;
154 /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
155 stack location's tail call argument has been already stored into the stack.
156 This bitmap is used to prevent sibling call optimization if function tries
157 to use parent's incoming argument slots when they have been already
158 overwritten with tail call arguments. */
159 static sbitmap stored_args_map
;
161 /* stack_arg_under_construction is nonzero when an argument may be
162 initialized with a constructor call (including a C function that
163 returns a BLKmode struct) and expand_call must take special action
164 to make sure the object being constructed does not overlap the
165 argument list for the constructor call. */
166 static int stack_arg_under_construction
;
168 static void emit_call_1 (rtx
, tree
, tree
, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
,
169 HOST_WIDE_INT
, rtx
, rtx
, int, rtx
, int,
171 static void precompute_register_parameters (int, struct arg_data
*, int *);
172 static void store_bounds (struct arg_data
*, struct arg_data
*);
173 static int store_one_arg (struct arg_data
*, rtx
, int, int, int);
174 static void store_unaligned_arguments_into_pseudos (struct arg_data
*, int);
175 static int finalize_must_preallocate (int, int, struct arg_data
*,
177 static void precompute_arguments (int, struct arg_data
*);
178 static int compute_argument_block_size (int, struct args_size
*, tree
, tree
, int);
179 static void initialize_argument_information (int, struct arg_data
*,
180 struct args_size
*, int,
182 tree
, tree
, cumulative_args_t
, int,
183 rtx
*, int *, int *, int *,
185 static void compute_argument_addresses (struct arg_data
*, rtx
, int);
186 static rtx
rtx_for_function_call (tree
, tree
);
187 static void load_register_parameters (struct arg_data
*, int, rtx
*, int,
189 static rtx
emit_library_call_value_1 (int, rtx
, rtx
, enum libcall_type
,
190 machine_mode
, int, va_list);
191 static int special_function_p (const_tree
, int);
192 static int check_sibcall_argument_overlap_1 (rtx
);
193 static int check_sibcall_argument_overlap (rtx_insn
*, struct arg_data
*, int);
195 static int combine_pending_stack_adjustment_and_call (int, struct args_size
*,
197 static tree
split_complex_types (tree
);
199 #ifdef REG_PARM_STACK_SPACE
200 static rtx
save_fixed_argument_area (int, rtx
, int *, int *);
201 static void restore_fixed_argument_area (rtx
, rtx
, int, int);
204 /* Force FUNEXP into a form suitable for the address of a CALL,
205 and return that as an rtx. Also load the static chain register
206 if FNDECL is a nested function.
208 CALL_FUSAGE points to a variable holding the prospective
209 CALL_INSN_FUNCTION_USAGE information. */
212 prepare_call_address (tree fndecl_or_type
, rtx funexp
, rtx static_chain_value
,
213 rtx
*call_fusage
, int reg_parm_seen
, int sibcallp
)
215 /* Make a valid memory address and copy constants through pseudo-regs,
216 but not for a constant address if -fno-function-cse. */
217 if (GET_CODE (funexp
) != SYMBOL_REF
)
218 /* If we are using registers for parameters, force the
219 function address into a register now. */
220 funexp
= ((reg_parm_seen
221 && targetm
.small_register_classes_for_mode_p (FUNCTION_MODE
))
222 ? force_not_mem (memory_address (FUNCTION_MODE
, funexp
))
223 : memory_address (FUNCTION_MODE
, funexp
));
226 && TREE_CODE (fndecl_or_type
) == FUNCTION_DECL
228 || lookup_attribute ("noplt", DECL_ATTRIBUTES (fndecl_or_type
)))
229 && !targetm
.binds_local_p (fndecl_or_type
))
231 /* This is done only for PIC code. There is no easy interface to force the
232 function address into GOT for non-PIC case. non-PIC case needs to be
233 handled specially by the backend. */
234 funexp
= force_reg (Pmode
, funexp
);
238 if (!NO_FUNCTION_CSE
&& optimize
&& ! flag_no_function_cse
)
239 funexp
= force_reg (Pmode
, funexp
);
242 if (static_chain_value
!= 0
243 && (TREE_CODE (fndecl_or_type
) != FUNCTION_DECL
244 || DECL_STATIC_CHAIN (fndecl_or_type
)))
248 chain
= targetm
.calls
.static_chain (fndecl_or_type
, false);
249 static_chain_value
= convert_memory_address (Pmode
, static_chain_value
);
251 emit_move_insn (chain
, static_chain_value
);
253 use_reg (call_fusage
, chain
);
259 /* Generate instructions to call function FUNEXP,
260 and optionally pop the results.
261 The CALL_INSN is the first insn generated.
263 FNDECL is the declaration node of the function. This is given to the
264 hook TARGET_RETURN_POPS_ARGS to determine whether this function pops
267 FUNTYPE is the data type of the function. This is given to the hook
268 TARGET_RETURN_POPS_ARGS to determine whether this function pops its
269 own args. We used to allow an identifier for library functions, but
270 that doesn't work when the return type is an aggregate type and the
271 calling convention says that the pointer to this aggregate is to be
272 popped by the callee.
274 STACK_SIZE is the number of bytes of arguments on the stack,
275 ROUNDED_STACK_SIZE is that number rounded up to
276 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
277 both to put into the call insn and to generate explicit popping
280 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
281 It is zero if this call doesn't want a structure value.
283 NEXT_ARG_REG is the rtx that results from executing
284 targetm.calls.function_arg (&args_so_far, VOIDmode, void_type_node, true)
285 just after all the args have had their registers assigned.
286 This could be whatever you like, but normally it is the first
287 arg-register beyond those used for args in this call,
288 or 0 if all the arg-registers are used in this call.
289 It is passed on to `gen_call' so you can put this info in the call insn.
291 VALREG is a hard register in which a value is returned,
292 or 0 if the call does not return a value.
294 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
295 the args to this call were processed.
296 We restore `inhibit_defer_pop' to that value.
298 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
299 denote registers used by the called function. */
302 emit_call_1 (rtx funexp
, tree fntree ATTRIBUTE_UNUSED
, tree fndecl ATTRIBUTE_UNUSED
,
303 tree funtype ATTRIBUTE_UNUSED
,
304 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED
,
305 HOST_WIDE_INT rounded_stack_size
,
306 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED
,
307 rtx next_arg_reg ATTRIBUTE_UNUSED
, rtx valreg
,
308 int old_inhibit_defer_pop
, rtx call_fusage
, int ecf_flags
,
309 cumulative_args_t args_so_far ATTRIBUTE_UNUSED
)
311 rtx rounded_stack_size_rtx
= GEN_INT (rounded_stack_size
);
314 int already_popped
= 0;
315 HOST_WIDE_INT n_popped
316 = targetm
.calls
.return_pops_args (fndecl
, funtype
, stack_size
);
318 #ifdef CALL_POPS_ARGS
319 n_popped
+= CALL_POPS_ARGS (*get_cumulative_args (args_so_far
));
322 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
323 and we don't want to load it into a register as an optimization,
324 because prepare_call_address already did it if it should be done. */
325 if (GET_CODE (funexp
) != SYMBOL_REF
)
326 funexp
= memory_address (FUNCTION_MODE
, funexp
);
328 funmem
= gen_rtx_MEM (FUNCTION_MODE
, funexp
);
329 if (fndecl
&& TREE_CODE (fndecl
) == FUNCTION_DECL
)
333 /* Although a built-in FUNCTION_DECL and its non-__builtin
334 counterpart compare equal and get a shared mem_attrs, they
335 produce different dump output in compare-debug compilations,
336 if an entry gets garbage collected in one compilation, then
337 adds a different (but equivalent) entry, while the other
338 doesn't run the garbage collector at the same spot and then
339 shares the mem_attr with the equivalent entry. */
340 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
)
342 tree t2
= builtin_decl_explicit (DECL_FUNCTION_CODE (t
));
347 set_mem_expr (funmem
, t
);
350 set_mem_expr (funmem
, build_simple_mem_ref (CALL_EXPR_FN (fntree
)));
352 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
353 if ((ecf_flags
& ECF_SIBCALL
)
354 && HAVE_sibcall_pop
&& HAVE_sibcall_value_pop
355 && (n_popped
> 0 || stack_size
== 0))
357 rtx n_pop
= GEN_INT (n_popped
);
360 /* If this subroutine pops its own args, record that in the call insn
361 if possible, for the sake of frame pointer elimination. */
364 pat
= GEN_SIBCALL_VALUE_POP (valreg
, funmem
, rounded_stack_size_rtx
,
365 next_arg_reg
, n_pop
);
367 pat
= GEN_SIBCALL_POP (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
370 emit_call_insn (pat
);
376 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
377 /* If the target has "call" or "call_value" insns, then prefer them
378 if no arguments are actually popped. If the target does not have
379 "call" or "call_value" insns, then we must use the popping versions
380 even if the call has no arguments to pop. */
381 #if defined (HAVE_call) && defined (HAVE_call_value)
382 if (HAVE_call
&& HAVE_call_value
&& HAVE_call_pop
&& HAVE_call_value_pop
385 if (HAVE_call_pop
&& HAVE_call_value_pop
)
388 rtx n_pop
= GEN_INT (n_popped
);
391 /* If this subroutine pops its own args, record that in the call insn
392 if possible, for the sake of frame pointer elimination. */
395 pat
= GEN_CALL_VALUE_POP (valreg
, funmem
, rounded_stack_size_rtx
,
396 next_arg_reg
, n_pop
);
398 pat
= GEN_CALL_POP (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
401 emit_call_insn (pat
);
407 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
408 if ((ecf_flags
& ECF_SIBCALL
)
409 && HAVE_sibcall
&& HAVE_sibcall_value
)
412 emit_call_insn (GEN_SIBCALL_VALUE (valreg
, funmem
,
413 rounded_stack_size_rtx
,
414 next_arg_reg
, NULL_RTX
));
416 emit_call_insn (GEN_SIBCALL (funmem
, rounded_stack_size_rtx
,
418 GEN_INT (struct_value_size
)));
423 #if defined (HAVE_call) && defined (HAVE_call_value)
424 if (HAVE_call
&& HAVE_call_value
)
427 emit_call_insn (GEN_CALL_VALUE (valreg
, funmem
, rounded_stack_size_rtx
,
428 next_arg_reg
, NULL_RTX
));
430 emit_call_insn (GEN_CALL (funmem
, rounded_stack_size_rtx
, next_arg_reg
,
431 GEN_INT (struct_value_size
)));
437 /* Find the call we just emitted. */
438 call_insn
= last_call_insn ();
440 /* Some target create a fresh MEM instead of reusing the one provided
441 above. Set its MEM_EXPR. */
442 call
= get_call_rtx_from (call_insn
);
444 && MEM_EXPR (XEXP (call
, 0)) == NULL_TREE
445 && MEM_EXPR (funmem
) != NULL_TREE
)
446 set_mem_expr (XEXP (call
, 0), MEM_EXPR (funmem
));
448 /* Mark instrumented calls. */
450 CALL_EXPR_WITH_BOUNDS_P (call
) = CALL_WITH_BOUNDS_P (fntree
);
452 /* Put the register usage information there. */
453 add_function_usage_to (call_insn
, call_fusage
);
455 /* If this is a const call, then set the insn's unchanging bit. */
456 if (ecf_flags
& ECF_CONST
)
457 RTL_CONST_CALL_P (call_insn
) = 1;
459 /* If this is a pure call, then set the insn's unchanging bit. */
460 if (ecf_flags
& ECF_PURE
)
461 RTL_PURE_CALL_P (call_insn
) = 1;
463 /* If this is a const call, then set the insn's unchanging bit. */
464 if (ecf_flags
& ECF_LOOPING_CONST_OR_PURE
)
465 RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn
) = 1;
467 /* Create a nothrow REG_EH_REGION note, if needed. */
468 make_reg_eh_region_note (call_insn
, ecf_flags
, 0);
470 if (ecf_flags
& ECF_NORETURN
)
471 add_reg_note (call_insn
, REG_NORETURN
, const0_rtx
);
473 if (ecf_flags
& ECF_RETURNS_TWICE
)
475 add_reg_note (call_insn
, REG_SETJMP
, const0_rtx
);
476 cfun
->calls_setjmp
= 1;
479 SIBLING_CALL_P (call_insn
) = ((ecf_flags
& ECF_SIBCALL
) != 0);
481 /* Restore this now, so that we do defer pops for this call's args
482 if the context of the call as a whole permits. */
483 inhibit_defer_pop
= old_inhibit_defer_pop
;
488 CALL_INSN_FUNCTION_USAGE (call_insn
)
489 = gen_rtx_EXPR_LIST (VOIDmode
,
490 gen_rtx_CLOBBER (VOIDmode
, stack_pointer_rtx
),
491 CALL_INSN_FUNCTION_USAGE (call_insn
));
492 rounded_stack_size
-= n_popped
;
493 rounded_stack_size_rtx
= GEN_INT (rounded_stack_size
);
494 stack_pointer_delta
-= n_popped
;
496 add_reg_note (call_insn
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
498 /* If popup is needed, stack realign must use DRAP */
499 if (SUPPORTS_STACK_ALIGNMENT
)
500 crtl
->need_drap
= true;
502 /* For noreturn calls when not accumulating outgoing args force
503 REG_ARGS_SIZE note to prevent crossjumping of calls with different
505 else if (!ACCUMULATE_OUTGOING_ARGS
&& (ecf_flags
& ECF_NORETURN
) != 0)
506 add_reg_note (call_insn
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
508 if (!ACCUMULATE_OUTGOING_ARGS
)
510 /* If returning from the subroutine does not automatically pop the args,
511 we need an instruction to pop them sooner or later.
512 Perhaps do it now; perhaps just record how much space to pop later.
514 If returning from the subroutine does pop the args, indicate that the
515 stack pointer will be changed. */
517 if (rounded_stack_size
!= 0)
519 if (ecf_flags
& ECF_NORETURN
)
520 /* Just pretend we did the pop. */
521 stack_pointer_delta
-= rounded_stack_size
;
522 else if (flag_defer_pop
&& inhibit_defer_pop
== 0
523 && ! (ecf_flags
& (ECF_CONST
| ECF_PURE
)))
524 pending_stack_adjust
+= rounded_stack_size
;
526 adjust_stack (rounded_stack_size_rtx
);
529 /* When we accumulate outgoing args, we must avoid any stack manipulations.
530 Restore the stack pointer to its original value now. Usually
531 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
532 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
533 popping variants of functions exist as well.
535 ??? We may optimize similar to defer_pop above, but it is
536 probably not worthwhile.
538 ??? It will be worthwhile to enable combine_stack_adjustments even for
541 anti_adjust_stack (GEN_INT (n_popped
));
544 /* Determine if the function identified by NAME and FNDECL is one with
545 special properties we wish to know about.
547 For example, if the function might return more than one time (setjmp), then
548 set RETURNS_TWICE to a nonzero value.
550 Similarly set NORETURN if the function is in the longjmp family.
552 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
553 space from the stack such as alloca. */
556 special_function_p (const_tree fndecl
, int flags
)
558 tree name_decl
= DECL_NAME (fndecl
);
560 /* For instrumentation clones we want to derive flags
561 from the original name. */
562 if (cgraph_node::get (fndecl
)
563 && cgraph_node::get (fndecl
)->instrumentation_clone
)
564 name_decl
= DECL_NAME (cgraph_node::get (fndecl
)->orig_decl
);
566 if (fndecl
&& name_decl
567 && IDENTIFIER_LENGTH (name_decl
) <= 17
568 /* Exclude functions not at the file scope, or not `extern',
569 since they are not the magic functions we would otherwise
571 FIXME: this should be handled with attributes, not with this
572 hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
573 because you can declare fork() inside a function if you
575 && (DECL_CONTEXT (fndecl
) == NULL_TREE
576 || TREE_CODE (DECL_CONTEXT (fndecl
)) == TRANSLATION_UNIT_DECL
)
577 && TREE_PUBLIC (fndecl
))
579 const char *name
= IDENTIFIER_POINTER (name_decl
);
580 const char *tname
= name
;
582 /* We assume that alloca will always be called by name. It
583 makes no sense to pass it as a pointer-to-function to
584 anything that does not understand its behavior. */
585 if (((IDENTIFIER_LENGTH (name_decl
) == 6
587 && ! strcmp (name
, "alloca"))
588 || (IDENTIFIER_LENGTH (name_decl
) == 16
590 && ! strcmp (name
, "__builtin_alloca"))))
591 flags
|= ECF_MAY_BE_ALLOCA
;
593 /* Disregard prefix _, __, __x or __builtin_. */
598 && !strncmp (name
+ 3, "uiltin_", 7))
600 else if (name
[1] == '_' && name
[2] == 'x')
602 else if (name
[1] == '_')
611 && (! strcmp (tname
, "setjmp")
612 || ! strcmp (tname
, "setjmp_syscall")))
614 && ! strcmp (tname
, "sigsetjmp"))
616 && ! strcmp (tname
, "savectx")))
617 flags
|= ECF_RETURNS_TWICE
| ECF_LEAF
;
620 && ! strcmp (tname
, "siglongjmp"))
621 flags
|= ECF_NORETURN
;
623 else if ((tname
[0] == 'q' && tname
[1] == 's'
624 && ! strcmp (tname
, "qsetjmp"))
625 || (tname
[0] == 'v' && tname
[1] == 'f'
626 && ! strcmp (tname
, "vfork"))
627 || (tname
[0] == 'g' && tname
[1] == 'e'
628 && !strcmp (tname
, "getcontext")))
629 flags
|= ECF_RETURNS_TWICE
| ECF_LEAF
;
631 else if (tname
[0] == 'l' && tname
[1] == 'o'
632 && ! strcmp (tname
, "longjmp"))
633 flags
|= ECF_NORETURN
;
639 /* Similar to special_function_p; return a set of ERF_ flags for the
642 decl_return_flags (tree fndecl
)
645 tree type
= TREE_TYPE (fndecl
);
649 attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
653 attr
= TREE_VALUE (TREE_VALUE (attr
));
654 if (!attr
|| TREE_STRING_LENGTH (attr
) < 1)
657 switch (TREE_STRING_POINTER (attr
)[0])
663 return ERF_RETURNS_ARG
| (TREE_STRING_POINTER (attr
)[0] - '1');
674 /* Return nonzero when FNDECL represents a call to setjmp. */
677 setjmp_call_p (const_tree fndecl
)
679 if (DECL_IS_RETURNS_TWICE (fndecl
))
680 return ECF_RETURNS_TWICE
;
681 return special_function_p (fndecl
, 0) & ECF_RETURNS_TWICE
;
685 /* Return true if STMT is an alloca call. */
688 gimple_alloca_call_p (const_gimple stmt
)
692 if (!is_gimple_call (stmt
))
695 fndecl
= gimple_call_fndecl (stmt
);
696 if (fndecl
&& (special_function_p (fndecl
, 0) & ECF_MAY_BE_ALLOCA
))
702 /* Return true when exp contains alloca call. */
705 alloca_call_p (const_tree exp
)
708 if (TREE_CODE (exp
) == CALL_EXPR
709 && (fndecl
= get_callee_fndecl (exp
))
710 && (special_function_p (fndecl
, 0) & ECF_MAY_BE_ALLOCA
))
715 /* Return TRUE if FNDECL is either a TM builtin or a TM cloned
716 function. Return FALSE otherwise. */
719 is_tm_builtin (const_tree fndecl
)
724 if (decl_is_tm_clone (fndecl
))
727 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
)
729 switch (DECL_FUNCTION_CODE (fndecl
))
731 case BUILT_IN_TM_COMMIT
:
732 case BUILT_IN_TM_COMMIT_EH
:
733 case BUILT_IN_TM_ABORT
:
734 case BUILT_IN_TM_IRREVOCABLE
:
735 case BUILT_IN_TM_GETTMCLONE_IRR
:
736 case BUILT_IN_TM_MEMCPY
:
737 case BUILT_IN_TM_MEMMOVE
:
738 case BUILT_IN_TM_MEMSET
:
739 CASE_BUILT_IN_TM_STORE (1):
740 CASE_BUILT_IN_TM_STORE (2):
741 CASE_BUILT_IN_TM_STORE (4):
742 CASE_BUILT_IN_TM_STORE (8):
743 CASE_BUILT_IN_TM_STORE (FLOAT
):
744 CASE_BUILT_IN_TM_STORE (DOUBLE
):
745 CASE_BUILT_IN_TM_STORE (LDOUBLE
):
746 CASE_BUILT_IN_TM_STORE (M64
):
747 CASE_BUILT_IN_TM_STORE (M128
):
748 CASE_BUILT_IN_TM_STORE (M256
):
749 CASE_BUILT_IN_TM_LOAD (1):
750 CASE_BUILT_IN_TM_LOAD (2):
751 CASE_BUILT_IN_TM_LOAD (4):
752 CASE_BUILT_IN_TM_LOAD (8):
753 CASE_BUILT_IN_TM_LOAD (FLOAT
):
754 CASE_BUILT_IN_TM_LOAD (DOUBLE
):
755 CASE_BUILT_IN_TM_LOAD (LDOUBLE
):
756 CASE_BUILT_IN_TM_LOAD (M64
):
757 CASE_BUILT_IN_TM_LOAD (M128
):
758 CASE_BUILT_IN_TM_LOAD (M256
):
759 case BUILT_IN_TM_LOG
:
760 case BUILT_IN_TM_LOG_1
:
761 case BUILT_IN_TM_LOG_2
:
762 case BUILT_IN_TM_LOG_4
:
763 case BUILT_IN_TM_LOG_8
:
764 case BUILT_IN_TM_LOG_FLOAT
:
765 case BUILT_IN_TM_LOG_DOUBLE
:
766 case BUILT_IN_TM_LOG_LDOUBLE
:
767 case BUILT_IN_TM_LOG_M64
:
768 case BUILT_IN_TM_LOG_M128
:
769 case BUILT_IN_TM_LOG_M256
:
778 /* Detect flags (function attributes) from the function decl or type node. */
781 flags_from_decl_or_type (const_tree exp
)
787 /* The function exp may have the `malloc' attribute. */
788 if (DECL_IS_MALLOC (exp
))
791 /* The function exp may have the `returns_twice' attribute. */
792 if (DECL_IS_RETURNS_TWICE (exp
))
793 flags
|= ECF_RETURNS_TWICE
;
795 /* Process the pure and const attributes. */
796 if (TREE_READONLY (exp
))
798 if (DECL_PURE_P (exp
))
800 if (DECL_LOOPING_CONST_OR_PURE_P (exp
))
801 flags
|= ECF_LOOPING_CONST_OR_PURE
;
803 if (DECL_IS_NOVOPS (exp
))
805 if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp
)))
808 if (TREE_NOTHROW (exp
))
809 flags
|= ECF_NOTHROW
;
813 if (is_tm_builtin (exp
))
814 flags
|= ECF_TM_BUILTIN
;
815 else if ((flags
& (ECF_CONST
|ECF_NOVOPS
)) != 0
816 || lookup_attribute ("transaction_pure",
817 TYPE_ATTRIBUTES (TREE_TYPE (exp
))))
818 flags
|= ECF_TM_PURE
;
821 flags
= special_function_p (exp
, flags
);
823 else if (TYPE_P (exp
))
825 if (TYPE_READONLY (exp
))
829 && ((flags
& ECF_CONST
) != 0
830 || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp
))))
831 flags
|= ECF_TM_PURE
;
836 if (TREE_THIS_VOLATILE (exp
))
838 flags
|= ECF_NORETURN
;
839 if (flags
& (ECF_CONST
|ECF_PURE
))
840 flags
|= ECF_LOOPING_CONST_OR_PURE
;
846 /* Detect flags from a CALL_EXPR. */
849 call_expr_flags (const_tree t
)
852 tree decl
= get_callee_fndecl (t
);
855 flags
= flags_from_decl_or_type (decl
);
856 else if (CALL_EXPR_FN (t
) == NULL_TREE
)
857 flags
= internal_fn_flags (CALL_EXPR_IFN (t
));
860 t
= TREE_TYPE (CALL_EXPR_FN (t
));
861 if (t
&& TREE_CODE (t
) == POINTER_TYPE
)
862 flags
= flags_from_decl_or_type (TREE_TYPE (t
));
870 /* Precompute all register parameters as described by ARGS, storing values
871 into fields within the ARGS array.
873 NUM_ACTUALS indicates the total number elements in the ARGS array.
875 Set REG_PARM_SEEN if we encounter a register parameter. */
878 precompute_register_parameters (int num_actuals
, struct arg_data
*args
,
885 for (i
= 0; i
< num_actuals
; i
++)
886 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
)
890 if (args
[i
].value
== 0)
893 args
[i
].value
= expand_normal (args
[i
].tree_value
);
894 preserve_temp_slots (args
[i
].value
);
898 /* If we are to promote the function arg to a wider mode,
901 if (args
[i
].mode
!= TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)))
903 = convert_modes (args
[i
].mode
,
904 TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)),
905 args
[i
].value
, args
[i
].unsignedp
);
907 /* If the value is a non-legitimate constant, force it into a
908 pseudo now. TLS symbols sometimes need a call to resolve. */
909 if (CONSTANT_P (args
[i
].value
)
910 && !targetm
.legitimate_constant_p (args
[i
].mode
, args
[i
].value
))
911 args
[i
].value
= force_reg (args
[i
].mode
, args
[i
].value
);
913 /* If we're going to have to load the value by parts, pull the
914 parts into pseudos. The part extraction process can involve
915 non-trivial computation. */
916 if (GET_CODE (args
[i
].reg
) == PARALLEL
)
918 tree type
= TREE_TYPE (args
[i
].tree_value
);
919 args
[i
].parallel_value
920 = emit_group_load_into_temps (args
[i
].reg
, args
[i
].value
,
921 type
, int_size_in_bytes (type
));
924 /* If the value is expensive, and we are inside an appropriately
925 short loop, put the value into a pseudo and then put the pseudo
928 For small register classes, also do this if this call uses
929 register parameters. This is to avoid reload conflicts while
930 loading the parameters registers. */
932 else if ((! (REG_P (args
[i
].value
)
933 || (GET_CODE (args
[i
].value
) == SUBREG
934 && REG_P (SUBREG_REG (args
[i
].value
)))))
935 && args
[i
].mode
!= BLKmode
936 && set_src_cost (args
[i
].value
, optimize_insn_for_speed_p ())
939 && targetm
.small_register_classes_for_mode_p (args
[i
].mode
))
941 args
[i
].value
= copy_to_mode_reg (args
[i
].mode
, args
[i
].value
);
945 #ifdef REG_PARM_STACK_SPACE
947 /* The argument list is the property of the called routine and it
948 may clobber it. If the fixed area has been used for previous
949 parameters, we must save and restore it. */
952 save_fixed_argument_area (int reg_parm_stack_space
, rtx argblock
, int *low_to_save
, int *high_to_save
)
957 /* Compute the boundary of the area that needs to be saved, if any. */
958 high
= reg_parm_stack_space
;
959 if (ARGS_GROW_DOWNWARD
)
962 if (high
> highest_outgoing_arg_in_use
)
963 high
= highest_outgoing_arg_in_use
;
965 for (low
= 0; low
< high
; low
++)
966 if (stack_usage_map
[low
] != 0)
969 machine_mode save_mode
;
975 while (stack_usage_map
[--high
] == 0)
979 *high_to_save
= high
;
981 num_to_save
= high
- low
+ 1;
982 save_mode
= mode_for_size (num_to_save
* BITS_PER_UNIT
, MODE_INT
, 1);
984 /* If we don't have the required alignment, must do this
986 if ((low
& (MIN (GET_MODE_SIZE (save_mode
),
987 BIGGEST_ALIGNMENT
/ UNITS_PER_WORD
) - 1)))
990 if (ARGS_GROW_DOWNWARD
)
995 addr
= plus_constant (Pmode
, argblock
, delta
);
996 stack_area
= gen_rtx_MEM (save_mode
, memory_address (save_mode
, addr
));
998 set_mem_align (stack_area
, PARM_BOUNDARY
);
999 if (save_mode
== BLKmode
)
1001 save_area
= assign_stack_temp (BLKmode
, num_to_save
);
1002 emit_block_move (validize_mem (save_area
), stack_area
,
1003 GEN_INT (num_to_save
), BLOCK_OP_CALL_PARM
);
1007 save_area
= gen_reg_rtx (save_mode
);
1008 emit_move_insn (save_area
, stack_area
);
1018 restore_fixed_argument_area (rtx save_area
, rtx argblock
, int high_to_save
, int low_to_save
)
1020 machine_mode save_mode
= GET_MODE (save_area
);
1022 rtx addr
, stack_area
;
1024 if (ARGS_GROW_DOWNWARD
)
1025 delta
= -high_to_save
;
1027 delta
= low_to_save
;
1029 addr
= plus_constant (Pmode
, argblock
, delta
);
1030 stack_area
= gen_rtx_MEM (save_mode
, memory_address (save_mode
, addr
));
1031 set_mem_align (stack_area
, PARM_BOUNDARY
);
1033 if (save_mode
!= BLKmode
)
1034 emit_move_insn (stack_area
, save_area
);
1036 emit_block_move (stack_area
, validize_mem (save_area
),
1037 GEN_INT (high_to_save
- low_to_save
+ 1),
1038 BLOCK_OP_CALL_PARM
);
1040 #endif /* REG_PARM_STACK_SPACE */
1042 /* If any elements in ARGS refer to parameters that are to be passed in
1043 registers, but not in memory, and whose alignment does not permit a
1044 direct copy into registers. Copy the values into a group of pseudos
1045 which we will later copy into the appropriate hard registers.
1047 Pseudos for each unaligned argument will be stored into the array
1048 args[argnum].aligned_regs. The caller is responsible for deallocating
1049 the aligned_regs array if it is nonzero. */
1052 store_unaligned_arguments_into_pseudos (struct arg_data
*args
, int num_actuals
)
1056 for (i
= 0; i
< num_actuals
; i
++)
1057 if (args
[i
].reg
!= 0 && ! args
[i
].pass_on_stack
1058 && GET_CODE (args
[i
].reg
) != PARALLEL
1059 && args
[i
].mode
== BLKmode
1060 && MEM_P (args
[i
].value
)
1061 && (MEM_ALIGN (args
[i
].value
)
1062 < (unsigned int) MIN (BIGGEST_ALIGNMENT
, BITS_PER_WORD
)))
1064 int bytes
= int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1065 int endian_correction
= 0;
1067 if (args
[i
].partial
)
1069 gcc_assert (args
[i
].partial
% UNITS_PER_WORD
== 0);
1070 args
[i
].n_aligned_regs
= args
[i
].partial
/ UNITS_PER_WORD
;
1074 args
[i
].n_aligned_regs
1075 = (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
1078 args
[i
].aligned_regs
= XNEWVEC (rtx
, args
[i
].n_aligned_regs
);
1080 /* Structures smaller than a word are normally aligned to the
1081 least significant byte. On a BYTES_BIG_ENDIAN machine,
1082 this means we must skip the empty high order bytes when
1083 calculating the bit offset. */
1084 if (bytes
< UNITS_PER_WORD
1085 #ifdef BLOCK_REG_PADDING
1086 && (BLOCK_REG_PADDING (args
[i
].mode
,
1087 TREE_TYPE (args
[i
].tree_value
), 1)
1093 endian_correction
= BITS_PER_WORD
- bytes
* BITS_PER_UNIT
;
1095 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
1097 rtx reg
= gen_reg_rtx (word_mode
);
1098 rtx word
= operand_subword_force (args
[i
].value
, j
, BLKmode
);
1099 int bitsize
= MIN (bytes
* BITS_PER_UNIT
, BITS_PER_WORD
);
1101 args
[i
].aligned_regs
[j
] = reg
;
1102 word
= extract_bit_field (word
, bitsize
, 0, 1, NULL_RTX
,
1103 word_mode
, word_mode
);
1105 /* There is no need to restrict this code to loading items
1106 in TYPE_ALIGN sized hunks. The bitfield instructions can
1107 load up entire word sized registers efficiently.
1109 ??? This may not be needed anymore.
1110 We use to emit a clobber here but that doesn't let later
1111 passes optimize the instructions we emit. By storing 0 into
1112 the register later passes know the first AND to zero out the
1113 bitfield being set in the register is unnecessary. The store
1114 of 0 will be deleted as will at least the first AND. */
1116 emit_move_insn (reg
, const0_rtx
);
1118 bytes
-= bitsize
/ BITS_PER_UNIT
;
1119 store_bit_field (reg
, bitsize
, endian_correction
, 0, 0,
1125 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
1128 NUM_ACTUALS is the total number of parameters.
1130 N_NAMED_ARGS is the total number of named arguments.
1132 STRUCT_VALUE_ADDR_VALUE is the implicit argument for a struct return
1135 FNDECL is the tree code for the target of this call (if known)
1137 ARGS_SO_FAR holds state needed by the target to know where to place
1140 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
1141 for arguments which are passed in registers.
1143 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
1144 and may be modified by this routine.
1146 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
1147 flags which may may be modified by this routine.
1149 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
1150 that requires allocation of stack space.
1152 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
1153 the thunked-to function. */
1156 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED
,
1157 struct arg_data
*args
,
1158 struct args_size
*args_size
,
1159 int n_named_args ATTRIBUTE_UNUSED
,
1160 tree exp
, tree struct_value_addr_value
,
1161 tree fndecl
, tree fntype
,
1162 cumulative_args_t args_so_far
,
1163 int reg_parm_stack_space
,
1164 rtx
*old_stack_level
, int *old_pending_adj
,
1165 int *must_preallocate
, int *ecf_flags
,
1166 bool *may_tailcall
, bool call_from_thunk_p
)
1168 CUMULATIVE_ARGS
*args_so_far_pnt
= get_cumulative_args (args_so_far
);
1169 location_t loc
= EXPR_LOCATION (exp
);
1171 /* Count arg position in order args appear. */
1176 args_size
->constant
= 0;
1179 bitmap_obstack_initialize (NULL
);
1181 /* In this loop, we consider args in the order they are written.
1182 We fill up ARGS from the back. */
1184 i
= num_actuals
- 1;
1186 int j
= i
, ptr_arg
= -1;
1187 call_expr_arg_iterator iter
;
1189 bitmap slots
= NULL
;
1191 if (struct_value_addr_value
)
1193 args
[j
].tree_value
= struct_value_addr_value
;
1196 /* If we pass structure address then we need to
1197 create bounds for it. Since created bounds is
1198 a call statement, we expand it right here to avoid
1199 fixing all other places where it may be expanded. */
1200 if (CALL_WITH_BOUNDS_P (exp
))
1202 args
[j
].value
= gen_reg_rtx (targetm
.chkp_bound_mode ());
1204 = chkp_make_bounds_for_struct_addr (struct_value_addr_value
);
1205 expand_expr_real (args
[j
].tree_value
, args
[j
].value
, VOIDmode
,
1206 EXPAND_NORMAL
, 0, false);
1207 args
[j
].pointer_arg
= j
+ 1;
1211 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
1213 tree argtype
= TREE_TYPE (arg
);
1215 /* Remember last param with pointer and associate it
1216 with following pointer bounds. */
1217 if (CALL_WITH_BOUNDS_P (exp
)
1218 && chkp_type_has_pointer (argtype
))
1221 BITMAP_FREE (slots
);
1223 if (!BOUNDED_TYPE_P (argtype
))
1225 slots
= BITMAP_ALLOC (NULL
);
1226 chkp_find_bound_slots (argtype
, slots
);
1229 else if (POINTER_BOUNDS_TYPE_P (argtype
))
1231 /* We expect bounds in instrumented calls only.
1232 Otherwise it is a sign we lost flag due to some optimization
1233 and may emit call args incorrectly. */
1234 gcc_assert (CALL_WITH_BOUNDS_P (exp
));
1236 /* For structures look for the next available pointer. */
1237 if (ptr_arg
!= -1 && slots
)
1239 unsigned bnd_no
= bitmap_first_set_bit (slots
);
1240 args
[j
].pointer_offset
=
1241 bnd_no
* POINTER_SIZE
/ BITS_PER_UNIT
;
1243 bitmap_clear_bit (slots
, bnd_no
);
1245 /* Check we have no more pointers in the structure. */
1246 if (bitmap_empty_p (slots
))
1247 BITMAP_FREE (slots
);
1249 args
[j
].pointer_arg
= ptr_arg
;
1251 /* Check we covered all pointers in the previous
1259 if (targetm
.calls
.split_complex_arg
1261 && TREE_CODE (argtype
) == COMPLEX_TYPE
1262 && targetm
.calls
.split_complex_arg (argtype
))
1264 tree subtype
= TREE_TYPE (argtype
);
1265 args
[j
].tree_value
= build1 (REALPART_EXPR
, subtype
, arg
);
1267 args
[j
].tree_value
= build1 (IMAGPART_EXPR
, subtype
, arg
);
1270 args
[j
].tree_value
= arg
;
1275 BITMAP_FREE (slots
);
1278 bitmap_obstack_release (NULL
);
1280 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1281 for (argpos
= 0; argpos
< num_actuals
; i
--, argpos
++)
1283 tree type
= TREE_TYPE (args
[i
].tree_value
);
1287 /* Replace erroneous argument with constant zero. */
1288 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
1289 args
[i
].tree_value
= integer_zero_node
, type
= integer_type_node
;
1291 /* If TYPE is a transparent union or record, pass things the way
1292 we would pass the first field of the union or record. We have
1293 already verified that the modes are the same. */
1294 if ((TREE_CODE (type
) == UNION_TYPE
|| TREE_CODE (type
) == RECORD_TYPE
)
1295 && TYPE_TRANSPARENT_AGGR (type
))
1296 type
= TREE_TYPE (first_field (type
));
1298 /* Decide where to pass this arg.
1300 args[i].reg is nonzero if all or part is passed in registers.
1302 args[i].partial is nonzero if part but not all is passed in registers,
1303 and the exact value says how many bytes are passed in registers.
1305 args[i].pass_on_stack is nonzero if the argument must at least be
1306 computed on the stack. It may then be loaded back into registers
1307 if args[i].reg is nonzero.
1309 These decisions are driven by the FUNCTION_... macros and must agree
1310 with those made by function.c. */
1312 /* See if this argument should be passed by invisible reference. */
1313 if (pass_by_reference (args_so_far_pnt
, TYPE_MODE (type
),
1314 type
, argpos
< n_named_args
))
1317 tree base
= NULL_TREE
;
1320 = reference_callee_copied (args_so_far_pnt
, TYPE_MODE (type
),
1321 type
, argpos
< n_named_args
);
1323 /* If we're compiling a thunk, pass through invisible references
1324 instead of making a copy. */
1325 if (call_from_thunk_p
1327 && !TREE_ADDRESSABLE (type
)
1328 && (base
= get_base_address (args
[i
].tree_value
))
1329 && TREE_CODE (base
) != SSA_NAME
1330 && (!DECL_P (base
) || MEM_P (DECL_RTL (base
)))))
1332 /* We may have turned the parameter value into an SSA name.
1333 Go back to the original parameter so we can take the
1335 if (TREE_CODE (args
[i
].tree_value
) == SSA_NAME
)
1337 gcc_assert (SSA_NAME_IS_DEFAULT_DEF (args
[i
].tree_value
));
1338 args
[i
].tree_value
= SSA_NAME_VAR (args
[i
].tree_value
);
1339 gcc_assert (TREE_CODE (args
[i
].tree_value
) == PARM_DECL
);
1341 /* Argument setup code may have copied the value to register. We
1342 revert that optimization now because the tail call code must
1343 use the original location. */
1344 if (TREE_CODE (args
[i
].tree_value
) == PARM_DECL
1345 && !MEM_P (DECL_RTL (args
[i
].tree_value
))
1346 && DECL_INCOMING_RTL (args
[i
].tree_value
)
1347 && MEM_P (DECL_INCOMING_RTL (args
[i
].tree_value
)))
1348 set_decl_rtl (args
[i
].tree_value
,
1349 DECL_INCOMING_RTL (args
[i
].tree_value
));
1351 mark_addressable (args
[i
].tree_value
);
1353 /* We can't use sibcalls if a callee-copied argument is
1354 stored in the current function's frame. */
1355 if (!call_from_thunk_p
&& DECL_P (base
) && !TREE_STATIC (base
))
1356 *may_tailcall
= false;
1358 args
[i
].tree_value
= build_fold_addr_expr_loc (loc
,
1359 args
[i
].tree_value
);
1360 type
= TREE_TYPE (args
[i
].tree_value
);
1362 if (*ecf_flags
& ECF_CONST
)
1363 *ecf_flags
&= ~(ECF_CONST
| ECF_LOOPING_CONST_OR_PURE
);
1367 /* We make a copy of the object and pass the address to the
1368 function being called. */
1371 if (!COMPLETE_TYPE_P (type
)
1372 || TREE_CODE (TYPE_SIZE_UNIT (type
)) != INTEGER_CST
1373 || (flag_stack_check
== GENERIC_STACK_CHECK
1374 && compare_tree_int (TYPE_SIZE_UNIT (type
),
1375 STACK_CHECK_MAX_VAR_SIZE
) > 0))
1377 /* This is a variable-sized object. Make space on the stack
1379 rtx size_rtx
= expr_size (args
[i
].tree_value
);
1381 if (*old_stack_level
== 0)
1383 emit_stack_save (SAVE_BLOCK
, old_stack_level
);
1384 *old_pending_adj
= pending_stack_adjust
;
1385 pending_stack_adjust
= 0;
1388 /* We can pass TRUE as the 4th argument because we just
1389 saved the stack pointer and will restore it right after
1391 copy
= allocate_dynamic_stack_space (size_rtx
,
1395 copy
= gen_rtx_MEM (BLKmode
, copy
);
1396 set_mem_attributes (copy
, type
, 1);
1399 copy
= assign_temp (type
, 1, 0);
1401 store_expr (args
[i
].tree_value
, copy
, 0, false);
1403 /* Just change the const function to pure and then let
1404 the next test clear the pure based on
1406 if (*ecf_flags
& ECF_CONST
)
1408 *ecf_flags
&= ~ECF_CONST
;
1409 *ecf_flags
|= ECF_PURE
;
1412 if (!callee_copies
&& *ecf_flags
& ECF_PURE
)
1413 *ecf_flags
&= ~(ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
1416 = build_fold_addr_expr_loc (loc
, make_tree (type
, copy
));
1417 type
= TREE_TYPE (args
[i
].tree_value
);
1418 *may_tailcall
= false;
1422 unsignedp
= TYPE_UNSIGNED (type
);
1423 mode
= promote_function_mode (type
, TYPE_MODE (type
), &unsignedp
,
1424 fndecl
? TREE_TYPE (fndecl
) : fntype
, 0);
1426 args
[i
].unsignedp
= unsignedp
;
1427 args
[i
].mode
= mode
;
1429 args
[i
].reg
= targetm
.calls
.function_arg (args_so_far
, mode
, type
,
1430 argpos
< n_named_args
);
1432 if (args
[i
].reg
&& CONST_INT_P (args
[i
].reg
))
1434 args
[i
].special_slot
= args
[i
].reg
;
1438 /* If this is a sibling call and the machine has register windows, the
1439 register window has to be unwinded before calling the routine, so
1440 arguments have to go into the incoming registers. */
1441 if (targetm
.calls
.function_incoming_arg
!= targetm
.calls
.function_arg
)
1442 args
[i
].tail_call_reg
1443 = targetm
.calls
.function_incoming_arg (args_so_far
, mode
, type
,
1444 argpos
< n_named_args
);
1446 args
[i
].tail_call_reg
= args
[i
].reg
;
1450 = targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, type
,
1451 argpos
< n_named_args
);
1453 args
[i
].pass_on_stack
= targetm
.calls
.must_pass_in_stack (mode
, type
);
1455 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1456 it means that we are to pass this arg in the register(s) designated
1457 by the PARALLEL, but also to pass it in the stack. */
1458 if (args
[i
].reg
&& GET_CODE (args
[i
].reg
) == PARALLEL
1459 && XEXP (XVECEXP (args
[i
].reg
, 0, 0), 0) == 0)
1460 args
[i
].pass_on_stack
= 1;
1462 /* If this is an addressable type, we must preallocate the stack
1463 since we must evaluate the object into its final location.
1465 If this is to be passed in both registers and the stack, it is simpler
1467 if (TREE_ADDRESSABLE (type
)
1468 || (args
[i
].pass_on_stack
&& args
[i
].reg
!= 0))
1469 *must_preallocate
= 1;
1471 /* No stack allocation and padding for bounds. */
1472 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
1474 /* Compute the stack-size of this argument. */
1475 else if (args
[i
].reg
== 0 || args
[i
].partial
!= 0
1476 || reg_parm_stack_space
> 0
1477 || args
[i
].pass_on_stack
)
1478 locate_and_pad_parm (mode
, type
,
1479 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1484 reg_parm_stack_space
,
1485 args
[i
].pass_on_stack
? 0 : args
[i
].partial
,
1486 fndecl
, args_size
, &args
[i
].locate
);
1487 #ifdef BLOCK_REG_PADDING
1489 /* The argument is passed entirely in registers. See at which
1490 end it should be padded. */
1491 args
[i
].locate
.where_pad
=
1492 BLOCK_REG_PADDING (mode
, type
,
1493 int_size_in_bytes (type
) <= UNITS_PER_WORD
);
1496 /* Update ARGS_SIZE, the total stack space for args so far. */
1498 args_size
->constant
+= args
[i
].locate
.size
.constant
;
1499 if (args
[i
].locate
.size
.var
)
1500 ADD_PARM_SIZE (*args_size
, args
[i
].locate
.size
.var
);
1502 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1503 have been used, etc. */
1505 targetm
.calls
.function_arg_advance (args_so_far
, TYPE_MODE (type
),
1506 type
, argpos
< n_named_args
);
1510 /* Update ARGS_SIZE to contain the total size for the argument block.
1511 Return the original constant component of the argument block's size.
1513 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1514 for arguments passed in registers. */
1517 compute_argument_block_size (int reg_parm_stack_space
,
1518 struct args_size
*args_size
,
1519 tree fndecl ATTRIBUTE_UNUSED
,
1520 tree fntype ATTRIBUTE_UNUSED
,
1521 int preferred_stack_boundary ATTRIBUTE_UNUSED
)
1523 int unadjusted_args_size
= args_size
->constant
;
1525 /* For accumulate outgoing args mode we don't need to align, since the frame
1526 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1527 backends from generating misaligned frame sizes. */
1528 if (ACCUMULATE_OUTGOING_ARGS
&& preferred_stack_boundary
> STACK_BOUNDARY
)
1529 preferred_stack_boundary
= STACK_BOUNDARY
;
1531 /* Compute the actual size of the argument block required. The variable
1532 and constant sizes must be combined, the size may have to be rounded,
1533 and there may be a minimum required size. */
1537 args_size
->var
= ARGS_SIZE_TREE (*args_size
);
1538 args_size
->constant
= 0;
1540 preferred_stack_boundary
/= BITS_PER_UNIT
;
1541 if (preferred_stack_boundary
> 1)
1543 /* We don't handle this case yet. To handle it correctly we have
1544 to add the delta, round and subtract the delta.
1545 Currently no machine description requires this support. */
1546 gcc_assert (!(stack_pointer_delta
& (preferred_stack_boundary
- 1)));
1547 args_size
->var
= round_up (args_size
->var
, preferred_stack_boundary
);
1550 if (reg_parm_stack_space
> 0)
1553 = size_binop (MAX_EXPR
, args_size
->var
,
1554 ssize_int (reg_parm_stack_space
));
1556 /* The area corresponding to register parameters is not to count in
1557 the size of the block we need. So make the adjustment. */
1558 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
1560 = size_binop (MINUS_EXPR
, args_size
->var
,
1561 ssize_int (reg_parm_stack_space
));
1566 preferred_stack_boundary
/= BITS_PER_UNIT
;
1567 if (preferred_stack_boundary
< 1)
1568 preferred_stack_boundary
= 1;
1569 args_size
->constant
= (((args_size
->constant
1570 + stack_pointer_delta
1571 + preferred_stack_boundary
- 1)
1572 / preferred_stack_boundary
1573 * preferred_stack_boundary
)
1574 - stack_pointer_delta
);
1576 args_size
->constant
= MAX (args_size
->constant
,
1577 reg_parm_stack_space
);
1579 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
1580 args_size
->constant
-= reg_parm_stack_space
;
1582 return unadjusted_args_size
;
1585 /* Precompute parameters as needed for a function call.
1587 FLAGS is mask of ECF_* constants.
1589 NUM_ACTUALS is the number of arguments.
1591 ARGS is an array containing information for each argument; this
1592 routine fills in the INITIAL_VALUE and VALUE fields for each
1593 precomputed argument. */
1596 precompute_arguments (int num_actuals
, struct arg_data
*args
)
1600 /* If this is a libcall, then precompute all arguments so that we do not
1601 get extraneous instructions emitted as part of the libcall sequence. */
1603 /* If we preallocated the stack space, and some arguments must be passed
1604 on the stack, then we must precompute any parameter which contains a
1605 function call which will store arguments on the stack.
1606 Otherwise, evaluating the parameter may clobber previous parameters
1607 which have already been stored into the stack. (we have code to avoid
1608 such case by saving the outgoing stack arguments, but it results in
1610 if (!ACCUMULATE_OUTGOING_ARGS
)
1613 for (i
= 0; i
< num_actuals
; i
++)
1618 if (TREE_CODE (args
[i
].tree_value
) != CALL_EXPR
)
1621 /* If this is an addressable type, we cannot pre-evaluate it. */
1622 type
= TREE_TYPE (args
[i
].tree_value
);
1623 gcc_assert (!TREE_ADDRESSABLE (type
));
1625 args
[i
].initial_value
= args
[i
].value
1626 = expand_normal (args
[i
].tree_value
);
1628 mode
= TYPE_MODE (type
);
1629 if (mode
!= args
[i
].mode
)
1631 int unsignedp
= args
[i
].unsignedp
;
1633 = convert_modes (args
[i
].mode
, mode
,
1634 args
[i
].value
, args
[i
].unsignedp
);
1636 /* CSE will replace this only if it contains args[i].value
1637 pseudo, so convert it down to the declared mode using
1639 if (REG_P (args
[i
].value
)
1640 && GET_MODE_CLASS (args
[i
].mode
) == MODE_INT
1641 && promote_mode (type
, mode
, &unsignedp
) != args
[i
].mode
)
1643 args
[i
].initial_value
1644 = gen_lowpart_SUBREG (mode
, args
[i
].value
);
1645 SUBREG_PROMOTED_VAR_P (args
[i
].initial_value
) = 1;
1646 SUBREG_PROMOTED_SET (args
[i
].initial_value
, args
[i
].unsignedp
);
1652 /* Given the current state of MUST_PREALLOCATE and information about
1653 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1654 compute and return the final value for MUST_PREALLOCATE. */
1657 finalize_must_preallocate (int must_preallocate
, int num_actuals
,
1658 struct arg_data
*args
, struct args_size
*args_size
)
1660 /* See if we have or want to preallocate stack space.
1662 If we would have to push a partially-in-regs parm
1663 before other stack parms, preallocate stack space instead.
1665 If the size of some parm is not a multiple of the required stack
1666 alignment, we must preallocate.
1668 If the total size of arguments that would otherwise create a copy in
1669 a temporary (such as a CALL) is more than half the total argument list
1670 size, preallocation is faster.
1672 Another reason to preallocate is if we have a machine (like the m88k)
1673 where stack alignment is required to be maintained between every
1674 pair of insns, not just when the call is made. However, we assume here
1675 that such machines either do not have push insns (and hence preallocation
1676 would occur anyway) or the problem is taken care of with
1679 if (! must_preallocate
)
1681 int partial_seen
= 0;
1682 int copy_to_evaluate_size
= 0;
1685 for (i
= 0; i
< num_actuals
&& ! must_preallocate
; i
++)
1687 if (args
[i
].partial
> 0 && ! args
[i
].pass_on_stack
)
1689 else if (partial_seen
&& args
[i
].reg
== 0)
1690 must_preallocate
= 1;
1691 /* We preallocate in case there are bounds passed
1692 in the bounds table to have precomputed address
1693 for bounds association. */
1694 else if (POINTER_BOUNDS_P (args
[i
].tree_value
)
1696 must_preallocate
= 1;
1698 if (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)) == BLKmode
1699 && (TREE_CODE (args
[i
].tree_value
) == CALL_EXPR
1700 || TREE_CODE (args
[i
].tree_value
) == TARGET_EXPR
1701 || TREE_CODE (args
[i
].tree_value
) == COND_EXPR
1702 || TREE_ADDRESSABLE (TREE_TYPE (args
[i
].tree_value
))))
1703 copy_to_evaluate_size
1704 += int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
1707 if (copy_to_evaluate_size
* 2 >= args_size
->constant
1708 && args_size
->constant
> 0)
1709 must_preallocate
= 1;
1711 return must_preallocate
;
1714 /* If we preallocated stack space, compute the address of each argument
1715 and store it into the ARGS array.
1717 We need not ensure it is a valid memory address here; it will be
1718 validized when it is used.
1720 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1723 compute_argument_addresses (struct arg_data
*args
, rtx argblock
, int num_actuals
)
1727 rtx arg_reg
= argblock
;
1728 int i
, arg_offset
= 0;
1730 if (GET_CODE (argblock
) == PLUS
)
1731 arg_reg
= XEXP (argblock
, 0), arg_offset
= INTVAL (XEXP (argblock
, 1));
1733 for (i
= 0; i
< num_actuals
; i
++)
1735 rtx offset
= ARGS_SIZE_RTX (args
[i
].locate
.offset
);
1736 rtx slot_offset
= ARGS_SIZE_RTX (args
[i
].locate
.slot_offset
);
1738 unsigned int align
, boundary
;
1739 unsigned int units_on_stack
= 0;
1740 machine_mode partial_mode
= VOIDmode
;
1742 /* Skip this parm if it will not be passed on the stack. */
1743 if (! args
[i
].pass_on_stack
1745 && args
[i
].partial
== 0)
1748 /* Pointer Bounds are never passed on the stack. */
1749 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
1752 if (CONST_INT_P (offset
))
1753 addr
= plus_constant (Pmode
, arg_reg
, INTVAL (offset
));
1755 addr
= gen_rtx_PLUS (Pmode
, arg_reg
, offset
);
1757 addr
= plus_constant (Pmode
, addr
, arg_offset
);
1759 if (args
[i
].partial
!= 0)
1761 /* Only part of the parameter is being passed on the stack.
1762 Generate a simple memory reference of the correct size. */
1763 units_on_stack
= args
[i
].locate
.size
.constant
;
1764 partial_mode
= mode_for_size (units_on_stack
* BITS_PER_UNIT
,
1766 args
[i
].stack
= gen_rtx_MEM (partial_mode
, addr
);
1767 set_mem_size (args
[i
].stack
, units_on_stack
);
1771 args
[i
].stack
= gen_rtx_MEM (args
[i
].mode
, addr
);
1772 set_mem_attributes (args
[i
].stack
,
1773 TREE_TYPE (args
[i
].tree_value
), 1);
1775 align
= BITS_PER_UNIT
;
1776 boundary
= args
[i
].locate
.boundary
;
1777 if (args
[i
].locate
.where_pad
!= downward
)
1779 else if (CONST_INT_P (offset
))
1781 align
= INTVAL (offset
) * BITS_PER_UNIT
| boundary
;
1782 align
= align
& -align
;
1784 set_mem_align (args
[i
].stack
, align
);
1786 if (CONST_INT_P (slot_offset
))
1787 addr
= plus_constant (Pmode
, arg_reg
, INTVAL (slot_offset
));
1789 addr
= gen_rtx_PLUS (Pmode
, arg_reg
, slot_offset
);
1791 addr
= plus_constant (Pmode
, addr
, arg_offset
);
1793 if (args
[i
].partial
!= 0)
1795 /* Only part of the parameter is being passed on the stack.
1796 Generate a simple memory reference of the correct size.
1798 args
[i
].stack_slot
= gen_rtx_MEM (partial_mode
, addr
);
1799 set_mem_size (args
[i
].stack_slot
, units_on_stack
);
1803 args
[i
].stack_slot
= gen_rtx_MEM (args
[i
].mode
, addr
);
1804 set_mem_attributes (args
[i
].stack_slot
,
1805 TREE_TYPE (args
[i
].tree_value
), 1);
1807 set_mem_align (args
[i
].stack_slot
, args
[i
].locate
.boundary
);
1809 /* Function incoming arguments may overlap with sibling call
1810 outgoing arguments and we cannot allow reordering of reads
1811 from function arguments with stores to outgoing arguments
1812 of sibling calls. */
1813 set_mem_alias_set (args
[i
].stack
, 0);
1814 set_mem_alias_set (args
[i
].stack_slot
, 0);
1819 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1820 in a call instruction.
1822 FNDECL is the tree node for the target function. For an indirect call
1823 FNDECL will be NULL_TREE.
1825 ADDR is the operand 0 of CALL_EXPR for this call. */
1828 rtx_for_function_call (tree fndecl
, tree addr
)
1832 /* Get the function to call, in the form of RTL. */
1835 if (!TREE_USED (fndecl
) && fndecl
!= current_function_decl
)
1836 TREE_USED (fndecl
) = 1;
1838 /* Get a SYMBOL_REF rtx for the function address. */
1839 funexp
= XEXP (DECL_RTL (fndecl
), 0);
1842 /* Generate an rtx (probably a pseudo-register) for the address. */
1845 funexp
= expand_normal (addr
);
1846 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1851 /* Internal state for internal_arg_pointer_based_exp and its helpers. */
1854 /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan,
1855 or NULL_RTX if none has been scanned yet. */
1856 rtx_insn
*scan_start
;
1857 /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is
1858 based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the
1859 pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it
1860 with fixed offset, or PC if this is with variable or unknown offset. */
1862 } internal_arg_pointer_exp_state
;
1864 static rtx
internal_arg_pointer_based_exp (const_rtx
, bool);
1866 /* Helper function for internal_arg_pointer_based_exp. Scan insns in
1867 the tail call sequence, starting with first insn that hasn't been
1868 scanned yet, and note for each pseudo on the LHS whether it is based
1869 on crtl->args.internal_arg_pointer or not, and what offset from that
1870 that pointer it has. */
1873 internal_arg_pointer_based_exp_scan (void)
1875 rtx_insn
*insn
, *scan_start
= internal_arg_pointer_exp_state
.scan_start
;
1877 if (scan_start
== NULL_RTX
)
1878 insn
= get_insns ();
1880 insn
= NEXT_INSN (scan_start
);
1884 rtx set
= single_set (insn
);
1885 if (set
&& REG_P (SET_DEST (set
)) && !HARD_REGISTER_P (SET_DEST (set
)))
1888 unsigned int idx
= REGNO (SET_DEST (set
)) - FIRST_PSEUDO_REGISTER
;
1889 /* Punt on pseudos set multiple times. */
1890 if (idx
< internal_arg_pointer_exp_state
.cache
.length ()
1891 && (internal_arg_pointer_exp_state
.cache
[idx
]
1895 val
= internal_arg_pointer_based_exp (SET_SRC (set
), false);
1896 if (val
!= NULL_RTX
)
1898 if (idx
>= internal_arg_pointer_exp_state
.cache
.length ())
1899 internal_arg_pointer_exp_state
.cache
1900 .safe_grow_cleared (idx
+ 1);
1901 internal_arg_pointer_exp_state
.cache
[idx
] = val
;
1904 if (NEXT_INSN (insn
) == NULL_RTX
)
1906 insn
= NEXT_INSN (insn
);
1909 internal_arg_pointer_exp_state
.scan_start
= scan_start
;
1912 /* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return
1913 NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on
1914 it with fixed offset, or PC if this is with variable or unknown offset.
1915 TOPLEVEL is true if the function is invoked at the topmost level. */
1918 internal_arg_pointer_based_exp (const_rtx rtl
, bool toplevel
)
1920 if (CONSTANT_P (rtl
))
1923 if (rtl
== crtl
->args
.internal_arg_pointer
)
1926 if (REG_P (rtl
) && HARD_REGISTER_P (rtl
))
1929 if (GET_CODE (rtl
) == PLUS
&& CONST_INT_P (XEXP (rtl
, 1)))
1931 rtx val
= internal_arg_pointer_based_exp (XEXP (rtl
, 0), toplevel
);
1932 if (val
== NULL_RTX
|| val
== pc_rtx
)
1934 return plus_constant (Pmode
, val
, INTVAL (XEXP (rtl
, 1)));
1937 /* When called at the topmost level, scan pseudo assignments in between the
1938 last scanned instruction in the tail call sequence and the latest insn
1939 in that sequence. */
1941 internal_arg_pointer_based_exp_scan ();
1945 unsigned int idx
= REGNO (rtl
) - FIRST_PSEUDO_REGISTER
;
1946 if (idx
< internal_arg_pointer_exp_state
.cache
.length ())
1947 return internal_arg_pointer_exp_state
.cache
[idx
];
1952 subrtx_iterator::array_type array
;
1953 FOR_EACH_SUBRTX (iter
, array
, rtl
, NONCONST
)
1955 const_rtx x
= *iter
;
1956 if (REG_P (x
) && internal_arg_pointer_based_exp (x
, false) != NULL_RTX
)
1959 iter
.skip_subrtxes ();
1965 /* Return true if and only if SIZE storage units (usually bytes)
1966 starting from address ADDR overlap with already clobbered argument
1967 area. This function is used to determine if we should give up a
1971 mem_overlaps_already_clobbered_arg_p (rtx addr
, unsigned HOST_WIDE_INT size
)
1976 if (bitmap_empty_p (stored_args_map
))
1978 val
= internal_arg_pointer_based_exp (addr
, true);
1979 if (val
== NULL_RTX
)
1981 else if (val
== pc_rtx
)
1986 if (STACK_GROWS_DOWNWARD
)
1987 i
-= crtl
->args
.pretend_args_size
;
1989 i
+= crtl
->args
.pretend_args_size
;
1992 if (ARGS_GROW_DOWNWARD
)
1997 unsigned HOST_WIDE_INT k
;
1999 for (k
= 0; k
< size
; k
++)
2000 if (i
+ k
< SBITMAP_SIZE (stored_args_map
)
2001 && bitmap_bit_p (stored_args_map
, i
+ k
))
2008 /* Do the register loads required for any wholly-register parms or any
2009 parms which are passed both on the stack and in a register. Their
2010 expressions were already evaluated.
2012 Mark all register-parms as living through the call, putting these USE
2013 insns in the CALL_INSN_FUNCTION_USAGE field.
2015 When IS_SIBCALL, perform the check_sibcall_argument_overlap
2016 checking, setting *SIBCALL_FAILURE if appropriate. */
2019 load_register_parameters (struct arg_data
*args
, int num_actuals
,
2020 rtx
*call_fusage
, int flags
, int is_sibcall
,
2021 int *sibcall_failure
)
2025 for (i
= 0; i
< num_actuals
; i
++)
2027 rtx reg
= ((flags
& ECF_SIBCALL
)
2028 ? args
[i
].tail_call_reg
: args
[i
].reg
);
2031 int partial
= args
[i
].partial
;
2034 rtx_insn
*before_arg
= get_last_insn ();
2035 /* Set non-negative if we must move a word at a time, even if
2036 just one word (e.g, partial == 4 && mode == DFmode). Set
2037 to -1 if we just use a normal move insn. This value can be
2038 zero if the argument is a zero size structure. */
2040 if (GET_CODE (reg
) == PARALLEL
)
2044 gcc_assert (partial
% UNITS_PER_WORD
== 0);
2045 nregs
= partial
/ UNITS_PER_WORD
;
2047 else if (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)) == BLKmode
)
2049 size
= int_size_in_bytes (TREE_TYPE (args
[i
].tree_value
));
2050 nregs
= (size
+ (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
2053 size
= GET_MODE_SIZE (args
[i
].mode
);
2055 /* Handle calls that pass values in multiple non-contiguous
2056 locations. The Irix 6 ABI has examples of this. */
2058 if (GET_CODE (reg
) == PARALLEL
)
2059 emit_group_move (reg
, args
[i
].parallel_value
);
2061 /* If simple case, just do move. If normal partial, store_one_arg
2062 has already loaded the register for us. In all other cases,
2063 load the register(s) from memory. */
2065 else if (nregs
== -1)
2067 emit_move_insn (reg
, args
[i
].value
);
2068 #ifdef BLOCK_REG_PADDING
2069 /* Handle case where we have a value that needs shifting
2070 up to the msb. eg. a QImode value and we're padding
2071 upward on a BYTES_BIG_ENDIAN machine. */
2072 if (size
< UNITS_PER_WORD
2073 && (args
[i
].locate
.where_pad
2074 == (BYTES_BIG_ENDIAN
? upward
: downward
)))
2077 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
2079 /* Assigning REG here rather than a temp makes CALL_FUSAGE
2080 report the whole reg as used. Strictly speaking, the
2081 call only uses SIZE bytes at the msb end, but it doesn't
2082 seem worth generating rtl to say that. */
2083 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
2084 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, shift
, reg
, 1);
2086 emit_move_insn (reg
, x
);
2091 /* If we have pre-computed the values to put in the registers in
2092 the case of non-aligned structures, copy them in now. */
2094 else if (args
[i
].n_aligned_regs
!= 0)
2095 for (j
= 0; j
< args
[i
].n_aligned_regs
; j
++)
2096 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
) + j
),
2097 args
[i
].aligned_regs
[j
]);
2099 else if (partial
== 0 || args
[i
].pass_on_stack
)
2101 rtx mem
= validize_mem (copy_rtx (args
[i
].value
));
2103 /* Check for overlap with already clobbered argument area,
2104 providing that this has non-zero size. */
2107 || mem_overlaps_already_clobbered_arg_p
2108 (XEXP (args
[i
].value
, 0), size
)))
2109 *sibcall_failure
= 1;
2111 if (size
% UNITS_PER_WORD
== 0
2112 || MEM_ALIGN (mem
) % BITS_PER_WORD
== 0)
2113 move_block_to_reg (REGNO (reg
), mem
, nregs
, args
[i
].mode
);
2117 move_block_to_reg (REGNO (reg
), mem
, nregs
- 1,
2119 rtx dest
= gen_rtx_REG (word_mode
, REGNO (reg
) + nregs
- 1);
2120 unsigned int bitoff
= (nregs
- 1) * BITS_PER_WORD
;
2121 unsigned int bitsize
= size
* BITS_PER_UNIT
- bitoff
;
2122 rtx x
= extract_bit_field (mem
, bitsize
, bitoff
, 1,
2123 dest
, word_mode
, word_mode
);
2124 if (BYTES_BIG_ENDIAN
)
2125 x
= expand_shift (LSHIFT_EXPR
, word_mode
, x
,
2126 BITS_PER_WORD
- bitsize
, dest
, 1);
2128 emit_move_insn (dest
, x
);
2131 /* Handle a BLKmode that needs shifting. */
2132 if (nregs
== 1 && size
< UNITS_PER_WORD
2133 #ifdef BLOCK_REG_PADDING
2134 && args
[i
].locate
.where_pad
== downward
2140 rtx dest
= gen_rtx_REG (word_mode
, REGNO (reg
));
2141 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
2142 enum tree_code dir
= (BYTES_BIG_ENDIAN
2143 ? RSHIFT_EXPR
: LSHIFT_EXPR
);
2146 x
= expand_shift (dir
, word_mode
, dest
, shift
, dest
, 1);
2148 emit_move_insn (dest
, x
);
2152 /* When a parameter is a block, and perhaps in other cases, it is
2153 possible that it did a load from an argument slot that was
2154 already clobbered. */
2156 && check_sibcall_argument_overlap (before_arg
, &args
[i
], 0))
2157 *sibcall_failure
= 1;
2159 /* Handle calls that pass values in multiple non-contiguous
2160 locations. The Irix 6 ABI has examples of this. */
2161 if (GET_CODE (reg
) == PARALLEL
)
2162 use_group_regs (call_fusage
, reg
);
2163 else if (nregs
== -1)
2164 use_reg_mode (call_fusage
, reg
,
2165 TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)));
2167 use_regs (call_fusage
, REGNO (reg
), nregs
);
2172 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
2173 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
2174 bytes, then we would need to push some additional bytes to pad the
2175 arguments. So, we compute an adjust to the stack pointer for an
2176 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
2177 bytes. Then, when the arguments are pushed the stack will be perfectly
2178 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
2179 be popped after the call. Returns the adjustment. */
2182 combine_pending_stack_adjustment_and_call (int unadjusted_args_size
,
2183 struct args_size
*args_size
,
2184 unsigned int preferred_unit_stack_boundary
)
2186 /* The number of bytes to pop so that the stack will be
2187 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
2188 HOST_WIDE_INT adjustment
;
2189 /* The alignment of the stack after the arguments are pushed, if we
2190 just pushed the arguments without adjust the stack here. */
2191 unsigned HOST_WIDE_INT unadjusted_alignment
;
2193 unadjusted_alignment
2194 = ((stack_pointer_delta
+ unadjusted_args_size
)
2195 % preferred_unit_stack_boundary
);
2197 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
2198 as possible -- leaving just enough left to cancel out the
2199 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
2200 PENDING_STACK_ADJUST is non-negative, and congruent to
2201 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
2203 /* Begin by trying to pop all the bytes. */
2204 unadjusted_alignment
2205 = (unadjusted_alignment
2206 - (pending_stack_adjust
% preferred_unit_stack_boundary
));
2207 adjustment
= pending_stack_adjust
;
2208 /* Push enough additional bytes that the stack will be aligned
2209 after the arguments are pushed. */
2210 if (preferred_unit_stack_boundary
> 1)
2212 if (unadjusted_alignment
> 0)
2213 adjustment
-= preferred_unit_stack_boundary
- unadjusted_alignment
;
2215 adjustment
+= unadjusted_alignment
;
2218 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
2219 bytes after the call. The right number is the entire
2220 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
2221 by the arguments in the first place. */
2223 = pending_stack_adjust
- adjustment
+ unadjusted_args_size
;
2228 /* Scan X expression if it does not dereference any argument slots
2229 we already clobbered by tail call arguments (as noted in stored_args_map
2231 Return nonzero if X expression dereferences such argument slots,
2235 check_sibcall_argument_overlap_1 (rtx x
)
2244 code
= GET_CODE (x
);
2246 /* We need not check the operands of the CALL expression itself. */
2251 return mem_overlaps_already_clobbered_arg_p (XEXP (x
, 0),
2252 GET_MODE_SIZE (GET_MODE (x
)));
2254 /* Scan all subexpressions. */
2255 fmt
= GET_RTX_FORMAT (code
);
2256 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
2260 if (check_sibcall_argument_overlap_1 (XEXP (x
, i
)))
2263 else if (*fmt
== 'E')
2265 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2266 if (check_sibcall_argument_overlap_1 (XVECEXP (x
, i
, j
)))
2273 /* Scan sequence after INSN if it does not dereference any argument slots
2274 we already clobbered by tail call arguments (as noted in stored_args_map
2275 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
2276 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
2277 should be 0). Return nonzero if sequence after INSN dereferences such argument
2278 slots, zero otherwise. */
2281 check_sibcall_argument_overlap (rtx_insn
*insn
, struct arg_data
*arg
,
2282 int mark_stored_args_map
)
2286 if (insn
== NULL_RTX
)
2287 insn
= get_insns ();
2289 insn
= NEXT_INSN (insn
);
2291 for (; insn
; insn
= NEXT_INSN (insn
))
2293 && check_sibcall_argument_overlap_1 (PATTERN (insn
)))
2296 if (mark_stored_args_map
)
2298 if (ARGS_GROW_DOWNWARD
)
2299 low
= -arg
->locate
.slot_offset
.constant
- arg
->locate
.size
.constant
;
2301 low
= arg
->locate
.slot_offset
.constant
;
2303 for (high
= low
+ arg
->locate
.size
.constant
; low
< high
; low
++)
2304 bitmap_set_bit (stored_args_map
, low
);
2306 return insn
!= NULL_RTX
;
2309 /* Given that a function returns a value of mode MODE at the most
2310 significant end of hard register VALUE, shift VALUE left or right
2311 as specified by LEFT_P. Return true if some action was needed. */
2314 shift_return_value (machine_mode mode
, bool left_p
, rtx value
)
2316 HOST_WIDE_INT shift
;
2318 gcc_assert (REG_P (value
) && HARD_REGISTER_P (value
));
2319 shift
= GET_MODE_BITSIZE (GET_MODE (value
)) - GET_MODE_BITSIZE (mode
);
2323 /* Use ashr rather than lshr for right shifts. This is for the benefit
2324 of the MIPS port, which requires SImode values to be sign-extended
2325 when stored in 64-bit registers. */
2326 if (!force_expand_binop (GET_MODE (value
), left_p
? ashl_optab
: ashr_optab
,
2327 value
, GEN_INT (shift
), value
, 1, OPTAB_WIDEN
))
2332 /* If X is a likely-spilled register value, copy it to a pseudo
2333 register and return that register. Return X otherwise. */
2336 avoid_likely_spilled_reg (rtx x
)
2341 && HARD_REGISTER_P (x
)
2342 && targetm
.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x
))))
2344 /* Make sure that we generate a REG rather than a CONCAT.
2345 Moves into CONCATs can need nontrivial instructions,
2346 and the whole point of this function is to avoid
2347 using the hard register directly in such a situation. */
2348 generating_concat_p
= 0;
2349 new_rtx
= gen_reg_rtx (GET_MODE (x
));
2350 generating_concat_p
= 1;
2351 emit_move_insn (new_rtx
, x
);
2357 /* Generate all the code for a CALL_EXPR exp
2358 and return an rtx for its value.
2359 Store the value in TARGET (specified as an rtx) if convenient.
2360 If the value is stored in TARGET then TARGET is returned.
2361 If IGNORE is nonzero, then we ignore the value of the function call. */
2364 expand_call (tree exp
, rtx target
, int ignore
)
2366 /* Nonzero if we are currently expanding a call. */
2367 static int currently_expanding_call
= 0;
2369 /* RTX for the function to be called. */
2371 /* Sequence of insns to perform a normal "call". */
2372 rtx_insn
*normal_call_insns
= NULL
;
2373 /* Sequence of insns to perform a tail "call". */
2374 rtx_insn
*tail_call_insns
= NULL
;
2375 /* Data type of the function. */
2377 tree type_arg_types
;
2379 /* Declaration of the function being called,
2380 or 0 if the function is computed (not known by name). */
2382 /* The type of the function being called. */
2384 bool try_tail_call
= CALL_EXPR_TAILCALL (exp
);
2387 /* Register in which non-BLKmode value will be returned,
2388 or 0 if no value or if value is BLKmode. */
2390 /* Register(s) in which bounds are returned. */
2392 /* Address where we should return a BLKmode value;
2393 0 if value not BLKmode. */
2394 rtx structure_value_addr
= 0;
2395 /* Nonzero if that address is being passed by treating it as
2396 an extra, implicit first parameter. Otherwise,
2397 it is passed by being copied directly into struct_value_rtx. */
2398 int structure_value_addr_parm
= 0;
2399 /* Holds the value of implicit argument for the struct value. */
2400 tree structure_value_addr_value
= NULL_TREE
;
2401 /* Size of aggregate value wanted, or zero if none wanted
2402 or if we are using the non-reentrant PCC calling convention
2403 or expecting the value in registers. */
2404 HOST_WIDE_INT struct_value_size
= 0;
2405 /* Nonzero if called function returns an aggregate in memory PCC style,
2406 by returning the address of where to find it. */
2407 int pcc_struct_value
= 0;
2408 rtx struct_value
= 0;
2410 /* Number of actual parameters in this call, including struct value addr. */
2412 /* Number of named args. Args after this are anonymous ones
2413 and they must all go on the stack. */
2415 /* Number of complex actual arguments that need to be split. */
2416 int num_complex_actuals
= 0;
2418 /* Vector of information about each argument.
2419 Arguments are numbered in the order they will be pushed,
2420 not the order they are written. */
2421 struct arg_data
*args
;
2423 /* Total size in bytes of all the stack-parms scanned so far. */
2424 struct args_size args_size
;
2425 struct args_size adjusted_args_size
;
2426 /* Size of arguments before any adjustments (such as rounding). */
2427 int unadjusted_args_size
;
2428 /* Data on reg parms scanned so far. */
2429 CUMULATIVE_ARGS args_so_far_v
;
2430 cumulative_args_t args_so_far
;
2431 /* Nonzero if a reg parm has been scanned. */
2433 /* Nonzero if this is an indirect function call. */
2435 /* Nonzero if we must avoid push-insns in the args for this call.
2436 If stack space is allocated for register parameters, but not by the
2437 caller, then it is preallocated in the fixed part of the stack frame.
2438 So the entire argument block must then be preallocated (i.e., we
2439 ignore PUSH_ROUNDING in that case). */
2441 int must_preallocate
= !PUSH_ARGS
;
2443 /* Size of the stack reserved for parameter registers. */
2444 int reg_parm_stack_space
= 0;
2446 /* Address of space preallocated for stack parms
2447 (on machines that lack push insns), or 0 if space not preallocated. */
2450 /* Mask of ECF_ and ERF_ flags. */
2452 int return_flags
= 0;
2453 #ifdef REG_PARM_STACK_SPACE
2454 /* Define the boundary of the register parm stack space that needs to be
2456 int low_to_save
, high_to_save
;
2457 rtx save_area
= 0; /* Place that it is saved */
2460 int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
2461 char *initial_stack_usage_map
= stack_usage_map
;
2462 char *stack_usage_map_buf
= NULL
;
2464 int old_stack_allocated
;
2466 /* State variables to track stack modifications. */
2467 rtx old_stack_level
= 0;
2468 int old_stack_arg_under_construction
= 0;
2469 int old_pending_adj
= 0;
2470 int old_inhibit_defer_pop
= inhibit_defer_pop
;
2472 /* Some stack pointer alterations we make are performed via
2473 allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
2474 which we then also need to save/restore along the way. */
2475 int old_stack_pointer_delta
= 0;
2478 tree addr
= CALL_EXPR_FN (exp
);
2480 /* The alignment of the stack, in bits. */
2481 unsigned HOST_WIDE_INT preferred_stack_boundary
;
2482 /* The alignment of the stack, in bytes. */
2483 unsigned HOST_WIDE_INT preferred_unit_stack_boundary
;
2484 /* The static chain value to use for this call. */
2485 rtx static_chain_value
;
2486 /* See if this is "nothrow" function call. */
2487 if (TREE_NOTHROW (exp
))
2488 flags
|= ECF_NOTHROW
;
2490 /* See if we can find a DECL-node for the actual function, and get the
2491 function attributes (flags) from the function decl or type node. */
2492 fndecl
= get_callee_fndecl (exp
);
2495 fntype
= TREE_TYPE (fndecl
);
2496 flags
|= flags_from_decl_or_type (fndecl
);
2497 return_flags
|= decl_return_flags (fndecl
);
2501 fntype
= TREE_TYPE (TREE_TYPE (addr
));
2502 flags
|= flags_from_decl_or_type (fntype
);
2504 rettype
= TREE_TYPE (exp
);
2506 struct_value
= targetm
.calls
.struct_value_rtx (fntype
, 0);
2508 /* Warn if this value is an aggregate type,
2509 regardless of which calling convention we are using for it. */
2510 if (AGGREGATE_TYPE_P (rettype
))
2511 warning (OPT_Waggregate_return
, "function call has aggregate value");
2513 /* If the result of a non looping pure or const function call is
2514 ignored (or void), and none of its arguments are volatile, we can
2515 avoid expanding the call and just evaluate the arguments for
2517 if ((flags
& (ECF_CONST
| ECF_PURE
))
2518 && (!(flags
& ECF_LOOPING_CONST_OR_PURE
))
2519 && (ignore
|| target
== const0_rtx
2520 || TYPE_MODE (rettype
) == VOIDmode
))
2522 bool volatilep
= false;
2524 call_expr_arg_iterator iter
;
2526 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2527 if (TREE_THIS_VOLATILE (arg
))
2535 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2536 expand_expr (arg
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
2541 #ifdef REG_PARM_STACK_SPACE
2542 reg_parm_stack_space
= REG_PARM_STACK_SPACE (!fndecl
? fntype
: fndecl
);
2545 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
)))
2546 && reg_parm_stack_space
> 0 && PUSH_ARGS
)
2547 must_preallocate
= 1;
2549 /* Set up a place to return a structure. */
2551 /* Cater to broken compilers. */
2552 if (aggregate_value_p (exp
, fntype
))
2554 /* This call returns a big structure. */
2555 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
2557 #ifdef PCC_STATIC_STRUCT_RETURN
2559 pcc_struct_value
= 1;
2561 #else /* not PCC_STATIC_STRUCT_RETURN */
2563 struct_value_size
= int_size_in_bytes (rettype
);
2565 /* Even if it is semantically safe to use the target as the return
2566 slot, it may be not sufficiently aligned for the return type. */
2567 if (CALL_EXPR_RETURN_SLOT_OPT (exp
)
2570 && !(MEM_ALIGN (target
) < TYPE_ALIGN (rettype
)
2571 && SLOW_UNALIGNED_ACCESS (TYPE_MODE (rettype
),
2572 MEM_ALIGN (target
))))
2573 structure_value_addr
= XEXP (target
, 0);
2576 /* For variable-sized objects, we must be called with a target
2577 specified. If we were to allocate space on the stack here,
2578 we would have no way of knowing when to free it. */
2579 rtx d
= assign_temp (rettype
, 1, 1);
2580 structure_value_addr
= XEXP (d
, 0);
2584 #endif /* not PCC_STATIC_STRUCT_RETURN */
2587 /* Figure out the amount to which the stack should be aligned. */
2588 preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
2591 struct cgraph_rtl_info
*i
= cgraph_node::rtl_info (fndecl
);
2592 /* Without automatic stack alignment, we can't increase preferred
2593 stack boundary. With automatic stack alignment, it is
2594 unnecessary since unless we can guarantee that all callers will
2595 align the outgoing stack properly, callee has to align its
2598 && i
->preferred_incoming_stack_boundary
2599 && i
->preferred_incoming_stack_boundary
< preferred_stack_boundary
)
2600 preferred_stack_boundary
= i
->preferred_incoming_stack_boundary
;
2603 /* Operand 0 is a pointer-to-function; get the type of the function. */
2604 funtype
= TREE_TYPE (addr
);
2605 gcc_assert (POINTER_TYPE_P (funtype
));
2606 funtype
= TREE_TYPE (funtype
);
2608 /* Count whether there are actual complex arguments that need to be split
2609 into their real and imaginary parts. Munge the type_arg_types
2610 appropriately here as well. */
2611 if (targetm
.calls
.split_complex_arg
)
2613 call_expr_arg_iterator iter
;
2615 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
2617 tree type
= TREE_TYPE (arg
);
2618 if (type
&& TREE_CODE (type
) == COMPLEX_TYPE
2619 && targetm
.calls
.split_complex_arg (type
))
2620 num_complex_actuals
++;
2622 type_arg_types
= split_complex_types (TYPE_ARG_TYPES (funtype
));
2625 type_arg_types
= TYPE_ARG_TYPES (funtype
);
2627 if (flags
& ECF_MAY_BE_ALLOCA
)
2628 cfun
->calls_alloca
= 1;
2630 /* If struct_value_rtx is 0, it means pass the address
2631 as if it were an extra parameter. Put the argument expression
2632 in structure_value_addr_value. */
2633 if (structure_value_addr
&& struct_value
== 0)
2635 /* If structure_value_addr is a REG other than
2636 virtual_outgoing_args_rtx, we can use always use it. If it
2637 is not a REG, we must always copy it into a register.
2638 If it is virtual_outgoing_args_rtx, we must copy it to another
2639 register in some cases. */
2640 rtx temp
= (!REG_P (structure_value_addr
)
2641 || (ACCUMULATE_OUTGOING_ARGS
2642 && stack_arg_under_construction
2643 && structure_value_addr
== virtual_outgoing_args_rtx
)
2644 ? copy_addr_to_reg (convert_memory_address
2645 (Pmode
, structure_value_addr
))
2646 : structure_value_addr
);
2648 structure_value_addr_value
=
2649 make_tree (build_pointer_type (TREE_TYPE (funtype
)), temp
);
2650 structure_value_addr_parm
= CALL_WITH_BOUNDS_P (exp
) ? 2 : 1;
2653 /* Count the arguments and set NUM_ACTUALS. */
2655 call_expr_nargs (exp
) + num_complex_actuals
+ structure_value_addr_parm
;
2657 /* Compute number of named args.
2658 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2660 if (type_arg_types
!= 0)
2662 = (list_length (type_arg_types
)
2663 /* Count the struct value address, if it is passed as a parm. */
2664 + structure_value_addr_parm
);
2666 /* If we know nothing, treat all args as named. */
2667 n_named_args
= num_actuals
;
2669 /* Start updating where the next arg would go.
2671 On some machines (such as the PA) indirect calls have a different
2672 calling convention than normal calls. The fourth argument in
2673 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2675 INIT_CUMULATIVE_ARGS (args_so_far_v
, funtype
, NULL_RTX
, fndecl
, n_named_args
);
2676 args_so_far
= pack_cumulative_args (&args_so_far_v
);
2678 /* Now possibly adjust the number of named args.
2679 Normally, don't include the last named arg if anonymous args follow.
2680 We do include the last named arg if
2681 targetm.calls.strict_argument_naming() returns nonzero.
2682 (If no anonymous args follow, the result of list_length is actually
2683 one too large. This is harmless.)
2685 If targetm.calls.pretend_outgoing_varargs_named() returns
2686 nonzero, and targetm.calls.strict_argument_naming() returns zero,
2687 this machine will be able to place unnamed args that were passed
2688 in registers into the stack. So treat all args as named. This
2689 allows the insns emitting for a specific argument list to be
2690 independent of the function declaration.
2692 If targetm.calls.pretend_outgoing_varargs_named() returns zero,
2693 we do not have any reliable way to pass unnamed args in
2694 registers, so we must force them into memory. */
2696 if (type_arg_types
!= 0
2697 && targetm
.calls
.strict_argument_naming (args_so_far
))
2699 else if (type_arg_types
!= 0
2700 && ! targetm
.calls
.pretend_outgoing_varargs_named (args_so_far
))
2701 /* Don't include the last named arg. */
2704 /* Treat all args as named. */
2705 n_named_args
= num_actuals
;
2707 /* Make a vector to hold all the information about each arg. */
2708 args
= XALLOCAVEC (struct arg_data
, num_actuals
);
2709 memset (args
, 0, num_actuals
* sizeof (struct arg_data
));
2711 /* Build up entries in the ARGS array, compute the size of the
2712 arguments into ARGS_SIZE, etc. */
2713 initialize_argument_information (num_actuals
, args
, &args_size
,
2715 structure_value_addr_value
, fndecl
, fntype
,
2716 args_so_far
, reg_parm_stack_space
,
2717 &old_stack_level
, &old_pending_adj
,
2718 &must_preallocate
, &flags
,
2719 &try_tail_call
, CALL_FROM_THUNK_P (exp
));
2722 must_preallocate
= 1;
2724 /* Now make final decision about preallocating stack space. */
2725 must_preallocate
= finalize_must_preallocate (must_preallocate
,
2729 /* If the structure value address will reference the stack pointer, we
2730 must stabilize it. We don't need to do this if we know that we are
2731 not going to adjust the stack pointer in processing this call. */
2733 if (structure_value_addr
2734 && (reg_mentioned_p (virtual_stack_dynamic_rtx
, structure_value_addr
)
2735 || reg_mentioned_p (virtual_outgoing_args_rtx
,
2736 structure_value_addr
))
2738 || (!ACCUMULATE_OUTGOING_ARGS
&& args_size
.constant
)))
2739 structure_value_addr
= copy_to_reg (structure_value_addr
);
2741 /* Tail calls can make things harder to debug, and we've traditionally
2742 pushed these optimizations into -O2. Don't try if we're already
2743 expanding a call, as that means we're an argument. Don't try if
2744 there's cleanups, as we know there's code to follow the call. */
2746 if (currently_expanding_call
++ != 0
2747 || !flag_optimize_sibling_calls
2749 || dbg_cnt (tail_call
) == false)
2752 /* Rest of purposes for tail call optimizations to fail. */
2754 #ifdef HAVE_sibcall_epilogue
2755 !HAVE_sibcall_epilogue
2760 /* Doing sibling call optimization needs some work, since
2761 structure_value_addr can be allocated on the stack.
2762 It does not seem worth the effort since few optimizable
2763 sibling calls will return a structure. */
2764 || structure_value_addr
!= NULL_RTX
2765 #ifdef REG_PARM_STACK_SPACE
2766 /* If outgoing reg parm stack space changes, we can not do sibcall. */
2767 || (OUTGOING_REG_PARM_STACK_SPACE (funtype
)
2768 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl
)))
2769 || (reg_parm_stack_space
!= REG_PARM_STACK_SPACE (current_function_decl
))
2771 /* Check whether the target is able to optimize the call
2773 || !targetm
.function_ok_for_sibcall (fndecl
, exp
)
2774 /* Functions that do not return exactly once may not be sibcall
2776 || (flags
& (ECF_RETURNS_TWICE
| ECF_NORETURN
))
2777 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr
)))
2778 /* If the called function is nested in the current one, it might access
2779 some of the caller's arguments, but could clobber them beforehand if
2780 the argument areas are shared. */
2781 || (fndecl
&& decl_function_context (fndecl
) == current_function_decl
)
2782 /* If this function requires more stack slots than the current
2783 function, we cannot change it into a sibling call.
2784 crtl->args.pretend_args_size is not part of the
2785 stack allocated by our caller. */
2786 || args_size
.constant
> (crtl
->args
.size
2787 - crtl
->args
.pretend_args_size
)
2788 /* If the callee pops its own arguments, then it must pop exactly
2789 the same number of arguments as the current function. */
2790 || (targetm
.calls
.return_pops_args (fndecl
, funtype
, args_size
.constant
)
2791 != targetm
.calls
.return_pops_args (current_function_decl
,
2792 TREE_TYPE (current_function_decl
),
2794 || !lang_hooks
.decls
.ok_for_sibcall (fndecl
))
2797 /* Check if caller and callee disagree in promotion of function
2801 machine_mode caller_mode
, caller_promoted_mode
;
2802 machine_mode callee_mode
, callee_promoted_mode
;
2803 int caller_unsignedp
, callee_unsignedp
;
2804 tree caller_res
= DECL_RESULT (current_function_decl
);
2806 caller_unsignedp
= TYPE_UNSIGNED (TREE_TYPE (caller_res
));
2807 caller_mode
= DECL_MODE (caller_res
);
2808 callee_unsignedp
= TYPE_UNSIGNED (TREE_TYPE (funtype
));
2809 callee_mode
= TYPE_MODE (TREE_TYPE (funtype
));
2810 caller_promoted_mode
2811 = promote_function_mode (TREE_TYPE (caller_res
), caller_mode
,
2813 TREE_TYPE (current_function_decl
), 1);
2814 callee_promoted_mode
2815 = promote_function_mode (TREE_TYPE (funtype
), callee_mode
,
2818 if (caller_mode
!= VOIDmode
2819 && (caller_promoted_mode
!= callee_promoted_mode
2820 || ((caller_mode
!= caller_promoted_mode
2821 || callee_mode
!= callee_promoted_mode
)
2822 && (caller_unsignedp
!= callee_unsignedp
2823 || GET_MODE_BITSIZE (caller_mode
)
2824 < GET_MODE_BITSIZE (callee_mode
)))))
2828 /* Ensure current function's preferred stack boundary is at least
2829 what we need. Stack alignment may also increase preferred stack
2831 if (crtl
->preferred_stack_boundary
< preferred_stack_boundary
)
2832 crtl
->preferred_stack_boundary
= preferred_stack_boundary
;
2834 preferred_stack_boundary
= crtl
->preferred_stack_boundary
;
2836 preferred_unit_stack_boundary
= preferred_stack_boundary
/ BITS_PER_UNIT
;
2838 /* We want to make two insn chains; one for a sibling call, the other
2839 for a normal call. We will select one of the two chains after
2840 initial RTL generation is complete. */
2841 for (pass
= try_tail_call
? 0 : 1; pass
< 2; pass
++)
2843 int sibcall_failure
= 0;
2844 /* We want to emit any pending stack adjustments before the tail
2845 recursion "call". That way we know any adjustment after the tail
2846 recursion call can be ignored if we indeed use the tail
2848 saved_pending_stack_adjust save
;
2849 rtx_insn
*insns
, *before_call
, *after_args
;
2854 /* State variables we need to save and restore between
2856 save_pending_stack_adjust (&save
);
2859 flags
&= ~ECF_SIBCALL
;
2861 flags
|= ECF_SIBCALL
;
2863 /* Other state variables that we must reinitialize each time
2864 through the loop (that are not initialized by the loop itself). */
2868 /* Start a new sequence for the normal call case.
2870 From this point on, if the sibling call fails, we want to set
2871 sibcall_failure instead of continuing the loop. */
2874 /* Don't let pending stack adjusts add up to too much.
2875 Also, do all pending adjustments now if there is any chance
2876 this might be a call to alloca or if we are expanding a sibling
2878 Also do the adjustments before a throwing call, otherwise
2879 exception handling can fail; PR 19225. */
2880 if (pending_stack_adjust
>= 32
2881 || (pending_stack_adjust
> 0
2882 && (flags
& ECF_MAY_BE_ALLOCA
))
2883 || (pending_stack_adjust
> 0
2884 && flag_exceptions
&& !(flags
& ECF_NOTHROW
))
2886 do_pending_stack_adjust ();
2888 /* Precompute any arguments as needed. */
2890 precompute_arguments (num_actuals
, args
);
2892 /* Now we are about to start emitting insns that can be deleted
2893 if a libcall is deleted. */
2894 if (pass
&& (flags
& ECF_MALLOC
))
2897 if (pass
== 0 && crtl
->stack_protect_guard
)
2898 stack_protect_epilogue ();
2900 adjusted_args_size
= args_size
;
2901 /* Compute the actual size of the argument block required. The variable
2902 and constant sizes must be combined, the size may have to be rounded,
2903 and there may be a minimum required size. When generating a sibcall
2904 pattern, do not round up, since we'll be re-using whatever space our
2906 unadjusted_args_size
2907 = compute_argument_block_size (reg_parm_stack_space
,
2908 &adjusted_args_size
,
2911 : preferred_stack_boundary
));
2913 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
2915 /* The argument block when performing a sibling call is the
2916 incoming argument block. */
2919 argblock
= crtl
->args
.internal_arg_pointer
;
2920 if (STACK_GROWS_DOWNWARD
)
2922 = plus_constant (Pmode
, argblock
, crtl
->args
.pretend_args_size
);
2925 = plus_constant (Pmode
, argblock
, -crtl
->args
.pretend_args_size
);
2927 stored_args_map
= sbitmap_alloc (args_size
.constant
);
2928 bitmap_clear (stored_args_map
);
2931 /* If we have no actual push instructions, or shouldn't use them,
2932 make space for all args right now. */
2933 else if (adjusted_args_size
.var
!= 0)
2935 if (old_stack_level
== 0)
2937 emit_stack_save (SAVE_BLOCK
, &old_stack_level
);
2938 old_stack_pointer_delta
= stack_pointer_delta
;
2939 old_pending_adj
= pending_stack_adjust
;
2940 pending_stack_adjust
= 0;
2941 /* stack_arg_under_construction says whether a stack arg is
2942 being constructed at the old stack level. Pushing the stack
2943 gets a clean outgoing argument block. */
2944 old_stack_arg_under_construction
= stack_arg_under_construction
;
2945 stack_arg_under_construction
= 0;
2947 argblock
= push_block (ARGS_SIZE_RTX (adjusted_args_size
), 0, 0);
2948 if (flag_stack_usage_info
)
2949 current_function_has_unbounded_dynamic_stack_size
= 1;
2953 /* Note that we must go through the motions of allocating an argument
2954 block even if the size is zero because we may be storing args
2955 in the area reserved for register arguments, which may be part of
2958 int needed
= adjusted_args_size
.constant
;
2960 /* Store the maximum argument space used. It will be pushed by
2961 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2964 if (needed
> crtl
->outgoing_args_size
)
2965 crtl
->outgoing_args_size
= needed
;
2967 if (must_preallocate
)
2969 if (ACCUMULATE_OUTGOING_ARGS
)
2971 /* Since the stack pointer will never be pushed, it is
2972 possible for the evaluation of a parm to clobber
2973 something we have already written to the stack.
2974 Since most function calls on RISC machines do not use
2975 the stack, this is uncommon, but must work correctly.
2977 Therefore, we save any area of the stack that was already
2978 written and that we are using. Here we set up to do this
2979 by making a new stack usage map from the old one. The
2980 actual save will be done by store_one_arg.
2982 Another approach might be to try to reorder the argument
2983 evaluations to avoid this conflicting stack usage. */
2985 /* Since we will be writing into the entire argument area,
2986 the map must be allocated for its entire size, not just
2987 the part that is the responsibility of the caller. */
2988 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
2989 needed
+= reg_parm_stack_space
;
2991 if (ARGS_GROW_DOWNWARD
)
2992 highest_outgoing_arg_in_use
2993 = MAX (initial_highest_arg_in_use
, needed
+ 1);
2995 highest_outgoing_arg_in_use
2996 = MAX (initial_highest_arg_in_use
, needed
);
2998 free (stack_usage_map_buf
);
2999 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
3000 stack_usage_map
= stack_usage_map_buf
;
3002 if (initial_highest_arg_in_use
)
3003 memcpy (stack_usage_map
, initial_stack_usage_map
,
3004 initial_highest_arg_in_use
);
3006 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
3007 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
3008 (highest_outgoing_arg_in_use
3009 - initial_highest_arg_in_use
));
3012 /* The address of the outgoing argument list must not be
3013 copied to a register here, because argblock would be left
3014 pointing to the wrong place after the call to
3015 allocate_dynamic_stack_space below. */
3017 argblock
= virtual_outgoing_args_rtx
;
3021 if (inhibit_defer_pop
== 0)
3023 /* Try to reuse some or all of the pending_stack_adjust
3024 to get this space. */
3026 = (combine_pending_stack_adjustment_and_call
3027 (unadjusted_args_size
,
3028 &adjusted_args_size
,
3029 preferred_unit_stack_boundary
));
3031 /* combine_pending_stack_adjustment_and_call computes
3032 an adjustment before the arguments are allocated.
3033 Account for them and see whether or not the stack
3034 needs to go up or down. */
3035 needed
= unadjusted_args_size
- needed
;
3039 /* We're releasing stack space. */
3040 /* ??? We can avoid any adjustment at all if we're
3041 already aligned. FIXME. */
3042 pending_stack_adjust
= -needed
;
3043 do_pending_stack_adjust ();
3047 /* We need to allocate space. We'll do that in
3048 push_block below. */
3049 pending_stack_adjust
= 0;
3052 /* Special case this because overhead of `push_block' in
3053 this case is non-trivial. */
3055 argblock
= virtual_outgoing_args_rtx
;
3058 argblock
= push_block (GEN_INT (needed
), 0, 0);
3059 if (ARGS_GROW_DOWNWARD
)
3060 argblock
= plus_constant (Pmode
, argblock
, needed
);
3063 /* We only really need to call `copy_to_reg' in the case
3064 where push insns are going to be used to pass ARGBLOCK
3065 to a function call in ARGS. In that case, the stack
3066 pointer changes value from the allocation point to the
3067 call point, and hence the value of
3068 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
3069 as well always do it. */
3070 argblock
= copy_to_reg (argblock
);
3075 if (ACCUMULATE_OUTGOING_ARGS
)
3077 /* The save/restore code in store_one_arg handles all
3078 cases except one: a constructor call (including a C
3079 function returning a BLKmode struct) to initialize
3081 if (stack_arg_under_construction
)
3084 = GEN_INT (adjusted_args_size
.constant
3085 + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
3086 : TREE_TYPE (fndecl
))) ? 0
3087 : reg_parm_stack_space
));
3088 if (old_stack_level
== 0)
3090 emit_stack_save (SAVE_BLOCK
, &old_stack_level
);
3091 old_stack_pointer_delta
= stack_pointer_delta
;
3092 old_pending_adj
= pending_stack_adjust
;
3093 pending_stack_adjust
= 0;
3094 /* stack_arg_under_construction says whether a stack
3095 arg is being constructed at the old stack level.
3096 Pushing the stack gets a clean outgoing argument
3098 old_stack_arg_under_construction
3099 = stack_arg_under_construction
;
3100 stack_arg_under_construction
= 0;
3101 /* Make a new map for the new argument list. */
3102 free (stack_usage_map_buf
);
3103 stack_usage_map_buf
= XCNEWVEC (char, highest_outgoing_arg_in_use
);
3104 stack_usage_map
= stack_usage_map_buf
;
3105 highest_outgoing_arg_in_use
= 0;
3107 /* We can pass TRUE as the 4th argument because we just
3108 saved the stack pointer and will restore it right after
3110 allocate_dynamic_stack_space (push_size
, 0,
3111 BIGGEST_ALIGNMENT
, true);
3114 /* If argument evaluation might modify the stack pointer,
3115 copy the address of the argument list to a register. */
3116 for (i
= 0; i
< num_actuals
; i
++)
3117 if (args
[i
].pass_on_stack
)
3119 argblock
= copy_addr_to_reg (argblock
);
3124 compute_argument_addresses (args
, argblock
, num_actuals
);
3126 /* Perform stack alignment before the first push (the last arg). */
3128 && adjusted_args_size
.constant
> reg_parm_stack_space
3129 && adjusted_args_size
.constant
!= unadjusted_args_size
)
3131 /* When the stack adjustment is pending, we get better code
3132 by combining the adjustments. */
3133 if (pending_stack_adjust
3134 && ! inhibit_defer_pop
)
3136 pending_stack_adjust
3137 = (combine_pending_stack_adjustment_and_call
3138 (unadjusted_args_size
,
3139 &adjusted_args_size
,
3140 preferred_unit_stack_boundary
));
3141 do_pending_stack_adjust ();
3143 else if (argblock
== 0)
3144 anti_adjust_stack (GEN_INT (adjusted_args_size
.constant
3145 - unadjusted_args_size
));
3147 /* Now that the stack is properly aligned, pops can't safely
3148 be deferred during the evaluation of the arguments. */
3151 /* Record the maximum pushed stack space size. We need to delay
3152 doing it this far to take into account the optimization done
3153 by combine_pending_stack_adjustment_and_call. */
3154 if (flag_stack_usage_info
3155 && !ACCUMULATE_OUTGOING_ARGS
3157 && adjusted_args_size
.var
== 0)
3159 int pushed
= adjusted_args_size
.constant
+ pending_stack_adjust
;
3160 if (pushed
> current_function_pushed_stack_size
)
3161 current_function_pushed_stack_size
= pushed
;
3164 funexp
= rtx_for_function_call (fndecl
, addr
);
3166 /* Precompute all register parameters. It isn't safe to compute anything
3167 once we have started filling any specific hard regs. */
3168 precompute_register_parameters (num_actuals
, args
, ®_parm_seen
);
3170 if (CALL_EXPR_STATIC_CHAIN (exp
))
3171 static_chain_value
= expand_normal (CALL_EXPR_STATIC_CHAIN (exp
));
3173 static_chain_value
= 0;
3175 #ifdef REG_PARM_STACK_SPACE
3176 /* Save the fixed argument area if it's part of the caller's frame and
3177 is clobbered by argument setup for this call. */
3178 if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
3179 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
3180 &low_to_save
, &high_to_save
);
3183 /* Now store (and compute if necessary) all non-register parms.
3184 These come before register parms, since they can require block-moves,
3185 which could clobber the registers used for register parms.
3186 Parms which have partial registers are not stored here,
3187 but we do preallocate space here if they want that. */
3189 for (i
= 0; i
< num_actuals
; i
++)
3191 /* Delay bounds until all other args are stored. */
3192 if (POINTER_BOUNDS_P (args
[i
].tree_value
))
3194 else if (args
[i
].reg
== 0 || args
[i
].pass_on_stack
)
3196 rtx_insn
*before_arg
= get_last_insn ();
3198 /* We don't allow passing huge (> 2^30 B) arguments
3199 by value. It would cause an overflow later on. */
3200 if (adjusted_args_size
.constant
3201 >= (1 << (HOST_BITS_PER_INT
- 2)))
3203 sorry ("passing too large argument on stack");
3207 if (store_one_arg (&args
[i
], argblock
, flags
,
3208 adjusted_args_size
.var
!= 0,
3209 reg_parm_stack_space
)
3211 && check_sibcall_argument_overlap (before_arg
,
3213 sibcall_failure
= 1;
3218 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args
[i
].tree_value
)),
3219 gen_rtx_USE (VOIDmode
, args
[i
].stack
),
3223 /* If we have a parm that is passed in registers but not in memory
3224 and whose alignment does not permit a direct copy into registers,
3225 make a group of pseudos that correspond to each register that we
3227 if (STRICT_ALIGNMENT
)
3228 store_unaligned_arguments_into_pseudos (args
, num_actuals
);
3230 /* Now store any partially-in-registers parm.
3231 This is the last place a block-move can happen. */
3233 for (i
= 0; i
< num_actuals
; i
++)
3234 if (args
[i
].partial
!= 0 && ! args
[i
].pass_on_stack
)
3236 rtx_insn
*before_arg
= get_last_insn ();
3238 /* On targets with weird calling conventions (e.g. PA) it's
3239 hard to ensure that all cases of argument overlap between
3240 stack and registers work. Play it safe and bail out. */
3241 if (ARGS_GROW_DOWNWARD
&& !STACK_GROWS_DOWNWARD
)
3243 sibcall_failure
= 1;
3247 if (store_one_arg (&args
[i
], argblock
, flags
,
3248 adjusted_args_size
.var
!= 0,
3249 reg_parm_stack_space
)
3251 && check_sibcall_argument_overlap (before_arg
,
3253 sibcall_failure
= 1;
3256 bool any_regs
= false;
3257 for (i
= 0; i
< num_actuals
; i
++)
3258 if (args
[i
].reg
!= NULL_RTX
)
3261 targetm
.calls
.call_args (args
[i
].reg
, funtype
);
3264 targetm
.calls
.call_args (pc_rtx
, funtype
);
3266 /* Figure out the register where the value, if any, will come back. */
3269 if (TYPE_MODE (rettype
) != VOIDmode
3270 && ! structure_value_addr
)
3272 if (pcc_struct_value
)
3274 valreg
= hard_function_value (build_pointer_type (rettype
),
3275 fndecl
, NULL
, (pass
== 0));
3276 if (CALL_WITH_BOUNDS_P (exp
))
3277 valbnd
= targetm
.calls
.
3278 chkp_function_value_bounds (build_pointer_type (rettype
),
3279 fndecl
, (pass
== 0));
3283 valreg
= hard_function_value (rettype
, fndecl
, fntype
,
3285 if (CALL_WITH_BOUNDS_P (exp
))
3286 valbnd
= targetm
.calls
.chkp_function_value_bounds (rettype
,
3291 /* If VALREG is a PARALLEL whose first member has a zero
3292 offset, use that. This is for targets such as m68k that
3293 return the same value in multiple places. */
3294 if (GET_CODE (valreg
) == PARALLEL
)
3296 rtx elem
= XVECEXP (valreg
, 0, 0);
3297 rtx where
= XEXP (elem
, 0);
3298 rtx offset
= XEXP (elem
, 1);
3299 if (offset
== const0_rtx
3300 && GET_MODE (where
) == GET_MODE (valreg
))
3305 /* Store all bounds not passed in registers. */
3306 for (i
= 0; i
< num_actuals
; i
++)
3308 if (POINTER_BOUNDS_P (args
[i
].tree_value
)
3310 store_bounds (&args
[i
],
3311 args
[i
].pointer_arg
== -1
3313 : &args
[args
[i
].pointer_arg
]);
3316 /* If register arguments require space on the stack and stack space
3317 was not preallocated, allocate stack space here for arguments
3318 passed in registers. */
3319 if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
)))
3320 && !ACCUMULATE_OUTGOING_ARGS
3321 && must_preallocate
== 0 && reg_parm_stack_space
> 0)
3322 anti_adjust_stack (GEN_INT (reg_parm_stack_space
));
3324 /* Pass the function the address in which to return a
3326 if (pass
!= 0 && structure_value_addr
&& ! structure_value_addr_parm
)
3328 structure_value_addr
3329 = convert_memory_address (Pmode
, structure_value_addr
);
3330 emit_move_insn (struct_value
,
3332 force_operand (structure_value_addr
,
3335 if (REG_P (struct_value
))
3336 use_reg (&call_fusage
, struct_value
);
3339 after_args
= get_last_insn ();
3340 funexp
= prepare_call_address (fndecl
? fndecl
: fntype
, funexp
,
3341 static_chain_value
, &call_fusage
,
3342 reg_parm_seen
, pass
== 0);
3344 load_register_parameters (args
, num_actuals
, &call_fusage
, flags
,
3345 pass
== 0, &sibcall_failure
);
3347 /* Save a pointer to the last insn before the call, so that we can
3348 later safely search backwards to find the CALL_INSN. */
3349 before_call
= get_last_insn ();
3351 /* Set up next argument register. For sibling calls on machines
3352 with register windows this should be the incoming register. */
3354 next_arg_reg
= targetm
.calls
.function_incoming_arg (args_so_far
,
3359 next_arg_reg
= targetm
.calls
.function_arg (args_so_far
,
3360 VOIDmode
, void_type_node
,
3363 if (pass
== 1 && (return_flags
& ERF_RETURNS_ARG
))
3365 int arg_nr
= return_flags
& ERF_RETURN_ARG_MASK
;
3366 arg_nr
= num_actuals
- arg_nr
- 1;
3368 && arg_nr
< num_actuals
3372 && GET_MODE (args
[arg_nr
].reg
) == GET_MODE (valreg
))
3374 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args
[arg_nr
].tree_value
)),
3375 gen_rtx_SET (valreg
, args
[arg_nr
].reg
),
3378 /* All arguments and registers used for the call must be set up by
3381 /* Stack must be properly aligned now. */
3383 || !(stack_pointer_delta
% preferred_unit_stack_boundary
));
3385 /* Generate the actual call instruction. */
3386 emit_call_1 (funexp
, exp
, fndecl
, funtype
, unadjusted_args_size
,
3387 adjusted_args_size
.constant
, struct_value_size
,
3388 next_arg_reg
, valreg
, old_inhibit_defer_pop
, call_fusage
,
3389 flags
, args_so_far
);
3393 rtx_call_insn
*last
;
3394 rtx datum
= NULL_RTX
;
3395 if (fndecl
!= NULL_TREE
)
3397 datum
= XEXP (DECL_RTL (fndecl
), 0);
3398 gcc_assert (datum
!= NULL_RTX
3399 && GET_CODE (datum
) == SYMBOL_REF
);
3401 last
= last_call_insn ();
3402 add_reg_note (last
, REG_CALL_DECL
, datum
);
3405 /* If the call setup or the call itself overlaps with anything
3406 of the argument setup we probably clobbered our call address.
3407 In that case we can't do sibcalls. */
3409 && check_sibcall_argument_overlap (after_args
, 0, 0))
3410 sibcall_failure
= 1;
3412 /* If a non-BLKmode value is returned at the most significant end
3413 of a register, shift the register right by the appropriate amount
3414 and update VALREG accordingly. BLKmode values are handled by the
3415 group load/store machinery below. */
3416 if (!structure_value_addr
3417 && !pcc_struct_value
3418 && TYPE_MODE (rettype
) != VOIDmode
3419 && TYPE_MODE (rettype
) != BLKmode
3421 && targetm
.calls
.return_in_msb (rettype
))
3423 if (shift_return_value (TYPE_MODE (rettype
), false, valreg
))
3424 sibcall_failure
= 1;
3425 valreg
= gen_rtx_REG (TYPE_MODE (rettype
), REGNO (valreg
));
3428 if (pass
&& (flags
& ECF_MALLOC
))
3430 rtx temp
= gen_reg_rtx (GET_MODE (valreg
));
3431 rtx_insn
*last
, *insns
;
3433 /* The return value from a malloc-like function is a pointer. */
3434 if (TREE_CODE (rettype
) == POINTER_TYPE
)
3435 mark_reg_pointer (temp
, MALLOC_ABI_ALIGNMENT
);
3437 emit_move_insn (temp
, valreg
);
3439 /* The return value from a malloc-like function can not alias
3441 last
= get_last_insn ();
3442 add_reg_note (last
, REG_NOALIAS
, temp
);
3444 /* Write out the sequence. */
3445 insns
= get_insns ();
3451 /* For calls to `setjmp', etc., inform
3452 function.c:setjmp_warnings that it should complain if
3453 nonvolatile values are live. For functions that cannot
3454 return, inform flow that control does not fall through. */
3456 if ((flags
& ECF_NORETURN
) || pass
== 0)
3458 /* The barrier must be emitted
3459 immediately after the CALL_INSN. Some ports emit more
3460 than just a CALL_INSN above, so we must search for it here. */
3462 rtx_insn
*last
= get_last_insn ();
3463 while (!CALL_P (last
))
3465 last
= PREV_INSN (last
);
3466 /* There was no CALL_INSN? */
3467 gcc_assert (last
!= before_call
);
3470 emit_barrier_after (last
);
3472 /* Stack adjustments after a noreturn call are dead code.
3473 However when NO_DEFER_POP is in effect, we must preserve
3474 stack_pointer_delta. */
3475 if (inhibit_defer_pop
== 0)
3477 stack_pointer_delta
= old_stack_allocated
;
3478 pending_stack_adjust
= 0;
3482 /* If value type not void, return an rtx for the value. */
3484 if (TYPE_MODE (rettype
) == VOIDmode
3486 target
= const0_rtx
;
3487 else if (structure_value_addr
)
3489 if (target
== 0 || !MEM_P (target
))
3492 = gen_rtx_MEM (TYPE_MODE (rettype
),
3493 memory_address (TYPE_MODE (rettype
),
3494 structure_value_addr
));
3495 set_mem_attributes (target
, rettype
, 1);
3498 else if (pcc_struct_value
)
3500 /* This is the special C++ case where we need to
3501 know what the true target was. We take care to
3502 never use this value more than once in one expression. */
3503 target
= gen_rtx_MEM (TYPE_MODE (rettype
),
3504 copy_to_reg (valreg
));
3505 set_mem_attributes (target
, rettype
, 1);
3507 /* Handle calls that return values in multiple non-contiguous locations.
3508 The Irix 6 ABI has examples of this. */
3509 else if (GET_CODE (valreg
) == PARALLEL
)
3512 target
= emit_group_move_into_temps (valreg
);
3513 else if (rtx_equal_p (target
, valreg
))
3515 else if (GET_CODE (target
) == PARALLEL
)
3516 /* Handle the result of a emit_group_move_into_temps
3517 call in the previous pass. */
3518 emit_group_move (target
, valreg
);
3520 emit_group_store (target
, valreg
, rettype
,
3521 int_size_in_bytes (rettype
));
3524 && GET_MODE (target
) == TYPE_MODE (rettype
)
3525 && GET_MODE (target
) == GET_MODE (valreg
))
3527 bool may_overlap
= false;
3529 /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
3530 reg to a plain register. */
3531 if (!REG_P (target
) || HARD_REGISTER_P (target
))
3532 valreg
= avoid_likely_spilled_reg (valreg
);
3534 /* If TARGET is a MEM in the argument area, and we have
3535 saved part of the argument area, then we can't store
3536 directly into TARGET as it may get overwritten when we
3537 restore the argument save area below. Don't work too
3538 hard though and simply force TARGET to a register if it
3539 is a MEM; the optimizer is quite likely to sort it out. */
3540 if (ACCUMULATE_OUTGOING_ARGS
&& pass
&& MEM_P (target
))
3541 for (i
= 0; i
< num_actuals
; i
++)
3542 if (args
[i
].save_area
)
3549 target
= copy_to_reg (valreg
);
3552 /* TARGET and VALREG cannot be equal at this point
3553 because the latter would not have
3554 REG_FUNCTION_VALUE_P true, while the former would if
3555 it were referring to the same register.
3557 If they refer to the same register, this move will be
3558 a no-op, except when function inlining is being
3560 emit_move_insn (target
, valreg
);
3562 /* If we are setting a MEM, this code must be executed.
3563 Since it is emitted after the call insn, sibcall
3564 optimization cannot be performed in that case. */
3566 sibcall_failure
= 1;
3570 target
= copy_to_reg (avoid_likely_spilled_reg (valreg
));
3572 /* If we promoted this return value, make the proper SUBREG.
3573 TARGET might be const0_rtx here, so be careful. */
3575 && TYPE_MODE (rettype
) != BLKmode
3576 && GET_MODE (target
) != TYPE_MODE (rettype
))
3578 tree type
= rettype
;
3579 int unsignedp
= TYPE_UNSIGNED (type
);
3583 /* Ensure we promote as expected, and get the new unsignedness. */
3584 pmode
= promote_function_mode (type
, TYPE_MODE (type
), &unsignedp
,
3586 gcc_assert (GET_MODE (target
) == pmode
);
3588 if ((WORDS_BIG_ENDIAN
|| BYTES_BIG_ENDIAN
)
3589 && (GET_MODE_SIZE (GET_MODE (target
))
3590 > GET_MODE_SIZE (TYPE_MODE (type
))))
3592 offset
= GET_MODE_SIZE (GET_MODE (target
))
3593 - GET_MODE_SIZE (TYPE_MODE (type
));
3594 if (! BYTES_BIG_ENDIAN
)
3595 offset
= (offset
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3596 else if (! WORDS_BIG_ENDIAN
)
3597 offset
%= UNITS_PER_WORD
;
3600 target
= gen_rtx_SUBREG (TYPE_MODE (type
), target
, offset
);
3601 SUBREG_PROMOTED_VAR_P (target
) = 1;
3602 SUBREG_PROMOTED_SET (target
, unsignedp
);
3605 /* If size of args is variable or this was a constructor call for a stack
3606 argument, restore saved stack-pointer value. */
3608 if (old_stack_level
)
3610 rtx_insn
*prev
= get_last_insn ();
3612 emit_stack_restore (SAVE_BLOCK
, old_stack_level
);
3613 stack_pointer_delta
= old_stack_pointer_delta
;
3615 fixup_args_size_notes (prev
, get_last_insn (), stack_pointer_delta
);
3617 pending_stack_adjust
= old_pending_adj
;
3618 old_stack_allocated
= stack_pointer_delta
- pending_stack_adjust
;
3619 stack_arg_under_construction
= old_stack_arg_under_construction
;
3620 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3621 stack_usage_map
= initial_stack_usage_map
;
3622 sibcall_failure
= 1;
3624 else if (ACCUMULATE_OUTGOING_ARGS
&& pass
)
3626 #ifdef REG_PARM_STACK_SPACE
3628 restore_fixed_argument_area (save_area
, argblock
,
3629 high_to_save
, low_to_save
);
3632 /* If we saved any argument areas, restore them. */
3633 for (i
= 0; i
< num_actuals
; i
++)
3634 if (args
[i
].save_area
)
3636 machine_mode save_mode
= GET_MODE (args
[i
].save_area
);
3638 = gen_rtx_MEM (save_mode
,
3639 memory_address (save_mode
,
3640 XEXP (args
[i
].stack_slot
, 0)));
3642 if (save_mode
!= BLKmode
)
3643 emit_move_insn (stack_area
, args
[i
].save_area
);
3645 emit_block_move (stack_area
, args
[i
].save_area
,
3646 GEN_INT (args
[i
].locate
.size
.constant
),
3647 BLOCK_OP_CALL_PARM
);
3650 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
3651 stack_usage_map
= initial_stack_usage_map
;
3654 /* If this was alloca, record the new stack level. */
3655 if (flags
& ECF_MAY_BE_ALLOCA
)
3656 record_new_stack_level ();
3658 /* Free up storage we no longer need. */
3659 for (i
= 0; i
< num_actuals
; ++i
)
3660 free (args
[i
].aligned_regs
);
3662 targetm
.calls
.end_call_args ();
3664 insns
= get_insns ();
3669 tail_call_insns
= insns
;
3671 /* Restore the pending stack adjustment now that we have
3672 finished generating the sibling call sequence. */
3674 restore_pending_stack_adjust (&save
);
3676 /* Prepare arg structure for next iteration. */
3677 for (i
= 0; i
< num_actuals
; i
++)
3680 args
[i
].aligned_regs
= 0;
3684 sbitmap_free (stored_args_map
);
3685 internal_arg_pointer_exp_state
.scan_start
= NULL
;
3686 internal_arg_pointer_exp_state
.cache
.release ();
3690 normal_call_insns
= insns
;
3692 /* Verify that we've deallocated all the stack we used. */
3693 gcc_assert ((flags
& ECF_NORETURN
)
3694 || (old_stack_allocated
3695 == stack_pointer_delta
- pending_stack_adjust
));
3698 /* If something prevents making this a sibling call,
3699 zero out the sequence. */
3700 if (sibcall_failure
)
3701 tail_call_insns
= NULL
;
3706 /* If tail call production succeeded, we need to remove REG_EQUIV notes on
3707 arguments too, as argument area is now clobbered by the call. */
3708 if (tail_call_insns
)
3710 emit_insn (tail_call_insns
);
3711 crtl
->tail_call_emit
= true;
3714 emit_insn (normal_call_insns
);
3716 currently_expanding_call
--;
3718 free (stack_usage_map_buf
);
3720 /* Join result with returned bounds so caller may use them if needed. */
3721 target
= chkp_join_splitted_slot (target
, valbnd
);
3726 /* A sibling call sequence invalidates any REG_EQUIV notes made for
3727 this function's incoming arguments.
3729 At the start of RTL generation we know the only REG_EQUIV notes
3730 in the rtl chain are those for incoming arguments, so we can look
3731 for REG_EQUIV notes between the start of the function and the
3732 NOTE_INSN_FUNCTION_BEG.
3734 This is (slight) overkill. We could keep track of the highest
3735 argument we clobber and be more selective in removing notes, but it
3736 does not seem to be worth the effort. */
3739 fixup_tail_calls (void)
3743 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3747 /* There are never REG_EQUIV notes for the incoming arguments
3748 after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
3750 && NOTE_KIND (insn
) == NOTE_INSN_FUNCTION_BEG
)
3753 note
= find_reg_note (insn
, REG_EQUIV
, 0);
3755 remove_note (insn
, note
);
3756 note
= find_reg_note (insn
, REG_EQUIV
, 0);
3761 /* Traverse a list of TYPES and expand all complex types into their
3764 split_complex_types (tree types
)
3768 /* Before allocating memory, check for the common case of no complex. */
3769 for (p
= types
; p
; p
= TREE_CHAIN (p
))
3771 tree type
= TREE_VALUE (p
);
3772 if (TREE_CODE (type
) == COMPLEX_TYPE
3773 && targetm
.calls
.split_complex_arg (type
))
3779 types
= copy_list (types
);
3781 for (p
= types
; p
; p
= TREE_CHAIN (p
))
3783 tree complex_type
= TREE_VALUE (p
);
3785 if (TREE_CODE (complex_type
) == COMPLEX_TYPE
3786 && targetm
.calls
.split_complex_arg (complex_type
))
3790 /* Rewrite complex type with component type. */
3791 TREE_VALUE (p
) = TREE_TYPE (complex_type
);
3792 next
= TREE_CHAIN (p
);
3794 /* Add another component type for the imaginary part. */
3795 imag
= build_tree_list (NULL_TREE
, TREE_VALUE (p
));
3796 TREE_CHAIN (p
) = imag
;
3797 TREE_CHAIN (imag
) = next
;
3799 /* Skip the newly created node. */
3807 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3808 The RETVAL parameter specifies whether return value needs to be saved, other
3809 parameters are documented in the emit_library_call function below. */
3812 emit_library_call_value_1 (int retval
, rtx orgfun
, rtx value
,
3813 enum libcall_type fn_type
,
3814 machine_mode outmode
, int nargs
, va_list p
)
3816 /* Total size in bytes of all the stack-parms scanned so far. */
3817 struct args_size args_size
;
3818 /* Size of arguments before any adjustments (such as rounding). */
3819 struct args_size original_args_size
;
3822 /* Todo, choose the correct decl type of orgfun. Sadly this information
3823 isn't present here, so we default to native calling abi here. */
3824 tree fndecl ATTRIBUTE_UNUSED
= NULL_TREE
; /* library calls default to host calling abi ? */
3825 tree fntype ATTRIBUTE_UNUSED
= NULL_TREE
; /* library calls default to host calling abi ? */
3828 CUMULATIVE_ARGS args_so_far_v
;
3829 cumulative_args_t args_so_far
;
3836 struct locate_and_pad_arg_data locate
;
3840 int old_inhibit_defer_pop
= inhibit_defer_pop
;
3841 rtx call_fusage
= 0;
3844 int pcc_struct_value
= 0;
3845 int struct_value_size
= 0;
3847 int reg_parm_stack_space
= 0;
3849 rtx_insn
*before_call
;
3850 bool have_push_fusage
;
3851 tree tfom
; /* type_for_mode (outmode, 0) */
3853 #ifdef REG_PARM_STACK_SPACE
3854 /* Define the boundary of the register parm stack space that needs to be
3856 int low_to_save
= 0, high_to_save
= 0;
3857 rtx save_area
= 0; /* Place that it is saved. */
3860 /* Size of the stack reserved for parameter registers. */
3861 int initial_highest_arg_in_use
= highest_outgoing_arg_in_use
;
3862 char *initial_stack_usage_map
= stack_usage_map
;
3863 char *stack_usage_map_buf
= NULL
;
3865 rtx struct_value
= targetm
.calls
.struct_value_rtx (0, 0);
3867 #ifdef REG_PARM_STACK_SPACE
3868 reg_parm_stack_space
= REG_PARM_STACK_SPACE ((tree
) 0);
3871 /* By default, library functions can not throw. */
3872 flags
= ECF_NOTHROW
;
3885 flags
|= ECF_NORETURN
;
3888 flags
= ECF_NORETURN
;
3890 case LCT_RETURNS_TWICE
:
3891 flags
= ECF_RETURNS_TWICE
;
3896 /* Ensure current function's preferred stack boundary is at least
3898 if (crtl
->preferred_stack_boundary
< PREFERRED_STACK_BOUNDARY
)
3899 crtl
->preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
3901 /* If this kind of value comes back in memory,
3902 decide where in memory it should come back. */
3903 if (outmode
!= VOIDmode
)
3905 tfom
= lang_hooks
.types
.type_for_mode (outmode
, 0);
3906 if (aggregate_value_p (tfom
, 0))
3908 #ifdef PCC_STATIC_STRUCT_RETURN
3910 = hard_function_value (build_pointer_type (tfom
), 0, 0, 0);
3911 mem_value
= gen_rtx_MEM (outmode
, pointer_reg
);
3912 pcc_struct_value
= 1;
3914 value
= gen_reg_rtx (outmode
);
3915 #else /* not PCC_STATIC_STRUCT_RETURN */
3916 struct_value_size
= GET_MODE_SIZE (outmode
);
3917 if (value
!= 0 && MEM_P (value
))
3920 mem_value
= assign_temp (tfom
, 1, 1);
3922 /* This call returns a big structure. */
3923 flags
&= ~(ECF_CONST
| ECF_PURE
| ECF_LOOPING_CONST_OR_PURE
);
3927 tfom
= void_type_node
;
3929 /* ??? Unfinished: must pass the memory address as an argument. */
3931 /* Copy all the libcall-arguments out of the varargs data
3932 and into a vector ARGVEC.
3934 Compute how to pass each argument. We only support a very small subset
3935 of the full argument passing conventions to limit complexity here since
3936 library functions shouldn't have many args. */
3938 argvec
= XALLOCAVEC (struct arg
, nargs
+ 1);
3939 memset (argvec
, 0, (nargs
+ 1) * sizeof (struct arg
));
3941 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3942 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v
, outmode
, fun
);
3944 INIT_CUMULATIVE_ARGS (args_so_far_v
, NULL_TREE
, fun
, 0, nargs
);
3946 args_so_far
= pack_cumulative_args (&args_so_far_v
);
3948 args_size
.constant
= 0;
3955 /* If there's a structure value address to be passed,
3956 either pass it in the special place, or pass it as an extra argument. */
3957 if (mem_value
&& struct_value
== 0 && ! pcc_struct_value
)
3959 rtx addr
= XEXP (mem_value
, 0);
3963 /* Make sure it is a reasonable operand for a move or push insn. */
3964 if (!REG_P (addr
) && !MEM_P (addr
)
3965 && !(CONSTANT_P (addr
)
3966 && targetm
.legitimate_constant_p (Pmode
, addr
)))
3967 addr
= force_operand (addr
, NULL_RTX
);
3969 argvec
[count
].value
= addr
;
3970 argvec
[count
].mode
= Pmode
;
3971 argvec
[count
].partial
= 0;
3973 argvec
[count
].reg
= targetm
.calls
.function_arg (args_so_far
,
3974 Pmode
, NULL_TREE
, true);
3975 gcc_assert (targetm
.calls
.arg_partial_bytes (args_so_far
, Pmode
,
3976 NULL_TREE
, 1) == 0);
3978 locate_and_pad_parm (Pmode
, NULL_TREE
,
3979 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3982 argvec
[count
].reg
!= 0,
3984 reg_parm_stack_space
, 0,
3985 NULL_TREE
, &args_size
, &argvec
[count
].locate
);
3987 if (argvec
[count
].reg
== 0 || argvec
[count
].partial
!= 0
3988 || reg_parm_stack_space
> 0)
3989 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
3991 targetm
.calls
.function_arg_advance (args_so_far
, Pmode
, (tree
) 0, true);
3996 for (; count
< nargs
; count
++)
3998 rtx val
= va_arg (p
, rtx
);
3999 machine_mode mode
= (machine_mode
) va_arg (p
, int);
4002 /* We cannot convert the arg value to the mode the library wants here;
4003 must do it earlier where we know the signedness of the arg. */
4004 gcc_assert (mode
!= BLKmode
4005 && (GET_MODE (val
) == mode
|| GET_MODE (val
) == VOIDmode
));
4007 /* Make sure it is a reasonable operand for a move or push insn. */
4008 if (!REG_P (val
) && !MEM_P (val
)
4009 && !(CONSTANT_P (val
) && targetm
.legitimate_constant_p (mode
, val
)))
4010 val
= force_operand (val
, NULL_RTX
);
4012 if (pass_by_reference (&args_so_far_v
, mode
, NULL_TREE
, 1))
4016 = !reference_callee_copied (&args_so_far_v
, mode
, NULL_TREE
, 1);
4018 /* If this was a CONST function, it is now PURE since it now
4020 if (flags
& ECF_CONST
)
4022 flags
&= ~ECF_CONST
;
4026 if (MEM_P (val
) && !must_copy
)
4028 tree val_expr
= MEM_EXPR (val
);
4030 mark_addressable (val_expr
);
4035 slot
= assign_temp (lang_hooks
.types
.type_for_mode (mode
, 0),
4037 emit_move_insn (slot
, val
);
4040 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
4041 gen_rtx_USE (VOIDmode
, slot
),
4044 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
,
4045 gen_rtx_CLOBBER (VOIDmode
,
4050 val
= force_operand (XEXP (slot
, 0), NULL_RTX
);
4053 mode
= promote_function_mode (NULL_TREE
, mode
, &unsigned_p
, NULL_TREE
, 0);
4054 argvec
[count
].mode
= mode
;
4055 argvec
[count
].value
= convert_modes (mode
, GET_MODE (val
), val
, unsigned_p
);
4056 argvec
[count
].reg
= targetm
.calls
.function_arg (args_so_far
, mode
,
4059 argvec
[count
].partial
4060 = targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL_TREE
, 1);
4062 if (argvec
[count
].reg
== 0
4063 || argvec
[count
].partial
!= 0
4064 || reg_parm_stack_space
> 0)
4066 locate_and_pad_parm (mode
, NULL_TREE
,
4067 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4070 argvec
[count
].reg
!= 0,
4072 reg_parm_stack_space
, argvec
[count
].partial
,
4073 NULL_TREE
, &args_size
, &argvec
[count
].locate
);
4074 args_size
.constant
+= argvec
[count
].locate
.size
.constant
;
4075 gcc_assert (!argvec
[count
].locate
.size
.var
);
4077 #ifdef BLOCK_REG_PADDING
4079 /* The argument is passed entirely in registers. See at which
4080 end it should be padded. */
4081 argvec
[count
].locate
.where_pad
=
4082 BLOCK_REG_PADDING (mode
, NULL_TREE
,
4083 GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
);
4086 targetm
.calls
.function_arg_advance (args_so_far
, mode
, (tree
) 0, true);
4089 /* If this machine requires an external definition for library
4090 functions, write one out. */
4091 assemble_external_libcall (fun
);
4093 original_args_size
= args_size
;
4094 args_size
.constant
= (((args_size
.constant
4095 + stack_pointer_delta
4099 - stack_pointer_delta
);
4101 args_size
.constant
= MAX (args_size
.constant
,
4102 reg_parm_stack_space
);
4104 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
4105 args_size
.constant
-= reg_parm_stack_space
;
4107 if (args_size
.constant
> crtl
->outgoing_args_size
)
4108 crtl
->outgoing_args_size
= args_size
.constant
;
4110 if (flag_stack_usage_info
&& !ACCUMULATE_OUTGOING_ARGS
)
4112 int pushed
= args_size
.constant
+ pending_stack_adjust
;
4113 if (pushed
> current_function_pushed_stack_size
)
4114 current_function_pushed_stack_size
= pushed
;
4117 if (ACCUMULATE_OUTGOING_ARGS
)
4119 /* Since the stack pointer will never be pushed, it is possible for
4120 the evaluation of a parm to clobber something we have already
4121 written to the stack. Since most function calls on RISC machines
4122 do not use the stack, this is uncommon, but must work correctly.
4124 Therefore, we save any area of the stack that was already written
4125 and that we are using. Here we set up to do this by making a new
4126 stack usage map from the old one.
4128 Another approach might be to try to reorder the argument
4129 evaluations to avoid this conflicting stack usage. */
4131 needed
= args_size
.constant
;
4133 /* Since we will be writing into the entire argument area, the
4134 map must be allocated for its entire size, not just the part that
4135 is the responsibility of the caller. */
4136 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl
? fntype
: TREE_TYPE (fndecl
))))
4137 needed
+= reg_parm_stack_space
;
4139 if (ARGS_GROW_DOWNWARD
)
4140 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
,
4143 highest_outgoing_arg_in_use
= MAX (initial_highest_arg_in_use
, needed
);
4145 stack_usage_map_buf
= XNEWVEC (char, highest_outgoing_arg_in_use
);
4146 stack_usage_map
= stack_usage_map_buf
;
4148 if (initial_highest_arg_in_use
)
4149 memcpy (stack_usage_map
, initial_stack_usage_map
,
4150 initial_highest_arg_in_use
);
4152 if (initial_highest_arg_in_use
!= highest_outgoing_arg_in_use
)
4153 memset (&stack_usage_map
[initial_highest_arg_in_use
], 0,
4154 highest_outgoing_arg_in_use
- initial_highest_arg_in_use
);
4157 /* We must be careful to use virtual regs before they're instantiated,
4158 and real regs afterwards. Loop optimization, for example, can create
4159 new libcalls after we've instantiated the virtual regs, and if we
4160 use virtuals anyway, they won't match the rtl patterns. */
4162 if (virtuals_instantiated
)
4163 argblock
= plus_constant (Pmode
, stack_pointer_rtx
,
4164 STACK_POINTER_OFFSET
);
4166 argblock
= virtual_outgoing_args_rtx
;
4171 argblock
= push_block (GEN_INT (args_size
.constant
), 0, 0);
4174 /* We push args individually in reverse order, perform stack alignment
4175 before the first push (the last arg). */
4177 anti_adjust_stack (GEN_INT (args_size
.constant
4178 - original_args_size
.constant
));
4182 #ifdef REG_PARM_STACK_SPACE
4183 if (ACCUMULATE_OUTGOING_ARGS
)
4185 /* The argument list is the property of the called routine and it
4186 may clobber it. If the fixed area has been used for previous
4187 parameters, we must save and restore it. */
4188 save_area
= save_fixed_argument_area (reg_parm_stack_space
, argblock
,
4189 &low_to_save
, &high_to_save
);
4193 /* When expanding a normal call, args are stored in push order,
4194 which is the reverse of what we have here. */
4195 bool any_regs
= false;
4196 for (int i
= nargs
; i
-- > 0; )
4197 if (argvec
[i
].reg
!= NULL_RTX
)
4199 targetm
.calls
.call_args (argvec
[i
].reg
, NULL_TREE
);
4203 targetm
.calls
.call_args (pc_rtx
, NULL_TREE
);
4205 /* Push the args that need to be pushed. */
4207 have_push_fusage
= false;
4209 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4210 are to be pushed. */
4211 for (count
= 0; count
< nargs
; count
++, argnum
--)
4213 machine_mode mode
= argvec
[argnum
].mode
;
4214 rtx val
= argvec
[argnum
].value
;
4215 rtx reg
= argvec
[argnum
].reg
;
4216 int partial
= argvec
[argnum
].partial
;
4217 unsigned int parm_align
= argvec
[argnum
].locate
.boundary
;
4218 int lower_bound
= 0, upper_bound
= 0, i
;
4220 if (! (reg
!= 0 && partial
== 0))
4224 if (ACCUMULATE_OUTGOING_ARGS
)
4226 /* If this is being stored into a pre-allocated, fixed-size,
4227 stack area, save any previous data at that location. */
4229 if (ARGS_GROW_DOWNWARD
)
4231 /* stack_slot is negative, but we want to index stack_usage_map
4232 with positive values. */
4233 upper_bound
= -argvec
[argnum
].locate
.slot_offset
.constant
+ 1;
4234 lower_bound
= upper_bound
- argvec
[argnum
].locate
.size
.constant
;
4238 lower_bound
= argvec
[argnum
].locate
.slot_offset
.constant
;
4239 upper_bound
= lower_bound
+ argvec
[argnum
].locate
.size
.constant
;
4243 /* Don't worry about things in the fixed argument area;
4244 it has already been saved. */
4245 if (i
< reg_parm_stack_space
)
4246 i
= reg_parm_stack_space
;
4247 while (i
< upper_bound
&& stack_usage_map
[i
] == 0)
4250 if (i
< upper_bound
)
4252 /* We need to make a save area. */
4254 = argvec
[argnum
].locate
.size
.constant
* BITS_PER_UNIT
;
4255 machine_mode save_mode
4256 = mode_for_size (size
, MODE_INT
, 1);
4258 = plus_constant (Pmode
, argblock
,
4259 argvec
[argnum
].locate
.offset
.constant
);
4261 = gen_rtx_MEM (save_mode
, memory_address (save_mode
, adr
));
4263 if (save_mode
== BLKmode
)
4265 argvec
[argnum
].save_area
4266 = assign_stack_temp (BLKmode
,
4267 argvec
[argnum
].locate
.size
.constant
4270 emit_block_move (validize_mem
4271 (copy_rtx (argvec
[argnum
].save_area
)),
4273 GEN_INT (argvec
[argnum
].locate
.size
.constant
),
4274 BLOCK_OP_CALL_PARM
);
4278 argvec
[argnum
].save_area
= gen_reg_rtx (save_mode
);
4280 emit_move_insn (argvec
[argnum
].save_area
, stack_area
);
4285 emit_push_insn (val
, mode
, NULL_TREE
, NULL_RTX
, parm_align
,
4286 partial
, reg
, 0, argblock
,
4287 GEN_INT (argvec
[argnum
].locate
.offset
.constant
),
4288 reg_parm_stack_space
,
4289 ARGS_SIZE_RTX (argvec
[argnum
].locate
.alignment_pad
), false);
4291 /* Now mark the segment we just used. */
4292 if (ACCUMULATE_OUTGOING_ARGS
)
4293 for (i
= lower_bound
; i
< upper_bound
; i
++)
4294 stack_usage_map
[i
] = 1;
4298 /* Indicate argument access so that alias.c knows that these
4301 use
= plus_constant (Pmode
, argblock
,
4302 argvec
[argnum
].locate
.offset
.constant
);
4303 else if (have_push_fusage
)
4307 /* When arguments are pushed, trying to tell alias.c where
4308 exactly this argument is won't work, because the
4309 auto-increment causes confusion. So we merely indicate
4310 that we access something with a known mode somewhere on
4312 use
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4313 gen_rtx_SCRATCH (Pmode
));
4314 have_push_fusage
= true;
4316 use
= gen_rtx_MEM (argvec
[argnum
].mode
, use
);
4317 use
= gen_rtx_USE (VOIDmode
, use
);
4318 call_fusage
= gen_rtx_EXPR_LIST (VOIDmode
, use
, call_fusage
);
4324 fun
= prepare_call_address (NULL
, fun
, NULL
, &call_fusage
, 0, 0);
4326 /* Now load any reg parms into their regs. */
4328 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4329 are to be pushed. */
4330 for (count
= 0; count
< nargs
; count
++, argnum
--)
4332 machine_mode mode
= argvec
[argnum
].mode
;
4333 rtx val
= argvec
[argnum
].value
;
4334 rtx reg
= argvec
[argnum
].reg
;
4335 int partial
= argvec
[argnum
].partial
;
4336 #ifdef BLOCK_REG_PADDING
4340 /* Handle calls that pass values in multiple non-contiguous
4341 locations. The PA64 has examples of this for library calls. */
4342 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
4343 emit_group_load (reg
, val
, NULL_TREE
, GET_MODE_SIZE (mode
));
4344 else if (reg
!= 0 && partial
== 0)
4346 emit_move_insn (reg
, val
);
4347 #ifdef BLOCK_REG_PADDING
4348 size
= GET_MODE_SIZE (argvec
[argnum
].mode
);
4350 /* Copied from load_register_parameters. */
4352 /* Handle case where we have a value that needs shifting
4353 up to the msb. eg. a QImode value and we're padding
4354 upward on a BYTES_BIG_ENDIAN machine. */
4355 if (size
< UNITS_PER_WORD
4356 && (argvec
[argnum
].locate
.where_pad
4357 == (BYTES_BIG_ENDIAN
? upward
: downward
)))
4360 int shift
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
4362 /* Assigning REG here rather than a temp makes CALL_FUSAGE
4363 report the whole reg as used. Strictly speaking, the
4364 call only uses SIZE bytes at the msb end, but it doesn't
4365 seem worth generating rtl to say that. */
4366 reg
= gen_rtx_REG (word_mode
, REGNO (reg
));
4367 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, shift
, reg
, 1);
4369 emit_move_insn (reg
, x
);
4377 /* Any regs containing parms remain in use through the call. */
4378 for (count
= 0; count
< nargs
; count
++)
4380 rtx reg
= argvec
[count
].reg
;
4381 if (reg
!= 0 && GET_CODE (reg
) == PARALLEL
)
4382 use_group_regs (&call_fusage
, reg
);
4385 int partial
= argvec
[count
].partial
;
4389 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4390 nregs
= partial
/ UNITS_PER_WORD
;
4391 use_regs (&call_fusage
, REGNO (reg
), nregs
);
4394 use_reg (&call_fusage
, reg
);
4398 /* Pass the function the address in which to return a structure value. */
4399 if (mem_value
!= 0 && struct_value
!= 0 && ! pcc_struct_value
)
4401 emit_move_insn (struct_value
,
4403 force_operand (XEXP (mem_value
, 0),
4405 if (REG_P (struct_value
))
4406 use_reg (&call_fusage
, struct_value
);
4409 /* Don't allow popping to be deferred, since then
4410 cse'ing of library calls could delete a call and leave the pop. */
4412 valreg
= (mem_value
== 0 && outmode
!= VOIDmode
4413 ? hard_libcall_value (outmode
, orgfun
) : NULL_RTX
);
4415 /* Stack must be properly aligned now. */
4416 gcc_assert (!(stack_pointer_delta
4417 & (PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)));
4419 before_call
= get_last_insn ();
4421 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4422 will set inhibit_defer_pop to that value. */
4423 /* The return type is needed to decide how many bytes the function pops.
4424 Signedness plays no role in that, so for simplicity, we pretend it's
4425 always signed. We also assume that the list of arguments passed has
4426 no impact, so we pretend it is unknown. */
4428 emit_call_1 (fun
, NULL
,
4429 get_identifier (XSTR (orgfun
, 0)),
4430 build_function_type (tfom
, NULL_TREE
),
4431 original_args_size
.constant
, args_size
.constant
,
4433 targetm
.calls
.function_arg (args_so_far
,
4434 VOIDmode
, void_type_node
, true),
4436 old_inhibit_defer_pop
+ 1, call_fusage
, flags
, args_so_far
);
4440 rtx last
, datum
= orgfun
;
4441 gcc_assert (GET_CODE (datum
) == SYMBOL_REF
);
4442 last
= last_call_insn ();
4443 add_reg_note (last
, REG_CALL_DECL
, datum
);
4446 /* Right-shift returned value if necessary. */
4447 if (!pcc_struct_value
4448 && TYPE_MODE (tfom
) != BLKmode
4449 && targetm
.calls
.return_in_msb (tfom
))
4451 shift_return_value (TYPE_MODE (tfom
), false, valreg
);
4452 valreg
= gen_rtx_REG (TYPE_MODE (tfom
), REGNO (valreg
));
4455 targetm
.calls
.end_call_args ();
4457 /* For calls to `setjmp', etc., inform function.c:setjmp_warnings
4458 that it should complain if nonvolatile values are live. For
4459 functions that cannot return, inform flow that control does not
4461 if (flags
& ECF_NORETURN
)
4463 /* The barrier note must be emitted
4464 immediately after the CALL_INSN. Some ports emit more than
4465 just a CALL_INSN above, so we must search for it here. */
4466 rtx_insn
*last
= get_last_insn ();
4467 while (!CALL_P (last
))
4469 last
= PREV_INSN (last
);
4470 /* There was no CALL_INSN? */
4471 gcc_assert (last
!= before_call
);
4474 emit_barrier_after (last
);
4477 /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW
4478 and LCT_RETURNS_TWICE, cannot perform non-local gotos. */
4479 if (flags
& ECF_NOTHROW
)
4481 rtx_insn
*last
= get_last_insn ();
4482 while (!CALL_P (last
))
4484 last
= PREV_INSN (last
);
4485 /* There was no CALL_INSN? */
4486 gcc_assert (last
!= before_call
);
4489 make_reg_eh_region_note_nothrow_nononlocal (last
);
4492 /* Now restore inhibit_defer_pop to its actual original value. */
4497 /* Copy the value to the right place. */
4498 if (outmode
!= VOIDmode
&& retval
)
4504 if (value
!= mem_value
)
4505 emit_move_insn (value
, mem_value
);
4507 else if (GET_CODE (valreg
) == PARALLEL
)
4510 value
= gen_reg_rtx (outmode
);
4511 emit_group_store (value
, valreg
, NULL_TREE
, GET_MODE_SIZE (outmode
));
4515 /* Convert to the proper mode if a promotion has been active. */
4516 if (GET_MODE (valreg
) != outmode
)
4518 int unsignedp
= TYPE_UNSIGNED (tfom
);
4520 gcc_assert (promote_function_mode (tfom
, outmode
, &unsignedp
,
4521 fndecl
? TREE_TYPE (fndecl
) : fntype
, 1)
4522 == GET_MODE (valreg
));
4523 valreg
= convert_modes (outmode
, GET_MODE (valreg
), valreg
, 0);
4527 emit_move_insn (value
, valreg
);
4533 if (ACCUMULATE_OUTGOING_ARGS
)
4535 #ifdef REG_PARM_STACK_SPACE
4537 restore_fixed_argument_area (save_area
, argblock
,
4538 high_to_save
, low_to_save
);
4541 /* If we saved any argument areas, restore them. */
4542 for (count
= 0; count
< nargs
; count
++)
4543 if (argvec
[count
].save_area
)
4545 machine_mode save_mode
= GET_MODE (argvec
[count
].save_area
);
4546 rtx adr
= plus_constant (Pmode
, argblock
,
4547 argvec
[count
].locate
.offset
.constant
);
4548 rtx stack_area
= gen_rtx_MEM (save_mode
,
4549 memory_address (save_mode
, adr
));
4551 if (save_mode
== BLKmode
)
4552 emit_block_move (stack_area
,
4554 (copy_rtx (argvec
[count
].save_area
)),
4555 GEN_INT (argvec
[count
].locate
.size
.constant
),
4556 BLOCK_OP_CALL_PARM
);
4558 emit_move_insn (stack_area
, argvec
[count
].save_area
);
4561 highest_outgoing_arg_in_use
= initial_highest_arg_in_use
;
4562 stack_usage_map
= initial_stack_usage_map
;
4565 free (stack_usage_map_buf
);
4571 /* Output a library call to function FUN (a SYMBOL_REF rtx)
4572 (emitting the queue unless NO_QUEUE is nonzero),
4573 for a value of mode OUTMODE,
4574 with NARGS different arguments, passed as alternating rtx values
4575 and machine_modes to convert them to.
4577 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for
4578 `const' calls, LCT_PURE for `pure' calls, or other LCT_ value for
4579 other types of library calls. */
4582 emit_library_call (rtx orgfun
, enum libcall_type fn_type
,
4583 machine_mode outmode
, int nargs
, ...)
4587 va_start (p
, nargs
);
4588 emit_library_call_value_1 (0, orgfun
, NULL_RTX
, fn_type
, outmode
, nargs
, p
);
4592 /* Like emit_library_call except that an extra argument, VALUE,
4593 comes second and says where to store the result.
4594 (If VALUE is zero, this function chooses a convenient way
4595 to return the value.
4597 This function returns an rtx for where the value is to be found.
4598 If VALUE is nonzero, VALUE is returned. */
4601 emit_library_call_value (rtx orgfun
, rtx value
,
4602 enum libcall_type fn_type
,
4603 machine_mode outmode
, int nargs
, ...)
4608 va_start (p
, nargs
);
4609 result
= emit_library_call_value_1 (1, orgfun
, value
, fn_type
, outmode
,
4617 /* Store pointer bounds argument ARG into Bounds Table entry
4618 associated with PARM. */
4620 store_bounds (struct arg_data
*arg
, struct arg_data
*parm
)
4622 rtx slot
= NULL
, ptr
= NULL
, addr
= NULL
;
4624 /* We may pass bounds not associated with any pointer. */
4627 gcc_assert (arg
->special_slot
);
4628 slot
= arg
->special_slot
;
4631 /* Find pointer associated with bounds and where it is
4637 gcc_assert (!arg
->special_slot
);
4639 addr
= adjust_address (parm
->stack
, Pmode
, arg
->pointer_offset
);
4641 else if (REG_P (parm
->reg
))
4643 gcc_assert (arg
->special_slot
);
4644 slot
= arg
->special_slot
;
4646 if (MEM_P (parm
->value
))
4647 addr
= adjust_address (parm
->value
, Pmode
, arg
->pointer_offset
);
4648 else if (REG_P (parm
->value
))
4649 ptr
= gen_rtx_SUBREG (Pmode
, parm
->value
, arg
->pointer_offset
);
4652 gcc_assert (!arg
->pointer_offset
);
4658 gcc_assert (GET_CODE (parm
->reg
) == PARALLEL
);
4660 gcc_assert (arg
->special_slot
);
4661 slot
= arg
->special_slot
;
4663 if (parm
->parallel_value
)
4664 ptr
= chkp_get_value_with_offs (parm
->parallel_value
,
4665 GEN_INT (arg
->pointer_offset
));
4671 /* Expand bounds. */
4673 arg
->value
= expand_normal (arg
->tree_value
);
4675 targetm
.calls
.store_bounds_for_arg (ptr
, addr
, arg
->value
, slot
);
4678 /* Store a single argument for a function call
4679 into the register or memory area where it must be passed.
4680 *ARG describes the argument value and where to pass it.
4682 ARGBLOCK is the address of the stack-block for all the arguments,
4683 or 0 on a machine where arguments are pushed individually.
4685 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4686 so must be careful about how the stack is used.
4688 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4689 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4690 that we need not worry about saving and restoring the stack.
4692 FNDECL is the declaration of the function we are calling.
4694 Return nonzero if this arg should cause sibcall failure,
4698 store_one_arg (struct arg_data
*arg
, rtx argblock
, int flags
,
4699 int variable_size ATTRIBUTE_UNUSED
, int reg_parm_stack_space
)
4701 tree pval
= arg
->tree_value
;
4705 int i
, lower_bound
= 0, upper_bound
= 0;
4706 int sibcall_failure
= 0;
4708 if (TREE_CODE (pval
) == ERROR_MARK
)
4711 /* Push a new temporary level for any temporaries we make for
4715 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
))
4717 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4718 save any previous data at that location. */
4719 if (argblock
&& ! variable_size
&& arg
->stack
)
4721 if (ARGS_GROW_DOWNWARD
)
4723 /* stack_slot is negative, but we want to index stack_usage_map
4724 with positive values. */
4725 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4726 upper_bound
= -INTVAL (XEXP (XEXP (arg
->stack_slot
, 0), 1)) + 1;
4730 lower_bound
= upper_bound
- arg
->locate
.size
.constant
;
4734 if (GET_CODE (XEXP (arg
->stack_slot
, 0)) == PLUS
)
4735 lower_bound
= INTVAL (XEXP (XEXP (arg
->stack_slot
, 0), 1));
4739 upper_bound
= lower_bound
+ arg
->locate
.size
.constant
;
4743 /* Don't worry about things in the fixed argument area;
4744 it has already been saved. */
4745 if (i
< reg_parm_stack_space
)
4746 i
= reg_parm_stack_space
;
4747 while (i
< upper_bound
&& stack_usage_map
[i
] == 0)
4750 if (i
< upper_bound
)
4752 /* We need to make a save area. */
4753 unsigned int size
= arg
->locate
.size
.constant
* BITS_PER_UNIT
;
4754 machine_mode save_mode
= mode_for_size (size
, MODE_INT
, 1);
4755 rtx adr
= memory_address (save_mode
, XEXP (arg
->stack_slot
, 0));
4756 rtx stack_area
= gen_rtx_MEM (save_mode
, adr
);
4758 if (save_mode
== BLKmode
)
4761 = assign_temp (TREE_TYPE (arg
->tree_value
), 1, 1);
4762 preserve_temp_slots (arg
->save_area
);
4763 emit_block_move (validize_mem (copy_rtx (arg
->save_area
)),
4765 GEN_INT (arg
->locate
.size
.constant
),
4766 BLOCK_OP_CALL_PARM
);
4770 arg
->save_area
= gen_reg_rtx (save_mode
);
4771 emit_move_insn (arg
->save_area
, stack_area
);
4777 /* If this isn't going to be placed on both the stack and in registers,
4778 set up the register and number of words. */
4779 if (! arg
->pass_on_stack
)
4781 if (flags
& ECF_SIBCALL
)
4782 reg
= arg
->tail_call_reg
;
4785 partial
= arg
->partial
;
4788 /* Being passed entirely in a register. We shouldn't be called in
4790 gcc_assert (reg
== 0 || partial
!= 0);
4792 /* If this arg needs special alignment, don't load the registers
4794 if (arg
->n_aligned_regs
!= 0)
4797 /* If this is being passed partially in a register, we can't evaluate
4798 it directly into its stack slot. Otherwise, we can. */
4799 if (arg
->value
== 0)
4801 /* stack_arg_under_construction is nonzero if a function argument is
4802 being evaluated directly into the outgoing argument list and
4803 expand_call must take special action to preserve the argument list
4804 if it is called recursively.
4806 For scalar function arguments stack_usage_map is sufficient to
4807 determine which stack slots must be saved and restored. Scalar
4808 arguments in general have pass_on_stack == 0.
4810 If this argument is initialized by a function which takes the
4811 address of the argument (a C++ constructor or a C function
4812 returning a BLKmode structure), then stack_usage_map is
4813 insufficient and expand_call must push the stack around the
4814 function call. Such arguments have pass_on_stack == 1.
4816 Note that it is always safe to set stack_arg_under_construction,
4817 but this generates suboptimal code if set when not needed. */
4819 if (arg
->pass_on_stack
)
4820 stack_arg_under_construction
++;
4822 arg
->value
= expand_expr (pval
,
4824 || TYPE_MODE (TREE_TYPE (pval
)) != arg
->mode
)
4825 ? NULL_RTX
: arg
->stack
,
4826 VOIDmode
, EXPAND_STACK_PARM
);
4828 /* If we are promoting object (or for any other reason) the mode
4829 doesn't agree, convert the mode. */
4831 if (arg
->mode
!= TYPE_MODE (TREE_TYPE (pval
)))
4832 arg
->value
= convert_modes (arg
->mode
, TYPE_MODE (TREE_TYPE (pval
)),
4833 arg
->value
, arg
->unsignedp
);
4835 if (arg
->pass_on_stack
)
4836 stack_arg_under_construction
--;
4839 /* Check for overlap with already clobbered argument area. */
4840 if ((flags
& ECF_SIBCALL
)
4841 && MEM_P (arg
->value
)
4842 && mem_overlaps_already_clobbered_arg_p (XEXP (arg
->value
, 0),
4843 arg
->locate
.size
.constant
))
4844 sibcall_failure
= 1;
4846 /* Don't allow anything left on stack from computation
4847 of argument to alloca. */
4848 if (flags
& ECF_MAY_BE_ALLOCA
)
4849 do_pending_stack_adjust ();
4851 if (arg
->value
== arg
->stack
)
4852 /* If the value is already in the stack slot, we are done. */
4854 else if (arg
->mode
!= BLKmode
)
4857 unsigned int parm_align
;
4859 /* Argument is a scalar, not entirely passed in registers.
4860 (If part is passed in registers, arg->partial says how much
4861 and emit_push_insn will take care of putting it there.)
4863 Push it, and if its size is less than the
4864 amount of space allocated to it,
4865 also bump stack pointer by the additional space.
4866 Note that in C the default argument promotions
4867 will prevent such mismatches. */
4869 size
= GET_MODE_SIZE (arg
->mode
);
4870 /* Compute how much space the push instruction will push.
4871 On many machines, pushing a byte will advance the stack
4872 pointer by a halfword. */
4873 #ifdef PUSH_ROUNDING
4874 size
= PUSH_ROUNDING (size
);
4878 /* Compute how much space the argument should get:
4879 round up to a multiple of the alignment for arguments. */
4880 if (none
!= FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)))
4881 used
= (((size
+ PARM_BOUNDARY
/ BITS_PER_UNIT
- 1)
4882 / (PARM_BOUNDARY
/ BITS_PER_UNIT
))
4883 * (PARM_BOUNDARY
/ BITS_PER_UNIT
));
4885 /* Compute the alignment of the pushed argument. */
4886 parm_align
= arg
->locate
.boundary
;
4887 if (FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)) == downward
)
4889 int pad
= used
- size
;
4892 unsigned int pad_align
= (pad
& -pad
) * BITS_PER_UNIT
;
4893 parm_align
= MIN (parm_align
, pad_align
);
4897 /* This isn't already where we want it on the stack, so put it there.
4898 This can either be done with push or copy insns. */
4899 if (!emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
), NULL_RTX
,
4900 parm_align
, partial
, reg
, used
- size
, argblock
,
4901 ARGS_SIZE_RTX (arg
->locate
.offset
), reg_parm_stack_space
,
4902 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
), true))
4903 sibcall_failure
= 1;
4905 /* Unless this is a partially-in-register argument, the argument is now
4908 arg
->value
= arg
->stack
;
4912 /* BLKmode, at least partly to be pushed. */
4914 unsigned int parm_align
;
4918 /* Pushing a nonscalar.
4919 If part is passed in registers, PARTIAL says how much
4920 and emit_push_insn will take care of putting it there. */
4922 /* Round its size up to a multiple
4923 of the allocation unit for arguments. */
4925 if (arg
->locate
.size
.var
!= 0)
4928 size_rtx
= ARGS_SIZE_RTX (arg
->locate
.size
);
4932 /* PUSH_ROUNDING has no effect on us, because emit_push_insn
4933 for BLKmode is careful to avoid it. */
4934 excess
= (arg
->locate
.size
.constant
4935 - int_size_in_bytes (TREE_TYPE (pval
))
4937 size_rtx
= expand_expr (size_in_bytes (TREE_TYPE (pval
)),
4938 NULL_RTX
, TYPE_MODE (sizetype
),
4942 parm_align
= arg
->locate
.boundary
;
4944 /* When an argument is padded down, the block is aligned to
4945 PARM_BOUNDARY, but the actual argument isn't. */
4946 if (FUNCTION_ARG_PADDING (arg
->mode
, TREE_TYPE (pval
)) == downward
)
4948 if (arg
->locate
.size
.var
)
4949 parm_align
= BITS_PER_UNIT
;
4952 unsigned int excess_align
= (excess
& -excess
) * BITS_PER_UNIT
;
4953 parm_align
= MIN (parm_align
, excess_align
);
4957 if ((flags
& ECF_SIBCALL
) && MEM_P (arg
->value
))
4959 /* emit_push_insn might not work properly if arg->value and
4960 argblock + arg->locate.offset areas overlap. */
4964 if (XEXP (x
, 0) == crtl
->args
.internal_arg_pointer
4965 || (GET_CODE (XEXP (x
, 0)) == PLUS
4966 && XEXP (XEXP (x
, 0), 0) ==
4967 crtl
->args
.internal_arg_pointer
4968 && CONST_INT_P (XEXP (XEXP (x
, 0), 1))))
4970 if (XEXP (x
, 0) != crtl
->args
.internal_arg_pointer
)
4971 i
= INTVAL (XEXP (XEXP (x
, 0), 1));
4973 /* expand_call should ensure this. */
4974 gcc_assert (!arg
->locate
.offset
.var
4975 && arg
->locate
.size
.var
== 0
4976 && CONST_INT_P (size_rtx
));
4978 if (arg
->locate
.offset
.constant
> i
)
4980 if (arg
->locate
.offset
.constant
< i
+ INTVAL (size_rtx
))
4981 sibcall_failure
= 1;
4983 else if (arg
->locate
.offset
.constant
< i
)
4985 /* Use arg->locate.size.constant instead of size_rtx
4986 because we only care about the part of the argument
4988 if (i
< (arg
->locate
.offset
.constant
4989 + arg
->locate
.size
.constant
))
4990 sibcall_failure
= 1;
4994 /* Even though they appear to be at the same location,
4995 if part of the outgoing argument is in registers,
4996 they aren't really at the same location. Check for
4997 this by making sure that the incoming size is the
4998 same as the outgoing size. */
4999 if (arg
->locate
.size
.constant
!= INTVAL (size_rtx
))
5000 sibcall_failure
= 1;
5005 emit_push_insn (arg
->value
, arg
->mode
, TREE_TYPE (pval
), size_rtx
,
5006 parm_align
, partial
, reg
, excess
, argblock
,
5007 ARGS_SIZE_RTX (arg
->locate
.offset
), reg_parm_stack_space
,
5008 ARGS_SIZE_RTX (arg
->locate
.alignment_pad
), false);
5010 /* Unless this is a partially-in-register argument, the argument is now
5013 ??? Unlike the case above, in which we want the actual
5014 address of the data, so that we can load it directly into a
5015 register, here we want the address of the stack slot, so that
5016 it's properly aligned for word-by-word copying or something
5017 like that. It's not clear that this is always correct. */
5019 arg
->value
= arg
->stack_slot
;
5022 if (arg
->reg
&& GET_CODE (arg
->reg
) == PARALLEL
)
5024 tree type
= TREE_TYPE (arg
->tree_value
);
5026 = emit_group_load_into_temps (arg
->reg
, arg
->value
, type
,
5027 int_size_in_bytes (type
));
5030 /* Mark all slots this store used. */
5031 if (ACCUMULATE_OUTGOING_ARGS
&& !(flags
& ECF_SIBCALL
)
5032 && argblock
&& ! variable_size
&& arg
->stack
)
5033 for (i
= lower_bound
; i
< upper_bound
; i
++)
5034 stack_usage_map
[i
] = 1;
5036 /* Once we have pushed something, pops can't safely
5037 be deferred during the rest of the arguments. */
5040 /* Free any temporary slots made in processing this argument. */
5043 return sibcall_failure
;
5046 /* Nonzero if we do not know how to pass TYPE solely in registers. */
5049 must_pass_in_stack_var_size (machine_mode mode ATTRIBUTE_UNUSED
,
5055 /* If the type has variable size... */
5056 if (TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
5059 /* If the type is marked as addressable (it is required
5060 to be constructed into the stack)... */
5061 if (TREE_ADDRESSABLE (type
))
5067 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
5068 takes trailing padding of a structure into account. */
5069 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
5072 must_pass_in_stack_var_size_or_pad (machine_mode mode
, const_tree type
)
5077 /* If the type has variable size... */
5078 if (TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
5081 /* If the type is marked as addressable (it is required
5082 to be constructed into the stack)... */
5083 if (TREE_ADDRESSABLE (type
))
5086 /* If the padding and mode of the type is such that a copy into
5087 a register would put it into the wrong part of the register. */
5089 && int_size_in_bytes (type
) % (PARM_BOUNDARY
/ BITS_PER_UNIT
)
5090 && (FUNCTION_ARG_PADDING (mode
, type
)
5091 == (BYTES_BIG_ENDIAN
? upward
: downward
)))