Call fatal_insn_not_found instead of abort
[official-gcc.git] / gcc / calls.c
blob6271a611a8c643f481ec9ca24983503d5548ef02
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 #ifdef __STDC__
23 #include <stdarg.h>
24 #else
25 #include <varargs.h>
26 #endif
27 #include "system.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "flags.h"
31 #include "expr.h"
32 #include "regs.h"
33 #include "insn-flags.h"
34 #include "toplev.h"
35 #include "output.h"
37 /* Decide whether a function's arguments should be processed
38 from first to last or from last to first.
40 They should if the stack and args grow in opposite directions, but
41 only if we have push insns. */
43 #ifdef PUSH_ROUNDING
45 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
46 #define PUSH_ARGS_REVERSED /* If it's last to first */
47 #endif
49 #endif
51 /* Like STACK_BOUNDARY but in units of bytes, not bits. */
52 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
54 /* Data structure and subroutines used within expand_call. */
56 struct arg_data
58 /* Tree node for this argument. */
59 tree tree_value;
60 /* Mode for value; TYPE_MODE unless promoted. */
61 enum machine_mode mode;
62 /* Current RTL value for argument, or 0 if it isn't precomputed. */
63 rtx value;
64 /* Initially-compute RTL value for argument; only for const functions. */
65 rtx initial_value;
66 /* Register to pass this argument in, 0 if passed on stack, or an
67 PARALLEL if the arg is to be copied into multiple non-contiguous
68 registers. */
69 rtx reg;
70 /* If REG was promoted from the actual mode of the argument expression,
71 indicates whether the promotion is sign- or zero-extended. */
72 int unsignedp;
73 /* Number of registers to use. 0 means put the whole arg in registers.
74 Also 0 if not passed in registers. */
75 int partial;
76 /* Non-zero if argument must be passed on stack.
77 Note that some arguments may be passed on the stack
78 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
79 pass_on_stack identifies arguments that *cannot* go in registers. */
80 int pass_on_stack;
81 /* Offset of this argument from beginning of stack-args. */
82 struct args_size offset;
83 /* Similar, but offset to the start of the stack slot. Different from
84 OFFSET if this arg pads downward. */
85 struct args_size slot_offset;
86 /* Size of this argument on the stack, rounded up for any padding it gets,
87 parts of the argument passed in registers do not count.
88 If REG_PARM_STACK_SPACE is defined, then register parms
89 are counted here as well. */
90 struct args_size size;
91 /* Location on the stack at which parameter should be stored. The store
92 has already been done if STACK == VALUE. */
93 rtx stack;
94 /* Location on the stack of the start of this argument slot. This can
95 differ from STACK if this arg pads downward. This location is known
96 to be aligned to FUNCTION_ARG_BOUNDARY. */
97 rtx stack_slot;
98 #ifdef ACCUMULATE_OUTGOING_ARGS
99 /* Place that this stack area has been saved, if needed. */
100 rtx save_area;
101 #endif
102 /* If an argument's alignment does not permit direct copying into registers,
103 copy in smaller-sized pieces into pseudos. These are stored in a
104 block pointed to by this field. The next field says how many
105 word-sized pseudos we made. */
106 rtx *aligned_regs;
107 int n_aligned_regs;
110 #ifdef ACCUMULATE_OUTGOING_ARGS
111 /* A vector of one char per byte of stack space. A byte if non-zero if
112 the corresponding stack location has been used.
113 This vector is used to prevent a function call within an argument from
114 clobbering any stack already set up. */
115 static char *stack_usage_map;
117 /* Size of STACK_USAGE_MAP. */
118 static int highest_outgoing_arg_in_use;
120 /* stack_arg_under_construction is nonzero when an argument may be
121 initialized with a constructor call (including a C function that
122 returns a BLKmode struct) and expand_call must take special action
123 to make sure the object being constructed does not overlap the
124 argument list for the constructor call. */
125 int stack_arg_under_construction;
126 #endif
128 static int calls_function PROTO((tree, int));
129 static int calls_function_1 PROTO((tree, int));
130 static void emit_call_1 PROTO((rtx, tree, tree, HOST_WIDE_INT,
131 HOST_WIDE_INT, rtx, rtx,
132 int, rtx, int));
133 static void store_one_arg PROTO ((struct arg_data *, rtx, int, int,
134 tree, int));
136 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
137 `alloca'.
139 If WHICH is 0, return 1 if EXP contains a call to any function.
140 Actually, we only need return 1 if evaluating EXP would require pushing
141 arguments on the stack, but that is too difficult to compute, so we just
142 assume any function call might require the stack. */
144 static tree calls_function_save_exprs;
146 static int
147 calls_function (exp, which)
148 tree exp;
149 int which;
151 int val;
152 calls_function_save_exprs = 0;
153 val = calls_function_1 (exp, which);
154 calls_function_save_exprs = 0;
155 return val;
158 static int
159 calls_function_1 (exp, which)
160 tree exp;
161 int which;
163 register int i;
164 enum tree_code code = TREE_CODE (exp);
165 int type = TREE_CODE_CLASS (code);
166 int length = tree_code_length[(int) code];
168 /* If this code is language-specific, we don't know what it will do. */
169 if ((int) code >= NUM_TREE_CODES)
170 return 1;
172 /* Only expressions and references can contain calls. */
173 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
174 && type != 'b')
175 return 0;
177 switch (code)
179 case CALL_EXPR:
180 if (which == 0)
181 return 1;
182 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
183 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
184 == FUNCTION_DECL))
186 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
188 if ((DECL_BUILT_IN (fndecl)
189 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA)
190 || (DECL_SAVED_INSNS (fndecl)
191 && (FUNCTION_FLAGS (DECL_SAVED_INSNS (fndecl))
192 & FUNCTION_FLAGS_CALLS_ALLOCA)))
193 return 1;
196 /* Third operand is RTL. */
197 length = 2;
198 break;
200 case SAVE_EXPR:
201 if (SAVE_EXPR_RTL (exp) != 0)
202 return 0;
203 if (value_member (exp, calls_function_save_exprs))
204 return 0;
205 calls_function_save_exprs = tree_cons (NULL_TREE, exp,
206 calls_function_save_exprs);
207 return (TREE_OPERAND (exp, 0) != 0
208 && calls_function_1 (TREE_OPERAND (exp, 0), which));
210 case BLOCK:
212 register tree local;
214 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
215 if (DECL_INITIAL (local) != 0
216 && calls_function_1 (DECL_INITIAL (local), which))
217 return 1;
220 register tree subblock;
222 for (subblock = BLOCK_SUBBLOCKS (exp);
223 subblock;
224 subblock = TREE_CHAIN (subblock))
225 if (calls_function_1 (subblock, which))
226 return 1;
228 return 0;
230 case METHOD_CALL_EXPR:
231 length = 3;
232 break;
234 case WITH_CLEANUP_EXPR:
235 length = 1;
236 break;
238 case RTL_EXPR:
239 return 0;
241 default:
242 break;
245 for (i = 0; i < length; i++)
246 if (TREE_OPERAND (exp, i) != 0
247 && calls_function_1 (TREE_OPERAND (exp, i), which))
248 return 1;
250 return 0;
253 /* Force FUNEXP into a form suitable for the address of a CALL,
254 and return that as an rtx. Also load the static chain register
255 if FNDECL is a nested function.
257 CALL_FUSAGE points to a variable holding the prospective
258 CALL_INSN_FUNCTION_USAGE information. */
261 prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen)
262 rtx funexp;
263 tree fndecl;
264 rtx *call_fusage;
265 int reg_parm_seen;
267 rtx static_chain_value = 0;
269 funexp = protect_from_queue (funexp, 0);
271 if (fndecl != 0)
272 /* Get possible static chain value for nested function in C. */
273 static_chain_value = lookup_static_chain (fndecl);
275 /* Make a valid memory address and copy constants thru pseudo-regs,
276 but not for a constant address if -fno-function-cse. */
277 if (GET_CODE (funexp) != SYMBOL_REF)
278 /* If we are using registers for parameters, force the
279 function address into a register now. */
280 funexp = ((SMALL_REGISTER_CLASSES && reg_parm_seen)
281 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
282 : memory_address (FUNCTION_MODE, funexp));
283 else
285 #ifndef NO_FUNCTION_CSE
286 if (optimize && ! flag_no_function_cse)
287 #ifdef NO_RECURSIVE_FUNCTION_CSE
288 if (fndecl != current_function_decl)
289 #endif
290 funexp = force_reg (Pmode, funexp);
291 #endif
294 if (static_chain_value != 0)
296 emit_move_insn (static_chain_rtx, static_chain_value);
298 if (GET_CODE (static_chain_rtx) == REG)
299 use_reg (call_fusage, static_chain_rtx);
302 return funexp;
305 /* Generate instructions to call function FUNEXP,
306 and optionally pop the results.
307 The CALL_INSN is the first insn generated.
309 FNDECL is the declaration node of the function. This is given to the
310 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
312 FUNTYPE is the data type of the function. This is given to the macro
313 RETURN_POPS_ARGS to determine whether this function pops its own args.
314 We used to allow an identifier for library functions, but that doesn't
315 work when the return type is an aggregate type and the calling convention
316 says that the pointer to this aggregate is to be popped by the callee.
318 STACK_SIZE is the number of bytes of arguments on the stack,
319 rounded up to STACK_BOUNDARY; zero if the size is variable.
320 This is both to put into the call insn and
321 to generate explicit popping code if necessary.
323 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
324 It is zero if this call doesn't want a structure value.
326 NEXT_ARG_REG is the rtx that results from executing
327 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
328 just after all the args have had their registers assigned.
329 This could be whatever you like, but normally it is the first
330 arg-register beyond those used for args in this call,
331 or 0 if all the arg-registers are used in this call.
332 It is passed on to `gen_call' so you can put this info in the call insn.
334 VALREG is a hard register in which a value is returned,
335 or 0 if the call does not return a value.
337 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
338 the args to this call were processed.
339 We restore `inhibit_defer_pop' to that value.
341 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
342 denote registers used by the called function.
344 IS_CONST is true if this is a `const' call. */
346 static void
347 emit_call_1 (funexp, fndecl, funtype, stack_size, struct_value_size,
348 next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
349 is_const)
350 rtx funexp;
351 tree fndecl;
352 tree funtype;
353 HOST_WIDE_INT stack_size;
354 HOST_WIDE_INT struct_value_size;
355 rtx next_arg_reg;
356 rtx valreg;
357 int old_inhibit_defer_pop;
358 rtx call_fusage;
359 int is_const;
361 rtx stack_size_rtx = GEN_INT (stack_size);
362 rtx struct_value_size_rtx = GEN_INT (struct_value_size);
363 rtx call_insn;
364 #ifndef ACCUMULATE_OUTGOING_ARGS
365 int already_popped = 0;
366 #endif
368 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
369 and we don't want to load it into a register as an optimization,
370 because prepare_call_address already did it if it should be done. */
371 if (GET_CODE (funexp) != SYMBOL_REF)
372 funexp = memory_address (FUNCTION_MODE, funexp);
374 #ifndef ACCUMULATE_OUTGOING_ARGS
375 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
376 if (HAVE_call_pop && HAVE_call_value_pop
377 && (RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0
378 || stack_size == 0))
380 rtx n_pop = GEN_INT (RETURN_POPS_ARGS (fndecl, funtype, stack_size));
381 rtx pat;
383 /* If this subroutine pops its own args, record that in the call insn
384 if possible, for the sake of frame pointer elimination. */
386 if (valreg)
387 pat = gen_call_value_pop (valreg,
388 gen_rtx_MEM (FUNCTION_MODE, funexp),
389 stack_size_rtx, next_arg_reg, n_pop);
390 else
391 pat = gen_call_pop (gen_rtx_MEM (FUNCTION_MODE, funexp),
392 stack_size_rtx, next_arg_reg, n_pop);
394 emit_call_insn (pat);
395 already_popped = 1;
397 else
398 #endif
399 #endif
401 #if defined (HAVE_call) && defined (HAVE_call_value)
402 if (HAVE_call && HAVE_call_value)
404 if (valreg)
405 emit_call_insn (gen_call_value (valreg,
406 gen_rtx_MEM (FUNCTION_MODE, funexp),
407 stack_size_rtx, next_arg_reg,
408 NULL_RTX));
409 else
410 emit_call_insn (gen_call (gen_rtx_MEM (FUNCTION_MODE, funexp),
411 stack_size_rtx, next_arg_reg,
412 struct_value_size_rtx));
414 else
415 #endif
416 abort ();
418 /* Find the CALL insn we just emitted. */
419 for (call_insn = get_last_insn ();
420 call_insn && GET_CODE (call_insn) != CALL_INSN;
421 call_insn = PREV_INSN (call_insn))
424 if (! call_insn)
425 abort ();
427 /* Put the register usage information on the CALL. If there is already
428 some usage information, put ours at the end. */
429 if (CALL_INSN_FUNCTION_USAGE (call_insn))
431 rtx link;
433 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
434 link = XEXP (link, 1))
437 XEXP (link, 1) = call_fusage;
439 else
440 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
442 /* If this is a const call, then set the insn's unchanging bit. */
443 if (is_const)
444 CONST_CALL_P (call_insn) = 1;
446 /* Restore this now, so that we do defer pops for this call's args
447 if the context of the call as a whole permits. */
448 inhibit_defer_pop = old_inhibit_defer_pop;
450 #ifndef ACCUMULATE_OUTGOING_ARGS
451 /* If returning from the subroutine does not automatically pop the args,
452 we need an instruction to pop them sooner or later.
453 Perhaps do it now; perhaps just record how much space to pop later.
455 If returning from the subroutine does pop the args, indicate that the
456 stack pointer will be changed. */
458 if (stack_size != 0 && RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0)
460 if (!already_popped)
461 CALL_INSN_FUNCTION_USAGE (call_insn)
462 = gen_rtx_EXPR_LIST (VOIDmode,
463 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
464 CALL_INSN_FUNCTION_USAGE (call_insn));
465 stack_size -= RETURN_POPS_ARGS (fndecl, funtype, stack_size);
466 stack_size_rtx = GEN_INT (stack_size);
469 if (stack_size != 0)
471 if (flag_defer_pop && inhibit_defer_pop == 0 && !is_const)
472 pending_stack_adjust += stack_size;
473 else
474 adjust_stack (stack_size_rtx);
476 #endif
479 /* Generate all the code for a function call
480 and return an rtx for its value.
481 Store the value in TARGET (specified as an rtx) if convenient.
482 If the value is stored in TARGET then TARGET is returned.
483 If IGNORE is nonzero, then we ignore the value of the function call. */
486 expand_call (exp, target, ignore)
487 tree exp;
488 rtx target;
489 int ignore;
491 /* List of actual parameters. */
492 tree actparms = TREE_OPERAND (exp, 1);
493 /* RTX for the function to be called. */
494 rtx funexp;
495 /* Data type of the function. */
496 tree funtype;
497 /* Declaration of the function being called,
498 or 0 if the function is computed (not known by name). */
499 tree fndecl = 0;
500 char *name = 0;
502 /* Register in which non-BLKmode value will be returned,
503 or 0 if no value or if value is BLKmode. */
504 rtx valreg;
505 /* Address where we should return a BLKmode value;
506 0 if value not BLKmode. */
507 rtx structure_value_addr = 0;
508 /* Nonzero if that address is being passed by treating it as
509 an extra, implicit first parameter. Otherwise,
510 it is passed by being copied directly into struct_value_rtx. */
511 int structure_value_addr_parm = 0;
512 /* Size of aggregate value wanted, or zero if none wanted
513 or if we are using the non-reentrant PCC calling convention
514 or expecting the value in registers. */
515 HOST_WIDE_INT struct_value_size = 0;
516 /* Nonzero if called function returns an aggregate in memory PCC style,
517 by returning the address of where to find it. */
518 int pcc_struct_value = 0;
520 /* Number of actual parameters in this call, including struct value addr. */
521 int num_actuals;
522 /* Number of named args. Args after this are anonymous ones
523 and they must all go on the stack. */
524 int n_named_args;
525 /* Count arg position in order args appear. */
526 int argpos;
528 /* Vector of information about each argument.
529 Arguments are numbered in the order they will be pushed,
530 not the order they are written. */
531 struct arg_data *args;
533 /* Total size in bytes of all the stack-parms scanned so far. */
534 struct args_size args_size;
535 /* Size of arguments before any adjustments (such as rounding). */
536 struct args_size original_args_size;
537 /* Data on reg parms scanned so far. */
538 CUMULATIVE_ARGS args_so_far;
539 /* Nonzero if a reg parm has been scanned. */
540 int reg_parm_seen;
541 /* Nonzero if this is an indirect function call. */
543 /* Nonzero if we must avoid push-insns in the args for this call.
544 If stack space is allocated for register parameters, but not by the
545 caller, then it is preallocated in the fixed part of the stack frame.
546 So the entire argument block must then be preallocated (i.e., we
547 ignore PUSH_ROUNDING in that case). */
549 #ifdef PUSH_ROUNDING
550 int must_preallocate = 0;
551 #else
552 int must_preallocate = 1;
553 #endif
555 /* Size of the stack reserved for parameter registers. */
556 int reg_parm_stack_space = 0;
558 /* 1 if scanning parms front to back, -1 if scanning back to front. */
559 int inc;
560 /* Address of space preallocated for stack parms
561 (on machines that lack push insns), or 0 if space not preallocated. */
562 rtx argblock = 0;
564 /* Nonzero if it is plausible that this is a call to alloca. */
565 int may_be_alloca;
566 /* Nonzero if this is a call to malloc or a related function. */
567 int is_malloc;
568 /* Nonzero if this is a call to setjmp or a related function. */
569 int returns_twice;
570 /* Nonzero if this is a call to `longjmp'. */
571 int is_longjmp;
572 /* Nonzero if this is a call to an inline function. */
573 int is_integrable = 0;
574 /* Nonzero if this is a call to a `const' function.
575 Note that only explicitly named functions are handled as `const' here. */
576 int is_const = 0;
577 /* Nonzero if this is a call to a `volatile' function. */
578 int is_volatile = 0;
579 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
580 /* Define the boundary of the register parm stack space that needs to be
581 save, if any. */
582 int low_to_save = -1, high_to_save;
583 rtx save_area = 0; /* Place that it is saved */
584 #endif
586 #ifdef ACCUMULATE_OUTGOING_ARGS
587 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
588 char *initial_stack_usage_map = stack_usage_map;
589 int old_stack_arg_under_construction;
590 #endif
592 rtx old_stack_level = 0;
593 int old_pending_adj = 0;
594 int old_inhibit_defer_pop = inhibit_defer_pop;
595 rtx call_fusage = 0;
596 register tree p;
597 register int i, j;
599 /* The value of the function call can be put in a hard register. But
600 if -fcheck-memory-usage, code which invokes functions (and thus
601 damages some hard registers) can be inserted before using the value.
602 So, target is always a pseudo-register in that case. */
603 if (flag_check_memory_usage)
604 target = 0;
606 /* See if we can find a DECL-node for the actual function.
607 As a result, decide whether this is a call to an integrable function. */
609 p = TREE_OPERAND (exp, 0);
610 if (TREE_CODE (p) == ADDR_EXPR)
612 fndecl = TREE_OPERAND (p, 0);
613 if (TREE_CODE (fndecl) != FUNCTION_DECL)
614 fndecl = 0;
615 else
617 if (!flag_no_inline
618 && fndecl != current_function_decl
619 && DECL_INLINE (fndecl)
620 && DECL_SAVED_INSNS (fndecl)
621 && RTX_INTEGRATED_P (DECL_SAVED_INSNS (fndecl)))
622 is_integrable = 1;
623 else if (! TREE_ADDRESSABLE (fndecl))
625 /* In case this function later becomes inlinable,
626 record that there was already a non-inline call to it.
628 Use abstraction instead of setting TREE_ADDRESSABLE
629 directly. */
630 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
631 && optimize > 0)
633 warning_with_decl (fndecl, "can't inline call to `%s'");
634 warning ("called from here");
636 mark_addressable (fndecl);
639 if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
640 && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
641 is_const = 1;
643 if (TREE_THIS_VOLATILE (fndecl))
644 is_volatile = 1;
648 /* If we don't have specific function to call, see if we have a
649 constant or `noreturn' function from the type. */
650 if (fndecl == 0)
652 is_const = TREE_READONLY (TREE_TYPE (TREE_TYPE (p)));
653 is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
656 #ifdef REG_PARM_STACK_SPACE
657 #ifdef MAYBE_REG_PARM_STACK_SPACE
658 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
659 #else
660 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
661 #endif
662 #endif
664 #if defined(PUSH_ROUNDING) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
665 if (reg_parm_stack_space > 0)
666 must_preallocate = 1;
667 #endif
669 /* Warn if this value is an aggregate type,
670 regardless of which calling convention we are using for it. */
671 if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp)))
672 warning ("function call has aggregate value");
674 /* Set up a place to return a structure. */
676 /* Cater to broken compilers. */
677 if (aggregate_value_p (exp))
679 /* This call returns a big structure. */
680 is_const = 0;
682 #ifdef PCC_STATIC_STRUCT_RETURN
684 pcc_struct_value = 1;
685 /* Easier than making that case work right. */
686 if (is_integrable)
688 /* In case this is a static function, note that it has been
689 used. */
690 if (! TREE_ADDRESSABLE (fndecl))
691 mark_addressable (fndecl);
692 is_integrable = 0;
695 #else /* not PCC_STATIC_STRUCT_RETURN */
697 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
699 if (target && GET_CODE (target) == MEM)
700 structure_value_addr = XEXP (target, 0);
701 else
703 /* Assign a temporary to hold the value. */
704 tree d;
706 /* For variable-sized objects, we must be called with a target
707 specified. If we were to allocate space on the stack here,
708 we would have no way of knowing when to free it. */
710 if (struct_value_size < 0)
711 abort ();
713 /* This DECL is just something to feed to mark_addressable;
714 it doesn't get pushed. */
715 d = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (exp));
716 DECL_RTL (d) = assign_temp (TREE_TYPE (exp), 1, 0, 1);
717 mark_addressable (d);
718 structure_value_addr = XEXP (DECL_RTL (d), 0);
719 TREE_USED (d) = 1;
720 target = 0;
723 #endif /* not PCC_STATIC_STRUCT_RETURN */
726 /* If called function is inline, try to integrate it. */
728 if (is_integrable)
730 rtx temp;
731 #ifdef ACCUMULATE_OUTGOING_ARGS
732 rtx before_call = get_last_insn ();
733 #endif
735 temp = expand_inline_function (fndecl, actparms, target,
736 ignore, TREE_TYPE (exp),
737 structure_value_addr);
739 /* If inlining succeeded, return. */
740 if (temp != (rtx) (HOST_WIDE_INT) -1)
742 #ifdef ACCUMULATE_OUTGOING_ARGS
743 /* If the outgoing argument list must be preserved, push
744 the stack before executing the inlined function if it
745 makes any calls. */
747 for (i = reg_parm_stack_space - 1; i >= 0; i--)
748 if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
749 break;
751 if (stack_arg_under_construction || i >= 0)
753 rtx first_insn
754 = before_call ? NEXT_INSN (before_call) : get_insns ();
755 rtx insn, seq;
757 /* Look for a call in the inline function code.
758 If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is
759 nonzero then there is a call and it is not necessary
760 to scan the insns. */
762 if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0)
763 for (insn = first_insn; insn; insn = NEXT_INSN (insn))
764 if (GET_CODE (insn) == CALL_INSN)
765 break;
767 if (insn)
769 /* Reserve enough stack space so that the largest
770 argument list of any function call in the inline
771 function does not overlap the argument list being
772 evaluated. This is usually an overestimate because
773 allocate_dynamic_stack_space reserves space for an
774 outgoing argument list in addition to the requested
775 space, but there is no way to ask for stack space such
776 that an argument list of a certain length can be
777 safely constructed.
779 Add the stack space reserved for register arguments, if
780 any, in the inline function. What is really needed is the
781 largest value of reg_parm_stack_space in the inline
782 function, but that is not available. Using the current
783 value of reg_parm_stack_space is wrong, but gives
784 correct results on all supported machines. */
786 int adjust = (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl))
787 + reg_parm_stack_space);
789 start_sequence ();
790 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
791 allocate_dynamic_stack_space (GEN_INT (adjust),
792 NULL_RTX, BITS_PER_UNIT);
793 seq = get_insns ();
794 end_sequence ();
795 emit_insns_before (seq, first_insn);
796 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
799 #endif
801 /* If the result is equivalent to TARGET, return TARGET to simplify
802 checks in store_expr. They can be equivalent but not equal in the
803 case of a function that returns BLKmode. */
804 if (temp != target && rtx_equal_p (temp, target))
805 return target;
806 return temp;
809 /* If inlining failed, mark FNDECL as needing to be compiled
810 separately after all. If function was declared inline,
811 give a warning. */
812 if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline
813 && optimize > 0 && ! TREE_ADDRESSABLE (fndecl))
815 warning_with_decl (fndecl, "inlining failed in call to `%s'");
816 warning ("called from here");
818 mark_addressable (fndecl);
821 /* When calling a const function, we must pop the stack args right away,
822 so that the pop is deleted or moved with the call. */
823 if (is_const)
824 NO_DEFER_POP;
826 function_call_count++;
828 if (fndecl && DECL_NAME (fndecl))
829 name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
831 #if 0
832 /* Unless it's a call to a specific function that isn't alloca,
833 if it has one argument, we must assume it might be alloca. */
835 may_be_alloca
836 = (!(fndecl != 0 && strcmp (name, "alloca"))
837 && actparms != 0
838 && TREE_CHAIN (actparms) == 0);
839 #else
840 /* We assume that alloca will always be called by name. It
841 makes no sense to pass it as a pointer-to-function to
842 anything that does not understand its behavior. */
843 may_be_alloca
844 = (name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
845 && name[0] == 'a'
846 && ! strcmp (name, "alloca"))
847 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
848 && name[0] == '_'
849 && ! strcmp (name, "__builtin_alloca"))));
850 #endif
852 /* See if this is a call to a function that can return more than once
853 or a call to longjmp. */
855 returns_twice = 0;
856 is_longjmp = 0;
857 is_malloc = 0;
859 if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 17
860 /* Exclude functions not at the file scope, or not `extern',
861 since they are not the magic functions we would otherwise
862 think they are. */
863 && DECL_CONTEXT (fndecl) == NULL_TREE && TREE_PUBLIC (fndecl))
865 char *tname = name;
867 /* Disregard prefix _, __ or __x. */
868 if (name[0] == '_')
870 if (name[1] == '_' && name[2] == 'x')
871 tname += 3;
872 else if (name[1] == '_')
873 tname += 2;
874 else
875 tname += 1;
878 if (tname[0] == 's')
880 returns_twice
881 = ((tname[1] == 'e'
882 && (! strcmp (tname, "setjmp")
883 || ! strcmp (tname, "setjmp_syscall")))
884 || (tname[1] == 'i'
885 && ! strcmp (tname, "sigsetjmp"))
886 || (tname[1] == 'a'
887 && ! strcmp (tname, "savectx")));
888 if (tname[1] == 'i'
889 && ! strcmp (tname, "siglongjmp"))
890 is_longjmp = 1;
892 else if ((tname[0] == 'q' && tname[1] == 's'
893 && ! strcmp (tname, "qsetjmp"))
894 || (tname[0] == 'v' && tname[1] == 'f'
895 && ! strcmp (tname, "vfork")))
896 returns_twice = 1;
898 else if (tname[0] == 'l' && tname[1] == 'o'
899 && ! strcmp (tname, "longjmp"))
900 is_longjmp = 1;
901 /* XXX should have "malloc" attribute on functions instead
902 of recognizing them by name. */
903 else if (! strcmp (tname, "malloc")
904 || ! strcmp (tname, "calloc")
905 || ! strcmp (tname, "realloc")
906 /* Note use of NAME rather than TNAME here. These functions
907 are only reserved when preceded with __. */
908 || ! strcmp (name, "__vn") /* mangled __builtin_vec_new */
909 || ! strcmp (name, "__nw") /* mangled __builtin_new */
910 || ! strcmp (name, "__builtin_new")
911 || ! strcmp (name, "__builtin_vec_new"))
912 is_malloc = 1;
915 if (may_be_alloca)
916 current_function_calls_alloca = 1;
918 /* Don't let pending stack adjusts add up to too much.
919 Also, do all pending adjustments now
920 if there is any chance this might be a call to alloca. */
922 if (pending_stack_adjust >= 32
923 || (pending_stack_adjust > 0 && may_be_alloca))
924 do_pending_stack_adjust ();
926 /* Operand 0 is a pointer-to-function; get the type of the function. */
927 funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
928 if (TREE_CODE (funtype) != POINTER_TYPE)
929 abort ();
930 funtype = TREE_TYPE (funtype);
932 /* Push the temporary stack slot level so that we can free any temporaries
933 we make. */
934 push_temp_slots ();
936 /* Start updating where the next arg would go.
938 On some machines (such as the PA) indirect calls have a different
939 calling convention than normal calls. The last argument in
940 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
941 or not. */
942 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX, (fndecl == 0));
944 /* If struct_value_rtx is 0, it means pass the address
945 as if it were an extra parameter. */
946 if (structure_value_addr && struct_value_rtx == 0)
948 /* If structure_value_addr is a REG other than
949 virtual_outgoing_args_rtx, we can use always use it. If it
950 is not a REG, we must always copy it into a register.
951 If it is virtual_outgoing_args_rtx, we must copy it to another
952 register in some cases. */
953 rtx temp = (GET_CODE (structure_value_addr) != REG
954 #ifdef ACCUMULATE_OUTGOING_ARGS
955 || (stack_arg_under_construction
956 && structure_value_addr == virtual_outgoing_args_rtx)
957 #endif
958 ? copy_addr_to_reg (structure_value_addr)
959 : structure_value_addr);
961 actparms
962 = tree_cons (error_mark_node,
963 make_tree (build_pointer_type (TREE_TYPE (funtype)),
964 temp),
965 actparms);
966 structure_value_addr_parm = 1;
969 /* Count the arguments and set NUM_ACTUALS. */
970 for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
971 num_actuals = i;
973 /* Compute number of named args.
974 Normally, don't include the last named arg if anonymous args follow.
975 We do include the last named arg if STRICT_ARGUMENT_NAMING is nonzero.
976 (If no anonymous args follow, the result of list_length is actually
977 one too large. This is harmless.)
979 If SETUP_INCOMING_VARARGS is defined and STRICT_ARGUMENT_NAMING is zero,
980 this machine will be able to place unnamed args that were passed in
981 registers into the stack. So treat all args as named. This allows the
982 insns emitting for a specific argument list to be independent of the
983 function declaration.
985 If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable
986 way to pass unnamed args in registers, so we must force them into
987 memory. */
989 if ((STRICT_ARGUMENT_NAMING
990 #ifndef SETUP_INCOMING_VARARGS
991 || 1
992 #endif
994 && TYPE_ARG_TYPES (funtype) != 0)
995 n_named_args
996 = (list_length (TYPE_ARG_TYPES (funtype))
997 /* Don't include the last named arg. */
998 - (STRICT_ARGUMENT_NAMING ? 0 : 1)
999 /* Count the struct value address, if it is passed as a parm. */
1000 + structure_value_addr_parm);
1001 else
1002 /* If we know nothing, treat all args as named. */
1003 n_named_args = num_actuals;
1005 /* Make a vector to hold all the information about each arg. */
1006 args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
1007 bzero ((char *) args, num_actuals * sizeof (struct arg_data));
1009 args_size.constant = 0;
1010 args_size.var = 0;
1012 /* In this loop, we consider args in the order they are written.
1013 We fill up ARGS from the front or from the back if necessary
1014 so that in any case the first arg to be pushed ends up at the front. */
1016 #ifdef PUSH_ARGS_REVERSED
1017 i = num_actuals - 1, inc = -1;
1018 /* In this case, must reverse order of args
1019 so that we compute and push the last arg first. */
1020 #else
1021 i = 0, inc = 1;
1022 #endif
1024 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1025 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
1027 tree type = TREE_TYPE (TREE_VALUE (p));
1028 int unsignedp;
1029 enum machine_mode mode;
1031 args[i].tree_value = TREE_VALUE (p);
1033 /* Replace erroneous argument with constant zero. */
1034 if (type == error_mark_node || TYPE_SIZE (type) == 0)
1035 args[i].tree_value = integer_zero_node, type = integer_type_node;
1037 /* If TYPE is a transparent union, pass things the way we would
1038 pass the first field of the union. We have already verified that
1039 the modes are the same. */
1040 if (TYPE_TRANSPARENT_UNION (type))
1041 type = TREE_TYPE (TYPE_FIELDS (type));
1043 /* Decide where to pass this arg.
1045 args[i].reg is nonzero if all or part is passed in registers.
1047 args[i].partial is nonzero if part but not all is passed in registers,
1048 and the exact value says how many words are passed in registers.
1050 args[i].pass_on_stack is nonzero if the argument must at least be
1051 computed on the stack. It may then be loaded back into registers
1052 if args[i].reg is nonzero.
1054 These decisions are driven by the FUNCTION_... macros and must agree
1055 with those made by function.c. */
1057 /* See if this argument should be passed by invisible reference. */
1058 if ((TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1059 && contains_placeholder_p (TYPE_SIZE (type)))
1060 || TREE_ADDRESSABLE (type)
1061 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1062 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, TYPE_MODE (type),
1063 type, argpos < n_named_args)
1064 #endif
1067 /* If we're compiling a thunk, pass through invisible
1068 references instead of making a copy. */
1069 if (current_function_is_thunk
1070 #ifdef FUNCTION_ARG_CALLEE_COPIES
1071 || (FUNCTION_ARG_CALLEE_COPIES (args_so_far, TYPE_MODE (type),
1072 type, argpos < n_named_args)
1073 /* If it's in a register, we must make a copy of it too. */
1074 /* ??? Is this a sufficient test? Is there a better one? */
1075 && !(TREE_CODE (args[i].tree_value) == VAR_DECL
1076 && REG_P (DECL_RTL (args[i].tree_value)))
1077 && ! TREE_ADDRESSABLE (type))
1078 #endif
1081 args[i].tree_value = build1 (ADDR_EXPR,
1082 build_pointer_type (type),
1083 args[i].tree_value);
1084 type = build_pointer_type (type);
1086 else
1088 /* We make a copy of the object and pass the address to the
1089 function being called. */
1090 rtx copy;
1092 if (TYPE_SIZE (type) == 0
1093 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
1094 || (flag_stack_check && ! STACK_CHECK_BUILTIN
1095 && (TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0
1096 || (TREE_INT_CST_LOW (TYPE_SIZE (type))
1097 > STACK_CHECK_MAX_VAR_SIZE * BITS_PER_UNIT))))
1099 /* This is a variable-sized object. Make space on the stack
1100 for it. */
1101 rtx size_rtx = expr_size (TREE_VALUE (p));
1103 if (old_stack_level == 0)
1105 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1106 old_pending_adj = pending_stack_adjust;
1107 pending_stack_adjust = 0;
1110 copy = gen_rtx_MEM (BLKmode,
1111 allocate_dynamic_stack_space (size_rtx,
1112 NULL_RTX,
1113 TYPE_ALIGN (type)));
1115 else
1117 int size = int_size_in_bytes (type);
1118 copy = assign_stack_temp (TYPE_MODE (type), size, 0);
1121 MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
1123 store_expr (args[i].tree_value, copy, 0);
1124 is_const = 0;
1126 args[i].tree_value = build1 (ADDR_EXPR,
1127 build_pointer_type (type),
1128 make_tree (type, copy));
1129 type = build_pointer_type (type);
1133 mode = TYPE_MODE (type);
1134 unsignedp = TREE_UNSIGNED (type);
1136 #ifdef PROMOTE_FUNCTION_ARGS
1137 mode = promote_mode (type, mode, &unsignedp, 1);
1138 #endif
1140 args[i].unsignedp = unsignedp;
1141 args[i].mode = mode;
1142 args[i].reg = FUNCTION_ARG (args_so_far, mode, type,
1143 argpos < n_named_args);
1144 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1145 if (args[i].reg)
1146 args[i].partial
1147 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, type,
1148 argpos < n_named_args);
1149 #endif
1151 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
1153 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1154 it means that we are to pass this arg in the register(s) designated
1155 by the PARALLEL, but also to pass it in the stack. */
1156 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1157 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1158 args[i].pass_on_stack = 1;
1160 /* If this is an addressable type, we must preallocate the stack
1161 since we must evaluate the object into its final location.
1163 If this is to be passed in both registers and the stack, it is simpler
1164 to preallocate. */
1165 if (TREE_ADDRESSABLE (type)
1166 || (args[i].pass_on_stack && args[i].reg != 0))
1167 must_preallocate = 1;
1169 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1170 we cannot consider this function call constant. */
1171 if (TREE_ADDRESSABLE (type))
1172 is_const = 0;
1174 /* Compute the stack-size of this argument. */
1175 if (args[i].reg == 0 || args[i].partial != 0
1176 || reg_parm_stack_space > 0
1177 || args[i].pass_on_stack)
1178 locate_and_pad_parm (mode, type,
1179 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1181 #else
1182 args[i].reg != 0,
1183 #endif
1184 fndecl, &args_size, &args[i].offset,
1185 &args[i].size);
1187 #ifndef ARGS_GROW_DOWNWARD
1188 args[i].slot_offset = args_size;
1189 #endif
1191 /* If a part of the arg was put into registers,
1192 don't include that part in the amount pushed. */
1193 if (reg_parm_stack_space == 0 && ! args[i].pass_on_stack)
1194 args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1195 / (PARM_BOUNDARY / BITS_PER_UNIT)
1196 * (PARM_BOUNDARY / BITS_PER_UNIT));
1198 /* Update ARGS_SIZE, the total stack space for args so far. */
1200 args_size.constant += args[i].size.constant;
1201 if (args[i].size.var)
1203 ADD_PARM_SIZE (args_size, args[i].size.var);
1206 /* Since the slot offset points to the bottom of the slot,
1207 we must record it after incrementing if the args grow down. */
1208 #ifdef ARGS_GROW_DOWNWARD
1209 args[i].slot_offset = args_size;
1211 args[i].slot_offset.constant = -args_size.constant;
1212 if (args_size.var)
1214 SUB_PARM_SIZE (args[i].slot_offset, args_size.var);
1216 #endif
1218 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1219 have been used, etc. */
1221 FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type,
1222 argpos < n_named_args);
1225 #ifdef FINAL_REG_PARM_STACK_SPACE
1226 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
1227 args_size.var);
1228 #endif
1230 /* Compute the actual size of the argument block required. The variable
1231 and constant sizes must be combined, the size may have to be rounded,
1232 and there may be a minimum required size. */
1234 original_args_size = args_size;
1235 if (args_size.var)
1237 /* If this function requires a variable-sized argument list, don't try to
1238 make a cse'able block for this call. We may be able to do this
1239 eventually, but it is too complicated to keep track of what insns go
1240 in the cse'able block and which don't. */
1242 is_const = 0;
1243 must_preallocate = 1;
1245 args_size.var = ARGS_SIZE_TREE (args_size);
1246 args_size.constant = 0;
1248 #ifdef STACK_BOUNDARY
1249 if (STACK_BOUNDARY != BITS_PER_UNIT)
1250 args_size.var = round_up (args_size.var, STACK_BYTES);
1251 #endif
1253 if (reg_parm_stack_space > 0)
1255 args_size.var
1256 = size_binop (MAX_EXPR, args_size.var,
1257 size_int (reg_parm_stack_space));
1259 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1260 /* The area corresponding to register parameters is not to count in
1261 the size of the block we need. So make the adjustment. */
1262 args_size.var
1263 = size_binop (MINUS_EXPR, args_size.var,
1264 size_int (reg_parm_stack_space));
1265 #endif
1268 else
1270 #ifdef STACK_BOUNDARY
1271 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
1272 / STACK_BYTES) * STACK_BYTES);
1273 #endif
1275 args_size.constant = MAX (args_size.constant,
1276 reg_parm_stack_space);
1278 #ifdef MAYBE_REG_PARM_STACK_SPACE
1279 if (reg_parm_stack_space == 0)
1280 args_size.constant = 0;
1281 #endif
1283 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1284 args_size.constant -= reg_parm_stack_space;
1285 #endif
1288 /* See if we have or want to preallocate stack space.
1290 If we would have to push a partially-in-regs parm
1291 before other stack parms, preallocate stack space instead.
1293 If the size of some parm is not a multiple of the required stack
1294 alignment, we must preallocate.
1296 If the total size of arguments that would otherwise create a copy in
1297 a temporary (such as a CALL) is more than half the total argument list
1298 size, preallocation is faster.
1300 Another reason to preallocate is if we have a machine (like the m88k)
1301 where stack alignment is required to be maintained between every
1302 pair of insns, not just when the call is made. However, we assume here
1303 that such machines either do not have push insns (and hence preallocation
1304 would occur anyway) or the problem is taken care of with
1305 PUSH_ROUNDING. */
1307 if (! must_preallocate)
1309 int partial_seen = 0;
1310 int copy_to_evaluate_size = 0;
1312 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1314 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1315 partial_seen = 1;
1316 else if (partial_seen && args[i].reg == 0)
1317 must_preallocate = 1;
1319 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1320 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1321 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1322 || TREE_CODE (args[i].tree_value) == COND_EXPR
1323 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1324 copy_to_evaluate_size
1325 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1328 if (copy_to_evaluate_size * 2 >= args_size.constant
1329 && args_size.constant > 0)
1330 must_preallocate = 1;
1333 /* If the structure value address will reference the stack pointer, we must
1334 stabilize it. We don't need to do this if we know that we are not going
1335 to adjust the stack pointer in processing this call. */
1337 if (structure_value_addr
1338 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
1339 || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr))
1340 && (args_size.var
1341 #ifndef ACCUMULATE_OUTGOING_ARGS
1342 || args_size.constant
1343 #endif
1345 structure_value_addr = copy_to_reg (structure_value_addr);
1347 /* If this function call is cse'able, precompute all the parameters.
1348 Note that if the parameter is constructed into a temporary, this will
1349 cause an additional copy because the parameter will be constructed
1350 into a temporary location and then copied into the outgoing arguments.
1351 If a parameter contains a call to alloca and this function uses the
1352 stack, precompute the parameter. */
1354 /* If we preallocated the stack space, and some arguments must be passed
1355 on the stack, then we must precompute any parameter which contains a
1356 function call which will store arguments on the stack.
1357 Otherwise, evaluating the parameter may clobber previous parameters
1358 which have already been stored into the stack. */
1360 for (i = 0; i < num_actuals; i++)
1361 if (is_const
1362 || ((args_size.var != 0 || args_size.constant != 0)
1363 && calls_function (args[i].tree_value, 1))
1364 || (must_preallocate && (args_size.var != 0 || args_size.constant != 0)
1365 && calls_function (args[i].tree_value, 0)))
1367 /* If this is an addressable type, we cannot pre-evaluate it. */
1368 if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))
1369 abort ();
1371 push_temp_slots ();
1373 args[i].initial_value = args[i].value
1374 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1376 preserve_temp_slots (args[i].value);
1377 pop_temp_slots ();
1379 /* ANSI doesn't require a sequence point here,
1380 but PCC has one, so this will avoid some problems. */
1381 emit_queue ();
1383 args[i].initial_value = args[i].value
1384 = protect_from_queue (args[i].initial_value, 0);
1386 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != args[i].mode)
1387 args[i].value
1388 = convert_modes (args[i].mode,
1389 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1390 args[i].value, args[i].unsignedp);
1393 /* Now we are about to start emitting insns that can be deleted
1394 if a libcall is deleted. */
1395 if (is_const || is_malloc)
1396 start_sequence ();
1398 /* If we have no actual push instructions, or shouldn't use them,
1399 make space for all args right now. */
1401 if (args_size.var != 0)
1403 if (old_stack_level == 0)
1405 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1406 old_pending_adj = pending_stack_adjust;
1407 pending_stack_adjust = 0;
1408 #ifdef ACCUMULATE_OUTGOING_ARGS
1409 /* stack_arg_under_construction says whether a stack arg is
1410 being constructed at the old stack level. Pushing the stack
1411 gets a clean outgoing argument block. */
1412 old_stack_arg_under_construction = stack_arg_under_construction;
1413 stack_arg_under_construction = 0;
1414 #endif
1416 argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
1418 else
1420 /* Note that we must go through the motions of allocating an argument
1421 block even if the size is zero because we may be storing args
1422 in the area reserved for register arguments, which may be part of
1423 the stack frame. */
1425 int needed = args_size.constant;
1427 /* Store the maximum argument space used. It will be pushed by
1428 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
1429 checking). */
1431 if (needed > current_function_outgoing_args_size)
1432 current_function_outgoing_args_size = needed;
1434 if (must_preallocate)
1436 #ifdef ACCUMULATE_OUTGOING_ARGS
1437 /* Since the stack pointer will never be pushed, it is possible for
1438 the evaluation of a parm to clobber something we have already
1439 written to the stack. Since most function calls on RISC machines
1440 do not use the stack, this is uncommon, but must work correctly.
1442 Therefore, we save any area of the stack that was already written
1443 and that we are using. Here we set up to do this by making a new
1444 stack usage map from the old one. The actual save will be done
1445 by store_one_arg.
1447 Another approach might be to try to reorder the argument
1448 evaluations to avoid this conflicting stack usage. */
1450 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1451 /* Since we will be writing into the entire argument area, the
1452 map must be allocated for its entire size, not just the part that
1453 is the responsibility of the caller. */
1454 needed += reg_parm_stack_space;
1455 #endif
1457 #ifdef ARGS_GROW_DOWNWARD
1458 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1459 needed + 1);
1460 #else
1461 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1462 needed);
1463 #endif
1464 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
1466 if (initial_highest_arg_in_use)
1467 bcopy (initial_stack_usage_map, stack_usage_map,
1468 initial_highest_arg_in_use);
1470 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
1471 bzero (&stack_usage_map[initial_highest_arg_in_use],
1472 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
1473 needed = 0;
1475 /* The address of the outgoing argument list must not be copied to a
1476 register here, because argblock would be left pointing to the
1477 wrong place after the call to allocate_dynamic_stack_space below.
1480 argblock = virtual_outgoing_args_rtx;
1482 #else /* not ACCUMULATE_OUTGOING_ARGS */
1483 if (inhibit_defer_pop == 0)
1485 /* Try to reuse some or all of the pending_stack_adjust
1486 to get this space. Maybe we can avoid any pushing. */
1487 if (needed > pending_stack_adjust)
1489 needed -= pending_stack_adjust;
1490 pending_stack_adjust = 0;
1492 else
1494 pending_stack_adjust -= needed;
1495 needed = 0;
1498 /* Special case this because overhead of `push_block' in this
1499 case is non-trivial. */
1500 if (needed == 0)
1501 argblock = virtual_outgoing_args_rtx;
1502 else
1503 argblock = push_block (GEN_INT (needed), 0, 0);
1505 /* We only really need to call `copy_to_reg' in the case where push
1506 insns are going to be used to pass ARGBLOCK to a function
1507 call in ARGS. In that case, the stack pointer changes value
1508 from the allocation point to the call point, and hence
1509 the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
1510 But might as well always do it. */
1511 argblock = copy_to_reg (argblock);
1512 #endif /* not ACCUMULATE_OUTGOING_ARGS */
1516 #ifdef ACCUMULATE_OUTGOING_ARGS
1517 /* The save/restore code in store_one_arg handles all cases except one:
1518 a constructor call (including a C function returning a BLKmode struct)
1519 to initialize an argument. */
1520 if (stack_arg_under_construction)
1522 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1523 rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
1524 #else
1525 rtx push_size = GEN_INT (args_size.constant);
1526 #endif
1527 if (old_stack_level == 0)
1529 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1530 old_pending_adj = pending_stack_adjust;
1531 pending_stack_adjust = 0;
1532 /* stack_arg_under_construction says whether a stack arg is
1533 being constructed at the old stack level. Pushing the stack
1534 gets a clean outgoing argument block. */
1535 old_stack_arg_under_construction = stack_arg_under_construction;
1536 stack_arg_under_construction = 0;
1537 /* Make a new map for the new argument list. */
1538 stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
1539 bzero (stack_usage_map, highest_outgoing_arg_in_use);
1540 highest_outgoing_arg_in_use = 0;
1542 allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
1544 /* If argument evaluation might modify the stack pointer, copy the
1545 address of the argument list to a register. */
1546 for (i = 0; i < num_actuals; i++)
1547 if (args[i].pass_on_stack)
1549 argblock = copy_addr_to_reg (argblock);
1550 break;
1552 #endif
1555 /* If we preallocated stack space, compute the address of each argument.
1556 We need not ensure it is a valid memory address here; it will be
1557 validized when it is used. */
1558 if (argblock)
1560 rtx arg_reg = argblock;
1561 int arg_offset = 0;
1563 if (GET_CODE (argblock) == PLUS)
1564 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1566 for (i = 0; i < num_actuals; i++)
1568 rtx offset = ARGS_SIZE_RTX (args[i].offset);
1569 rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1570 rtx addr;
1572 /* Skip this parm if it will not be passed on the stack. */
1573 if (! args[i].pass_on_stack && args[i].reg != 0)
1574 continue;
1576 if (GET_CODE (offset) == CONST_INT)
1577 addr = plus_constant (arg_reg, INTVAL (offset));
1578 else
1579 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1581 addr = plus_constant (addr, arg_offset);
1582 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1583 MEM_IN_STRUCT_P (args[i].stack)
1584 = AGGREGATE_TYPE_P (TREE_TYPE (args[i].tree_value));
1586 if (GET_CODE (slot_offset) == CONST_INT)
1587 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1588 else
1589 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1591 addr = plus_constant (addr, arg_offset);
1592 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1596 #ifdef PUSH_ARGS_REVERSED
1597 #ifdef STACK_BOUNDARY
1598 /* If we push args individually in reverse order, perform stack alignment
1599 before the first push (the last arg). */
1600 if (argblock == 0)
1601 anti_adjust_stack (GEN_INT (args_size.constant
1602 - original_args_size.constant));
1603 #endif
1604 #endif
1606 /* Don't try to defer pops if preallocating, not even from the first arg,
1607 since ARGBLOCK probably refers to the SP. */
1608 if (argblock)
1609 NO_DEFER_POP;
1611 /* Get the function to call, in the form of RTL. */
1612 if (fndecl)
1614 /* If this is the first use of the function, see if we need to
1615 make an external definition for it. */
1616 if (! TREE_USED (fndecl))
1618 assemble_external (fndecl);
1619 TREE_USED (fndecl) = 1;
1622 /* Get a SYMBOL_REF rtx for the function address. */
1623 funexp = XEXP (DECL_RTL (fndecl), 0);
1625 else
1626 /* Generate an rtx (probably a pseudo-register) for the address. */
1628 push_temp_slots ();
1629 funexp = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1630 pop_temp_slots (); /* FUNEXP can't be BLKmode */
1632 /* Check the function is executable. */
1633 if (flag_check_memory_usage)
1634 emit_library_call (chkr_check_exec_libfunc, 1,
1635 VOIDmode, 1,
1636 funexp, ptr_mode);
1637 emit_queue ();
1640 /* Figure out the register where the value, if any, will come back. */
1641 valreg = 0;
1642 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
1643 && ! structure_value_addr)
1645 if (pcc_struct_value)
1646 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
1647 fndecl);
1648 else
1649 valreg = hard_function_value (TREE_TYPE (exp), fndecl);
1652 /* Precompute all register parameters. It isn't safe to compute anything
1653 once we have started filling any specific hard regs. */
1654 reg_parm_seen = 0;
1655 for (i = 0; i < num_actuals; i++)
1656 if (args[i].reg != 0 && ! args[i].pass_on_stack)
1658 reg_parm_seen = 1;
1660 if (args[i].value == 0)
1662 push_temp_slots ();
1663 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
1664 VOIDmode, 0);
1665 preserve_temp_slots (args[i].value);
1666 pop_temp_slots ();
1668 /* ANSI doesn't require a sequence point here,
1669 but PCC has one, so this will avoid some problems. */
1670 emit_queue ();
1673 /* If we are to promote the function arg to a wider mode,
1674 do it now. */
1676 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
1677 args[i].value
1678 = convert_modes (args[i].mode,
1679 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
1680 args[i].value, args[i].unsignedp);
1682 /* If the value is expensive, and we are inside an appropriately
1683 short loop, put the value into a pseudo and then put the pseudo
1684 into the hard reg.
1686 For small register classes, also do this if this call uses
1687 register parameters. This is to avoid reload conflicts while
1688 loading the parameters registers. */
1690 if ((! (GET_CODE (args[i].value) == REG
1691 || (GET_CODE (args[i].value) == SUBREG
1692 && GET_CODE (SUBREG_REG (args[i].value)) == REG)))
1693 && args[i].mode != BLKmode
1694 && rtx_cost (args[i].value, SET) > 2
1695 && ((SMALL_REGISTER_CLASSES && reg_parm_seen)
1696 || preserve_subexpressions_p ()))
1697 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
1700 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1702 /* The argument list is the property of the called routine and it
1703 may clobber it. If the fixed area has been used for previous
1704 parameters, we must save and restore it.
1706 Here we compute the boundary of the that needs to be saved, if any. */
1708 #ifdef ARGS_GROW_DOWNWARD
1709 for (i = 0; i < reg_parm_stack_space + 1; i++)
1710 #else
1711 for (i = 0; i < reg_parm_stack_space; i++)
1712 #endif
1714 if (i >= highest_outgoing_arg_in_use
1715 || stack_usage_map[i] == 0)
1716 continue;
1718 if (low_to_save == -1)
1719 low_to_save = i;
1721 high_to_save = i;
1724 if (low_to_save >= 0)
1726 int num_to_save = high_to_save - low_to_save + 1;
1727 enum machine_mode save_mode
1728 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
1729 rtx stack_area;
1731 /* If we don't have the required alignment, must do this in BLKmode. */
1732 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
1733 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
1734 save_mode = BLKmode;
1736 #ifdef ARGS_GROW_DOWNWARD
1737 stack_area = gen_rtx_MEM (save_mode,
1738 memory_address (save_mode,
1739 plus_constant (argblock,
1740 - high_to_save)));
1741 #else
1742 stack_area = gen_rtx_MEM (save_mode,
1743 memory_address (save_mode,
1744 plus_constant (argblock,
1745 low_to_save)));
1746 #endif
1747 if (save_mode == BLKmode)
1749 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
1750 MEM_IN_STRUCT_P (save_area) = 0;
1751 emit_block_move (validize_mem (save_area), stack_area,
1752 GEN_INT (num_to_save),
1753 PARM_BOUNDARY / BITS_PER_UNIT);
1755 else
1757 save_area = gen_reg_rtx (save_mode);
1758 emit_move_insn (save_area, stack_area);
1761 #endif
1764 /* Now store (and compute if necessary) all non-register parms.
1765 These come before register parms, since they can require block-moves,
1766 which could clobber the registers used for register parms.
1767 Parms which have partial registers are not stored here,
1768 but we do preallocate space here if they want that. */
1770 for (i = 0; i < num_actuals; i++)
1771 if (args[i].reg == 0 || args[i].pass_on_stack)
1772 store_one_arg (&args[i], argblock, may_be_alloca,
1773 args_size.var != 0, fndecl, reg_parm_stack_space);
1775 /* If we have a parm that is passed in registers but not in memory
1776 and whose alignment does not permit a direct copy into registers,
1777 make a group of pseudos that correspond to each register that we
1778 will later fill. */
1780 if (STRICT_ALIGNMENT)
1781 for (i = 0; i < num_actuals; i++)
1782 if (args[i].reg != 0 && ! args[i].pass_on_stack
1783 && args[i].mode == BLKmode
1784 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
1785 < MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
1787 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1788 int big_endian_correction = 0;
1790 args[i].n_aligned_regs
1791 = args[i].partial ? args[i].partial
1792 : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
1794 args[i].aligned_regs = (rtx *) alloca (sizeof (rtx)
1795 * args[i].n_aligned_regs);
1797 /* Structures smaller than a word are aligned to the least
1798 significant byte (to the right). On a BYTES_BIG_ENDIAN machine,
1799 this means we must skip the empty high order bytes when
1800 calculating the bit offset. */
1801 if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD)
1802 big_endian_correction = (BITS_PER_WORD - (bytes * BITS_PER_UNIT));
1804 for (j = 0; j < args[i].n_aligned_regs; j++)
1806 rtx reg = gen_reg_rtx (word_mode);
1807 rtx word = operand_subword_force (args[i].value, j, BLKmode);
1808 int bitsize = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
1809 int bitpos;
1811 args[i].aligned_regs[j] = reg;
1813 /* Clobber REG and move each partword into it. Ensure we don't
1814 go past the end of the structure. Note that the loop below
1815 works because we've already verified that padding
1816 and endianness are compatible.
1818 We use to emit a clobber here but that doesn't let later
1819 passes optimize the instructions we emit. By storing 0 into
1820 the register later passes know the first AND to zero out the
1821 bitfield being set in the register is unnecessary. The store
1822 of 0 will be deleted as will at least the first AND. */
1824 emit_move_insn (reg, const0_rtx);
1826 for (bitpos = 0;
1827 bitpos < BITS_PER_WORD && bytes > 0;
1828 bitpos += bitsize, bytes -= bitsize / BITS_PER_UNIT)
1830 int xbitpos = bitpos + big_endian_correction;
1832 store_bit_field (reg, bitsize, xbitpos, word_mode,
1833 extract_bit_field (word, bitsize, bitpos, 1,
1834 NULL_RTX, word_mode,
1835 word_mode,
1836 bitsize / BITS_PER_UNIT,
1837 BITS_PER_WORD),
1838 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
1843 /* Now store any partially-in-registers parm.
1844 This is the last place a block-move can happen. */
1845 if (reg_parm_seen)
1846 for (i = 0; i < num_actuals; i++)
1847 if (args[i].partial != 0 && ! args[i].pass_on_stack)
1848 store_one_arg (&args[i], argblock, may_be_alloca,
1849 args_size.var != 0, fndecl, reg_parm_stack_space);
1851 #ifndef PUSH_ARGS_REVERSED
1852 #ifdef STACK_BOUNDARY
1853 /* If we pushed args in forward order, perform stack alignment
1854 after pushing the last arg. */
1855 if (argblock == 0)
1856 anti_adjust_stack (GEN_INT (args_size.constant
1857 - original_args_size.constant));
1858 #endif
1859 #endif
1861 /* If register arguments require space on the stack and stack space
1862 was not preallocated, allocate stack space here for arguments
1863 passed in registers. */
1864 #if ! defined(ACCUMULATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
1865 if (must_preallocate == 0 && reg_parm_stack_space > 0)
1866 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
1867 #endif
1869 /* Pass the function the address in which to return a structure value. */
1870 if (structure_value_addr && ! structure_value_addr_parm)
1872 emit_move_insn (struct_value_rtx,
1873 force_reg (Pmode,
1874 force_operand (structure_value_addr,
1875 NULL_RTX)));
1877 /* Mark the memory for the aggregate as write-only. */
1878 if (flag_check_memory_usage)
1879 emit_library_call (chkr_set_right_libfunc, 1,
1880 VOIDmode, 3,
1881 structure_value_addr, ptr_mode,
1882 GEN_INT (struct_value_size), TYPE_MODE (sizetype),
1883 GEN_INT (MEMORY_USE_WO),
1884 TYPE_MODE (integer_type_node));
1886 if (GET_CODE (struct_value_rtx) == REG)
1887 use_reg (&call_fusage, struct_value_rtx);
1890 funexp = prepare_call_address (funexp, fndecl, &call_fusage, reg_parm_seen);
1892 /* Now do the register loads required for any wholly-register parms or any
1893 parms which are passed both on the stack and in a register. Their
1894 expressions were already evaluated.
1896 Mark all register-parms as living through the call, putting these USE
1897 insns in the CALL_INSN_FUNCTION_USAGE field. */
1899 #ifdef LOAD_ARGS_REVERSED
1900 for (i = num_actuals - 1; i >= 0; i--)
1901 #else
1902 for (i = 0; i < num_actuals; i++)
1903 #endif
1905 rtx reg = args[i].reg;
1906 int partial = args[i].partial;
1907 int nregs;
1909 if (reg)
1911 /* Set to non-negative if must move a word at a time, even if just
1912 one word (e.g, partial == 1 && mode == DFmode). Set to -1 if
1913 we just use a normal move insn. This value can be zero if the
1914 argument is a zero size structure with no fields. */
1915 nregs = (partial ? partial
1916 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1917 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1918 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1919 : -1));
1921 /* Handle calls that pass values in multiple non-contiguous
1922 locations. The Irix 6 ABI has examples of this. */
1924 if (GET_CODE (reg) == PARALLEL)
1925 emit_group_load (reg, args[i].value);
1927 /* If simple case, just do move. If normal partial, store_one_arg
1928 has already loaded the register for us. In all other cases,
1929 load the register(s) from memory. */
1931 else if (nregs == -1)
1932 emit_move_insn (reg, args[i].value);
1934 /* If we have pre-computed the values to put in the registers in
1935 the case of non-aligned structures, copy them in now. */
1937 else if (args[i].n_aligned_regs != 0)
1938 for (j = 0; j < args[i].n_aligned_regs; j++)
1939 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
1940 args[i].aligned_regs[j]);
1942 else if (partial == 0 || args[i].pass_on_stack)
1943 move_block_to_reg (REGNO (reg),
1944 validize_mem (args[i].value), nregs,
1945 args[i].mode);
1947 /* Handle calls that pass values in multiple non-contiguous
1948 locations. The Irix 6 ABI has examples of this. */
1949 if (GET_CODE (reg) == PARALLEL)
1950 use_group_regs (&call_fusage, reg);
1951 else if (nregs == -1)
1952 use_reg (&call_fusage, reg);
1953 else
1954 use_regs (&call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs);
1958 /* Perform postincrements before actually calling the function. */
1959 emit_queue ();
1961 /* All arguments and registers used for the call must be set up by now! */
1963 /* Generate the actual call instruction. */
1964 emit_call_1 (funexp, fndecl, funtype, args_size.constant, struct_value_size,
1965 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
1966 valreg, old_inhibit_defer_pop, call_fusage, is_const);
1968 /* If call is cse'able, make appropriate pair of reg-notes around it.
1969 Test valreg so we don't crash; may safely ignore `const'
1970 if return type is void. Disable for PARALLEL return values, because
1971 we have no way to move such values into a pseudo register. */
1972 if (is_const && valreg != 0 && GET_CODE (valreg) != PARALLEL)
1974 rtx note = 0;
1975 rtx temp = gen_reg_rtx (GET_MODE (valreg));
1976 rtx insns;
1978 /* Mark the return value as a pointer if needed. */
1979 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
1981 tree pointed_to = TREE_TYPE (TREE_TYPE (exp));
1982 mark_reg_pointer (temp, TYPE_ALIGN (pointed_to) / BITS_PER_UNIT);
1985 /* Construct an "equal form" for the value which mentions all the
1986 arguments in order as well as the function name. */
1987 #ifdef PUSH_ARGS_REVERSED
1988 for (i = 0; i < num_actuals; i++)
1989 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
1990 #else
1991 for (i = num_actuals - 1; i >= 0; i--)
1992 note = gen_rtx_EXPR_LIST (VOIDmode, args[i].initial_value, note);
1993 #endif
1994 note = gen_rtx_EXPR_LIST (VOIDmode, funexp, note);
1996 insns = get_insns ();
1997 end_sequence ();
1999 emit_libcall_block (insns, temp, valreg, note);
2001 valreg = temp;
2003 else if (is_const)
2005 /* Otherwise, just write out the sequence without a note. */
2006 rtx insns = get_insns ();
2008 end_sequence ();
2009 emit_insns (insns);
2011 else if (is_malloc)
2013 rtx temp = gen_reg_rtx (GET_MODE (valreg));
2014 rtx last, insns;
2016 /* The return value from a malloc-like function is a pointer. */
2017 if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE)
2018 mark_reg_pointer (temp, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2020 emit_move_insn (temp, valreg);
2022 /* The return value from a malloc-like function can not alias
2023 anything else. */
2024 last = get_last_insn ();
2025 REG_NOTES (last) =
2026 gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));
2028 /* Write out the sequence. */
2029 insns = get_insns ();
2030 end_sequence ();
2031 emit_insns (insns);
2032 valreg = temp;
2035 /* For calls to `setjmp', etc., inform flow.c it should complain
2036 if nonvolatile values are live. */
2038 if (returns_twice)
2040 emit_note (name, NOTE_INSN_SETJMP);
2041 current_function_calls_setjmp = 1;
2044 if (is_longjmp)
2045 current_function_calls_longjmp = 1;
2047 /* Notice functions that cannot return.
2048 If optimizing, insns emitted below will be dead.
2049 If not optimizing, they will exist, which is useful
2050 if the user uses the `return' command in the debugger. */
2052 if (is_volatile || is_longjmp)
2053 emit_barrier ();
2055 /* If value type not void, return an rtx for the value. */
2057 /* If there are cleanups to be called, don't use a hard reg as target.
2058 We need to double check this and see if it matters anymore. */
2059 if (any_pending_cleanups (1)
2060 && target && REG_P (target)
2061 && REGNO (target) < FIRST_PSEUDO_REGISTER)
2062 target = 0;
2064 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
2065 || ignore)
2067 target = const0_rtx;
2069 else if (structure_value_addr)
2071 if (target == 0 || GET_CODE (target) != MEM)
2073 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2074 memory_address (TYPE_MODE (TREE_TYPE (exp)),
2075 structure_value_addr));
2076 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2079 else if (pcc_struct_value)
2081 /* This is the special C++ case where we need to
2082 know what the true target was. We take care to
2083 never use this value more than once in one expression. */
2084 target = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
2085 copy_to_reg (valreg));
2086 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2088 /* Handle calls that return values in multiple non-contiguous locations.
2089 The Irix 6 ABI has examples of this. */
2090 else if (GET_CODE (valreg) == PARALLEL)
2092 if (target == 0)
2094 int bytes = int_size_in_bytes (TREE_TYPE (exp));
2095 target = assign_stack_temp (TYPE_MODE (TREE_TYPE (exp)), bytes, 0);
2096 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2097 preserve_temp_slots (target);
2100 emit_group_store (target, valreg);
2102 else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
2103 && GET_MODE (target) == GET_MODE (valreg))
2104 /* TARGET and VALREG cannot be equal at this point because the latter
2105 would not have REG_FUNCTION_VALUE_P true, while the former would if
2106 it were referring to the same register.
2108 If they refer to the same register, this move will be a no-op, except
2109 when function inlining is being done. */
2110 emit_move_insn (target, valreg);
2111 else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
2113 /* Some machines (the PA for example) want to return all small
2114 structures in registers regardless of the structure's alignment.
2116 Deal with them explicitly by copying from the return registers
2117 into the target MEM locations. */
2118 int bytes = int_size_in_bytes (TREE_TYPE (exp));
2119 rtx src = NULL, dst = NULL;
2120 int bitsize = MIN (TYPE_ALIGN (TREE_TYPE (exp)), BITS_PER_WORD);
2121 int bitpos, xbitpos, big_endian_correction = 0;
2123 if (target == 0)
2125 target = assign_stack_temp (BLKmode, bytes, 0);
2126 MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp));
2127 preserve_temp_slots (target);
2130 /* This code assumes valreg is at least a full word. If it isn't,
2131 copy it into a new pseudo which is a full word. */
2132 if (GET_MODE (valreg) != BLKmode
2133 && GET_MODE_SIZE (GET_MODE (valreg)) < UNITS_PER_WORD)
2134 valreg = convert_to_mode (word_mode, valreg,
2135 TREE_UNSIGNED (TREE_TYPE (exp)));
2137 /* Structures whose size is not a multiple of a word are aligned
2138 to the least significant byte (to the right). On a BYTES_BIG_ENDIAN
2139 machine, this means we must skip the empty high order bytes when
2140 calculating the bit offset. */
2141 if (BYTES_BIG_ENDIAN && bytes % UNITS_PER_WORD)
2142 big_endian_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2143 * BITS_PER_UNIT));
2145 /* Copy the structure BITSIZE bites at a time.
2147 We could probably emit more efficient code for machines
2148 which do not use strict alignment, but it doesn't seem
2149 worth the effort at the current time. */
2150 for (bitpos = 0, xbitpos = big_endian_correction;
2151 bitpos < bytes * BITS_PER_UNIT;
2152 bitpos += bitsize, xbitpos += bitsize)
2155 /* We need a new source operand each time xbitpos is on a
2156 word boundary and when xbitpos == big_endian_correction
2157 (the first time through). */
2158 if (xbitpos % BITS_PER_WORD == 0
2159 || xbitpos == big_endian_correction)
2160 src = operand_subword_force (valreg,
2161 xbitpos / BITS_PER_WORD,
2162 BLKmode);
2164 /* We need a new destination operand each time bitpos is on
2165 a word boundary. */
2166 if (bitpos % BITS_PER_WORD == 0)
2167 dst = operand_subword (target, bitpos / BITS_PER_WORD, 1, BLKmode);
2169 /* Use xbitpos for the source extraction (right justified) and
2170 xbitpos for the destination store (left justified). */
2171 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, word_mode,
2172 extract_bit_field (src, bitsize,
2173 xbitpos % BITS_PER_WORD, 1,
2174 NULL_RTX, word_mode,
2175 word_mode,
2176 bitsize / BITS_PER_UNIT,
2177 BITS_PER_WORD),
2178 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
2181 else
2182 target = copy_to_reg (valreg);
2184 #ifdef PROMOTE_FUNCTION_RETURN
2185 /* If we promoted this return value, make the proper SUBREG. TARGET
2186 might be const0_rtx here, so be careful. */
2187 if (GET_CODE (target) == REG
2188 && TYPE_MODE (TREE_TYPE (exp)) != BLKmode
2189 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
2191 tree type = TREE_TYPE (exp);
2192 int unsignedp = TREE_UNSIGNED (type);
2194 /* If we don't promote as expected, something is wrong. */
2195 if (GET_MODE (target)
2196 != promote_mode (type, TYPE_MODE (type), &unsignedp, 1))
2197 abort ();
2199 target = gen_rtx_SUBREG (TYPE_MODE (type), target, 0);
2200 SUBREG_PROMOTED_VAR_P (target) = 1;
2201 SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
2203 #endif
2205 /* If size of args is variable or this was a constructor call for a stack
2206 argument, restore saved stack-pointer value. */
2208 if (old_stack_level)
2210 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
2211 pending_stack_adjust = old_pending_adj;
2212 #ifdef ACCUMULATE_OUTGOING_ARGS
2213 stack_arg_under_construction = old_stack_arg_under_construction;
2214 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2215 stack_usage_map = initial_stack_usage_map;
2216 #endif
2218 #ifdef ACCUMULATE_OUTGOING_ARGS
2219 else
2221 #ifdef REG_PARM_STACK_SPACE
2222 if (save_area)
2224 enum machine_mode save_mode = GET_MODE (save_area);
2225 #ifdef ARGS_GROW_DOWNWARD
2226 rtx stack_area
2227 = gen_rtx_MEM (save_mode,
2228 memory_address (save_mode,
2229 plus_constant (argblock,
2230 - high_to_save)));
2231 #else
2232 rtx stack_area
2233 = gen_rtx_MEM (save_mode,
2234 memory_address (save_mode,
2235 plus_constant (argblock,
2236 low_to_save)));
2237 #endif
2239 if (save_mode != BLKmode)
2240 emit_move_insn (stack_area, save_area);
2241 else
2242 emit_block_move (stack_area, validize_mem (save_area),
2243 GEN_INT (high_to_save - low_to_save + 1),
2244 PARM_BOUNDARY / BITS_PER_UNIT);
2246 #endif
2248 /* If we saved any argument areas, restore them. */
2249 for (i = 0; i < num_actuals; i++)
2250 if (args[i].save_area)
2252 enum machine_mode save_mode = GET_MODE (args[i].save_area);
2253 rtx stack_area
2254 = gen_rtx_MEM (save_mode,
2255 memory_address (save_mode,
2256 XEXP (args[i].stack_slot, 0)));
2258 if (save_mode != BLKmode)
2259 emit_move_insn (stack_area, args[i].save_area);
2260 else
2261 emit_block_move (stack_area, validize_mem (args[i].save_area),
2262 GEN_INT (args[i].size.constant),
2263 PARM_BOUNDARY / BITS_PER_UNIT);
2266 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2267 stack_usage_map = initial_stack_usage_map;
2269 #endif
2271 /* If this was alloca, record the new stack level for nonlocal gotos.
2272 Check for the handler slots since we might not have a save area
2273 for non-local gotos. */
2275 if (may_be_alloca && nonlocal_goto_handler_slot != 0)
2276 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
2278 pop_temp_slots ();
2280 return target;
2283 /* Output a library call to function FUN (a SYMBOL_REF rtx)
2284 (emitting the queue unless NO_QUEUE is nonzero),
2285 for a value of mode OUTMODE,
2286 with NARGS different arguments, passed as alternating rtx values
2287 and machine_modes to convert them to.
2288 The rtx values should have been passed through protect_from_queue already.
2290 NO_QUEUE will be true if and only if the library call is a `const' call
2291 which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent
2292 to the variable is_const in expand_call.
2294 NO_QUEUE must be true for const calls, because if it isn't, then
2295 any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes,
2296 and will be lost if the libcall sequence is optimized away.
2298 NO_QUEUE must be false for non-const calls, because if it isn't, the
2299 call insn will have its CONST_CALL_P bit set, and it will be incorrectly
2300 optimized. For instance, the instruction scheduler may incorrectly
2301 move memory references across the non-const call. */
2303 void
2304 emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode,
2305 int nargs, ...))
2307 #ifndef __STDC__
2308 rtx orgfun;
2309 int no_queue;
2310 enum machine_mode outmode;
2311 int nargs;
2312 #endif
2313 va_list p;
2314 /* Total size in bytes of all the stack-parms scanned so far. */
2315 struct args_size args_size;
2316 /* Size of arguments before any adjustments (such as rounding). */
2317 struct args_size original_args_size;
2318 register int argnum;
2319 rtx fun;
2320 int inc;
2321 int count;
2322 rtx argblock = 0;
2323 CUMULATIVE_ARGS args_so_far;
2324 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2325 struct args_size offset; struct args_size size; rtx save_area; };
2326 struct arg *argvec;
2327 int old_inhibit_defer_pop = inhibit_defer_pop;
2328 rtx call_fusage = 0;
2329 int reg_parm_stack_space = 0;
2330 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2331 /* Define the boundary of the register parm stack space that needs to be
2332 save, if any. */
2333 int low_to_save = -1, high_to_save;
2334 rtx save_area = 0; /* Place that it is saved */
2335 #endif
2337 #ifdef ACCUMULATE_OUTGOING_ARGS
2338 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2339 char *initial_stack_usage_map = stack_usage_map;
2340 int needed;
2341 #endif
2343 #ifdef REG_PARM_STACK_SPACE
2344 /* Size of the stack reserved for parameter registers. */
2345 #ifdef MAYBE_REG_PARM_STACK_SPACE
2346 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2347 #else
2348 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
2349 #endif
2350 #endif
2352 VA_START (p, nargs);
2354 #ifndef __STDC__
2355 orgfun = va_arg (p, rtx);
2356 no_queue = va_arg (p, int);
2357 outmode = va_arg (p, enum machine_mode);
2358 nargs = va_arg (p, int);
2359 #endif
2361 fun = orgfun;
2363 /* Copy all the libcall-arguments out of the varargs data
2364 and into a vector ARGVEC.
2366 Compute how to pass each argument. We only support a very small subset
2367 of the full argument passing conventions to limit complexity here since
2368 library functions shouldn't have many args. */
2370 argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
2371 bzero ((char *) argvec, nargs * sizeof (struct arg));
2374 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
2376 args_size.constant = 0;
2377 args_size.var = 0;
2379 push_temp_slots ();
2381 for (count = 0; count < nargs; count++)
2383 rtx val = va_arg (p, rtx);
2384 enum machine_mode mode = va_arg (p, enum machine_mode);
2386 /* We cannot convert the arg value to the mode the library wants here;
2387 must do it earlier where we know the signedness of the arg. */
2388 if (mode == BLKmode
2389 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2390 abort ();
2392 /* On some machines, there's no way to pass a float to a library fcn.
2393 Pass it as a double instead. */
2394 #ifdef LIBGCC_NEEDS_DOUBLE
2395 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2396 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
2397 #endif
2399 /* There's no need to call protect_from_queue, because
2400 either emit_move_insn or emit_push_insn will do that. */
2402 /* Make sure it is a reasonable operand for a move or push insn. */
2403 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2404 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2405 val = force_operand (val, NULL_RTX);
2407 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2408 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2410 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2411 be viewed as just an efficiency improvement. */
2412 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2413 emit_move_insn (slot, val);
2414 val = force_operand (XEXP (slot, 0), NULL_RTX);
2415 mode = Pmode;
2417 #endif
2419 argvec[count].value = val;
2420 argvec[count].mode = mode;
2422 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2423 if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
2424 abort ();
2425 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2426 argvec[count].partial
2427 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2428 #else
2429 argvec[count].partial = 0;
2430 #endif
2432 locate_and_pad_parm (mode, NULL_TREE,
2433 argvec[count].reg && argvec[count].partial == 0,
2434 NULL_TREE, &args_size, &argvec[count].offset,
2435 &argvec[count].size);
2437 if (argvec[count].size.var)
2438 abort ();
2440 if (reg_parm_stack_space == 0 && argvec[count].partial)
2441 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2443 if (argvec[count].reg == 0 || argvec[count].partial != 0
2444 || reg_parm_stack_space > 0)
2445 args_size.constant += argvec[count].size.constant;
2447 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
2449 va_end (p);
2451 #ifdef FINAL_REG_PARM_STACK_SPACE
2452 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
2453 args_size.var);
2454 #endif
2456 /* If this machine requires an external definition for library
2457 functions, write one out. */
2458 assemble_external_libcall (fun);
2460 original_args_size = args_size;
2461 #ifdef STACK_BOUNDARY
2462 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2463 / STACK_BYTES) * STACK_BYTES);
2464 #endif
2466 args_size.constant = MAX (args_size.constant,
2467 reg_parm_stack_space);
2469 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2470 args_size.constant -= reg_parm_stack_space;
2471 #endif
2473 if (args_size.constant > current_function_outgoing_args_size)
2474 current_function_outgoing_args_size = args_size.constant;
2476 #ifdef ACCUMULATE_OUTGOING_ARGS
2477 /* Since the stack pointer will never be pushed, it is possible for
2478 the evaluation of a parm to clobber something we have already
2479 written to the stack. Since most function calls on RISC machines
2480 do not use the stack, this is uncommon, but must work correctly.
2482 Therefore, we save any area of the stack that was already written
2483 and that we are using. Here we set up to do this by making a new
2484 stack usage map from the old one.
2486 Another approach might be to try to reorder the argument
2487 evaluations to avoid this conflicting stack usage. */
2489 needed = args_size.constant;
2491 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2492 /* Since we will be writing into the entire argument area, the
2493 map must be allocated for its entire size, not just the part that
2494 is the responsibility of the caller. */
2495 needed += reg_parm_stack_space;
2496 #endif
2498 #ifdef ARGS_GROW_DOWNWARD
2499 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2500 needed + 1);
2501 #else
2502 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
2503 needed);
2504 #endif
2505 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
2507 if (initial_highest_arg_in_use)
2508 bcopy (initial_stack_usage_map, stack_usage_map,
2509 initial_highest_arg_in_use);
2511 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
2512 bzero (&stack_usage_map[initial_highest_arg_in_use],
2513 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
2514 needed = 0;
2516 /* The address of the outgoing argument list must not be copied to a
2517 register here, because argblock would be left pointing to the
2518 wrong place after the call to allocate_dynamic_stack_space below.
2521 argblock = virtual_outgoing_args_rtx;
2522 #else /* not ACCUMULATE_OUTGOING_ARGS */
2523 #ifndef PUSH_ROUNDING
2524 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2525 #endif
2526 #endif
2528 #ifdef PUSH_ARGS_REVERSED
2529 #ifdef STACK_BOUNDARY
2530 /* If we push args individually in reverse order, perform stack alignment
2531 before the first push (the last arg). */
2532 if (argblock == 0)
2533 anti_adjust_stack (GEN_INT (args_size.constant
2534 - original_args_size.constant));
2535 #endif
2536 #endif
2538 #ifdef PUSH_ARGS_REVERSED
2539 inc = -1;
2540 argnum = nargs - 1;
2541 #else
2542 inc = 1;
2543 argnum = 0;
2544 #endif
2546 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2547 /* The argument list is the property of the called routine and it
2548 may clobber it. If the fixed area has been used for previous
2549 parameters, we must save and restore it.
2551 Here we compute the boundary of the that needs to be saved, if any. */
2553 #ifdef ARGS_GROW_DOWNWARD
2554 for (count = 0; count < reg_parm_stack_space + 1; count++)
2555 #else
2556 for (count = 0; count < reg_parm_stack_space; count++)
2557 #endif
2559 if (count >= highest_outgoing_arg_in_use
2560 || stack_usage_map[count] == 0)
2561 continue;
2563 if (low_to_save == -1)
2564 low_to_save = count;
2566 high_to_save = count;
2569 if (low_to_save >= 0)
2571 int num_to_save = high_to_save - low_to_save + 1;
2572 enum machine_mode save_mode
2573 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
2574 rtx stack_area;
2576 /* If we don't have the required alignment, must do this in BLKmode. */
2577 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
2578 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
2579 save_mode = BLKmode;
2581 #ifdef ARGS_GROW_DOWNWARD
2582 stack_area = gen_rtx_MEM (save_mode,
2583 memory_address (save_mode,
2584 plus_constant (argblock,
2585 - high_to_save)));
2586 #else
2587 stack_area = gen_rtx_MEM (save_mode,
2588 memory_address (save_mode,
2589 plus_constant (argblock,
2590 low_to_save)));
2591 #endif
2592 if (save_mode == BLKmode)
2594 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
2595 MEM_IN_STRUCT_P (save_area) = 0;
2596 emit_block_move (validize_mem (save_area), stack_area,
2597 GEN_INT (num_to_save),
2598 PARM_BOUNDARY / BITS_PER_UNIT);
2600 else
2602 save_area = gen_reg_rtx (save_mode);
2603 emit_move_insn (save_area, stack_area);
2606 #endif
2608 /* Push the args that need to be pushed. */
2610 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
2611 are to be pushed. */
2612 for (count = 0; count < nargs; count++, argnum += inc)
2614 register enum machine_mode mode = argvec[argnum].mode;
2615 register rtx val = argvec[argnum].value;
2616 rtx reg = argvec[argnum].reg;
2617 int partial = argvec[argnum].partial;
2618 #ifdef ACCUMULATE_OUTGOING_ARGS
2619 int lower_bound, upper_bound, i;
2620 #endif
2622 if (! (reg != 0 && partial == 0))
2624 #ifdef ACCUMULATE_OUTGOING_ARGS
2625 /* If this is being stored into a pre-allocated, fixed-size, stack
2626 area, save any previous data at that location. */
2628 #ifdef ARGS_GROW_DOWNWARD
2629 /* stack_slot is negative, but we want to index stack_usage_map
2630 with positive values. */
2631 upper_bound = -argvec[argnum].offset.constant + 1;
2632 lower_bound = upper_bound - argvec[argnum].size.constant;
2633 #else
2634 lower_bound = argvec[argnum].offset.constant;
2635 upper_bound = lower_bound + argvec[argnum].size.constant;
2636 #endif
2638 for (i = lower_bound; i < upper_bound; i++)
2639 if (stack_usage_map[i]
2640 /* Don't store things in the fixed argument area at this point;
2641 it has already been saved. */
2642 && i > reg_parm_stack_space)
2643 break;
2645 if (i != upper_bound)
2647 /* We need to make a save area. See what mode we can make it. */
2648 enum machine_mode save_mode
2649 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
2650 MODE_INT, 1);
2651 rtx stack_area
2652 = gen_rtx_MEM (save_mode,
2653 memory_address (save_mode,
2654 plus_constant (argblock, argvec[argnum].offset.constant)));
2655 argvec[argnum].save_area = gen_reg_rtx (save_mode);
2656 emit_move_insn (argvec[argnum].save_area, stack_area);
2658 #endif
2659 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
2660 argblock, GEN_INT (argvec[argnum].offset.constant),
2661 reg_parm_stack_space);
2663 #ifdef ACCUMULATE_OUTGOING_ARGS
2664 /* Now mark the segment we just used. */
2665 for (i = lower_bound; i < upper_bound; i++)
2666 stack_usage_map[i] = 1;
2667 #endif
2669 NO_DEFER_POP;
2673 #ifndef PUSH_ARGS_REVERSED
2674 #ifdef STACK_BOUNDARY
2675 /* If we pushed args in forward order, perform stack alignment
2676 after pushing the last arg. */
2677 if (argblock == 0)
2678 anti_adjust_stack (GEN_INT (args_size.constant
2679 - original_args_size.constant));
2680 #endif
2681 #endif
2683 #ifdef PUSH_ARGS_REVERSED
2684 argnum = nargs - 1;
2685 #else
2686 argnum = 0;
2687 #endif
2689 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
2691 /* Now load any reg parms into their regs. */
2693 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
2694 are to be pushed. */
2695 for (count = 0; count < nargs; count++, argnum += inc)
2697 register rtx val = argvec[argnum].value;
2698 rtx reg = argvec[argnum].reg;
2699 int partial = argvec[argnum].partial;
2701 if (reg != 0 && partial == 0)
2702 emit_move_insn (reg, val);
2703 NO_DEFER_POP;
2706 /* For version 1.37, try deleting this entirely. */
2707 if (! no_queue)
2708 emit_queue ();
2710 /* Any regs containing parms remain in use through the call. */
2711 for (count = 0; count < nargs; count++)
2712 if (argvec[count].reg != 0)
2713 use_reg (&call_fusage, argvec[count].reg);
2715 /* Don't allow popping to be deferred, since then
2716 cse'ing of library calls could delete a call and leave the pop. */
2717 NO_DEFER_POP;
2719 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
2720 will set inhibit_defer_pop to that value. */
2722 /* The return type is needed to decide how many bytes the function pops.
2723 Signedness plays no role in that, so for simplicity, we pretend it's
2724 always signed. We also assume that the list of arguments passed has
2725 no impact, so we pretend it is unknown. */
2727 emit_call_1 (fun,
2728 get_identifier (XSTR (orgfun, 0)),
2729 build_function_type (outmode == VOIDmode ? void_type_node
2730 : type_for_mode (outmode, 0), NULL_TREE),
2731 args_size.constant, 0,
2732 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2733 outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
2734 old_inhibit_defer_pop + 1, call_fusage, no_queue);
2736 pop_temp_slots ();
2738 /* Now restore inhibit_defer_pop to its actual original value. */
2739 OK_DEFER_POP;
2741 #ifdef ACCUMULATE_OUTGOING_ARGS
2742 #ifdef REG_PARM_STACK_SPACE
2743 if (save_area)
2745 enum machine_mode save_mode = GET_MODE (save_area);
2746 #ifdef ARGS_GROW_DOWNWARD
2747 rtx stack_area
2748 = gen_rtx_MEM (save_mode,
2749 memory_address (save_mode,
2750 plus_constant (argblock,
2751 - high_to_save)));
2752 #else
2753 rtx stack_area
2754 = gen_rtx_MEM (save_mode,
2755 memory_address (save_mode,
2756 plus_constant (argblock, low_to_save)));
2757 #endif
2759 if (save_mode != BLKmode)
2760 emit_move_insn (stack_area, save_area);
2761 else
2762 emit_block_move (stack_area, validize_mem (save_area),
2763 GEN_INT (high_to_save - low_to_save + 1),
2764 PARM_BOUNDARY / BITS_PER_UNIT);
2766 #endif
2768 /* If we saved any argument areas, restore them. */
2769 for (count = 0; count < nargs; count++)
2770 if (argvec[count].save_area)
2772 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
2773 rtx stack_area
2774 = gen_rtx_MEM (save_mode,
2775 memory_address (save_mode,
2776 plus_constant (argblock, argvec[count].offset.constant)));
2778 emit_move_insn (stack_area, argvec[count].save_area);
2781 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
2782 stack_usage_map = initial_stack_usage_map;
2783 #endif
2786 /* Like emit_library_call except that an extra argument, VALUE,
2787 comes second and says where to store the result.
2788 (If VALUE is zero, this function chooses a convenient way
2789 to return the value.
2791 This function returns an rtx for where the value is to be found.
2792 If VALUE is nonzero, VALUE is returned. */
2795 emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue,
2796 enum machine_mode outmode, int nargs, ...))
2798 #ifndef __STDC__
2799 rtx orgfun;
2800 rtx value;
2801 int no_queue;
2802 enum machine_mode outmode;
2803 int nargs;
2804 #endif
2805 va_list p;
2806 /* Total size in bytes of all the stack-parms scanned so far. */
2807 struct args_size args_size;
2808 /* Size of arguments before any adjustments (such as rounding). */
2809 struct args_size original_args_size;
2810 register int argnum;
2811 rtx fun;
2812 int inc;
2813 int count;
2814 rtx argblock = 0;
2815 CUMULATIVE_ARGS args_so_far;
2816 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2817 struct args_size offset; struct args_size size; rtx save_area; };
2818 struct arg *argvec;
2819 int old_inhibit_defer_pop = inhibit_defer_pop;
2820 rtx call_fusage = 0;
2821 rtx mem_value = 0;
2822 int pcc_struct_value = 0;
2823 int struct_value_size = 0;
2824 int is_const;
2825 int reg_parm_stack_space = 0;
2826 #ifdef ACCUMULATE_OUTGOING_ARGS
2827 int needed;
2828 #endif
2830 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
2831 /* Define the boundary of the register parm stack space that needs to be
2832 save, if any. */
2833 int low_to_save = -1, high_to_save;
2834 rtx save_area = 0; /* Place that it is saved */
2835 #endif
2837 #ifdef ACCUMULATE_OUTGOING_ARGS
2838 /* Size of the stack reserved for parameter registers. */
2839 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2840 char *initial_stack_usage_map = stack_usage_map;
2841 #endif
2843 #ifdef REG_PARM_STACK_SPACE
2844 #ifdef MAYBE_REG_PARM_STACK_SPACE
2845 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
2846 #else
2847 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
2848 #endif
2849 #endif
2851 VA_START (p, nargs);
2853 #ifndef __STDC__
2854 orgfun = va_arg (p, rtx);
2855 value = va_arg (p, rtx);
2856 no_queue = va_arg (p, int);
2857 outmode = va_arg (p, enum machine_mode);
2858 nargs = va_arg (p, int);
2859 #endif
2861 is_const = no_queue;
2862 fun = orgfun;
2864 /* If this kind of value comes back in memory,
2865 decide where in memory it should come back. */
2866 if (aggregate_value_p (type_for_mode (outmode, 0)))
2868 #ifdef PCC_STATIC_STRUCT_RETURN
2869 rtx pointer_reg
2870 = hard_function_value (build_pointer_type (type_for_mode (outmode, 0)),
2872 mem_value = gen_rtx_MEM (outmode, pointer_reg);
2873 pcc_struct_value = 1;
2874 if (value == 0)
2875 value = gen_reg_rtx (outmode);
2876 #else /* not PCC_STATIC_STRUCT_RETURN */
2877 struct_value_size = GET_MODE_SIZE (outmode);
2878 if (value != 0 && GET_CODE (value) == MEM)
2879 mem_value = value;
2880 else
2881 mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
2882 #endif
2884 /* This call returns a big structure. */
2885 is_const = 0;
2888 /* ??? Unfinished: must pass the memory address as an argument. */
2890 /* Copy all the libcall-arguments out of the varargs data
2891 and into a vector ARGVEC.
2893 Compute how to pass each argument. We only support a very small subset
2894 of the full argument passing conventions to limit complexity here since
2895 library functions shouldn't have many args. */
2897 argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
2898 bzero ((char *) argvec, (nargs + 1) * sizeof (struct arg));
2900 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun, 0);
2902 args_size.constant = 0;
2903 args_size.var = 0;
2905 count = 0;
2907 push_temp_slots ();
2909 /* If there's a structure value address to be passed,
2910 either pass it in the special place, or pass it as an extra argument. */
2911 if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value)
2913 rtx addr = XEXP (mem_value, 0);
2914 nargs++;
2916 /* Make sure it is a reasonable operand for a move or push insn. */
2917 if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
2918 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
2919 addr = force_operand (addr, NULL_RTX);
2921 argvec[count].value = addr;
2922 argvec[count].mode = Pmode;
2923 argvec[count].partial = 0;
2925 argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1);
2926 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2927 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1))
2928 abort ();
2929 #endif
2931 locate_and_pad_parm (Pmode, NULL_TREE,
2932 argvec[count].reg && argvec[count].partial == 0,
2933 NULL_TREE, &args_size, &argvec[count].offset,
2934 &argvec[count].size);
2937 if (argvec[count].reg == 0 || argvec[count].partial != 0
2938 || reg_parm_stack_space > 0)
2939 args_size.constant += argvec[count].size.constant;
2941 FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree) 0, 1);
2943 count++;
2946 for (; count < nargs; count++)
2948 rtx val = va_arg (p, rtx);
2949 enum machine_mode mode = va_arg (p, enum machine_mode);
2951 /* We cannot convert the arg value to the mode the library wants here;
2952 must do it earlier where we know the signedness of the arg. */
2953 if (mode == BLKmode
2954 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2955 abort ();
2957 /* On some machines, there's no way to pass a float to a library fcn.
2958 Pass it as a double instead. */
2959 #ifdef LIBGCC_NEEDS_DOUBLE
2960 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2961 val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode;
2962 #endif
2964 /* There's no need to call protect_from_queue, because
2965 either emit_move_insn or emit_push_insn will do that. */
2967 /* Make sure it is a reasonable operand for a move or push insn. */
2968 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2969 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2970 val = force_operand (val, NULL_RTX);
2972 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2973 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2975 /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can
2976 be viewed as just an efficiency improvement. */
2977 rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2978 emit_move_insn (slot, val);
2979 val = XEXP (slot, 0);
2980 mode = Pmode;
2982 #endif
2984 argvec[count].value = val;
2985 argvec[count].mode = mode;
2987 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2988 if (argvec[count].reg && GET_CODE (argvec[count].reg) == PARALLEL)
2989 abort ();
2990 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2991 argvec[count].partial
2992 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2993 #else
2994 argvec[count].partial = 0;
2995 #endif
2997 locate_and_pad_parm (mode, NULL_TREE,
2998 argvec[count].reg && argvec[count].partial == 0,
2999 NULL_TREE, &args_size, &argvec[count].offset,
3000 &argvec[count].size);
3002 if (argvec[count].size.var)
3003 abort ();
3005 if (reg_parm_stack_space == 0 && argvec[count].partial)
3006 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
3008 if (argvec[count].reg == 0 || argvec[count].partial != 0
3009 || reg_parm_stack_space > 0)
3010 args_size.constant += argvec[count].size.constant;
3012 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree) 0, 1);
3014 va_end (p);
3016 #ifdef FINAL_REG_PARM_STACK_SPACE
3017 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
3018 args_size.var);
3019 #endif
3020 /* If this machine requires an external definition for library
3021 functions, write one out. */
3022 assemble_external_libcall (fun);
3024 original_args_size = args_size;
3025 #ifdef STACK_BOUNDARY
3026 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
3027 / STACK_BYTES) * STACK_BYTES);
3028 #endif
3030 args_size.constant = MAX (args_size.constant,
3031 reg_parm_stack_space);
3033 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3034 args_size.constant -= reg_parm_stack_space;
3035 #endif
3037 if (args_size.constant > current_function_outgoing_args_size)
3038 current_function_outgoing_args_size = args_size.constant;
3040 #ifdef ACCUMULATE_OUTGOING_ARGS
3041 /* Since the stack pointer will never be pushed, it is possible for
3042 the evaluation of a parm to clobber something we have already
3043 written to the stack. Since most function calls on RISC machines
3044 do not use the stack, this is uncommon, but must work correctly.
3046 Therefore, we save any area of the stack that was already written
3047 and that we are using. Here we set up to do this by making a new
3048 stack usage map from the old one.
3050 Another approach might be to try to reorder the argument
3051 evaluations to avoid this conflicting stack usage. */
3053 needed = args_size.constant;
3055 #ifndef OUTGOING_REG_PARM_STACK_SPACE
3056 /* Since we will be writing into the entire argument area, the
3057 map must be allocated for its entire size, not just the part that
3058 is the responsibility of the caller. */
3059 needed += reg_parm_stack_space;
3060 #endif
3062 #ifdef ARGS_GROW_DOWNWARD
3063 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3064 needed + 1);
3065 #else
3066 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
3067 needed);
3068 #endif
3069 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
3071 if (initial_highest_arg_in_use)
3072 bcopy (initial_stack_usage_map, stack_usage_map,
3073 initial_highest_arg_in_use);
3075 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3076 bzero (&stack_usage_map[initial_highest_arg_in_use],
3077 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
3078 needed = 0;
3080 /* The address of the outgoing argument list must not be copied to a
3081 register here, because argblock would be left pointing to the
3082 wrong place after the call to allocate_dynamic_stack_space below.
3085 argblock = virtual_outgoing_args_rtx;
3086 #else /* not ACCUMULATE_OUTGOING_ARGS */
3087 #ifndef PUSH_ROUNDING
3088 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
3089 #endif
3090 #endif
3092 #ifdef PUSH_ARGS_REVERSED
3093 #ifdef STACK_BOUNDARY
3094 /* If we push args individually in reverse order, perform stack alignment
3095 before the first push (the last arg). */
3096 if (argblock == 0)
3097 anti_adjust_stack (GEN_INT (args_size.constant
3098 - original_args_size.constant));
3099 #endif
3100 #endif
3102 #ifdef PUSH_ARGS_REVERSED
3103 inc = -1;
3104 argnum = nargs - 1;
3105 #else
3106 inc = 1;
3107 argnum = 0;
3108 #endif
3110 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
3111 /* The argument list is the property of the called routine and it
3112 may clobber it. If the fixed area has been used for previous
3113 parameters, we must save and restore it.
3115 Here we compute the boundary of the that needs to be saved, if any. */
3117 #ifdef ARGS_GROW_DOWNWARD
3118 for (count = 0; count < reg_parm_stack_space + 1; count++)
3119 #else
3120 for (count = 0; count < reg_parm_stack_space; count++)
3121 #endif
3123 if (count >= highest_outgoing_arg_in_use
3124 || stack_usage_map[count] == 0)
3125 continue;
3127 if (low_to_save == -1)
3128 low_to_save = count;
3130 high_to_save = count;
3133 if (low_to_save >= 0)
3135 int num_to_save = high_to_save - low_to_save + 1;
3136 enum machine_mode save_mode
3137 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
3138 rtx stack_area;
3140 /* If we don't have the required alignment, must do this in BLKmode. */
3141 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
3142 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
3143 save_mode = BLKmode;
3145 #ifdef ARGS_GROW_DOWNWARD
3146 stack_area = gen_rtx_MEM (save_mode,
3147 memory_address (save_mode,
3148 plus_constant (argblock,
3149 - high_to_save)));
3150 #else
3151 stack_area = gen_rtx_MEM (save_mode,
3152 memory_address (save_mode,
3153 plus_constant (argblock,
3154 low_to_save)));
3155 #endif
3156 if (save_mode == BLKmode)
3158 save_area = assign_stack_temp (BLKmode, num_to_save, 0);
3159 MEM_IN_STRUCT_P (save_area) = 0;
3160 emit_block_move (validize_mem (save_area), stack_area,
3161 GEN_INT (num_to_save),
3162 PARM_BOUNDARY / BITS_PER_UNIT);
3164 else
3166 save_area = gen_reg_rtx (save_mode);
3167 emit_move_insn (save_area, stack_area);
3170 #endif
3172 /* Push the args that need to be pushed. */
3174 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3175 are to be pushed. */
3176 for (count = 0; count < nargs; count++, argnum += inc)
3178 register enum machine_mode mode = argvec[argnum].mode;
3179 register rtx val = argvec[argnum].value;
3180 rtx reg = argvec[argnum].reg;
3181 int partial = argvec[argnum].partial;
3182 #ifdef ACCUMULATE_OUTGOING_ARGS
3183 int lower_bound, upper_bound, i;
3184 #endif
3186 if (! (reg != 0 && partial == 0))
3188 #ifdef ACCUMULATE_OUTGOING_ARGS
3189 /* If this is being stored into a pre-allocated, fixed-size, stack
3190 area, save any previous data at that location. */
3192 #ifdef ARGS_GROW_DOWNWARD
3193 /* stack_slot is negative, but we want to index stack_usage_map
3194 with positive values. */
3195 upper_bound = -argvec[argnum].offset.constant + 1;
3196 lower_bound = upper_bound - argvec[argnum].size.constant;
3197 #else
3198 lower_bound = argvec[argnum].offset.constant;
3199 upper_bound = lower_bound + argvec[argnum].size.constant;
3200 #endif
3202 for (i = lower_bound; i < upper_bound; i++)
3203 if (stack_usage_map[i]
3204 /* Don't store things in the fixed argument area at this point;
3205 it has already been saved. */
3206 && i > reg_parm_stack_space)
3207 break;
3209 if (i != upper_bound)
3211 /* We need to make a save area. See what mode we can make it. */
3212 enum machine_mode save_mode
3213 = mode_for_size (argvec[argnum].size.constant * BITS_PER_UNIT,
3214 MODE_INT, 1);
3215 rtx stack_area
3216 = gen_rtx_MEM (save_mode,
3217 memory_address (save_mode,
3218 plus_constant (argblock,
3219 argvec[argnum].offset.constant)));
3220 argvec[argnum].save_area = gen_reg_rtx (save_mode);
3221 emit_move_insn (argvec[argnum].save_area, stack_area);
3223 #endif
3224 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
3225 argblock, GEN_INT (argvec[argnum].offset.constant),
3226 reg_parm_stack_space);
3228 #ifdef ACCUMULATE_OUTGOING_ARGS
3229 /* Now mark the segment we just used. */
3230 for (i = lower_bound; i < upper_bound; i++)
3231 stack_usage_map[i] = 1;
3232 #endif
3234 NO_DEFER_POP;
3238 #ifndef PUSH_ARGS_REVERSED
3239 #ifdef STACK_BOUNDARY
3240 /* If we pushed args in forward order, perform stack alignment
3241 after pushing the last arg. */
3242 if (argblock == 0)
3243 anti_adjust_stack (GEN_INT (args_size.constant
3244 - original_args_size.constant));
3245 #endif
3246 #endif
3248 #ifdef PUSH_ARGS_REVERSED
3249 argnum = nargs - 1;
3250 #else
3251 argnum = 0;
3252 #endif
3254 fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0);
3256 /* Now load any reg parms into their regs. */
3258 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
3259 are to be pushed. */
3260 for (count = 0; count < nargs; count++, argnum += inc)
3262 register rtx val = argvec[argnum].value;
3263 rtx reg = argvec[argnum].reg;
3264 int partial = argvec[argnum].partial;
3266 if (reg != 0 && partial == 0)
3267 emit_move_insn (reg, val);
3268 NO_DEFER_POP;
3271 #if 0
3272 /* For version 1.37, try deleting this entirely. */
3273 if (! no_queue)
3274 emit_queue ();
3275 #endif
3277 /* Any regs containing parms remain in use through the call. */
3278 for (count = 0; count < nargs; count++)
3279 if (argvec[count].reg != 0)
3280 use_reg (&call_fusage, argvec[count].reg);
3282 /* Pass the function the address in which to return a structure value. */
3283 if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value)
3285 emit_move_insn (struct_value_rtx,
3286 force_reg (Pmode,
3287 force_operand (XEXP (mem_value, 0),
3288 NULL_RTX)));
3289 if (GET_CODE (struct_value_rtx) == REG)
3290 use_reg (&call_fusage, struct_value_rtx);
3293 /* Don't allow popping to be deferred, since then
3294 cse'ing of library calls could delete a call and leave the pop. */
3295 NO_DEFER_POP;
3297 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
3298 will set inhibit_defer_pop to that value. */
3299 /* See the comment in emit_library_call about the function type we build
3300 and pass here. */
3302 emit_call_1 (fun,
3303 get_identifier (XSTR (orgfun, 0)),
3304 build_function_type (type_for_mode (outmode, 0), NULL_TREE),
3305 args_size.constant, struct_value_size,
3306 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
3307 mem_value == 0 ? hard_libcall_value (outmode) : NULL_RTX,
3308 old_inhibit_defer_pop + 1, call_fusage, is_const);
3310 /* Now restore inhibit_defer_pop to its actual original value. */
3311 OK_DEFER_POP;
3313 pop_temp_slots ();
3315 /* Copy the value to the right place. */
3316 if (outmode != VOIDmode)
3318 if (mem_value)
3320 if (value == 0)
3321 value = mem_value;
3322 if (value != mem_value)
3323 emit_move_insn (value, mem_value);
3325 else if (value != 0)
3326 emit_move_insn (value, hard_libcall_value (outmode));
3327 else
3328 value = hard_libcall_value (outmode);
3331 #ifdef ACCUMULATE_OUTGOING_ARGS
3332 #ifdef REG_PARM_STACK_SPACE
3333 if (save_area)
3335 enum machine_mode save_mode = GET_MODE (save_area);
3336 #ifdef ARGS_GROW_DOWNWARD
3337 rtx stack_area
3338 = gen_rtx_MEM (save_mode,
3339 memory_address (save_mode,
3340 plus_constant (argblock,
3341 - high_to_save)));
3342 #else
3343 rtx stack_area
3344 = gen_rtx_MEM (save_mode,
3345 memory_address (save_mode,
3346 plus_constant (argblock, low_to_save)));
3347 #endif
3348 if (save_mode != BLKmode)
3349 emit_move_insn (stack_area, save_area);
3350 else
3351 emit_block_move (stack_area, validize_mem (save_area),
3352 GEN_INT (high_to_save - low_to_save + 1),
3353 PARM_BOUNDARY / BITS_PER_UNIT);
3355 #endif
3357 /* If we saved any argument areas, restore them. */
3358 for (count = 0; count < nargs; count++)
3359 if (argvec[count].save_area)
3361 enum machine_mode save_mode = GET_MODE (argvec[count].save_area);
3362 rtx stack_area
3363 = gen_rtx_MEM (save_mode,
3364 memory_address (save_mode, plus_constant (argblock,
3365 argvec[count].offset.constant)));
3367 emit_move_insn (stack_area, argvec[count].save_area);
3370 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3371 stack_usage_map = initial_stack_usage_map;
3372 #endif
3374 return value;
3377 #if 0
3378 /* Return an rtx which represents a suitable home on the stack
3379 given TYPE, the type of the argument looking for a home.
3380 This is called only for BLKmode arguments.
3382 SIZE is the size needed for this target.
3383 ARGS_ADDR is the address of the bottom of the argument block for this call.
3384 OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
3385 if this machine uses push insns. */
3387 static rtx
3388 target_for_arg (type, size, args_addr, offset)
3389 tree type;
3390 rtx size;
3391 rtx args_addr;
3392 struct args_size offset;
3394 rtx target;
3395 rtx offset_rtx = ARGS_SIZE_RTX (offset);
3397 /* We do not call memory_address if possible,
3398 because we want to address as close to the stack
3399 as possible. For non-variable sized arguments,
3400 this will be stack-pointer relative addressing. */
3401 if (GET_CODE (offset_rtx) == CONST_INT)
3402 target = plus_constant (args_addr, INTVAL (offset_rtx));
3403 else
3405 /* I have no idea how to guarantee that this
3406 will work in the presence of register parameters. */
3407 target = gen_rtx_PLUS (Pmode, args_addr, offset_rtx);
3408 target = memory_address (QImode, target);
3411 return gen_rtx_MEM (BLKmode, target);
3413 #endif
3415 /* Store a single argument for a function call
3416 into the register or memory area where it must be passed.
3417 *ARG describes the argument value and where to pass it.
3419 ARGBLOCK is the address of the stack-block for all the arguments,
3420 or 0 on a machine where arguments are pushed individually.
3422 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
3423 so must be careful about how the stack is used.
3425 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
3426 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
3427 that we need not worry about saving and restoring the stack.
3429 FNDECL is the declaration of the function we are calling. */
3431 static void
3432 store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl,
3433 reg_parm_stack_space)
3434 struct arg_data *arg;
3435 rtx argblock;
3436 int may_be_alloca;
3437 int variable_size;
3438 tree fndecl;
3439 int reg_parm_stack_space;
3441 register tree pval = arg->tree_value;
3442 rtx reg = 0;
3443 int partial = 0;
3444 int used = 0;
3445 #ifdef ACCUMULATE_OUTGOING_ARGS
3446 int i, lower_bound, upper_bound;
3447 #endif
3449 if (TREE_CODE (pval) == ERROR_MARK)
3450 return;
3452 /* Push a new temporary level for any temporaries we make for
3453 this argument. */
3454 push_temp_slots ();
3456 #ifdef ACCUMULATE_OUTGOING_ARGS
3457 /* If this is being stored into a pre-allocated, fixed-size, stack area,
3458 save any previous data at that location. */
3459 if (argblock && ! variable_size && arg->stack)
3461 #ifdef ARGS_GROW_DOWNWARD
3462 /* stack_slot is negative, but we want to index stack_usage_map
3463 with positive values. */
3464 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3465 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
3466 else
3467 upper_bound = 0;
3469 lower_bound = upper_bound - arg->size.constant;
3470 #else
3471 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
3472 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
3473 else
3474 lower_bound = 0;
3476 upper_bound = lower_bound + arg->size.constant;
3477 #endif
3479 for (i = lower_bound; i < upper_bound; i++)
3480 if (stack_usage_map[i]
3481 /* Don't store things in the fixed argument area at this point;
3482 it has already been saved. */
3483 && i > reg_parm_stack_space)
3484 break;
3486 if (i != upper_bound)
3488 /* We need to make a save area. See what mode we can make it. */
3489 enum machine_mode save_mode
3490 = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
3491 rtx stack_area
3492 = gen_rtx_MEM (save_mode,
3493 memory_address (save_mode,
3494 XEXP (arg->stack_slot, 0)));
3496 if (save_mode == BLKmode)
3498 arg->save_area = assign_stack_temp (BLKmode,
3499 arg->size.constant, 0);
3500 MEM_IN_STRUCT_P (arg->save_area)
3501 = AGGREGATE_TYPE_P (TREE_TYPE (arg->tree_value));
3502 preserve_temp_slots (arg->save_area);
3503 emit_block_move (validize_mem (arg->save_area), stack_area,
3504 GEN_INT (arg->size.constant),
3505 PARM_BOUNDARY / BITS_PER_UNIT);
3507 else
3509 arg->save_area = gen_reg_rtx (save_mode);
3510 emit_move_insn (arg->save_area, stack_area);
3514 #endif
3516 /* If this isn't going to be placed on both the stack and in registers,
3517 set up the register and number of words. */
3518 if (! arg->pass_on_stack)
3519 reg = arg->reg, partial = arg->partial;
3521 if (reg != 0 && partial == 0)
3522 /* Being passed entirely in a register. We shouldn't be called in
3523 this case. */
3524 abort ();
3526 /* If this arg needs special alignment, don't load the registers
3527 here. */
3528 if (arg->n_aligned_regs != 0)
3529 reg = 0;
3531 /* If this is being passed partially in a register, we can't evaluate
3532 it directly into its stack slot. Otherwise, we can. */
3533 if (arg->value == 0)
3535 #ifdef ACCUMULATE_OUTGOING_ARGS
3536 /* stack_arg_under_construction is nonzero if a function argument is
3537 being evaluated directly into the outgoing argument list and
3538 expand_call must take special action to preserve the argument list
3539 if it is called recursively.
3541 For scalar function arguments stack_usage_map is sufficient to
3542 determine which stack slots must be saved and restored. Scalar
3543 arguments in general have pass_on_stack == 0.
3545 If this argument is initialized by a function which takes the
3546 address of the argument (a C++ constructor or a C function
3547 returning a BLKmode structure), then stack_usage_map is
3548 insufficient and expand_call must push the stack around the
3549 function call. Such arguments have pass_on_stack == 1.
3551 Note that it is always safe to set stack_arg_under_construction,
3552 but this generates suboptimal code if set when not needed. */
3554 if (arg->pass_on_stack)
3555 stack_arg_under_construction++;
3556 #endif
3557 arg->value = expand_expr (pval,
3558 (partial
3559 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
3560 ? NULL_RTX : arg->stack,
3561 VOIDmode, 0);
3563 /* If we are promoting object (or for any other reason) the mode
3564 doesn't agree, convert the mode. */
3566 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
3567 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
3568 arg->value, arg->unsignedp);
3570 #ifdef ACCUMULATE_OUTGOING_ARGS
3571 if (arg->pass_on_stack)
3572 stack_arg_under_construction--;
3573 #endif
3576 /* Don't allow anything left on stack from computation
3577 of argument to alloca. */
3578 if (may_be_alloca)
3579 do_pending_stack_adjust ();
3581 if (arg->value == arg->stack)
3583 /* If the value is already in the stack slot, we are done. */
3584 if (flag_check_memory_usage && GET_CODE (arg->stack) == MEM)
3586 if (arg->mode == BLKmode)
3587 abort ();
3589 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
3590 XEXP (arg->stack, 0), ptr_mode,
3591 GEN_INT (GET_MODE_SIZE (arg->mode)),
3592 TYPE_MODE (sizetype),
3593 GEN_INT (MEMORY_USE_RW),
3594 TYPE_MODE (integer_type_node));
3597 else if (arg->mode != BLKmode)
3599 register int size;
3601 /* Argument is a scalar, not entirely passed in registers.
3602 (If part is passed in registers, arg->partial says how much
3603 and emit_push_insn will take care of putting it there.)
3605 Push it, and if its size is less than the
3606 amount of space allocated to it,
3607 also bump stack pointer by the additional space.
3608 Note that in C the default argument promotions
3609 will prevent such mismatches. */
3611 size = GET_MODE_SIZE (arg->mode);
3612 /* Compute how much space the push instruction will push.
3613 On many machines, pushing a byte will advance the stack
3614 pointer by a halfword. */
3615 #ifdef PUSH_ROUNDING
3616 size = PUSH_ROUNDING (size);
3617 #endif
3618 used = size;
3620 /* Compute how much space the argument should get:
3621 round up to a multiple of the alignment for arguments. */
3622 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
3623 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
3624 / (PARM_BOUNDARY / BITS_PER_UNIT))
3625 * (PARM_BOUNDARY / BITS_PER_UNIT));
3627 /* This isn't already where we want it on the stack, so put it there.
3628 This can either be done with push or copy insns. */
3629 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, 0,
3630 partial, reg, used - size, argblock,
3631 ARGS_SIZE_RTX (arg->offset), reg_parm_stack_space);
3633 else
3635 /* BLKmode, at least partly to be pushed. */
3637 register int excess;
3638 rtx size_rtx;
3640 /* Pushing a nonscalar.
3641 If part is passed in registers, PARTIAL says how much
3642 and emit_push_insn will take care of putting it there. */
3644 /* Round its size up to a multiple
3645 of the allocation unit for arguments. */
3647 if (arg->size.var != 0)
3649 excess = 0;
3650 size_rtx = ARGS_SIZE_RTX (arg->size);
3652 else
3654 /* PUSH_ROUNDING has no effect on us, because
3655 emit_push_insn for BLKmode is careful to avoid it. */
3656 excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
3657 + partial * UNITS_PER_WORD);
3658 size_rtx = expr_size (pval);
3661 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
3662 TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
3663 reg, excess, argblock, ARGS_SIZE_RTX (arg->offset),
3664 reg_parm_stack_space);
3668 /* Unless this is a partially-in-register argument, the argument is now
3669 in the stack.
3671 ??? Note that this can change arg->value from arg->stack to
3672 arg->stack_slot and it matters when they are not the same.
3673 It isn't totally clear that this is correct in all cases. */
3674 if (partial == 0)
3675 arg->value = arg->stack_slot;
3677 /* Once we have pushed something, pops can't safely
3678 be deferred during the rest of the arguments. */
3679 NO_DEFER_POP;
3681 /* ANSI doesn't require a sequence point here,
3682 but PCC has one, so this will avoid some problems. */
3683 emit_queue ();
3685 /* Free any temporary slots made in processing this argument. Show
3686 that we might have taken the address of something and pushed that
3687 as an operand. */
3688 preserve_temp_slots (NULL_RTX);
3689 free_temp_slots ();
3690 pop_temp_slots ();
3692 #ifdef ACCUMULATE_OUTGOING_ARGS
3693 /* Now mark the segment we just used. */
3694 if (argblock && ! variable_size && arg->stack)
3695 for (i = lower_bound; i < upper_bound; i++)
3696 stack_usage_map[i] = 1;
3697 #endif