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