Branch data Line data Source code
1 : : /* Convert function calls to rtl insns, for GNU C compiler.
2 : : Copyright (C) 1989-2025 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 : 5834249 : 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 : 5834249 : 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 : 181202 : 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 : 181202 : funexp = ((reg_parm_seen
292 : 137045 : && targetm.small_register_classes_for_mode_p (FUNCTION_MODE))
293 : 318247 : ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
294 : 44157 : : 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 : 5653047 : if (GET_MODE (funexp) != Pmode)
302 : 0 : funexp = convert_memory_address (Pmode, funexp);
303 : :
304 : 5653047 : if (!(flags & ECF_SIBCALL))
305 : : {
306 : 5653047 : if (!NO_FUNCTION_CSE && optimize && ! flag_no_function_cse)
307 : : funexp = force_reg (Pmode, funexp);
308 : : }
309 : : }
310 : :
311 : 5834249 : if (static_chain_value != 0
312 : 5834249 : && (TREE_CODE (fndecl_or_type) != FUNCTION_DECL
313 : 15285 : || DECL_STATIC_CHAIN (fndecl_or_type)))
314 : : {
315 : 37536 : rtx chain;
316 : :
317 : 37536 : chain = targetm.calls.static_chain (fndecl_or_type, false);
318 : 37536 : static_chain_value = convert_memory_address (Pmode, static_chain_value);
319 : :
320 : 37536 : emit_move_insn (chain, static_chain_value);
321 : 37536 : if (REG_P (chain))
322 : : {
323 : 37536 : use_reg (call_fusage, chain);
324 : 37536 : STATIC_CHAIN_REG_P (chain) = 1;
325 : : }
326 : : }
327 : :
328 : 5834249 : 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 : 5833766 : 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 : 5833766 : rtx rounded_stack_size_rtx = gen_int_mode (rounded_stack_size, Pmode);
385 : 5833766 : rtx call, funmem, pat;
386 : 5833766 : bool already_popped = false;
387 : 5833766 : 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 : 5833766 : if (!(ecf_flags & ECF_SIBCALL))
393 : : {
394 : 5711775 : 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 : 5833766 : if (GET_CODE (funexp) != SYMBOL_REF)
405 : 181173 : funexp = memory_address (FUNCTION_MODE, funexp);
406 : :
407 : 5833766 : funmem = gen_rtx_MEM (FUNCTION_MODE, funexp);
408 : 5833766 : if (fndecl && TREE_CODE (fndecl) == FUNCTION_DECL)
409 : : {
410 : 5533726 : 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 : 5533726 : if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL)
420 : : {
421 : 1171018 : tree t2 = builtin_decl_explicit (DECL_FUNCTION_CODE (t));
422 : 1171018 : if (t2)
423 : 5533726 : t = t2;
424 : : }
425 : :
426 : 5533726 : set_mem_expr (funmem, t);
427 : 5533726 : }
428 : 300040 : else if (fntree)
429 : 181190 : set_mem_expr (funmem, build_simple_mem_ref (CALL_EXPR_FN (fntree)));
430 : :
431 : 5833766 : if (ecf_flags & ECF_SIBCALL)
432 : : {
433 : 121991 : if (valreg)
434 : 37077 : pat = targetm.gen_sibcall_value (valreg, funmem,
435 : : rounded_stack_size_rtx,
436 : : next_arg_reg, NULL_RTX);
437 : : else
438 : 84914 : pat = targetm.gen_sibcall (funmem, rounded_stack_size_rtx,
439 : : next_arg_reg,
440 : 84914 : 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 : 5711775 : else if (maybe_ne (n_popped, 0)
447 : 11297153 : || !(valreg
448 : 2365675 : ? targetm.have_call_value ()
449 : 3219703 : : targetm.have_call ()))
450 : : {
451 : 126397 : 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 : 126397 : 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 : 126397 : 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 : 5585378 : if (valreg)
469 : 2365675 : pat = targetm.gen_call_value (valreg, funmem, rounded_stack_size_rtx,
470 : : next_arg_reg, NULL_RTX);
471 : : else
472 : 3219703 : pat = targetm.gen_call (funmem, rounded_stack_size_rtx, next_arg_reg,
473 : 3219703 : gen_int_mode (struct_value_size, Pmode));
474 : : }
475 : 5833766 : emit_insn (pat);
476 : :
477 : : /* Find the call we just emitted. */
478 : 5833766 : 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 : 5833766 : call = get_call_rtx_from (call_insn);
483 : 5833766 : if (call
484 : 5953210 : && MEM_EXPR (XEXP (call, 0)) == NULL_TREE
485 : 5953210 : && MEM_EXPR (funmem) != NULL_TREE)
486 : 594 : set_mem_expr (XEXP (call, 0), MEM_EXPR (funmem));
487 : :
488 : : /* Put the register usage information there. */
489 : 5833766 : add_function_usage_to (call_insn, call_fusage);
490 : :
491 : : /* If this is a const call, then set the insn's unchanging bit. */
492 : 5833766 : if (ecf_flags & ECF_CONST)
493 : 207244 : RTL_CONST_CALL_P (call_insn) = 1;
494 : :
495 : : /* If this is a pure call, then set the insn's unchanging bit. */
496 : 5833766 : if (ecf_flags & ECF_PURE)
497 : 338480 : RTL_PURE_CALL_P (call_insn) = 1;
498 : :
499 : : /* If this is a const call, then set the insn's unchanging bit. */
500 : 5833766 : if (ecf_flags & ECF_LOOPING_CONST_OR_PURE)
501 : 38670 : RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn) = 1;
502 : :
503 : : /* Create a nothrow REG_EH_REGION note, if needed. */
504 : 5833766 : make_reg_eh_region_note (call_insn, ecf_flags, 0);
505 : :
506 : 5833766 : if (ecf_flags & ECF_NORETURN)
507 : 741089 : add_reg_note (call_insn, REG_NORETURN, const0_rtx);
508 : :
509 : 5833766 : if (ecf_flags & ECF_RETURNS_TWICE)
510 : : {
511 : 1557 : add_reg_note (call_insn, REG_SETJMP, const0_rtx);
512 : 1557 : cfun->calls_setjmp = 1;
513 : : }
514 : :
515 : 5833766 : 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 : 5833766 : inhibit_defer_pop = old_inhibit_defer_pop;
520 : :
521 : 5833766 : if (maybe_ne (n_popped, 0))
522 : : {
523 : 126397 : 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 : 126397 : rounded_stack_size -= n_popped;
529 : 126397 : rounded_stack_size_rtx = gen_int_mode (rounded_stack_size, Pmode);
530 : 126397 : stack_pointer_delta -= n_popped;
531 : :
532 : 126397 : add_args_size_note (call_insn, stack_pointer_delta);
533 : :
534 : : /* If popup is needed, stack realign must use DRAP */
535 : 126397 : if (SUPPORTS_STACK_ALIGNMENT)
536 : 126397 : 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 : 5707369 : else if (!ACCUMULATE_OUTGOING_ARGS && (ecf_flags & ECF_NORETURN) != 0)
542 : 740906 : add_args_size_note (call_insn, stack_pointer_delta);
543 : :
544 : 5833766 : 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 : 5759204 : if (maybe_ne (rounded_stack_size, 0))
554 : : {
555 : 929861 : if (ecf_flags & ECF_NORETURN)
556 : : /* Just pretend we did the pop. */
557 : 5833766 : stack_pointer_delta -= rounded_stack_size;
558 : 875949 : else if (flag_defer_pop && inhibit_defer_pop == 0
559 : 771269 : && ! (ecf_flags & (ECF_CONST | ECF_PURE)))
560 : 5833766 : pending_stack_adjust += rounded_stack_size;
561 : : else
562 : 120547 : 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 : 74562 : else if (maybe_ne (n_popped, 0))
577 : 0 : anti_adjust_stack (gen_int_mode (n_popped, Pmode));
578 : 5833766 : }
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 : 4311904618 : special_function_p (const_tree fndecl, int flags)
591 : : {
592 : 4311904618 : tree name_decl = DECL_NAME (fndecl);
593 : :
594 : 4311904618 : if (maybe_special_function_p (fndecl)
595 : 7295259403 : && IDENTIFIER_LENGTH (name_decl) <= 11)
596 : : {
597 : 561607012 : const char *name = IDENTIFIER_POINTER (name_decl);
598 : 561607012 : 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 : 561607012 : if (IDENTIFIER_LENGTH (name_decl) == 6
604 : 147262679 : && name[0] == 'a'
605 : 562286576 : && ! strcmp (name, "alloca"))
606 : 79810 : flags |= ECF_MAY_BE_ALLOCA;
607 : :
608 : : /* Disregard prefix _ or __. */
609 : 561607012 : if (name[0] == '_')
610 : : {
611 : 37873730 : if (name[1] == '_')
612 : 11128344 : tname += 2;
613 : : else
614 : 26745386 : tname += 1;
615 : : }
616 : :
617 : : /* ECF_RETURNS_TWICE is safe even for -ffreestanding. */
618 : 561607012 : if (! strcmp (tname, "setjmp")
619 : 561280880 : || ! strcmp (tname, "sigsetjmp")
620 : 561253070 : || ! strcmp (name, "savectx")
621 : 561253070 : || ! strcmp (name, "vfork")
622 : 561231540 : || ! strcmp (name, "getcontext"))
623 : 401958 : flags |= ECF_RETURNS_TWICE;
624 : : }
625 : :
626 : 4311904618 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
627 : 4311904618 : && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (fndecl)))
628 : 11754348 : flags |= ECF_MAY_BE_ALLOCA;
629 : :
630 : 4311904618 : return flags;
631 : : }
632 : :
633 : : /* Return fnspec for DECL. */
634 : :
635 : : static attr_fnspec
636 : 5533722 : decl_fnspec (tree fndecl)
637 : : {
638 : 5533722 : tree attr;
639 : 5533722 : tree type = TREE_TYPE (fndecl);
640 : 5533722 : if (type)
641 : : {
642 : 5533722 : attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
643 : 5533722 : if (attr)
644 : : {
645 : 334000 : return TREE_VALUE (TREE_VALUE (attr));
646 : : }
647 : : }
648 : 5199722 : if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
649 : 1159001 : return builtin_fnspec (fndecl);
650 : 4040721 : return "";
651 : : }
652 : :
653 : : /* Similar to special_function_p; return a set of ERF_ flags for the
654 : : function FNDECL. */
655 : : static int
656 : 5533722 : decl_return_flags (tree fndecl)
657 : : {
658 : 5533722 : attr_fnspec fnspec = decl_fnspec (fndecl);
659 : :
660 : 5533722 : unsigned int arg;
661 : 5533722 : if (fnspec.returns_arg (&arg))
662 : 129520 : return ERF_RETURNS_ARG | arg;
663 : :
664 : 5404202 : if (fnspec.returns_noalias_p ())
665 : 53335 : return ERF_NOALIAS;
666 : : return 0;
667 : : }
668 : :
669 : : /* Return true when FNDECL represents a call to setjmp. */
670 : :
671 : : bool
672 : 31160273 : setjmp_call_p (const_tree fndecl)
673 : : {
674 : 31160273 : if (DECL_IS_RETURNS_TWICE (fndecl))
675 : : return true;
676 : 31158910 : if (special_function_p (fndecl, 0) & ECF_RETURNS_TWICE)
677 : 2123 : return true;
678 : :
679 : : return false;
680 : : }
681 : :
682 : :
683 : : /* Return true if STMT may be an alloca call. */
684 : :
685 : : bool
686 : 17859328 : gimple_maybe_alloca_call_p (const gimple *stmt)
687 : : {
688 : 17859328 : tree fndecl;
689 : :
690 : 17859328 : if (!is_gimple_call (stmt))
691 : : return false;
692 : :
693 : 17859328 : fndecl = gimple_call_fndecl (stmt);
694 : 17859328 : 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 : 154832765 : gimple_alloca_call_p (const gimple *stmt)
704 : : {
705 : 154832765 : tree fndecl;
706 : :
707 : 154832765 : if (!is_gimple_call (stmt))
708 : : return false;
709 : :
710 : 26277506 : fndecl = gimple_call_fndecl (stmt);
711 : 26277506 : if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
712 : 6859007 : switch (DECL_FUNCTION_CODE (fndecl))
713 : : {
714 : 155320 : CASE_BUILT_IN_ALLOCA:
715 : 155320 : 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 : 2479097 : alloca_call_p (const_tree exp)
727 : : {
728 : 2479097 : tree fndecl;
729 : 2479097 : if (TREE_CODE (exp) == CALL_EXPR
730 : 2479097 : && (fndecl = get_callee_fndecl (exp))
731 : 4958194 : && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
732 : 1342601 : 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 : 874207 : is_tm_builtin (const_tree fndecl)
748 : : {
749 : 874207 : if (fndecl == NULL)
750 : : return false;
751 : :
752 : 1653427 : if (decl_is_tm_clone (fndecl))
753 : : return true;
754 : :
755 : 851460 : if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
756 : : {
757 : 461172 : switch (DECL_FUNCTION_CODE (fndecl))
758 : : {
759 : 319852 : case BUILT_IN_TM_COMMIT:
760 : 319852 : case BUILT_IN_TM_COMMIT_EH:
761 : 319852 : case BUILT_IN_TM_ABORT:
762 : 319852 : case BUILT_IN_TM_IRREVOCABLE:
763 : 319852 : case BUILT_IN_TM_GETTMCLONE_IRR:
764 : 319852 : case BUILT_IN_TM_MEMCPY:
765 : 319852 : case BUILT_IN_TM_MEMMOVE:
766 : 319852 : case BUILT_IN_TM_MEMSET:
767 : 319852 : CASE_BUILT_IN_TM_STORE (1):
768 : 319852 : CASE_BUILT_IN_TM_STORE (2):
769 : 319852 : CASE_BUILT_IN_TM_STORE (4):
770 : 319852 : CASE_BUILT_IN_TM_STORE (8):
771 : 319852 : CASE_BUILT_IN_TM_STORE (FLOAT):
772 : 319852 : CASE_BUILT_IN_TM_STORE (DOUBLE):
773 : 319852 : CASE_BUILT_IN_TM_STORE (LDOUBLE):
774 : 319852 : CASE_BUILT_IN_TM_STORE (M64):
775 : 319852 : CASE_BUILT_IN_TM_STORE (M128):
776 : 319852 : CASE_BUILT_IN_TM_STORE (M256):
777 : 319852 : CASE_BUILT_IN_TM_LOAD (1):
778 : 319852 : CASE_BUILT_IN_TM_LOAD (2):
779 : 319852 : CASE_BUILT_IN_TM_LOAD (4):
780 : 319852 : CASE_BUILT_IN_TM_LOAD (8):
781 : 319852 : CASE_BUILT_IN_TM_LOAD (FLOAT):
782 : 319852 : CASE_BUILT_IN_TM_LOAD (DOUBLE):
783 : 319852 : CASE_BUILT_IN_TM_LOAD (LDOUBLE):
784 : 319852 : CASE_BUILT_IN_TM_LOAD (M64):
785 : 319852 : CASE_BUILT_IN_TM_LOAD (M128):
786 : 319852 : CASE_BUILT_IN_TM_LOAD (M256):
787 : 319852 : case BUILT_IN_TM_LOG:
788 : 319852 : case BUILT_IN_TM_LOG_1:
789 : 319852 : case BUILT_IN_TM_LOG_2:
790 : 319852 : case BUILT_IN_TM_LOG_4:
791 : 319852 : case BUILT_IN_TM_LOG_8:
792 : 319852 : case BUILT_IN_TM_LOG_FLOAT:
793 : 319852 : case BUILT_IN_TM_LOG_DOUBLE:
794 : 319852 : case BUILT_IN_TM_LOG_LDOUBLE:
795 : 319852 : case BUILT_IN_TM_LOG_M64:
796 : 319852 : case BUILT_IN_TM_LOG_M128:
797 : 319852 : case BUILT_IN_TM_LOG_M256:
798 : 319852 : 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 : 8235240120 : flags_from_decl_or_type (const_tree exp)
810 : : {
811 : 8235240120 : int flags = 0;
812 : :
813 : 8235240120 : if (DECL_P (exp))
814 : : {
815 : : /* The function exp may have the `malloc' attribute. */
816 : 4263384171 : if (DECL_IS_MALLOC (exp))
817 : 73181708 : flags |= ECF_MALLOC;
818 : :
819 : : /* The function exp may have the `returns_twice' attribute. */
820 : 4263384171 : if (DECL_IS_RETURNS_TWICE (exp))
821 : 240687 : flags |= ECF_RETURNS_TWICE;
822 : :
823 : : /* Process the pure and const attributes. */
824 : 4263384171 : if (TREE_READONLY (exp))
825 : 252283815 : flags |= ECF_CONST;
826 : 4263384171 : if (DECL_PURE_P (exp))
827 : 249983822 : flags |= ECF_PURE;
828 : 4263384171 : if (DECL_LOOPING_CONST_OR_PURE_P (exp))
829 : 20880346 : flags |= ECF_LOOPING_CONST_OR_PURE;
830 : :
831 : 4263384171 : if (DECL_IS_NOVOPS (exp))
832 : 613476 : flags |= ECF_NOVOPS;
833 : 4263384171 : if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp)))
834 : 815035322 : flags |= ECF_LEAF;
835 : 4263384171 : if (lookup_attribute ("cold", DECL_ATTRIBUTES (exp)))
836 : 337202880 : flags |= ECF_COLD;
837 : :
838 : 4263384171 : if (TREE_NOTHROW (exp))
839 : 1834761532 : flags |= ECF_NOTHROW;
840 : :
841 : 4263384171 : if (flag_tm)
842 : : {
843 : 874207 : if (is_tm_builtin (exp))
844 : 342599 : flags |= ECF_TM_BUILTIN;
845 : 531608 : else if ((flags & (ECF_CONST|ECF_NOVOPS)) != 0
846 : 1049126 : || lookup_attribute ("transaction_pure",
847 : 517518 : TYPE_ATTRIBUTES (TREE_TYPE (exp))))
848 : 122157 : flags |= ECF_TM_PURE;
849 : : }
850 : :
851 : 4263384171 : if (lookup_attribute ("expected_throw", DECL_ATTRIBUTES (exp)))
852 : 13559920 : flags |= ECF_XTHROW;
853 : :
854 : 4263384171 : flags = special_function_p (exp, flags);
855 : :
856 : 4263384171 : if ((flags & ECF_CONST) == 0
857 : 8274484527 : && lookup_attribute ("unsequenced noptr",
858 : 4011100356 : TYPE_ATTRIBUTES (TREE_TYPE (exp))))
859 : : {
860 : : /* [[unsequenced]] with no pointers in arguments is like
861 : : [[gnu::const]] without finite guarantee. */
862 : 122170 : flags |= ECF_CONST;
863 : 122170 : if ((flags & ECF_PURE) == 0)
864 : 122170 : flags |= ECF_LOOPING_CONST_OR_PURE;
865 : : }
866 : 122170 : if ((flags & (ECF_CONST | ECF_PURE)) == 0
867 : 8024256365 : && lookup_attribute ("reproducible noptr",
868 : 3760994364 : TYPE_ATTRIBUTES (TREE_TYPE (exp))))
869 : : /* [[reproducible]] with no pointers in arguments is like
870 : : [[gnu::pure]] without finite guarantee. */
871 : 147445 : flags |= ECF_PURE | ECF_LOOPING_CONST_OR_PURE;
872 : : }
873 : 3971855949 : else if (TYPE_P (exp))
874 : : {
875 : 3971855949 : if (TYPE_READONLY (exp))
876 : 40208225 : flags |= ECF_CONST;
877 : :
878 : 3971855949 : if (flag_tm
879 : 3971855949 : && ((flags & ECF_CONST) != 0
880 : 832723 : || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp))))
881 : 107784 : flags |= ECF_TM_PURE;
882 : :
883 : 3971855949 : if ((flags & ECF_CONST) == 0
884 : 3971855949 : && lookup_attribute ("unsequenced noptr", TYPE_ATTRIBUTES (exp)))
885 : : /* [[unsequenced]] with no pointers in arguments is like
886 : : [[gnu::const]] without finite guarantee. */
887 : 120558 : flags |= ECF_CONST | ECF_LOOPING_CONST_OR_PURE;
888 : 120558 : if ((flags & ECF_CONST) == 0
889 : 3971735391 : && lookup_attribute ("reproducible noptr", TYPE_ATTRIBUTES (exp)))
890 : : /* [[reproducible]] with no pointers in arguments is like
891 : : [[gnu::pure]] without finite guarantee. */
892 : 151806 : flags |= ECF_PURE | ECF_LOOPING_CONST_OR_PURE;
893 : : }
894 : : else
895 : 0 : gcc_unreachable ();
896 : :
897 : 8235240120 : if (TREE_THIS_VOLATILE (exp))
898 : : {
899 : 742997311 : flags |= ECF_NORETURN;
900 : 742997311 : if (flags & (ECF_CONST|ECF_PURE))
901 : 99042591 : flags |= ECF_LOOPING_CONST_OR_PURE;
902 : : }
903 : :
904 : 8235240120 : return flags;
905 : : }
906 : :
907 : : /* Detect flags from a CALL_EXPR. */
908 : :
909 : : int
910 : 261129479 : call_expr_flags (const_tree t)
911 : : {
912 : 261129479 : int flags;
913 : 261129479 : tree decl = get_callee_fndecl (t);
914 : :
915 : 261129479 : if (decl)
916 : 236654697 : flags = flags_from_decl_or_type (decl);
917 : 24474782 : else if (CALL_EXPR_FN (t) == NULL_TREE)
918 : 463964 : flags = internal_fn_flags (CALL_EXPR_IFN (t));
919 : : else
920 : : {
921 : 24010818 : tree type = TREE_TYPE (CALL_EXPR_FN (t));
922 : 24010818 : if (type && TREE_CODE (type) == POINTER_TYPE)
923 : 2878050 : flags = flags_from_decl_or_type (TREE_TYPE (type));
924 : : else
925 : : flags = 0;
926 : 24010818 : if (CALL_EXPR_BY_DESCRIPTOR (t))
927 : 0 : flags |= ECF_BY_DESCRIPTOR;
928 : : }
929 : :
930 : 261129479 : return flags;
931 : : }
932 : :
933 : : /* Return true if ARG should be passed by invisible reference. */
934 : :
935 : : bool
936 : 21164177 : pass_by_reference (CUMULATIVE_ARGS *ca, function_arg_info arg)
937 : : {
938 : 21164177 : 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 : 20958588 : if (TREE_ADDRESSABLE (type))
943 : : return true;
944 : :
945 : : /* GCC post 3.4 passes *all* variable sized types by reference. */
946 : 20958437 : 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 : 20957931 : 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 : 21163520 : 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 : 51697 : pass_va_arg_by_reference (tree type)
966 : : {
967 : 51697 : 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 : 9026822 : apply_pass_by_reference_rules (CUMULATIVE_ARGS *ca, function_arg_info &arg)
976 : : {
977 : 9026822 : if (pass_by_reference (ca, arg))
978 : : {
979 : 10084 : arg.type = build_pointer_type (arg.type);
980 : 10084 : arg.mode = TYPE_MODE (arg.type);
981 : 10084 : arg.pass_by_reference = true;
982 : 10084 : 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 : 5314 : reference_callee_copied (CUMULATIVE_ARGS *ca, const function_arg_info &arg)
992 : : {
993 : 5314 : if (arg.type && TREE_ADDRESSABLE (arg.type))
994 : : return false;
995 : 5304 : 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 : 5714916 : precompute_register_parameters (int num_actuals, struct arg_data *args,
1008 : : int *reg_parm_seen)
1009 : : {
1010 : 5714916 : int i;
1011 : :
1012 : 5714916 : *reg_parm_seen = 0;
1013 : :
1014 : 17595025 : for (i = 0; i < num_actuals; i++)
1015 : 11880109 : if (args[i].reg != 0 && ! args[i].pass_on_stack)
1016 : : {
1017 : 9762080 : *reg_parm_seen = 1;
1018 : :
1019 : 9762080 : if (args[i].value == 0)
1020 : : {
1021 : 9762080 : push_temp_slots ();
1022 : 9762080 : args[i].value = expand_normal (args[i].tree_value);
1023 : 9762080 : preserve_temp_slots (args[i].value);
1024 : 9762080 : pop_temp_slots ();
1025 : : }
1026 : :
1027 : : /* If we are to promote the function arg to a wider mode,
1028 : : do it now. */
1029 : :
1030 : 9762080 : 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 : 9762080 : if (SCALAR_INT_MODE_P (args[i].mode)
1037 : 9373819 : && SCALAR_FLOAT_MODE_P (old_mode)
1038 : 9762080 : && 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 : 9762080 : else if (args[i].mode != old_mode)
1043 : 47 : 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 : 9762080 : if (CONSTANT_P (args[i].value)
1049 : 9762080 : && (!targetm.legitimate_constant_p (args[i].mode, args[i].value)
1050 : 4337603 : || targetm.precompute_tls_p (args[i].mode, args[i].value)))
1051 : 3825 : 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 : 9762080 : if (GET_CODE (args[i].reg) == PARALLEL)
1057 : : {
1058 : 273426 : tree type = TREE_TYPE (args[i].tree_value);
1059 : 273426 : args[i].parallel_value
1060 : 273426 : = emit_group_load_into_temps (args[i].reg, args[i].value,
1061 : 273426 : 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 : 5093536 : else if ((! (REG_P (args[i].value)
1073 : : || (GET_CODE (args[i].value) == SUBREG
1074 : 18700 : && REG_P (SUBREG_REG (args[i].value)))))
1075 : 5074836 : && args[i].mode != BLKmode
1076 : 5073248 : && (set_src_cost (args[i].value, args[i].mode,
1077 : 5073248 : optimize_insn_for_speed_p ())
1078 : : > COSTS_N_INSNS (1))
1079 : 10340340 : && ((*reg_parm_seen
1080 : 851686 : && targetm.small_register_classes_for_mode_p (args[i].mode))
1081 : 0 : || optimize))
1082 : 851686 : args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
1083 : : }
1084 : 5714916 : }
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 : 73376 : save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
1094 : : {
1095 : 73376 : unsigned int low;
1096 : 73376 : unsigned int high;
1097 : :
1098 : : /* Compute the boundary of the area that needs to be saved, if any. */
1099 : 73376 : high = reg_parm_stack_space;
1100 : 73376 : if (ARGS_GROW_DOWNWARD)
1101 : : high += 1;
1102 : :
1103 : 73376 : if (high > highest_outgoing_arg_in_use)
1104 : : high = highest_outgoing_arg_in_use;
1105 : :
1106 : 264256 : 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 : 5594083 : maybe_complain_about_tail_call (tree call_expr, const char *reason)
1274 : : {
1275 : 5594083 : gcc_assert (TREE_CODE (call_expr) == CALL_EXPR);
1276 : 5594083 : if (CALL_EXPR_MUST_TAIL_CALL (call_expr))
1277 : : {
1278 : 21 : error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason);
1279 : 21 : CALL_EXPR_MUST_TAIL_CALL (call_expr) = 0;
1280 : : }
1281 : 5594083 : if (CALL_EXPR_TAILCALL (call_expr)
1282 : 10818 : && dump_file
1283 : 5594083 : && (dump_flags & TDF_DETAILS))
1284 : : {
1285 : 0 : fprintf (dump_file, ";; Cannot tail-call: %s: ", reason);
1286 : 0 : print_generic_expr (dump_file, call_expr, TDF_SLIM);
1287 : 0 : fprintf (dump_file, "\n");
1288 : : }
1289 : 5594083 : }
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 : 5714912 : 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 : 5714912 : CUMULATIVE_ARGS *args_so_far_pnt = get_cumulative_args (args_so_far);
1339 : 5714912 : location_t loc = EXPR_LOCATION (exp);
1340 : :
1341 : : /* Count arg position in order args appear. */
1342 : 5714912 : int argpos;
1343 : :
1344 : 5714912 : int i;
1345 : :
1346 : 5714912 : args_size->constant = 0;
1347 : 5714912 : 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 : 5714912 : i = num_actuals - 1;
1353 : 5714912 : {
1354 : 5714912 : int j = i;
1355 : 5714912 : call_expr_arg_iterator iter;
1356 : 5714912 : tree arg;
1357 : :
1358 : 5714912 : if (struct_value_addr_value)
1359 : : {
1360 : 226545 : args[j].tree_value = struct_value_addr_value;
1361 : 226545 : j--;
1362 : : }
1363 : 5714912 : argpos = 0;
1364 : 17368436 : FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
1365 : : {
1366 : 11653524 : tree argtype = TREE_TYPE (arg);
1367 : :
1368 : 11653524 : if (targetm.calls.split_complex_arg
1369 : 0 : && argtype
1370 : 0 : && TREE_CODE (argtype) == COMPLEX_TYPE
1371 : 11653524 : && 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 : 11653524 : args[j].tree_value = arg;
1380 : 11653524 : j--;
1381 : 11653524 : argpos++;
1382 : : }
1383 : : }
1384 : :
1385 : : /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1386 : 17594981 : for (argpos = 0; argpos < num_actuals; i--, argpos++)
1387 : : {
1388 : 11880069 : tree type = TREE_TYPE (args[i].tree_value);
1389 : 11880069 : int unsignedp;
1390 : :
1391 : : /* Replace erroneous argument with constant zero. */
1392 : 11880069 : if (type == error_mark_node || !COMPLETE_TYPE_P (type))
1393 : 0 : args[i].tree_value = integer_zero_node, type = integer_type_node;
1394 : :
1395 : : /* If TYPE is a transparent union or record, pass things the way
1396 : : we would pass the first field of the union or record. We have
1397 : : already verified that the modes are the same. */
1398 : 11880069 : if (RECORD_OR_UNION_TYPE_P (type) && TYPE_TRANSPARENT_AGGR (type))
1399 : 3635 : type = TREE_TYPE (first_field (type));
1400 : :
1401 : : /* Decide where to pass this arg.
1402 : :
1403 : : args[i].reg is nonzero if all or part is passed in registers.
1404 : :
1405 : : args[i].partial is nonzero if part but not all is passed in registers,
1406 : : and the exact value says how many bytes are passed in registers.
1407 : :
1408 : : args[i].pass_on_stack is true if the argument must at least be
1409 : : computed on the stack. It may then be loaded back into registers
1410 : : if args[i].reg is nonzero.
1411 : :
1412 : : These decisions are driven by the FUNCTION_... macros and must agree
1413 : : with those made by function.cc. */
1414 : :
1415 : : /* See if this argument should be passed by invisible reference. */
1416 : 11880069 : function_arg_info arg (type, argpos < n_named_args);
1417 : 11880069 : if (pass_by_reference (args_so_far_pnt, arg))
1418 : : {
1419 : 376 : const bool callee_copies
1420 : 376 : = reference_callee_copied (args_so_far_pnt, arg);
1421 : 376 : tree base;
1422 : :
1423 : : /* If we're compiling a thunk, pass directly the address of an object
1424 : : already in memory, instead of making a copy. Likewise if we want
1425 : : to make the copy in the callee instead of the caller. */
1426 : 376 : if ((call_from_thunk_p || callee_copies)
1427 : 10 : && TREE_CODE (args[i].tree_value) != WITH_SIZE_EXPR
1428 : 10 : && ((base = get_base_address (args[i].tree_value)), true)
1429 : 10 : && TREE_CODE (base) != SSA_NAME
1430 : 386 : && (!DECL_P (base) || MEM_P (DECL_RTL (base))))
1431 : : {
1432 : : /* We may have turned the parameter value into an SSA name.
1433 : : Go back to the original parameter so we can take the
1434 : : address. */
1435 : 10 : if (TREE_CODE (args[i].tree_value) == SSA_NAME)
1436 : : {
1437 : 0 : gcc_assert (SSA_NAME_IS_DEFAULT_DEF (args[i].tree_value));
1438 : 0 : args[i].tree_value = SSA_NAME_VAR (args[i].tree_value);
1439 : 0 : gcc_assert (TREE_CODE (args[i].tree_value) == PARM_DECL);
1440 : : }
1441 : : /* Argument setup code may have copied the value to register. We
1442 : : revert that optimization now because the tail call code must
1443 : : use the original location. */
1444 : 10 : if (TREE_CODE (args[i].tree_value) == PARM_DECL
1445 : 0 : && !MEM_P (DECL_RTL (args[i].tree_value))
1446 : 0 : && DECL_INCOMING_RTL (args[i].tree_value)
1447 : 10 : && MEM_P (DECL_INCOMING_RTL (args[i].tree_value)))
1448 : 0 : set_decl_rtl (args[i].tree_value,
1449 : 0 : DECL_INCOMING_RTL (args[i].tree_value));
1450 : :
1451 : 10 : mark_addressable (args[i].tree_value);
1452 : :
1453 : : /* We can't use sibcalls if a callee-copied argument is
1454 : : stored in the current function's frame. */
1455 : 10 : if (!call_from_thunk_p && DECL_P (base) && !TREE_STATIC (base))
1456 : : {
1457 : 0 : *may_tailcall = false;
1458 : 0 : maybe_complain_about_tail_call (exp, _("a callee-copied "
1459 : : "argument is stored "
1460 : : "in the current "
1461 : : "function's frame"));
1462 : : }
1463 : :
1464 : 10 : args[i].tree_value = build_fold_addr_expr_loc (loc,
1465 : : args[i].tree_value);
1466 : 10 : type = TREE_TYPE (args[i].tree_value);
1467 : :
1468 : 10 : if (*ecf_flags & ECF_CONST)
1469 : 0 : *ecf_flags &= ~(ECF_CONST | ECF_LOOPING_CONST_OR_PURE);
1470 : : }
1471 : : else
1472 : : {
1473 : : /* We make a copy of the object and pass the address to the
1474 : : function being called. */
1475 : 366 : rtx copy;
1476 : :
1477 : 366 : if (!COMPLETE_TYPE_P (type)
1478 : 366 : || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
1479 : 477 : || (flag_stack_check == GENERIC_STACK_CHECK
1480 : 0 : && compare_tree_int (TYPE_SIZE_UNIT (type),
1481 : : STACK_CHECK_MAX_VAR_SIZE) > 0))
1482 : : {
1483 : : /* This is a variable-sized object. Make space on the stack
1484 : : for it. */
1485 : 255 : rtx size_rtx = expr_size (args[i].tree_value);
1486 : :
1487 : 255 : if (*old_stack_level == 0)
1488 : : {
1489 : 157 : emit_stack_save (SAVE_BLOCK, old_stack_level);
1490 : 157 : *old_pending_adj = pending_stack_adjust;
1491 : 157 : pending_stack_adjust = 0;
1492 : : }
1493 : :
1494 : : /* We can pass TRUE as the 4th argument because we just
1495 : : saved the stack pointer and will restore it right after
1496 : : the call. */
1497 : 510 : copy = allocate_dynamic_stack_space (size_rtx,
1498 : 255 : TYPE_ALIGN (type),
1499 : 255 : TYPE_ALIGN (type),
1500 : : max_int_size_in_bytes
1501 : : (type),
1502 : : true);
1503 : 255 : copy = gen_rtx_MEM (BLKmode, copy);
1504 : 255 : set_mem_attributes (copy, type, 1);
1505 : : }
1506 : : else
1507 : 111 : copy = assign_temp (type, 1, 0);
1508 : :
1509 : 366 : store_expr (args[i].tree_value, copy, 0, false, false);
1510 : :
1511 : : /* Just change the const function to pure and then let
1512 : : the next test clear the pure based on
1513 : : callee_copies. */
1514 : 366 : if (*ecf_flags & ECF_CONST)
1515 : : {
1516 : 1 : *ecf_flags &= ~ECF_CONST;
1517 : 1 : *ecf_flags |= ECF_PURE;
1518 : : }
1519 : :
1520 : 366 : if (!callee_copies && *ecf_flags & ECF_PURE)
1521 : 3 : *ecf_flags &= ~(ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
1522 : :
1523 : 366 : args[i].tree_value
1524 : 366 : = build_fold_addr_expr_loc (loc, make_tree (type, copy));
1525 : 366 : type = TREE_TYPE (args[i].tree_value);
1526 : 366 : *may_tailcall = false;
1527 : 366 : maybe_complain_about_tail_call (exp,
1528 : 366 : _("argument must be passed"
1529 : : " by copying"));
1530 : : }
1531 : 376 : arg.pass_by_reference = true;
1532 : : }
1533 : :
1534 : 11880069 : unsignedp = TYPE_UNSIGNED (type);
1535 : 11880069 : arg.type = type;
1536 : 11880069 : arg.mode
1537 : 23386700 : = promote_function_mode (type, TYPE_MODE (type), &unsignedp,
1538 : 11506631 : fndecl ? TREE_TYPE (fndecl) : fntype, 0);
1539 : :
1540 : 11880069 : args[i].unsignedp = unsignedp;
1541 : 11880069 : args[i].mode = arg.mode;
1542 : :
1543 : 11880069 : targetm.calls.warn_parameter_passing_abi (args_so_far, type);
1544 : :
1545 : 11880069 : args[i].reg = targetm.calls.function_arg (args_so_far, arg);
1546 : :
1547 : : /* If this is a sibling call and the machine has register windows, the
1548 : : register window has to be unwinded before calling the routine, so
1549 : : arguments have to go into the incoming registers. */
1550 : 11880069 : if (targetm.calls.function_incoming_arg != targetm.calls.function_arg)
1551 : 0 : args[i].tail_call_reg
1552 : 0 : = targetm.calls.function_incoming_arg (args_so_far, arg);
1553 : : else
1554 : 11880069 : args[i].tail_call_reg = args[i].reg;
1555 : :
1556 : 11880069 : if (args[i].reg)
1557 : 9762068 : args[i].partial = targetm.calls.arg_partial_bytes (args_so_far, arg);
1558 : :
1559 : 11880069 : args[i].pass_on_stack = targetm.calls.must_pass_in_stack (arg);
1560 : :
1561 : : /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1562 : : it means that we are to pass this arg in the register(s) designated
1563 : : by the PARALLEL, but also to pass it in the stack. */
1564 : 11880069 : if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1565 : 273426 : && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1566 : 0 : args[i].pass_on_stack = true;
1567 : :
1568 : : /* If this is an addressable type, we must preallocate the stack
1569 : : since we must evaluate the object into its final location.
1570 : :
1571 : : If this is to be passed in both registers and the stack, it is simpler
1572 : : to preallocate. */
1573 : 11880069 : if (TREE_ADDRESSABLE (type)
1574 : 11880069 : || (args[i].pass_on_stack && args[i].reg != 0))
1575 : 0 : *must_preallocate = true;
1576 : :
1577 : : /* Compute the stack-size of this argument. */
1578 : 11880069 : if (args[i].reg == 0 || args[i].partial != 0
1579 : 9762068 : || reg_parm_stack_space > 0
1580 : 9695789 : || args[i].pass_on_stack)
1581 : 2184280 : locate_and_pad_parm (arg.mode, type,
1582 : : #ifdef STACK_PARMS_IN_REG_PARM_AREA
1583 : : 1,
1584 : : #else
1585 : : args[i].reg != 0,
1586 : : #endif
1587 : : reg_parm_stack_space,
1588 : 2184280 : args[i].pass_on_stack ? 0 : args[i].partial,
1589 : : fndecl, args_size, &args[i].locate);
1590 : : #ifdef BLOCK_REG_PADDING
1591 : : else
1592 : : /* The argument is passed entirely in registers. See at which
1593 : : end it should be padded. */
1594 : : args[i].locate.where_pad =
1595 : : BLOCK_REG_PADDING (arg.mode, type,
1596 : : int_size_in_bytes (type) <= UNITS_PER_WORD);
1597 : : #endif
1598 : :
1599 : : /* Update ARGS_SIZE, the total stack space for args so far. */
1600 : :
1601 : 11880069 : args_size->constant += args[i].locate.size.constant;
1602 : 11880069 : if (args[i].locate.size.var)
1603 : 0 : ADD_PARM_SIZE (*args_size, args[i].locate.size.var);
1604 : :
1605 : : /* Increment ARGS_SO_FAR, which has info about which arg-registers
1606 : : have been used, etc. */
1607 : :
1608 : : /* ??? Traditionally we've passed TYPE_MODE here, instead of the
1609 : : promoted_mode used for function_arg above. However, the
1610 : : corresponding handling of incoming arguments in function.cc
1611 : : does pass the promoted mode. */
1612 : 11880069 : arg.mode = TYPE_MODE (type);
1613 : 11880069 : targetm.calls.function_arg_advance (args_so_far, arg);
1614 : : }
1615 : 5714912 : }
1616 : :
1617 : : /* Update ARGS_SIZE to contain the total size for the argument block.
1618 : : Return the original constant component of the argument block's size.
1619 : :
1620 : : REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1621 : : for arguments passed in registers. */
1622 : :
1623 : : static poly_int64
1624 : 5714916 : compute_argument_block_size (int reg_parm_stack_space,
1625 : : struct args_size *args_size,
1626 : : tree fndecl ATTRIBUTE_UNUSED,
1627 : : tree fntype ATTRIBUTE_UNUSED,
1628 : : int preferred_stack_boundary ATTRIBUTE_UNUSED)
1629 : : {
1630 : 5714916 : poly_int64 unadjusted_args_size = args_size->constant;
1631 : :
1632 : : /* For accumulate outgoing args mode we don't need to align, since the frame
1633 : : will be already aligned. Align to STACK_BOUNDARY in order to prevent
1634 : : backends from generating misaligned frame sizes. */
1635 : 5714916 : if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY)
1636 : 1072 : preferred_stack_boundary = STACK_BOUNDARY;
1637 : :
1638 : : /* Compute the actual size of the argument block required. The variable
1639 : : and constant sizes must be combined, the size may have to be rounded,
1640 : : and there may be a minimum required size. */
1641 : :
1642 : 5714916 : if (args_size->var)
1643 : : {
1644 : 0 : args_size->var = ARGS_SIZE_TREE (*args_size);
1645 : 0 : args_size->constant = 0;
1646 : :
1647 : 0 : preferred_stack_boundary /= BITS_PER_UNIT;
1648 : 0 : if (preferred_stack_boundary > 1)
1649 : : {
1650 : : /* We don't handle this case yet. To handle it correctly we have
1651 : : to add the delta, round and subtract the delta.
1652 : : Currently no machine description requires this support. */
1653 : 0 : gcc_assert (multiple_p (stack_pointer_delta,
1654 : : preferred_stack_boundary));
1655 : 0 : args_size->var = round_up (args_size->var, preferred_stack_boundary);
1656 : : }
1657 : :
1658 : 0 : if (reg_parm_stack_space > 0)
1659 : : {
1660 : 0 : args_size->var
1661 : 0 : = size_binop (MAX_EXPR, args_size->var,
1662 : : ssize_int (reg_parm_stack_space));
1663 : :
1664 : : /* The area corresponding to register parameters is not to count in
1665 : : the size of the block we need. So make the adjustment. */
1666 : 0 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
1667 : 0 : args_size->var
1668 : 0 : = size_binop (MINUS_EXPR, args_size->var,
1669 : : ssize_int (reg_parm_stack_space));
1670 : : }
1671 : : }
1672 : : else
1673 : : {
1674 : 5714916 : preferred_stack_boundary /= BITS_PER_UNIT;
1675 : 5714916 : if (preferred_stack_boundary < 1)
1676 : 121991 : preferred_stack_boundary = 1;
1677 : 5714916 : args_size->constant = (aligned_upper_bound (args_size->constant
1678 : 5714916 : + stack_pointer_delta,
1679 : : preferred_stack_boundary)
1680 : 5714916 : - stack_pointer_delta);
1681 : :
1682 : 5714916 : args_size->constant = upper_bound (args_size->constant,
1683 : : reg_parm_stack_space);
1684 : :
1685 : 5714916 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
1686 : 5678560 : args_size->constant -= reg_parm_stack_space;
1687 : : }
1688 : 5714916 : return unadjusted_args_size;
1689 : : }
1690 : :
1691 : : /* Precompute parameters as needed for a function call.
1692 : :
1693 : : FLAGS is mask of ECF_* constants.
1694 : :
1695 : : NUM_ACTUALS is the number of arguments.
1696 : :
1697 : : ARGS is an array containing information for each argument; this
1698 : : routine fills in the INITIAL_VALUE and VALUE fields for each
1699 : : precomputed argument. */
1700 : :
1701 : : static void
1702 : 5592925 : precompute_arguments (int num_actuals, struct arg_data *args)
1703 : : {
1704 : 5592925 : int i;
1705 : :
1706 : : /* If this is a libcall, then precompute all arguments so that we do not
1707 : : get extraneous instructions emitted as part of the libcall sequence. */
1708 : :
1709 : : /* If we preallocated the stack space, and some arguments must be passed
1710 : : on the stack, then we must precompute any parameter which contains a
1711 : : function call which will store arguments on the stack.
1712 : : Otherwise, evaluating the parameter may clobber previous parameters
1713 : : which have already been stored into the stack. (we have code to avoid
1714 : : such case by saving the outgoing stack arguments, but it results in
1715 : : worse code) */
1716 : 5592925 : if (!ACCUMULATE_OUTGOING_ARGS)
1717 : 5519563 : return;
1718 : :
1719 : 366523 : for (i = 0; i < num_actuals; i++)
1720 : : {
1721 : 293161 : tree type;
1722 : 293161 : machine_mode mode;
1723 : :
1724 : 293161 : if (TREE_CODE (args[i].tree_value) != CALL_EXPR)
1725 : 293161 : continue;
1726 : :
1727 : : /* If this is an addressable type, we cannot pre-evaluate it. */
1728 : 0 : type = TREE_TYPE (args[i].tree_value);
1729 : 0 : gcc_assert (!TREE_ADDRESSABLE (type));
1730 : :
1731 : 0 : args[i].initial_value = args[i].value
1732 : 0 : = expand_normal (args[i].tree_value);
1733 : :
1734 : 0 : mode = TYPE_MODE (type);
1735 : 0 : if (mode != args[i].mode)
1736 : : {
1737 : 0 : int unsignedp = args[i].unsignedp;
1738 : 0 : args[i].value
1739 : 0 : = convert_modes (args[i].mode, mode,
1740 : : args[i].value, args[i].unsignedp);
1741 : :
1742 : : /* CSE will replace this only if it contains args[i].value
1743 : : pseudo, so convert it down to the declared mode using
1744 : : a SUBREG. */
1745 : 0 : if (REG_P (args[i].value)
1746 : 0 : && GET_MODE_CLASS (args[i].mode) == MODE_INT
1747 : 0 : && promote_mode (type, mode, &unsignedp) != args[i].mode)
1748 : : {
1749 : 0 : args[i].initial_value
1750 : 0 : = gen_lowpart_SUBREG (mode, args[i].value);
1751 : 0 : SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1752 : 0 : SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp);
1753 : : }
1754 : : }
1755 : : }
1756 : : }
1757 : :
1758 : : /* Given the current state of MUST_PREALLOCATE and information about
1759 : : arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1760 : : compute and return the final value for MUST_PREALLOCATE. */
1761 : :
1762 : : static bool
1763 : 5714912 : finalize_must_preallocate (bool must_preallocate, int num_actuals,
1764 : : struct arg_data *args, struct args_size *args_size)
1765 : : {
1766 : : /* See if we have or want to preallocate stack space.
1767 : :
1768 : : If we would have to push a partially-in-regs parm
1769 : : before other stack parms, preallocate stack space instead.
1770 : :
1771 : : If the size of some parm is not a multiple of the required stack
1772 : : alignment, we must preallocate.
1773 : :
1774 : : If the total size of arguments that would otherwise create a copy in
1775 : : a temporary (such as a CALL) is more than half the total argument list
1776 : : size, preallocation is faster.
1777 : :
1778 : : Another reason to preallocate is if we have a machine (like the m88k)
1779 : : where stack alignment is required to be maintained between every
1780 : : pair of insns, not just when the call is made. However, we assume here
1781 : : that such machines either do not have push insns (and hence preallocation
1782 : : would occur anyway) or the problem is taken care of with
1783 : : PUSH_ROUNDING. */
1784 : :
1785 : 5714912 : if (! must_preallocate)
1786 : : {
1787 : : bool partial_seen = false;
1788 : : poly_int64 copy_to_evaluate_size = 0;
1789 : : int i;
1790 : :
1791 : 17226052 : for (i = 0; i < num_actuals && ! must_preallocate; i++)
1792 : : {
1793 : 11585695 : if (args[i].partial > 0 && ! args[i].pass_on_stack)
1794 : : partial_seen = true;
1795 : 11585695 : else if (partial_seen && args[i].reg == 0)
1796 : 0 : must_preallocate = true;
1797 : :
1798 : 11585695 : if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1799 : 11585695 : && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1800 : 276238 : || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1801 : 276238 : || TREE_CODE (args[i].tree_value) == COND_EXPR
1802 : 276238 : || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1803 : 0 : copy_to_evaluate_size
1804 : 0 : += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1805 : : }
1806 : :
1807 : 5640357 : if (maybe_ne (args_size->constant, 0)
1808 : 5640357 : && maybe_ge (copy_to_evaluate_size * 2, args_size->constant))
1809 : : must_preallocate = true;
1810 : : }
1811 : 5714912 : return must_preallocate;
1812 : : }
1813 : :
1814 : : /* If we preallocated stack space, compute the address of each argument
1815 : : and store it into the ARGS array.
1816 : :
1817 : : We need not ensure it is a valid memory address here; it will be
1818 : : validized when it is used.
1819 : :
1820 : : ARGBLOCK is an rtx for the address of the outgoing arguments. */
1821 : :
1822 : : static void
1823 : 5714916 : compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals)
1824 : : {
1825 : 5714916 : if (argblock)
1826 : : {
1827 : 195359 : rtx arg_reg = argblock;
1828 : 195359 : int i;
1829 : 195359 : poly_int64 arg_offset = 0;
1830 : :
1831 : 195359 : if (GET_CODE (argblock) == PLUS)
1832 : : {
1833 : 0 : arg_reg = XEXP (argblock, 0);
1834 : 0 : arg_offset = rtx_to_poly_int64 (XEXP (argblock, 1));
1835 : : }
1836 : :
1837 : 711579 : for (i = 0; i < num_actuals; i++)
1838 : : {
1839 : 516220 : rtx offset = ARGS_SIZE_RTX (args[i].locate.offset);
1840 : 516220 : rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
1841 : 516220 : rtx addr;
1842 : 516220 : unsigned int align, boundary;
1843 : 516220 : poly_uint64 units_on_stack = 0;
1844 : 516220 : machine_mode partial_mode = VOIDmode;
1845 : :
1846 : : /* Skip this parm if it will not be passed on the stack. */
1847 : 516220 : if (! args[i].pass_on_stack
1848 : 516220 : && args[i].reg != 0
1849 : 452444 : && args[i].partial == 0)
1850 : 516220 : continue;
1851 : :
1852 : 63776 : if (TYPE_EMPTY_P (TREE_TYPE (args[i].tree_value)))
1853 : 262 : continue;
1854 : :
1855 : 63514 : addr = simplify_gen_binary (PLUS, Pmode, arg_reg, offset);
1856 : 63514 : addr = plus_constant (Pmode, addr, arg_offset);
1857 : :
1858 : 63514 : if (args[i].partial != 0)
1859 : : {
1860 : : /* Only part of the parameter is being passed on the stack.
1861 : : Generate a simple memory reference of the correct size. */
1862 : 0 : units_on_stack = args[i].locate.size.constant;
1863 : 0 : poly_uint64 bits_on_stack = units_on_stack * BITS_PER_UNIT;
1864 : 0 : partial_mode = int_mode_for_size (bits_on_stack, 1).else_blk ();
1865 : 0 : args[i].stack = gen_rtx_MEM (partial_mode, addr);
1866 : 0 : set_mem_size (args[i].stack, units_on_stack);
1867 : : }
1868 : : else
1869 : : {
1870 : 63514 : args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1871 : 63514 : set_mem_attributes (args[i].stack,
1872 : 63514 : TREE_TYPE (args[i].tree_value), 1);
1873 : : }
1874 : 63514 : align = BITS_PER_UNIT;
1875 : 63514 : boundary = args[i].locate.boundary;
1876 : 63514 : poly_int64 offset_val;
1877 : 63514 : if (args[i].locate.where_pad != PAD_DOWNWARD)
1878 : : align = boundary;
1879 : 0 : else if (poly_int_rtx_p (offset, &offset_val))
1880 : : {
1881 : 0 : align = least_bit_hwi (boundary);
1882 : 0 : unsigned int offset_align
1883 : 0 : = known_alignment (offset_val) * BITS_PER_UNIT;
1884 : 0 : if (offset_align != 0)
1885 : 0 : align = MIN (align, offset_align);
1886 : : }
1887 : 63514 : set_mem_align (args[i].stack, align);
1888 : :
1889 : 63514 : addr = simplify_gen_binary (PLUS, Pmode, arg_reg, slot_offset);
1890 : 63514 : addr = plus_constant (Pmode, addr, arg_offset);
1891 : :
1892 : 63514 : if (args[i].partial != 0)
1893 : : {
1894 : : /* Only part of the parameter is being passed on the stack.
1895 : : Generate a simple memory reference of the correct size.
1896 : : */
1897 : 0 : args[i].stack_slot = gen_rtx_MEM (partial_mode, addr);
1898 : 0 : set_mem_size (args[i].stack_slot, units_on_stack);
1899 : : }
1900 : : else
1901 : : {
1902 : 63514 : args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1903 : 63514 : set_mem_attributes (args[i].stack_slot,
1904 : 63514 : TREE_TYPE (args[i].tree_value), 1);
1905 : : }
1906 : 63514 : set_mem_align (args[i].stack_slot, args[i].locate.boundary);
1907 : :
1908 : : /* Function incoming arguments may overlap with sibling call
1909 : : outgoing arguments and we cannot allow reordering of reads
1910 : : from function arguments with stores to outgoing arguments
1911 : : of sibling calls. */
1912 : 63514 : set_mem_alias_set (args[i].stack, 0);
1913 : 63514 : set_mem_alias_set (args[i].stack_slot, 0);
1914 : : }
1915 : : }
1916 : 5714916 : }
1917 : :
1918 : : /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1919 : : in a call instruction.
1920 : :
1921 : : FNDECL is the tree node for the target function. For an indirect call
1922 : : FNDECL will be NULL_TREE.
1923 : :
1924 : : ADDR is the operand 0 of CALL_EXPR for this call. */
1925 : :
1926 : : static rtx
1927 : 5714916 : rtx_for_function_call (tree fndecl, tree addr)
1928 : : {
1929 : 5714916 : rtx funexp;
1930 : :
1931 : : /* Get the function to call, in the form of RTL. */
1932 : 5714916 : if (fndecl)
1933 : : {
1934 : 5533726 : if (!TREE_USED (fndecl) && fndecl != current_function_decl)
1935 : 532152 : TREE_USED (fndecl) = 1;
1936 : :
1937 : : /* Get a SYMBOL_REF rtx for the function address. */
1938 : 5533726 : funexp = XEXP (DECL_RTL (fndecl), 0);
1939 : : }
1940 : : else
1941 : : /* Generate an rtx (probably a pseudo-register) for the address. */
1942 : : {
1943 : 181190 : push_temp_slots ();
1944 : 181190 : funexp = expand_normal (addr);
1945 : 181190 : pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1946 : : }
1947 : 5714916 : return funexp;
1948 : : }
1949 : :
1950 : : /* Return the static chain for this function, if any. */
1951 : :
1952 : : rtx
1953 : 14682390 : rtx_for_static_chain (const_tree fndecl_or_type, bool incoming_p)
1954 : : {
1955 : 29364780 : if (DECL_P (fndecl_or_type) && !DECL_STATIC_CHAIN (fndecl_or_type))
1956 : : return NULL;
1957 : :
1958 : 210090 : return targetm.calls.static_chain (fndecl_or_type, incoming_p);
1959 : : }
1960 : :
1961 : : /* Internal state for internal_arg_pointer_based_exp and its helpers. */
1962 : : static struct
1963 : : {
1964 : : /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan,
1965 : : or NULL_RTX if none has been scanned yet. */
1966 : : rtx_insn *scan_start;
1967 : : /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is
1968 : : based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the
1969 : : pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it
1970 : : with fixed offset, or PC if this is with variable or unknown offset. */
1971 : : vec<rtx> cache;
1972 : : } internal_arg_pointer_exp_state;
1973 : :
1974 : : static rtx internal_arg_pointer_based_exp (const_rtx, bool);
1975 : :
1976 : : /* Helper function for internal_arg_pointer_based_exp. Scan insns in
1977 : : the tail call sequence, starting with first insn that hasn't been
1978 : : scanned yet, and note for each pseudo on the LHS whether it is based
1979 : : on crtl->args.internal_arg_pointer or not, and what offset from that
1980 : : that pointer it has. */
1981 : :
1982 : : static void
1983 : 1533 : internal_arg_pointer_based_exp_scan (void)
1984 : : {
1985 : 1533 : rtx_insn *insn, *scan_start = internal_arg_pointer_exp_state.scan_start;
1986 : :
1987 : 1533 : if (scan_start == NULL_RTX)
1988 : 1330 : insn = get_insns ();
1989 : : else
1990 : 203 : insn = NEXT_INSN (scan_start);
1991 : :
1992 : 9405 : while (insn)
1993 : : {
1994 : 7872 : rtx set = single_set (insn);
1995 : 7872 : if (set && REG_P (SET_DEST (set)) && !HARD_REGISTER_P (SET_DEST (set)))
1996 : : {
1997 : 2225 : rtx val = NULL_RTX;
1998 : 2225 : unsigned int idx = REGNO (SET_DEST (set)) - FIRST_PSEUDO_REGISTER;
1999 : : /* Punt on pseudos set multiple times. */
2000 : 2225 : if (idx < internal_arg_pointer_exp_state.cache.length ()
2001 : 0 : && (internal_arg_pointer_exp_state.cache[idx]
2002 : 0 : != NULL_RTX))
2003 : 0 : val = pc_rtx;
2004 : : else
2005 : 2225 : val = internal_arg_pointer_based_exp (SET_SRC (set), false);
2006 : 2225 : if (val != NULL_RTX)
2007 : : {
2008 : 0 : if (idx >= internal_arg_pointer_exp_state.cache.length ())
2009 : 0 : internal_arg_pointer_exp_state.cache
2010 : 0 : .safe_grow_cleared (idx + 1, true);
2011 : 0 : internal_arg_pointer_exp_state.cache[idx] = val;
2012 : : }
2013 : : }
2014 : 7872 : if (NEXT_INSN (insn) == NULL_RTX)
2015 : 1488 : scan_start = insn;
2016 : : insn = NEXT_INSN (insn);
2017 : : }
2018 : :
2019 : 1533 : internal_arg_pointer_exp_state.scan_start = scan_start;
2020 : 1533 : }
2021 : :
2022 : : /* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return
2023 : : NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on
2024 : : it with fixed offset, or PC if this is with variable or unknown offset.
2025 : : TOPLEVEL is true if the function is invoked at the topmost level. */
2026 : :
2027 : : static rtx
2028 : 13696 : internal_arg_pointer_based_exp (const_rtx rtl, bool toplevel)
2029 : : {
2030 : 13696 : if (CONSTANT_P (rtl))
2031 : : return NULL_RTX;
2032 : :
2033 : 13608 : if (rtl == crtl->args.internal_arg_pointer)
2034 : 5382 : return const0_rtx;
2035 : :
2036 : 8226 : if (REG_P (rtl) && HARD_REGISTER_P (rtl))
2037 : : return NULL_RTX;
2038 : :
2039 : 8208 : poly_int64 offset;
2040 : 8208 : if (GET_CODE (rtl) == PLUS && poly_int_rtx_p (XEXP (rtl, 1), &offset))
2041 : : {
2042 : 3323 : rtx val = internal_arg_pointer_based_exp (XEXP (rtl, 0), toplevel);
2043 : 3323 : if (val == NULL_RTX || val == pc_rtx)
2044 : : return val;
2045 : 2774 : return plus_constant (Pmode, val, offset);
2046 : : }
2047 : :
2048 : : /* When called at the topmost level, scan pseudo assignments in between the
2049 : : last scanned instruction in the tail call sequence and the latest insn
2050 : : in that sequence. */
2051 : 4885 : if (toplevel)
2052 : 1533 : internal_arg_pointer_based_exp_scan ();
2053 : :
2054 : 4885 : if (REG_P (rtl))
2055 : : {
2056 : 1930 : unsigned int idx = REGNO (rtl) - FIRST_PSEUDO_REGISTER;
2057 : 2036 : if (idx < internal_arg_pointer_exp_state.cache.length ())
2058 : 0 : return internal_arg_pointer_exp_state.cache[idx];
2059 : :
2060 : : return NULL_RTX;
2061 : : }
2062 : :
2063 : 2955 : subrtx_iterator::array_type array;
2064 : 7926 : FOR_EACH_SUBRTX (iter, array, rtl, NONCONST)
2065 : : {
2066 : 4971 : const_rtx x = *iter;
2067 : 4971 : if (REG_P (x) && internal_arg_pointer_based_exp (x, false) != NULL_RTX)
2068 : 0 : return pc_rtx;
2069 : 4971 : if (MEM_P (x))
2070 : 1806 : iter.skip_subrtxes ();
2071 : : }
2072 : :
2073 : 2955 : return NULL_RTX;
2074 : 2955 : }
2075 : :
2076 : : /* Return true if SIZE bytes starting from address ADDR might overlap an
2077 : : already-clobbered argument area. This function is used to determine
2078 : : if we should give up a sibcall. */
2079 : :
2080 : : static bool
2081 : 18037 : mem_might_overlap_already_clobbered_arg_p (rtx addr, poly_uint64 size)
2082 : : {
2083 : 18037 : poly_int64 i;
2084 : 18037 : unsigned HOST_WIDE_INT start, end;
2085 : 18037 : rtx val;
2086 : :
2087 : 18037 : if (bitmap_empty_p (stored_args_map)
2088 : 18037 : && stored_args_watermark == HOST_WIDE_INT_M1U)
2089 : : return false;
2090 : 6955 : val = internal_arg_pointer_based_exp (addr, true);
2091 : 6955 : if (val == NULL_RTX)
2092 : : return false;
2093 : 5386 : else if (!poly_int_rtx_p (val, &i))
2094 : : return true;
2095 : :
2096 : 5382 : if (known_eq (size, 0U))
2097 : : return false;
2098 : :
2099 : 5382 : if (STACK_GROWS_DOWNWARD)
2100 : 5382 : i -= crtl->args.pretend_args_size;
2101 : : else
2102 : : i += crtl->args.pretend_args_size;
2103 : :
2104 : 5382 : if (ARGS_GROW_DOWNWARD)
2105 : : i = -i - size;
2106 : :
2107 : : /* We can ignore any references to the function's pretend args,
2108 : : which at this point would manifest as negative values of I. */
2109 : 5382 : if (known_le (i, 0) && known_le (size, poly_uint64 (-i)))
2110 : : return false;
2111 : :
2112 : 5382 : start = maybe_lt (i, 0) ? 0 : constant_lower_bound (i);
2113 : 5382 : if (!(i + size).is_constant (&end))
2114 : : end = HOST_WIDE_INT_M1U;
2115 : :
2116 : 5382 : if (end > stored_args_watermark)
2117 : : return true;
2118 : :
2119 : 5382 : end = MIN (end, SBITMAP_SIZE (stored_args_map));
2120 : 30851 : for (unsigned HOST_WIDE_INT k = start; k < end; ++k)
2121 : 25473 : if (bitmap_bit_p (stored_args_map, k))
2122 : : return true;
2123 : :
2124 : : return false;
2125 : : }
2126 : :
2127 : : /* Do the register loads required for any wholly-register parms or any
2128 : : parms which are passed both on the stack and in a register. Their
2129 : : expressions were already evaluated.
2130 : :
2131 : : Mark all register-parms as living through the call, putting these USE
2132 : : insns in the CALL_INSN_FUNCTION_USAGE field.
2133 : :
2134 : : When IS_SIBCALL, perform the check_sibcall_argument_overlap
2135 : : checking, setting *SIBCALL_FAILURE if appropriate. */
2136 : :
2137 : : static void
2138 : 5714916 : load_register_parameters (struct arg_data *args, int num_actuals,
2139 : : rtx *call_fusage, int flags, int is_sibcall,
2140 : : bool *sibcall_failure)
2141 : : {
2142 : 5714916 : int i, j;
2143 : :
2144 : 17595025 : for (i = 0; i < num_actuals; i++)
2145 : : {
2146 : 23760218 : rtx reg = ((flags & ECF_SIBCALL)
2147 : 11880109 : ? args[i].tail_call_reg : args[i].reg);
2148 : 11880109 : if (reg)
2149 : : {
2150 : 9762080 : int partial = args[i].partial;
2151 : 9762080 : int nregs;
2152 : 9762080 : poly_int64 size = 0;
2153 : 9762080 : HOST_WIDE_INT const_size = 0;
2154 : 9762080 : rtx_insn *before_arg = get_last_insn ();
2155 : 9762080 : tree tree_value = args[i].tree_value;
2156 : 9762080 : tree type = TREE_TYPE (tree_value);
2157 : 9762080 : if (RECORD_OR_UNION_TYPE_P (type) && TYPE_TRANSPARENT_AGGR (type))
2158 : 3078 : type = TREE_TYPE (first_field (type));
2159 : : /* Set non-negative if we must move a word at a time, even if
2160 : : just one word (e.g, partial == 4 && mode == DFmode). Set
2161 : : to -1 if we just use a normal move insn. This value can be
2162 : : zero if the argument is a zero size structure. */
2163 : 9762080 : nregs = -1;
2164 : 9762080 : if (GET_CODE (reg) == PARALLEL)
2165 : : ;
2166 : 9488654 : else if (partial)
2167 : : {
2168 : 0 : gcc_assert (partial % UNITS_PER_WORD == 0);
2169 : 0 : nregs = partial / UNITS_PER_WORD;
2170 : : }
2171 : 9488654 : else if (TYPE_MODE (type) == BLKmode)
2172 : : {
2173 : : /* Variable-sized parameters should be described by a
2174 : : PARALLEL instead. */
2175 : 1588 : const_size = int_size_in_bytes (type);
2176 : 1588 : gcc_assert (const_size >= 0);
2177 : 1602 : nregs = (const_size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
2178 : 1588 : size = const_size;
2179 : : }
2180 : : else
2181 : 18974132 : size = GET_MODE_SIZE (args[i].mode);
2182 : :
2183 : : /* Handle calls that pass values in multiple non-contiguous
2184 : : locations. The Irix 6 ABI has examples of this. */
2185 : :
2186 : 9762080 : if (GET_CODE (reg) == PARALLEL)
2187 : 273426 : emit_group_move (reg, args[i].parallel_value);
2188 : :
2189 : : /* If simple case, just do move. If normal partial, store_one_arg
2190 : : has already loaded the register for us. In all other cases,
2191 : : load the register(s) from memory. */
2192 : :
2193 : 9488654 : else if (nregs == -1)
2194 : : {
2195 : 9487066 : emit_move_insn (reg, args[i].value);
2196 : : #ifdef BLOCK_REG_PADDING
2197 : : /* Handle case where we have a value that needs shifting
2198 : : up to the msb. eg. a QImode value and we're padding
2199 : : upward on a BYTES_BIG_ENDIAN machine. */
2200 : : if (args[i].locate.where_pad
2201 : : == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD))
2202 : : {
2203 : : gcc_checking_assert (ordered_p (size, UNITS_PER_WORD));
2204 : : if (maybe_lt (size, UNITS_PER_WORD))
2205 : : {
2206 : : rtx x;
2207 : : poly_int64 shift
2208 : : = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
2209 : :
2210 : : /* Assigning REG here rather than a temp makes
2211 : : CALL_FUSAGE report the whole reg as used.
2212 : : Strictly speaking, the call only uses SIZE
2213 : : bytes at the msb end, but it doesn't seem worth
2214 : : generating rtl to say that. */
2215 : : reg = gen_rtx_REG (word_mode, REGNO (reg));
2216 : : x = expand_shift (LSHIFT_EXPR, word_mode,
2217 : : reg, shift, reg, 1);
2218 : : if (x != reg)
2219 : : emit_move_insn (reg, x);
2220 : : }
2221 : : }
2222 : : #endif
2223 : : }
2224 : :
2225 : : /* If we have pre-computed the values to put in the registers in
2226 : : the case of non-aligned structures, copy them in now. */
2227 : :
2228 : 1588 : else if (args[i].n_aligned_regs != 0)
2229 : 0 : for (j = 0; j < args[i].n_aligned_regs; j++)
2230 : 0 : emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
2231 : 0 : args[i].aligned_regs[j]);
2232 : :
2233 : : /* If we need a single register and the source is a constant
2234 : : VAR_DECL with a simple constructor, expand that constructor
2235 : : via a pseudo rather than read from (possibly misaligned)
2236 : : memory. PR middle-end/95126. */
2237 : 1588 : else if (nregs == 1
2238 : 1588 : && partial == 0
2239 : 1574 : && !args[i].pass_on_stack
2240 : 1574 : && VAR_P (tree_value)
2241 : 1108 : && TREE_READONLY (tree_value)
2242 : 15 : && !TREE_SIDE_EFFECTS (tree_value)
2243 : 1603 : && immediate_const_ctor_p (DECL_INITIAL (tree_value)))
2244 : : {
2245 : 15 : rtx target = gen_reg_rtx (word_mode);
2246 : 15 : store_constructor (DECL_INITIAL (tree_value), target, 0,
2247 : 15 : int_expr_size (DECL_INITIAL (tree_value)),
2248 : : false);
2249 : 15 : reg = gen_rtx_REG (word_mode, REGNO (reg));
2250 : 15 : emit_move_insn (reg, target);
2251 : : }
2252 : 1573 : else if (partial == 0 || args[i].pass_on_stack)
2253 : : {
2254 : : /* SIZE and CONST_SIZE are 0 for partial arguments and
2255 : : the size of a BLKmode type otherwise. */
2256 : 1573 : gcc_checking_assert (known_eq (size, const_size));
2257 : 1573 : rtx mem = validize_mem (copy_rtx (args[i].value));
2258 : :
2259 : : /* Check for overlap with already clobbered argument area,
2260 : : providing that this has non-zero size. */
2261 : 1573 : if (is_sibcall
2262 : 27 : && const_size != 0
2263 : 1600 : && (mem_might_overlap_already_clobbered_arg_p
2264 : 1600 : (XEXP (args[i].value, 0), const_size)))
2265 : 0 : *sibcall_failure = true;
2266 : :
2267 : 1573 : if (const_size % UNITS_PER_WORD == 0
2268 : 2939 : || MEM_ALIGN (mem) % BITS_PER_WORD == 0)
2269 : 317 : move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode);
2270 : : else
2271 : : {
2272 : 1256 : if (nregs > 1)
2273 : 0 : move_block_to_reg (REGNO (reg), mem, nregs - 1,
2274 : : args[i].mode);
2275 : 1256 : rtx dest = gen_rtx_REG (word_mode, REGNO (reg) + nregs - 1);
2276 : 1256 : unsigned int bitoff = (nregs - 1) * BITS_PER_WORD;
2277 : 1256 : unsigned int bitsize = const_size * BITS_PER_UNIT - bitoff;
2278 : 1256 : rtx x = extract_bit_field (mem, bitsize, bitoff, 1, dest,
2279 : : word_mode, word_mode, false,
2280 : : NULL);
2281 : 1256 : if (BYTES_BIG_ENDIAN)
2282 : : x = expand_shift (LSHIFT_EXPR, word_mode, x,
2283 : : BITS_PER_WORD - bitsize, dest, 1);
2284 : 1256 : if (x != dest)
2285 : 1213 : emit_move_insn (dest, x);
2286 : : }
2287 : :
2288 : : /* Handle a BLKmode that needs shifting. */
2289 : : if (nregs == 1 && const_size < UNITS_PER_WORD
2290 : : #ifdef BLOCK_REG_PADDING
2291 : : && args[i].locate.where_pad == PAD_DOWNWARD
2292 : : #else
2293 : : && BYTES_BIG_ENDIAN
2294 : : #endif
2295 : : )
2296 : : {
2297 : : rtx dest = gen_rtx_REG (word_mode, REGNO (reg));
2298 : : int shift = (UNITS_PER_WORD - const_size) * BITS_PER_UNIT;
2299 : : enum tree_code dir = (BYTES_BIG_ENDIAN
2300 : : ? RSHIFT_EXPR : LSHIFT_EXPR);
2301 : : rtx x;
2302 : :
2303 : : x = expand_shift (dir, word_mode, dest, shift, dest, 1);
2304 : : if (x != dest)
2305 : : emit_move_insn (dest, x);
2306 : : }
2307 : : }
2308 : :
2309 : : /* When a parameter is a block, and perhaps in other cases, it is
2310 : : possible that it did a load from an argument slot that was
2311 : : already clobbered. */
2312 : 9762080 : if (is_sibcall
2313 : 9762080 : && check_sibcall_argument_overlap (before_arg, &args[i], false))
2314 : 0 : *sibcall_failure = true;
2315 : :
2316 : : /* Handle calls that pass values in multiple non-contiguous
2317 : : locations. The Irix 6 ABI has examples of this. */
2318 : 9762080 : if (GET_CODE (reg) == PARALLEL)
2319 : 273426 : use_group_regs (call_fusage, reg);
2320 : 9488654 : else if (nregs == -1)
2321 : 9487066 : use_reg_mode (call_fusage, reg, TYPE_MODE (type));
2322 : 1588 : else if (nregs > 0)
2323 : 1574 : use_regs (call_fusage, REGNO (reg), nregs);
2324 : : }
2325 : : }
2326 : 5714916 : }
2327 : :
2328 : : /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
2329 : : wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
2330 : : bytes, then we would need to push some additional bytes to pad the
2331 : : arguments. So, we try to compute an adjust to the stack pointer for an
2332 : : amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
2333 : : bytes. Then, when the arguments are pushed the stack will be perfectly
2334 : : aligned.
2335 : :
2336 : : Return true if this optimization is possible, storing the adjustment
2337 : : in ADJUSTMENT_OUT and setting ARGS_SIZE->CONSTANT to the number of
2338 : : bytes that should be popped after the call. */
2339 : :
2340 : : static bool
2341 : 12890 : combine_pending_stack_adjustment_and_call (poly_int64 *adjustment_out,
2342 : : poly_int64 unadjusted_args_size,
2343 : : struct args_size *args_size,
2344 : : unsigned int preferred_unit_stack_boundary)
2345 : : {
2346 : : /* The number of bytes to pop so that the stack will be
2347 : : under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
2348 : 12890 : poly_int64 adjustment;
2349 : : /* The alignment of the stack after the arguments are pushed, if we
2350 : : just pushed the arguments without adjust the stack here. */
2351 : 12890 : unsigned HOST_WIDE_INT unadjusted_alignment;
2352 : :
2353 : 12890 : if (!known_misalignment (stack_pointer_delta + unadjusted_args_size,
2354 : : preferred_unit_stack_boundary,
2355 : : &unadjusted_alignment))
2356 : : return false;
2357 : :
2358 : : /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
2359 : : as possible -- leaving just enough left to cancel out the
2360 : : UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
2361 : : PENDING_STACK_ADJUST is non-negative, and congruent to
2362 : : -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
2363 : :
2364 : : /* Begin by trying to pop all the bytes. */
2365 : 12890 : unsigned HOST_WIDE_INT tmp_misalignment;
2366 : 12890 : if (!known_misalignment (pending_stack_adjust,
2367 : : preferred_unit_stack_boundary,
2368 : : &tmp_misalignment))
2369 : : return false;
2370 : 12890 : unadjusted_alignment -= tmp_misalignment;
2371 : 12890 : adjustment = pending_stack_adjust;
2372 : : /* Push enough additional bytes that the stack will be aligned
2373 : : after the arguments are pushed. */
2374 : 12890 : if (preferred_unit_stack_boundary > 1 && unadjusted_alignment)
2375 : 12701 : adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
2376 : :
2377 : : /* We need to know whether the adjusted argument size
2378 : : (UNADJUSTED_ARGS_SIZE - ADJUSTMENT) constitutes an allocation
2379 : : or a deallocation. */
2380 : 12890 : if (!ordered_p (adjustment, unadjusted_args_size))
2381 : : return false;
2382 : :
2383 : : /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
2384 : : bytes after the call. The right number is the entire
2385 : : PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
2386 : : by the arguments in the first place. */
2387 : : args_size->constant
2388 : 12890 : = pending_stack_adjust - adjustment + unadjusted_args_size;
2389 : :
2390 : 12890 : *adjustment_out = adjustment;
2391 : 12890 : return true;
2392 : : }
2393 : :
2394 : : /* Scan X expression if it does not dereference any argument slots
2395 : : we already clobbered by tail call arguments (as noted in stored_args_map
2396 : : bitmap).
2397 : : Return true if X expression dereferences such argument slots,
2398 : : false otherwise. */
2399 : :
2400 : : static bool
2401 : 1571779 : check_sibcall_argument_overlap_1 (rtx x)
2402 : : {
2403 : 1571779 : RTX_CODE code;
2404 : 1571779 : int i, j;
2405 : 1571779 : const char *fmt;
2406 : :
2407 : 1571779 : if (x == NULL_RTX)
2408 : : return false;
2409 : :
2410 : 1571779 : code = GET_CODE (x);
2411 : :
2412 : : /* We need not check the operands of the CALL expression itself. */
2413 : 1571779 : if (code == CALL)
2414 : : return false;
2415 : :
2416 : 1449788 : if (code == MEM)
2417 : 17548 : return (mem_might_overlap_already_clobbered_arg_p
2418 : 35096 : (XEXP (x, 0), GET_MODE_SIZE (GET_MODE (x))));
2419 : :
2420 : : /* Scan all subexpressions. */
2421 : 1432240 : fmt = GET_RTX_FORMAT (code);
2422 : 3443283 : for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2423 : : {
2424 : 2011043 : if (*fmt == 'e')
2425 : : {
2426 : 992023 : if (check_sibcall_argument_overlap_1 (XEXP (x, i)))
2427 : : return true;
2428 : : }
2429 : 1019020 : else if (*fmt == 'E')
2430 : : {
2431 : 2077 : for (j = 0; j < XVECLEN (x, i); j++)
2432 : 1382 : if (check_sibcall_argument_overlap_1 (XVECEXP (x, i, j)))
2433 : : return true;
2434 : : }
2435 : : }
2436 : : return false;
2437 : : }
2438 : :
2439 : : /* Scan sequence after INSN if it does not dereference any argument slots
2440 : : we already clobbered by tail call arguments (as noted in stored_args_map
2441 : : bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
2442 : : stored_args_map bitmap afterwards (when ARG is a register
2443 : : MARK_STORED_ARGS_MAP should be false). Return true if sequence after
2444 : : INSN dereferences such argument slots, false otherwise. */
2445 : :
2446 : : static bool
2447 : 345041 : check_sibcall_argument_overlap (rtx_insn *insn, struct arg_data *arg,
2448 : : bool mark_stored_args_map)
2449 : : {
2450 : 345041 : poly_uint64 low, high;
2451 : 345041 : unsigned HOST_WIDE_INT const_low, const_high;
2452 : :
2453 : 345041 : if (insn == NULL_RTX)
2454 : 155348 : insn = get_insns ();
2455 : : else
2456 : 189693 : insn = NEXT_INSN (insn);
2457 : :
2458 : 923415 : for (; insn; insn = NEXT_INSN (insn))
2459 : 578374 : if (INSN_P (insn)
2460 : 578374 : && check_sibcall_argument_overlap_1 (PATTERN (insn)))
2461 : : break;
2462 : :
2463 : 345041 : if (mark_stored_args_map)
2464 : : {
2465 : 9871 : if (ARGS_GROW_DOWNWARD)
2466 : : low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
2467 : : else
2468 : 9871 : low = arg->locate.slot_offset.constant;
2469 : 9871 : high = low + arg->locate.size.constant;
2470 : :
2471 : 9871 : const_low = constant_lower_bound (low);
2472 : 9871 : if (high.is_constant (&const_high))
2473 : 63187 : for (unsigned HOST_WIDE_INT i = const_low; i < const_high; ++i)
2474 : 53316 : bitmap_set_bit (stored_args_map, i);
2475 : : else
2476 : : stored_args_watermark = MIN (stored_args_watermark, const_low);
2477 : : }
2478 : 345041 : return insn != NULL_RTX;
2479 : : }
2480 : :
2481 : : /* Given that a function returns a value of mode MODE at the most
2482 : : significant end of hard register VALUE, shift VALUE left or right
2483 : : as specified by LEFT_P. Return true if some action was needed. */
2484 : :
2485 : : bool
2486 : 0 : shift_return_value (machine_mode mode, bool left_p, rtx value)
2487 : : {
2488 : 0 : gcc_assert (REG_P (value) && HARD_REGISTER_P (value));
2489 : 0 : machine_mode value_mode = GET_MODE (value);
2490 : 0 : poly_int64 shift = GET_MODE_BITSIZE (value_mode) - GET_MODE_BITSIZE (mode);
2491 : :
2492 : 0 : if (known_eq (shift, 0))
2493 : : return false;
2494 : :
2495 : : /* Use ashr rather than lshr for right shifts. This is for the benefit
2496 : : of the MIPS port, which requires SImode values to be sign-extended
2497 : : when stored in 64-bit registers. */
2498 : 0 : if (!force_expand_binop (value_mode, left_p ? ashl_optab : ashr_optab,
2499 : : value, gen_int_shift_amount (value_mode, shift),
2500 : : value, 1, OPTAB_WIDEN))
2501 : 0 : gcc_unreachable ();
2502 : : return true;
2503 : : }
2504 : :
2505 : : /* If X is a likely-spilled register value, copy it to a pseudo
2506 : : register and return that register. Return X otherwise. */
2507 : :
2508 : : static rtx
2509 : 192026 : avoid_likely_spilled_reg (rtx x)
2510 : : {
2511 : 192026 : rtx new_rtx;
2512 : :
2513 : 192026 : if (REG_P (x)
2514 : 192026 : && HARD_REGISTER_P (x)
2515 : 377507 : && targetm.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x))))
2516 : : {
2517 : : /* Make sure that we generate a REG rather than a CONCAT.
2518 : : Moves into CONCATs can need nontrivial instructions,
2519 : : and the whole point of this function is to avoid
2520 : : using the hard register directly in such a situation. */
2521 : 185481 : generating_concat_p = 0;
2522 : 185481 : new_rtx = gen_reg_rtx (GET_MODE (x));
2523 : 185481 : generating_concat_p = 1;
2524 : 185481 : emit_move_insn (new_rtx, x);
2525 : 185481 : return new_rtx;
2526 : : }
2527 : : return x;
2528 : : }
2529 : :
2530 : : /* Helper function for expand_call.
2531 : : Return false is EXP is not implementable as a sibling call. */
2532 : :
2533 : : static bool
2534 : 132081 : can_implement_as_sibling_call_p (tree exp,
2535 : : rtx structure_value_addr,
2536 : : tree funtype,
2537 : : tree fndecl,
2538 : : int flags,
2539 : : tree addr,
2540 : : const args_size &args_size)
2541 : : {
2542 : 132081 : if (!targetm.have_sibcall_epilogue ()
2543 : 132081 : && !targetm.emit_epilogue_for_sibcall)
2544 : : {
2545 : 0 : maybe_complain_about_tail_call (exp, _("machine description does not "
2546 : : "have a sibcall_epilogue "
2547 : : "instruction pattern"));
2548 : 0 : return false;
2549 : : }
2550 : :
2551 : : /* Doing sibling call optimization needs some work, since
2552 : : structure_value_addr can be allocated on the stack.
2553 : : It does not seem worth the effort since few optimizable
2554 : : sibling calls will return a structure. */
2555 : 132081 : if (structure_value_addr != NULL_RTX)
2556 : : {
2557 : 460 : maybe_complain_about_tail_call (exp, _("callee returns a structure"));
2558 : 460 : return false;
2559 : : }
2560 : :
2561 : : /* Check whether the target is able to optimize the call
2562 : : into a sibcall. */
2563 : 131621 : if (!targetm.function_ok_for_sibcall (fndecl, exp))
2564 : : {
2565 : 6236 : maybe_complain_about_tail_call (exp, _("target is not able to optimize "
2566 : : "the call into a sibling call"));
2567 : 6236 : return false;
2568 : : }
2569 : :
2570 : : /* Functions that do not return exactly once may not be sibcall
2571 : : optimized. */
2572 : 125385 : if (flags & ECF_RETURNS_TWICE)
2573 : : {
2574 : 0 : maybe_complain_about_tail_call (exp, _("callee returns twice"));
2575 : 0 : return false;
2576 : : }
2577 : 125617 : if ((flags & ECF_NORETURN) && !CALL_EXPR_MUST_TAIL_CALL (exp))
2578 : : {
2579 : 224 : maybe_complain_about_tail_call (exp, _("callee does not return"));
2580 : 224 : return false;
2581 : : }
2582 : :
2583 : 125161 : if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr))))
2584 : : {
2585 : 1 : maybe_complain_about_tail_call (exp, _("volatile function type"));
2586 : 1 : return false;
2587 : : }
2588 : :
2589 : : /* __sanitizer_cov_trace_pc is supposed to inspect its return address
2590 : : to identify the caller, and therefore should not be tailcalled. */
2591 : 115891 : if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
2592 : 141795 : && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SANITIZER_COV_TRACE_PC)
2593 : : {
2594 : : /* No need for maybe_complain_about_tail_call here:
2595 : : the call is synthesized by the compiler. */
2596 : : return false;
2597 : : }
2598 : :
2599 : : /* If the called function is nested in the current one, it might access
2600 : : some of the caller's arguments, but could clobber them beforehand if
2601 : : the argument areas are shared. */
2602 : 125124 : if (fndecl && decl_function_context (fndecl) == current_function_decl)
2603 : : {
2604 : 121 : maybe_complain_about_tail_call (exp, _("nested function"));
2605 : 121 : return false;
2606 : : }
2607 : :
2608 : : /* If this function requires more stack slots than the current
2609 : : function, we cannot change it into a sibling call.
2610 : : crtl->args.pretend_args_size is not part of the
2611 : : stack allocated by our caller. */
2612 : 125003 : if (maybe_gt (args_size.constant,
2613 : : crtl->args.size - crtl->args.pretend_args_size))
2614 : : {
2615 : 3012 : maybe_complain_about_tail_call (exp, _("callee required more stack "
2616 : : "slots than the caller"));
2617 : 3012 : return false;
2618 : : }
2619 : :
2620 : : /* If the callee pops its own arguments, then it must pop exactly
2621 : : the same number of arguments as the current function. */
2622 : 121991 : if (maybe_ne (targetm.calls.return_pops_args (fndecl, funtype,
2623 : : args_size.constant),
2624 : 243982 : targetm.calls.return_pops_args (current_function_decl,
2625 : 121991 : TREE_TYPE
2626 : : (current_function_decl),
2627 : : crtl->args.size)))
2628 : : {
2629 : 0 : maybe_complain_about_tail_call (exp, _("inconsistent number of"
2630 : : " popped arguments"));
2631 : 0 : return false;
2632 : : }
2633 : :
2634 : 121991 : if (!lang_hooks.decls.ok_for_sibcall (fndecl))
2635 : : {
2636 : 0 : maybe_complain_about_tail_call (exp, _("frontend does not support"
2637 : : " sibling call"));
2638 : 0 : return false;
2639 : : }
2640 : :
2641 : : /* All checks passed. */
2642 : : return true;
2643 : : }
2644 : :
2645 : : /* Update stack alignment when the parameter is passed in the stack
2646 : : since the outgoing parameter requires extra alignment on the calling
2647 : : function side. */
2648 : :
2649 : : static void
2650 : 2221966 : update_stack_alignment_for_call (struct locate_and_pad_arg_data *locate)
2651 : : {
2652 : 2221966 : if (crtl->stack_alignment_needed < locate->boundary)
2653 : 2213 : crtl->stack_alignment_needed = locate->boundary;
2654 : 2221966 : if (crtl->preferred_stack_boundary < locate->boundary)
2655 : 4469 : crtl->preferred_stack_boundary = locate->boundary;
2656 : 2221966 : }
2657 : :
2658 : : /* Generate all the code for a CALL_EXPR exp
2659 : : and return an rtx for its value.
2660 : : Store the value in TARGET (specified as an rtx) if convenient.
2661 : : If the value is stored in TARGET then TARGET is returned.
2662 : : If IGNORE is nonzero, then we ignore the value of the function call. */
2663 : :
2664 : : rtx
2665 : 5714912 : expand_call (tree exp, rtx target, int ignore)
2666 : : {
2667 : : /* Nonzero if we are currently expanding a call. */
2668 : 5714912 : static int currently_expanding_call = 0;
2669 : :
2670 : : /* RTX for the function to be called. */
2671 : 5714912 : rtx funexp;
2672 : : /* Sequence of insns to perform a normal "call". */
2673 : 5714912 : rtx_insn *normal_call_insns = NULL;
2674 : : /* Sequence of insns to perform a tail "call". */
2675 : 5714912 : rtx_insn *tail_call_insns = NULL;
2676 : : /* Data type of the function. */
2677 : 5714912 : tree funtype;
2678 : 5714912 : tree type_arg_types;
2679 : 5714912 : tree rettype;
2680 : : /* Declaration of the function being called,
2681 : : or 0 if the function is computed (not known by name). */
2682 : 5714912 : tree fndecl = 0;
2683 : : /* The type of the function being called. */
2684 : 5714912 : tree fntype;
2685 : 5714912 : bool try_tail_call = CALL_EXPR_TAILCALL (exp);
2686 : : /* tree-tailcall decided not to do tail calls. Error for the musttail case,
2687 : : unfortunately we don't know the reason so it's fairly vague.
2688 : : When tree-tailcall reported an error it already cleared the flag,
2689 : : so this shouldn't really happen unless the
2690 : : the musttail pass gave up walking before finding the call. */
2691 : 5714912 : if (!try_tail_call)
2692 : 5582807 : maybe_complain_about_tail_call (exp, _("other reasons"));
2693 : 5714912 : int pass;
2694 : :
2695 : : /* Register in which non-BLKmode value will be returned,
2696 : : or 0 if no value or if value is BLKmode. */
2697 : 5714912 : rtx valreg;
2698 : : /* Address where we should return a BLKmode value;
2699 : : 0 if value not BLKmode. */
2700 : 5714912 : rtx structure_value_addr = 0;
2701 : : /* Nonzero if that address is being passed by treating it as
2702 : : an extra, implicit first parameter. Otherwise,
2703 : : it is passed by being copied directly into struct_value_rtx. */
2704 : 5714912 : int structure_value_addr_parm = 0;
2705 : : /* Holds the value of implicit argument for the struct value. */
2706 : 5714912 : tree structure_value_addr_value = NULL_TREE;
2707 : : /* Size of aggregate value wanted, or zero if none wanted
2708 : : or if we are using the non-reentrant PCC calling convention
2709 : : or expecting the value in registers. */
2710 : 5714912 : poly_int64 struct_value_size = 0;
2711 : : /* True if called function returns an aggregate in memory PCC style,
2712 : : by returning the address of where to find it. */
2713 : 5714912 : bool pcc_struct_value = false;
2714 : 5714912 : rtx struct_value = 0;
2715 : :
2716 : : /* Number of actual parameters in this call, including struct value addr. */
2717 : 5714912 : int num_actuals;
2718 : : /* Number of named args. Args after this are anonymous ones
2719 : : and they must all go on the stack. */
2720 : 5714912 : int n_named_args;
2721 : : /* Number of complex actual arguments that need to be split. */
2722 : 5714912 : int num_complex_actuals = 0;
2723 : :
2724 : : /* Vector of information about each argument.
2725 : : Arguments are numbered in the order they will be pushed,
2726 : : not the order they are written. */
2727 : 5714912 : struct arg_data *args;
2728 : :
2729 : : /* Total size in bytes of all the stack-parms scanned so far. */
2730 : 5714912 : struct args_size args_size;
2731 : 5714912 : struct args_size adjusted_args_size;
2732 : : /* Size of arguments before any adjustments (such as rounding). */
2733 : 5714912 : poly_int64 unadjusted_args_size;
2734 : : /* Data on reg parms scanned so far. */
2735 : 5714912 : CUMULATIVE_ARGS args_so_far_v;
2736 : 5714912 : cumulative_args_t args_so_far;
2737 : : /* Nonzero if a reg parm has been scanned. */
2738 : 5714912 : int reg_parm_seen;
2739 : :
2740 : : /* True if we must avoid push-insns in the args for this call.
2741 : : If stack space is allocated for register parameters, but not by the
2742 : : caller, then it is preallocated in the fixed part of the stack frame.
2743 : : So the entire argument block must then be preallocated (i.e., we
2744 : : ignore PUSH_ROUNDING in that case). */
2745 : 5714912 : bool must_preallocate = !targetm.calls.push_argument (0);
2746 : :
2747 : : /* Size of the stack reserved for parameter registers. */
2748 : 5714912 : int reg_parm_stack_space = 0;
2749 : :
2750 : : /* Address of space preallocated for stack parms
2751 : : (on machines that lack push insns), or 0 if space not preallocated. */
2752 : 5714912 : rtx argblock = 0;
2753 : :
2754 : : /* Mask of ECF_ and ERF_ flags. */
2755 : 5714912 : int flags = 0;
2756 : 5714912 : int return_flags = 0;
2757 : : #ifdef REG_PARM_STACK_SPACE
2758 : : /* Define the boundary of the register parm stack space that needs to be
2759 : : saved, if any. */
2760 : 5714912 : int low_to_save, high_to_save;
2761 : 5714912 : rtx save_area = 0; /* Place that it is saved */
2762 : : #endif
2763 : :
2764 : 5714912 : unsigned int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2765 : 5714912 : char *initial_stack_usage_map = stack_usage_map;
2766 : 5714912 : unsigned HOST_WIDE_INT initial_stack_usage_watermark = stack_usage_watermark;
2767 : 5714912 : char *stack_usage_map_buf = NULL;
2768 : :
2769 : 5714912 : poly_int64 old_stack_allocated;
2770 : :
2771 : : /* State variables to track stack modifications. */
2772 : 5714912 : rtx old_stack_level = 0;
2773 : 5714912 : int old_stack_arg_under_construction = 0;
2774 : 5714912 : poly_int64 old_pending_adj = 0;
2775 : 5714912 : int old_inhibit_defer_pop = inhibit_defer_pop;
2776 : :
2777 : : /* Some stack pointer alterations we make are performed via
2778 : : allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
2779 : : which we then also need to save/restore along the way. */
2780 : 5714912 : poly_int64 old_stack_pointer_delta = 0;
2781 : :
2782 : 5714912 : rtx call_fusage;
2783 : 5714912 : tree addr = CALL_EXPR_FN (exp);
2784 : 5714912 : int i;
2785 : : /* The alignment of the stack, in bits. */
2786 : 5714912 : unsigned HOST_WIDE_INT preferred_stack_boundary;
2787 : : /* The alignment of the stack, in bytes. */
2788 : 5714912 : unsigned HOST_WIDE_INT preferred_unit_stack_boundary;
2789 : : /* The static chain value to use for this call. */
2790 : 5714912 : rtx static_chain_value;
2791 : : /* See if this is "nothrow" function call. */
2792 : 5714912 : if (TREE_NOTHROW (exp))
2793 : 2010295 : flags |= ECF_NOTHROW;
2794 : :
2795 : : /* See if we can find a DECL-node for the actual function, and get the
2796 : : function attributes (flags) from the function decl or type node. */
2797 : 5714912 : fndecl = get_callee_fndecl (exp);
2798 : 5714912 : if (fndecl)
2799 : : {
2800 : 5533722 : fntype = TREE_TYPE (fndecl);
2801 : 5533722 : flags |= flags_from_decl_or_type (fndecl);
2802 : 5533722 : return_flags |= decl_return_flags (fndecl);
2803 : : }
2804 : : else
2805 : : {
2806 : 181190 : fntype = TREE_TYPE (TREE_TYPE (addr));
2807 : 181190 : flags |= flags_from_decl_or_type (fntype);
2808 : 181190 : if (CALL_EXPR_BY_DESCRIPTOR (exp))
2809 : 0 : flags |= ECF_BY_DESCRIPTOR;
2810 : : }
2811 : 5714912 : rettype = TREE_TYPE (exp);
2812 : :
2813 : 5714912 : struct_value = targetm.calls.struct_value_rtx (fntype, 0);
2814 : :
2815 : : /* Warn if this value is an aggregate type,
2816 : : regardless of which calling convention we are using for it. */
2817 : 5714912 : if (AGGREGATE_TYPE_P (rettype))
2818 : 372500 : warning (OPT_Waggregate_return, "function call has aggregate value");
2819 : :
2820 : : /* If the result of a non looping pure or const function call is
2821 : : ignored (or void), and none of its arguments are volatile, we can
2822 : : avoid expanding the call and just evaluate the arguments for
2823 : : side-effects. */
2824 : 5714912 : if ((flags & (ECF_CONST | ECF_PURE))
2825 : : && (!(flags & ECF_LOOPING_CONST_OR_PURE))
2826 : 444789 : && (flags & ECF_NOTHROW)
2827 : 6113976 : && (ignore || target == const0_rtx
2828 : 399063 : || TYPE_MODE (rettype) == VOIDmode))
2829 : : {
2830 : 1 : bool volatilep = false;
2831 : 1 : tree arg;
2832 : 1 : call_expr_arg_iterator iter;
2833 : :
2834 : 4 : FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2835 : 3 : if (TREE_THIS_VOLATILE (arg))
2836 : : {
2837 : : volatilep = true;
2838 : : break;
2839 : : }
2840 : :
2841 : 1 : if (! volatilep)
2842 : : {
2843 : 0 : FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2844 : 0 : expand_expr (arg, const0_rtx, VOIDmode, EXPAND_NORMAL);
2845 : 0 : return const0_rtx;
2846 : : }
2847 : : }
2848 : :
2849 : : #ifdef REG_PARM_STACK_SPACE
2850 : 11248634 : reg_parm_stack_space = REG_PARM_STACK_SPACE (!fndecl ? fntype : fndecl);
2851 : : #endif
2852 : :
2853 : 4995118 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
2854 : 10673674 : && reg_parm_stack_space > 0 && targetm.calls.push_argument (0))
2855 : 0 : must_preallocate = true;
2856 : :
2857 : : /* Set up a place to return a structure. */
2858 : :
2859 : : /* Cater to broken compilers. */
2860 : 5714912 : if (aggregate_value_p (exp, fntype))
2861 : : {
2862 : : /* This call returns a big structure. */
2863 : 226545 : flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
2864 : :
2865 : : #ifdef PCC_STATIC_STRUCT_RETURN
2866 : : {
2867 : : pcc_struct_value = true;
2868 : : }
2869 : : #else /* not PCC_STATIC_STRUCT_RETURN */
2870 : 226545 : {
2871 : 226545 : if (!poly_int_tree_p (TYPE_SIZE_UNIT (rettype), &struct_value_size))
2872 : 53 : struct_value_size = -1;
2873 : :
2874 : : /* Even if it is semantically safe to use the target as the return
2875 : : slot, it may be not sufficiently aligned for the return type. */
2876 : 226545 : if (CALL_EXPR_RETURN_SLOT_OPT (exp)
2877 : 216790 : && target
2878 : 201876 : && MEM_P (target)
2879 : : /* If rettype is addressable, we may not create a temporary.
2880 : : If target is properly aligned at runtime and the compiler
2881 : : just doesn't know about it, it will work fine, otherwise it
2882 : : will be UB. */
2883 : 372404 : && (TREE_ADDRESSABLE (rettype)
2884 : 120780 : || !(MEM_ALIGN (target) < TYPE_ALIGN (rettype)
2885 : 0 : && targetm.slow_unaligned_access (TYPE_MODE (rettype),
2886 : 0 : MEM_ALIGN (target)))))
2887 : 145859 : structure_value_addr = XEXP (target, 0);
2888 : : else
2889 : : {
2890 : : /* For variable-sized objects, we must be called with a target
2891 : : specified. If we were to allocate space on the stack here,
2892 : : we would have no way of knowing when to free it. */
2893 : 80686 : rtx d = assign_temp (rettype, 1, 1);
2894 : 80686 : structure_value_addr = XEXP (d, 0);
2895 : 80686 : target = 0;
2896 : : }
2897 : : }
2898 : : #endif /* not PCC_STATIC_STRUCT_RETURN */
2899 : : }
2900 : :
2901 : : /* Figure out the amount to which the stack should be aligned. */
2902 : 5714912 : preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2903 : 5714912 : if (fndecl)
2904 : : {
2905 : 5533722 : struct cgraph_rtl_info *i = cgraph_node::rtl_info (fndecl);
2906 : : /* Without automatic stack alignment, we can't increase preferred
2907 : : stack boundary. With automatic stack alignment, it is
2908 : : unnecessary since unless we can guarantee that all callers will
2909 : : align the outgoing stack properly, callee has to align its
2910 : : stack anyway. */
2911 : 5533722 : if (i
2912 : 1286171 : && i->preferred_incoming_stack_boundary
2913 : 932906 : && i->preferred_incoming_stack_boundary < preferred_stack_boundary)
2914 : 300461 : preferred_stack_boundary = i->preferred_incoming_stack_boundary;
2915 : : }
2916 : :
2917 : : /* Operand 0 is a pointer-to-function; get the type of the function. */
2918 : 5714912 : funtype = TREE_TYPE (addr);
2919 : 5714912 : gcc_assert (POINTER_TYPE_P (funtype));
2920 : 5714912 : funtype = TREE_TYPE (funtype);
2921 : :
2922 : : /* Count whether there are actual complex arguments that need to be split
2923 : : into their real and imaginary parts. Munge the type_arg_types
2924 : : appropriately here as well. */
2925 : 5714912 : if (targetm.calls.split_complex_arg)
2926 : : {
2927 : 0 : call_expr_arg_iterator iter;
2928 : 0 : tree arg;
2929 : 0 : FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2930 : : {
2931 : 0 : tree type = TREE_TYPE (arg);
2932 : 0 : if (type && TREE_CODE (type) == COMPLEX_TYPE
2933 : 0 : && targetm.calls.split_complex_arg (type))
2934 : 0 : num_complex_actuals++;
2935 : : }
2936 : 0 : type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype));
2937 : : }
2938 : : else
2939 : 5714912 : type_arg_types = TYPE_ARG_TYPES (funtype);
2940 : :
2941 : 5714912 : if (flags & ECF_MAY_BE_ALLOCA)
2942 : 29 : cfun->calls_alloca = 1;
2943 : :
2944 : : /* If struct_value_rtx is 0, it means pass the address
2945 : : as if it were an extra parameter. Put the argument expression
2946 : : in structure_value_addr_value. */
2947 : 5714912 : if (structure_value_addr && struct_value == 0)
2948 : : {
2949 : : /* If structure_value_addr is a REG other than
2950 : : virtual_outgoing_args_rtx, we can use always use it. If it
2951 : : is not a REG, we must always copy it into a register.
2952 : : If it is virtual_outgoing_args_rtx, we must copy it to another
2953 : : register in some cases. */
2954 : 226545 : rtx temp = (!REG_P (structure_value_addr)
2955 : 2598 : || (ACCUMULATE_OUTGOING_ARGS
2956 : 0 : && stack_arg_under_construction
2957 : 0 : && structure_value_addr == virtual_outgoing_args_rtx)
2958 : 226545 : ? copy_addr_to_reg (convert_memory_address
2959 : : (Pmode, structure_value_addr))
2960 : 226545 : : structure_value_addr);
2961 : :
2962 : 226545 : structure_value_addr_value =
2963 : 226545 : make_tree (build_pointer_type (TREE_TYPE (funtype)), temp);
2964 : 226545 : structure_value_addr_parm = 1;
2965 : : }
2966 : :
2967 : : /* Count the arguments and set NUM_ACTUALS. */
2968 : 5714912 : num_actuals
2969 : 5714912 : = call_expr_nargs (exp) + num_complex_actuals + structure_value_addr_parm;
2970 : :
2971 : : /* Compute number of named args.
2972 : : First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2973 : :
2974 : 5714912 : if (type_arg_types != 0)
2975 : 5693478 : n_named_args
2976 : 5693478 : = (list_length (type_arg_types)
2977 : : /* Count the struct value address, if it is passed as a parm. */
2978 : : + structure_value_addr_parm);
2979 : 21434 : else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype))
2980 : 155 : n_named_args = structure_value_addr_parm;
2981 : : else
2982 : : /* If we know nothing, treat all args as named. */
2983 : : n_named_args = num_actuals;
2984 : :
2985 : : /* Start updating where the next arg would go.
2986 : :
2987 : : On some machines (such as the PA) indirect calls have a different
2988 : : calling convention than normal calls. The fourth argument in
2989 : : INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2990 : : or not. */
2991 : 5714912 : INIT_CUMULATIVE_ARGS (args_so_far_v, funtype, NULL_RTX, fndecl, n_named_args);
2992 : 5714912 : args_so_far = pack_cumulative_args (&args_so_far_v);
2993 : :
2994 : : /* Now possibly adjust the number of named args.
2995 : : Normally, don't include the last named arg if anonymous args follow.
2996 : : We do include the last named arg if
2997 : : targetm.calls.strict_argument_naming() returns nonzero.
2998 : : (If no anonymous args follow, the result of list_length is actually
2999 : : one too large. This is harmless.)
3000 : :
3001 : : If targetm.calls.pretend_outgoing_varargs_named() returns
3002 : : nonzero, and targetm.calls.strict_argument_naming() returns zero,
3003 : : this machine will be able to place unnamed args that were passed
3004 : : in registers into the stack. So treat all args as named. This
3005 : : allows the insns emitting for a specific argument list to be
3006 : : independent of the function declaration.
3007 : :
3008 : : If targetm.calls.pretend_outgoing_varargs_named() returns zero,
3009 : : we do not have any reliable way to pass unnamed args in
3010 : : registers, so we must force them into memory. */
3011 : :
3012 : 21434 : if ((type_arg_types != 0 || TYPE_NO_NAMED_ARGS_STDARG_P (funtype))
3013 : 5715067 : && targetm.calls.strict_argument_naming (args_so_far))
3014 : : ;
3015 : 21279 : else if (type_arg_types != 0
3016 : 21279 : && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far))
3017 : : /* Don't include the last named arg. */
3018 : 0 : --n_named_args;
3019 : 21279 : else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype)
3020 : 21279 : && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far))
3021 : : n_named_args = 0;
3022 : : else
3023 : : /* Treat all args as named. */
3024 : : n_named_args = num_actuals;
3025 : :
3026 : : /* Make a vector to hold all the information about each arg. */
3027 : 5714912 : args = XCNEWVEC (struct arg_data, num_actuals);
3028 : :
3029 : : /* Build up entries in the ARGS array, compute the size of the
3030 : : arguments into ARGS_SIZE, etc. */
3031 : 5714912 : initialize_argument_information (num_actuals, args, &args_size,
3032 : : n_named_args, exp,
3033 : : structure_value_addr_value, fndecl, fntype,
3034 : : args_so_far, reg_parm_stack_space,
3035 : : &old_stack_level, &old_pending_adj,
3036 : : &must_preallocate, &flags,
3037 : 5714912 : &try_tail_call, CALL_FROM_THUNK_P (exp));
3038 : :
3039 : 5714912 : if (args_size.var)
3040 : 0 : must_preallocate = true;
3041 : :
3042 : : /* Now make final decision about preallocating stack space. */
3043 : 5714912 : must_preallocate = finalize_must_preallocate (must_preallocate,
3044 : : num_actuals, args,
3045 : : &args_size);
3046 : :
3047 : : /* If the structure value address will reference the stack pointer, we
3048 : : must stabilize it. We don't need to do this if we know that we are
3049 : : not going to adjust the stack pointer in processing this call. */
3050 : :
3051 : 5714912 : if (structure_value_addr
3052 : 226545 : && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
3053 : 226545 : || reg_mentioned_p (virtual_outgoing_args_rtx,
3054 : : structure_value_addr))
3055 : 5714912 : && (args_size.var
3056 : 0 : || (!ACCUMULATE_OUTGOING_ARGS
3057 : 0 : && maybe_ne (args_size.constant, 0))))
3058 : 0 : structure_value_addr = copy_to_reg (structure_value_addr);
3059 : :
3060 : : /* Tail calls can make things harder to debug, and we've traditionally
3061 : : pushed these optimizations into -O2. Don't try if we're already
3062 : : expanding a call, as that means we're an argument. Don't try if
3063 : : there's cleanups, as we know there's code to follow the call. */
3064 : 5714912 : if (currently_expanding_call++ != 0)
3065 : : {
3066 : 105 : maybe_complain_about_tail_call (exp, _("inside another call"));
3067 : 105 : try_tail_call = 0;
3068 : : }
3069 : 5714912 : if (!flag_optimize_sibling_calls
3070 : 2883299 : && !CALL_FROM_THUNK_P (exp)
3071 : 8597550 : && !CALL_EXPR_MUST_TAIL_CALL (exp))
3072 : 2882360 : try_tail_call = 0;
3073 : 5714912 : if (args_size.var)
3074 : : {
3075 : 0 : maybe_complain_about_tail_call (exp, _("variable size arguments"));
3076 : 0 : try_tail_call = 0;
3077 : : }
3078 : 5714912 : if (dbg_cnt (tail_call) == false)
3079 : 0 : try_tail_call = 0;
3080 : :
3081 : : /* Workaround buggy C/C++ wrappers around Fortran routines with
3082 : : character(len=constant) arguments if the hidden string length arguments
3083 : : are passed on the stack; if the callers forget to pass those arguments,
3084 : : attempting to tail call in such routines leads to stack corruption.
3085 : : Avoid tail calls in functions where at least one such hidden string
3086 : : length argument is passed (partially or fully) on the stack in the
3087 : : caller and the callee needs to pass any arguments on the stack.
3088 : : See PR90329. */
3089 : 5714912 : if (try_tail_call && maybe_ne (args_size.constant, 0))
3090 : 13884 : for (tree arg = DECL_ARGUMENTS (current_function_decl);
3091 : 50400 : arg; arg = DECL_CHAIN (arg))
3092 : 36516 : if (DECL_HIDDEN_STRING_LENGTH (arg) && DECL_INCOMING_RTL (arg))
3093 : : {
3094 : 0 : subrtx_iterator::array_type array;
3095 : 0 : FOR_EACH_SUBRTX (iter, array, DECL_INCOMING_RTL (arg), NONCONST)
3096 : 0 : if (MEM_P (*iter))
3097 : : {
3098 : 0 : try_tail_call = 0;
3099 : 0 : maybe_complain_about_tail_call (exp, _("hidden string length "
3100 : : "argument passed on "
3101 : : "stack"));
3102 : 0 : break;
3103 : : }
3104 : 0 : }
3105 : :
3106 : : /* If the user has marked the function as requiring tail-call
3107 : : optimization, attempt it. */
3108 : 5714912 : if (CALL_EXPR_MUST_TAIL_CALL (exp))
3109 : 551 : try_tail_call = 1;
3110 : :
3111 : : /* Rest of purposes for tail call optimizations to fail. */
3112 : 5714912 : if (try_tail_call)
3113 : 132081 : try_tail_call = can_implement_as_sibling_call_p (exp,
3114 : : structure_value_addr,
3115 : : funtype,
3116 : : fndecl,
3117 : : flags, addr, args_size);
3118 : :
3119 : : /* Check if caller and callee disagree in promotion of function
3120 : : return value. */
3121 : 5714912 : if (try_tail_call)
3122 : : {
3123 : 121991 : machine_mode caller_mode, caller_promoted_mode;
3124 : 121991 : machine_mode callee_mode, callee_promoted_mode;
3125 : 121991 : int caller_unsignedp, callee_unsignedp;
3126 : 121991 : tree caller_res = DECL_RESULT (current_function_decl);
3127 : :
3128 : 121991 : caller_unsignedp = TYPE_UNSIGNED (TREE_TYPE (caller_res));
3129 : 121991 : caller_mode = DECL_MODE (caller_res);
3130 : 121991 : callee_unsignedp = TYPE_UNSIGNED (TREE_TYPE (funtype));
3131 : 121991 : callee_mode = TYPE_MODE (TREE_TYPE (funtype));
3132 : 121991 : caller_promoted_mode
3133 : 121991 : = promote_function_mode (TREE_TYPE (caller_res), caller_mode,
3134 : : &caller_unsignedp,
3135 : 121991 : TREE_TYPE (current_function_decl), 1);
3136 : 121991 : callee_promoted_mode
3137 : 121991 : = promote_function_mode (TREE_TYPE (funtype), callee_mode,
3138 : : &callee_unsignedp,
3139 : : funtype, 1);
3140 : 121991 : if (caller_mode != VOIDmode
3141 : 121991 : && (caller_promoted_mode != callee_promoted_mode
3142 : 23264 : || ((caller_mode != caller_promoted_mode
3143 : 23264 : || callee_mode != callee_promoted_mode)
3144 : 0 : && (caller_unsignedp != callee_unsignedp
3145 : 0 : || partial_subreg_p (caller_mode, callee_mode)))))
3146 : : {
3147 : 0 : try_tail_call = 0;
3148 : 0 : maybe_complain_about_tail_call (exp, _("caller and callee disagree "
3149 : : "in promotion of function "
3150 : : "return value"));
3151 : : }
3152 : : }
3153 : :
3154 : : /* Ensure current function's preferred stack boundary is at least
3155 : : what we need. Stack alignment may also increase preferred stack
3156 : : boundary. */
3157 : 17594981 : for (i = 0; i < num_actuals; i++)
3158 : 11880069 : if (reg_parm_stack_space > 0
3159 : 11801032 : || args[i].reg == 0
3160 : 9695789 : || args[i].partial != 0
3161 : 9695789 : || args[i].pass_on_stack)
3162 : 2184280 : update_stack_alignment_for_call (&args[i].locate);
3163 : 5714912 : if (crtl->preferred_stack_boundary < preferred_stack_boundary)
3164 : 839428 : crtl->preferred_stack_boundary = preferred_stack_boundary;
3165 : : else
3166 : : preferred_stack_boundary = crtl->preferred_stack_boundary;
3167 : :
3168 : 5714912 : preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
3169 : :
3170 : 5714912 : if (flag_callgraph_info)
3171 : 0 : record_final_call (fndecl, EXPR_LOCATION (exp));
3172 : :
3173 : : /* We want to make two insn chains; one for a sibling call, the other
3174 : : for a normal call. We will select one of the two chains after
3175 : : initial RTL generation is complete. */
3176 : 11475898 : for (pass = try_tail_call ? 0 : 1; pass < 2; pass++)
3177 : : {
3178 : 5714916 : bool sibcall_failure = false;
3179 : 5714916 : bool normal_failure = false;
3180 : : /* We want to emit any pending stack adjustments before the tail
3181 : : recursion "call". That way we know any adjustment after the tail
3182 : : recursion call can be ignored if we indeed use the tail
3183 : : call expansion. */
3184 : 5714916 : saved_pending_stack_adjust save;
3185 : 5714916 : rtx_insn *insns, *before_call, *after_args;
3186 : 5714916 : rtx next_arg_reg;
3187 : :
3188 : 5714916 : if (pass == 0)
3189 : : {
3190 : : /* State variables we need to save and restore between
3191 : : iterations. */
3192 : 121991 : save_pending_stack_adjust (&save);
3193 : : }
3194 : 5714916 : if (pass)
3195 : 5592925 : flags &= ~ECF_SIBCALL;
3196 : : else
3197 : 121991 : flags |= ECF_SIBCALL;
3198 : :
3199 : : /* Other state variables that we must reinitialize each time
3200 : : through the loop (that are not initialized by the loop itself). */
3201 : 5714916 : argblock = 0;
3202 : 5714916 : call_fusage = 0;
3203 : :
3204 : : /* Start a new sequence for the normal call case.
3205 : :
3206 : : From this point on, if the sibling call fails, we want to set
3207 : : sibcall_failure instead of continuing the loop. */
3208 : 5714916 : start_sequence ();
3209 : :
3210 : : /* Don't let pending stack adjusts add up to too much.
3211 : : Also, do all pending adjustments now if there is any chance
3212 : : this might be a call to alloca or if we are expanding a sibling
3213 : : call sequence.
3214 : : Also do the adjustments before a throwing call, otherwise
3215 : : exception handling can fail; PR 19225. */
3216 : 5714916 : if (maybe_ge (pending_stack_adjust, 32)
3217 : 5652516 : || (maybe_ne (pending_stack_adjust, 0)
3218 : 136243 : && (flags & ECF_MAY_BE_ALLOCA))
3219 : 5652516 : || (maybe_ne (pending_stack_adjust, 0)
3220 : 136243 : && flag_exceptions && !(flags & ECF_NOTHROW))
3221 : 11262166 : || pass == 0)
3222 : 289091 : do_pending_stack_adjust ();
3223 : :
3224 : : /* Precompute any arguments as needed. */
3225 : 5714916 : if (pass)
3226 : 5592925 : precompute_arguments (num_actuals, args);
3227 : :
3228 : : /* Now we are about to start emitting insns that can be deleted
3229 : : if a libcall is deleted. */
3230 : 5592925 : if (pass && (flags & ECF_MALLOC))
3231 : 103717 : start_sequence ();
3232 : :
3233 : : /* Check the canary value for sibcall or function which doesn't
3234 : : return and could throw. */
3235 : 5592925 : if ((pass == 0
3236 : 5592925 : || ((flags & ECF_NORETURN) != 0 && tree_could_throw_p (exp)))
3237 : 446036 : && crtl->stack_protect_guard
3238 : 19 : && targetm.stack_protect_runtime_enabled_p ())
3239 : 19 : stack_protect_epilogue ();
3240 : :
3241 : 5714916 : adjusted_args_size = args_size;
3242 : : /* Compute the actual size of the argument block required. The variable
3243 : : and constant sizes must be combined, the size may have to be rounded,
3244 : : and there may be a minimum required size. When generating a sibcall
3245 : : pattern, do not round up, since we'll be re-using whatever space our
3246 : : caller provided. */
3247 : 5714916 : unadjusted_args_size
3248 : 11307841 : = compute_argument_block_size (reg_parm_stack_space,
3249 : : &adjusted_args_size,
3250 : : fndecl, fntype,
3251 : : (pass == 0 ? 0
3252 : : : preferred_stack_boundary));
3253 : :
3254 : 5714916 : old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
3255 : :
3256 : : /* The argument block when performing a sibling call is the
3257 : : incoming argument block. */
3258 : 5714916 : if (pass == 0)
3259 : : {
3260 : 121991 : argblock = crtl->args.internal_arg_pointer;
3261 : 121991 : if (STACK_GROWS_DOWNWARD)
3262 : 121991 : argblock
3263 : 121991 : = plus_constant (Pmode, argblock, crtl->args.pretend_args_size);
3264 : : else
3265 : : argblock
3266 : : = plus_constant (Pmode, argblock, -crtl->args.pretend_args_size);
3267 : :
3268 : 121991 : HOST_WIDE_INT map_size = constant_lower_bound (args_size.constant);
3269 : 121991 : stored_args_map = sbitmap_alloc (map_size);
3270 : 121991 : bitmap_clear (stored_args_map);
3271 : 121991 : stored_args_watermark = HOST_WIDE_INT_M1U;
3272 : : }
3273 : :
3274 : : /* If we have no actual push instructions, or shouldn't use them,
3275 : : make space for all args right now. */
3276 : 5592925 : else if (adjusted_args_size.var != 0)
3277 : : {
3278 : 0 : if (old_stack_level == 0)
3279 : : {
3280 : 0 : emit_stack_save (SAVE_BLOCK, &old_stack_level);
3281 : 0 : old_stack_pointer_delta = stack_pointer_delta;
3282 : 0 : old_pending_adj = pending_stack_adjust;
3283 : 0 : pending_stack_adjust = 0;
3284 : : /* stack_arg_under_construction says whether a stack arg is
3285 : : being constructed at the old stack level. Pushing the stack
3286 : : gets a clean outgoing argument block. */
3287 : 0 : old_stack_arg_under_construction = stack_arg_under_construction;
3288 : 0 : stack_arg_under_construction = 0;
3289 : : }
3290 : 0 : argblock = push_block (ARGS_SIZE_RTX (adjusted_args_size), 0, 0);
3291 : 0 : if (flag_stack_usage_info)
3292 : 0 : current_function_has_unbounded_dynamic_stack_size = 1;
3293 : : }
3294 : : else
3295 : : {
3296 : : /* Note that we must go through the motions of allocating an argument
3297 : : block even if the size is zero because we may be storing args
3298 : : in the area reserved for register arguments, which may be part of
3299 : : the stack frame. */
3300 : :
3301 : 5592925 : poly_int64 needed = adjusted_args_size.constant;
3302 : :
3303 : : /* Store the maximum argument space used. It will be pushed by
3304 : : the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
3305 : : checking). */
3306 : :
3307 : 5592925 : crtl->outgoing_args_size = upper_bound (crtl->outgoing_args_size,
3308 : : needed);
3309 : :
3310 : 5592925 : if (must_preallocate)
3311 : : {
3312 : 73368 : if (ACCUMULATE_OUTGOING_ARGS)
3313 : : {
3314 : : /* Since the stack pointer will never be pushed, it is
3315 : : possible for the evaluation of a parm to clobber
3316 : : something we have already written to the stack.
3317 : : Since most function calls on RISC machines do not use
3318 : : the stack, this is uncommon, but must work correctly.
3319 : :
3320 : : Therefore, we save any area of the stack that was already
3321 : : written and that we are using. Here we set up to do this
3322 : : by making a new stack usage map from the old one. The
3323 : : actual save will be done by store_one_arg.
3324 : :
3325 : : Another approach might be to try to reorder the argument
3326 : : evaluations to avoid this conflicting stack usage. */
3327 : :
3328 : : /* Since we will be writing into the entire argument area,
3329 : : the map must be allocated for its entire size, not just
3330 : : the part that is the responsibility of the caller. */
3331 : 73362 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
3332 : 67397 : needed += reg_parm_stack_space;
3333 : :
3334 : 73362 : poly_int64 limit = needed;
3335 : 73362 : if (ARGS_GROW_DOWNWARD)
3336 : : limit += 1;
3337 : :
3338 : : /* For polynomial sizes, this is the maximum possible
3339 : : size needed for arguments with a constant size
3340 : : and offset. */
3341 : 73362 : HOST_WIDE_INT const_limit = constant_lower_bound (limit);
3342 : 73362 : highest_outgoing_arg_in_use
3343 : 73362 : = MAX (initial_highest_arg_in_use, const_limit);
3344 : :
3345 : 73362 : free (stack_usage_map_buf);
3346 : 73362 : stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
3347 : 73362 : stack_usage_map = stack_usage_map_buf;
3348 : :
3349 : 73362 : if (initial_highest_arg_in_use)
3350 : 0 : memcpy (stack_usage_map, initial_stack_usage_map,
3351 : : initial_highest_arg_in_use);
3352 : :
3353 : 73362 : if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3354 : 17653 : memset (&stack_usage_map[initial_highest_arg_in_use], 0,
3355 : : (highest_outgoing_arg_in_use
3356 : 17653 : - initial_highest_arg_in_use));
3357 : 73362 : needed = 0;
3358 : :
3359 : : /* The address of the outgoing argument list must not be
3360 : : copied to a register here, because argblock would be left
3361 : : pointing to the wrong place after the call to
3362 : : allocate_dynamic_stack_space below. */
3363 : :
3364 : 73362 : argblock = virtual_outgoing_args_rtx;
3365 : : }
3366 : : else
3367 : : {
3368 : : /* Try to reuse some or all of the pending_stack_adjust
3369 : : to get this space. */
3370 : 6 : if (inhibit_defer_pop == 0
3371 : 12 : && (combine_pending_stack_adjustment_and_call
3372 : 6 : (&needed,
3373 : : unadjusted_args_size,
3374 : : &adjusted_args_size,
3375 : : preferred_unit_stack_boundary)))
3376 : : {
3377 : : /* combine_pending_stack_adjustment_and_call computes
3378 : : an adjustment before the arguments are allocated.
3379 : : Account for them and see whether or not the stack
3380 : : needs to go up or down. */
3381 : 6 : needed = unadjusted_args_size - needed;
3382 : :
3383 : : /* Checked by
3384 : : combine_pending_stack_adjustment_and_call. */
3385 : 6 : gcc_checking_assert (ordered_p (needed, 0));
3386 : 6 : if (maybe_lt (needed, 0))
3387 : : {
3388 : : /* We're releasing stack space. */
3389 : : /* ??? We can avoid any adjustment at all if we're
3390 : : already aligned. FIXME. */
3391 : 0 : pending_stack_adjust = -needed;
3392 : 0 : do_pending_stack_adjust ();
3393 : 0 : needed = 0;
3394 : : }
3395 : : else
3396 : : /* We need to allocate space. We'll do that in
3397 : : push_block below. */
3398 : 6 : pending_stack_adjust = 0;
3399 : : }
3400 : :
3401 : : /* Special case this because overhead of `push_block' in
3402 : : this case is non-trivial. */
3403 : 6 : if (known_eq (needed, 0))
3404 : 4 : argblock = virtual_outgoing_args_rtx;
3405 : : else
3406 : : {
3407 : 2 : rtx needed_rtx = gen_int_mode (needed, Pmode);
3408 : 2 : argblock = push_block (needed_rtx, 0, 0);
3409 : 2 : if (ARGS_GROW_DOWNWARD)
3410 : : argblock = plus_constant (Pmode, argblock, needed);
3411 : : }
3412 : :
3413 : : /* We only really need to call `copy_to_reg' in the case
3414 : : where push insns are going to be used to pass ARGBLOCK
3415 : : to a function call in ARGS. In that case, the stack
3416 : : pointer changes value from the allocation point to the
3417 : : call point, and hence the value of
3418 : : VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
3419 : : as well always do it. */
3420 : 6 : argblock = copy_to_reg (argblock);
3421 : : }
3422 : : }
3423 : : }
3424 : :
3425 : 5714916 : if (ACCUMULATE_OUTGOING_ARGS)
3426 : : {
3427 : : /* The save/restore code in store_one_arg handles all
3428 : : cases except one: a constructor call (including a C
3429 : : function returning a BLKmode struct) to initialize
3430 : : an argument. */
3431 : 74548 : if (stack_arg_under_construction)
3432 : : {
3433 : 0 : rtx push_size
3434 : : = (gen_int_mode
3435 : 0 : (adjusted_args_size.constant
3436 : 0 : + (OUTGOING_REG_PARM_STACK_SPACE (!fndecl ? fntype
3437 : : : TREE_TYPE (fndecl))
3438 : 0 : ? 0 : reg_parm_stack_space), Pmode));
3439 : 0 : if (old_stack_level == 0)
3440 : : {
3441 : 0 : emit_stack_save (SAVE_BLOCK, &old_stack_level);
3442 : 0 : old_stack_pointer_delta = stack_pointer_delta;
3443 : 0 : old_pending_adj = pending_stack_adjust;
3444 : 0 : pending_stack_adjust = 0;
3445 : : /* stack_arg_under_construction says whether a stack
3446 : : arg is being constructed at the old stack level.
3447 : : Pushing the stack gets a clean outgoing argument
3448 : : block. */
3449 : 0 : old_stack_arg_under_construction
3450 : 0 : = stack_arg_under_construction;
3451 : 0 : stack_arg_under_construction = 0;
3452 : : /* Make a new map for the new argument list. */
3453 : 0 : free (stack_usage_map_buf);
3454 : 0 : stack_usage_map_buf = XCNEWVEC (char, highest_outgoing_arg_in_use);
3455 : 0 : stack_usage_map = stack_usage_map_buf;
3456 : 0 : highest_outgoing_arg_in_use = 0;
3457 : 0 : stack_usage_watermark = HOST_WIDE_INT_M1U;
3458 : : }
3459 : : /* We can pass TRUE as the 4th argument because we just
3460 : : saved the stack pointer and will restore it right after
3461 : : the call. */
3462 : 0 : allocate_dynamic_stack_space (push_size, 0, BIGGEST_ALIGNMENT,
3463 : : -1, true);
3464 : : }
3465 : :
3466 : : /* If argument evaluation might modify the stack pointer,
3467 : : copy the address of the argument list to a register. */
3468 : 368915 : for (i = 0; i < num_actuals; i++)
3469 : 294367 : if (args[i].pass_on_stack)
3470 : : {
3471 : 0 : argblock = copy_addr_to_reg (argblock);
3472 : 0 : break;
3473 : : }
3474 : : }
3475 : :
3476 : 5714916 : compute_argument_addresses (args, argblock, num_actuals);
3477 : :
3478 : : /* Stack is properly aligned, pops can't safely be deferred during
3479 : : the evaluation of the arguments. */
3480 : 5714916 : NO_DEFER_POP;
3481 : :
3482 : : /* Precompute all register parameters. It isn't safe to compute
3483 : : anything once we have started filling any specific hard regs.
3484 : : TLS symbols sometimes need a call to resolve. Precompute
3485 : : register parameters before any stack pointer manipulation
3486 : : to avoid unaligned stack in the called function. */
3487 : 5714916 : precompute_register_parameters (num_actuals, args, ®_parm_seen);
3488 : :
3489 : 5714916 : OK_DEFER_POP;
3490 : :
3491 : : /* Perform stack alignment before the first push (the last arg). */
3492 : 5714916 : if (argblock == 0
3493 : 5519557 : && maybe_gt (adjusted_args_size.constant, reg_parm_stack_space)
3494 : 6608105 : && maybe_ne (adjusted_args_size.constant, unadjusted_args_size))
3495 : : {
3496 : : /* When the stack adjustment is pending, we get better code
3497 : : by combining the adjustments. */
3498 : 715606 : if (maybe_ne (pending_stack_adjust, 0)
3499 : 12884 : && ! inhibit_defer_pop
3500 : 728490 : && (combine_pending_stack_adjustment_and_call
3501 : 12884 : (&pending_stack_adjust,
3502 : : unadjusted_args_size,
3503 : : &adjusted_args_size,
3504 : : preferred_unit_stack_boundary)))
3505 : 12884 : do_pending_stack_adjust ();
3506 : 702722 : else if (argblock == 0)
3507 : 702722 : anti_adjust_stack (gen_int_mode (adjusted_args_size.constant
3508 : : - unadjusted_args_size,
3509 : 702722 : Pmode));
3510 : : }
3511 : : /* Now that the stack is properly aligned, pops can't safely
3512 : : be deferred during the evaluation of the arguments. */
3513 : 5714916 : NO_DEFER_POP;
3514 : :
3515 : : /* Record the maximum pushed stack space size. We need to delay
3516 : : doing it this far to take into account the optimization done
3517 : : by combine_pending_stack_adjustment_and_call. */
3518 : 5714916 : if (flag_stack_usage_info
3519 : 1003 : && !ACCUMULATE_OUTGOING_ARGS
3520 : 1003 : && pass
3521 : 5715919 : && adjusted_args_size.var == 0)
3522 : : {
3523 : : poly_int64 pushed = (adjusted_args_size.constant
3524 : 1003 : + pending_stack_adjust);
3525 : 1003 : current_function_pushed_stack_size
3526 : 2006 : = upper_bound (current_function_pushed_stack_size, pushed);
3527 : : }
3528 : :
3529 : 5714916 : funexp = rtx_for_function_call (fndecl, addr);
3530 : :
3531 : 5714916 : if (CALL_EXPR_STATIC_CHAIN (exp))
3532 : 37536 : static_chain_value = expand_normal (CALL_EXPR_STATIC_CHAIN (exp));
3533 : : else
3534 : : static_chain_value = 0;
3535 : :
3536 : : #ifdef REG_PARM_STACK_SPACE
3537 : : /* Save the fixed argument area if it's part of the caller's frame and
3538 : : is clobbered by argument setup for this call. */
3539 : 5714916 : if (ACCUMULATE_OUTGOING_ARGS && pass)
3540 : 73362 : save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
3541 : : &low_to_save, &high_to_save);
3542 : : #endif
3543 : :
3544 : : /* Now store (and compute if necessary) all non-register parms.
3545 : : These come before register parms, since they can require block-moves,
3546 : : which could clobber the registers used for register parms.
3547 : : Parms which have partial registers are not stored here,
3548 : : but we do preallocate space here if they want that. */
3549 : :
3550 : 17595025 : for (i = 0; i < num_actuals; i++)
3551 : : {
3552 : 11880109 : if (args[i].reg == 0 || args[i].pass_on_stack)
3553 : : {
3554 : 2118029 : rtx_insn *before_arg = get_last_insn ();
3555 : :
3556 : : /* We don't allow passing huge (> 2^30 B) arguments
3557 : : by value. It would cause an overflow later on. */
3558 : 2118029 : if (constant_lower_bound (adjusted_args_size.constant)
3559 : : >= (1 << (HOST_BITS_PER_INT - 2)))
3560 : : {
3561 : 6 : sorry ("passing too large argument on stack");
3562 : : /* Don't worry about stack clean-up. */
3563 : 6 : if (pass == 0)
3564 : 0 : sibcall_failure = true;
3565 : : else
3566 : : normal_failure = true;
3567 : 6 : continue;
3568 : : }
3569 : :
3570 : 2118023 : if (store_one_arg (&args[i], argblock, flags,
3571 : 2118023 : adjusted_args_size.var != 0,
3572 : : reg_parm_stack_space)
3573 : 2118023 : || (pass == 0
3574 : 9871 : && check_sibcall_argument_overlap (before_arg,
3575 : : &args[i], true)))
3576 : 4 : sibcall_failure = true;
3577 : : }
3578 : :
3579 : 11880103 : if (args[i].stack)
3580 : 63514 : call_fusage
3581 : 63514 : = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
3582 : : gen_rtx_USE (VOIDmode, args[i].stack),
3583 : : call_fusage);
3584 : : }
3585 : :
3586 : : /* If we have a parm that is passed in registers but not in memory
3587 : : and whose alignment does not permit a direct copy into registers,
3588 : : make a group of pseudos that correspond to each register that we
3589 : : will later fill. */
3590 : 5714916 : if (STRICT_ALIGNMENT)
3591 : : store_unaligned_arguments_into_pseudos (args, num_actuals);
3592 : :
3593 : : /* Now store any partially-in-registers parm.
3594 : : This is the last place a block-move can happen. */
3595 : 5714916 : if (reg_parm_seen)
3596 : 14635242 : for (i = 0; i < num_actuals; i++)
3597 : 10390767 : if (args[i].partial != 0 && ! args[i].pass_on_stack)
3598 : : {
3599 : 0 : rtx_insn *before_arg = get_last_insn ();
3600 : :
3601 : : /* On targets with weird calling conventions (e.g. PA) it's
3602 : : hard to ensure that all cases of argument overlap between
3603 : : stack and registers work. Play it safe and bail out. */
3604 : 0 : if (ARGS_GROW_DOWNWARD && !STACK_GROWS_DOWNWARD)
3605 : : {
3606 : : sibcall_failure = true;
3607 : : break;
3608 : : }
3609 : :
3610 : 0 : if (store_one_arg (&args[i], argblock, flags,
3611 : 0 : adjusted_args_size.var != 0,
3612 : : reg_parm_stack_space)
3613 : 0 : || (pass == 0
3614 : 0 : && check_sibcall_argument_overlap (before_arg,
3615 : : &args[i], true)))
3616 : 0 : sibcall_failure = true;
3617 : : }
3618 : :
3619 : : /* Set up the next argument register. For sibling calls on machines
3620 : : with register windows this should be the incoming register. */
3621 : 5714916 : if (pass == 0)
3622 : 121991 : next_arg_reg = targetm.calls.function_incoming_arg
3623 : 121991 : (args_so_far, function_arg_info::end_marker ());
3624 : : else
3625 : 5592925 : next_arg_reg = targetm.calls.function_arg
3626 : 5592925 : (args_so_far, function_arg_info::end_marker ());
3627 : :
3628 : 5714916 : targetm.calls.start_call_args (args_so_far);
3629 : :
3630 : 5714916 : bool any_regs = false;
3631 : 23309941 : for (i = 0; i < num_actuals; i++)
3632 : 11880109 : if (args[i].reg != NULL_RTX)
3633 : : {
3634 : 9762080 : any_regs = true;
3635 : 9762080 : targetm.calls.call_args (args_so_far, args[i].reg, funtype);
3636 : : }
3637 : 5714916 : if (!any_regs)
3638 : 1470441 : targetm.calls.call_args (args_so_far, pc_rtx, funtype);
3639 : :
3640 : : /* Figure out the register where the value, if any, will come back. */
3641 : 5714916 : valreg = 0;
3642 : 5714916 : if (TYPE_MODE (rettype) != VOIDmode
3643 : 5714916 : && ! structure_value_addr)
3644 : : {
3645 : 2295979 : if (pcc_struct_value)
3646 : : valreg = hard_function_value (build_pointer_type (rettype),
3647 : : fndecl, NULL, (pass == 0));
3648 : : else
3649 : 2295979 : valreg = hard_function_value (rettype, fndecl, fntype,
3650 : : (pass == 0));
3651 : :
3652 : : /* If VALREG is a PARALLEL whose first member has a zero
3653 : : offset, use that. This is for targets such as m68k that
3654 : : return the same value in multiple places. */
3655 : 2295979 : if (GET_CODE (valreg) == PARALLEL)
3656 : : {
3657 : 10545 : rtx elem = XVECEXP (valreg, 0, 0);
3658 : 10545 : rtx where = XEXP (elem, 0);
3659 : 10545 : rtx offset = XEXP (elem, 1);
3660 : 10545 : if (offset == const0_rtx
3661 : 10528 : && GET_MODE (where) == GET_MODE (valreg))
3662 : 5714916 : valreg = where;
3663 : : }
3664 : : }
3665 : :
3666 : : /* If register arguments require space on the stack and stack space
3667 : : was not preallocated, allocate stack space here for arguments
3668 : : passed in registers. */
3669 : 4995118 : if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
3670 : 36356 : && !ACCUMULATE_OUTGOING_ARGS
3671 : 5744155 : && !must_preallocate && reg_parm_stack_space > 0)
3672 : 29239 : anti_adjust_stack (GEN_INT (reg_parm_stack_space));
3673 : :
3674 : : /* Pass the function the address in which to return a
3675 : : structure value. */
3676 : 5714916 : if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
3677 : : {
3678 : 0 : structure_value_addr
3679 : 0 : = convert_memory_address (Pmode, structure_value_addr);
3680 : 0 : emit_move_insn (struct_value,
3681 : 0 : force_reg (Pmode,
3682 : : force_operand (structure_value_addr,
3683 : : NULL_RTX)));
3684 : :
3685 : 0 : if (REG_P (struct_value))
3686 : 0 : use_reg (&call_fusage, struct_value);
3687 : : }
3688 : :
3689 : 5714916 : after_args = get_last_insn ();
3690 : 5896106 : funexp = prepare_call_address (fndecl ? fndecl : fntype, funexp,
3691 : : static_chain_value, &call_fusage,
3692 : : reg_parm_seen, flags);
3693 : :
3694 : 5714916 : load_register_parameters (args, num_actuals, &call_fusage, flags,
3695 : : pass == 0, &sibcall_failure);
3696 : :
3697 : : /* Save a pointer to the last insn before the call, so that we can
3698 : : later safely search backwards to find the CALL_INSN. */
3699 : 5714916 : before_call = get_last_insn ();
3700 : :
3701 : 5714916 : if (pass == 1 && (return_flags & ERF_RETURNS_ARG))
3702 : : {
3703 : 126323 : int arg_nr = return_flags & ERF_RETURN_ARG_MASK;
3704 : 126323 : arg_nr = num_actuals - arg_nr - 1;
3705 : 126323 : if (arg_nr >= 0
3706 : 126323 : && arg_nr < num_actuals
3707 : 126317 : && args[arg_nr].reg
3708 : 121369 : && valreg
3709 : 118876 : && REG_P (valreg)
3710 : 118876 : && GET_MODE (args[arg_nr].reg) == GET_MODE (valreg))
3711 : 118876 : call_fusage
3712 : 118876 : = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[arg_nr].tree_value)),
3713 : : gen_rtx_SET (valreg, args[arg_nr].reg),
3714 : : call_fusage);
3715 : : }
3716 : : /* All arguments and registers used for the call must be set up by
3717 : : now! */
3718 : :
3719 : : /* Stack must be properly aligned now. */
3720 : 11307841 : gcc_assert (!pass
3721 : : || multiple_p (stack_pointer_delta,
3722 : : preferred_unit_stack_boundary));
3723 : :
3724 : : /* Generate the actual call instruction. */
3725 : 5714916 : emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,
3726 : : adjusted_args_size.constant, struct_value_size,
3727 : : next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
3728 : : flags, args_so_far);
3729 : :
3730 : 5714916 : if (flag_ipa_ra)
3731 : : {
3732 : 4157402 : rtx_call_insn *last;
3733 : 4157402 : rtx datum = NULL_RTX;
3734 : 4157402 : if (fndecl != NULL_TREE)
3735 : : {
3736 : 4006813 : datum = XEXP (DECL_RTL (fndecl), 0);
3737 : 4006813 : gcc_assert (datum != NULL_RTX
3738 : : && GET_CODE (datum) == SYMBOL_REF);
3739 : : }
3740 : 4157402 : last = last_call_insn ();
3741 : 4157402 : add_reg_note (last, REG_CALL_DECL, datum);
3742 : : }
3743 : :
3744 : : /* If the call setup or the call itself overlaps with anything
3745 : : of the argument setup we probably clobbered our call address.
3746 : : In that case we can't do sibcalls. */
3747 : 5714916 : if (pass == 0
3748 : 5714916 : && check_sibcall_argument_overlap (after_args, 0, false))
3749 : 0 : sibcall_failure = true;
3750 : :
3751 : : /* If a non-BLKmode value is returned at the most significant end
3752 : : of a register, shift the register right by the appropriate amount
3753 : : and update VALREG accordingly. BLKmode values are handled by the
3754 : : group load/store machinery below. */
3755 : 5714916 : if (!structure_value_addr
3756 : : && !pcc_struct_value
3757 : 5488371 : && TYPE_MODE (rettype) != VOIDmode
3758 : 2295979 : && TYPE_MODE (rettype) != BLKmode
3759 : 2293344 : && REG_P (valreg)
3760 : 7999275 : && targetm.calls.return_in_msb (rettype))
3761 : : {
3762 : 0 : if (shift_return_value (TYPE_MODE (rettype), false, valreg))
3763 : 0 : sibcall_failure = true;
3764 : 0 : valreg = gen_rtx_REG (TYPE_MODE (rettype), REGNO (valreg));
3765 : : }
3766 : :
3767 : 5714916 : if (pass && (flags & ECF_MALLOC))
3768 : : {
3769 : 103717 : rtx temp = gen_reg_rtx (GET_MODE (valreg));
3770 : 103717 : rtx_insn *last, *insns;
3771 : :
3772 : : /* The return value from a malloc-like function is a pointer. */
3773 : 103717 : if (TREE_CODE (rettype) == POINTER_TYPE)
3774 : 107512 : mark_reg_pointer (temp, MALLOC_ABI_ALIGNMENT);
3775 : :
3776 : 103717 : emit_move_insn (temp, valreg);
3777 : :
3778 : : /* The return value from a malloc-like function cannot alias
3779 : : anything else. */
3780 : 103717 : last = get_last_insn ();
3781 : 103717 : add_reg_note (last, REG_NOALIAS, temp);
3782 : :
3783 : : /* Write out the sequence. */
3784 : 103717 : insns = get_insns ();
3785 : 103717 : end_sequence ();
3786 : 103717 : emit_insn (insns);
3787 : 103717 : valreg = temp;
3788 : : }
3789 : :
3790 : : /* For calls to `setjmp', etc., inform
3791 : : function.cc:setjmp_warnings that it should complain if
3792 : : nonvolatile values are live. For functions that cannot
3793 : : return, inform flow that control does not fall through. */
3794 : :
3795 : 5714916 : if ((flags & ECF_NORETURN) || pass == 0)
3796 : : {
3797 : : /* The barrier must be emitted
3798 : : immediately after the CALL_INSN. Some ports emit more
3799 : : than just a CALL_INSN above, so we must search for it here. */
3800 : :
3801 : 863073 : rtx_insn *last = get_last_insn ();
3802 : 863183 : while (!CALL_P (last))
3803 : : {
3804 : 110 : last = PREV_INSN (last);
3805 : : /* There was no CALL_INSN? */
3806 : 110 : gcc_assert (last != before_call);
3807 : : }
3808 : :
3809 : 863073 : emit_barrier_after (last);
3810 : :
3811 : : /* Stack adjustments after a noreturn call are dead code.
3812 : : However when NO_DEFER_POP is in effect, we must preserve
3813 : : stack_pointer_delta. */
3814 : 863073 : if (inhibit_defer_pop == 0)
3815 : : {
3816 : 863073 : stack_pointer_delta = old_stack_allocated;
3817 : 863073 : pending_stack_adjust = 0;
3818 : : }
3819 : : }
3820 : :
3821 : : /* If value type not void, return an rtx for the value. */
3822 : :
3823 : 5714916 : if (TYPE_MODE (rettype) == VOIDmode
3824 : 5714916 : || ignore)
3825 : 3822879 : target = const0_rtx;
3826 : 1892037 : else if (structure_value_addr)
3827 : : {
3828 : 205685 : if (target == 0 || !MEM_P (target))
3829 : : {
3830 : 59826 : target
3831 : 59826 : = gen_rtx_MEM (TYPE_MODE (rettype),
3832 : 59826 : memory_address (TYPE_MODE (rettype),
3833 : : structure_value_addr));
3834 : 59826 : set_mem_attributes (target, rettype, 1);
3835 : : }
3836 : : }
3837 : 1686352 : else if (pcc_struct_value)
3838 : : {
3839 : : /* This is the special C++ case where we need to
3840 : : know what the true target was. We take care to
3841 : : never use this value more than once in one expression. */
3842 : : target = gen_rtx_MEM (TYPE_MODE (rettype),
3843 : : copy_to_reg (valreg));
3844 : : set_mem_attributes (target, rettype, 1);
3845 : : }
3846 : : /* Handle calls that return values in multiple non-contiguous locations.
3847 : : The Irix 6 ABI has examples of this. */
3848 : 1686352 : else if (GET_CODE (valreg) == PARALLEL)
3849 : : {
3850 : 10319 : if (target == 0)
3851 : 1922 : target = emit_group_move_into_temps (valreg);
3852 : 8397 : else if (rtx_equal_p (target, valreg))
3853 : : ;
3854 : 8397 : else if (GET_CODE (target) == PARALLEL)
3855 : : /* Handle the result of a emit_group_move_into_temps
3856 : : call in the previous pass. */
3857 : 0 : emit_group_move (target, valreg);
3858 : : else
3859 : 8397 : emit_group_store (target, valreg, rettype,
3860 : 8397 : int_size_in_bytes (rettype));
3861 : : }
3862 : 1676033 : else if (target
3863 : 1531232 : && GET_MODE (target) == TYPE_MODE (rettype)
3864 : 3207265 : && GET_MODE (target) == GET_MODE (valreg))
3865 : : {
3866 : 1531229 : bool may_overlap = false;
3867 : :
3868 : : /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
3869 : : reg to a plain register. */
3870 : 1531229 : if (!REG_P (target) || HARD_REGISTER_P (target))
3871 : 47222 : valreg = avoid_likely_spilled_reg (valreg);
3872 : :
3873 : : /* If TARGET is a MEM in the argument area, and we have
3874 : : saved part of the argument area, then we can't store
3875 : : directly into TARGET as it may get overwritten when we
3876 : : restore the argument save area below. Don't work too
3877 : : hard though and simply force TARGET to a register if it
3878 : : is a MEM; the optimizer is quite likely to sort it out. */
3879 : 1531229 : if (ACCUMULATE_OUTGOING_ARGS && pass && MEM_P (target))
3880 : 1063 : for (i = 0; i < num_actuals; i++)
3881 : 669 : if (args[i].save_area)
3882 : : {
3883 : : may_overlap = true;
3884 : : break;
3885 : : }
3886 : :
3887 : 394 : if (may_overlap)
3888 : 0 : target = copy_to_reg (valreg);
3889 : : else
3890 : : {
3891 : : /* TARGET and VALREG cannot be equal at this point
3892 : : because the latter would not have
3893 : : REG_FUNCTION_VALUE_P true, while the former would if
3894 : : it were referring to the same register.
3895 : :
3896 : : If they refer to the same register, this move will be
3897 : : a no-op, except when function inlining is being
3898 : : done. */
3899 : 1531229 : emit_move_insn (target, valreg);
3900 : :
3901 : : /* If we are setting a MEM, this code must be executed.
3902 : : Since it is emitted after the call insn, sibcall
3903 : : optimization cannot be performed in that case. */
3904 : 1531229 : if (MEM_P (target))
3905 : 45913 : sibcall_failure = true;
3906 : : }
3907 : : }
3908 : : else
3909 : 144804 : target = copy_to_reg (avoid_likely_spilled_reg (valreg));
3910 : :
3911 : : /* If we promoted this return value, make the proper SUBREG.
3912 : : TARGET might be const0_rtx here, so be careful. */
3913 : 5714916 : if (REG_P (target)
3914 : 1631643 : && TYPE_MODE (rettype) != BLKmode
3915 : 7346308 : && GET_MODE (target) != TYPE_MODE (rettype))
3916 : : {
3917 : 1 : tree type = rettype;
3918 : 1 : int unsignedp = TYPE_UNSIGNED (type);
3919 : 1 : machine_mode ret_mode = TYPE_MODE (type);
3920 : 1 : machine_mode pmode;
3921 : :
3922 : : /* Ensure we promote as expected, and get the new unsignedness. */
3923 : 1 : pmode = promote_function_mode (type, ret_mode, &unsignedp,
3924 : : funtype, 1);
3925 : 1 : gcc_assert (GET_MODE (target) == pmode);
3926 : :
3927 : 1 : if (SCALAR_INT_MODE_P (pmode)
3928 : 1 : && SCALAR_FLOAT_MODE_P (ret_mode)
3929 : 1 : && known_gt (GET_MODE_SIZE (pmode), GET_MODE_SIZE (ret_mode)))
3930 : 0 : target = convert_wider_int_to_float (ret_mode, pmode, target);
3931 : : else
3932 : : {
3933 : 1 : target = gen_lowpart_SUBREG (ret_mode, target);
3934 : 1 : SUBREG_PROMOTED_VAR_P (target) = 1;
3935 : 2 : SUBREG_PROMOTED_SET (target, unsignedp);
3936 : : }
3937 : : }
3938 : :
3939 : : /* If size of args is variable or this was a constructor call for a stack
3940 : : argument, restore saved stack-pointer value. */
3941 : :
3942 : 5714916 : if (old_stack_level)
3943 : : {
3944 : 157 : rtx_insn *prev = get_last_insn ();
3945 : :
3946 : 157 : emit_stack_restore (SAVE_BLOCK, old_stack_level);
3947 : 157 : stack_pointer_delta = old_stack_pointer_delta;
3948 : :
3949 : 157 : fixup_args_size_notes (prev, get_last_insn (), stack_pointer_delta);
3950 : :
3951 : 157 : pending_stack_adjust = old_pending_adj;
3952 : 157 : old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
3953 : 157 : stack_arg_under_construction = old_stack_arg_under_construction;
3954 : 157 : highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3955 : 157 : stack_usage_map = initial_stack_usage_map;
3956 : 157 : stack_usage_watermark = initial_stack_usage_watermark;
3957 : 157 : sibcall_failure = true;
3958 : : }
3959 : 5714759 : else if (ACCUMULATE_OUTGOING_ARGS && pass)
3960 : : {
3961 : : #ifdef REG_PARM_STACK_SPACE
3962 : 73362 : if (save_area)
3963 : 0 : restore_fixed_argument_area (save_area, argblock,
3964 : : high_to_save, low_to_save);
3965 : : #endif
3966 : :
3967 : : /* If we saved any argument areas, restore them. */
3968 : 366523 : for (i = 0; i < num_actuals; i++)
3969 : 293161 : if (args[i].save_area)
3970 : : {
3971 : 0 : machine_mode save_mode = GET_MODE (args[i].save_area);
3972 : 0 : rtx stack_area
3973 : 0 : = gen_rtx_MEM (save_mode,
3974 : 0 : memory_address (save_mode,
3975 : : XEXP (args[i].stack_slot, 0)));
3976 : :
3977 : 0 : if (save_mode != BLKmode)
3978 : 0 : emit_move_insn (stack_area, args[i].save_area);
3979 : : else
3980 : 0 : emit_block_move (stack_area, args[i].save_area,
3981 : : (gen_int_mode
3982 : 0 : (args[i].locate.size.constant, Pmode)),
3983 : : BLOCK_OP_CALL_PARM);
3984 : : }
3985 : :
3986 : 73362 : highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3987 : 73362 : stack_usage_map = initial_stack_usage_map;
3988 : 73362 : stack_usage_watermark = initial_stack_usage_watermark;
3989 : : }
3990 : :
3991 : : /* If this was alloca, record the new stack level. */
3992 : 5714916 : if (flags & ECF_MAY_BE_ALLOCA)
3993 : 29 : record_new_stack_level ();
3994 : :
3995 : : /* Free up storage we no longer need. */
3996 : 17595025 : for (i = 0; i < num_actuals; ++i)
3997 : 11880109 : free (args[i].aligned_regs);
3998 : :
3999 : 5714916 : targetm.calls.end_call_args (args_so_far);
4000 : :
4001 : 5714916 : insns = get_insns ();
4002 : 5714916 : end_sequence ();
4003 : :
4004 : 5714916 : if (pass == 0)
4005 : : {
4006 : 121991 : tail_call_insns = insns;
4007 : :
4008 : : /* Restore the pending stack adjustment now that we have
4009 : : finished generating the sibling call sequence. */
4010 : :
4011 : 121991 : restore_pending_stack_adjust (&save);
4012 : :
4013 : : /* Prepare arg structure for next iteration. */
4014 : 467036 : for (i = 0; i < num_actuals; i++)
4015 : : {
4016 : 223054 : args[i].value = 0;
4017 : 223054 : args[i].aligned_regs = 0;
4018 : 223054 : args[i].stack = 0;
4019 : : }
4020 : :
4021 : 121991 : sbitmap_free (stored_args_map);
4022 : 121991 : internal_arg_pointer_exp_state.scan_start = NULL;
4023 : 121991 : internal_arg_pointer_exp_state.cache.release ();
4024 : : }
4025 : : else
4026 : : {
4027 : 5592925 : normal_call_insns = insns;
4028 : :
4029 : : /* Verify that we've deallocated all the stack we used. */
4030 : 5592925 : gcc_assert ((flags & ECF_NORETURN)
4031 : : || normal_failure
4032 : : || known_eq (old_stack_allocated,
4033 : : stack_pointer_delta
4034 : : - pending_stack_adjust));
4035 : 5592919 : if (normal_failure)
4036 : : normal_call_insns = NULL;
4037 : : }
4038 : :
4039 : : /* If something prevents making this a sibling call,
4040 : : zero out the sequence. */
4041 : 5714916 : if (sibcall_failure)
4042 : 46074 : tail_call_insns = NULL;
4043 : : else
4044 : : break;
4045 : : }
4046 : :
4047 : : /* If tail call production succeeded, we need to remove REG_EQUIV notes on
4048 : : arguments too, as argument area is now clobbered by the call. */
4049 : 5714912 : if (tail_call_insns)
4050 : : {
4051 : 121987 : emit_insn (tail_call_insns);
4052 : 121987 : crtl->tail_call_emit = true;
4053 : : }
4054 : : else
4055 : : {
4056 : 5592925 : emit_insn (normal_call_insns);
4057 : 5592925 : if (try_tail_call)
4058 : : /* Ideally we'd emit a message for all of the ways that it could
4059 : : have failed. */
4060 : 4 : maybe_complain_about_tail_call (exp, _("tail call production failed"));
4061 : : }
4062 : :
4063 : 5714912 : currently_expanding_call--;
4064 : :
4065 : 5714912 : free (stack_usage_map_buf);
4066 : 5714912 : free (args);
4067 : 5714912 : return target;
4068 : : }
4069 : :
4070 : : /* A sibling call sequence invalidates any REG_EQUIV notes made for
4071 : : this function's incoming arguments.
4072 : :
4073 : : At the start of RTL generation we know the only REG_EQUIV notes
4074 : : in the rtl chain are those for incoming arguments, so we can look
4075 : : for REG_EQUIV notes between the start of the function and the
4076 : : NOTE_INSN_FUNCTION_BEG.
4077 : :
4078 : : This is (slight) overkill. We could keep track of the highest
4079 : : argument we clobber and be more selective in removing notes, but it
4080 : : does not seem to be worth the effort. */
4081 : :
4082 : : void
4083 : 116902 : fixup_tail_calls (void)
4084 : : {
4085 : 116902 : rtx_insn *insn;
4086 : :
4087 : 551285 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4088 : : {
4089 : 551285 : rtx note;
4090 : :
4091 : : /* There are never REG_EQUIV notes for the incoming arguments
4092 : : after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
4093 : 551285 : if (NOTE_P (insn)
4094 : 350852 : && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
4095 : : break;
4096 : :
4097 : 434383 : note = find_reg_note (insn, REG_EQUIV, 0);
4098 : 434383 : if (note)
4099 : 18676 : remove_note (insn, note);
4100 : 434383 : note = find_reg_note (insn, REG_EQUIV, 0);
4101 : 434383 : gcc_assert (!note);
4102 : : }
4103 : 116902 : }
4104 : :
4105 : : /* Traverse a list of TYPES and expand all complex types into their
4106 : : components. */
4107 : : static tree
4108 : 0 : split_complex_types (tree types)
4109 : : {
4110 : 0 : tree p;
4111 : :
4112 : : /* Before allocating memory, check for the common case of no complex. */
4113 : 0 : for (p = types; p; p = TREE_CHAIN (p))
4114 : : {
4115 : 0 : tree type = TREE_VALUE (p);
4116 : 0 : if (TREE_CODE (type) == COMPLEX_TYPE
4117 : 0 : && targetm.calls.split_complex_arg (type))
4118 : 0 : goto found;
4119 : : }
4120 : : return types;
4121 : :
4122 : 0 : found:
4123 : 0 : types = copy_list (types);
4124 : :
4125 : 0 : for (p = types; p; p = TREE_CHAIN (p))
4126 : : {
4127 : 0 : tree complex_type = TREE_VALUE (p);
4128 : :
4129 : 0 : if (TREE_CODE (complex_type) == COMPLEX_TYPE
4130 : 0 : && targetm.calls.split_complex_arg (complex_type))
4131 : : {
4132 : 0 : tree next, imag;
4133 : :
4134 : : /* Rewrite complex type with component type. */
4135 : 0 : TREE_VALUE (p) = TREE_TYPE (complex_type);
4136 : 0 : next = TREE_CHAIN (p);
4137 : :
4138 : : /* Add another component type for the imaginary part. */
4139 : 0 : imag = build_tree_list (NULL_TREE, TREE_VALUE (p));
4140 : 0 : TREE_CHAIN (p) = imag;
4141 : 0 : TREE_CHAIN (imag) = next;
4142 : :
4143 : : /* Skip the newly created node. */
4144 : 0 : p = TREE_CHAIN (p);
4145 : : }
4146 : : }
4147 : :
4148 : : return types;
4149 : : }
4150 : :
4151 : : /* Output a library call to function ORGFUN (a SYMBOL_REF rtx)
4152 : : for a value of mode OUTMODE,
4153 : : with NARGS different arguments, passed as ARGS.
4154 : : Store the return value if RETVAL is nonzero: store it in VALUE if
4155 : : VALUE is nonnull, otherwise pick a convenient location. In either
4156 : : case return the location of the stored value.
4157 : :
4158 : : FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for
4159 : : `const' calls, LCT_PURE for `pure' calls, or another LCT_ value for
4160 : : other types of library calls. */
4161 : :
4162 : : rtx
4163 : 118850 : emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
4164 : : enum libcall_type fn_type,
4165 : : machine_mode outmode, int nargs, rtx_mode_t *args)
4166 : : {
4167 : : /* Total size in bytes of all the stack-parms scanned so far. */
4168 : 118850 : struct args_size args_size;
4169 : : /* Size of arguments before any adjustments (such as rounding). */
4170 : 118850 : struct args_size original_args_size;
4171 : 118850 : int argnum;
4172 : 118850 : rtx fun;
4173 : : /* Todo, choose the correct decl type of orgfun. Sadly this information
4174 : : isn't present here, so we default to native calling abi here. */
4175 : 118850 : tree fndecl ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
4176 : 118850 : tree fntype ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
4177 : 118850 : int count;
4178 : 118850 : rtx argblock = 0;
4179 : 118850 : CUMULATIVE_ARGS args_so_far_v;
4180 : 118850 : cumulative_args_t args_so_far;
4181 : 118850 : struct arg
4182 : : {
4183 : : rtx value;
4184 : : machine_mode mode;
4185 : : rtx reg;
4186 : : int partial;
4187 : : struct locate_and_pad_arg_data locate;
4188 : : rtx save_area;
4189 : : };
4190 : 118850 : struct arg *argvec;
4191 : 118850 : int old_inhibit_defer_pop = inhibit_defer_pop;
4192 : 118850 : rtx call_fusage = 0;
4193 : 118850 : rtx mem_value = 0;
4194 : 118850 : rtx valreg;
4195 : 118850 : bool pcc_struct_value = false;
4196 : 118850 : poly_int64 struct_value_size = 0;
4197 : 118850 : int flags;
4198 : 118850 : int reg_parm_stack_space = 0;
4199 : 118850 : poly_int64 needed;
4200 : 118850 : rtx_insn *before_call;
4201 : 118850 : bool have_push_fusage;
4202 : 118850 : tree tfom; /* type_for_mode (outmode, 0) */
4203 : :
4204 : : #ifdef REG_PARM_STACK_SPACE
4205 : : /* Define the boundary of the register parm stack space that needs to be
4206 : : save, if any. */
4207 : 118850 : int low_to_save = 0, high_to_save = 0;
4208 : 118850 : rtx save_area = 0; /* Place that it is saved. */
4209 : : #endif
4210 : :
4211 : : /* Size of the stack reserved for parameter registers. */
4212 : 118850 : unsigned int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
4213 : 118850 : char *initial_stack_usage_map = stack_usage_map;
4214 : 118850 : unsigned HOST_WIDE_INT initial_stack_usage_watermark = stack_usage_watermark;
4215 : 118850 : char *stack_usage_map_buf = NULL;
4216 : :
4217 : 118850 : rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
4218 : :
4219 : : #ifdef REG_PARM_STACK_SPACE
4220 : 118850 : reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
4221 : : #endif
4222 : :
4223 : : /* By default, library functions cannot throw. */
4224 : 118850 : flags = ECF_NOTHROW;
4225 : :
4226 : 118850 : switch (fn_type)
4227 : : {
4228 : : case LCT_NORMAL:
4229 : : break;
4230 : : case LCT_CONST:
4231 : : flags |= ECF_CONST;
4232 : : break;
4233 : : case LCT_PURE:
4234 : : flags |= ECF_PURE;
4235 : : break;
4236 : : case LCT_NORETURN:
4237 : : flags |= ECF_NORETURN;
4238 : : break;
4239 : : case LCT_THROW:
4240 : : flags &= ~ECF_NOTHROW;
4241 : : break;
4242 : : case LCT_RETURNS_TWICE:
4243 : : flags = ECF_RETURNS_TWICE;
4244 : : break;
4245 : : }
4246 : 118850 : fun = orgfun;
4247 : :
4248 : : /* Ensure current function's preferred stack boundary is at least
4249 : : what we need. */
4250 : 118850 : if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
4251 : 12272 : crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
4252 : :
4253 : : /* If this kind of value comes back in memory,
4254 : : decide where in memory it should come back. */
4255 : 118850 : if (outmode != VOIDmode)
4256 : : {
4257 : 116854 : tfom = lang_hooks.types.type_for_mode (outmode, 0);
4258 : 116854 : if (aggregate_value_p (tfom, 0))
4259 : : {
4260 : : #ifdef PCC_STATIC_STRUCT_RETURN
4261 : : rtx pointer_reg
4262 : : = hard_function_value (build_pointer_type (tfom), 0, 0, 0);
4263 : : mem_value = gen_rtx_MEM (outmode, pointer_reg);
4264 : : pcc_struct_value = true;
4265 : : if (value == 0)
4266 : : value = gen_reg_rtx (outmode);
4267 : : #else /* not PCC_STATIC_STRUCT_RETURN */
4268 : 20162 : struct_value_size = GET_MODE_SIZE (outmode);
4269 : 10081 : if (value != 0 && MEM_P (value))
4270 : : mem_value = value;
4271 : : else
4272 : 10081 : mem_value = assign_temp (tfom, 1, 1);
4273 : : #endif
4274 : : /* This call returns a big structure. */
4275 : 10081 : flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
4276 : : }
4277 : : }
4278 : : else
4279 : 1996 : tfom = void_type_node;
4280 : :
4281 : : /* ??? Unfinished: must pass the memory address as an argument. */
4282 : :
4283 : : /* Copy all the libcall-arguments out of the varargs data
4284 : : and into a vector ARGVEC.
4285 : :
4286 : : Compute how to pass each argument. We only support a very small subset
4287 : : of the full argument passing conventions to limit complexity here since
4288 : : library functions shouldn't have many args. */
4289 : :
4290 : 118850 : argvec = XALLOCAVEC (struct arg, nargs + 1);
4291 : 118850 : memset (argvec, 0, (nargs + 1) * sizeof (struct arg));
4292 : :
4293 : : #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
4294 : : INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v, outmode, fun);
4295 : : #else
4296 : 118850 : INIT_CUMULATIVE_ARGS (args_so_far_v, NULL_TREE, fun, 0, nargs);
4297 : : #endif
4298 : 118850 : args_so_far = pack_cumulative_args (&args_so_far_v);
4299 : :
4300 : 118850 : args_size.constant = 0;
4301 : 118850 : args_size.var = 0;
4302 : :
4303 : 118850 : count = 0;
4304 : :
4305 : 118850 : push_temp_slots ();
4306 : :
4307 : : /* If there's a structure value address to be passed,
4308 : : either pass it in the special place, or pass it as an extra argument. */
4309 : 118850 : if (mem_value && struct_value == 0 && ! pcc_struct_value)
4310 : : {
4311 : 10081 : rtx addr = XEXP (mem_value, 0);
4312 : :
4313 : 10081 : nargs++;
4314 : :
4315 : : /* Make sure it is a reasonable operand for a move or push insn. */
4316 : 10081 : if (!REG_P (addr) && !MEM_P (addr)
4317 : 20162 : && !(CONSTANT_P (addr)
4318 : 0 : && targetm.legitimate_constant_p (Pmode, addr)))
4319 : 10081 : addr = force_operand (addr, NULL_RTX);
4320 : :
4321 : 10081 : argvec[count].value = addr;
4322 : 10081 : argvec[count].mode = Pmode;
4323 : 10081 : argvec[count].partial = 0;
4324 : :
4325 : 10081 : function_arg_info ptr_arg (Pmode, /*named=*/true);
4326 : 10081 : argvec[count].reg = targetm.calls.function_arg (args_so_far, ptr_arg);
4327 : 10081 : gcc_assert (targetm.calls.arg_partial_bytes (args_so_far, ptr_arg) == 0);
4328 : :
4329 : 10081 : locate_and_pad_parm (Pmode, NULL_TREE,
4330 : : #ifdef STACK_PARMS_IN_REG_PARM_AREA
4331 : : 1,
4332 : : #else
4333 : 10081 : argvec[count].reg != 0,
4334 : : #endif
4335 : : reg_parm_stack_space, 0,
4336 : : NULL_TREE, &args_size, &argvec[count].locate);
4337 : :
4338 : 10081 : if (argvec[count].reg == 0 || argvec[count].partial != 0
4339 : 0 : || reg_parm_stack_space > 0)
4340 : 10081 : args_size.constant += argvec[count].locate.size.constant;
4341 : :
4342 : 10081 : targetm.calls.function_arg_advance (args_so_far, ptr_arg);
4343 : :
4344 : 10081 : count++;
4345 : : }
4346 : :
4347 : 324439 : for (unsigned int i = 0; count < nargs; i++, count++)
4348 : : {
4349 : 205589 : rtx val = args[i].first;
4350 : 205589 : function_arg_info arg (args[i].second, /*named=*/true);
4351 : 205589 : int unsigned_p = 0;
4352 : :
4353 : : /* We cannot convert the arg value to the mode the library wants here;
4354 : : must do it earlier where we know the signedness of the arg. */
4355 : 205589 : gcc_assert (arg.mode != BLKmode
4356 : : && (GET_MODE (val) == arg.mode
4357 : : || GET_MODE (val) == VOIDmode));
4358 : :
4359 : : /* Make sure it is a reasonable operand for a move or push insn. */
4360 : 43316 : if (!REG_P (val) && !MEM_P (val)
4361 : 278516 : && !(CONSTANT_P (val)
4362 : 35897 : && targetm.legitimate_constant_p (arg.mode, val)))
4363 : 1137 : val = force_operand (val, NULL_RTX);
4364 : :
4365 : 205589 : if (pass_by_reference (&args_so_far_v, arg))
4366 : : {
4367 : 0 : rtx slot;
4368 : 0 : int must_copy = !reference_callee_copied (&args_so_far_v, arg);
4369 : :
4370 : : /* If this was a CONST function, it is now PURE since it now
4371 : : reads memory. */
4372 : 0 : if (flags & ECF_CONST)
4373 : : {
4374 : 0 : flags &= ~ECF_CONST;
4375 : 0 : flags |= ECF_PURE;
4376 : : }
4377 : :
4378 : 0 : if (MEM_P (val) && !must_copy)
4379 : : {
4380 : 0 : tree val_expr = MEM_EXPR (val);
4381 : 0 : if (val_expr)
4382 : 0 : mark_addressable (val_expr);
4383 : : slot = val;
4384 : : }
4385 : : else
4386 : : {
4387 : 0 : slot = assign_temp (lang_hooks.types.type_for_mode (arg.mode, 0),
4388 : : 1, 1);
4389 : 0 : emit_move_insn (slot, val);
4390 : : }
4391 : :
4392 : 0 : call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
4393 : : gen_rtx_USE (VOIDmode, slot),
4394 : : call_fusage);
4395 : 0 : if (must_copy)
4396 : 0 : call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
4397 : : gen_rtx_CLOBBER (VOIDmode,
4398 : : slot),
4399 : : call_fusage);
4400 : :
4401 : 0 : arg.mode = Pmode;
4402 : 0 : arg.pass_by_reference = true;
4403 : 0 : val = force_operand (XEXP (slot, 0), NULL_RTX);
4404 : : }
4405 : :
4406 : 205589 : arg.mode = promote_function_mode (NULL_TREE, arg.mode, &unsigned_p,
4407 : : NULL_TREE, 0);
4408 : 205589 : argvec[count].mode = arg.mode;
4409 : 205589 : argvec[count].value = convert_modes (arg.mode, GET_MODE (val), val,
4410 : : unsigned_p);
4411 : 205589 : argvec[count].reg = targetm.calls.function_arg (args_so_far, arg);
4412 : :
4413 : 205589 : argvec[count].partial
4414 : 205589 : = targetm.calls.arg_partial_bytes (args_so_far, arg);
4415 : :
4416 : 205589 : if (argvec[count].reg == 0
4417 : 177984 : || argvec[count].partial != 0
4418 : 177984 : || reg_parm_stack_space > 0)
4419 : : {
4420 : 27605 : locate_and_pad_parm (arg.mode, NULL_TREE,
4421 : : #ifdef STACK_PARMS_IN_REG_PARM_AREA
4422 : : 1,
4423 : : #else
4424 : : argvec[count].reg != 0,
4425 : : #endif
4426 : : reg_parm_stack_space, argvec[count].partial,
4427 : : NULL_TREE, &args_size, &argvec[count].locate);
4428 : 27605 : args_size.constant += argvec[count].locate.size.constant;
4429 : 27605 : gcc_assert (!argvec[count].locate.size.var);
4430 : : }
4431 : : #ifdef BLOCK_REG_PADDING
4432 : : else
4433 : : /* The argument is passed entirely in registers. See at which
4434 : : end it should be padded. */
4435 : : argvec[count].locate.where_pad =
4436 : : BLOCK_REG_PADDING (arg.mode, NULL_TREE,
4437 : : known_le (GET_MODE_SIZE (arg.mode),
4438 : : UNITS_PER_WORD));
4439 : : #endif
4440 : :
4441 : 205589 : targetm.calls.function_arg_advance (args_so_far, arg);
4442 : : }
4443 : :
4444 : 334520 : for (int i = 0; i < nargs; i++)
4445 : 215670 : if (reg_parm_stack_space > 0
4446 : 215670 : || argvec[i].reg == 0
4447 : 177984 : || argvec[i].partial != 0)
4448 : 37686 : update_stack_alignment_for_call (&argvec[i].locate);
4449 : :
4450 : : /* If this machine requires an external definition for library
4451 : : functions, write one out. */
4452 : 118850 : assemble_external_libcall (fun);
4453 : :
4454 : 118850 : original_args_size = args_size;
4455 : 118850 : args_size.constant = (aligned_upper_bound (args_size.constant
4456 : 118850 : + stack_pointer_delta,
4457 : : STACK_BYTES)
4458 : 118850 : - stack_pointer_delta);
4459 : :
4460 : 118850 : args_size.constant = upper_bound (args_size.constant,
4461 : : reg_parm_stack_space);
4462 : :
4463 : 118850 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
4464 : 118850 : args_size.constant -= reg_parm_stack_space;
4465 : :
4466 : 118850 : crtl->outgoing_args_size = upper_bound (crtl->outgoing_args_size,
4467 : : args_size.constant);
4468 : :
4469 : 118850 : if (flag_stack_usage_info && !ACCUMULATE_OUTGOING_ARGS)
4470 : : {
4471 : 0 : poly_int64 pushed = args_size.constant + pending_stack_adjust;
4472 : 0 : current_function_pushed_stack_size
4473 : 0 : = upper_bound (current_function_pushed_stack_size, pushed);
4474 : : }
4475 : :
4476 : 118850 : if (ACCUMULATE_OUTGOING_ARGS)
4477 : : {
4478 : : /* Since the stack pointer will never be pushed, it is possible for
4479 : : the evaluation of a parm to clobber something we have already
4480 : : written to the stack. Since most function calls on RISC machines
4481 : : do not use the stack, this is uncommon, but must work correctly.
4482 : :
4483 : : Therefore, we save any area of the stack that was already written
4484 : : and that we are using. Here we set up to do this by making a new
4485 : : stack usage map from the old one.
4486 : :
4487 : : Another approach might be to try to reorder the argument
4488 : : evaluations to avoid this conflicting stack usage. */
4489 : :
4490 : 14 : needed = args_size.constant;
4491 : :
4492 : : /* Since we will be writing into the entire argument area, the
4493 : : map must be allocated for its entire size, not just the part that
4494 : : is the responsibility of the caller. */
4495 : 14 : if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
4496 : 14 : needed += reg_parm_stack_space;
4497 : :
4498 : 14 : poly_int64 limit = needed;
4499 : 14 : if (ARGS_GROW_DOWNWARD)
4500 : : limit += 1;
4501 : :
4502 : : /* For polynomial sizes, this is the maximum possible size needed
4503 : : for arguments with a constant size and offset. */
4504 : 14 : HOST_WIDE_INT const_limit = constant_lower_bound (limit);
4505 : 14 : highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
4506 : : const_limit);
4507 : :
4508 : 14 : stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
4509 : 14 : stack_usage_map = stack_usage_map_buf;
4510 : :
4511 : 14 : if (initial_highest_arg_in_use)
4512 : 0 : memcpy (stack_usage_map, initial_stack_usage_map,
4513 : : initial_highest_arg_in_use);
4514 : :
4515 : 14 : if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
4516 : 0 : memset (&stack_usage_map[initial_highest_arg_in_use], 0,
4517 : 0 : highest_outgoing_arg_in_use - initial_highest_arg_in_use);
4518 : 14 : needed = 0;
4519 : :
4520 : : /* We must be careful to use virtual regs before they're instantiated,
4521 : : and real regs afterwards. Loop optimization, for example, can create
4522 : : new libcalls after we've instantiated the virtual regs, and if we
4523 : : use virtuals anyway, they won't match the rtl patterns. */
4524 : :
4525 : 14 : if (virtuals_instantiated)
4526 : 0 : argblock = plus_constant (Pmode, stack_pointer_rtx,
4527 : 0 : STACK_POINTER_OFFSET);
4528 : : else
4529 : 14 : argblock = virtual_outgoing_args_rtx;
4530 : : }
4531 : : else
4532 : : {
4533 : 118836 : if (!targetm.calls.push_argument (0))
4534 : 0 : argblock = push_block (gen_int_mode (args_size.constant, Pmode), 0, 0);
4535 : : }
4536 : :
4537 : : /* We push args individually in reverse order, perform stack alignment
4538 : : before the first push (the last arg). */
4539 : 14 : if (argblock == 0)
4540 : 118836 : anti_adjust_stack (gen_int_mode (args_size.constant
4541 : : - original_args_size.constant,
4542 : 118836 : Pmode));
4543 : :
4544 : 118850 : argnum = nargs - 1;
4545 : :
4546 : : #ifdef REG_PARM_STACK_SPACE
4547 : 118850 : if (ACCUMULATE_OUTGOING_ARGS)
4548 : : {
4549 : : /* The argument list is the property of the called routine and it
4550 : : may clobber it. If the fixed area has been used for previous
4551 : : parameters, we must save and restore it. */
4552 : 14 : save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
4553 : : &low_to_save, &high_to_save);
4554 : : }
4555 : : #endif
4556 : :
4557 : 118850 : rtx call_cookie
4558 : 118850 : = targetm.calls.function_arg (args_so_far,
4559 : 118850 : function_arg_info::end_marker ());
4560 : :
4561 : : /* Push the args that need to be pushed. */
4562 : :
4563 : 118850 : have_push_fusage = false;
4564 : :
4565 : : /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4566 : : are to be pushed. */
4567 : 334520 : for (count = 0; count < nargs; count++, argnum--)
4568 : : {
4569 : 215670 : machine_mode mode = argvec[argnum].mode;
4570 : 215670 : rtx val = argvec[argnum].value;
4571 : 215670 : rtx reg = argvec[argnum].reg;
4572 : 215670 : int partial = argvec[argnum].partial;
4573 : 215670 : unsigned int parm_align = argvec[argnum].locate.boundary;
4574 : 215670 : poly_int64 lower_bound = 0, upper_bound = 0;
4575 : :
4576 : 215670 : if (! (reg != 0 && partial == 0))
4577 : : {
4578 : 37686 : rtx use;
4579 : :
4580 : 37686 : if (ACCUMULATE_OUTGOING_ARGS)
4581 : : {
4582 : : /* If this is being stored into a pre-allocated, fixed-size,
4583 : : stack area, save any previous data at that location. */
4584 : :
4585 : 0 : if (ARGS_GROW_DOWNWARD)
4586 : : {
4587 : : /* stack_slot is negative, but we want to index stack_usage_map
4588 : : with positive values. */
4589 : : upper_bound = -argvec[argnum].locate.slot_offset.constant + 1;
4590 : : lower_bound = upper_bound - argvec[argnum].locate.size.constant;
4591 : : }
4592 : : else
4593 : : {
4594 : 0 : lower_bound = argvec[argnum].locate.slot_offset.constant;
4595 : 0 : upper_bound = lower_bound + argvec[argnum].locate.size.constant;
4596 : : }
4597 : :
4598 : 0 : if (stack_region_maybe_used_p (lower_bound, upper_bound,
4599 : : reg_parm_stack_space))
4600 : : {
4601 : : /* We need to make a save area. */
4602 : 0 : poly_uint64 size
4603 : 0 : = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
4604 : 0 : machine_mode save_mode
4605 : 0 : = int_mode_for_size (size, 1).else_blk ();
4606 : 0 : rtx adr
4607 : 0 : = plus_constant (Pmode, argblock,
4608 : : argvec[argnum].locate.offset.constant);
4609 : 0 : rtx stack_area
4610 : 0 : = gen_rtx_MEM (save_mode, memory_address (save_mode, adr));
4611 : :
4612 : 0 : if (save_mode == BLKmode)
4613 : : {
4614 : 0 : argvec[argnum].save_area
4615 : 0 : = assign_stack_temp (BLKmode,
4616 : : argvec[argnum].locate.size.constant
4617 : : );
4618 : :
4619 : 0 : emit_block_move (validize_mem
4620 : : (copy_rtx (argvec[argnum].save_area)),
4621 : : stack_area,
4622 : : (gen_int_mode
4623 : : (argvec[argnum].locate.size.constant,
4624 : 0 : Pmode)),
4625 : : BLOCK_OP_CALL_PARM);
4626 : : }
4627 : : else
4628 : : {
4629 : 0 : argvec[argnum].save_area = gen_reg_rtx (save_mode);
4630 : :
4631 : 0 : emit_move_insn (argvec[argnum].save_area, stack_area);
4632 : : }
4633 : : }
4634 : : }
4635 : :
4636 : 37686 : emit_push_insn (val, mode, lang_hooks.types.type_for_mode (mode, 0),
4637 : 37686 : NULL_RTX, parm_align, partial, reg, 0, argblock,
4638 : : (gen_int_mode
4639 : 37686 : (argvec[argnum].locate.offset.constant, Pmode)),
4640 : : reg_parm_stack_space,
4641 : 37686 : ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad), false);
4642 : :
4643 : : /* Now mark the segment we just used. */
4644 : 37686 : if (ACCUMULATE_OUTGOING_ARGS)
4645 : 0 : mark_stack_region_used (lower_bound, upper_bound);
4646 : :
4647 : 37686 : NO_DEFER_POP;
4648 : :
4649 : : /* Indicate argument access so that alias.cc knows that these
4650 : : values are live. */
4651 : 37686 : if (argblock)
4652 : 0 : use = plus_constant (Pmode, argblock,
4653 : : argvec[argnum].locate.offset.constant);
4654 : 37686 : else if (have_push_fusage)
4655 : 22889 : continue;
4656 : : else
4657 : : {
4658 : : /* When arguments are pushed, trying to tell alias.cc where
4659 : : exactly this argument is won't work, because the
4660 : : auto-increment causes confusion. So we merely indicate
4661 : : that we access something with a known mode somewhere on
4662 : : the stack. */
4663 : 14797 : use = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
4664 : : gen_rtx_SCRATCH (Pmode));
4665 : 14797 : have_push_fusage = true;
4666 : : }
4667 : 14797 : use = gen_rtx_MEM (argvec[argnum].mode, use);
4668 : 14797 : use = gen_rtx_USE (VOIDmode, use);
4669 : 14797 : call_fusage = gen_rtx_EXPR_LIST (VOIDmode, use, call_fusage);
4670 : : }
4671 : : }
4672 : :
4673 : 118850 : argnum = nargs - 1;
4674 : :
4675 : 118850 : fun = prepare_call_address (NULL, fun, NULL, &call_fusage, 0, 0);
4676 : :
4677 : 118850 : targetm.calls.start_call_args (args_so_far);
4678 : :
4679 : : /* When expanding a normal call, args are stored in push order,
4680 : : which is the reverse of what we have here. */
4681 : 118850 : bool any_regs = false;
4682 : 334520 : for (int i = nargs; i-- > 0; )
4683 : 215670 : if (argvec[i].reg != NULL_RTX)
4684 : : {
4685 : 177984 : targetm.calls.call_args (args_so_far, argvec[i].reg, NULL_TREE);
4686 : 177984 : any_regs = true;
4687 : : }
4688 : 118850 : if (!any_regs)
4689 : 14655 : targetm.calls.call_args (args_so_far, pc_rtx, NULL_TREE);
4690 : :
4691 : : /* Now load any reg parms into their regs. */
4692 : :
4693 : : /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4694 : : are to be pushed. */
4695 : 334520 : for (count = 0; count < nargs; count++, argnum--)
4696 : : {
4697 : 215670 : machine_mode mode = argvec[argnum].mode;
4698 : 215670 : rtx val = argvec[argnum].value;
4699 : 215670 : rtx reg = argvec[argnum].reg;
4700 : 215670 : int partial = argvec[argnum].partial;
4701 : :
4702 : : /* Handle calls that pass values in multiple non-contiguous
4703 : : locations. The PA64 has examples of this for library calls. */
4704 : 215670 : if (reg != 0 && GET_CODE (reg) == PARALLEL)
4705 : 14142 : emit_group_load (reg, val, NULL_TREE, GET_MODE_SIZE (mode));
4706 : 208599 : else if (reg != 0 && partial == 0)
4707 : : {
4708 : 170913 : emit_move_insn (reg, val);
4709 : : #ifdef BLOCK_REG_PADDING
4710 : : poly_int64 size = GET_MODE_SIZE (argvec[argnum].mode);
4711 : :
4712 : : /* Copied from load_register_parameters. */
4713 : :
4714 : : /* Handle case where we have a value that needs shifting
4715 : : up to the msb. eg. a QImode value and we're padding
4716 : : upward on a BYTES_BIG_ENDIAN machine. */
4717 : : if (known_lt (size, UNITS_PER_WORD)
4718 : : && (argvec[argnum].locate.where_pad
4719 : : == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)))
4720 : : {
4721 : : rtx x;
4722 : : poly_int64 shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
4723 : :
4724 : : /* Assigning REG here rather than a temp makes CALL_FUSAGE
4725 : : report the whole reg as used. Strictly speaking, the
4726 : : call only uses SIZE bytes at the msb end, but it doesn't
4727 : : seem worth generating rtl to say that. */
4728 : : reg = gen_rtx_REG (word_mode, REGNO (reg));
4729 : : x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1);
4730 : : if (x != reg)
4731 : : emit_move_insn (reg, x);
4732 : : }
4733 : : #endif
4734 : : }
4735 : :
4736 : 215670 : NO_DEFER_POP;
4737 : : }
4738 : :
4739 : : /* Any regs containing parms remain in use through the call. */
4740 : 334520 : for (count = 0; count < nargs; count++)
4741 : : {
4742 : 215670 : rtx reg = argvec[count].reg;
4743 : 215670 : if (reg != 0 && GET_CODE (reg) == PARALLEL)
4744 : 7071 : use_group_regs (&call_fusage, reg);
4745 : 170913 : else if (reg != 0)
4746 : : {
4747 : 170913 : int partial = argvec[count].partial;
4748 : 170913 : if (partial)
4749 : : {
4750 : 0 : int nregs;
4751 : 0 : gcc_assert (partial % UNITS_PER_WORD == 0);
4752 : 0 : nregs = partial / UNITS_PER_WORD;
4753 : 0 : use_regs (&call_fusage, REGNO (reg), nregs);
4754 : : }
4755 : : else
4756 : 170913 : use_reg (&call_fusage, reg);
4757 : : }
4758 : : }
4759 : :
4760 : : /* Pass the function the address in which to return a structure value. */
4761 : 118850 : if (mem_value != 0 && struct_value != 0 && ! pcc_struct_value)
4762 : : {
4763 : 0 : emit_move_insn (struct_value,
4764 : 0 : force_reg (Pmode,
4765 : : force_operand (XEXP (mem_value, 0),
4766 : : NULL_RTX)));
4767 : 0 : if (REG_P (struct_value))
4768 : 0 : use_reg (&call_fusage, struct_value);
4769 : : }
4770 : :
4771 : : /* Don't allow popping to be deferred, since then
4772 : : cse'ing of library calls could delete a call and leave the pop. */
4773 : 118850 : NO_DEFER_POP;
4774 : 108769 : valreg = (mem_value == 0 && outmode != VOIDmode
4775 : 225623 : ? hard_libcall_value (outmode, orgfun) : NULL_RTX);
4776 : :
4777 : : /* Stack must be properly aligned now. */
4778 : 237700 : gcc_assert (multiple_p (stack_pointer_delta,
4779 : : PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT));
4780 : :
4781 : 118850 : before_call = get_last_insn ();
4782 : :
4783 : 118850 : if (flag_callgraph_info)
4784 : 0 : record_final_call (SYMBOL_REF_DECL (orgfun), UNKNOWN_LOCATION);
4785 : :
4786 : : /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4787 : : will set inhibit_defer_pop to that value. */
4788 : : /* The return type is needed to decide how many bytes the function pops.
4789 : : Signedness plays no role in that, so for simplicity, we pretend it's
4790 : : always signed. We also assume that the list of arguments passed has
4791 : : no impact, so we pretend it is unknown. */
4792 : :
4793 : 118850 : emit_call_1 (fun, NULL,
4794 : : get_identifier (XSTR (orgfun, 0)),
4795 : : build_function_type (tfom, NULL_TREE),
4796 : : original_args_size.constant, args_size.constant,
4797 : : struct_value_size, call_cookie, valreg,
4798 : : old_inhibit_defer_pop + 1, call_fusage, flags, args_so_far);
4799 : :
4800 : 118850 : if (flag_ipa_ra)
4801 : : {
4802 : 82815 : rtx datum = orgfun;
4803 : 82815 : gcc_assert (GET_CODE (datum) == SYMBOL_REF);
4804 : 82815 : rtx_call_insn *last = last_call_insn ();
4805 : 82815 : add_reg_note (last, REG_CALL_DECL, datum);
4806 : : }
4807 : :
4808 : : /* Right-shift returned value if necessary. */
4809 : 118850 : if (!pcc_struct_value
4810 : 118850 : && TYPE_MODE (tfom) != BLKmode
4811 : 118850 : && targetm.calls.return_in_msb (tfom))
4812 : : {
4813 : 0 : shift_return_value (TYPE_MODE (tfom), false, valreg);
4814 : 0 : valreg = gen_rtx_REG (TYPE_MODE (tfom), REGNO (valreg));
4815 : : }
4816 : :
4817 : 118850 : targetm.calls.end_call_args (args_so_far);
4818 : :
4819 : : /* For calls to `setjmp', etc., inform function.cc:setjmp_warnings
4820 : : that it should complain if nonvolatile values are live. For
4821 : : functions that cannot return, inform flow that control does not
4822 : : fall through. */
4823 : 118850 : if (flags & ECF_NORETURN)
4824 : : {
4825 : : /* The barrier note must be emitted
4826 : : immediately after the CALL_INSN. Some ports emit more than
4827 : : just a CALL_INSN above, so we must search for it here. */
4828 : 0 : rtx_insn *last = get_last_insn ();
4829 : 0 : while (!CALL_P (last))
4830 : : {
4831 : 0 : last = PREV_INSN (last);
4832 : : /* There was no CALL_INSN? */
4833 : 0 : gcc_assert (last != before_call);
4834 : : }
4835 : :
4836 : 0 : emit_barrier_after (last);
4837 : : }
4838 : :
4839 : : /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW
4840 : : and LCT_RETURNS_TWICE, cannot perform non-local gotos. */
4841 : 118850 : if (flags & ECF_NOTHROW)
4842 : : {
4843 : 118850 : rtx_insn *last = get_last_insn ();
4844 : 133648 : while (!CALL_P (last))
4845 : : {
4846 : 14798 : last = PREV_INSN (last);
4847 : : /* There was no CALL_INSN? */
4848 : 14798 : gcc_assert (last != before_call);
4849 : : }
4850 : :
4851 : 118850 : make_reg_eh_region_note_nothrow_nononlocal (last);
4852 : : }
4853 : :
4854 : : /* Now restore inhibit_defer_pop to its actual original value. */
4855 : 118850 : OK_DEFER_POP;
4856 : :
4857 : 118850 : pop_temp_slots ();
4858 : :
4859 : : /* Copy the value to the right place. */
4860 : 118850 : if (outmode != VOIDmode && retval)
4861 : : {
4862 : 116574 : if (mem_value)
4863 : : {
4864 : 10081 : if (value == 0)
4865 : 10081 : value = mem_value;
4866 : 10081 : if (value != mem_value)
4867 : 0 : emit_move_insn (value, mem_value);
4868 : : }
4869 : 106493 : else if (GET_CODE (valreg) == PARALLEL)
4870 : : {
4871 : 0 : if (value == 0)
4872 : 0 : value = gen_reg_rtx (outmode);
4873 : 0 : emit_group_store (value, valreg, NULL_TREE, GET_MODE_SIZE (outmode));
4874 : : }
4875 : : else
4876 : : {
4877 : : /* Convert to the proper mode if a promotion has been active. */
4878 : 106493 : if (GET_MODE (valreg) != outmode)
4879 : : {
4880 : 0 : int unsignedp = TYPE_UNSIGNED (tfom);
4881 : :
4882 : 0 : gcc_assert (promote_function_mode (tfom, outmode, &unsignedp,
4883 : : fndecl ? TREE_TYPE (fndecl) : fntype, 1)
4884 : : == GET_MODE (valreg));
4885 : 0 : valreg = convert_modes (outmode, GET_MODE (valreg), valreg, 0);
4886 : : }
4887 : :
4888 : 106493 : if (value != 0)
4889 : 453 : emit_move_insn (value, valreg);
4890 : : else
4891 : : value = valreg;
4892 : : }
4893 : : }
4894 : :
4895 : 118850 : if (ACCUMULATE_OUTGOING_ARGS)
4896 : : {
4897 : : #ifdef REG_PARM_STACK_SPACE
4898 : 14 : if (save_area)
4899 : 0 : restore_fixed_argument_area (save_area, argblock,
4900 : : high_to_save, low_to_save);
4901 : : #endif
4902 : :
4903 : : /* If we saved any argument areas, restore them. */
4904 : 28 : for (count = 0; count < nargs; count++)
4905 : 14 : if (argvec[count].save_area)
4906 : : {
4907 : 0 : machine_mode save_mode = GET_MODE (argvec[count].save_area);
4908 : 0 : rtx adr = plus_constant (Pmode, argblock,
4909 : : argvec[count].locate.offset.constant);
4910 : 0 : rtx stack_area = gen_rtx_MEM (save_mode,
4911 : : memory_address (save_mode, adr));
4912 : :
4913 : 0 : if (save_mode == BLKmode)
4914 : 0 : emit_block_move (stack_area,
4915 : : validize_mem
4916 : : (copy_rtx (argvec[count].save_area)),
4917 : : (gen_int_mode
4918 : 0 : (argvec[count].locate.size.constant, Pmode)),
4919 : : BLOCK_OP_CALL_PARM);
4920 : : else
4921 : 0 : emit_move_insn (stack_area, argvec[count].save_area);
4922 : : }
4923 : :
4924 : 14 : highest_outgoing_arg_in_use = initial_highest_arg_in_use;
4925 : 14 : stack_usage_map = initial_stack_usage_map;
4926 : 14 : stack_usage_watermark = initial_stack_usage_watermark;
4927 : : }
4928 : :
4929 : 118850 : free (stack_usage_map_buf);
4930 : :
4931 : 118850 : return value;
4932 : :
4933 : : }
4934 : :
4935 : :
4936 : : /* Store a single argument for a function call
4937 : : into the register or memory area where it must be passed.
4938 : : *ARG describes the argument value and where to pass it.
4939 : :
4940 : : ARGBLOCK is the address of the stack-block for all the arguments,
4941 : : or 0 on a machine where arguments are pushed individually.
4942 : :
4943 : : MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4944 : : so must be careful about how the stack is used.
4945 : :
4946 : : VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4947 : : argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4948 : : that we need not worry about saving and restoring the stack.
4949 : :
4950 : : FNDECL is the declaration of the function we are calling.
4951 : :
4952 : : Return true if this arg should cause sibcall failure,
4953 : : false otherwise. */
4954 : :
4955 : : static bool
4956 : 2118023 : store_one_arg (struct arg_data *arg, rtx argblock, int flags,
4957 : : int variable_size ATTRIBUTE_UNUSED, int reg_parm_stack_space)
4958 : : {
4959 : 2118023 : tree pval = arg->tree_value;
4960 : 2118023 : rtx reg = 0;
4961 : 2118023 : int partial = 0;
4962 : 2118023 : poly_int64 used = 0;
4963 : 2118023 : poly_int64 lower_bound = 0, upper_bound = 0;
4964 : 2118023 : bool sibcall_failure = false;
4965 : :
4966 : 2118023 : if (TREE_CODE (pval) == ERROR_MARK)
4967 : : return true;
4968 : :
4969 : : /* Push a new temporary level for any temporaries we make for
4970 : : this argument. */
4971 : 2118023 : push_temp_slots ();
4972 : :
4973 : 2118023 : if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL))
4974 : : {
4975 : : /* If this is being stored into a pre-allocated, fixed-size, stack area,
4976 : : save any previous data at that location. */
4977 : 53898 : if (argblock && ! variable_size && arg->stack)
4978 : : {
4979 : 53816 : if (ARGS_GROW_DOWNWARD)
4980 : : {
4981 : : /* stack_slot is negative, but we want to index stack_usage_map
4982 : : with positive values. */
4983 : : if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4984 : : {
4985 : : rtx offset = XEXP (XEXP (arg->stack_slot, 0), 1);
4986 : : upper_bound = -rtx_to_poly_int64 (offset) + 1;
4987 : : }
4988 : : else
4989 : : upper_bound = 0;
4990 : :
4991 : : lower_bound = upper_bound - arg->locate.size.constant;
4992 : : }
4993 : : else
4994 : : {
4995 : 53816 : if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4996 : : {
4997 : 42128 : rtx offset = XEXP (XEXP (arg->stack_slot, 0), 1);
4998 : 42128 : lower_bound = rtx_to_poly_int64 (offset);
4999 : : }
5000 : : else
5001 : : lower_bound = 0;
5002 : :
5003 : 53816 : upper_bound = lower_bound + arg->locate.size.constant;
5004 : : }
5005 : :
5006 : 53816 : if (stack_region_maybe_used_p (lower_bound, upper_bound,
5007 : : reg_parm_stack_space))
5008 : : {
5009 : : /* We need to make a save area. */
5010 : 0 : poly_uint64 size = arg->locate.size.constant * BITS_PER_UNIT;
5011 : 0 : machine_mode save_mode
5012 : 0 : = int_mode_for_size (size, 1).else_blk ();
5013 : 0 : rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0));
5014 : 0 : rtx stack_area = gen_rtx_MEM (save_mode, adr);
5015 : :
5016 : 0 : if (save_mode == BLKmode)
5017 : : {
5018 : 0 : arg->save_area
5019 : 0 : = assign_temp (TREE_TYPE (arg->tree_value), 1, 1);
5020 : 0 : preserve_temp_slots (arg->save_area);
5021 : 0 : emit_block_move (validize_mem (copy_rtx (arg->save_area)),
5022 : : stack_area,
5023 : : (gen_int_mode
5024 : 0 : (arg->locate.size.constant, Pmode)),
5025 : : BLOCK_OP_CALL_PARM);
5026 : : }
5027 : : else
5028 : : {
5029 : 0 : arg->save_area = gen_reg_rtx (save_mode);
5030 : 0 : emit_move_insn (arg->save_area, stack_area);
5031 : : }
5032 : : }
5033 : : }
5034 : : }
5035 : :
5036 : : /* If this isn't going to be placed on both the stack and in registers,
5037 : : set up the register and number of words. */
5038 : 2118023 : if (! arg->pass_on_stack)
5039 : : {
5040 : 2118023 : if (flags & ECF_SIBCALL)
5041 : 9875 : reg = arg->tail_call_reg;
5042 : : else
5043 : 2108148 : reg = arg->reg;
5044 : 2118023 : partial = arg->partial;
5045 : : }
5046 : :
5047 : : /* Being passed entirely in a register. We shouldn't be called in
5048 : : this case. */
5049 : 2118023 : gcc_assert (reg == 0 || partial != 0);
5050 : :
5051 : : /* If this arg needs special alignment, don't load the registers
5052 : : here. */
5053 : 2118023 : if (arg->n_aligned_regs != 0)
5054 : 0 : reg = 0;
5055 : :
5056 : : /* If this is being passed partially in a register, we can't evaluate
5057 : : it directly into its stack slot. Otherwise, we can. */
5058 : 2118023 : if (arg->value == 0)
5059 : : {
5060 : : /* stack_arg_under_construction is nonzero if a function argument is
5061 : : being evaluated directly into the outgoing argument list and
5062 : : expand_call must take special action to preserve the argument list
5063 : : if it is called recursively.
5064 : :
5065 : : For scalar function arguments stack_usage_map is sufficient to
5066 : : determine which stack slots must be saved and restored. Scalar
5067 : : arguments in general have pass_on_stack == false.
5068 : :
5069 : : If this argument is initialized by a function which takes the
5070 : : address of the argument (a C++ constructor or a C function
5071 : : returning a BLKmode structure), then stack_usage_map is
5072 : : insufficient and expand_call must push the stack around the
5073 : : function call. Such arguments have pass_on_stack == true.
5074 : :
5075 : : Note that it is always safe to set stack_arg_under_construction,
5076 : : but this generates suboptimal code if set when not needed. */
5077 : :
5078 : 2118023 : if (arg->pass_on_stack)
5079 : 0 : stack_arg_under_construction++;
5080 : :
5081 : 4236046 : arg->value = expand_expr (pval,
5082 : : (partial
5083 : 2118023 : || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
5084 : : ? NULL_RTX : arg->stack,
5085 : : VOIDmode, EXPAND_STACK_PARM);
5086 : :
5087 : : /* If we are promoting object (or for any other reason) the mode
5088 : : doesn't agree, convert the mode. */
5089 : :
5090 : 2118023 : if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
5091 : 0 : arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
5092 : : arg->value, arg->unsignedp);
5093 : :
5094 : 2118023 : if (arg->pass_on_stack)
5095 : 0 : stack_arg_under_construction--;
5096 : : }
5097 : :
5098 : : /* Check for overlap with already clobbered argument area. */
5099 : 2118023 : if ((flags & ECF_SIBCALL)
5100 : 9875 : && MEM_P (arg->value)
5101 : 2127898 : && mem_might_overlap_already_clobbered_arg_p (XEXP (arg->value, 0),
5102 : 462 : arg->locate.size.constant))
5103 : 4 : sibcall_failure = true;
5104 : :
5105 : : /* Don't allow anything left on stack from computation
5106 : : of argument to alloca. */
5107 : 2118023 : if (flags & ECF_MAY_BE_ALLOCA)
5108 : 0 : do_pending_stack_adjust ();
5109 : :
5110 : 2118023 : if (arg->value == arg->stack)
5111 : : /* If the value is already in the stack slot, we are done. */
5112 : : ;
5113 : 2109374 : else if (arg->mode != BLKmode)
5114 : : {
5115 : 1840964 : unsigned int parm_align;
5116 : :
5117 : : /* Argument is a scalar, not entirely passed in registers.
5118 : : (If part is passed in registers, arg->partial says how much
5119 : : and emit_push_insn will take care of putting it there.)
5120 : :
5121 : : Push it, and if its size is less than the
5122 : : amount of space allocated to it,
5123 : : also bump stack pointer by the additional space.
5124 : : Note that in C the default argument promotions
5125 : : will prevent such mismatches. */
5126 : :
5127 : 1840964 : poly_int64 size = (TYPE_EMPTY_P (TREE_TYPE (pval))
5128 : 3681928 : ? 0 : GET_MODE_SIZE (arg->mode));
5129 : :
5130 : : /* Compute how much space the push instruction will push.
5131 : : On many machines, pushing a byte will advance the stack
5132 : : pointer by a halfword. */
5133 : : #ifdef PUSH_ROUNDING
5134 : 1840964 : size = PUSH_ROUNDING (size);
5135 : : #endif
5136 : 1840964 : used = size;
5137 : :
5138 : : /* Compute how much space the argument should get:
5139 : : round up to a multiple of the alignment for arguments. */
5140 : 1840964 : if (targetm.calls.function_arg_padding (arg->mode, TREE_TYPE (pval))
5141 : : != PAD_NONE)
5142 : : /* At the moment we don't (need to) support ABIs for which the
5143 : : padding isn't known at compile time. In principle it should
5144 : : be easy to add though. */
5145 : 3239354 : used = force_align_up (size, PARM_BOUNDARY / BITS_PER_UNIT);
5146 : :
5147 : : /* Compute the alignment of the pushed argument. */
5148 : 1840964 : parm_align = arg->locate.boundary;
5149 : 1840964 : if (targetm.calls.function_arg_padding (arg->mode, TREE_TYPE (pval))
5150 : : == PAD_DOWNWARD)
5151 : : {
5152 : 0 : poly_int64 pad = used - size;
5153 : 0 : unsigned int pad_align = known_alignment (pad) * BITS_PER_UNIT;
5154 : 0 : if (pad_align != 0)
5155 : 0 : parm_align = MIN (parm_align, pad_align);
5156 : : }
5157 : :
5158 : : /* This isn't already where we want it on the stack, so put it there.
5159 : : This can either be done with push or copy insns. */
5160 : 1840964 : if (maybe_ne (used, 0)
5161 : 3673721 : && !emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval),
5162 : : NULL_RTX, parm_align, partial, reg, used - size,
5163 : 1832757 : argblock, ARGS_SIZE_RTX (arg->locate.offset),
5164 : : reg_parm_stack_space,
5165 : 1832757 : ARGS_SIZE_RTX (arg->locate.alignment_pad), true))
5166 : : sibcall_failure = true;
5167 : :
5168 : : /* Unless this is a partially-in-register argument, the argument is now
5169 : : in the stack. */
5170 : 1840964 : if (partial == 0)
5171 : 1840964 : arg->value = arg->stack;
5172 : : }
5173 : : else
5174 : : {
5175 : : /* BLKmode, at least partly to be pushed. */
5176 : :
5177 : 268410 : unsigned int parm_align;
5178 : 268410 : poly_int64 excess;
5179 : 268410 : rtx size_rtx;
5180 : :
5181 : : /* Pushing a nonscalar.
5182 : : If part is passed in registers, PARTIAL says how much
5183 : : and emit_push_insn will take care of putting it there. */
5184 : :
5185 : : /* Round its size up to a multiple
5186 : : of the allocation unit for arguments. */
5187 : :
5188 : 268410 : if (arg->locate.size.var != 0)
5189 : : {
5190 : 0 : excess = 0;
5191 : 0 : size_rtx = ARGS_SIZE_RTX (arg->locate.size);
5192 : : }
5193 : : else
5194 : : {
5195 : : /* PUSH_ROUNDING has no effect on us, because emit_push_insn
5196 : : for BLKmode is careful to avoid it. */
5197 : 268410 : excess = (arg->locate.size.constant
5198 : 268410 : - arg_int_size_in_bytes (TREE_TYPE (pval))
5199 : 268410 : + partial);
5200 : 268410 : size_rtx = expand_expr (arg_size_in_bytes (TREE_TYPE (pval)),
5201 : 268410 : NULL_RTX, TYPE_MODE (sizetype),
5202 : : EXPAND_NORMAL);
5203 : : }
5204 : :
5205 : 268410 : parm_align = arg->locate.boundary;
5206 : :
5207 : : /* When an argument is padded down, the block is aligned to
5208 : : PARM_BOUNDARY, but the actual argument isn't. */
5209 : 268410 : if (targetm.calls.function_arg_padding (arg->mode, TREE_TYPE (pval))
5210 : : == PAD_DOWNWARD)
5211 : : {
5212 : 0 : if (arg->locate.size.var)
5213 : : parm_align = BITS_PER_UNIT;
5214 : : else
5215 : : {
5216 : 0 : unsigned int excess_align
5217 : 0 : = known_alignment (excess) * BITS_PER_UNIT;
5218 : 0 : if (excess_align != 0)
5219 : 0 : parm_align = MIN (parm_align, excess_align);
5220 : : }
5221 : : }
5222 : :
5223 : 268410 : if ((flags & ECF_SIBCALL) && MEM_P (arg->value))
5224 : : {
5225 : : /* emit_push_insn might not work properly if arg->value and
5226 : : argblock + arg->locate.offset areas overlap. */
5227 : 78 : rtx x = arg->value;
5228 : 78 : poly_int64 i = 0;
5229 : :
5230 : 78 : if (strip_offset (XEXP (x, 0), &i)
5231 : 78 : == crtl->args.internal_arg_pointer)
5232 : : {
5233 : : /* arg.locate doesn't contain the pretend_args_size offset,
5234 : : it's part of argblock. Ensure we don't count it in I. */
5235 : 22 : if (STACK_GROWS_DOWNWARD)
5236 : 22 : i -= crtl->args.pretend_args_size;
5237 : : else
5238 : : i += crtl->args.pretend_args_size;
5239 : :
5240 : : /* expand_call should ensure this. */
5241 : 22 : gcc_assert (!arg->locate.offset.var
5242 : : && arg->locate.size.var == 0);
5243 : 22 : poly_int64 size_val = rtx_to_poly_int64 (size_rtx);
5244 : :
5245 : 22 : if (known_eq (arg->locate.offset.constant, i))
5246 : : {
5247 : : /* Even though they appear to be at the same location,
5248 : : if part of the outgoing argument is in registers,
5249 : : they aren't really at the same location. Check for
5250 : : this by making sure that the incoming size is the
5251 : : same as the outgoing size. */
5252 : 16 : if (partial != 0)
5253 : 78 : sibcall_failure = true;
5254 : : }
5255 : 6 : else if (maybe_in_range_p (arg->locate.offset.constant,
5256 : : i, size_val))
5257 : : sibcall_failure = true;
5258 : : /* Use arg->locate.size.constant instead of size_rtx
5259 : : because we only care about the part of the argument
5260 : : on the stack. */
5261 : 6 : else if (maybe_in_range_p (i, arg->locate.offset.constant,
5262 : 6 : arg->locate.size.constant))
5263 : 78 : sibcall_failure = true;
5264 : : }
5265 : : }
5266 : :
5267 : 268410 : if (!CONST_INT_P (size_rtx) || INTVAL (size_rtx) != 0)
5268 : 266337 : emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
5269 : : parm_align, partial, reg, excess, argblock,
5270 : 266337 : ARGS_SIZE_RTX (arg->locate.offset),
5271 : : reg_parm_stack_space,
5272 : 266337 : ARGS_SIZE_RTX (arg->locate.alignment_pad), false);
5273 : : /* If we bypass emit_push_insn because it is a zero sized argument,
5274 : : we still might need to adjust stack if such argument requires
5275 : : extra alignment. See PR104558. */
5276 : 2073 : else if ((arg->locate.alignment_pad.var
5277 : 2073 : || maybe_ne (arg->locate.alignment_pad.constant, 0))
5278 : 2074 : && !argblock)
5279 : 1 : anti_adjust_stack (ARGS_SIZE_RTX (arg->locate.alignment_pad));
5280 : :
5281 : : /* Unless this is a partially-in-register argument, the argument is now
5282 : : in the stack.
5283 : :
5284 : : ??? Unlike the case above, in which we want the actual
5285 : : address of the data, so that we can load it directly into a
5286 : : register, here we want the address of the stack slot, so that
5287 : : it's properly aligned for word-by-word copying or something
5288 : : like that. It's not clear that this is always correct. */
5289 : 268410 : if (partial == 0)
5290 : 268410 : arg->value = arg->stack_slot;
5291 : : }
5292 : :
5293 : 2118023 : if (arg->reg && GET_CODE (arg->reg) == PARALLEL)
5294 : : {
5295 : 0 : tree type = TREE_TYPE (arg->tree_value);
5296 : 0 : arg->parallel_value
5297 : 0 : = emit_group_load_into_temps (arg->reg, arg->value, type,
5298 : 0 : int_size_in_bytes (type));
5299 : : }
5300 : :
5301 : : /* Mark all slots this store used. */
5302 : 2118023 : if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)
5303 : 2171921 : && argblock && ! variable_size && arg->stack)
5304 : 53816 : mark_stack_region_used (lower_bound, upper_bound);
5305 : :
5306 : : /* Once we have pushed something, pops can't safely
5307 : : be deferred during the rest of the arguments. */
5308 : 2118023 : NO_DEFER_POP;
5309 : :
5310 : : /* Free any temporary slots made in processing this argument. */
5311 : 2118023 : pop_temp_slots ();
5312 : :
5313 : 2118023 : return sibcall_failure;
5314 : : }
5315 : :
5316 : : /* Nonzero if we do not know how to pass ARG solely in registers. */
5317 : :
5318 : : bool
5319 : 0 : must_pass_in_stack_var_size (const function_arg_info &arg)
5320 : : {
5321 : 0 : if (!arg.type)
5322 : : return false;
5323 : :
5324 : : /* If the type has variable size... */
5325 : 0 : if (!poly_int_tree_p (TYPE_SIZE (arg.type)))
5326 : : return true;
5327 : :
5328 : : /* If the type is marked as addressable (it is required
5329 : : to be constructed into the stack)... */
5330 : 0 : if (TREE_ADDRESSABLE (arg.type))
5331 : 0 : return true;
5332 : :
5333 : : return false;
5334 : : }
5335 : :
5336 : : /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
5337 : : takes trailing padding of a structure into account. */
5338 : : /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
5339 : :
5340 : : bool
5341 : 367484165 : must_pass_in_stack_var_size_or_pad (const function_arg_info &arg)
5342 : : {
5343 : 367484165 : if (!arg.type)
5344 : : return false;
5345 : :
5346 : : /* If the type has variable size... */
5347 : 366764052 : if (TREE_CODE (TYPE_SIZE (arg.type)) != INTEGER_CST)
5348 : : return true;
5349 : :
5350 : : /* If the type is marked as addressable (it is required
5351 : : to be constructed into the stack)... */
5352 : 366764052 : if (TREE_ADDRESSABLE (arg.type))
5353 : : return true;
5354 : :
5355 : 366764015 : if (TYPE_EMPTY_P (arg.type))
5356 : : return false;
5357 : :
5358 : : /* If the padding and mode of the type is such that a copy into
5359 : : a register would put it into the wrong part of the register. */
5360 : 364967421 : if (arg.mode == BLKmode
5361 : 5401841 : && int_size_in_bytes (arg.type) % (PARM_BOUNDARY / BITS_PER_UNIT)
5362 : 365317569 : && (targetm.calls.function_arg_padding (arg.mode, arg.type)
5363 : : == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)))
5364 : : return true;
5365 : :
5366 : : return false;
5367 : : }
5368 : :
5369 : : /* Return true if TYPE must be passed on the stack when passed to
5370 : : the "..." arguments of a function. */
5371 : :
5372 : : bool
5373 : 0 : must_pass_va_arg_in_stack (tree type)
5374 : : {
5375 : 0 : function_arg_info arg (type, /*named=*/false);
5376 : 0 : return targetm.calls.must_pass_in_stack (arg);
5377 : : }
5378 : :
5379 : : /* Return true if FIELD is the C++17 empty base field that should
5380 : : be ignored for ABI calling convention decisions in order to
5381 : : maintain ABI compatibility between C++14 and earlier, which doesn't
5382 : : add this FIELD to classes with empty bases, and C++17 and later
5383 : : which does. */
5384 : :
5385 : : bool
5386 : 0 : cxx17_empty_base_field_p (const_tree field)
5387 : : {
5388 : 0 : return (DECL_FIELD_ABI_IGNORED (field)
5389 : 0 : && DECL_ARTIFICIAL (field)
5390 : 0 : && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
5391 : 0 : && !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (field)));
5392 : : }
|