lto-streamer-out.c (hash_tree): Use cl_optimization_hash.
[official-gcc.git] / gcc / calls.c
blob7f55aafa7346e841cd9130a9e8d4667a25b99837
1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
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
14 for more details.
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/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "rtl.h"
25 #include "tree.h"
26 #include "stor-layout.h"
27 #include "varasm.h"
28 #include "stringpool.h"
29 #include "attribs.h"
30 #include "predict.h"
31 #include "vec.h"
32 #include "hashtab.h"
33 #include "hash-set.h"
34 #include "machmode.h"
35 #include "hard-reg-set.h"
36 #include "input.h"
37 #include "function.h"
38 #include "basic-block.h"
39 #include "tree-ssa-alias.h"
40 #include "internal-fn.h"
41 #include "gimple-expr.h"
42 #include "is-a.h"
43 #include "gimple.h"
44 #include "flags.h"
45 #include "expr.h"
46 #include "insn-codes.h"
47 #include "optabs.h"
48 #include "libfuncs.h"
49 #include "regs.h"
50 #include "diagnostic-core.h"
51 #include "output.h"
52 #include "tm_p.h"
53 #include "timevar.h"
54 #include "sbitmap.h"
55 #include "bitmap.h"
56 #include "langhooks.h"
57 #include "target.h"
58 #include "hash-map.h"
59 #include "plugin-api.h"
60 #include "ipa-ref.h"
61 #include "cgraph.h"
62 #include "except.h"
63 #include "dbgcnt.h"
64 #include "rtl-iter.h"
65 #include "tree-chkp.h"
66 #include "rtl-chkp.h"
68 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
69 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
71 /* Data structure and subroutines used within expand_call. */
73 struct arg_data
75 /* Tree node for this argument. */
76 tree tree_value;
77 /* Mode for value; TYPE_MODE unless promoted. */
78 machine_mode mode;
79 /* Current RTL value for argument, or 0 if it isn't precomputed. */
80 rtx value;
81 /* Initially-compute RTL value for argument; only for const functions. */
82 rtx initial_value;
83 /* Register to pass this argument in, 0 if passed on stack, or an
84 PARALLEL if the arg is to be copied into multiple non-contiguous
85 registers. */
86 rtx reg;
87 /* Register to pass this argument in when generating tail call sequence.
88 This is not the same register as for normal calls on machines with
89 register windows. */
90 rtx tail_call_reg;
91 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
92 form for emit_group_move. */
93 rtx parallel_value;
94 /* If value is passed in neither reg nor stack, this field holds a number
95 of a special slot to be used. */
96 rtx special_slot;
97 /* For pointer bounds hold an index of parm bounds are bound to. -1 if
98 there is no such pointer. */
99 int pointer_arg;
100 /* If pointer_arg refers a structure, then pointer_offset holds an offset
101 of a pointer in this structure. */
102 int pointer_offset;
103 /* If REG was promoted from the actual mode of the argument expression,
104 indicates whether the promotion is sign- or zero-extended. */
105 int unsignedp;
106 /* Number of bytes to put in registers. 0 means put the whole arg
107 in registers. Also 0 if not passed in registers. */
108 int partial;
109 /* Nonzero if argument must be passed on stack.
110 Note that some arguments may be passed on the stack
111 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
112 pass_on_stack identifies arguments that *cannot* go in registers. */
113 int pass_on_stack;
114 /* Some fields packaged up for locate_and_pad_parm. */
115 struct locate_and_pad_arg_data locate;
116 /* Location on the stack at which parameter should be stored. The store
117 has already been done if STACK == VALUE. */
118 rtx stack;
119 /* Location on the stack of the start of this argument slot. This can
120 differ from STACK if this arg pads downward. This location is known
121 to be aligned to TARGET_FUNCTION_ARG_BOUNDARY. */
122 rtx stack_slot;
123 /* Place that this stack area has been saved, if needed. */
124 rtx save_area;
125 /* If an argument's alignment does not permit direct copying into registers,
126 copy in smaller-sized pieces into pseudos. These are stored in a
127 block pointed to by this field. The next field says how many
128 word-sized pseudos we made. */
129 rtx *aligned_regs;
130 int n_aligned_regs;
133 /* A vector of one char per byte of stack space. A byte if nonzero if
134 the corresponding stack location has been used.
135 This vector is used to prevent a function call within an argument from
136 clobbering any stack already set up. */
137 static char *stack_usage_map;
139 /* Size of STACK_USAGE_MAP. */
140 static int highest_outgoing_arg_in_use;
142 /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
143 stack location's tail call argument has been already stored into the stack.
144 This bitmap is used to prevent sibling call optimization if function tries
145 to use parent's incoming argument slots when they have been already
146 overwritten with tail call arguments. */
147 static sbitmap stored_args_map;
149 /* stack_arg_under_construction is nonzero when an argument may be
150 initialized with a constructor call (including a C function that
151 returns a BLKmode struct) and expand_call must take special action
152 to make sure the object being constructed does not overlap the
153 argument list for the constructor call. */
154 static int stack_arg_under_construction;
156 static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT,
157 HOST_WIDE_INT, rtx, rtx, int, rtx, int,
158 cumulative_args_t);
159 static void precompute_register_parameters (int, struct arg_data *, int *);
160 static void store_bounds (struct arg_data *, struct arg_data *);
161 static int store_one_arg (struct arg_data *, rtx, int, int, int);
162 static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
163 static int finalize_must_preallocate (int, int, struct arg_data *,
164 struct args_size *);
165 static void precompute_arguments (int, struct arg_data *);
166 static int compute_argument_block_size (int, struct args_size *, tree, tree, int);
167 static void initialize_argument_information (int, struct arg_data *,
168 struct args_size *, int,
169 tree, tree,
170 tree, tree, cumulative_args_t, int,
171 rtx *, int *, int *, int *,
172 bool *, bool);
173 static void compute_argument_addresses (struct arg_data *, rtx, int);
174 static rtx rtx_for_function_call (tree, tree);
175 static void load_register_parameters (struct arg_data *, int, rtx *, int,
176 int, int *);
177 static rtx emit_library_call_value_1 (int, rtx, rtx, enum libcall_type,
178 machine_mode, int, va_list);
179 static int special_function_p (const_tree, int);
180 static int check_sibcall_argument_overlap_1 (rtx);
181 static int check_sibcall_argument_overlap (rtx_insn *, struct arg_data *, int);
183 static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
184 unsigned int);
185 static tree split_complex_types (tree);
187 #ifdef REG_PARM_STACK_SPACE
188 static rtx save_fixed_argument_area (int, rtx, int *, int *);
189 static void restore_fixed_argument_area (rtx, rtx, int, int);
190 #endif
192 /* Force FUNEXP into a form suitable for the address of a CALL,
193 and return that as an rtx. Also load the static chain register
194 if FNDECL is a nested function.
196 CALL_FUSAGE points to a variable holding the prospective
197 CALL_INSN_FUNCTION_USAGE information. */
200 prepare_call_address (tree fndecl, rtx funexp, rtx static_chain_value,
201 rtx *call_fusage, int reg_parm_seen, int sibcallp)
203 /* Make a valid memory address and copy constants through pseudo-regs,
204 but not for a constant address if -fno-function-cse. */
205 if (GET_CODE (funexp) != SYMBOL_REF)
206 /* If we are using registers for parameters, force the
207 function address into a register now. */
208 funexp = ((reg_parm_seen
209 && targetm.small_register_classes_for_mode_p (FUNCTION_MODE))
210 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
211 : memory_address (FUNCTION_MODE, funexp));
212 else if (! sibcallp)
214 #ifndef NO_FUNCTION_CSE
215 if (optimize && ! flag_no_function_cse)
216 funexp = force_reg (Pmode, funexp);
217 #endif
220 if (static_chain_value != 0)
222 rtx chain;
224 gcc_assert (fndecl);
225 chain = targetm.calls.static_chain (fndecl, false);
226 static_chain_value = convert_memory_address (Pmode, static_chain_value);
228 emit_move_insn (chain, static_chain_value);
229 if (REG_P (chain))
230 use_reg (call_fusage, chain);
233 return funexp;
236 /* Generate instructions to call function FUNEXP,
237 and optionally pop the results.
238 The CALL_INSN is the first insn generated.
240 FNDECL is the declaration node of the function. This is given to the
241 hook TARGET_RETURN_POPS_ARGS to determine whether this function pops
242 its own args.
244 FUNTYPE is the data type of the function. This is given to the hook
245 TARGET_RETURN_POPS_ARGS to determine whether this function pops its
246 own args. We used to allow an identifier for library functions, but
247 that doesn't work when the return type is an aggregate type and the
248 calling convention says that the pointer to this aggregate is to be
249 popped by the callee.
251 STACK_SIZE is the number of bytes of arguments on the stack,
252 ROUNDED_STACK_SIZE is that number rounded up to
253 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
254 both to put into the call insn and to generate explicit popping
255 code if necessary.
257 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
258 It is zero if this call doesn't want a structure value.
260 NEXT_ARG_REG is the rtx that results from executing
261 targetm.calls.function_arg (&args_so_far, VOIDmode, void_type_node, true)
262 just after all the args have had their registers assigned.
263 This could be whatever you like, but normally it is the first
264 arg-register beyond those used for args in this call,
265 or 0 if all the arg-registers are used in this call.
266 It is passed on to `gen_call' so you can put this info in the call insn.
268 VALREG is a hard register in which a value is returned,
269 or 0 if the call does not return a value.
271 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
272 the args to this call were processed.
273 We restore `inhibit_defer_pop' to that value.
275 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
276 denote registers used by the called function. */
278 static void
279 emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNUSED,
280 tree funtype ATTRIBUTE_UNUSED,
281 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED,
282 HOST_WIDE_INT rounded_stack_size,
283 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED,
284 rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg,
285 int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags,
286 cumulative_args_t args_so_far ATTRIBUTE_UNUSED)
288 rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
289 rtx_insn *call_insn;
290 rtx call, funmem;
291 int already_popped = 0;
292 HOST_WIDE_INT n_popped
293 = targetm.calls.return_pops_args (fndecl, funtype, stack_size);
295 #ifdef CALL_POPS_ARGS
296 n_popped += CALL_POPS_ARGS (*get_cumulative_args (args_so_far));
297 #endif
299 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
300 and we don't want to load it into a register as an optimization,
301 because prepare_call_address already did it if it should be done. */
302 if (GET_CODE (funexp) != SYMBOL_REF)
303 funexp = memory_address (FUNCTION_MODE, funexp);
305 funmem = gen_rtx_MEM (FUNCTION_MODE, funexp);
306 if (fndecl && TREE_CODE (fndecl) == FUNCTION_DECL)
308 tree t = fndecl;
310 /* Although a built-in FUNCTION_DECL and its non-__builtin
311 counterpart compare equal and get a shared mem_attrs, they
312 produce different dump output in compare-debug compilations,
313 if an entry gets garbage collected in one compilation, then
314 adds a different (but equivalent) entry, while the other
315 doesn't run the garbage collector at the same spot and then
316 shares the mem_attr with the equivalent entry. */
317 if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL)
319 tree t2 = builtin_decl_explicit (DECL_FUNCTION_CODE (t));
320 if (t2)
321 t = t2;
324 set_mem_expr (funmem, t);
326 else if (fntree)
327 set_mem_expr (funmem, build_simple_mem_ref (CALL_EXPR_FN (fntree)));
329 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
330 if ((ecf_flags & ECF_SIBCALL)
331 && HAVE_sibcall_pop && HAVE_sibcall_value_pop
332 && (n_popped > 0 || stack_size == 0))
334 rtx n_pop = GEN_INT (n_popped);
335 rtx pat;
337 /* If this subroutine pops its own args, record that in the call insn
338 if possible, for the sake of frame pointer elimination. */
340 if (valreg)
341 pat = GEN_SIBCALL_VALUE_POP (valreg, funmem, rounded_stack_size_rtx,
342 next_arg_reg, n_pop);
343 else
344 pat = GEN_SIBCALL_POP (funmem, rounded_stack_size_rtx, next_arg_reg,
345 n_pop);
347 emit_call_insn (pat);
348 already_popped = 1;
350 else
351 #endif
353 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
354 /* If the target has "call" or "call_value" insns, then prefer them
355 if no arguments are actually popped. If the target does not have
356 "call" or "call_value" insns, then we must use the popping versions
357 even if the call has no arguments to pop. */
358 #if defined (HAVE_call) && defined (HAVE_call_value)
359 if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
360 && n_popped > 0)
361 #else
362 if (HAVE_call_pop && HAVE_call_value_pop)
363 #endif
365 rtx n_pop = GEN_INT (n_popped);
366 rtx pat;
368 /* If this subroutine pops its own args, record that in the call insn
369 if possible, for the sake of frame pointer elimination. */
371 if (valreg)
372 pat = GEN_CALL_VALUE_POP (valreg, funmem, rounded_stack_size_rtx,
373 next_arg_reg, n_pop);
374 else
375 pat = GEN_CALL_POP (funmem, rounded_stack_size_rtx, next_arg_reg,
376 n_pop);
378 emit_call_insn (pat);
379 already_popped = 1;
381 else
382 #endif
384 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
385 if ((ecf_flags & ECF_SIBCALL)
386 && HAVE_sibcall && HAVE_sibcall_value)
388 if (valreg)
389 emit_call_insn (GEN_SIBCALL_VALUE (valreg, funmem,
390 rounded_stack_size_rtx,
391 next_arg_reg, NULL_RTX));
392 else
393 emit_call_insn (GEN_SIBCALL (funmem, rounded_stack_size_rtx,
394 next_arg_reg,
395 GEN_INT (struct_value_size)));
397 else
398 #endif
400 #if defined (HAVE_call) && defined (HAVE_call_value)
401 if (HAVE_call && HAVE_call_value)
403 if (valreg)
404 emit_call_insn (GEN_CALL_VALUE (valreg, funmem, rounded_stack_size_rtx,
405 next_arg_reg, NULL_RTX));
406 else
407 emit_call_insn (GEN_CALL (funmem, rounded_stack_size_rtx, next_arg_reg,
408 GEN_INT (struct_value_size)));
410 else
411 #endif
412 gcc_unreachable ();
414 /* Find the call we just emitted. */
415 call_insn = last_call_insn ();
417 /* Some target create a fresh MEM instead of reusing the one provided
418 above. Set its MEM_EXPR. */
419 call = get_call_rtx_from (call_insn);
420 if (call
421 && MEM_EXPR (XEXP (call, 0)) == NULL_TREE
422 && MEM_EXPR (funmem) != NULL_TREE)
423 set_mem_expr (XEXP (call, 0), MEM_EXPR (funmem));
425 /* Mark instrumented calls. */
426 if (call && fntree)
427 CALL_EXPR_WITH_BOUNDS_P (call) = CALL_WITH_BOUNDS_P (fntree);
429 /* Put the register usage information there. */
430 add_function_usage_to (call_insn, call_fusage);
432 /* If this is a const call, then set the insn's unchanging bit. */
433 if (ecf_flags & ECF_CONST)
434 RTL_CONST_CALL_P (call_insn) = 1;
436 /* If this is a pure call, then set the insn's unchanging bit. */
437 if (ecf_flags & ECF_PURE)
438 RTL_PURE_CALL_P (call_insn) = 1;
440 /* If this is a const call, then set the insn's unchanging bit. */
441 if (ecf_flags & ECF_LOOPING_CONST_OR_PURE)
442 RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn) = 1;
444 /* Create a nothrow REG_EH_REGION note, if needed. */
445 make_reg_eh_region_note (call_insn, ecf_flags, 0);
447 if (ecf_flags & ECF_NORETURN)
448 add_reg_note (call_insn, REG_NORETURN, const0_rtx);
450 if (ecf_flags & ECF_RETURNS_TWICE)
452 add_reg_note (call_insn, REG_SETJMP, const0_rtx);
453 cfun->calls_setjmp = 1;
456 SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
458 /* Restore this now, so that we do defer pops for this call's args
459 if the context of the call as a whole permits. */
460 inhibit_defer_pop = old_inhibit_defer_pop;
462 if (n_popped > 0)
464 if (!already_popped)
465 CALL_INSN_FUNCTION_USAGE (call_insn)
466 = gen_rtx_EXPR_LIST (VOIDmode,
467 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
468 CALL_INSN_FUNCTION_USAGE (call_insn));
469 rounded_stack_size -= n_popped;
470 rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
471 stack_pointer_delta -= n_popped;
473 add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
475 /* If popup is needed, stack realign must use DRAP */
476 if (SUPPORTS_STACK_ALIGNMENT)
477 crtl->need_drap = true;
479 /* For noreturn calls when not accumulating outgoing args force
480 REG_ARGS_SIZE note to prevent crossjumping of calls with different
481 args sizes. */
482 else if (!ACCUMULATE_OUTGOING_ARGS && (ecf_flags & ECF_NORETURN) != 0)
483 add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
485 if (!ACCUMULATE_OUTGOING_ARGS)
487 /* If returning from the subroutine does not automatically pop the args,
488 we need an instruction to pop them sooner or later.
489 Perhaps do it now; perhaps just record how much space to pop later.
491 If returning from the subroutine does pop the args, indicate that the
492 stack pointer will be changed. */
494 if (rounded_stack_size != 0)
496 if (ecf_flags & ECF_NORETURN)
497 /* Just pretend we did the pop. */
498 stack_pointer_delta -= rounded_stack_size;
499 else if (flag_defer_pop && inhibit_defer_pop == 0
500 && ! (ecf_flags & (ECF_CONST | ECF_PURE)))
501 pending_stack_adjust += rounded_stack_size;
502 else
503 adjust_stack (rounded_stack_size_rtx);
506 /* When we accumulate outgoing args, we must avoid any stack manipulations.
507 Restore the stack pointer to its original value now. Usually
508 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
509 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
510 popping variants of functions exist as well.
512 ??? We may optimize similar to defer_pop above, but it is
513 probably not worthwhile.
515 ??? It will be worthwhile to enable combine_stack_adjustments even for
516 such machines. */
517 else if (n_popped)
518 anti_adjust_stack (GEN_INT (n_popped));
521 /* Determine if the function identified by NAME and FNDECL is one with
522 special properties we wish to know about.
524 For example, if the function might return more than one time (setjmp), then
525 set RETURNS_TWICE to a nonzero value.
527 Similarly set NORETURN if the function is in the longjmp family.
529 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
530 space from the stack such as alloca. */
532 static int
533 special_function_p (const_tree fndecl, int flags)
535 tree name_decl = DECL_NAME (fndecl);
537 /* For instrumentation clones we want to derive flags
538 from the original name. */
539 if (cgraph_node::get (fndecl)
540 && cgraph_node::get (fndecl)->instrumentation_clone)
541 name_decl = DECL_NAME (cgraph_node::get (fndecl)->orig_decl);
543 if (fndecl && name_decl
544 && IDENTIFIER_LENGTH (name_decl) <= 17
545 /* Exclude functions not at the file scope, or not `extern',
546 since they are not the magic functions we would otherwise
547 think they are.
548 FIXME: this should be handled with attributes, not with this
549 hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
550 because you can declare fork() inside a function if you
551 wish. */
552 && (DECL_CONTEXT (fndecl) == NULL_TREE
553 || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL)
554 && TREE_PUBLIC (fndecl))
556 const char *name = IDENTIFIER_POINTER (name_decl);
557 const char *tname = name;
559 /* We assume that alloca will always be called by name. It
560 makes no sense to pass it as a pointer-to-function to
561 anything that does not understand its behavior. */
562 if (((IDENTIFIER_LENGTH (name_decl) == 6
563 && name[0] == 'a'
564 && ! strcmp (name, "alloca"))
565 || (IDENTIFIER_LENGTH (name_decl) == 16
566 && name[0] == '_'
567 && ! strcmp (name, "__builtin_alloca"))))
568 flags |= ECF_MAY_BE_ALLOCA;
570 /* Disregard prefix _, __, __x or __builtin_. */
571 if (name[0] == '_')
573 if (name[1] == '_'
574 && name[2] == 'b'
575 && !strncmp (name + 3, "uiltin_", 7))
576 tname += 10;
577 else if (name[1] == '_' && name[2] == 'x')
578 tname += 3;
579 else if (name[1] == '_')
580 tname += 2;
581 else
582 tname += 1;
585 if (tname[0] == 's')
587 if ((tname[1] == 'e'
588 && (! strcmp (tname, "setjmp")
589 || ! strcmp (tname, "setjmp_syscall")))
590 || (tname[1] == 'i'
591 && ! strcmp (tname, "sigsetjmp"))
592 || (tname[1] == 'a'
593 && ! strcmp (tname, "savectx")))
594 flags |= ECF_RETURNS_TWICE | ECF_LEAF;
596 if (tname[1] == 'i'
597 && ! strcmp (tname, "siglongjmp"))
598 flags |= ECF_NORETURN;
600 else if ((tname[0] == 'q' && tname[1] == 's'
601 && ! strcmp (tname, "qsetjmp"))
602 || (tname[0] == 'v' && tname[1] == 'f'
603 && ! strcmp (tname, "vfork"))
604 || (tname[0] == 'g' && tname[1] == 'e'
605 && !strcmp (tname, "getcontext")))
606 flags |= ECF_RETURNS_TWICE | ECF_LEAF;
608 else if (tname[0] == 'l' && tname[1] == 'o'
609 && ! strcmp (tname, "longjmp"))
610 flags |= ECF_NORETURN;
613 return flags;
616 /* Similar to special_function_p; return a set of ERF_ flags for the
617 function FNDECL. */
618 static int
619 decl_return_flags (tree fndecl)
621 tree attr;
622 tree type = TREE_TYPE (fndecl);
623 if (!type)
624 return 0;
626 attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
627 if (!attr)
628 return 0;
630 attr = TREE_VALUE (TREE_VALUE (attr));
631 if (!attr || TREE_STRING_LENGTH (attr) < 1)
632 return 0;
634 switch (TREE_STRING_POINTER (attr)[0])
636 case '1':
637 case '2':
638 case '3':
639 case '4':
640 return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1');
642 case 'm':
643 return ERF_NOALIAS;
645 case '.':
646 default:
647 return 0;
651 /* Return nonzero when FNDECL represents a call to setjmp. */
654 setjmp_call_p (const_tree fndecl)
656 if (DECL_IS_RETURNS_TWICE (fndecl))
657 return ECF_RETURNS_TWICE;
658 return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE;
662 /* Return true if STMT is an alloca call. */
664 bool
665 gimple_alloca_call_p (const_gimple stmt)
667 tree fndecl;
669 if (!is_gimple_call (stmt))
670 return false;
672 fndecl = gimple_call_fndecl (stmt);
673 if (fndecl && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA))
674 return true;
676 return false;
679 /* Return true when exp contains alloca call. */
681 bool
682 alloca_call_p (const_tree exp)
684 tree fndecl;
685 if (TREE_CODE (exp) == CALL_EXPR
686 && (fndecl = get_callee_fndecl (exp))
687 && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA))
688 return true;
689 return false;
692 /* Return TRUE if FNDECL is either a TM builtin or a TM cloned
693 function. Return FALSE otherwise. */
695 static bool
696 is_tm_builtin (const_tree fndecl)
698 if (fndecl == NULL)
699 return false;
701 if (decl_is_tm_clone (fndecl))
702 return true;
704 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
706 switch (DECL_FUNCTION_CODE (fndecl))
708 case BUILT_IN_TM_COMMIT:
709 case BUILT_IN_TM_COMMIT_EH:
710 case BUILT_IN_TM_ABORT:
711 case BUILT_IN_TM_IRREVOCABLE:
712 case BUILT_IN_TM_GETTMCLONE_IRR:
713 case BUILT_IN_TM_MEMCPY:
714 case BUILT_IN_TM_MEMMOVE:
715 case BUILT_IN_TM_MEMSET:
716 CASE_BUILT_IN_TM_STORE (1):
717 CASE_BUILT_IN_TM_STORE (2):
718 CASE_BUILT_IN_TM_STORE (4):
719 CASE_BUILT_IN_TM_STORE (8):
720 CASE_BUILT_IN_TM_STORE (FLOAT):
721 CASE_BUILT_IN_TM_STORE (DOUBLE):
722 CASE_BUILT_IN_TM_STORE (LDOUBLE):
723 CASE_BUILT_IN_TM_STORE (M64):
724 CASE_BUILT_IN_TM_STORE (M128):
725 CASE_BUILT_IN_TM_STORE (M256):
726 CASE_BUILT_IN_TM_LOAD (1):
727 CASE_BUILT_IN_TM_LOAD (2):
728 CASE_BUILT_IN_TM_LOAD (4):
729 CASE_BUILT_IN_TM_LOAD (8):
730 CASE_BUILT_IN_TM_LOAD (FLOAT):
731 CASE_BUILT_IN_TM_LOAD (DOUBLE):
732 CASE_BUILT_IN_TM_LOAD (LDOUBLE):
733 CASE_BUILT_IN_TM_LOAD (M64):
734 CASE_BUILT_IN_TM_LOAD (M128):
735 CASE_BUILT_IN_TM_LOAD (M256):
736 case BUILT_IN_TM_LOG:
737 case BUILT_IN_TM_LOG_1:
738 case BUILT_IN_TM_LOG_2:
739 case BUILT_IN_TM_LOG_4:
740 case BUILT_IN_TM_LOG_8:
741 case BUILT_IN_TM_LOG_FLOAT:
742 case BUILT_IN_TM_LOG_DOUBLE:
743 case BUILT_IN_TM_LOG_LDOUBLE:
744 case BUILT_IN_TM_LOG_M64:
745 case BUILT_IN_TM_LOG_M128:
746 case BUILT_IN_TM_LOG_M256:
747 return true;
748 default:
749 break;
752 return false;
755 /* Detect flags (function attributes) from the function decl or type node. */
758 flags_from_decl_or_type (const_tree exp)
760 int flags = 0;
762 if (DECL_P (exp))
764 /* The function exp may have the `malloc' attribute. */
765 if (DECL_IS_MALLOC (exp))
766 flags |= ECF_MALLOC;
768 /* The function exp may have the `returns_twice' attribute. */
769 if (DECL_IS_RETURNS_TWICE (exp))
770 flags |= ECF_RETURNS_TWICE;
772 /* Process the pure and const attributes. */
773 if (TREE_READONLY (exp))
774 flags |= ECF_CONST;
775 if (DECL_PURE_P (exp))
776 flags |= ECF_PURE;
777 if (DECL_LOOPING_CONST_OR_PURE_P (exp))
778 flags |= ECF_LOOPING_CONST_OR_PURE;
780 if (DECL_IS_NOVOPS (exp))
781 flags |= ECF_NOVOPS;
782 if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp)))
783 flags |= ECF_LEAF;
785 if (TREE_NOTHROW (exp))
786 flags |= ECF_NOTHROW;
788 if (flag_tm)
790 if (is_tm_builtin (exp))
791 flags |= ECF_TM_BUILTIN;
792 else if ((flags & (ECF_CONST|ECF_NOVOPS)) != 0
793 || lookup_attribute ("transaction_pure",
794 TYPE_ATTRIBUTES (TREE_TYPE (exp))))
795 flags |= ECF_TM_PURE;
798 flags = special_function_p (exp, flags);
800 else if (TYPE_P (exp))
802 if (TYPE_READONLY (exp))
803 flags |= ECF_CONST;
805 if (flag_tm
806 && ((flags & ECF_CONST) != 0
807 || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp))))
808 flags |= ECF_TM_PURE;
810 else
811 gcc_unreachable ();
813 if (TREE_THIS_VOLATILE (exp))
815 flags |= ECF_NORETURN;
816 if (flags & (ECF_CONST|ECF_PURE))
817 flags |= ECF_LOOPING_CONST_OR_PURE;
820 return flags;
823 /* Detect flags from a CALL_EXPR. */
826 call_expr_flags (const_tree t)
828 int flags;
829 tree decl = get_callee_fndecl (t);
831 if (decl)
832 flags = flags_from_decl_or_type (decl);
833 else
835 t = TREE_TYPE (CALL_EXPR_FN (t));
836 if (t && TREE_CODE (t) == POINTER_TYPE)
837 flags = flags_from_decl_or_type (TREE_TYPE (t));
838 else
839 flags = 0;
842 return flags;
845 /* Precompute all register parameters as described by ARGS, storing values
846 into fields within the ARGS array.
848 NUM_ACTUALS indicates the total number elements in the ARGS array.
850 Set REG_PARM_SEEN if we encounter a register parameter. */
852 static void
853 precompute_register_parameters (int num_actuals, struct arg_data *args,
854 int *reg_parm_seen)
856 int i;
858 *reg_parm_seen = 0;
860 for (i = 0; i < num_actuals; i++)
861 if (args[i].reg != 0 && ! args[i].pass_on_stack)
863 *reg_parm_seen = 1;
865 if (args[i].value == 0)
867 push_temp_slots ();
868 args[i].value = expand_normal (args[i].tree_value);
869 preserve_temp_slots (args[i].value);
870 pop_temp_slots ();
873 /* If we are to promote the function arg to a wider mode,
874 do it now. */
876 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
877 args[i].value
878 = convert_modes (args[i].mode,
879 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
880 args[i].value, args[i].unsignedp);
882 /* If the value is a non-legitimate constant, force it into a
883 pseudo now. TLS symbols sometimes need a call to resolve. */
884 if (CONSTANT_P (args[i].value)
885 && !targetm.legitimate_constant_p (args[i].mode, args[i].value))
886 args[i].value = force_reg (args[i].mode, args[i].value);
888 /* If we're going to have to load the value by parts, pull the
889 parts into pseudos. The part extraction process can involve
890 non-trivial computation. */
891 if (GET_CODE (args[i].reg) == PARALLEL)
893 tree type = TREE_TYPE (args[i].tree_value);
894 args[i].parallel_value
895 = emit_group_load_into_temps (args[i].reg, args[i].value,
896 type, int_size_in_bytes (type));
899 /* If the value is expensive, and we are inside an appropriately
900 short loop, put the value into a pseudo and then put the pseudo
901 into the hard reg.
903 For small register classes, also do this if this call uses
904 register parameters. This is to avoid reload conflicts while
905 loading the parameters registers. */
907 else if ((! (REG_P (args[i].value)
908 || (GET_CODE (args[i].value) == SUBREG
909 && REG_P (SUBREG_REG (args[i].value)))))
910 && args[i].mode != BLKmode
911 && set_src_cost (args[i].value, optimize_insn_for_speed_p ())
912 > COSTS_N_INSNS (1)
913 && ((*reg_parm_seen
914 && targetm.small_register_classes_for_mode_p (args[i].mode))
915 || optimize))
916 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
920 #ifdef REG_PARM_STACK_SPACE
922 /* The argument list is the property of the called routine and it
923 may clobber it. If the fixed area has been used for previous
924 parameters, we must save and restore it. */
926 static rtx
927 save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
929 int low;
930 int high;
932 /* Compute the boundary of the area that needs to be saved, if any. */
933 high = reg_parm_stack_space;
934 #ifdef ARGS_GROW_DOWNWARD
935 high += 1;
936 #endif
937 if (high > highest_outgoing_arg_in_use)
938 high = highest_outgoing_arg_in_use;
940 for (low = 0; low < high; low++)
941 if (stack_usage_map[low] != 0)
943 int num_to_save;
944 machine_mode save_mode;
945 int delta;
946 rtx addr;
947 rtx stack_area;
948 rtx save_area;
950 while (stack_usage_map[--high] == 0)
953 *low_to_save = low;
954 *high_to_save = high;
956 num_to_save = high - low + 1;
957 save_mode = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
959 /* If we don't have the required alignment, must do this
960 in BLKmode. */
961 if ((low & (MIN (GET_MODE_SIZE (save_mode),
962 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
963 save_mode = BLKmode;
965 #ifdef ARGS_GROW_DOWNWARD
966 delta = -high;
967 #else
968 delta = low;
969 #endif
970 addr = plus_constant (Pmode, argblock, delta);
971 stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr));
973 set_mem_align (stack_area, PARM_BOUNDARY);
974 if (save_mode == BLKmode)
976 save_area = assign_stack_temp (BLKmode, num_to_save);
977 emit_block_move (validize_mem (save_area), stack_area,
978 GEN_INT (num_to_save), BLOCK_OP_CALL_PARM);
980 else
982 save_area = gen_reg_rtx (save_mode);
983 emit_move_insn (save_area, stack_area);
986 return save_area;
989 return NULL_RTX;
992 static void
993 restore_fixed_argument_area (rtx save_area, rtx argblock, int high_to_save, int low_to_save)
995 machine_mode save_mode = GET_MODE (save_area);
996 int delta;
997 rtx addr, stack_area;
999 #ifdef ARGS_GROW_DOWNWARD
1000 delta = -high_to_save;
1001 #else
1002 delta = low_to_save;
1003 #endif
1004 addr = plus_constant (Pmode, argblock, delta);
1005 stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr));
1006 set_mem_align (stack_area, PARM_BOUNDARY);
1008 if (save_mode != BLKmode)
1009 emit_move_insn (stack_area, save_area);
1010 else
1011 emit_block_move (stack_area, validize_mem (save_area),
1012 GEN_INT (high_to_save - low_to_save + 1),
1013 BLOCK_OP_CALL_PARM);
1015 #endif /* REG_PARM_STACK_SPACE */
1017 /* If any elements in ARGS refer to parameters that are to be passed in
1018 registers, but not in memory, and whose alignment does not permit a
1019 direct copy into registers. Copy the values into a group of pseudos
1020 which we will later copy into the appropriate hard registers.
1022 Pseudos for each unaligned argument will be stored into the array
1023 args[argnum].aligned_regs. The caller is responsible for deallocating
1024 the aligned_regs array if it is nonzero. */
1026 static void
1027 store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals)
1029 int i, j;
1031 for (i = 0; i < num_actuals; i++)
1032 if (args[i].reg != 0 && ! args[i].pass_on_stack
1033 && GET_CODE (args[i].reg) != PARALLEL
1034 && args[i].mode == BLKmode
1035 && MEM_P (args[i].value)
1036 && (MEM_ALIGN (args[i].value)
1037 < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
1039 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1040 int endian_correction = 0;
1042 if (args[i].partial)
1044 gcc_assert (args[i].partial % UNITS_PER_WORD == 0);
1045 args[i].n_aligned_regs = args[i].partial / UNITS_PER_WORD;
1047 else
1049 args[i].n_aligned_regs
1050 = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1053 args[i].aligned_regs = XNEWVEC (rtx, args[i].n_aligned_regs);
1055 /* Structures smaller than a word are normally aligned to the
1056 least significant byte. On a BYTES_BIG_ENDIAN machine,
1057 this means we must skip the empty high order bytes when
1058 calculating the bit offset. */
1059 if (bytes < UNITS_PER_WORD
1060 #ifdef BLOCK_REG_PADDING
1061 && (BLOCK_REG_PADDING (args[i].mode,
1062 TREE_TYPE (args[i].tree_value), 1)
1063 == downward)
1064 #else
1065 && BYTES_BIG_ENDIAN
1066 #endif
1068 endian_correction = BITS_PER_WORD - bytes * BITS_PER_UNIT;
1070 for (j = 0; j < args[i].n_aligned_regs; j++)
1072 rtx reg = gen_reg_rtx (word_mode);
1073 rtx word = operand_subword_force (args[i].value, j, BLKmode);
1074 int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
1076 args[i].aligned_regs[j] = reg;
1077 word = extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
1078 word_mode, word_mode);
1080 /* There is no need to restrict this code to loading items
1081 in TYPE_ALIGN sized hunks. The bitfield instructions can
1082 load up entire word sized registers efficiently.
1084 ??? This may not be needed anymore.
1085 We use to emit a clobber here but that doesn't let later
1086 passes optimize the instructions we emit. By storing 0 into
1087 the register later passes know the first AND to zero out the
1088 bitfield being set in the register is unnecessary. The store
1089 of 0 will be deleted as will at least the first AND. */
1091 emit_move_insn (reg, const0_rtx);
1093 bytes -= bitsize / BITS_PER_UNIT;
1094 store_bit_field (reg, bitsize, endian_correction, 0, 0,
1095 word_mode, word);
1100 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
1101 CALL_EXPR EXP.
1103 NUM_ACTUALS is the total number of parameters.
1105 N_NAMED_ARGS is the total number of named arguments.
1107 STRUCT_VALUE_ADDR_VALUE is the implicit argument for a struct return
1108 value, or null.
1110 FNDECL is the tree code for the target of this call (if known)
1112 ARGS_SO_FAR holds state needed by the target to know where to place
1113 the next argument.
1115 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
1116 for arguments which are passed in registers.
1118 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
1119 and may be modified by this routine.
1121 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
1122 flags which may may be modified by this routine.
1124 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
1125 that requires allocation of stack space.
1127 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
1128 the thunked-to function. */
1130 static void
1131 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
1132 struct arg_data *args,
1133 struct args_size *args_size,
1134 int n_named_args ATTRIBUTE_UNUSED,
1135 tree exp, tree struct_value_addr_value,
1136 tree fndecl, tree fntype,
1137 cumulative_args_t args_so_far,
1138 int reg_parm_stack_space,
1139 rtx *old_stack_level, int *old_pending_adj,
1140 int *must_preallocate, int *ecf_flags,
1141 bool *may_tailcall, bool call_from_thunk_p)
1143 CUMULATIVE_ARGS *args_so_far_pnt = get_cumulative_args (args_so_far);
1144 location_t loc = EXPR_LOCATION (exp);
1146 /* Count arg position in order args appear. */
1147 int argpos;
1149 int i;
1151 args_size->constant = 0;
1152 args_size->var = 0;
1154 bitmap_obstack_initialize (NULL);
1156 /* In this loop, we consider args in the order they are written.
1157 We fill up ARGS from the back. */
1159 i = num_actuals - 1;
1161 int j = i, ptr_arg = -1;
1162 call_expr_arg_iterator iter;
1163 tree arg;
1164 bitmap slots = NULL;
1166 if (struct_value_addr_value)
1168 args[j].tree_value = struct_value_addr_value;
1169 j--;
1171 /* If we pass structure address then we need to
1172 create bounds for it. Since created bounds is
1173 a call statement, we expand it right here to avoid
1174 fixing all other places where it may be expanded. */
1175 if (CALL_WITH_BOUNDS_P (exp))
1177 args[j].value = gen_reg_rtx (targetm.chkp_bound_mode ());
1178 args[j].tree_value
1179 = chkp_make_bounds_for_struct_addr (struct_value_addr_value);
1180 expand_expr_real (args[j].tree_value, args[j].value, VOIDmode,
1181 EXPAND_NORMAL, 0, false);
1182 args[j].pointer_arg = j + 1;
1183 j--;
1186 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
1188 tree argtype = TREE_TYPE (arg);
1190 /* Remember last param with pointer and associate it
1191 with following pointer bounds. */
1192 if (CALL_WITH_BOUNDS_P (exp)
1193 && chkp_type_has_pointer (argtype))
1195 if (slots)
1196 BITMAP_FREE (slots);
1197 ptr_arg = j;
1198 if (!BOUNDED_TYPE_P (argtype))
1200 slots = BITMAP_ALLOC (NULL);
1201 chkp_find_bound_slots (argtype, slots);
1204 else if (POINTER_BOUNDS_TYPE_P (argtype))
1206 /* We expect bounds in instrumented calls only.
1207 Otherwise it is a sign we lost flag due to some optimization
1208 and may emit call args incorrectly. */
1209 gcc_assert (CALL_WITH_BOUNDS_P (exp));
1211 /* For structures look for the next available pointer. */
1212 if (ptr_arg != -1 && slots)
1214 unsigned bnd_no = bitmap_first_set_bit (slots);
1215 args[j].pointer_offset =
1216 bnd_no * POINTER_SIZE / BITS_PER_UNIT;
1218 bitmap_clear_bit (slots, bnd_no);
1220 /* Check we have no more pointers in the structure. */
1221 if (bitmap_empty_p (slots))
1222 BITMAP_FREE (slots);
1224 args[j].pointer_arg = ptr_arg;
1226 /* Check we covered all pointers in the previous
1227 non bounds arg. */
1228 if (!slots)
1229 ptr_arg = -1;
1231 else
1232 ptr_arg = -1;
1234 if (targetm.calls.split_complex_arg
1235 && argtype
1236 && TREE_CODE (argtype) == COMPLEX_TYPE
1237 && targetm.calls.split_complex_arg (argtype))
1239 tree subtype = TREE_TYPE (argtype);
1240 args[j].tree_value = build1 (REALPART_EXPR, subtype, arg);
1241 j--;
1242 args[j].tree_value = build1 (IMAGPART_EXPR, subtype, arg);
1244 else
1245 args[j].tree_value = arg;
1246 j--;
1249 if (slots)
1250 BITMAP_FREE (slots);
1253 bitmap_obstack_release (NULL);
1255 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1256 for (argpos = 0; argpos < num_actuals; i--, argpos++)
1258 tree type = TREE_TYPE (args[i].tree_value);
1259 int unsignedp;
1260 machine_mode mode;
1262 /* Replace erroneous argument with constant zero. */
1263 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
1264 args[i].tree_value = integer_zero_node, type = integer_type_node;
1266 /* If TYPE is a transparent union or record, pass things the way
1267 we would pass the first field of the union or record. We have
1268 already verified that the modes are the same. */
1269 if ((TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == RECORD_TYPE)
1270 && TYPE_TRANSPARENT_AGGR (type))
1271 type = TREE_TYPE (first_field (type));
1273 /* Decide where to pass this arg.
1275 args[i].reg is nonzero if all or part is passed in registers.
1277 args[i].partial is nonzero if part but not all is passed in registers,
1278 and the exact value says how many bytes are passed in registers.
1280 args[i].pass_on_stack is nonzero if the argument must at least be
1281 computed on the stack. It may then be loaded back into registers
1282 if args[i].reg is nonzero.
1284 These decisions are driven by the FUNCTION_... macros and must agree
1285 with those made by function.c. */
1287 /* See if this argument should be passed by invisible reference. */
1288 if (pass_by_reference (args_so_far_pnt, TYPE_MODE (type),
1289 type, argpos < n_named_args))
1291 bool callee_copies;
1292 tree base = NULL_TREE;
1294 callee_copies
1295 = reference_callee_copied (args_so_far_pnt, TYPE_MODE (type),
1296 type, argpos < n_named_args);
1298 /* If we're compiling a thunk, pass through invisible references
1299 instead of making a copy. */
1300 if (call_from_thunk_p
1301 || (callee_copies
1302 && !TREE_ADDRESSABLE (type)
1303 && (base = get_base_address (args[i].tree_value))
1304 && TREE_CODE (base) != SSA_NAME
1305 && (!DECL_P (base) || MEM_P (DECL_RTL (base)))))
1307 /* Argument setup code may have copied the value to register. We
1308 revert that optimization now because the tail call code must
1309 use the original location. */
1310 if (TREE_CODE (args[i].tree_value) == PARM_DECL
1311 && !MEM_P (DECL_RTL (args[i].tree_value))
1312 && DECL_INCOMING_RTL (args[i].tree_value)
1313 && MEM_P (DECL_INCOMING_RTL (args[i].tree_value)))
1314 set_decl_rtl (args[i].tree_value,
1315 DECL_INCOMING_RTL (args[i].tree_value));
1317 mark_addressable (args[i].tree_value);
1319 /* We can't use sibcalls if a callee-copied argument is
1320 stored in the current function's frame. */
1321 if (!call_from_thunk_p && DECL_P (base) && !TREE_STATIC (base))
1322 *may_tailcall = false;
1324 args[i].tree_value = build_fold_addr_expr_loc (loc,
1325 args[i].tree_value);
1326 type = TREE_TYPE (args[i].tree_value);
1328 if (*ecf_flags & ECF_CONST)
1329 *ecf_flags &= ~(ECF_CONST | ECF_LOOPING_CONST_OR_PURE);
1331 else
1333 /* We make a copy of the object and pass the address to the
1334 function being called. */
1335 rtx copy;
1337 if (!COMPLETE_TYPE_P (type)
1338 || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
1339 || (flag_stack_check == GENERIC_STACK_CHECK
1340 && compare_tree_int (TYPE_SIZE_UNIT (type),
1341 STACK_CHECK_MAX_VAR_SIZE) > 0))
1343 /* This is a variable-sized object. Make space on the stack
1344 for it. */
1345 rtx size_rtx = expr_size (args[i].tree_value);
1347 if (*old_stack_level == 0)
1349 emit_stack_save (SAVE_BLOCK, old_stack_level);
1350 *old_pending_adj = pending_stack_adjust;
1351 pending_stack_adjust = 0;
1354 /* We can pass TRUE as the 4th argument because we just
1355 saved the stack pointer and will restore it right after
1356 the call. */
1357 copy = allocate_dynamic_stack_space (size_rtx,
1358 TYPE_ALIGN (type),
1359 TYPE_ALIGN (type),
1360 true);
1361 copy = gen_rtx_MEM (BLKmode, copy);
1362 set_mem_attributes (copy, type, 1);
1364 else
1365 copy = assign_temp (type, 1, 0);
1367 store_expr (args[i].tree_value, copy, 0, false);
1369 /* Just change the const function to pure and then let
1370 the next test clear the pure based on
1371 callee_copies. */
1372 if (*ecf_flags & ECF_CONST)
1374 *ecf_flags &= ~ECF_CONST;
1375 *ecf_flags |= ECF_PURE;
1378 if (!callee_copies && *ecf_flags & ECF_PURE)
1379 *ecf_flags &= ~(ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
1381 args[i].tree_value
1382 = build_fold_addr_expr_loc (loc, make_tree (type, copy));
1383 type = TREE_TYPE (args[i].tree_value);
1384 *may_tailcall = false;
1388 unsignedp = TYPE_UNSIGNED (type);
1389 mode = promote_function_mode (type, TYPE_MODE (type), &unsignedp,
1390 fndecl ? TREE_TYPE (fndecl) : fntype, 0);
1392 args[i].unsignedp = unsignedp;
1393 args[i].mode = mode;
1395 args[i].reg = targetm.calls.function_arg (args_so_far, mode, type,
1396 argpos < n_named_args);
1398 if (args[i].reg && CONST_INT_P (args[i].reg))
1400 args[i].special_slot = args[i].reg;
1401 args[i].reg = NULL;
1404 /* If this is a sibling call and the machine has register windows, the
1405 register window has to be unwinded before calling the routine, so
1406 arguments have to go into the incoming registers. */
1407 if (targetm.calls.function_incoming_arg != targetm.calls.function_arg)
1408 args[i].tail_call_reg
1409 = targetm.calls.function_incoming_arg (args_so_far, mode, type,
1410 argpos < n_named_args);
1411 else
1412 args[i].tail_call_reg = args[i].reg;
1414 if (args[i].reg)
1415 args[i].partial
1416 = targetm.calls.arg_partial_bytes (args_so_far, mode, type,
1417 argpos < n_named_args);
1419 args[i].pass_on_stack = targetm.calls.must_pass_in_stack (mode, type);
1421 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1422 it means that we are to pass this arg in the register(s) designated
1423 by the PARALLEL, but also to pass it in the stack. */
1424 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1425 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1426 args[i].pass_on_stack = 1;
1428 /* If this is an addressable type, we must preallocate the stack
1429 since we must evaluate the object into its final location.
1431 If this is to be passed in both registers and the stack, it is simpler
1432 to preallocate. */
1433 if (TREE_ADDRESSABLE (type)
1434 || (args[i].pass_on_stack && args[i].reg != 0))
1435 *must_preallocate = 1;
1437 /* No stack allocation and padding for bounds. */
1438 if (POINTER_BOUNDS_P (args[i].tree_value))
1440 /* Compute the stack-size of this argument. */
1441 else if (args[i].reg == 0 || args[i].partial != 0
1442 || reg_parm_stack_space > 0
1443 || args[i].pass_on_stack)
1444 locate_and_pad_parm (mode, type,
1445 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1447 #else
1448 args[i].reg != 0,
1449 #endif
1450 reg_parm_stack_space,
1451 args[i].pass_on_stack ? 0 : args[i].partial,
1452 fndecl, args_size, &args[i].locate);
1453 #ifdef BLOCK_REG_PADDING
1454 else
1455 /* The argument is passed entirely in registers. See at which
1456 end it should be padded. */
1457 args[i].locate.where_pad =
1458 BLOCK_REG_PADDING (mode, type,
1459 int_size_in_bytes (type) <= UNITS_PER_WORD);
1460 #endif
1462 /* Update ARGS_SIZE, the total stack space for args so far. */
1464 args_size->constant += args[i].locate.size.constant;
1465 if (args[i].locate.size.var)
1466 ADD_PARM_SIZE (*args_size, args[i].locate.size.var);
1468 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1469 have been used, etc. */
1471 targetm.calls.function_arg_advance (args_so_far, TYPE_MODE (type),
1472 type, argpos < n_named_args);
1476 /* Update ARGS_SIZE to contain the total size for the argument block.
1477 Return the original constant component of the argument block's size.
1479 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1480 for arguments passed in registers. */
1482 static int
1483 compute_argument_block_size (int reg_parm_stack_space,
1484 struct args_size *args_size,
1485 tree fndecl ATTRIBUTE_UNUSED,
1486 tree fntype ATTRIBUTE_UNUSED,
1487 int preferred_stack_boundary ATTRIBUTE_UNUSED)
1489 int unadjusted_args_size = args_size->constant;
1491 /* For accumulate outgoing args mode we don't need to align, since the frame
1492 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1493 backends from generating misaligned frame sizes. */
1494 if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY)
1495 preferred_stack_boundary = STACK_BOUNDARY;
1497 /* Compute the actual size of the argument block required. The variable
1498 and constant sizes must be combined, the size may have to be rounded,
1499 and there may be a minimum required size. */
1501 if (args_size->var)
1503 args_size->var = ARGS_SIZE_TREE (*args_size);
1504 args_size->constant = 0;
1506 preferred_stack_boundary /= BITS_PER_UNIT;
1507 if (preferred_stack_boundary > 1)
1509 /* We don't handle this case yet. To handle it correctly we have
1510 to add the delta, round and subtract the delta.
1511 Currently no machine description requires this support. */
1512 gcc_assert (!(stack_pointer_delta & (preferred_stack_boundary - 1)));
1513 args_size->var = round_up (args_size->var, preferred_stack_boundary);
1516 if (reg_parm_stack_space > 0)
1518 args_size->var
1519 = size_binop (MAX_EXPR, args_size->var,
1520 ssize_int (reg_parm_stack_space));
1522 /* The area corresponding to register parameters is not to count in
1523 the size of the block we need. So make the adjustment. */
1524 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
1525 args_size->var
1526 = size_binop (MINUS_EXPR, args_size->var,
1527 ssize_int (reg_parm_stack_space));
1530 else
1532 preferred_stack_boundary /= BITS_PER_UNIT;
1533 if (preferred_stack_boundary < 1)
1534 preferred_stack_boundary = 1;
1535 args_size->constant = (((args_size->constant
1536 + stack_pointer_delta
1537 + preferred_stack_boundary - 1)
1538 / preferred_stack_boundary
1539 * preferred_stack_boundary)
1540 - stack_pointer_delta);
1542 args_size->constant = MAX (args_size->constant,
1543 reg_parm_stack_space);
1545 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
1546 args_size->constant -= reg_parm_stack_space;
1548 return unadjusted_args_size;
1551 /* Precompute parameters as needed for a function call.
1553 FLAGS is mask of ECF_* constants.
1555 NUM_ACTUALS is the number of arguments.
1557 ARGS is an array containing information for each argument; this
1558 routine fills in the INITIAL_VALUE and VALUE fields for each
1559 precomputed argument. */
1561 static void
1562 precompute_arguments (int num_actuals, struct arg_data *args)
1564 int i;
1566 /* If this is a libcall, then precompute all arguments so that we do not
1567 get extraneous instructions emitted as part of the libcall sequence. */
1569 /* If we preallocated the stack space, and some arguments must be passed
1570 on the stack, then we must precompute any parameter which contains a
1571 function call which will store arguments on the stack.
1572 Otherwise, evaluating the parameter may clobber previous parameters
1573 which have already been stored into the stack. (we have code to avoid
1574 such case by saving the outgoing stack arguments, but it results in
1575 worse code) */
1576 if (!ACCUMULATE_OUTGOING_ARGS)
1577 return;
1579 for (i = 0; i < num_actuals; i++)
1581 tree type;
1582 machine_mode mode;
1584 if (TREE_CODE (args[i].tree_value) != CALL_EXPR)
1585 continue;
1587 /* If this is an addressable type, we cannot pre-evaluate it. */
1588 type = TREE_TYPE (args[i].tree_value);
1589 gcc_assert (!TREE_ADDRESSABLE (type));
1591 args[i].initial_value = args[i].value
1592 = expand_normal (args[i].tree_value);
1594 mode = TYPE_MODE (type);
1595 if (mode != args[i].mode)
1597 int unsignedp = args[i].unsignedp;
1598 args[i].value
1599 = convert_modes (args[i].mode, mode,
1600 args[i].value, args[i].unsignedp);
1602 /* CSE will replace this only if it contains args[i].value
1603 pseudo, so convert it down to the declared mode using
1604 a SUBREG. */
1605 if (REG_P (args[i].value)
1606 && GET_MODE_CLASS (args[i].mode) == MODE_INT
1607 && promote_mode (type, mode, &unsignedp) != args[i].mode)
1609 args[i].initial_value
1610 = gen_lowpart_SUBREG (mode, args[i].value);
1611 SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1612 SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp);
1618 /* Given the current state of MUST_PREALLOCATE and information about
1619 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1620 compute and return the final value for MUST_PREALLOCATE. */
1622 static int
1623 finalize_must_preallocate (int must_preallocate, int num_actuals,
1624 struct arg_data *args, struct args_size *args_size)
1626 /* See if we have or want to preallocate stack space.
1628 If we would have to push a partially-in-regs parm
1629 before other stack parms, preallocate stack space instead.
1631 If the size of some parm is not a multiple of the required stack
1632 alignment, we must preallocate.
1634 If the total size of arguments that would otherwise create a copy in
1635 a temporary (such as a CALL) is more than half the total argument list
1636 size, preallocation is faster.
1638 Another reason to preallocate is if we have a machine (like the m88k)
1639 where stack alignment is required to be maintained between every
1640 pair of insns, not just when the call is made. However, we assume here
1641 that such machines either do not have push insns (and hence preallocation
1642 would occur anyway) or the problem is taken care of with
1643 PUSH_ROUNDING. */
1645 if (! must_preallocate)
1647 int partial_seen = 0;
1648 int copy_to_evaluate_size = 0;
1649 int i;
1651 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1653 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1654 partial_seen = 1;
1655 else if (partial_seen && args[i].reg == 0)
1656 must_preallocate = 1;
1657 /* We preallocate in case there are bounds passed
1658 in the bounds table to have precomputed address
1659 for bounds association. */
1660 else if (POINTER_BOUNDS_P (args[i].tree_value)
1661 && !args[i].reg)
1662 must_preallocate = 1;
1664 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1665 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1666 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1667 || TREE_CODE (args[i].tree_value) == COND_EXPR
1668 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1669 copy_to_evaluate_size
1670 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1673 if (copy_to_evaluate_size * 2 >= args_size->constant
1674 && args_size->constant > 0)
1675 must_preallocate = 1;
1677 return must_preallocate;
1680 /* If we preallocated stack space, compute the address of each argument
1681 and store it into the ARGS array.
1683 We need not ensure it is a valid memory address here; it will be
1684 validized when it is used.
1686 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1688 static void
1689 compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals)
1691 if (argblock)
1693 rtx arg_reg = argblock;
1694 int i, arg_offset = 0;
1696 if (GET_CODE (argblock) == PLUS)
1697 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1699 for (i = 0; i < num_actuals; i++)
1701 rtx offset = ARGS_SIZE_RTX (args[i].locate.offset);
1702 rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
1703 rtx addr;
1704 unsigned int align, boundary;
1705 unsigned int units_on_stack = 0;
1706 machine_mode partial_mode = VOIDmode;
1708 /* Skip this parm if it will not be passed on the stack. */
1709 if (! args[i].pass_on_stack
1710 && args[i].reg != 0
1711 && args[i].partial == 0)
1712 continue;
1714 /* Pointer Bounds are never passed on the stack. */
1715 if (POINTER_BOUNDS_P (args[i].tree_value))
1716 continue;
1718 if (CONST_INT_P (offset))
1719 addr = plus_constant (Pmode, arg_reg, INTVAL (offset));
1720 else
1721 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1723 addr = plus_constant (Pmode, addr, arg_offset);
1725 if (args[i].partial != 0)
1727 /* Only part of the parameter is being passed on the stack.
1728 Generate a simple memory reference of the correct size. */
1729 units_on_stack = args[i].locate.size.constant;
1730 partial_mode = mode_for_size (units_on_stack * BITS_PER_UNIT,
1731 MODE_INT, 1);
1732 args[i].stack = gen_rtx_MEM (partial_mode, addr);
1733 set_mem_size (args[i].stack, units_on_stack);
1735 else
1737 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1738 set_mem_attributes (args[i].stack,
1739 TREE_TYPE (args[i].tree_value), 1);
1741 align = BITS_PER_UNIT;
1742 boundary = args[i].locate.boundary;
1743 if (args[i].locate.where_pad != downward)
1744 align = boundary;
1745 else if (CONST_INT_P (offset))
1747 align = INTVAL (offset) * BITS_PER_UNIT | boundary;
1748 align = align & -align;
1750 set_mem_align (args[i].stack, align);
1752 if (CONST_INT_P (slot_offset))
1753 addr = plus_constant (Pmode, arg_reg, INTVAL (slot_offset));
1754 else
1755 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1757 addr = plus_constant (Pmode, addr, arg_offset);
1759 if (args[i].partial != 0)
1761 /* Only part of the parameter is being passed on the stack.
1762 Generate a simple memory reference of the correct size.
1764 args[i].stack_slot = gen_rtx_MEM (partial_mode, addr);
1765 set_mem_size (args[i].stack_slot, units_on_stack);
1767 else
1769 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1770 set_mem_attributes (args[i].stack_slot,
1771 TREE_TYPE (args[i].tree_value), 1);
1773 set_mem_align (args[i].stack_slot, args[i].locate.boundary);
1775 /* Function incoming arguments may overlap with sibling call
1776 outgoing arguments and we cannot allow reordering of reads
1777 from function arguments with stores to outgoing arguments
1778 of sibling calls. */
1779 set_mem_alias_set (args[i].stack, 0);
1780 set_mem_alias_set (args[i].stack_slot, 0);
1785 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1786 in a call instruction.
1788 FNDECL is the tree node for the target function. For an indirect call
1789 FNDECL will be NULL_TREE.
1791 ADDR is the operand 0 of CALL_EXPR for this call. */
1793 static rtx
1794 rtx_for_function_call (tree fndecl, tree addr)
1796 rtx funexp;
1798 /* Get the function to call, in the form of RTL. */
1799 if (fndecl)
1801 if (!TREE_USED (fndecl) && fndecl != current_function_decl)
1802 TREE_USED (fndecl) = 1;
1804 /* Get a SYMBOL_REF rtx for the function address. */
1805 funexp = XEXP (DECL_RTL (fndecl), 0);
1807 else
1808 /* Generate an rtx (probably a pseudo-register) for the address. */
1810 push_temp_slots ();
1811 funexp = expand_normal (addr);
1812 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1814 return funexp;
1817 /* Internal state for internal_arg_pointer_based_exp and its helpers. */
1818 static struct
1820 /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan,
1821 or NULL_RTX if none has been scanned yet. */
1822 rtx_insn *scan_start;
1823 /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is
1824 based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the
1825 pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it
1826 with fixed offset, or PC if this is with variable or unknown offset. */
1827 vec<rtx> cache;
1828 } internal_arg_pointer_exp_state;
1830 static rtx internal_arg_pointer_based_exp (const_rtx, bool);
1832 /* Helper function for internal_arg_pointer_based_exp. Scan insns in
1833 the tail call sequence, starting with first insn that hasn't been
1834 scanned yet, and note for each pseudo on the LHS whether it is based
1835 on crtl->args.internal_arg_pointer or not, and what offset from that
1836 that pointer it has. */
1838 static void
1839 internal_arg_pointer_based_exp_scan (void)
1841 rtx_insn *insn, *scan_start = internal_arg_pointer_exp_state.scan_start;
1843 if (scan_start == NULL_RTX)
1844 insn = get_insns ();
1845 else
1846 insn = NEXT_INSN (scan_start);
1848 while (insn)
1850 rtx set = single_set (insn);
1851 if (set && REG_P (SET_DEST (set)) && !HARD_REGISTER_P (SET_DEST (set)))
1853 rtx val = NULL_RTX;
1854 unsigned int idx = REGNO (SET_DEST (set)) - FIRST_PSEUDO_REGISTER;
1855 /* Punt on pseudos set multiple times. */
1856 if (idx < internal_arg_pointer_exp_state.cache.length ()
1857 && (internal_arg_pointer_exp_state.cache[idx]
1858 != NULL_RTX))
1859 val = pc_rtx;
1860 else
1861 val = internal_arg_pointer_based_exp (SET_SRC (set), false);
1862 if (val != NULL_RTX)
1864 if (idx >= internal_arg_pointer_exp_state.cache.length ())
1865 internal_arg_pointer_exp_state.cache
1866 .safe_grow_cleared (idx + 1);
1867 internal_arg_pointer_exp_state.cache[idx] = val;
1870 if (NEXT_INSN (insn) == NULL_RTX)
1871 scan_start = insn;
1872 insn = NEXT_INSN (insn);
1875 internal_arg_pointer_exp_state.scan_start = scan_start;
1878 /* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return
1879 NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on
1880 it with fixed offset, or PC if this is with variable or unknown offset.
1881 TOPLEVEL is true if the function is invoked at the topmost level. */
1883 static rtx
1884 internal_arg_pointer_based_exp (const_rtx rtl, bool toplevel)
1886 if (CONSTANT_P (rtl))
1887 return NULL_RTX;
1889 if (rtl == crtl->args.internal_arg_pointer)
1890 return const0_rtx;
1892 if (REG_P (rtl) && HARD_REGISTER_P (rtl))
1893 return NULL_RTX;
1895 if (GET_CODE (rtl) == PLUS && CONST_INT_P (XEXP (rtl, 1)))
1897 rtx val = internal_arg_pointer_based_exp (XEXP (rtl, 0), toplevel);
1898 if (val == NULL_RTX || val == pc_rtx)
1899 return val;
1900 return plus_constant (Pmode, val, INTVAL (XEXP (rtl, 1)));
1903 /* When called at the topmost level, scan pseudo assignments in between the
1904 last scanned instruction in the tail call sequence and the latest insn
1905 in that sequence. */
1906 if (toplevel)
1907 internal_arg_pointer_based_exp_scan ();
1909 if (REG_P (rtl))
1911 unsigned int idx = REGNO (rtl) - FIRST_PSEUDO_REGISTER;
1912 if (idx < internal_arg_pointer_exp_state.cache.length ())
1913 return internal_arg_pointer_exp_state.cache[idx];
1915 return NULL_RTX;
1918 subrtx_iterator::array_type array;
1919 FOR_EACH_SUBRTX (iter, array, rtl, NONCONST)
1921 const_rtx x = *iter;
1922 if (REG_P (x) && internal_arg_pointer_based_exp (x, false) != NULL_RTX)
1923 return pc_rtx;
1924 if (MEM_P (x))
1925 iter.skip_subrtxes ();
1928 return NULL_RTX;
1931 /* Return true if and only if SIZE storage units (usually bytes)
1932 starting from address ADDR overlap with already clobbered argument
1933 area. This function is used to determine if we should give up a
1934 sibcall. */
1936 static bool
1937 mem_overlaps_already_clobbered_arg_p (rtx addr, unsigned HOST_WIDE_INT size)
1939 HOST_WIDE_INT i;
1940 rtx val;
1942 if (bitmap_empty_p (stored_args_map))
1943 return false;
1944 val = internal_arg_pointer_based_exp (addr, true);
1945 if (val == NULL_RTX)
1946 return false;
1947 else if (val == pc_rtx)
1948 return true;
1949 else
1950 i = INTVAL (val);
1951 #ifdef STACK_GROWS_DOWNWARD
1952 i -= crtl->args.pretend_args_size;
1953 #else
1954 i += crtl->args.pretend_args_size;
1955 #endif
1957 #ifdef ARGS_GROW_DOWNWARD
1958 i = -i - size;
1959 #endif
1960 if (size > 0)
1962 unsigned HOST_WIDE_INT k;
1964 for (k = 0; k < size; k++)
1965 if (i + k < SBITMAP_SIZE (stored_args_map)
1966 && bitmap_bit_p (stored_args_map, i + k))
1967 return true;
1970 return false;
1973 /* Do the register loads required for any wholly-register parms or any
1974 parms which are passed both on the stack and in a register. Their
1975 expressions were already evaluated.
1977 Mark all register-parms as living through the call, putting these USE
1978 insns in the CALL_INSN_FUNCTION_USAGE field.
1980 When IS_SIBCALL, perform the check_sibcall_argument_overlap
1981 checking, setting *SIBCALL_FAILURE if appropriate. */
1983 static void
1984 load_register_parameters (struct arg_data *args, int num_actuals,
1985 rtx *call_fusage, int flags, int is_sibcall,
1986 int *sibcall_failure)
1988 int i, j;
1990 for (i = 0; i < num_actuals; i++)
1992 rtx reg = ((flags & ECF_SIBCALL)
1993 ? args[i].tail_call_reg : args[i].reg);
1994 if (reg)
1996 int partial = args[i].partial;
1997 int nregs;
1998 int size = 0;
1999 rtx_insn *before_arg = get_last_insn ();
2000 /* Set non-negative if we must move a word at a time, even if
2001 just one word (e.g, partial == 4 && mode == DFmode). Set
2002 to -1 if we just use a normal move insn. This value can be
2003 zero if the argument is a zero size structure. */
2004 nregs = -1;
2005 if (GET_CODE (reg) == PARALLEL)
2007 else if (partial)
2009 gcc_assert (partial % UNITS_PER_WORD == 0);
2010 nregs = partial / UNITS_PER_WORD;
2012 else if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode)
2014 size = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
2015 nregs = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
2017 else
2018 size = GET_MODE_SIZE (args[i].mode);
2020 /* Handle calls that pass values in multiple non-contiguous
2021 locations. The Irix 6 ABI has examples of this. */
2023 if (GET_CODE (reg) == PARALLEL)
2024 emit_group_move (reg, args[i].parallel_value);
2026 /* If simple case, just do move. If normal partial, store_one_arg
2027 has already loaded the register for us. In all other cases,
2028 load the register(s) from memory. */
2030 else if (nregs == -1)
2032 emit_move_insn (reg, args[i].value);
2033 #ifdef BLOCK_REG_PADDING
2034 /* Handle case where we have a value that needs shifting
2035 up to the msb. eg. a QImode value and we're padding
2036 upward on a BYTES_BIG_ENDIAN machine. */
2037 if (size < UNITS_PER_WORD
2038 && (args[i].locate.where_pad
2039 == (BYTES_BIG_ENDIAN ? upward : downward)))
2041 rtx x;
2042 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
2044 /* Assigning REG here rather than a temp makes CALL_FUSAGE
2045 report the whole reg as used. Strictly speaking, the
2046 call only uses SIZE bytes at the msb end, but it doesn't
2047 seem worth generating rtl to say that. */
2048 reg = gen_rtx_REG (word_mode, REGNO (reg));
2049 x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1);
2050 if (x != reg)
2051 emit_move_insn (reg, x);
2053 #endif
2056 /* If we have pre-computed the values to put in the registers in
2057 the case of non-aligned structures, copy them in now. */
2059 else if (args[i].n_aligned_regs != 0)
2060 for (j = 0; j < args[i].n_aligned_regs; j++)
2061 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
2062 args[i].aligned_regs[j]);
2064 else if (partial == 0 || args[i].pass_on_stack)
2066 rtx mem = validize_mem (copy_rtx (args[i].value));
2068 /* Check for overlap with already clobbered argument area,
2069 providing that this has non-zero size. */
2070 if (is_sibcall
2071 && (size == 0
2072 || mem_overlaps_already_clobbered_arg_p
2073 (XEXP (args[i].value, 0), size)))
2074 *sibcall_failure = 1;
2076 /* Handle a BLKmode that needs shifting. */
2077 if (nregs == 1 && size < UNITS_PER_WORD
2078 #ifdef BLOCK_REG_PADDING
2079 && args[i].locate.where_pad == downward
2080 #else
2081 && BYTES_BIG_ENDIAN
2082 #endif
2085 rtx tem = operand_subword_force (mem, 0, args[i].mode);
2086 rtx ri = gen_rtx_REG (word_mode, REGNO (reg));
2087 rtx x = gen_reg_rtx (word_mode);
2088 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
2089 enum tree_code dir = BYTES_BIG_ENDIAN ? RSHIFT_EXPR
2090 : LSHIFT_EXPR;
2092 emit_move_insn (x, tem);
2093 x = expand_shift (dir, word_mode, x, shift, ri, 1);
2094 if (x != ri)
2095 emit_move_insn (ri, x);
2097 else
2098 move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode);
2101 /* When a parameter is a block, and perhaps in other cases, it is
2102 possible that it did a load from an argument slot that was
2103 already clobbered. */
2104 if (is_sibcall
2105 && check_sibcall_argument_overlap (before_arg, &args[i], 0))
2106 *sibcall_failure = 1;
2108 /* Handle calls that pass values in multiple non-contiguous
2109 locations. The Irix 6 ABI has examples of this. */
2110 if (GET_CODE (reg) == PARALLEL)
2111 use_group_regs (call_fusage, reg);
2112 else if (nregs == -1)
2113 use_reg_mode (call_fusage, reg,
2114 TYPE_MODE (TREE_TYPE (args[i].tree_value)));
2115 else if (nregs > 0)
2116 use_regs (call_fusage, REGNO (reg), nregs);
2121 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
2122 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
2123 bytes, then we would need to push some additional bytes to pad the
2124 arguments. So, we compute an adjust to the stack pointer for an
2125 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
2126 bytes. Then, when the arguments are pushed the stack will be perfectly
2127 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
2128 be popped after the call. Returns the adjustment. */
2130 static int
2131 combine_pending_stack_adjustment_and_call (int unadjusted_args_size,
2132 struct args_size *args_size,
2133 unsigned int preferred_unit_stack_boundary)
2135 /* The number of bytes to pop so that the stack will be
2136 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
2137 HOST_WIDE_INT adjustment;
2138 /* The alignment of the stack after the arguments are pushed, if we
2139 just pushed the arguments without adjust the stack here. */
2140 unsigned HOST_WIDE_INT unadjusted_alignment;
2142 unadjusted_alignment
2143 = ((stack_pointer_delta + unadjusted_args_size)
2144 % preferred_unit_stack_boundary);
2146 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
2147 as possible -- leaving just enough left to cancel out the
2148 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
2149 PENDING_STACK_ADJUST is non-negative, and congruent to
2150 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
2152 /* Begin by trying to pop all the bytes. */
2153 unadjusted_alignment
2154 = (unadjusted_alignment
2155 - (pending_stack_adjust % preferred_unit_stack_boundary));
2156 adjustment = pending_stack_adjust;
2157 /* Push enough additional bytes that the stack will be aligned
2158 after the arguments are pushed. */
2159 if (preferred_unit_stack_boundary > 1)
2161 if (unadjusted_alignment > 0)
2162 adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
2163 else
2164 adjustment += unadjusted_alignment;
2167 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
2168 bytes after the call. The right number is the entire
2169 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
2170 by the arguments in the first place. */
2171 args_size->constant
2172 = pending_stack_adjust - adjustment + unadjusted_args_size;
2174 return adjustment;
2177 /* Scan X expression if it does not dereference any argument slots
2178 we already clobbered by tail call arguments (as noted in stored_args_map
2179 bitmap).
2180 Return nonzero if X expression dereferences such argument slots,
2181 zero otherwise. */
2183 static int
2184 check_sibcall_argument_overlap_1 (rtx x)
2186 RTX_CODE code;
2187 int i, j;
2188 const char *fmt;
2190 if (x == NULL_RTX)
2191 return 0;
2193 code = GET_CODE (x);
2195 /* We need not check the operands of the CALL expression itself. */
2196 if (code == CALL)
2197 return 0;
2199 if (code == MEM)
2200 return mem_overlaps_already_clobbered_arg_p (XEXP (x, 0),
2201 GET_MODE_SIZE (GET_MODE (x)));
2203 /* Scan all subexpressions. */
2204 fmt = GET_RTX_FORMAT (code);
2205 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2207 if (*fmt == 'e')
2209 if (check_sibcall_argument_overlap_1 (XEXP (x, i)))
2210 return 1;
2212 else if (*fmt == 'E')
2214 for (j = 0; j < XVECLEN (x, i); j++)
2215 if (check_sibcall_argument_overlap_1 (XVECEXP (x, i, j)))
2216 return 1;
2219 return 0;
2222 /* Scan sequence after INSN if it does not dereference any argument slots
2223 we already clobbered by tail call arguments (as noted in stored_args_map
2224 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
2225 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
2226 should be 0). Return nonzero if sequence after INSN dereferences such argument
2227 slots, zero otherwise. */
2229 static int
2230 check_sibcall_argument_overlap (rtx_insn *insn, struct arg_data *arg,
2231 int mark_stored_args_map)
2233 int low, high;
2235 if (insn == NULL_RTX)
2236 insn = get_insns ();
2237 else
2238 insn = NEXT_INSN (insn);
2240 for (; insn; insn = NEXT_INSN (insn))
2241 if (INSN_P (insn)
2242 && check_sibcall_argument_overlap_1 (PATTERN (insn)))
2243 break;
2245 if (mark_stored_args_map)
2247 #ifdef ARGS_GROW_DOWNWARD
2248 low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
2249 #else
2250 low = arg->locate.slot_offset.constant;
2251 #endif
2253 for (high = low + arg->locate.size.constant; low < high; low++)
2254 bitmap_set_bit (stored_args_map, low);
2256 return insn != NULL_RTX;
2259 /* Given that a function returns a value of mode MODE at the most
2260 significant end of hard register VALUE, shift VALUE left or right
2261 as specified by LEFT_P. Return true if some action was needed. */
2263 bool
2264 shift_return_value (machine_mode mode, bool left_p, rtx value)
2266 HOST_WIDE_INT shift;
2268 gcc_assert (REG_P (value) && HARD_REGISTER_P (value));
2269 shift = GET_MODE_BITSIZE (GET_MODE (value)) - GET_MODE_BITSIZE (mode);
2270 if (shift == 0)
2271 return false;
2273 /* Use ashr rather than lshr for right shifts. This is for the benefit
2274 of the MIPS port, which requires SImode values to be sign-extended
2275 when stored in 64-bit registers. */
2276 if (!force_expand_binop (GET_MODE (value), left_p ? ashl_optab : ashr_optab,
2277 value, GEN_INT (shift), value, 1, OPTAB_WIDEN))
2278 gcc_unreachable ();
2279 return true;
2282 /* If X is a likely-spilled register value, copy it to a pseudo
2283 register and return that register. Return X otherwise. */
2285 static rtx
2286 avoid_likely_spilled_reg (rtx x)
2288 rtx new_rtx;
2290 if (REG_P (x)
2291 && HARD_REGISTER_P (x)
2292 && targetm.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x))))
2294 /* Make sure that we generate a REG rather than a CONCAT.
2295 Moves into CONCATs can need nontrivial instructions,
2296 and the whole point of this function is to avoid
2297 using the hard register directly in such a situation. */
2298 generating_concat_p = 0;
2299 new_rtx = gen_reg_rtx (GET_MODE (x));
2300 generating_concat_p = 1;
2301 emit_move_insn (new_rtx, x);
2302 return new_rtx;
2304 return x;
2307 /* Generate all the code for a CALL_EXPR exp
2308 and return an rtx for its value.
2309 Store the value in TARGET (specified as an rtx) if convenient.
2310 If the value is stored in TARGET then TARGET is returned.
2311 If IGNORE is nonzero, then we ignore the value of the function call. */
2314 expand_call (tree exp, rtx target, int ignore)
2316 /* Nonzero if we are currently expanding a call. */
2317 static int currently_expanding_call = 0;
2319 /* RTX for the function to be called. */
2320 rtx funexp;
2321 /* Sequence of insns to perform a normal "call". */
2322 rtx_insn *normal_call_insns = NULL;
2323 /* Sequence of insns to perform a tail "call". */
2324 rtx_insn *tail_call_insns = NULL;
2325 /* Data type of the function. */
2326 tree funtype;
2327 tree type_arg_types;
2328 tree rettype;
2329 /* Declaration of the function being called,
2330 or 0 if the function is computed (not known by name). */
2331 tree fndecl = 0;
2332 /* The type of the function being called. */
2333 tree fntype;
2334 bool try_tail_call = CALL_EXPR_TAILCALL (exp);
2335 int pass;
2337 /* Register in which non-BLKmode value will be returned,
2338 or 0 if no value or if value is BLKmode. */
2339 rtx valreg;
2340 /* Register(s) in which bounds are returned. */
2341 rtx valbnd = NULL;
2342 /* Address where we should return a BLKmode value;
2343 0 if value not BLKmode. */
2344 rtx structure_value_addr = 0;
2345 /* Nonzero if that address is being passed by treating it as
2346 an extra, implicit first parameter. Otherwise,
2347 it is passed by being copied directly into struct_value_rtx. */
2348 int structure_value_addr_parm = 0;
2349 /* Holds the value of implicit argument for the struct value. */
2350 tree structure_value_addr_value = NULL_TREE;
2351 /* Size of aggregate value wanted, or zero if none wanted
2352 or if we are using the non-reentrant PCC calling convention
2353 or expecting the value in registers. */
2354 HOST_WIDE_INT struct_value_size = 0;
2355 /* Nonzero if called function returns an aggregate in memory PCC style,
2356 by returning the address of where to find it. */
2357 int pcc_struct_value = 0;
2358 rtx struct_value = 0;
2360 /* Number of actual parameters in this call, including struct value addr. */
2361 int num_actuals;
2362 /* Number of named args. Args after this are anonymous ones
2363 and they must all go on the stack. */
2364 int n_named_args;
2365 /* Number of complex actual arguments that need to be split. */
2366 int num_complex_actuals = 0;
2368 /* Vector of information about each argument.
2369 Arguments are numbered in the order they will be pushed,
2370 not the order they are written. */
2371 struct arg_data *args;
2373 /* Total size in bytes of all the stack-parms scanned so far. */
2374 struct args_size args_size;
2375 struct args_size adjusted_args_size;
2376 /* Size of arguments before any adjustments (such as rounding). */
2377 int unadjusted_args_size;
2378 /* Data on reg parms scanned so far. */
2379 CUMULATIVE_ARGS args_so_far_v;
2380 cumulative_args_t args_so_far;
2381 /* Nonzero if a reg parm has been scanned. */
2382 int reg_parm_seen;
2383 /* Nonzero if this is an indirect function call. */
2385 /* Nonzero if we must avoid push-insns in the args for this call.
2386 If stack space is allocated for register parameters, but not by the
2387 caller, then it is preallocated in the fixed part of the stack frame.
2388 So the entire argument block must then be preallocated (i.e., we
2389 ignore PUSH_ROUNDING in that case). */
2391 int must_preallocate = !PUSH_ARGS;
2393 /* Size of the stack reserved for parameter registers. */
2394 int reg_parm_stack_space = 0;
2396 /* Address of space preallocated for stack parms
2397 (on machines that lack push insns), or 0 if space not preallocated. */
2398 rtx argblock = 0;
2400 /* Mask of ECF_ and ERF_ flags. */
2401 int flags = 0;
2402 int return_flags = 0;
2403 #ifdef REG_PARM_STACK_SPACE
2404 /* Define the boundary of the register parm stack space that needs to be
2405 saved, if any. */
2406 int low_to_save, high_to_save;
2407 rtx save_area = 0; /* Place that it is saved */
2408 #endif
2410 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2411 char *initial_stack_usage_map = stack_usage_map;
2412 char *stack_usage_map_buf = NULL;
2414 int old_stack_allocated;
2416 /* State variables to track stack modifications. */
2417 rtx old_stack_level = 0;
2418 int old_stack_arg_under_construction = 0;
2419 int old_pending_adj = 0;
2420 int old_inhibit_defer_pop = inhibit_defer_pop;
2422 /* Some stack pointer alterations we make are performed via
2423 allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
2424 which we then also need to save/restore along the way. */
2425 int old_stack_pointer_delta = 0;
2427 rtx call_fusage;
2428 tree addr = CALL_EXPR_FN (exp);
2429 int i;
2430 /* The alignment of the stack, in bits. */
2431 unsigned HOST_WIDE_INT preferred_stack_boundary;
2432 /* The alignment of the stack, in bytes. */
2433 unsigned HOST_WIDE_INT preferred_unit_stack_boundary;
2434 /* The static chain value to use for this call. */
2435 rtx static_chain_value;
2436 /* See if this is "nothrow" function call. */
2437 if (TREE_NOTHROW (exp))
2438 flags |= ECF_NOTHROW;
2440 /* See if we can find a DECL-node for the actual function, and get the
2441 function attributes (flags) from the function decl or type node. */
2442 fndecl = get_callee_fndecl (exp);
2443 if (fndecl)
2445 fntype = TREE_TYPE (fndecl);
2446 flags |= flags_from_decl_or_type (fndecl);
2447 return_flags |= decl_return_flags (fndecl);
2449 else
2451 fntype = TREE_TYPE (TREE_TYPE (addr));
2452 flags |= flags_from_decl_or_type (fntype);
2454 rettype = TREE_TYPE (exp);
2456 struct_value = targetm.calls.struct_value_rtx (fntype, 0);
2458 /* Warn if this value is an aggregate type,
2459 regardless of which calling convention we are using for it. */
2460 if (AGGREGATE_TYPE_P (rettype))
2461 warning (OPT_Waggregate_return, "function call has aggregate value");
2463 /* If the result of a non looping pure or const function call is
2464 ignored (or void), and none of its arguments are volatile, we can
2465 avoid expanding the call and just evaluate the arguments for
2466 side-effects. */
2467 if ((flags & (ECF_CONST | ECF_PURE))
2468 && (!(flags & ECF_LOOPING_CONST_OR_PURE))
2469 && (ignore || target == const0_rtx
2470 || TYPE_MODE (rettype) == VOIDmode))
2472 bool volatilep = false;
2473 tree arg;
2474 call_expr_arg_iterator iter;
2476 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2477 if (TREE_THIS_VOLATILE (arg))
2479 volatilep = true;
2480 break;
2483 if (! volatilep)
2485 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2486 expand_expr (arg, const0_rtx, VOIDmode, EXPAND_NORMAL);
2487 return const0_rtx;
2491 #ifdef REG_PARM_STACK_SPACE
2492 reg_parm_stack_space = REG_PARM_STACK_SPACE (!fndecl ? fntype : fndecl);
2493 #endif
2495 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
2496 && reg_parm_stack_space > 0 && PUSH_ARGS)
2497 must_preallocate = 1;
2499 /* Set up a place to return a structure. */
2501 /* Cater to broken compilers. */
2502 if (aggregate_value_p (exp, fntype))
2504 /* This call returns a big structure. */
2505 flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
2507 #ifdef PCC_STATIC_STRUCT_RETURN
2509 pcc_struct_value = 1;
2511 #else /* not PCC_STATIC_STRUCT_RETURN */
2513 struct_value_size = int_size_in_bytes (rettype);
2515 /* Even if it is semantically safe to use the target as the return
2516 slot, it may be not sufficiently aligned for the return type. */
2517 if (CALL_EXPR_RETURN_SLOT_OPT (exp)
2518 && target
2519 && MEM_P (target)
2520 && !(MEM_ALIGN (target) < TYPE_ALIGN (rettype)
2521 && SLOW_UNALIGNED_ACCESS (TYPE_MODE (rettype),
2522 MEM_ALIGN (target))))
2523 structure_value_addr = XEXP (target, 0);
2524 else
2526 /* For variable-sized objects, we must be called with a target
2527 specified. If we were to allocate space on the stack here,
2528 we would have no way of knowing when to free it. */
2529 rtx d = assign_temp (rettype, 1, 1);
2530 structure_value_addr = XEXP (d, 0);
2531 target = 0;
2534 #endif /* not PCC_STATIC_STRUCT_RETURN */
2537 /* Figure out the amount to which the stack should be aligned. */
2538 preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2539 if (fndecl)
2541 struct cgraph_rtl_info *i = cgraph_node::rtl_info (fndecl);
2542 /* Without automatic stack alignment, we can't increase preferred
2543 stack boundary. With automatic stack alignment, it is
2544 unnecessary since unless we can guarantee that all callers will
2545 align the outgoing stack properly, callee has to align its
2546 stack anyway. */
2547 if (i
2548 && i->preferred_incoming_stack_boundary
2549 && i->preferred_incoming_stack_boundary < preferred_stack_boundary)
2550 preferred_stack_boundary = i->preferred_incoming_stack_boundary;
2553 /* Operand 0 is a pointer-to-function; get the type of the function. */
2554 funtype = TREE_TYPE (addr);
2555 gcc_assert (POINTER_TYPE_P (funtype));
2556 funtype = TREE_TYPE (funtype);
2558 /* Count whether there are actual complex arguments that need to be split
2559 into their real and imaginary parts. Munge the type_arg_types
2560 appropriately here as well. */
2561 if (targetm.calls.split_complex_arg)
2563 call_expr_arg_iterator iter;
2564 tree arg;
2565 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2567 tree type = TREE_TYPE (arg);
2568 if (type && TREE_CODE (type) == COMPLEX_TYPE
2569 && targetm.calls.split_complex_arg (type))
2570 num_complex_actuals++;
2572 type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype));
2574 else
2575 type_arg_types = TYPE_ARG_TYPES (funtype);
2577 if (flags & ECF_MAY_BE_ALLOCA)
2578 cfun->calls_alloca = 1;
2580 /* If struct_value_rtx is 0, it means pass the address
2581 as if it were an extra parameter. Put the argument expression
2582 in structure_value_addr_value. */
2583 if (structure_value_addr && struct_value == 0)
2585 /* If structure_value_addr is a REG other than
2586 virtual_outgoing_args_rtx, we can use always use it. If it
2587 is not a REG, we must always copy it into a register.
2588 If it is virtual_outgoing_args_rtx, we must copy it to another
2589 register in some cases. */
2590 rtx temp = (!REG_P (structure_value_addr)
2591 || (ACCUMULATE_OUTGOING_ARGS
2592 && stack_arg_under_construction
2593 && structure_value_addr == virtual_outgoing_args_rtx)
2594 ? copy_addr_to_reg (convert_memory_address
2595 (Pmode, structure_value_addr))
2596 : structure_value_addr);
2598 structure_value_addr_value =
2599 make_tree (build_pointer_type (TREE_TYPE (funtype)), temp);
2600 structure_value_addr_parm = CALL_WITH_BOUNDS_P (exp) ? 2 : 1;
2603 /* Count the arguments and set NUM_ACTUALS. */
2604 num_actuals =
2605 call_expr_nargs (exp) + num_complex_actuals + structure_value_addr_parm;
2607 /* Compute number of named args.
2608 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2610 if (type_arg_types != 0)
2611 n_named_args
2612 = (list_length (type_arg_types)
2613 /* Count the struct value address, if it is passed as a parm. */
2614 + structure_value_addr_parm);
2615 else
2616 /* If we know nothing, treat all args as named. */
2617 n_named_args = num_actuals;
2619 /* Start updating where the next arg would go.
2621 On some machines (such as the PA) indirect calls have a different
2622 calling convention than normal calls. The fourth argument in
2623 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2624 or not. */
2625 INIT_CUMULATIVE_ARGS (args_so_far_v, funtype, NULL_RTX, fndecl, n_named_args);
2626 args_so_far = pack_cumulative_args (&args_so_far_v);
2628 /* Now possibly adjust the number of named args.
2629 Normally, don't include the last named arg if anonymous args follow.
2630 We do include the last named arg if
2631 targetm.calls.strict_argument_naming() returns nonzero.
2632 (If no anonymous args follow, the result of list_length is actually
2633 one too large. This is harmless.)
2635 If targetm.calls.pretend_outgoing_varargs_named() returns
2636 nonzero, and targetm.calls.strict_argument_naming() returns zero,
2637 this machine will be able to place unnamed args that were passed
2638 in registers into the stack. So treat all args as named. This
2639 allows the insns emitting for a specific argument list to be
2640 independent of the function declaration.
2642 If targetm.calls.pretend_outgoing_varargs_named() returns zero,
2643 we do not have any reliable way to pass unnamed args in
2644 registers, so we must force them into memory. */
2646 if (type_arg_types != 0
2647 && targetm.calls.strict_argument_naming (args_so_far))
2649 else if (type_arg_types != 0
2650 && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far))
2651 /* Don't include the last named arg. */
2652 --n_named_args;
2653 else
2654 /* Treat all args as named. */
2655 n_named_args = num_actuals;
2657 /* Make a vector to hold all the information about each arg. */
2658 args = XALLOCAVEC (struct arg_data, num_actuals);
2659 memset (args, 0, num_actuals * sizeof (struct arg_data));
2661 /* Build up entries in the ARGS array, compute the size of the
2662 arguments into ARGS_SIZE, etc. */
2663 initialize_argument_information (num_actuals, args, &args_size,
2664 n_named_args, exp,
2665 structure_value_addr_value, fndecl, fntype,
2666 args_so_far, reg_parm_stack_space,
2667 &old_stack_level, &old_pending_adj,
2668 &must_preallocate, &flags,
2669 &try_tail_call, CALL_FROM_THUNK_P (exp));
2671 if (args_size.var)
2672 must_preallocate = 1;
2674 /* Now make final decision about preallocating stack space. */
2675 must_preallocate = finalize_must_preallocate (must_preallocate,
2676 num_actuals, args,
2677 &args_size);
2679 /* If the structure value address will reference the stack pointer, we
2680 must stabilize it. We don't need to do this if we know that we are
2681 not going to adjust the stack pointer in processing this call. */
2683 if (structure_value_addr
2684 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
2685 || reg_mentioned_p (virtual_outgoing_args_rtx,
2686 structure_value_addr))
2687 && (args_size.var
2688 || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant)))
2689 structure_value_addr = copy_to_reg (structure_value_addr);
2691 /* Tail calls can make things harder to debug, and we've traditionally
2692 pushed these optimizations into -O2. Don't try if we're already
2693 expanding a call, as that means we're an argument. Don't try if
2694 there's cleanups, as we know there's code to follow the call. */
2696 if (currently_expanding_call++ != 0
2697 || !flag_optimize_sibling_calls
2698 || args_size.var
2699 || dbg_cnt (tail_call) == false)
2700 try_tail_call = 0;
2702 /* Rest of purposes for tail call optimizations to fail. */
2703 if (
2704 #ifdef HAVE_sibcall_epilogue
2705 !HAVE_sibcall_epilogue
2706 #else
2708 #endif
2709 || !try_tail_call
2710 /* Doing sibling call optimization needs some work, since
2711 structure_value_addr can be allocated on the stack.
2712 It does not seem worth the effort since few optimizable
2713 sibling calls will return a structure. */
2714 || structure_value_addr != NULL_RTX
2715 #ifdef REG_PARM_STACK_SPACE
2716 /* If outgoing reg parm stack space changes, we can not do sibcall. */
2717 || (OUTGOING_REG_PARM_STACK_SPACE (funtype)
2718 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl)))
2719 || (reg_parm_stack_space != REG_PARM_STACK_SPACE (current_function_decl))
2720 #endif
2721 /* Check whether the target is able to optimize the call
2722 into a sibcall. */
2723 || !targetm.function_ok_for_sibcall (fndecl, exp)
2724 /* Functions that do not return exactly once may not be sibcall
2725 optimized. */
2726 || (flags & (ECF_RETURNS_TWICE | ECF_NORETURN))
2727 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr)))
2728 /* If the called function is nested in the current one, it might access
2729 some of the caller's arguments, but could clobber them beforehand if
2730 the argument areas are shared. */
2731 || (fndecl && decl_function_context (fndecl) == current_function_decl)
2732 /* If this function requires more stack slots than the current
2733 function, we cannot change it into a sibling call.
2734 crtl->args.pretend_args_size is not part of the
2735 stack allocated by our caller. */
2736 || args_size.constant > (crtl->args.size
2737 - crtl->args.pretend_args_size)
2738 /* If the callee pops its own arguments, then it must pop exactly
2739 the same number of arguments as the current function. */
2740 || (targetm.calls.return_pops_args (fndecl, funtype, args_size.constant)
2741 != targetm.calls.return_pops_args (current_function_decl,
2742 TREE_TYPE (current_function_decl),
2743 crtl->args.size))
2744 || !lang_hooks.decls.ok_for_sibcall (fndecl))
2745 try_tail_call = 0;
2747 /* Check if caller and callee disagree in promotion of function
2748 return value. */
2749 if (try_tail_call)
2751 machine_mode caller_mode, caller_promoted_mode;
2752 machine_mode callee_mode, callee_promoted_mode;
2753 int caller_unsignedp, callee_unsignedp;
2754 tree caller_res = DECL_RESULT (current_function_decl);
2756 caller_unsignedp = TYPE_UNSIGNED (TREE_TYPE (caller_res));
2757 caller_mode = DECL_MODE (caller_res);
2758 callee_unsignedp = TYPE_UNSIGNED (TREE_TYPE (funtype));
2759 callee_mode = TYPE_MODE (TREE_TYPE (funtype));
2760 caller_promoted_mode
2761 = promote_function_mode (TREE_TYPE (caller_res), caller_mode,
2762 &caller_unsignedp,
2763 TREE_TYPE (current_function_decl), 1);
2764 callee_promoted_mode
2765 = promote_function_mode (TREE_TYPE (funtype), callee_mode,
2766 &callee_unsignedp,
2767 funtype, 1);
2768 if (caller_mode != VOIDmode
2769 && (caller_promoted_mode != callee_promoted_mode
2770 || ((caller_mode != caller_promoted_mode
2771 || callee_mode != callee_promoted_mode)
2772 && (caller_unsignedp != callee_unsignedp
2773 || GET_MODE_BITSIZE (caller_mode)
2774 < GET_MODE_BITSIZE (callee_mode)))))
2775 try_tail_call = 0;
2778 /* Ensure current function's preferred stack boundary is at least
2779 what we need. Stack alignment may also increase preferred stack
2780 boundary. */
2781 if (crtl->preferred_stack_boundary < preferred_stack_boundary)
2782 crtl->preferred_stack_boundary = preferred_stack_boundary;
2783 else
2784 preferred_stack_boundary = crtl->preferred_stack_boundary;
2786 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
2788 /* We want to make two insn chains; one for a sibling call, the other
2789 for a normal call. We will select one of the two chains after
2790 initial RTL generation is complete. */
2791 for (pass = try_tail_call ? 0 : 1; pass < 2; pass++)
2793 int sibcall_failure = 0;
2794 /* We want to emit any pending stack adjustments before the tail
2795 recursion "call". That way we know any adjustment after the tail
2796 recursion call can be ignored if we indeed use the tail
2797 call expansion. */
2798 saved_pending_stack_adjust save;
2799 rtx_insn *insns, *before_call, *after_args;
2800 rtx next_arg_reg;
2802 if (pass == 0)
2804 /* State variables we need to save and restore between
2805 iterations. */
2806 save_pending_stack_adjust (&save);
2808 if (pass)
2809 flags &= ~ECF_SIBCALL;
2810 else
2811 flags |= ECF_SIBCALL;
2813 /* Other state variables that we must reinitialize each time
2814 through the loop (that are not initialized by the loop itself). */
2815 argblock = 0;
2816 call_fusage = 0;
2818 /* Start a new sequence for the normal call case.
2820 From this point on, if the sibling call fails, we want to set
2821 sibcall_failure instead of continuing the loop. */
2822 start_sequence ();
2824 /* Don't let pending stack adjusts add up to too much.
2825 Also, do all pending adjustments now if there is any chance
2826 this might be a call to alloca or if we are expanding a sibling
2827 call sequence.
2828 Also do the adjustments before a throwing call, otherwise
2829 exception handling can fail; PR 19225. */
2830 if (pending_stack_adjust >= 32
2831 || (pending_stack_adjust > 0
2832 && (flags & ECF_MAY_BE_ALLOCA))
2833 || (pending_stack_adjust > 0
2834 && flag_exceptions && !(flags & ECF_NOTHROW))
2835 || pass == 0)
2836 do_pending_stack_adjust ();
2838 /* Precompute any arguments as needed. */
2839 if (pass)
2840 precompute_arguments (num_actuals, args);
2842 /* Now we are about to start emitting insns that can be deleted
2843 if a libcall is deleted. */
2844 if (pass && (flags & ECF_MALLOC))
2845 start_sequence ();
2847 if (pass == 0 && crtl->stack_protect_guard)
2848 stack_protect_epilogue ();
2850 adjusted_args_size = args_size;
2851 /* Compute the actual size of the argument block required. The variable
2852 and constant sizes must be combined, the size may have to be rounded,
2853 and there may be a minimum required size. When generating a sibcall
2854 pattern, do not round up, since we'll be re-using whatever space our
2855 caller provided. */
2856 unadjusted_args_size
2857 = compute_argument_block_size (reg_parm_stack_space,
2858 &adjusted_args_size,
2859 fndecl, fntype,
2860 (pass == 0 ? 0
2861 : preferred_stack_boundary));
2863 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
2865 /* The argument block when performing a sibling call is the
2866 incoming argument block. */
2867 if (pass == 0)
2869 argblock = crtl->args.internal_arg_pointer;
2870 argblock
2871 #ifdef STACK_GROWS_DOWNWARD
2872 = plus_constant (Pmode, argblock, crtl->args.pretend_args_size);
2873 #else
2874 = plus_constant (Pmode, argblock, -crtl->args.pretend_args_size);
2875 #endif
2876 stored_args_map = sbitmap_alloc (args_size.constant);
2877 bitmap_clear (stored_args_map);
2880 /* If we have no actual push instructions, or shouldn't use them,
2881 make space for all args right now. */
2882 else if (adjusted_args_size.var != 0)
2884 if (old_stack_level == 0)
2886 emit_stack_save (SAVE_BLOCK, &old_stack_level);
2887 old_stack_pointer_delta = stack_pointer_delta;
2888 old_pending_adj = pending_stack_adjust;
2889 pending_stack_adjust = 0;
2890 /* stack_arg_under_construction says whether a stack arg is
2891 being constructed at the old stack level. Pushing the stack
2892 gets a clean outgoing argument block. */
2893 old_stack_arg_under_construction = stack_arg_under_construction;
2894 stack_arg_under_construction = 0;
2896 argblock = push_block (ARGS_SIZE_RTX (adjusted_args_size), 0, 0);
2897 if (flag_stack_usage_info)
2898 current_function_has_unbounded_dynamic_stack_size = 1;
2900 else
2902 /* Note that we must go through the motions of allocating an argument
2903 block even if the size is zero because we may be storing args
2904 in the area reserved for register arguments, which may be part of
2905 the stack frame. */
2907 int needed = adjusted_args_size.constant;
2909 /* Store the maximum argument space used. It will be pushed by
2910 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2911 checking). */
2913 if (needed > crtl->outgoing_args_size)
2914 crtl->outgoing_args_size = needed;
2916 if (must_preallocate)
2918 if (ACCUMULATE_OUTGOING_ARGS)
2920 /* Since the stack pointer will never be pushed, it is
2921 possible for the evaluation of a parm to clobber
2922 something we have already written to the stack.
2923 Since most function calls on RISC machines do not use
2924 the stack, this is uncommon, but must work correctly.
2926 Therefore, we save any area of the stack that was already
2927 written and that we are using. Here we set up to do this
2928 by making a new stack usage map from the old one. The
2929 actual save will be done by store_one_arg.
2931 Another approach might be to try to reorder the argument
2932 evaluations to avoid this conflicting stack usage. */
2934 /* Since we will be writing into the entire argument area,
2935 the map must be allocated for its entire size, not just
2936 the part that is the responsibility of the caller. */
2937 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
2938 needed += reg_parm_stack_space;
2940 #ifdef ARGS_GROW_DOWNWARD
2941 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2942 needed + 1);
2943 #else
2944 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2945 needed);
2946 #endif
2947 free (stack_usage_map_buf);
2948 stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
2949 stack_usage_map = stack_usage_map_buf;
2951 if (initial_highest_arg_in_use)
2952 memcpy (stack_usage_map, initial_stack_usage_map,
2953 initial_highest_arg_in_use);
2955 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2956 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
2957 (highest_outgoing_arg_in_use
2958 - initial_highest_arg_in_use));
2959 needed = 0;
2961 /* The address of the outgoing argument list must not be
2962 copied to a register here, because argblock would be left
2963 pointing to the wrong place after the call to
2964 allocate_dynamic_stack_space below. */
2966 argblock = virtual_outgoing_args_rtx;
2968 else
2970 if (inhibit_defer_pop == 0)
2972 /* Try to reuse some or all of the pending_stack_adjust
2973 to get this space. */
2974 needed
2975 = (combine_pending_stack_adjustment_and_call
2976 (unadjusted_args_size,
2977 &adjusted_args_size,
2978 preferred_unit_stack_boundary));
2980 /* combine_pending_stack_adjustment_and_call computes
2981 an adjustment before the arguments are allocated.
2982 Account for them and see whether or not the stack
2983 needs to go up or down. */
2984 needed = unadjusted_args_size - needed;
2986 if (needed < 0)
2988 /* We're releasing stack space. */
2989 /* ??? We can avoid any adjustment at all if we're
2990 already aligned. FIXME. */
2991 pending_stack_adjust = -needed;
2992 do_pending_stack_adjust ();
2993 needed = 0;
2995 else
2996 /* We need to allocate space. We'll do that in
2997 push_block below. */
2998 pending_stack_adjust = 0;
3001 /* Special case this because overhead of `push_block' in
3002 this case is non-trivial. */
3003 if (needed == 0)
3004 argblock = virtual_outgoing_args_rtx;
3005 else
3007 argblock = push_block (GEN_INT (needed), 0, 0);
3008 #ifdef ARGS_GROW_DOWNWARD
3009 argblock = plus_constant (Pmode, argblock, needed);
3010 #endif
3013 /* We only really need to call `copy_to_reg' in the case
3014 where push insns are going to be used to pass ARGBLOCK
3015 to a function call in ARGS. In that case, the stack
3016 pointer changes value from the allocation point to the
3017 call point, and hence the value of
3018 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
3019 as well always do it. */
3020 argblock = copy_to_reg (argblock);
3025 if (ACCUMULATE_OUTGOING_ARGS)
3027 /* The save/restore code in store_one_arg handles all
3028 cases except one: a constructor call (including a C
3029 function returning a BLKmode struct) to initialize
3030 an argument. */
3031 if (stack_arg_under_construction)
3033 rtx push_size
3034 = GEN_INT (adjusted_args_size.constant
3035 + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype
3036 : TREE_TYPE (fndecl))) ? 0
3037 : reg_parm_stack_space));
3038 if (old_stack_level == 0)
3040 emit_stack_save (SAVE_BLOCK, &old_stack_level);
3041 old_stack_pointer_delta = stack_pointer_delta;
3042 old_pending_adj = pending_stack_adjust;
3043 pending_stack_adjust = 0;
3044 /* stack_arg_under_construction says whether a stack
3045 arg is being constructed at the old stack level.
3046 Pushing the stack gets a clean outgoing argument
3047 block. */
3048 old_stack_arg_under_construction
3049 = stack_arg_under_construction;
3050 stack_arg_under_construction = 0;
3051 /* Make a new map for the new argument list. */
3052 free (stack_usage_map_buf);
3053 stack_usage_map_buf = XCNEWVEC (char, highest_outgoing_arg_in_use);
3054 stack_usage_map = stack_usage_map_buf;
3055 highest_outgoing_arg_in_use = 0;
3057 /* We can pass TRUE as the 4th argument because we just
3058 saved the stack pointer and will restore it right after
3059 the call. */
3060 allocate_dynamic_stack_space (push_size, 0,
3061 BIGGEST_ALIGNMENT, true);
3064 /* If argument evaluation might modify the stack pointer,
3065 copy the address of the argument list to a register. */
3066 for (i = 0; i < num_actuals; i++)
3067 if (args[i].pass_on_stack)
3069 argblock = copy_addr_to_reg (argblock);
3070 break;
3074 compute_argument_addresses (args, argblock, num_actuals);
3076 /* Perform stack alignment before the first push (the last arg). */
3077 if (argblock == 0
3078 && adjusted_args_size.constant > reg_parm_stack_space
3079 && adjusted_args_size.constant != unadjusted_args_size)
3081 /* When the stack adjustment is pending, we get better code
3082 by combining the adjustments. */
3083 if (pending_stack_adjust
3084 && ! inhibit_defer_pop)
3086 pending_stack_adjust
3087 = (combine_pending_stack_adjustment_and_call
3088 (unadjusted_args_size,
3089 &adjusted_args_size,
3090 preferred_unit_stack_boundary));
3091 do_pending_stack_adjust ();
3093 else if (argblock == 0)
3094 anti_adjust_stack (GEN_INT (adjusted_args_size.constant
3095 - unadjusted_args_size));
3097 /* Now that the stack is properly aligned, pops can't safely
3098 be deferred during the evaluation of the arguments. */
3099 NO_DEFER_POP;
3101 /* Record the maximum pushed stack space size. We need to delay
3102 doing it this far to take into account the optimization done
3103 by combine_pending_stack_adjustment_and_call. */
3104 if (flag_stack_usage_info
3105 && !ACCUMULATE_OUTGOING_ARGS
3106 && pass
3107 && adjusted_args_size.var == 0)
3109 int pushed = adjusted_args_size.constant + pending_stack_adjust;
3110 if (pushed > current_function_pushed_stack_size)
3111 current_function_pushed_stack_size = pushed;
3114 funexp = rtx_for_function_call (fndecl, addr);
3116 /* Precompute all register parameters. It isn't safe to compute anything
3117 once we have started filling any specific hard regs. */
3118 precompute_register_parameters (num_actuals, args, &reg_parm_seen);
3120 if (CALL_EXPR_STATIC_CHAIN (exp))
3121 static_chain_value = expand_normal (CALL_EXPR_STATIC_CHAIN (exp));
3122 else
3123 static_chain_value = 0;
3125 #ifdef REG_PARM_STACK_SPACE
3126 /* Save the fixed argument area if it's part of the caller's frame and
3127 is clobbered by argument setup for this call. */
3128 if (ACCUMULATE_OUTGOING_ARGS && pass)
3129 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
3130 &low_to_save, &high_to_save);
3131 #endif
3133 /* Now store (and compute if necessary) all non-register parms.
3134 These come before register parms, since they can require block-moves,
3135 which could clobber the registers used for register parms.
3136 Parms which have partial registers are not stored here,
3137 but we do preallocate space here if they want that. */
3139 for (i = 0; i < num_actuals; i++)
3141 /* Delay bounds until all other args are stored. */
3142 if (POINTER_BOUNDS_P (args[i].tree_value))
3143 continue;
3144 else if (args[i].reg == 0 || args[i].pass_on_stack)
3146 rtx_insn *before_arg = get_last_insn ();
3148 /* We don't allow passing huge (> 2^30 B) arguments
3149 by value. It would cause an overflow later on. */
3150 if (adjusted_args_size.constant
3151 >= (1 << (HOST_BITS_PER_INT - 2)))
3153 sorry ("passing too large argument on stack");
3154 continue;
3157 if (store_one_arg (&args[i], argblock, flags,
3158 adjusted_args_size.var != 0,
3159 reg_parm_stack_space)
3160 || (pass == 0
3161 && check_sibcall_argument_overlap (before_arg,
3162 &args[i], 1)))
3163 sibcall_failure = 1;
3166 if (args[i].stack)
3167 call_fusage
3168 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
3169 gen_rtx_USE (VOIDmode, args[i].stack),
3170 call_fusage);
3173 /* If we have a parm that is passed in registers but not in memory
3174 and whose alignment does not permit a direct copy into registers,
3175 make a group of pseudos that correspond to each register that we
3176 will later fill. */
3177 if (STRICT_ALIGNMENT)
3178 store_unaligned_arguments_into_pseudos (args, num_actuals);
3180 /* Now store any partially-in-registers parm.
3181 This is the last place a block-move can happen. */
3182 if (reg_parm_seen)
3183 for (i = 0; i < num_actuals; i++)
3184 if (args[i].partial != 0 && ! args[i].pass_on_stack)
3186 rtx_insn *before_arg = get_last_insn ();
3188 if (store_one_arg (&args[i], argblock, flags,
3189 adjusted_args_size.var != 0,
3190 reg_parm_stack_space)
3191 || (pass == 0
3192 && check_sibcall_argument_overlap (before_arg,
3193 &args[i], 1)))
3194 sibcall_failure = 1;
3197 bool any_regs = false;
3198 for (i = 0; i < num_actuals; i++)
3199 if (args[i].reg != NULL_RTX)
3201 any_regs = true;
3202 targetm.calls.call_args (args[i].reg, funtype);
3204 if (!any_regs)
3205 targetm.calls.call_args (pc_rtx, funtype);
3207 /* Figure out the register where the value, if any, will come back. */
3208 valreg = 0;
3209 valbnd = 0;
3210 if (TYPE_MODE (rettype) != VOIDmode
3211 && ! structure_value_addr)
3213 if (pcc_struct_value)
3215 valreg = hard_function_value (build_pointer_type (rettype),
3216 fndecl, NULL, (pass == 0));
3217 if (CALL_WITH_BOUNDS_P (exp))
3218 valbnd = targetm.calls.
3219 chkp_function_value_bounds (build_pointer_type (rettype),
3220 fndecl, (pass == 0));
3222 else
3224 valreg = hard_function_value (rettype, fndecl, fntype,
3225 (pass == 0));
3226 if (CALL_WITH_BOUNDS_P (exp))
3227 valbnd = targetm.calls.chkp_function_value_bounds (rettype,
3228 fndecl,
3229 (pass == 0));
3232 /* If VALREG is a PARALLEL whose first member has a zero
3233 offset, use that. This is for targets such as m68k that
3234 return the same value in multiple places. */
3235 if (GET_CODE (valreg) == PARALLEL)
3237 rtx elem = XVECEXP (valreg, 0, 0);
3238 rtx where = XEXP (elem, 0);
3239 rtx offset = XEXP (elem, 1);
3240 if (offset == const0_rtx
3241 && GET_MODE (where) == GET_MODE (valreg))
3242 valreg = where;
3246 /* Store all bounds not passed in registers. */
3247 for (i = 0; i < num_actuals; i++)
3249 if (POINTER_BOUNDS_P (args[i].tree_value)
3250 && !args[i].reg)
3251 store_bounds (&args[i],
3252 args[i].pointer_arg == -1
3253 ? NULL
3254 : &args[args[i].pointer_arg]);
3257 /* If register arguments require space on the stack and stack space
3258 was not preallocated, allocate stack space here for arguments
3259 passed in registers. */
3260 if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
3261 && !ACCUMULATE_OUTGOING_ARGS
3262 && must_preallocate == 0 && reg_parm_stack_space > 0)
3263 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
3265 /* Pass the function the address in which to return a
3266 structure value. */
3267 if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
3269 structure_value_addr
3270 = convert_memory_address (Pmode, structure_value_addr);
3271 emit_move_insn (struct_value,
3272 force_reg (Pmode,
3273 force_operand (structure_value_addr,
3274 NULL_RTX)));
3276 if (REG_P (struct_value))
3277 use_reg (&call_fusage, struct_value);
3280 after_args = get_last_insn ();
3281 funexp = prepare_call_address (fndecl, funexp, static_chain_value,
3282 &call_fusage, reg_parm_seen, pass == 0);
3284 load_register_parameters (args, num_actuals, &call_fusage, flags,
3285 pass == 0, &sibcall_failure);
3287 /* Save a pointer to the last insn before the call, so that we can
3288 later safely search backwards to find the CALL_INSN. */
3289 before_call = get_last_insn ();
3291 /* Set up next argument register. For sibling calls on machines
3292 with register windows this should be the incoming register. */
3293 if (pass == 0)
3294 next_arg_reg = targetm.calls.function_incoming_arg (args_so_far,
3295 VOIDmode,
3296 void_type_node,
3297 true);
3298 else
3299 next_arg_reg = targetm.calls.function_arg (args_so_far,
3300 VOIDmode, void_type_node,
3301 true);
3303 if (pass == 1 && (return_flags & ERF_RETURNS_ARG))
3305 int arg_nr = return_flags & ERF_RETURN_ARG_MASK;
3306 arg_nr = num_actuals - arg_nr - 1;
3307 if (arg_nr >= 0
3308 && arg_nr < num_actuals
3309 && args[arg_nr].reg
3310 && valreg
3311 && REG_P (valreg)
3312 && GET_MODE (args[arg_nr].reg) == GET_MODE (valreg))
3313 call_fusage
3314 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[arg_nr].tree_value)),
3315 gen_rtx_SET (VOIDmode, valreg, args[arg_nr].reg),
3316 call_fusage);
3318 /* All arguments and registers used for the call must be set up by
3319 now! */
3321 /* Stack must be properly aligned now. */
3322 gcc_assert (!pass
3323 || !(stack_pointer_delta % preferred_unit_stack_boundary));
3325 /* Generate the actual call instruction. */
3326 emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,
3327 adjusted_args_size.constant, struct_value_size,
3328 next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
3329 flags, args_so_far);
3331 if (flag_use_caller_save)
3333 rtx_call_insn *last;
3334 rtx datum = NULL_RTX;
3335 if (fndecl != NULL_TREE)
3337 datum = XEXP (DECL_RTL (fndecl), 0);
3338 gcc_assert (datum != NULL_RTX
3339 && GET_CODE (datum) == SYMBOL_REF);
3341 last = last_call_insn ();
3342 add_reg_note (last, REG_CALL_DECL, datum);
3345 /* If the call setup or the call itself overlaps with anything
3346 of the argument setup we probably clobbered our call address.
3347 In that case we can't do sibcalls. */
3348 if (pass == 0
3349 && check_sibcall_argument_overlap (after_args, 0, 0))
3350 sibcall_failure = 1;
3352 /* If a non-BLKmode value is returned at the most significant end
3353 of a register, shift the register right by the appropriate amount
3354 and update VALREG accordingly. BLKmode values are handled by the
3355 group load/store machinery below. */
3356 if (!structure_value_addr
3357 && !pcc_struct_value
3358 && TYPE_MODE (rettype) != VOIDmode
3359 && TYPE_MODE (rettype) != BLKmode
3360 && REG_P (valreg)
3361 && targetm.calls.return_in_msb (rettype))
3363 if (shift_return_value (TYPE_MODE (rettype), false, valreg))
3364 sibcall_failure = 1;
3365 valreg = gen_rtx_REG (TYPE_MODE (rettype), REGNO (valreg));
3368 if (pass && (flags & ECF_MALLOC))
3370 rtx temp = gen_reg_rtx (GET_MODE (valreg));
3371 rtx_insn *last, *insns;
3373 /* The return value from a malloc-like function is a pointer. */
3374 if (TREE_CODE (rettype) == POINTER_TYPE)
3375 mark_reg_pointer (temp, MALLOC_ABI_ALIGNMENT);
3377 emit_move_insn (temp, valreg);
3379 /* The return value from a malloc-like function can not alias
3380 anything else. */
3381 last = get_last_insn ();
3382 add_reg_note (last, REG_NOALIAS, temp);
3384 /* Write out the sequence. */
3385 insns = get_insns ();
3386 end_sequence ();
3387 emit_insn (insns);
3388 valreg = temp;
3391 /* For calls to `setjmp', etc., inform
3392 function.c:setjmp_warnings that it should complain if
3393 nonvolatile values are live. For functions that cannot
3394 return, inform flow that control does not fall through. */
3396 if ((flags & ECF_NORETURN) || pass == 0)
3398 /* The barrier must be emitted
3399 immediately after the CALL_INSN. Some ports emit more
3400 than just a CALL_INSN above, so we must search for it here. */
3402 rtx_insn *last = get_last_insn ();
3403 while (!CALL_P (last))
3405 last = PREV_INSN (last);
3406 /* There was no CALL_INSN? */
3407 gcc_assert (last != before_call);
3410 emit_barrier_after (last);
3412 /* Stack adjustments after a noreturn call are dead code.
3413 However when NO_DEFER_POP is in effect, we must preserve
3414 stack_pointer_delta. */
3415 if (inhibit_defer_pop == 0)
3417 stack_pointer_delta = old_stack_allocated;
3418 pending_stack_adjust = 0;
3422 /* If value type not void, return an rtx for the value. */
3424 if (TYPE_MODE (rettype) == VOIDmode
3425 || ignore)
3426 target = const0_rtx;
3427 else if (structure_value_addr)
3429 if (target == 0 || !MEM_P (target))
3431 target
3432 = gen_rtx_MEM (TYPE_MODE (rettype),
3433 memory_address (TYPE_MODE (rettype),
3434 structure_value_addr));
3435 set_mem_attributes (target, rettype, 1);
3438 else if (pcc_struct_value)
3440 /* This is the special C++ case where we need to
3441 know what the true target was. We take care to
3442 never use this value more than once in one expression. */
3443 target = gen_rtx_MEM (TYPE_MODE (rettype),
3444 copy_to_reg (valreg));
3445 set_mem_attributes (target, rettype, 1);
3447 /* Handle calls that return values in multiple non-contiguous locations.
3448 The Irix 6 ABI has examples of this. */
3449 else if (GET_CODE (valreg) == PARALLEL)
3451 if (target == 0)
3452 target = emit_group_move_into_temps (valreg);
3453 else if (rtx_equal_p (target, valreg))
3455 else if (GET_CODE (target) == PARALLEL)
3456 /* Handle the result of a emit_group_move_into_temps
3457 call in the previous pass. */
3458 emit_group_move (target, valreg);
3459 else
3460 emit_group_store (target, valreg, rettype,
3461 int_size_in_bytes (rettype));
3463 else if (target
3464 && GET_MODE (target) == TYPE_MODE (rettype)
3465 && GET_MODE (target) == GET_MODE (valreg))
3467 bool may_overlap = false;
3469 /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
3470 reg to a plain register. */
3471 if (!REG_P (target) || HARD_REGISTER_P (target))
3472 valreg = avoid_likely_spilled_reg (valreg);
3474 /* If TARGET is a MEM in the argument area, and we have
3475 saved part of the argument area, then we can't store
3476 directly into TARGET as it may get overwritten when we
3477 restore the argument save area below. Don't work too
3478 hard though and simply force TARGET to a register if it
3479 is a MEM; the optimizer is quite likely to sort it out. */
3480 if (ACCUMULATE_OUTGOING_ARGS && pass && MEM_P (target))
3481 for (i = 0; i < num_actuals; i++)
3482 if (args[i].save_area)
3484 may_overlap = true;
3485 break;
3488 if (may_overlap)
3489 target = copy_to_reg (valreg);
3490 else
3492 /* TARGET and VALREG cannot be equal at this point
3493 because the latter would not have
3494 REG_FUNCTION_VALUE_P true, while the former would if
3495 it were referring to the same register.
3497 If they refer to the same register, this move will be
3498 a no-op, except when function inlining is being
3499 done. */
3500 emit_move_insn (target, valreg);
3502 /* If we are setting a MEM, this code must be executed.
3503 Since it is emitted after the call insn, sibcall
3504 optimization cannot be performed in that case. */
3505 if (MEM_P (target))
3506 sibcall_failure = 1;
3509 else
3510 target = copy_to_reg (avoid_likely_spilled_reg (valreg));
3512 /* If we promoted this return value, make the proper SUBREG.
3513 TARGET might be const0_rtx here, so be careful. */
3514 if (REG_P (target)
3515 && TYPE_MODE (rettype) != BLKmode
3516 && GET_MODE (target) != TYPE_MODE (rettype))
3518 tree type = rettype;
3519 int unsignedp = TYPE_UNSIGNED (type);
3520 int offset = 0;
3521 machine_mode pmode;
3523 /* Ensure we promote as expected, and get the new unsignedness. */
3524 pmode = promote_function_mode (type, TYPE_MODE (type), &unsignedp,
3525 funtype, 1);
3526 gcc_assert (GET_MODE (target) == pmode);
3528 if ((WORDS_BIG_ENDIAN || BYTES_BIG_ENDIAN)
3529 && (GET_MODE_SIZE (GET_MODE (target))
3530 > GET_MODE_SIZE (TYPE_MODE (type))))
3532 offset = GET_MODE_SIZE (GET_MODE (target))
3533 - GET_MODE_SIZE (TYPE_MODE (type));
3534 if (! BYTES_BIG_ENDIAN)
3535 offset = (offset / UNITS_PER_WORD) * UNITS_PER_WORD;
3536 else if (! WORDS_BIG_ENDIAN)
3537 offset %= UNITS_PER_WORD;
3540 target = gen_rtx_SUBREG (TYPE_MODE (type), target, offset);
3541 SUBREG_PROMOTED_VAR_P (target) = 1;
3542 SUBREG_PROMOTED_SET (target, unsignedp);
3545 /* If size of args is variable or this was a constructor call for a stack
3546 argument, restore saved stack-pointer value. */
3548 if (old_stack_level)
3550 rtx_insn *prev = get_last_insn ();
3552 emit_stack_restore (SAVE_BLOCK, old_stack_level);
3553 stack_pointer_delta = old_stack_pointer_delta;
3555 fixup_args_size_notes (prev, get_last_insn (), stack_pointer_delta);
3557 pending_stack_adjust = old_pending_adj;
3558 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
3559 stack_arg_under_construction = old_stack_arg_under_construction;
3560 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3561 stack_usage_map = initial_stack_usage_map;
3562 sibcall_failure = 1;
3564 else if (ACCUMULATE_OUTGOING_ARGS && pass)
3566 #ifdef REG_PARM_STACK_SPACE
3567 if (save_area)
3568 restore_fixed_argument_area (save_area, argblock,
3569 high_to_save, low_to_save);
3570 #endif
3572 /* If we saved any argument areas, restore them. */
3573 for (i = 0; i < num_actuals; i++)
3574 if (args[i].save_area)
3576 machine_mode save_mode = GET_MODE (args[i].save_area);
3577 rtx stack_area
3578 = gen_rtx_MEM (save_mode,
3579 memory_address (save_mode,
3580 XEXP (args[i].stack_slot, 0)));
3582 if (save_mode != BLKmode)
3583 emit_move_insn (stack_area, args[i].save_area);
3584 else
3585 emit_block_move (stack_area, args[i].save_area,
3586 GEN_INT (args[i].locate.size.constant),
3587 BLOCK_OP_CALL_PARM);
3590 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3591 stack_usage_map = initial_stack_usage_map;
3594 /* If this was alloca, record the new stack level for nonlocal gotos.
3595 Check for the handler slots since we might not have a save area
3596 for non-local gotos. */
3598 if ((flags & ECF_MAY_BE_ALLOCA) && cfun->nonlocal_goto_save_area != 0)
3599 update_nonlocal_goto_save_area ();
3601 /* Free up storage we no longer need. */
3602 for (i = 0; i < num_actuals; ++i)
3603 free (args[i].aligned_regs);
3605 targetm.calls.end_call_args ();
3607 insns = get_insns ();
3608 end_sequence ();
3610 if (pass == 0)
3612 tail_call_insns = insns;
3614 /* Restore the pending stack adjustment now that we have
3615 finished generating the sibling call sequence. */
3617 restore_pending_stack_adjust (&save);
3619 /* Prepare arg structure for next iteration. */
3620 for (i = 0; i < num_actuals; i++)
3622 args[i].value = 0;
3623 args[i].aligned_regs = 0;
3624 args[i].stack = 0;
3627 sbitmap_free (stored_args_map);
3628 internal_arg_pointer_exp_state.scan_start = NULL;
3629 internal_arg_pointer_exp_state.cache.release ();
3631 else
3633 normal_call_insns = insns;
3635 /* Verify that we've deallocated all the stack we used. */
3636 gcc_assert ((flags & ECF_NORETURN)
3637 || (old_stack_allocated
3638 == stack_pointer_delta - pending_stack_adjust));
3641 /* If something prevents making this a sibling call,
3642 zero out the sequence. */
3643 if (sibcall_failure)
3644 tail_call_insns = NULL;
3645 else
3646 break;
3649 /* If tail call production succeeded, we need to remove REG_EQUIV notes on
3650 arguments too, as argument area is now clobbered by the call. */
3651 if (tail_call_insns)
3653 emit_insn (tail_call_insns);
3654 crtl->tail_call_emit = true;
3656 else
3657 emit_insn (normal_call_insns);
3659 currently_expanding_call--;
3661 free (stack_usage_map_buf);
3663 /* Join result with returned bounds so caller may use them if needed. */
3664 target = chkp_join_splitted_slot (target, valbnd);
3666 return target;
3669 /* A sibling call sequence invalidates any REG_EQUIV notes made for
3670 this function's incoming arguments.
3672 At the start of RTL generation we know the only REG_EQUIV notes
3673 in the rtl chain are those for incoming arguments, so we can look
3674 for REG_EQUIV notes between the start of the function and the
3675 NOTE_INSN_FUNCTION_BEG.
3677 This is (slight) overkill. We could keep track of the highest
3678 argument we clobber and be more selective in removing notes, but it
3679 does not seem to be worth the effort. */
3681 void
3682 fixup_tail_calls (void)
3684 rtx_insn *insn;
3686 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3688 rtx note;
3690 /* There are never REG_EQUIV notes for the incoming arguments
3691 after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
3692 if (NOTE_P (insn)
3693 && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
3694 break;
3696 note = find_reg_note (insn, REG_EQUIV, 0);
3697 if (note)
3698 remove_note (insn, note);
3699 note = find_reg_note (insn, REG_EQUIV, 0);
3700 gcc_assert (!note);
3704 /* Traverse a list of TYPES and expand all complex types into their
3705 components. */
3706 static tree
3707 split_complex_types (tree types)
3709 tree p;
3711 /* Before allocating memory, check for the common case of no complex. */
3712 for (p = types; p; p = TREE_CHAIN (p))
3714 tree type = TREE_VALUE (p);
3715 if (TREE_CODE (type) == COMPLEX_TYPE
3716 && targetm.calls.split_complex_arg (type))
3717 goto found;
3719 return types;
3721 found:
3722 types = copy_list (types);
3724 for (p = types; p; p = TREE_CHAIN (p))
3726 tree complex_type = TREE_VALUE (p);
3728 if (TREE_CODE (complex_type) == COMPLEX_TYPE
3729 && targetm.calls.split_complex_arg (complex_type))
3731 tree next, imag;
3733 /* Rewrite complex type with component type. */
3734 TREE_VALUE (p) = TREE_TYPE (complex_type);
3735 next = TREE_CHAIN (p);
3737 /* Add another component type for the imaginary part. */
3738 imag = build_tree_list (NULL_TREE, TREE_VALUE (p));
3739 TREE_CHAIN (p) = imag;
3740 TREE_CHAIN (imag) = next;
3742 /* Skip the newly created node. */
3743 p = TREE_CHAIN (p);
3747 return types;
3750 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3751 The RETVAL parameter specifies whether return value needs to be saved, other
3752 parameters are documented in the emit_library_call function below. */
3754 static rtx
3755 emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
3756 enum libcall_type fn_type,
3757 machine_mode outmode, int nargs, va_list p)
3759 /* Total size in bytes of all the stack-parms scanned so far. */
3760 struct args_size args_size;
3761 /* Size of arguments before any adjustments (such as rounding). */
3762 struct args_size original_args_size;
3763 int argnum;
3764 rtx fun;
3765 /* Todo, choose the correct decl type of orgfun. Sadly this information
3766 isn't present here, so we default to native calling abi here. */
3767 tree fndecl ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
3768 tree fntype ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
3769 int count;
3770 rtx argblock = 0;
3771 CUMULATIVE_ARGS args_so_far_v;
3772 cumulative_args_t args_so_far;
3773 struct arg
3775 rtx value;
3776 machine_mode mode;
3777 rtx reg;
3778 int partial;
3779 struct locate_and_pad_arg_data locate;
3780 rtx save_area;
3782 struct arg *argvec;
3783 int old_inhibit_defer_pop = inhibit_defer_pop;
3784 rtx call_fusage = 0;
3785 rtx mem_value = 0;
3786 rtx valreg;
3787 int pcc_struct_value = 0;
3788 int struct_value_size = 0;
3789 int flags;
3790 int reg_parm_stack_space = 0;
3791 int needed;
3792 rtx_insn *before_call;
3793 tree tfom; /* type_for_mode (outmode, 0) */
3795 #ifdef REG_PARM_STACK_SPACE
3796 /* Define the boundary of the register parm stack space that needs to be
3797 save, if any. */
3798 int low_to_save = 0, high_to_save = 0;
3799 rtx save_area = 0; /* Place that it is saved. */
3800 #endif
3802 /* Size of the stack reserved for parameter registers. */
3803 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3804 char *initial_stack_usage_map = stack_usage_map;
3805 char *stack_usage_map_buf = NULL;
3807 rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
3809 #ifdef REG_PARM_STACK_SPACE
3810 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3811 #endif
3813 /* By default, library functions can not throw. */
3814 flags = ECF_NOTHROW;
3816 switch (fn_type)
3818 case LCT_NORMAL:
3819 break;
3820 case LCT_CONST:
3821 flags |= ECF_CONST;
3822 break;
3823 case LCT_PURE:
3824 flags |= ECF_PURE;
3825 break;
3826 case LCT_NORETURN:
3827 flags |= ECF_NORETURN;
3828 break;
3829 case LCT_THROW:
3830 flags = ECF_NORETURN;
3831 break;
3832 case LCT_RETURNS_TWICE:
3833 flags = ECF_RETURNS_TWICE;
3834 break;
3836 fun = orgfun;
3838 /* Ensure current function's preferred stack boundary is at least
3839 what we need. */
3840 if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3841 crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3843 /* If this kind of value comes back in memory,
3844 decide where in memory it should come back. */
3845 if (outmode != VOIDmode)
3847 tfom = lang_hooks.types.type_for_mode (outmode, 0);
3848 if (aggregate_value_p (tfom, 0))
3850 #ifdef PCC_STATIC_STRUCT_RETURN
3851 rtx pointer_reg
3852 = hard_function_value (build_pointer_type (tfom), 0, 0, 0);
3853 mem_value = gen_rtx_MEM (outmode, pointer_reg);
3854 pcc_struct_value = 1;
3855 if (value == 0)
3856 value = gen_reg_rtx (outmode);
3857 #else /* not PCC_STATIC_STRUCT_RETURN */
3858 struct_value_size = GET_MODE_SIZE (outmode);
3859 if (value != 0 && MEM_P (value))
3860 mem_value = value;
3861 else
3862 mem_value = assign_temp (tfom, 1, 1);
3863 #endif
3864 /* This call returns a big structure. */
3865 flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
3868 else
3869 tfom = void_type_node;
3871 /* ??? Unfinished: must pass the memory address as an argument. */
3873 /* Copy all the libcall-arguments out of the varargs data
3874 and into a vector ARGVEC.
3876 Compute how to pass each argument. We only support a very small subset
3877 of the full argument passing conventions to limit complexity here since
3878 library functions shouldn't have many args. */
3880 argvec = XALLOCAVEC (struct arg, nargs + 1);
3881 memset (argvec, 0, (nargs + 1) * sizeof (struct arg));
3883 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3884 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v, outmode, fun);
3885 #else
3886 INIT_CUMULATIVE_ARGS (args_so_far_v, NULL_TREE, fun, 0, nargs);
3887 #endif
3888 args_so_far = pack_cumulative_args (&args_so_far_v);
3890 args_size.constant = 0;
3891 args_size.var = 0;
3893 count = 0;
3895 push_temp_slots ();
3897 /* If there's a structure value address to be passed,
3898 either pass it in the special place, or pass it as an extra argument. */
3899 if (mem_value && struct_value == 0 && ! pcc_struct_value)
3901 rtx addr = XEXP (mem_value, 0);
3903 nargs++;
3905 /* Make sure it is a reasonable operand for a move or push insn. */
3906 if (!REG_P (addr) && !MEM_P (addr)
3907 && !(CONSTANT_P (addr)
3908 && targetm.legitimate_constant_p (Pmode, addr)))
3909 addr = force_operand (addr, NULL_RTX);
3911 argvec[count].value = addr;
3912 argvec[count].mode = Pmode;
3913 argvec[count].partial = 0;
3915 argvec[count].reg = targetm.calls.function_arg (args_so_far,
3916 Pmode, NULL_TREE, true);
3917 gcc_assert (targetm.calls.arg_partial_bytes (args_so_far, Pmode,
3918 NULL_TREE, 1) == 0);
3920 locate_and_pad_parm (Pmode, NULL_TREE,
3921 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3923 #else
3924 argvec[count].reg != 0,
3925 #endif
3926 reg_parm_stack_space, 0,
3927 NULL_TREE, &args_size, &argvec[count].locate);
3929 if (argvec[count].reg == 0 || argvec[count].partial != 0
3930 || reg_parm_stack_space > 0)
3931 args_size.constant += argvec[count].locate.size.constant;
3933 targetm.calls.function_arg_advance (args_so_far, Pmode, (tree) 0, true);
3935 count++;
3938 for (; count < nargs; count++)
3940 rtx val = va_arg (p, rtx);
3941 machine_mode mode = (machine_mode) va_arg (p, int);
3942 int unsigned_p = 0;
3944 /* We cannot convert the arg value to the mode the library wants here;
3945 must do it earlier where we know the signedness of the arg. */
3946 gcc_assert (mode != BLKmode
3947 && (GET_MODE (val) == mode || GET_MODE (val) == VOIDmode));
3949 /* Make sure it is a reasonable operand for a move or push insn. */
3950 if (!REG_P (val) && !MEM_P (val)
3951 && !(CONSTANT_P (val) && targetm.legitimate_constant_p (mode, val)))
3952 val = force_operand (val, NULL_RTX);
3954 if (pass_by_reference (&args_so_far_v, mode, NULL_TREE, 1))
3956 rtx slot;
3957 int must_copy
3958 = !reference_callee_copied (&args_so_far_v, mode, NULL_TREE, 1);
3960 /* If this was a CONST function, it is now PURE since it now
3961 reads memory. */
3962 if (flags & ECF_CONST)
3964 flags &= ~ECF_CONST;
3965 flags |= ECF_PURE;
3968 if (MEM_P (val) && !must_copy)
3970 tree val_expr = MEM_EXPR (val);
3971 if (val_expr)
3972 mark_addressable (val_expr);
3973 slot = val;
3975 else
3977 slot = assign_temp (lang_hooks.types.type_for_mode (mode, 0),
3978 1, 1);
3979 emit_move_insn (slot, val);
3982 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
3983 gen_rtx_USE (VOIDmode, slot),
3984 call_fusage);
3985 if (must_copy)
3986 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
3987 gen_rtx_CLOBBER (VOIDmode,
3988 slot),
3989 call_fusage);
3991 mode = Pmode;
3992 val = force_operand (XEXP (slot, 0), NULL_RTX);
3995 mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0);
3996 argvec[count].mode = mode;
3997 argvec[count].value = convert_modes (mode, GET_MODE (val), val, unsigned_p);
3998 argvec[count].reg = targetm.calls.function_arg (args_so_far, mode,
3999 NULL_TREE, true);
4001 argvec[count].partial
4002 = targetm.calls.arg_partial_bytes (args_so_far, mode, NULL_TREE, 1);
4004 if (argvec[count].reg == 0
4005 || argvec[count].partial != 0
4006 || reg_parm_stack_space > 0)
4008 locate_and_pad_parm (mode, NULL_TREE,
4009 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4011 #else
4012 argvec[count].reg != 0,
4013 #endif
4014 reg_parm_stack_space, argvec[count].partial,
4015 NULL_TREE, &args_size, &argvec[count].locate);
4016 args_size.constant += argvec[count].locate.size.constant;
4017 gcc_assert (!argvec[count].locate.size.var);
4019 #ifdef BLOCK_REG_PADDING
4020 else
4021 /* The argument is passed entirely in registers. See at which
4022 end it should be padded. */
4023 argvec[count].locate.where_pad =
4024 BLOCK_REG_PADDING (mode, NULL_TREE,
4025 GET_MODE_SIZE (mode) <= UNITS_PER_WORD);
4026 #endif
4028 targetm.calls.function_arg_advance (args_so_far, mode, (tree) 0, true);
4031 /* If this machine requires an external definition for library
4032 functions, write one out. */
4033 assemble_external_libcall (fun);
4035 original_args_size = args_size;
4036 args_size.constant = (((args_size.constant
4037 + stack_pointer_delta
4038 + STACK_BYTES - 1)
4039 / STACK_BYTES
4040 * STACK_BYTES)
4041 - stack_pointer_delta);
4043 args_size.constant = MAX (args_size.constant,
4044 reg_parm_stack_space);
4046 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
4047 args_size.constant -= reg_parm_stack_space;
4049 if (args_size.constant > crtl->outgoing_args_size)
4050 crtl->outgoing_args_size = args_size.constant;
4052 if (flag_stack_usage_info && !ACCUMULATE_OUTGOING_ARGS)
4054 int pushed = args_size.constant + pending_stack_adjust;
4055 if (pushed > current_function_pushed_stack_size)
4056 current_function_pushed_stack_size = pushed;
4059 if (ACCUMULATE_OUTGOING_ARGS)
4061 /* Since the stack pointer will never be pushed, it is possible for
4062 the evaluation of a parm to clobber something we have already
4063 written to the stack. Since most function calls on RISC machines
4064 do not use the stack, this is uncommon, but must work correctly.
4066 Therefore, we save any area of the stack that was already written
4067 and that we are using. Here we set up to do this by making a new
4068 stack usage map from the old one.
4070 Another approach might be to try to reorder the argument
4071 evaluations to avoid this conflicting stack usage. */
4073 needed = args_size.constant;
4075 /* Since we will be writing into the entire argument area, the
4076 map must be allocated for its entire size, not just the part that
4077 is the responsibility of the caller. */
4078 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
4079 needed += reg_parm_stack_space;
4081 #ifdef ARGS_GROW_DOWNWARD
4082 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
4083 needed + 1);
4084 #else
4085 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
4086 needed);
4087 #endif
4088 stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
4089 stack_usage_map = stack_usage_map_buf;
4091 if (initial_highest_arg_in_use)
4092 memcpy (stack_usage_map, initial_stack_usage_map,
4093 initial_highest_arg_in_use);
4095 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
4096 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
4097 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
4098 needed = 0;
4100 /* We must be careful to use virtual regs before they're instantiated,
4101 and real regs afterwards. Loop optimization, for example, can create
4102 new libcalls after we've instantiated the virtual regs, and if we
4103 use virtuals anyway, they won't match the rtl patterns. */
4105 if (virtuals_instantiated)
4106 argblock = plus_constant (Pmode, stack_pointer_rtx,
4107 STACK_POINTER_OFFSET);
4108 else
4109 argblock = virtual_outgoing_args_rtx;
4111 else
4113 if (!PUSH_ARGS)
4114 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
4117 /* We push args individually in reverse order, perform stack alignment
4118 before the first push (the last arg). */
4119 if (argblock == 0)
4120 anti_adjust_stack (GEN_INT (args_size.constant
4121 - original_args_size.constant));
4123 argnum = nargs - 1;
4125 #ifdef REG_PARM_STACK_SPACE
4126 if (ACCUMULATE_OUTGOING_ARGS)
4128 /* The argument list is the property of the called routine and it
4129 may clobber it. If the fixed area has been used for previous
4130 parameters, we must save and restore it. */
4131 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
4132 &low_to_save, &high_to_save);
4134 #endif
4136 /* When expanding a normal call, args are stored in push order,
4137 which is the reverse of what we have here. */
4138 bool any_regs = false;
4139 for (int i = nargs; i-- > 0; )
4140 if (argvec[i].reg != NULL_RTX)
4142 targetm.calls.call_args (argvec[i].reg, NULL_TREE);
4143 any_regs = true;
4145 if (!any_regs)
4146 targetm.calls.call_args (pc_rtx, NULL_TREE);
4148 /* Push the args that need to be pushed. */
4150 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4151 are to be pushed. */
4152 for (count = 0; count < nargs; count++, argnum--)
4154 machine_mode mode = argvec[argnum].mode;
4155 rtx val = argvec[argnum].value;
4156 rtx reg = argvec[argnum].reg;
4157 int partial = argvec[argnum].partial;
4158 unsigned int parm_align = argvec[argnum].locate.boundary;
4159 int lower_bound = 0, upper_bound = 0, i;
4161 if (! (reg != 0 && partial == 0))
4163 rtx use;
4165 if (ACCUMULATE_OUTGOING_ARGS)
4167 /* If this is being stored into a pre-allocated, fixed-size,
4168 stack area, save any previous data at that location. */
4170 #ifdef ARGS_GROW_DOWNWARD
4171 /* stack_slot is negative, but we want to index stack_usage_map
4172 with positive values. */
4173 upper_bound = -argvec[argnum].locate.slot_offset.constant + 1;
4174 lower_bound = upper_bound - argvec[argnum].locate.size.constant;
4175 #else
4176 lower_bound = argvec[argnum].locate.slot_offset.constant;
4177 upper_bound = lower_bound + argvec[argnum].locate.size.constant;
4178 #endif
4180 i = lower_bound;
4181 /* Don't worry about things in the fixed argument area;
4182 it has already been saved. */
4183 if (i < reg_parm_stack_space)
4184 i = reg_parm_stack_space;
4185 while (i < upper_bound && stack_usage_map[i] == 0)
4186 i++;
4188 if (i < upper_bound)
4190 /* We need to make a save area. */
4191 unsigned int size
4192 = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
4193 machine_mode save_mode
4194 = mode_for_size (size, MODE_INT, 1);
4195 rtx adr
4196 = plus_constant (Pmode, argblock,
4197 argvec[argnum].locate.offset.constant);
4198 rtx stack_area
4199 = gen_rtx_MEM (save_mode, memory_address (save_mode, adr));
4201 if (save_mode == BLKmode)
4203 argvec[argnum].save_area
4204 = assign_stack_temp (BLKmode,
4205 argvec[argnum].locate.size.constant
4208 emit_block_move (validize_mem
4209 (copy_rtx (argvec[argnum].save_area)),
4210 stack_area,
4211 GEN_INT (argvec[argnum].locate.size.constant),
4212 BLOCK_OP_CALL_PARM);
4214 else
4216 argvec[argnum].save_area = gen_reg_rtx (save_mode);
4218 emit_move_insn (argvec[argnum].save_area, stack_area);
4223 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, parm_align,
4224 partial, reg, 0, argblock,
4225 GEN_INT (argvec[argnum].locate.offset.constant),
4226 reg_parm_stack_space,
4227 ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad));
4229 /* Now mark the segment we just used. */
4230 if (ACCUMULATE_OUTGOING_ARGS)
4231 for (i = lower_bound; i < upper_bound; i++)
4232 stack_usage_map[i] = 1;
4234 NO_DEFER_POP;
4236 /* Indicate argument access so that alias.c knows that these
4237 values are live. */
4238 if (argblock)
4239 use = plus_constant (Pmode, argblock,
4240 argvec[argnum].locate.offset.constant);
4241 else
4242 /* When arguments are pushed, trying to tell alias.c where
4243 exactly this argument is won't work, because the
4244 auto-increment causes confusion. So we merely indicate
4245 that we access something with a known mode somewhere on
4246 the stack. */
4247 use = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
4248 gen_rtx_SCRATCH (Pmode));
4249 use = gen_rtx_MEM (argvec[argnum].mode, use);
4250 use = gen_rtx_USE (VOIDmode, use);
4251 call_fusage = gen_rtx_EXPR_LIST (VOIDmode, use, call_fusage);
4255 argnum = nargs - 1;
4257 fun = prepare_call_address (NULL, fun, NULL, &call_fusage, 0, 0);
4259 /* Now load any reg parms into their regs. */
4261 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4262 are to be pushed. */
4263 for (count = 0; count < nargs; count++, argnum--)
4265 machine_mode mode = argvec[argnum].mode;
4266 rtx val = argvec[argnum].value;
4267 rtx reg = argvec[argnum].reg;
4268 int partial = argvec[argnum].partial;
4269 #ifdef BLOCK_REG_PADDING
4270 int size = 0;
4271 #endif
4273 /* Handle calls that pass values in multiple non-contiguous
4274 locations. The PA64 has examples of this for library calls. */
4275 if (reg != 0 && GET_CODE (reg) == PARALLEL)
4276 emit_group_load (reg, val, NULL_TREE, GET_MODE_SIZE (mode));
4277 else if (reg != 0 && partial == 0)
4279 emit_move_insn (reg, val);
4280 #ifdef BLOCK_REG_PADDING
4281 size = GET_MODE_SIZE (argvec[argnum].mode);
4283 /* Copied from load_register_parameters. */
4285 /* Handle case where we have a value that needs shifting
4286 up to the msb. eg. a QImode value and we're padding
4287 upward on a BYTES_BIG_ENDIAN machine. */
4288 if (size < UNITS_PER_WORD
4289 && (argvec[argnum].locate.where_pad
4290 == (BYTES_BIG_ENDIAN ? upward : downward)))
4292 rtx x;
4293 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
4295 /* Assigning REG here rather than a temp makes CALL_FUSAGE
4296 report the whole reg as used. Strictly speaking, the
4297 call only uses SIZE bytes at the msb end, but it doesn't
4298 seem worth generating rtl to say that. */
4299 reg = gen_rtx_REG (word_mode, REGNO (reg));
4300 x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1);
4301 if (x != reg)
4302 emit_move_insn (reg, x);
4304 #endif
4307 NO_DEFER_POP;
4310 /* Any regs containing parms remain in use through the call. */
4311 for (count = 0; count < nargs; count++)
4313 rtx reg = argvec[count].reg;
4314 if (reg != 0 && GET_CODE (reg) == PARALLEL)
4315 use_group_regs (&call_fusage, reg);
4316 else if (reg != 0)
4318 int partial = argvec[count].partial;
4319 if (partial)
4321 int nregs;
4322 gcc_assert (partial % UNITS_PER_WORD == 0);
4323 nregs = partial / UNITS_PER_WORD;
4324 use_regs (&call_fusage, REGNO (reg), nregs);
4326 else
4327 use_reg (&call_fusage, reg);
4331 /* Pass the function the address in which to return a structure value. */
4332 if (mem_value != 0 && struct_value != 0 && ! pcc_struct_value)
4334 emit_move_insn (struct_value,
4335 force_reg (Pmode,
4336 force_operand (XEXP (mem_value, 0),
4337 NULL_RTX)));
4338 if (REG_P (struct_value))
4339 use_reg (&call_fusage, struct_value);
4342 /* Don't allow popping to be deferred, since then
4343 cse'ing of library calls could delete a call and leave the pop. */
4344 NO_DEFER_POP;
4345 valreg = (mem_value == 0 && outmode != VOIDmode
4346 ? hard_libcall_value (outmode, orgfun) : NULL_RTX);
4348 /* Stack must be properly aligned now. */
4349 gcc_assert (!(stack_pointer_delta
4350 & (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)));
4352 before_call = get_last_insn ();
4354 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4355 will set inhibit_defer_pop to that value. */
4356 /* The return type is needed to decide how many bytes the function pops.
4357 Signedness plays no role in that, so for simplicity, we pretend it's
4358 always signed. We also assume that the list of arguments passed has
4359 no impact, so we pretend it is unknown. */
4361 emit_call_1 (fun, NULL,
4362 get_identifier (XSTR (orgfun, 0)),
4363 build_function_type (tfom, NULL_TREE),
4364 original_args_size.constant, args_size.constant,
4365 struct_value_size,
4366 targetm.calls.function_arg (args_so_far,
4367 VOIDmode, void_type_node, true),
4368 valreg,
4369 old_inhibit_defer_pop + 1, call_fusage, flags, args_so_far);
4371 if (flag_use_caller_save)
4373 rtx last, datum = orgfun;
4374 gcc_assert (GET_CODE (datum) == SYMBOL_REF);
4375 last = last_call_insn ();
4376 add_reg_note (last, REG_CALL_DECL, datum);
4379 /* Right-shift returned value if necessary. */
4380 if (!pcc_struct_value
4381 && TYPE_MODE (tfom) != BLKmode
4382 && targetm.calls.return_in_msb (tfom))
4384 shift_return_value (TYPE_MODE (tfom), false, valreg);
4385 valreg = gen_rtx_REG (TYPE_MODE (tfom), REGNO (valreg));
4388 targetm.calls.end_call_args ();
4390 /* For calls to `setjmp', etc., inform function.c:setjmp_warnings
4391 that it should complain if nonvolatile values are live. For
4392 functions that cannot return, inform flow that control does not
4393 fall through. */
4394 if (flags & ECF_NORETURN)
4396 /* The barrier note must be emitted
4397 immediately after the CALL_INSN. Some ports emit more than
4398 just a CALL_INSN above, so we must search for it here. */
4399 rtx_insn *last = get_last_insn ();
4400 while (!CALL_P (last))
4402 last = PREV_INSN (last);
4403 /* There was no CALL_INSN? */
4404 gcc_assert (last != before_call);
4407 emit_barrier_after (last);
4410 /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW
4411 and LCT_RETURNS_TWICE, cannot perform non-local gotos. */
4412 if (flags & ECF_NOTHROW)
4414 rtx_insn *last = get_last_insn ();
4415 while (!CALL_P (last))
4417 last = PREV_INSN (last);
4418 /* There was no CALL_INSN? */
4419 gcc_assert (last != before_call);
4422 make_reg_eh_region_note_nothrow_nononlocal (last);
4425 /* Now restore inhibit_defer_pop to its actual original value. */
4426 OK_DEFER_POP;
4428 pop_temp_slots ();
4430 /* Copy the value to the right place. */
4431 if (outmode != VOIDmode && retval)
4433 if (mem_value)
4435 if (value == 0)
4436 value = mem_value;
4437 if (value != mem_value)
4438 emit_move_insn (value, mem_value);
4440 else if (GET_CODE (valreg) == PARALLEL)
4442 if (value == 0)
4443 value = gen_reg_rtx (outmode);
4444 emit_group_store (value, valreg, NULL_TREE, GET_MODE_SIZE (outmode));
4446 else
4448 /* Convert to the proper mode if a promotion has been active. */
4449 if (GET_MODE (valreg) != outmode)
4451 int unsignedp = TYPE_UNSIGNED (tfom);
4453 gcc_assert (promote_function_mode (tfom, outmode, &unsignedp,
4454 fndecl ? TREE_TYPE (fndecl) : fntype, 1)
4455 == GET_MODE (valreg));
4456 valreg = convert_modes (outmode, GET_MODE (valreg), valreg, 0);
4459 if (value != 0)
4460 emit_move_insn (value, valreg);
4461 else
4462 value = valreg;
4466 if (ACCUMULATE_OUTGOING_ARGS)
4468 #ifdef REG_PARM_STACK_SPACE
4469 if (save_area)
4470 restore_fixed_argument_area (save_area, argblock,
4471 high_to_save, low_to_save);
4472 #endif
4474 /* If we saved any argument areas, restore them. */
4475 for (count = 0; count < nargs; count++)
4476 if (argvec[count].save_area)
4478 machine_mode save_mode = GET_MODE (argvec[count].save_area);
4479 rtx adr = plus_constant (Pmode, argblock,
4480 argvec[count].locate.offset.constant);
4481 rtx stack_area = gen_rtx_MEM (save_mode,
4482 memory_address (save_mode, adr));
4484 if (save_mode == BLKmode)
4485 emit_block_move (stack_area,
4486 validize_mem
4487 (copy_rtx (argvec[count].save_area)),
4488 GEN_INT (argvec[count].locate.size.constant),
4489 BLOCK_OP_CALL_PARM);
4490 else
4491 emit_move_insn (stack_area, argvec[count].save_area);
4494 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
4495 stack_usage_map = initial_stack_usage_map;
4498 free (stack_usage_map_buf);
4500 return value;
4504 /* Output a library call to function FUN (a SYMBOL_REF rtx)
4505 (emitting the queue unless NO_QUEUE is nonzero),
4506 for a value of mode OUTMODE,
4507 with NARGS different arguments, passed as alternating rtx values
4508 and machine_modes to convert them to.
4510 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for
4511 `const' calls, LCT_PURE for `pure' calls, or other LCT_ value for
4512 other types of library calls. */
4514 void
4515 emit_library_call (rtx orgfun, enum libcall_type fn_type,
4516 machine_mode outmode, int nargs, ...)
4518 va_list p;
4520 va_start (p, nargs);
4521 emit_library_call_value_1 (0, orgfun, NULL_RTX, fn_type, outmode, nargs, p);
4522 va_end (p);
4525 /* Like emit_library_call except that an extra argument, VALUE,
4526 comes second and says where to store the result.
4527 (If VALUE is zero, this function chooses a convenient way
4528 to return the value.
4530 This function returns an rtx for where the value is to be found.
4531 If VALUE is nonzero, VALUE is returned. */
4534 emit_library_call_value (rtx orgfun, rtx value,
4535 enum libcall_type fn_type,
4536 machine_mode outmode, int nargs, ...)
4538 rtx result;
4539 va_list p;
4541 va_start (p, nargs);
4542 result = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode,
4543 nargs, p);
4544 va_end (p);
4546 return result;
4550 /* Store pointer bounds argument ARG into Bounds Table entry
4551 associated with PARM. */
4552 static void
4553 store_bounds (struct arg_data *arg, struct arg_data *parm)
4555 rtx slot = NULL, ptr = NULL, addr = NULL;
4557 /* We may pass bounds not associated with any pointer. */
4558 if (!parm)
4560 gcc_assert (arg->special_slot);
4561 slot = arg->special_slot;
4562 ptr = const0_rtx;
4564 /* Find pointer associated with bounds and where it is
4565 passed. */
4566 else
4568 if (!parm->reg)
4570 gcc_assert (!arg->special_slot);
4572 addr = adjust_address (parm->stack, Pmode, arg->pointer_offset);
4574 else if (REG_P (parm->reg))
4576 gcc_assert (arg->special_slot);
4577 slot = arg->special_slot;
4579 if (MEM_P (parm->value))
4580 addr = adjust_address (parm->value, Pmode, arg->pointer_offset);
4581 else if (REG_P (parm->value))
4582 ptr = gen_rtx_SUBREG (Pmode, parm->value, arg->pointer_offset);
4583 else
4585 gcc_assert (!arg->pointer_offset);
4586 ptr = parm->value;
4589 else
4591 gcc_assert (GET_CODE (parm->reg) == PARALLEL);
4593 gcc_assert (arg->special_slot);
4594 slot = arg->special_slot;
4596 if (parm->parallel_value)
4597 ptr = chkp_get_value_with_offs (parm->parallel_value,
4598 GEN_INT (arg->pointer_offset));
4599 else
4600 gcc_unreachable ();
4604 /* Expand bounds. */
4605 if (!arg->value)
4606 arg->value = expand_normal (arg->tree_value);
4608 targetm.calls.store_bounds_for_arg (ptr, addr, arg->value, slot);
4611 /* Store a single argument for a function call
4612 into the register or memory area where it must be passed.
4613 *ARG describes the argument value and where to pass it.
4615 ARGBLOCK is the address of the stack-block for all the arguments,
4616 or 0 on a machine where arguments are pushed individually.
4618 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4619 so must be careful about how the stack is used.
4621 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4622 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4623 that we need not worry about saving and restoring the stack.
4625 FNDECL is the declaration of the function we are calling.
4627 Return nonzero if this arg should cause sibcall failure,
4628 zero otherwise. */
4630 static int
4631 store_one_arg (struct arg_data *arg, rtx argblock, int flags,
4632 int variable_size ATTRIBUTE_UNUSED, int reg_parm_stack_space)
4634 tree pval = arg->tree_value;
4635 rtx reg = 0;
4636 int partial = 0;
4637 int used = 0;
4638 int i, lower_bound = 0, upper_bound = 0;
4639 int sibcall_failure = 0;
4641 if (TREE_CODE (pval) == ERROR_MARK)
4642 return 1;
4644 /* Push a new temporary level for any temporaries we make for
4645 this argument. */
4646 push_temp_slots ();
4648 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL))
4650 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4651 save any previous data at that location. */
4652 if (argblock && ! variable_size && arg->stack)
4654 #ifdef ARGS_GROW_DOWNWARD
4655 /* stack_slot is negative, but we want to index stack_usage_map
4656 with positive values. */
4657 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4658 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
4659 else
4660 upper_bound = 0;
4662 lower_bound = upper_bound - arg->locate.size.constant;
4663 #else
4664 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4665 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
4666 else
4667 lower_bound = 0;
4669 upper_bound = lower_bound + arg->locate.size.constant;
4670 #endif
4672 i = lower_bound;
4673 /* Don't worry about things in the fixed argument area;
4674 it has already been saved. */
4675 if (i < reg_parm_stack_space)
4676 i = reg_parm_stack_space;
4677 while (i < upper_bound && stack_usage_map[i] == 0)
4678 i++;
4680 if (i < upper_bound)
4682 /* We need to make a save area. */
4683 unsigned int size = arg->locate.size.constant * BITS_PER_UNIT;
4684 machine_mode save_mode = mode_for_size (size, MODE_INT, 1);
4685 rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0));
4686 rtx stack_area = gen_rtx_MEM (save_mode, adr);
4688 if (save_mode == BLKmode)
4690 arg->save_area
4691 = assign_temp (TREE_TYPE (arg->tree_value), 1, 1);
4692 preserve_temp_slots (arg->save_area);
4693 emit_block_move (validize_mem (copy_rtx (arg->save_area)),
4694 stack_area,
4695 GEN_INT (arg->locate.size.constant),
4696 BLOCK_OP_CALL_PARM);
4698 else
4700 arg->save_area = gen_reg_rtx (save_mode);
4701 emit_move_insn (arg->save_area, stack_area);
4707 /* If this isn't going to be placed on both the stack and in registers,
4708 set up the register and number of words. */
4709 if (! arg->pass_on_stack)
4711 if (flags & ECF_SIBCALL)
4712 reg = arg->tail_call_reg;
4713 else
4714 reg = arg->reg;
4715 partial = arg->partial;
4718 /* Being passed entirely in a register. We shouldn't be called in
4719 this case. */
4720 gcc_assert (reg == 0 || partial != 0);
4722 /* If this arg needs special alignment, don't load the registers
4723 here. */
4724 if (arg->n_aligned_regs != 0)
4725 reg = 0;
4727 /* If this is being passed partially in a register, we can't evaluate
4728 it directly into its stack slot. Otherwise, we can. */
4729 if (arg->value == 0)
4731 /* stack_arg_under_construction is nonzero if a function argument is
4732 being evaluated directly into the outgoing argument list and
4733 expand_call must take special action to preserve the argument list
4734 if it is called recursively.
4736 For scalar function arguments stack_usage_map is sufficient to
4737 determine which stack slots must be saved and restored. Scalar
4738 arguments in general have pass_on_stack == 0.
4740 If this argument is initialized by a function which takes the
4741 address of the argument (a C++ constructor or a C function
4742 returning a BLKmode structure), then stack_usage_map is
4743 insufficient and expand_call must push the stack around the
4744 function call. Such arguments have pass_on_stack == 1.
4746 Note that it is always safe to set stack_arg_under_construction,
4747 but this generates suboptimal code if set when not needed. */
4749 if (arg->pass_on_stack)
4750 stack_arg_under_construction++;
4752 arg->value = expand_expr (pval,
4753 (partial
4754 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
4755 ? NULL_RTX : arg->stack,
4756 VOIDmode, EXPAND_STACK_PARM);
4758 /* If we are promoting object (or for any other reason) the mode
4759 doesn't agree, convert the mode. */
4761 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
4762 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
4763 arg->value, arg->unsignedp);
4765 if (arg->pass_on_stack)
4766 stack_arg_under_construction--;
4769 /* Check for overlap with already clobbered argument area. */
4770 if ((flags & ECF_SIBCALL)
4771 && MEM_P (arg->value)
4772 && mem_overlaps_already_clobbered_arg_p (XEXP (arg->value, 0),
4773 arg->locate.size.constant))
4774 sibcall_failure = 1;
4776 /* Don't allow anything left on stack from computation
4777 of argument to alloca. */
4778 if (flags & ECF_MAY_BE_ALLOCA)
4779 do_pending_stack_adjust ();
4781 if (arg->value == arg->stack)
4782 /* If the value is already in the stack slot, we are done. */
4784 else if (arg->mode != BLKmode)
4786 int size;
4787 unsigned int parm_align;
4789 /* Argument is a scalar, not entirely passed in registers.
4790 (If part is passed in registers, arg->partial says how much
4791 and emit_push_insn will take care of putting it there.)
4793 Push it, and if its size is less than the
4794 amount of space allocated to it,
4795 also bump stack pointer by the additional space.
4796 Note that in C the default argument promotions
4797 will prevent such mismatches. */
4799 size = GET_MODE_SIZE (arg->mode);
4800 /* Compute how much space the push instruction will push.
4801 On many machines, pushing a byte will advance the stack
4802 pointer by a halfword. */
4803 #ifdef PUSH_ROUNDING
4804 size = PUSH_ROUNDING (size);
4805 #endif
4806 used = size;
4808 /* Compute how much space the argument should get:
4809 round up to a multiple of the alignment for arguments. */
4810 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
4811 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4812 / (PARM_BOUNDARY / BITS_PER_UNIT))
4813 * (PARM_BOUNDARY / BITS_PER_UNIT));
4815 /* Compute the alignment of the pushed argument. */
4816 parm_align = arg->locate.boundary;
4817 if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward)
4819 int pad = used - size;
4820 if (pad)
4822 unsigned int pad_align = (pad & -pad) * BITS_PER_UNIT;
4823 parm_align = MIN (parm_align, pad_align);
4827 /* This isn't already where we want it on the stack, so put it there.
4828 This can either be done with push or copy insns. */
4829 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
4830 parm_align, partial, reg, used - size, argblock,
4831 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4832 ARGS_SIZE_RTX (arg->locate.alignment_pad));
4834 /* Unless this is a partially-in-register argument, the argument is now
4835 in the stack. */
4836 if (partial == 0)
4837 arg->value = arg->stack;
4839 else
4841 /* BLKmode, at least partly to be pushed. */
4843 unsigned int parm_align;
4844 int excess;
4845 rtx size_rtx;
4847 /* Pushing a nonscalar.
4848 If part is passed in registers, PARTIAL says how much
4849 and emit_push_insn will take care of putting it there. */
4851 /* Round its size up to a multiple
4852 of the allocation unit for arguments. */
4854 if (arg->locate.size.var != 0)
4856 excess = 0;
4857 size_rtx = ARGS_SIZE_RTX (arg->locate.size);
4859 else
4861 /* PUSH_ROUNDING has no effect on us, because emit_push_insn
4862 for BLKmode is careful to avoid it. */
4863 excess = (arg->locate.size.constant
4864 - int_size_in_bytes (TREE_TYPE (pval))
4865 + partial);
4866 size_rtx = expand_expr (size_in_bytes (TREE_TYPE (pval)),
4867 NULL_RTX, TYPE_MODE (sizetype),
4868 EXPAND_NORMAL);
4871 parm_align = arg->locate.boundary;
4873 /* When an argument is padded down, the block is aligned to
4874 PARM_BOUNDARY, but the actual argument isn't. */
4875 if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward)
4877 if (arg->locate.size.var)
4878 parm_align = BITS_PER_UNIT;
4879 else if (excess)
4881 unsigned int excess_align = (excess & -excess) * BITS_PER_UNIT;
4882 parm_align = MIN (parm_align, excess_align);
4886 if ((flags & ECF_SIBCALL) && MEM_P (arg->value))
4888 /* emit_push_insn might not work properly if arg->value and
4889 argblock + arg->locate.offset areas overlap. */
4890 rtx x = arg->value;
4891 int i = 0;
4893 if (XEXP (x, 0) == crtl->args.internal_arg_pointer
4894 || (GET_CODE (XEXP (x, 0)) == PLUS
4895 && XEXP (XEXP (x, 0), 0) ==
4896 crtl->args.internal_arg_pointer
4897 && CONST_INT_P (XEXP (XEXP (x, 0), 1))))
4899 if (XEXP (x, 0) != crtl->args.internal_arg_pointer)
4900 i = INTVAL (XEXP (XEXP (x, 0), 1));
4902 /* expand_call should ensure this. */
4903 gcc_assert (!arg->locate.offset.var
4904 && arg->locate.size.var == 0
4905 && CONST_INT_P (size_rtx));
4907 if (arg->locate.offset.constant > i)
4909 if (arg->locate.offset.constant < i + INTVAL (size_rtx))
4910 sibcall_failure = 1;
4912 else if (arg->locate.offset.constant < i)
4914 /* Use arg->locate.size.constant instead of size_rtx
4915 because we only care about the part of the argument
4916 on the stack. */
4917 if (i < (arg->locate.offset.constant
4918 + arg->locate.size.constant))
4919 sibcall_failure = 1;
4921 else
4923 /* Even though they appear to be at the same location,
4924 if part of the outgoing argument is in registers,
4925 they aren't really at the same location. Check for
4926 this by making sure that the incoming size is the
4927 same as the outgoing size. */
4928 if (arg->locate.size.constant != INTVAL (size_rtx))
4929 sibcall_failure = 1;
4934 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
4935 parm_align, partial, reg, excess, argblock,
4936 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4937 ARGS_SIZE_RTX (arg->locate.alignment_pad));
4939 /* Unless this is a partially-in-register argument, the argument is now
4940 in the stack.
4942 ??? Unlike the case above, in which we want the actual
4943 address of the data, so that we can load it directly into a
4944 register, here we want the address of the stack slot, so that
4945 it's properly aligned for word-by-word copying or something
4946 like that. It's not clear that this is always correct. */
4947 if (partial == 0)
4948 arg->value = arg->stack_slot;
4951 if (arg->reg && GET_CODE (arg->reg) == PARALLEL)
4953 tree type = TREE_TYPE (arg->tree_value);
4954 arg->parallel_value
4955 = emit_group_load_into_temps (arg->reg, arg->value, type,
4956 int_size_in_bytes (type));
4959 /* Mark all slots this store used. */
4960 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)
4961 && argblock && ! variable_size && arg->stack)
4962 for (i = lower_bound; i < upper_bound; i++)
4963 stack_usage_map[i] = 1;
4965 /* Once we have pushed something, pops can't safely
4966 be deferred during the rest of the arguments. */
4967 NO_DEFER_POP;
4969 /* Free any temporary slots made in processing this argument. */
4970 pop_temp_slots ();
4972 return sibcall_failure;
4975 /* Nonzero if we do not know how to pass TYPE solely in registers. */
4977 bool
4978 must_pass_in_stack_var_size (machine_mode mode ATTRIBUTE_UNUSED,
4979 const_tree type)
4981 if (!type)
4982 return false;
4984 /* If the type has variable size... */
4985 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4986 return true;
4988 /* If the type is marked as addressable (it is required
4989 to be constructed into the stack)... */
4990 if (TREE_ADDRESSABLE (type))
4991 return true;
4993 return false;
4996 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
4997 takes trailing padding of a structure into account. */
4998 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
5000 bool
5001 must_pass_in_stack_var_size_or_pad (machine_mode mode, const_tree type)
5003 if (!type)
5004 return false;
5006 /* If the type has variable size... */
5007 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
5008 return true;
5010 /* If the type is marked as addressable (it is required
5011 to be constructed into the stack)... */
5012 if (TREE_ADDRESSABLE (type))
5013 return true;
5015 /* If the padding and mode of the type is such that a copy into
5016 a register would put it into the wrong part of the register. */
5017 if (mode == BLKmode
5018 && int_size_in_bytes (type) % (PARM_BOUNDARY / BITS_PER_UNIT)
5019 && (FUNCTION_ARG_PADDING (mode, type)
5020 == (BYTES_BIG_ENDIAN ? upward : downward)))
5021 return true;
5023 return false;