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