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