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