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