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