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