]> gcc.gnu.org Git - gcc.git/blob - gcc/calls.c
(stamp-proto): Pass LOCAL_INCLUDE_DIR based on local_prefix.
[gcc.git] / gcc / calls.c
1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989, 1992 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include "config.h"
21 #include "rtl.h"
22 #include "tree.h"
23 #include "flags.h"
24 #include "expr.h"
25 #include "gvarargs.h"
26 #include "insn-flags.h"
27
28 /* Decide whether a function's arguments should be processed
29 from first to last or from last to first.
30
31 They should if the stack and args grow in opposite directions, but
32 only if we have push insns. */
33
34 #ifdef PUSH_ROUNDING
35
36 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNARD)
37 #define PUSH_ARGS_REVERSED /* If it's last to first */
38 #endif
39
40 #endif
41
42 /* Like STACK_BOUNDARY but in units of bytes, not bits. */
43 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
44
45 /* Data structure and subroutines used within expand_call. */
46
47 struct arg_data
48 {
49 /* Tree node for this argument. */
50 tree tree_value;
51 /* Mode for value; TYPE_MODE unless promoted. */
52 enum machine_mode mode;
53 /* Current RTL value for argument, or 0 if it isn't precomputed. */
54 rtx value;
55 /* Initially-compute RTL value for argument; only for const functions. */
56 rtx initial_value;
57 /* Register to pass this argument in, 0 if passed on stack, or an
58 EXPR_LIST if the arg is to be copied into multiple different
59 registers. */
60 rtx reg;
61 /* If REG was promoted from the actual mode of the argument expression,
62 indicates whether the promotion is sign- or zero-extended. */
63 int unsignedp;
64 /* Number of registers to use. 0 means put the whole arg in registers.
65 Also 0 if not passed in registers. */
66 int partial;
67 /* Non-zero if argument must be passed on stack.
68 Note that some arguments may be passed on the stack
69 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
70 pass_on_stack identifies arguments that *cannot* go in registers. */
71 int pass_on_stack;
72 /* Offset of this argument from beginning of stack-args. */
73 struct args_size offset;
74 /* Similar, but offset to the start of the stack slot. Different from
75 OFFSET if this arg pads downward. */
76 struct args_size slot_offset;
77 /* Size of this argument on the stack, rounded up for any padding it gets,
78 parts of the argument passed in registers do not count.
79 If REG_PARM_STACK_SPACE is defined, then register parms
80 are counted here as well. */
81 struct args_size size;
82 /* Location on the stack at which parameter should be stored. The store
83 has already been done if STACK == VALUE. */
84 rtx stack;
85 /* Location on the stack of the start of this argument slot. This can
86 differ from STACK if this arg pads downward. This location is known
87 to be aligned to FUNCTION_ARG_BOUNDARY. */
88 rtx stack_slot;
89 #ifdef ACCUMULATE_OUTGOING_ARGS
90 /* Place that this stack area has been saved, if needed. */
91 rtx save_area;
92 #endif
93 #ifdef STRICT_ALIGNMENT
94 /* If an argument's alignment does not permit direct copying into registers,
95 copy in smaller-sized pieces into pseudos. These are stored in a
96 block pointed to by this field. The next field says how many
97 word-sized pseudos we made. */
98 rtx *aligned_regs;
99 int n_aligned_regs;
100 #endif
101 };
102
103 #ifdef ACCUMULATE_OUTGOING_ARGS
104 /* A vector of one char per byte of stack space. A byte if non-zero if
105 the corresponding stack location has been used.
106 This vector is used to prevent a function call within an argument from
107 clobbering any stack already set up. */
108 static char *stack_usage_map;
109
110 /* Size of STACK_USAGE_MAP. */
111 static int highest_outgoing_arg_in_use;
112
113 /* stack_arg_under_construction is nonzero when an argument may be
114 initialized with a constructor call (including a C function that
115 returns a BLKmode struct) and expand_call must take special action
116 to make sure the object being constructed does not overlap the
117 argument list for the constructor call. */
118 int stack_arg_under_construction;
119 #endif
120
121 static int calls_function PROTO((tree, int));
122 static void emit_call_1 PROTO((rtx, tree, int, int, rtx, rtx, int,
123 rtx, int));
124 static void store_one_arg PROTO ((struct arg_data *, rtx, int, int,
125 tree, int));
126 \f
127 /* If WHICH is 1, return 1 if EXP contains a call to the built-in function
128 `alloca'.
129
130 If WHICH is 0, return 1 if EXP contains a call to any function.
131 Actually, we only need return 1 if evaluating EXP would require pushing
132 arguments on the stack, but that is too difficult to compute, so we just
133 assume any function call might require the stack. */
134
135 static int
136 calls_function (exp, which)
137 tree exp;
138 int which;
139 {
140 register int i;
141 int type = TREE_CODE_CLASS (TREE_CODE (exp));
142 int length = tree_code_length[(int) TREE_CODE (exp)];
143
144 /* Only expressions and references can contain calls. */
145
146 if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r'
147 && type != 'b')
148 return 0;
149
150 switch (TREE_CODE (exp))
151 {
152 case CALL_EXPR:
153 if (which == 0)
154 return 1;
155 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
156 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
157 == FUNCTION_DECL)
158 && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
159 && (DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
160 == BUILT_IN_ALLOCA))
161 return 1;
162
163 /* Third operand is RTL. */
164 length = 2;
165 break;
166
167 case SAVE_EXPR:
168 if (SAVE_EXPR_RTL (exp) != 0)
169 return 0;
170 break;
171
172 case BLOCK:
173 {
174 register tree local;
175
176 for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local))
177 if (DECL_INITIAL (local) != 0
178 && calls_function (DECL_INITIAL (local), which))
179 return 1;
180 }
181 {
182 register tree subblock;
183
184 for (subblock = BLOCK_SUBBLOCKS (exp);
185 subblock;
186 subblock = TREE_CHAIN (subblock))
187 if (calls_function (subblock, which))
188 return 1;
189 }
190 return 0;
191
192 case METHOD_CALL_EXPR:
193 length = 3;
194 break;
195
196 case WITH_CLEANUP_EXPR:
197 length = 1;
198 break;
199
200 case RTL_EXPR:
201 return 0;
202 }
203
204 for (i = 0; i < length; i++)
205 if (TREE_OPERAND (exp, i) != 0
206 && calls_function (TREE_OPERAND (exp, i), which))
207 return 1;
208
209 return 0;
210 }
211 \f
212 /* Force FUNEXP into a form suitable for the address of a CALL,
213 and return that as an rtx. Also load the static chain register
214 if FNDECL is a nested function.
215
216 USE_INSNS points to a variable holding a chain of USE insns
217 to which a USE of the static chain
218 register should be added, if required. */
219
220 rtx
221 prepare_call_address (funexp, fndecl, use_insns)
222 rtx funexp;
223 tree fndecl;
224 rtx *use_insns;
225 {
226 rtx static_chain_value = 0;
227
228 funexp = protect_from_queue (funexp, 0);
229
230 if (fndecl != 0)
231 /* Get possible static chain value for nested function in C. */
232 static_chain_value = lookup_static_chain (fndecl);
233
234 /* Make a valid memory address and copy constants thru pseudo-regs,
235 but not for a constant address if -fno-function-cse. */
236 if (GET_CODE (funexp) != SYMBOL_REF)
237 funexp = memory_address (FUNCTION_MODE, funexp);
238 else
239 {
240 #ifndef NO_FUNCTION_CSE
241 if (optimize && ! flag_no_function_cse)
242 #ifdef NO_RECURSIVE_FUNCTION_CSE
243 if (fndecl != current_function_decl)
244 #endif
245 funexp = force_reg (Pmode, funexp);
246 #endif
247 }
248
249 if (static_chain_value != 0)
250 {
251 emit_move_insn (static_chain_rtx, static_chain_value);
252
253 /* Put the USE insn in the chain we were passed. It will later be
254 output immediately in front of the CALL insn. */
255 push_to_sequence (*use_insns);
256 emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx));
257 *use_insns = get_insns ();
258 end_sequence ();
259 }
260
261 return funexp;
262 }
263
264 /* Generate instructions to call function FUNEXP,
265 and optionally pop the results.
266 The CALL_INSN is the first insn generated.
267
268 FUNTYPE is the data type of the function, or, for a library call,
269 the identifier for the name of the call. This is given to the
270 macro RETURN_POPS_ARGS to determine whether this function pops its own args.
271
272 STACK_SIZE is the number of bytes of arguments on the stack,
273 rounded up to STACK_BOUNDARY; zero if the size is variable.
274 This is both to put into the call insn and
275 to generate explicit popping code if necessary.
276
277 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
278 It is zero if this call doesn't want a structure value.
279
280 NEXT_ARG_REG is the rtx that results from executing
281 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1)
282 just after all the args have had their registers assigned.
283 This could be whatever you like, but normally it is the first
284 arg-register beyond those used for args in this call,
285 or 0 if all the arg-registers are used in this call.
286 It is passed on to `gen_call' so you can put this info in the call insn.
287
288 VALREG is a hard register in which a value is returned,
289 or 0 if the call does not return a value.
290
291 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
292 the args to this call were processed.
293 We restore `inhibit_defer_pop' to that value.
294
295 USE_INSNS is a chain of USE insns to be emitted immediately before
296 the actual CALL insn.
297
298 IS_CONST is true if this is a `const' call. */
299
300 static void
301 emit_call_1 (funexp, funtype, stack_size, struct_value_size, next_arg_reg,
302 valreg, old_inhibit_defer_pop, use_insns, is_const)
303 rtx funexp;
304 tree funtype;
305 int stack_size;
306 int struct_value_size;
307 rtx next_arg_reg;
308 rtx valreg;
309 int old_inhibit_defer_pop;
310 rtx use_insns;
311 int is_const;
312 {
313 rtx stack_size_rtx = GEN_INT (stack_size);
314 rtx struct_value_size_rtx = GEN_INT (struct_value_size);
315 rtx call_insn;
316 int already_popped = 0;
317
318 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
319 and we don't want to load it into a register as an optimization,
320 because prepare_call_address already did it if it should be done. */
321 if (GET_CODE (funexp) != SYMBOL_REF)
322 funexp = memory_address (FUNCTION_MODE, funexp);
323
324 #ifndef ACCUMULATE_OUTGOING_ARGS
325 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
326 if (HAVE_call_pop && HAVE_call_value_pop
327 && (RETURN_POPS_ARGS (funtype, stack_size) > 0 || stack_size == 0))
328 {
329 rtx n_pop = GEN_INT (RETURN_POPS_ARGS (funtype, stack_size));
330 rtx pat;
331
332 /* If this subroutine pops its own args, record that in the call insn
333 if possible, for the sake of frame pointer elimination. */
334 if (valreg)
335 pat = gen_call_value_pop (valreg,
336 gen_rtx (MEM, FUNCTION_MODE, funexp),
337 stack_size_rtx, next_arg_reg, n_pop);
338 else
339 pat = gen_call_pop (gen_rtx (MEM, FUNCTION_MODE, funexp),
340 stack_size_rtx, next_arg_reg, n_pop);
341
342 emit_call_insn (pat);
343 already_popped = 1;
344 }
345 else
346 #endif
347 #endif
348
349 #if defined (HAVE_call) && defined (HAVE_call_value)
350 if (HAVE_call && HAVE_call_value)
351 {
352 if (valreg)
353 emit_call_insn (gen_call_value (valreg,
354 gen_rtx (MEM, FUNCTION_MODE, funexp),
355 stack_size_rtx, next_arg_reg,
356 NULL_RTX));
357 else
358 emit_call_insn (gen_call (gen_rtx (MEM, FUNCTION_MODE, funexp),
359 stack_size_rtx, next_arg_reg,
360 struct_value_size_rtx));
361 }
362 else
363 #endif
364 abort ();
365
366 /* Find the CALL insn we just emitted and write the USE insns before it. */
367 for (call_insn = get_last_insn ();
368 call_insn && GET_CODE (call_insn) != CALL_INSN;
369 call_insn = PREV_INSN (call_insn))
370 ;
371
372 if (! call_insn)
373 abort ();
374
375 /* Put the USE insns before the CALL. */
376 emit_insns_before (use_insns, call_insn);
377
378 /* If this is a const call, then set the insn's unchanging bit. */
379 if (is_const)
380 CONST_CALL_P (call_insn) = 1;
381
382 /* Restore this now, so that we do defer pops for this call's args
383 if the context of the call as a whole permits. */
384 inhibit_defer_pop = old_inhibit_defer_pop;
385
386 #ifndef ACCUMULATE_OUTGOING_ARGS
387 /* If returning from the subroutine does not automatically pop the args,
388 we need an instruction to pop them sooner or later.
389 Perhaps do it now; perhaps just record how much space to pop later.
390
391 If returning from the subroutine does pop the args, indicate that the
392 stack pointer will be changed. */
393
394 if (stack_size != 0 && RETURN_POPS_ARGS (funtype, stack_size) > 0)
395 {
396 if (!already_popped)
397 emit_insn (gen_rtx (CLOBBER, VOIDmode, stack_pointer_rtx));
398 stack_size -= RETURN_POPS_ARGS (funtype, stack_size);
399 stack_size_rtx = GEN_INT (stack_size);
400 }
401
402 if (stack_size != 0)
403 {
404 if (flag_defer_pop && inhibit_defer_pop == 0 && !is_const)
405 pending_stack_adjust += stack_size;
406 else
407 adjust_stack (stack_size_rtx);
408 }
409 #endif
410 }
411
412 /* Generate all the code for a function call
413 and return an rtx for its value.
414 Store the value in TARGET (specified as an rtx) if convenient.
415 If the value is stored in TARGET then TARGET is returned.
416 If IGNORE is nonzero, then we ignore the value of the function call. */
417
418 rtx
419 expand_call (exp, target, ignore)
420 tree exp;
421 rtx target;
422 int ignore;
423 {
424 /* List of actual parameters. */
425 tree actparms = TREE_OPERAND (exp, 1);
426 /* RTX for the function to be called. */
427 rtx funexp;
428 /* Tree node for the function to be called (not the address!). */
429 tree funtree;
430 /* Data type of the function. */
431 tree funtype;
432 /* Declaration of the function being called,
433 or 0 if the function is computed (not known by name). */
434 tree fndecl = 0;
435 char *name = 0;
436
437 /* Register in which non-BLKmode value will be returned,
438 or 0 if no value or if value is BLKmode. */
439 rtx valreg;
440 /* Address where we should return a BLKmode value;
441 0 if value not BLKmode. */
442 rtx structure_value_addr = 0;
443 /* Nonzero if that address is being passed by treating it as
444 an extra, implicit first parameter. Otherwise,
445 it is passed by being copied directly into struct_value_rtx. */
446 int structure_value_addr_parm = 0;
447 /* Size of aggregate value wanted, or zero if none wanted
448 or if we are using the non-reentrant PCC calling convention
449 or expecting the value in registers. */
450 int struct_value_size = 0;
451 /* Nonzero if called function returns an aggregate in memory PCC style,
452 by returning the address of where to find it. */
453 int pcc_struct_value = 0;
454
455 /* Number of actual parameters in this call, including struct value addr. */
456 int num_actuals;
457 /* Number of named args. Args after this are anonymous ones
458 and they must all go on the stack. */
459 int n_named_args;
460 /* Count arg position in order args appear. */
461 int argpos;
462
463 /* Vector of information about each argument.
464 Arguments are numbered in the order they will be pushed,
465 not the order they are written. */
466 struct arg_data *args;
467
468 /* Total size in bytes of all the stack-parms scanned so far. */
469 struct args_size args_size;
470 /* Size of arguments before any adjustments (such as rounding). */
471 struct args_size original_args_size;
472 /* Data on reg parms scanned so far. */
473 CUMULATIVE_ARGS args_so_far;
474 /* Nonzero if a reg parm has been scanned. */
475 int reg_parm_seen;
476 /* Nonzero if this is an indirect function call. */
477 int current_call_is_indirect = 0;
478
479 /* Nonzero if we must avoid push-insns in the args for this call.
480 If stack space is allocated for register parameters, but not by the
481 caller, then it is preallocated in the fixed part of the stack frame.
482 So the entire argument block must then be preallocated (i.e., we
483 ignore PUSH_ROUNDING in that case). */
484
485 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
486 int must_preallocate = 1;
487 #else
488 #ifdef PUSH_ROUNDING
489 int must_preallocate = 0;
490 #else
491 int must_preallocate = 1;
492 #endif
493 #endif
494
495 /* Size of the stack reserved for parameter registers. */
496 int reg_parm_stack_space = 0;
497
498 /* 1 if scanning parms front to back, -1 if scanning back to front. */
499 int inc;
500 /* Address of space preallocated for stack parms
501 (on machines that lack push insns), or 0 if space not preallocated. */
502 rtx argblock = 0;
503
504 /* Nonzero if it is plausible that this is a call to alloca. */
505 int may_be_alloca;
506 /* Nonzero if this is a call to setjmp or a related function. */
507 int returns_twice;
508 /* Nonzero if this is a call to `longjmp'. */
509 int is_longjmp;
510 /* Nonzero if this is a call to an inline function. */
511 int is_integrable = 0;
512 /* Nonzero if this is a call to a `const' function.
513 Note that only explicitly named functions are handled as `const' here. */
514 int is_const = 0;
515 /* Nonzero if this is a call to a `volatile' function. */
516 int is_volatile = 0;
517 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
518 /* Define the boundary of the register parm stack space that needs to be
519 save, if any. */
520 int low_to_save = -1, high_to_save;
521 rtx save_area = 0; /* Place that it is saved */
522 #endif
523
524 #ifdef ACCUMULATE_OUTGOING_ARGS
525 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
526 char *initial_stack_usage_map = stack_usage_map;
527 #endif
528
529 rtx old_stack_level = 0;
530 int old_pending_adj;
531 int old_stack_arg_under_construction;
532 int old_inhibit_defer_pop = inhibit_defer_pop;
533 tree old_cleanups = cleanups_this_call;
534
535 rtx use_insns = 0;
536
537 register tree p;
538 register int i, j;
539
540 /* See if we can find a DECL-node for the actual function.
541 As a result, decide whether this is a call to an integrable function. */
542
543 p = TREE_OPERAND (exp, 0);
544 if (TREE_CODE (p) == ADDR_EXPR)
545 {
546 fndecl = TREE_OPERAND (p, 0);
547 if (TREE_CODE (fndecl) != FUNCTION_DECL)
548 {
549 /* May still be a `const' function if it is
550 a call through a pointer-to-const.
551 But we don't handle that. */
552 fndecl = 0;
553 }
554 else
555 {
556 if (!flag_no_inline
557 && fndecl != current_function_decl
558 && DECL_SAVED_INSNS (fndecl))
559 is_integrable = 1;
560 else if (! TREE_ADDRESSABLE (fndecl))
561 {
562 /* In case this function later becomes inlinable,
563 record that there was already a non-inline call to it.
564
565 Use abstraction instead of setting TREE_ADDRESSABLE
566 directly. */
567 if (DECL_INLINE (fndecl) && extra_warnings && warn_inline
568 && !flag_no_inline)
569 warning_with_decl (fndecl, "can't inline call to `%s' which was declared inline");
570 mark_addressable (fndecl);
571 }
572
573 if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl)
574 && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode)
575 is_const = 1;
576 }
577 }
578
579 is_volatile = TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (p)));
580
581 #ifdef REG_PARM_STACK_SPACE
582 #ifdef MAYBE_REG_PARM_STACK_SPACE
583 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
584 #else
585 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
586 #endif
587 #endif
588
589 /* Warn if this value is an aggregate type,
590 regardless of which calling convention we are using for it. */
591 if (warn_aggregate_return
592 && (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
593 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
594 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE
595 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE))
596 warning ("function call has aggregate value");
597
598 /* Set up a place to return a structure. */
599
600 /* Cater to broken compilers. */
601 if (aggregate_value_p (exp))
602 {
603 /* This call returns a big structure. */
604 is_const = 0;
605
606 #ifdef PCC_STATIC_STRUCT_RETURN
607 {
608 pcc_struct_value = 1;
609 is_integrable = 0; /* Easier than making that case work right. */
610 }
611 #else /* not PCC_STATIC_STRUCT_RETURN */
612 {
613 struct_value_size = int_size_in_bytes (TREE_TYPE (exp));
614
615 if (struct_value_size < 0)
616 abort ();
617
618 if (target && GET_CODE (target) == MEM)
619 structure_value_addr = XEXP (target, 0);
620 else
621 {
622 /* Assign a temporary on the stack to hold the value. */
623
624 /* For variable-sized objects, we must be called with a target
625 specified. If we were to allocate space on the stack here,
626 we would have no way of knowing when to free it. */
627
628 structure_value_addr
629 = XEXP (assign_stack_temp (BLKmode, struct_value_size, 1), 0);
630 target = 0;
631 }
632 }
633 #endif /* not PCC_STATIC_STRUCT_RETURN */
634 }
635
636 /* If called function is inline, try to integrate it. */
637
638 if (is_integrable)
639 {
640 rtx temp;
641 rtx before_call = get_last_insn ();
642
643 temp = expand_inline_function (fndecl, actparms, target,
644 ignore, TREE_TYPE (exp),
645 structure_value_addr);
646
647 /* If inlining succeeded, return. */
648 if ((HOST_WIDE_INT) temp != -1)
649 {
650 /* Perform all cleanups needed for the arguments of this call
651 (i.e. destructors in C++). It is ok if these destructors
652 clobber RETURN_VALUE_REG, because the only time we care about
653 this is when TARGET is that register. But in C++, we take
654 care to never return that register directly. */
655 expand_cleanups_to (old_cleanups);
656
657 #ifdef ACCUMULATE_OUTGOING_ARGS
658 /* If the outgoing argument list must be preserved, push
659 the stack before executing the inlined function if it
660 makes any calls. */
661
662 for (i = reg_parm_stack_space - 1; i >= 0; i--)
663 if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0)
664 break;
665
666 if (stack_arg_under_construction || i >= 0)
667 {
668 rtx insn = NEXT_INSN (before_call), seq;
669
670 /* Look for a call in the inline function code.
671 If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is
672 nonzero then there is a call and it is not necessary
673 to scan the insns. */
674
675 if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0)
676 for (; insn; insn = NEXT_INSN (insn))
677 if (GET_CODE (insn) == CALL_INSN)
678 break;
679
680 if (insn)
681 {
682 /* Reserve enough stack space so that the largest
683 argument list of any function call in the inline
684 function does not overlap the argument list being
685 evaluated. This is usually an overestimate because
686 allocate_dynamic_stack_space reserves space for an
687 outgoing argument list in addition to the requested
688 space, but there is no way to ask for stack space such
689 that an argument list of a certain length can be
690 safely constructed. */
691
692 int adjust = OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl));
693 #ifdef REG_PARM_STACK_SPACE
694 /* Add the stack space reserved for register arguments
695 in the inline function. What is really needed is the
696 largest value of reg_parm_stack_space in the inline
697 function, but that is not available. Using the current
698 value of reg_parm_stack_space is wrong, but gives
699 correct results on all supported machines. */
700 adjust += reg_parm_stack_space;
701 #endif
702 start_sequence ();
703 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
704 allocate_dynamic_stack_space (GEN_INT (adjust),
705 NULL_RTX, BITS_PER_UNIT);
706 seq = get_insns ();
707 end_sequence ();
708 emit_insns_before (seq, NEXT_INSN (before_call));
709 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
710 }
711 }
712 #endif
713
714 /* If the result is equivalent to TARGET, return TARGET to simplify
715 checks in store_expr. They can be equivalent but not equal in the
716 case of a function that returns BLKmode. */
717 if (temp != target && rtx_equal_p (temp, target))
718 return target;
719 return temp;
720 }
721
722 /* If inlining failed, mark FNDECL as needing to be compiled
723 separately after all. */
724 mark_addressable (fndecl);
725 }
726
727 /* When calling a const function, we must pop the stack args right away,
728 so that the pop is deleted or moved with the call. */
729 if (is_const)
730 NO_DEFER_POP;
731
732 function_call_count++;
733
734 if (fndecl && DECL_NAME (fndecl))
735 name = IDENTIFIER_POINTER (DECL_NAME (fndecl));
736
737 /* On some machines (such as the PA) indirect calls have a different
738 calling convention than normal calls. FUNCTION_ARG in the target
739 description can look at current_call_is_indirect to determine which
740 calling convention to use. */
741 current_call_is_indirect = (fndecl == 0);
742 #if 0
743 = TREE_CODE (TREE_OPERAND (exp, 0)) == NON_LVALUE_EXPR ? 1 : 0;
744 #endif
745
746 #if 0
747 /* Unless it's a call to a specific function that isn't alloca,
748 if it has one argument, we must assume it might be alloca. */
749
750 may_be_alloca =
751 (!(fndecl != 0 && strcmp (name, "alloca"))
752 && actparms != 0
753 && TREE_CHAIN (actparms) == 0);
754 #else
755 /* We assume that alloca will always be called by name. It
756 makes no sense to pass it as a pointer-to-function to
757 anything that does not understand its behavior. */
758 may_be_alloca =
759 (name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6
760 && name[0] == 'a'
761 && ! strcmp (name, "alloca"))
762 || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16
763 && name[0] == '_'
764 && ! strcmp (name, "__builtin_alloca"))));
765 #endif
766
767 /* See if this is a call to a function that can return more than once
768 or a call to longjmp. */
769
770 returns_twice = 0;
771 is_longjmp = 0;
772
773 if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 15)
774 {
775 char *tname = name;
776
777 if (name[0] == '_')
778 tname += ((name[1] == '_' && name[2] == 'x') ? 3 : 1);
779
780 if (tname[0] == 's')
781 {
782 returns_twice
783 = ((tname[1] == 'e'
784 && (! strcmp (tname, "setjmp")
785 || ! strcmp (tname, "setjmp_syscall")))
786 || (tname[1] == 'i'
787 && ! strcmp (tname, "sigsetjmp"))
788 || (tname[1] == 'a'
789 && ! strcmp (tname, "savectx")));
790 if (tname[1] == 'i'
791 && ! strcmp (tname, "siglongjmp"))
792 is_longjmp = 1;
793 }
794 else if ((tname[0] == 'q' && tname[1] == 's'
795 && ! strcmp (tname, "qsetjmp"))
796 || (tname[0] == 'v' && tname[1] == 'f'
797 && ! strcmp (tname, "vfork")))
798 returns_twice = 1;
799
800 else if (tname[0] == 'l' && tname[1] == 'o'
801 && ! strcmp (tname, "longjmp"))
802 is_longjmp = 1;
803 }
804
805 if (may_be_alloca)
806 current_function_calls_alloca = 1;
807
808 /* Don't let pending stack adjusts add up to too much.
809 Also, do all pending adjustments now
810 if there is any chance this might be a call to alloca. */
811
812 if (pending_stack_adjust >= 32
813 || (pending_stack_adjust > 0 && may_be_alloca))
814 do_pending_stack_adjust ();
815
816 /* Operand 0 is a pointer-to-function; get the type of the function. */
817 funtype = TREE_TYPE (TREE_OPERAND (exp, 0));
818 if (TREE_CODE (funtype) != POINTER_TYPE)
819 abort ();
820 funtype = TREE_TYPE (funtype);
821
822 /* Push the temporary stack slot level so that we can free temporaries used
823 by each of the arguments separately. */
824 push_temp_slots ();
825
826 /* Start updating where the next arg would go. */
827 INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX);
828
829 /* If struct_value_rtx is 0, it means pass the address
830 as if it were an extra parameter. */
831 if (structure_value_addr && struct_value_rtx == 0)
832 {
833 #ifdef ACCUMULATE_OUTGOING_ARGS
834 /* If the stack will be adjusted, make sure the structure address
835 does not refer to virtual_outgoing_args_rtx. */
836 rtx temp = (stack_arg_under_construction
837 ? copy_addr_to_reg (structure_value_addr)
838 : force_reg (Pmode, structure_value_addr));
839 #else
840 rtx temp = force_reg (Pmode, structure_value_addr);
841 #endif
842
843 actparms
844 = tree_cons (error_mark_node,
845 make_tree (build_pointer_type (TREE_TYPE (funtype)),
846 temp),
847 actparms);
848 structure_value_addr_parm = 1;
849 }
850
851 /* Count the arguments and set NUM_ACTUALS. */
852 for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++;
853 num_actuals = i;
854
855 /* Compute number of named args.
856 Normally, don't include the last named arg if anonymous args follow.
857 (If no anonymous args follow, the result of list_length
858 is actually one too large.)
859
860 If SETUP_INCOMING_VARARGS is defined, this machine will be able to
861 place unnamed args that were passed in registers into the stack. So
862 treat all args as named. This allows the insns emitting for a specific
863 argument list to be independent of the function declaration.
864
865 If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable
866 way to pass unnamed args in registers, so we must force them into
867 memory. */
868 #ifndef SETUP_INCOMING_VARARGS
869 if (TYPE_ARG_TYPES (funtype) != 0)
870 n_named_args
871 = list_length (TYPE_ARG_TYPES (funtype)) - 1
872 /* Count the struct value address, if it is passed as a parm. */
873 + structure_value_addr_parm;
874 else
875 #endif
876 /* If we know nothing, treat all args as named. */
877 n_named_args = num_actuals;
878
879 /* Make a vector to hold all the information about each arg. */
880 args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data));
881 bzero (args, num_actuals * sizeof (struct arg_data));
882
883 args_size.constant = 0;
884 args_size.var = 0;
885
886 /* In this loop, we consider args in the order they are written.
887 We fill up ARGS from the front of from the back if necessary
888 so that in any case the first arg to be pushed ends up at the front. */
889
890 #ifdef PUSH_ARGS_REVERSED
891 i = num_actuals - 1, inc = -1;
892 /* In this case, must reverse order of args
893 so that we compute and push the last arg first. */
894 #else
895 i = 0, inc = 1;
896 #endif
897
898 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
899 for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++)
900 {
901 tree type = TREE_TYPE (TREE_VALUE (p));
902 enum machine_mode mode;
903
904 args[i].tree_value = TREE_VALUE (p);
905
906 /* Replace erroneous argument with constant zero. */
907 if (type == error_mark_node || TYPE_SIZE (type) == 0)
908 args[i].tree_value = integer_zero_node, type = integer_type_node;
909
910 /* Decide where to pass this arg.
911
912 args[i].reg is nonzero if all or part is passed in registers.
913
914 args[i].partial is nonzero if part but not all is passed in registers,
915 and the exact value says how many words are passed in registers.
916
917 args[i].pass_on_stack is nonzero if the argument must at least be
918 computed on the stack. It may then be loaded back into registers
919 if args[i].reg is nonzero.
920
921 These decisions are driven by the FUNCTION_... macros and must agree
922 with those made by function.c. */
923
924 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
925 /* See if this argument should be passed by invisible reference. */
926 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, TYPE_MODE (type), type,
927 argpos < n_named_args))
928 {
929 #ifdef FUNCTION_ARG_CALLEE_COPIES
930 if (FUNCTION_ARG_CALLEE_COPIES (args_so_far, TYPE_MODE (type), type,
931 argpos < n_named_args)
932 /* If it's in a register, we must make a copy of it too. */
933 /* ??? Is this a sufficient test? Is there a better one? */
934 && !(TREE_CODE (args[i].tree_value) == VAR_DECL
935 && REG_P (DECL_RTL (args[i].tree_value))))
936 {
937 args[i].tree_value = build1 (ADDR_EXPR,
938 build_pointer_type (type),
939 args[i].tree_value);
940 type = build_pointer_type (type);
941 }
942 else
943 #endif
944 {
945 /* We make a copy of the object and pass the address to the
946 function being called. */
947 rtx copy;
948
949 if (TYPE_SIZE (type) == 0
950 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
951 {
952 /* This is a variable-sized object. Make space on the stack
953 for it. */
954 rtx size_rtx = expr_size (TREE_VALUE (p));
955
956 if (old_stack_level == 0)
957 {
958 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
959 old_pending_adj = pending_stack_adjust;
960 pending_stack_adjust = 0;
961 }
962
963 copy = gen_rtx (MEM, BLKmode,
964 allocate_dynamic_stack_space (size_rtx,
965 NULL_RTX,
966 TYPE_ALIGN (type)));
967 }
968 else
969 {
970 int size = int_size_in_bytes (type);
971 copy = assign_stack_temp (TYPE_MODE (type), size, 1);
972 }
973
974 store_expr (args[i].tree_value, copy, 0);
975
976 args[i].tree_value = build1 (ADDR_EXPR,
977 build_pointer_type (type),
978 make_tree (type, copy));
979 type = build_pointer_type (type);
980 }
981 }
982 #endif /* FUNCTION_ARG_PASS_BY_REFERENCE */
983
984 mode = TYPE_MODE (type);
985
986 #ifdef PROMOTE_FUNCTION_ARGS
987 /* Compute the mode in which the arg is actually to be extended to. */
988 if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == ENUMERAL_TYPE
989 || TREE_CODE (type) == BOOLEAN_TYPE || TREE_CODE (type) == CHAR_TYPE
990 || TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == POINTER_TYPE
991 || TREE_CODE (type) == OFFSET_TYPE)
992 {
993 int unsignedp = TREE_UNSIGNED (type);
994 PROMOTE_MODE (mode, unsignedp, type);
995 args[i].unsignedp = unsignedp;
996 }
997 #endif
998
999 args[i].mode = mode;
1000 args[i].reg = FUNCTION_ARG (args_so_far, mode, type,
1001 argpos < n_named_args);
1002 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1003 if (args[i].reg)
1004 args[i].partial
1005 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, type,
1006 argpos < n_named_args);
1007 #endif
1008
1009 args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type);
1010
1011 /* If FUNCTION_ARG returned an (expr_list (nil) FOO), it means that
1012 we are to pass this arg in the register(s) designated by FOO, but
1013 also to pass it in the stack. */
1014 if (args[i].reg && GET_CODE (args[i].reg) == EXPR_LIST
1015 && XEXP (args[i].reg, 0) == 0)
1016 args[i].pass_on_stack = 1, args[i].reg = XEXP (args[i].reg, 1);
1017
1018 /* If this is an addressable type, we must preallocate the stack
1019 since we must evaluate the object into its final location.
1020
1021 If this is to be passed in both registers and the stack, it is simpler
1022 to preallocate. */
1023 if (TREE_ADDRESSABLE (type)
1024 || (args[i].pass_on_stack && args[i].reg != 0))
1025 must_preallocate = 1;
1026
1027 /* If this is an addressable type, we cannot pre-evaluate it. Thus,
1028 we cannot consider this function call constant. */
1029 if (TREE_ADDRESSABLE (type))
1030 is_const = 0;
1031
1032 /* Compute the stack-size of this argument. */
1033 if (args[i].reg == 0 || args[i].partial != 0
1034 #ifdef REG_PARM_STACK_SPACE
1035 || reg_parm_stack_space > 0
1036 #endif
1037 || args[i].pass_on_stack)
1038 locate_and_pad_parm (mode, type,
1039 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1040 1,
1041 #else
1042 args[i].reg != 0,
1043 #endif
1044 fndecl, &args_size, &args[i].offset,
1045 &args[i].size);
1046
1047 #ifndef ARGS_GROW_DOWNWARD
1048 args[i].slot_offset = args_size;
1049 #endif
1050
1051 #ifndef REG_PARM_STACK_SPACE
1052 /* If a part of the arg was put into registers,
1053 don't include that part in the amount pushed. */
1054 if (! args[i].pass_on_stack)
1055 args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD)
1056 / (PARM_BOUNDARY / BITS_PER_UNIT)
1057 * (PARM_BOUNDARY / BITS_PER_UNIT));
1058 #endif
1059
1060 /* Update ARGS_SIZE, the total stack space for args so far. */
1061
1062 args_size.constant += args[i].size.constant;
1063 if (args[i].size.var)
1064 {
1065 ADD_PARM_SIZE (args_size, args[i].size.var);
1066 }
1067
1068 /* Since the slot offset points to the bottom of the slot,
1069 we must record it after incrementing if the args grow down. */
1070 #ifdef ARGS_GROW_DOWNWARD
1071 args[i].slot_offset = args_size;
1072
1073 args[i].slot_offset.constant = -args_size.constant;
1074 if (args_size.var)
1075 {
1076 SUB_PARM_SIZE (args[i].slot_offset, args_size.var);
1077 }
1078 #endif
1079
1080 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1081 have been used, etc. */
1082
1083 FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type,
1084 argpos < n_named_args);
1085 }
1086
1087 #ifdef FINAL_REG_PARM_STACK_SPACE
1088 reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant,
1089 args_size.var);
1090 #endif
1091
1092 /* Compute the actual size of the argument block required. The variable
1093 and constant sizes must be combined, the size may have to be rounded,
1094 and there may be a minimum required size. */
1095
1096 original_args_size = args_size;
1097 if (args_size.var)
1098 {
1099 /* If this function requires a variable-sized argument list, don't try to
1100 make a cse'able block for this call. We may be able to do this
1101 eventually, but it is too complicated to keep track of what insns go
1102 in the cse'able block and which don't. */
1103
1104 is_const = 0;
1105 must_preallocate = 1;
1106
1107 args_size.var = ARGS_SIZE_TREE (args_size);
1108 args_size.constant = 0;
1109
1110 #ifdef STACK_BOUNDARY
1111 if (STACK_BOUNDARY != BITS_PER_UNIT)
1112 args_size.var = round_up (args_size.var, STACK_BYTES);
1113 #endif
1114
1115 #ifdef REG_PARM_STACK_SPACE
1116 if (reg_parm_stack_space > 0)
1117 {
1118 args_size.var
1119 = size_binop (MAX_EXPR, args_size.var,
1120 size_int (REG_PARM_STACK_SPACE (fndecl)));
1121
1122 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1123 /* The area corresponding to register parameters is not to count in
1124 the size of the block we need. So make the adjustment. */
1125 args_size.var
1126 = size_binop (MINUS_EXPR, args_size.var,
1127 size_int (reg_parm_stack_space));
1128 #endif
1129 }
1130 #endif
1131 }
1132 else
1133 {
1134 #ifdef STACK_BOUNDARY
1135 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
1136 / STACK_BYTES) * STACK_BYTES);
1137 #endif
1138
1139 #ifdef REG_PARM_STACK_SPACE
1140 args_size.constant = MAX (args_size.constant,
1141 reg_parm_stack_space);
1142 #ifdef MAYBE_REG_PARM_STACK_SPACE
1143 if (reg_parm_stack_space == 0)
1144 args_size.constant = 0;
1145 #endif
1146 #ifndef OUTGOING_REG_PARM_STACK_SPACE
1147 args_size.constant -= reg_parm_stack_space;
1148 #endif
1149 #endif
1150 }
1151
1152 /* See if we have or want to preallocate stack space.
1153
1154 If we would have to push a partially-in-regs parm
1155 before other stack parms, preallocate stack space instead.
1156
1157 If the size of some parm is not a multiple of the required stack
1158 alignment, we must preallocate.
1159
1160 If the total size of arguments that would otherwise create a copy in
1161 a temporary (such as a CALL) is more than half the total argument list
1162 size, preallocation is faster.
1163
1164 Another reason to preallocate is if we have a machine (like the m88k)
1165 where stack alignment is required to be maintained between every
1166 pair of insns, not just when the call is made. However, we assume here
1167 that such machines either do not have push insns (and hence preallocation
1168 would occur anyway) or the problem is taken care of with
1169 PUSH_ROUNDING. */
1170
1171 if (! must_preallocate)
1172 {
1173 int partial_seen = 0;
1174 int copy_to_evaluate_size = 0;
1175
1176 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1177 {
1178 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1179 partial_seen = 1;
1180 else if (partial_seen && args[i].reg == 0)
1181 must_preallocate = 1;
1182
1183 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1184 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1185 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1186 || TREE_CODE (args[i].tree_value) == COND_EXPR
1187 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1188 copy_to_evaluate_size
1189 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1190 }
1191
1192 if (copy_to_evaluate_size * 2 >= args_size.constant
1193 && args_size.constant > 0)
1194 must_preallocate = 1;
1195 }
1196
1197 /* If the structure value address will reference the stack pointer, we must
1198 stabilize it. We don't need to do this if we know that we are not going
1199 to adjust the stack pointer in processing this call. */
1200
1201 if (structure_value_addr
1202 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
1203 || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr))
1204 && (args_size.var
1205 #ifndef ACCUMULATE_OUTGOING_ARGS
1206 || args_size.constant
1207 #endif
1208 ))
1209 structure_value_addr = copy_to_reg (structure_value_addr);
1210
1211 /* If this function call is cse'able, precompute all the parameters.
1212 Note that if the parameter is constructed into a temporary, this will
1213 cause an additional copy because the parameter will be constructed
1214 into a temporary location and then copied into the outgoing arguments.
1215 If a parameter contains a call to alloca and this function uses the
1216 stack, precompute the parameter. */
1217
1218 /* If we preallocated the stack space, and some arguments must be passed
1219 on the stack, then we must precompute any parameter which contains a
1220 function call which will store arguments on the stack.
1221 Otherwise, evaluating the parameter may clobber previous parameters
1222 which have already been stored into the stack. */
1223
1224 for (i = 0; i < num_actuals; i++)
1225 if (is_const
1226 || ((args_size.var != 0 || args_size.constant != 0)
1227 && calls_function (args[i].tree_value, 1))
1228 || (must_preallocate && (args_size.var != 0 || args_size.constant != 0)
1229 && calls_function (args[i].tree_value, 0)))
1230 {
1231 args[i].initial_value = args[i].value
1232 = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0);
1233
1234 if (GET_MODE (args[i].value ) != VOIDmode
1235 && GET_MODE (args[i].value) != args[i].mode)
1236 args[i].value = convert_to_mode (args[i].mode, args[i].value,
1237 args[i].unsignedp);
1238 preserve_temp_slots (args[i].value);
1239
1240 free_temp_slots ();
1241
1242 /* ANSI doesn't require a sequence point here,
1243 but PCC has one, so this will avoid some problems. */
1244 emit_queue ();
1245 }
1246
1247 /* Now we are about to start emitting insns that can be deleted
1248 if a libcall is deleted. */
1249 if (is_const)
1250 start_sequence ();
1251
1252 /* If we have no actual push instructions, or shouldn't use them,
1253 make space for all args right now. */
1254
1255 if (args_size.var != 0)
1256 {
1257 if (old_stack_level == 0)
1258 {
1259 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1260 old_pending_adj = pending_stack_adjust;
1261 pending_stack_adjust = 0;
1262 #ifdef ACCUMULATE_OUTGOING_ARGS
1263 /* stack_arg_under_construction says whether a stack arg is
1264 being constructed at the old stack level. Pushing the stack
1265 gets a clean outgoing argument block. */
1266 old_stack_arg_under_construction = stack_arg_under_construction;
1267 stack_arg_under_construction = 0;
1268 #endif
1269 }
1270 argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0);
1271 }
1272 else if (must_preallocate)
1273 {
1274 /* Note that we must go through the motions of allocating an argument
1275 block even if the size is zero because we may be storing args
1276 in the area reserved for register arguments, which may be part of
1277 the stack frame. */
1278 int needed = args_size.constant;
1279
1280 #ifdef ACCUMULATE_OUTGOING_ARGS
1281 /* Store the maximum argument space used. It will be pushed by the
1282 prologue.
1283
1284 Since the stack pointer will never be pushed, it is possible for
1285 the evaluation of a parm to clobber something we have already
1286 written to the stack. Since most function calls on RISC machines
1287 do not use the stack, this is uncommon, but must work correctly.
1288
1289 Therefore, we save any area of the stack that was already written
1290 and that we are using. Here we set up to do this by making a new
1291 stack usage map from the old one. The actual save will be done
1292 by store_one_arg.
1293
1294 Another approach might be to try to reorder the argument
1295 evaluations to avoid this conflicting stack usage. */
1296
1297 if (needed > current_function_outgoing_args_size)
1298 current_function_outgoing_args_size = needed;
1299
1300 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1301 /* Since we will be writing into the entire argument area, the
1302 map must be allocated for its entire size, not just the part that
1303 is the responsibility of the caller. */
1304 needed += reg_parm_stack_space;
1305 #endif
1306
1307 #ifdef ARGS_GROW_DOWNWARD
1308 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
1309 needed + 1);
1310 #else
1311 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, needed);
1312 #endif
1313 stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use);
1314
1315 if (initial_highest_arg_in_use)
1316 bcopy (initial_stack_usage_map, stack_usage_map,
1317 initial_highest_arg_in_use);
1318
1319 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
1320 bzero (&stack_usage_map[initial_highest_arg_in_use],
1321 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
1322 needed = 0;
1323
1324 /* The address of the outgoing argument list must not be copied to a
1325 register here, because argblock would be left pointing to the
1326 wrong place after the call to allocate_dynamic_stack_space below. */
1327
1328 argblock = virtual_outgoing_args_rtx;
1329
1330 #else /* not ACCUMULATE_OUTGOING_ARGS */
1331 if (inhibit_defer_pop == 0)
1332 {
1333 /* Try to reuse some or all of the pending_stack_adjust
1334 to get this space. Maybe we can avoid any pushing. */
1335 if (needed > pending_stack_adjust)
1336 {
1337 needed -= pending_stack_adjust;
1338 pending_stack_adjust = 0;
1339 }
1340 else
1341 {
1342 pending_stack_adjust -= needed;
1343 needed = 0;
1344 }
1345 }
1346 /* Special case this because overhead of `push_block' in this
1347 case is non-trivial. */
1348 if (needed == 0)
1349 argblock = virtual_outgoing_args_rtx;
1350 else
1351 argblock = push_block (GEN_INT (needed), 0, 0);
1352
1353 /* We only really need to call `copy_to_reg' in the case where push
1354 insns are going to be used to pass ARGBLOCK to a function
1355 call in ARGS. In that case, the stack pointer changes value
1356 from the allocation point to the call point, and hence
1357 the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well.
1358 But might as well always do it. */
1359 argblock = copy_to_reg (argblock);
1360 #endif /* not ACCUMULATE_OUTGOING_ARGS */
1361 }
1362
1363
1364 #ifdef ACCUMULATE_OUTGOING_ARGS
1365 /* The save/restore code in store_one_arg handles all cases except one:
1366 a constructor call (including a C function returning a BLKmode struct)
1367 to initialize an argument. */
1368 if (stack_arg_under_construction)
1369 {
1370 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
1371 rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant);
1372 #else
1373 rtx push_size = GEN_INT (args_size.constant);
1374 #endif
1375 if (old_stack_level == 0)
1376 {
1377 emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX);
1378 old_pending_adj = pending_stack_adjust;
1379 pending_stack_adjust = 0;
1380 /* stack_arg_under_construction says whether a stack arg is
1381 being constructed at the old stack level. Pushing the stack
1382 gets a clean outgoing argument block. */
1383 old_stack_arg_under_construction = stack_arg_under_construction;
1384 stack_arg_under_construction = 0;
1385 /* Make a new map for the new argument list. */
1386 stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use);
1387 bzero (stack_usage_map, highest_outgoing_arg_in_use);
1388 highest_outgoing_arg_in_use = 0;
1389 }
1390 allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT);
1391 }
1392 /* If argument evaluation might modify the stack pointer, copy the
1393 address of the argument list to a register. */
1394 for (i = 0; i < num_actuals; i++)
1395 if (args[i].pass_on_stack)
1396 {
1397 argblock = copy_addr_to_reg (argblock);
1398 break;
1399 }
1400 #endif
1401
1402
1403 /* If we preallocated stack space, compute the address of each argument.
1404 We need not ensure it is a valid memory address here; it will be
1405 validized when it is used. */
1406 if (argblock)
1407 {
1408 rtx arg_reg = argblock;
1409 int arg_offset = 0;
1410
1411 if (GET_CODE (argblock) == PLUS)
1412 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1413
1414 for (i = 0; i < num_actuals; i++)
1415 {
1416 rtx offset = ARGS_SIZE_RTX (args[i].offset);
1417 rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset);
1418 rtx addr;
1419
1420 /* Skip this parm if it will not be passed on the stack. */
1421 if (! args[i].pass_on_stack && args[i].reg != 0)
1422 continue;
1423
1424 if (GET_CODE (offset) == CONST_INT)
1425 addr = plus_constant (arg_reg, INTVAL (offset));
1426 else
1427 addr = gen_rtx (PLUS, Pmode, arg_reg, offset);
1428
1429 addr = plus_constant (addr, arg_offset);
1430 args[i].stack = gen_rtx (MEM, args[i].mode, addr);
1431
1432 if (GET_CODE (slot_offset) == CONST_INT)
1433 addr = plus_constant (arg_reg, INTVAL (slot_offset));
1434 else
1435 addr = gen_rtx (PLUS, Pmode, arg_reg, slot_offset);
1436
1437 addr = plus_constant (addr, arg_offset);
1438 args[i].stack_slot = gen_rtx (MEM, args[i].mode, addr);
1439 }
1440 }
1441
1442 #ifdef PUSH_ARGS_REVERSED
1443 #ifdef STACK_BOUNDARY
1444 /* If we push args individually in reverse order, perform stack alignment
1445 before the first push (the last arg). */
1446 if (argblock == 0)
1447 anti_adjust_stack (GEN_INT (args_size.constant
1448 - original_args_size.constant));
1449 #endif
1450 #endif
1451
1452 /* Don't try to defer pops if preallocating, not even from the first arg,
1453 since ARGBLOCK probably refers to the SP. */
1454 if (argblock)
1455 NO_DEFER_POP;
1456
1457 /* Get the function to call, in the form of RTL. */
1458 if (fndecl)
1459 /* Get a SYMBOL_REF rtx for the function address. */
1460 funexp = XEXP (DECL_RTL (fndecl), 0);
1461 else
1462 /* Generate an rtx (probably a pseudo-register) for the address. */
1463 {
1464 funexp = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
1465 free_temp_slots (); /* FUNEXP can't be BLKmode */
1466 emit_queue ();
1467 }
1468
1469 /* Figure out the register where the value, if any, will come back. */
1470 valreg = 0;
1471 if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode
1472 && ! structure_value_addr)
1473 {
1474 if (pcc_struct_value)
1475 valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
1476 fndecl);
1477 else
1478 valreg = hard_function_value (TREE_TYPE (exp), fndecl);
1479 }
1480
1481 /* Precompute all register parameters. It isn't safe to compute anything
1482 once we have started filling any specific hard regs. */
1483 reg_parm_seen = 0;
1484 for (i = 0; i < num_actuals; i++)
1485 if (args[i].reg != 0 && ! args[i].pass_on_stack)
1486 {
1487 reg_parm_seen = 1;
1488
1489 if (args[i].value == 0)
1490 {
1491 args[i].value = expand_expr (args[i].tree_value, NULL_RTX,
1492 VOIDmode, 0);
1493 preserve_temp_slots (args[i].value);
1494 free_temp_slots ();
1495
1496 /* ANSI doesn't require a sequence point here,
1497 but PCC has one, so this will avoid some problems. */
1498 emit_queue ();
1499 }
1500
1501 /* If we are to promote the function arg to a wider mode,
1502 do it now. */
1503
1504 if (GET_MODE (args[i].value) != VOIDmode
1505 && GET_MODE (args[i].value) != args[i].mode)
1506 args[i].value = convert_to_mode (args[i].mode, args[i].value,
1507 args[i].unsignedp);
1508 }
1509
1510 #if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE)
1511 /* The argument list is the property of the called routine and it
1512 may clobber it. If the fixed area has been used for previous
1513 parameters, we must save and restore it.
1514
1515 Here we compute the boundary of the that needs to be saved, if any. */
1516
1517 #ifdef ARGS_GROW_DOWNWARD
1518 for (i = 0; i < reg_parm_stack_space + 1; i++)
1519 #else
1520 for (i = 0; i < reg_parm_stack_space; i++)
1521 #endif
1522 {
1523 if (i >= highest_outgoing_arg_in_use
1524 || stack_usage_map[i] == 0)
1525 continue;
1526
1527 if (low_to_save == -1)
1528 low_to_save = i;
1529
1530 high_to_save = i;
1531 }
1532
1533 if (low_to_save >= 0)
1534 {
1535 int num_to_save = high_to_save - low_to_save + 1;
1536 enum machine_mode save_mode
1537 = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
1538 rtx stack_area;
1539
1540 /* If we don't have the required alignment, must do this in BLKmode. */
1541 if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode),
1542 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
1543 save_mode = BLKmode;
1544
1545 stack_area = gen_rtx (MEM, save_mode,
1546 memory_address (save_mode,
1547
1548 #ifdef ARGS_GROW_DOWNWARD
1549 plus_constant (argblock,
1550 - high_to_save)
1551 #else
1552 plus_constant (argblock,
1553 low_to_save)
1554 #endif
1555 ));
1556 if (save_mode == BLKmode)
1557 {
1558 save_area = assign_stack_temp (BLKmode, num_to_save, 1);
1559 emit_block_move (validize_mem (save_area), stack_area,
1560 GEN_INT (num_to_save),
1561 PARM_BOUNDARY / BITS_PER_UNIT);
1562 }
1563 else
1564 {
1565 save_area = gen_reg_rtx (save_mode);
1566 emit_move_insn (save_area, stack_area);
1567 }
1568 }
1569 #endif
1570
1571
1572 /* Now store (and compute if necessary) all non-register parms.
1573 These come before register parms, since they can require block-moves,
1574 which could clobber the registers used for register parms.
1575 Parms which have partial registers are not stored here,
1576 but we do preallocate space here if they want that. */
1577
1578 for (i = 0; i < num_actuals; i++)
1579 if (args[i].reg == 0 || args[i].pass_on_stack)
1580 store_one_arg (&args[i], argblock, may_be_alloca,
1581 args_size.var != 0, fndecl, reg_parm_stack_space);
1582
1583 #ifdef STRICT_ALIGNMENT
1584 /* If we have a parm that is passed in registers but not in memory
1585 and whose alignment does not permit a direct copy into registers,
1586 make a group of pseudos that correspond to each register that we
1587 will later fill. */
1588
1589 for (i = 0; i < num_actuals; i++)
1590 if (args[i].reg != 0 && ! args[i].pass_on_stack
1591 && args[i].mode == BLKmode
1592 && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value))
1593 < MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
1594 {
1595 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1596
1597 args[i].n_aligned_regs
1598 = args[i].partial ? args[i].partial
1599 : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
1600
1601 args[i].aligned_regs = (rtx *) alloca (sizeof (rtx)
1602 * args[i].n_aligned_regs);
1603
1604 for (j = 0; j < args[i].n_aligned_regs; j++)
1605 {
1606 rtx reg = gen_reg_rtx (word_mode);
1607 rtx word = operand_subword_force (args[i].value, j, BLKmode);
1608 int bitsize = TYPE_ALIGN (TREE_TYPE (args[i].tree_value));
1609 int bitpos;
1610
1611 args[i].aligned_regs[j] = reg;
1612
1613 /* Clobber REG and move each partword into it. Ensure we don't
1614 go past the end of the structure. Note that the loop below
1615 works because we've already verified that padding
1616 and endianness are compatible. */
1617
1618 emit_insn (gen_rtx (CLOBBER, VOIDmode, reg));
1619
1620 for (bitpos = 0;
1621 bitpos < BITS_PER_WORD && bytes > 0;
1622 bitpos += bitsize, bytes -= bitsize / BITS_PER_UNIT)
1623 {
1624 int xbitpos = (BYTES_BIG_ENDIAN
1625 ? BITS_PER_WORD - bitpos - bitsize
1626 : bitpos);
1627
1628 store_bit_field (reg, bitsize, xbitpos, word_mode,
1629 extract_bit_field (word, bitsize, xbitpos, 1,
1630 NULL_RTX, word_mode,
1631 word_mode,
1632 bitsize / BITS_PER_UNIT,
1633 BITS_PER_WORD),
1634 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
1635 }
1636 }
1637 }
1638 #endif
1639
1640 /* Now store any partially-in-registers parm.
1641 This is the last place a block-move can happen. */
1642 if (reg_parm_seen)
1643 for (i = 0; i < num_actuals; i++)
1644 if (args[i].partial != 0 && ! args[i].pass_on_stack)
1645 store_one_arg (&args[i], argblock, may_be_alloca,
1646 args_size.var != 0, fndecl, reg_parm_stack_space);
1647
1648 #ifndef PUSH_ARGS_REVERSED
1649 #ifdef STACK_BOUNDARY
1650 /* If we pushed args in forward order, perform stack alignment
1651 after pushing the last arg. */
1652 if (argblock == 0)
1653 anti_adjust_stack (GEN_INT (args_size.constant
1654 - original_args_size.constant));
1655 #endif
1656 #endif
1657
1658 /* If register arguments require space on the stack and stack space
1659 was not preallocated, allocate stack space here for arguments
1660 passed in registers. */
1661 #if ! defined(ALLOCATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE)
1662 if (must_preallocate == 0 && reg_parm_stack_space > 0)
1663 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
1664 #endif
1665
1666 /* Pass the function the address in which to return a structure value. */
1667 if (structure_value_addr && ! structure_value_addr_parm)
1668 {
1669 emit_move_insn (struct_value_rtx,
1670 force_reg (Pmode,
1671 force_operand (structure_value_addr,
1672 NULL_RTX)));
1673 if (GET_CODE (struct_value_rtx) == REG)
1674 {
1675 push_to_sequence (use_insns);
1676 emit_insn (gen_rtx (USE, VOIDmode, struct_value_rtx));
1677 use_insns = get_insns ();
1678 end_sequence ();
1679 }
1680 }
1681
1682 /* Now do the register loads required for any wholly-register parms or any
1683 parms which are passed both on the stack and in a register. Their
1684 expressions were already evaluated.
1685
1686 Mark all register-parms as living through the call, putting these USE
1687 insns in a list headed by USE_INSNS. */
1688
1689 for (i = 0; i < num_actuals; i++)
1690 {
1691 rtx list = args[i].reg;
1692 int partial = args[i].partial;
1693
1694 while (list)
1695 {
1696 rtx reg;
1697 int nregs;
1698
1699 /* Process each register that needs to get this arg. */
1700 if (GET_CODE (list) == EXPR_LIST)
1701 reg = XEXP (list, 0), list = XEXP (list, 1);
1702 else
1703 reg = list, list = 0;
1704
1705 /* Set to non-zero if must move a word at a time, even if just one
1706 word (e.g, partial == 1 && mode == DFmode). Set to zero if
1707 we just use a normal move insn. */
1708 nregs = (partial ? partial
1709 : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1710 ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value))
1711 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
1712 : 0));
1713
1714 /* If simple case, just do move. If normal partial, store_one_arg
1715 has already loaded the register for us. In all other cases,
1716 load the register(s) from memory. */
1717
1718 if (nregs == 0)
1719 emit_move_insn (reg, args[i].value);
1720
1721 #ifdef STRICT_ALIGNMENT
1722 /* If we have pre-computed the values to put in the registers in
1723 the case of non-aligned structures, copy them in now. */
1724
1725 else if (args[i].n_aligned_regs != 0)
1726 for (j = 0; j < args[i].n_aligned_regs; j++)
1727 emit_move_insn (gen_rtx (REG, word_mode, REGNO (reg) + j),
1728 args[i].aligned_regs[j]);
1729 #endif
1730
1731 else if (args[i].partial == 0 || args[i].pass_on_stack)
1732 move_block_to_reg (REGNO (reg),
1733 validize_mem (args[i].value), nregs,
1734 args[i].mode);
1735
1736 push_to_sequence (use_insns);
1737 if (nregs == 0)
1738 emit_insn (gen_rtx (USE, VOIDmode, reg));
1739 else
1740 use_regs (REGNO (reg), nregs);
1741 use_insns = get_insns ();
1742 end_sequence ();
1743
1744 /* PARTIAL referred only to the first register, so clear it for the
1745 next time. */
1746 partial = 0;
1747 }
1748 }
1749
1750 /* Perform postincrements before actually calling the function. */
1751 emit_queue ();
1752
1753 /* All arguments and registers used for the call must be set up by now! */
1754
1755 funexp = prepare_call_address (funexp, fndecl, &use_insns);
1756
1757 /* Generate the actual call instruction. */
1758 emit_call_1 (funexp, funtype, args_size.constant, struct_value_size,
1759 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
1760 valreg, old_inhibit_defer_pop, use_insns, is_const);
1761
1762 /* If call is cse'able, make appropriate pair of reg-notes around it.
1763 Test valreg so we don't crash; may safely ignore `const'
1764 if return type is void. */
1765 if (is_const && valreg != 0)
1766 {
1767 rtx note = 0;
1768 rtx temp = gen_reg_rtx (GET_MODE (valreg));
1769 rtx insns;
1770
1771 /* Construct an "equal form" for the value which mentions all the
1772 arguments in order as well as the function name. */
1773 #ifdef PUSH_ARGS_REVERSED
1774 for (i = 0; i < num_actuals; i++)
1775 note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1776 #else
1777 for (i = num_actuals - 1; i >= 0; i--)
1778 note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note);
1779 #endif
1780 note = gen_rtx (EXPR_LIST, VOIDmode, funexp, note);
1781
1782 insns = get_insns ();
1783 end_sequence ();
1784
1785 emit_libcall_block (insns, temp, valreg, note);
1786
1787 valreg = temp;
1788 }
1789
1790 /* For calls to `setjmp', etc., inform flow.c it should complain
1791 if nonvolatile values are live. */
1792
1793 if (returns_twice)
1794 {
1795 emit_note (name, NOTE_INSN_SETJMP);
1796 current_function_calls_setjmp = 1;
1797 }
1798
1799 if (is_longjmp)
1800 current_function_calls_longjmp = 1;
1801
1802 /* Notice functions that cannot return.
1803 If optimizing, insns emitted below will be dead.
1804 If not optimizing, they will exist, which is useful
1805 if the user uses the `return' command in the debugger. */
1806
1807 if (is_volatile || is_longjmp)
1808 emit_barrier ();
1809
1810 /* If value type not void, return an rtx for the value. */
1811
1812 /* If there are cleanups to be called, don't use a hard reg as target. */
1813 if (cleanups_this_call != old_cleanups
1814 && target && REG_P (target)
1815 && REGNO (target) < FIRST_PSEUDO_REGISTER)
1816 target = 0;
1817
1818 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode
1819 || ignore)
1820 {
1821 target = const0_rtx;
1822 }
1823 else if (structure_value_addr)
1824 {
1825 if (target == 0 || GET_CODE (target) != MEM)
1826 {
1827 target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1828 memory_address (TYPE_MODE (TREE_TYPE (exp)),
1829 structure_value_addr));
1830 MEM_IN_STRUCT_P (target)
1831 = (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1832 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
1833 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
1834 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE);
1835 }
1836 }
1837 else if (pcc_struct_value)
1838 {
1839 if (target == 0)
1840 {
1841 target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1842 copy_to_reg (valreg));
1843 MEM_IN_STRUCT_P (target)
1844 = (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
1845 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
1846 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
1847 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE);
1848 }
1849 else if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
1850 emit_move_insn (target, gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)),
1851 copy_to_reg (valreg)));
1852 else
1853 emit_block_move (target, gen_rtx (MEM, BLKmode, copy_to_reg (valreg)),
1854 expr_size (exp),
1855 TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT);
1856 }
1857 else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp))
1858 && GET_MODE (target) == GET_MODE (valreg))
1859 /* TARGET and VALREG cannot be equal at this point because the latter
1860 would not have REG_FUNCTION_VALUE_P true, while the former would if
1861 it were referring to the same register.
1862
1863 If they refer to the same register, this move will be a no-op, except
1864 when function inlining is being done. */
1865 emit_move_insn (target, valreg);
1866 else
1867 target = copy_to_reg (valreg);
1868
1869 #ifdef PROMOTE_FUNCTION_RETURN
1870 /* If we promoted this return value, make the proper SUBREG. TARGET
1871 might be const0_rtx here, so be careful. */
1872 if (GET_CODE (target) == REG
1873 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
1874 {
1875 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
1876 int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
1877
1878 if (TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE
1879 || TREE_CODE (TREE_TYPE (exp)) == ENUMERAL_TYPE
1880 || TREE_CODE (TREE_TYPE (exp)) == BOOLEAN_TYPE
1881 || TREE_CODE (TREE_TYPE (exp)) == CHAR_TYPE
1882 || TREE_CODE (TREE_TYPE (exp)) == REAL_TYPE
1883 || TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE
1884 || TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE)
1885 {
1886 PROMOTE_MODE (mode, unsignedp, TREE_TYPE (exp));
1887 }
1888
1889 /* If we didn't promote as expected, something is wrong. */
1890 if (mode != GET_MODE (target))
1891 abort ();
1892
1893 target = gen_rtx (SUBREG, TYPE_MODE (TREE_TYPE (exp)), target, 0);
1894 SUBREG_PROMOTED_VAR_P (target) = 1;
1895 SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp;
1896 }
1897 #endif
1898
1899 /* Perform all cleanups needed for the arguments of this call
1900 (i.e. destructors in C++). */
1901 expand_cleanups_to (old_cleanups);
1902
1903 /* If size of args is variable or this was a constructor call for a stack
1904 argument, restore saved stack-pointer value. */
1905
1906 if (old_stack_level)
1907 {
1908 emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX);
1909 pending_stack_adjust = old_pending_adj;
1910 #ifdef ACCUMULATE_OUTGOING_ARGS
1911 stack_arg_under_construction = old_stack_arg_under_construction;
1912 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
1913 stack_usage_map = initial_stack_usage_map;
1914 #endif
1915 }
1916 #ifdef ACCUMULATE_OUTGOING_ARGS
1917 else
1918 {
1919 #ifdef REG_PARM_STACK_SPACE
1920 if (save_area)
1921 {
1922 enum machine_mode save_mode = GET_MODE (save_area);
1923 rtx stack_area
1924 = gen_rtx (MEM, save_mode,
1925 memory_address (save_mode,
1926 #ifdef ARGS_GROW_DOWNWARD
1927 plus_constant (argblock, - high_to_save)
1928 #else
1929 plus_constant (argblock, low_to_save)
1930 #endif
1931 ));
1932
1933 if (save_mode != BLKmode)
1934 emit_move_insn (stack_area, save_area);
1935 else
1936 emit_block_move (stack_area, validize_mem (save_area),
1937 GEN_INT (high_to_save - low_to_save + 1),
1938 PARM_BOUNDARY / BITS_PER_UNIT);
1939 }
1940 #endif
1941
1942 /* If we saved any argument areas, restore them. */
1943 for (i = 0; i < num_actuals; i++)
1944 if (args[i].save_area)
1945 {
1946 enum machine_mode save_mode = GET_MODE (args[i].save_area);
1947 rtx stack_area
1948 = gen_rtx (MEM, save_mode,
1949 memory_address (save_mode,
1950 XEXP (args[i].stack_slot, 0)));
1951
1952 if (save_mode != BLKmode)
1953 emit_move_insn (stack_area, args[i].save_area);
1954 else
1955 emit_block_move (stack_area, validize_mem (args[i].save_area),
1956 GEN_INT (args[i].size.constant),
1957 PARM_BOUNDARY / BITS_PER_UNIT);
1958 }
1959
1960 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
1961 stack_usage_map = initial_stack_usage_map;
1962 }
1963 #endif
1964
1965 /* If this was alloca, record the new stack level for nonlocal gotos.
1966 Check for the handler slots since we might not have a save area
1967 for non-local gotos. */
1968
1969 if (may_be_alloca && nonlocal_goto_handler_slot != 0)
1970 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX);
1971
1972 pop_temp_slots ();
1973
1974 return target;
1975 }
1976 \f
1977 /* Output a library call to function FUN (a SYMBOL_REF rtx)
1978 (emitting the queue unless NO_QUEUE is nonzero),
1979 for a value of mode OUTMODE,
1980 with NARGS different arguments, passed as alternating rtx values
1981 and machine_modes to convert them to.
1982 The rtx values should have been passed through protect_from_queue already.
1983
1984 NO_QUEUE will be true if and only if the library call is a `const' call
1985 which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent
1986 to the variable is_const in expand_call.
1987
1988 NO_QUEUE must be true for const calls, because if it isn't, then
1989 any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes,
1990 and will be lost if the libcall sequence is optimized away.
1991
1992 NO_QUEUE must be false for non-const calls, because if it isn't, the
1993 call insn will have its CONST_CALL_P bit set, and it will be incorrectly
1994 optimized. For instance, the instruction scheduler may incorrectly
1995 move memory references across the non-const call. */
1996
1997 void
1998 emit_library_call (va_alist)
1999 va_dcl
2000 {
2001 va_list p;
2002 /* Total size in bytes of all the stack-parms scanned so far. */
2003 struct args_size args_size;
2004 /* Size of arguments before any adjustments (such as rounding). */
2005 struct args_size original_args_size;
2006 register int argnum;
2007 enum machine_mode outmode;
2008 int nargs;
2009 rtx fun;
2010 rtx orgfun;
2011 int inc;
2012 int count;
2013 rtx argblock = 0;
2014 CUMULATIVE_ARGS args_so_far;
2015 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2016 struct args_size offset; struct args_size size; };
2017 struct arg *argvec;
2018 int old_inhibit_defer_pop = inhibit_defer_pop;
2019 int no_queue = 0;
2020 rtx use_insns;
2021 /* library calls are never indirect calls. */
2022 int current_call_is_indirect = 0;
2023
2024 va_start (p);
2025 orgfun = fun = va_arg (p, rtx);
2026 no_queue = va_arg (p, int);
2027 outmode = va_arg (p, enum machine_mode);
2028 nargs = va_arg (p, int);
2029
2030 /* Copy all the libcall-arguments out of the varargs data
2031 and into a vector ARGVEC.
2032
2033 Compute how to pass each argument. We only support a very small subset
2034 of the full argument passing conventions to limit complexity here since
2035 library functions shouldn't have many args. */
2036
2037 argvec = (struct arg *) alloca (nargs * sizeof (struct arg));
2038
2039 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun);
2040
2041 args_size.constant = 0;
2042 args_size.var = 0;
2043
2044 for (count = 0; count < nargs; count++)
2045 {
2046 rtx val = va_arg (p, rtx);
2047 enum machine_mode mode = va_arg (p, enum machine_mode);
2048
2049 /* We cannot convert the arg value to the mode the library wants here;
2050 must do it earlier where we know the signedness of the arg. */
2051 if (mode == BLKmode
2052 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2053 abort ();
2054
2055 /* On some machines, there's no way to pass a float to a library fcn.
2056 Pass it as a double instead. */
2057 #ifdef LIBGCC_NEEDS_DOUBLE
2058 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2059 val = convert_to_mode (DFmode, val, 0), mode = DFmode;
2060 #endif
2061
2062 /* There's no need to call protect_from_queue, because
2063 either emit_move_insn or emit_push_insn will do that. */
2064
2065 /* Make sure it is a reasonable operand for a move or push insn. */
2066 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2067 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2068 val = force_operand (val, NULL_RTX);
2069
2070 argvec[count].value = val;
2071 argvec[count].mode = mode;
2072
2073 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2074 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2075 abort ();
2076 #endif
2077
2078 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2079 if (argvec[count].reg && GET_CODE (argvec[count].reg) == EXPR_LIST)
2080 abort ();
2081 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2082 argvec[count].partial
2083 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2084 #else
2085 argvec[count].partial = 0;
2086 #endif
2087
2088 locate_and_pad_parm (mode, NULL_TREE,
2089 argvec[count].reg && argvec[count].partial == 0,
2090 NULL_TREE, &args_size, &argvec[count].offset,
2091 &argvec[count].size);
2092
2093 if (argvec[count].size.var)
2094 abort ();
2095
2096 #ifndef REG_PARM_STACK_SPACE
2097 if (argvec[count].partial)
2098 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2099 #endif
2100
2101 if (argvec[count].reg == 0 || argvec[count].partial != 0
2102 #ifdef REG_PARM_STACK_SPACE
2103 || 1
2104 #endif
2105 )
2106 args_size.constant += argvec[count].size.constant;
2107
2108 #ifdef ACCUMULATE_OUTGOING_ARGS
2109 /* If this arg is actually passed on the stack, it might be
2110 clobbering something we already put there (this library call might
2111 be inside the evaluation of an argument to a function whose call
2112 requires the stack). This will only occur when the library call
2113 has sufficient args to run out of argument registers. Abort in
2114 this case; if this ever occurs, code must be added to save and
2115 restore the arg slot. */
2116
2117 if (argvec[count].reg == 0 || argvec[count].partial != 0)
2118 abort ();
2119 #endif
2120
2121 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree)0, 1);
2122 }
2123 va_end (p);
2124
2125 /* If this machine requires an external definition for library
2126 functions, write one out. */
2127 assemble_external_libcall (fun);
2128
2129 original_args_size = args_size;
2130 #ifdef STACK_BOUNDARY
2131 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2132 / STACK_BYTES) * STACK_BYTES);
2133 #endif
2134
2135 #ifdef REG_PARM_STACK_SPACE
2136 args_size.constant = MAX (args_size.constant,
2137 REG_PARM_STACK_SPACE (NULL_TREE));
2138 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2139 args_size.constant -= REG_PARM_STACK_SPACE (NULL_TREE);
2140 #endif
2141 #endif
2142
2143 #ifdef ACCUMULATE_OUTGOING_ARGS
2144 if (args_size.constant > current_function_outgoing_args_size)
2145 current_function_outgoing_args_size = args_size.constant;
2146 args_size.constant = 0;
2147 #endif
2148
2149 #ifndef PUSH_ROUNDING
2150 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2151 #endif
2152
2153 #ifdef PUSH_ARGS_REVERSED
2154 #ifdef STACK_BOUNDARY
2155 /* If we push args individually in reverse order, perform stack alignment
2156 before the first push (the last arg). */
2157 if (argblock == 0)
2158 anti_adjust_stack (GEN_INT (args_size.constant
2159 - original_args_size.constant));
2160 #endif
2161 #endif
2162
2163 #ifdef PUSH_ARGS_REVERSED
2164 inc = -1;
2165 argnum = nargs - 1;
2166 #else
2167 inc = 1;
2168 argnum = 0;
2169 #endif
2170
2171 /* Push the args that need to be pushed. */
2172
2173 for (count = 0; count < nargs; count++, argnum += inc)
2174 {
2175 register enum machine_mode mode = argvec[argnum].mode;
2176 register rtx val = argvec[argnum].value;
2177 rtx reg = argvec[argnum].reg;
2178 int partial = argvec[argnum].partial;
2179
2180 if (! (reg != 0 && partial == 0))
2181 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
2182 argblock, GEN_INT (argvec[count].offset.constant));
2183 NO_DEFER_POP;
2184 }
2185
2186 #ifndef PUSH_ARGS_REVERSED
2187 #ifdef STACK_BOUNDARY
2188 /* If we pushed args in forward order, perform stack alignment
2189 after pushing the last arg. */
2190 if (argblock == 0)
2191 anti_adjust_stack (GEN_INT (args_size.constant
2192 - original_args_size.constant));
2193 #endif
2194 #endif
2195
2196 #ifdef PUSH_ARGS_REVERSED
2197 argnum = nargs - 1;
2198 #else
2199 argnum = 0;
2200 #endif
2201
2202 /* Now load any reg parms into their regs. */
2203
2204 for (count = 0; count < nargs; count++, argnum += inc)
2205 {
2206 register enum machine_mode mode = argvec[argnum].mode;
2207 register rtx val = argvec[argnum].value;
2208 rtx reg = argvec[argnum].reg;
2209 int partial = argvec[argnum].partial;
2210
2211 if (reg != 0 && partial == 0)
2212 emit_move_insn (reg, val);
2213 NO_DEFER_POP;
2214 }
2215
2216 /* For version 1.37, try deleting this entirely. */
2217 if (! no_queue)
2218 emit_queue ();
2219
2220 /* Any regs containing parms remain in use through the call. */
2221 start_sequence ();
2222 for (count = 0; count < nargs; count++)
2223 if (argvec[count].reg != 0)
2224 emit_insn (gen_rtx (USE, VOIDmode, argvec[count].reg));
2225
2226 use_insns = get_insns ();
2227 end_sequence ();
2228
2229 fun = prepare_call_address (fun, NULL_TREE, &use_insns);
2230
2231 /* Don't allow popping to be deferred, since then
2232 cse'ing of library calls could delete a call and leave the pop. */
2233 NO_DEFER_POP;
2234
2235 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
2236 will set inhibit_defer_pop to that value. */
2237
2238 emit_call_1 (fun, get_identifier (XSTR (orgfun, 0)), args_size.constant, 0,
2239 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2240 outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
2241 old_inhibit_defer_pop + 1, use_insns, no_queue);
2242
2243 /* Now restore inhibit_defer_pop to its actual original value. */
2244 OK_DEFER_POP;
2245 }
2246 \f
2247 /* Like emit_library_call except that an extra argument, VALUE,
2248 comes second and says where to store the result.
2249 (If VALUE is zero, the result comes in the function value register.) */
2250
2251 void
2252 emit_library_call_value (va_alist)
2253 va_dcl
2254 {
2255 va_list p;
2256 /* Total size in bytes of all the stack-parms scanned so far. */
2257 struct args_size args_size;
2258 /* Size of arguments before any adjustments (such as rounding). */
2259 struct args_size original_args_size;
2260 register int argnum;
2261 enum machine_mode outmode;
2262 int nargs;
2263 rtx fun;
2264 rtx orgfun;
2265 int inc;
2266 int count;
2267 rtx argblock = 0;
2268 CUMULATIVE_ARGS args_so_far;
2269 struct arg { rtx value; enum machine_mode mode; rtx reg; int partial;
2270 struct args_size offset; struct args_size size; };
2271 struct arg *argvec;
2272 int old_inhibit_defer_pop = inhibit_defer_pop;
2273 int no_queue = 0;
2274 rtx use_insns;
2275 rtx value;
2276 rtx mem_value = 0;
2277 /* library calls are never indirect calls. */
2278 int current_call_is_indirect = 0;
2279
2280 va_start (p);
2281 orgfun = fun = va_arg (p, rtx);
2282 value = va_arg (p, rtx);
2283 no_queue = va_arg (p, int);
2284 outmode = va_arg (p, enum machine_mode);
2285 nargs = va_arg (p, int);
2286
2287 /* If this kind of value comes back in memory,
2288 decide where in memory it should come back. */
2289 if (RETURN_IN_MEMORY (type_for_mode (outmode, 0)))
2290 {
2291 if (GET_CODE (value) == MEM)
2292 mem_value = value;
2293 else
2294 mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0);
2295 }
2296
2297 /* ??? Unfinished: must pass the memory address as an argument. */
2298
2299 /* Copy all the libcall-arguments out of the varargs data
2300 and into a vector ARGVEC.
2301
2302 Compute how to pass each argument. We only support a very small subset
2303 of the full argument passing conventions to limit complexity here since
2304 library functions shouldn't have many args. */
2305
2306 argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg));
2307
2308 INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun);
2309
2310 args_size.constant = 0;
2311 args_size.var = 0;
2312
2313 count = 0;
2314
2315 /* If there's a structure value address to be passed,
2316 either pass it in the special place, or pass it as an extra argument. */
2317 if (mem_value)
2318 {
2319 rtx addr = XEXP (mem_value, 0);
2320
2321 if (! struct_value_rtx)
2322 {
2323 nargs++;
2324
2325 /* Make sure it is a reasonable operand for a move or push insn. */
2326 if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM
2327 && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr)))
2328 addr = force_operand (addr, NULL_RTX);
2329
2330 argvec[count].value = addr;
2331 argvec[count].mode = outmode;
2332 argvec[count].partial = 0;
2333
2334 argvec[count].reg = FUNCTION_ARG (args_so_far, outmode, NULL_TREE, 1);
2335 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2336 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, outmode, NULL_TREE, 1))
2337 abort ();
2338 #endif
2339
2340 locate_and_pad_parm (outmode, NULL_TREE,
2341 argvec[count].reg && argvec[count].partial == 0,
2342 NULL_TREE, &args_size, &argvec[count].offset,
2343 &argvec[count].size);
2344
2345
2346 if (argvec[count].reg == 0 || argvec[count].partial != 0
2347 #ifdef REG_PARM_STACK_SPACE
2348 || 1
2349 #endif
2350 )
2351 args_size.constant += argvec[count].size.constant;
2352
2353 FUNCTION_ARG_ADVANCE (args_so_far, outmode, (tree)0, 1);
2354 }
2355 }
2356
2357 for (; count < nargs; count++)
2358 {
2359 rtx val = va_arg (p, rtx);
2360 enum machine_mode mode = va_arg (p, enum machine_mode);
2361
2362 /* We cannot convert the arg value to the mode the library wants here;
2363 must do it earlier where we know the signedness of the arg. */
2364 if (mode == BLKmode
2365 || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode))
2366 abort ();
2367
2368 /* On some machines, there's no way to pass a float to a library fcn.
2369 Pass it as a double instead. */
2370 #ifdef LIBGCC_NEEDS_DOUBLE
2371 if (LIBGCC_NEEDS_DOUBLE && mode == SFmode)
2372 val = convert_to_mode (DFmode, val, 0), mode = DFmode;
2373 #endif
2374
2375 /* There's no need to call protect_from_queue, because
2376 either emit_move_insn or emit_push_insn will do that. */
2377
2378 /* Make sure it is a reasonable operand for a move or push insn. */
2379 if (GET_CODE (val) != REG && GET_CODE (val) != MEM
2380 && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val)))
2381 val = force_operand (val, NULL_RTX);
2382
2383 argvec[count].value = val;
2384 argvec[count].mode = mode;
2385
2386 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
2387 if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1))
2388 abort ();
2389 #endif
2390
2391 argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
2392 if (argvec[count].reg && GET_CODE (argvec[count].reg) == EXPR_LIST)
2393 abort ();
2394 #ifdef FUNCTION_ARG_PARTIAL_NREGS
2395 argvec[count].partial
2396 = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1);
2397 #else
2398 argvec[count].partial = 0;
2399 #endif
2400
2401 locate_and_pad_parm (mode, NULL_TREE,
2402 argvec[count].reg && argvec[count].partial == 0,
2403 NULL_TREE, &args_size, &argvec[count].offset,
2404 &argvec[count].size);
2405
2406 if (argvec[count].size.var)
2407 abort ();
2408
2409 #ifndef REG_PARM_STACK_SPACE
2410 if (argvec[count].partial)
2411 argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD;
2412 #endif
2413
2414 if (argvec[count].reg == 0 || argvec[count].partial != 0
2415 #ifdef REG_PARM_STACK_SPACE
2416 || 1
2417 #endif
2418 )
2419 args_size.constant += argvec[count].size.constant;
2420
2421 #ifdef ACCUMULATE_OUTGOING_ARGS
2422 /* If this arg is actually passed on the stack, it might be
2423 clobbering something we already put there (this library call might
2424 be inside the evaluation of an argument to a function whose call
2425 requires the stack). This will only occur when the library call
2426 has sufficient args to run out of argument registers. Abort in
2427 this case; if this ever occurs, code must be added to save and
2428 restore the arg slot. */
2429
2430 if (argvec[count].reg == 0 || argvec[count].partial != 0)
2431 abort ();
2432 #endif
2433
2434 FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree)0, 1);
2435 }
2436 va_end (p);
2437
2438 /* If this machine requires an external definition for library
2439 functions, write one out. */
2440 assemble_external_libcall (fun);
2441
2442 original_args_size = args_size;
2443 #ifdef STACK_BOUNDARY
2444 args_size.constant = (((args_size.constant + (STACK_BYTES - 1))
2445 / STACK_BYTES) * STACK_BYTES);
2446 #endif
2447
2448 #ifdef REG_PARM_STACK_SPACE
2449 args_size.constant = MAX (args_size.constant,
2450 REG_PARM_STACK_SPACE (NULL_TREE));
2451 #ifndef OUTGOING_REG_PARM_STACK_SPACE
2452 args_size.constant -= REG_PARM_STACK_SPACE (NULL_TREE);
2453 #endif
2454 #endif
2455
2456 #ifdef ACCUMULATE_OUTGOING_ARGS
2457 if (args_size.constant > current_function_outgoing_args_size)
2458 current_function_outgoing_args_size = args_size.constant;
2459 args_size.constant = 0;
2460 #endif
2461
2462 #ifndef PUSH_ROUNDING
2463 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
2464 #endif
2465
2466 #ifdef PUSH_ARGS_REVERSED
2467 #ifdef STACK_BOUNDARY
2468 /* If we push args individually in reverse order, perform stack alignment
2469 before the first push (the last arg). */
2470 if (argblock == 0)
2471 anti_adjust_stack (GEN_INT (args_size.constant
2472 - original_args_size.constant));
2473 #endif
2474 #endif
2475
2476 #ifdef PUSH_ARGS_REVERSED
2477 inc = -1;
2478 argnum = nargs - 1;
2479 #else
2480 inc = 1;
2481 argnum = 0;
2482 #endif
2483
2484 /* Push the args that need to be pushed. */
2485
2486 for (count = 0; count < nargs; count++, argnum += inc)
2487 {
2488 register enum machine_mode mode = argvec[argnum].mode;
2489 register rtx val = argvec[argnum].value;
2490 rtx reg = argvec[argnum].reg;
2491 int partial = argvec[argnum].partial;
2492
2493 if (! (reg != 0 && partial == 0))
2494 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0,
2495 argblock, GEN_INT (argvec[count].offset.constant));
2496 NO_DEFER_POP;
2497 }
2498
2499 #ifndef PUSH_ARGS_REVERSED
2500 #ifdef STACK_BOUNDARY
2501 /* If we pushed args in forward order, perform stack alignment
2502 after pushing the last arg. */
2503 if (argblock == 0)
2504 anti_adjust_stack (GEN_INT (args_size.constant
2505 - original_args_size.constant));
2506 #endif
2507 #endif
2508
2509 #ifdef PUSH_ARGS_REVERSED
2510 argnum = nargs - 1;
2511 #else
2512 argnum = 0;
2513 #endif
2514
2515 /* Now load any reg parms into their regs. */
2516
2517 if (mem_value != 0 && struct_value_rtx != 0)
2518 emit_move_insn (struct_value_rtx, XEXP (mem_value, 0));
2519
2520 for (count = 0; count < nargs; count++, argnum += inc)
2521 {
2522 register enum machine_mode mode = argvec[argnum].mode;
2523 register rtx val = argvec[argnum].value;
2524 rtx reg = argvec[argnum].reg;
2525 int partial = argvec[argnum].partial;
2526
2527 if (reg != 0 && partial == 0)
2528 emit_move_insn (reg, val);
2529 NO_DEFER_POP;
2530 }
2531
2532 #if 0
2533 /* For version 1.37, try deleting this entirely. */
2534 if (! no_queue)
2535 emit_queue ();
2536 #endif
2537
2538 /* Any regs containing parms remain in use through the call. */
2539 start_sequence ();
2540 for (count = 0; count < nargs; count++)
2541 if (argvec[count].reg != 0)
2542 emit_insn (gen_rtx (USE, VOIDmode, argvec[count].reg));
2543
2544 use_insns = get_insns ();
2545 end_sequence ();
2546
2547 fun = prepare_call_address (fun, NULL_TREE, &use_insns);
2548
2549 /* Don't allow popping to be deferred, since then
2550 cse'ing of library calls could delete a call and leave the pop. */
2551 NO_DEFER_POP;
2552
2553 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
2554 will set inhibit_defer_pop to that value. */
2555
2556 emit_call_1 (fun, get_identifier (XSTR (orgfun, 0)), args_size.constant, 0,
2557 FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1),
2558 outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX,
2559 old_inhibit_defer_pop + 1, use_insns, no_queue);
2560
2561 /* Now restore inhibit_defer_pop to its actual original value. */
2562 OK_DEFER_POP;
2563
2564 /* Copy the value to the right place. */
2565 if (outmode != VOIDmode)
2566 {
2567 if (mem_value)
2568 {
2569 if (value == 0)
2570 value = hard_libcall_value (outmode);
2571 if (value != mem_value)
2572 emit_move_insn (value, mem_value);
2573 }
2574 else if (value != 0)
2575 emit_move_insn (value, hard_libcall_value (outmode));
2576 }
2577 }
2578 \f
2579 #if 0
2580 /* Return an rtx which represents a suitable home on the stack
2581 given TYPE, the type of the argument looking for a home.
2582 This is called only for BLKmode arguments.
2583
2584 SIZE is the size needed for this target.
2585 ARGS_ADDR is the address of the bottom of the argument block for this call.
2586 OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless
2587 if this machine uses push insns. */
2588
2589 static rtx
2590 target_for_arg (type, size, args_addr, offset)
2591 tree type;
2592 rtx size;
2593 rtx args_addr;
2594 struct args_size offset;
2595 {
2596 rtx target;
2597 rtx offset_rtx = ARGS_SIZE_RTX (offset);
2598
2599 /* We do not call memory_address if possible,
2600 because we want to address as close to the stack
2601 as possible. For non-variable sized arguments,
2602 this will be stack-pointer relative addressing. */
2603 if (GET_CODE (offset_rtx) == CONST_INT)
2604 target = plus_constant (args_addr, INTVAL (offset_rtx));
2605 else
2606 {
2607 /* I have no idea how to guarantee that this
2608 will work in the presence of register parameters. */
2609 target = gen_rtx (PLUS, Pmode, args_addr, offset_rtx);
2610 target = memory_address (QImode, target);
2611 }
2612
2613 return gen_rtx (MEM, BLKmode, target);
2614 }
2615 #endif
2616 \f
2617 /* Store a single argument for a function call
2618 into the register or memory area where it must be passed.
2619 *ARG describes the argument value and where to pass it.
2620
2621 ARGBLOCK is the address of the stack-block for all the arguments,
2622 or 0 on a machine where arguments are pushed individually.
2623
2624 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
2625 so must be careful about how the stack is used.
2626
2627 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
2628 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
2629 that we need not worry about saving and restoring the stack.
2630
2631 FNDECL is the declaration of the function we are calling. */
2632
2633 static void
2634 store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl,
2635 reg_parm_stack_space)
2636 struct arg_data *arg;
2637 rtx argblock;
2638 int may_be_alloca;
2639 int variable_size;
2640 tree fndecl;
2641 int reg_parm_stack_space;
2642 {
2643 register tree pval = arg->tree_value;
2644 rtx reg = 0;
2645 int partial = 0;
2646 int used = 0;
2647 int i, lower_bound, upper_bound;
2648
2649 if (TREE_CODE (pval) == ERROR_MARK)
2650 return;
2651
2652 #ifdef ACCUMULATE_OUTGOING_ARGS
2653 /* If this is being stored into a pre-allocated, fixed-size, stack area,
2654 save any previous data at that location. */
2655 if (argblock && ! variable_size && arg->stack)
2656 {
2657 #ifdef ARGS_GROW_DOWNWARD
2658 /* stack_slot is negative, but we want to index stack_usage_map */
2659 /* with positive values. */
2660 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
2661 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
2662 else
2663 abort ();
2664
2665 lower_bound = upper_bound - arg->size.constant;
2666 #else
2667 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
2668 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
2669 else
2670 lower_bound = 0;
2671
2672 upper_bound = lower_bound + arg->size.constant;
2673 #endif
2674
2675 for (i = lower_bound; i < upper_bound; i++)
2676 if (stack_usage_map[i]
2677 #ifdef REG_PARM_STACK_SPACE
2678 /* Don't store things in the fixed argument area at this point;
2679 it has already been saved. */
2680 && i > reg_parm_stack_space
2681 #endif
2682 )
2683 break;
2684
2685 if (i != upper_bound)
2686 {
2687 /* We need to make a save area. See what mode we can make it. */
2688 enum machine_mode save_mode
2689 = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1);
2690 rtx stack_area
2691 = gen_rtx (MEM, save_mode,
2692 memory_address (save_mode, XEXP (arg->stack_slot, 0)));
2693
2694 if (save_mode == BLKmode)
2695 {
2696 arg->save_area = assign_stack_temp (BLKmode,
2697 arg->size.constant, 1);
2698 emit_block_move (validize_mem (arg->save_area), stack_area,
2699 GEN_INT (arg->size.constant),
2700 PARM_BOUNDARY / BITS_PER_UNIT);
2701 }
2702 else
2703 {
2704 arg->save_area = gen_reg_rtx (save_mode);
2705 emit_move_insn (arg->save_area, stack_area);
2706 }
2707 }
2708 }
2709 #endif
2710
2711 /* If this isn't going to be placed on both the stack and in registers,
2712 set up the register and number of words. */
2713 if (! arg->pass_on_stack)
2714 reg = arg->reg, partial = arg->partial;
2715
2716 if (reg != 0 && partial == 0)
2717 /* Being passed entirely in a register. We shouldn't be called in
2718 this case. */
2719 abort ();
2720
2721 #ifdef STRICT_ALIGNMENT
2722 /* If this arg needs special alignment, don't load the registers
2723 here. */
2724 if (arg->n_aligned_regs != 0)
2725 reg = 0;
2726 #endif
2727
2728 /* If this is being partially passed in a register, but multiple locations
2729 are specified, we assume that the one partially used is the one that is
2730 listed first. */
2731 if (reg && GET_CODE (reg) == EXPR_LIST)
2732 reg = XEXP (reg, 0);
2733
2734 /* If this is being passed partially in a register, we can't evaluate
2735 it directly into its stack slot. Otherwise, we can. */
2736 if (arg->value == 0)
2737 {
2738 #ifdef ACCUMULATE_OUTGOING_ARGS
2739 /* stack_arg_under_construction is nonzero if a function argument is
2740 being evaluated directly into the outgoing argument list and
2741 expand_call must take special action to preserve the argument list
2742 if it is called recursively.
2743
2744 For scalar function arguments stack_usage_map is sufficient to
2745 determine which stack slots must be saved and restored. Scalar
2746 arguments in general have pass_on_stack == 0.
2747
2748 If this argument is initialized by a function which takes the
2749 address of the argument (a C++ constructor or a C function
2750 returning a BLKmode structure), then stack_usage_map is
2751 insufficient and expand_call must push the stack around the
2752 function call. Such arguments have pass_on_stack == 1.
2753
2754 Note that it is always safe to set stack_arg_under_construction,
2755 but this generates suboptimal code if set when not needed. */
2756
2757 if (arg->pass_on_stack)
2758 stack_arg_under_construction++;
2759 #endif
2760 arg->value = expand_expr (pval, partial ? NULL_RTX : arg->stack,
2761 VOIDmode, 0);
2762
2763 /* If we are promoting object (or for any other reason) the mode
2764 doesn't agree, convert the mode. */
2765
2766 if (GET_MODE (arg->value) != VOIDmode
2767 && GET_MODE (arg->value) != arg->mode)
2768 arg->value = convert_to_mode (arg->mode, arg->value, arg->unsignedp);
2769
2770 #ifdef ACCUMULATE_OUTGOING_ARGS
2771 if (arg->pass_on_stack)
2772 stack_arg_under_construction--;
2773 #endif
2774 }
2775
2776 /* Don't allow anything left on stack from computation
2777 of argument to alloca. */
2778 if (may_be_alloca)
2779 do_pending_stack_adjust ();
2780
2781 if (arg->value == arg->stack)
2782 /* If the value is already in the stack slot, we are done. */
2783 ;
2784 else if (arg->mode != BLKmode)
2785 {
2786 register int size;
2787
2788 /* Argument is a scalar, not entirely passed in registers.
2789 (If part is passed in registers, arg->partial says how much
2790 and emit_push_insn will take care of putting it there.)
2791
2792 Push it, and if its size is less than the
2793 amount of space allocated to it,
2794 also bump stack pointer by the additional space.
2795 Note that in C the default argument promotions
2796 will prevent such mismatches. */
2797
2798 size = GET_MODE_SIZE (arg->mode);
2799 /* Compute how much space the push instruction will push.
2800 On many machines, pushing a byte will advance the stack
2801 pointer by a halfword. */
2802 #ifdef PUSH_ROUNDING
2803 size = PUSH_ROUNDING (size);
2804 #endif
2805 used = size;
2806
2807 /* Compute how much space the argument should get:
2808 round up to a multiple of the alignment for arguments. */
2809 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
2810 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
2811 / (PARM_BOUNDARY / BITS_PER_UNIT))
2812 * (PARM_BOUNDARY / BITS_PER_UNIT));
2813
2814 /* This isn't already where we want it on the stack, so put it there.
2815 This can either be done with push or copy insns. */
2816 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
2817 0, partial, reg, used - size,
2818 argblock, ARGS_SIZE_RTX (arg->offset));
2819 }
2820 else
2821 {
2822 /* BLKmode, at least partly to be pushed. */
2823
2824 register int excess;
2825 rtx size_rtx;
2826
2827 /* Pushing a nonscalar.
2828 If part is passed in registers, PARTIAL says how much
2829 and emit_push_insn will take care of putting it there. */
2830
2831 /* Round its size up to a multiple
2832 of the allocation unit for arguments. */
2833
2834 if (arg->size.var != 0)
2835 {
2836 excess = 0;
2837 size_rtx = ARGS_SIZE_RTX (arg->size);
2838 }
2839 else
2840 {
2841 /* PUSH_ROUNDING has no effect on us, because
2842 emit_push_insn for BLKmode is careful to avoid it. */
2843 excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval))
2844 + partial * UNITS_PER_WORD);
2845 size_rtx = expr_size (pval);
2846 }
2847
2848 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
2849 TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial,
2850 reg, excess, argblock, ARGS_SIZE_RTX (arg->offset));
2851 }
2852
2853
2854 /* Unless this is a partially-in-register argument, the argument is now
2855 in the stack.
2856
2857 ??? Note that this can change arg->value from arg->stack to
2858 arg->stack_slot and it matters when they are not the same.
2859 It isn't totally clear that this is correct in all cases. */
2860 if (partial == 0)
2861 arg->value = arg->stack_slot;
2862
2863 /* Once we have pushed something, pops can't safely
2864 be deferred during the rest of the arguments. */
2865 NO_DEFER_POP;
2866
2867 /* ANSI doesn't require a sequence point here,
2868 but PCC has one, so this will avoid some problems. */
2869 emit_queue ();
2870
2871 /* Free any temporary slots made in processing this argument. */
2872 free_temp_slots ();
2873
2874 #ifdef ACCUMULATE_OUTGOING_ARGS
2875 /* Now mark the segment we just used. */
2876 if (argblock && ! variable_size && arg->stack)
2877 for (i = lower_bound; i < upper_bound; i++)
2878 stack_usage_map[i] = 1;
2879 #endif
2880 }
This page took 0.149154 seconds and 5 git commands to generate.