]>
Commit | Line | Data |
---|---|---|
51bbfa0c RS |
1 | /* Convert function calls to rtl insns, for GNU C compiler. |
2 | Copyright (C) 1989, 1992 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GNU CC. | |
5 | ||
6 | GNU CC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU CC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU CC; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | #include "config.h" | |
21 | #include "rtl.h" | |
22 | #include "tree.h" | |
23 | #include "flags.h" | |
24 | #include "expr.h" | |
25 | #include "insn-flags.h" | |
26 | ||
27 | /* Decide whether a function's arguments should be processed | |
28 | from first to last or from last to first. */ | |
29 | ||
30 | #ifdef STACK_GROWS_DOWNWARD | |
31 | #ifdef PUSH_ROUNDING | |
32 | #define PUSH_ARGS_REVERSED /* If it's last to first */ | |
33 | #endif | |
34 | #endif | |
35 | ||
36 | /* Like STACK_BOUNDARY but in units of bytes, not bits. */ | |
37 | #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT) | |
38 | ||
39 | /* Data structure and subroutines used within expand_call. */ | |
40 | ||
41 | struct arg_data | |
42 | { | |
43 | /* Tree node for this argument. */ | |
44 | tree tree_value; | |
45 | /* Current RTL value for argument, or 0 if it isn't precomputed. */ | |
46 | rtx value; | |
47 | /* Initially-compute RTL value for argument; only for const functions. */ | |
48 | rtx initial_value; | |
49 | /* Register to pass this argument in, 0 if passed on stack, or an | |
50 | EXPR_LIST if the arg is to be copied into multiple different | |
51 | registers. */ | |
52 | rtx reg; | |
53 | /* Number of registers to use. 0 means put the whole arg in registers. | |
54 | Also 0 if not passed in registers. */ | |
55 | int partial; | |
d64f5a78 RS |
56 | /* Non-zero if argument must be passed on stack. |
57 | Note that some arguments may be passed on the stack | |
58 | even though pass_on_stack is zero, just because FUNCTION_ARG says so. | |
59 | pass_on_stack identifies arguments that *cannot* go in registers. */ | |
51bbfa0c RS |
60 | int pass_on_stack; |
61 | /* Offset of this argument from beginning of stack-args. */ | |
62 | struct args_size offset; | |
63 | /* Similar, but offset to the start of the stack slot. Different from | |
64 | OFFSET if this arg pads downward. */ | |
65 | struct args_size slot_offset; | |
66 | /* Size of this argument on the stack, rounded up for any padding it gets, | |
67 | parts of the argument passed in registers do not count. | |
68 | If REG_PARM_STACK_SPACE is defined, then register parms | |
69 | are counted here as well. */ | |
70 | struct args_size size; | |
71 | /* Location on the stack at which parameter should be stored. The store | |
72 | has already been done if STACK == VALUE. */ | |
73 | rtx stack; | |
74 | /* Location on the stack of the start of this argument slot. This can | |
75 | differ from STACK if this arg pads downward. This location is known | |
76 | to be aligned to FUNCTION_ARG_BOUNDARY. */ | |
77 | rtx stack_slot; | |
78 | #ifdef ACCUMULATE_OUTGOING_ARGS | |
79 | /* Place that this stack area has been saved, if needed. */ | |
80 | rtx save_area; | |
81 | #endif | |
82 | }; | |
83 | ||
84 | #ifdef ACCUMULATE_OUTGOING_ARGS | |
85 | /* A vector of one char per word of stack space. A byte if non-zero if | |
86 | the corresponding stack location has been used. | |
87 | This vector is used to prevent a function call within an argument from | |
88 | clobbering any stack already set up. */ | |
89 | static char *stack_usage_map; | |
90 | ||
91 | /* Size of STACK_USAGE_MAP. */ | |
92 | static int highest_outgoing_arg_in_use; | |
2f4aa534 RS |
93 | |
94 | /* stack_arg_under_construction is nonzero when an argument may be | |
95 | initialized with a constructor call (including a C function that | |
96 | returns a BLKmode struct) and expand_call must take special action | |
97 | to make sure the object being constructed does not overlap the | |
98 | argument list for the constructor call. */ | |
99 | int stack_arg_under_construction; | |
51bbfa0c RS |
100 | #endif |
101 | ||
102 | static void store_one_arg (); | |
103 | extern enum machine_mode mode_for_size (); | |
104 | \f | |
105 | /* Return 1 if EXP contains a call to the built-in function `alloca'. */ | |
106 | ||
107 | static int | |
108 | calls_alloca (exp) | |
109 | tree exp; | |
110 | { | |
111 | register int i; | |
112 | int type = TREE_CODE_CLASS (TREE_CODE (exp)); | |
113 | int length = tree_code_length[(int) TREE_CODE (exp)]; | |
114 | ||
115 | /* Only expressions and references can contain calls. */ | |
116 | ||
117 | if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r') | |
118 | return 0; | |
119 | ||
120 | switch (TREE_CODE (exp)) | |
121 | { | |
122 | case CALL_EXPR: | |
123 | if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR | |
124 | && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) | |
125 | == FUNCTION_DECL) | |
126 | && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) | |
127 | && (DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) | |
128 | == BUILT_IN_ALLOCA)) | |
129 | return 1; | |
130 | ||
131 | /* Third operand is RTL. */ | |
132 | length = 2; | |
133 | break; | |
134 | ||
135 | case SAVE_EXPR: | |
136 | if (SAVE_EXPR_RTL (exp) != 0) | |
137 | return 0; | |
138 | break; | |
139 | ||
140 | case BLOCK: | |
141 | /* Must not look at BLOCK_SUPERCONTEXT since it will point back to | |
142 | us. */ | |
143 | length = 3; | |
144 | break; | |
145 | ||
146 | case METHOD_CALL_EXPR: | |
147 | length = 3; | |
148 | break; | |
149 | ||
150 | case WITH_CLEANUP_EXPR: | |
151 | length = 1; | |
152 | break; | |
153 | ||
154 | case RTL_EXPR: | |
155 | return 0; | |
156 | } | |
157 | ||
158 | for (i = 0; i < length; i++) | |
159 | if (TREE_OPERAND (exp, i) != 0 | |
160 | && calls_alloca (TREE_OPERAND (exp, i))) | |
161 | return 1; | |
162 | ||
163 | return 0; | |
164 | } | |
165 | \f | |
166 | /* Force FUNEXP into a form suitable for the address of a CALL, | |
167 | and return that as an rtx. Also load the static chain register | |
168 | if FNDECL is a nested function. | |
169 | ||
170 | USE_INSNS points to a variable holding a chain of USE insns | |
171 | to which a USE of the static chain | |
172 | register should be added, if required. */ | |
173 | ||
174 | rtx | |
175 | prepare_call_address (funexp, fndecl, use_insns) | |
176 | rtx funexp; | |
177 | tree fndecl; | |
178 | rtx *use_insns; | |
179 | { | |
180 | rtx static_chain_value = 0; | |
181 | ||
182 | funexp = protect_from_queue (funexp, 0); | |
183 | ||
184 | if (fndecl != 0) | |
185 | /* Get possible static chain value for nested function in C. */ | |
186 | static_chain_value = lookup_static_chain (fndecl); | |
187 | ||
188 | /* Make a valid memory address and copy constants thru pseudo-regs, | |
189 | but not for a constant address if -fno-function-cse. */ | |
190 | if (GET_CODE (funexp) != SYMBOL_REF) | |
191 | funexp = memory_address (FUNCTION_MODE, funexp); | |
192 | else | |
193 | { | |
194 | #ifndef NO_FUNCTION_CSE | |
195 | if (optimize && ! flag_no_function_cse) | |
196 | #ifdef NO_RECURSIVE_FUNCTION_CSE | |
197 | if (fndecl != current_function_decl) | |
198 | #endif | |
199 | funexp = force_reg (Pmode, funexp); | |
200 | #endif | |
201 | } | |
202 | ||
203 | if (static_chain_value != 0) | |
204 | { | |
205 | emit_move_insn (static_chain_rtx, static_chain_value); | |
206 | ||
207 | /* Put the USE insn in the chain we were passed. It will later be | |
208 | output immediately in front of the CALL insn. */ | |
209 | push_to_sequence (*use_insns); | |
210 | emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx)); | |
211 | *use_insns = get_insns (); | |
212 | end_sequence (); | |
213 | } | |
214 | ||
215 | return funexp; | |
216 | } | |
217 | ||
218 | /* Generate instructions to call function FUNEXP, | |
219 | and optionally pop the results. | |
220 | The CALL_INSN is the first insn generated. | |
221 | ||
222 | FUNTYPE is the data type of the function, or, for a library call, | |
223 | the identifier for the name of the call. This is given to the | |
224 | macro RETURN_POPS_ARGS to determine whether this function pops its own args. | |
225 | ||
226 | STACK_SIZE is the number of bytes of arguments on the stack, | |
227 | rounded up to STACK_BOUNDARY; zero if the size is variable. | |
228 | This is both to put into the call insn and | |
229 | to generate explicit popping code if necessary. | |
230 | ||
231 | STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value. | |
232 | It is zero if this call doesn't want a structure value. | |
233 | ||
234 | NEXT_ARG_REG is the rtx that results from executing | |
235 | FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1) | |
236 | just after all the args have had their registers assigned. | |
237 | This could be whatever you like, but normally it is the first | |
238 | arg-register beyond those used for args in this call, | |
239 | or 0 if all the arg-registers are used in this call. | |
240 | It is passed on to `gen_call' so you can put this info in the call insn. | |
241 | ||
242 | VALREG is a hard register in which a value is returned, | |
243 | or 0 if the call does not return a value. | |
244 | ||
245 | OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before | |
246 | the args to this call were processed. | |
247 | We restore `inhibit_defer_pop' to that value. | |
248 | ||
249 | USE_INSNS is a chain of USE insns to be emitted immediately before | |
250 | the actual CALL insn. | |
251 | ||
252 | IS_CONST is true if this is a `const' call. */ | |
253 | ||
254 | void | |
255 | emit_call_1 (funexp, funtype, stack_size, struct_value_size, next_arg_reg, | |
256 | valreg, old_inhibit_defer_pop, use_insns, is_const) | |
257 | rtx funexp; | |
258 | tree funtype; | |
259 | int stack_size; | |
260 | int struct_value_size; | |
261 | rtx next_arg_reg; | |
262 | rtx valreg; | |
263 | int old_inhibit_defer_pop; | |
264 | rtx use_insns; | |
265 | int is_const; | |
266 | { | |
267 | rtx stack_size_rtx = gen_rtx (CONST_INT, VOIDmode, stack_size); | |
268 | rtx struct_value_size_rtx = gen_rtx (CONST_INT, VOIDmode, struct_value_size); | |
269 | rtx call_insn; | |
270 | int already_popped = 0; | |
271 | ||
272 | /* Ensure address is valid. SYMBOL_REF is already valid, so no need, | |
273 | and we don't want to load it into a register as an optimization, | |
274 | because prepare_call_address already did it if it should be done. */ | |
275 | if (GET_CODE (funexp) != SYMBOL_REF) | |
276 | funexp = memory_address (FUNCTION_MODE, funexp); | |
277 | ||
278 | #ifndef ACCUMULATE_OUTGOING_ARGS | |
279 | #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop) | |
280 | if (HAVE_call_pop && HAVE_call_value_pop | |
281 | && (RETURN_POPS_ARGS (funtype, stack_size) > 0 || stack_size == 0)) | |
282 | { | |
283 | rtx n_pop = gen_rtx (CONST_INT, VOIDmode, | |
284 | RETURN_POPS_ARGS (funtype, stack_size)); | |
285 | rtx pat; | |
286 | ||
287 | /* If this subroutine pops its own args, record that in the call insn | |
288 | if possible, for the sake of frame pointer elimination. */ | |
289 | if (valreg) | |
290 | pat = gen_call_value_pop (valreg, | |
291 | gen_rtx (MEM, FUNCTION_MODE, funexp), | |
292 | stack_size_rtx, next_arg_reg, n_pop); | |
293 | else | |
294 | pat = gen_call_pop (gen_rtx (MEM, FUNCTION_MODE, funexp), | |
295 | stack_size_rtx, next_arg_reg, n_pop); | |
296 | ||
297 | emit_call_insn (pat); | |
298 | already_popped = 1; | |
299 | } | |
300 | else | |
301 | #endif | |
302 | #endif | |
303 | ||
304 | #if defined (HAVE_call) && defined (HAVE_call_value) | |
305 | if (HAVE_call && HAVE_call_value) | |
306 | { | |
307 | if (valreg) | |
308 | emit_call_insn (gen_call_value (valreg, | |
309 | gen_rtx (MEM, FUNCTION_MODE, funexp), | |
310 | stack_size_rtx, next_arg_reg)); | |
311 | else | |
312 | emit_call_insn (gen_call (gen_rtx (MEM, FUNCTION_MODE, funexp), | |
313 | stack_size_rtx, next_arg_reg, | |
314 | struct_value_size_rtx)); | |
315 | } | |
316 | else | |
317 | #endif | |
318 | abort (); | |
319 | ||
320 | /* Find the CALL insn we just emitted and write the USE insns before it. */ | |
321 | for (call_insn = get_last_insn (); | |
322 | call_insn && GET_CODE (call_insn) != CALL_INSN; | |
323 | call_insn = PREV_INSN (call_insn)) | |
324 | ; | |
325 | ||
326 | if (! call_insn) | |
327 | abort (); | |
328 | ||
329 | /* Put the USE insns before the CALL. */ | |
330 | emit_insns_before (use_insns, call_insn); | |
331 | ||
332 | /* If this is a const call, then set the insn's unchanging bit. */ | |
333 | if (is_const) | |
334 | CONST_CALL_P (call_insn) = 1; | |
335 | ||
51bbfa0c RS |
336 | #ifndef ACCUMULATE_OUTGOING_ARGS |
337 | /* If returning from the subroutine does not automatically pop the args, | |
338 | we need an instruction to pop them sooner or later. | |
339 | Perhaps do it now; perhaps just record how much space to pop later. | |
340 | ||
341 | If returning from the subroutine does pop the args, indicate that the | |
342 | stack pointer will be changed. */ | |
343 | ||
344 | if (stack_size != 0 && RETURN_POPS_ARGS (funtype, stack_size) > 0) | |
345 | { | |
346 | if (!already_popped) | |
347 | emit_insn (gen_rtx (CLOBBER, VOIDmode, stack_pointer_rtx)); | |
348 | stack_size -= RETURN_POPS_ARGS (funtype, stack_size); | |
349 | stack_size_rtx = gen_rtx (CONST_INT, VOIDmode, stack_size); | |
350 | } | |
351 | ||
352 | if (stack_size != 0) | |
353 | { | |
354 | if (flag_defer_pop && inhibit_defer_pop == 0) | |
355 | pending_stack_adjust += stack_size; | |
356 | else | |
357 | adjust_stack (stack_size_rtx); | |
358 | } | |
359 | #endif | |
ff1e9821 RS |
360 | |
361 | inhibit_defer_pop = old_inhibit_defer_pop; | |
51bbfa0c RS |
362 | } |
363 | ||
364 | /* Generate all the code for a function call | |
365 | and return an rtx for its value. | |
366 | Store the value in TARGET (specified as an rtx) if convenient. | |
367 | If the value is stored in TARGET then TARGET is returned. | |
368 | If IGNORE is nonzero, then we ignore the value of the function call. */ | |
369 | ||
370 | rtx | |
8129842c | 371 | expand_call (exp, target, ignore) |
51bbfa0c RS |
372 | tree exp; |
373 | rtx target; | |
374 | int ignore; | |
51bbfa0c RS |
375 | { |
376 | /* List of actual parameters. */ | |
377 | tree actparms = TREE_OPERAND (exp, 1); | |
378 | /* RTX for the function to be called. */ | |
379 | rtx funexp; | |
380 | /* Tree node for the function to be called (not the address!). */ | |
381 | tree funtree; | |
382 | /* Data type of the function. */ | |
383 | tree funtype; | |
384 | /* Declaration of the function being called, | |
385 | or 0 if the function is computed (not known by name). */ | |
386 | tree fndecl = 0; | |
387 | char *name = 0; | |
388 | ||
389 | /* Register in which non-BLKmode value will be returned, | |
390 | or 0 if no value or if value is BLKmode. */ | |
391 | rtx valreg; | |
392 | /* Address where we should return a BLKmode value; | |
393 | 0 if value not BLKmode. */ | |
394 | rtx structure_value_addr = 0; | |
395 | /* Nonzero if that address is being passed by treating it as | |
396 | an extra, implicit first parameter. Otherwise, | |
397 | it is passed by being copied directly into struct_value_rtx. */ | |
398 | int structure_value_addr_parm = 0; | |
399 | /* Size of aggregate value wanted, or zero if none wanted | |
400 | or if we are using the non-reentrant PCC calling convention | |
401 | or expecting the value in registers. */ | |
402 | int struct_value_size = 0; | |
403 | /* Nonzero if called function returns an aggregate in memory PCC style, | |
404 | by returning the address of where to find it. */ | |
405 | int pcc_struct_value = 0; | |
406 | ||
407 | /* Number of actual parameters in this call, including struct value addr. */ | |
408 | int num_actuals; | |
409 | /* Number of named args. Args after this are anonymous ones | |
410 | and they must all go on the stack. */ | |
411 | int n_named_args; | |
412 | /* Count arg position in order args appear. */ | |
413 | int argpos; | |
414 | ||
415 | /* Vector of information about each argument. | |
416 | Arguments are numbered in the order they will be pushed, | |
417 | not the order they are written. */ | |
418 | struct arg_data *args; | |
419 | ||
420 | /* Total size in bytes of all the stack-parms scanned so far. */ | |
421 | struct args_size args_size; | |
422 | /* Size of arguments before any adjustments (such as rounding). */ | |
423 | struct args_size original_args_size; | |
424 | /* Data on reg parms scanned so far. */ | |
425 | CUMULATIVE_ARGS args_so_far; | |
426 | /* Nonzero if a reg parm has been scanned. */ | |
427 | int reg_parm_seen; | |
428 | ||
429 | /* Nonzero if we must avoid push-insns in the args for this call. | |
430 | If stack space is allocated for register parameters, but not by the | |
431 | caller, then it is preallocated in the fixed part of the stack frame. | |
432 | So the entire argument block must then be preallocated (i.e., we | |
433 | ignore PUSH_ROUNDING in that case). */ | |
434 | ||
435 | #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE) | |
436 | int must_preallocate = 1; | |
437 | #else | |
438 | #ifdef PUSH_ROUNDING | |
439 | int must_preallocate = 0; | |
440 | #else | |
441 | int must_preallocate = 1; | |
442 | #endif | |
443 | #endif | |
444 | ||
6f90e075 JW |
445 | /* Size of the stack reserved for paramter registers. */ |
446 | int reg_parm_stack_space = 0; | |
447 | ||
51bbfa0c RS |
448 | /* 1 if scanning parms front to back, -1 if scanning back to front. */ |
449 | int inc; | |
450 | /* Address of space preallocated for stack parms | |
451 | (on machines that lack push insns), or 0 if space not preallocated. */ | |
452 | rtx argblock = 0; | |
453 | ||
454 | /* Nonzero if it is plausible that this is a call to alloca. */ | |
455 | int may_be_alloca; | |
456 | /* Nonzero if this is a call to setjmp or a related function. */ | |
457 | int returns_twice; | |
458 | /* Nonzero if this is a call to `longjmp'. */ | |
459 | int is_longjmp; | |
460 | /* Nonzero if this is a call to an inline function. */ | |
461 | int is_integrable = 0; | |
51bbfa0c RS |
462 | /* Nonzero if this is a call to a `const' function. |
463 | Note that only explicitly named functions are handled as `const' here. */ | |
464 | int is_const = 0; | |
465 | /* Nonzero if this is a call to a `volatile' function. */ | |
466 | int is_volatile = 0; | |
467 | #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE) | |
468 | /* Define the boundary of the register parm stack space that needs to be | |
469 | save, if any. */ | |
470 | int low_to_save = -1, high_to_save; | |
471 | rtx save_area = 0; /* Place that it is saved */ | |
472 | #endif | |
473 | ||
474 | #ifdef ACCUMULATE_OUTGOING_ARGS | |
475 | int initial_highest_arg_in_use = highest_outgoing_arg_in_use; | |
476 | char *initial_stack_usage_map = stack_usage_map; | |
477 | #endif | |
478 | ||
479 | rtx old_stack_level = 0; | |
480 | int old_pending_adj; | |
2f4aa534 | 481 | int old_stack_arg_under_construction; |
51bbfa0c RS |
482 | int old_inhibit_defer_pop = inhibit_defer_pop; |
483 | tree old_cleanups = cleanups_this_call; | |
484 | ||
485 | rtx use_insns = 0; | |
486 | ||
487 | register tree p; | |
488 | register int i; | |
489 | ||
490 | /* See if we can find a DECL-node for the actual function. | |
491 | As a result, decide whether this is a call to an integrable function. */ | |
492 | ||
493 | p = TREE_OPERAND (exp, 0); | |
494 | if (TREE_CODE (p) == ADDR_EXPR) | |
495 | { | |
496 | fndecl = TREE_OPERAND (p, 0); | |
497 | if (TREE_CODE (fndecl) != FUNCTION_DECL) | |
498 | { | |
499 | /* May still be a `const' function if it is | |
500 | a call through a pointer-to-const. | |
501 | But we don't handle that. */ | |
502 | fndecl = 0; | |
503 | } | |
504 | else | |
505 | { | |
506 | if (!flag_no_inline | |
507 | && fndecl != current_function_decl | |
508 | && DECL_SAVED_INSNS (fndecl)) | |
509 | is_integrable = 1; | |
510 | else if (! TREE_ADDRESSABLE (fndecl)) | |
511 | { | |
512 | /* In case this function later becomes inlineable, | |
513 | record that there was already a non-inline call to it. | |
514 | ||
515 | Use abstraction instead of setting TREE_ADDRESSABLE | |
516 | directly. */ | |
517 | if (TREE_INLINE (fndecl) && extra_warnings && !flag_no_inline) | |
518 | warning_with_decl (fndecl, "can't inline call to `%s' which was declared inline"); | |
519 | mark_addressable (fndecl); | |
520 | } | |
521 | ||
d45cf215 RS |
522 | if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl) |
523 | && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode) | |
51bbfa0c RS |
524 | is_const = 1; |
525 | } | |
526 | } | |
527 | ||
528 | is_volatile = TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (p))); | |
529 | ||
6f90e075 JW |
530 | #ifdef REG_PARM_STACK_SPACE |
531 | #ifdef MAYBE_REG_PARM_STACK_SPACE | |
532 | reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE; | |
533 | #else | |
534 | reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl); | |
535 | #endif | |
536 | #endif | |
537 | ||
51bbfa0c RS |
538 | /* Warn if this value is an aggregate type, |
539 | regardless of which calling convention we are using for it. */ | |
540 | if (warn_aggregate_return | |
541 | && (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE | |
542 | || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE | |
543 | || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)) | |
544 | warning ("function call has aggregate value"); | |
545 | ||
546 | /* Set up a place to return a structure. */ | |
547 | ||
548 | /* Cater to broken compilers. */ | |
549 | if (aggregate_value_p (exp)) | |
550 | { | |
551 | /* This call returns a big structure. */ | |
552 | is_const = 0; | |
553 | ||
554 | #ifdef PCC_STATIC_STRUCT_RETURN | |
555 | if (flag_pcc_struct_return) | |
556 | { | |
557 | pcc_struct_value = 1; | |
558 | is_integrable = 0; /* Easier than making that case work right. */ | |
559 | } | |
560 | else | |
561 | #endif | |
562 | { | |
563 | struct_value_size = int_size_in_bytes (TREE_TYPE (exp)); | |
564 | ||
565 | if (struct_value_size < 0) | |
566 | abort (); | |
567 | ||
568 | if (target && GET_CODE (target) == MEM) | |
569 | structure_value_addr = XEXP (target, 0); | |
570 | else | |
571 | { | |
572 | /* Assign a temporary on the stack to hold the value. */ | |
573 | ||
574 | /* For variable-sized objects, we must be called with a target | |
575 | specified. If we were to allocate space on the stack here, | |
576 | we would have no way of knowing when to free it. */ | |
577 | ||
578 | structure_value_addr | |
579 | = XEXP (assign_stack_temp (BLKmode, struct_value_size, 1), 0); | |
580 | target = 0; | |
581 | } | |
582 | } | |
583 | } | |
584 | ||
585 | /* If called function is inline, try to integrate it. */ | |
586 | ||
587 | if (is_integrable) | |
588 | { | |
589 | rtx temp; | |
2f4aa534 | 590 | rtx before_call = get_last_insn (); |
51bbfa0c RS |
591 | |
592 | temp = expand_inline_function (fndecl, actparms, target, | |
593 | ignore, TREE_TYPE (exp), | |
594 | structure_value_addr); | |
595 | ||
596 | /* If inlining succeeded, return. */ | |
597 | if ((int) temp != -1) | |
598 | { | |
2f4aa534 RS |
599 | int i; |
600 | ||
d64f5a78 RS |
601 | /* Perform all cleanups needed for the arguments of this call |
602 | (i.e. destructors in C++). It is ok if these destructors | |
603 | clobber RETURN_VALUE_REG, because the only time we care about | |
604 | this is when TARGET is that register. But in C++, we take | |
605 | care to never return that register directly. */ | |
606 | expand_cleanups_to (old_cleanups); | |
607 | ||
608 | #ifdef ACCUMULATE_OUTGOING_ARGS | |
2f4aa534 RS |
609 | /* If the outgoing argument list must be preserved, push |
610 | the stack before executing the inlined function if it | |
611 | makes any calls. */ | |
612 | ||
613 | for (i = reg_parm_stack_space - 1; i >= 0; i--) | |
614 | if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0) | |
615 | break; | |
616 | ||
617 | if (stack_arg_under_construction || i >= 0) | |
618 | { | |
d64f5a78 | 619 | rtx insn = NEXT_INSN (before_call), seq; |
2f4aa534 | 620 | |
d64f5a78 RS |
621 | /* Look for a call in the inline function code. |
622 | If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is | |
623 | nonzero then there is a call and it is not necessary | |
624 | to scan the insns. */ | |
625 | ||
626 | if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0) | |
627 | for (; insn; insn = NEXT_INSN (insn)) | |
628 | if (GET_CODE (insn) == CALL_INSN) | |
629 | break; | |
2f4aa534 RS |
630 | |
631 | if (insn) | |
632 | { | |
d64f5a78 RS |
633 | /* Reserve enough stack space so that the largest |
634 | argument list of any function call in the inline | |
635 | function does not overlap the argument list being | |
636 | evaluated. This is usually an overestimate because | |
637 | allocate_dynamic_stack_space reserves space for an | |
638 | outgoing argument list in addition to the requested | |
639 | space, but there is no way to ask for stack space such | |
640 | that an argument list of a certain length can be | |
641 | safely constructed. */ | |
642 | ||
643 | int adjust = OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)); | |
644 | #ifdef REG_PARM_STACK_SPACE | |
645 | /* Add the stack space reserved for register arguments | |
646 | in the inline function. What is really needed is the | |
647 | largest value of reg_parm_stack_space in the inline | |
648 | function, but that is not available. Using the current | |
649 | value of reg_parm_stack_space is wrong, but gives | |
650 | correct results on all supported machines. */ | |
651 | adjust += reg_parm_stack_space; | |
652 | #endif | |
2f4aa534 RS |
653 | start_sequence (); |
654 | emit_stack_save (SAVE_BLOCK, &old_stack_level, 0); | |
655 | allocate_dynamic_stack_space (gen_rtx (CONST_INT, VOIDmode, | |
d64f5a78 | 656 | adjust), |
2f4aa534 RS |
657 | 0, BITS_PER_UNIT); |
658 | seq = get_insns (); | |
659 | end_sequence (); | |
660 | emit_insns_before (seq, NEXT_INSN (before_call)); | |
661 | emit_stack_restore (SAVE_BLOCK, old_stack_level, 0); | |
662 | } | |
663 | } | |
d64f5a78 | 664 | #endif |
51bbfa0c RS |
665 | |
666 | /* If the result is equivalent to TARGET, return TARGET to simplify | |
667 | checks in store_expr. They can be equivalent but not equal in the | |
668 | case of a function that returns BLKmode. */ | |
669 | if (temp != target && rtx_equal_p (temp, target)) | |
670 | return target; | |
671 | return temp; | |
672 | } | |
673 | ||
674 | /* If inlining failed, mark FNDECL as needing to be compiled | |
675 | separately after all. */ | |
676 | mark_addressable (fndecl); | |
677 | } | |
678 | ||
679 | /* When calling a const function, we must pop the stack args right away, | |
680 | so that the pop is deleted or moved with the call. */ | |
681 | if (is_const) | |
682 | NO_DEFER_POP; | |
683 | ||
684 | function_call_count++; | |
685 | ||
686 | if (fndecl && DECL_NAME (fndecl)) | |
687 | name = IDENTIFIER_POINTER (DECL_NAME (fndecl)); | |
688 | ||
689 | #if 0 | |
690 | /* Unless it's a call to a specific function that isn't alloca, | |
691 | if it has one argument, we must assume it might be alloca. */ | |
692 | ||
693 | may_be_alloca = | |
694 | (!(fndecl != 0 && strcmp (name, "alloca")) | |
695 | && actparms != 0 | |
696 | && TREE_CHAIN (actparms) == 0); | |
697 | #else | |
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. */ | |
701 | may_be_alloca = | |
702 | (name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6 | |
703 | && name[0] == 'a' | |
704 | && ! strcmp (name, "alloca")) | |
705 | || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16 | |
706 | && name[0] == '_' | |
707 | && ! strcmp (name, "__builtin_alloca")))); | |
708 | #endif | |
709 | ||
710 | /* See if this is a call to a function that can return more than once | |
711 | or a call to longjmp. */ | |
712 | ||
713 | returns_twice = 0; | |
714 | is_longjmp = 0; | |
715 | ||
716 | if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 15) | |
717 | { | |
718 | char *tname = name; | |
719 | ||
720 | if (name[0] == '_') | |
721 | tname += ((name[1] == '_' && name[2] == 'x') ? 3 : 1); | |
722 | ||
723 | if (tname[0] == 's') | |
724 | { | |
725 | returns_twice | |
726 | = ((tname[1] == 'e' | |
727 | && (! strcmp (tname, "setjmp") | |
728 | || ! strcmp (tname, "setjmp_syscall"))) | |
729 | || (tname[1] == 'i' | |
730 | && ! strcmp (tname, "sigsetjmp")) | |
731 | || (tname[1] == 'a' | |
732 | && ! strcmp (tname, "savectx"))); | |
733 | if (tname[1] == 'i' | |
734 | && ! strcmp (tname, "siglongjmp")) | |
735 | is_longjmp = 1; | |
736 | } | |
737 | else if ((tname[0] == 'q' && tname[1] == 's' | |
738 | && ! strcmp (tname, "qsetjmp")) | |
739 | || (tname[0] == 'v' && tname[1] == 'f' | |
740 | && ! strcmp (tname, "vfork"))) | |
741 | returns_twice = 1; | |
742 | ||
743 | else if (tname[0] == 'l' && tname[1] == 'o' | |
744 | && ! strcmp (tname, "longjmp")) | |
745 | is_longjmp = 1; | |
746 | } | |
747 | ||
51bbfa0c RS |
748 | if (may_be_alloca) |
749 | current_function_calls_alloca = 1; | |
750 | ||
751 | /* Don't let pending stack adjusts add up to too much. | |
752 | Also, do all pending adjustments now | |
753 | if there is any chance this might be a call to alloca. */ | |
754 | ||
755 | if (pending_stack_adjust >= 32 | |
756 | || (pending_stack_adjust > 0 && may_be_alloca)) | |
757 | do_pending_stack_adjust (); | |
758 | ||
759 | /* Operand 0 is a pointer-to-function; get the type of the function. */ | |
760 | funtype = TREE_TYPE (TREE_OPERAND (exp, 0)); | |
761 | if (TREE_CODE (funtype) != POINTER_TYPE) | |
762 | abort (); | |
763 | funtype = TREE_TYPE (funtype); | |
764 | ||
765 | /* Push the temporary stack slot level so that we can free temporaries used | |
766 | by each of the arguments separately. */ | |
767 | push_temp_slots (); | |
768 | ||
769 | /* Start updating where the next arg would go. */ | |
770 | INIT_CUMULATIVE_ARGS (args_so_far, funtype, 0); | |
771 | ||
772 | /* If struct_value_rtx is 0, it means pass the address | |
773 | as if it were an extra parameter. */ | |
774 | if (structure_value_addr && struct_value_rtx == 0) | |
775 | { | |
d64f5a78 | 776 | #ifdef ACCUMULATE_OUTGOING_ARGS |
2f4aa534 RS |
777 | /* If the stack will be adjusted, make sure the structure address |
778 | does not refer to virtual_outgoing_args_rtx. */ | |
779 | rtx temp = (stack_arg_under_construction | |
780 | ? copy_addr_to_reg (structure_value_addr) | |
781 | : force_reg (Pmode, structure_value_addr)); | |
d64f5a78 RS |
782 | #else |
783 | rtx temp = force_reg (Pmode, structure_value_addr); | |
784 | #endif | |
785 | ||
51bbfa0c RS |
786 | actparms |
787 | = tree_cons (error_mark_node, | |
788 | make_tree (build_pointer_type (TREE_TYPE (funtype)), | |
2f4aa534 | 789 | temp), |
51bbfa0c RS |
790 | actparms); |
791 | structure_value_addr_parm = 1; | |
792 | } | |
793 | ||
794 | /* Count the arguments and set NUM_ACTUALS. */ | |
795 | for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++; | |
796 | num_actuals = i; | |
797 | ||
798 | /* Compute number of named args. | |
799 | Normally, don't include the last named arg if anonymous args follow. | |
800 | (If no anonymous args follow, the result of list_length | |
801 | is actually one too large.) | |
802 | ||
803 | If SETUP_INCOMING_VARARGS is defined, this machine will be able to | |
804 | place unnamed args that were passed in registers into the stack. So | |
805 | treat all args as named. This allows the insns emitting for a specific | |
d45cf215 | 806 | argument list to be independent of the function declaration. |
51bbfa0c RS |
807 | |
808 | If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable | |
809 | way to pass unnamed args in registers, so we must force them into | |
810 | memory. */ | |
811 | #ifndef SETUP_INCOMING_VARARGS | |
812 | if (TYPE_ARG_TYPES (funtype) != 0) | |
813 | n_named_args | |
814 | = list_length (TYPE_ARG_TYPES (funtype)) - 1 | |
815 | /* Count the struct value address, if it is passed as a parm. */ | |
816 | + structure_value_addr_parm; | |
817 | else | |
818 | #endif | |
819 | /* If we know nothing, treat all args as named. */ | |
820 | n_named_args = num_actuals; | |
821 | ||
822 | /* Make a vector to hold all the information about each arg. */ | |
823 | args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data)); | |
824 | bzero (args, num_actuals * sizeof (struct arg_data)); | |
825 | ||
826 | args_size.constant = 0; | |
827 | args_size.var = 0; | |
828 | ||
829 | /* In this loop, we consider args in the order they are written. | |
830 | We fill up ARGS from the front of from the back if necessary | |
831 | so that in any case the first arg to be pushed ends up at the front. */ | |
832 | ||
833 | #ifdef PUSH_ARGS_REVERSED | |
834 | i = num_actuals - 1, inc = -1; | |
835 | /* In this case, must reverse order of args | |
836 | so that we compute and push the last arg first. */ | |
837 | #else | |
838 | i = 0, inc = 1; | |
839 | #endif | |
840 | ||
841 | /* I counts args in order (to be) pushed; ARGPOS counts in order written. */ | |
842 | for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++) | |
843 | { | |
844 | tree type = TREE_TYPE (TREE_VALUE (p)); | |
845 | ||
846 | args[i].tree_value = TREE_VALUE (p); | |
847 | ||
848 | /* Replace erroneous argument with constant zero. */ | |
849 | if (type == error_mark_node || TYPE_SIZE (type) == 0) | |
850 | args[i].tree_value = integer_zero_node, type = integer_type_node; | |
851 | ||
852 | /* Decide where to pass this arg. | |
853 | ||
854 | args[i].reg is nonzero if all or part is passed in registers. | |
855 | ||
856 | args[i].partial is nonzero if part but not all is passed in registers, | |
857 | and the exact value says how many words are passed in registers. | |
858 | ||
859 | args[i].pass_on_stack is nonzero if the argument must at least be | |
860 | computed on the stack. It may then be loaded back into registers | |
861 | if args[i].reg is nonzero. | |
862 | ||
863 | These decisions are driven by the FUNCTION_... macros and must agree | |
864 | with those made by function.c. */ | |
865 | ||
866 | #ifdef FUNCTION_ARG_PASS_BY_REFERENCE | |
867 | /* See if this argument should be passed by invisible reference. */ | |
868 | if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, TYPE_MODE (type), type, | |
869 | argpos < n_named_args)) | |
870 | { | |
871 | /* We make a copy of the object and pass the address to the function | |
872 | being called. */ | |
873 | int size = int_size_in_bytes (type); | |
874 | rtx copy; | |
875 | ||
876 | if (size < 0) | |
877 | { | |
878 | /* This is a variable-sized object. Make space on the stack | |
879 | for it. */ | |
880 | rtx size_rtx = expand_expr (size_in_bytes (type), 0, | |
881 | VOIDmode, 0); | |
882 | ||
883 | if (old_stack_level == 0) | |
884 | { | |
59257ff7 | 885 | emit_stack_save (SAVE_BLOCK, &old_stack_level, 0); |
51bbfa0c RS |
886 | old_pending_adj = pending_stack_adjust; |
887 | pending_stack_adjust = 0; | |
888 | } | |
889 | ||
890 | copy = gen_rtx (MEM, BLKmode, | |
5130a5cc RS |
891 | allocate_dynamic_stack_space (size_rtx, 0, |
892 | TYPE_ALIGN (type))); | |
51bbfa0c RS |
893 | } |
894 | else | |
895 | copy = assign_stack_temp (TYPE_MODE (type), size, 1); | |
896 | ||
897 | store_expr (args[i].tree_value, copy, 0); | |
898 | ||
899 | args[i].tree_value = build1 (ADDR_EXPR, build_pointer_type (type), | |
900 | make_tree (type, copy)); | |
901 | type = build_pointer_type (type); | |
902 | } | |
903 | #endif | |
904 | ||
905 | args[i].reg = FUNCTION_ARG (args_so_far, TYPE_MODE (type), type, | |
906 | argpos < n_named_args); | |
907 | #ifdef FUNCTION_ARG_PARTIAL_NREGS | |
908 | if (args[i].reg) | |
909 | args[i].partial | |
910 | = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, TYPE_MODE (type), type, | |
911 | argpos < n_named_args); | |
912 | #endif | |
913 | ||
914 | args[i].pass_on_stack = MUST_PASS_IN_STACK (TYPE_MODE (type), type); | |
915 | ||
916 | /* If FUNCTION_ARG returned an (expr_list (nil) FOO), it means that | |
917 | we are to pass this arg in the register(s) designated by FOO, but | |
918 | also to pass it in the stack. */ | |
919 | if (args[i].reg && GET_CODE (args[i].reg) == EXPR_LIST | |
920 | && XEXP (args[i].reg, 0) == 0) | |
921 | args[i].pass_on_stack = 1, args[i].reg = XEXP (args[i].reg, 1); | |
922 | ||
923 | /* If this is an addressable type, we must preallocate the stack | |
924 | since we must evaluate the object into its final location. | |
925 | ||
926 | If this is to be passed in both registers and the stack, it is simpler | |
927 | to preallocate. */ | |
928 | if (TREE_ADDRESSABLE (type) | |
929 | || (args[i].pass_on_stack && args[i].reg != 0)) | |
930 | must_preallocate = 1; | |
931 | ||
932 | /* If this is an addressable type, we cannot pre-evaluate it. Thus, | |
933 | we cannot consider this function call constant. */ | |
934 | if (TREE_ADDRESSABLE (type)) | |
935 | is_const = 0; | |
936 | ||
937 | /* Compute the stack-size of this argument. */ | |
938 | if (args[i].reg == 0 || args[i].partial != 0 | |
939 | #ifdef REG_PARM_STACK_SPACE | |
6f90e075 | 940 | || reg_parm_stack_space > 0 |
51bbfa0c RS |
941 | #endif |
942 | || args[i].pass_on_stack) | |
943 | locate_and_pad_parm (TYPE_MODE (type), type, | |
944 | #ifdef STACK_PARMS_IN_REG_PARM_AREA | |
945 | 1, | |
946 | #else | |
947 | args[i].reg != 0, | |
948 | #endif | |
949 | fndecl, &args_size, &args[i].offset, | |
950 | &args[i].size); | |
951 | ||
952 | #ifndef ARGS_GROW_DOWNWARD | |
953 | args[i].slot_offset = args_size; | |
954 | #endif | |
955 | ||
956 | #ifndef REG_PARM_STACK_SPACE | |
957 | /* If a part of the arg was put into registers, | |
958 | don't include that part in the amount pushed. */ | |
959 | if (! args[i].pass_on_stack) | |
960 | args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD) | |
961 | / (PARM_BOUNDARY / BITS_PER_UNIT) | |
962 | * (PARM_BOUNDARY / BITS_PER_UNIT)); | |
963 | #endif | |
964 | ||
965 | /* Update ARGS_SIZE, the total stack space for args so far. */ | |
966 | ||
967 | args_size.constant += args[i].size.constant; | |
968 | if (args[i].size.var) | |
969 | { | |
970 | ADD_PARM_SIZE (args_size, args[i].size.var); | |
971 | } | |
972 | ||
973 | /* Since the slot offset points to the bottom of the slot, | |
974 | we must record it after incrementing if the args grow down. */ | |
975 | #ifdef ARGS_GROW_DOWNWARD | |
976 | args[i].slot_offset = args_size; | |
977 | ||
978 | args[i].slot_offset.constant = -args_size.constant; | |
979 | if (args_size.var) | |
980 | { | |
981 | SUB_PARM_SIZE (args[i].slot_offset, args_size.var); | |
982 | } | |
983 | #endif | |
984 | ||
985 | /* Increment ARGS_SO_FAR, which has info about which arg-registers | |
986 | have been used, etc. */ | |
987 | ||
988 | FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type, | |
989 | argpos < n_named_args); | |
990 | } | |
991 | ||
6f90e075 JW |
992 | #ifdef FINAL_REG_PARM_STACK_SPACE |
993 | reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant, | |
994 | args_size.var); | |
995 | #endif | |
996 | ||
51bbfa0c RS |
997 | /* Compute the actual size of the argument block required. The variable |
998 | and constant sizes must be combined, the size may have to be rounded, | |
999 | and there may be a minimum required size. */ | |
1000 | ||
1001 | original_args_size = args_size; | |
1002 | if (args_size.var) | |
1003 | { | |
1004 | /* If this function requires a variable-sized argument list, don't try to | |
1005 | make a cse'able block for this call. We may be able to do this | |
1006 | eventually, but it is too complicated to keep track of what insns go | |
1007 | in the cse'able block and which don't. */ | |
1008 | ||
1009 | is_const = 0; | |
1010 | must_preallocate = 1; | |
1011 | ||
1012 | args_size.var = ARGS_SIZE_TREE (args_size); | |
1013 | args_size.constant = 0; | |
1014 | ||
1015 | #ifdef STACK_BOUNDARY | |
1016 | if (STACK_BOUNDARY != BITS_PER_UNIT) | |
1017 | args_size.var = round_up (args_size.var, STACK_BYTES); | |
1018 | #endif | |
1019 | ||
1020 | #ifdef REG_PARM_STACK_SPACE | |
6f90e075 | 1021 | if (reg_parm_stack_space > 0) |
51bbfa0c RS |
1022 | { |
1023 | args_size.var | |
1024 | = size_binop (MAX_EXPR, args_size.var, | |
1025 | size_int (REG_PARM_STACK_SPACE (fndecl))); | |
1026 | ||
1027 | #ifndef OUTGOING_REG_PARM_STACK_SPACE | |
1028 | /* The area corresponding to register parameters is not to count in | |
1029 | the size of the block we need. So make the adjustment. */ | |
1030 | args_size.var | |
1031 | = size_binop (MINUS_EXPR, args_size.var, | |
6f90e075 | 1032 | size_int (reg_parm_stack_space)); |
51bbfa0c RS |
1033 | #endif |
1034 | } | |
1035 | #endif | |
1036 | } | |
1037 | else | |
1038 | { | |
1039 | #ifdef STACK_BOUNDARY | |
1040 | args_size.constant = (((args_size.constant + (STACK_BYTES - 1)) | |
1041 | / STACK_BYTES) * STACK_BYTES); | |
1042 | #endif | |
1043 | ||
1044 | #ifdef REG_PARM_STACK_SPACE | |
1045 | args_size.constant = MAX (args_size.constant, | |
6f90e075 | 1046 | reg_parm_stack_space); |
51bbfa0c | 1047 | #ifndef OUTGOING_REG_PARM_STACK_SPACE |
6f90e075 | 1048 | args_size.constant -= reg_parm_stack_space; |
51bbfa0c RS |
1049 | #endif |
1050 | #endif | |
1051 | } | |
1052 | ||
1053 | /* See if we have or want to preallocate stack space. | |
1054 | ||
1055 | If we would have to push a partially-in-regs parm | |
1056 | before other stack parms, preallocate stack space instead. | |
1057 | ||
1058 | If the size of some parm is not a multiple of the required stack | |
1059 | alignment, we must preallocate. | |
1060 | ||
1061 | If the total size of arguments that would otherwise create a copy in | |
1062 | a temporary (such as a CALL) is more than half the total argument list | |
1063 | size, preallocation is faster. | |
1064 | ||
1065 | Another reason to preallocate is if we have a machine (like the m88k) | |
1066 | where stack alignment is required to be maintained between every | |
1067 | pair of insns, not just when the call is made. However, we assume here | |
1068 | that such machines either do not have push insns (and hence preallocation | |
1069 | would occur anyway) or the problem is taken care of with | |
1070 | PUSH_ROUNDING. */ | |
1071 | ||
1072 | if (! must_preallocate) | |
1073 | { | |
1074 | int partial_seen = 0; | |
1075 | int copy_to_evaluate_size = 0; | |
1076 | ||
1077 | for (i = 0; i < num_actuals && ! must_preallocate; i++) | |
1078 | { | |
1079 | if (args[i].partial > 0 && ! args[i].pass_on_stack) | |
1080 | partial_seen = 1; | |
1081 | else if (partial_seen && args[i].reg == 0) | |
1082 | must_preallocate = 1; | |
1083 | ||
1084 | if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode | |
1085 | && (TREE_CODE (args[i].tree_value) == CALL_EXPR | |
1086 | || TREE_CODE (args[i].tree_value) == TARGET_EXPR | |
1087 | || TREE_CODE (args[i].tree_value) == COND_EXPR | |
1088 | || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))) | |
1089 | copy_to_evaluate_size | |
1090 | += int_size_in_bytes (TREE_TYPE (args[i].tree_value)); | |
1091 | } | |
1092 | ||
c62f36cf RS |
1093 | if (copy_to_evaluate_size * 2 >= args_size.constant |
1094 | && args_size.constant > 0) | |
51bbfa0c RS |
1095 | must_preallocate = 1; |
1096 | } | |
1097 | ||
1098 | /* If the structure value address will reference the stack pointer, we must | |
1099 | stabilize it. We don't need to do this if we know that we are not going | |
1100 | to adjust the stack pointer in processing this call. */ | |
1101 | ||
1102 | if (structure_value_addr | |
1103 | && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr) | |
1104 | || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr)) | |
1105 | && (args_size.var | |
1106 | #ifndef ACCUMULATE_OUTGOING_ARGS | |
1107 | || args_size.constant | |
1108 | #endif | |
1109 | )) | |
1110 | structure_value_addr = copy_to_reg (structure_value_addr); | |
1111 | ||
1112 | /* If this function call is cse'able, precompute all the parameters. | |
1113 | Note that if the parameter is constructed into a temporary, this will | |
1114 | cause an additional copy because the parameter will be constructed | |
1115 | into a temporary location and then copied into the outgoing arguments. | |
1116 | If a parameter contains a call to alloca and this function uses the | |
1117 | stack, precompute the parameter. */ | |
1118 | ||
1119 | for (i = 0; i < num_actuals; i++) | |
1120 | if (is_const | |
1121 | || ((args_size.var != 0 || args_size.constant != 0) | |
1122 | && calls_alloca (args[i].tree_value))) | |
1123 | { | |
1124 | args[i].initial_value = args[i].value | |
1125 | = expand_expr (args[i].tree_value, 0, VOIDmode, 0); | |
1126 | preserve_temp_slots (args[i].value); | |
1127 | free_temp_slots (); | |
1128 | ||
1129 | /* ANSI doesn't require a sequence point here, | |
1130 | but PCC has one, so this will avoid some problems. */ | |
1131 | emit_queue (); | |
1132 | } | |
1133 | ||
1134 | /* Now we are about to start emitting insns that can be deleted | |
1135 | if a libcall is deleted. */ | |
1136 | if (is_const) | |
1137 | start_sequence (); | |
1138 | ||
1139 | /* If we have no actual push instructions, or shouldn't use them, | |
1140 | make space for all args right now. */ | |
1141 | ||
1142 | if (args_size.var != 0) | |
1143 | { | |
1144 | if (old_stack_level == 0) | |
1145 | { | |
59257ff7 | 1146 | emit_stack_save (SAVE_BLOCK, &old_stack_level, 0); |
51bbfa0c RS |
1147 | old_pending_adj = pending_stack_adjust; |
1148 | pending_stack_adjust = 0; | |
d64f5a78 | 1149 | #ifdef ACCUMULATE_OUTGOING_ARGS |
2f4aa534 RS |
1150 | /* stack_arg_under_construction says whether a stack arg is |
1151 | being constructed at the old stack level. Pushing the stack | |
1152 | gets a clean outgoing argument block. */ | |
1153 | old_stack_arg_under_construction = stack_arg_under_construction; | |
1154 | stack_arg_under_construction = 0; | |
d64f5a78 | 1155 | #endif |
51bbfa0c RS |
1156 | } |
1157 | argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0); | |
1158 | } | |
1159 | else if (must_preallocate) | |
1160 | { | |
1161 | /* Note that we must go through the motions of allocating an argument | |
1162 | block even if the size is zero because we may be storing args | |
1163 | in the area reserved for register arguments, which may be part of | |
1164 | the stack frame. */ | |
1165 | int needed = args_size.constant; | |
1166 | ||
1167 | #ifdef ACCUMULATE_OUTGOING_ARGS | |
1168 | /* Store the maximum argument space used. It will be pushed by the | |
1169 | prologue. | |
1170 | ||
1171 | Since the stack pointer will never be pushed, it is possible for | |
1172 | the evaluation of a parm to clobber something we have already | |
1173 | written to the stack. Since most function calls on RISC machines | |
1174 | do not use the stack, this is uncommon, but must work correctly. | |
1175 | ||
1176 | Therefore, we save any area of the stack that was already written | |
1177 | and that we are using. Here we set up to do this by making a new | |
1178 | stack usage map from the old one. The actual save will be done | |
1179 | by store_one_arg. | |
1180 | ||
1181 | Another approach might be to try to reorder the argument | |
1182 | evaluations to avoid this conflicting stack usage. */ | |
1183 | ||
1184 | if (needed > current_function_outgoing_args_size) | |
1185 | current_function_outgoing_args_size = needed; | |
1186 | ||
1187 | #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE) | |
1188 | /* Since we will be writing into the entire argument area, the | |
1189 | map must be allocated for its entire size, not just the part that | |
1190 | is the responsibility of the caller. */ | |
6f90e075 | 1191 | needed += reg_parm_stack_space; |
51bbfa0c RS |
1192 | #endif |
1193 | ||
1194 | #ifdef ARGS_GROW_DOWNWARD | |
1195 | highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, | |
1196 | needed + 1); | |
1197 | #else | |
1198 | highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, needed); | |
1199 | #endif | |
1200 | stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use); | |
1201 | ||
1202 | if (initial_highest_arg_in_use) | |
1203 | bcopy (initial_stack_usage_map, stack_usage_map, | |
1204 | initial_highest_arg_in_use); | |
1205 | ||
1206 | if (initial_highest_arg_in_use != highest_outgoing_arg_in_use) | |
1207 | bzero (&stack_usage_map[initial_highest_arg_in_use], | |
1208 | highest_outgoing_arg_in_use - initial_highest_arg_in_use); | |
1209 | needed = 0; | |
2f4aa534 RS |
1210 | |
1211 | /* The only way the stack pointer can change here is if some arguments | |
1212 | which are passed in memory are constructed in place in the outgoing | |
1213 | argument area. All objects which are constructed in place have | |
1214 | pass_on_stack == 1 (see store_one_arg ()). | |
1215 | ||
1216 | The test for arguments being constructed on the stack is just an | |
1217 | optimization: it would be correct but suboptimal to call | |
1218 | copy_addr_to_reg () unconditionally. */ | |
1219 | ||
51bbfa0c | 1220 | argblock = virtual_outgoing_args_rtx; |
2f4aa534 RS |
1221 | for (i = 0; i < num_actuals; i++) |
1222 | if (args[i].pass_on_stack) | |
1223 | { | |
1224 | argblock = copy_addr_to_reg (argblock); | |
1225 | break; | |
1226 | } | |
1227 | ||
51bbfa0c RS |
1228 | #else /* not ACCUMULATE_OUTGOING_ARGS */ |
1229 | if (inhibit_defer_pop == 0) | |
1230 | { | |
1231 | /* Try to reuse some or all of the pending_stack_adjust | |
1232 | to get this space. Maybe we can avoid any pushing. */ | |
1233 | if (needed > pending_stack_adjust) | |
1234 | { | |
1235 | needed -= pending_stack_adjust; | |
1236 | pending_stack_adjust = 0; | |
1237 | } | |
1238 | else | |
1239 | { | |
1240 | pending_stack_adjust -= needed; | |
1241 | needed = 0; | |
1242 | } | |
1243 | } | |
1244 | /* Special case this because overhead of `push_block' in this | |
1245 | case is non-trivial. */ | |
1246 | if (needed == 0) | |
1247 | argblock = virtual_outgoing_args_rtx; | |
1248 | else | |
1249 | argblock = push_block (gen_rtx (CONST_INT, VOIDmode, needed), 0, 0); | |
1250 | ||
1251 | /* We only really need to call `copy_to_reg' in the case where push | |
1252 | insns are going to be used to pass ARGBLOCK to a function | |
1253 | call in ARGS. In that case, the stack pointer changes value | |
1254 | from the allocation point to the call point, and hence | |
1255 | the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well. | |
1256 | But might as well always do it. */ | |
1257 | argblock = copy_to_reg (argblock); | |
1258 | #endif /* not ACCUMULATE_OUTGOING_ARGS */ | |
1259 | } | |
1260 | ||
1261 | /* If we preallocated stack space, compute the address of each argument. | |
1262 | We need not ensure it is a valid memory address here; it will be | |
1263 | validized when it is used. */ | |
1264 | if (argblock) | |
1265 | { | |
1266 | rtx arg_reg = argblock; | |
1267 | int arg_offset = 0; | |
1268 | ||
1269 | if (GET_CODE (argblock) == PLUS) | |
1270 | arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1)); | |
1271 | ||
1272 | for (i = 0; i < num_actuals; i++) | |
1273 | { | |
1274 | rtx offset = ARGS_SIZE_RTX (args[i].offset); | |
1275 | rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset); | |
1276 | rtx addr; | |
1277 | ||
1278 | /* Skip this parm if it will not be passed on the stack. */ | |
1279 | if (! args[i].pass_on_stack && args[i].reg != 0) | |
1280 | continue; | |
1281 | ||
1282 | if (GET_CODE (offset) == CONST_INT) | |
1283 | addr = plus_constant (arg_reg, INTVAL (offset)); | |
1284 | else | |
1285 | addr = gen_rtx (PLUS, Pmode, arg_reg, offset); | |
1286 | ||
1287 | addr = plus_constant (addr, arg_offset); | |
1288 | args[i].stack | |
1289 | = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (args[i].tree_value)), addr); | |
1290 | ||
1291 | if (GET_CODE (slot_offset) == CONST_INT) | |
1292 | addr = plus_constant (arg_reg, INTVAL (slot_offset)); | |
1293 | else | |
1294 | addr = gen_rtx (PLUS, Pmode, arg_reg, slot_offset); | |
1295 | ||
1296 | addr = plus_constant (addr, arg_offset); | |
1297 | args[i].stack_slot | |
1298 | = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (args[i].tree_value)), addr); | |
1299 | } | |
1300 | } | |
1301 | ||
1302 | #ifdef PUSH_ARGS_REVERSED | |
1303 | #ifdef STACK_BOUNDARY | |
1304 | /* If we push args individually in reverse order, perform stack alignment | |
1305 | before the first push (the last arg). */ | |
1306 | if (argblock == 0) | |
1307 | anti_adjust_stack (gen_rtx (CONST_INT, VOIDmode, | |
1308 | (args_size.constant | |
1309 | - original_args_size.constant))); | |
1310 | #endif | |
1311 | #endif | |
1312 | ||
d64f5a78 | 1313 | #ifdef ACCUMULATE_OUTGOING_ARGS |
2f4aa534 RS |
1314 | /* The save/restore code in store_one_arg handles all cases except one: |
1315 | a constructor call (including a C function returning a BLKmode struct) | |
1316 | to initialize an argument. */ | |
1317 | if (stack_arg_under_construction) | |
1318 | { | |
d64f5a78 | 1319 | #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE) |
2f4aa534 | 1320 | rtx push_size = gen_rtx (CONST_INT, VOIDmode, |
d64f5a78 RS |
1321 | reg_parm_stack_space + args_size.constant); |
1322 | #else | |
1323 | rtx push_size = gen_rtx (CONST_INT, VOIDmode, args_size.constant); | |
1324 | #endif | |
2f4aa534 RS |
1325 | if (old_stack_level == 0) |
1326 | { | |
1327 | emit_stack_save (SAVE_BLOCK, &old_stack_level, 0); | |
1328 | old_pending_adj = pending_stack_adjust; | |
1329 | pending_stack_adjust = 0; | |
1330 | /* stack_arg_under_construction says whether a stack arg is | |
1331 | being constructed at the old stack level. Pushing the stack | |
1332 | gets a clean outgoing argument block. */ | |
1333 | old_stack_arg_under_construction = stack_arg_under_construction; | |
1334 | stack_arg_under_construction = 0; | |
1335 | /* Make a new map for the new argument list. */ | |
1336 | stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use); | |
1337 | bzero (stack_usage_map, highest_outgoing_arg_in_use); | |
1338 | highest_outgoing_arg_in_use = 0; | |
1339 | } | |
1340 | allocate_dynamic_stack_space (push_size, 0, BITS_PER_UNIT); | |
1341 | } | |
d64f5a78 | 1342 | #endif |
2f4aa534 | 1343 | |
51bbfa0c RS |
1344 | /* Don't try to defer pops if preallocating, not even from the first arg, |
1345 | since ARGBLOCK probably refers to the SP. */ | |
1346 | if (argblock) | |
1347 | NO_DEFER_POP; | |
1348 | ||
1349 | /* Get the function to call, in the form of RTL. */ | |
1350 | if (fndecl) | |
1351 | /* Get a SYMBOL_REF rtx for the function address. */ | |
1352 | funexp = XEXP (DECL_RTL (fndecl), 0); | |
1353 | else | |
1354 | /* Generate an rtx (probably a pseudo-register) for the address. */ | |
1355 | { | |
1356 | funexp = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0); | |
1357 | free_temp_slots (); /* FUNEXP can't be BLKmode */ | |
1358 | emit_queue (); | |
1359 | } | |
1360 | ||
1361 | /* Figure out the register where the value, if any, will come back. */ | |
1362 | valreg = 0; | |
1363 | if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode | |
1364 | && ! structure_value_addr) | |
1365 | { | |
1366 | if (pcc_struct_value) | |
1367 | valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)), | |
1368 | fndecl); | |
1369 | else | |
1370 | valreg = hard_function_value (TREE_TYPE (exp), fndecl); | |
1371 | } | |
1372 | ||
1373 | /* Precompute all register parameters. It isn't safe to compute anything | |
1374 | once we have started filling any specific hard regs. */ | |
1375 | reg_parm_seen = 0; | |
1376 | for (i = 0; i < num_actuals; i++) | |
1377 | if (args[i].reg != 0 && ! args[i].pass_on_stack) | |
1378 | { | |
1379 | reg_parm_seen = 1; | |
1380 | ||
1381 | if (args[i].value == 0) | |
1382 | { | |
1383 | args[i].value = expand_expr (args[i].tree_value, 0, VOIDmode, 0); | |
1384 | preserve_temp_slots (args[i].value); | |
1385 | free_temp_slots (); | |
1386 | ||
1387 | /* ANSI doesn't require a sequence point here, | |
1388 | but PCC has one, so this will avoid some problems. */ | |
1389 | emit_queue (); | |
1390 | } | |
1391 | } | |
1392 | ||
1393 | #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE) | |
1394 | /* The argument list is the property of the called routine and it | |
1395 | may clobber it. If the fixed area has been used for previous | |
1396 | parameters, we must save and restore it. | |
1397 | ||
1398 | Here we compute the boundary of the that needs to be saved, if any. */ | |
1399 | ||
6f90e075 | 1400 | for (i = 0; i < reg_parm_stack_space; i++) |
51bbfa0c RS |
1401 | { |
1402 | if (i >= highest_outgoing_arg_in_use | |
1403 | || stack_usage_map[i] == 0) | |
1404 | continue; | |
1405 | ||
1406 | if (low_to_save == -1) | |
1407 | low_to_save = i; | |
1408 | ||
1409 | high_to_save = i; | |
1410 | } | |
1411 | ||
1412 | if (low_to_save >= 0) | |
1413 | { | |
1414 | int num_to_save = high_to_save - low_to_save + 1; | |
1415 | enum machine_mode save_mode | |
1416 | = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1); | |
1417 | rtx stack_area; | |
1418 | ||
1419 | /* If we don't have the required alignment, must do this in BLKmode. */ | |
1420 | if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode), | |
1421 | BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1))) | |
1422 | save_mode = BLKmode; | |
1423 | ||
1424 | stack_area = gen_rtx (MEM, save_mode, | |
1425 | memory_address (save_mode, | |
1426 | plus_constant (argblock, | |
1427 | low_to_save))); | |
1428 | if (save_mode == BLKmode) | |
1429 | { | |
1430 | save_area = assign_stack_temp (BLKmode, num_to_save, 1); | |
1431 | emit_block_move (validize_mem (save_area), stack_area, | |
1432 | gen_rtx (CONST_INT, VOIDmode, num_to_save), | |
1433 | PARM_BOUNDARY / BITS_PER_UNIT); | |
1434 | } | |
1435 | else | |
1436 | { | |
1437 | save_area = gen_reg_rtx (save_mode); | |
1438 | emit_move_insn (save_area, stack_area); | |
1439 | } | |
1440 | } | |
1441 | #endif | |
1442 | ||
1443 | ||
1444 | /* Now store (and compute if necessary) all non-register parms. | |
1445 | These come before register parms, since they can require block-moves, | |
1446 | which could clobber the registers used for register parms. | |
1447 | Parms which have partial registers are not stored here, | |
1448 | but we do preallocate space here if they want that. */ | |
1449 | ||
1450 | for (i = 0; i < num_actuals; i++) | |
1451 | if (args[i].reg == 0 || args[i].pass_on_stack) | |
1452 | store_one_arg (&args[i], argblock, may_be_alloca, | |
6f90e075 | 1453 | args_size.var != 0, fndecl, reg_parm_stack_space); |
51bbfa0c RS |
1454 | |
1455 | /* Now store any partially-in-registers parm. | |
1456 | This is the last place a block-move can happen. */ | |
1457 | if (reg_parm_seen) | |
1458 | for (i = 0; i < num_actuals; i++) | |
1459 | if (args[i].partial != 0 && ! args[i].pass_on_stack) | |
1460 | store_one_arg (&args[i], argblock, may_be_alloca, | |
6f90e075 | 1461 | args_size.var != 0, fndecl, reg_parm_stack_space); |
51bbfa0c RS |
1462 | |
1463 | #ifndef PUSH_ARGS_REVERSED | |
1464 | #ifdef STACK_BOUNDARY | |
1465 | /* If we pushed args in forward order, perform stack alignment | |
1466 | after pushing the last arg. */ | |
1467 | if (argblock == 0) | |
1468 | anti_adjust_stack (gen_rtx (CONST_INT, VOIDmode, | |
1469 | (args_size.constant | |
1470 | - original_args_size.constant))); | |
1471 | #endif | |
1472 | #endif | |
1473 | ||
756e0e12 RS |
1474 | /* If register arguments require space on the stack and stack space |
1475 | was not preallocated, allocate stack space here for arguments | |
1476 | passed in registers. */ | |
1477 | #if ! defined(ALLOCATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE) | |
1478 | if (must_preallocate == 0 && reg_parm_stack_space > 0) | |
1479 | anti_adjust_stack (gen_rtx (CONST_INT, VOIDmode, reg_parm_stack_space)); | |
1480 | #endif | |
1481 | ||
51bbfa0c RS |
1482 | /* Pass the function the address in which to return a structure value. */ |
1483 | if (structure_value_addr && ! structure_value_addr_parm) | |
1484 | { | |
1485 | emit_move_insn (struct_value_rtx, | |
1486 | force_reg (Pmode, | |
1487 | force_operand (structure_value_addr, 0))); | |
1488 | if (GET_CODE (struct_value_rtx) == REG) | |
1489 | { | |
1490 | push_to_sequence (use_insns); | |
1491 | emit_insn (gen_rtx (USE, VOIDmode, struct_value_rtx)); | |
1492 | use_insns = get_insns (); | |
1493 | end_sequence (); | |
1494 | } | |
1495 | } | |
1496 | ||
1497 | /* Now do the register loads required for any wholly-register parms or any | |
1498 | parms which are passed both on the stack and in a register. Their | |
1499 | expressions were already evaluated. | |
1500 | ||
1501 | Mark all register-parms as living through the call, putting these USE | |
1502 | insns in a list headed by USE_INSNS. */ | |
1503 | ||
1504 | for (i = 0; i < num_actuals; i++) | |
1505 | { | |
1506 | rtx list = args[i].reg; | |
1507 | int partial = args[i].partial; | |
1508 | ||
1509 | while (list) | |
1510 | { | |
1511 | rtx reg; | |
1512 | int nregs; | |
1513 | ||
1514 | /* Process each register that needs to get this arg. */ | |
1515 | if (GET_CODE (list) == EXPR_LIST) | |
1516 | reg = XEXP (list, 0), list = XEXP (list, 1); | |
1517 | else | |
1518 | reg = list, list = 0; | |
1519 | ||
1520 | /* Set to non-zero if must move a word at a time, even if just one | |
1521 | word (e.g, partial == 1 && mode == DFmode). Set to zero if | |
1522 | we just use a normal move insn. */ | |
1523 | nregs = (partial ? partial | |
1524 | : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode | |
1525 | ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value)) | |
1526 | + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD) | |
1527 | : 0)); | |
1528 | ||
1529 | /* If simple case, just do move. If normal partial, store_one_arg | |
1530 | has already loaded the register for us. In all other cases, | |
1531 | load the register(s) from memory. */ | |
1532 | ||
1533 | if (nregs == 0) | |
1534 | emit_move_insn (reg, args[i].value); | |
1535 | else if (args[i].partial == 0 || args[i].pass_on_stack) | |
1536 | move_block_to_reg (REGNO (reg), | |
1537 | validize_mem (args[i].value), nregs, | |
1538 | TYPE_MODE (TREE_TYPE (args[i].tree_value))); | |
1539 | ||
1540 | push_to_sequence (use_insns); | |
1541 | if (nregs == 0) | |
1542 | emit_insn (gen_rtx (USE, VOIDmode, reg)); | |
1543 | else | |
1544 | use_regs (REGNO (reg), nregs); | |
1545 | use_insns = get_insns (); | |
1546 | end_sequence (); | |
1547 | ||
1548 | /* PARTIAL referred only to the first register, so clear it for the | |
1549 | next time. */ | |
1550 | partial = 0; | |
1551 | } | |
1552 | } | |
1553 | ||
1554 | /* Perform postincrements before actually calling the function. */ | |
1555 | emit_queue (); | |
1556 | ||
1557 | /* All arguments and registers used for the call must be set up by now! */ | |
1558 | ||
1559 | funexp = prepare_call_address (funexp, fndecl, &use_insns); | |
1560 | ||
1561 | /* Generate the actual call instruction. */ | |
1562 | emit_call_1 (funexp, funtype, args_size.constant, struct_value_size, | |
1563 | FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1), | |
1564 | valreg, old_inhibit_defer_pop, use_insns, is_const); | |
1565 | ||
1566 | /* If call is cse'able, make appropriate pair of reg-notes around it. | |
1567 | Test valreg so we don't crash; may safely ignore `const' | |
1568 | if return type is void. */ | |
1569 | if (is_const && valreg != 0) | |
1570 | { | |
1571 | rtx note = 0; | |
1572 | rtx temp = gen_reg_rtx (GET_MODE (valreg)); | |
1573 | rtx insns; | |
1574 | ||
1575 | /* Construct an "equal form" for the value which mentions all the | |
1576 | arguments in order as well as the function name. */ | |
1577 | #ifdef PUSH_ARGS_REVERSED | |
1578 | for (i = 0; i < num_actuals; i++) | |
1579 | note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note); | |
1580 | #else | |
1581 | for (i = num_actuals - 1; i >= 0; i--) | |
1582 | note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note); | |
1583 | #endif | |
1584 | note = gen_rtx (EXPR_LIST, VOIDmode, funexp, note); | |
1585 | ||
1586 | insns = get_insns (); | |
1587 | end_sequence (); | |
1588 | ||
1589 | emit_libcall_block (insns, temp, valreg, note); | |
1590 | ||
1591 | valreg = temp; | |
1592 | } | |
1593 | ||
1594 | /* For calls to `setjmp', etc., inform flow.c it should complain | |
1595 | if nonvolatile values are live. */ | |
1596 | ||
1597 | if (returns_twice) | |
1598 | { | |
1599 | emit_note (name, NOTE_INSN_SETJMP); | |
1600 | current_function_calls_setjmp = 1; | |
1601 | } | |
1602 | ||
1603 | if (is_longjmp) | |
1604 | current_function_calls_longjmp = 1; | |
1605 | ||
1606 | /* Notice functions that cannot return. | |
1607 | If optimizing, insns emitted below will be dead. | |
1608 | If not optimizing, they will exist, which is useful | |
1609 | if the user uses the `return' command in the debugger. */ | |
1610 | ||
1611 | if (is_volatile || is_longjmp) | |
1612 | emit_barrier (); | |
1613 | ||
51bbfa0c RS |
1614 | /* If value type not void, return an rtx for the value. */ |
1615 | ||
1616 | /* If there are cleanups to be called, don't use a hard reg as target. */ | |
1617 | if (cleanups_this_call != old_cleanups | |
1618 | && target && REG_P (target) | |
1619 | && REGNO (target) < FIRST_PSEUDO_REGISTER) | |
1620 | target = 0; | |
1621 | ||
1622 | if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode | |
1623 | || ignore) | |
1624 | { | |
1625 | target = const0_rtx; | |
1626 | } | |
1627 | else if (structure_value_addr) | |
1628 | { | |
1629 | if (target == 0 || GET_CODE (target) != MEM) | |
29008b51 JW |
1630 | { |
1631 | target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), | |
1632 | memory_address (TYPE_MODE (TREE_TYPE (exp)), | |
1633 | structure_value_addr)); | |
1634 | MEM_IN_STRUCT_P (target) | |
1635 | = (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE | |
1636 | || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE | |
1637 | || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE); | |
1638 | } | |
51bbfa0c RS |
1639 | } |
1640 | else if (pcc_struct_value) | |
1641 | { | |
1642 | if (target == 0) | |
29008b51 JW |
1643 | { |
1644 | target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), | |
1645 | copy_to_reg (valreg)); | |
1646 | MEM_IN_STRUCT_P (target) | |
1647 | = (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE | |
1648 | || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE | |
1649 | || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE); | |
1650 | } | |
51bbfa0c RS |
1651 | else if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode) |
1652 | emit_move_insn (target, gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), | |
1653 | copy_to_reg (valreg))); | |
1654 | else | |
1655 | emit_block_move (target, gen_rtx (MEM, BLKmode, copy_to_reg (valreg)), | |
1656 | expr_size (exp), | |
1657 | TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT); | |
1658 | } | |
1659 | else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))) | |
1660 | /* TARGET and VALREG cannot be equal at this point because the latter | |
1661 | would not have REG_FUNCTION_VALUE_P true, while the former would if | |
1662 | it were referring to the same register. | |
1663 | ||
1664 | If they refer to the same register, this move will be a no-op, except | |
1665 | when function inlining is being done. */ | |
1666 | emit_move_insn (target, valreg); | |
1667 | else | |
1668 | target = copy_to_reg (valreg); | |
1669 | ||
1670 | /* Perform all cleanups needed for the arguments of this call | |
1671 | (i.e. destructors in C++). */ | |
1672 | expand_cleanups_to (old_cleanups); | |
1673 | ||
2f4aa534 RS |
1674 | /* If size of args is variable or this was a constructor call for a stack |
1675 | argument, restore saved stack-pointer value. */ | |
51bbfa0c RS |
1676 | |
1677 | if (old_stack_level) | |
1678 | { | |
59257ff7 | 1679 | emit_stack_restore (SAVE_BLOCK, old_stack_level, 0); |
51bbfa0c | 1680 | pending_stack_adjust = old_pending_adj; |
d64f5a78 | 1681 | #ifdef ACCUMULATE_OUTGOING_ARGS |
2f4aa534 RS |
1682 | stack_arg_under_construction = old_stack_arg_under_construction; |
1683 | highest_outgoing_arg_in_use = initial_highest_arg_in_use; | |
1684 | stack_usage_map = initial_stack_usage_map; | |
d64f5a78 | 1685 | #endif |
51bbfa0c | 1686 | } |
51bbfa0c RS |
1687 | #ifdef ACCUMULATE_OUTGOING_ARGS |
1688 | else | |
1689 | { | |
1690 | #ifdef REG_PARM_STACK_SPACE | |
1691 | if (save_area) | |
1692 | { | |
1693 | enum machine_mode save_mode = GET_MODE (save_area); | |
1694 | rtx stack_area | |
1695 | = gen_rtx (MEM, save_mode, | |
1696 | memory_address (save_mode, | |
1697 | plus_constant (argblock, low_to_save))); | |
1698 | ||
1699 | if (save_mode != BLKmode) | |
1700 | emit_move_insn (stack_area, save_area); | |
1701 | else | |
1702 | emit_block_move (stack_area, validize_mem (save_area), | |
1703 | gen_rtx (CONST_INT, VOIDmode, | |
1704 | high_to_save - low_to_save + 1, | |
1705 | PARM_BOUNDARY / BITS_PER_UNIT)); | |
1706 | } | |
1707 | #endif | |
1708 | ||
1709 | /* If we saved any argument areas, restore them. */ | |
1710 | for (i = 0; i < num_actuals; i++) | |
1711 | if (args[i].save_area) | |
1712 | { | |
1713 | enum machine_mode save_mode = GET_MODE (args[i].save_area); | |
1714 | rtx stack_area | |
1715 | = gen_rtx (MEM, save_mode, | |
1716 | memory_address (save_mode, | |
1717 | XEXP (args[i].stack_slot, 0))); | |
1718 | ||
1719 | if (save_mode != BLKmode) | |
1720 | emit_move_insn (stack_area, args[i].save_area); | |
1721 | else | |
1722 | emit_block_move (stack_area, validize_mem (args[i].save_area), | |
1723 | gen_rtx (CONST_INT, VOIDmode, | |
1724 | args[i].size.constant), | |
1725 | PARM_BOUNDARY / BITS_PER_UNIT); | |
1726 | } | |
1727 | ||
1728 | highest_outgoing_arg_in_use = initial_highest_arg_in_use; | |
1729 | stack_usage_map = initial_stack_usage_map; | |
1730 | } | |
1731 | #endif | |
1732 | ||
59257ff7 RK |
1733 | /* If this was alloca, record the new stack level for nonlocal gotos. |
1734 | Check for the handler slots since we might not have a save area | |
1735 | for non-local gotos. */ | |
1736 | ||
1737 | if (may_be_alloca && nonlocal_goto_handler_slot != 0) | |
1738 | emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, 0); | |
51bbfa0c RS |
1739 | |
1740 | pop_temp_slots (); | |
1741 | ||
1742 | return target; | |
1743 | } | |
1744 | \f | |
1745 | #if 0 | |
1746 | /* Return an rtx which represents a suitable home on the stack | |
1747 | given TYPE, the type of the argument looking for a home. | |
1748 | This is called only for BLKmode arguments. | |
1749 | ||
1750 | SIZE is the size needed for this target. | |
1751 | ARGS_ADDR is the address of the bottom of the argument block for this call. | |
1752 | OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless | |
1753 | if this machine uses push insns. */ | |
1754 | ||
1755 | static rtx | |
1756 | target_for_arg (type, size, args_addr, offset) | |
1757 | tree type; | |
1758 | rtx size; | |
1759 | rtx args_addr; | |
1760 | struct args_size offset; | |
1761 | { | |
1762 | rtx target; | |
1763 | rtx offset_rtx = ARGS_SIZE_RTX (offset); | |
1764 | ||
1765 | /* We do not call memory_address if possible, | |
1766 | because we want to address as close to the stack | |
1767 | as possible. For non-variable sized arguments, | |
1768 | this will be stack-pointer relative addressing. */ | |
1769 | if (GET_CODE (offset_rtx) == CONST_INT) | |
1770 | target = plus_constant (args_addr, INTVAL (offset_rtx)); | |
1771 | else | |
1772 | { | |
1773 | /* I have no idea how to guarantee that this | |
1774 | will work in the presence of register parameters. */ | |
1775 | target = gen_rtx (PLUS, Pmode, args_addr, offset_rtx); | |
1776 | target = memory_address (QImode, target); | |
1777 | } | |
1778 | ||
1779 | return gen_rtx (MEM, BLKmode, target); | |
1780 | } | |
1781 | #endif | |
1782 | \f | |
1783 | /* Store a single argument for a function call | |
1784 | into the register or memory area where it must be passed. | |
1785 | *ARG describes the argument value and where to pass it. | |
1786 | ||
1787 | ARGBLOCK is the address of the stack-block for all the arguments, | |
d45cf215 | 1788 | or 0 on a machine where arguments are pushed individually. |
51bbfa0c RS |
1789 | |
1790 | MAY_BE_ALLOCA nonzero says this could be a call to `alloca' | |
1791 | so must be careful about how the stack is used. | |
1792 | ||
1793 | VARIABLE_SIZE nonzero says that this was a variable-sized outgoing | |
1794 | argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate | |
1795 | that we need not worry about saving and restoring the stack. | |
1796 | ||
1797 | FNDECL is the declaration of the function we are calling. */ | |
1798 | ||
1799 | static void | |
6f90e075 JW |
1800 | store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl, |
1801 | reg_parm_stack_space) | |
51bbfa0c RS |
1802 | struct arg_data *arg; |
1803 | rtx argblock; | |
1804 | int may_be_alloca; | |
1805 | int variable_size; | |
1806 | tree fndecl; | |
6f90e075 | 1807 | int reg_parm_stack_space; |
51bbfa0c RS |
1808 | { |
1809 | register tree pval = arg->tree_value; | |
1810 | rtx reg = 0; | |
1811 | int partial = 0; | |
1812 | int used = 0; | |
1813 | int i, lower_bound, upper_bound; | |
1814 | ||
1815 | if (TREE_CODE (pval) == ERROR_MARK) | |
1816 | return; | |
1817 | ||
1818 | #ifdef ACCUMULATE_OUTGOING_ARGS | |
1819 | /* If this is being stored into a pre-allocated, fixed-size, stack area, | |
1820 | save any previous data at that location. */ | |
1821 | if (argblock && ! variable_size && arg->stack) | |
1822 | { | |
1823 | #ifdef ARGS_GROW_DOWNWARD | |
1824 | /* stack_slot is negative, but we want to index stack_usage_map */ | |
1825 | /* with positive values. */ | |
1826 | if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS) | |
1827 | upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1; | |
1828 | else | |
1829 | abort (); | |
1830 | ||
1831 | lower_bound = upper_bound - arg->size.constant; | |
1832 | #else | |
1833 | if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS) | |
1834 | lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)); | |
1835 | else | |
1836 | lower_bound = 0; | |
1837 | ||
1838 | upper_bound = lower_bound + arg->size.constant; | |
1839 | #endif | |
1840 | ||
1841 | for (i = lower_bound; i < upper_bound; i++) | |
1842 | if (stack_usage_map[i] | |
1843 | #ifdef REG_PARM_STACK_SPACE | |
1844 | /* Don't store things in the fixed argument area at this point; | |
1845 | it has already been saved. */ | |
6f90e075 | 1846 | && i > reg_parm_stack_space |
51bbfa0c RS |
1847 | #endif |
1848 | ) | |
1849 | break; | |
1850 | ||
1851 | if (i != upper_bound) | |
1852 | { | |
1853 | /* We need to make a save area. See what mode we can make it. */ | |
1854 | enum machine_mode save_mode | |
1855 | = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1); | |
1856 | rtx stack_area | |
1857 | = gen_rtx (MEM, save_mode, | |
1858 | memory_address (save_mode, XEXP (arg->stack_slot, 0))); | |
1859 | ||
1860 | if (save_mode == BLKmode) | |
1861 | { | |
1862 | arg->save_area = assign_stack_temp (BLKmode, | |
1863 | arg->size.constant, 1); | |
1864 | emit_block_move (validize_mem (arg->save_area), stack_area, | |
1865 | gen_rtx (CONST_INT, VOIDmode, | |
1866 | arg->size.constant), | |
1867 | PARM_BOUNDARY / BITS_PER_UNIT); | |
1868 | } | |
1869 | else | |
1870 | { | |
1871 | arg->save_area = gen_reg_rtx (save_mode); | |
1872 | emit_move_insn (arg->save_area, stack_area); | |
1873 | } | |
1874 | } | |
1875 | } | |
1876 | #endif | |
1877 | ||
1878 | /* If this isn't going to be placed on both the stack and in registers, | |
1879 | set up the register and number of words. */ | |
1880 | if (! arg->pass_on_stack) | |
1881 | reg = arg->reg, partial = arg->partial; | |
1882 | ||
1883 | if (reg != 0 && partial == 0) | |
1884 | /* Being passed entirely in a register. We shouldn't be called in | |
1885 | this case. */ | |
1886 | abort (); | |
1887 | ||
1888 | /* If this is being partially passed in a register, but multiple locations | |
1889 | are specified, we assume that the one partially used is the one that is | |
1890 | listed first. */ | |
1891 | if (reg && GET_CODE (reg) == EXPR_LIST) | |
1892 | reg = XEXP (reg, 0); | |
1893 | ||
1894 | /* If this is being passes partially in a register, we can't evaluate | |
1895 | it directly into its stack slot. Otherwise, we can. */ | |
1896 | if (arg->value == 0) | |
d64f5a78 RS |
1897 | { |
1898 | #ifdef ACCUMULATE_OUTGOING_ARGS | |
1899 | /* stack_arg_under_construction is nonzero if a function argument is | |
1900 | being evaluated directly into the outgoing argument list and | |
1901 | expand_call must take special action to preserve the argument list | |
1902 | if it is called recursively. | |
1903 | ||
1904 | For scalar function arguments stack_usage_map is sufficient to | |
1905 | determine which stack slots must be saved and restored. Scalar | |
1906 | arguments in general have pass_on_stack == 0. | |
1907 | ||
1908 | If this argument is initialized by a function which takes the | |
1909 | address of the argument (a C++ constructor or a C function | |
1910 | returning a BLKmode structure), then stack_usage_map is | |
1911 | insufficient and expand_call must push the stack around the | |
1912 | function call. Such arguments have pass_on_stack == 1. | |
1913 | ||
1914 | Note that it is always safe to set stack_arg_under_construction, | |
1915 | but this generates suboptimal code if set when not needed. */ | |
1916 | ||
1917 | if (arg->pass_on_stack) | |
1918 | stack_arg_under_construction++; | |
1919 | #endif | |
1920 | arg->value = expand_expr (pval, partial ? 0 : arg->stack, VOIDmode, 0); | |
1921 | #ifdef ACCUMULATE_OUTGOING_ARGS | |
1922 | if (arg->pass_on_stack) | |
1923 | stack_arg_under_construction--; | |
1924 | #endif | |
1925 | } | |
51bbfa0c RS |
1926 | |
1927 | /* Don't allow anything left on stack from computation | |
1928 | of argument to alloca. */ | |
1929 | if (may_be_alloca) | |
1930 | do_pending_stack_adjust (); | |
1931 | ||
1932 | if (arg->value == arg->stack) | |
1933 | /* If the value is already in the stack slot, we are done. */ | |
1934 | ; | |
1935 | else if (TYPE_MODE (TREE_TYPE (pval)) != BLKmode) | |
1936 | { | |
1937 | register int size; | |
1938 | ||
1939 | /* Argument is a scalar, not entirely passed in registers. | |
1940 | (If part is passed in registers, arg->partial says how much | |
1941 | and emit_push_insn will take care of putting it there.) | |
1942 | ||
1943 | Push it, and if its size is less than the | |
1944 | amount of space allocated to it, | |
1945 | also bump stack pointer by the additional space. | |
1946 | Note that in C the default argument promotions | |
1947 | will prevent such mismatches. */ | |
1948 | ||
1949 | size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (pval))); | |
1950 | /* Compute how much space the push instruction will push. | |
1951 | On many machines, pushing a byte will advance the stack | |
1952 | pointer by a halfword. */ | |
1953 | #ifdef PUSH_ROUNDING | |
1954 | size = PUSH_ROUNDING (size); | |
1955 | #endif | |
1956 | used = size; | |
1957 | ||
1958 | /* Compute how much space the argument should get: | |
1959 | round up to a multiple of the alignment for arguments. */ | |
1960 | if (none != FUNCTION_ARG_PADDING (TYPE_MODE (TREE_TYPE (pval)), | |
1961 | TREE_TYPE (pval))) | |
1962 | used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1) | |
1963 | / (PARM_BOUNDARY / BITS_PER_UNIT)) | |
1964 | * (PARM_BOUNDARY / BITS_PER_UNIT)); | |
1965 | ||
1966 | /* This isn't already where we want it on the stack, so put it there. | |
1967 | This can either be done with push or copy insns. */ | |
1968 | emit_push_insn (arg->value, TYPE_MODE (TREE_TYPE (pval)), | |
1969 | TREE_TYPE (pval), 0, 0, partial, reg, | |
1970 | used - size, argblock, ARGS_SIZE_RTX (arg->offset)); | |
1971 | } | |
1972 | else | |
1973 | { | |
1974 | /* BLKmode, at least partly to be pushed. */ | |
1975 | ||
1976 | register int excess; | |
1977 | rtx size_rtx; | |
1978 | ||
1979 | /* Pushing a nonscalar. | |
1980 | If part is passed in registers, PARTIAL says how much | |
1981 | and emit_push_insn will take care of putting it there. */ | |
1982 | ||
1983 | /* Round its size up to a multiple | |
1984 | of the allocation unit for arguments. */ | |
1985 | ||
1986 | if (arg->size.var != 0) | |
1987 | { | |
1988 | excess = 0; | |
1989 | size_rtx = ARGS_SIZE_RTX (arg->size); | |
1990 | } | |
1991 | else | |
1992 | { | |
1993 | register tree size = size_in_bytes (TREE_TYPE (pval)); | |
1994 | /* PUSH_ROUNDING has no effect on us, because | |
1995 | emit_push_insn for BLKmode is careful to avoid it. */ | |
1996 | excess = (arg->size.constant - TREE_INT_CST_LOW (size) | |
1997 | + partial * UNITS_PER_WORD); | |
1998 | size_rtx = expand_expr (size, 0, VOIDmode, 0); | |
1999 | } | |
2000 | ||
2001 | emit_push_insn (arg->value, TYPE_MODE (TREE_TYPE (pval)), | |
2002 | TREE_TYPE (pval), size_rtx, | |
2003 | TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial, | |
2004 | reg, excess, argblock, ARGS_SIZE_RTX (arg->offset)); | |
2005 | } | |
2006 | ||
2007 | ||
2008 | /* Unless this is a partially-in-register argument, the argument is now | |
2009 | in the stack. | |
2010 | ||
2011 | ??? Note that this can change arg->value from arg->stack to | |
2012 | arg->stack_slot and it matters when they are not the same. | |
2013 | It isn't totally clear that this is correct in all cases. */ | |
2014 | if (partial == 0) | |
2015 | arg->value = arg->stack_slot; | |
2016 | ||
2017 | /* Once we have pushed something, pops can't safely | |
2018 | be deferred during the rest of the arguments. */ | |
2019 | NO_DEFER_POP; | |
2020 | ||
2021 | /* ANSI doesn't require a sequence point here, | |
2022 | but PCC has one, so this will avoid some problems. */ | |
2023 | emit_queue (); | |
2024 | ||
2025 | /* Free any temporary slots made in processing this argument. */ | |
2026 | free_temp_slots (); | |
2027 | ||
2028 | #ifdef ACCUMULATE_OUTGOING_ARGS | |
2029 | /* Now mark the segment we just used. */ | |
2030 | if (argblock && ! variable_size && arg->stack) | |
2031 | for (i = lower_bound; i < upper_bound; i++) | |
2032 | stack_usage_map[i] = 1; | |
2033 | #endif | |
2034 | } |