Line data Source code
1 : /* Convert function calls to rtl insns, for GNU C compiler.
2 : Copyright (C) 1989-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
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.
10 :
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.
15 :
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/>. */
19 :
20 : #include "config.h"
21 : #include "system.h"
22 : #include "coretypes.h"
23 : #include "backend.h"
24 : #include "target.h"
25 : #include "rtl.h"
26 : #include "tree.h"
27 : #include "gimple.h"
28 : #include "predict.h"
29 : #include "memmodel.h"
30 : #include "tm_p.h"
31 : #include "stringpool.h"
32 : #include "expmed.h"
33 : #include "optabs.h"
34 : #include "emit-rtl.h"
35 : #include "cgraph.h"
36 : #include "diagnostic-core.h"
37 : #include "fold-const.h"
38 : #include "stor-layout.h"
39 : #include "varasm.h"
40 : #include "internal-fn.h"
41 : #include "dojump.h"
42 : #include "explow.h"
43 : #include "calls.h"
44 : #include "expr.h"
45 : #include "output.h"
46 : #include "langhooks.h"
47 : #include "except.h"
48 : #include "dbgcnt.h"
49 : #include "rtl-iter.h"
50 : #include "tree-vrp.h"
51 : #include "tree-ssanames.h"
52 : #include "intl.h"
53 : #include "hash-map.h"
54 : #include "hash-traits.h"
55 : #include "attribs.h"
56 : #include "builtins.h"
57 : #include "gimple-iterator.h"
58 : #include "gimple-fold.h"
59 : #include "attr-fnspec.h"
60 : #include "value-query.h"
61 : #include "tree-pretty-print.h"
62 : #include "tree-eh.h"
63 : #include "regs.h"
64 : #include "function-abi.h"
65 :
66 : /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
67 : #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
68 :
69 : /* Data structure and subroutines used within expand_call. */
70 :
71 : struct arg_data
72 : {
73 : /* Tree node for this argument. */
74 : tree tree_value;
75 : /* Mode for value; TYPE_MODE unless promoted. */
76 : machine_mode mode;
77 : /* Current RTL value for argument, or 0 if it isn't precomputed. */
78 : rtx value;
79 : /* Initially-compute RTL value for argument; only for const functions. */
80 : rtx initial_value;
81 : /* Register to pass this argument in, 0 if passed on stack, or an
82 : PARALLEL if the arg is to be copied into multiple non-contiguous
83 : registers. */
84 : rtx reg;
85 : /* Register to pass this argument in when generating tail call sequence.
86 : This is not the same register as for normal calls on machines with
87 : register windows. */
88 : rtx tail_call_reg;
89 : /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
90 : form for emit_group_move. */
91 : rtx parallel_value;
92 : /* If REG was promoted from the actual mode of the argument expression,
93 : indicates whether the promotion is sign- or zero-extended. */
94 : int unsignedp;
95 : /* Number of bytes to put in registers. 0 means put the whole arg
96 : in registers. Also 0 if not passed in registers. */
97 : int partial;
98 : /* True if argument must be passed on stack.
99 : Note that some arguments may be passed on the stack
100 : even though pass_on_stack is false, just because FUNCTION_ARG says so.
101 : pass_on_stack identifies arguments that *cannot* go in registers. */
102 : bool pass_on_stack;
103 : /* Some fields packaged up for locate_and_pad_parm. */
104 : struct locate_and_pad_arg_data locate;
105 : /* Location on the stack at which parameter should be stored. The store
106 : has already been done if STACK == VALUE. */
107 : rtx stack;
108 : /* Location on the stack of the start of this argument slot. This can
109 : differ from STACK if this arg pads downward. This location is known
110 : to be aligned to TARGET_FUNCTION_ARG_BOUNDARY. */
111 : rtx stack_slot;
112 : /* Place that this stack area has been saved, if needed. */
113 : rtx save_area;
114 : /* If an argument's alignment does not permit direct copying into registers,
115 : copy in smaller-sized pieces into pseudos. These are stored in a
116 : block pointed to by this field. The next field says how many
117 : word-sized pseudos we made. */
118 : rtx *aligned_regs;
119 : int n_aligned_regs;
120 : };
121 :
122 : /* A vector of one char per byte of stack space. A byte if nonzero if
123 : the corresponding stack location has been used.
124 : This vector is used to prevent a function call within an argument from
125 : clobbering any stack already set up. */
126 : static char *stack_usage_map;
127 :
128 : /* Size of STACK_USAGE_MAP. */
129 : static unsigned int highest_outgoing_arg_in_use;
130 :
131 : /* Assume that any stack location at this byte index is used,
132 : without checking the contents of stack_usage_map. */
133 : static unsigned HOST_WIDE_INT stack_usage_watermark = HOST_WIDE_INT_M1U;
134 :
135 : /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
136 : stack location's tail call argument has been already stored into the stack.
137 : This bitmap is used to prevent sibling call optimization if function tries
138 : to use parent's incoming argument slots when they have been already
139 : overwritten with tail call arguments. */
140 : static sbitmap stored_args_map;
141 :
142 : /* Assume that any virtual-incoming location at this byte index has been
143 : stored, without checking the contents of stored_args_map. */
144 : static unsigned HOST_WIDE_INT stored_args_watermark;
145 :
146 : /* stack_arg_under_construction is nonzero when an argument may be
147 : initialized with a constructor call (including a C function that
148 : returns a BLKmode struct) and expand_call must take special action
149 : to make sure the object being constructed does not overlap the
150 : argument list for the constructor call. */
151 : static int stack_arg_under_construction;
152 :
153 : static void precompute_register_parameters (int, struct arg_data *, int *);
154 : static bool store_one_arg (struct arg_data *, rtx, int, int, int);
155 : static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
156 : static bool finalize_must_preallocate (bool, int, struct arg_data *,
157 : struct args_size *);
158 : static void precompute_arguments (int, struct arg_data *);
159 : static void compute_argument_addresses (struct arg_data *, rtx, int);
160 : static rtx rtx_for_function_call (tree, tree);
161 : static void load_register_parameters (struct arg_data *, int, rtx *, int,
162 : int, bool *);
163 : static int special_function_p (const_tree, int);
164 : static bool check_sibcall_argument_overlap_1 (rtx);
165 : static bool check_sibcall_argument_overlap (rtx_insn *, struct arg_data *,
166 : bool);
167 : static tree split_complex_types (tree);
168 :
169 : #ifdef REG_PARM_STACK_SPACE
170 : static rtx save_fixed_argument_area (int, rtx, int *, int *);
171 : static void restore_fixed_argument_area (rtx, rtx, int, int);
172 : #endif
173 :
174 : /* Return true if bytes [LOWER_BOUND, UPPER_BOUND) of the outgoing
175 : stack region might already be in use. */
176 :
177 : static bool
178 53835 : stack_region_maybe_used_p (poly_uint64 lower_bound, poly_uint64 upper_bound,
179 : unsigned int reg_parm_stack_space)
180 : {
181 53835 : unsigned HOST_WIDE_INT const_lower, const_upper;
182 53835 : const_lower = constant_lower_bound (lower_bound);
183 53835 : if (!upper_bound.is_constant (&const_upper))
184 : const_upper = HOST_WIDE_INT_M1U;
185 :
186 53835 : if (const_upper > stack_usage_watermark)
187 : return true;
188 :
189 : /* Don't worry about things in the fixed argument area;
190 : it has already been saved. */
191 53835 : const_lower = MAX (const_lower, reg_parm_stack_space);
192 53835 : const_upper = MIN (const_upper, highest_outgoing_arg_in_use);
193 486883 : for (unsigned HOST_WIDE_INT i = const_lower; i < const_upper; ++i)
194 433048 : if (stack_usage_map[i])
195 : return true;
196 : return false;
197 : }
198 :
199 : /* Record that bytes [LOWER_BOUND, UPPER_BOUND) of the outgoing
200 : stack region are now in use. */
201 :
202 : static void
203 53835 : mark_stack_region_used (poly_uint64 lower_bound, poly_uint64 upper_bound)
204 : {
205 53835 : unsigned HOST_WIDE_INT const_lower, const_upper;
206 53835 : const_lower = constant_lower_bound (lower_bound);
207 53835 : if (upper_bound.is_constant (&const_upper)
208 53835 : && const_upper <= highest_outgoing_arg_in_use)
209 486883 : for (unsigned HOST_WIDE_INT i = const_lower; i < const_upper; ++i)
210 433048 : stack_usage_map[i] = 1;
211 : else
212 0 : stack_usage_watermark = MIN (stack_usage_watermark, const_lower);
213 53835 : }
214 :
215 : /* Force FUNEXP into a form suitable for the address of a CALL,
216 : and return that as an rtx. Also load the static chain register
217 : if FNDECL is a nested function.
218 :
219 : CALL_FUSAGE points to a variable holding the prospective
220 : CALL_INSN_FUNCTION_USAGE information. */
221 :
222 : rtx
223 6123828 : prepare_call_address (tree fndecl_or_type, rtx funexp, rtx static_chain_value,
224 : rtx *call_fusage, int reg_parm_seen, int flags)
225 : {
226 : /* Make a valid memory address and copy constants through pseudo-regs,
227 : but not for a constant address if -fno-function-cse. */
228 6123828 : if (GET_CODE (funexp) != SYMBOL_REF)
229 : {
230 : /* If it's an indirect call by descriptor, generate code to perform
231 : runtime identification of the pointer and load the descriptor. */
232 187012 : if ((flags & ECF_BY_DESCRIPTOR) && !flag_trampolines)
233 : {
234 0 : const int bit_val = targetm.calls.custom_function_descriptors;
235 0 : rtx call_lab = gen_label_rtx ();
236 :
237 0 : gcc_assert (fndecl_or_type && TYPE_P (fndecl_or_type));
238 0 : fndecl_or_type
239 0 : = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, NULL_TREE,
240 : fndecl_or_type);
241 0 : DECL_STATIC_CHAIN (fndecl_or_type) = 1;
242 0 : rtx chain = targetm.calls.static_chain (fndecl_or_type, false);
243 :
244 0 : if (GET_MODE (funexp) != Pmode)
245 0 : funexp = convert_memory_address (Pmode, funexp);
246 :
247 : /* Avoid long live ranges around function calls. */
248 0 : funexp = copy_to_mode_reg (Pmode, funexp);
249 :
250 0 : if (REG_P (chain))
251 0 : emit_insn (gen_rtx_CLOBBER (VOIDmode, chain));
252 :
253 : /* Emit the runtime identification pattern. */
254 0 : rtx mask = gen_rtx_AND (Pmode, funexp, GEN_INT (bit_val));
255 0 : emit_cmp_and_jump_insns (mask, const0_rtx, EQ, NULL_RTX, Pmode, 1,
256 : call_lab);
257 :
258 : /* Statically predict the branch to very likely taken. */
259 0 : rtx_insn *insn = get_last_insn ();
260 0 : if (JUMP_P (insn))
261 0 : predict_insn_def (insn, PRED_BUILTIN_EXPECT, TAKEN);
262 :
263 : /* Load the descriptor. */
264 0 : rtx mem = gen_rtx_MEM (ptr_mode,
265 0 : plus_constant (Pmode, funexp, - bit_val));
266 0 : MEM_NOTRAP_P (mem) = 1;
267 0 : mem = convert_memory_address (Pmode, mem);
268 0 : emit_move_insn (chain, mem);
269 :
270 0 : mem = gen_rtx_MEM (ptr_mode,
271 0 : plus_constant (Pmode, funexp,
272 0 : POINTER_SIZE / BITS_PER_UNIT
273 0 : - bit_val));
274 0 : MEM_NOTRAP_P (mem) = 1;
275 0 : mem = convert_memory_address (Pmode, mem);
276 0 : emit_move_insn (funexp, mem);
277 :
278 0 : emit_label (call_lab);
279 :
280 0 : if (REG_P (chain))
281 : {
282 0 : use_reg (call_fusage, chain);
283 0 : STATIC_CHAIN_REG_P (chain) = 1;
284 : }
285 :
286 : /* Make sure we're not going to be overwritten below. */
287 0 : gcc_assert (!static_chain_value);
288 : }
289 :
290 : /* If we are using registers for parameters, force the
291 : function address into a register now. */
292 141781 : funexp = ((reg_parm_seen
293 141781 : && targetm.small_register_classes_for_mode_p (FUNCTION_MODE))
294 328793 : ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
295 45231 : : memory_address (FUNCTION_MODE, funexp));
296 : }
297 : else
298 : {
299 : /* funexp could be a SYMBOL_REF represents a function pointer which is
300 : of ptr_mode. In this case, it should be converted into address mode
301 : to be a valid address for memory rtx pattern. See PR 64971. */
302 6644844 : if (GET_MODE (funexp) != Pmode)
303 0 : funexp = convert_memory_address (Pmode, funexp);
304 :
305 : if (!(flags & ECF_SIBCALL))
306 : {
307 : if (!NO_FUNCTION_CSE && optimize && ! flag_no_function_cse)
308 : funexp = force_reg (Pmode, funexp);
309 : }
310 : }
311 :
312 6123828 : if (static_chain_value != 0
313 6123828 : && (TREE_CODE (fndecl_or_type) != FUNCTION_DECL
314 15498 : || DECL_STATIC_CHAIN (fndecl_or_type)))
315 : {
316 37818 : rtx chain;
317 :
318 37818 : chain = targetm.calls.static_chain (fndecl_or_type, false);
319 48233 : static_chain_value = convert_memory_address (Pmode, static_chain_value);
320 :
321 37818 : emit_move_insn (chain, static_chain_value);
322 37818 : if (REG_P (chain))
323 : {
324 37818 : use_reg (call_fusage, chain);
325 37818 : STATIC_CHAIN_REG_P (chain) = 1;
326 : }
327 : }
328 :
329 6123828 : return funexp;
330 : }
331 :
332 : /* Generate instructions to call function FUNEXP,
333 : and optionally pop the results.
334 : The CALL_INSN is the first insn generated.
335 :
336 : FNDECL is the declaration node of the function. This is given to the
337 : hook TARGET_RETURN_POPS_ARGS to determine whether this function pops
338 : its own args.
339 :
340 : FUNTYPE is the data type of the function. This is given to the hook
341 : TARGET_RETURN_POPS_ARGS to determine whether this function pops its
342 : own args. We used to allow an identifier for library functions, but
343 : that doesn't work when the return type is an aggregate type and the
344 : calling convention says that the pointer to this aggregate is to be
345 : popped by the callee.
346 :
347 : STACK_SIZE is the number of bytes of arguments on the stack,
348 : ROUNDED_STACK_SIZE is that number rounded up to
349 : PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
350 : both to put into the call insn and to generate explicit popping
351 : code if necessary.
352 :
353 : STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
354 : It is zero if this call doesn't want a structure value.
355 :
356 : NEXT_ARG_REG is the rtx that results from executing
357 : targetm.calls.function_arg (&args_so_far,
358 : function_arg_info::end_marker ());
359 : just after all the args have had their registers assigned.
360 : This could be whatever you like, but normally it is the first
361 : arg-register beyond those used for args in this call,
362 : or 0 if all the arg-registers are used in this call.
363 : It is passed on to `gen_call' so you can put this info in the call insn.
364 :
365 : VALREG is a hard register in which a value is returned,
366 : or 0 if the call does not return a value.
367 :
368 : OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
369 : the args to this call were processed.
370 : We restore `inhibit_defer_pop' to that value.
371 :
372 : CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
373 : denote registers used by the called function. */
374 :
375 : static void
376 6123345 : emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNUSED,
377 : tree funtype ATTRIBUTE_UNUSED,
378 : poly_int64 stack_size ATTRIBUTE_UNUSED,
379 : poly_int64 rounded_stack_size,
380 : poly_int64 struct_value_size ATTRIBUTE_UNUSED,
381 : rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg,
382 : int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags,
383 : cumulative_args_t args_so_far ATTRIBUTE_UNUSED)
384 : {
385 6865737 : rtx rounded_stack_size_rtx = gen_int_mode (rounded_stack_size, Pmode);
386 6123345 : rtx call, funmem, pat;
387 6123345 : bool already_popped = false;
388 6123345 : poly_int64 n_popped = 0;
389 :
390 : /* Sibling call patterns never pop arguments (no sibcall(_value)_pop
391 : patterns exist). Any popping that the callee does on return will
392 : be from our caller's frame rather than ours. */
393 6123345 : if (!(ecf_flags & ECF_SIBCALL))
394 : {
395 5992478 : n_popped += targetm.calls.return_pops_args (fndecl, funtype, stack_size);
396 :
397 : #ifdef CALL_POPS_ARGS
398 : n_popped += CALL_POPS_ARGS (*get_cumulative_args (args_so_far));
399 : #endif
400 : }
401 :
402 : /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
403 : and we don't want to load it into a register as an optimization,
404 : because prepare_call_address already did it if it should be done. */
405 6123345 : if (GET_CODE (funexp) != SYMBOL_REF)
406 186983 : funexp = memory_address (FUNCTION_MODE, funexp);
407 :
408 6123345 : funmem = gen_rtx_MEM (FUNCTION_MODE, funexp);
409 6123345 : if (fndecl && TREE_CODE (fndecl) == FUNCTION_DECL)
410 : {
411 5812378 : tree t = fndecl;
412 :
413 : /* Although a built-in FUNCTION_DECL and its non-__builtin
414 : counterpart compare equal and get a shared mem_attrs, they
415 : produce different dump output in compare-debug compilations,
416 : if an entry gets garbage collected in one compilation, then
417 : adds a different (but equivalent) entry, while the other
418 : doesn't run the garbage collector at the same spot and then
419 : shares the mem_attr with the equivalent entry. */
420 5812378 : if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL)
421 : {
422 1218847 : tree t2 = builtin_decl_explicit (DECL_FUNCTION_CODE (t));
423 1218847 : if (t2)
424 5812378 : t = t2;
425 : }
426 :
427 5812378 : set_mem_expr (funmem, t);
428 5812378 : }
429 310967 : else if (fntree)
430 187000 : set_mem_expr (funmem, build_simple_mem_ref (CALL_EXPR_FN (fntree)));
431 :
432 6123345 : if (ecf_flags & ECF_SIBCALL)
433 : {
434 130867 : if (valreg)
435 38232 : pat = targetm.gen_sibcall_value (valreg, funmem,
436 : rounded_stack_size_rtx,
437 : next_arg_reg, NULL_RTX);
438 : else
439 92635 : pat = targetm.gen_sibcall (funmem, rounded_stack_size_rtx,
440 : next_arg_reg,
441 92635 : gen_int_mode (struct_value_size, Pmode));
442 : }
443 : /* If the target has "call" or "call_value" insns, then prefer them
444 : if no arguments are actually popped. If the target does not have
445 : "call" or "call_value" insns, then we must use the popping versions
446 : even if the call has no arguments to pop. */
447 5992478 : else if (maybe_ne (n_popped, 0)
448 11857806 : || !(valreg
449 2484164 : ? targetm.have_call_value ()
450 3381164 : : targetm.have_call ()))
451 : {
452 254300 : rtx n_pop = gen_int_mode (n_popped, Pmode);
453 :
454 : /* If this subroutine pops its own args, record that in the call insn
455 : if possible, for the sake of frame pointer elimination. */
456 :
457 127150 : if (valreg)
458 0 : pat = targetm.gen_call_value_pop (valreg, funmem,
459 : rounded_stack_size_rtx,
460 : next_arg_reg, n_pop);
461 : else
462 127150 : pat = targetm.gen_call_pop (funmem, rounded_stack_size_rtx,
463 : next_arg_reg, n_pop);
464 :
465 : already_popped = true;
466 : }
467 : else
468 : {
469 5865328 : if (valreg)
470 2484164 : pat = targetm.gen_call_value (valreg, funmem, rounded_stack_size_rtx,
471 : next_arg_reg, NULL_RTX);
472 : else
473 3381164 : pat = targetm.gen_call (funmem, rounded_stack_size_rtx, next_arg_reg,
474 3381164 : gen_int_mode (struct_value_size, Pmode));
475 : }
476 6123345 : emit_insn (pat);
477 :
478 : /* Find the call we just emitted. */
479 6123345 : rtx_call_insn *call_insn = last_call_insn ();
480 :
481 : /* Some target create a fresh MEM instead of reusing the one provided
482 : above. Set its MEM_EXPR. */
483 6123345 : call = get_call_rtx_from (call_insn);
484 6123345 : if (call
485 6247917 : && MEM_EXPR (XEXP (call, 0)) == NULL_TREE
486 6247917 : && MEM_EXPR (funmem) != NULL_TREE)
487 605 : set_mem_expr (XEXP (call, 0), MEM_EXPR (funmem));
488 :
489 : /* Put the register usage information there. */
490 6123345 : add_function_usage_to (call_insn, call_fusage);
491 :
492 : /* If this is a const call, then set the insn's unchanging bit. */
493 6123345 : if (ecf_flags & ECF_CONST)
494 198156 : RTL_CONST_CALL_P (call_insn) = 1;
495 :
496 : /* If this is a pure call, then set the insn's unchanging bit. */
497 6123345 : if (ecf_flags & ECF_PURE)
498 318835 : RTL_PURE_CALL_P (call_insn) = 1;
499 :
500 : /* If this is a const call, then set the insn's unchanging bit. */
501 6123345 : if (ecf_flags & ECF_LOOPING_CONST_OR_PURE)
502 39250 : RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn) = 1;
503 :
504 : /* Create a nothrow REG_EH_REGION note, if needed. */
505 6123345 : make_reg_eh_region_note (call_insn, ecf_flags, 0);
506 :
507 6123345 : if (ecf_flags & ECF_NORETURN)
508 791298 : add_reg_note (call_insn, REG_NORETURN, const0_rtx);
509 :
510 6123345 : if (ecf_flags & ECF_RETURNS_TWICE)
511 : {
512 1660 : add_reg_note (call_insn, REG_SETJMP, const0_rtx);
513 1660 : cfun->calls_setjmp = 1;
514 : }
515 :
516 6123345 : CALL_INSN_ABI_ID (call_insn) = (funtype ? fntype_abi (funtype).id () : 0);
517 6123345 : SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
518 :
519 : /* Restore this now, so that we do defer pops for this call's args
520 : if the context of the call as a whole permits. */
521 6123345 : inhibit_defer_pop = old_inhibit_defer_pop;
522 :
523 6123345 : if (maybe_ne (n_popped, 0))
524 : {
525 127150 : if (!already_popped)
526 0 : CALL_INSN_FUNCTION_USAGE (call_insn)
527 0 : = gen_rtx_EXPR_LIST (VOIDmode,
528 : gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
529 : CALL_INSN_FUNCTION_USAGE (call_insn));
530 127150 : rounded_stack_size -= n_popped;
531 254300 : rounded_stack_size_rtx = gen_int_mode (rounded_stack_size, Pmode);
532 127150 : stack_pointer_delta -= n_popped;
533 :
534 127150 : add_args_size_note (call_insn, stack_pointer_delta);
535 :
536 : /* If popup is needed, stack realign must use DRAP */
537 127150 : if (SUPPORTS_STACK_ALIGNMENT)
538 127150 : crtl->need_drap = true;
539 : }
540 : /* For noreturn calls when not accumulating outgoing args force
541 : REG_ARGS_SIZE note to prevent crossjumping of calls with different
542 : args sizes. */
543 5996195 : else if (!ACCUMULATE_OUTGOING_ARGS && (ecf_flags & ECF_NORETURN) != 0)
544 791111 : add_args_size_note (call_insn, stack_pointer_delta);
545 :
546 6123345 : if (!ACCUMULATE_OUTGOING_ARGS)
547 : {
548 : /* If returning from the subroutine does not automatically pop the args,
549 : we need an instruction to pop them sooner or later.
550 : Perhaps do it now; perhaps just record how much space to pop later.
551 :
552 : If returning from the subroutine does pop the args, indicate that the
553 : stack pointer will be changed. */
554 :
555 6048752 : if (maybe_ne (rounded_stack_size, 0))
556 : {
557 944693 : if (ecf_flags & ECF_NORETURN)
558 : /* Just pretend we did the pop. */
559 6123345 : stack_pointer_delta -= rounded_stack_size;
560 890492 : else if (flag_defer_pop && inhibit_defer_pop == 0
561 783431 : && ! (ecf_flags & (ECF_CONST | ECF_PURE)))
562 6123345 : pending_stack_adjust += rounded_stack_size;
563 : else
564 123983 : adjust_stack (rounded_stack_size_rtx);
565 : }
566 : }
567 : /* When we accumulate outgoing args, we must avoid any stack manipulations.
568 : Restore the stack pointer to its original value now. Usually
569 : ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
570 : On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
571 : popping variants of functions exist as well.
572 :
573 : ??? We may optimize similar to defer_pop above, but it is
574 : probably not worthwhile.
575 :
576 : ??? It will be worthwhile to enable combine_stack_adjustments even for
577 : such machines. */
578 74593 : else if (maybe_ne (n_popped, 0))
579 0 : anti_adjust_stack (gen_int_mode (n_popped, Pmode));
580 6123345 : }
581 :
582 : /* Determine if the function identified by FNDECL is one with
583 : special properties we wish to know about. Modify FLAGS accordingly.
584 :
585 : For example, if the function might return more than one time (setjmp), then
586 : set ECF_RETURNS_TWICE.
587 :
588 : Set ECF_MAY_BE_ALLOCA for any memory allocation function that might allocate
589 : space from the stack such as alloca. */
590 :
591 : static int
592 4605103417 : special_function_p (const_tree fndecl, int flags)
593 : {
594 4605103417 : tree name_decl = DECL_NAME (fndecl);
595 :
596 4605103417 : if (maybe_special_function_p (fndecl)
597 7757497845 : && IDENTIFIER_LENGTH (name_decl) <= 11)
598 : {
599 575227644 : const char *name = IDENTIFIER_POINTER (name_decl);
600 575227644 : const char *tname = name;
601 :
602 : /* We assume that alloca will always be called by name. It
603 : makes no sense to pass it as a pointer-to-function to
604 : anything that does not understand its behavior. */
605 575227644 : if (IDENTIFIER_LENGTH (name_decl) == 6
606 146594680 : && name[0] == 'a'
607 575904524 : && ! strcmp (name, "alloca"))
608 79178 : flags |= ECF_MAY_BE_ALLOCA;
609 :
610 : /* Disregard prefix _ or __. */
611 575227644 : if (name[0] == '_')
612 : {
613 41211416 : if (name[1] == '_')
614 14510399 : tname += 2;
615 : else
616 26701017 : tname += 1;
617 : }
618 :
619 : /* ECF_RETURNS_TWICE is safe even for -ffreestanding. */
620 575227644 : if (! strcmp (tname, "setjmp")
621 574880635 : || ! strcmp (tname, "sigsetjmp")
622 574852368 : || ! strcmp (name, "savectx")
623 574852368 : || ! strcmp (name, "vfork")
624 574831081 : || ! strcmp (name, "getcontext"))
625 422678 : flags |= ECF_RETURNS_TWICE;
626 : }
627 :
628 4605103417 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
629 4605103417 : && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (fndecl)))
630 13546540 : flags |= ECF_MAY_BE_ALLOCA;
631 :
632 4605103417 : return flags;
633 : }
634 :
635 : /* Return fnspec for DECL. */
636 :
637 : static attr_fnspec
638 5812376 : decl_fnspec (tree fndecl)
639 : {
640 5812376 : tree attr;
641 5812376 : tree type = TREE_TYPE (fndecl);
642 5812376 : if (type)
643 : {
644 5812376 : attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
645 5812376 : if (attr)
646 : {
647 360909 : return TREE_VALUE (TREE_VALUE (attr));
648 : }
649 : }
650 5451467 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
651 1206629 : return builtin_fnspec (fndecl);
652 4244838 : return "";
653 : }
654 :
655 : /* Similar to special_function_p; return a set of ERF_ flags for the
656 : function FNDECL. */
657 : static int
658 5812376 : decl_return_flags (tree fndecl)
659 : {
660 5812376 : attr_fnspec fnspec = decl_fnspec (fndecl);
661 :
662 5812376 : unsigned int arg;
663 5812376 : if (fnspec.returns_arg (&arg))
664 168688 : return ERF_RETURNS_ARG | arg;
665 :
666 5643688 : if (fnspec.returns_noalias_p ())
667 63145 : return ERF_NOALIAS;
668 : return 0;
669 : }
670 :
671 : /* Return true when FNDECL represents a call to setjmp. */
672 :
673 : bool
674 33247938 : setjmp_call_p (const_tree fndecl)
675 : {
676 33247938 : if (DECL_IS_RETURNS_TWICE (fndecl))
677 : return true;
678 33246334 : if (special_function_p (fndecl, 0) & ECF_RETURNS_TWICE)
679 2237 : return true;
680 :
681 : return false;
682 : }
683 :
684 :
685 : /* Return true if STMT may be an alloca call. */
686 :
687 : bool
688 19329362 : gimple_maybe_alloca_call_p (const gimple *stmt)
689 : {
690 19329362 : tree fndecl;
691 :
692 19329362 : if (!is_gimple_call (stmt))
693 : return false;
694 :
695 19329362 : fndecl = gimple_call_fndecl (stmt);
696 19329362 : if (fndecl && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA))
697 10118 : return true;
698 :
699 : return false;
700 : }
701 :
702 : /* Return true if STMT is a builtin alloca call. */
703 :
704 : bool
705 170513532 : gimple_alloca_call_p (const gimple *stmt)
706 : {
707 170513532 : tree fndecl;
708 :
709 170513532 : if (!is_gimple_call (stmt))
710 : return false;
711 :
712 28110750 : fndecl = gimple_call_fndecl (stmt);
713 28110750 : if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
714 6768775 : switch (DECL_FUNCTION_CODE (fndecl))
715 : {
716 170297 : CASE_BUILT_IN_ALLOCA:
717 170297 : return gimple_call_num_args (stmt) > 0;
718 : default:
719 : break;
720 : }
721 :
722 : return false;
723 : }
724 :
725 : /* Return true when exp contains a builtin alloca call. */
726 :
727 : bool
728 3108764 : alloca_call_p (const_tree exp)
729 : {
730 3108764 : tree fndecl;
731 3108764 : if (TREE_CODE (exp) == CALL_EXPR
732 3108764 : && (fndecl = get_callee_fndecl (exp))
733 6217528 : && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
734 1766432 : switch (DECL_FUNCTION_CODE (fndecl))
735 : {
736 0 : CASE_BUILT_IN_ALLOCA:
737 0 : return true;
738 : default:
739 : break;
740 : }
741 :
742 : return false;
743 : }
744 :
745 : /* Return TRUE if FNDECL is either a TM builtin or a TM cloned
746 : function. Return FALSE otherwise. */
747 :
748 : static bool
749 866232 : is_tm_builtin (const_tree fndecl)
750 : {
751 866232 : if (fndecl == NULL)
752 : return false;
753 :
754 1636757 : if (decl_is_tm_clone (fndecl))
755 : return true;
756 :
757 843724 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
758 : {
759 458572 : switch (DECL_FUNCTION_CODE (fndecl))
760 : {
761 316628 : case BUILT_IN_TM_COMMIT:
762 316628 : case BUILT_IN_TM_COMMIT_EH:
763 316628 : case BUILT_IN_TM_ABORT:
764 316628 : case BUILT_IN_TM_IRREVOCABLE:
765 316628 : case BUILT_IN_TM_GETTMCLONE_IRR:
766 316628 : case BUILT_IN_TM_MEMCPY:
767 316628 : case BUILT_IN_TM_MEMMOVE:
768 316628 : case BUILT_IN_TM_MEMSET:
769 316628 : CASE_BUILT_IN_TM_STORE (1):
770 316628 : CASE_BUILT_IN_TM_STORE (2):
771 316628 : CASE_BUILT_IN_TM_STORE (4):
772 316628 : CASE_BUILT_IN_TM_STORE (8):
773 316628 : CASE_BUILT_IN_TM_STORE (FLOAT):
774 316628 : CASE_BUILT_IN_TM_STORE (DOUBLE):
775 316628 : CASE_BUILT_IN_TM_STORE (LDOUBLE):
776 316628 : CASE_BUILT_IN_TM_STORE (M64):
777 316628 : CASE_BUILT_IN_TM_STORE (M128):
778 316628 : CASE_BUILT_IN_TM_STORE (M256):
779 316628 : CASE_BUILT_IN_TM_LOAD (1):
780 316628 : CASE_BUILT_IN_TM_LOAD (2):
781 316628 : CASE_BUILT_IN_TM_LOAD (4):
782 316628 : CASE_BUILT_IN_TM_LOAD (8):
783 316628 : CASE_BUILT_IN_TM_LOAD (FLOAT):
784 316628 : CASE_BUILT_IN_TM_LOAD (DOUBLE):
785 316628 : CASE_BUILT_IN_TM_LOAD (LDOUBLE):
786 316628 : CASE_BUILT_IN_TM_LOAD (M64):
787 316628 : CASE_BUILT_IN_TM_LOAD (M128):
788 316628 : CASE_BUILT_IN_TM_LOAD (M256):
789 316628 : case BUILT_IN_TM_LOG:
790 316628 : case BUILT_IN_TM_LOG_1:
791 316628 : case BUILT_IN_TM_LOG_2:
792 316628 : case BUILT_IN_TM_LOG_4:
793 316628 : case BUILT_IN_TM_LOG_8:
794 316628 : case BUILT_IN_TM_LOG_FLOAT:
795 316628 : case BUILT_IN_TM_LOG_DOUBLE:
796 316628 : case BUILT_IN_TM_LOG_LDOUBLE:
797 316628 : case BUILT_IN_TM_LOG_M64:
798 316628 : case BUILT_IN_TM_LOG_M128:
799 316628 : case BUILT_IN_TM_LOG_M256:
800 316628 : return true;
801 : default:
802 : break;
803 : }
804 : }
805 : return false;
806 : }
807 :
808 : /* Detect flags (function attributes) from the function decl or type node. */
809 :
810 : int
811 8759507909 : flags_from_decl_or_type (const_tree exp)
812 : {
813 8759507909 : int flags = 0;
814 :
815 8759507909 : if (DECL_P (exp))
816 : {
817 : /* The function exp may have the `malloc' attribute. */
818 4553245877 : if (DECL_IS_MALLOC (exp))
819 101233846 : flags |= ECF_MALLOC;
820 :
821 : /* The function exp may have the `returns_twice' attribute. */
822 4553245877 : if (DECL_IS_RETURNS_TWICE (exp))
823 279218 : flags |= ECF_RETURNS_TWICE;
824 :
825 : /* Process the pure and const attributes. */
826 4553245877 : if (TREE_READONLY (exp))
827 293200425 : flags |= ECF_CONST;
828 4553245877 : if (DECL_PURE_P (exp))
829 257353540 : flags |= ECF_PURE;
830 4553245877 : if (DECL_LOOPING_CONST_OR_PURE_P (exp))
831 22007492 : flags |= ECF_LOOPING_CONST_OR_PURE;
832 :
833 4553245877 : if (DECL_IS_NOVOPS (exp))
834 638915 : flags |= ECF_NOVOPS;
835 4553245877 : if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp)))
836 887151942 : flags |= ECF_LEAF;
837 4553245877 : if (lookup_attribute ("cold", DECL_ATTRIBUTES (exp)))
838 387155738 : flags |= ECF_COLD;
839 :
840 4553245877 : if (TREE_NOTHROW (exp))
841 2002384163 : flags |= ECF_NOTHROW;
842 :
843 4553245877 : if (flag_tm)
844 : {
845 866232 : if (is_tm_builtin (exp))
846 339136 : flags |= ECF_TM_BUILTIN;
847 527096 : else if ((flags & (ECF_CONST|ECF_NOVOPS)) != 0
848 1038853 : || lookup_attribute ("transaction_pure",
849 511757 : TYPE_ATTRIBUTES (TREE_TYPE (exp))))
850 122723 : flags |= ECF_TM_PURE;
851 : }
852 :
853 4553245877 : if (lookup_attribute ("expected_throw", DECL_ATTRIBUTES (exp)))
854 17629040 : flags |= ECF_XTHROW;
855 :
856 4553245877 : flags = special_function_p (exp, flags);
857 :
858 4553245877 : if ((flags & ECF_CONST) == 0
859 8813291329 : && lookup_attribute ("unsequenced noptr",
860 4260045452 : TYPE_ATTRIBUTES (TREE_TYPE (exp))))
861 : {
862 : /* [[unsequenced]] with no pointers in arguments is like
863 : [[gnu::const]] without finite guarantee. */
864 123166 : flags |= ECF_CONST;
865 123166 : if ((flags & ECF_PURE) == 0)
866 123166 : flags |= ECF_LOOPING_CONST_OR_PURE;
867 : }
868 123166 : if ((flags & (ECF_CONST | ECF_PURE)) == 0
869 8555691457 : && lookup_attribute ("reproducible noptr",
870 4002568746 : TYPE_ATTRIBUTES (TREE_TYPE (exp))))
871 : /* [[reproducible]] with no pointers in arguments is like
872 : [[gnu::pure]] without finite guarantee. */
873 148482 : flags |= ECF_PURE | ECF_LOOPING_CONST_OR_PURE;
874 : }
875 4206262032 : else if (TYPE_P (exp))
876 : {
877 4206262032 : if (TYPE_READONLY (exp))
878 41291883 : flags |= ECF_CONST;
879 :
880 4206262032 : if (flag_tm
881 4206262032 : && ((flags & ECF_CONST) != 0
882 823939 : || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp))))
883 107064 : flags |= ECF_TM_PURE;
884 :
885 4206262032 : if ((flags & ECF_CONST) == 0
886 4206262032 : && lookup_attribute ("unsequenced noptr", TYPE_ATTRIBUTES (exp)))
887 : /* [[unsequenced]] with no pointers in arguments is like
888 : [[gnu::const]] without finite guarantee. */
889 121485 : flags |= ECF_CONST | ECF_LOOPING_CONST_OR_PURE;
890 121485 : if ((flags & ECF_CONST) == 0
891 4206140547 : && lookup_attribute ("reproducible noptr", TYPE_ATTRIBUTES (exp)))
892 : /* [[reproducible]] with no pointers in arguments is like
893 : [[gnu::pure]] without finite guarantee. */
894 152705 : flags |= ECF_PURE | ECF_LOOPING_CONST_OR_PURE;
895 : }
896 : else
897 0 : gcc_unreachable ();
898 :
899 8759507909 : if (TREE_THIS_VOLATILE (exp))
900 : {
901 806263619 : flags |= ECF_NORETURN;
902 806263619 : if (flags & (ECF_CONST|ECF_PURE))
903 127521687 : flags |= ECF_LOOPING_CONST_OR_PURE;
904 : }
905 :
906 8759507909 : return flags;
907 : }
908 :
909 : /* Detect flags from a CALL_EXPR. */
910 :
911 : int
912 337442957 : call_expr_flags (const_tree t)
913 : {
914 337442957 : int flags;
915 337442957 : tree decl = get_callee_fndecl (t);
916 :
917 337442957 : if (decl)
918 304193652 : flags = flags_from_decl_or_type (decl);
919 33249305 : else if (CALL_EXPR_FN (t) == NULL_TREE)
920 1137946 : flags = internal_fn_flags (CALL_EXPR_IFN (t));
921 : else
922 : {
923 32111359 : tree type = TREE_TYPE (CALL_EXPR_FN (t));
924 32111359 : if (type && TREE_CODE (type) == POINTER_TYPE)
925 7461080 : flags = flags_from_decl_or_type (TREE_TYPE (type));
926 : else
927 : flags = 0;
928 32111359 : if (CALL_EXPR_BY_DESCRIPTOR (t))
929 0 : flags |= ECF_BY_DESCRIPTOR;
930 : }
931 :
932 337442957 : return flags;
933 : }
934 :
935 : /* Return true if ARG should be passed by invisible reference. */
936 :
937 : bool
938 22176186 : pass_by_reference (CUMULATIVE_ARGS *ca, function_arg_info arg)
939 : {
940 22176186 : if (tree type = arg.type)
941 : {
942 : /* If this type contains non-trivial constructors, then it is
943 : forbidden for the middle-end to create any new copies. */
944 21963672 : if (TREE_ADDRESSABLE (type))
945 : return true;
946 :
947 : /* GCC post 3.4 passes *all* variable sized types by reference. */
948 21963532 : if (!TYPE_SIZE (type) || !poly_int_tree_p (TYPE_SIZE (type)))
949 : return true;
950 :
951 : /* If a record type should be passed the same as its first (and only)
952 : member, use the type and mode of that member. */
953 21963018 : if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
954 : {
955 18 : arg.type = TREE_TYPE (first_field (type));
956 18 : arg.mode = TYPE_MODE (arg.type);
957 : }
958 : }
959 :
960 22175532 : return targetm.calls.pass_by_reference (pack_cumulative_args (ca), arg);
961 : }
962 :
963 : /* Return true if TYPE should be passed by reference when passed to
964 : the "..." arguments of a function. */
965 :
966 : bool
967 52304 : pass_va_arg_by_reference (tree type)
968 : {
969 52304 : return pass_by_reference (NULL, function_arg_info (type, /*named=*/false));
970 : }
971 :
972 : /* Decide whether ARG, which occurs in the state described by CA,
973 : should be passed by reference. Return true if so and update
974 : ARG accordingly. */
975 :
976 : bool
977 9534522 : apply_pass_by_reference_rules (CUMULATIVE_ARGS *ca, function_arg_info &arg)
978 : {
979 9534522 : if (pass_by_reference (ca, arg))
980 : {
981 10137 : arg.type = build_pointer_type (arg.type);
982 10137 : arg.mode = TYPE_MODE (arg.type);
983 10137 : arg.pass_by_reference = true;
984 10137 : return true;
985 : }
986 : return false;
987 : }
988 :
989 : /* Return true if ARG, which is passed by reference, should be callee
990 : copied instead of caller copied. */
991 :
992 : bool
993 5360 : reference_callee_copied (CUMULATIVE_ARGS *ca, const function_arg_info &arg)
994 : {
995 5360 : if (arg.type && TREE_ADDRESSABLE (arg.type))
996 : return false;
997 5340 : return targetm.calls.callee_copies (pack_cumulative_args (ca), arg);
998 : }
999 :
1000 :
1001 : /* Precompute all register parameters as described by ARGS, storing values
1002 : into fields within the ARGS array.
1003 :
1004 : NUM_ACTUALS indicates the total number elements in the ARGS array.
1005 :
1006 : Set REG_PARM_SEEN if we encounter a register parameter. */
1007 :
1008 : static void
1009 5999380 : precompute_register_parameters (int num_actuals, struct arg_data *args,
1010 : int *reg_parm_seen)
1011 : {
1012 5999380 : int i;
1013 :
1014 5999380 : *reg_parm_seen = 0;
1015 :
1016 18376264 : for (i = 0; i < num_actuals; i++)
1017 12376886 : if (args[i].reg != 0 && ! args[i].pass_on_stack)
1018 : {
1019 10223176 : *reg_parm_seen = 1;
1020 :
1021 10223176 : if (args[i].value == 0)
1022 : {
1023 10223176 : push_temp_slots ();
1024 10223176 : args[i].value = expand_normal (args[i].tree_value);
1025 10223174 : preserve_temp_slots (args[i].value);
1026 10223174 : pop_temp_slots ();
1027 : }
1028 :
1029 : /* If we are to promote the function arg to a wider mode,
1030 : do it now. */
1031 :
1032 10223174 : machine_mode old_mode = TYPE_MODE (TREE_TYPE (args[i].tree_value));
1033 :
1034 : /* Some ABIs require scalar floating point modes to be returned
1035 : in a wider scalar integer mode. We need to explicitly
1036 : reinterpret to an integer mode of the correct precision
1037 : before extending to the desired result. */
1038 10223174 : if (SCALAR_INT_MODE_P (args[i].mode)
1039 9831876 : && SCALAR_FLOAT_MODE_P (old_mode)
1040 10223174 : && known_gt (GET_MODE_SIZE (args[i].mode),
1041 : GET_MODE_SIZE (old_mode)))
1042 0 : args[i].value = convert_float_to_wider_int (args[i].mode, old_mode,
1043 : args[i].value);
1044 10223174 : else if (args[i].mode != old_mode)
1045 319146 : args[i].value = convert_modes (args[i].mode, old_mode,
1046 : args[i].value, args[i].unsignedp);
1047 :
1048 : /* If the value is a non-legitimate constant, force it into a
1049 : pseudo now. TLS symbols sometimes need a call to resolve. */
1050 10223174 : if (CONSTANT_P (args[i].value)
1051 10223174 : && (!targetm.legitimate_constant_p (args[i].mode, args[i].value)
1052 4426532 : || targetm.precompute_tls_p (args[i].mode, args[i].value)))
1053 4201 : args[i].value = force_reg (args[i].mode, args[i].value);
1054 :
1055 : /* If we're going to have to load the value by parts, pull the
1056 : parts into pseudos. The part extraction process can involve
1057 : non-trivial computation. */
1058 10223174 : if (GET_CODE (args[i].reg) == PARALLEL)
1059 : {
1060 287205 : tree type = TREE_TYPE (args[i].tree_value);
1061 287205 : args[i].parallel_value
1062 287205 : = emit_group_load_into_temps (args[i].reg, args[i].value,
1063 287205 : type, int_size_in_bytes (type));
1064 : }
1065 :
1066 : /* If the value is expensive, and we are inside an appropriately
1067 : short loop, put the value into a pseudo and then put the pseudo
1068 : into the hard reg.
1069 :
1070 : For small register classes, also do this if this call uses
1071 : register parameters. This is to avoid reload conflicts while
1072 : loading the parameters registers. */
1073 :
1074 5204750 : else if ((! (REG_P (args[i].value)
1075 : || (GET_CODE (args[i].value) == SUBREG
1076 19643 : && REG_P (SUBREG_REG (args[i].value)))))
1077 5185107 : && args[i].mode != BLKmode
1078 5183485 : && (set_src_cost (args[i].value, args[i].mode,
1079 : optimize_insn_for_speed_p ())
1080 : > COSTS_N_INSNS (1))
1081 10947486 : && ((*reg_parm_seen
1082 1011517 : && targetm.small_register_classes_for_mode_p (args[i].mode))
1083 0 : || optimize))
1084 1011517 : args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
1085 : }
1086 5999378 : }
1087 :
1088 : #ifdef REG_PARM_STACK_SPACE
1089 :
1090 : /* The argument list is the property of the called routine and it
1091 : may clobber it. If the fixed area has been used for previous
1092 : parameters, we must save and restore it. */
1093 :
1094 : static rtx
1095 73399 : save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
1096 : {
1097 73399 : unsigned int low;
1098 73399 : unsigned int high;
1099 :
1100 : /* Compute the boundary of the area that needs to be saved, if any. */
1101 73399 : high = reg_parm_stack_space;
1102 73399 : if (ARGS_GROW_DOWNWARD)
1103 : high += 1;
1104 :
1105 73399 : if (high > highest_outgoing_arg_in_use)
1106 : high = highest_outgoing_arg_in_use;
1107 :
1108 264695 : for (low = 0; low < high; low++)
1109 191296 : if (stack_usage_map[low] != 0 || low >= stack_usage_watermark)
1110 : {
1111 : int num_to_save;
1112 : machine_mode save_mode;
1113 : int delta;
1114 : rtx addr;
1115 : rtx stack_area;
1116 : rtx save_area;
1117 :
1118 0 : while (stack_usage_map[--high] == 0)
1119 : ;
1120 :
1121 0 : *low_to_save = low;
1122 0 : *high_to_save = high;
1123 :
1124 0 : num_to_save = high - low + 1;
1125 :
1126 : /* If we don't have the required alignment, must do this
1127 : in BLKmode. */
1128 0 : scalar_int_mode imode;
1129 0 : if (int_mode_for_size (num_to_save * BITS_PER_UNIT, 1).exists (&imode)
1130 0 : && (low & (MIN (GET_MODE_SIZE (imode),
1131 0 : BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)) == 0)
1132 0 : save_mode = imode;
1133 : else
1134 : save_mode = BLKmode;
1135 :
1136 0 : if (ARGS_GROW_DOWNWARD)
1137 : delta = -high;
1138 : else
1139 0 : delta = low;
1140 :
1141 0 : addr = plus_constant (Pmode, argblock, delta);
1142 0 : stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr));
1143 :
1144 0 : set_mem_align (stack_area, PARM_BOUNDARY);
1145 0 : if (save_mode == BLKmode)
1146 : {
1147 0 : save_area = assign_stack_temp (BLKmode, num_to_save);
1148 0 : emit_block_move (validize_mem (save_area), stack_area,
1149 : GEN_INT (num_to_save), BLOCK_OP_CALL_PARM);
1150 : }
1151 : else
1152 : {
1153 0 : save_area = gen_reg_rtx (save_mode);
1154 0 : emit_move_insn (save_area, stack_area);
1155 : }
1156 :
1157 : return save_area;
1158 : }
1159 :
1160 : return NULL_RTX;
1161 : }
1162 :
1163 : static void
1164 0 : restore_fixed_argument_area (rtx save_area, rtx argblock, int high_to_save, int low_to_save)
1165 : {
1166 0 : machine_mode save_mode = GET_MODE (save_area);
1167 0 : int delta;
1168 0 : rtx addr, stack_area;
1169 :
1170 0 : if (ARGS_GROW_DOWNWARD)
1171 : delta = -high_to_save;
1172 : else
1173 0 : delta = low_to_save;
1174 :
1175 0 : addr = plus_constant (Pmode, argblock, delta);
1176 0 : stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr));
1177 0 : set_mem_align (stack_area, PARM_BOUNDARY);
1178 :
1179 0 : if (save_mode != BLKmode)
1180 0 : emit_move_insn (stack_area, save_area);
1181 : else
1182 0 : emit_block_move (stack_area, validize_mem (save_area),
1183 0 : GEN_INT (high_to_save - low_to_save + 1),
1184 : BLOCK_OP_CALL_PARM);
1185 0 : }
1186 : #endif /* REG_PARM_STACK_SPACE */
1187 :
1188 : /* If any elements in ARGS refer to parameters that are to be passed in
1189 : registers, but not in memory, and whose alignment does not permit a
1190 : direct copy into registers. Copy the values into a group of pseudos
1191 : which we will later copy into the appropriate hard registers.
1192 :
1193 : Pseudos for each unaligned argument will be stored into the array
1194 : args[argnum].aligned_regs. The caller is responsible for deallocating
1195 : the aligned_regs array if it is nonzero. */
1196 :
1197 : static void
1198 0 : store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals)
1199 : {
1200 0 : int i, j;
1201 :
1202 0 : for (i = 0; i < num_actuals; i++)
1203 0 : if (args[i].reg != 0 && ! args[i].pass_on_stack
1204 0 : && GET_CODE (args[i].reg) != PARALLEL
1205 0 : && args[i].mode == BLKmode
1206 0 : && MEM_P (args[i].value)
1207 0 : && (MEM_ALIGN (args[i].value)
1208 0 : < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
1209 : {
1210 0 : int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1211 0 : int endian_correction = 0;
1212 :
1213 0 : if (args[i].partial)
1214 : {
1215 0 : gcc_assert (args[i].partial % UNITS_PER_WORD == 0);
1216 0 : args[i].n_aligned_regs = args[i].partial / UNITS_PER_WORD;
1217 : }
1218 : else
1219 : {
1220 0 : args[i].n_aligned_regs
1221 0 : = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1222 : }
1223 :
1224 0 : args[i].aligned_regs = XNEWVEC (rtx, args[i].n_aligned_regs);
1225 :
1226 : /* Structures smaller than a word are normally aligned to the
1227 : least significant byte. On a BYTES_BIG_ENDIAN machine,
1228 : this means we must skip the empty high order bytes when
1229 : calculating the bit offset. */
1230 0 : if (bytes < UNITS_PER_WORD
1231 : #ifdef BLOCK_REG_PADDING
1232 : && (BLOCK_REG_PADDING (args[i].mode,
1233 : TREE_TYPE (args[i].tree_value), 1)
1234 : == PAD_DOWNWARD)
1235 : #else
1236 : && BYTES_BIG_ENDIAN
1237 : #endif
1238 : )
1239 : endian_correction = BITS_PER_WORD - bytes * BITS_PER_UNIT;
1240 :
1241 0 : for (j = 0; j < args[i].n_aligned_regs; j++)
1242 : {
1243 0 : rtx reg = gen_reg_rtx (word_mode);
1244 0 : rtx word = operand_subword_force (args[i].value, j, BLKmode);
1245 0 : int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
1246 :
1247 0 : args[i].aligned_regs[j] = reg;
1248 0 : word = extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
1249 : word_mode, word_mode, false, NULL);
1250 :
1251 : /* There is no need to restrict this code to loading items
1252 : in TYPE_ALIGN sized hunks. The bitfield instructions can
1253 : load up entire word sized registers efficiently.
1254 :
1255 : ??? This may not be needed anymore.
1256 : We use to emit a clobber here but that doesn't let later
1257 : passes optimize the instructions we emit. By storing 0 into
1258 : the register later passes know the first AND to zero out the
1259 : bitfield being set in the register is unnecessary. The store
1260 : of 0 will be deleted as will at least the first AND. */
1261 :
1262 0 : emit_move_insn (reg, const0_rtx);
1263 :
1264 0 : bytes -= bitsize / BITS_PER_UNIT;
1265 0 : store_bit_field (reg, bitsize, endian_correction, 0, 0,
1266 : word_mode, word, false, false);
1267 : }
1268 : }
1269 0 : }
1270 :
1271 : /* Issue an error if CALL_EXPR was flagged as requiring
1272 : tall-call optimization. */
1273 :
1274 : void
1275 5876071 : maybe_complain_about_tail_call (tree call_expr, const char *reason)
1276 : {
1277 5876071 : gcc_assert (TREE_CODE (call_expr) == CALL_EXPR);
1278 5876071 : if (CALL_EXPR_TAILCALL (call_expr)
1279 11158 : && dump_file
1280 5876071 : && (dump_flags & TDF_DETAILS))
1281 : {
1282 0 : fprintf (dump_file, ";; Cannot tail-call: %s: ", reason);
1283 0 : print_generic_expr (dump_file, call_expr, TDF_SLIM);
1284 0 : fprintf (dump_file, "\n");
1285 : }
1286 5876071 : if (CALL_EXPR_MUST_TAIL_CALL (call_expr))
1287 : {
1288 20 : error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason);
1289 20 : CALL_EXPR_MUST_TAIL_CALL (call_expr) = 0;
1290 : }
1291 5876071 : }
1292 :
1293 : /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
1294 : CALL_EXPR EXP.
1295 :
1296 : NUM_ACTUALS is the total number of parameters.
1297 :
1298 : N_NAMED_ARGS is the total number of named arguments.
1299 :
1300 : STRUCT_VALUE_ADDR_VALUE is the implicit argument for a struct return
1301 : value, or null.
1302 :
1303 : FNDECL is the tree code for the target of this call (if known)
1304 :
1305 : ARGS_SO_FAR holds state needed by the target to know where to place
1306 : the next argument.
1307 :
1308 : REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
1309 : for arguments which are passed in registers.
1310 :
1311 : OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
1312 : and may be modified by this routine.
1313 :
1314 : OLD_PENDING_ADJ and FLAGS are pointers to integer flags which
1315 : may be modified by this routine.
1316 :
1317 : MUST_PREALLOCATE is a pointer to bool which may be
1318 : modified by this routine.
1319 :
1320 : MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
1321 : that requires allocation of stack space.
1322 :
1323 : CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
1324 : the thunked-to function. */
1325 :
1326 : static void
1327 5999376 : initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
1328 : struct arg_data *args,
1329 : struct args_size *args_size,
1330 : int n_named_args ATTRIBUTE_UNUSED,
1331 : tree exp, tree struct_value_addr_value,
1332 : tree fndecl, tree fntype,
1333 : cumulative_args_t args_so_far,
1334 : int reg_parm_stack_space,
1335 : rtx *old_stack_level,
1336 : poly_int64 *old_pending_adj,
1337 : bool *must_preallocate, int *ecf_flags,
1338 : bool *may_tailcall, bool call_from_thunk_p)
1339 : {
1340 5999376 : CUMULATIVE_ARGS *args_so_far_pnt = get_cumulative_args (args_so_far);
1341 5999376 : location_t loc = EXPR_LOCATION (exp);
1342 :
1343 : /* Count arg position in order args appear. */
1344 5999376 : int argpos;
1345 :
1346 5999376 : int i;
1347 :
1348 5999376 : args_size->constant = 0;
1349 5999376 : args_size->var = 0;
1350 :
1351 : /* In this loop, we consider args in the order they are written.
1352 : We fill up ARGS from the back. */
1353 :
1354 5999376 : i = num_actuals - 1;
1355 5999376 : {
1356 5999376 : int j = i;
1357 5999376 : call_expr_arg_iterator iter;
1358 5999376 : tree arg;
1359 :
1360 5999376 : if (struct_value_addr_value)
1361 : {
1362 227410 : args[j].tree_value = struct_value_addr_value;
1363 227410 : j--;
1364 : }
1365 5999376 : argpos = 0;
1366 24148188 : FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
1367 : {
1368 12149436 : tree argtype = TREE_TYPE (arg);
1369 :
1370 12149436 : if (targetm.calls.split_complex_arg
1371 0 : && argtype
1372 0 : && TREE_CODE (argtype) == COMPLEX_TYPE
1373 12149436 : && targetm.calls.split_complex_arg (argtype))
1374 : {
1375 0 : tree subtype = TREE_TYPE (argtype);
1376 0 : args[j].tree_value = build1 (REALPART_EXPR, subtype, arg);
1377 0 : j--;
1378 0 : args[j].tree_value = build1 (IMAGPART_EXPR, subtype, arg);
1379 : }
1380 : else
1381 12149436 : args[j].tree_value = arg;
1382 12149436 : j--;
1383 12149436 : argpos++;
1384 : }
1385 : }
1386 :
1387 5999376 : bool promote_p
1388 11811752 : = targetm.calls.promote_prototypes (fndecl
1389 5812376 : ? TREE_TYPE (fndecl)
1390 : : fntype);
1391 :
1392 : /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1393 24375598 : for (argpos = 0; argpos < num_actuals; i--, argpos++)
1394 : {
1395 12376846 : tree type = TREE_TYPE (args[i].tree_value);
1396 12376846 : int unsignedp;
1397 :
1398 : /* Replace erroneous argument with constant zero. */
1399 12376846 : if (type == error_mark_node || !COMPLETE_TYPE_P (type))
1400 0 : args[i].tree_value = integer_zero_node, type = integer_type_node;
1401 :
1402 : /* If TYPE is a transparent union or record, pass things the way
1403 : we would pass the first field of the union or record. We have
1404 : already verified that the modes are the same. */
1405 12376846 : if (RECORD_OR_UNION_TYPE_P (type) && TYPE_TRANSPARENT_AGGR (type))
1406 3602 : type = TREE_TYPE (first_field (type));
1407 :
1408 : /* Decide where to pass this arg.
1409 :
1410 : args[i].reg is nonzero if all or part is passed in registers.
1411 :
1412 : args[i].partial is nonzero if part but not all is passed in registers,
1413 : and the exact value says how many bytes are passed in registers.
1414 :
1415 : args[i].pass_on_stack is true if the argument must at least be
1416 : computed on the stack. It may then be loaded back into registers
1417 : if args[i].reg is nonzero.
1418 :
1419 : These decisions are driven by the FUNCTION_... macros and must agree
1420 : with those made by function.cc. */
1421 :
1422 : /* See if this argument should be passed by invisible reference. */
1423 12376846 : function_arg_info arg (type, argpos < n_named_args);
1424 12376846 : if (pass_by_reference (args_so_far_pnt, arg))
1425 : {
1426 386 : const bool callee_copies
1427 386 : = reference_callee_copied (args_so_far_pnt, arg);
1428 386 : tree base;
1429 :
1430 : /* If we're compiling a thunk, pass directly the address of an object
1431 : already in memory, instead of making a copy. Likewise if we want
1432 : to make the copy in the callee instead of the caller. */
1433 386 : if ((call_from_thunk_p || callee_copies)
1434 20 : && TREE_CODE (args[i].tree_value) != WITH_SIZE_EXPR
1435 20 : && ((base = get_base_address (args[i].tree_value)), true)
1436 20 : && TREE_CODE (base) != SSA_NAME
1437 406 : && (!DECL_P (base) || MEM_P (DECL_RTL (base))))
1438 : {
1439 : /* We may have turned the parameter value into an SSA name.
1440 : Go back to the original parameter so we can take the
1441 : address. */
1442 20 : if (TREE_CODE (args[i].tree_value) == SSA_NAME)
1443 : {
1444 0 : gcc_assert (SSA_NAME_IS_DEFAULT_DEF (args[i].tree_value));
1445 0 : args[i].tree_value = SSA_NAME_VAR (args[i].tree_value);
1446 0 : gcc_assert (TREE_CODE (args[i].tree_value) == PARM_DECL);
1447 : }
1448 : /* Argument setup code may have copied the value to register. We
1449 : revert that optimization now because the tail call code must
1450 : use the original location. */
1451 20 : if (TREE_CODE (args[i].tree_value) == PARM_DECL
1452 0 : && !MEM_P (DECL_RTL (args[i].tree_value))
1453 0 : && DECL_INCOMING_RTL (args[i].tree_value)
1454 20 : && MEM_P (DECL_INCOMING_RTL (args[i].tree_value)))
1455 0 : set_decl_rtl (args[i].tree_value,
1456 0 : DECL_INCOMING_RTL (args[i].tree_value));
1457 :
1458 20 : mark_addressable (args[i].tree_value);
1459 :
1460 : /* We can't use sibcalls if a callee-copied argument is
1461 : stored in the current function's frame. */
1462 20 : if (!call_from_thunk_p && DECL_P (base) && !TREE_STATIC (base))
1463 : {
1464 0 : *may_tailcall = false;
1465 0 : maybe_complain_about_tail_call (exp, _("a callee-copied "
1466 : "argument is stored "
1467 : "in the current "
1468 : "function's frame"));
1469 : }
1470 :
1471 20 : args[i].tree_value = build_fold_addr_expr_loc (loc,
1472 : args[i].tree_value);
1473 20 : type = TREE_TYPE (args[i].tree_value);
1474 :
1475 20 : if (*ecf_flags & ECF_CONST)
1476 0 : *ecf_flags &= ~(ECF_CONST | ECF_LOOPING_CONST_OR_PURE);
1477 : }
1478 : else
1479 : {
1480 : /* We make a copy of the object and pass the address to the
1481 : function being called. */
1482 366 : rtx copy;
1483 :
1484 366 : if (!COMPLETE_TYPE_P (type)
1485 366 : || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
1486 475 : || (flag_stack_check == GENERIC_STACK_CHECK
1487 0 : && compare_tree_int (TYPE_SIZE_UNIT (type),
1488 : STACK_CHECK_MAX_VAR_SIZE) > 0))
1489 : {
1490 : /* This is a variable-sized object. Make space on the stack
1491 : for it. */
1492 257 : rtx size_rtx = expr_size (args[i].tree_value);
1493 :
1494 257 : if (*old_stack_level == 0)
1495 : {
1496 158 : emit_stack_save (SAVE_BLOCK, old_stack_level);
1497 158 : *old_pending_adj = pending_stack_adjust;
1498 158 : pending_stack_adjust = 0;
1499 : }
1500 :
1501 : /* We can pass TRUE as the 4th argument because we just
1502 : saved the stack pointer and will restore it right after
1503 : the call. */
1504 514 : copy = allocate_dynamic_stack_space (size_rtx,
1505 257 : TYPE_ALIGN (type),
1506 257 : TYPE_ALIGN (type),
1507 : max_int_size_in_bytes
1508 : (type),
1509 : true);
1510 257 : copy = gen_rtx_MEM (BLKmode, copy);
1511 257 : set_mem_attributes (copy, type, 1);
1512 : }
1513 : else
1514 109 : copy = assign_temp (type, 1, 0);
1515 :
1516 366 : store_expr (args[i].tree_value, copy, 0, false, false);
1517 :
1518 : /* Just change the const function to pure and then let
1519 : the next test clear the pure based on
1520 : callee_copies. */
1521 366 : if (*ecf_flags & ECF_CONST)
1522 : {
1523 1 : *ecf_flags &= ~ECF_CONST;
1524 1 : *ecf_flags |= ECF_PURE;
1525 : }
1526 :
1527 366 : if (!callee_copies && *ecf_flags & ECF_PURE)
1528 3 : *ecf_flags &= ~(ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
1529 :
1530 366 : args[i].tree_value
1531 366 : = build_fold_addr_expr_loc (loc, make_tree (type, copy));
1532 366 : type = TREE_TYPE (args[i].tree_value);
1533 366 : *may_tailcall = false;
1534 366 : maybe_complain_about_tail_call (exp,
1535 366 : _("argument must be passed"
1536 : " by copying"));
1537 : }
1538 386 : arg.pass_by_reference = true;
1539 : }
1540 :
1541 12376846 : unsignedp = TYPE_UNSIGNED (type);
1542 12376846 : if (promote_p
1543 12376846 : && INTEGRAL_TYPE_P (type)
1544 16444199 : && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
1545 : type = integer_type_node;
1546 :
1547 12376846 : arg.type = type;
1548 12376846 : arg.mode
1549 24373861 : = promote_function_mode (type, TYPE_MODE (type), &unsignedp,
1550 11997015 : fndecl ? TREE_TYPE (fndecl) : fntype, 0);
1551 :
1552 12376846 : args[i].unsignedp = unsignedp;
1553 12376846 : args[i].mode = arg.mode;
1554 :
1555 12376846 : targetm.calls.warn_parameter_passing_abi (args_so_far, type);
1556 :
1557 12376846 : args[i].reg = targetm.calls.function_arg (args_so_far, arg);
1558 :
1559 : /* If this is a sibling call and the machine has register windows, the
1560 : register window has to be unwinded before calling the routine, so
1561 : arguments have to go into the incoming registers. */
1562 12376846 : if (targetm.calls.function_incoming_arg != targetm.calls.function_arg)
1563 0 : args[i].tail_call_reg
1564 0 : = targetm.calls.function_incoming_arg (args_so_far, arg);
1565 : else
1566 : args[i].tail_call_reg = args[i].reg;
1567 :
1568 12376846 : if (args[i].reg)
1569 10223164 : args[i].partial = targetm.calls.arg_partial_bytes (args_so_far, arg);
1570 :
1571 12376846 : args[i].pass_on_stack = targetm.calls.must_pass_in_stack (arg);
1572 :
1573 : /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1574 : it means that we are to pass this arg in the register(s) designated
1575 : by the PARALLEL, but also to pass it in the stack. */
1576 12376846 : if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1577 287205 : && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1578 0 : args[i].pass_on_stack = true;
1579 :
1580 : /* If this is an addressable type, we must preallocate the stack
1581 : since we must evaluate the object into its final location.
1582 :
1583 : If this is to be passed in both registers and the stack, it is simpler
1584 : to preallocate. */
1585 12376846 : if (TREE_ADDRESSABLE (type)
1586 12376846 : || (args[i].pass_on_stack && args[i].reg != 0))
1587 0 : *must_preallocate = true;
1588 :
1589 : /* Compute the stack-size of this argument. */
1590 12376846 : if (args[i].reg == 0 || args[i].partial != 0
1591 10223164 : || reg_parm_stack_space > 0
1592 10156987 : || args[i].pass_on_stack)
1593 2219859 : locate_and_pad_parm (arg.mode, type,
1594 : #ifdef STACK_PARMS_IN_REG_PARM_AREA
1595 : 1,
1596 : #else
1597 : args[i].reg != 0,
1598 : #endif
1599 : reg_parm_stack_space,
1600 2219859 : args[i].pass_on_stack ? 0 : args[i].partial,
1601 : fndecl, args_size, &args[i].locate);
1602 : #ifdef BLOCK_REG_PADDING
1603 : else
1604 : /* The argument is passed entirely in registers. See at which
1605 : end it should be padded. */
1606 : args[i].locate.where_pad =
1607 : BLOCK_REG_PADDING (arg.mode, type,
1608 : int_size_in_bytes (type) <= UNITS_PER_WORD);
1609 : #endif
1610 :
1611 : /* Update ARGS_SIZE, the total stack space for args so far. */
1612 :
1613 12376846 : args_size->constant += args[i].locate.size.constant;
1614 12376846 : if (args[i].locate.size.var)
1615 0 : ADD_PARM_SIZE (*args_size, args[i].locate.size.var);
1616 :
1617 : /* Increment ARGS_SO_FAR, which has info about which arg-registers
1618 : have been used, etc. */
1619 :
1620 : /* ??? Traditionally we've passed TYPE_MODE here, instead of the
1621 : promoted_mode used for function_arg above. However, the
1622 : corresponding handling of incoming arguments in function.cc
1623 : does pass the promoted mode. */
1624 12376846 : arg.mode = TYPE_MODE (type);
1625 12376846 : targetm.calls.function_arg_advance (args_so_far, arg);
1626 : }
1627 5999376 : }
1628 :
1629 : /* Update ARGS_SIZE to contain the total size for the argument block.
1630 : Return the original constant component of the argument block's size.
1631 :
1632 : REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1633 : for arguments passed in registers. */
1634 :
1635 : static poly_int64
1636 5999380 : compute_argument_block_size (int reg_parm_stack_space,
1637 : struct args_size *args_size,
1638 : tree fndecl ATTRIBUTE_UNUSED,
1639 : tree fntype ATTRIBUTE_UNUSED,
1640 : int preferred_stack_boundary ATTRIBUTE_UNUSED)
1641 : {
1642 5999380 : poly_int64 unadjusted_args_size = args_size->constant;
1643 :
1644 : /* For accumulate outgoing args mode we don't need to align, since the frame
1645 : will be already aligned. Align to STACK_BOUNDARY in order to prevent
1646 : backends from generating misaligned frame sizes. */
1647 5999380 : if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY)
1648 1069 : preferred_stack_boundary = STACK_BOUNDARY;
1649 :
1650 : /* Compute the actual size of the argument block required. The variable
1651 : and constant sizes must be combined, the size may have to be rounded,
1652 : and there may be a minimum required size. */
1653 :
1654 5999380 : if (args_size->var)
1655 : {
1656 0 : args_size->var = ARGS_SIZE_TREE (*args_size);
1657 0 : args_size->constant = 0;
1658 :
1659 0 : preferred_stack_boundary /= BITS_PER_UNIT;
1660 0 : if (preferred_stack_boundary > 1)
1661 : {
1662 : /* We don't handle this case yet. To handle it correctly we have
1663 : to add the delta, round and subtract the delta.
1664 : Currently no machine description requires this support. */
1665 0 : gcc_assert (multiple_p (stack_pointer_delta,
1666 : preferred_stack_boundary));
1667 0 : args_size->var = round_up (args_size->var, preferred_stack_boundary);
1668 : }
1669 :
1670 0 : if (reg_parm_stack_space > 0)
1671 : {
1672 0 : args_size->var
1673 0 : = size_binop (MAX_EXPR, args_size->var,
1674 : ssize_int (reg_parm_stack_space));
1675 :
1676 : /* The area corresponding to register parameters is not to count in
1677 : the size of the block we need. So make the adjustment. */
1678 0 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
1679 0 : args_size->var
1680 0 : = size_binop (MINUS_EXPR, args_size->var,
1681 : ssize_int (reg_parm_stack_space));
1682 : }
1683 : }
1684 : else
1685 : {
1686 5999380 : preferred_stack_boundary /= BITS_PER_UNIT;
1687 5999380 : if (preferred_stack_boundary < 1)
1688 130867 : preferred_stack_boundary = 1;
1689 5999380 : args_size->constant = (aligned_upper_bound (args_size->constant
1690 5999380 : + stack_pointer_delta,
1691 : preferred_stack_boundary)
1692 5999380 : - stack_pointer_delta);
1693 :
1694 5999380 : args_size->constant = upper_bound (args_size->constant,
1695 : reg_parm_stack_space);
1696 :
1697 5999380 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
1698 5963051 : args_size->constant -= reg_parm_stack_space;
1699 : }
1700 5999380 : return unadjusted_args_size;
1701 : }
1702 :
1703 : /* Precompute parameters as needed for a function call.
1704 :
1705 : FLAGS is mask of ECF_* constants.
1706 :
1707 : NUM_ACTUALS is the number of arguments.
1708 :
1709 : ARGS is an array containing information for each argument; this
1710 : routine fills in the INITIAL_VALUE and VALUE fields for each
1711 : precomputed argument. */
1712 :
1713 : static void
1714 5868513 : precompute_arguments (int num_actuals, struct arg_data *args)
1715 : {
1716 5868513 : int i;
1717 :
1718 : /* If this is a libcall, then precompute all arguments so that we do not
1719 : get extraneous instructions emitted as part of the libcall sequence. */
1720 :
1721 : /* If we preallocated the stack space, and some arguments must be passed
1722 : on the stack, then we must precompute any parameter which contains a
1723 : function call which will store arguments on the stack.
1724 : Otherwise, evaluating the parameter may clobber previous parameters
1725 : which have already been stored into the stack. (we have code to avoid
1726 : such case by saving the outgoing stack arguments, but it results in
1727 : worse code) */
1728 5868513 : if (!ACCUMULATE_OUTGOING_ARGS)
1729 : return;
1730 :
1731 366614 : for (i = 0; i < num_actuals; i++)
1732 : {
1733 293227 : tree type;
1734 293227 : machine_mode mode;
1735 :
1736 293227 : if (TREE_CODE (args[i].tree_value) != CALL_EXPR)
1737 293227 : continue;
1738 :
1739 : /* If this is an addressable type, we cannot pre-evaluate it. */
1740 0 : type = TREE_TYPE (args[i].tree_value);
1741 0 : gcc_assert (!TREE_ADDRESSABLE (type));
1742 :
1743 0 : args[i].initial_value = args[i].value
1744 0 : = expand_normal (args[i].tree_value);
1745 :
1746 0 : mode = TYPE_MODE (type);
1747 0 : if (mode != args[i].mode)
1748 : {
1749 0 : int unsignedp = args[i].unsignedp;
1750 0 : args[i].value
1751 0 : = convert_modes (args[i].mode, mode,
1752 : args[i].value, args[i].unsignedp);
1753 :
1754 : /* CSE will replace this only if it contains args[i].value
1755 : pseudo, so convert it down to the declared mode using
1756 : a SUBREG. */
1757 0 : if (REG_P (args[i].value)
1758 0 : && GET_MODE_CLASS (args[i].mode) == MODE_INT
1759 0 : && promote_mode (type, mode, &unsignedp) != args[i].mode)
1760 : {
1761 0 : args[i].initial_value
1762 0 : = gen_lowpart_SUBREG (mode, args[i].value);
1763 0 : SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1764 0 : SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp);
1765 : }
1766 : }
1767 : }
1768 : }
1769 :
1770 : /* Given the current state of MUST_PREALLOCATE and information about
1771 : arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1772 : compute and return the final value for MUST_PREALLOCATE. */
1773 :
1774 : static bool
1775 5999376 : finalize_must_preallocate (bool must_preallocate, int num_actuals,
1776 : struct arg_data *args, struct args_size *args_size)
1777 : {
1778 : /* See if we have or want to preallocate stack space.
1779 :
1780 : If we would have to push a partially-in-regs parm
1781 : before other stack parms, preallocate stack space instead.
1782 :
1783 : If the size of some parm is not a multiple of the required stack
1784 : alignment, we must preallocate.
1785 :
1786 : If the total size of arguments that would otherwise create a copy in
1787 : a temporary (such as a CALL) is more than half the total argument list
1788 : size, preallocation is faster.
1789 :
1790 : Another reason to preallocate is if we have a machine (like the m88k)
1791 : where stack alignment is required to be maintained between every
1792 : pair of insns, not just when the call is made. However, we assume here
1793 : that such machines either do not have push insns (and hence preallocation
1794 : would occur anyway) or the problem is taken care of with
1795 : PUSH_ROUNDING. */
1796 :
1797 5999376 : if (! must_preallocate)
1798 : {
1799 : bool partial_seen = false;
1800 : poly_int64 copy_to_evaluate_size = 0;
1801 : int i;
1802 :
1803 18007049 : for (i = 0; i < num_actuals && ! must_preallocate; i++)
1804 : {
1805 12082277 : if (args[i].partial > 0 && ! args[i].pass_on_stack)
1806 : partial_seen = true;
1807 12082277 : else if (partial_seen && args[i].reg == 0)
1808 0 : must_preallocate = true;
1809 :
1810 12082277 : if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1811 12082277 : && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1812 279219 : || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1813 279219 : || TREE_CODE (args[i].tree_value) == COND_EXPR
1814 279219 : || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1815 0 : copy_to_evaluate_size
1816 0 : += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1817 : }
1818 :
1819 5924772 : if (maybe_ne (args_size->constant, 0)
1820 5924772 : && maybe_ge (copy_to_evaluate_size * 2, args_size->constant))
1821 : must_preallocate = true;
1822 : }
1823 5999376 : return must_preallocate;
1824 : }
1825 :
1826 : /* If we preallocated stack space, compute the address of each argument
1827 : and store it into the ARGS array.
1828 :
1829 : We need not ensure it is a valid memory address here; it will be
1830 : validized when it is used.
1831 :
1832 : ARGBLOCK is an rtx for the address of the outgoing arguments. */
1833 :
1834 : static void
1835 5999380 : compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals)
1836 : {
1837 5999380 : if (argblock)
1838 : {
1839 204270 : rtx arg_reg = argblock;
1840 204270 : int i;
1841 204270 : poly_int64 arg_offset = 0;
1842 :
1843 204270 : if (GET_CODE (argblock) == PLUS)
1844 : {
1845 0 : arg_reg = XEXP (argblock, 0);
1846 0 : arg_offset = rtx_to_poly_int64 (XEXP (argblock, 1));
1847 : }
1848 :
1849 730355 : for (i = 0; i < num_actuals; i++)
1850 : {
1851 538366 : rtx offset = ARGS_SIZE_RTX (args[i].locate.offset);
1852 538366 : rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
1853 526085 : rtx addr;
1854 526085 : unsigned int align, boundary;
1855 526085 : poly_uint64 units_on_stack = 0;
1856 526085 : machine_mode partial_mode = VOIDmode;
1857 :
1858 : /* Skip this parm if it will not be passed on the stack. */
1859 526085 : if (! args[i].pass_on_stack
1860 526085 : && args[i].reg != 0
1861 461758 : && args[i].partial == 0)
1862 526085 : continue;
1863 :
1864 64327 : if (TYPE_EMPTY_P (TREE_TYPE (args[i].tree_value)))
1865 311 : continue;
1866 :
1867 72312 : addr = simplify_gen_binary (PLUS, Pmode, arg_reg, offset);
1868 72312 : addr = plus_constant (Pmode, addr, arg_offset);
1869 :
1870 64016 : if (args[i].partial != 0)
1871 : {
1872 : /* Only part of the parameter is being passed on the stack.
1873 : Generate a simple memory reference of the correct size. */
1874 0 : units_on_stack = args[i].locate.size.constant;
1875 0 : poly_uint64 bits_on_stack = units_on_stack * BITS_PER_UNIT;
1876 0 : partial_mode = int_mode_for_size (bits_on_stack, 1).else_blk ();
1877 0 : args[i].stack = gen_rtx_MEM (partial_mode, addr);
1878 0 : set_mem_size (args[i].stack, units_on_stack);
1879 : }
1880 : else
1881 : {
1882 64016 : args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1883 64016 : set_mem_attributes (args[i].stack,
1884 64016 : TREE_TYPE (args[i].tree_value), 1);
1885 : }
1886 64016 : align = BITS_PER_UNIT;
1887 64016 : boundary = args[i].locate.boundary;
1888 64016 : poly_int64 offset_val;
1889 64016 : if (args[i].locate.where_pad != PAD_DOWNWARD)
1890 : align = boundary;
1891 0 : else if (poly_int_rtx_p (offset, &offset_val))
1892 : {
1893 0 : align = least_bit_hwi (boundary);
1894 0 : unsigned int offset_align
1895 0 : = known_alignment (offset_val) * BITS_PER_UNIT;
1896 0 : if (offset_align != 0)
1897 0 : align = MIN (align, offset_align);
1898 : }
1899 64016 : set_mem_align (args[i].stack, align);
1900 :
1901 72312 : addr = simplify_gen_binary (PLUS, Pmode, arg_reg, slot_offset);
1902 72312 : addr = plus_constant (Pmode, addr, arg_offset);
1903 :
1904 64016 : if (args[i].partial != 0)
1905 : {
1906 : /* Only part of the parameter is being passed on the stack.
1907 : Generate a simple memory reference of the correct size.
1908 : */
1909 0 : args[i].stack_slot = gen_rtx_MEM (partial_mode, addr);
1910 0 : set_mem_size (args[i].stack_slot, units_on_stack);
1911 : }
1912 : else
1913 : {
1914 64016 : args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1915 64016 : set_mem_attributes (args[i].stack_slot,
1916 64016 : TREE_TYPE (args[i].tree_value), 1);
1917 : }
1918 64016 : set_mem_align (args[i].stack_slot, args[i].locate.boundary);
1919 :
1920 : /* Function incoming arguments may overlap with sibling call
1921 : outgoing arguments and we cannot allow reordering of reads
1922 : from function arguments with stores to outgoing arguments
1923 : of sibling calls. */
1924 64016 : set_mem_alias_set (args[i].stack, 0);
1925 64016 : set_mem_alias_set (args[i].stack_slot, 0);
1926 : }
1927 : }
1928 5999380 : }
1929 :
1930 : /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1931 : in a call instruction.
1932 :
1933 : FNDECL is the tree node for the target function. For an indirect call
1934 : FNDECL will be NULL_TREE.
1935 :
1936 : ADDR is the operand 0 of CALL_EXPR for this call. */
1937 :
1938 : static rtx
1939 5999378 : rtx_for_function_call (tree fndecl, tree addr)
1940 : {
1941 5999378 : rtx funexp;
1942 :
1943 : /* Get the function to call, in the form of RTL. */
1944 5999378 : if (fndecl)
1945 : {
1946 5812378 : if (!TREE_USED (fndecl) && fndecl != current_function_decl)
1947 549166 : TREE_USED (fndecl) = 1;
1948 :
1949 : /* Get a SYMBOL_REF rtx for the function address. */
1950 5812378 : funexp = XEXP (DECL_RTL (fndecl), 0);
1951 : }
1952 : else
1953 : /* Generate an rtx (probably a pseudo-register) for the address. */
1954 : {
1955 187000 : push_temp_slots ();
1956 187000 : funexp = expand_normal (addr);
1957 187000 : pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1958 : }
1959 5999378 : return funexp;
1960 : }
1961 :
1962 : /* Return the static chain for this function, if any. */
1963 :
1964 : rtx
1965 16192630 : rtx_for_static_chain (const_tree fndecl_or_type, bool incoming_p)
1966 : {
1967 32385260 : if (DECL_P (fndecl_or_type) && !DECL_STATIC_CHAIN (fndecl_or_type))
1968 : return NULL;
1969 :
1970 213503 : return targetm.calls.static_chain (fndecl_or_type, incoming_p);
1971 : }
1972 :
1973 : /* Internal state for internal_arg_pointer_based_exp and its helpers. */
1974 : static struct
1975 : {
1976 : /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan,
1977 : or NULL_RTX if none has been scanned yet. */
1978 : rtx_insn *scan_start;
1979 : /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is
1980 : based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the
1981 : pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it
1982 : with fixed offset, or PC if this is with variable or unknown offset. */
1983 : vec<rtx> cache;
1984 : } internal_arg_pointer_exp_state;
1985 :
1986 : static rtx internal_arg_pointer_based_exp (const_rtx, bool);
1987 :
1988 : /* Helper function for internal_arg_pointer_based_exp. Scan insns in
1989 : the tail call sequence, starting with first insn that hasn't been
1990 : scanned yet, and note for each pseudo on the LHS whether it is based
1991 : on crtl->args.internal_arg_pointer or not, and what offset from that
1992 : that pointer it has. */
1993 :
1994 : static void
1995 1488 : internal_arg_pointer_based_exp_scan (void)
1996 : {
1997 1488 : rtx_insn *insn, *scan_start = internal_arg_pointer_exp_state.scan_start;
1998 :
1999 1488 : if (scan_start == NULL_RTX)
2000 1291 : insn = get_insns ();
2001 : else
2002 197 : insn = NEXT_INSN (scan_start);
2003 :
2004 8941 : while (insn)
2005 : {
2006 7453 : rtx set = single_set (insn);
2007 7453 : if (set && REG_P (SET_DEST (set)) && !HARD_REGISTER_P (SET_DEST (set)))
2008 : {
2009 2027 : rtx val = NULL_RTX;
2010 2027 : unsigned int idx = REGNO (SET_DEST (set)) - FIRST_PSEUDO_REGISTER;
2011 : /* Punt on pseudos set multiple times. */
2012 2027 : if (idx < internal_arg_pointer_exp_state.cache.length ()
2013 0 : && (internal_arg_pointer_exp_state.cache[idx]
2014 0 : != NULL_RTX))
2015 0 : val = pc_rtx;
2016 : else
2017 2027 : val = internal_arg_pointer_based_exp (SET_SRC (set), false);
2018 2027 : if (val != NULL_RTX)
2019 : {
2020 0 : if (idx >= internal_arg_pointer_exp_state.cache.length ())
2021 0 : internal_arg_pointer_exp_state.cache
2022 0 : .safe_grow_cleared (idx + 1, true);
2023 0 : internal_arg_pointer_exp_state.cache[idx] = val;
2024 : }
2025 : }
2026 7453 : if (NEXT_INSN (insn) == NULL_RTX)
2027 1446 : scan_start = insn;
2028 7453 : insn = NEXT_INSN (insn);
2029 : }
2030 :
2031 1488 : internal_arg_pointer_exp_state.scan_start = scan_start;
2032 1488 : }
2033 :
2034 : /* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return
2035 : NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on
2036 : it with fixed offset, or PC if this is with variable or unknown offset.
2037 : TOPLEVEL is true if the function is invoked at the topmost level. */
2038 :
2039 : static rtx
2040 13322 : internal_arg_pointer_based_exp (const_rtx rtl, bool toplevel)
2041 : {
2042 13322 : if (CONSTANT_P (rtl))
2043 : return NULL_RTX;
2044 :
2045 13232 : if (rtl == crtl->args.internal_arg_pointer)
2046 5399 : return const0_rtx;
2047 :
2048 7833 : if (REG_P (rtl) && HARD_REGISTER_P (rtl))
2049 : return NULL_RTX;
2050 :
2051 7815 : poly_int64 offset;
2052 7815 : if (GET_CODE (rtl) == PLUS && poly_int_rtx_p (XEXP (rtl, 1), &offset))
2053 : {
2054 3259 : rtx val = internal_arg_pointer_based_exp (XEXP (rtl, 0), toplevel);
2055 3259 : if (val == NULL_RTX || val == pc_rtx)
2056 : return val;
2057 5310 : return plus_constant (Pmode, val, offset);
2058 : }
2059 :
2060 : /* When called at the topmost level, scan pseudo assignments in between the
2061 : last scanned instruction in the tail call sequence and the latest insn
2062 : in that sequence. */
2063 4556 : if (toplevel)
2064 1488 : internal_arg_pointer_based_exp_scan ();
2065 :
2066 4556 : if (REG_P (rtl))
2067 : {
2068 1779 : unsigned int idx = REGNO (rtl) - FIRST_PSEUDO_REGISTER;
2069 1779 : if (idx < internal_arg_pointer_exp_state.cache.length ())
2070 0 : return internal_arg_pointer_exp_state.cache[idx];
2071 :
2072 : return NULL_RTX;
2073 : }
2074 :
2075 2777 : subrtx_iterator::array_type array;
2076 7506 : FOR_EACH_SUBRTX (iter, array, rtl, NONCONST)
2077 : {
2078 4729 : const_rtx x = *iter;
2079 4729 : if (REG_P (x) && internal_arg_pointer_based_exp (x, false) != NULL_RTX)
2080 0 : return pc_rtx;
2081 4729 : if (MEM_P (x))
2082 1714 : iter.skip_subrtxes ();
2083 : }
2084 :
2085 2777 : return NULL_RTX;
2086 2777 : }
2087 :
2088 : /* Return true if SIZE bytes starting from address ADDR might overlap an
2089 : already-clobbered argument area. This function is used to determine
2090 : if we should give up a sibcall. */
2091 :
2092 : static bool
2093 18311 : mem_might_overlap_already_clobbered_arg_p (rtx addr, poly_uint64 size)
2094 : {
2095 18311 : poly_int64 i;
2096 18311 : unsigned HOST_WIDE_INT start, end;
2097 18311 : rtx val;
2098 :
2099 18311 : if (bitmap_empty_p (stored_args_map)
2100 18311 : && stored_args_watermark == HOST_WIDE_INT_M1U)
2101 : return false;
2102 6929 : val = internal_arg_pointer_based_exp (addr, true);
2103 6929 : if (val == NULL_RTX)
2104 : return false;
2105 5399 : else if (!poly_int_rtx_p (val, &i))
2106 : return true;
2107 :
2108 5399 : if (known_eq (size, 0U))
2109 : return false;
2110 :
2111 5399 : if (STACK_GROWS_DOWNWARD)
2112 5399 : i -= crtl->args.pretend_args_size;
2113 : else
2114 : i += crtl->args.pretend_args_size;
2115 :
2116 5399 : if (ARGS_GROW_DOWNWARD)
2117 : i = -i - size;
2118 :
2119 : /* We can ignore any references to the function's pretend args,
2120 : which at this point would manifest as negative values of I. */
2121 5399 : if (known_le (i, 0) && known_le (size, poly_uint64 (-i)))
2122 : return false;
2123 :
2124 5399 : start = maybe_lt (i, 0) ? 0 : constant_lower_bound (i);
2125 5399 : if (!(i + size).is_constant (&end))
2126 : end = HOST_WIDE_INT_M1U;
2127 :
2128 5399 : if (end > stored_args_watermark)
2129 : return true;
2130 :
2131 5399 : end = MIN (end, SBITMAP_SIZE (stored_args_map));
2132 31383 : for (unsigned HOST_WIDE_INT k = start; k < end; ++k)
2133 25988 : if (bitmap_bit_p (stored_args_map, k))
2134 : return true;
2135 :
2136 : return false;
2137 : }
2138 :
2139 : /* Do the register loads required for any wholly-register parms or any
2140 : parms which are passed both on the stack and in a register. Their
2141 : expressions were already evaluated.
2142 :
2143 : Mark all register-parms as living through the call, putting these USE
2144 : insns in the CALL_INSN_FUNCTION_USAGE field.
2145 :
2146 : When IS_SIBCALL, perform the check_sibcall_argument_overlap
2147 : checking, setting *SIBCALL_FAILURE if appropriate. */
2148 :
2149 : static void
2150 5999378 : load_register_parameters (struct arg_data *args, int num_actuals,
2151 : rtx *call_fusage, int flags, int is_sibcall,
2152 : bool *sibcall_failure)
2153 : {
2154 5999378 : int i, j;
2155 :
2156 18376262 : for (i = 0; i < num_actuals; i++)
2157 : {
2158 24753768 : rtx reg = ((flags & ECF_SIBCALL)
2159 12376884 : ? args[i].tail_call_reg : args[i].reg);
2160 12376884 : if (reg)
2161 : {
2162 10223174 : int partial = args[i].partial;
2163 10223174 : int nregs;
2164 10223174 : poly_int64 size = 0;
2165 10223174 : HOST_WIDE_INT const_size = 0;
2166 10223174 : rtx_insn *before_arg = get_last_insn ();
2167 10223174 : tree tree_value = args[i].tree_value;
2168 10223174 : tree type = TREE_TYPE (tree_value);
2169 10223174 : if (RECORD_OR_UNION_TYPE_P (type) && TYPE_TRANSPARENT_AGGR (type))
2170 3045 : type = TREE_TYPE (first_field (type));
2171 : /* Set non-negative if we must move a word at a time, even if
2172 : just one word (e.g, partial == 4 && mode == DFmode). Set
2173 : to -1 if we just use a normal move insn. This value can be
2174 : zero if the argument is a zero size structure. */
2175 10223174 : nregs = -1;
2176 10223174 : if (GET_CODE (reg) == PARALLEL)
2177 : ;
2178 9935969 : else if (partial)
2179 : {
2180 0 : gcc_assert (partial % UNITS_PER_WORD == 0);
2181 0 : nregs = partial / UNITS_PER_WORD;
2182 : }
2183 9935969 : else if (TYPE_MODE (type) == BLKmode)
2184 : {
2185 : /* Variable-sized parameters should be described by a
2186 : PARALLEL instead. */
2187 1622 : const_size = int_size_in_bytes (type);
2188 1622 : gcc_assert (const_size >= 0);
2189 1640 : nregs = (const_size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
2190 1622 : size = const_size;
2191 : }
2192 : else
2193 19868694 : size = GET_MODE_SIZE (args[i].mode);
2194 :
2195 : /* Handle calls that pass values in multiple non-contiguous
2196 : locations. The Irix 6 ABI has examples of this. */
2197 :
2198 10223174 : if (GET_CODE (reg) == PARALLEL)
2199 287205 : emit_group_move (reg, args[i].parallel_value);
2200 :
2201 : /* If simple case, just do move. If normal partial, store_one_arg
2202 : has already loaded the register for us. In all other cases,
2203 : load the register(s) from memory. */
2204 :
2205 9935969 : else if (nregs == -1)
2206 : {
2207 9934347 : emit_move_insn (reg, args[i].value);
2208 : #ifdef BLOCK_REG_PADDING
2209 : /* Handle case where we have a value that needs shifting
2210 : up to the msb. eg. a QImode value and we're padding
2211 : upward on a BYTES_BIG_ENDIAN machine. */
2212 : if (args[i].locate.where_pad
2213 : == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD))
2214 : {
2215 : gcc_checking_assert (ordered_p (size, UNITS_PER_WORD));
2216 : if (maybe_lt (size, UNITS_PER_WORD))
2217 : {
2218 : rtx x;
2219 : poly_int64 shift
2220 : = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
2221 :
2222 : /* Assigning REG here rather than a temp makes
2223 : CALL_FUSAGE report the whole reg as used.
2224 : Strictly speaking, the call only uses SIZE
2225 : bytes at the msb end, but it doesn't seem worth
2226 : generating rtl to say that. */
2227 : reg = gen_rtx_REG (word_mode, REGNO (reg));
2228 : x = expand_shift (LSHIFT_EXPR, word_mode,
2229 : reg, shift, reg, 1);
2230 : if (x != reg)
2231 : emit_move_insn (reg, x);
2232 : }
2233 : }
2234 : #endif
2235 : }
2236 :
2237 : /* If we have pre-computed the values to put in the registers in
2238 : the case of non-aligned structures, copy them in now. */
2239 :
2240 1622 : else if (args[i].n_aligned_regs != 0)
2241 0 : for (j = 0; j < args[i].n_aligned_regs; j++)
2242 0 : emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
2243 0 : args[i].aligned_regs[j]);
2244 :
2245 : /* If we need a single register and the source is a constant
2246 : VAR_DECL with a simple constructor, expand that constructor
2247 : via a pseudo rather than read from (possibly misaligned)
2248 : memory. PR middle-end/95126. */
2249 1622 : else if (nregs == 1
2250 1622 : && partial == 0
2251 1604 : && !args[i].pass_on_stack
2252 1604 : && VAR_P (tree_value)
2253 1127 : && TREE_READONLY (tree_value)
2254 16 : && !TREE_SIDE_EFFECTS (tree_value)
2255 1638 : && immediate_const_ctor_p (DECL_INITIAL (tree_value)))
2256 : {
2257 16 : HOST_WIDE_INT size = int_expr_size (DECL_INITIAL (tree_value));
2258 16 : rtx target = gen_reg_rtx (word_mode);
2259 16 : store_constructor (DECL_INITIAL (tree_value), target, 0,
2260 16 : size, false);
2261 : /* On big-endian targets, store_constructor places fields
2262 : from the MSB, which places any padding bits in the least
2263 : significant bytes. If required, use a logical right shift
2264 : to place things where expected in a register parameter. */
2265 16 : if (BYTES_BIG_ENDIAN
2266 : && size < UNITS_PER_WORD
2267 : && args[i].locate.where_pad == PAD_DOWNWARD)
2268 : target = expand_shift (RSHIFT_EXPR, word_mode, target,
2269 : (UNITS_PER_WORD - size) * BITS_PER_UNIT,
2270 : NULL_RTX, 1);
2271 16 : reg = gen_rtx_REG (word_mode, REGNO (reg));
2272 16 : emit_move_insn (reg, target);
2273 : }
2274 1606 : else if (partial == 0 || args[i].pass_on_stack)
2275 : {
2276 : /* SIZE and CONST_SIZE are 0 for partial arguments and
2277 : the size of a BLKmode type otherwise. */
2278 1606 : gcc_checking_assert (known_eq (size, const_size));
2279 1606 : rtx mem = validize_mem (copy_rtx (args[i].value));
2280 :
2281 : /* Check for overlap with already clobbered argument area,
2282 : providing that this has non-zero size. */
2283 1606 : if (is_sibcall
2284 38 : && const_size != 0
2285 1644 : && (mem_might_overlap_already_clobbered_arg_p
2286 1644 : (XEXP (args[i].value, 0), const_size)))
2287 0 : *sibcall_failure = true;
2288 :
2289 1606 : if (const_size % UNITS_PER_WORD == 0
2290 2991 : || MEM_ALIGN (mem) % BITS_PER_WORD == 0)
2291 434 : move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode);
2292 : else
2293 : {
2294 1172 : if (nregs > 1)
2295 0 : move_block_to_reg (REGNO (reg), mem, nregs - 1,
2296 : args[i].mode);
2297 1172 : rtx dest = gen_rtx_REG (word_mode, REGNO (reg) + nregs - 1);
2298 1172 : unsigned int bitoff = (nregs - 1) * BITS_PER_WORD;
2299 1172 : unsigned int bitsize = const_size * BITS_PER_UNIT - bitoff;
2300 1172 : rtx x = extract_bit_field (mem, bitsize, bitoff, 1, dest,
2301 : word_mode, word_mode, false,
2302 : NULL);
2303 1172 : if (BYTES_BIG_ENDIAN)
2304 : x = expand_shift (LSHIFT_EXPR, word_mode, x,
2305 : BITS_PER_WORD - bitsize, dest, 1);
2306 1172 : if (x != dest)
2307 1145 : emit_move_insn (dest, x);
2308 : }
2309 :
2310 : /* Handle a BLKmode that needs shifting. */
2311 : if (nregs == 1 && const_size < UNITS_PER_WORD
2312 : #ifdef BLOCK_REG_PADDING
2313 : && args[i].locate.where_pad == PAD_DOWNWARD
2314 : #else
2315 : && BYTES_BIG_ENDIAN
2316 : #endif
2317 : )
2318 : {
2319 : rtx dest = gen_rtx_REG (word_mode, REGNO (reg));
2320 : int shift = (UNITS_PER_WORD - const_size) * BITS_PER_UNIT;
2321 : enum tree_code dir = (BYTES_BIG_ENDIAN
2322 : ? RSHIFT_EXPR : LSHIFT_EXPR);
2323 : rtx x;
2324 :
2325 : x = expand_shift (dir, word_mode, dest, shift, dest, 1);
2326 : if (x != dest)
2327 : emit_move_insn (dest, x);
2328 : }
2329 : }
2330 :
2331 : /* When a parameter is a block, and perhaps in other cases, it is
2332 : possible that it did a load from an argument slot that was
2333 : already clobbered. */
2334 10223174 : if (is_sibcall
2335 10223174 : && check_sibcall_argument_overlap (before_arg, &args[i], false))
2336 0 : *sibcall_failure = true;
2337 :
2338 : /* Handle calls that pass values in multiple non-contiguous
2339 : locations. The Irix 6 ABI has examples of this. */
2340 10223174 : if (GET_CODE (reg) == PARALLEL)
2341 287205 : use_group_regs (call_fusage, reg);
2342 9935969 : else if (nregs == -1)
2343 9934347 : use_reg_mode (call_fusage, reg, TYPE_MODE (type));
2344 1622 : else if (nregs > 0)
2345 1608 : use_regs (call_fusage, REGNO (reg), nregs);
2346 : }
2347 : }
2348 5999378 : }
2349 :
2350 : /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
2351 : wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
2352 : bytes, then we would need to push some additional bytes to pad the
2353 : arguments. So, we try to compute an adjust to the stack pointer for an
2354 : amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
2355 : bytes. Then, when the arguments are pushed the stack will be perfectly
2356 : aligned.
2357 :
2358 : Return true if this optimization is possible, storing the adjustment
2359 : in ADJUSTMENT_OUT and setting ARGS_SIZE->CONSTANT to the number of
2360 : bytes that should be popped after the call. */
2361 :
2362 : static bool
2363 14376 : combine_pending_stack_adjustment_and_call (poly_int64 *adjustment_out,
2364 : poly_int64 unadjusted_args_size,
2365 : struct args_size *args_size,
2366 : unsigned int preferred_unit_stack_boundary)
2367 : {
2368 : /* The number of bytes to pop so that the stack will be
2369 : under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
2370 14376 : poly_int64 adjustment;
2371 : /* The alignment of the stack after the arguments are pushed, if we
2372 : just pushed the arguments without adjust the stack here. */
2373 14376 : unsigned HOST_WIDE_INT unadjusted_alignment;
2374 :
2375 14376 : if (!known_misalignment (stack_pointer_delta + unadjusted_args_size,
2376 : preferred_unit_stack_boundary,
2377 : &unadjusted_alignment))
2378 : return false;
2379 :
2380 : /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
2381 : as possible -- leaving just enough left to cancel out the
2382 : UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
2383 : PENDING_STACK_ADJUST is non-negative, and congruent to
2384 : -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
2385 :
2386 : /* Begin by trying to pop all the bytes. */
2387 14376 : unsigned HOST_WIDE_INT tmp_misalignment;
2388 14376 : if (!known_misalignment (pending_stack_adjust,
2389 : preferred_unit_stack_boundary,
2390 : &tmp_misalignment))
2391 : return false;
2392 14376 : unadjusted_alignment -= tmp_misalignment;
2393 14376 : adjustment = pending_stack_adjust;
2394 : /* Push enough additional bytes that the stack will be aligned
2395 : after the arguments are pushed. */
2396 14376 : if (preferred_unit_stack_boundary > 1 && unadjusted_alignment)
2397 14183 : adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
2398 :
2399 : /* We need to know whether the adjusted argument size
2400 : (UNADJUSTED_ARGS_SIZE - ADJUSTMENT) constitutes an allocation
2401 : or a deallocation. */
2402 14376 : if (!ordered_p (adjustment, unadjusted_args_size))
2403 : return false;
2404 :
2405 : /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
2406 : bytes after the call. The right number is the entire
2407 : PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
2408 : by the arguments in the first place. */
2409 : args_size->constant
2410 14376 : = pending_stack_adjust - adjustment + unadjusted_args_size;
2411 :
2412 14376 : *adjustment_out = adjustment;
2413 14376 : return true;
2414 : }
2415 :
2416 : /* Scan X expression if it does not dereference any argument slots
2417 : we already clobbered by tail call arguments (as noted in stored_args_map
2418 : bitmap).
2419 : Return true if X expression dereferences such argument slots,
2420 : false otherwise. */
2421 :
2422 : static bool
2423 1630866 : check_sibcall_argument_overlap_1 (rtx x)
2424 : {
2425 1630866 : RTX_CODE code;
2426 1630866 : int i, j;
2427 1630866 : const char *fmt;
2428 :
2429 1630866 : if (x == NULL_RTX)
2430 : return false;
2431 :
2432 1630866 : code = GET_CODE (x);
2433 :
2434 : /* We need not check the operands of the CALL expression itself. */
2435 1630866 : if (code == CALL)
2436 : return false;
2437 :
2438 1499999 : if (code == MEM)
2439 17834 : return (mem_might_overlap_already_clobbered_arg_p
2440 35668 : (XEXP (x, 0), GET_MODE_SIZE (GET_MODE (x))));
2441 :
2442 : /* Scan all subexpressions. */
2443 1482165 : fmt = GET_RTX_FORMAT (code);
2444 3502174 : for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2445 : {
2446 2020009 : if (*fmt == 'e')
2447 : {
2448 1026438 : if (check_sibcall_argument_overlap_1 (XEXP (x, i)))
2449 : return true;
2450 : }
2451 993571 : else if (*fmt == 'E')
2452 : {
2453 2300 : for (j = 0; j < XVECLEN (x, i); j++)
2454 1498 : if (check_sibcall_argument_overlap_1 (XVECEXP (x, i, j)))
2455 : return true;
2456 : }
2457 : }
2458 : return false;
2459 : }
2460 :
2461 : /* Scan sequence after INSN if it does not dereference any argument slots
2462 : we already clobbered by tail call arguments (as noted in stored_args_map
2463 : bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
2464 : stored_args_map bitmap afterwards (when ARG is a register
2465 : MARK_STORED_ARGS_MAP should be false). Return true if sequence after
2466 : INSN dereferences such argument slots, false otherwise. */
2467 :
2468 : static bool
2469 363672 : check_sibcall_argument_overlap (rtx_insn *insn, struct arg_data *arg,
2470 : bool mark_stored_args_map)
2471 : {
2472 363672 : poly_uint64 low, high;
2473 363672 : unsigned HOST_WIDE_INT const_low, const_high;
2474 :
2475 363672 : if (insn == NULL_RTX)
2476 159586 : insn = get_insns ();
2477 : else
2478 204086 : insn = NEXT_INSN (insn);
2479 :
2480 966602 : for (; insn; insn = NEXT_INSN (insn))
2481 602930 : if (INSN_P (insn)
2482 602930 : && check_sibcall_argument_overlap_1 (PATTERN (insn)))
2483 : break;
2484 :
2485 363672 : if (mark_stored_args_map)
2486 : {
2487 10396 : if (ARGS_GROW_DOWNWARD)
2488 : low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
2489 : else
2490 10396 : low = arg->locate.slot_offset.constant;
2491 10396 : high = low + arg->locate.size.constant;
2492 :
2493 10396 : const_low = constant_lower_bound (low);
2494 10396 : if (high.is_constant (&const_high))
2495 70876 : for (unsigned HOST_WIDE_INT i = const_low; i < const_high; ++i)
2496 60480 : bitmap_set_bit (stored_args_map, i);
2497 : else
2498 : stored_args_watermark = MIN (stored_args_watermark, const_low);
2499 : }
2500 363672 : return insn != NULL_RTX;
2501 : }
2502 :
2503 : /* Given that a function returns a value of mode MODE at the most
2504 : significant end of hard register VALUE, shift VALUE left or right
2505 : as specified by LEFT_P. Return true if some action was needed. */
2506 :
2507 : bool
2508 0 : shift_return_value (machine_mode mode, bool left_p, rtx value)
2509 : {
2510 0 : gcc_assert (REG_P (value) && HARD_REGISTER_P (value));
2511 0 : machine_mode value_mode = GET_MODE (value);
2512 0 : poly_int64 shift = GET_MODE_BITSIZE (value_mode) - GET_MODE_BITSIZE (mode);
2513 :
2514 0 : if (known_eq (shift, 0))
2515 : return false;
2516 :
2517 : /* Use ashr rather than lshr for right shifts. This is for the benefit
2518 : of the MIPS port, which requires SImode values to be sign-extended
2519 : when stored in 64-bit registers. */
2520 0 : if (!force_expand_binop (value_mode, left_p ? ashl_optab : ashr_optab,
2521 : value, gen_int_shift_amount (value_mode, shift),
2522 : value, 1, OPTAB_WIDEN))
2523 0 : gcc_unreachable ();
2524 : return true;
2525 : }
2526 :
2527 : /* If X is a likely-spilled register value, copy it to a pseudo
2528 : register and return that register. Return X otherwise. */
2529 :
2530 : static rtx
2531 217502 : avoid_likely_spilled_reg (rtx x)
2532 : {
2533 217502 : rtx new_rtx;
2534 :
2535 217502 : if (REG_P (x)
2536 217502 : && HARD_REGISTER_P (x)
2537 428318 : && targetm.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x))))
2538 : {
2539 : /* Make sure that we generate a REG rather than a CONCAT.
2540 : Moves into CONCATs can need nontrivial instructions,
2541 : and the whole point of this function is to avoid
2542 : using the hard register directly in such a situation. */
2543 210816 : generating_concat_p = 0;
2544 210816 : new_rtx = gen_reg_rtx (GET_MODE (x));
2545 210816 : generating_concat_p = 1;
2546 210816 : emit_move_insn (new_rtx, x);
2547 210816 : return new_rtx;
2548 : }
2549 : return x;
2550 : }
2551 :
2552 : /* Helper function for expand_call.
2553 : Return false is EXP is not implementable as a sibling call. */
2554 :
2555 : static bool
2556 141280 : can_implement_as_sibling_call_p (tree exp,
2557 : rtx structure_value_addr,
2558 : tree funtype,
2559 : tree fndecl,
2560 : int flags,
2561 : tree addr,
2562 : const args_size &args_size)
2563 : {
2564 141280 : if (!targetm.have_sibcall_epilogue ()
2565 141280 : && !targetm.emit_epilogue_for_sibcall)
2566 : {
2567 0 : maybe_complain_about_tail_call (exp, _("machine description does not "
2568 : "have a sibcall_epilogue "
2569 : "instruction pattern"));
2570 0 : return false;
2571 : }
2572 :
2573 : /* Doing sibling call optimization needs some work, since
2574 : structure_value_addr can be allocated on the stack.
2575 : It does not seem worth the effort since few optimizable
2576 : sibling calls will return a structure. */
2577 141280 : if (structure_value_addr != NULL_RTX)
2578 : {
2579 501 : maybe_complain_about_tail_call (exp, _("callee returns a structure"));
2580 501 : return false;
2581 : }
2582 :
2583 : /* Check whether the target is able to optimize the call
2584 : into a sibcall. */
2585 140779 : if (!targetm.function_ok_for_sibcall (fndecl, exp))
2586 : {
2587 6448 : maybe_complain_about_tail_call (exp, _("target is not able to optimize "
2588 : "the call into a sibling call"));
2589 6448 : return false;
2590 : }
2591 :
2592 : /* Functions that do not return exactly once may not be sibcall
2593 : optimized. */
2594 134331 : if (flags & ECF_RETURNS_TWICE)
2595 : {
2596 0 : maybe_complain_about_tail_call (exp, _("callee returns twice"));
2597 0 : return false;
2598 : }
2599 134590 : if ((flags & ECF_NORETURN) && !CALL_EXPR_MUST_TAIL_CALL (exp))
2600 : {
2601 247 : maybe_complain_about_tail_call (exp, _("callee does not return"));
2602 247 : return false;
2603 : }
2604 :
2605 134084 : if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr)))
2606 134086 : && !CALL_EXPR_MUST_TAIL_CALL (exp))
2607 : {
2608 0 : maybe_complain_about_tail_call (exp, _("volatile function type"));
2609 0 : return false;
2610 : }
2611 :
2612 : /* __sanitizer_cov_trace_pc is supposed to inspect its return address
2613 : to identify the caller, and therefore should not be tailcalled. */
2614 123794 : if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
2615 152049 : && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SANITIZER_COV_TRACE_PC)
2616 : {
2617 : /* No need for maybe_complain_about_tail_call here:
2618 : the call is synthesized by the compiler. */
2619 : return false;
2620 : }
2621 :
2622 : /* If the called function is nested in the current one, it might access
2623 : some of the caller's arguments, but could clobber them beforehand if
2624 : the argument areas are shared. */
2625 134048 : if (fndecl && decl_function_context (fndecl) == current_function_decl)
2626 : {
2627 111 : maybe_complain_about_tail_call (exp, _("nested function"));
2628 111 : return false;
2629 : }
2630 :
2631 : /* If this function requires more stack slots than the current
2632 : function, we cannot change it into a sibling call.
2633 : crtl->args.pretend_args_size is not part of the
2634 : stack allocated by our caller. */
2635 133937 : if (maybe_gt (args_size.constant,
2636 : crtl->args.size - crtl->args.pretend_args_size))
2637 : {
2638 3070 : maybe_complain_about_tail_call (exp, _("callee required more stack "
2639 : "slots than the caller"));
2640 3070 : return false;
2641 : }
2642 :
2643 : /* If the callee pops its own arguments, then it must pop exactly
2644 : the same number of arguments as the current function. */
2645 130867 : if (maybe_ne (targetm.calls.return_pops_args (fndecl, funtype,
2646 : args_size.constant),
2647 261734 : targetm.calls.return_pops_args (current_function_decl,
2648 130867 : TREE_TYPE
2649 : (current_function_decl),
2650 : crtl->args.size)))
2651 : {
2652 0 : maybe_complain_about_tail_call (exp, _("inconsistent number of"
2653 : " popped arguments"));
2654 0 : return false;
2655 : }
2656 :
2657 130867 : if (!lang_hooks.decls.ok_for_sibcall (fndecl))
2658 : {
2659 0 : maybe_complain_about_tail_call (exp, _("frontend does not support"
2660 : " sibling call"));
2661 0 : return false;
2662 : }
2663 :
2664 : /* All checks passed. */
2665 : return true;
2666 : }
2667 :
2668 : /* Update stack alignment when the parameter is passed in the stack
2669 : since the outgoing parameter requires extra alignment on the calling
2670 : function side. */
2671 :
2672 : static void
2673 2257890 : update_stack_alignment_for_call (struct locate_and_pad_arg_data *locate)
2674 : {
2675 2257890 : if (crtl->stack_alignment_needed < locate->boundary)
2676 2338 : crtl->stack_alignment_needed = locate->boundary;
2677 2257890 : if (crtl->preferred_stack_boundary < locate->boundary)
2678 5869 : crtl->preferred_stack_boundary = locate->boundary;
2679 2257890 : }
2680 :
2681 : /* Generate all the code for a CALL_EXPR exp
2682 : and return an rtx for its value.
2683 : Store the value in TARGET (specified as an rtx) if convenient.
2684 : If the value is stored in TARGET then TARGET is returned.
2685 : If IGNORE is nonzero, then we ignore the value of the function call. */
2686 :
2687 : rtx
2688 5999376 : expand_call (tree exp, rtx target, int ignore)
2689 : {
2690 : /* Nonzero if we are currently expanding a call. */
2691 5999376 : static int currently_expanding_call = 0;
2692 :
2693 : /* RTX for the function to be called. */
2694 5999376 : rtx funexp;
2695 : /* Sequence of insns to perform a normal "call". */
2696 5999376 : rtx_insn *normal_call_insns = NULL;
2697 : /* Sequence of insns to perform a tail "call". */
2698 5999376 : rtx_insn *tail_call_insns = NULL;
2699 : /* Data type of the function. */
2700 5999376 : tree funtype;
2701 5999376 : tree type_arg_types;
2702 5999376 : tree rettype;
2703 : /* Declaration of the function being called,
2704 : or 0 if the function is computed (not known by name). */
2705 5999376 : tree fndecl = 0;
2706 : /* The type of the function being called. */
2707 5999376 : tree fntype;
2708 5999376 : bool try_tail_call = CALL_EXPR_TAILCALL (exp);
2709 : /* tree-tailcall decided not to do tail calls. Error for the musttail case,
2710 : unfortunately we don't know the reason so it's fairly vague.
2711 : When tree-tailcall reported an error it already cleared the flag,
2712 : so this shouldn't really happen unless the
2713 : the musttail pass gave up walking before finding the call. */
2714 5999376 : if (!try_tail_call)
2715 5858048 : maybe_complain_about_tail_call (exp, _("other reasons"));
2716 5999376 : int pass;
2717 :
2718 : /* Register in which non-BLKmode value will be returned,
2719 : or 0 if no value or if value is BLKmode. */
2720 5999376 : rtx valreg;
2721 : /* Address where we should return a BLKmode value;
2722 : 0 if value not BLKmode. */
2723 5999376 : rtx structure_value_addr = 0;
2724 : /* Nonzero if that address is being passed by treating it as
2725 : an extra, implicit first parameter. Otherwise,
2726 : it is passed by being copied directly into struct_value_rtx. */
2727 5999376 : int structure_value_addr_parm = 0;
2728 : /* Holds the value of implicit argument for the struct value. */
2729 5999376 : tree structure_value_addr_value = NULL_TREE;
2730 : /* Size of aggregate value wanted, or zero if none wanted
2731 : or if we are using the non-reentrant PCC calling convention
2732 : or expecting the value in registers. */
2733 5999376 : poly_int64 struct_value_size = 0;
2734 : /* True if called function returns an aggregate in memory PCC style,
2735 : by returning the address of where to find it. */
2736 5999376 : bool pcc_struct_value = false;
2737 5999376 : rtx struct_value = 0;
2738 :
2739 : /* Number of actual parameters in this call, including struct value addr. */
2740 5999376 : int num_actuals;
2741 : /* Number of named args. Args after this are anonymous ones
2742 : and they must all go on the stack. */
2743 5999376 : int n_named_args;
2744 : /* Number of complex actual arguments that need to be split. */
2745 5999376 : int num_complex_actuals = 0;
2746 :
2747 : /* Vector of information about each argument.
2748 : Arguments are numbered in the order they will be pushed,
2749 : not the order they are written. */
2750 5999376 : struct arg_data *args;
2751 :
2752 : /* Total size in bytes of all the stack-parms scanned so far. */
2753 5999376 : struct args_size args_size;
2754 5999376 : struct args_size adjusted_args_size;
2755 : /* Size of arguments before any adjustments (such as rounding). */
2756 5999376 : poly_int64 unadjusted_args_size;
2757 : /* Data on reg parms scanned so far. */
2758 5999376 : CUMULATIVE_ARGS args_so_far_v;
2759 5999376 : cumulative_args_t args_so_far;
2760 : /* Nonzero if a reg parm has been scanned. */
2761 5999376 : int reg_parm_seen;
2762 :
2763 : /* True if we must avoid push-insns in the args for this call.
2764 : If stack space is allocated for register parameters, but not by the
2765 : caller, then it is preallocated in the fixed part of the stack frame.
2766 : So the entire argument block must then be preallocated (i.e., we
2767 : ignore PUSH_ROUNDING in that case). */
2768 5999376 : bool must_preallocate = !targetm.calls.push_argument (0);
2769 :
2770 : /* Size of the stack reserved for parameter registers. */
2771 5999376 : int reg_parm_stack_space = 0;
2772 :
2773 : /* Address of space preallocated for stack parms
2774 : (on machines that lack push insns), or 0 if space not preallocated. */
2775 5999376 : rtx argblock = 0;
2776 :
2777 : /* Mask of ECF_ and ERF_ flags. */
2778 5999376 : int flags = 0;
2779 5999376 : int return_flags = 0;
2780 : #ifdef REG_PARM_STACK_SPACE
2781 : /* Define the boundary of the register parm stack space that needs to be
2782 : saved, if any. */
2783 5999376 : int low_to_save, high_to_save;
2784 5999376 : rtx save_area = 0; /* Place that it is saved */
2785 : #endif
2786 :
2787 5999376 : unsigned int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2788 5999376 : char *initial_stack_usage_map = stack_usage_map;
2789 5999376 : unsigned HOST_WIDE_INT initial_stack_usage_watermark = stack_usage_watermark;
2790 5999376 : char *stack_usage_map_buf = NULL;
2791 :
2792 5999376 : poly_int64 old_stack_allocated;
2793 :
2794 : /* State variables to track stack modifications. */
2795 5999376 : rtx old_stack_level = 0;
2796 5999376 : int old_stack_arg_under_construction = 0;
2797 5999376 : poly_int64 old_pending_adj = 0;
2798 5999376 : int old_inhibit_defer_pop = inhibit_defer_pop;
2799 :
2800 : /* Some stack pointer alterations we make are performed via
2801 : allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
2802 : which we then also need to save/restore along the way. */
2803 5999376 : poly_int64 old_stack_pointer_delta = 0;
2804 :
2805 5999376 : rtx call_fusage;
2806 5999376 : tree addr = CALL_EXPR_FN (exp);
2807 5999376 : int i;
2808 : /* The alignment of the stack, in bits. */
2809 5999376 : unsigned HOST_WIDE_INT preferred_stack_boundary;
2810 : /* The alignment of the stack, in bytes. */
2811 5999376 : unsigned HOST_WIDE_INT preferred_unit_stack_boundary;
2812 : /* The static chain value to use for this call. */
2813 5999376 : rtx static_chain_value;
2814 : /* See if this is "nothrow" function call. */
2815 5999376 : if (TREE_NOTHROW (exp))
2816 2079044 : flags |= ECF_NOTHROW;
2817 :
2818 : /* See if we can find a DECL-node for the actual function, and get the
2819 : function attributes (flags) from the function decl or type node. */
2820 5999376 : fndecl = get_callee_fndecl (exp);
2821 5999376 : if (fndecl)
2822 : {
2823 5812376 : fntype = TREE_TYPE (fndecl);
2824 5812376 : flags |= flags_from_decl_or_type (fndecl);
2825 5812376 : return_flags |= decl_return_flags (fndecl);
2826 : }
2827 : else
2828 : {
2829 187000 : fntype = TREE_TYPE (TREE_TYPE (addr));
2830 187000 : flags |= flags_from_decl_or_type (fntype);
2831 187000 : if (CALL_EXPR_BY_DESCRIPTOR (exp))
2832 0 : flags |= ECF_BY_DESCRIPTOR;
2833 : }
2834 5999376 : rettype = TREE_TYPE (exp);
2835 :
2836 5999376 : struct_value = targetm.calls.struct_value_rtx (fntype, 0);
2837 :
2838 : /* Warn if this value is an aggregate type,
2839 : regardless of which calling convention we are using for it. */
2840 5999376 : if (AGGREGATE_TYPE_P (rettype))
2841 366369 : warning (OPT_Waggregate_return, "function call has aggregate value");
2842 :
2843 : /* If the result of a non looping pure or const function call is
2844 : ignored (or void), and none of its arguments are volatile, we can
2845 : avoid expanding the call and just evaluate the arguments for
2846 : side-effects. */
2847 5999376 : if ((flags & (ECF_CONST | ECF_PURE))
2848 411341 : && (!(flags & ECF_LOOPING_CONST_OR_PURE))
2849 371660 : && (flags & ECF_NOTHROW)
2850 6363914 : && (ignore || target == const0_rtx
2851 364537 : || TYPE_MODE (rettype) == VOIDmode))
2852 : {
2853 1 : bool volatilep = false;
2854 1 : tree arg;
2855 1 : call_expr_arg_iterator iter;
2856 :
2857 4 : FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2858 3 : if (TREE_THIS_VOLATILE (arg))
2859 : {
2860 : volatilep = true;
2861 : break;
2862 : }
2863 :
2864 1 : if (! volatilep)
2865 : {
2866 0 : FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2867 0 : expand_expr (arg, const0_rtx, VOIDmode, EXPAND_NORMAL);
2868 0 : return const0_rtx;
2869 : }
2870 : }
2871 :
2872 : #ifdef REG_PARM_STACK_SPACE
2873 11811752 : reg_parm_stack_space = REG_PARM_STACK_SPACE (!fndecl ? fntype : fndecl);
2874 : #endif
2875 :
2876 5270274 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
2877 11233321 : && reg_parm_stack_space > 0 && targetm.calls.push_argument (0))
2878 0 : must_preallocate = true;
2879 :
2880 : /* Set up a place to return a structure. */
2881 :
2882 : /* Cater to broken compilers. */
2883 5999376 : if (aggregate_value_p (exp, fntype))
2884 : {
2885 : /* This call returns a big structure. */
2886 227410 : flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
2887 :
2888 : #ifdef PCC_STATIC_STRUCT_RETURN
2889 : {
2890 : pcc_struct_value = true;
2891 : }
2892 : #else /* not PCC_STATIC_STRUCT_RETURN */
2893 227410 : {
2894 227410 : if (!poly_int_tree_p (TYPE_SIZE_UNIT (rettype), &struct_value_size))
2895 55 : struct_value_size = -1;
2896 :
2897 : /* Even if it is semantically safe to use the target as the return
2898 : slot, it may be not sufficiently aligned for the return type. */
2899 227410 : if (CALL_EXPR_RETURN_SLOT_OPT (exp)
2900 217575 : && target
2901 202304 : && MEM_P (target)
2902 : /* If rettype is addressable, we may not create a temporary.
2903 : If target is properly aligned at runtime and the compiler
2904 : just doesn't know about it, it will work fine, otherwise it
2905 : will be UB. */
2906 376272 : && (TREE_ADDRESSABLE (rettype)
2907 124443 : || !(MEM_ALIGN (target) < TYPE_ALIGN (rettype)
2908 0 : && targetm.slow_unaligned_access (TYPE_MODE (rettype),
2909 0 : MEM_ALIGN (target)))))
2910 148862 : structure_value_addr = XEXP (target, 0);
2911 : else
2912 : {
2913 : /* For variable-sized objects, we must be called with a target
2914 : specified. If we were to allocate space on the stack here,
2915 : we would have no way of knowing when to free it. */
2916 78548 : rtx d = assign_temp (rettype, 1, 1);
2917 78548 : structure_value_addr = XEXP (d, 0);
2918 78548 : target = 0;
2919 : }
2920 : }
2921 : #endif /* not PCC_STATIC_STRUCT_RETURN */
2922 : }
2923 :
2924 : /* Figure out the amount to which the stack should be aligned. */
2925 5999376 : preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2926 5999376 : if (fndecl)
2927 : {
2928 5812376 : struct cgraph_rtl_info *i = cgraph_node::rtl_info (fndecl);
2929 : /* Without automatic stack alignment, we can't increase preferred
2930 : stack boundary. With automatic stack alignment, it is
2931 : unnecessary since unless we can guarantee that all callers will
2932 : align the outgoing stack properly, callee has to align its
2933 : stack anyway. */
2934 5812376 : if (i
2935 1357828 : && i->preferred_incoming_stack_boundary
2936 980999 : && i->preferred_incoming_stack_boundary < preferred_stack_boundary)
2937 304473 : preferred_stack_boundary = i->preferred_incoming_stack_boundary;
2938 : }
2939 :
2940 : /* Operand 0 is a pointer-to-function; get the type of the function. */
2941 5999376 : funtype = TREE_TYPE (addr);
2942 5999376 : gcc_assert (POINTER_TYPE_P (funtype));
2943 5999376 : funtype = TREE_TYPE (funtype);
2944 :
2945 : /* Count whether there are actual complex arguments that need to be split
2946 : into their real and imaginary parts. Munge the type_arg_types
2947 : appropriately here as well. */
2948 5999376 : if (targetm.calls.split_complex_arg)
2949 : {
2950 0 : call_expr_arg_iterator iter;
2951 0 : tree arg;
2952 0 : FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2953 : {
2954 0 : tree type = TREE_TYPE (arg);
2955 0 : if (type && TREE_CODE (type) == COMPLEX_TYPE
2956 0 : && targetm.calls.split_complex_arg (type))
2957 0 : num_complex_actuals++;
2958 : }
2959 0 : type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype));
2960 : }
2961 : else
2962 5999376 : type_arg_types = TYPE_ARG_TYPES (funtype);
2963 :
2964 5999376 : if (flags & ECF_MAY_BE_ALLOCA)
2965 29 : cfun->calls_alloca = 1;
2966 :
2967 : /* If struct_value_rtx is 0, it means pass the address
2968 : as if it were an extra parameter. Put the argument expression
2969 : in structure_value_addr_value. */
2970 5999376 : if (structure_value_addr && struct_value == 0)
2971 : {
2972 : /* If structure_value_addr is a REG other than
2973 : virtual_outgoing_args_rtx, we can use always use it. If it
2974 : is not a REG, we must always copy it into a register.
2975 : If it is virtual_outgoing_args_rtx, we must copy it to another
2976 : register in some cases. */
2977 227410 : rtx temp = (!REG_P (structure_value_addr)
2978 6819 : || (ACCUMULATE_OUTGOING_ARGS
2979 0 : && stack_arg_under_construction
2980 0 : && structure_value_addr == virtual_outgoing_args_rtx)
2981 344677 : ? copy_addr_to_reg (convert_memory_address
2982 : (Pmode, structure_value_addr))
2983 220591 : : structure_value_addr);
2984 :
2985 227410 : structure_value_addr_value =
2986 227410 : make_tree (build_pointer_type (TREE_TYPE (funtype)), temp);
2987 227410 : structure_value_addr_parm = 1;
2988 : }
2989 :
2990 : /* Count the arguments and set NUM_ACTUALS. */
2991 5999376 : num_actuals
2992 5999376 : = call_expr_nargs (exp) + num_complex_actuals + structure_value_addr_parm;
2993 :
2994 : /* Compute number of named args.
2995 : First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2996 :
2997 5999376 : if (type_arg_types != 0)
2998 5974733 : n_named_args
2999 5974733 : = (list_length (type_arg_types)
3000 : /* Count the struct value address, if it is passed as a parm. */
3001 : + structure_value_addr_parm);
3002 24643 : else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype))
3003 565 : n_named_args = structure_value_addr_parm;
3004 : else
3005 : /* If we know nothing, treat all args as named. */
3006 : n_named_args = num_actuals;
3007 :
3008 : /* Start updating where the next arg would go.
3009 :
3010 : On some machines (such as the PA) indirect calls have a different
3011 : calling convention than normal calls. The fourth argument in
3012 : INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
3013 : or not. */
3014 5999376 : INIT_CUMULATIVE_ARGS (args_so_far_v, funtype, NULL_RTX, fndecl, n_named_args);
3015 5999376 : args_so_far = pack_cumulative_args (&args_so_far_v);
3016 :
3017 : /* Now possibly adjust the number of named args.
3018 : Normally, don't include the last named arg if anonymous args follow.
3019 : We do include the last named arg if
3020 : targetm.calls.strict_argument_naming() returns nonzero.
3021 : (If no anonymous args follow, the result of list_length is actually
3022 : one too large. This is harmless.)
3023 :
3024 : If targetm.calls.pretend_outgoing_varargs_named() returns
3025 : nonzero, and targetm.calls.strict_argument_naming() returns zero,
3026 : this machine will be able to place unnamed args that were passed
3027 : in registers into the stack. So treat all args as named. This
3028 : allows the insns emitting for a specific argument list to be
3029 : independent of the function declaration.
3030 :
3031 : If targetm.calls.pretend_outgoing_varargs_named() returns zero,
3032 : we do not have any reliable way to pass unnamed args in
3033 : registers, so we must force them into memory. */
3034 :
3035 24643 : if ((type_arg_types != 0 || TYPE_NO_NAMED_ARGS_STDARG_P (funtype))
3036 5999941 : && targetm.calls.strict_argument_naming (args_so_far))
3037 : ;
3038 24078 : else if (type_arg_types != 0
3039 24078 : && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far))
3040 : /* Don't include the last named arg. */
3041 0 : --n_named_args;
3042 24078 : else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype)
3043 24078 : && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far))
3044 : n_named_args = 0;
3045 : else
3046 : /* Treat all args as named. */
3047 : n_named_args = num_actuals;
3048 :
3049 : /* Make a vector to hold all the information about each arg. */
3050 5999376 : args = XCNEWVEC (struct arg_data, num_actuals);
3051 :
3052 : /* Build up entries in the ARGS array, compute the size of the
3053 : arguments into ARGS_SIZE, etc. */
3054 5999376 : initialize_argument_information (num_actuals, args, &args_size,
3055 : n_named_args, exp,
3056 : structure_value_addr_value, fndecl, fntype,
3057 : args_so_far, reg_parm_stack_space,
3058 : &old_stack_level, &old_pending_adj,
3059 : &must_preallocate, &flags,
3060 5999376 : &try_tail_call, CALL_FROM_THUNK_P (exp));
3061 :
3062 5999376 : if (args_size.var)
3063 0 : must_preallocate = true;
3064 :
3065 : /* Now make final decision about preallocating stack space. */
3066 5999376 : must_preallocate = finalize_must_preallocate (must_preallocate,
3067 : num_actuals, args,
3068 : &args_size);
3069 :
3070 : /* If the structure value address will reference the stack pointer, we
3071 : must stabilize it. We don't need to do this if we know that we are
3072 : not going to adjust the stack pointer in processing this call. */
3073 :
3074 5999376 : if (structure_value_addr
3075 227410 : && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
3076 227410 : || reg_mentioned_p (virtual_outgoing_args_rtx,
3077 : structure_value_addr))
3078 5999376 : && (args_size.var
3079 0 : || (!ACCUMULATE_OUTGOING_ARGS
3080 0 : && maybe_ne (args_size.constant, 0))))
3081 0 : structure_value_addr = copy_to_reg (structure_value_addr);
3082 :
3083 : /* Tail calls can make things harder to debug, and we've traditionally
3084 : pushed these optimizations into -O2. Don't try if we're already
3085 : expanding a call, as that means we're an argument. Don't try if
3086 : there's cleanups, as we know there's code to follow the call. */
3087 5999376 : if (currently_expanding_call++ != 0)
3088 : {
3089 6518 : maybe_complain_about_tail_call (exp, _("inside another call"));
3090 6518 : try_tail_call = 0;
3091 : }
3092 5999376 : if (!flag_optimize_sibling_calls
3093 2951217 : && !CALL_FROM_THUNK_P (exp)
3094 8950160 : && !CALL_EXPR_MUST_TAIL_CALL (exp))
3095 2950459 : try_tail_call = 0;
3096 5999376 : if (args_size.var)
3097 : {
3098 0 : maybe_complain_about_tail_call (exp, _("variable size arguments"));
3099 0 : try_tail_call = 0;
3100 : }
3101 5999376 : if (dbg_cnt (tail_call) == false)
3102 0 : try_tail_call = 0;
3103 :
3104 : /* Workaround buggy C/C++ wrappers around Fortran routines with
3105 : character(len=constant) arguments if the hidden string length arguments
3106 : are passed on the stack; if the callers forget to pass those arguments,
3107 : attempting to tail call in such routines leads to stack corruption.
3108 : Avoid tail calls in functions where at least one such hidden string
3109 : length argument is passed (partially or fully) on the stack in the
3110 : caller and the callee needs to pass any arguments on the stack.
3111 : See PR90329. */
3112 5999376 : if (try_tail_call && maybe_ne (args_size.constant, 0))
3113 14624 : for (tree arg = DECL_ARGUMENTS (current_function_decl);
3114 52091 : arg; arg = DECL_CHAIN (arg))
3115 37467 : if (DECL_HIDDEN_STRING_LENGTH (arg) && DECL_INCOMING_RTL (arg))
3116 : {
3117 0 : subrtx_iterator::array_type array;
3118 0 : FOR_EACH_SUBRTX (iter, array, DECL_INCOMING_RTL (arg), NONCONST)
3119 0 : if (MEM_P (*iter))
3120 : {
3121 0 : try_tail_call = 0;
3122 0 : maybe_complain_about_tail_call (exp, _("hidden string length "
3123 : "argument passed on "
3124 : "stack"));
3125 0 : break;
3126 : }
3127 0 : }
3128 :
3129 : /* If the user has marked the function as requiring tail-call
3130 : optimization, attempt it. */
3131 5999376 : if (CALL_EXPR_MUST_TAIL_CALL (exp))
3132 708 : try_tail_call = 1;
3133 :
3134 : /* Rest of purposes for tail call optimizations to fail. */
3135 5999376 : if (try_tail_call)
3136 141280 : try_tail_call = can_implement_as_sibling_call_p (exp,
3137 : structure_value_addr,
3138 : funtype,
3139 : fndecl,
3140 : flags, addr, args_size);
3141 :
3142 : /* Check if caller and callee disagree in promotion of function
3143 : return value. */
3144 5999376 : if (try_tail_call)
3145 : {
3146 130867 : machine_mode caller_mode, caller_promoted_mode;
3147 130867 : machine_mode callee_mode, callee_promoted_mode;
3148 130867 : int caller_unsignedp, callee_unsignedp;
3149 130867 : tree caller_res = DECL_RESULT (current_function_decl);
3150 :
3151 130867 : caller_unsignedp = TYPE_UNSIGNED (TREE_TYPE (caller_res));
3152 130867 : caller_mode = DECL_MODE (caller_res);
3153 130867 : callee_unsignedp = TYPE_UNSIGNED (TREE_TYPE (funtype));
3154 130867 : callee_mode = TYPE_MODE (TREE_TYPE (funtype));
3155 130867 : caller_promoted_mode
3156 130867 : = promote_function_mode (TREE_TYPE (caller_res), caller_mode,
3157 : &caller_unsignedp,
3158 130867 : TREE_TYPE (current_function_decl), 1);
3159 130867 : callee_promoted_mode
3160 130867 : = promote_function_mode (TREE_TYPE (funtype), callee_mode,
3161 : &callee_unsignedp,
3162 : funtype, 1);
3163 130867 : if (caller_mode != VOIDmode
3164 130867 : && (caller_promoted_mode != callee_promoted_mode
3165 24522 : || ((caller_mode != caller_promoted_mode
3166 24522 : || callee_mode != callee_promoted_mode)
3167 0 : && (caller_unsignedp != callee_unsignedp
3168 0 : || partial_subreg_p (caller_mode, callee_mode)))))
3169 : {
3170 0 : try_tail_call = 0;
3171 0 : maybe_complain_about_tail_call (exp, _("caller and callee disagree "
3172 : "in promotion of function "
3173 : "return value"));
3174 : }
3175 : }
3176 :
3177 : /* Ensure current function's preferred stack boundary is at least
3178 : what we need. Stack alignment may also increase preferred stack
3179 : boundary. */
3180 18376222 : for (i = 0; i < num_actuals; i++)
3181 12376846 : if (reg_parm_stack_space > 0
3182 12297913 : || args[i].reg == 0
3183 10156987 : || args[i].partial != 0
3184 10156987 : || args[i].pass_on_stack)
3185 2219859 : update_stack_alignment_for_call (&args[i].locate);
3186 5999376 : if (crtl->preferred_stack_boundary < preferred_stack_boundary)
3187 881559 : crtl->preferred_stack_boundary = preferred_stack_boundary;
3188 : else
3189 : preferred_stack_boundary = crtl->preferred_stack_boundary;
3190 :
3191 5999376 : preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
3192 :
3193 5999376 : if (flag_callgraph_info)
3194 0 : record_final_call (fndecl, EXPR_LOCATION (exp));
3195 :
3196 : /* We want to make two insn chains; one for a sibling call, the other
3197 : for a normal call. We will select one of the two chains after
3198 : initial RTL generation is complete. */
3199 6047918 : for (pass = try_tail_call ? 0 : 1; pass < 2; pass++)
3200 : {
3201 5999380 : bool sibcall_failure = false;
3202 5999380 : bool normal_failure = false;
3203 : /* We want to emit any pending stack adjustments before the tail
3204 : recursion "call". That way we know any adjustment after the tail
3205 : recursion call can be ignored if we indeed use the tail
3206 : call expansion. */
3207 5999380 : saved_pending_stack_adjust save;
3208 5999380 : rtx_insn *insns, *before_call, *after_args;
3209 5999380 : rtx next_arg_reg;
3210 :
3211 5999380 : if (pass == 0)
3212 : {
3213 : /* State variables we need to save and restore between
3214 : iterations. */
3215 130867 : save_pending_stack_adjust (&save);
3216 : }
3217 130867 : if (pass)
3218 5868513 : flags &= ~ECF_SIBCALL;
3219 : else
3220 130867 : flags |= ECF_SIBCALL;
3221 :
3222 : /* Other state variables that we must reinitialize each time
3223 : through the loop (that are not initialized by the loop itself). */
3224 5999380 : argblock = 0;
3225 5999380 : call_fusage = 0;
3226 :
3227 : /* Start a new sequence for the normal call case.
3228 :
3229 : From this point on, if the sibling call fails, we want to set
3230 : sibcall_failure instead of continuing the loop. */
3231 5999380 : start_sequence ();
3232 :
3233 : /* Don't let pending stack adjusts add up to too much.
3234 : Also, do all pending adjustments now if there is any chance
3235 : this might be a call to alloca or if we are expanding a sibling
3236 : call sequence.
3237 : Also do the adjustments before a throwing call, otherwise
3238 : exception handling can fail; PR 19225. */
3239 5999380 : if (maybe_ge (pending_stack_adjust, 32)
3240 5936001 : || (maybe_ne (pending_stack_adjust, 0)
3241 139248 : && (flags & ECF_MAY_BE_ALLOCA))
3242 5936001 : || (maybe_ne (pending_stack_adjust, 0)
3243 139248 : && flag_exceptions && !(flags & ECF_NOTHROW))
3244 11829227 : || pass == 0)
3245 299921 : do_pending_stack_adjust ();
3246 :
3247 : /* Precompute any arguments as needed. */
3248 5999380 : if (pass)
3249 5868513 : precompute_arguments (num_actuals, args);
3250 :
3251 : /* Check the canary value for sibcall or function which doesn't
3252 : return and could throw. */
3253 5868513 : if ((pass == 0
3254 5868513 : || ((flags & ECF_NORETURN) != 0 && tree_could_throw_p (exp)))
3255 474727 : && crtl->stack_protect_guard
3256 33 : && targetm.stack_protect_runtime_enabled_p ())
3257 33 : stack_protect_epilogue ();
3258 :
3259 5999380 : adjusted_args_size = args_size;
3260 : /* Compute the actual size of the argument block required. The variable
3261 : and constant sizes must be combined, the size may have to be rounded,
3262 : and there may be a minimum required size. When generating a sibcall
3263 : pattern, do not round up, since we'll be re-using whatever space our
3264 : caller provided. */
3265 5999380 : unadjusted_args_size
3266 11867893 : = compute_argument_block_size (reg_parm_stack_space,
3267 : &adjusted_args_size,
3268 : fndecl, fntype,
3269 : (pass == 0 ? 0
3270 : : preferred_stack_boundary));
3271 :
3272 5999380 : old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
3273 :
3274 : /* The argument block when performing a sibling call is the
3275 : incoming argument block. */
3276 5999380 : if (pass == 0)
3277 : {
3278 130867 : argblock = crtl->args.internal_arg_pointer;
3279 130867 : if (STACK_GROWS_DOWNWARD)
3280 130867 : argblock
3281 135783 : = plus_constant (Pmode, argblock, crtl->args.pretend_args_size);
3282 : else
3283 : argblock
3284 : = plus_constant (Pmode, argblock, -crtl->args.pretend_args_size);
3285 :
3286 130867 : HOST_WIDE_INT map_size = constant_lower_bound (args_size.constant);
3287 130867 : stored_args_map = sbitmap_alloc (map_size);
3288 130867 : bitmap_clear (stored_args_map);
3289 130867 : stored_args_watermark = HOST_WIDE_INT_M1U;
3290 : }
3291 :
3292 : /* If we have no actual push instructions, or shouldn't use them,
3293 : make space for all args right now. */
3294 5868513 : else if (adjusted_args_size.var != 0)
3295 : {
3296 0 : if (old_stack_level == 0)
3297 : {
3298 0 : emit_stack_save (SAVE_BLOCK, &old_stack_level);
3299 0 : old_stack_pointer_delta = stack_pointer_delta;
3300 0 : old_pending_adj = pending_stack_adjust;
3301 0 : pending_stack_adjust = 0;
3302 : /* stack_arg_under_construction says whether a stack arg is
3303 : being constructed at the old stack level. Pushing the stack
3304 : gets a clean outgoing argument block. */
3305 0 : old_stack_arg_under_construction = stack_arg_under_construction;
3306 0 : stack_arg_under_construction = 0;
3307 : }
3308 0 : argblock = push_block (ARGS_SIZE_RTX (adjusted_args_size), 0, 0);
3309 0 : if (flag_stack_usage_info)
3310 0 : current_function_has_unbounded_dynamic_stack_size = 1;
3311 : }
3312 : else
3313 : {
3314 : /* Note that we must go through the motions of allocating an argument
3315 : block even if the size is zero because we may be storing args
3316 : in the area reserved for register arguments, which may be part of
3317 : the stack frame. */
3318 :
3319 5868513 : poly_int64 needed = adjusted_args_size.constant;
3320 :
3321 : /* Store the maximum argument space used. It will be pushed by
3322 : the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
3323 : checking). */
3324 :
3325 5868513 : crtl->outgoing_args_size = upper_bound (crtl->outgoing_args_size,
3326 : needed);
3327 :
3328 5868513 : if (must_preallocate)
3329 : {
3330 73403 : if (ACCUMULATE_OUTGOING_ARGS)
3331 : {
3332 : /* Since the stack pointer will never be pushed, it is
3333 : possible for the evaluation of a parm to clobber
3334 : something we have already written to the stack.
3335 : Since most function calls on RISC machines do not use
3336 : the stack, this is uncommon, but must work correctly.
3337 :
3338 : Therefore, we save any area of the stack that was already
3339 : written and that we are using. Here we set up to do this
3340 : by making a new stack usage map from the old one. The
3341 : actual save will be done by store_one_arg.
3342 :
3343 : Another approach might be to try to reorder the argument
3344 : evaluations to avoid this conflicting stack usage. */
3345 :
3346 : /* Since we will be writing into the entire argument area,
3347 : the map must be allocated for its entire size, not just
3348 : the part that is the responsibility of the caller. */
3349 73387 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
3350 67409 : needed += reg_parm_stack_space;
3351 :
3352 73387 : poly_int64 limit = needed;
3353 73387 : if (ARGS_GROW_DOWNWARD)
3354 : limit += 1;
3355 :
3356 : /* For polynomial sizes, this is the maximum possible
3357 : size needed for arguments with a constant size
3358 : and offset. */
3359 73387 : HOST_WIDE_INT const_limit = constant_lower_bound (limit);
3360 73387 : highest_outgoing_arg_in_use
3361 73387 : = MAX (initial_highest_arg_in_use, const_limit);
3362 :
3363 73387 : free (stack_usage_map_buf);
3364 73387 : stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
3365 73387 : stack_usage_map = stack_usage_map_buf;
3366 :
3367 73387 : if (initial_highest_arg_in_use)
3368 0 : memcpy (stack_usage_map, initial_stack_usage_map,
3369 : initial_highest_arg_in_use);
3370 :
3371 73387 : if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3372 17666 : memset (&stack_usage_map[initial_highest_arg_in_use], 0,
3373 : (highest_outgoing_arg_in_use
3374 17666 : - initial_highest_arg_in_use));
3375 73387 : needed = 0;
3376 :
3377 : /* The address of the outgoing argument list must not be
3378 : copied to a register here, because argblock would be left
3379 : pointing to the wrong place after the call to
3380 : allocate_dynamic_stack_space below. */
3381 :
3382 73387 : argblock = virtual_outgoing_args_rtx;
3383 : }
3384 : else
3385 : {
3386 : /* Try to reuse some or all of the pending_stack_adjust
3387 : to get this space. */
3388 16 : if (inhibit_defer_pop == 0
3389 32 : && (combine_pending_stack_adjustment_and_call
3390 16 : (&needed,
3391 : unadjusted_args_size,
3392 : &adjusted_args_size,
3393 : preferred_unit_stack_boundary)))
3394 : {
3395 : /* combine_pending_stack_adjustment_and_call computes
3396 : an adjustment before the arguments are allocated.
3397 : Account for them and see whether or not the stack
3398 : needs to go up or down. */
3399 16 : needed = unadjusted_args_size - needed;
3400 :
3401 : /* Checked by
3402 : combine_pending_stack_adjustment_and_call. */
3403 16 : gcc_checking_assert (ordered_p (needed, 0));
3404 16 : if (maybe_lt (needed, 0))
3405 : {
3406 : /* We're releasing stack space. */
3407 : /* ??? We can avoid any adjustment at all if we're
3408 : already aligned. FIXME. */
3409 0 : pending_stack_adjust = -needed;
3410 0 : do_pending_stack_adjust ();
3411 0 : needed = 0;
3412 : }
3413 : else
3414 : /* We need to allocate space. We'll do that in
3415 : push_block below. */
3416 16 : pending_stack_adjust = 0;
3417 : }
3418 :
3419 : /* Special case this because overhead of `push_block' in
3420 : this case is non-trivial. */
3421 16 : if (known_eq (needed, 0))
3422 7 : argblock = virtual_outgoing_args_rtx;
3423 : else
3424 : {
3425 9 : rtx needed_rtx = gen_int_mode (needed, Pmode);
3426 9 : argblock = push_block (needed_rtx, 0, 0);
3427 9 : if (ARGS_GROW_DOWNWARD)
3428 : argblock = plus_constant (Pmode, argblock, needed);
3429 : }
3430 :
3431 : /* We only really need to call `copy_to_reg' in the case
3432 : where push insns are going to be used to pass ARGBLOCK
3433 : to a function call in ARGS. In that case, the stack
3434 : pointer changes value from the allocation point to the
3435 : call point, and hence the value of
3436 : VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
3437 : as well always do it. */
3438 16 : argblock = copy_to_reg (argblock);
3439 : }
3440 : }
3441 : }
3442 :
3443 5999380 : if (ACCUMULATE_OUTGOING_ARGS)
3444 : {
3445 : /* The save/restore code in store_one_arg handles all
3446 : cases except one: a constructor call (including a C
3447 : function returning a BLKmode struct) to initialize
3448 : an argument. */
3449 74581 : if (stack_arg_under_construction)
3450 : {
3451 0 : rtx push_size
3452 : = (gen_int_mode
3453 0 : (adjusted_args_size.constant
3454 0 : + (OUTGOING_REG_PARM_STACK_SPACE (!fndecl ? fntype
3455 : : TREE_TYPE (fndecl))
3456 0 : ? 0 : reg_parm_stack_space), Pmode));
3457 0 : if (old_stack_level == 0)
3458 : {
3459 0 : emit_stack_save (SAVE_BLOCK, &old_stack_level);
3460 0 : old_stack_pointer_delta = stack_pointer_delta;
3461 0 : old_pending_adj = pending_stack_adjust;
3462 0 : pending_stack_adjust = 0;
3463 : /* stack_arg_under_construction says whether a stack
3464 : arg is being constructed at the old stack level.
3465 : Pushing the stack gets a clean outgoing argument
3466 : block. */
3467 0 : old_stack_arg_under_construction
3468 0 : = stack_arg_under_construction;
3469 0 : stack_arg_under_construction = 0;
3470 : /* Make a new map for the new argument list. */
3471 0 : free (stack_usage_map_buf);
3472 0 : stack_usage_map_buf = XCNEWVEC (char, highest_outgoing_arg_in_use);
3473 0 : stack_usage_map = stack_usage_map_buf;
3474 0 : highest_outgoing_arg_in_use = 0;
3475 0 : stack_usage_watermark = HOST_WIDE_INT_M1U;
3476 : }
3477 : /* We can pass TRUE as the 4th argument because we just
3478 : saved the stack pointer and will restore it right after
3479 : the call. */
3480 0 : allocate_dynamic_stack_space (push_size, 0, BIGGEST_ALIGNMENT,
3481 : -1, true);
3482 : }
3483 :
3484 : /* If argument evaluation might modify the stack pointer,
3485 : copy the address of the argument list to a register. */
3486 369057 : for (i = 0; i < num_actuals; i++)
3487 294476 : if (args[i].pass_on_stack)
3488 : {
3489 0 : argblock = copy_addr_to_reg (argblock);
3490 0 : break;
3491 : }
3492 : }
3493 :
3494 5999380 : compute_argument_addresses (args, argblock, num_actuals);
3495 :
3496 : /* Stack is properly aligned, pops can't safely be deferred during
3497 : the evaluation of the arguments. */
3498 5999380 : NO_DEFER_POP;
3499 :
3500 : /* Precompute all register parameters. It isn't safe to compute
3501 : anything once we have started filling any specific hard regs.
3502 : TLS symbols sometimes need a call to resolve. Precompute
3503 : register parameters before any stack pointer manipulation
3504 : to avoid unaligned stack in the called function. */
3505 5999380 : precompute_register_parameters (num_actuals, args, ®_parm_seen);
3506 :
3507 5999378 : OK_DEFER_POP;
3508 :
3509 : /* Perform stack alignment before the first push (the last arg). */
3510 5999378 : if (argblock == 0
3511 5795108 : && maybe_gt (adjusted_args_size.constant, reg_parm_stack_space)
3512 6906820 : && maybe_ne (adjusted_args_size.constant, unadjusted_args_size))
3513 : {
3514 : /* When the stack adjustment is pending, we get better code
3515 : by combining the adjustments. */
3516 727318 : if (maybe_ne (pending_stack_adjust, 0)
3517 14360 : && ! inhibit_defer_pop
3518 741678 : && (combine_pending_stack_adjustment_and_call
3519 14360 : (&pending_stack_adjust,
3520 : unadjusted_args_size,
3521 : &adjusted_args_size,
3522 : preferred_unit_stack_boundary)))
3523 14360 : do_pending_stack_adjust ();
3524 712958 : else if (argblock == 0)
3525 712958 : anti_adjust_stack (gen_int_mode (adjusted_args_size.constant
3526 : - unadjusted_args_size,
3527 712958 : Pmode));
3528 : }
3529 : /* Now that the stack is properly aligned, pops can't safely
3530 : be deferred during the evaluation of the arguments. */
3531 5999378 : NO_DEFER_POP;
3532 :
3533 : /* Record the maximum pushed stack space size. We need to delay
3534 : doing it this far to take into account the optimization done
3535 : by combine_pending_stack_adjustment_and_call. */
3536 5999378 : if (flag_stack_usage_info
3537 1044 : && !ACCUMULATE_OUTGOING_ARGS
3538 1044 : && pass
3539 6000422 : && adjusted_args_size.var == 0)
3540 : {
3541 1044 : poly_int64 pushed = (adjusted_args_size.constant
3542 1044 : + pending_stack_adjust);
3543 1044 : current_function_pushed_stack_size
3544 1044 : = upper_bound (current_function_pushed_stack_size, pushed);
3545 : }
3546 :
3547 5999378 : funexp = rtx_for_function_call (fndecl, addr);
3548 :
3549 5999378 : if (CALL_EXPR_STATIC_CHAIN (exp))
3550 37818 : static_chain_value = expand_normal (CALL_EXPR_STATIC_CHAIN (exp));
3551 : else
3552 : static_chain_value = 0;
3553 :
3554 : #ifdef REG_PARM_STACK_SPACE
3555 : /* Save the fixed argument area if it's part of the caller's frame and
3556 : is clobbered by argument setup for this call. */
3557 5999378 : if (ACCUMULATE_OUTGOING_ARGS && pass)
3558 73387 : save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
3559 : &low_to_save, &high_to_save);
3560 : #endif
3561 :
3562 : /* Now store (and compute if necessary) all non-register parms.
3563 : These come before register parms, since they can require block-moves,
3564 : which could clobber the registers used for register parms.
3565 : Parms which have partial registers are not stored here,
3566 : but we do preallocate space here if they want that. */
3567 :
3568 18376262 : for (i = 0; i < num_actuals; i++)
3569 : {
3570 12376884 : if (args[i].reg == 0 || args[i].pass_on_stack)
3571 : {
3572 2153710 : rtx_insn *before_arg = get_last_insn ();
3573 :
3574 : /* We don't allow passing huge (> 2^30 B) arguments
3575 : by value. It would cause an overflow later on. */
3576 2153710 : if (constant_lower_bound (adjusted_args_size.constant)
3577 : >= (1 << (HOST_BITS_PER_INT - 2)))
3578 : {
3579 6 : sorry ("passing too large argument on stack");
3580 : /* Don't worry about stack clean-up. */
3581 6 : if (pass == 0)
3582 0 : sibcall_failure = true;
3583 : else
3584 : normal_failure = true;
3585 6 : continue;
3586 : }
3587 :
3588 2153704 : if (store_one_arg (&args[i], argblock, flags,
3589 2153704 : adjusted_args_size.var != 0,
3590 : reg_parm_stack_space)
3591 2153704 : || (pass == 0
3592 10396 : && check_sibcall_argument_overlap (before_arg,
3593 : &args[i], true)))
3594 4 : sibcall_failure = true;
3595 2153704 : gcc_checking_assert (!args[i].stack || argblock);
3596 : }
3597 :
3598 12376878 : if (args[i].stack)
3599 64016 : call_fusage
3600 64016 : = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
3601 : gen_rtx_USE (VOIDmode, args[i].stack),
3602 : call_fusage);
3603 : }
3604 :
3605 : /* If we have a parm that is passed in registers but not in memory
3606 : and whose alignment does not permit a direct copy into registers,
3607 : make a group of pseudos that correspond to each register that we
3608 : will later fill. */
3609 5999378 : if (STRICT_ALIGNMENT)
3610 : store_unaligned_arguments_into_pseudos (args, num_actuals);
3611 :
3612 : /* Now store any partially-in-registers parm.
3613 : This is the last place a block-move can happen. */
3614 5999378 : if (reg_parm_seen)
3615 15397264 : for (i = 0; i < num_actuals; i++)
3616 10863459 : if (args[i].partial != 0 && ! args[i].pass_on_stack)
3617 : {
3618 0 : rtx_insn *before_arg = get_last_insn ();
3619 :
3620 : /* On targets with weird calling conventions (e.g. PA) it's
3621 : hard to ensure that all cases of argument overlap between
3622 : stack and registers work. Play it safe and bail out. */
3623 0 : if (ARGS_GROW_DOWNWARD && !STACK_GROWS_DOWNWARD)
3624 : {
3625 : sibcall_failure = true;
3626 : break;
3627 : }
3628 :
3629 0 : if (store_one_arg (&args[i], argblock, flags,
3630 0 : adjusted_args_size.var != 0,
3631 : reg_parm_stack_space)
3632 0 : || (pass == 0
3633 0 : && check_sibcall_argument_overlap (before_arg,
3634 : &args[i], true)))
3635 0 : sibcall_failure = true;
3636 : }
3637 :
3638 : /* Set up the next argument register. For sibling calls on machines
3639 : with register windows this should be the incoming register. */
3640 5999378 : if (pass == 0)
3641 130867 : next_arg_reg = targetm.calls.function_incoming_arg
3642 130867 : (args_so_far, function_arg_info::end_marker ());
3643 : else
3644 5868511 : next_arg_reg = targetm.calls.function_arg
3645 5868511 : (args_so_far, function_arg_info::end_marker ());
3646 :
3647 5999378 : targetm.calls.start_call_args (args_so_far);
3648 :
3649 5999378 : bool any_regs = false;
3650 24375640 : for (i = 0; i < num_actuals; i++)
3651 12376884 : if (args[i].reg != NULL_RTX)
3652 : {
3653 10223174 : any_regs = true;
3654 10223174 : targetm.calls.call_args (args_so_far, args[i].reg, funtype);
3655 : }
3656 5999378 : if (!any_regs)
3657 1465573 : targetm.calls.call_args (args_so_far, pc_rtx, funtype);
3658 :
3659 : /* Figure out the register where the value, if any, will come back. */
3660 5999378 : valreg = 0;
3661 5999378 : if (TYPE_MODE (rettype) != VOIDmode
3662 5999378 : && ! structure_value_addr)
3663 : {
3664 2410703 : if (pcc_struct_value)
3665 : valreg = hard_function_value (build_pointer_type (rettype),
3666 : fndecl, NULL, (pass == 0));
3667 : else
3668 2410703 : valreg = hard_function_value (rettype, fndecl, fntype,
3669 : (pass == 0));
3670 :
3671 : /* If VALREG is a PARALLEL whose first member has a zero
3672 : offset, use that. This is for targets such as m68k that
3673 : return the same value in multiple places. */
3674 2410703 : if (GET_CODE (valreg) == PARALLEL)
3675 : {
3676 11555 : rtx elem = XVECEXP (valreg, 0, 0);
3677 11555 : rtx where = XEXP (elem, 0);
3678 11555 : rtx offset = XEXP (elem, 1);
3679 11555 : if (offset == const0_rtx
3680 11538 : && GET_MODE (where) == GET_MODE (valreg))
3681 5999378 : valreg = where;
3682 : }
3683 : }
3684 :
3685 : /* If register arguments require space on the stack and stack space
3686 : was not preallocated, allocate stack space here for arguments
3687 : passed in registers. */
3688 5270272 : if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
3689 36329 : && !ACCUMULATE_OUTGOING_ARGS
3690 6028570 : && !must_preallocate && reg_parm_stack_space > 0)
3691 29185 : anti_adjust_stack (GEN_INT (reg_parm_stack_space));
3692 :
3693 : /* Cover pushed arguments with call usage, so that cselib knows to
3694 : invalidate the stores in them at the call insn. */
3695 5999378 : if (pass == 1 && !argblock
3696 5999378 : && (maybe_ne (adjusted_args_size.constant, 0)
3697 4870198 : || adjusted_args_size.var))
3698 : {
3699 924910 : rtx addr = virtual_outgoing_args_rtx;
3700 924910 : poly_int64 size = adjusted_args_size.constant;
3701 924910 : if (!STACK_GROWS_DOWNWARD)
3702 : {
3703 : if (adjusted_args_size.var)
3704 : /* ??? We can't compute the exact base address. */
3705 : addr = gen_rtx_PLUS (GET_MODE (addr), addr,
3706 : gen_rtx_SCRATCH (GET_MODE (addr)));
3707 : else
3708 : addr = plus_constant (GET_MODE (addr), addr, -size);
3709 : }
3710 924910 : rtx fu = gen_rtx_MEM (BLKmode, addr);
3711 924910 : if (adjusted_args_size.var == 0)
3712 924910 : set_mem_size (fu, size);
3713 924910 : call_fusage
3714 924910 : = gen_rtx_EXPR_LIST (BLKmode,
3715 : gen_rtx_USE (VOIDmode, fu),
3716 : call_fusage);
3717 : }
3718 :
3719 : /* Pass the function the address in which to return a
3720 : structure value. */
3721 5999378 : if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
3722 : {
3723 0 : structure_value_addr
3724 0 : = convert_memory_address (Pmode, structure_value_addr);
3725 0 : emit_move_insn (struct_value,
3726 0 : force_reg (Pmode,
3727 : force_operand (structure_value_addr,
3728 : NULL_RTX)));
3729 :
3730 0 : if (REG_P (struct_value))
3731 0 : use_reg (&call_fusage, struct_value);
3732 : }
3733 :
3734 5999378 : after_args = get_last_insn ();
3735 6186378 : funexp = prepare_call_address (fndecl ? fndecl : fntype, funexp,
3736 : static_chain_value, &call_fusage,
3737 : reg_parm_seen, flags);
3738 :
3739 5999378 : load_register_parameters (args, num_actuals, &call_fusage, flags,
3740 : pass == 0, &sibcall_failure);
3741 :
3742 : /* Save a pointer to the last insn before the call, so that we can
3743 : later safely search backwards to find the CALL_INSN. */
3744 5999378 : before_call = get_last_insn ();
3745 :
3746 5999378 : if (pass == 1 && (return_flags & ERF_RETURNS_ARG))
3747 : {
3748 164814 : int arg_nr = return_flags & ERF_RETURN_ARG_MASK;
3749 164814 : arg_nr = num_actuals - arg_nr - 1;
3750 164814 : if (arg_nr >= 0
3751 164814 : && arg_nr < num_actuals
3752 164808 : && args[arg_nr].reg
3753 157974 : && valreg
3754 152666 : && REG_P (valreg)
3755 152666 : && GET_MODE (args[arg_nr].reg) == GET_MODE (valreg))
3756 152666 : call_fusage
3757 152666 : = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[arg_nr].tree_value)),
3758 : gen_rtx_SET (valreg, args[arg_nr].reg),
3759 : call_fusage);
3760 : }
3761 : /* All arguments and registers used for the call must be set up by
3762 : now! */
3763 :
3764 : /* Stack must be properly aligned now. */
3765 11867889 : gcc_assert (!pass
3766 : || multiple_p (stack_pointer_delta,
3767 : preferred_unit_stack_boundary));
3768 :
3769 : /* Generate the actual call instruction. */
3770 5999378 : emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,
3771 : adjusted_args_size.constant, struct_value_size,
3772 : next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
3773 : flags, args_so_far);
3774 :
3775 5999378 : rtx_call_insn *last;
3776 5999378 : rtx datum = NULL_RTX;
3777 5999378 : if (fndecl != NULL_TREE)
3778 : {
3779 5812378 : datum = XEXP (DECL_RTL (fndecl), 0);
3780 5812378 : gcc_assert (datum != NULL_RTX
3781 : && GET_CODE (datum) == SYMBOL_REF);
3782 : }
3783 5999378 : last = last_call_insn ();
3784 5999378 : add_reg_note (last, REG_CALL_DECL, datum);
3785 :
3786 : /* If the call setup or the call itself overlaps with anything
3787 : of the argument setup we probably clobbered our call address.
3788 : In that case we can't do sibcalls. */
3789 5999378 : if (pass == 0
3790 5999378 : && check_sibcall_argument_overlap (after_args, 0, false))
3791 0 : sibcall_failure = true;
3792 :
3793 : /* If a non-BLKmode value is returned at the most significant end
3794 : of a register, shift the register right by the appropriate amount
3795 : and update VALREG accordingly. BLKmode values are handled by the
3796 : group load/store machinery below. */
3797 5999378 : if (!structure_value_addr
3798 : && !pcc_struct_value
3799 5771968 : && TYPE_MODE (rettype) != VOIDmode
3800 2410703 : && TYPE_MODE (rettype) != BLKmode
3801 2407913 : && REG_P (valreg)
3802 8397370 : && targetm.calls.return_in_msb (rettype))
3803 : {
3804 0 : if (shift_return_value (TYPE_MODE (rettype), false, valreg))
3805 0 : sibcall_failure = true;
3806 0 : valreg = gen_rtx_REG (TYPE_MODE (rettype), REGNO (valreg));
3807 : }
3808 :
3809 : /* If the return register exists, for malloc like
3810 : function calls, mark the return register with the
3811 : alignment and noalias reg note. */
3812 5999378 : if (pass && (flags & ECF_MALLOC) && valreg)
3813 : {
3814 142955 : rtx temp = gen_reg_rtx (GET_MODE (valreg));
3815 142955 : rtx_insn *last;
3816 :
3817 : /* The return value from a malloc-like function is a pointer. */
3818 142955 : if (TREE_CODE (rettype) == POINTER_TYPE)
3819 147138 : mark_reg_pointer (temp, MALLOC_ABI_ALIGNMENT);
3820 :
3821 142955 : last = emit_move_insn (temp, valreg);
3822 :
3823 : /* The return value from a malloc-like function cannot alias
3824 : anything else. */
3825 142955 : add_reg_note (last, REG_NOALIAS, temp);
3826 142955 : valreg = temp;
3827 : }
3828 :
3829 : /* For calls to `setjmp', etc., inform
3830 : function.cc:setjmp_warnings that it should complain if
3831 : nonvolatile values are live. For functions that cannot
3832 : return, inform flow that control does not fall through. */
3833 :
3834 5999378 : if ((flags & ECF_NORETURN) || pass == 0)
3835 : {
3836 : /* The barrier must be emitted
3837 : immediately after the CALL_INSN. Some ports emit more
3838 : than just a CALL_INSN above, so we must search for it here. */
3839 :
3840 922153 : rtx_insn *last = get_last_insn ();
3841 922272 : while (!CALL_P (last))
3842 : {
3843 119 : last = PREV_INSN (last);
3844 : /* There was no CALL_INSN? */
3845 119 : gcc_assert (last != before_call);
3846 : }
3847 :
3848 922153 : emit_barrier_after (last);
3849 :
3850 : /* Stack adjustments after a noreturn call are dead code.
3851 : However when NO_DEFER_POP is in effect, we must preserve
3852 : stack_pointer_delta. */
3853 922153 : if (inhibit_defer_pop == 0)
3854 : {
3855 922153 : stack_pointer_delta = old_stack_allocated;
3856 922153 : pending_stack_adjust = 0;
3857 : }
3858 : }
3859 :
3860 : /* If value type not void, return an rtx for the value. */
3861 :
3862 5999378 : if (TYPE_MODE (rettype) == VOIDmode
3863 5999378 : || ignore)
3864 4024773 : target = const0_rtx;
3865 1974605 : else if (structure_value_addr)
3866 : {
3867 206251 : if (target == 0 || !MEM_P (target))
3868 : {
3869 57389 : target
3870 57389 : = gen_rtx_MEM (TYPE_MODE (rettype),
3871 57389 : memory_address (TYPE_MODE (rettype),
3872 : structure_value_addr));
3873 57389 : set_mem_attributes (target, rettype, 1);
3874 : }
3875 : }
3876 1768354 : else if (pcc_struct_value)
3877 : {
3878 : /* This is the special C++ case where we need to
3879 : know what the true target was. We take care to
3880 : never use this value more than once in one expression. */
3881 : target = gen_rtx_MEM (TYPE_MODE (rettype),
3882 : copy_to_reg (valreg));
3883 : set_mem_attributes (target, rettype, 1);
3884 : }
3885 : /* Handle calls that return values in multiple non-contiguous locations.
3886 : The Irix 6 ABI has examples of this. */
3887 1768354 : else if (GET_CODE (valreg) == PARALLEL)
3888 : {
3889 11291 : if (target == 0)
3890 1963 : target = emit_group_move_into_temps (valreg);
3891 9328 : else if (rtx_equal_p (target, valreg))
3892 : ;
3893 9328 : else if (GET_CODE (target) == PARALLEL)
3894 : /* Handle the result of a emit_group_move_into_temps
3895 : call in the previous pass. */
3896 0 : emit_group_move (target, valreg);
3897 : else
3898 9328 : emit_group_store (target, valreg, rettype,
3899 9328 : int_size_in_bytes (rettype));
3900 : }
3901 1757063 : else if (target
3902 1607084 : && GET_MODE (target) == TYPE_MODE (rettype)
3903 3364147 : && GET_MODE (target) == GET_MODE (valreg))
3904 : {
3905 1607081 : bool may_overlap = false;
3906 :
3907 : /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
3908 : reg to a plain register. */
3909 1607081 : if (!REG_P (target) || HARD_REGISTER_P (target))
3910 67520 : valreg = avoid_likely_spilled_reg (valreg);
3911 :
3912 : /* If TARGET is a MEM in the argument area, and we have
3913 : saved part of the argument area, then we can't store
3914 : directly into TARGET as it may get overwritten when we
3915 : restore the argument save area below. Don't work too
3916 : hard though and simply force TARGET to a register if it
3917 : is a MEM; the optimizer is quite likely to sort it out. */
3918 1607081 : if (ACCUMULATE_OUTGOING_ARGS && pass && MEM_P (target))
3919 1063 : for (i = 0; i < num_actuals; i++)
3920 669 : if (args[i].save_area)
3921 : {
3922 : may_overlap = true;
3923 : break;
3924 : }
3925 :
3926 394 : if (may_overlap)
3927 0 : target = copy_to_reg (valreg);
3928 : else
3929 : {
3930 : /* TARGET and VALREG cannot be equal at this point
3931 : because the latter would not have
3932 : REG_FUNCTION_VALUE_P true, while the former would if
3933 : it were referring to the same register.
3934 :
3935 : If they refer to the same register, this move will be
3936 : a no-op, except when function inlining is being
3937 : done. */
3938 1607081 : emit_move_insn (target, valreg);
3939 :
3940 : /* If we are setting a MEM, this code must be executed.
3941 : Since it is emitted after the call insn, sibcall
3942 : optimization cannot be performed in that case. */
3943 1607081 : if (MEM_P (target))
3944 48380 : sibcall_failure = true;
3945 : }
3946 : }
3947 : else
3948 149982 : target = copy_to_reg (avoid_likely_spilled_reg (valreg));
3949 :
3950 : /* If we promoted this return value, make the proper SUBREG.
3951 : TARGET might be const0_rtx here, so be careful. */
3952 5999378 : if (REG_P (target)
3953 1692427 : && TYPE_MODE (rettype) != BLKmode
3954 7691549 : && GET_MODE (target) != TYPE_MODE (rettype))
3955 : {
3956 1 : tree type = rettype;
3957 1 : int unsignedp = TYPE_UNSIGNED (type);
3958 1 : machine_mode ret_mode = TYPE_MODE (type);
3959 1 : machine_mode pmode;
3960 :
3961 : /* Ensure we promote as expected, and get the new unsignedness. */
3962 1 : pmode = promote_function_mode (type, ret_mode, &unsignedp,
3963 : funtype, 1);
3964 1 : gcc_assert (GET_MODE (target) == pmode);
3965 :
3966 1 : if (SCALAR_INT_MODE_P (pmode)
3967 1 : && SCALAR_FLOAT_MODE_P (ret_mode)
3968 1 : && known_gt (GET_MODE_SIZE (pmode), GET_MODE_SIZE (ret_mode)))
3969 0 : target = convert_wider_int_to_float (ret_mode, pmode, target);
3970 : else
3971 : {
3972 1 : target = gen_lowpart_SUBREG (ret_mode, target);
3973 1 : SUBREG_PROMOTED_VAR_P (target) = 1;
3974 1 : SUBREG_PROMOTED_SET (target, unsignedp);
3975 : }
3976 : }
3977 :
3978 : /* If size of args is variable or this was a constructor call for a stack
3979 : argument, restore saved stack-pointer value. */
3980 :
3981 5999378 : if (old_stack_level)
3982 : {
3983 158 : rtx_insn *prev = get_last_insn ();
3984 :
3985 158 : emit_stack_restore (SAVE_BLOCK, old_stack_level);
3986 158 : stack_pointer_delta = old_stack_pointer_delta;
3987 :
3988 158 : fixup_args_size_notes (prev, get_last_insn (), stack_pointer_delta);
3989 :
3990 158 : pending_stack_adjust = old_pending_adj;
3991 158 : old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
3992 158 : stack_arg_under_construction = old_stack_arg_under_construction;
3993 158 : highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3994 158 : stack_usage_map = initial_stack_usage_map;
3995 158 : stack_usage_watermark = initial_stack_usage_watermark;
3996 158 : sibcall_failure = true;
3997 : }
3998 5999220 : else if (ACCUMULATE_OUTGOING_ARGS && pass)
3999 : {
4000 : #ifdef REG_PARM_STACK_SPACE
4001 73387 : if (save_area)
4002 0 : restore_fixed_argument_area (save_area, argblock,
4003 : high_to_save, low_to_save);
4004 : #endif
4005 :
4006 : /* If we saved any argument areas, restore them. */
4007 366614 : for (i = 0; i < num_actuals; i++)
4008 293227 : if (args[i].save_area)
4009 : {
4010 0 : machine_mode save_mode = GET_MODE (args[i].save_area);
4011 0 : rtx stack_area
4012 0 : = gen_rtx_MEM (save_mode,
4013 0 : memory_address (save_mode,
4014 : XEXP (args[i].stack_slot, 0)));
4015 :
4016 0 : if (save_mode != BLKmode)
4017 0 : emit_move_insn (stack_area, args[i].save_area);
4018 : else
4019 0 : emit_block_move (stack_area, args[i].save_area,
4020 : (gen_int_mode
4021 0 : (args[i].locate.size.constant, Pmode)),
4022 : BLOCK_OP_CALL_PARM);
4023 : }
4024 :
4025 73387 : highest_outgoing_arg_in_use = initial_highest_arg_in_use;
4026 73387 : stack_usage_map = initial_stack_usage_map;
4027 73387 : stack_usage_watermark = initial_stack_usage_watermark;
4028 : }
4029 :
4030 : /* If this was alloca, record the new stack level. */
4031 5999378 : if (flags & ECF_MAY_BE_ALLOCA)
4032 29 : record_new_stack_level ();
4033 :
4034 : /* Free up storage we no longer need. */
4035 18376262 : for (i = 0; i < num_actuals; ++i)
4036 12376884 : free (args[i].aligned_regs);
4037 :
4038 5999378 : targetm.calls.end_call_args (args_so_far);
4039 :
4040 5999378 : insns = end_sequence ();
4041 :
4042 5999378 : if (pass == 0)
4043 : {
4044 130867 : tail_call_insns = insns;
4045 :
4046 : /* Restore the pending stack adjustment now that we have
4047 : finished generating the sibling call sequence. */
4048 :
4049 130867 : restore_pending_stack_adjust (&save);
4050 :
4051 : /* Prepare arg structure for next iteration. */
4052 494543 : for (i = 0; i < num_actuals; i++)
4053 : {
4054 232809 : args[i].value = 0;
4055 232809 : args[i].aligned_regs = 0;
4056 232809 : args[i].stack = 0;
4057 : }
4058 :
4059 130867 : sbitmap_free (stored_args_map);
4060 130867 : internal_arg_pointer_exp_state.scan_start = NULL;
4061 130867 : internal_arg_pointer_exp_state.cache.release ();
4062 : }
4063 : else
4064 : {
4065 5868511 : normal_call_insns = insns;
4066 :
4067 : /* Verify that we've deallocated all the stack we used. */
4068 5868511 : gcc_assert ((flags & ECF_NORETURN)
4069 : || normal_failure
4070 : || known_eq (old_stack_allocated,
4071 : stack_pointer_delta
4072 : - pending_stack_adjust));
4073 5868505 : if (normal_failure)
4074 : normal_call_insns = NULL;
4075 : }
4076 :
4077 : /* If something prevents making this a sibling call,
4078 : zero out the sequence. */
4079 5999378 : if (sibcall_failure)
4080 48542 : tail_call_insns = NULL;
4081 : else
4082 : break;
4083 : }
4084 :
4085 : /* If tail call production succeeded, we need to remove REG_EQUIV notes on
4086 : arguments too, as argument area is now clobbered by the call. */
4087 5999374 : if (tail_call_insns)
4088 : {
4089 130863 : emit_insn (tail_call_insns);
4090 130863 : crtl->tail_call_emit = true;
4091 : }
4092 : else
4093 : {
4094 5868511 : emit_insn (normal_call_insns);
4095 5868511 : if (try_tail_call)
4096 : /* Ideally we'd emit a message for all of the ways that it could
4097 : have failed. */
4098 4 : maybe_complain_about_tail_call (exp, _("tail call production failed"));
4099 : }
4100 :
4101 5999374 : currently_expanding_call--;
4102 :
4103 5999374 : free (stack_usage_map_buf);
4104 5999374 : free (args);
4105 5999374 : return target;
4106 : }
4107 :
4108 : /* A sibling call sequence invalidates any REG_EQUIV notes made for
4109 : this function's incoming arguments.
4110 :
4111 : At the start of RTL generation we know the only REG_EQUIV notes
4112 : in the rtl chain are those for incoming arguments, so we can look
4113 : for REG_EQUIV notes between the start of the function and the
4114 : NOTE_INSN_FUNCTION_BEG.
4115 :
4116 : This is (slight) overkill. We could keep track of the highest
4117 : argument we clobber and be more selective in removing notes, but it
4118 : does not seem to be worth the effort. */
4119 :
4120 : void
4121 125441 : fixup_tail_calls (void)
4122 : {
4123 125441 : rtx_insn *insn;
4124 :
4125 577617 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4126 : {
4127 577617 : rtx note;
4128 :
4129 : /* There are never REG_EQUIV notes for the incoming arguments
4130 : after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
4131 577617 : if (NOTE_P (insn)
4132 376820 : && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
4133 : break;
4134 :
4135 452176 : note = find_reg_note (insn, REG_EQUIV, 0);
4136 452176 : if (note)
4137 19453 : remove_note (insn, note);
4138 452176 : note = find_reg_note (insn, REG_EQUIV, 0);
4139 452176 : gcc_assert (!note);
4140 : }
4141 125441 : }
4142 :
4143 : /* Traverse a list of TYPES and expand all complex types into their
4144 : components. */
4145 : static tree
4146 0 : split_complex_types (tree types)
4147 : {
4148 0 : tree p;
4149 :
4150 : /* Before allocating memory, check for the common case of no complex. */
4151 0 : for (p = types; p; p = TREE_CHAIN (p))
4152 : {
4153 0 : tree type = TREE_VALUE (p);
4154 0 : if (TREE_CODE (type) == COMPLEX_TYPE
4155 0 : && targetm.calls.split_complex_arg (type))
4156 0 : goto found;
4157 : }
4158 : return types;
4159 :
4160 0 : found:
4161 0 : types = copy_list (types);
4162 :
4163 0 : for (p = types; p; p = TREE_CHAIN (p))
4164 : {
4165 0 : tree complex_type = TREE_VALUE (p);
4166 :
4167 0 : if (TREE_CODE (complex_type) == COMPLEX_TYPE
4168 0 : && targetm.calls.split_complex_arg (complex_type))
4169 : {
4170 0 : tree next, imag;
4171 :
4172 : /* Rewrite complex type with component type. */
4173 0 : TREE_VALUE (p) = TREE_TYPE (complex_type);
4174 0 : next = TREE_CHAIN (p);
4175 :
4176 : /* Add another component type for the imaginary part. */
4177 0 : imag = build_tree_list (NULL_TREE, TREE_VALUE (p));
4178 0 : TREE_CHAIN (p) = imag;
4179 0 : TREE_CHAIN (imag) = next;
4180 :
4181 : /* Skip the newly created node. */
4182 0 : p = TREE_CHAIN (p);
4183 : }
4184 : }
4185 :
4186 : return types;
4187 : }
4188 :
4189 : /* Output a library call to function ORGFUN (a SYMBOL_REF rtx)
4190 : for a value of mode OUTMODE,
4191 : with NARGS different arguments, passed as ARGS.
4192 : Store the return value if RETVAL is nonzero: store it in VALUE if
4193 : VALUE is nonnull, otherwise pick a convenient location. In either
4194 : case return the location of the stored value.
4195 :
4196 : FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for
4197 : `const' calls, LCT_PURE for `pure' calls, or another LCT_ value for
4198 : other types of library calls. */
4199 :
4200 : rtx
4201 123967 : emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
4202 : enum libcall_type fn_type,
4203 : machine_mode outmode, int nargs, rtx_mode_t *args)
4204 : {
4205 : /* Total size in bytes of all the stack-parms scanned so far. */
4206 123967 : struct args_size args_size;
4207 : /* Size of arguments before any adjustments (such as rounding). */
4208 123967 : struct args_size original_args_size;
4209 123967 : int argnum;
4210 123967 : rtx fun;
4211 : /* Todo, choose the correct decl type of orgfun. Sadly this information
4212 : isn't present here, so we default to native calling abi here. */
4213 123967 : tree fndecl ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
4214 123967 : tree fntype ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
4215 123967 : int count;
4216 123967 : rtx argblock = 0;
4217 123967 : CUMULATIVE_ARGS args_so_far_v;
4218 123967 : cumulative_args_t args_so_far;
4219 123967 : struct arg
4220 : {
4221 : rtx value;
4222 : machine_mode mode;
4223 : rtx reg;
4224 : int partial;
4225 : struct locate_and_pad_arg_data locate;
4226 : rtx save_area;
4227 : };
4228 123967 : struct arg *argvec;
4229 123967 : int old_inhibit_defer_pop = inhibit_defer_pop;
4230 123967 : rtx call_fusage = 0;
4231 123967 : rtx mem_value = 0;
4232 123967 : rtx valreg;
4233 123967 : bool pcc_struct_value = false;
4234 123967 : poly_int64 struct_value_size = 0;
4235 123967 : int flags;
4236 123967 : int reg_parm_stack_space = 0;
4237 123967 : poly_int64 needed;
4238 123967 : rtx_insn *before_call;
4239 123967 : bool have_push_fusage;
4240 123967 : tree tfom; /* type_for_mode (outmode, 0) */
4241 :
4242 : #ifdef REG_PARM_STACK_SPACE
4243 : /* Define the boundary of the register parm stack space that needs to be
4244 : save, if any. */
4245 123967 : int low_to_save = 0, high_to_save = 0;
4246 123967 : rtx save_area = 0; /* Place that it is saved. */
4247 : #endif
4248 :
4249 : /* Size of the stack reserved for parameter registers. */
4250 123967 : unsigned int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
4251 123967 : char *initial_stack_usage_map = stack_usage_map;
4252 123967 : unsigned HOST_WIDE_INT initial_stack_usage_watermark = stack_usage_watermark;
4253 123967 : char *stack_usage_map_buf = NULL;
4254 :
4255 123967 : rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
4256 :
4257 : #ifdef REG_PARM_STACK_SPACE
4258 123967 : reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
4259 : #endif
4260 :
4261 : /* By default, library functions cannot throw. */
4262 123967 : flags = ECF_NOTHROW;
4263 :
4264 123967 : switch (fn_type)
4265 : {
4266 : case LCT_NORMAL:
4267 : break;
4268 : case LCT_CONST:
4269 : flags |= ECF_CONST;
4270 : break;
4271 : case LCT_PURE:
4272 : flags |= ECF_PURE;
4273 : break;
4274 : case LCT_NORETURN:
4275 : flags |= ECF_NORETURN;
4276 : break;
4277 : case LCT_THROW:
4278 : flags &= ~ECF_NOTHROW;
4279 : break;
4280 : case LCT_RETURNS_TWICE:
4281 : flags = ECF_RETURNS_TWICE;
4282 : break;
4283 : }
4284 123967 : fun = orgfun;
4285 :
4286 : /* Ensure current function's preferred stack boundary is at least
4287 : what we need. */
4288 123967 : if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
4289 12685 : crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
4290 :
4291 : /* If this kind of value comes back in memory,
4292 : decide where in memory it should come back. */
4293 123967 : if (outmode != VOIDmode)
4294 : {
4295 121784 : tfom = lang_hooks.types.type_for_mode (outmode, 0);
4296 121784 : if (aggregate_value_p (tfom, 0))
4297 : {
4298 : #ifdef PCC_STATIC_STRUCT_RETURN
4299 : rtx pointer_reg
4300 : = hard_function_value (build_pointer_type (tfom), 0, 0, 0);
4301 : mem_value = gen_rtx_MEM (outmode, pointer_reg);
4302 : pcc_struct_value = true;
4303 : if (value == 0)
4304 : value = gen_reg_rtx (outmode);
4305 : #else /* not PCC_STATIC_STRUCT_RETURN */
4306 20182 : struct_value_size = GET_MODE_SIZE (outmode);
4307 10091 : if (value != 0 && MEM_P (value))
4308 : mem_value = value;
4309 : else
4310 10091 : mem_value = assign_temp (tfom, 1, 1);
4311 : #endif
4312 : /* This call returns a big structure. */
4313 10091 : flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
4314 : }
4315 : }
4316 : else
4317 2183 : tfom = void_type_node;
4318 :
4319 : /* ??? Unfinished: must pass the memory address as an argument. */
4320 :
4321 : /* Copy all the libcall-arguments out of the varargs data
4322 : and into a vector ARGVEC.
4323 :
4324 : Compute how to pass each argument. We only support a very small subset
4325 : of the full argument passing conventions to limit complexity here since
4326 : library functions shouldn't have many args. */
4327 :
4328 123967 : argvec = XALLOCAVEC (struct arg, nargs + 1);
4329 123967 : memset (argvec, 0, (nargs + 1) * sizeof (struct arg));
4330 :
4331 : #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
4332 : INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v, outmode, fun);
4333 : #else
4334 123967 : INIT_CUMULATIVE_ARGS (args_so_far_v, NULL_TREE, fun, 0, nargs);
4335 : #endif
4336 123967 : args_so_far = pack_cumulative_args (&args_so_far_v);
4337 :
4338 123967 : args_size.constant = 0;
4339 123967 : args_size.var = 0;
4340 :
4341 123967 : count = 0;
4342 :
4343 123967 : push_temp_slots ();
4344 :
4345 : /* If there's a structure value address to be passed,
4346 : either pass it in the special place, or pass it as an extra argument. */
4347 123967 : if (mem_value && struct_value == 0 && ! pcc_struct_value)
4348 : {
4349 10091 : rtx addr = XEXP (mem_value, 0);
4350 :
4351 10091 : nargs++;
4352 :
4353 : /* Make sure it is a reasonable operand for a move or push insn. */
4354 10091 : if (!REG_P (addr) && !MEM_P (addr)
4355 20182 : && !(CONSTANT_P (addr)
4356 0 : && targetm.legitimate_constant_p (Pmode, addr)))
4357 10091 : addr = force_operand (addr, NULL_RTX);
4358 :
4359 10091 : argvec[count].value = addr;
4360 10091 : argvec[count].mode = Pmode;
4361 10091 : argvec[count].partial = 0;
4362 :
4363 10091 : function_arg_info ptr_arg (Pmode, /*named=*/true);
4364 10091 : argvec[count].reg = targetm.calls.function_arg (args_so_far, ptr_arg);
4365 10091 : gcc_assert (targetm.calls.arg_partial_bytes (args_so_far, ptr_arg) == 0);
4366 :
4367 10091 : locate_and_pad_parm (Pmode, NULL_TREE,
4368 : #ifdef STACK_PARMS_IN_REG_PARM_AREA
4369 : 1,
4370 : #else
4371 10091 : argvec[count].reg != 0,
4372 : #endif
4373 : reg_parm_stack_space, 0,
4374 : NULL_TREE, &args_size, &argvec[count].locate);
4375 :
4376 10091 : if (argvec[count].reg == 0 || argvec[count].partial != 0
4377 0 : || reg_parm_stack_space > 0)
4378 10091 : args_size.constant += argvec[count].locate.size.constant;
4379 :
4380 10091 : targetm.calls.function_arg_advance (args_so_far, ptr_arg);
4381 :
4382 10091 : count++;
4383 : }
4384 :
4385 336481 : for (unsigned int i = 0; count < nargs; i++, count++)
4386 : {
4387 212514 : rtx val = args[i].first;
4388 212514 : function_arg_info arg (args[i].second, /*named=*/true);
4389 212514 : int unsigned_p = 0;
4390 :
4391 : /* We cannot convert the arg value to the mode the library wants here;
4392 : must do it earlier where we know the signedness of the arg. */
4393 212514 : gcc_assert (arg.mode != BLKmode
4394 : && (GET_MODE (val) == arg.mode
4395 : || GET_MODE (val) == VOIDmode));
4396 :
4397 : /* Make sure it is a reasonable operand for a move or push insn. */
4398 45747 : if (!REG_P (val) && !MEM_P (val)
4399 289564 : && !(CONSTANT_P (val)
4400 37952 : && targetm.legitimate_constant_p (arg.mode, val)))
4401 1150 : val = force_operand (val, NULL_RTX);
4402 :
4403 212514 : if (pass_by_reference (&args_so_far_v, arg))
4404 : {
4405 0 : rtx slot;
4406 0 : int must_copy = !reference_callee_copied (&args_so_far_v, arg);
4407 :
4408 : /* If this was a CONST function, it is now PURE since it now
4409 : reads memory. */
4410 0 : if (flags & ECF_CONST)
4411 : {
4412 0 : flags &= ~ECF_CONST;
4413 0 : flags |= ECF_PURE;
4414 : }
4415 :
4416 0 : if (MEM_P (val) && !must_copy)
4417 : {
4418 0 : tree val_expr = MEM_EXPR (val);
4419 0 : if (val_expr)
4420 0 : mark_addressable (val_expr);
4421 : slot = val;
4422 : }
4423 : else
4424 : {
4425 0 : slot = assign_temp (lang_hooks.types.type_for_mode (arg.mode, 0),
4426 : 1, 1);
4427 0 : emit_move_insn (slot, val);
4428 : }
4429 :
4430 0 : call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
4431 : gen_rtx_USE (VOIDmode, slot),
4432 : call_fusage);
4433 0 : if (must_copy)
4434 0 : call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
4435 : gen_rtx_CLOBBER (VOIDmode,
4436 : slot),
4437 : call_fusage);
4438 :
4439 0 : arg.mode = Pmode;
4440 0 : arg.pass_by_reference = true;
4441 0 : val = force_operand (XEXP (slot, 0), NULL_RTX);
4442 : }
4443 :
4444 212514 : arg.mode = promote_function_mode (NULL_TREE, arg.mode, &unsigned_p,
4445 : NULL_TREE, 0);
4446 212514 : argvec[count].mode = arg.mode;
4447 212514 : argvec[count].value = convert_modes (arg.mode, GET_MODE (val), val,
4448 : unsigned_p);
4449 212514 : argvec[count].reg = targetm.calls.function_arg (args_so_far, arg);
4450 :
4451 212514 : argvec[count].partial
4452 212514 : = targetm.calls.arg_partial_bytes (args_so_far, arg);
4453 :
4454 212514 : if (argvec[count].reg == 0
4455 184574 : || argvec[count].partial != 0
4456 184574 : || reg_parm_stack_space > 0)
4457 : {
4458 27940 : locate_and_pad_parm (arg.mode, NULL_TREE,
4459 : #ifdef STACK_PARMS_IN_REG_PARM_AREA
4460 : 1,
4461 : #else
4462 : argvec[count].reg != 0,
4463 : #endif
4464 : reg_parm_stack_space, argvec[count].partial,
4465 : NULL_TREE, &args_size, &argvec[count].locate);
4466 27940 : args_size.constant += argvec[count].locate.size.constant;
4467 27940 : gcc_assert (!argvec[count].locate.size.var);
4468 : }
4469 : #ifdef BLOCK_REG_PADDING
4470 : else
4471 : /* The argument is passed entirely in registers. See at which
4472 : end it should be padded. */
4473 : argvec[count].locate.where_pad =
4474 : BLOCK_REG_PADDING (arg.mode, NULL_TREE,
4475 : known_le (GET_MODE_SIZE (arg.mode),
4476 : UNITS_PER_WORD));
4477 : #endif
4478 :
4479 212514 : targetm.calls.function_arg_advance (args_so_far, arg);
4480 : }
4481 :
4482 346572 : for (int i = 0; i < nargs; i++)
4483 222605 : if (reg_parm_stack_space > 0
4484 222605 : || argvec[i].reg == 0
4485 184574 : || argvec[i].partial != 0)
4486 38031 : update_stack_alignment_for_call (&argvec[i].locate);
4487 :
4488 : /* If this machine requires an external definition for library
4489 : functions, write one out. */
4490 123967 : assemble_external_libcall (fun);
4491 :
4492 123967 : original_args_size = args_size;
4493 123967 : args_size.constant = (aligned_upper_bound (args_size.constant
4494 123967 : + stack_pointer_delta,
4495 : STACK_BYTES)
4496 123967 : - stack_pointer_delta);
4497 :
4498 123967 : args_size.constant = upper_bound (args_size.constant,
4499 : reg_parm_stack_space);
4500 :
4501 123967 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
4502 123967 : args_size.constant -= reg_parm_stack_space;
4503 :
4504 123967 : crtl->outgoing_args_size = upper_bound (crtl->outgoing_args_size,
4505 : args_size.constant);
4506 :
4507 123967 : if (flag_stack_usage_info && !ACCUMULATE_OUTGOING_ARGS)
4508 : {
4509 0 : poly_int64 pushed = args_size.constant + pending_stack_adjust;
4510 0 : current_function_pushed_stack_size
4511 0 : = upper_bound (current_function_pushed_stack_size, pushed);
4512 : }
4513 :
4514 123967 : if (ACCUMULATE_OUTGOING_ARGS)
4515 : {
4516 : /* Since the stack pointer will never be pushed, it is possible for
4517 : the evaluation of a parm to clobber something we have already
4518 : written to the stack. Since most function calls on RISC machines
4519 : do not use the stack, this is uncommon, but must work correctly.
4520 :
4521 : Therefore, we save any area of the stack that was already written
4522 : and that we are using. Here we set up to do this by making a new
4523 : stack usage map from the old one.
4524 :
4525 : Another approach might be to try to reorder the argument
4526 : evaluations to avoid this conflicting stack usage. */
4527 :
4528 12 : needed = args_size.constant;
4529 :
4530 : /* Since we will be writing into the entire argument area, the
4531 : map must be allocated for its entire size, not just the part that
4532 : is the responsibility of the caller. */
4533 12 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
4534 12 : needed += reg_parm_stack_space;
4535 :
4536 12 : poly_int64 limit = needed;
4537 12 : if (ARGS_GROW_DOWNWARD)
4538 : limit += 1;
4539 :
4540 : /* For polynomial sizes, this is the maximum possible size needed
4541 : for arguments with a constant size and offset. */
4542 12 : HOST_WIDE_INT const_limit = constant_lower_bound (limit);
4543 12 : highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
4544 : const_limit);
4545 :
4546 12 : stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
4547 12 : stack_usage_map = stack_usage_map_buf;
4548 :
4549 12 : if (initial_highest_arg_in_use)
4550 0 : memcpy (stack_usage_map, initial_stack_usage_map,
4551 : initial_highest_arg_in_use);
4552 :
4553 12 : if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
4554 0 : memset (&stack_usage_map[initial_highest_arg_in_use], 0,
4555 0 : highest_outgoing_arg_in_use - initial_highest_arg_in_use);
4556 12 : needed = 0;
4557 :
4558 : /* We must be careful to use virtual regs before they're instantiated,
4559 : and real regs afterwards. Loop optimization, for example, can create
4560 : new libcalls after we've instantiated the virtual regs, and if we
4561 : use virtuals anyway, they won't match the rtl patterns. */
4562 :
4563 12 : if (virtuals_instantiated)
4564 0 : argblock = plus_constant (Pmode, stack_pointer_rtx,
4565 : STACK_POINTER_OFFSET);
4566 : else
4567 12 : argblock = virtual_outgoing_args_rtx;
4568 : }
4569 : else
4570 : {
4571 123955 : if (!targetm.calls.push_argument (0))
4572 0 : argblock = push_block (gen_int_mode (args_size.constant, Pmode), 0, 0);
4573 : }
4574 :
4575 : /* We push args individually in reverse order, perform stack alignment
4576 : before the first push (the last arg). */
4577 12 : if (argblock == 0)
4578 123955 : anti_adjust_stack (gen_int_mode (args_size.constant
4579 : - original_args_size.constant,
4580 123955 : Pmode));
4581 :
4582 123967 : argnum = nargs - 1;
4583 :
4584 : #ifdef REG_PARM_STACK_SPACE
4585 123967 : if (ACCUMULATE_OUTGOING_ARGS)
4586 : {
4587 : /* The argument list is the property of the called routine and it
4588 : may clobber it. If the fixed area has been used for previous
4589 : parameters, we must save and restore it. */
4590 12 : save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
4591 : &low_to_save, &high_to_save);
4592 : }
4593 : #endif
4594 :
4595 123967 : rtx call_cookie
4596 123967 : = targetm.calls.function_arg (args_so_far,
4597 123967 : function_arg_info::end_marker ());
4598 :
4599 : /* Push the args that need to be pushed. */
4600 :
4601 123967 : have_push_fusage = false;
4602 :
4603 : /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4604 : are to be pushed. */
4605 346572 : for (count = 0; count < nargs; count++, argnum--)
4606 : {
4607 222605 : machine_mode mode = argvec[argnum].mode;
4608 222605 : rtx val = argvec[argnum].value;
4609 222605 : rtx reg = argvec[argnum].reg;
4610 222605 : int partial = argvec[argnum].partial;
4611 222605 : unsigned int parm_align = argvec[argnum].locate.boundary;
4612 222605 : poly_int64 lower_bound = 0, upper_bound = 0;
4613 :
4614 222605 : if (! (reg != 0 && partial == 0))
4615 : {
4616 38031 : rtx use;
4617 :
4618 38031 : if (ACCUMULATE_OUTGOING_ARGS)
4619 : {
4620 : /* If this is being stored into a pre-allocated, fixed-size,
4621 : stack area, save any previous data at that location. */
4622 :
4623 0 : if (ARGS_GROW_DOWNWARD)
4624 : {
4625 : /* stack_slot is negative, but we want to index stack_usage_map
4626 : with positive values. */
4627 : upper_bound = -argvec[argnum].locate.slot_offset.constant + 1;
4628 : lower_bound = upper_bound - argvec[argnum].locate.size.constant;
4629 : }
4630 : else
4631 : {
4632 0 : lower_bound = argvec[argnum].locate.slot_offset.constant;
4633 0 : upper_bound = lower_bound + argvec[argnum].locate.size.constant;
4634 : }
4635 :
4636 0 : if (stack_region_maybe_used_p (lower_bound, upper_bound,
4637 : reg_parm_stack_space))
4638 : {
4639 : /* We need to make a save area. */
4640 0 : poly_uint64 size
4641 0 : = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
4642 0 : machine_mode save_mode
4643 0 : = int_mode_for_size (size, 1).else_blk ();
4644 0 : rtx adr
4645 0 : = plus_constant (Pmode, argblock,
4646 : argvec[argnum].locate.offset.constant);
4647 0 : rtx stack_area
4648 0 : = gen_rtx_MEM (save_mode, memory_address (save_mode, adr));
4649 :
4650 0 : if (save_mode == BLKmode)
4651 : {
4652 0 : argvec[argnum].save_area
4653 0 : = assign_stack_temp (BLKmode,
4654 : argvec[argnum].locate.size.constant
4655 : );
4656 :
4657 0 : emit_block_move (validize_mem
4658 : (copy_rtx (argvec[argnum].save_area)),
4659 : stack_area,
4660 : (gen_int_mode
4661 : (argvec[argnum].locate.size.constant,
4662 0 : Pmode)),
4663 : BLOCK_OP_CALL_PARM);
4664 : }
4665 : else
4666 : {
4667 0 : argvec[argnum].save_area = gen_reg_rtx (save_mode);
4668 :
4669 0 : emit_move_insn (argvec[argnum].save_area, stack_area);
4670 : }
4671 : }
4672 : }
4673 :
4674 38031 : emit_push_insn (val, mode, lang_hooks.types.type_for_mode (mode, 0),
4675 : NULL_RTX, parm_align, partial, reg, 0, argblock,
4676 : (gen_int_mode
4677 38031 : (argvec[argnum].locate.offset.constant, Pmode)),
4678 : reg_parm_stack_space,
4679 74170 : ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad), false);
4680 :
4681 : /* Now mark the segment we just used. */
4682 38031 : if (ACCUMULATE_OUTGOING_ARGS)
4683 0 : mark_stack_region_used (lower_bound, upper_bound);
4684 :
4685 38031 : NO_DEFER_POP;
4686 :
4687 : /* Indicate argument access so that alias.cc knows that these
4688 : values are live. */
4689 38031 : if (argblock)
4690 0 : use = plus_constant (Pmode, argblock,
4691 : argvec[argnum].locate.offset.constant);
4692 38031 : else if (have_push_fusage)
4693 23073 : continue;
4694 : else
4695 : {
4696 : /* When arguments are pushed, trying to tell alias.cc where
4697 : exactly this argument is won't work, because the
4698 : auto-increment causes confusion. So we merely indicate
4699 : that we access something with a known mode somewhere on
4700 : the stack. */
4701 41440 : use = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
4702 : gen_rtx_SCRATCH (Pmode));
4703 14958 : have_push_fusage = true;
4704 : }
4705 14958 : use = gen_rtx_MEM (argvec[argnum].mode, use);
4706 14958 : use = gen_rtx_USE (VOIDmode, use);
4707 14958 : call_fusage = gen_rtx_EXPR_LIST (VOIDmode, use, call_fusage);
4708 : }
4709 : }
4710 :
4711 123967 : argnum = nargs - 1;
4712 :
4713 123967 : fun = prepare_call_address (NULL, fun, NULL, &call_fusage, 0, 0);
4714 :
4715 123967 : targetm.calls.start_call_args (args_so_far);
4716 :
4717 : /* When expanding a normal call, args are stored in push order,
4718 : which is the reverse of what we have here. */
4719 123967 : bool any_regs = false;
4720 470539 : for (int i = nargs; i-- > 0; )
4721 222605 : if (argvec[i].reg != NULL_RTX)
4722 : {
4723 184574 : targetm.calls.call_args (args_so_far, argvec[i].reg, NULL_TREE);
4724 184574 : any_regs = true;
4725 : }
4726 123967 : if (!any_regs)
4727 14777 : targetm.calls.call_args (args_so_far, pc_rtx, NULL_TREE);
4728 :
4729 : /* Now load any reg parms into their regs. */
4730 :
4731 : /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4732 : are to be pushed. */
4733 346572 : for (count = 0; count < nargs; count++, argnum--)
4734 : {
4735 222605 : machine_mode mode = argvec[argnum].mode;
4736 222605 : rtx val = argvec[argnum].value;
4737 222605 : rtx reg = argvec[argnum].reg;
4738 222605 : int partial = argvec[argnum].partial;
4739 :
4740 : /* Handle calls that pass values in multiple non-contiguous
4741 : locations. The PA64 has examples of this for library calls. */
4742 222605 : if (reg != 0 && GET_CODE (reg) == PARALLEL)
4743 13450 : emit_group_load (reg, val, NULL_TREE, GET_MODE_SIZE (mode));
4744 215880 : else if (reg != 0 && partial == 0)
4745 : {
4746 177849 : emit_move_insn (reg, val);
4747 : #ifdef BLOCK_REG_PADDING
4748 : poly_int64 size = GET_MODE_SIZE (argvec[argnum].mode);
4749 :
4750 : /* Copied from load_register_parameters. */
4751 :
4752 : /* Handle case where we have a value that needs shifting
4753 : up to the msb. eg. a QImode value and we're padding
4754 : upward on a BYTES_BIG_ENDIAN machine. */
4755 : if (known_lt (size, UNITS_PER_WORD)
4756 : && (argvec[argnum].locate.where_pad
4757 : == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)))
4758 : {
4759 : rtx x;
4760 : poly_int64 shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
4761 :
4762 : /* Assigning REG here rather than a temp makes CALL_FUSAGE
4763 : report the whole reg as used. Strictly speaking, the
4764 : call only uses SIZE bytes at the msb end, but it doesn't
4765 : seem worth generating rtl to say that. */
4766 : reg = gen_rtx_REG (word_mode, REGNO (reg));
4767 : x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1);
4768 : if (x != reg)
4769 : emit_move_insn (reg, x);
4770 : }
4771 : #endif
4772 : }
4773 :
4774 222605 : NO_DEFER_POP;
4775 : }
4776 :
4777 : /* Any regs containing parms remain in use through the call. */
4778 346572 : for (count = 0; count < nargs; count++)
4779 : {
4780 222605 : rtx reg = argvec[count].reg;
4781 222605 : if (reg != 0 && GET_CODE (reg) == PARALLEL)
4782 6725 : use_group_regs (&call_fusage, reg);
4783 177849 : else if (reg != 0)
4784 : {
4785 177849 : int partial = argvec[count].partial;
4786 177849 : if (partial)
4787 : {
4788 0 : int nregs;
4789 0 : gcc_assert (partial % UNITS_PER_WORD == 0);
4790 0 : nregs = partial / UNITS_PER_WORD;
4791 0 : use_regs (&call_fusage, REGNO (reg), nregs);
4792 : }
4793 : else
4794 177849 : use_reg (&call_fusage, reg);
4795 : }
4796 : }
4797 :
4798 : /* Pass the function the address in which to return a structure value. */
4799 123967 : if (mem_value != 0 && struct_value != 0 && ! pcc_struct_value)
4800 : {
4801 0 : emit_move_insn (struct_value,
4802 0 : force_reg (Pmode,
4803 : force_operand (XEXP (mem_value, 0),
4804 : NULL_RTX)));
4805 0 : if (REG_P (struct_value))
4806 0 : use_reg (&call_fusage, struct_value);
4807 : }
4808 :
4809 : /* Don't allow popping to be deferred, since then
4810 : cse'ing of library calls could delete a call and leave the pop. */
4811 123967 : NO_DEFER_POP;
4812 225569 : valreg = (mem_value == 0 && outmode != VOIDmode
4813 235660 : ? hard_libcall_value (outmode, orgfun) : NULL_RTX);
4814 :
4815 : /* Stack must be properly aligned now. */
4816 247934 : gcc_assert (multiple_p (stack_pointer_delta,
4817 : PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT));
4818 :
4819 123967 : before_call = get_last_insn ();
4820 :
4821 123967 : if (flag_callgraph_info)
4822 0 : record_final_call (SYMBOL_REF_DECL (orgfun), UNKNOWN_LOCATION);
4823 :
4824 : /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4825 : will set inhibit_defer_pop to that value. */
4826 : /* The return type is needed to decide how many bytes the function pops.
4827 : Signedness plays no role in that, so for simplicity, we pretend it's
4828 : always signed. We also assume that the list of arguments passed has
4829 : no impact, so we pretend it is unknown. */
4830 :
4831 123967 : emit_call_1 (fun, NULL,
4832 : get_identifier (XSTR (orgfun, 0)),
4833 : build_function_type (tfom, NULL_TREE),
4834 : original_args_size.constant, args_size.constant,
4835 : struct_value_size, call_cookie, valreg,
4836 : old_inhibit_defer_pop + 1, call_fusage, flags, args_so_far);
4837 :
4838 123967 : rtx datum = orgfun;
4839 123967 : gcc_assert (GET_CODE (datum) == SYMBOL_REF);
4840 123967 : rtx_call_insn *last = last_call_insn ();
4841 123967 : add_reg_note (last, REG_CALL_DECL, datum);
4842 :
4843 : /* Right-shift returned value if necessary. */
4844 123967 : if (!pcc_struct_value
4845 123967 : && TYPE_MODE (tfom) != BLKmode
4846 123967 : && targetm.calls.return_in_msb (tfom))
4847 : {
4848 0 : shift_return_value (TYPE_MODE (tfom), false, valreg);
4849 0 : valreg = gen_rtx_REG (TYPE_MODE (tfom), REGNO (valreg));
4850 : }
4851 :
4852 123967 : targetm.calls.end_call_args (args_so_far);
4853 :
4854 : /* For calls to `setjmp', etc., inform function.cc:setjmp_warnings
4855 : that it should complain if nonvolatile values are live. For
4856 : functions that cannot return, inform flow that control does not
4857 : fall through. */
4858 123967 : if (flags & ECF_NORETURN)
4859 : {
4860 : /* The barrier note must be emitted
4861 : immediately after the CALL_INSN. Some ports emit more than
4862 : just a CALL_INSN above, so we must search for it here. */
4863 0 : rtx_insn *last = get_last_insn ();
4864 0 : while (!CALL_P (last))
4865 : {
4866 0 : last = PREV_INSN (last);
4867 : /* There was no CALL_INSN? */
4868 0 : gcc_assert (last != before_call);
4869 : }
4870 :
4871 0 : emit_barrier_after (last);
4872 : }
4873 :
4874 : /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW
4875 : and LCT_RETURNS_TWICE, cannot perform non-local gotos. */
4876 123967 : if (flags & ECF_NOTHROW)
4877 : {
4878 123967 : rtx_insn *last = get_last_insn ();
4879 138926 : while (!CALL_P (last))
4880 : {
4881 14959 : last = PREV_INSN (last);
4882 : /* There was no CALL_INSN? */
4883 14959 : gcc_assert (last != before_call);
4884 : }
4885 :
4886 123967 : make_reg_eh_region_note_nothrow_nononlocal (last);
4887 : }
4888 :
4889 : /* Now restore inhibit_defer_pop to its actual original value. */
4890 123967 : OK_DEFER_POP;
4891 :
4892 123967 : pop_temp_slots ();
4893 :
4894 : /* Copy the value to the right place. */
4895 123967 : if (outmode != VOIDmode && retval)
4896 : {
4897 121498 : if (mem_value)
4898 : {
4899 10091 : if (value == 0)
4900 10091 : value = mem_value;
4901 10091 : if (value != mem_value)
4902 0 : emit_move_insn (value, mem_value);
4903 : }
4904 111407 : else if (GET_CODE (valreg) == PARALLEL)
4905 : {
4906 0 : if (value == 0)
4907 0 : value = gen_reg_rtx (outmode);
4908 0 : emit_group_store (value, valreg, NULL_TREE, GET_MODE_SIZE (outmode));
4909 : }
4910 : else
4911 : {
4912 : /* Convert to the proper mode if a promotion has been active. */
4913 111407 : if (GET_MODE (valreg) != outmode)
4914 : {
4915 0 : int unsignedp = TYPE_UNSIGNED (tfom);
4916 :
4917 0 : gcc_assert (promote_function_mode (tfom, outmode, &unsignedp,
4918 : fndecl ? TREE_TYPE (fndecl) : fntype, 1)
4919 : == GET_MODE (valreg));
4920 0 : valreg = convert_modes (outmode, GET_MODE (valreg), valreg, 0);
4921 : }
4922 :
4923 111407 : if (value != 0)
4924 450 : emit_move_insn (value, valreg);
4925 : else
4926 : value = valreg;
4927 : }
4928 : }
4929 :
4930 123967 : if (ACCUMULATE_OUTGOING_ARGS)
4931 : {
4932 : #ifdef REG_PARM_STACK_SPACE
4933 12 : if (save_area)
4934 0 : restore_fixed_argument_area (save_area, argblock,
4935 : high_to_save, low_to_save);
4936 : #endif
4937 :
4938 : /* If we saved any argument areas, restore them. */
4939 24 : for (count = 0; count < nargs; count++)
4940 12 : if (argvec[count].save_area)
4941 : {
4942 0 : machine_mode save_mode = GET_MODE (argvec[count].save_area);
4943 0 : rtx adr = plus_constant (Pmode, argblock,
4944 : argvec[count].locate.offset.constant);
4945 0 : rtx stack_area = gen_rtx_MEM (save_mode,
4946 : memory_address (save_mode, adr));
4947 :
4948 0 : if (save_mode == BLKmode)
4949 0 : emit_block_move (stack_area,
4950 : validize_mem
4951 : (copy_rtx (argvec[count].save_area)),
4952 : (gen_int_mode
4953 0 : (argvec[count].locate.size.constant, Pmode)),
4954 : BLOCK_OP_CALL_PARM);
4955 : else
4956 0 : emit_move_insn (stack_area, argvec[count].save_area);
4957 : }
4958 :
4959 12 : highest_outgoing_arg_in_use = initial_highest_arg_in_use;
4960 12 : stack_usage_map = initial_stack_usage_map;
4961 12 : stack_usage_watermark = initial_stack_usage_watermark;
4962 : }
4963 :
4964 123967 : free (stack_usage_map_buf);
4965 :
4966 123967 : return value;
4967 :
4968 : }
4969 :
4970 :
4971 : /* Store a single argument for a function call
4972 : into the register or memory area where it must be passed.
4973 : *ARG describes the argument value and where to pass it.
4974 :
4975 : ARGBLOCK is the address of the stack-block for all the arguments,
4976 : or 0 on a machine where arguments are pushed individually.
4977 :
4978 : MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4979 : so must be careful about how the stack is used.
4980 :
4981 : VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4982 : argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4983 : that we need not worry about saving and restoring the stack.
4984 :
4985 : FNDECL is the declaration of the function we are calling.
4986 :
4987 : Return true if this arg should cause sibcall failure,
4988 : false otherwise. */
4989 :
4990 : static bool
4991 2153704 : store_one_arg (struct arg_data *arg, rtx argblock, int flags,
4992 : int variable_size ATTRIBUTE_UNUSED, int reg_parm_stack_space)
4993 : {
4994 2153704 : tree pval = arg->tree_value;
4995 2153704 : rtx reg = 0;
4996 2153704 : int partial = 0;
4997 2153704 : poly_int64 used = 0;
4998 2153704 : poly_int64 lower_bound = 0, upper_bound = 0;
4999 2153704 : bool sibcall_failure = false;
5000 :
5001 2153704 : if (TREE_CODE (pval) == ERROR_MARK)
5002 : return true;
5003 :
5004 : /* Push a new temporary level for any temporaries we make for
5005 : this argument. */
5006 2153704 : push_temp_slots ();
5007 :
5008 2153704 : if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL))
5009 : {
5010 : /* If this is being stored into a pre-allocated, fixed-size, stack area,
5011 : save any previous data at that location. */
5012 53914 : if (argblock && ! variable_size && arg->stack)
5013 : {
5014 53835 : if (ARGS_GROW_DOWNWARD)
5015 : {
5016 : /* stack_slot is negative, but we want to index stack_usage_map
5017 : with positive values. */
5018 : if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
5019 : {
5020 : rtx offset = XEXP (XEXP (arg->stack_slot, 0), 1);
5021 : upper_bound = -rtx_to_poly_int64 (offset) + 1;
5022 : }
5023 : else
5024 : upper_bound = 0;
5025 :
5026 : lower_bound = upper_bound - arg->locate.size.constant;
5027 : }
5028 : else
5029 : {
5030 53835 : if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
5031 : {
5032 42147 : rtx offset = XEXP (XEXP (arg->stack_slot, 0), 1);
5033 42147 : lower_bound = rtx_to_poly_int64 (offset);
5034 : }
5035 : else
5036 : lower_bound = 0;
5037 :
5038 53835 : upper_bound = lower_bound + arg->locate.size.constant;
5039 : }
5040 :
5041 107670 : if (stack_region_maybe_used_p (lower_bound, upper_bound,
5042 : reg_parm_stack_space))
5043 : {
5044 : /* We need to make a save area. */
5045 0 : poly_uint64 size = arg->locate.size.constant * BITS_PER_UNIT;
5046 0 : machine_mode save_mode
5047 0 : = int_mode_for_size (size, 1).else_blk ();
5048 0 : rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0));
5049 0 : rtx stack_area = gen_rtx_MEM (save_mode, adr);
5050 :
5051 0 : if (save_mode == BLKmode)
5052 : {
5053 0 : arg->save_area
5054 0 : = assign_temp (TREE_TYPE (arg->tree_value), 1, 1);
5055 0 : preserve_temp_slots (arg->save_area);
5056 0 : emit_block_move (validize_mem (copy_rtx (arg->save_area)),
5057 : stack_area,
5058 : (gen_int_mode
5059 0 : (arg->locate.size.constant, Pmode)),
5060 : BLOCK_OP_CALL_PARM);
5061 : }
5062 : else
5063 : {
5064 0 : arg->save_area = gen_reg_rtx (save_mode);
5065 0 : emit_move_insn (arg->save_area, stack_area);
5066 : }
5067 : }
5068 : }
5069 : }
5070 :
5071 : /* If this isn't going to be placed on both the stack and in registers,
5072 : set up the register and number of words. */
5073 2153704 : if (! arg->pass_on_stack)
5074 : {
5075 2153704 : if (flags & ECF_SIBCALL)
5076 10400 : reg = arg->tail_call_reg;
5077 : else
5078 2143304 : reg = arg->reg;
5079 2153704 : partial = arg->partial;
5080 : }
5081 :
5082 : /* Being passed entirely in a register. We shouldn't be called in
5083 : this case. */
5084 2153704 : gcc_assert (reg == 0 || partial != 0);
5085 :
5086 : /* If this arg needs special alignment, don't load the registers
5087 : here. */
5088 2153704 : if (arg->n_aligned_regs != 0)
5089 0 : reg = 0;
5090 :
5091 : /* If this is being passed partially in a register, we can't evaluate
5092 : it directly into its stack slot. Otherwise, we can. */
5093 2153704 : if (arg->value == 0)
5094 : {
5095 : /* stack_arg_under_construction is nonzero if a function argument is
5096 : being evaluated directly into the outgoing argument list and
5097 : expand_call must take special action to preserve the argument list
5098 : if it is called recursively.
5099 :
5100 : For scalar function arguments stack_usage_map is sufficient to
5101 : determine which stack slots must be saved and restored. Scalar
5102 : arguments in general have pass_on_stack == false.
5103 :
5104 : If this argument is initialized by a function which takes the
5105 : address of the argument (a C++ constructor or a C function
5106 : returning a BLKmode structure), then stack_usage_map is
5107 : insufficient and expand_call must push the stack around the
5108 : function call. Such arguments have pass_on_stack == true.
5109 :
5110 : Note that it is always safe to set stack_arg_under_construction,
5111 : but this generates suboptimal code if set when not needed. */
5112 :
5113 2153704 : if (arg->pass_on_stack)
5114 0 : stack_arg_under_construction++;
5115 :
5116 4271334 : arg->value = expand_expr (pval,
5117 : (partial
5118 2153704 : || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
5119 : ? NULL_RTX : arg->stack,
5120 : VOIDmode, EXPAND_STACK_PARM);
5121 :
5122 : /* If we are promoting object (or for any other reason) the mode
5123 : doesn't agree, convert the mode. */
5124 :
5125 2153704 : if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
5126 36074 : arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
5127 : arg->value, arg->unsignedp);
5128 :
5129 2153704 : if (arg->pass_on_stack)
5130 0 : stack_arg_under_construction--;
5131 : }
5132 :
5133 : /* Check for overlap with already clobbered argument area. */
5134 2153704 : if ((flags & ECF_SIBCALL)
5135 10400 : && MEM_P (arg->value)
5136 2164104 : && mem_might_overlap_already_clobbered_arg_p (XEXP (arg->value, 0),
5137 439 : arg->locate.size.constant))
5138 4 : sibcall_failure = true;
5139 :
5140 : /* Don't allow anything left on stack from computation
5141 : of argument to alloca. */
5142 2153704 : if (flags & ECF_MAY_BE_ALLOCA)
5143 0 : do_pending_stack_adjust ();
5144 :
5145 2153704 : if (arg->value == arg->stack)
5146 : /* If the value is already in the stack slot, we are done. */
5147 : ;
5148 2145080 : else if (arg->mode != BLKmode)
5149 : {
5150 1873893 : unsigned int parm_align;
5151 :
5152 : /* Argument is a scalar, not entirely passed in registers.
5153 : (If part is passed in registers, arg->partial says how much
5154 : and emit_push_insn will take care of putting it there.)
5155 :
5156 : Push it, and if its size is less than the
5157 : amount of space allocated to it,
5158 : also bump stack pointer by the additional space.
5159 : Note that in C the default argument promotions
5160 : will prevent such mismatches. */
5161 :
5162 1873893 : poly_int64 size = (TYPE_EMPTY_P (TREE_TYPE (pval))
5163 3738773 : ? 0 : GET_MODE_SIZE (arg->mode));
5164 :
5165 : /* Compute how much space the push instruction will push.
5166 : On many machines, pushing a byte will advance the stack
5167 : pointer by a halfword. */
5168 : #ifdef PUSH_ROUNDING
5169 1873893 : size = PUSH_ROUNDING (size);
5170 : #endif
5171 1873893 : used = size;
5172 :
5173 : /* Compute how much space the argument should get:
5174 : round up to a multiple of the alignment for arguments. */
5175 1873893 : if (targetm.calls.function_arg_padding (arg->mode, TREE_TYPE (pval))
5176 : != PAD_NONE)
5177 : /* At the moment we don't (need to) support ABIs for which the
5178 : padding isn't known at compile time. In principle it should
5179 : be easy to add though. */
5180 3293617 : used = force_align_up (size, PARM_BOUNDARY / BITS_PER_UNIT);
5181 :
5182 : /* Compute the alignment of the pushed argument. */
5183 1873893 : parm_align = arg->locate.boundary;
5184 1873893 : if (targetm.calls.function_arg_padding (arg->mode, TREE_TYPE (pval))
5185 : == PAD_DOWNWARD)
5186 : {
5187 0 : poly_int64 pad = used - size;
5188 0 : unsigned int pad_align = known_alignment (pad) * BITS_PER_UNIT;
5189 0 : if (pad_align != 0)
5190 0 : parm_align = MIN (parm_align, pad_align);
5191 : }
5192 :
5193 : /* This isn't already where we want it on the stack, so put it there.
5194 : This can either be done with push or copy insns. */
5195 1873893 : if (maybe_ne (used, 0)
5196 3738773 : && !emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval),
5197 : NULL_RTX, parm_align, partial, reg, used - size,
5198 3284608 : argblock, ARGS_SIZE_RTX (arg->locate.offset),
5199 : reg_parm_stack_space,
5200 3284608 : ARGS_SIZE_RTX (arg->locate.alignment_pad), true))
5201 : sibcall_failure = true;
5202 :
5203 : /* Unless this is a partially-in-register argument, the argument is now
5204 : in the stack. */
5205 1873893 : if (partial == 0)
5206 1873893 : arg->value = arg->stack;
5207 : }
5208 : else
5209 : {
5210 : /* BLKmode, at least partly to be pushed. */
5211 :
5212 271187 : unsigned int parm_align;
5213 271187 : poly_int64 excess;
5214 271187 : rtx size_rtx;
5215 :
5216 : /* Pushing a nonscalar.
5217 : If part is passed in registers, PARTIAL says how much
5218 : and emit_push_insn will take care of putting it there. */
5219 :
5220 : /* Round its size up to a multiple
5221 : of the allocation unit for arguments. */
5222 :
5223 271187 : if (arg->locate.size.var != 0)
5224 : {
5225 0 : excess = 0;
5226 0 : size_rtx = ARGS_SIZE_RTX (arg->locate.size);
5227 : }
5228 : else
5229 : {
5230 : /* PUSH_ROUNDING has no effect on us, because emit_push_insn
5231 : for BLKmode is careful to avoid it. */
5232 271187 : excess = (arg->locate.size.constant
5233 271187 : - arg_int_size_in_bytes (TREE_TYPE (pval))
5234 271187 : + partial);
5235 271187 : size_rtx = expand_expr (arg_size_in_bytes (TREE_TYPE (pval)),
5236 271187 : NULL_RTX, TYPE_MODE (sizetype),
5237 : EXPAND_NORMAL);
5238 : }
5239 :
5240 271187 : parm_align = arg->locate.boundary;
5241 :
5242 : /* When an argument is padded down, the block is aligned to
5243 : PARM_BOUNDARY, but the actual argument isn't. */
5244 271187 : if (targetm.calls.function_arg_padding (arg->mode, TREE_TYPE (pval))
5245 : == PAD_DOWNWARD)
5246 : {
5247 0 : if (arg->locate.size.var)
5248 : parm_align = BITS_PER_UNIT;
5249 : else
5250 : {
5251 0 : unsigned int excess_align
5252 0 : = known_alignment (excess) * BITS_PER_UNIT;
5253 0 : if (excess_align != 0)
5254 0 : parm_align = MIN (parm_align, excess_align);
5255 : }
5256 : }
5257 :
5258 271187 : if ((flags & ECF_SIBCALL) && MEM_P (arg->value))
5259 : {
5260 : /* emit_push_insn might not work properly if arg->value and
5261 : argblock + arg->locate.offset areas overlap. */
5262 87 : rtx x = arg->value;
5263 87 : poly_int64 i = 0;
5264 :
5265 87 : if (strip_offset (XEXP (x, 0), &i)
5266 87 : == crtl->args.internal_arg_pointer)
5267 : {
5268 : /* arg.locate doesn't contain the pretend_args_size offset,
5269 : it's part of argblock. Ensure we don't count it in I. */
5270 28 : if (STACK_GROWS_DOWNWARD)
5271 28 : i -= crtl->args.pretend_args_size;
5272 : else
5273 : i += crtl->args.pretend_args_size;
5274 :
5275 : /* expand_call should ensure this. */
5276 28 : gcc_assert (!arg->locate.offset.var
5277 : && arg->locate.size.var == 0);
5278 28 : poly_int64 size_val = rtx_to_poly_int64 (size_rtx);
5279 :
5280 28 : if (known_eq (arg->locate.offset.constant, i))
5281 : {
5282 : /* Even though they appear to be at the same location,
5283 : if part of the outgoing argument is in registers,
5284 : they aren't really at the same location. Check for
5285 : this by making sure that the incoming size is the
5286 : same as the outgoing size. */
5287 19 : if (partial != 0)
5288 0 : sibcall_failure = true;
5289 : }
5290 12 : else if (maybe_in_range_p (arg->locate.offset.constant,
5291 : i, size_val))
5292 : sibcall_failure = true;
5293 : /* Use arg->locate.size.constant instead of size_rtx
5294 : because we only care about the part of the argument
5295 : on the stack. */
5296 87 : else if (maybe_in_range_p (i, arg->locate.offset.constant,
5297 9 : arg->locate.size.constant))
5298 0 : sibcall_failure = true;
5299 : }
5300 : }
5301 :
5302 271187 : if (!CONST_INT_P (size_rtx) || INTVAL (size_rtx) != 0)
5303 269117 : emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
5304 : parm_align, partial, reg, excess, argblock,
5305 334124 : ARGS_SIZE_RTX (arg->locate.offset),
5306 : reg_parm_stack_space,
5307 334124 : ARGS_SIZE_RTX (arg->locate.alignment_pad), false);
5308 : /* If we bypass emit_push_insn because it is a zero sized argument,
5309 : we still might need to adjust stack if such argument requires
5310 : extra alignment. See PR104558. */
5311 2070 : else if ((arg->locate.alignment_pad.var
5312 2070 : || maybe_ne (arg->locate.alignment_pad.constant, 0))
5313 2071 : && !argblock)
5314 1 : anti_adjust_stack (ARGS_SIZE_RTX (arg->locate.alignment_pad));
5315 :
5316 : /* Unless this is a partially-in-register argument, the argument is now
5317 : in the stack.
5318 :
5319 : ??? Unlike the case above, in which we want the actual
5320 : address of the data, so that we can load it directly into a
5321 : register, here we want the address of the stack slot, so that
5322 : it's properly aligned for word-by-word copying or something
5323 : like that. It's not clear that this is always correct. */
5324 271187 : if (partial == 0)
5325 271187 : arg->value = arg->stack_slot;
5326 : }
5327 :
5328 2153704 : if (arg->reg && GET_CODE (arg->reg) == PARALLEL)
5329 : {
5330 0 : tree type = TREE_TYPE (arg->tree_value);
5331 0 : arg->parallel_value
5332 0 : = emit_group_load_into_temps (arg->reg, arg->value, type,
5333 0 : int_size_in_bytes (type));
5334 : }
5335 :
5336 : /* Mark all slots this store used. */
5337 2153704 : if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)
5338 2207618 : && argblock && ! variable_size && arg->stack)
5339 53835 : mark_stack_region_used (lower_bound, upper_bound);
5340 :
5341 : /* Once we have pushed something, pops can't safely
5342 : be deferred during the rest of the arguments. */
5343 2153704 : NO_DEFER_POP;
5344 :
5345 : /* Free any temporary slots made in processing this argument. */
5346 2153704 : pop_temp_slots ();
5347 :
5348 2153704 : return sibcall_failure;
5349 : }
5350 :
5351 : /* Nonzero if we do not know how to pass ARG solely in registers. */
5352 :
5353 : bool
5354 0 : must_pass_in_stack_var_size (const function_arg_info &arg)
5355 : {
5356 0 : if (!arg.type)
5357 : return false;
5358 :
5359 : /* If the type has variable size... */
5360 0 : if (!poly_int_tree_p (TYPE_SIZE (arg.type)))
5361 : return true;
5362 :
5363 : /* If the type is marked as addressable (it is required
5364 : to be constructed into the stack)... */
5365 0 : if (TREE_ADDRESSABLE (arg.type))
5366 0 : return true;
5367 :
5368 : return false;
5369 : }
5370 :
5371 : /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
5372 : takes trailing padding of a structure into account. */
5373 : /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
5374 :
5375 : bool
5376 423853457 : must_pass_in_stack_var_size_or_pad (const function_arg_info &arg)
5377 : {
5378 423853457 : if (!arg.type)
5379 : return false;
5380 :
5381 : /* If the type has variable size... */
5382 422987762 : if (TREE_CODE (TYPE_SIZE (arg.type)) != INTEGER_CST)
5383 : return true;
5384 :
5385 : /* If the type is marked as addressable (it is required
5386 : to be constructed into the stack)... */
5387 422987762 : if (TREE_ADDRESSABLE (arg.type))
5388 : return true;
5389 :
5390 422987725 : if (TYPE_EMPTY_P (arg.type))
5391 : return false;
5392 :
5393 : /* If the padding and mode of the type is such that a copy into
5394 : a register would put it into the wrong part of the register. */
5395 420513203 : if (arg.mode == BLKmode
5396 6733754 : && int_size_in_bytes (arg.type) % (PARM_BOUNDARY / BITS_PER_UNIT)
5397 421170789 : && (targetm.calls.function_arg_padding (arg.mode, arg.type)
5398 : == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)))
5399 0 : return true;
5400 :
5401 : return false;
5402 : }
5403 :
5404 : /* Return true if TYPE must be passed on the stack when passed to
5405 : the "..." arguments of a function. */
5406 :
5407 : bool
5408 0 : must_pass_va_arg_in_stack (tree type)
5409 : {
5410 0 : function_arg_info arg (type, /*named=*/false);
5411 0 : return targetm.calls.must_pass_in_stack (arg);
5412 : }
5413 :
5414 : /* Return true if FIELD is the C++17 empty base field that should
5415 : be ignored for ABI calling convention decisions in order to
5416 : maintain ABI compatibility between C++14 and earlier, which doesn't
5417 : add this FIELD to classes with empty bases, and C++17 and later
5418 : which does. */
5419 :
5420 : bool
5421 0 : cxx17_empty_base_field_p (const_tree field)
5422 : {
5423 0 : return (DECL_FIELD_ABI_IGNORED (field)
5424 0 : && DECL_ARTIFICIAL (field)
5425 0 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
5426 0 : && !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (field)));
5427 : }
|