Import final gcc2 snapshot (990109)
[official-gcc.git] / gcc / calls.c
blob7f247c6779fd61388c21db9a4ac210eb52cce037
1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989, 92-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include "config.h"
22 #include "system.h"
23 #include "rtl.h"
24 #include "tree.h"
25 #include "flags.h"
26 #include "expr.h"
27 #include "regs.h"
28 #include "insn-flags.h"
30 /* Decide whether a function's arguments should be processed
31 from first to last or from last to first.
33 They should if the stack and args grow in opposite directions, but
34 only if we have push insns. */
36 #ifdef PUSH_ROUNDING
38 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
39 #define PUSH_ARGS_REVERSED /* If it's last to first */
40 #endif
42 #endif
44 /* Like STACK_BOUNDARY but in units of bytes, not bits. */
45 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
47 /* Data structure and subroutines used within expand_call. */
49 struct arg_data
51 /* Tree node for this argument. */
52 tree tree_value;
53 /* Mode for value; TYPE_MODE unless promoted. */
54 enum machine_mode mode;
55 /* Current RTL value for argument, or 0 if it isn't precomputed. */
56 rtx value;
57 /* Initially-compute RTL value for argument; only for const functions. */
58 rtx initial_value;
59 /* Register to pass this argument in, 0 if passed on stack, or an
60 PARALLEL if the arg is to be copied into multiple non-contiguous
61 registers. */
62 rtx reg;
63 /* If REG was promoted from the actual mode of the argument expression,
64 indicates whether the promotion is sign- or zero-extended. */
65 int unsignedp;
66 /* Number of registers to use. 0 means put the whole arg in registers.
67 Also 0 if not passed in registers. */
68 int partial;
69 /* Non-zero if argument must be passed on stack.
70 Note that some arguments may be passed on the stack
71 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
72 pass_on_stack identifies arguments that *cannot* go in registers. */
73 int pass_on_stack;
74 /* Offset of this argument from beginning of stack-args. */
75 struct args_size offset;
76 /* Similar, but offset to the start of the stack slot. Different from
77 OFFSET if this arg pads downward. */
78 struct args_size slot_offset;
79 /* Size of this argument on the stack, rounded up for any padding it gets,
80 parts of the argument passed in registers do not count.
81 If REG_PARM_STACK_SPACE is defined, then register parms
82 are counted here as well. */
83 struct args_size size;
84 /* Location on the stack at which parameter should be stored. The store
85 has already been done if STACK == VALUE. */
86 rtx stack;
87 /* Location on the stack of the start of this argument slot. This can
88 differ from STACK if this arg pads downward. This location is known
89 to be aligned to FUNCTION_ARG_BOUNDARY. */
90 rtx stack_slot;
91 #ifdef ACCUMULATE_OUTGOING_ARGS
92 /* Place that this stack area has been saved, if needed. */
93 rtx save_area;
94 #endif
95 /* If an argument's alignment does not permit direct copying into registers,
96 copy in smaller-sized pieces into pseudos. These are stored in a
97 block pointed to by this field. The next field says how many
98 word-sized pseudos we made. */
99 rtx *aligned_regs;
100 int n_aligned_regs;
103 #ifdef ACCUMULATE_OUTGOING_ARGS
104 /* A vector of one char per byte of stack space. A byte if non-zero if
105 the corresponding stack location has been used.
106 This vector is used to prevent a function call within an argument from
107 clobbering any stack already set up. */
108 static char *stack_usage_map;
110 /* Size of STACK_USAGE_MAP. */
111 static int highest_outgoing_arg_in_use;
113 /* stack_arg_under_construction is nonzero when an argument may be
114 initialized with a constructor call (including a C function that
115 returns a BLKmode struct) and expand_call must take special action
116 to make sure the object being constructed does not overlap the
117 argument list for the constructor call. */
118 int stack_arg_under_construction;
119 #endif
121 static int calls_function PROTO((tree, int));
122 static int calls_function_1 PROTO((tree, int));
123 static void emit_call_1 PROTO((rtx, tree, tree, HOST_WIDE_INT,
124 HOST_WIDE_INT, rtx, rtx,
125 int, rtx, int));
126 static void store_one_arg PROTO ((struct arg_data *, rtx, int, int,
127 tree, int));
129 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
130 `alloca'.
132 If WHICH is 0, return 1 if EXP contains a call to any function.
133 Actually, we only need return 1 if evaluating EXP would require pushing
134 arguments on the stack, but that is too difficult to compute, so we just
135 assume any function call might require the stack. */
137 static tree calls_function_save_exprs;
139 static int
140 calls_function (exp, which)
141 tree exp;
142 int which;
144 int val;
145 calls_function_save_exprs = 0;
146 val = calls_function_1 (exp, which);
147 calls_function_save_exprs = 0;
148 return val;
151 static int
152 calls_function_1 (exp, which)
153 tree exp;
154 int which;
156 register int i;
157 enum tree_code code = TREE_CODE (exp);
158 int type = TREE_CODE_CLASS (code);
159 int length = tree_code_length[(int) code];
161 /* If this code is language-specific, we don't know what it will do. */
162 if ((int) code >= NUM_TREE_CODES)
163 return 1;
165 /* Only expressions and references can contain calls. */
166 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
167 && type != 'b')
168 return 0;
170 switch (code)
172 case CALL_EXPR:
173 if (which == 0)
174 return 1;
175 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
176 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
177 == FUNCTION_DECL))
179 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
181 if ((DECL_BUILT_IN (fndecl)
182 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA)
183 || (DECL_SAVED_INSNS (fndecl)
184 && (FUNCTION_FLAGS (DECL_SAVED_INSNS (fndecl))
185 & FUNCTION_FLAGS_CALLS_ALLOCA)))
186 return 1;
189 /* Third operand is RTL. */
190 length = 2;
191 break;
193 case SAVE_EXPR:
194 if (SAVE_EXPR_RTL (exp) != 0)
195 return 0;
196 if (value_member (exp, calls_function_save_exprs))
197 return 0;
198 calls_function_save_exprs = tree_cons (NULL_TREE, exp,
199 calls_function_save_exprs);
200 return (TREE_OPERAND (exp, 0) != 0
201 && calls_function_1 (TREE_OPERAND (exp, 0), which));
203 case BLOCK:
205 register tree local;
207 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
208 if (DECL_INITIAL (local) != 0
209 && calls_function_1 (DECL_INITIAL (local), which))
210 return 1;
213 register tree subblock;
215 for (subblock = BLOCK_SUBBLOCKS (exp);
216 subblock;
217 subblock = TREE_CHAIN (subblock))
218 if (calls_function_1 (subblock, which))
219 return 1;
221 return 0;
223 case METHOD_CALL_EXPR:
224 length = 3;
225 break;
227 case WITH_CLEANUP_EXPR:
228 length = 1;
229 break;
231 case RTL_EXPR:
232 return 0;
234 default:
235 break;
238 for (i = 0; i < length; i++)
239 if (TREE_OPERAND (exp, i) != 0
240 && calls_function_1 (TREE_OPERAND (exp, i), which))
241 return 1;
243 return 0;
246 /* Force FUNEXP into a form suitable for the address of a CALL,
247 and return that as an rtx. Also load the static chain register
248 if FNDECL is a nested function.
250 CALL_FUSAGE points to a variable holding the prospective
251 CALL_INSN_FUNCTION_USAGE information. */
254 prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen)
255 rtx funexp;
256 tree fndecl;
257 rtx *call_fusage;
258 int reg_parm_seen;
260 rtx static_chain_value = 0;
262 funexp = protect_from_queue (funexp, 0);
264 if (fndecl != 0)
265 /* Get possible static chain value for nested function in C. */
266 static_chain_value = lookup_static_chain (fndecl);
268 /* Make a valid memory address and copy constants thru pseudo-regs,
269 but not for a constant address if -fno-function-cse. */
270 if (GET_CODE (funexp) != SYMBOL_REF)
271 /* If we are using registers for parameters, force the
272 function address into a register now. */
273 funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
274 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
275 : memory_address (FUNCTION_MODE, funexp));
276 else
278 #ifndef NO_FUNCTION_CSE
279 if (optimize && ! flag_no_function_cse)
280 #ifdef NO_RECURSIVE_FUNCTION_CSE
281 if (fndecl != current_function_decl)
282 #endif
283 funexp = force_reg (Pmode, funexp);
284 #endif
287 if (static_chain_value != 0)
289 emit_move_insn (static_chain_rtx, static_chain_value);
291 if (GET_CODE (static_chain_rtx) == REG)
292 use_reg (call_fusage, static_chain_rtx);
295 return funexp;
298 /* Generate instructions to call function FUNEXP,
299 and optionally pop the results.
300 The CALL_INSN is the first insn generated.
302 FNDECL is the declaration node of the function. This is given to the
303 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
305 FUNTYPE is the data type of the function. This is given to the macro
306 RETURN_POPS_ARGS to determine whether this function pops its own args.
307 We used to allow an identifier for library functions, but that doesn't
308 work when the return type is an aggregate type and the calling convention
309 says that the pointer to this aggregate is to be popped by the callee.
311 STACK_SIZE is the number of bytes of arguments on the stack,
312 rounded up to STACK_BOUNDARY; zero if the size is variable.
313 This is both to put into the call insn and
314 to generate explicit popping code if necessary.
316 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
317 It is zero if this call doesn't want a structure value.
319 NEXT_ARG_REG is the rtx that results from executing
320 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
321 just after all the args have had their registers assigned.
322 This could be whatever you like, but normally it is the first
323 arg-register beyond those used for args in this call,
324 or 0 if all the arg-registers are used in this call.
325 It is passed on to `gen_call' so you can put this info in the call insn.
327 VALREG is a hard register in which a value is returned,
328 or 0 if the call does not return a value.
330 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
331 the args to this call were processed.
332 We restore `inhibit_defer_pop' to that value.
334 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
335 denote registers used by the called function.
337 IS_CONST is true if this is a `const' call. */
339 static void
340 emit_call_1 (funexp, fndecl, funtype, stack_size, struct_value_size,
341 next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
342 is_const)
343 rtx funexp;
344 tree fndecl;
345 tree funtype;
346 HOST_WIDE_INT stack_size;
347 HOST_WIDE_INT struct_value_size;
348 rtx next_arg_reg;
349 rtx valreg;
350 int old_inhibit_defer_pop;
351 rtx call_fusage;
352 int is_const;
354 rtx stack_size_rtx = GEN_INT (stack_size);
355 rtx struct_value_size_rtx = GEN_INT (struct_value_size);
356 rtx call_insn;
357 int already_popped = 0;
359 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
360 and we don't want to load it into a register as an optimization,
361 because prepare_call_address already did it if it should be done. */
362 if (GET_CODE (funexp) != SYMBOL_REF)
363 funexp = memory_address (FUNCTION_MODE, funexp);
365 #ifndef ACCUMULATE_OUTGOING_ARGS
366 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
367 if (HAVE_call_pop && HAVE_call_value_pop
368 && (RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0
369 || stack_size == 0))
371 rtx n_pop = GEN_INT (RETURN_POPS_ARGS (fndecl, funtype, stack_size));
372 rtx pat;
374 /* If this subroutine pops its own args, record that in the call insn
375 if possible, for the sake of frame pointer elimination. */
377 if (valreg)
378 pat = gen_call_value_pop (valreg,
379 gen_rtx_MEM (FUNCTION_MODE, funexp),
380 stack_size_rtx, next_arg_reg, n_pop);
381 else
382 pat = gen_call_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
383 stack_size_rtx, next_arg_reg, n_pop);
385 emit_call_insn (pat);
386 already_popped = 1;
388 else
389 #endif
390 #endif
392 #if defined (HAVE_call) && defined (HAVE_call_value)
393 if (HAVE_call && HAVE_call_value)
395 if (valreg)
396 emit_call_insn (gen_call_value (valreg,
397 gen_rtx_MEM (FUNCTION_MODE, funexp),
398 stack_size_rtx, next_arg_reg,
399 NULL_RTX));
400 else
401 emit_call_insn (gen_call (gen_rtx_MEM (FUNCTION_MODE, funexp),
402 stack_size_rtx, next_arg_reg,
403 struct_value_size_rtx));
405 else
406 #endif
407 abort ();
409 /* Find the CALL insn we just emitted. */
410 for (call_insn = get_last_insn ();
411 call_insn && GET_CODE (call_insn) != CALL_INSN;
412 call_insn = PREV_INSN (call_insn))
415 if (! call_insn)
416 abort ();
418 /* Put the register usage information on the CALL. If there is already
419 some usage information, put ours at the end. */
420 if (CALL_INSN_FUNCTION_USAGE (call_insn))
422 rtx link;
424 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
425 link = XEXP (link, 1))
428 XEXP (link, 1) = call_fusage;
430 else
431 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
433 /* If this is a const call, then set the insn's unchanging bit. */
434 if (is_const)
435 CONST_CALL_P (call_insn) = 1;
437 /* Restore this now, so that we do defer pops for this call's args
438 if the context of the call as a whole permits. */
439 inhibit_defer_pop = old_inhibit_defer_pop;
441 #ifndef ACCUMULATE_OUTGOING_ARGS
442 /* If returning from the subroutine does not automatically pop the args,
443 we need an instruction to pop them sooner or later.
444 Perhaps do it now; perhaps just record how much space to pop later.
446 If returning from the subroutine does pop the args, indicate that the
447 stack pointer will be changed. */
449 if (stack_size != 0 && RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0)
451 if (!already_popped)
452 CALL_INSN_FUNCTION_USAGE (call_insn)
453 = gen_rtx_EXPR_LIST (VOIDmode,
454 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
455 CALL_INSN_FUNCTION_USAGE (call_insn));
456 stack_size -= RETURN_POPS_ARGS (fndecl, funtype, stack_size);
457 stack_size_rtx = GEN_INT (stack_size);
460 if (stack_size != 0)
462 if (flag_defer_pop && inhibit_defer_pop == 0 && !is_const)
463 pending_stack_adjust += stack_size;
464 else
465 adjust_stack (stack_size_rtx);
467 #endif
470 /* Generate all the code for a function call
471 and return an rtx for its value.
472 Store the value in TARGET (specified as an rtx) if convenient.
473 If the value is stored in TARGET then TARGET is returned.
474 If IGNORE is nonzero, then we ignore the value of the function call. */
477 expand_call (exp, target, ignore)
478 tree exp;
479 rtx target;
480 int ignore;
482 /* List of actual parameters. */
483 tree actparms = TREE_OPERAND (exp, 1);
484 /* RTX for the function to be called. */
485 rtx funexp;
486 /* Tree node for the function to be called (not the address!). */
487 tree funtree;
488 /* Data type of the function. */
489 tree funtype;
490 /* Declaration of the function being called,
491 or 0 if the function is computed (not known by name). */
492 tree fndecl = 0;
493 char *name = 0;
495 /* Register in which non-BLKmode value will be returned,
496 or 0 if no value or if value is BLKmode. */
497 rtx valreg;
498 /* Address where we should return a BLKmode value;
499 0 if value not BLKmode. */
500 rtx structure_value_addr = 0;
501 /* Nonzero if that address is being passed by treating it as
502 an extra, implicit first parameter. Otherwise,
503 it is passed by being copied directly into struct_value_rtx. */
504 int structure_value_addr_parm = 0;
505 /* Size of aggregate value wanted, or zero if none wanted
506 or if we are using the non-reentrant PCC calling convention
507 or expecting the value in registers. */
508 HOST_WIDE_INT struct_value_size = 0;
509 /* Nonzero if called function returns an aggregate in memory PCC style,
510 by returning the address of where to find it. */
511 int pcc_struct_value = 0;
513 /* Number of actual parameters in this call, including struct value addr. */
514 int num_actuals;
515 /* Number of named args. Args after this are anonymous ones
516 and they must all go on the stack. */
517 int n_named_args;
518 /* Count arg position in order args appear. */
519 int argpos;
521 /* Vector of information about each argument.
522 Arguments are numbered in the order they will be pushed,
523 not the order they are written. */
524 struct arg_data *args;
526 /* Total size in bytes of all the stack-parms scanned so far. */
527 struct args_size args_size;
528 /* Size of arguments before any adjustments (such as rounding). */
529 struct args_size original_args_size;
530 /* Data on reg parms scanned so far. */
531 CUMULATIVE_ARGS args_so_far;
532 /* Nonzero if a reg parm has been scanned. */
533 int reg_parm_seen;
534 /* Nonzero if this is an indirect function call. */
536 /* Nonzero if we must avoid push-insns in the args for this call.
537 If stack space is allocated for register parameters, but not by the
538 caller, then it is preallocated in the fixed part of the stack frame.
539 So the entire argument block must then be preallocated (i.e., we
540 ignore PUSH_ROUNDING in that case). */
542 #ifdef PUSH_ROUNDING
543 int must_preallocate = 0;
544 #else
545 int must_preallocate = 1;
546 #endif
548 /* Size of the stack reserved for parameter registers. */
549 int reg_parm_stack_space = 0;
551 /* 1 if scanning parms front to back, -1 if scanning back to front. */
552 int inc;
553 /* Address of space preallocated for stack parms
554 (on machines that lack push insns), or 0 if space not preallocated. */
555 rtx argblock = 0;
557 /* Nonzero if it is plausible that this is a call to alloca. */
558 int may_be_alloca;
559 /* Nonzero if this is a call to setjmp or a related function. */
560 int returns_twice;
561 /* Nonzero if this is a call to `longjmp'. */
562 int is_longjmp;
563 /* Nonzero if this is a call to an inline function. */
564 int is_integrable = 0;
565 /* Nonzero if this is a call to a `const' function.
566 Note that only explicitly named functions are handled as `const' here. */
567 int is_const = 0;
568 /* Nonzero if this is a call to a `volatile' function. */
569 int is_volatile = 0;
570 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
571 /* Define the boundary of the register parm stack space that needs to be
572 save, if any. */
573 int low_to_save = -1, high_to_save;
574 rtx save_area = 0; /* Place that it is saved */
575 #endif
577 #ifdef ACCUMULATE_OUTGOING_ARGS
578 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
579 char *initial_stack_usage_map = stack_usage_map;
580 #endif
582 rtx old_stack_level = 0;
583 int old_pending_adj = 0;
584 int old_stack_arg_under_construction;
585 int old_inhibit_defer_pop = inhibit_defer_pop;
586 rtx call_fusage = 0;
587 register tree p;
588 register int i, j;
590 /* The value of the function call can be put in a hard register. But
591 if -fcheck-memory-usage, code which invokes functions (and thus
592 damages some hard registers) can be inserted before using the value.
593 So, target is always a pseudo-register in that case. */
594 if (current_function_check_memory_usage)
595 target = 0;
597 /* See if we can find a DECL-node for the actual function.
598 As a result, decide whether this is a call to an integrable function. */
600 p = TREE_OPERAND (exp, 0);
601 if (TREE_CODE (p) == ADDR_EXPR)
603 fndecl = TREE_OPERAND (p, 0);
604 if (TREE_CODE (fndecl) != FUNCTION_DECL)
605 fndecl = 0;
606 else
608 if (!flag_no_inline
609 && fndecl != current_function_decl
610 && DECL_INLINE (fndecl)
611 && DECL_SAVED_INSNS (fndecl)
612 && RTX_INTEGRATED_P (DECL_SAVED_INSNS (fndecl)))
613 is_integrable = 1;
614 else if (! TREE_ADDRESSABLE (fndecl))
616 /* In case this function later becomes inlinable,
617 record that there was already a non-inline call to it.
619 Use abstraction instead of setting TREE_ADDRESSABLE
620 directly. */
621 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
622 && optimize > 0)
624 warning_with_decl (fndecl, "can't inline call to `%s'");
625 warning ("called from here");
627 mark_addressable (fndecl);
630 if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
631 && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
632 is_const = 1;
634 if (TREE_THIS_VOLATILE (fndecl))
635 is_volatile = 1;
639 /* If we don't have specific function to call, see if we have a
640 constant or `noreturn' function from the type. */
641 if (fndecl == 0)
643 is_const = TREE_READONLY (TREE_TYPE (TREE_TYPE (p)));
644 is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
647 #ifdef REG_PARM_STACK_SPACE
648 #ifdef MAYBE_REG_PARM_STACK_SPACE
649 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
650 #else
651 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
652 #endif
653 #endif
655 #if defined(PUSH_ROUNDING) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
656 if (reg_parm_stack_space > 0)
657 must_preallocate = 1;
658 #endif
660 /* Warn if this value is an aggregate type,
661 regardless of which calling convention we are using for it. */
662 if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
663 warning ("function call has aggregate value");
665 /* Set up a place to return a structure. */
667 /* Cater to broken compilers. */
668 if (aggregate_value_p (exp))
670 /* This call returns a big structure. */
671 is_const = 0;
673 #ifdef PCC_STATIC_STRUCT_RETURN
675 pcc_struct_value = 1;
676 /* Easier than making that case work right. */
677 if (is_integrable)
679 /* In case this is a static function, note that it has been
680 used. */
681 if (! TREE_ADDRESSABLE (fndecl))
682 mark_addressable (fndecl);
683 is_integrable = 0;
686 #else /* not PCC_STATIC_STRUCT_RETURN */
688 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
690 if (target && GET_CODE (target) == MEM)
691 structure_value_addr = XEXP (target, 0);
692 else
694 /* Assign a temporary to hold the value. */
695 tree d;
697 /* For variable-sized objects, we must be called with a target
698 specified. If we were to allocate space on the stack here,
699 we would have no way of knowing when to free it. */
701 if (struct_value_size < 0)
702 abort ();
704 /* This DECL is just something to feed to mark_addressable;
705 it doesn't get pushed. */
706 d = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (exp));
707 DECL_RTL (d) = assign_temp (TREE_TYPE (exp), 1, 0, 1);
708 mark_addressable (d);
709 structure_value_addr = XEXP (DECL_RTL (d), 0);
710 TREE_USED (d) = 1;
711 target = 0;
714 #endif /* not PCC_STATIC_STRUCT_RETURN */
717 /* If called function is inline, try to integrate it. */
719 if (is_integrable)
721 rtx temp;
722 rtx before_call = get_last_insn ();
724 temp = expand_inline_function (fndecl, actparms, target,
725 ignore, TREE_TYPE (exp),
726 structure_value_addr);
728 /* If inlining succeeded, return. */
729 if ((HOST_WIDE_INT) temp != -1)
731 #ifdef ACCUMULATE_OUTGOING_ARGS
732 /* If the outgoing argument list must be preserved, push
733 the stack before executing the inlined function if it
734 makes any calls. */
736 for (i = reg_parm_stack_space - 1; i >= 0; i--)
737 if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
738 break;
740 if (stack_arg_under_construction || i >= 0)
742 rtx first_insn
743 = before_call ? NEXT_INSN (before_call) : get_insns ();
744 rtx insn, seq;
746 /* Look for a call in the inline function code.
747 If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is
748 nonzero then there is a call and it is not necessary
749 to scan the insns. */
751 if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0)
752 for (insn = first_insn; insn; insn = NEXT_INSN (insn))
753 if (GET_CODE (insn) == CALL_INSN)
754 break;
756 if (insn)
758 /* Reserve enough stack space so that the largest
759 argument list of any function call in the inline
760 function does not overlap the argument list being
761 evaluated. This is usually an overestimate because
762 allocate_dynamic_stack_space reserves space for an
763 outgoing argument list in addition to the requested
764 space, but there is no way to ask for stack space such
765 that an argument list of a certain length can be
766 safely constructed.
768 Add the stack space reserved for register arguments, if
769 any, in the inline function. What is really needed is the
770 largest value of reg_parm_stack_space in the inline
771 function, but that is not available. Using the current
772 value of reg_parm_stack_space is wrong, but gives
773 correct results on all supported machines. */
775 int adjust = (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl))
776 + reg_parm_stack_space);
778 start_sequence ();
779 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
780 allocate_dynamic_stack_space (GEN_INT (adjust),
781 NULL_RTX, BITS_PER_UNIT);
782 seq = get_insns ();
783 end_sequence ();
784 emit_insns_before (seq, first_insn);
785 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
788 #endif
790 /* If the result is equivalent to TARGET, return TARGET to simplify
791 checks in store_expr. They can be equivalent but not equal in the
792 case of a function that returns BLKmode. */
793 if (temp != target && rtx_equal_p (temp, target))
794 return target;
795 return temp;
798 /* If inlining failed, mark FNDECL as needing to be compiled
799 separately after all. If function was declared inline,
800 give a warning. */
801 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
802 && optimize > 0 && ! TREE_ADDRESSABLE (fndecl))
804 warning_with_decl (fndecl, "inlining failed in call to `%s'");
805 warning ("called from here");
807 mark_addressable (fndecl);
810 /* When calling a const function, we must pop the stack args right away,
811 so that the pop is deleted or moved with the call. */
812 if (is_const)
813 NO_DEFER_POP;
815 function_call_count++;
817 if (fndecl && DECL_NAME (fndecl))
818 name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
820 #if 0
821 /* Unless it's a call to a specific function that isn't alloca,
822 if it has one argument, we must assume it might be alloca. */
824 may_be_alloca
825 = (!(fndecl != 0 && strcmp (name, "alloca"))
826 && actparms != 0
827 && TREE_CHAIN (actparms) == 0);
828 #else
829 /* We assume that alloca will always be called by name. It
830 makes no sense to pass it as a pointer-to-function to
831 anything that does not understand its behavior. */
832 may_be_alloca
833 = (name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
834 && name[0] == 'a'
835 && ! strcmp (name, "alloca"))
836 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
837 && name[0] == '_'
838 && ! strcmp (name, "__builtin_alloca"))));
839 #endif
841 /* See if this is a call to a function that can return more than once
842 or a call to longjmp. */
844 returns_twice = 0;
845 is_longjmp = 0;
847 if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 15)
849 char *tname = name;
851 /* Disregard prefix _, __ or __x. */
852 if (name[0] == '_')
854 if (name[1] == '_' && name[2] == 'x')
855 tname += 3;
856 else if (name[1] == '_')
857 tname += 2;
858 else
859 tname += 1;
862 if (tname[0] == 's')
864 returns_twice
865 = ((tname[1] == 'e'
866 && (! strcmp (tname, "setjmp")
867 || ! strcmp (tname, "setjmp_syscall")))
868 || (tname[1] == 'i'
869 && ! strcmp (tname, "sigsetjmp"))
870 || (tname[1] == 'a'
871 && ! strcmp (tname, "savectx")));
872 if (tname[1] == 'i'
873 && ! strcmp (tname, "siglongjmp"))
874 is_longjmp = 1;
876 else if ((tname[0] == 'q' && tname[1] == 's'
877 && ! strcmp (tname, "qsetjmp"))
878 || (tname[0] == 'v' && tname[1] == 'f'
879 && ! strcmp (tname, "vfork")))
880 returns_twice = 1;
882 else if (tname[0] == 'l' && tname[1] == 'o'
883 && ! strcmp (tname, "longjmp"))
884 is_longjmp = 1;
887 if (may_be_alloca)
888 current_function_calls_alloca = 1;
890 /* Don't let pending stack adjusts add up to too much.
891 Also, do all pending adjustments now
892 if there is any chance this might be a call to alloca. */
894 if (pending_stack_adjust >= 32
895 || (pending_stack_adjust > 0 && may_be_alloca))
896 do_pending_stack_adjust ();
898 /* Operand 0 is a pointer-to-function; get the type of the function. */
899 funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
900 if (! POINTER_TYPE_P (funtype))
901 abort ();
903 funtype = TREE_TYPE (funtype);
905 /* Push the temporary stack slot level so that we can free any temporaries
906 we make. */
907 push_temp_slots ();
909 /* Start updating where the next arg would go.
911 On some machines (such as the PA) indirect calls have a different
912 calling convention than normal calls. The last argument in
913 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
914 or not. */
915 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, (fndecl == 0));
917 /* If struct_value_rtx is 0, it means pass the address
918 as if it were an extra parameter. */
919 if (structure_value_addr && struct_value_rtx == 0)
921 /* If structure_value_addr is a REG other than
922 virtual_outgoing_args_rtx, we can use always use it. If it
923 is not a REG, we must always copy it into a register.
924 If it is virtual_outgoing_args_rtx, we must copy it to another
925 register in some cases. */
926 rtx temp = (GET_CODE (structure_value_addr) != REG
927 #ifdef ACCUMULATE_OUTGOING_ARGS
928 || (stack_arg_under_construction
929 && structure_value_addr == virtual_outgoing_args_rtx)
930 #endif
931 ? copy_addr_to_reg (structure_value_addr)
932 : structure_value_addr);
934 actparms
935 = tree_cons (error_mark_node,
936 make_tree (build_pointer_type (TREE_TYPE (funtype)),
937 temp),
938 actparms);
939 structure_value_addr_parm = 1;
942 /* Count the arguments and set NUM_ACTUALS. */
943 for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
944 num_actuals = i;
946 /* Compute number of named args.
947 Normally, don't include the last named arg if anonymous args follow.
948 We do include the last named arg if STRICT_ARGUMENT_NAMING is nonzero.
949 (If no anonymous args follow, the result of list_length is actually
950 one too large. This is harmless.)
952 If SETUP_INCOMING_VARARGS is defined and STRICT_ARGUMENT_NAMING is zero,
953 this machine will be able to place unnamed args that were passed in
954 registers into the stack. So treat all args as named. This allows the
955 insns emitting for a specific argument list to be independent of the
956 function declaration.
958 If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable
959 way to pass unnamed args in registers, so we must force them into
960 memory. */
962 if ((STRICT_ARGUMENT_NAMING
963 #ifndef SETUP_INCOMING_VARARGS
964 || 1
965 #endif
967 && TYPE_ARG_TYPES (funtype) != 0)
968 n_named_args
969 = (list_length (TYPE_ARG_TYPES (funtype))
970 /* Don't include the last named arg. */
971 - (STRICT_ARGUMENT_NAMING ? 0 : 1)
972 /* Count the struct value address, if it is passed as a parm. */
973 + structure_value_addr_parm);
974 else
975 /* If we know nothing, treat all args as named. */
976 n_named_args = num_actuals;
978 /* Make a vector to hold all the information about each arg. */
979 args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
980 bzero ((char *) args, num_actuals * sizeof (struct arg_data));
982 args_size.constant = 0;
983 args_size.var = 0;
985 /* In this loop, we consider args in the order they are written.
986 We fill up ARGS from the front or from the back if necessary
987 so that in any case the first arg to be pushed ends up at the front. */
989 #ifdef PUSH_ARGS_REVERSED
990 i = num_actuals - 1, inc = -1;
991 /* In this case, must reverse order of args
992 so that we compute and push the last arg first. */
993 #else
994 i = 0, inc = 1;
995 #endif
997 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
998 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
1000 tree type = TREE_TYPE (TREE_VALUE (p));
1001 int unsignedp;
1002 enum machine_mode mode;
1004 args[i].tree_value = TREE_VALUE (p);
1006 /* Replace erroneous argument with constant zero. */
1007 if (type == error_mark_node || TYPE_SIZE (type) == 0)
1008 args[i].tree_value = integer_zero_node, type = integer_type_node;
1010 /* If TYPE is a transparent union, pass things the way we would
1011 pass the first field of the union. We have already verified that
1012 the modes are the same. */
1013 if (TYPE_TRANSPARENT_UNION (type))
1014 type = TREE_TYPE (TYPE_FIELDS (type));
1016 /* Decide where to pass this arg.
1018 args[i].reg is nonzero if all or part is passed in registers.
1020 args[i].partial is nonzero if part but not all is passed in registers,
1021 and the exact value says how many words are passed in registers.
1023 args[i].pass_on_stack is nonzero if the argument must at least be
1024 computed on the stack. It may then be loaded back into registers
1025 if args[i].reg is nonzero.
1027 These decisions are driven by the FUNCTION_... macros and must agree
1028 with those made by function.c. */
1030 /* See if this argument should be passed by invisible reference. */
1031 if ((TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1032 && contains_placeholder_p (TYPE_SIZE (type)))
1033 || TREE_ADDRESSABLE (type)
1034 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1035 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, TYPE_MODE (type),
1036 type, argpos < n_named_args)
1037 #endif
1040 /* If we're compiling a thunk, pass through invisible
1041 references instead of making a copy. */
1042 if (current_function_is_thunk
1043 #ifdef FUNCTION_ARG_CALLEE_COPIES
1044 || (FUNCTION_ARG_CALLEE_COPIES (args_so_far, TYPE_MODE (type),
1045 type, argpos < n_named_args)
1046 /* If it's in a register, we must make a copy of it too. */
1047 /* ??? Is this a sufficient test? Is there a better one? */
1048 && !(TREE_CODE (args[i].tree_value) == VAR_DECL
1049 && REG_P (DECL_RTL (args[i].tree_value)))
1050 && ! TREE_ADDRESSABLE (type))
1051 #endif
1054 args[i].tree_value = build1 (ADDR_EXPR,
1055 build_pointer_type (type),
1056 args[i].tree_value);
1057 type = build_pointer_type (type);
1059 else
1061 /* We make a copy of the object and pass the address to the
1062 function being called. */
1063 rtx copy;
1065 if (TYPE_SIZE (type) == 0
1066 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1067 || (flag_stack_check && ! STACK_CHECK_BUILTIN
1068 && (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0
1069 || (TREE_INT_CST_LOW (TYPE_SIZE (type))
1070 > STACK_CHECK_MAX_VAR_SIZE * BITS_PER_UNIT))))
1072 /* This is a variable-sized object. Make space on the stack
1073 for it. */
1074 rtx size_rtx = expr_size (TREE_VALUE (p));
1076 if (old_stack_level == 0)
1078 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1079 old_pending_adj = pending_stack_adjust;
1080 pending_stack_adjust = 0;
1083 copy = gen_rtx_MEM
1084 (BLKmode,
1085 allocate_dynamic_stack_space (size_rtx, NULL_RTX,
1086 TYPE_ALIGN (type)));
1088 else
1090 int size = int_size_in_bytes (type);
1092 copy = assign_stack_temp (TYPE_MODE (type), size, 0);
1095 MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
1097 store_expr (args[i].tree_value, copy, 0);
1098 is_const = 0;
1100 args[i].tree_value = build1 (ADDR_EXPR,
1101 build_pointer_type (type),
1102 make_tree (type, copy));
1103 type = build_pointer_type (type);
1107 mode = TYPE_MODE (type);
1108 unsignedp = TREE_UNSIGNED (type);
1110 #ifdef PROMOTE_FUNCTION_ARGS
1111 mode = promote_mode (type, mode, &unsignedp, 1);
1112 #endif
1114 args[i].unsignedp = unsignedp;
1115 args[i].mode = mode;
1116 args[i].reg = FUNCTION_ARG (args_so_far, mode, type,
1117 argpos < n_named_args);
1118 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1119 if (args[i].reg)
1120 args[i].partial
1121 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, type,
1122 argpos < n_named_args);
1123 #endif
1125 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
1127 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1128 it means that we are to pass this arg in the register(s) designated
1129 by the PARALLEL, but also to pass it in the stack. */
1130 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1131 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1132 args[i].pass_on_stack = 1;
1134 /* If this is an addressable type, we must preallocate the stack
1135 since we must evaluate the object into its final location.
1137 If this is to be passed in both registers and the stack, it is simpler
1138 to preallocate. */
1139 if (TREE_ADDRESSABLE (type)
1140 || (args[i].pass_on_stack && args[i].reg != 0))
1141 must_preallocate = 1;
1143 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1144 we cannot consider this function call constant. */
1145 if (TREE_ADDRESSABLE (type))
1146 is_const = 0;
1148 /* Compute the stack-size of this argument. */
1149 if (args[i].reg == 0 || args[i].partial != 0
1150 || reg_parm_stack_space > 0
1151 || args[i].pass_on_stack)
1152 locate_and_pad_parm (mode, type,
1153 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1155 #else
1156 args[i].reg != 0,
1157 #endif
1158 fndecl, &args_size, &args[i].offset,
1159 &args[i].size);
1161 #ifndef ARGS_GROW_DOWNWARD
1162 args[i].slot_offset = args_size;
1163 #endif
1165 /* If a part of the arg was put into registers,
1166 don't include that part in the amount pushed. */
1167 if (reg_parm_stack_space == 0 && ! args[i].pass_on_stack)
1168 args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1169 / (PARM_BOUNDARY / BITS_PER_UNIT)
1170 * (PARM_BOUNDARY / BITS_PER_UNIT));
1172 /* Update ARGS_SIZE, the total stack space for args so far. */
1174 args_size.constant += args[i].size.constant;
1175 if (args[i].size.var)
1177 ADD_PARM_SIZE (args_size, args[i].size.var);
1180 /* Since the slot offset points to the bottom of the slot,
1181 we must record it after incrementing if the args grow down. */
1182 #ifdef ARGS_GROW_DOWNWARD
1183 args[i].slot_offset = args_size;
1185 args[i].slot_offset.constant = -args_size.constant;
1186 if (args_size.var)
1188 SUB_PARM_SIZE (args[i].slot_offset, args_size.var);
1190 #endif
1192 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1193 have been used, etc. */
1195 FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type,
1196 argpos < n_named_args);
1199 #ifdef FINAL_REG_PARM_STACK_SPACE
1200 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
1201 args_size.var);
1202 #endif
1204 /* Compute the actual size of the argument block required. The variable
1205 and constant sizes must be combined, the size may have to be rounded,
1206 and there may be a minimum required size. */
1208 original_args_size = args_size;
1209 if (args_size.var)
1211 /* If this function requires a variable-sized argument list, don't try to
1212 make a cse'able block for this call. We may be able to do this
1213 eventually, but it is too complicated to keep track of what insns go
1214 in the cse'able block and which don't. */
1216 is_const = 0;
1217 must_preallocate = 1;
1219 args_size.var = ARGS_SIZE_TREE (args_size);
1220 args_size.constant = 0;
1222 #ifdef STACK_BOUNDARY
1223 if (STACK_BOUNDARY != BITS_PER_UNIT)
1224 args_size.var = round_up (args_size.var, STACK_BYTES);
1225 #endif
1227 if (reg_parm_stack_space > 0)
1229 args_size.var
1230 = size_binop (MAX_EXPR, args_size.var,
1231 size_int (reg_parm_stack_space));
1233 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1234 /* The area corresponding to register parameters is not to count in
1235 the size of the block we need. So make the adjustment. */
1236 args_size.var
1237 = size_binop (MINUS_EXPR, args_size.var,
1238 size_int (reg_parm_stack_space));
1239 #endif
1242 else
1244 #ifdef STACK_BOUNDARY
1245 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
1246 / STACK_BYTES) * STACK_BYTES);
1247 #endif
1249 args_size.constant = MAX (args_size.constant,
1250 reg_parm_stack_space);
1252 #ifdef MAYBE_REG_PARM_STACK_SPACE
1253 if (reg_parm_stack_space == 0)
1254 args_size.constant = 0;
1255 #endif
1257 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1258 args_size.constant -= reg_parm_stack_space;
1259 #endif
1262 /* See if we have or want to preallocate stack space.
1264 If we would have to push a partially-in-regs parm
1265 before other stack parms, preallocate stack space instead.
1267 If the size of some parm is not a multiple of the required stack
1268 alignment, we must preallocate.
1270 If the total size of arguments that would otherwise create a copy in
1271 a temporary (such as a CALL) is more than half the total argument list
1272 size, preallocation is faster.
1274 Another reason to preallocate is if we have a machine (like the m88k)
1275 where stack alignment is required to be maintained between every
1276 pair of insns, not just when the call is made. However, we assume here
1277 that such machines either do not have push insns (and hence preallocation
1278 would occur anyway) or the problem is taken care of with
1279 PUSH_ROUNDING. */
1281 if (! must_preallocate)
1283 int partial_seen = 0;
1284 int copy_to_evaluate_size = 0;
1286 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1288 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1289 partial_seen = 1;
1290 else if (partial_seen && args[i].reg == 0)
1291 must_preallocate = 1;
1293 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1294 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1295 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1296 || TREE_CODE (args[i].tree_value) == COND_EXPR
1297 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1298 copy_to_evaluate_size
1299 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1302 if (copy_to_evaluate_size * 2 >= args_size.constant
1303 && args_size.constant > 0)
1304 must_preallocate = 1;
1307 /* If the structure value address will reference the stack pointer, we must
1308 stabilize it. We don't need to do this if we know that we are not going
1309 to adjust the stack pointer in processing this call. */
1311 if (structure_value_addr
1312 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
1313 || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr))
1314 && (args_size.var
1315 #ifndef ACCUMULATE_OUTGOING_ARGS
1316 || args_size.constant
1317 #endif
1319 structure_value_addr = copy_to_reg (structure_value_addr);
1321 /* If this function call is cse'able, precompute all the parameters.
1322 Note that if the parameter is constructed into a temporary, this will
1323 cause an additional copy because the parameter will be constructed
1324 into a temporary location and then copied into the outgoing arguments.
1325 If a parameter contains a call to alloca and this function uses the
1326 stack, precompute the parameter. */
1328 /* If we preallocated the stack space, and some arguments must be passed
1329 on the stack, then we must precompute any parameter which contains a
1330 function call which will store arguments on the stack.
1331 Otherwise, evaluating the parameter may clobber previous parameters
1332 which have already been stored into the stack. */
1334 for (i = 0; i < num_actuals; i++)
1335 if (is_const
1336 || ((args_size.var != 0 || args_size.constant != 0)
1337 && calls_function (args[i].tree_value, 1))
1338 || (must_preallocate && (args_size.var != 0 || args_size.constant != 0)
1339 && calls_function (args[i].tree_value, 0)))
1341 /* If this is an addressable type, we cannot pre-evaluate it. */
1342 if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))
1343 abort ();
1345 push_temp_slots ();
1347 args[i].initial_value = args[i].value
1348 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1350 preserve_temp_slots (args[i].value);
1351 pop_temp_slots ();
1353 /* ANSI doesn't require a sequence point here,
1354 but PCC has one, so this will avoid some problems. */
1355 emit_queue ();
1357 args[i].initial_value = args[i].value
1358 = protect_from_queue (args[i].initial_value, 0);
1360 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != args[i].mode)
1361 args[i].value
1362 = convert_modes (args[i].mode,
1363 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1364 args[i].value, args[i].unsignedp);
1367 /* Now we are about to start emitting insns that can be deleted
1368 if a libcall is deleted. */
1369 if (is_const)
1370 start_sequence ();
1372 /* If we have no actual push instructions, or shouldn't use them,
1373 make space for all args right now. */
1375 if (args_size.var != 0)
1377 if (old_stack_level == 0)
1379 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1380 old_pending_adj = pending_stack_adjust;
1381 pending_stack_adjust = 0;
1382 #ifdef ACCUMULATE_OUTGOING_ARGS
1383 /* stack_arg_under_construction says whether a stack arg is
1384 being constructed at the old stack level. Pushing the stack
1385 gets a clean outgoing argument block. */
1386 old_stack_arg_under_construction = stack_arg_under_construction;
1387 stack_arg_under_construction = 0;
1388 #endif
1390 argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
1392 else
1394 /* Note that we must go through the motions of allocating an argument
1395 block even if the size is zero because we may be storing args
1396 in the area reserved for register arguments, which may be part of
1397 the stack frame. */
1399 int needed = args_size.constant;
1401 /* Store the maximum argument space used. It will be pushed by
1402 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
1403 checking). */
1405 if (needed > current_function_outgoing_args_size)
1406 current_function_outgoing_args_size = needed;
1408 if (must_preallocate)
1410 #ifdef ACCUMULATE_OUTGOING_ARGS
1411 /* Since the stack pointer will never be pushed, it is possible for
1412 the evaluation of a parm to clobber something we have already
1413 written to the stack. Since most function calls on RISC machines
1414 do not use the stack, this is uncommon, but must work correctly.
1416 Therefore, we save any area of the stack that was already written
1417 and that we are using. Here we set up to do this by making a new
1418 stack usage map from the old one. The actual save will be done
1419 by store_one_arg.
1421 Another approach might be to try to reorder the argument
1422 evaluations to avoid this conflicting stack usage. */
1424 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1425 /* Since we will be writing into the entire argument area, the
1426 map must be allocated for its entire size, not just the part that
1427 is the responsibility of the caller. */
1428 needed += reg_parm_stack_space;
1429 #endif
1431 #ifdef ARGS_GROW_DOWNWARD
1432 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1433 needed + 1);
1434 #else
1435 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1436 needed);
1437 #endif
1438 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
1440 if (initial_highest_arg_in_use)
1441 bcopy (initial_stack_usage_map, stack_usage_map,
1442 initial_highest_arg_in_use);
1444 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
1445 bzero (&stack_usage_map[initial_highest_arg_in_use],
1446 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
1447 needed = 0;
1449 /* The address of the outgoing argument list must not be copied to a
1450 register here, because argblock would be left pointing to the
1451 wrong place after the call to allocate_dynamic_stack_space below.
1454 argblock = virtual_outgoing_args_rtx;
1456 #else /* not ACCUMULATE_OUTGOING_ARGS */
1457 if (inhibit_defer_pop == 0)
1459 /* Try to reuse some or all of the pending_stack_adjust
1460 to get this space. Maybe we can avoid any pushing. */
1461 if (needed > pending_stack_adjust)
1463 needed -= pending_stack_adjust;
1464 pending_stack_adjust = 0;
1466 else
1468 pending_stack_adjust -= needed;
1469 needed = 0;
1472 /* Special case this because overhead of `push_block' in this
1473 case is non-trivial. */
1474 if (needed == 0)
1475 argblock = virtual_outgoing_args_rtx;
1476 else
1477 argblock = push_block (GEN_INT (needed), 0, 0);
1479 /* We only really need to call `copy_to_reg' in the case where push
1480 insns are going to be used to pass ARGBLOCK to a function
1481 call in ARGS. In that case, the stack pointer changes value
1482 from the allocation point to the call point, and hence
1483 the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
1484 But might as well always do it. */
1485 argblock = copy_to_reg (argblock);
1486 #endif /* not ACCUMULATE_OUTGOING_ARGS */
1490 #ifdef ACCUMULATE_OUTGOING_ARGS
1491 /* The save/restore code in store_one_arg handles all cases except one:
1492 a constructor call (including a C function returning a BLKmode struct)
1493 to initialize an argument. */
1494 if (stack_arg_under_construction)
1496 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1497 rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
1498 #else
1499 rtx push_size = GEN_INT (args_size.constant);
1500 #endif
1501 if (old_stack_level == 0)
1503 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1504 old_pending_adj = pending_stack_adjust;
1505 pending_stack_adjust = 0;
1506 /* stack_arg_under_construction says whether a stack arg is
1507 being constructed at the old stack level. Pushing the stack
1508 gets a clean outgoing argument block. */
1509 old_stack_arg_under_construction = stack_arg_under_construction;
1510 stack_arg_under_construction = 0;
1511 /* Make a new map for the new argument list. */
1512 stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
1513 bzero (stack_usage_map, highest_outgoing_arg_in_use);
1514 highest_outgoing_arg_in_use = 0;
1516 allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
1518 /* If argument evaluation might modify the stack pointer, copy the
1519 address of the argument list to a register. */
1520 for (i = 0; i < num_actuals; i++)
1521 if (args[i].pass_on_stack)
1523 argblock = copy_addr_to_reg (argblock);
1524 break;
1526 #endif
1529 /* If we preallocated stack space, compute the address of each argument.
1530 We need not ensure it is a valid memory address here; it will be
1531 validized when it is used. */
1532 if (argblock)
1534 rtx arg_reg = argblock;
1535 int arg_offset = 0;
1537 if (GET_CODE (argblock) == PLUS)
1538 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1540 for (i = 0; i < num_actuals; i++)
1542 rtx offset = ARGS_SIZE_RTX (args[i].offset);
1543 rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1544 rtx addr;
1546 /* Skip this parm if it will not be passed on the stack. */
1547 if (! args[i].pass_on_stack && args[i].reg != 0)
1548 continue;
1550 if (GET_CODE (offset) == CONST_INT)
1551 addr = plus_constant (arg_reg, INTVAL (offset));
1552 else
1553 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1555 addr = plus_constant (addr, arg_offset);
1556 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1557 MEM_IN_STRUCT_P (args[i].stack)
1558 = AGGREGATE_TYPE_P (TREE_TYPE (args[i].tree_value));
1560 if (GET_CODE (slot_offset) == CONST_INT)
1561 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1562 else
1563 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1565 addr = plus_constant (addr, arg_offset);
1566 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1570 #ifdef PUSH_ARGS_REVERSED
1571 #ifdef STACK_BOUNDARY
1572 /* If we push args individually in reverse order, perform stack alignment
1573 before the first push (the last arg). */
1574 if (argblock == 0)
1575 anti_adjust_stack (GEN_INT (args_size.constant
1576 - original_args_size.constant));
1577 #endif
1578 #endif
1580 /* Don't try to defer pops if preallocating, not even from the first arg,
1581 since ARGBLOCK probably refers to the SP. */
1582 if (argblock)
1583 NO_DEFER_POP;
1585 /* Get the function to call, in the form of RTL. */
1586 if (fndecl)
1588 /* If this is the first use of the function, see if we need to
1589 make an external definition for it. */
1590 if (! TREE_USED (fndecl))
1592 assemble_external (fndecl);
1593 TREE_USED (fndecl) = 1;
1596 /* Get a SYMBOL_REF rtx for the function address. */
1597 funexp = XEXP (DECL_RTL (fndecl), 0);
1599 else
1600 /* Generate an rtx (probably a pseudo-register) for the address. */
1602 push_temp_slots ();
1603 funexp = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1604 pop_temp_slots (); /* FUNEXP can't be BLKmode */
1606 /* Check the function is executable. */
1607 if (current_function_check_memory_usage)
1608 emit_library_call (chkr_check_exec_libfunc, 1,
1609 VOIDmode, 1,
1610 funexp, ptr_mode);
1611 emit_queue ();
1614 /* Figure out the register where the value, if any, will come back. */
1615 valreg = 0;
1616 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
1617 && ! structure_value_addr)
1619 if (pcc_struct_value)
1620 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
1621 fndecl);
1622 else
1623 valreg = hard_function_value (TREE_TYPE (exp), fndecl);
1626 /* Precompute all register parameters. It isn't safe to compute anything
1627 once we have started filling any specific hard regs. */
1628 reg_parm_seen = 0;
1629 for (i = 0; i < num_actuals; i++)
1630 if (args[i].reg != 0 && ! args[i].pass_on_stack)
1632 reg_parm_seen = 1;
1634 if (args[i].value == 0)
1636 push_temp_slots ();
1637 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
1638 VOIDmode, 0);
1639 preserve_temp_slots (args[i].value);
1640 pop_temp_slots ();
1642 /* ANSI doesn't require a sequence point here,
1643 but PCC has one, so this will avoid some problems. */
1644 emit_queue ();
1647 /* If we are to promote the function arg to a wider mode,
1648 do it now. */
1650 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
1651 args[i].value
1652 = convert_modes (args[i].mode,
1653 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1654 args[i].value, args[i].unsignedp);
1656 /* If the value is expensive, and we are inside an appropriately
1657 short loop, put the value into a pseudo and then put the pseudo
1658 into the hard reg.
1660 For small register classes, also do this if this call uses
1661 register parameters. This is to avoid reload conflicts while
1662 loading the parameters registers. */
1664 if ((! (GET_CODE (args[i].value) == REG
1665 || (GET_CODE (args[i].value) == SUBREG
1666 && GET_CODE (SUBREG_REG (args[i].value)) == REG)))
1667 && args[i].mode != BLKmode
1668 && rtx_cost (args[i].value, SET) > 2
1669 && ((SMALL_REGISTER_CLASSES && reg_parm_seen)
1670 || preserve_subexpressions_p ()))
1671 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
1674 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1676 /* The argument list is the property of the called routine and it
1677 may clobber it. If the fixed area has been used for previous
1678 parameters, we must save and restore it.
1680 Here we compute the boundary of the that needs to be saved, if any. */
1682 #ifdef ARGS_GROW_DOWNWARD
1683 for (i = 0; i < reg_parm_stack_space + 1; i++)
1684 #else
1685 for (i = 0; i < reg_parm_stack_space; i++)
1686 #endif
1688 if (i >= highest_outgoing_arg_in_use
1689 || stack_usage_map[i] == 0)
1690 continue;
1692 if (low_to_save == -1)
1693 low_to_save = i;
1695 high_to_save = i;
1698 if (low_to_save >= 0)
1700 int num_to_save = high_to_save - low_to_save + 1;
1701 enum machine_mode save_mode
1702 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
1703 rtx stack_area;
1705 /* If we don't have the required alignment, must do this in BLKmode. */
1706 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
1707 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
1708 save_mode = BLKmode;
1710 stack_area = gen_rtx_MEM (save_mode,
1711 memory_address (save_mode,
1713 #ifdef ARGS_GROW_DOWNWARD
1714 plus_constant (argblock,
1715 - high_to_save)
1716 #else
1717 plus_constant (argblock,
1718 low_to_save)
1719 #endif
1721 if (save_mode == BLKmode)
1723 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
1724 MEM_IN_STRUCT_P (save_area) = 0;
1725 emit_block_move (validize_mem (save_area), stack_area,
1726 GEN_INT (num_to_save),
1727 PARM_BOUNDARY / BITS_PER_UNIT);
1729 else
1731 save_area = gen_reg_rtx (save_mode);
1732 emit_move_insn (save_area, stack_area);
1735 #endif
1738 /* Now store (and compute if necessary) all non-register parms.
1739 These come before register parms, since they can require block-moves,
1740 which could clobber the registers used for register parms.
1741 Parms which have partial registers are not stored here,
1742 but we do preallocate space here if they want that. */
1744 for (i = 0; i < num_actuals; i++)
1745 if (args[i].reg == 0 || args[i].pass_on_stack)
1746 store_one_arg (&args[i], argblock, may_be_alloca,
1747 args_size.var != 0, fndecl, reg_parm_stack_space);
1749 /* If we have a parm that is passed in registers but not in memory
1750 and whose alignment does not permit a direct copy into registers,
1751 make a group of pseudos that correspond to each register that we
1752 will later fill. */
1754 if (STRICT_ALIGNMENT)
1755 for (i = 0; i < num_actuals; i++)
1756 if (args[i].reg != 0 && ! args[i].pass_on_stack
1757 && args[i].mode == BLKmode
1758 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
1759 < MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
1761 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1762 int big_endian_correction = 0;
1764 args[i].n_aligned_regs
1765 = args[i].partial ? args[i].partial
1766 : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
1768 args[i].aligned_regs = (rtx *) alloca (sizeof (rtx)
1769 * args[i].n_aligned_regs);
1771 /* Structures smaller than a word are aligned to the least
1772 significant byte (to the right). On a BYTES_BIG_ENDIAN machine,
1773 this means we must skip the empty high order bytes when
1774 calculating the bit offset. */
1775 if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD)
1776 big_endian_correction = (BITS_PER_WORD - (bytes * BITS_PER_UNIT));
1778 for (j = 0; j < args[i].n_aligned_regs; j++)
1780 rtx reg = gen_reg_rtx (word_mode);
1781 rtx word = operand_subword_force (args[i].value, j, BLKmode);
1782 int bitsize = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
1783 int bitpos;
1785 args[i].aligned_regs[j] = reg;
1787 /* Clobber REG and move each partword into it. Ensure we don't
1788 go past the end of the structure. Note that the loop below
1789 works because we've already verified that padding
1790 and endianness are compatible.
1792 We use to emit a clobber here but that doesn't let later
1793 passes optimize the instructions we emit. By storing 0 into
1794 the register later passes know the first AND to zero out the
1795 bitfield being set in the register is unnecessary. The store
1796 of 0 will be deleted as will at least the first AND. */
1798 emit_move_insn (reg, const0_rtx);
1800 for (bitpos = 0;
1801 bitpos < BITS_PER_WORD && bytes > 0;
1802 bitpos += bitsize, bytes -= bitsize / BITS_PER_UNIT)
1804 int xbitpos = bitpos + big_endian_correction;
1806 store_bit_field (reg, bitsize, xbitpos, word_mode,
1807 extract_bit_field (word, bitsize, bitpos, 1,
1808 NULL_RTX, word_mode,
1809 word_mode,
1810 bitsize / BITS_PER_UNIT,
1811 BITS_PER_WORD),
1812 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
1817 /* Now store any partially-in-registers parm.
1818 This is the last place a block-move can happen. */
1819 if (reg_parm_seen)
1820 for (i = 0; i < num_actuals; i++)
1821 if (args[i].partial != 0 && ! args[i].pass_on_stack)
1822 store_one_arg (&args[i], argblock, may_be_alloca,
1823 args_size.var != 0, fndecl, reg_parm_stack_space);
1825 #ifndef PUSH_ARGS_REVERSED
1826 #ifdef STACK_BOUNDARY
1827 /* If we pushed args in forward order, perform stack alignment
1828 after pushing the last arg. */
1829 if (argblock == 0)
1830 anti_adjust_stack (GEN_INT (args_size.constant
1831 - original_args_size.constant));
1832 #endif
1833 #endif
1835 /* If register arguments require space on the stack and stack space
1836 was not preallocated, allocate stack space here for arguments
1837 passed in registers. */
1838 #if ! defined(ACCUMULATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
1839 if (must_preallocate == 0 && reg_parm_stack_space > 0)
1840 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
1841 #endif
1843 /* Pass the function the address in which to return a structure value. */
1844 if (structure_value_addr && ! structure_value_addr_parm)
1846 emit_move_insn (struct_value_rtx,
1847 force_reg (Pmode,
1848 force_operand (structure_value_addr,
1849 NULL_RTX)));
1851 /* Mark the memory for the aggregate as write-only. */
1852 if (current_function_check_memory_usage)
1853 emit_library_call (chkr_set_right_libfunc, 1,
1854 VOIDmode, 3,
1855 structure_value_addr, ptr_mode,
1856 GEN_INT (struct_value_size), TYPE_MODE (sizetype),
1857 GEN_INT (MEMORY_USE_WO),
1858 TYPE_MODE (integer_type_node));
1860 if (GET_CODE (struct_value_rtx) == REG)
1861 use_reg (&call_fusage, struct_value_rtx);
1864 funexp = prepare_call_address (funexp, fndecl, &call_fusage, reg_parm_seen);
1866 /* Now do the register loads required for any wholly-register parms or any
1867 parms which are passed both on the stack and in a register. Their
1868 expressions were already evaluated.
1870 Mark all register-parms as living through the call, putting these USE
1871 insns in the CALL_INSN_FUNCTION_USAGE field. */
1873 for (i = 0; i < num_actuals; i++)
1875 rtx reg = args[i].reg;
1876 int partial = args[i].partial;
1877 int nregs;
1879 if (reg)
1881 /* Set to non-negative if must move a word at a time, even if just
1882 one word (e.g, partial == 1 && mode == DFmode). Set to -1 if
1883 we just use a normal move insn. This value can be zero if the
1884 argument is a zero size structure with no fields. */
1885 nregs = (partial ? partial
1886 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1887 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1888 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1889 : -1));
1891 /* Handle calls that pass values in multiple non-contiguous
1892 locations. The Irix 6 ABI has examples of this. */
1894 if (GET_CODE (reg) == PARALLEL)
1895 emit_group_load (reg, args[i].value);
1897 /* If simple case, just do move. If normal partial, store_one_arg
1898 has already loaded the register for us. In all other cases,
1899 load the register(s) from memory. */
1901 else if (nregs == -1)
1902 emit_move_insn (reg, args[i].value);
1904 /* If we have pre-computed the values to put in the registers in
1905 the case of non-aligned structures, copy them in now. */
1907 else if (args[i].n_aligned_regs != 0)
1908 for (j = 0; j < args[i].n_aligned_regs; j++)
1909 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
1910 args[i].aligned_regs[j]);
1912 else if (partial == 0 || args[i].pass_on_stack)
1913 move_block_to_reg (REGNO (reg),
1914 validize_mem (args[i].value), nregs,
1915 args[i].mode);
1917 /* Handle calls that pass values in multiple non-contiguous
1918 locations. The Irix 6 ABI has examples of this. */
1919 if (GET_CODE (reg) == PARALLEL)
1920 use_group_regs (&call_fusage, reg);
1921 else if (nregs == -1)
1922 use_reg (&call_fusage, reg);
1923 else
1924 use_regs (&call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1928 /* Perform postincrements before actually calling the function. */
1929 emit_queue ();
1931 /* All arguments and registers used for the call must be set up by now! */
1933 /* Generate the actual call instruction. */
1934 emit_call_1 (funexp, fndecl, funtype, args_size.constant, struct_value_size,
1935 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
1936 valreg, old_inhibit_defer_pop, call_fusage, is_const);
1938 /* If call is cse'able, make appropriate pair of reg-notes around it.
1939 Test valreg so we don't crash; may safely ignore `const'
1940 if return type is void. Disable for PARALLEL return values, because
1941 we have no way to move such values into a pseudo register. */
1942 if (is_const && valreg != 0 && GET_CODE (valreg) != PARALLEL)
1944 rtx note = 0;
1945 rtx temp = gen_reg_rtx (GET_MODE (valreg));
1946 rtx insns;
1948 /* Construct an "equal form" for the value which mentions all the
1949 arguments in order as well as the function name. */
1950 #ifdef PUSH_ARGS_REVERSED
1951 for (i = 0; i < num_actuals; i++)
1952 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
1953 #else
1954 for (i = num_actuals - 1; i >= 0; i--)
1955 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
1956 #endif
1957 note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
1959 insns = get_insns ();
1960 end_sequence ();
1962 emit_libcall_block (insns, temp, valreg, note);
1964 valreg = temp;
1966 else if (is_const)
1968 /* Otherwise, just write out the sequence without a note. */
1969 rtx insns = get_insns ();
1971 end_sequence ();
1972 emit_insns (insns);
1975 /* For calls to `setjmp', etc., inform flow.c it should complain
1976 if nonvolatile values are live. */
1978 if (returns_twice)
1980 emit_note (name, NOTE_INSN_SETJMP);
1981 current_function_calls_setjmp = 1;
1984 if (is_longjmp)
1985 current_function_calls_longjmp = 1;
1987 /* Notice functions that cannot return.
1988 If optimizing, insns emitted below will be dead.
1989 If not optimizing, they will exist, which is useful
1990 if the user uses the `return' command in the debugger. */
1992 if (is_volatile || is_longjmp)
1993 emit_barrier ();
1995 /* If value type not void, return an rtx for the value. */
1997 /* If there are cleanups to be called, don't use a hard reg as target.
1998 We need to double check this and see if it matters anymore. */
1999 if (any_pending_cleanups (1)
2000 && target && REG_P (target)
2001 && REGNO (target) < FIRST_PSEUDO_REGISTER)
2002 target = 0;
2004 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
2005 || ignore)
2007 target = const0_rtx;
2009 else if (structure_value_addr)
2011 if (target == 0 || GET_CODE (target) != MEM)
2013 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2014 memory_address (TYPE_MODE (TREE_TYPE (exp)),
2015 structure_value_addr));
2016 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2019 else if (pcc_struct_value)
2021 if (target == 0)
2023 /* We used leave the value in the location that it is
2024 returned in, but that causes problems if it is used more
2025 than once in one expression. Rather than trying to track
2026 when a copy is required, we always copy when TARGET is
2027 not specified. This calling sequence is only used on
2028 a few machines and TARGET is usually nonzero. */
2029 if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2031 target = assign_stack_temp (BLKmode,
2032 int_size_in_bytes (TREE_TYPE (exp)),
2035 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2037 /* Save this temp slot around the pop below. */
2038 preserve_temp_slots (target);
2040 else
2041 target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
2044 if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
2045 emit_move_insn (target, gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2046 copy_to_reg (valreg)));
2047 else
2048 emit_block_move (target, gen_rtx_MEM (BLKmode, copy_to_reg (valreg)),
2049 expr_size (exp),
2050 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
2052 /* Handle calls that return values in multiple non-contiguous locations.
2053 The Irix 6 ABI has examples of this. */
2054 else if (GET_CODE (valreg) == PARALLEL)
2056 if (target == 0)
2058 int bytes = int_size_in_bytes (TREE_TYPE (exp));
2059 target = assign_stack_temp (TYPE_MODE (TREE_TYPE (exp)), bytes, 0);
2060 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2061 preserve_temp_slots (target);
2064 if (! rtx_equal_p (target, valreg))
2065 emit_group_store (target, valreg);
2067 else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2068 && GET_MODE (target) == GET_MODE (valreg))
2069 /* TARGET and VALREG cannot be equal at this point because the latter
2070 would not have REG_FUNCTION_VALUE_P true, while the former would if
2071 it were referring to the same register.
2073 If they refer to the same register, this move will be a no-op, except
2074 when function inlining is being done. */
2075 emit_move_insn (target, valreg);
2076 else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2078 /* Some machines (the PA for example) want to return all small
2079 structures in registers regardless of the structure's alignment.
2081 Deal with them explicitly by copying from the return registers
2082 into the target MEM locations. */
2083 int bytes = int_size_in_bytes (TREE_TYPE (exp));
2084 int n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2085 int i;
2086 enum machine_mode tmpmode;
2087 rtx src, dst;
2088 int bitsize = MIN (TYPE_ALIGN (TREE_TYPE (exp)), BITS_PER_WORD);
2089 int bitpos, xbitpos, big_endian_correction = 0;
2091 if (target == 0)
2093 target = assign_stack_temp (BLKmode, bytes, 0);
2094 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2095 preserve_temp_slots (target);
2098 /* This code assumes valreg is at least a full word. If it isn't,
2099 copy it into a new pseudo which is a full word. */
2100 if (GET_MODE (valreg) != BLKmode
2101 && GET_MODE_SIZE (GET_MODE (valreg)) < UNITS_PER_WORD)
2102 valreg = convert_to_mode (word_mode, valreg,
2103 TREE_UNSIGNED (TREE_TYPE (exp)));
2105 /* Structures whose size is not a multiple of a word are aligned
2106 to the least significant byte (to the right). On a BYTES_BIG_ENDIAN
2107 machine, this means we must skip the empty high order bytes when
2108 calculating the bit offset. */
2109 if (BYTES_BIG_ENDIAN && bytes % UNITS_PER_WORD)
2110 big_endian_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2111 * BITS_PER_UNIT));
2113 /* Copy the structure BITSIZE bites at a time.
2115 We could probably emit more efficient code for machines
2116 which do not use strict alignment, but it doesn't seem
2117 worth the effort at the current time. */
2118 for (bitpos = 0, xbitpos = big_endian_correction;
2119 bitpos < bytes * BITS_PER_UNIT;
2120 bitpos += bitsize, xbitpos += bitsize)
2123 /* We need a new source operand each time xbitpos is on a
2124 word boundary and when xbitpos == big_endian_correction
2125 (the first time through). */
2126 if (xbitpos % BITS_PER_WORD == 0
2127 || xbitpos == big_endian_correction)
2128 src = operand_subword_force (valreg,
2129 xbitpos / BITS_PER_WORD,
2130 BLKmode);
2132 /* We need a new destination operand each time bitpos is on
2133 a word boundary. */
2134 if (bitpos % BITS_PER_WORD == 0)
2135 dst = operand_subword (target, bitpos / BITS_PER_WORD, 1, BLKmode);
2137 /* Use xbitpos for the source extraction (right justified) and
2138 xbitpos for the destination store (left justified). */
2139 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, word_mode,
2140 extract_bit_field (src, bitsize,
2141 xbitpos % BITS_PER_WORD, 1,
2142 NULL_RTX, word_mode,
2143 word_mode,
2144 bitsize / BITS_PER_UNIT,
2145 BITS_PER_WORD),
2146 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
2149 else
2150 target = copy_to_reg (valreg);
2152 #ifdef PROMOTE_FUNCTION_RETURN
2153 /* If we promoted this return value, make the proper SUBREG. TARGET
2154 might be const0_rtx here, so be careful. */
2155 if (GET_CODE (target) == REG
2156 && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
2157 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
2159 tree type = TREE_TYPE (exp);
2160 int unsignedp = TREE_UNSIGNED (type);
2162 /* If we don't promote as expected, something is wrong. */
2163 if (GET_MODE (target)
2164 != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
2165 abort ();
2167 target = gen_rtx_SUBREG (TYPE_MODE (type), target, 0);
2168 SUBREG_PROMOTED_VAR_P (target) = 1;
2169 SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
2171 #endif
2173 /* If size of args is variable or this was a constructor call for a stack
2174 argument, restore saved stack-pointer value. */
2176 if (old_stack_level)
2178 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
2179 pending_stack_adjust = old_pending_adj;
2180 #ifdef ACCUMULATE_OUTGOING_ARGS
2181 stack_arg_under_construction = old_stack_arg_under_construction;
2182 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2183 stack_usage_map = initial_stack_usage_map;
2184 #endif
2186 #ifdef ACCUMULATE_OUTGOING_ARGS
2187 else
2189 #ifdef REG_PARM_STACK_SPACE
2190 if (save_area)
2192 enum machine_mode save_mode = GET_MODE (save_area);
2193 rtx stack_area
2194 = gen_rtx_MEM (save_mode,
2195 memory_address (save_mode,
2196 #ifdef ARGS_GROW_DOWNWARD
2197 plus_constant (argblock,
2198 - high_to_save)
2199 #else
2200 plus_constant (argblock,
2201 low_to_save)
2202 #endif
2205 if (save_mode != BLKmode)
2206 emit_move_insn (stack_area, save_area);
2207 else
2208 emit_block_move (stack_area, validize_mem (save_area),
2209 GEN_INT (high_to_save - low_to_save + 1),
2210 PARM_BOUNDARY / BITS_PER_UNIT);
2212 #endif
2214 /* If we saved any argument areas, restore them. */
2215 for (i = 0; i < num_actuals; i++)
2216 if (args[i].save_area)
2218 enum machine_mode save_mode = GET_MODE (args[i].save_area);
2219 rtx stack_area
2220 = gen_rtx_MEM (save_mode,
2221 memory_address (save_mode,
2222 XEXP (args[i].stack_slot, 0)));
2224 if (save_mode != BLKmode)
2225 emit_move_insn (stack_area, args[i].save_area);
2226 else
2227 emit_block_move (stack_area, validize_mem (args[i].save_area),
2228 GEN_INT (args[i].size.constant),
2229 PARM_BOUNDARY / BITS_PER_UNIT);
2232 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2233 stack_usage_map = initial_stack_usage_map;
2235 #endif
2237 /* If this was alloca, record the new stack level for nonlocal gotos.
2238 Check for the handler slots since we might not have a save area
2239 for non-local gotos. */
2241 if (may_be_alloca && nonlocal_goto_handler_slot != 0)
2242 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
2244 pop_temp_slots ();
2246 return target;
2249 /* Output a library call to function FUN (a SYMBOL_REF rtx)
2250 (emitting the queue unless NO_QUEUE is nonzero),
2251 for a value of mode OUTMODE,
2252 with NARGS different arguments, passed as alternating rtx values
2253 and machine_modes to convert them to.
2254 The rtx values should have been passed through protect_from_queue already.
2256 NO_QUEUE will be true if and only if the library call is a `const' call
2257 which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent
2258 to the variable is_const in expand_call.
2260 NO_QUEUE must be true for const calls, because if it isn't, then
2261 any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes,
2262 and will be lost if the libcall sequence is optimized away.
2264 NO_QUEUE must be false for non-const calls, because if it isn't, the
2265 call insn will have its CONST_CALL_P bit set, and it will be incorrectly
2266 optimized. For instance, the instruction scheduler may incorrectly
2267 move memory references across the non-const call. */
2269 void
2270 emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
2271 int nargs, ...))
2273 #ifndef ANSI_PROTOTYPES
2274 rtx orgfun;
2275 int no_queue;
2276 enum machine_mode outmode;
2277 int nargs;
2278 #endif
2279 va_list p;
2280 /* Total size in bytes of all the stack-parms scanned so far. */
2281 struct args_size args_size;
2282 /* Size of arguments before any adjustments (such as rounding). */
2283 struct args_size original_args_size;
2284 register int argnum;
2285 rtx fun;
2286 int inc;
2287 int count;
2288 rtx argblock = 0;
2289 CUMULATIVE_ARGS args_so_far;
2290 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2291 struct args_size offset; struct args_size size; rtx save_area; };
2292 struct arg *argvec;
2293 int old_inhibit_defer_pop = inhibit_defer_pop;
2294 rtx call_fusage = 0;
2295 /* Size of the stack reserved for parameter registers. */
2296 int reg_parm_stack_space = 0;
2297 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2298 /* Define the boundary of the register parm stack space that needs to be
2299 save, if any. */
2300 int low_to_save = -1, high_to_save;
2301 rtx save_area = 0; /* Place that it is saved */
2302 #endif
2304 #ifdef ACCUMULATE_OUTGOING_ARGS
2305 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2306 char *initial_stack_usage_map = stack_usage_map;
2307 int needed;
2308 #endif
2310 #ifdef REG_PARM_STACK_SPACE
2311 #ifdef MAYBE_REG_PARM_STACK_SPACE
2312 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2313 #else
2314 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
2315 #endif
2316 #endif
2318 VA_START (p, nargs);
2320 #ifndef ANSI_PROTOTYPES
2321 orgfun = va_arg (p, rtx);
2322 no_queue = va_arg (p, int);
2323 outmode = va_arg (p, enum machine_mode);
2324 nargs = va_arg (p, int);
2325 #endif
2327 fun = orgfun;
2329 /* Copy all the libcall-arguments out of the varargs data
2330 and into a vector ARGVEC.
2332 Compute how to pass each argument. We only support a very small subset
2333 of the full argument passing conventions to limit complexity here since
2334 library functions shouldn't have many args. */
2336 argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
2337 bzero ((char *) argvec, nargs * sizeof (struct arg));
2340 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
2342 args_size.constant = 0;
2343 args_size.var = 0;
2345 push_temp_slots ();
2347 for (count = 0; count < nargs; count++)
2349 rtx val = va_arg (p, rtx);
2350 enum machine_mode mode = va_arg (p, enum machine_mode);
2352 /* We cannot convert the arg value to the mode the library wants here;
2353 must do it earlier where we know the signedness of the arg. */
2354 if (mode == BLKmode
2355 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2356 abort ();
2358 /* On some machines, there's no way to pass a float to a library fcn.
2359 Pass it as a double instead. */
2360 #ifdef LIBGCC_NEEDS_DOUBLE
2361 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2362 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
2363 #endif
2365 /* There's no need to call protect_from_queue, because
2366 either emit_move_insn or emit_push_insn will do that. */
2368 /* Make sure it is a reasonable operand for a move or push insn. */
2369 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2370 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2371 val = force_operand (val, NULL_RTX);
2373 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2374 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2376 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2377 be viewed as just an efficiency improvement. */
2378 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2379 emit_move_insn (slot, val);
2380 val = force_operand (XEXP (slot, 0), NULL_RTX);
2381 mode = Pmode;
2383 #endif
2385 argvec[count].value = val;
2386 argvec[count].mode = mode;
2388 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2389 if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
2390 abort ();
2391 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2392 argvec[count].partial
2393 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2394 #else
2395 argvec[count].partial = 0;
2396 #endif
2398 locate_and_pad_parm (mode, NULL_TREE,
2399 argvec[count].reg && argvec[count].partial == 0,
2400 NULL_TREE, &args_size, &argvec[count].offset,
2401 &argvec[count].size);
2403 if (argvec[count].size.var)
2404 abort ();
2406 if (reg_parm_stack_space == 0 && argvec[count].partial)
2407 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2409 if (argvec[count].reg == 0 || argvec[count].partial != 0
2410 || reg_parm_stack_space > 0)
2411 args_size.constant += argvec[count].size.constant;
2413 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
2415 va_end (p);
2417 #ifdef FINAL_REG_PARM_STACK_SPACE
2418 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2419 args_size.var);
2420 #endif
2422 /* If this machine requires an external definition for library
2423 functions, write one out. */
2424 assemble_external_libcall (fun);
2426 original_args_size = args_size;
2427 #ifdef STACK_BOUNDARY
2428 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2429 / STACK_BYTES) * STACK_BYTES);
2430 #endif
2432 args_size.constant = MAX (args_size.constant,
2433 reg_parm_stack_space);
2435 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2436 args_size.constant -= reg_parm_stack_space;
2437 #endif
2439 if (args_size.constant > current_function_outgoing_args_size)
2440 current_function_outgoing_args_size = args_size.constant;
2442 #ifdef ACCUMULATE_OUTGOING_ARGS
2443 /* Since the stack pointer will never be pushed, it is possible for
2444 the evaluation of a parm to clobber something we have already
2445 written to the stack. Since most function calls on RISC machines
2446 do not use the stack, this is uncommon, but must work correctly.
2448 Therefore, we save any area of the stack that was already written
2449 and that we are using. Here we set up to do this by making a new
2450 stack usage map from the old one.
2452 Another approach might be to try to reorder the argument
2453 evaluations to avoid this conflicting stack usage. */
2455 needed = args_size.constant;
2457 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2458 /* Since we will be writing into the entire argument area, the
2459 map must be allocated for its entire size, not just the part that
2460 is the responsibility of the caller. */
2461 needed += reg_parm_stack_space;
2462 #endif
2464 #ifdef ARGS_GROW_DOWNWARD
2465 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2466 needed + 1);
2467 #else
2468 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2469 needed);
2470 #endif
2471 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
2473 if (initial_highest_arg_in_use)
2474 bcopy (initial_stack_usage_map, stack_usage_map,
2475 initial_highest_arg_in_use);
2477 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2478 bzero (&stack_usage_map[initial_highest_arg_in_use],
2479 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
2480 needed = 0;
2482 /* The address of the outgoing argument list must not be copied to a
2483 register here, because argblock would be left pointing to the
2484 wrong place after the call to allocate_dynamic_stack_space below.
2487 argblock = virtual_outgoing_args_rtx;
2488 #else /* not ACCUMULATE_OUTGOING_ARGS */
2489 #ifndef PUSH_ROUNDING
2490 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2491 #endif
2492 #endif
2494 #ifdef PUSH_ARGS_REVERSED
2495 #ifdef STACK_BOUNDARY
2496 /* If we push args individually in reverse order, perform stack alignment
2497 before the first push (the last arg). */
2498 if (argblock == 0)
2499 anti_adjust_stack (GEN_INT (args_size.constant
2500 - original_args_size.constant));
2501 #endif
2502 #endif
2504 #ifdef PUSH_ARGS_REVERSED
2505 inc = -1;
2506 argnum = nargs - 1;
2507 #else
2508 inc = 1;
2509 argnum = 0;
2510 #endif
2512 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2513 /* The argument list is the property of the called routine and it
2514 may clobber it. If the fixed area has been used for previous
2515 parameters, we must save and restore it.
2517 Here we compute the boundary of the that needs to be saved, if any. */
2519 #ifdef ARGS_GROW_DOWNWARD
2520 for (count = 0; count < reg_parm_stack_space + 1; count++)
2521 #else
2522 for (count = 0; count < reg_parm_stack_space; count++)
2523 #endif
2525 if (count >= highest_outgoing_arg_in_use
2526 || stack_usage_map[count] == 0)
2527 continue;
2529 if (low_to_save == -1)
2530 low_to_save = count;
2532 high_to_save = count;
2535 if (low_to_save >= 0)
2537 int num_to_save = high_to_save - low_to_save + 1;
2538 enum machine_mode save_mode
2539 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
2540 rtx stack_area;
2542 /* If we don't have the required alignment, must do this in BLKmode. */
2543 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
2544 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
2545 save_mode = BLKmode;
2547 stack_area = gen_rtx_MEM (save_mode,
2548 memory_address (save_mode,
2550 #ifdef ARGS_GROW_DOWNWARD
2551 plus_constant (argblock,
2552 - high_to_save)
2553 #else
2554 plus_constant (argblock,
2555 low_to_save)
2556 #endif
2558 if (save_mode == BLKmode)
2560 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
2561 MEM_IN_STRUCT_P (save_area) = 0;
2562 emit_block_move (validize_mem (save_area), stack_area,
2563 GEN_INT (num_to_save),
2564 PARM_BOUNDARY / BITS_PER_UNIT);
2566 else
2568 save_area = gen_reg_rtx (save_mode);
2569 emit_move_insn (save_area, stack_area);
2572 #endif
2574 /* Push the args that need to be pushed. */
2576 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
2577 are to be pushed. */
2578 for (count = 0; count < nargs; count++, argnum += inc)
2580 register enum machine_mode mode = argvec[argnum].mode;
2581 register rtx val = argvec[argnum].value;
2582 rtx reg = argvec[argnum].reg;
2583 int partial = argvec[argnum].partial;
2584 int lower_bound, upper_bound, i;
2586 if (! (reg != 0 && partial == 0))
2588 #ifdef ACCUMULATE_OUTGOING_ARGS
2589 /* If this is being stored into a pre-allocated, fixed-size, stack
2590 area, save any previous data at that location. */
2592 #ifdef ARGS_GROW_DOWNWARD
2593 /* stack_slot is negative, but we want to index stack_usage_map
2594 with positive values. */
2595 upper_bound = -argvec[argnum].offset.constant + 1;
2596 lower_bound = upper_bound - argvec[argnum].size.constant;
2597 #else
2598 lower_bound = argvec[argnum].offset.constant;
2599 upper_bound = lower_bound + argvec[argnum].size.constant;
2600 #endif
2602 for (i = lower_bound; i < upper_bound; i++)
2603 if (stack_usage_map[i]
2604 /* Don't store things in the fixed argument area at this point;
2605 it has already been saved. */
2606 && i > reg_parm_stack_space)
2607 break;
2609 if (i != upper_bound)
2611 /* We need to make a save area. See what mode we can make it. */
2612 enum machine_mode save_mode
2613 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
2614 MODE_INT, 1);
2615 rtx stack_area
2616 = gen_rtx_MEM
2617 (save_mode,
2618 memory_address
2619 (save_mode,
2620 plus_constant (argblock,
2621 argvec[argnum].offset.constant)));
2623 argvec[argnum].save_area = gen_reg_rtx (save_mode);
2624 emit_move_insn (argvec[argnum].save_area, stack_area);
2626 #endif
2627 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
2628 argblock, GEN_INT (argvec[argnum].offset.constant),
2629 reg_parm_stack_space);
2631 #ifdef ACCUMULATE_OUTGOING_ARGS
2632 /* Now mark the segment we just used. */
2633 for (i = lower_bound; i < upper_bound; i++)
2634 stack_usage_map[i] = 1;
2635 #endif
2637 NO_DEFER_POP;
2641 #ifndef PUSH_ARGS_REVERSED
2642 #ifdef STACK_BOUNDARY
2643 /* If we pushed args in forward order, perform stack alignment
2644 after pushing the last arg. */
2645 if (argblock == 0)
2646 anti_adjust_stack (GEN_INT (args_size.constant
2647 - original_args_size.constant));
2648 #endif
2649 #endif
2651 #ifdef PUSH_ARGS_REVERSED
2652 argnum = nargs - 1;
2653 #else
2654 argnum = 0;
2655 #endif
2657 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
2659 /* Now load any reg parms into their regs. */
2661 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
2662 are to be pushed. */
2663 for (count = 0; count < nargs; count++, argnum += inc)
2665 register enum machine_mode mode = argvec[argnum].mode;
2666 register rtx val = argvec[argnum].value;
2667 rtx reg = argvec[argnum].reg;
2668 int partial = argvec[argnum].partial;
2670 if (reg != 0 && partial == 0)
2671 emit_move_insn (reg, val);
2672 NO_DEFER_POP;
2675 /* For version 1.37, try deleting this entirely. */
2676 if (! no_queue)
2677 emit_queue ();
2679 /* Any regs containing parms remain in use through the call. */
2680 for (count = 0; count < nargs; count++)
2681 if (argvec[count].reg != 0)
2682 use_reg (&call_fusage, argvec[count].reg);
2684 /* Don't allow popping to be deferred, since then
2685 cse'ing of library calls could delete a call and leave the pop. */
2686 NO_DEFER_POP;
2688 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
2689 will set inhibit_defer_pop to that value. */
2691 /* The return type is needed to decide how many bytes the function pops.
2692 Signedness plays no role in that, so for simplicity, we pretend it's
2693 always signed. We also assume that the list of arguments passed has
2694 no impact, so we pretend it is unknown. */
2696 emit_call_1 (fun,
2697 get_identifier (XSTR (orgfun, 0)),
2698 build_function_type (outmode == VOIDmode ? void_type_node
2699 : type_for_mode (outmode, 0), NULL_TREE),
2700 args_size.constant, 0,
2701 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2702 outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
2703 old_inhibit_defer_pop + 1, call_fusage, no_queue);
2705 pop_temp_slots ();
2707 /* Now restore inhibit_defer_pop to its actual original value. */
2708 OK_DEFER_POP;
2710 #ifdef ACCUMULATE_OUTGOING_ARGS
2711 #ifdef REG_PARM_STACK_SPACE
2712 if (save_area)
2714 enum machine_mode save_mode = GET_MODE (save_area);
2715 rtx stack_area
2716 = gen_rtx_MEM (save_mode,
2717 memory_address (save_mode,
2718 #ifdef ARGS_GROW_DOWNWARD
2719 plus_constant (argblock, - high_to_save)
2720 #else
2721 plus_constant (argblock, low_to_save)
2722 #endif
2725 if (save_mode != BLKmode)
2726 emit_move_insn (stack_area, save_area);
2727 else
2728 emit_block_move (stack_area, validize_mem (save_area),
2729 GEN_INT (high_to_save - low_to_save + 1),
2730 PARM_BOUNDARY / BITS_PER_UNIT);
2732 #endif
2734 /* If we saved any argument areas, restore them. */
2735 for (count = 0; count < nargs; count++)
2736 if (argvec[count].save_area)
2738 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
2739 rtx stack_area
2740 = gen_rtx_MEM (save_mode,
2741 memory_address
2742 (save_mode,
2743 plus_constant (argblock,
2744 argvec[count].offset.constant)));
2746 emit_move_insn (stack_area, argvec[count].save_area);
2749 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2750 stack_usage_map = initial_stack_usage_map;
2751 #endif
2754 /* Like emit_library_call except that an extra argument, VALUE,
2755 comes second and says where to store the result.
2756 (If VALUE is zero, this function chooses a convenient way
2757 to return the value.
2759 This function returns an rtx for where the value is to be found.
2760 If VALUE is nonzero, VALUE is returned. */
2763 emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
2764 enum machine_mode outmode, int nargs, ...))
2766 #ifndef ANSI_PROTOTYPES
2767 rtx orgfun;
2768 rtx value;
2769 int no_queue;
2770 enum machine_mode outmode;
2771 int nargs;
2772 #endif
2773 va_list p;
2774 /* Total size in bytes of all the stack-parms scanned so far. */
2775 struct args_size args_size;
2776 /* Size of arguments before any adjustments (such as rounding). */
2777 struct args_size original_args_size;
2778 register int argnum;
2779 rtx fun;
2780 int inc;
2781 int count;
2782 rtx argblock = 0;
2783 CUMULATIVE_ARGS args_so_far;
2784 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2785 struct args_size offset; struct args_size size; rtx save_area; };
2786 struct arg *argvec;
2787 int old_inhibit_defer_pop = inhibit_defer_pop;
2788 rtx call_fusage = 0;
2789 /* Size of the stack reserved for parameter registers. */
2790 int reg_parm_stack_space = 0;
2791 rtx mem_value = 0;
2792 int pcc_struct_value = 0;
2793 int struct_value_size = 0;
2794 int is_const;
2795 int needed;
2797 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2798 /* Define the boundary of the register parm stack space that needs to be
2799 save, if any. */
2800 int low_to_save = -1, high_to_save;
2801 rtx save_area = 0; /* Place that it is saved */
2802 #endif
2804 #ifdef ACCUMULATE_OUTGOING_ARGS
2805 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2806 char *initial_stack_usage_map = stack_usage_map;
2807 #endif
2809 #ifdef REG_PARM_STACK_SPACE
2810 #ifdef MAYBE_REG_PARM_STACK_SPACE
2811 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2812 #else
2813 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
2814 #endif
2815 #endif
2817 VA_START (p, nargs);
2819 #ifndef ANSI_PROTOTYPES
2820 orgfun = va_arg (p, rtx);
2821 value = va_arg (p, rtx);
2822 no_queue = va_arg (p, int);
2823 outmode = va_arg (p, enum machine_mode);
2824 nargs = va_arg (p, int);
2825 #endif
2827 is_const = no_queue;
2828 fun = orgfun;
2830 /* If this kind of value comes back in memory,
2831 decide where in memory it should come back. */
2832 if (aggregate_value_p (type_for_mode (outmode, 0)))
2834 #ifdef PCC_STATIC_STRUCT_RETURN
2835 rtx pointer_reg
2836 = hard_function_value (build_pointer_type (type_for_mode (outmode, 0)),
2838 mem_value = gen_rtx_MEM (outmode, pointer_reg);
2839 pcc_struct_value = 1;
2840 if (value == 0)
2841 value = gen_reg_rtx (outmode);
2842 #else /* not PCC_STATIC_STRUCT_RETURN */
2843 struct_value_size = GET_MODE_SIZE (outmode);
2844 if (value != 0 && GET_CODE (value) == MEM)
2845 mem_value = value;
2846 else
2847 mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
2848 #endif
2850 /* This call returns a big structure. */
2851 is_const = 0;
2854 /* ??? Unfinished: must pass the memory address as an argument. */
2856 /* Copy all the libcall-arguments out of the varargs data
2857 and into a vector ARGVEC.
2859 Compute how to pass each argument. We only support a very small subset
2860 of the full argument passing conventions to limit complexity here since
2861 library functions shouldn't have many args. */
2863 argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
2864 bzero ((char *) argvec, (nargs + 1) * sizeof (struct arg));
2866 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
2868 args_size.constant = 0;
2869 args_size.var = 0;
2871 count = 0;
2873 push_temp_slots ();
2875 /* If there's a structure value address to be passed,
2876 either pass it in the special place, or pass it as an extra argument. */
2877 if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
2879 rtx addr = XEXP (mem_value, 0);
2880 nargs++;
2882 /* Make sure it is a reasonable operand for a move or push insn. */
2883 if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
2884 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
2885 addr = force_operand (addr, NULL_RTX);
2887 argvec[count].value = addr;
2888 argvec[count].mode = Pmode;
2889 argvec[count].partial = 0;
2891 argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
2892 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2893 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
2894 abort ();
2895 #endif
2897 locate_and_pad_parm (Pmode, NULL_TREE,
2898 argvec[count].reg && argvec[count].partial == 0,
2899 NULL_TREE, &args_size, &argvec[count].offset,
2900 &argvec[count].size);
2903 if (argvec[count].reg == 0 || argvec[count].partial != 0
2904 || reg_parm_stack_space > 0)
2905 args_size.constant += argvec[count].size.constant;
2907 FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
2909 count++;
2912 for (; count < nargs; count++)
2914 rtx val = va_arg (p, rtx);
2915 enum machine_mode mode = va_arg (p, enum machine_mode);
2917 /* We cannot convert the arg value to the mode the library wants here;
2918 must do it earlier where we know the signedness of the arg. */
2919 if (mode == BLKmode
2920 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2921 abort ();
2923 /* On some machines, there's no way to pass a float to a library fcn.
2924 Pass it as a double instead. */
2925 #ifdef LIBGCC_NEEDS_DOUBLE
2926 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2927 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
2928 #endif
2930 /* There's no need to call protect_from_queue, because
2931 either emit_move_insn or emit_push_insn will do that. */
2933 /* Make sure it is a reasonable operand for a move or push insn. */
2934 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2935 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2936 val = force_operand (val, NULL_RTX);
2938 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2939 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2941 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2942 be viewed as just an efficiency improvement. */
2943 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2944 emit_move_insn (slot, val);
2945 val = XEXP (slot, 0);
2946 mode = Pmode;
2948 #endif
2950 argvec[count].value = val;
2951 argvec[count].mode = mode;
2953 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2954 if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
2955 abort ();
2956 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2957 argvec[count].partial
2958 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2959 #else
2960 argvec[count].partial = 0;
2961 #endif
2963 locate_and_pad_parm (mode, NULL_TREE,
2964 argvec[count].reg && argvec[count].partial == 0,
2965 NULL_TREE, &args_size, &argvec[count].offset,
2966 &argvec[count].size);
2968 if (argvec[count].size.var)
2969 abort ();
2971 if (reg_parm_stack_space == 0 && argvec[count].partial)
2972 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2974 if (argvec[count].reg == 0 || argvec[count].partial != 0
2975 || reg_parm_stack_space > 0)
2976 args_size.constant += argvec[count].size.constant;
2978 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
2980 va_end (p);
2982 #ifdef FINAL_REG_PARM_STACK_SPACE
2983 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2984 args_size.var);
2985 #endif
2986 /* If this machine requires an external definition for library
2987 functions, write one out. */
2988 assemble_external_libcall (fun);
2990 original_args_size = args_size;
2991 #ifdef STACK_BOUNDARY
2992 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2993 / STACK_BYTES) * STACK_BYTES);
2994 #endif
2996 args_size.constant = MAX (args_size.constant,
2997 reg_parm_stack_space);
2999 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3000 args_size.constant -= reg_parm_stack_space;
3001 #endif
3003 if (args_size.constant > current_function_outgoing_args_size)
3004 current_function_outgoing_args_size = args_size.constant;
3006 #ifdef ACCUMULATE_OUTGOING_ARGS
3007 /* Since the stack pointer will never be pushed, it is possible for
3008 the evaluation of a parm to clobber something we have already
3009 written to the stack. Since most function calls on RISC machines
3010 do not use the stack, this is uncommon, but must work correctly.
3012 Therefore, we save any area of the stack that was already written
3013 and that we are using. Here we set up to do this by making a new
3014 stack usage map from the old one.
3016 Another approach might be to try to reorder the argument
3017 evaluations to avoid this conflicting stack usage. */
3019 needed = args_size.constant;
3021 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3022 /* Since we will be writing into the entire argument area, the
3023 map must be allocated for its entire size, not just the part that
3024 is the responsibility of the caller. */
3025 needed += reg_parm_stack_space;
3026 #endif
3028 #ifdef ARGS_GROW_DOWNWARD
3029 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3030 needed + 1);
3031 #else
3032 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3033 needed);
3034 #endif
3035 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3037 if (initial_highest_arg_in_use)
3038 bcopy (initial_stack_usage_map, stack_usage_map,
3039 initial_highest_arg_in_use);
3041 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3042 bzero (&stack_usage_map[initial_highest_arg_in_use],
3043 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3044 needed = 0;
3046 /* The address of the outgoing argument list must not be copied to a
3047 register here, because argblock would be left pointing to the
3048 wrong place after the call to allocate_dynamic_stack_space below.
3051 argblock = virtual_outgoing_args_rtx;
3052 #else /* not ACCUMULATE_OUTGOING_ARGS */
3053 #ifndef PUSH_ROUNDING
3054 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3055 #endif
3056 #endif
3058 #ifdef PUSH_ARGS_REVERSED
3059 #ifdef STACK_BOUNDARY
3060 /* If we push args individually in reverse order, perform stack alignment
3061 before the first push (the last arg). */
3062 if (argblock == 0)
3063 anti_adjust_stack (GEN_INT (args_size.constant
3064 - original_args_size.constant));
3065 #endif
3066 #endif
3068 #ifdef PUSH_ARGS_REVERSED
3069 inc = -1;
3070 argnum = nargs - 1;
3071 #else
3072 inc = 1;
3073 argnum = 0;
3074 #endif
3076 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3077 /* The argument list is the property of the called routine and it
3078 may clobber it. If the fixed area has been used for previous
3079 parameters, we must save and restore it.
3081 Here we compute the boundary of the that needs to be saved, if any. */
3083 #ifdef ARGS_GROW_DOWNWARD
3084 for (count = 0; count < reg_parm_stack_space + 1; count++)
3085 #else
3086 for (count = 0; count < reg_parm_stack_space; count++)
3087 #endif
3089 if (count >= highest_outgoing_arg_in_use
3090 || stack_usage_map[count] == 0)
3091 continue;
3093 if (low_to_save == -1)
3094 low_to_save = count;
3096 high_to_save = count;
3099 if (low_to_save >= 0)
3101 int num_to_save = high_to_save - low_to_save + 1;
3102 enum machine_mode save_mode
3103 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
3104 rtx stack_area;
3106 /* If we don't have the required alignment, must do this in BLKmode. */
3107 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
3108 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
3109 save_mode = BLKmode;
3111 stack_area = gen_rtx_MEM (save_mode,
3112 memory_address (save_mode,
3113 #ifdef ARGS_GROW_DOWNWARD
3114 plus_constant (argblock,
3115 - high_to_save)
3116 #else
3117 plus_constant (argblock,
3118 low_to_save)
3119 #endif
3122 if (save_mode == BLKmode)
3124 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
3125 MEM_IN_STRUCT_P (save_area) = 0;
3126 emit_block_move (validize_mem (save_area), stack_area,
3127 GEN_INT (num_to_save),
3128 PARM_BOUNDARY / BITS_PER_UNIT);
3130 else
3132 save_area = gen_reg_rtx (save_mode);
3133 emit_move_insn (save_area, stack_area);
3136 #endif
3138 /* Push the args that need to be pushed. */
3140 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3141 are to be pushed. */
3142 for (count = 0; count < nargs; count++, argnum += inc)
3144 register enum machine_mode mode = argvec[argnum].mode;
3145 register rtx val = argvec[argnum].value;
3146 rtx reg = argvec[argnum].reg;
3147 int partial = argvec[argnum].partial;
3148 int lower_bound, upper_bound, i;
3150 if (! (reg != 0 && partial == 0))
3152 #ifdef ACCUMULATE_OUTGOING_ARGS
3153 /* If this is being stored into a pre-allocated, fixed-size, stack
3154 area, save any previous data at that location. */
3156 #ifdef ARGS_GROW_DOWNWARD
3157 /* stack_slot is negative, but we want to index stack_usage_map
3158 with positive values. */
3159 upper_bound = -argvec[argnum].offset.constant + 1;
3160 lower_bound = upper_bound - argvec[argnum].size.constant;
3161 #else
3162 lower_bound = argvec[argnum].offset.constant;
3163 upper_bound = lower_bound + argvec[argnum].size.constant;
3164 #endif
3166 for (i = lower_bound; i < upper_bound; i++)
3167 if (stack_usage_map[i]
3168 /* Don't store things in the fixed argument area at this point;
3169 it has already been saved. */
3170 && i > reg_parm_stack_space)
3171 break;
3173 if (i != upper_bound)
3175 /* We need to make a save area. See what mode we can make it. */
3176 enum machine_mode save_mode
3177 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
3178 MODE_INT, 1);
3179 rtx stack_area
3180 = gen_rtx_MEM
3181 (save_mode,
3182 memory_address
3183 (save_mode,
3184 plus_constant (argblock,
3185 argvec[argnum].offset.constant)));
3186 argvec[argnum].save_area = gen_reg_rtx (save_mode);
3188 emit_move_insn (argvec[argnum].save_area, stack_area);
3190 #endif
3191 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
3192 argblock, GEN_INT (argvec[argnum].offset.constant),
3193 reg_parm_stack_space);
3195 #ifdef ACCUMULATE_OUTGOING_ARGS
3196 /* Now mark the segment we just used. */
3197 for (i = lower_bound; i < upper_bound; i++)
3198 stack_usage_map[i] = 1;
3199 #endif
3201 NO_DEFER_POP;
3205 #ifndef PUSH_ARGS_REVERSED
3206 #ifdef STACK_BOUNDARY
3207 /* If we pushed args in forward order, perform stack alignment
3208 after pushing the last arg. */
3209 if (argblock == 0)
3210 anti_adjust_stack (GEN_INT (args_size.constant
3211 - original_args_size.constant));
3212 #endif
3213 #endif
3215 #ifdef PUSH_ARGS_REVERSED
3216 argnum = nargs - 1;
3217 #else
3218 argnum = 0;
3219 #endif
3221 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
3223 /* Now load any reg parms into their regs. */
3225 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3226 are to be pushed. */
3227 for (count = 0; count < nargs; count++, argnum += inc)
3229 register enum machine_mode mode = argvec[argnum].mode;
3230 register rtx val = argvec[argnum].value;
3231 rtx reg = argvec[argnum].reg;
3232 int partial = argvec[argnum].partial;
3234 if (reg != 0 && partial == 0)
3235 emit_move_insn (reg, val);
3236 NO_DEFER_POP;
3239 #if 0
3240 /* For version 1.37, try deleting this entirely. */
3241 if (! no_queue)
3242 emit_queue ();
3243 #endif
3245 /* Any regs containing parms remain in use through the call. */
3246 for (count = 0; count < nargs; count++)
3247 if (argvec[count].reg != 0)
3248 use_reg (&call_fusage, argvec[count].reg);
3250 /* Pass the function the address in which to return a structure value. */
3251 if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
3253 emit_move_insn (struct_value_rtx,
3254 force_reg (Pmode,
3255 force_operand (XEXP (mem_value, 0),
3256 NULL_RTX)));
3257 if (GET_CODE (struct_value_rtx) == REG)
3258 use_reg (&call_fusage, struct_value_rtx);
3261 /* Don't allow popping to be deferred, since then
3262 cse'ing of library calls could delete a call and leave the pop. */
3263 NO_DEFER_POP;
3265 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3266 will set inhibit_defer_pop to that value. */
3267 /* See the comment in emit_library_call about the function type we build
3268 and pass here. */
3270 emit_call_1 (fun,
3271 get_identifier (XSTR (orgfun, 0)),
3272 build_function_type (type_for_mode (outmode, 0), NULL_TREE),
3273 args_size.constant, struct_value_size,
3274 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3275 mem_value == 0 ? hard_libcall_value (outmode) : NULL_RTX,
3276 old_inhibit_defer_pop + 1, call_fusage, is_const);
3278 /* Now restore inhibit_defer_pop to its actual original value. */
3279 OK_DEFER_POP;
3281 pop_temp_slots ();
3283 /* Copy the value to the right place. */
3284 if (outmode != VOIDmode)
3286 if (mem_value)
3288 if (value == 0)
3289 value = mem_value;
3290 if (value != mem_value)
3291 emit_move_insn (value, mem_value);
3293 else if (value != 0)
3294 emit_move_insn (value, hard_libcall_value (outmode));
3295 else
3296 value = hard_libcall_value (outmode);
3299 #ifdef ACCUMULATE_OUTGOING_ARGS
3300 #ifdef REG_PARM_STACK_SPACE
3301 if (save_area)
3303 enum machine_mode save_mode = GET_MODE (save_area);
3304 rtx stack_area
3305 = gen_rtx_MEM (save_mode,
3306 memory_address (save_mode,
3307 #ifdef ARGS_GROW_DOWNWARD
3308 plus_constant (argblock, - high_to_save)
3309 #else
3310 plus_constant (argblock, low_to_save)
3311 #endif
3314 if (save_mode != BLKmode)
3315 emit_move_insn (stack_area, save_area);
3316 else
3317 emit_block_move (stack_area, validize_mem (save_area),
3318 GEN_INT (high_to_save - low_to_save + 1),
3319 PARM_BOUNDARY / BITS_PER_UNIT);
3321 #endif
3323 /* If we saved any argument areas, restore them. */
3324 for (count = 0; count < nargs; count++)
3325 if (argvec[count].save_area)
3327 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3328 rtx stack_area
3329 = gen_rtx_MEM (save_mode,
3330 memory_address
3331 (save_mode,
3332 plus_constant (argblock,
3333 argvec[count].offset.constant)));
3335 emit_move_insn (stack_area, argvec[count].save_area);
3338 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3339 stack_usage_map = initial_stack_usage_map;
3340 #endif
3342 return value;
3345 #if 0
3346 /* Return an rtx which represents a suitable home on the stack
3347 given TYPE, the type of the argument looking for a home.
3348 This is called only for BLKmode arguments.
3350 SIZE is the size needed for this target.
3351 ARGS_ADDR is the address of the bottom of the argument block for this call.
3352 OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
3353 if this machine uses push insns. */
3355 static rtx
3356 target_for_arg (type, size, args_addr, offset)
3357 tree type;
3358 rtx size;
3359 rtx args_addr;
3360 struct args_size offset;
3362 rtx target;
3363 rtx offset_rtx = ARGS_SIZE_RTX (offset);
3365 /* We do not call memory_address if possible,
3366 because we want to address as close to the stack
3367 as possible. For non-variable sized arguments,
3368 this will be stack-pointer relative addressing. */
3369 if (GET_CODE (offset_rtx) == CONST_INT)
3370 target = plus_constant (args_addr, INTVAL (offset_rtx));
3371 else
3373 /* I have no idea how to guarantee that this
3374 will work in the presence of register parameters. */
3375 target = gen_rtx_PLUS (Pmode, args_addr, offset_rtx);
3376 target = memory_address (QImode, target);
3379 return gen_rtx_MEM (BLKmode, target);
3381 #endif
3383 /* Store a single argument for a function call
3384 into the register or memory area where it must be passed.
3385 *ARG describes the argument value and where to pass it.
3387 ARGBLOCK is the address of the stack-block for all the arguments,
3388 or 0 on a machine where arguments are pushed individually.
3390 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
3391 so must be careful about how the stack is used.
3393 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
3394 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
3395 that we need not worry about saving and restoring the stack.
3397 FNDECL is the declaration of the function we are calling. */
3399 static void
3400 store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl,
3401 reg_parm_stack_space)
3402 struct arg_data *arg;
3403 rtx argblock;
3404 int may_be_alloca;
3405 int variable_size;
3406 tree fndecl;
3407 int reg_parm_stack_space;
3409 register tree pval = arg->tree_value;
3410 rtx reg = 0;
3411 int partial = 0;
3412 int used = 0;
3413 int i, lower_bound, upper_bound;
3415 if (TREE_CODE (pval) == ERROR_MARK)
3416 return;
3418 /* Push a new temporary level for any temporaries we make for
3419 this argument. */
3420 push_temp_slots ();
3422 #ifdef ACCUMULATE_OUTGOING_ARGS
3423 /* If this is being stored into a pre-allocated, fixed-size, stack area,
3424 save any previous data at that location. */
3425 if (argblock && ! variable_size && arg->stack)
3427 #ifdef ARGS_GROW_DOWNWARD
3428 /* stack_slot is negative, but we want to index stack_usage_map
3429 with positive values. */
3430 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3431 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
3432 else
3433 upper_bound = 0;
3435 lower_bound = upper_bound - arg->size.constant;
3436 #else
3437 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3438 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
3439 else
3440 lower_bound = 0;
3442 upper_bound = lower_bound + arg->size.constant;
3443 #endif
3445 for (i = lower_bound; i < upper_bound; i++)
3446 if (stack_usage_map[i]
3447 /* Don't store things in the fixed argument area at this point;
3448 it has already been saved. */
3449 && i > reg_parm_stack_space)
3450 break;
3452 if (i != upper_bound)
3454 /* We need to make a save area. See what mode we can make it. */
3455 enum machine_mode save_mode
3456 = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
3457 rtx stack_area
3458 = gen_rtx_MEM (save_mode,
3459 memory_address (save_mode,
3460 XEXP (arg->stack_slot, 0)));
3462 if (save_mode == BLKmode)
3464 arg->save_area = assign_stack_temp (BLKmode,
3465 arg->size.constant, 0);
3466 MEM_IN_STRUCT_P (arg->save_area)
3467 = AGGREGATE_TYPE_P (TREE_TYPE (arg->tree_value));
3468 preserve_temp_slots (arg->save_area);
3469 emit_block_move (validize_mem (arg->save_area), stack_area,
3470 GEN_INT (arg->size.constant),
3471 PARM_BOUNDARY / BITS_PER_UNIT);
3473 else
3475 arg->save_area = gen_reg_rtx (save_mode);
3476 emit_move_insn (arg->save_area, stack_area);
3480 #endif
3482 /* If this isn't going to be placed on both the stack and in registers,
3483 set up the register and number of words. */
3484 if (! arg->pass_on_stack)
3485 reg = arg->reg, partial = arg->partial;
3487 if (reg != 0 && partial == 0)
3488 /* Being passed entirely in a register. We shouldn't be called in
3489 this case. */
3490 abort ();
3492 /* If this arg needs special alignment, don't load the registers
3493 here. */
3494 if (arg->n_aligned_regs != 0)
3495 reg = 0;
3497 /* If this is being passed partially in a register, we can't evaluate
3498 it directly into its stack slot. Otherwise, we can. */
3499 if (arg->value == 0)
3501 #ifdef ACCUMULATE_OUTGOING_ARGS
3502 /* stack_arg_under_construction is nonzero if a function argument is
3503 being evaluated directly into the outgoing argument list and
3504 expand_call must take special action to preserve the argument list
3505 if it is called recursively.
3507 For scalar function arguments stack_usage_map is sufficient to
3508 determine which stack slots must be saved and restored. Scalar
3509 arguments in general have pass_on_stack == 0.
3511 If this argument is initialized by a function which takes the
3512 address of the argument (a C++ constructor or a C function
3513 returning a BLKmode structure), then stack_usage_map is
3514 insufficient and expand_call must push the stack around the
3515 function call. Such arguments have pass_on_stack == 1.
3517 Note that it is always safe to set stack_arg_under_construction,
3518 but this generates suboptimal code if set when not needed. */
3520 if (arg->pass_on_stack)
3521 stack_arg_under_construction++;
3522 #endif
3523 arg->value = expand_expr (pval,
3524 (partial
3525 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
3526 ? NULL_RTX : arg->stack,
3527 VOIDmode, 0);
3529 /* If we are promoting object (or for any other reason) the mode
3530 doesn't agree, convert the mode. */
3532 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
3533 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
3534 arg->value, arg->unsignedp);
3536 #ifdef ACCUMULATE_OUTGOING_ARGS
3537 if (arg->pass_on_stack)
3538 stack_arg_under_construction--;
3539 #endif
3542 /* Don't allow anything left on stack from computation
3543 of argument to alloca. */
3544 if (may_be_alloca)
3545 do_pending_stack_adjust ();
3547 if (arg->value == arg->stack)
3549 /* If the value is already in the stack slot, we are done. */
3550 if (current_function_check_memory_usage && GET_CODE (arg->stack) == MEM)
3552 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
3553 XEXP (arg->stack, 0), ptr_mode,
3554 ARGS_SIZE_RTX (arg->size),
3555 TYPE_MODE (sizetype),
3556 GEN_INT (MEMORY_USE_RW),
3557 TYPE_MODE (integer_type_node));
3560 else if (arg->mode != BLKmode)
3562 register int size;
3564 /* Argument is a scalar, not entirely passed in registers.
3565 (If part is passed in registers, arg->partial says how much
3566 and emit_push_insn will take care of putting it there.)
3568 Push it, and if its size is less than the
3569 amount of space allocated to it,
3570 also bump stack pointer by the additional space.
3571 Note that in C the default argument promotions
3572 will prevent such mismatches. */
3574 size = GET_MODE_SIZE (arg->mode);
3575 /* Compute how much space the push instruction will push.
3576 On many machines, pushing a byte will advance the stack
3577 pointer by a halfword. */
3578 #ifdef PUSH_ROUNDING
3579 size = PUSH_ROUNDING (size);
3580 #endif
3581 used = size;
3583 /* Compute how much space the argument should get:
3584 round up to a multiple of the alignment for arguments. */
3585 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
3586 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
3587 / (PARM_BOUNDARY / BITS_PER_UNIT))
3588 * (PARM_BOUNDARY / BITS_PER_UNIT));
3590 /* This isn't already where we want it on the stack, so put it there.
3591 This can either be done with push or copy insns. */
3592 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, 0,
3593 partial, reg, used - size, argblock,
3594 ARGS_SIZE_RTX (arg->offset), reg_parm_stack_space);
3596 else
3598 /* BLKmode, at least partly to be pushed. */
3600 register int excess;
3601 rtx size_rtx;
3603 /* Pushing a nonscalar.
3604 If part is passed in registers, PARTIAL says how much
3605 and emit_push_insn will take care of putting it there. */
3607 /* Round its size up to a multiple
3608 of the allocation unit for arguments. */
3610 if (arg->size.var != 0)
3612 excess = 0;
3613 size_rtx = ARGS_SIZE_RTX (arg->size);
3615 else
3617 /* PUSH_ROUNDING has no effect on us, because
3618 emit_push_insn for BLKmode is careful to avoid it. */
3619 excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
3620 + partial * UNITS_PER_WORD);
3621 size_rtx = expr_size (pval);
3624 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
3625 TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
3626 reg, excess, argblock, ARGS_SIZE_RTX (arg->offset),
3627 reg_parm_stack_space);
3631 /* Unless this is a partially-in-register argument, the argument is now
3632 in the stack.
3634 ??? Note that this can change arg->value from arg->stack to
3635 arg->stack_slot and it matters when they are not the same.
3636 It isn't totally clear that this is correct in all cases. */
3637 if (partial == 0)
3638 arg->value = arg->stack_slot;
3640 /* Once we have pushed something, pops can't safely
3641 be deferred during the rest of the arguments. */
3642 NO_DEFER_POP;
3644 /* ANSI doesn't require a sequence point here,
3645 but PCC has one, so this will avoid some problems. */
3646 emit_queue ();
3648 /* Free any temporary slots made in processing this argument. Show
3649 that we might have taken the address of something and pushed that
3650 as an operand. */
3651 preserve_temp_slots (NULL_RTX);
3652 free_temp_slots ();
3653 pop_temp_slots ();
3655 #ifdef ACCUMULATE_OUTGOING_ARGS
3656 /* Now mark the segment we just used. */
3657 if (argblock && ! variable_size && arg->stack)
3658 for (i = lower_bound; i < upper_bound; i++)
3659 stack_usage_map[i] = 1;
3660 #endif