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