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