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