1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989-2016 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"
30 #include "stringpool.h"
35 #include "diagnostic-core.h"
36 #include "fold-const.h"
37 #include "stor-layout.h"
39 #include "internal-fn.h"
45 #include "langhooks.h"
49 #include "tree-chkp.h"
53 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
54 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
56 /* Data structure and subroutines used within expand_call. */
60 /* Tree node for this argument. */
62 /* Mode for value; TYPE_MODE unless promoted. */
64 /* Current RTL value for argument, or 0 if it isn't precomputed. */
66 /* Initially-compute RTL value for argument; only for const functions. */
68 /* Register to pass this argument in, 0 if passed on stack, or an
69 PARALLEL if the arg is to be copied into multiple non-contiguous
72 /* Register to pass this argument in when generating tail call sequence.
73 This is not the same register as for normal calls on machines with
76 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
77 form for emit_group_move. */
79 /* If value is passed in neither reg nor stack, this field holds a number
80 of a special slot to be used. */
82 /* For pointer bounds hold an index of parm bounds are bound to. -1 if
83 there is no such pointer. */
85 /* If pointer_arg refers a structure, then pointer_offset holds an offset
86 of a pointer in this structure. */
88 /* If REG was promoted from the actual mode of the argument expression,
89 indicates whether the promotion is sign- or zero-extended. */
91 /* Number of bytes to put in registers. 0 means put the whole arg
92 in registers. Also 0 if not passed in registers. */
94 /* Nonzero if argument must be passed on stack.
95 Note that some arguments may be passed on the stack
96 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
97 pass_on_stack identifies arguments that *cannot* go in registers. */
99 /* Some fields packaged up for locate_and_pad_parm. */
100 struct locate_and_pad_arg_data locate;
101 /* Location on the stack at which parameter should be stored. The store
102 has already been done if STACK == VALUE. */
104 /* Location on the stack of the start of this argument slot. This can
105 differ from STACK if this arg pads downward. This location is known
106 to be aligned to TARGET_FUNCTION_ARG_BOUNDARY. */
108 /* Place that this stack area has been saved, if needed. */
110 /* If an argument's alignment does not permit direct copying into registers,
111 copy in smaller-sized pieces into pseudos. These are stored in a
112 block pointed to by this field. The next field says how many
113 word-sized pseudos we made. */
118 /* A vector of one char per byte of stack space. A byte if nonzero if
119 the corresponding stack location has been used.
120 This vector is used to prevent a function call within an argument from
121 clobbering any stack already set up. */
122 static char *stack_usage_map;
124 /* Size of STACK_USAGE_MAP. */
125 static int highest_outgoing_arg_in_use;
127 /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
128 stack location's tail call argument has been already stored into the stack.
129 This bitmap is used to prevent sibling call optimization if function tries
130 to use parent's incoming argument slots when they have been already
131 overwritten with tail call arguments. */
132 static sbitmap stored_args_map;
134 /* stack_arg_under_construction is nonzero when an argument may be
135 initialized with a constructor call (including a C function that
136 returns a BLKmode struct) and expand_call must take special action
137 to make sure the object being constructed does not overlap the
138 argument list for the constructor call. */
139 static int stack_arg_under_construction;
141 static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT,
142 HOST_WIDE_INT, rtx, rtx, int, rtx, int,
144 static void precompute_register_parameters (int, struct arg_data *, int *);
145 static void store_bounds (struct arg_data *, struct arg_data *);
146 static int store_one_arg (struct arg_data *, rtx, int, int, int);
147 static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
148 static int finalize_must_preallocate (int, int, struct arg_data *,
150 static void precompute_arguments (int, struct arg_data *);
151 static int compute_argument_block_size (int, struct args_size *, tree, tree, int);
152 static void initialize_argument_information (int, struct arg_data *,
153 struct args_size *, int,
155 tree, tree, cumulative_args_t, int,
156 rtx *, int *, int *, int *,
158 static void compute_argument_addresses (struct arg_data *, rtx, int);
159 static rtx rtx_for_function_call (tree, tree);
160 static void load_register_parameters (struct arg_data *, int, rtx *, int,
162 static rtx emit_library_call_value_1 (int, rtx, rtx, enum libcall_type,
163 machine_mode, int, va_list);
164 static int special_function_p (const_tree, int);
165 static int check_sibcall_argument_overlap_1 (rtx);
166 static int check_sibcall_argument_overlap (rtx_insn *, struct arg_data *, int);
168 static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
170 static tree split_complex_types (tree);
172 #ifdef REG_PARM_STACK_SPACE
173 static rtx save_fixed_argument_area (int, rtx, int *, int *);
174 static void restore_fixed_argument_area (rtx, rtx, int, int);
177 /* Force FUNEXP into a form suitable for the address of a CALL,
178 and return that as an rtx. Also load the static chain register
179 if FNDECL is a nested function.
181 CALL_FUSAGE points to a variable holding the prospective
182 CALL_INSN_FUNCTION_USAGE information. */
185 prepare_call_address (tree fndecl_or_type, rtx funexp, rtx static_chain_value,
186 rtx *call_fusage, int reg_parm_seen, int sibcallp)
188 /* Make a valid memory address and copy constants through pseudo-regs,
189 but not for a constant address if -fno-function-cse. */
190 if (GET_CODE (funexp) != SYMBOL_REF)
191 /* If we are using registers for parameters, force the
192 function address into a register now. */
193 funexp = ((reg_parm_seen
194 && targetm.small_register_classes_for_mode_p (FUNCTION_MODE))
195 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
196 : memory_address (FUNCTION_MODE, funexp));
199 /* funexp could be a SYMBOL_REF represents a function pointer which is
200 of ptr_mode. In this case, it should be converted into address mode
201 to be a valid address for memory rtx pattern. See PR 64971. */
202 if (GET_MODE (funexp) != Pmode)
203 funexp = convert_memory_address (Pmode, funexp);
207 if (!NO_FUNCTION_CSE && optimize && ! flag_no_function_cse)
208 funexp = force_reg (Pmode, funexp);
212 if (static_chain_value != 0
213 && (TREE_CODE (fndecl_or_type) != FUNCTION_DECL
214 || DECL_STATIC_CHAIN (fndecl_or_type)))
218 chain = targetm.calls.static_chain (fndecl_or_type, false);
219 static_chain_value = convert_memory_address (Pmode, static_chain_value);
221 emit_move_insn (chain, static_chain_value);
223 use_reg (call_fusage, chain);
229 /* Generate instructions to call function FUNEXP,
230 and optionally pop the results.
231 The CALL_INSN is the first insn generated.
233 FNDECL is the declaration node of the function. This is given to the
234 hook TARGET_RETURN_POPS_ARGS to determine whether this function pops
237 FUNTYPE is the data type of the function. This is given to the hook
238 TARGET_RETURN_POPS_ARGS to determine whether this function pops its
239 own args. We used to allow an identifier for library functions, but
240 that doesn't work when the return type is an aggregate type and the
241 calling convention says that the pointer to this aggregate is to be
242 popped by the callee.
244 STACK_SIZE is the number of bytes of arguments on the stack,
245 ROUNDED_STACK_SIZE is that number rounded up to
246 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
247 both to put into the call insn and to generate explicit popping
250 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
251 It is zero if this call doesn't want a structure value.
253 NEXT_ARG_REG is the rtx that results from executing
254 targetm.calls.function_arg (&args_so_far, VOIDmode, void_type_node, true)
255 just after all the args have had their registers assigned.
256 This could be whatever you like, but normally it is the first
257 arg-register beyond those used for args in this call,
258 or 0 if all the arg-registers are used in this call.
259 It is passed on to `gen_call' so you can put this info in the call insn.
261 VALREG is a hard register in which a value is returned,
262 or 0 if the call does not return a value.
264 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
265 the args to this call were processed.
266 We restore `inhibit_defer_pop' to that value.
268 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
269 denote registers used by the called function. */
272 emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNUSED,
273 tree funtype ATTRIBUTE_UNUSED,
274 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED,
275 HOST_WIDE_INT rounded_stack_size,
276 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED,
277 rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg,
278 int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags,
279 cumulative_args_t args_so_far ATTRIBUTE_UNUSED)
281 rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
282 rtx call, funmem, pat;
283 int already_popped = 0;
284 HOST_WIDE_INT n_popped = 0;
286 /* Sibling call patterns never pop arguments (no sibcall(_value)_pop
287 patterns exist). Any popping that the callee does on return will
288 be from our caller's frame rather than ours. */
289 if (!(ecf_flags & ECF_SIBCALL))
291 n_popped += targetm.calls.return_pops_args (fndecl, funtype, stack_size);
293 #ifdef CALL_POPS_ARGS
294 n_popped += CALL_POPS_ARGS (*get_cumulative_args (args_so_far));
298 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
299 and we don't want to load it into a register as an optimization,
300 because prepare_call_address already did it if it should be done. */
301 if (GET_CODE (funexp) != SYMBOL_REF)
302 funexp = memory_address (FUNCTION_MODE, funexp);
304 funmem = gen_rtx_MEM (FUNCTION_MODE, funexp);
305 if (fndecl && TREE_CODE (fndecl) == FUNCTION_DECL)
309 /* Although a built-in FUNCTION_DECL and its non-__builtin
310 counterpart compare equal and get a shared mem_attrs, they
311 produce different dump output in compare-debug compilations,
312 if an entry gets garbage collected in one compilation, then
313 adds a different (but equivalent) entry, while the other
314 doesn't run the garbage collector at the same spot and then
315 shares the mem_attr with the equivalent entry. */
316 if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL)
318 tree t2 = builtin_decl_explicit (DECL_FUNCTION_CODE (t));
323 set_mem_expr (funmem, t);
326 set_mem_expr (funmem, build_simple_mem_ref (CALL_EXPR_FN (fntree)));
328 if (ecf_flags & ECF_SIBCALL)
331 pat = targetm.gen_sibcall_value (valreg, funmem,
332 rounded_stack_size_rtx,
333 next_arg_reg, NULL_RTX);
335 pat = targetm.gen_sibcall (funmem, rounded_stack_size_rtx,
336 next_arg_reg, GEN_INT (struct_value_size));
338 /* If the target has "call" or "call_value" insns, then prefer them
339 if no arguments are actually popped. If the target does not have
340 "call" or "call_value" insns, then we must use the popping versions
341 even if the call has no arguments to pop. */
342 else if (n_popped > 0
344 ? targetm.have_call_value ()
345 : targetm.have_call ()))
347 rtx n_pop = GEN_INT (n_popped);
349 /* If this subroutine pops its own args, record that in the call insn
350 if possible, for the sake of frame pointer elimination. */
353 pat = targetm.gen_call_value_pop (valreg, funmem,
354 rounded_stack_size_rtx,
355 next_arg_reg, n_pop);
357 pat = targetm.gen_call_pop (funmem, rounded_stack_size_rtx,
358 next_arg_reg, n_pop);
365 pat = targetm.gen_call_value (valreg, funmem, rounded_stack_size_rtx,
366 next_arg_reg, NULL_RTX);
368 pat = targetm.gen_call (funmem, rounded_stack_size_rtx, next_arg_reg,
369 GEN_INT (struct_value_size));
373 /* Find the call we just emitted. */
374 rtx_call_insn *call_insn = last_call_insn ();
376 /* Some target create a fresh MEM instead of reusing the one provided
377 above. Set its MEM_EXPR. */
378 call = get_call_rtx_from (call_insn);
380 && MEM_EXPR (XEXP (call, 0)) == NULL_TREE
381 && MEM_EXPR (funmem) != NULL_TREE)
382 set_mem_expr (XEXP (call, 0), MEM_EXPR (funmem));
384 /* Mark instrumented calls. */
386 CALL_EXPR_WITH_BOUNDS_P (call) = CALL_WITH_BOUNDS_P (fntree);
388 /* Put the register usage information there. */
389 add_function_usage_to (call_insn, call_fusage);
391 /* If this is a const call, then set the insn's unchanging bit. */
392 if (ecf_flags & ECF_CONST)
393 RTL_CONST_CALL_P (call_insn) = 1;
395 /* If this is a pure call, then set the insn's unchanging bit. */
396 if (ecf_flags & ECF_PURE)
397 RTL_PURE_CALL_P (call_insn) = 1;
399 /* If this is a const call, then set the insn's unchanging bit. */
400 if (ecf_flags & ECF_LOOPING_CONST_OR_PURE)
401 RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn) = 1;
403 /* Create a nothrow REG_EH_REGION note, if needed. */
404 make_reg_eh_region_note (call_insn, ecf_flags, 0);
406 if (ecf_flags & ECF_NORETURN)
407 add_reg_note (call_insn, REG_NORETURN, const0_rtx);
409 if (ecf_flags & ECF_RETURNS_TWICE)
411 add_reg_note (call_insn, REG_SETJMP, const0_rtx);
412 cfun->calls_setjmp = 1;
415 SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
417 /* Restore this now, so that we do defer pops for this call's args
418 if the context of the call as a whole permits. */
419 inhibit_defer_pop = old_inhibit_defer_pop;
424 CALL_INSN_FUNCTION_USAGE (call_insn)
425 = gen_rtx_EXPR_LIST (VOIDmode,
426 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
427 CALL_INSN_FUNCTION_USAGE (call_insn));
428 rounded_stack_size -= n_popped;
429 rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
430 stack_pointer_delta -= n_popped;
432 add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
434 /* If popup is needed, stack realign must use DRAP */
435 if (SUPPORTS_STACK_ALIGNMENT)
436 crtl->need_drap = true;
438 /* For noreturn calls when not accumulating outgoing args force
439 REG_ARGS_SIZE note to prevent crossjumping of calls with different
441 else if (!ACCUMULATE_OUTGOING_ARGS && (ecf_flags & ECF_NORETURN) != 0)
442 add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
444 if (!ACCUMULATE_OUTGOING_ARGS)
446 /* If returning from the subroutine does not automatically pop the args,
447 we need an instruction to pop them sooner or later.
448 Perhaps do it now; perhaps just record how much space to pop later.
450 If returning from the subroutine does pop the args, indicate that the
451 stack pointer will be changed. */
453 if (rounded_stack_size != 0)
455 if (ecf_flags & ECF_NORETURN)
456 /* Just pretend we did the pop. */
457 stack_pointer_delta -= rounded_stack_size;
458 else if (flag_defer_pop && inhibit_defer_pop == 0
459 && ! (ecf_flags & (ECF_CONST | ECF_PURE)))
460 pending_stack_adjust += rounded_stack_size;
462 adjust_stack (rounded_stack_size_rtx);
465 /* When we accumulate outgoing args, we must avoid any stack manipulations.
466 Restore the stack pointer to its original value now. Usually
467 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
468 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
469 popping variants of functions exist as well.
471 ??? We may optimize similar to defer_pop above, but it is
472 probably not worthwhile.
474 ??? It will be worthwhile to enable combine_stack_adjustments even for
477 anti_adjust_stack (GEN_INT (n_popped));
480 /* Determine if the function identified by NAME and FNDECL is one with
481 special properties we wish to know about.
483 For example, if the function might return more than one time (setjmp), then
484 set RETURNS_TWICE to a nonzero value.
486 Similarly set NORETURN if the function is in the longjmp family.
488 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
489 space from the stack such as alloca. */
492 special_function_p (const_tree fndecl, int flags)
494 tree name_decl = DECL_NAME (fndecl);
496 /* For instrumentation clones we want to derive flags
497 from the original name. */
498 if (cgraph_node::get (fndecl)
499 && cgraph_node::get (fndecl)->instrumentation_clone)
500 name_decl = DECL_NAME (cgraph_node::get (fndecl)->orig_decl);
502 if (fndecl && name_decl
503 && IDENTIFIER_LENGTH (name_decl) <= 17
504 /* Exclude functions not at the file scope, or not `extern',
505 since they are not the magic functions we would otherwise
507 FIXME: this should be handled with attributes, not with this
508 hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
509 because you can declare fork() inside a function if you
511 && (DECL_CONTEXT (fndecl) == NULL_TREE
512 || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL)
513 && TREE_PUBLIC (fndecl))
515 const char *name = IDENTIFIER_POINTER (name_decl);
516 const char *tname = name;
518 /* We assume that alloca will always be called by name. It
519 makes no sense to pass it as a pointer-to-function to
520 anything that does not understand its behavior. */
521 if (IDENTIFIER_LENGTH (name_decl) == 6
523 && ! strcmp (name, "alloca"))
524 flags |= ECF_MAY_BE_ALLOCA;
526 /* Disregard prefix _, __, __x or __builtin_. */
531 && !strncmp (name + 3, "uiltin_", 7))
533 else if (name[1] == '_' && name[2] == 'x')
535 else if (name[1] == '_')
544 && (! strcmp (tname, "setjmp")
545 || ! strcmp (tname, "setjmp_syscall")))
547 && ! strcmp (tname, "sigsetjmp"))
549 && ! strcmp (tname, "savectx")))
550 flags |= ECF_RETURNS_TWICE | ECF_LEAF;
553 && ! strcmp (tname, "siglongjmp"))
554 flags |= ECF_NORETURN;
556 else if ((tname[0] == 'q' && tname[1] == 's'
557 && ! strcmp (tname, "qsetjmp"))
558 || (tname[0] == 'v' && tname[1] == 'f'
559 && ! strcmp (tname, "vfork"))
560 || (tname[0] == 'g' && tname[1] == 'e'
561 && !strcmp (tname, "getcontext")))
562 flags |= ECF_RETURNS_TWICE | ECF_LEAF;
564 else if (tname[0] == 'l' && tname[1] == 'o'
565 && ! strcmp (tname, "longjmp"))
566 flags |= ECF_NORETURN;
569 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
570 switch (DECL_FUNCTION_CODE (fndecl))
572 case BUILT_IN_ALLOCA:
573 case BUILT_IN_ALLOCA_WITH_ALIGN:
574 flags |= ECF_MAY_BE_ALLOCA;
583 /* Similar to special_function_p; return a set of ERF_ flags for the
586 decl_return_flags (tree fndecl)
589 tree type = TREE_TYPE (fndecl);
593 attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
597 attr = TREE_VALUE (TREE_VALUE (attr));
598 if (!attr || TREE_STRING_LENGTH (attr) < 1)
601 switch (TREE_STRING_POINTER (attr)[0])
607 return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1');
618 /* Return nonzero when FNDECL represents a call to setjmp. */
621 setjmp_call_p (const_tree fndecl)
623 if (DECL_IS_RETURNS_TWICE (fndecl))
624 return ECF_RETURNS_TWICE;
625 return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE;
629 /* Return true if STMT is an alloca call. */
632 gimple_alloca_call_p (const gimple *stmt)
636 if (!is_gimple_call (stmt))
639 fndecl = gimple_call_fndecl (stmt);
640 if (fndecl && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA))
646 /* Return true when exp contains alloca call. */
649 alloca_call_p (const_tree exp)
652 if (TREE_CODE (exp) == CALL_EXPR
653 && (fndecl = get_callee_fndecl (exp))
654 && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA))
659 /* Return TRUE if FNDECL is either a TM builtin or a TM cloned
660 function. Return FALSE otherwise. */
663 is_tm_builtin (const_tree fndecl)
668 if (decl_is_tm_clone (fndecl))
671 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
673 switch (DECL_FUNCTION_CODE (fndecl))
675 case BUILT_IN_TM_COMMIT:
676 case BUILT_IN_TM_COMMIT_EH:
677 case BUILT_IN_TM_ABORT:
678 case BUILT_IN_TM_IRREVOCABLE:
679 case BUILT_IN_TM_GETTMCLONE_IRR:
680 case BUILT_IN_TM_MEMCPY:
681 case BUILT_IN_TM_MEMMOVE:
682 case BUILT_IN_TM_MEMSET:
683 CASE_BUILT_IN_TM_STORE (1):
684 CASE_BUILT_IN_TM_STORE (2):
685 CASE_BUILT_IN_TM_STORE (4):
686 CASE_BUILT_IN_TM_STORE (8):
687 CASE_BUILT_IN_TM_STORE (FLOAT):
688 CASE_BUILT_IN_TM_STORE (DOUBLE):
689 CASE_BUILT_IN_TM_STORE (LDOUBLE):
690 CASE_BUILT_IN_TM_STORE (M64):
691 CASE_BUILT_IN_TM_STORE (M128):
692 CASE_BUILT_IN_TM_STORE (M256):
693 CASE_BUILT_IN_TM_LOAD (1):
694 CASE_BUILT_IN_TM_LOAD (2):
695 CASE_BUILT_IN_TM_LOAD (4):
696 CASE_BUILT_IN_TM_LOAD (8):
697 CASE_BUILT_IN_TM_LOAD (FLOAT):
698 CASE_BUILT_IN_TM_LOAD (DOUBLE):
699 CASE_BUILT_IN_TM_LOAD (LDOUBLE):
700 CASE_BUILT_IN_TM_LOAD (M64):
701 CASE_BUILT_IN_TM_LOAD (M128):
702 CASE_BUILT_IN_TM_LOAD (M256):
703 case BUILT_IN_TM_LOG:
704 case BUILT_IN_TM_LOG_1:
705 case BUILT_IN_TM_LOG_2:
706 case BUILT_IN_TM_LOG_4:
707 case BUILT_IN_TM_LOG_8:
708 case BUILT_IN_TM_LOG_FLOAT:
709 case BUILT_IN_TM_LOG_DOUBLE:
710 case BUILT_IN_TM_LOG_LDOUBLE:
711 case BUILT_IN_TM_LOG_M64:
712 case BUILT_IN_TM_LOG_M128:
713 case BUILT_IN_TM_LOG_M256:
722 /* Detect flags (function attributes) from the function decl or type node. */
725 flags_from_decl_or_type (const_tree exp)
731 /* The function exp may have the `malloc' attribute. */
732 if (DECL_IS_MALLOC (exp))
735 /* The function exp may have the `returns_twice' attribute. */
736 if (DECL_IS_RETURNS_TWICE (exp))
737 flags |= ECF_RETURNS_TWICE;
739 /* Process the pure and const attributes. */
740 if (TREE_READONLY (exp))
742 if (DECL_PURE_P (exp))
744 if (DECL_LOOPING_CONST_OR_PURE_P (exp))
745 flags |= ECF_LOOPING_CONST_OR_PURE;
747 if (DECL_IS_NOVOPS (exp))
749 if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp)))
752 if (TREE_NOTHROW (exp))
753 flags |= ECF_NOTHROW;
757 if (is_tm_builtin (exp))
758 flags |= ECF_TM_BUILTIN;
759 else if ((flags & (ECF_CONST|ECF_NOVOPS)) != 0
760 || lookup_attribute ("transaction_pure",
761 TYPE_ATTRIBUTES (TREE_TYPE (exp))))
762 flags |= ECF_TM_PURE;
765 flags = special_function_p (exp, flags);
767 else if (TYPE_P (exp))
769 if (TYPE_READONLY (exp))
773 && ((flags & ECF_CONST) != 0
774 || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp))))
775 flags |= ECF_TM_PURE;
780 if (TREE_THIS_VOLATILE (exp))
782 flags |= ECF_NORETURN;
783 if (flags & (ECF_CONST|ECF_PURE))
784 flags |= ECF_LOOPING_CONST_OR_PURE;
790 /* Detect flags from a CALL_EXPR. */
793 call_expr_flags (const_tree t)
796 tree decl = get_callee_fndecl (t);
798 /* We may have UBSan internal functions here. */
799 if (!CALL_EXPR_FN (t))
800 return ECF_CONST | ECF_LEAF | ECF_NOTHROW;
803 flags = flags_from_decl_or_type (decl);
804 else if (CALL_EXPR_FN (t) == NULL_TREE)
805 flags = internal_fn_flags (CALL_EXPR_IFN (t));
808 t = TREE_TYPE (CALL_EXPR_FN (t));
809 if (t && TREE_CODE (t) == POINTER_TYPE)
810 flags = flags_from_decl_or_type (TREE_TYPE (t));
818 /* Return true if TYPE should be passed by invisible reference. */
821 pass_by_reference (CUMULATIVE_ARGS *ca, machine_mode mode,
822 tree type, bool named_arg)
826 /* If this type contains non-trivial constructors, then it is
827 forbidden for the middle-end to create any new copies. */
828 if (TREE_ADDRESSABLE (type))
831 /* GCC post 3.4 passes *all* variable sized types by reference. */
832 if (!TYPE_SIZE (type) || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
835 /* If a record type should be passed the same as its first (and only)
836 member, use the type and mode of that member. */
837 if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
839 type = TREE_TYPE (first_field (type));
840 mode = TYPE_MODE (type);
844 return targetm.calls.pass_by_reference (pack_cumulative_args (ca), mode,
848 /* Return true if TYPE, which is passed by reference, should be callee
849 copied instead of caller copied. */
852 reference_callee_copied (CUMULATIVE_ARGS *ca, machine_mode mode,
853 tree type, bool named_arg)
855 if (type && TREE_ADDRESSABLE (type))
857 return targetm.calls.callee_copies (pack_cumulative_args (ca), mode, type,
862 /* Precompute all register parameters as described by ARGS, storing values
863 into fields within the ARGS array.
865 NUM_ACTUALS indicates the total number elements in the ARGS array.
867 Set REG_PARM_SEEN if we encounter a register parameter. */
870 precompute_register_parameters (int num_actuals, struct arg_data *args,
877 for (i = 0; i < num_actuals; i++)
878 if (args[i].reg != 0 && ! args[i].pass_on_stack)
882 if (args[i].value == 0)
885 args[i].value = expand_normal (args[i].tree_value);
886 preserve_temp_slots (args[i].value);
890 /* If we are to promote the function arg to a wider mode,
893 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
895 = convert_modes (args[i].mode,
896 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
897 args[i].value, args[i].unsignedp);
899 /* If the value is a non-legitimate constant, force it into a
900 pseudo now. TLS symbols sometimes need a call to resolve. */
901 if (CONSTANT_P (args[i].value)
902 && !targetm.legitimate_constant_p (args[i].mode, args[i].value))
903 args[i].value = force_reg (args[i].mode, args[i].value);
905 /* If we're going to have to load the value by parts, pull the
906 parts into pseudos. The part extraction process can involve
907 non-trivial computation. */
908 if (GET_CODE (args[i].reg) == PARALLEL)
910 tree type = TREE_TYPE (args[i].tree_value);
911 args[i].parallel_value
912 = emit_group_load_into_temps (args[i].reg, args[i].value,
913 type, int_size_in_bytes (type));
916 /* If the value is expensive, and we are inside an appropriately
917 short loop, put the value into a pseudo and then put the pseudo
920 For small register classes, also do this if this call uses
921 register parameters. This is to avoid reload conflicts while
922 loading the parameters registers. */
924 else if ((! (REG_P (args[i].value)
925 || (GET_CODE (args[i].value) == SUBREG
926 && REG_P (SUBREG_REG (args[i].value)))))
927 && args[i].mode != BLKmode
928 && (set_src_cost (args[i].value, args[i].mode,
929 optimize_insn_for_speed_p ())
932 && targetm.small_register_classes_for_mode_p (args[i].mode))
934 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
938 #ifdef REG_PARM_STACK_SPACE
940 /* The argument list is the property of the called routine and it
941 may clobber it. If the fixed area has been used for previous
942 parameters, we must save and restore it. */
945 save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
950 /* Compute the boundary of the area that needs to be saved, if any. */
951 high = reg_parm_stack_space;
952 if (ARGS_GROW_DOWNWARD)
955 if (high > highest_outgoing_arg_in_use)
956 high = highest_outgoing_arg_in_use;
958 for (low = 0; low < high; low++)
959 if (stack_usage_map[low] != 0)
962 machine_mode save_mode;
968 while (stack_usage_map[--high] == 0)
972 *high_to_save = high;
974 num_to_save = high - low + 1;
975 save_mode = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
977 /* If we don't have the required alignment, must do this
979 if ((low & (MIN (GET_MODE_SIZE (save_mode),
980 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
983 if (ARGS_GROW_DOWNWARD)
988 addr = plus_constant (Pmode, argblock, delta);
989 stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr));
991 set_mem_align (stack_area, PARM_BOUNDARY);
992 if (save_mode == BLKmode)
994 save_area = assign_stack_temp (BLKmode, num_to_save);
995 emit_block_move (validize_mem (save_area), stack_area,
996 GEN_INT (num_to_save), BLOCK_OP_CALL_PARM);
1000 save_area = gen_reg_rtx (save_mode);
1001 emit_move_insn (save_area, stack_area);
1011 restore_fixed_argument_area (rtx save_area, rtx argblock, int high_to_save, int low_to_save)
1013 machine_mode save_mode = GET_MODE (save_area);
1015 rtx addr, stack_area;
1017 if (ARGS_GROW_DOWNWARD)
1018 delta = -high_to_save;
1020 delta = low_to_save;
1022 addr = plus_constant (Pmode, argblock, delta);
1023 stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr));
1024 set_mem_align (stack_area, PARM_BOUNDARY);
1026 if (save_mode != BLKmode)
1027 emit_move_insn (stack_area, save_area);
1029 emit_block_move (stack_area, validize_mem (save_area),
1030 GEN_INT (high_to_save - low_to_save + 1),
1031 BLOCK_OP_CALL_PARM);
1033 #endif /* REG_PARM_STACK_SPACE */
1035 /* If any elements in ARGS refer to parameters that are to be passed in
1036 registers, but not in memory, and whose alignment does not permit a
1037 direct copy into registers. Copy the values into a group of pseudos
1038 which we will later copy into the appropriate hard registers.
1040 Pseudos for each unaligned argument will be stored into the array
1041 args[argnum].aligned_regs. The caller is responsible for deallocating
1042 the aligned_regs array if it is nonzero. */
1045 store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals)
1049 for (i = 0; i < num_actuals; i++)
1050 if (args[i].reg != 0 && ! args[i].pass_on_stack
1051 && GET_CODE (args[i].reg) != PARALLEL
1052 && args[i].mode == BLKmode
1053 && MEM_P (args[i].value)
1054 && (MEM_ALIGN (args[i].value)
1055 < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
1057 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1058 int endian_correction = 0;
1060 if (args[i].partial)
1062 gcc_assert (args[i].partial % UNITS_PER_WORD == 0);
1063 args[i].n_aligned_regs = args[i].partial / UNITS_PER_WORD;
1067 args[i].n_aligned_regs
1068 = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1071 args[i].aligned_regs = XNEWVEC (rtx, args[i].n_aligned_regs);
1073 /* Structures smaller than a word are normally aligned to the
1074 least significant byte. On a BYTES_BIG_ENDIAN machine,
1075 this means we must skip the empty high order bytes when
1076 calculating the bit offset. */
1077 if (bytes < UNITS_PER_WORD
1078 #ifdef BLOCK_REG_PADDING
1079 && (BLOCK_REG_PADDING (args[i].mode,
1080 TREE_TYPE (args[i].tree_value), 1)
1086 endian_correction = BITS_PER_WORD - bytes * BITS_PER_UNIT;
1088 for (j = 0; j < args[i].n_aligned_regs; j++)
1090 rtx reg = gen_reg_rtx (word_mode);
1091 rtx word = operand_subword_force (args[i].value, j, BLKmode);
1092 int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
1094 args[i].aligned_regs[j] = reg;
1095 word = extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
1096 word_mode, word_mode, false);
1098 /* There is no need to restrict this code to loading items
1099 in TYPE_ALIGN sized hunks. The bitfield instructions can
1100 load up entire word sized registers efficiently.
1102 ??? This may not be needed anymore.
1103 We use to emit a clobber here but that doesn't let later
1104 passes optimize the instructions we emit. By storing 0 into
1105 the register later passes know the first AND to zero out the
1106 bitfield being set in the register is unnecessary. The store
1107 of 0 will be deleted as will at least the first AND. */
1109 emit_move_insn (reg, const0_rtx);
1111 bytes -= bitsize / BITS_PER_UNIT;
1112 store_bit_field (reg, bitsize, endian_correction, 0, 0,
1113 word_mode, word, false);
1118 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
1121 NUM_ACTUALS is the total number of parameters.
1123 N_NAMED_ARGS is the total number of named arguments.
1125 STRUCT_VALUE_ADDR_VALUE is the implicit argument for a struct return
1128 FNDECL is the tree code for the target of this call (if known)
1130 ARGS_SO_FAR holds state needed by the target to know where to place
1133 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
1134 for arguments which are passed in registers.
1136 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
1137 and may be modified by this routine.
1139 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
1140 flags which may be modified by this routine.
1142 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
1143 that requires allocation of stack space.
1145 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
1146 the thunked-to function. */
1149 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
1150 struct arg_data *args,
1151 struct args_size *args_size,
1152 int n_named_args ATTRIBUTE_UNUSED,
1153 tree exp, tree struct_value_addr_value,
1154 tree fndecl, tree fntype,
1155 cumulative_args_t args_so_far,
1156 int reg_parm_stack_space,
1157 rtx *old_stack_level, int *old_pending_adj,
1158 int *must_preallocate, int *ecf_flags,
1159 bool *may_tailcall, bool call_from_thunk_p)
1161 CUMULATIVE_ARGS *args_so_far_pnt = get_cumulative_args (args_so_far);
1162 location_t loc = EXPR_LOCATION (exp);
1164 /* Count arg position in order args appear. */
1169 args_size->constant = 0;
1172 bitmap_obstack_initialize (NULL);
1174 /* In this loop, we consider args in the order they are written.
1175 We fill up ARGS from the back. */
1177 i = num_actuals - 1;
1179 int j = i, ptr_arg = -1;
1180 call_expr_arg_iterator iter;
1182 bitmap slots = NULL;
1184 if (struct_value_addr_value)
1186 args[j].tree_value = struct_value_addr_value;
1189 /* If we pass structure address then we need to
1190 create bounds for it. Since created bounds is
1191 a call statement, we expand it right here to avoid
1192 fixing all other places where it may be expanded. */
1193 if (CALL_WITH_BOUNDS_P (exp))
1195 args[j].value = gen_reg_rtx (targetm.chkp_bound_mode ());
1197 = chkp_make_bounds_for_struct_addr (struct_value_addr_value);
1198 expand_expr_real (args[j].tree_value, args[j].value, VOIDmode,
1199 EXPAND_NORMAL, 0, false);
1200 args[j].pointer_arg = j + 1;
1205 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
1207 tree argtype = TREE_TYPE (arg);
1209 /* Remember last param with pointer and associate it
1210 with following pointer bounds. */
1211 if (CALL_WITH_BOUNDS_P (exp)
1212 && chkp_type_has_pointer (argtype))
1215 BITMAP_FREE (slots);
1217 if (!BOUNDED_TYPE_P (argtype))
1219 slots = BITMAP_ALLOC (NULL);
1220 chkp_find_bound_slots (argtype, slots);
1223 else if (CALL_WITH_BOUNDS_P (exp)
1224 && pass_by_reference (NULL, TYPE_MODE (argtype), argtype,
1225 argpos < n_named_args))
1228 BITMAP_FREE (slots);
1231 else if (POINTER_BOUNDS_TYPE_P (argtype))
1233 /* We expect bounds in instrumented calls only.
1234 Otherwise it is a sign we lost flag due to some optimization
1235 and may emit call args incorrectly. */
1236 gcc_assert (CALL_WITH_BOUNDS_P (exp));
1238 /* For structures look for the next available pointer. */
1239 if (ptr_arg != -1 && slots)
1241 unsigned bnd_no = bitmap_first_set_bit (slots);
1242 args[j].pointer_offset =
1243 bnd_no * POINTER_SIZE / BITS_PER_UNIT;
1245 bitmap_clear_bit (slots, bnd_no);
1247 /* Check we have no more pointers in the structure. */
1248 if (bitmap_empty_p (slots))
1249 BITMAP_FREE (slots);
1251 args[j].pointer_arg = ptr_arg;
1253 /* Check we covered all pointers in the previous
1261 if (targetm.calls.split_complex_arg
1263 && TREE_CODE (argtype) == COMPLEX_TYPE
1264 && targetm.calls.split_complex_arg (argtype))
1266 tree subtype = TREE_TYPE (argtype);
1267 args[j].tree_value = build1 (REALPART_EXPR, subtype, arg);
1269 args[j].tree_value = build1 (IMAGPART_EXPR, subtype, arg);
1272 args[j].tree_value = arg;
1278 BITMAP_FREE (slots);
1281 bitmap_obstack_release (NULL);
1283 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1284 for (argpos = 0; argpos < num_actuals; i--, argpos++)
1286 tree type = TREE_TYPE (args[i].tree_value);
1290 /* Replace erroneous argument with constant zero. */
1291 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
1292 args[i].tree_value = integer_zero_node, type = integer_type_node;
1294 /* If TYPE is a transparent union or record, pass things the way
1295 we would pass the first field of the union or record. We have
1296 already verified that the modes are the same. */
1297 if ((TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == RECORD_TYPE)
1298 && TYPE_TRANSPARENT_AGGR (type))
1299 type = TREE_TYPE (first_field (type));
1301 /* Decide where to pass this arg.
1303 args[i].reg is nonzero if all or part is passed in registers.
1305 args[i].partial is nonzero if part but not all is passed in registers,
1306 and the exact value says how many bytes are passed in registers.
1308 args[i].pass_on_stack is nonzero if the argument must at least be
1309 computed on the stack. It may then be loaded back into registers
1310 if args[i].reg is nonzero.
1312 These decisions are driven by the FUNCTION_... macros and must agree
1313 with those made by function.c. */
1315 /* See if this argument should be passed by invisible reference. */
1316 if (pass_by_reference (args_so_far_pnt, TYPE_MODE (type),
1317 type, argpos < n_named_args))
1320 tree base = NULL_TREE;
1323 = reference_callee_copied (args_so_far_pnt, TYPE_MODE (type),
1324 type, argpos < n_named_args);
1326 /* If we're compiling a thunk, pass through invisible references
1327 instead of making a copy. */
1328 if (call_from_thunk_p
1330 && !TREE_ADDRESSABLE (type)
1331 && (base = get_base_address (args[i].tree_value))
1332 && TREE_CODE (base) != SSA_NAME
1333 && (!DECL_P (base) || MEM_P (DECL_RTL (base)))))
1335 /* We may have turned the parameter value into an SSA name.
1336 Go back to the original parameter so we can take the
1338 if (TREE_CODE (args[i].tree_value) == SSA_NAME)
1340 gcc_assert (SSA_NAME_IS_DEFAULT_DEF (args[i].tree_value));
1341 args[i].tree_value = SSA_NAME_VAR (args[i].tree_value);
1342 gcc_assert (TREE_CODE (args[i].tree_value) == PARM_DECL);
1344 /* Argument setup code may have copied the value to register. We
1345 revert that optimization now because the tail call code must
1346 use the original location. */
1347 if (TREE_CODE (args[i].tree_value) == PARM_DECL
1348 && !MEM_P (DECL_RTL (args[i].tree_value))
1349 && DECL_INCOMING_RTL (args[i].tree_value)
1350 && MEM_P (DECL_INCOMING_RTL (args[i].tree_value)))
1351 set_decl_rtl (args[i].tree_value,
1352 DECL_INCOMING_RTL (args[i].tree_value));
1354 mark_addressable (args[i].tree_value);
1356 /* We can't use sibcalls if a callee-copied argument is
1357 stored in the current function's frame. */
1358 if (!call_from_thunk_p && DECL_P (base) && !TREE_STATIC (base))
1359 *may_tailcall = false;
1361 args[i].tree_value = build_fold_addr_expr_loc (loc,
1362 args[i].tree_value);
1363 type = TREE_TYPE (args[i].tree_value);
1365 if (*ecf_flags & ECF_CONST)
1366 *ecf_flags &= ~(ECF_CONST | ECF_LOOPING_CONST_OR_PURE);
1370 /* We make a copy of the object and pass the address to the
1371 function being called. */
1374 if (!COMPLETE_TYPE_P (type)
1375 || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
1376 || (flag_stack_check == GENERIC_STACK_CHECK
1377 && compare_tree_int (TYPE_SIZE_UNIT (type),
1378 STACK_CHECK_MAX_VAR_SIZE) > 0))
1380 /* This is a variable-sized object. Make space on the stack
1382 rtx size_rtx = expr_size (args[i].tree_value);
1384 if (*old_stack_level == 0)
1386 emit_stack_save (SAVE_BLOCK, old_stack_level);
1387 *old_pending_adj = pending_stack_adjust;
1388 pending_stack_adjust = 0;
1391 /* We can pass TRUE as the 4th argument because we just
1392 saved the stack pointer and will restore it right after
1394 copy = allocate_dynamic_stack_space (size_rtx,
1398 copy = gen_rtx_MEM (BLKmode, copy);
1399 set_mem_attributes (copy, type, 1);
1402 copy = assign_temp (type, 1, 0);
1404 store_expr (args[i].tree_value, copy, 0, false, false);
1406 /* Just change the const function to pure and then let
1407 the next test clear the pure based on
1409 if (*ecf_flags & ECF_CONST)
1411 *ecf_flags &= ~ECF_CONST;
1412 *ecf_flags |= ECF_PURE;
1415 if (!callee_copies && *ecf_flags & ECF_PURE)
1416 *ecf_flags &= ~(ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
1419 = build_fold_addr_expr_loc (loc, make_tree (type, copy));
1420 type = TREE_TYPE (args[i].tree_value);
1421 *may_tailcall = false;
1425 unsignedp = TYPE_UNSIGNED (type);
1426 mode = promote_function_mode (type, TYPE_MODE (type), &unsignedp,
1427 fndecl ? TREE_TYPE (fndecl) : fntype, 0);
1429 args[i].unsignedp = unsignedp;
1430 args[i].mode = mode;
1432 args[i].reg = targetm.calls.function_arg (args_so_far, mode, type,
1433 argpos < n_named_args);
1435 if (args[i].reg && CONST_INT_P (args[i].reg))
1437 args[i].special_slot = args[i].reg;
1441 /* If this is a sibling call and the machine has register windows, the
1442 register window has to be unwinded before calling the routine, so
1443 arguments have to go into the incoming registers. */
1444 if (targetm.calls.function_incoming_arg != targetm.calls.function_arg)
1445 args[i].tail_call_reg
1446 = targetm.calls.function_incoming_arg (args_so_far, mode, type,
1447 argpos < n_named_args);
1449 args[i].tail_call_reg = args[i].reg;
1453 = targetm.calls.arg_partial_bytes (args_so_far, mode, type,
1454 argpos < n_named_args);
1456 args[i].pass_on_stack = targetm.calls.must_pass_in_stack (mode, type);
1458 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1459 it means that we are to pass this arg in the register(s) designated
1460 by the PARALLEL, but also to pass it in the stack. */
1461 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1462 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1463 args[i].pass_on_stack = 1;
1465 /* If this is an addressable type, we must preallocate the stack
1466 since we must evaluate the object into its final location.
1468 If this is to be passed in both registers and the stack, it is simpler
1470 if (TREE_ADDRESSABLE (type)
1471 || (args[i].pass_on_stack && args[i].reg != 0))
1472 *must_preallocate = 1;
1474 /* No stack allocation and padding for bounds. */
1475 if (POINTER_BOUNDS_P (args[i].tree_value))
1477 /* Compute the stack-size of this argument. */
1478 else if (args[i].reg == 0 || args[i].partial != 0
1479 || reg_parm_stack_space > 0
1480 || args[i].pass_on_stack)
1481 locate_and_pad_parm (mode, type,
1482 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1487 reg_parm_stack_space,
1488 args[i].pass_on_stack ? 0 : args[i].partial,
1489 fndecl, args_size, &args[i].locate);
1490 #ifdef BLOCK_REG_PADDING
1492 /* The argument is passed entirely in registers. See at which
1493 end it should be padded. */
1494 args[i].locate.where_pad =
1495 BLOCK_REG_PADDING (mode, type,
1496 int_size_in_bytes (type) <= UNITS_PER_WORD);
1499 /* Update ARGS_SIZE, the total stack space for args so far. */
1501 args_size->constant += args[i].locate.size.constant;
1502 if (args[i].locate.size.var)
1503 ADD_PARM_SIZE (*args_size, args[i].locate.size.var);
1505 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1506 have been used, etc. */
1508 targetm.calls.function_arg_advance (args_so_far, TYPE_MODE (type),
1509 type, argpos < n_named_args);
1513 /* Update ARGS_SIZE to contain the total size for the argument block.
1514 Return the original constant component of the argument block's size.
1516 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1517 for arguments passed in registers. */
1520 compute_argument_block_size (int reg_parm_stack_space,
1521 struct args_size *args_size,
1522 tree fndecl ATTRIBUTE_UNUSED,
1523 tree fntype ATTRIBUTE_UNUSED,
1524 int preferred_stack_boundary ATTRIBUTE_UNUSED)
1526 int unadjusted_args_size = args_size->constant;
1528 /* For accumulate outgoing args mode we don't need to align, since the frame
1529 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1530 backends from generating misaligned frame sizes. */
1531 if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY)
1532 preferred_stack_boundary = STACK_BOUNDARY;
1534 /* Compute the actual size of the argument block required. The variable
1535 and constant sizes must be combined, the size may have to be rounded,
1536 and there may be a minimum required size. */
1540 args_size->var = ARGS_SIZE_TREE (*args_size);
1541 args_size->constant = 0;
1543 preferred_stack_boundary /= BITS_PER_UNIT;
1544 if (preferred_stack_boundary > 1)
1546 /* We don't handle this case yet. To handle it correctly we have
1547 to add the delta, round and subtract the delta.
1548 Currently no machine description requires this support. */
1549 gcc_assert (!(stack_pointer_delta & (preferred_stack_boundary - 1)));
1550 args_size->var = round_up (args_size->var, preferred_stack_boundary);
1553 if (reg_parm_stack_space > 0)
1556 = size_binop (MAX_EXPR, args_size->var,
1557 ssize_int (reg_parm_stack_space));
1559 /* The area corresponding to register parameters is not to count in
1560 the size of the block we need. So make the adjustment. */
1561 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
1563 = size_binop (MINUS_EXPR, args_size->var,
1564 ssize_int (reg_parm_stack_space));
1569 preferred_stack_boundary /= BITS_PER_UNIT;
1570 if (preferred_stack_boundary < 1)
1571 preferred_stack_boundary = 1;
1572 args_size->constant = (((args_size->constant
1573 + stack_pointer_delta
1574 + preferred_stack_boundary - 1)
1575 / preferred_stack_boundary
1576 * preferred_stack_boundary)
1577 - stack_pointer_delta);
1579 args_size->constant = MAX (args_size->constant,
1580 reg_parm_stack_space);
1582 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
1583 args_size->constant -= reg_parm_stack_space;
1585 return unadjusted_args_size;
1588 /* Precompute parameters as needed for a function call.
1590 FLAGS is mask of ECF_* constants.
1592 NUM_ACTUALS is the number of arguments.
1594 ARGS is an array containing information for each argument; this
1595 routine fills in the INITIAL_VALUE and VALUE fields for each
1596 precomputed argument. */
1599 precompute_arguments (int num_actuals, struct arg_data *args)
1603 /* If this is a libcall, then precompute all arguments so that we do not
1604 get extraneous instructions emitted as part of the libcall sequence. */
1606 /* If we preallocated the stack space, and some arguments must be passed
1607 on the stack, then we must precompute any parameter which contains a
1608 function call which will store arguments on the stack.
1609 Otherwise, evaluating the parameter may clobber previous parameters
1610 which have already been stored into the stack. (we have code to avoid
1611 such case by saving the outgoing stack arguments, but it results in
1613 if (!ACCUMULATE_OUTGOING_ARGS)
1616 for (i = 0; i < num_actuals; i++)
1621 if (TREE_CODE (args[i].tree_value) != CALL_EXPR)
1624 /* If this is an addressable type, we cannot pre-evaluate it. */
1625 type = TREE_TYPE (args[i].tree_value);
1626 gcc_assert (!TREE_ADDRESSABLE (type));
1628 args[i].initial_value = args[i].value
1629 = expand_normal (args[i].tree_value);
1631 mode = TYPE_MODE (type);
1632 if (mode != args[i].mode)
1634 int unsignedp = args[i].unsignedp;
1636 = convert_modes (args[i].mode, mode,
1637 args[i].value, args[i].unsignedp);
1639 /* CSE will replace this only if it contains args[i].value
1640 pseudo, so convert it down to the declared mode using
1642 if (REG_P (args[i].value)
1643 && GET_MODE_CLASS (args[i].mode) == MODE_INT
1644 && promote_mode (type, mode, &unsignedp) != args[i].mode)
1646 args[i].initial_value
1647 = gen_lowpart_SUBREG (mode, args[i].value);
1648 SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1649 SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp);
1655 /* Given the current state of MUST_PREALLOCATE and information about
1656 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1657 compute and return the final value for MUST_PREALLOCATE. */
1660 finalize_must_preallocate (int must_preallocate, int num_actuals,
1661 struct arg_data *args, struct args_size *args_size)
1663 /* See if we have or want to preallocate stack space.
1665 If we would have to push a partially-in-regs parm
1666 before other stack parms, preallocate stack space instead.
1668 If the size of some parm is not a multiple of the required stack
1669 alignment, we must preallocate.
1671 If the total size of arguments that would otherwise create a copy in
1672 a temporary (such as a CALL) is more than half the total argument list
1673 size, preallocation is faster.
1675 Another reason to preallocate is if we have a machine (like the m88k)
1676 where stack alignment is required to be maintained between every
1677 pair of insns, not just when the call is made. However, we assume here
1678 that such machines either do not have push insns (and hence preallocation
1679 would occur anyway) or the problem is taken care of with
1682 if (! must_preallocate)
1684 int partial_seen = 0;
1685 int copy_to_evaluate_size = 0;
1688 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1690 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1692 else if (partial_seen && args[i].reg == 0)
1693 must_preallocate = 1;
1694 /* We preallocate in case there are bounds passed
1695 in the bounds table to have precomputed address
1696 for bounds association. */
1697 else if (POINTER_BOUNDS_P (args[i].tree_value)
1699 must_preallocate = 1;
1701 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1702 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1703 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1704 || TREE_CODE (args[i].tree_value) == COND_EXPR
1705 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1706 copy_to_evaluate_size
1707 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1710 if (copy_to_evaluate_size * 2 >= args_size->constant
1711 && args_size->constant > 0)
1712 must_preallocate = 1;
1714 return must_preallocate;
1717 /* If we preallocated stack space, compute the address of each argument
1718 and store it into the ARGS array.
1720 We need not ensure it is a valid memory address here; it will be
1721 validized when it is used.
1723 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1726 compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals)
1730 rtx arg_reg = argblock;
1731 int i, arg_offset = 0;
1733 if (GET_CODE (argblock) == PLUS)
1734 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1736 for (i = 0; i < num_actuals; i++)
1738 rtx offset = ARGS_SIZE_RTX (args[i].locate.offset);
1739 rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
1741 unsigned int align, boundary;
1742 unsigned int units_on_stack = 0;
1743 machine_mode partial_mode = VOIDmode;
1745 /* Skip this parm if it will not be passed on the stack. */
1746 if (! args[i].pass_on_stack
1748 && args[i].partial == 0)
1751 /* Pointer Bounds are never passed on the stack. */
1752 if (POINTER_BOUNDS_P (args[i].tree_value))
1755 if (CONST_INT_P (offset))
1756 addr = plus_constant (Pmode, arg_reg, INTVAL (offset));
1758 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1760 addr = plus_constant (Pmode, addr, arg_offset);
1762 if (args[i].partial != 0)
1764 /* Only part of the parameter is being passed on the stack.
1765 Generate a simple memory reference of the correct size. */
1766 units_on_stack = args[i].locate.size.constant;
1767 partial_mode = mode_for_size (units_on_stack * BITS_PER_UNIT,
1769 args[i].stack = gen_rtx_MEM (partial_mode, addr);
1770 set_mem_size (args[i].stack, units_on_stack);
1774 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1775 set_mem_attributes (args[i].stack,
1776 TREE_TYPE (args[i].tree_value), 1);
1778 align = BITS_PER_UNIT;
1779 boundary = args[i].locate.boundary;
1780 if (args[i].locate.where_pad != downward)
1782 else if (CONST_INT_P (offset))
1784 align = INTVAL (offset) * BITS_PER_UNIT | boundary;
1785 align = align & -align;
1787 set_mem_align (args[i].stack, align);
1789 if (CONST_INT_P (slot_offset))
1790 addr = plus_constant (Pmode, arg_reg, INTVAL (slot_offset));
1792 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1794 addr = plus_constant (Pmode, addr, arg_offset);
1796 if (args[i].partial != 0)
1798 /* Only part of the parameter is being passed on the stack.
1799 Generate a simple memory reference of the correct size.
1801 args[i].stack_slot = gen_rtx_MEM (partial_mode, addr);
1802 set_mem_size (args[i].stack_slot, units_on_stack);
1806 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1807 set_mem_attributes (args[i].stack_slot,
1808 TREE_TYPE (args[i].tree_value), 1);
1810 set_mem_align (args[i].stack_slot, args[i].locate.boundary);
1812 /* Function incoming arguments may overlap with sibling call
1813 outgoing arguments and we cannot allow reordering of reads
1814 from function arguments with stores to outgoing arguments
1815 of sibling calls. */
1816 set_mem_alias_set (args[i].stack, 0);
1817 set_mem_alias_set (args[i].stack_slot, 0);
1822 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1823 in a call instruction.
1825 FNDECL is the tree node for the target function. For an indirect call
1826 FNDECL will be NULL_TREE.
1828 ADDR is the operand 0 of CALL_EXPR for this call. */
1831 rtx_for_function_call (tree fndecl, tree addr)
1835 /* Get the function to call, in the form of RTL. */
1838 if (!TREE_USED (fndecl) && fndecl != current_function_decl)
1839 TREE_USED (fndecl) = 1;
1841 /* Get a SYMBOL_REF rtx for the function address. */
1842 funexp = XEXP (DECL_RTL (fndecl), 0);
1845 /* Generate an rtx (probably a pseudo-register) for the address. */
1848 funexp = expand_normal (addr);
1849 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1854 /* Internal state for internal_arg_pointer_based_exp and its helpers. */
1857 /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan,
1858 or NULL_RTX if none has been scanned yet. */
1859 rtx_insn *scan_start;
1860 /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is
1861 based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the
1862 pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it
1863 with fixed offset, or PC if this is with variable or unknown offset. */
1865 } internal_arg_pointer_exp_state;
1867 static rtx internal_arg_pointer_based_exp (const_rtx, bool);
1869 /* Helper function for internal_arg_pointer_based_exp. Scan insns in
1870 the tail call sequence, starting with first insn that hasn't been
1871 scanned yet, and note for each pseudo on the LHS whether it is based
1872 on crtl->args.internal_arg_pointer or not, and what offset from that
1873 that pointer it has. */
1876 internal_arg_pointer_based_exp_scan (void)
1878 rtx_insn *insn, *scan_start = internal_arg_pointer_exp_state.scan_start;
1880 if (scan_start == NULL_RTX)
1881 insn = get_insns ();
1883 insn = NEXT_INSN (scan_start);
1887 rtx set = single_set (insn);
1888 if (set && REG_P (SET_DEST (set)) && !HARD_REGISTER_P (SET_DEST (set)))
1891 unsigned int idx = REGNO (SET_DEST (set)) - FIRST_PSEUDO_REGISTER;
1892 /* Punt on pseudos set multiple times. */
1893 if (idx < internal_arg_pointer_exp_state.cache.length ()
1894 && (internal_arg_pointer_exp_state.cache[idx]
1898 val = internal_arg_pointer_based_exp (SET_SRC (set), false);
1899 if (val != NULL_RTX)
1901 if (idx >= internal_arg_pointer_exp_state.cache.length ())
1902 internal_arg_pointer_exp_state.cache
1903 .safe_grow_cleared (idx + 1);
1904 internal_arg_pointer_exp_state.cache[idx] = val;
1907 if (NEXT_INSN (insn) == NULL_RTX)
1909 insn = NEXT_INSN (insn);
1912 internal_arg_pointer_exp_state.scan_start = scan_start;
1915 /* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return
1916 NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on
1917 it with fixed offset, or PC if this is with variable or unknown offset.
1918 TOPLEVEL is true if the function is invoked at the topmost level. */
1921 internal_arg_pointer_based_exp (const_rtx rtl, bool toplevel)
1923 if (CONSTANT_P (rtl))
1926 if (rtl == crtl->args.internal_arg_pointer)
1929 if (REG_P (rtl) && HARD_REGISTER_P (rtl))
1932 if (GET_CODE (rtl) == PLUS && CONST_INT_P (XEXP (rtl, 1)))
1934 rtx val = internal_arg_pointer_based_exp (XEXP (rtl, 0), toplevel);
1935 if (val == NULL_RTX || val == pc_rtx)
1937 return plus_constant (Pmode, val, INTVAL (XEXP (rtl, 1)));
1940 /* When called at the topmost level, scan pseudo assignments in between the
1941 last scanned instruction in the tail call sequence and the latest insn
1942 in that sequence. */
1944 internal_arg_pointer_based_exp_scan ();
1948 unsigned int idx = REGNO (rtl) - FIRST_PSEUDO_REGISTER;
1949 if (idx < internal_arg_pointer_exp_state.cache.length ())
1950 return internal_arg_pointer_exp_state.cache[idx];
1955 subrtx_iterator::array_type array;
1956 FOR_EACH_SUBRTX (iter, array, rtl, NONCONST)
1958 const_rtx x = *iter;
1959 if (REG_P (x) && internal_arg_pointer_based_exp (x, false) != NULL_RTX)
1962 iter.skip_subrtxes ();
1968 /* Return true if and only if SIZE storage units (usually bytes)
1969 starting from address ADDR overlap with already clobbered argument
1970 area. This function is used to determine if we should give up a
1974 mem_overlaps_already_clobbered_arg_p (rtx addr, unsigned HOST_WIDE_INT size)
1979 if (bitmap_empty_p (stored_args_map))
1981 val = internal_arg_pointer_based_exp (addr, true);
1982 if (val == NULL_RTX)
1984 else if (val == pc_rtx)
1989 if (STACK_GROWS_DOWNWARD)
1990 i -= crtl->args.pretend_args_size;
1992 i += crtl->args.pretend_args_size;
1995 if (ARGS_GROW_DOWNWARD)
2000 unsigned HOST_WIDE_INT k;
2002 for (k = 0; k < size; k++)
2003 if (i + k < SBITMAP_SIZE (stored_args_map)
2004 && bitmap_bit_p (stored_args_map, i + k))
2011 /* Do the register loads required for any wholly-register parms or any
2012 parms which are passed both on the stack and in a register. Their
2013 expressions were already evaluated.
2015 Mark all register-parms as living through the call, putting these USE
2016 insns in the CALL_INSN_FUNCTION_USAGE field.
2018 When IS_SIBCALL, perform the check_sibcall_argument_overlap
2019 checking, setting *SIBCALL_FAILURE if appropriate. */
2022 load_register_parameters (struct arg_data *args, int num_actuals,
2023 rtx *call_fusage, int flags, int is_sibcall,
2024 int *sibcall_failure)
2028 for (i = 0; i < num_actuals; i++)
2030 rtx reg = ((flags & ECF_SIBCALL)
2031 ? args[i].tail_call_reg : args[i].reg);
2034 int partial = args[i].partial;
2037 rtx_insn *before_arg = get_last_insn ();
2038 /* Set non-negative if we must move a word at a time, even if
2039 just one word (e.g, partial == 4 && mode == DFmode). Set
2040 to -1 if we just use a normal move insn. This value can be
2041 zero if the argument is a zero size structure. */
2043 if (GET_CODE (reg) == PARALLEL)
2047 gcc_assert (partial % UNITS_PER_WORD == 0);
2048 nregs = partial / UNITS_PER_WORD;
2050 else if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode)
2052 size = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
2053 nregs = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
2056 size = GET_MODE_SIZE (args[i].mode);
2058 /* Handle calls that pass values in multiple non-contiguous
2059 locations. The Irix 6 ABI has examples of this. */
2061 if (GET_CODE (reg) == PARALLEL)
2062 emit_group_move (reg, args[i].parallel_value);
2064 /* If simple case, just do move. If normal partial, store_one_arg
2065 has already loaded the register for us. In all other cases,
2066 load the register(s) from memory. */
2068 else if (nregs == -1)
2070 emit_move_insn (reg, args[i].value);
2071 #ifdef BLOCK_REG_PADDING
2072 /* Handle case where we have a value that needs shifting
2073 up to the msb. eg. a QImode value and we're padding
2074 upward on a BYTES_BIG_ENDIAN machine. */
2075 if (size < UNITS_PER_WORD
2076 && (args[i].locate.where_pad
2077 == (BYTES_BIG_ENDIAN ? upward : downward)))
2080 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
2082 /* Assigning REG here rather than a temp makes CALL_FUSAGE
2083 report the whole reg as used. Strictly speaking, the
2084 call only uses SIZE bytes at the msb end, but it doesn't
2085 seem worth generating rtl to say that. */
2086 reg = gen_rtx_REG (word_mode, REGNO (reg));
2087 x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1);
2089 emit_move_insn (reg, x);
2094 /* If we have pre-computed the values to put in the registers in
2095 the case of non-aligned structures, copy them in now. */
2097 else if (args[i].n_aligned_regs != 0)
2098 for (j = 0; j < args[i].n_aligned_regs; j++)
2099 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
2100 args[i].aligned_regs[j]);
2102 else if (partial == 0 || args[i].pass_on_stack)
2104 rtx mem = validize_mem (copy_rtx (args[i].value));
2106 /* Check for overlap with already clobbered argument area,
2107 providing that this has non-zero size. */
2110 && (mem_overlaps_already_clobbered_arg_p
2111 (XEXP (args[i].value, 0), size)))
2112 *sibcall_failure = 1;
2114 if (size % UNITS_PER_WORD == 0
2115 || MEM_ALIGN (mem) % BITS_PER_WORD == 0)
2116 move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode);
2120 move_block_to_reg (REGNO (reg), mem, nregs - 1,
2122 rtx dest = gen_rtx_REG (word_mode, REGNO (reg) + nregs - 1);
2123 unsigned int bitoff = (nregs - 1) * BITS_PER_WORD;
2124 unsigned int bitsize = size * BITS_PER_UNIT - bitoff;
2125 rtx x = extract_bit_field (mem, bitsize, bitoff, 1, dest,
2126 word_mode, word_mode, false);
2127 if (BYTES_BIG_ENDIAN)
2128 x = expand_shift (LSHIFT_EXPR, word_mode, x,
2129 BITS_PER_WORD - bitsize, dest, 1);
2131 emit_move_insn (dest, x);
2134 /* Handle a BLKmode that needs shifting. */
2135 if (nregs == 1 && size < UNITS_PER_WORD
2136 #ifdef BLOCK_REG_PADDING
2137 && args[i].locate.where_pad == downward
2143 rtx dest = gen_rtx_REG (word_mode, REGNO (reg));
2144 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
2145 enum tree_code dir = (BYTES_BIG_ENDIAN
2146 ? RSHIFT_EXPR : LSHIFT_EXPR);
2149 x = expand_shift (dir, word_mode, dest, shift, dest, 1);
2151 emit_move_insn (dest, x);
2155 /* When a parameter is a block, and perhaps in other cases, it is
2156 possible that it did a load from an argument slot that was
2157 already clobbered. */
2159 && check_sibcall_argument_overlap (before_arg, &args[i], 0))
2160 *sibcall_failure = 1;
2162 /* Handle calls that pass values in multiple non-contiguous
2163 locations. The Irix 6 ABI has examples of this. */
2164 if (GET_CODE (reg) == PARALLEL)
2165 use_group_regs (call_fusage, reg);
2166 else if (nregs == -1)
2167 use_reg_mode (call_fusage, reg,
2168 TYPE_MODE (TREE_TYPE (args[i].tree_value)));
2170 use_regs (call_fusage, REGNO (reg), nregs);
2175 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
2176 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
2177 bytes, then we would need to push some additional bytes to pad the
2178 arguments. So, we compute an adjust to the stack pointer for an
2179 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
2180 bytes. Then, when the arguments are pushed the stack will be perfectly
2181 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
2182 be popped after the call. Returns the adjustment. */
2185 combine_pending_stack_adjustment_and_call (int unadjusted_args_size,
2186 struct args_size *args_size,
2187 unsigned int preferred_unit_stack_boundary)
2189 /* The number of bytes to pop so that the stack will be
2190 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
2191 HOST_WIDE_INT adjustment;
2192 /* The alignment of the stack after the arguments are pushed, if we
2193 just pushed the arguments without adjust the stack here. */
2194 unsigned HOST_WIDE_INT unadjusted_alignment;
2196 unadjusted_alignment
2197 = ((stack_pointer_delta + unadjusted_args_size)
2198 % preferred_unit_stack_boundary);
2200 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
2201 as possible -- leaving just enough left to cancel out the
2202 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
2203 PENDING_STACK_ADJUST is non-negative, and congruent to
2204 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
2206 /* Begin by trying to pop all the bytes. */
2207 unadjusted_alignment
2208 = (unadjusted_alignment
2209 - (pending_stack_adjust % preferred_unit_stack_boundary));
2210 adjustment = pending_stack_adjust;
2211 /* Push enough additional bytes that the stack will be aligned
2212 after the arguments are pushed. */
2213 if (preferred_unit_stack_boundary > 1)
2215 if (unadjusted_alignment > 0)
2216 adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
2218 adjustment += unadjusted_alignment;
2221 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
2222 bytes after the call. The right number is the entire
2223 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
2224 by the arguments in the first place. */
2226 = pending_stack_adjust - adjustment + unadjusted_args_size;
2231 /* Scan X expression if it does not dereference any argument slots
2232 we already clobbered by tail call arguments (as noted in stored_args_map
2234 Return nonzero if X expression dereferences such argument slots,
2238 check_sibcall_argument_overlap_1 (rtx x)
2247 code = GET_CODE (x);
2249 /* We need not check the operands of the CALL expression itself. */
2254 return mem_overlaps_already_clobbered_arg_p (XEXP (x, 0),
2255 GET_MODE_SIZE (GET_MODE (x)));
2257 /* Scan all subexpressions. */
2258 fmt = GET_RTX_FORMAT (code);
2259 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2263 if (check_sibcall_argument_overlap_1 (XEXP (x, i)))
2266 else if (*fmt == 'E')
2268 for (j = 0; j < XVECLEN (x, i); j++)
2269 if (check_sibcall_argument_overlap_1 (XVECEXP (x, i, j)))
2276 /* Scan sequence after INSN if it does not dereference any argument slots
2277 we already clobbered by tail call arguments (as noted in stored_args_map
2278 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
2279 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
2280 should be 0). Return nonzero if sequence after INSN dereferences such argument
2281 slots, zero otherwise. */
2284 check_sibcall_argument_overlap (rtx_insn *insn, struct arg_data *arg,
2285 int mark_stored_args_map)
2289 if (insn == NULL_RTX)
2290 insn = get_insns ();
2292 insn = NEXT_INSN (insn);
2294 for (; insn; insn = NEXT_INSN (insn))
2296 && check_sibcall_argument_overlap_1 (PATTERN (insn)))
2299 if (mark_stored_args_map)
2301 if (ARGS_GROW_DOWNWARD)
2302 low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
2304 low = arg->locate.slot_offset.constant;
2306 for (high = low + arg->locate.size.constant; low < high; low++)
2307 bitmap_set_bit (stored_args_map, low);
2309 return insn != NULL_RTX;
2312 /* Given that a function returns a value of mode MODE at the most
2313 significant end of hard register VALUE, shift VALUE left or right
2314 as specified by LEFT_P. Return true if some action was needed. */
2317 shift_return_value (machine_mode mode, bool left_p, rtx value)
2319 HOST_WIDE_INT shift;
2321 gcc_assert (REG_P (value) && HARD_REGISTER_P (value));
2322 shift = GET_MODE_BITSIZE (GET_MODE (value)) - GET_MODE_BITSIZE (mode);
2326 /* Use ashr rather than lshr for right shifts. This is for the benefit
2327 of the MIPS port, which requires SImode values to be sign-extended
2328 when stored in 64-bit registers. */
2329 if (!force_expand_binop (GET_MODE (value), left_p ? ashl_optab : ashr_optab,
2330 value, GEN_INT (shift), value, 1, OPTAB_WIDEN))
2335 /* If X is a likely-spilled register value, copy it to a pseudo
2336 register and return that register. Return X otherwise. */
2339 avoid_likely_spilled_reg (rtx x)
2344 && HARD_REGISTER_P (x)
2345 && targetm.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x))))
2347 /* Make sure that we generate a REG rather than a CONCAT.
2348 Moves into CONCATs can need nontrivial instructions,
2349 and the whole point of this function is to avoid
2350 using the hard register directly in such a situation. */
2351 generating_concat_p = 0;
2352 new_rtx = gen_reg_rtx (GET_MODE (x));
2353 generating_concat_p = 1;
2354 emit_move_insn (new_rtx, x);
2360 /* Generate all the code for a CALL_EXPR exp
2361 and return an rtx for its value.
2362 Store the value in TARGET (specified as an rtx) if convenient.
2363 If the value is stored in TARGET then TARGET is returned.
2364 If IGNORE is nonzero, then we ignore the value of the function call. */
2367 expand_call (tree exp, rtx target, int ignore)
2369 /* Nonzero if we are currently expanding a call. */
2370 static int currently_expanding_call = 0;
2372 /* RTX for the function to be called. */
2374 /* Sequence of insns to perform a normal "call". */
2375 rtx_insn *normal_call_insns = NULL;
2376 /* Sequence of insns to perform a tail "call". */
2377 rtx_insn *tail_call_insns = NULL;
2378 /* Data type of the function. */
2380 tree type_arg_types;
2382 /* Declaration of the function being called,
2383 or 0 if the function is computed (not known by name). */
2385 /* The type of the function being called. */
2387 bool try_tail_call = CALL_EXPR_TAILCALL (exp);
2390 /* Register in which non-BLKmode value will be returned,
2391 or 0 if no value or if value is BLKmode. */
2393 /* Register(s) in which bounds are returned. */
2395 /* Address where we should return a BLKmode value;
2396 0 if value not BLKmode. */
2397 rtx structure_value_addr = 0;
2398 /* Nonzero if that address is being passed by treating it as
2399 an extra, implicit first parameter. Otherwise,
2400 it is passed by being copied directly into struct_value_rtx. */
2401 int structure_value_addr_parm = 0;
2402 /* Holds the value of implicit argument for the struct value. */
2403 tree structure_value_addr_value = NULL_TREE;
2404 /* Size of aggregate value wanted, or zero if none wanted
2405 or if we are using the non-reentrant PCC calling convention
2406 or expecting the value in registers. */
2407 HOST_WIDE_INT struct_value_size = 0;
2408 /* Nonzero if called function returns an aggregate in memory PCC style,
2409 by returning the address of where to find it. */
2410 int pcc_struct_value = 0;
2411 rtx struct_value = 0;
2413 /* Number of actual parameters in this call, including struct value addr. */
2415 /* Number of named args. Args after this are anonymous ones
2416 and they must all go on the stack. */
2418 /* Number of complex actual arguments that need to be split. */
2419 int num_complex_actuals = 0;
2421 /* Vector of information about each argument.
2422 Arguments are numbered in the order they will be pushed,
2423 not the order they are written. */
2424 struct arg_data *args;
2426 /* Total size in bytes of all the stack-parms scanned so far. */
2427 struct args_size args_size;
2428 struct args_size adjusted_args_size;
2429 /* Size of arguments before any adjustments (such as rounding). */
2430 int unadjusted_args_size;
2431 /* Data on reg parms scanned so far. */
2432 CUMULATIVE_ARGS args_so_far_v;
2433 cumulative_args_t args_so_far;
2434 /* Nonzero if a reg parm has been scanned. */
2436 /* Nonzero if this is an indirect function call. */
2438 /* Nonzero if we must avoid push-insns in the args for this call.
2439 If stack space is allocated for register parameters, but not by the
2440 caller, then it is preallocated in the fixed part of the stack frame.
2441 So the entire argument block must then be preallocated (i.e., we
2442 ignore PUSH_ROUNDING in that case). */
2444 int must_preallocate = !PUSH_ARGS;
2446 /* Size of the stack reserved for parameter registers. */
2447 int reg_parm_stack_space = 0;
2449 /* Address of space preallocated for stack parms
2450 (on machines that lack push insns), or 0 if space not preallocated. */
2453 /* Mask of ECF_ and ERF_ flags. */
2455 int return_flags = 0;
2456 #ifdef REG_PARM_STACK_SPACE
2457 /* Define the boundary of the register parm stack space that needs to be
2459 int low_to_save, high_to_save;
2460 rtx save_area = 0; /* Place that it is saved */
2463 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2464 char *initial_stack_usage_map = stack_usage_map;
2465 char *stack_usage_map_buf = NULL;
2467 int old_stack_allocated;
2469 /* State variables to track stack modifications. */
2470 rtx old_stack_level = 0;
2471 int old_stack_arg_under_construction = 0;
2472 int old_pending_adj = 0;
2473 int old_inhibit_defer_pop = inhibit_defer_pop;
2475 /* Some stack pointer alterations we make are performed via
2476 allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
2477 which we then also need to save/restore along the way. */
2478 int old_stack_pointer_delta = 0;
2481 tree addr = CALL_EXPR_FN (exp);
2483 /* The alignment of the stack, in bits. */
2484 unsigned HOST_WIDE_INT preferred_stack_boundary;
2485 /* The alignment of the stack, in bytes. */
2486 unsigned HOST_WIDE_INT preferred_unit_stack_boundary;
2487 /* The static chain value to use for this call. */
2488 rtx static_chain_value;
2489 /* See if this is "nothrow" function call. */
2490 if (TREE_NOTHROW (exp))
2491 flags |= ECF_NOTHROW;
2493 /* See if we can find a DECL-node for the actual function, and get the
2494 function attributes (flags) from the function decl or type node. */
2495 fndecl = get_callee_fndecl (exp);
2498 fntype = TREE_TYPE (fndecl);
2499 flags |= flags_from_decl_or_type (fndecl);
2500 return_flags |= decl_return_flags (fndecl);
2504 fntype = TREE_TYPE (TREE_TYPE (addr));
2505 flags |= flags_from_decl_or_type (fntype);
2507 rettype = TREE_TYPE (exp);
2509 struct_value = targetm.calls.struct_value_rtx (fntype, 0);
2511 /* Warn if this value is an aggregate type,
2512 regardless of which calling convention we are using for it. */
2513 if (AGGREGATE_TYPE_P (rettype))
2514 warning (OPT_Waggregate_return, "function call has aggregate value");
2516 /* If the result of a non looping pure or const function call is
2517 ignored (or void), and none of its arguments are volatile, we can
2518 avoid expanding the call and just evaluate the arguments for
2520 if ((flags & (ECF_CONST | ECF_PURE))
2521 && (!(flags & ECF_LOOPING_CONST_OR_PURE))
2522 && (ignore || target == const0_rtx
2523 || TYPE_MODE (rettype) == VOIDmode))
2525 bool volatilep = false;
2527 call_expr_arg_iterator iter;
2529 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2530 if (TREE_THIS_VOLATILE (arg))
2538 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2539 expand_expr (arg, const0_rtx, VOIDmode, EXPAND_NORMAL);
2544 #ifdef REG_PARM_STACK_SPACE
2545 reg_parm_stack_space = REG_PARM_STACK_SPACE (!fndecl ? fntype : fndecl);
2548 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
2549 && reg_parm_stack_space > 0 && PUSH_ARGS)
2550 must_preallocate = 1;
2552 /* Set up a place to return a structure. */
2554 /* Cater to broken compilers. */
2555 if (aggregate_value_p (exp, fntype))
2557 /* This call returns a big structure. */
2558 flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
2560 #ifdef PCC_STATIC_STRUCT_RETURN
2562 pcc_struct_value = 1;
2564 #else /* not PCC_STATIC_STRUCT_RETURN */
2566 struct_value_size = int_size_in_bytes (rettype);
2568 /* Even if it is semantically safe to use the target as the return
2569 slot, it may be not sufficiently aligned for the return type. */
2570 if (CALL_EXPR_RETURN_SLOT_OPT (exp)
2573 && !(MEM_ALIGN (target) < TYPE_ALIGN (rettype)
2574 && SLOW_UNALIGNED_ACCESS (TYPE_MODE (rettype),
2575 MEM_ALIGN (target))))
2576 structure_value_addr = XEXP (target, 0);
2579 /* For variable-sized objects, we must be called with a target
2580 specified. If we were to allocate space on the stack here,
2581 we would have no way of knowing when to free it. */
2582 rtx d = assign_temp (rettype, 1, 1);
2583 structure_value_addr = XEXP (d, 0);
2587 #endif /* not PCC_STATIC_STRUCT_RETURN */
2590 /* Figure out the amount to which the stack should be aligned. */
2591 preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2594 struct cgraph_rtl_info *i = cgraph_node::rtl_info (fndecl);
2595 /* Without automatic stack alignment, we can't increase preferred
2596 stack boundary. With automatic stack alignment, it is
2597 unnecessary since unless we can guarantee that all callers will
2598 align the outgoing stack properly, callee has to align its
2601 && i->preferred_incoming_stack_boundary
2602 && i->preferred_incoming_stack_boundary < preferred_stack_boundary)
2603 preferred_stack_boundary = i->preferred_incoming_stack_boundary;
2606 /* Operand 0 is a pointer-to-function; get the type of the function. */
2607 funtype = TREE_TYPE (addr);
2608 gcc_assert (POINTER_TYPE_P (funtype));
2609 funtype = TREE_TYPE (funtype);
2611 /* Count whether there are actual complex arguments that need to be split
2612 into their real and imaginary parts. Munge the type_arg_types
2613 appropriately here as well. */
2614 if (targetm.calls.split_complex_arg)
2616 call_expr_arg_iterator iter;
2618 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2620 tree type = TREE_TYPE (arg);
2621 if (type && TREE_CODE (type) == COMPLEX_TYPE
2622 && targetm.calls.split_complex_arg (type))
2623 num_complex_actuals++;
2625 type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype));
2628 type_arg_types = TYPE_ARG_TYPES (funtype);
2630 if (flags & ECF_MAY_BE_ALLOCA)
2631 cfun->calls_alloca = 1;
2633 /* If struct_value_rtx is 0, it means pass the address
2634 as if it were an extra parameter. Put the argument expression
2635 in structure_value_addr_value. */
2636 if (structure_value_addr && struct_value == 0)
2638 /* If structure_value_addr is a REG other than
2639 virtual_outgoing_args_rtx, we can use always use it. If it
2640 is not a REG, we must always copy it into a register.
2641 If it is virtual_outgoing_args_rtx, we must copy it to another
2642 register in some cases. */
2643 rtx temp = (!REG_P (structure_value_addr)
2644 || (ACCUMULATE_OUTGOING_ARGS
2645 && stack_arg_under_construction
2646 && structure_value_addr == virtual_outgoing_args_rtx)
2647 ? copy_addr_to_reg (convert_memory_address
2648 (Pmode, structure_value_addr))
2649 : structure_value_addr);
2651 structure_value_addr_value =
2652 make_tree (build_pointer_type (TREE_TYPE (funtype)), temp);
2653 structure_value_addr_parm = CALL_WITH_BOUNDS_P (exp) ? 2 : 1;
2656 /* Count the arguments and set NUM_ACTUALS. */
2658 call_expr_nargs (exp) + num_complex_actuals + structure_value_addr_parm;
2660 /* Compute number of named args.
2661 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2663 if (type_arg_types != 0)
2665 = (list_length (type_arg_types)
2666 /* Count the struct value address, if it is passed as a parm. */
2667 + structure_value_addr_parm);
2669 /* If we know nothing, treat all args as named. */
2670 n_named_args = num_actuals;
2672 /* Start updating where the next arg would go.
2674 On some machines (such as the PA) indirect calls have a different
2675 calling convention than normal calls. The fourth argument in
2676 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2678 INIT_CUMULATIVE_ARGS (args_so_far_v, funtype, NULL_RTX, fndecl, n_named_args);
2679 args_so_far = pack_cumulative_args (&args_so_far_v);
2681 /* Now possibly adjust the number of named args.
2682 Normally, don't include the last named arg if anonymous args follow.
2683 We do include the last named arg if
2684 targetm.calls.strict_argument_naming() returns nonzero.
2685 (If no anonymous args follow, the result of list_length is actually
2686 one too large. This is harmless.)
2688 If targetm.calls.pretend_outgoing_varargs_named() returns
2689 nonzero, and targetm.calls.strict_argument_naming() returns zero,
2690 this machine will be able to place unnamed args that were passed
2691 in registers into the stack. So treat all args as named. This
2692 allows the insns emitting for a specific argument list to be
2693 independent of the function declaration.
2695 If targetm.calls.pretend_outgoing_varargs_named() returns zero,
2696 we do not have any reliable way to pass unnamed args in
2697 registers, so we must force them into memory. */
2699 if (type_arg_types != 0
2700 && targetm.calls.strict_argument_naming (args_so_far))
2702 else if (type_arg_types != 0
2703 && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far))
2704 /* Don't include the last named arg. */
2707 /* Treat all args as named. */
2708 n_named_args = num_actuals;
2710 /* Make a vector to hold all the information about each arg. */
2711 args = XALLOCAVEC (struct arg_data, num_actuals);
2712 memset (args, 0, num_actuals * sizeof (struct arg_data));
2714 /* Build up entries in the ARGS array, compute the size of the
2715 arguments into ARGS_SIZE, etc. */
2716 initialize_argument_information (num_actuals, args, &args_size,
2718 structure_value_addr_value, fndecl, fntype,
2719 args_so_far, reg_parm_stack_space,
2720 &old_stack_level, &old_pending_adj,
2721 &must_preallocate, &flags,
2722 &try_tail_call, CALL_FROM_THUNK_P (exp));
2725 must_preallocate = 1;
2727 /* Now make final decision about preallocating stack space. */
2728 must_preallocate = finalize_must_preallocate (must_preallocate,
2732 /* If the structure value address will reference the stack pointer, we
2733 must stabilize it. We don't need to do this if we know that we are
2734 not going to adjust the stack pointer in processing this call. */
2736 if (structure_value_addr
2737 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
2738 || reg_mentioned_p (virtual_outgoing_args_rtx,
2739 structure_value_addr))
2741 || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant)))
2742 structure_value_addr = copy_to_reg (structure_value_addr);
2744 /* Tail calls can make things harder to debug, and we've traditionally
2745 pushed these optimizations into -O2. Don't try if we're already
2746 expanding a call, as that means we're an argument. Don't try if
2747 there's cleanups, as we know there's code to follow the call. */
2749 if (currently_expanding_call++ != 0
2750 || !flag_optimize_sibling_calls
2752 || dbg_cnt (tail_call) == false)
2755 /* Rest of purposes for tail call optimizations to fail. */
2757 || !targetm.have_sibcall_epilogue ()
2758 /* Doing sibling call optimization needs some work, since
2759 structure_value_addr can be allocated on the stack.
2760 It does not seem worth the effort since few optimizable
2761 sibling calls will return a structure. */
2762 || structure_value_addr != NULL_RTX
2763 #ifdef REG_PARM_STACK_SPACE
2764 /* If outgoing reg parm stack space changes, we can not do sibcall. */
2765 || (OUTGOING_REG_PARM_STACK_SPACE (funtype)
2766 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl)))
2767 || (reg_parm_stack_space != REG_PARM_STACK_SPACE (current_function_decl))
2769 /* Check whether the target is able to optimize the call
2771 || !targetm.function_ok_for_sibcall (fndecl, exp)
2772 /* Functions that do not return exactly once may not be sibcall
2774 || (flags & (ECF_RETURNS_TWICE | ECF_NORETURN))
2775 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr)))
2776 /* If the called function is nested in the current one, it might access
2777 some of the caller's arguments, but could clobber them beforehand if
2778 the argument areas are shared. */
2779 || (fndecl && decl_function_context (fndecl) == current_function_decl)
2780 /* If this function requires more stack slots than the current
2781 function, we cannot change it into a sibling call.
2782 crtl->args.pretend_args_size is not part of the
2783 stack allocated by our caller. */
2784 || args_size.constant > (crtl->args.size
2785 - crtl->args.pretend_args_size)
2786 /* If the callee pops its own arguments, then it must pop exactly
2787 the same number of arguments as the current function. */
2788 || (targetm.calls.return_pops_args (fndecl, funtype, args_size.constant)
2789 != targetm.calls.return_pops_args (current_function_decl,
2790 TREE_TYPE (current_function_decl),
2792 || !lang_hooks.decls.ok_for_sibcall (fndecl))
2795 /* Check if caller and callee disagree in promotion of function
2799 machine_mode caller_mode, caller_promoted_mode;
2800 machine_mode callee_mode, callee_promoted_mode;
2801 int caller_unsignedp, callee_unsignedp;
2802 tree caller_res = DECL_RESULT (current_function_decl);
2804 caller_unsignedp = TYPE_UNSIGNED (TREE_TYPE (caller_res));
2805 caller_mode = DECL_MODE (caller_res);
2806 callee_unsignedp = TYPE_UNSIGNED (TREE_TYPE (funtype));
2807 callee_mode = TYPE_MODE (TREE_TYPE (funtype));
2808 caller_promoted_mode
2809 = promote_function_mode (TREE_TYPE (caller_res), caller_mode,
2811 TREE_TYPE (current_function_decl), 1);
2812 callee_promoted_mode
2813 = promote_function_mode (TREE_TYPE (funtype), callee_mode,
2816 if (caller_mode != VOIDmode
2817 && (caller_promoted_mode != callee_promoted_mode
2818 || ((caller_mode != caller_promoted_mode
2819 || callee_mode != callee_promoted_mode)
2820 && (caller_unsignedp != callee_unsignedp
2821 || GET_MODE_BITSIZE (caller_mode)
2822 < GET_MODE_BITSIZE (callee_mode)))))
2826 /* Ensure current function's preferred stack boundary is at least
2827 what we need. Stack alignment may also increase preferred stack
2829 if (crtl->preferred_stack_boundary < preferred_stack_boundary)
2830 crtl->preferred_stack_boundary = preferred_stack_boundary;
2832 preferred_stack_boundary = crtl->preferred_stack_boundary;
2834 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
2836 /* We want to make two insn chains; one for a sibling call, the other
2837 for a normal call. We will select one of the two chains after
2838 initial RTL generation is complete. */
2839 for (pass = try_tail_call ? 0 : 1; pass < 2; pass++)
2841 int sibcall_failure = 0;
2842 /* We want to emit any pending stack adjustments before the tail
2843 recursion "call". That way we know any adjustment after the tail
2844 recursion call can be ignored if we indeed use the tail
2846 saved_pending_stack_adjust save;
2847 rtx_insn *insns, *before_call, *after_args;
2852 /* State variables we need to save and restore between
2854 save_pending_stack_adjust (&save);
2857 flags &= ~ECF_SIBCALL;
2859 flags |= ECF_SIBCALL;
2861 /* Other state variables that we must reinitialize each time
2862 through the loop (that are not initialized by the loop itself). */
2866 /* Start a new sequence for the normal call case.
2868 From this point on, if the sibling call fails, we want to set
2869 sibcall_failure instead of continuing the loop. */
2872 /* Don't let pending stack adjusts add up to too much.
2873 Also, do all pending adjustments now if there is any chance
2874 this might be a call to alloca or if we are expanding a sibling
2876 Also do the adjustments before a throwing call, otherwise
2877 exception handling can fail; PR 19225. */
2878 if (pending_stack_adjust >= 32
2879 || (pending_stack_adjust > 0
2880 && (flags & ECF_MAY_BE_ALLOCA))
2881 || (pending_stack_adjust > 0
2882 && flag_exceptions && !(flags & ECF_NOTHROW))
2884 do_pending_stack_adjust ();
2886 /* Precompute any arguments as needed. */
2888 precompute_arguments (num_actuals, args);
2890 /* Now we are about to start emitting insns that can be deleted
2891 if a libcall is deleted. */
2892 if (pass && (flags & ECF_MALLOC))
2895 if (pass == 0 && crtl->stack_protect_guard)
2896 stack_protect_epilogue ();
2898 adjusted_args_size = args_size;
2899 /* Compute the actual size of the argument block required. The variable
2900 and constant sizes must be combined, the size may have to be rounded,
2901 and there may be a minimum required size. When generating a sibcall
2902 pattern, do not round up, since we'll be re-using whatever space our
2904 unadjusted_args_size
2905 = compute_argument_block_size (reg_parm_stack_space,
2906 &adjusted_args_size,
2909 : preferred_stack_boundary));
2911 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
2913 /* The argument block when performing a sibling call is the
2914 incoming argument block. */
2917 argblock = crtl->args.internal_arg_pointer;
2918 if (STACK_GROWS_DOWNWARD)
2920 = plus_constant (Pmode, argblock, crtl->args.pretend_args_size);
2923 = plus_constant (Pmode, argblock, -crtl->args.pretend_args_size);
2925 stored_args_map = sbitmap_alloc (args_size.constant);
2926 bitmap_clear (stored_args_map);
2929 /* If we have no actual push instructions, or shouldn't use them,
2930 make space for all args right now. */
2931 else if (adjusted_args_size.var != 0)
2933 if (old_stack_level == 0)
2935 emit_stack_save (SAVE_BLOCK, &old_stack_level);
2936 old_stack_pointer_delta = stack_pointer_delta;
2937 old_pending_adj = pending_stack_adjust;
2938 pending_stack_adjust = 0;
2939 /* stack_arg_under_construction says whether a stack arg is
2940 being constructed at the old stack level. Pushing the stack
2941 gets a clean outgoing argument block. */
2942 old_stack_arg_under_construction = stack_arg_under_construction;
2943 stack_arg_under_construction = 0;
2945 argblock = push_block (ARGS_SIZE_RTX (adjusted_args_size), 0, 0);
2946 if (flag_stack_usage_info)
2947 current_function_has_unbounded_dynamic_stack_size = 1;
2951 /* Note that we must go through the motions of allocating an argument
2952 block even if the size is zero because we may be storing args
2953 in the area reserved for register arguments, which may be part of
2956 int needed = adjusted_args_size.constant;
2958 /* Store the maximum argument space used. It will be pushed by
2959 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2962 if (needed > crtl->outgoing_args_size)
2963 crtl->outgoing_args_size = needed;
2965 if (must_preallocate)
2967 if (ACCUMULATE_OUTGOING_ARGS)
2969 /* Since the stack pointer will never be pushed, it is
2970 possible for the evaluation of a parm to clobber
2971 something we have already written to the stack.
2972 Since most function calls on RISC machines do not use
2973 the stack, this is uncommon, but must work correctly.
2975 Therefore, we save any area of the stack that was already
2976 written and that we are using. Here we set up to do this
2977 by making a new stack usage map from the old one. The
2978 actual save will be done by store_one_arg.
2980 Another approach might be to try to reorder the argument
2981 evaluations to avoid this conflicting stack usage. */
2983 /* Since we will be writing into the entire argument area,
2984 the map must be allocated for its entire size, not just
2985 the part that is the responsibility of the caller. */
2986 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
2987 needed += reg_parm_stack_space;
2989 if (ARGS_GROW_DOWNWARD)
2990 highest_outgoing_arg_in_use
2991 = MAX (initial_highest_arg_in_use, needed + 1);
2993 highest_outgoing_arg_in_use
2994 = MAX (initial_highest_arg_in_use, needed);
2996 free (stack_usage_map_buf);
2997 stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
2998 stack_usage_map = stack_usage_map_buf;
3000 if (initial_highest_arg_in_use)
3001 memcpy (stack_usage_map, initial_stack_usage_map,
3002 initial_highest_arg_in_use);
3004 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3005 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
3006 (highest_outgoing_arg_in_use
3007 - initial_highest_arg_in_use));
3010 /* The address of the outgoing argument list must not be
3011 copied to a register here, because argblock would be left
3012 pointing to the wrong place after the call to
3013 allocate_dynamic_stack_space below. */
3015 argblock = virtual_outgoing_args_rtx;
3019 if (inhibit_defer_pop == 0)
3021 /* Try to reuse some or all of the pending_stack_adjust
3022 to get this space. */
3024 = (combine_pending_stack_adjustment_and_call
3025 (unadjusted_args_size,
3026 &adjusted_args_size,
3027 preferred_unit_stack_boundary));
3029 /* combine_pending_stack_adjustment_and_call computes
3030 an adjustment before the arguments are allocated.
3031 Account for them and see whether or not the stack
3032 needs to go up or down. */
3033 needed = unadjusted_args_size - needed;
3037 /* We're releasing stack space. */
3038 /* ??? We can avoid any adjustment at all if we're
3039 already aligned. FIXME. */
3040 pending_stack_adjust = -needed;
3041 do_pending_stack_adjust ();
3045 /* We need to allocate space. We'll do that in
3046 push_block below. */
3047 pending_stack_adjust = 0;
3050 /* Special case this because overhead of `push_block' in
3051 this case is non-trivial. */
3053 argblock = virtual_outgoing_args_rtx;
3056 argblock = push_block (GEN_INT (needed), 0, 0);
3057 if (ARGS_GROW_DOWNWARD)
3058 argblock = plus_constant (Pmode, argblock, needed);
3061 /* We only really need to call `copy_to_reg' in the case
3062 where push insns are going to be used to pass ARGBLOCK
3063 to a function call in ARGS. In that case, the stack
3064 pointer changes value from the allocation point to the
3065 call point, and hence the value of
3066 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
3067 as well always do it. */
3068 argblock = copy_to_reg (argblock);
3073 if (ACCUMULATE_OUTGOING_ARGS)
3075 /* The save/restore code in store_one_arg handles all
3076 cases except one: a constructor call (including a C
3077 function returning a BLKmode struct) to initialize
3079 if (stack_arg_under_construction)
3082 = GEN_INT (adjusted_args_size.constant
3083 + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype
3084 : TREE_TYPE (fndecl))) ? 0
3085 : reg_parm_stack_space));
3086 if (old_stack_level == 0)
3088 emit_stack_save (SAVE_BLOCK, &old_stack_level);
3089 old_stack_pointer_delta = stack_pointer_delta;
3090 old_pending_adj = pending_stack_adjust;
3091 pending_stack_adjust = 0;
3092 /* stack_arg_under_construction says whether a stack
3093 arg is being constructed at the old stack level.
3094 Pushing the stack gets a clean outgoing argument
3096 old_stack_arg_under_construction
3097 = stack_arg_under_construction;
3098 stack_arg_under_construction = 0;
3099 /* Make a new map for the new argument list. */
3100 free (stack_usage_map_buf);
3101 stack_usage_map_buf = XCNEWVEC (char, highest_outgoing_arg_in_use);
3102 stack_usage_map = stack_usage_map_buf;
3103 highest_outgoing_arg_in_use = 0;
3105 /* We can pass TRUE as the 4th argument because we just
3106 saved the stack pointer and will restore it right after
3108 allocate_dynamic_stack_space (push_size, 0,
3109 BIGGEST_ALIGNMENT, true);
3112 /* If argument evaluation might modify the stack pointer,
3113 copy the address of the argument list to a register. */
3114 for (i = 0; i < num_actuals; i++)
3115 if (args[i].pass_on_stack)
3117 argblock = copy_addr_to_reg (argblock);
3122 compute_argument_addresses (args, argblock, num_actuals);
3124 /* Stack is properly aligned, pops can't safely be deferred during
3125 the evaluation of the arguments. */
3128 /* Precompute all register parameters. It isn't safe to compute
3129 anything once we have started filling any specific hard regs.
3130 TLS symbols sometimes need a call to resolve. Precompute
3131 register parameters before any stack pointer manipulation
3132 to avoid unaligned stack in the called function. */
3133 precompute_register_parameters (num_actuals, args, ®_parm_seen);
3137 /* Perform stack alignment before the first push (the last arg). */
3139 && adjusted_args_size.constant > reg_parm_stack_space
3140 && adjusted_args_size.constant != unadjusted_args_size)
3142 /* When the stack adjustment is pending, we get better code
3143 by combining the adjustments. */
3144 if (pending_stack_adjust
3145 && ! inhibit_defer_pop)
3147 pending_stack_adjust
3148 = (combine_pending_stack_adjustment_and_call
3149 (unadjusted_args_size,
3150 &adjusted_args_size,
3151 preferred_unit_stack_boundary));
3152 do_pending_stack_adjust ();
3154 else if (argblock == 0)
3155 anti_adjust_stack (GEN_INT (adjusted_args_size.constant
3156 - unadjusted_args_size));
3158 /* Now that the stack is properly aligned, pops can't safely
3159 be deferred during the evaluation of the arguments. */
3162 /* Record the maximum pushed stack space size. We need to delay
3163 doing it this far to take into account the optimization done
3164 by combine_pending_stack_adjustment_and_call. */
3165 if (flag_stack_usage_info
3166 && !ACCUMULATE_OUTGOING_ARGS
3168 && adjusted_args_size.var == 0)
3170 int pushed = adjusted_args_size.constant + pending_stack_adjust;
3171 if (pushed > current_function_pushed_stack_size)
3172 current_function_pushed_stack_size = pushed;
3175 funexp = rtx_for_function_call (fndecl, addr);
3177 if (CALL_EXPR_STATIC_CHAIN (exp))
3178 static_chain_value = expand_normal (CALL_EXPR_STATIC_CHAIN (exp));
3180 static_chain_value = 0;
3182 #ifdef REG_PARM_STACK_SPACE
3183 /* Save the fixed argument area if it's part of the caller's frame and
3184 is clobbered by argument setup for this call. */
3185 if (ACCUMULATE_OUTGOING_ARGS && pass)
3186 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
3187 &low_to_save, &high_to_save);
3190 /* Now store (and compute if necessary) all non-register parms.
3191 These come before register parms, since they can require block-moves,
3192 which could clobber the registers used for register parms.
3193 Parms which have partial registers are not stored here,
3194 but we do preallocate space here if they want that. */
3196 for (i = 0; i < num_actuals; i++)
3198 /* Delay bounds until all other args are stored. */
3199 if (POINTER_BOUNDS_P (args[i].tree_value))
3201 else if (args[i].reg == 0 || args[i].pass_on_stack)
3203 rtx_insn *before_arg = get_last_insn ();
3205 /* We don't allow passing huge (> 2^30 B) arguments
3206 by value. It would cause an overflow later on. */
3207 if (adjusted_args_size.constant
3208 >= (1 << (HOST_BITS_PER_INT - 2)))
3210 sorry ("passing too large argument on stack");
3214 if (store_one_arg (&args[i], argblock, flags,
3215 adjusted_args_size.var != 0,
3216 reg_parm_stack_space)
3218 && check_sibcall_argument_overlap (before_arg,
3220 sibcall_failure = 1;
3225 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
3226 gen_rtx_USE (VOIDmode, args[i].stack),
3230 /* If we have a parm that is passed in registers but not in memory
3231 and whose alignment does not permit a direct copy into registers,
3232 make a group of pseudos that correspond to each register that we
3234 if (STRICT_ALIGNMENT)
3235 store_unaligned_arguments_into_pseudos (args, num_actuals);
3237 /* Now store any partially-in-registers parm.
3238 This is the last place a block-move can happen. */
3240 for (i = 0; i < num_actuals; i++)
3241 if (args[i].partial != 0 && ! args[i].pass_on_stack)
3243 rtx_insn *before_arg = get_last_insn ();
3245 /* On targets with weird calling conventions (e.g. PA) it's
3246 hard to ensure that all cases of argument overlap between
3247 stack and registers work. Play it safe and bail out. */
3248 if (ARGS_GROW_DOWNWARD && !STACK_GROWS_DOWNWARD)
3250 sibcall_failure = 1;
3254 if (store_one_arg (&args[i], argblock, flags,
3255 adjusted_args_size.var != 0,
3256 reg_parm_stack_space)
3258 && check_sibcall_argument_overlap (before_arg,
3260 sibcall_failure = 1;
3263 bool any_regs = false;
3264 for (i = 0; i < num_actuals; i++)
3265 if (args[i].reg != NULL_RTX)
3268 targetm.calls.call_args (args[i].reg, funtype);
3271 targetm.calls.call_args (pc_rtx, funtype);
3273 /* Figure out the register where the value, if any, will come back. */
3276 if (TYPE_MODE (rettype) != VOIDmode
3277 && ! structure_value_addr)
3279 if (pcc_struct_value)
3281 valreg = hard_function_value (build_pointer_type (rettype),
3282 fndecl, NULL, (pass == 0));
3283 if (CALL_WITH_BOUNDS_P (exp))
3284 valbnd = targetm.calls.
3285 chkp_function_value_bounds (build_pointer_type (rettype),
3286 fndecl, (pass == 0));
3290 valreg = hard_function_value (rettype, fndecl, fntype,
3292 if (CALL_WITH_BOUNDS_P (exp))
3293 valbnd = targetm.calls.chkp_function_value_bounds (rettype,
3298 /* If VALREG is a PARALLEL whose first member has a zero
3299 offset, use that. This is for targets such as m68k that
3300 return the same value in multiple places. */
3301 if (GET_CODE (valreg) == PARALLEL)
3303 rtx elem = XVECEXP (valreg, 0, 0);
3304 rtx where = XEXP (elem, 0);
3305 rtx offset = XEXP (elem, 1);
3306 if (offset == const0_rtx
3307 && GET_MODE (where) == GET_MODE (valreg))
3312 /* Store all bounds not passed in registers. */
3313 for (i = 0; i < num_actuals; i++)
3315 if (POINTER_BOUNDS_P (args[i].tree_value)
3317 store_bounds (&args[i],
3318 args[i].pointer_arg == -1
3320 : &args[args[i].pointer_arg]);
3323 /* If register arguments require space on the stack and stack space
3324 was not preallocated, allocate stack space here for arguments
3325 passed in registers. */
3326 if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
3327 && !ACCUMULATE_OUTGOING_ARGS
3328 && must_preallocate == 0 && reg_parm_stack_space > 0)
3329 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
3331 /* Pass the function the address in which to return a
3333 if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
3335 structure_value_addr
3336 = convert_memory_address (Pmode, structure_value_addr);
3337 emit_move_insn (struct_value,
3339 force_operand (structure_value_addr,
3342 if (REG_P (struct_value))
3343 use_reg (&call_fusage, struct_value);
3346 after_args = get_last_insn ();
3347 funexp = prepare_call_address (fndecl ? fndecl : fntype, funexp,
3348 static_chain_value, &call_fusage,
3349 reg_parm_seen, pass == 0);
3351 load_register_parameters (args, num_actuals, &call_fusage, flags,
3352 pass == 0, &sibcall_failure);
3354 /* Save a pointer to the last insn before the call, so that we can
3355 later safely search backwards to find the CALL_INSN. */
3356 before_call = get_last_insn ();
3358 /* Set up next argument register. For sibling calls on machines
3359 with register windows this should be the incoming register. */
3361 next_arg_reg = targetm.calls.function_incoming_arg (args_so_far,
3366 next_arg_reg = targetm.calls.function_arg (args_so_far,
3367 VOIDmode, void_type_node,
3370 if (pass == 1 && (return_flags & ERF_RETURNS_ARG))
3372 int arg_nr = return_flags & ERF_RETURN_ARG_MASK;
3373 arg_nr = num_actuals - arg_nr - 1;
3375 && arg_nr < num_actuals
3379 && GET_MODE (args[arg_nr].reg) == GET_MODE (valreg))
3381 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[arg_nr].tree_value)),
3382 gen_rtx_SET (valreg, args[arg_nr].reg),
3385 /* All arguments and registers used for the call must be set up by
3388 /* Stack must be properly aligned now. */
3390 || !(stack_pointer_delta % preferred_unit_stack_boundary));
3392 /* Generate the actual call instruction. */
3393 emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,
3394 adjusted_args_size.constant, struct_value_size,
3395 next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
3396 flags, args_so_far);
3400 rtx_call_insn *last;
3401 rtx datum = NULL_RTX;
3402 if (fndecl != NULL_TREE)
3404 datum = XEXP (DECL_RTL (fndecl), 0);
3405 gcc_assert (datum != NULL_RTX
3406 && GET_CODE (datum) == SYMBOL_REF);
3408 last = last_call_insn ();
3409 add_reg_note (last, REG_CALL_DECL, datum);
3412 /* If the call setup or the call itself overlaps with anything
3413 of the argument setup we probably clobbered our call address.
3414 In that case we can't do sibcalls. */
3416 && check_sibcall_argument_overlap (after_args, 0, 0))
3417 sibcall_failure = 1;
3419 /* If a non-BLKmode value is returned at the most significant end
3420 of a register, shift the register right by the appropriate amount
3421 and update VALREG accordingly. BLKmode values are handled by the
3422 group load/store machinery below. */
3423 if (!structure_value_addr
3424 && !pcc_struct_value
3425 && TYPE_MODE (rettype) != VOIDmode
3426 && TYPE_MODE (rettype) != BLKmode
3428 && targetm.calls.return_in_msb (rettype))
3430 if (shift_return_value (TYPE_MODE (rettype), false, valreg))
3431 sibcall_failure = 1;
3432 valreg = gen_rtx_REG (TYPE_MODE (rettype), REGNO (valreg));
3435 if (pass && (flags & ECF_MALLOC))
3437 rtx temp = gen_reg_rtx (GET_MODE (valreg));
3438 rtx_insn *last, *insns;
3440 /* The return value from a malloc-like function is a pointer. */
3441 if (TREE_CODE (rettype) == POINTER_TYPE)
3442 mark_reg_pointer (temp, MALLOC_ABI_ALIGNMENT);
3444 emit_move_insn (temp, valreg);
3446 /* The return value from a malloc-like function can not alias
3448 last = get_last_insn ();
3449 add_reg_note (last, REG_NOALIAS, temp);
3451 /* Write out the sequence. */
3452 insns = get_insns ();
3458 /* For calls to `setjmp', etc., inform
3459 function.c:setjmp_warnings that it should complain if
3460 nonvolatile values are live. For functions that cannot
3461 return, inform flow that control does not fall through. */
3463 if ((flags & ECF_NORETURN) || pass == 0)
3465 /* The barrier must be emitted
3466 immediately after the CALL_INSN. Some ports emit more
3467 than just a CALL_INSN above, so we must search for it here. */
3469 rtx_insn *last = get_last_insn ();
3470 while (!CALL_P (last))
3472 last = PREV_INSN (last);
3473 /* There was no CALL_INSN? */
3474 gcc_assert (last != before_call);
3477 emit_barrier_after (last);
3479 /* Stack adjustments after a noreturn call are dead code.
3480 However when NO_DEFER_POP is in effect, we must preserve
3481 stack_pointer_delta. */
3482 if (inhibit_defer_pop == 0)
3484 stack_pointer_delta = old_stack_allocated;
3485 pending_stack_adjust = 0;
3489 /* If value type not void, return an rtx for the value. */
3491 if (TYPE_MODE (rettype) == VOIDmode
3493 target = const0_rtx;
3494 else if (structure_value_addr)
3496 if (target == 0 || !MEM_P (target))
3499 = gen_rtx_MEM (TYPE_MODE (rettype),
3500 memory_address (TYPE_MODE (rettype),
3501 structure_value_addr));
3502 set_mem_attributes (target, rettype, 1);
3505 else if (pcc_struct_value)
3507 /* This is the special C++ case where we need to
3508 know what the true target was. We take care to
3509 never use this value more than once in one expression. */
3510 target = gen_rtx_MEM (TYPE_MODE (rettype),
3511 copy_to_reg (valreg));
3512 set_mem_attributes (target, rettype, 1);
3514 /* Handle calls that return values in multiple non-contiguous locations.
3515 The Irix 6 ABI has examples of this. */
3516 else if (GET_CODE (valreg) == PARALLEL)
3519 target = emit_group_move_into_temps (valreg);
3520 else if (rtx_equal_p (target, valreg))
3522 else if (GET_CODE (target) == PARALLEL)
3523 /* Handle the result of a emit_group_move_into_temps
3524 call in the previous pass. */
3525 emit_group_move (target, valreg);
3527 emit_group_store (target, valreg, rettype,
3528 int_size_in_bytes (rettype));
3531 && GET_MODE (target) == TYPE_MODE (rettype)
3532 && GET_MODE (target) == GET_MODE (valreg))
3534 bool may_overlap = false;
3536 /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
3537 reg to a plain register. */
3538 if (!REG_P (target) || HARD_REGISTER_P (target))
3539 valreg = avoid_likely_spilled_reg (valreg);
3541 /* If TARGET is a MEM in the argument area, and we have
3542 saved part of the argument area, then we can't store
3543 directly into TARGET as it may get overwritten when we
3544 restore the argument save area below. Don't work too
3545 hard though and simply force TARGET to a register if it
3546 is a MEM; the optimizer is quite likely to sort it out. */
3547 if (ACCUMULATE_OUTGOING_ARGS && pass && MEM_P (target))
3548 for (i = 0; i < num_actuals; i++)
3549 if (args[i].save_area)
3556 target = copy_to_reg (valreg);
3559 /* TARGET and VALREG cannot be equal at this point
3560 because the latter would not have
3561 REG_FUNCTION_VALUE_P true, while the former would if
3562 it were referring to the same register.
3564 If they refer to the same register, this move will be
3565 a no-op, except when function inlining is being
3567 emit_move_insn (target, valreg);
3569 /* If we are setting a MEM, this code must be executed.
3570 Since it is emitted after the call insn, sibcall
3571 optimization cannot be performed in that case. */
3573 sibcall_failure = 1;
3577 target = copy_to_reg (avoid_likely_spilled_reg (valreg));
3579 /* If we promoted this return value, make the proper SUBREG.
3580 TARGET might be const0_rtx here, so be careful. */
3582 && TYPE_MODE (rettype) != BLKmode
3583 && GET_MODE (target) != TYPE_MODE (rettype))
3585 tree type = rettype;
3586 int unsignedp = TYPE_UNSIGNED (type);
3590 /* Ensure we promote as expected, and get the new unsignedness. */
3591 pmode = promote_function_mode (type, TYPE_MODE (type), &unsignedp,
3593 gcc_assert (GET_MODE (target) == pmode);
3595 if ((WORDS_BIG_ENDIAN || BYTES_BIG_ENDIAN)
3596 && (GET_MODE_SIZE (GET_MODE (target))
3597 > GET_MODE_SIZE (TYPE_MODE (type))))
3599 offset = GET_MODE_SIZE (GET_MODE (target))
3600 - GET_MODE_SIZE (TYPE_MODE (type));
3601 if (! BYTES_BIG_ENDIAN)
3602 offset = (offset / UNITS_PER_WORD) * UNITS_PER_WORD;
3603 else if (! WORDS_BIG_ENDIAN)
3604 offset %= UNITS_PER_WORD;
3607 target = gen_rtx_SUBREG (TYPE_MODE (type), target, offset);
3608 SUBREG_PROMOTED_VAR_P (target) = 1;
3609 SUBREG_PROMOTED_SET (target, unsignedp);
3612 /* If size of args is variable or this was a constructor call for a stack
3613 argument, restore saved stack-pointer value. */
3615 if (old_stack_level)
3617 rtx_insn *prev = get_last_insn ();
3619 emit_stack_restore (SAVE_BLOCK, old_stack_level);
3620 stack_pointer_delta = old_stack_pointer_delta;
3622 fixup_args_size_notes (prev, get_last_insn (), stack_pointer_delta);
3624 pending_stack_adjust = old_pending_adj;
3625 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
3626 stack_arg_under_construction = old_stack_arg_under_construction;
3627 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3628 stack_usage_map = initial_stack_usage_map;
3629 sibcall_failure = 1;
3631 else if (ACCUMULATE_OUTGOING_ARGS && pass)
3633 #ifdef REG_PARM_STACK_SPACE
3635 restore_fixed_argument_area (save_area, argblock,
3636 high_to_save, low_to_save);
3639 /* If we saved any argument areas, restore them. */
3640 for (i = 0; i < num_actuals; i++)
3641 if (args[i].save_area)
3643 machine_mode save_mode = GET_MODE (args[i].save_area);
3645 = gen_rtx_MEM (save_mode,
3646 memory_address (save_mode,
3647 XEXP (args[i].stack_slot, 0)));
3649 if (save_mode != BLKmode)
3650 emit_move_insn (stack_area, args[i].save_area);
3652 emit_block_move (stack_area, args[i].save_area,
3653 GEN_INT (args[i].locate.size.constant),
3654 BLOCK_OP_CALL_PARM);
3657 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3658 stack_usage_map = initial_stack_usage_map;
3661 /* If this was alloca, record the new stack level. */
3662 if (flags & ECF_MAY_BE_ALLOCA)
3663 record_new_stack_level ();
3665 /* Free up storage we no longer need. */
3666 for (i = 0; i < num_actuals; ++i)
3667 free (args[i].aligned_regs);
3669 targetm.calls.end_call_args ();
3671 insns = get_insns ();
3676 tail_call_insns = insns;
3678 /* Restore the pending stack adjustment now that we have
3679 finished generating the sibling call sequence. */
3681 restore_pending_stack_adjust (&save);
3683 /* Prepare arg structure for next iteration. */
3684 for (i = 0; i < num_actuals; i++)
3687 args[i].aligned_regs = 0;
3691 sbitmap_free (stored_args_map);
3692 internal_arg_pointer_exp_state.scan_start = NULL;
3693 internal_arg_pointer_exp_state.cache.release ();
3697 normal_call_insns = insns;
3699 /* Verify that we've deallocated all the stack we used. */
3700 gcc_assert ((flags & ECF_NORETURN)
3701 || (old_stack_allocated
3702 == stack_pointer_delta - pending_stack_adjust));
3705 /* If something prevents making this a sibling call,
3706 zero out the sequence. */
3707 if (sibcall_failure)
3708 tail_call_insns = NULL;
3713 /* If tail call production succeeded, we need to remove REG_EQUIV notes on
3714 arguments too, as argument area is now clobbered by the call. */
3715 if (tail_call_insns)
3717 emit_insn (tail_call_insns);
3718 crtl->tail_call_emit = true;
3721 emit_insn (normal_call_insns);
3723 currently_expanding_call--;
3725 free (stack_usage_map_buf);
3727 /* Join result with returned bounds so caller may use them if needed. */
3728 target = chkp_join_splitted_slot (target, valbnd);
3733 /* A sibling call sequence invalidates any REG_EQUIV notes made for
3734 this function's incoming arguments.
3736 At the start of RTL generation we know the only REG_EQUIV notes
3737 in the rtl chain are those for incoming arguments, so we can look
3738 for REG_EQUIV notes between the start of the function and the
3739 NOTE_INSN_FUNCTION_BEG.
3741 This is (slight) overkill. We could keep track of the highest
3742 argument we clobber and be more selective in removing notes, but it
3743 does not seem to be worth the effort. */
3746 fixup_tail_calls (void)
3750 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3754 /* There are never REG_EQUIV notes for the incoming arguments
3755 after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
3757 && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
3760 note = find_reg_note (insn, REG_EQUIV, 0);
3762 remove_note (insn, note);
3763 note = find_reg_note (insn, REG_EQUIV, 0);
3768 /* Traverse a list of TYPES and expand all complex types into their
3771 split_complex_types (tree types)
3775 /* Before allocating memory, check for the common case of no complex. */
3776 for (p = types; p; p = TREE_CHAIN (p))
3778 tree type = TREE_VALUE (p);
3779 if (TREE_CODE (type) == COMPLEX_TYPE
3780 && targetm.calls.split_complex_arg (type))
3786 types = copy_list (types);
3788 for (p = types; p; p = TREE_CHAIN (p))
3790 tree complex_type = TREE_VALUE (p);
3792 if (TREE_CODE (complex_type) == COMPLEX_TYPE
3793 && targetm.calls.split_complex_arg (complex_type))
3797 /* Rewrite complex type with component type. */
3798 TREE_VALUE (p) = TREE_TYPE (complex_type);
3799 next = TREE_CHAIN (p);
3801 /* Add another component type for the imaginary part. */
3802 imag = build_tree_list (NULL_TREE, TREE_VALUE (p));
3803 TREE_CHAIN (p) = imag;
3804 TREE_CHAIN (imag) = next;
3806 /* Skip the newly created node. */
3814 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3815 The RETVAL parameter specifies whether return value needs to be saved, other
3816 parameters are documented in the emit_library_call function below. */
3819 emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
3820 enum libcall_type fn_type,
3821 machine_mode outmode, int nargs, va_list p)
3823 /* Total size in bytes of all the stack-parms scanned so far. */
3824 struct args_size args_size;
3825 /* Size of arguments before any adjustments (such as rounding). */
3826 struct args_size original_args_size;
3829 /* Todo, choose the correct decl type of orgfun. Sadly this information
3830 isn't present here, so we default to native calling abi here. */
3831 tree fndecl ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
3832 tree fntype ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
3835 CUMULATIVE_ARGS args_so_far_v;
3836 cumulative_args_t args_so_far;
3843 struct locate_and_pad_arg_data locate;
3847 int old_inhibit_defer_pop = inhibit_defer_pop;
3848 rtx call_fusage = 0;
3851 int pcc_struct_value = 0;
3852 int struct_value_size = 0;
3854 int reg_parm_stack_space = 0;
3856 rtx_insn *before_call;
3857 bool have_push_fusage;
3858 tree tfom; /* type_for_mode (outmode, 0) */
3860 #ifdef REG_PARM_STACK_SPACE
3861 /* Define the boundary of the register parm stack space that needs to be
3863 int low_to_save = 0, high_to_save = 0;
3864 rtx save_area = 0; /* Place that it is saved. */
3867 /* Size of the stack reserved for parameter registers. */
3868 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3869 char *initial_stack_usage_map = stack_usage_map;
3870 char *stack_usage_map_buf = NULL;
3872 rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
3874 #ifdef REG_PARM_STACK_SPACE
3875 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3878 /* By default, library functions cannot throw. */
3879 flags = ECF_NOTHROW;
3892 flags |= ECF_NORETURN;
3895 flags &= ~ECF_NOTHROW;
3897 case LCT_RETURNS_TWICE:
3898 flags = ECF_RETURNS_TWICE;
3903 /* Ensure current function's preferred stack boundary is at least
3905 if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3906 crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3908 /* If this kind of value comes back in memory,
3909 decide where in memory it should come back. */
3910 if (outmode != VOIDmode)
3912 tfom = lang_hooks.types.type_for_mode (outmode, 0);
3913 if (aggregate_value_p (tfom, 0))
3915 #ifdef PCC_STATIC_STRUCT_RETURN
3917 = hard_function_value (build_pointer_type (tfom), 0, 0, 0);
3918 mem_value = gen_rtx_MEM (outmode, pointer_reg);
3919 pcc_struct_value = 1;
3921 value = gen_reg_rtx (outmode);
3922 #else /* not PCC_STATIC_STRUCT_RETURN */
3923 struct_value_size = GET_MODE_SIZE (outmode);
3924 if (value != 0 && MEM_P (value))
3927 mem_value = assign_temp (tfom, 1, 1);
3929 /* This call returns a big structure. */
3930 flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
3934 tfom = void_type_node;
3936 /* ??? Unfinished: must pass the memory address as an argument. */
3938 /* Copy all the libcall-arguments out of the varargs data
3939 and into a vector ARGVEC.
3941 Compute how to pass each argument. We only support a very small subset
3942 of the full argument passing conventions to limit complexity here since
3943 library functions shouldn't have many args. */
3945 argvec = XALLOCAVEC (struct arg, nargs + 1);
3946 memset (argvec, 0, (nargs + 1) * sizeof (struct arg));
3948 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3949 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v, outmode, fun);
3951 INIT_CUMULATIVE_ARGS (args_so_far_v, NULL_TREE, fun, 0, nargs);
3953 args_so_far = pack_cumulative_args (&args_so_far_v);
3955 args_size.constant = 0;
3962 /* If there's a structure value address to be passed,
3963 either pass it in the special place, or pass it as an extra argument. */
3964 if (mem_value && struct_value == 0 && ! pcc_struct_value)
3966 rtx addr = XEXP (mem_value, 0);
3970 /* Make sure it is a reasonable operand for a move or push insn. */
3971 if (!REG_P (addr) && !MEM_P (addr)
3972 && !(CONSTANT_P (addr)
3973 && targetm.legitimate_constant_p (Pmode, addr)))
3974 addr = force_operand (addr, NULL_RTX);
3976 argvec[count].value = addr;
3977 argvec[count].mode = Pmode;
3978 argvec[count].partial = 0;
3980 argvec[count].reg = targetm.calls.function_arg (args_so_far,
3981 Pmode, NULL_TREE, true);
3982 gcc_assert (targetm.calls.arg_partial_bytes (args_so_far, Pmode,
3983 NULL_TREE, 1) == 0);
3985 locate_and_pad_parm (Pmode, NULL_TREE,
3986 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3989 argvec[count].reg != 0,
3991 reg_parm_stack_space, 0,
3992 NULL_TREE, &args_size, &argvec[count].locate);
3994 if (argvec[count].reg == 0 || argvec[count].partial != 0
3995 || reg_parm_stack_space > 0)
3996 args_size.constant += argvec[count].locate.size.constant;
3998 targetm.calls.function_arg_advance (args_so_far, Pmode, (tree) 0, true);
4003 for (; count < nargs; count++)
4005 rtx val = va_arg (p, rtx);
4006 machine_mode mode = (machine_mode) va_arg (p, int);
4009 /* We cannot convert the arg value to the mode the library wants here;
4010 must do it earlier where we know the signedness of the arg. */
4011 gcc_assert (mode != BLKmode
4012 && (GET_MODE (val) == mode || GET_MODE (val) == VOIDmode));
4014 /* Make sure it is a reasonable operand for a move or push insn. */
4015 if (!REG_P (val) && !MEM_P (val)
4016 && !(CONSTANT_P (val) && targetm.legitimate_constant_p (mode, val)))
4017 val = force_operand (val, NULL_RTX);
4019 if (pass_by_reference (&args_so_far_v, mode, NULL_TREE, 1))
4023 = !reference_callee_copied (&args_so_far_v, mode, NULL_TREE, 1);
4025 /* If this was a CONST function, it is now PURE since it now
4027 if (flags & ECF_CONST)
4029 flags &= ~ECF_CONST;
4033 if (MEM_P (val) && !must_copy)
4035 tree val_expr = MEM_EXPR (val);
4037 mark_addressable (val_expr);
4042 slot = assign_temp (lang_hooks.types.type_for_mode (mode, 0),
4044 emit_move_insn (slot, val);
4047 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
4048 gen_rtx_USE (VOIDmode, slot),
4051 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
4052 gen_rtx_CLOBBER (VOIDmode,
4057 val = force_operand (XEXP (slot, 0), NULL_RTX);
4060 mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0);
4061 argvec[count].mode = mode;
4062 argvec[count].value = convert_modes (mode, GET_MODE (val), val, unsigned_p);
4063 argvec[count].reg = targetm.calls.function_arg (args_so_far, mode,
4066 argvec[count].partial
4067 = targetm.calls.arg_partial_bytes (args_so_far, mode, NULL_TREE, 1);
4069 if (argvec[count].reg == 0
4070 || argvec[count].partial != 0
4071 || reg_parm_stack_space > 0)
4073 locate_and_pad_parm (mode, NULL_TREE,
4074 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4077 argvec[count].reg != 0,
4079 reg_parm_stack_space, argvec[count].partial,
4080 NULL_TREE, &args_size, &argvec[count].locate);
4081 args_size.constant += argvec[count].locate.size.constant;
4082 gcc_assert (!argvec[count].locate.size.var);
4084 #ifdef BLOCK_REG_PADDING
4086 /* The argument is passed entirely in registers. See at which
4087 end it should be padded. */
4088 argvec[count].locate.where_pad =
4089 BLOCK_REG_PADDING (mode, NULL_TREE,
4090 GET_MODE_SIZE (mode) <= UNITS_PER_WORD);
4093 targetm.calls.function_arg_advance (args_so_far, mode, (tree) 0, true);
4096 /* If this machine requires an external definition for library
4097 functions, write one out. */
4098 assemble_external_libcall (fun);
4100 original_args_size = args_size;
4101 args_size.constant = (((args_size.constant
4102 + stack_pointer_delta
4106 - stack_pointer_delta);
4108 args_size.constant = MAX (args_size.constant,
4109 reg_parm_stack_space);
4111 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
4112 args_size.constant -= reg_parm_stack_space;
4114 if (args_size.constant > crtl->outgoing_args_size)
4115 crtl->outgoing_args_size = args_size.constant;
4117 if (flag_stack_usage_info && !ACCUMULATE_OUTGOING_ARGS)
4119 int pushed = args_size.constant + pending_stack_adjust;
4120 if (pushed > current_function_pushed_stack_size)
4121 current_function_pushed_stack_size = pushed;
4124 if (ACCUMULATE_OUTGOING_ARGS)
4126 /* Since the stack pointer will never be pushed, it is possible for
4127 the evaluation of a parm to clobber something we have already
4128 written to the stack. Since most function calls on RISC machines
4129 do not use the stack, this is uncommon, but must work correctly.
4131 Therefore, we save any area of the stack that was already written
4132 and that we are using. Here we set up to do this by making a new
4133 stack usage map from the old one.
4135 Another approach might be to try to reorder the argument
4136 evaluations to avoid this conflicting stack usage. */
4138 needed = args_size.constant;
4140 /* Since we will be writing into the entire argument area, the
4141 map must be allocated for its entire size, not just the part that
4142 is the responsibility of the caller. */
4143 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
4144 needed += reg_parm_stack_space;
4146 if (ARGS_GROW_DOWNWARD)
4147 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
4150 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, needed);
4152 stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
4153 stack_usage_map = stack_usage_map_buf;
4155 if (initial_highest_arg_in_use)
4156 memcpy (stack_usage_map, initial_stack_usage_map,
4157 initial_highest_arg_in_use);
4159 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
4160 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
4161 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
4164 /* We must be careful to use virtual regs before they're instantiated,
4165 and real regs afterwards. Loop optimization, for example, can create
4166 new libcalls after we've instantiated the virtual regs, and if we
4167 use virtuals anyway, they won't match the rtl patterns. */
4169 if (virtuals_instantiated)
4170 argblock = plus_constant (Pmode, stack_pointer_rtx,
4171 STACK_POINTER_OFFSET);
4173 argblock = virtual_outgoing_args_rtx;
4178 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
4181 /* We push args individually in reverse order, perform stack alignment
4182 before the first push (the last arg). */
4184 anti_adjust_stack (GEN_INT (args_size.constant
4185 - original_args_size.constant));
4189 #ifdef REG_PARM_STACK_SPACE
4190 if (ACCUMULATE_OUTGOING_ARGS)
4192 /* The argument list is the property of the called routine and it
4193 may clobber it. If the fixed area has been used for previous
4194 parameters, we must save and restore it. */
4195 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
4196 &low_to_save, &high_to_save);
4200 /* When expanding a normal call, args are stored in push order,
4201 which is the reverse of what we have here. */
4202 bool any_regs = false;
4203 for (int i = nargs; i-- > 0; )
4204 if (argvec[i].reg != NULL_RTX)
4206 targetm.calls.call_args (argvec[i].reg, NULL_TREE);
4210 targetm.calls.call_args (pc_rtx, NULL_TREE);
4212 /* Push the args that need to be pushed. */
4214 have_push_fusage = false;
4216 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4217 are to be pushed. */
4218 for (count = 0; count < nargs; count++, argnum--)
4220 machine_mode mode = argvec[argnum].mode;
4221 rtx val = argvec[argnum].value;
4222 rtx reg = argvec[argnum].reg;
4223 int partial = argvec[argnum].partial;
4224 unsigned int parm_align = argvec[argnum].locate.boundary;
4225 int lower_bound = 0, upper_bound = 0, i;
4227 if (! (reg != 0 && partial == 0))
4231 if (ACCUMULATE_OUTGOING_ARGS)
4233 /* If this is being stored into a pre-allocated, fixed-size,
4234 stack area, save any previous data at that location. */
4236 if (ARGS_GROW_DOWNWARD)
4238 /* stack_slot is negative, but we want to index stack_usage_map
4239 with positive values. */
4240 upper_bound = -argvec[argnum].locate.slot_offset.constant + 1;
4241 lower_bound = upper_bound - argvec[argnum].locate.size.constant;
4245 lower_bound = argvec[argnum].locate.slot_offset.constant;
4246 upper_bound = lower_bound + argvec[argnum].locate.size.constant;
4250 /* Don't worry about things in the fixed argument area;
4251 it has already been saved. */
4252 if (i < reg_parm_stack_space)
4253 i = reg_parm_stack_space;
4254 while (i < upper_bound && stack_usage_map[i] == 0)
4257 if (i < upper_bound)
4259 /* We need to make a save area. */
4261 = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
4262 machine_mode save_mode
4263 = mode_for_size (size, MODE_INT, 1);
4265 = plus_constant (Pmode, argblock,
4266 argvec[argnum].locate.offset.constant);
4268 = gen_rtx_MEM (save_mode, memory_address (save_mode, adr));
4270 if (save_mode == BLKmode)
4272 argvec[argnum].save_area
4273 = assign_stack_temp (BLKmode,
4274 argvec[argnum].locate.size.constant
4277 emit_block_move (validize_mem
4278 (copy_rtx (argvec[argnum].save_area)),
4280 GEN_INT (argvec[argnum].locate.size.constant),
4281 BLOCK_OP_CALL_PARM);
4285 argvec[argnum].save_area = gen_reg_rtx (save_mode);
4287 emit_move_insn (argvec[argnum].save_area, stack_area);
4292 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, parm_align,
4293 partial, reg, 0, argblock,
4294 GEN_INT (argvec[argnum].locate.offset.constant),
4295 reg_parm_stack_space,
4296 ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad), false);
4298 /* Now mark the segment we just used. */
4299 if (ACCUMULATE_OUTGOING_ARGS)
4300 for (i = lower_bound; i < upper_bound; i++)
4301 stack_usage_map[i] = 1;
4305 /* Indicate argument access so that alias.c knows that these
4308 use = plus_constant (Pmode, argblock,
4309 argvec[argnum].locate.offset.constant);
4310 else if (have_push_fusage)
4314 /* When arguments are pushed, trying to tell alias.c where
4315 exactly this argument is won't work, because the
4316 auto-increment causes confusion. So we merely indicate
4317 that we access something with a known mode somewhere on
4319 use = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
4320 gen_rtx_SCRATCH (Pmode));
4321 have_push_fusage = true;
4323 use = gen_rtx_MEM (argvec[argnum].mode, use);
4324 use = gen_rtx_USE (VOIDmode, use);
4325 call_fusage = gen_rtx_EXPR_LIST (VOIDmode, use, call_fusage);
4331 fun = prepare_call_address (NULL, fun, NULL, &call_fusage, 0, 0);
4333 /* Now load any reg parms into their regs. */
4335 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4336 are to be pushed. */
4337 for (count = 0; count < nargs; count++, argnum--)
4339 machine_mode mode = argvec[argnum].mode;
4340 rtx val = argvec[argnum].value;
4341 rtx reg = argvec[argnum].reg;
4342 int partial = argvec[argnum].partial;
4343 #ifdef BLOCK_REG_PADDING
4347 /* Handle calls that pass values in multiple non-contiguous
4348 locations. The PA64 has examples of this for library calls. */
4349 if (reg != 0 && GET_CODE (reg) == PARALLEL)
4350 emit_group_load (reg, val, NULL_TREE, GET_MODE_SIZE (mode));
4351 else if (reg != 0 && partial == 0)
4353 emit_move_insn (reg, val);
4354 #ifdef BLOCK_REG_PADDING
4355 size = GET_MODE_SIZE (argvec[argnum].mode);
4357 /* Copied from load_register_parameters. */
4359 /* Handle case where we have a value that needs shifting
4360 up to the msb. eg. a QImode value and we're padding
4361 upward on a BYTES_BIG_ENDIAN machine. */
4362 if (size < UNITS_PER_WORD
4363 && (argvec[argnum].locate.where_pad
4364 == (BYTES_BIG_ENDIAN ? upward : downward)))
4367 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
4369 /* Assigning REG here rather than a temp makes CALL_FUSAGE
4370 report the whole reg as used. Strictly speaking, the
4371 call only uses SIZE bytes at the msb end, but it doesn't
4372 seem worth generating rtl to say that. */
4373 reg = gen_rtx_REG (word_mode, REGNO (reg));
4374 x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1);
4376 emit_move_insn (reg, x);
4384 /* Any regs containing parms remain in use through the call. */
4385 for (count = 0; count < nargs; count++)
4387 rtx reg = argvec[count].reg;
4388 if (reg != 0 && GET_CODE (reg) == PARALLEL)
4389 use_group_regs (&call_fusage, reg);
4392 int partial = argvec[count].partial;
4396 gcc_assert (partial % UNITS_PER_WORD == 0);
4397 nregs = partial / UNITS_PER_WORD;
4398 use_regs (&call_fusage, REGNO (reg), nregs);
4401 use_reg (&call_fusage, reg);
4405 /* Pass the function the address in which to return a structure value. */
4406 if (mem_value != 0 && struct_value != 0 && ! pcc_struct_value)
4408 emit_move_insn (struct_value,
4410 force_operand (XEXP (mem_value, 0),
4412 if (REG_P (struct_value))
4413 use_reg (&call_fusage, struct_value);
4416 /* Don't allow popping to be deferred, since then
4417 cse'ing of library calls could delete a call and leave the pop. */
4419 valreg = (mem_value == 0 && outmode != VOIDmode
4420 ? hard_libcall_value (outmode, orgfun) : NULL_RTX);
4422 /* Stack must be properly aligned now. */
4423 gcc_assert (!(stack_pointer_delta
4424 & (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)));
4426 before_call = get_last_insn ();
4428 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4429 will set inhibit_defer_pop to that value. */
4430 /* The return type is needed to decide how many bytes the function pops.
4431 Signedness plays no role in that, so for simplicity, we pretend it's
4432 always signed. We also assume that the list of arguments passed has
4433 no impact, so we pretend it is unknown. */
4435 emit_call_1 (fun, NULL,
4436 get_identifier (XSTR (orgfun, 0)),
4437 build_function_type (tfom, NULL_TREE),
4438 original_args_size.constant, args_size.constant,
4440 targetm.calls.function_arg (args_so_far,
4441 VOIDmode, void_type_node, true),
4443 old_inhibit_defer_pop + 1, call_fusage, flags, args_so_far);
4448 gcc_assert (GET_CODE (datum) == SYMBOL_REF);
4449 rtx_call_insn *last = last_call_insn ();
4450 add_reg_note (last, REG_CALL_DECL, datum);
4453 /* Right-shift returned value if necessary. */
4454 if (!pcc_struct_value
4455 && TYPE_MODE (tfom) != BLKmode
4456 && targetm.calls.return_in_msb (tfom))
4458 shift_return_value (TYPE_MODE (tfom), false, valreg);
4459 valreg = gen_rtx_REG (TYPE_MODE (tfom), REGNO (valreg));
4462 targetm.calls.end_call_args ();
4464 /* For calls to `setjmp', etc., inform function.c:setjmp_warnings
4465 that it should complain if nonvolatile values are live. For
4466 functions that cannot return, inform flow that control does not
4468 if (flags & ECF_NORETURN)
4470 /* The barrier note must be emitted
4471 immediately after the CALL_INSN. Some ports emit more than
4472 just a CALL_INSN above, so we must search for it here. */
4473 rtx_insn *last = get_last_insn ();
4474 while (!CALL_P (last))
4476 last = PREV_INSN (last);
4477 /* There was no CALL_INSN? */
4478 gcc_assert (last != before_call);
4481 emit_barrier_after (last);
4484 /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW
4485 and LCT_RETURNS_TWICE, cannot perform non-local gotos. */
4486 if (flags & ECF_NOTHROW)
4488 rtx_insn *last = get_last_insn ();
4489 while (!CALL_P (last))
4491 last = PREV_INSN (last);
4492 /* There was no CALL_INSN? */
4493 gcc_assert (last != before_call);
4496 make_reg_eh_region_note_nothrow_nononlocal (last);
4499 /* Now restore inhibit_defer_pop to its actual original value. */
4504 /* Copy the value to the right place. */
4505 if (outmode != VOIDmode && retval)
4511 if (value != mem_value)
4512 emit_move_insn (value, mem_value);
4514 else if (GET_CODE (valreg) == PARALLEL)
4517 value = gen_reg_rtx (outmode);
4518 emit_group_store (value, valreg, NULL_TREE, GET_MODE_SIZE (outmode));
4522 /* Convert to the proper mode if a promotion has been active. */
4523 if (GET_MODE (valreg) != outmode)
4525 int unsignedp = TYPE_UNSIGNED (tfom);
4527 gcc_assert (promote_function_mode (tfom, outmode, &unsignedp,
4528 fndecl ? TREE_TYPE (fndecl) : fntype, 1)
4529 == GET_MODE (valreg));
4530 valreg = convert_modes (outmode, GET_MODE (valreg), valreg, 0);
4534 emit_move_insn (value, valreg);
4540 if (ACCUMULATE_OUTGOING_ARGS)
4542 #ifdef REG_PARM_STACK_SPACE
4544 restore_fixed_argument_area (save_area, argblock,
4545 high_to_save, low_to_save);
4548 /* If we saved any argument areas, restore them. */
4549 for (count = 0; count < nargs; count++)
4550 if (argvec[count].save_area)
4552 machine_mode save_mode = GET_MODE (argvec[count].save_area);
4553 rtx adr = plus_constant (Pmode, argblock,
4554 argvec[count].locate.offset.constant);
4555 rtx stack_area = gen_rtx_MEM (save_mode,
4556 memory_address (save_mode, adr));
4558 if (save_mode == BLKmode)
4559 emit_block_move (stack_area,
4561 (copy_rtx (argvec[count].save_area)),
4562 GEN_INT (argvec[count].locate.size.constant),
4563 BLOCK_OP_CALL_PARM);
4565 emit_move_insn (stack_area, argvec[count].save_area);
4568 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
4569 stack_usage_map = initial_stack_usage_map;
4572 free (stack_usage_map_buf);
4578 /* Output a library call to function FUN (a SYMBOL_REF rtx)
4579 (emitting the queue unless NO_QUEUE is nonzero),
4580 for a value of mode OUTMODE,
4581 with NARGS different arguments, passed as alternating rtx values
4582 and machine_modes to convert them to.
4584 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for
4585 `const' calls, LCT_PURE for `pure' calls, or other LCT_ value for
4586 other types of library calls. */
4589 emit_library_call (rtx orgfun, enum libcall_type fn_type,
4590 machine_mode outmode, int nargs, ...)
4594 va_start (p, nargs);
4595 emit_library_call_value_1 (0, orgfun, NULL_RTX, fn_type, outmode, nargs, p);
4599 /* Like emit_library_call except that an extra argument, VALUE,
4600 comes second and says where to store the result.
4601 (If VALUE is zero, this function chooses a convenient way
4602 to return the value.
4604 This function returns an rtx for where the value is to be found.
4605 If VALUE is nonzero, VALUE is returned. */
4608 emit_library_call_value (rtx orgfun, rtx value,
4609 enum libcall_type fn_type,
4610 machine_mode outmode, int nargs, ...)
4615 va_start (p, nargs);
4616 result = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode,
4624 /* Store pointer bounds argument ARG into Bounds Table entry
4625 associated with PARM. */
4627 store_bounds (struct arg_data *arg, struct arg_data *parm)
4629 rtx slot = NULL, ptr = NULL, addr = NULL;
4631 /* We may pass bounds not associated with any pointer. */
4634 gcc_assert (arg->special_slot);
4635 slot = arg->special_slot;
4638 /* Find pointer associated with bounds and where it is
4644 gcc_assert (!arg->special_slot);
4646 addr = adjust_address (parm->stack, Pmode, arg->pointer_offset);
4648 else if (REG_P (parm->reg))
4650 gcc_assert (arg->special_slot);
4651 slot = arg->special_slot;
4653 if (MEM_P (parm->value))
4654 addr = adjust_address (parm->value, Pmode, arg->pointer_offset);
4655 else if (REG_P (parm->value))
4656 ptr = gen_rtx_SUBREG (Pmode, parm->value, arg->pointer_offset);
4659 gcc_assert (!arg->pointer_offset);
4665 gcc_assert (GET_CODE (parm->reg) == PARALLEL);
4667 gcc_assert (arg->special_slot);
4668 slot = arg->special_slot;
4670 if (parm->parallel_value)
4671 ptr = chkp_get_value_with_offs (parm->parallel_value,
4672 GEN_INT (arg->pointer_offset));
4678 /* Expand bounds. */
4680 arg->value = expand_normal (arg->tree_value);
4682 targetm.calls.store_bounds_for_arg (ptr, addr, arg->value, slot);
4685 /* Store a single argument for a function call
4686 into the register or memory area where it must be passed.
4687 *ARG describes the argument value and where to pass it.
4689 ARGBLOCK is the address of the stack-block for all the arguments,
4690 or 0 on a machine where arguments are pushed individually.
4692 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4693 so must be careful about how the stack is used.
4695 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4696 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4697 that we need not worry about saving and restoring the stack.
4699 FNDECL is the declaration of the function we are calling.
4701 Return nonzero if this arg should cause sibcall failure,
4705 store_one_arg (struct arg_data *arg, rtx argblock, int flags,
4706 int variable_size ATTRIBUTE_UNUSED, int reg_parm_stack_space)
4708 tree pval = arg->tree_value;
4712 int i, lower_bound = 0, upper_bound = 0;
4713 int sibcall_failure = 0;
4715 if (TREE_CODE (pval) == ERROR_MARK)
4718 /* Push a new temporary level for any temporaries we make for
4722 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL))
4724 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4725 save any previous data at that location. */
4726 if (argblock && ! variable_size && arg->stack)
4728 if (ARGS_GROW_DOWNWARD)
4730 /* stack_slot is negative, but we want to index stack_usage_map
4731 with positive values. */
4732 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4733 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
4737 lower_bound = upper_bound - arg->locate.size.constant;
4741 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4742 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
4746 upper_bound = lower_bound + arg->locate.size.constant;
4750 /* Don't worry about things in the fixed argument area;
4751 it has already been saved. */
4752 if (i < reg_parm_stack_space)
4753 i = reg_parm_stack_space;
4754 while (i < upper_bound && stack_usage_map[i] == 0)
4757 if (i < upper_bound)
4759 /* We need to make a save area. */
4760 unsigned int size = arg->locate.size.constant * BITS_PER_UNIT;
4761 machine_mode save_mode = mode_for_size (size, MODE_INT, 1);
4762 rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0));
4763 rtx stack_area = gen_rtx_MEM (save_mode, adr);
4765 if (save_mode == BLKmode)
4768 = assign_temp (TREE_TYPE (arg->tree_value), 1, 1);
4769 preserve_temp_slots (arg->save_area);
4770 emit_block_move (validize_mem (copy_rtx (arg->save_area)),
4772 GEN_INT (arg->locate.size.constant),
4773 BLOCK_OP_CALL_PARM);
4777 arg->save_area = gen_reg_rtx (save_mode);
4778 emit_move_insn (arg->save_area, stack_area);
4784 /* If this isn't going to be placed on both the stack and in registers,
4785 set up the register and number of words. */
4786 if (! arg->pass_on_stack)
4788 if (flags & ECF_SIBCALL)
4789 reg = arg->tail_call_reg;
4792 partial = arg->partial;
4795 /* Being passed entirely in a register. We shouldn't be called in
4797 gcc_assert (reg == 0 || partial != 0);
4799 /* If this arg needs special alignment, don't load the registers
4801 if (arg->n_aligned_regs != 0)
4804 /* If this is being passed partially in a register, we can't evaluate
4805 it directly into its stack slot. Otherwise, we can. */
4806 if (arg->value == 0)
4808 /* stack_arg_under_construction is nonzero if a function argument is
4809 being evaluated directly into the outgoing argument list and
4810 expand_call must take special action to preserve the argument list
4811 if it is called recursively.
4813 For scalar function arguments stack_usage_map is sufficient to
4814 determine which stack slots must be saved and restored. Scalar
4815 arguments in general have pass_on_stack == 0.
4817 If this argument is initialized by a function which takes the
4818 address of the argument (a C++ constructor or a C function
4819 returning a BLKmode structure), then stack_usage_map is
4820 insufficient and expand_call must push the stack around the
4821 function call. Such arguments have pass_on_stack == 1.
4823 Note that it is always safe to set stack_arg_under_construction,
4824 but this generates suboptimal code if set when not needed. */
4826 if (arg->pass_on_stack)
4827 stack_arg_under_construction++;
4829 arg->value = expand_expr (pval,
4831 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
4832 ? NULL_RTX : arg->stack,
4833 VOIDmode, EXPAND_STACK_PARM);
4835 /* If we are promoting object (or for any other reason) the mode
4836 doesn't agree, convert the mode. */
4838 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
4839 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
4840 arg->value, arg->unsignedp);
4842 if (arg->pass_on_stack)
4843 stack_arg_under_construction--;
4846 /* Check for overlap with already clobbered argument area. */
4847 if ((flags & ECF_SIBCALL)
4848 && MEM_P (arg->value)
4849 && mem_overlaps_already_clobbered_arg_p (XEXP (arg->value, 0),
4850 arg->locate.size.constant))
4851 sibcall_failure = 1;
4853 /* Don't allow anything left on stack from computation
4854 of argument to alloca. */
4855 if (flags & ECF_MAY_BE_ALLOCA)
4856 do_pending_stack_adjust ();
4858 if (arg->value == arg->stack)
4859 /* If the value is already in the stack slot, we are done. */
4861 else if (arg->mode != BLKmode)
4864 unsigned int parm_align;
4866 /* Argument is a scalar, not entirely passed in registers.
4867 (If part is passed in registers, arg->partial says how much
4868 and emit_push_insn will take care of putting it there.)
4870 Push it, and if its size is less than the
4871 amount of space allocated to it,
4872 also bump stack pointer by the additional space.
4873 Note that in C the default argument promotions
4874 will prevent such mismatches. */
4876 size = GET_MODE_SIZE (arg->mode);
4877 /* Compute how much space the push instruction will push.
4878 On many machines, pushing a byte will advance the stack
4879 pointer by a halfword. */
4880 #ifdef PUSH_ROUNDING
4881 size = PUSH_ROUNDING (size);
4885 /* Compute how much space the argument should get:
4886 round up to a multiple of the alignment for arguments. */
4887 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
4888 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4889 / (PARM_BOUNDARY / BITS_PER_UNIT))
4890 * (PARM_BOUNDARY / BITS_PER_UNIT));
4892 /* Compute the alignment of the pushed argument. */
4893 parm_align = arg->locate.boundary;
4894 if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward)
4896 int pad = used - size;
4899 unsigned int pad_align = (pad & -pad) * BITS_PER_UNIT;
4900 parm_align = MIN (parm_align, pad_align);
4904 /* This isn't already where we want it on the stack, so put it there.
4905 This can either be done with push or copy insns. */
4906 if (!emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
4907 parm_align, partial, reg, used - size, argblock,
4908 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4909 ARGS_SIZE_RTX (arg->locate.alignment_pad), true))
4910 sibcall_failure = 1;
4912 /* Unless this is a partially-in-register argument, the argument is now
4915 arg->value = arg->stack;
4919 /* BLKmode, at least partly to be pushed. */
4921 unsigned int parm_align;
4925 /* Pushing a nonscalar.
4926 If part is passed in registers, PARTIAL says how much
4927 and emit_push_insn will take care of putting it there. */
4929 /* Round its size up to a multiple
4930 of the allocation unit for arguments. */
4932 if (arg->locate.size.var != 0)
4935 size_rtx = ARGS_SIZE_RTX (arg->locate.size);
4939 /* PUSH_ROUNDING has no effect on us, because emit_push_insn
4940 for BLKmode is careful to avoid it. */
4941 excess = (arg->locate.size.constant
4942 - int_size_in_bytes (TREE_TYPE (pval))
4944 size_rtx = expand_expr (size_in_bytes (TREE_TYPE (pval)),
4945 NULL_RTX, TYPE_MODE (sizetype),
4949 parm_align = arg->locate.boundary;
4951 /* When an argument is padded down, the block is aligned to
4952 PARM_BOUNDARY, but the actual argument isn't. */
4953 if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward)
4955 if (arg->locate.size.var)
4956 parm_align = BITS_PER_UNIT;
4959 unsigned int excess_align = (excess & -excess) * BITS_PER_UNIT;
4960 parm_align = MIN (parm_align, excess_align);
4964 if ((flags & ECF_SIBCALL) && MEM_P (arg->value))
4966 /* emit_push_insn might not work properly if arg->value and
4967 argblock + arg->locate.offset areas overlap. */
4971 if (XEXP (x, 0) == crtl->args.internal_arg_pointer
4972 || (GET_CODE (XEXP (x, 0)) == PLUS
4973 && XEXP (XEXP (x, 0), 0) ==
4974 crtl->args.internal_arg_pointer
4975 && CONST_INT_P (XEXP (XEXP (x, 0), 1))))
4977 if (XEXP (x, 0) != crtl->args.internal_arg_pointer)
4978 i = INTVAL (XEXP (XEXP (x, 0), 1));
4980 /* arg.locate doesn't contain the pretend_args_size offset,
4981 it's part of argblock. Ensure we don't count it in I. */
4982 if (STACK_GROWS_DOWNWARD)
4983 i -= crtl->args.pretend_args_size;
4985 i += crtl->args.pretend_args_size;
4987 /* expand_call should ensure this. */
4988 gcc_assert (!arg->locate.offset.var
4989 && arg->locate.size.var == 0
4990 && CONST_INT_P (size_rtx));
4992 if (arg->locate.offset.constant > i)
4994 if (arg->locate.offset.constant < i + INTVAL (size_rtx))
4995 sibcall_failure = 1;
4997 else if (arg->locate.offset.constant < i)
4999 /* Use arg->locate.size.constant instead of size_rtx
5000 because we only care about the part of the argument
5002 if (i < (arg->locate.offset.constant
5003 + arg->locate.size.constant))
5004 sibcall_failure = 1;
5008 /* Even though they appear to be at the same location,
5009 if part of the outgoing argument is in registers,
5010 they aren't really at the same location. Check for
5011 this by making sure that the incoming size is the
5012 same as the outgoing size. */
5013 if (arg->locate.size.constant != INTVAL (size_rtx))
5014 sibcall_failure = 1;
5019 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
5020 parm_align, partial, reg, excess, argblock,
5021 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
5022 ARGS_SIZE_RTX (arg->locate.alignment_pad), false);
5024 /* Unless this is a partially-in-register argument, the argument is now
5027 ??? Unlike the case above, in which we want the actual
5028 address of the data, so that we can load it directly into a
5029 register, here we want the address of the stack slot, so that
5030 it's properly aligned for word-by-word copying or something
5031 like that. It's not clear that this is always correct. */
5033 arg->value = arg->stack_slot;
5036 if (arg->reg && GET_CODE (arg->reg) == PARALLEL)
5038 tree type = TREE_TYPE (arg->tree_value);
5040 = emit_group_load_into_temps (arg->reg, arg->value, type,
5041 int_size_in_bytes (type));
5044 /* Mark all slots this store used. */
5045 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)
5046 && argblock && ! variable_size && arg->stack)
5047 for (i = lower_bound; i < upper_bound; i++)
5048 stack_usage_map[i] = 1;
5050 /* Once we have pushed something, pops can't safely
5051 be deferred during the rest of the arguments. */
5054 /* Free any temporary slots made in processing this argument. */
5057 return sibcall_failure;
5060 /* Nonzero if we do not know how to pass TYPE solely in registers. */
5063 must_pass_in_stack_var_size (machine_mode mode ATTRIBUTE_UNUSED,
5069 /* If the type has variable size... */
5070 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
5073 /* If the type is marked as addressable (it is required
5074 to be constructed into the stack)... */
5075 if (TREE_ADDRESSABLE (type))
5081 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
5082 takes trailing padding of a structure into account. */
5083 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
5086 must_pass_in_stack_var_size_or_pad (machine_mode mode, const_tree type)
5091 /* If the type has variable size... */
5092 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
5095 /* If the type is marked as addressable (it is required
5096 to be constructed into the stack)... */
5097 if (TREE_ADDRESSABLE (type))
5100 /* If the padding and mode of the type is such that a copy into
5101 a register would put it into the wrong part of the register. */
5103 && int_size_in_bytes (type) % (PARM_BOUNDARY / BITS_PER_UNIT)
5104 && (FUNCTION_ARG_PADDING (mode, type)
5105 == (BYTES_BIG_ENDIAN ? upward : downward)))