[calls.c] Remove #ifdef checks on STACK_GROWS_DOWNWARD
[gcc.git] / gcc / calls.c
1 /* Convert function calls to rtl insns, for GNU C compiler.
2 Copyright (C) 1989-2015 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "rtl.h"
25 #include "hash-set.h"
26 #include "machmode.h"
27 #include "vec.h"
28 #include "double-int.h"
29 #include "input.h"
30 #include "alias.h"
31 #include "symtab.h"
32 #include "wide-int.h"
33 #include "inchash.h"
34 #include "tree.h"
35 #include "fold-const.h"
36 #include "stor-layout.h"
37 #include "varasm.h"
38 #include "stringpool.h"
39 #include "attribs.h"
40 #include "predict.h"
41 #include "hashtab.h"
42 #include "hard-reg-set.h"
43 #include "function.h"
44 #include "basic-block.h"
45 #include "tree-ssa-alias.h"
46 #include "internal-fn.h"
47 #include "gimple-expr.h"
48 #include "is-a.h"
49 #include "gimple.h"
50 #include "flags.h"
51 #include "statistics.h"
52 #include "real.h"
53 #include "fixed-value.h"
54 #include "insn-config.h"
55 #include "expmed.h"
56 #include "dojump.h"
57 #include "explow.h"
58 #include "calls.h"
59 #include "emit-rtl.h"
60 #include "stmt.h"
61 #include "expr.h"
62 #include "insn-codes.h"
63 #include "optabs.h"
64 #include "libfuncs.h"
65 #include "regs.h"
66 #include "diagnostic-core.h"
67 #include "output.h"
68 #include "tm_p.h"
69 #include "timevar.h"
70 #include "sbitmap.h"
71 #include "bitmap.h"
72 #include "langhooks.h"
73 #include "target.h"
74 #include "hash-map.h"
75 #include "plugin-api.h"
76 #include "ipa-ref.h"
77 #include "cgraph.h"
78 #include "except.h"
79 #include "dbgcnt.h"
80 #include "rtl-iter.h"
81 #include "tree-chkp.h"
82 #include "rtl-chkp.h"
83
84
85 /* Redefine STACK_GROWS_DOWNWARD in terms of 0 or 1. */
86 #ifdef STACK_GROWS_DOWNWARD
87 # undef STACK_GROWS_DOWNWARD
88 # define STACK_GROWS_DOWNWARD 1
89 #else
90 # define STACK_GROWS_DOWNWARD 0
91 #endif
92
93 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */
94 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
95
96 /* Data structure and subroutines used within expand_call. */
97
98 struct arg_data
99 {
100 /* Tree node for this argument. */
101 tree tree_value;
102 /* Mode for value; TYPE_MODE unless promoted. */
103 machine_mode mode;
104 /* Current RTL value for argument, or 0 if it isn't precomputed. */
105 rtx value;
106 /* Initially-compute RTL value for argument; only for const functions. */
107 rtx initial_value;
108 /* Register to pass this argument in, 0 if passed on stack, or an
109 PARALLEL if the arg is to be copied into multiple non-contiguous
110 registers. */
111 rtx reg;
112 /* Register to pass this argument in when generating tail call sequence.
113 This is not the same register as for normal calls on machines with
114 register windows. */
115 rtx tail_call_reg;
116 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
117 form for emit_group_move. */
118 rtx parallel_value;
119 /* If value is passed in neither reg nor stack, this field holds a number
120 of a special slot to be used. */
121 rtx special_slot;
122 /* For pointer bounds hold an index of parm bounds are bound to. -1 if
123 there is no such pointer. */
124 int pointer_arg;
125 /* If pointer_arg refers a structure, then pointer_offset holds an offset
126 of a pointer in this structure. */
127 int pointer_offset;
128 /* If REG was promoted from the actual mode of the argument expression,
129 indicates whether the promotion is sign- or zero-extended. */
130 int unsignedp;
131 /* Number of bytes to put in registers. 0 means put the whole arg
132 in registers. Also 0 if not passed in registers. */
133 int partial;
134 /* Nonzero if argument must be passed on stack.
135 Note that some arguments may be passed on the stack
136 even though pass_on_stack is zero, just because FUNCTION_ARG says so.
137 pass_on_stack identifies arguments that *cannot* go in registers. */
138 int pass_on_stack;
139 /* Some fields packaged up for locate_and_pad_parm. */
140 struct locate_and_pad_arg_data locate;
141 /* Location on the stack at which parameter should be stored. The store
142 has already been done if STACK == VALUE. */
143 rtx stack;
144 /* Location on the stack of the start of this argument slot. This can
145 differ from STACK if this arg pads downward. This location is known
146 to be aligned to TARGET_FUNCTION_ARG_BOUNDARY. */
147 rtx stack_slot;
148 /* Place that this stack area has been saved, if needed. */
149 rtx save_area;
150 /* If an argument's alignment does not permit direct copying into registers,
151 copy in smaller-sized pieces into pseudos. These are stored in a
152 block pointed to by this field. The next field says how many
153 word-sized pseudos we made. */
154 rtx *aligned_regs;
155 int n_aligned_regs;
156 };
157
158 /* A vector of one char per byte of stack space. A byte if nonzero if
159 the corresponding stack location has been used.
160 This vector is used to prevent a function call within an argument from
161 clobbering any stack already set up. */
162 static char *stack_usage_map;
163
164 /* Size of STACK_USAGE_MAP. */
165 static int highest_outgoing_arg_in_use;
166
167 /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding
168 stack location's tail call argument has been already stored into the stack.
169 This bitmap is used to prevent sibling call optimization if function tries
170 to use parent's incoming argument slots when they have been already
171 overwritten with tail call arguments. */
172 static sbitmap stored_args_map;
173
174 /* stack_arg_under_construction is nonzero when an argument may be
175 initialized with a constructor call (including a C function that
176 returns a BLKmode struct) and expand_call must take special action
177 to make sure the object being constructed does not overlap the
178 argument list for the constructor call. */
179 static int stack_arg_under_construction;
180
181 static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT,
182 HOST_WIDE_INT, rtx, rtx, int, rtx, int,
183 cumulative_args_t);
184 static void precompute_register_parameters (int, struct arg_data *, int *);
185 static void store_bounds (struct arg_data *, struct arg_data *);
186 static int store_one_arg (struct arg_data *, rtx, int, int, int);
187 static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
188 static int finalize_must_preallocate (int, int, struct arg_data *,
189 struct args_size *);
190 static void precompute_arguments (int, struct arg_data *);
191 static int compute_argument_block_size (int, struct args_size *, tree, tree, int);
192 static void initialize_argument_information (int, struct arg_data *,
193 struct args_size *, int,
194 tree, tree,
195 tree, tree, cumulative_args_t, int,
196 rtx *, int *, int *, int *,
197 bool *, bool);
198 static void compute_argument_addresses (struct arg_data *, rtx, int);
199 static rtx rtx_for_function_call (tree, tree);
200 static void load_register_parameters (struct arg_data *, int, rtx *, int,
201 int, int *);
202 static rtx emit_library_call_value_1 (int, rtx, rtx, enum libcall_type,
203 machine_mode, int, va_list);
204 static int special_function_p (const_tree, int);
205 static int check_sibcall_argument_overlap_1 (rtx);
206 static int check_sibcall_argument_overlap (rtx_insn *, struct arg_data *, int);
207
208 static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
209 unsigned int);
210 static tree split_complex_types (tree);
211
212 #ifdef REG_PARM_STACK_SPACE
213 static rtx save_fixed_argument_area (int, rtx, int *, int *);
214 static void restore_fixed_argument_area (rtx, rtx, int, int);
215 #endif
216 \f
217 /* Force FUNEXP into a form suitable for the address of a CALL,
218 and return that as an rtx. Also load the static chain register
219 if FNDECL is a nested function.
220
221 CALL_FUSAGE points to a variable holding the prospective
222 CALL_INSN_FUNCTION_USAGE information. */
223
224 rtx
225 prepare_call_address (tree fndecl_or_type, rtx funexp, rtx static_chain_value,
226 rtx *call_fusage, int reg_parm_seen, int sibcallp)
227 {
228 /* Make a valid memory address and copy constants through pseudo-regs,
229 but not for a constant address if -fno-function-cse. */
230 if (GET_CODE (funexp) != SYMBOL_REF)
231 /* If we are using registers for parameters, force the
232 function address into a register now. */
233 funexp = ((reg_parm_seen
234 && targetm.small_register_classes_for_mode_p (FUNCTION_MODE))
235 ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
236 : memory_address (FUNCTION_MODE, funexp));
237 else if (flag_pic && !flag_plt && fndecl_or_type
238 && TREE_CODE (fndecl_or_type) == FUNCTION_DECL
239 && !targetm.binds_local_p (fndecl_or_type))
240 {
241 funexp = force_reg (Pmode, funexp);
242 }
243 else if (! sibcallp)
244 {
245 if (!NO_FUNCTION_CSE && optimize && ! flag_no_function_cse)
246 funexp = force_reg (Pmode, funexp);
247 }
248
249 if (static_chain_value != 0
250 && (TREE_CODE (fndecl_or_type) != FUNCTION_DECL
251 || DECL_STATIC_CHAIN (fndecl_or_type)))
252 {
253 rtx chain;
254
255 chain = targetm.calls.static_chain (fndecl_or_type, false);
256 static_chain_value = convert_memory_address (Pmode, static_chain_value);
257
258 emit_move_insn (chain, static_chain_value);
259 if (REG_P (chain))
260 use_reg (call_fusage, chain);
261 }
262
263 return funexp;
264 }
265
266 /* Generate instructions to call function FUNEXP,
267 and optionally pop the results.
268 The CALL_INSN is the first insn generated.
269
270 FNDECL is the declaration node of the function. This is given to the
271 hook TARGET_RETURN_POPS_ARGS to determine whether this function pops
272 its own args.
273
274 FUNTYPE is the data type of the function. This is given to the hook
275 TARGET_RETURN_POPS_ARGS to determine whether this function pops its
276 own args. We used to allow an identifier for library functions, but
277 that doesn't work when the return type is an aggregate type and the
278 calling convention says that the pointer to this aggregate is to be
279 popped by the callee.
280
281 STACK_SIZE is the number of bytes of arguments on the stack,
282 ROUNDED_STACK_SIZE is that number rounded up to
283 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is
284 both to put into the call insn and to generate explicit popping
285 code if necessary.
286
287 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value.
288 It is zero if this call doesn't want a structure value.
289
290 NEXT_ARG_REG is the rtx that results from executing
291 targetm.calls.function_arg (&args_so_far, VOIDmode, void_type_node, true)
292 just after all the args have had their registers assigned.
293 This could be whatever you like, but normally it is the first
294 arg-register beyond those used for args in this call,
295 or 0 if all the arg-registers are used in this call.
296 It is passed on to `gen_call' so you can put this info in the call insn.
297
298 VALREG is a hard register in which a value is returned,
299 or 0 if the call does not return a value.
300
301 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before
302 the args to this call were processed.
303 We restore `inhibit_defer_pop' to that value.
304
305 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that
306 denote registers used by the called function. */
307
308 static void
309 emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNUSED,
310 tree funtype ATTRIBUTE_UNUSED,
311 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED,
312 HOST_WIDE_INT rounded_stack_size,
313 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED,
314 rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg,
315 int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags,
316 cumulative_args_t args_so_far ATTRIBUTE_UNUSED)
317 {
318 rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
319 rtx_insn *call_insn;
320 rtx call, funmem;
321 int already_popped = 0;
322 HOST_WIDE_INT n_popped
323 = targetm.calls.return_pops_args (fndecl, funtype, stack_size);
324
325 #ifdef CALL_POPS_ARGS
326 n_popped += CALL_POPS_ARGS (*get_cumulative_args (args_so_far));
327 #endif
328
329 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
330 and we don't want to load it into a register as an optimization,
331 because prepare_call_address already did it if it should be done. */
332 if (GET_CODE (funexp) != SYMBOL_REF)
333 funexp = memory_address (FUNCTION_MODE, funexp);
334
335 funmem = gen_rtx_MEM (FUNCTION_MODE, funexp);
336 if (fndecl && TREE_CODE (fndecl) == FUNCTION_DECL)
337 {
338 tree t = fndecl;
339
340 /* Although a built-in FUNCTION_DECL and its non-__builtin
341 counterpart compare equal and get a shared mem_attrs, they
342 produce different dump output in compare-debug compilations,
343 if an entry gets garbage collected in one compilation, then
344 adds a different (but equivalent) entry, while the other
345 doesn't run the garbage collector at the same spot and then
346 shares the mem_attr with the equivalent entry. */
347 if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL)
348 {
349 tree t2 = builtin_decl_explicit (DECL_FUNCTION_CODE (t));
350 if (t2)
351 t = t2;
352 }
353
354 set_mem_expr (funmem, t);
355 }
356 else if (fntree)
357 set_mem_expr (funmem, build_simple_mem_ref (CALL_EXPR_FN (fntree)));
358
359 #if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop)
360 if ((ecf_flags & ECF_SIBCALL)
361 && HAVE_sibcall_pop && HAVE_sibcall_value_pop
362 && (n_popped > 0 || stack_size == 0))
363 {
364 rtx n_pop = GEN_INT (n_popped);
365 rtx pat;
366
367 /* If this subroutine pops its own args, record that in the call insn
368 if possible, for the sake of frame pointer elimination. */
369
370 if (valreg)
371 pat = GEN_SIBCALL_VALUE_POP (valreg, funmem, rounded_stack_size_rtx,
372 next_arg_reg, n_pop);
373 else
374 pat = GEN_SIBCALL_POP (funmem, rounded_stack_size_rtx, next_arg_reg,
375 n_pop);
376
377 emit_call_insn (pat);
378 already_popped = 1;
379 }
380 else
381 #endif
382
383 #if defined (HAVE_call_pop) && defined (HAVE_call_value_pop)
384 /* If the target has "call" or "call_value" insns, then prefer them
385 if no arguments are actually popped. If the target does not have
386 "call" or "call_value" insns, then we must use the popping versions
387 even if the call has no arguments to pop. */
388 #if defined (HAVE_call) && defined (HAVE_call_value)
389 if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop
390 && n_popped > 0)
391 #else
392 if (HAVE_call_pop && HAVE_call_value_pop)
393 #endif
394 {
395 rtx n_pop = GEN_INT (n_popped);
396 rtx pat;
397
398 /* If this subroutine pops its own args, record that in the call insn
399 if possible, for the sake of frame pointer elimination. */
400
401 if (valreg)
402 pat = GEN_CALL_VALUE_POP (valreg, funmem, rounded_stack_size_rtx,
403 next_arg_reg, n_pop);
404 else
405 pat = GEN_CALL_POP (funmem, rounded_stack_size_rtx, next_arg_reg,
406 n_pop);
407
408 emit_call_insn (pat);
409 already_popped = 1;
410 }
411 else
412 #endif
413
414 #if defined (HAVE_sibcall) && defined (HAVE_sibcall_value)
415 if ((ecf_flags & ECF_SIBCALL)
416 && HAVE_sibcall && HAVE_sibcall_value)
417 {
418 if (valreg)
419 emit_call_insn (GEN_SIBCALL_VALUE (valreg, funmem,
420 rounded_stack_size_rtx,
421 next_arg_reg, NULL_RTX));
422 else
423 emit_call_insn (GEN_SIBCALL (funmem, rounded_stack_size_rtx,
424 next_arg_reg,
425 GEN_INT (struct_value_size)));
426 }
427 else
428 #endif
429
430 #if defined (HAVE_call) && defined (HAVE_call_value)
431 if (HAVE_call && HAVE_call_value)
432 {
433 if (valreg)
434 emit_call_insn (GEN_CALL_VALUE (valreg, funmem, rounded_stack_size_rtx,
435 next_arg_reg, NULL_RTX));
436 else
437 emit_call_insn (GEN_CALL (funmem, rounded_stack_size_rtx, next_arg_reg,
438 GEN_INT (struct_value_size)));
439 }
440 else
441 #endif
442 gcc_unreachable ();
443
444 /* Find the call we just emitted. */
445 call_insn = last_call_insn ();
446
447 /* Some target create a fresh MEM instead of reusing the one provided
448 above. Set its MEM_EXPR. */
449 call = get_call_rtx_from (call_insn);
450 if (call
451 && MEM_EXPR (XEXP (call, 0)) == NULL_TREE
452 && MEM_EXPR (funmem) != NULL_TREE)
453 set_mem_expr (XEXP (call, 0), MEM_EXPR (funmem));
454
455 /* Mark instrumented calls. */
456 if (call && fntree)
457 CALL_EXPR_WITH_BOUNDS_P (call) = CALL_WITH_BOUNDS_P (fntree);
458
459 /* Put the register usage information there. */
460 add_function_usage_to (call_insn, call_fusage);
461
462 /* If this is a const call, then set the insn's unchanging bit. */
463 if (ecf_flags & ECF_CONST)
464 RTL_CONST_CALL_P (call_insn) = 1;
465
466 /* If this is a pure call, then set the insn's unchanging bit. */
467 if (ecf_flags & ECF_PURE)
468 RTL_PURE_CALL_P (call_insn) = 1;
469
470 /* If this is a const call, then set the insn's unchanging bit. */
471 if (ecf_flags & ECF_LOOPING_CONST_OR_PURE)
472 RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn) = 1;
473
474 /* Create a nothrow REG_EH_REGION note, if needed. */
475 make_reg_eh_region_note (call_insn, ecf_flags, 0);
476
477 if (ecf_flags & ECF_NORETURN)
478 add_reg_note (call_insn, REG_NORETURN, const0_rtx);
479
480 if (ecf_flags & ECF_RETURNS_TWICE)
481 {
482 add_reg_note (call_insn, REG_SETJMP, const0_rtx);
483 cfun->calls_setjmp = 1;
484 }
485
486 SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
487
488 /* Restore this now, so that we do defer pops for this call's args
489 if the context of the call as a whole permits. */
490 inhibit_defer_pop = old_inhibit_defer_pop;
491
492 if (n_popped > 0)
493 {
494 if (!already_popped)
495 CALL_INSN_FUNCTION_USAGE (call_insn)
496 = gen_rtx_EXPR_LIST (VOIDmode,
497 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
498 CALL_INSN_FUNCTION_USAGE (call_insn));
499 rounded_stack_size -= n_popped;
500 rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
501 stack_pointer_delta -= n_popped;
502
503 add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
504
505 /* If popup is needed, stack realign must use DRAP */
506 if (SUPPORTS_STACK_ALIGNMENT)
507 crtl->need_drap = true;
508 }
509 /* For noreturn calls when not accumulating outgoing args force
510 REG_ARGS_SIZE note to prevent crossjumping of calls with different
511 args sizes. */
512 else if (!ACCUMULATE_OUTGOING_ARGS && (ecf_flags & ECF_NORETURN) != 0)
513 add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
514
515 if (!ACCUMULATE_OUTGOING_ARGS)
516 {
517 /* If returning from the subroutine does not automatically pop the args,
518 we need an instruction to pop them sooner or later.
519 Perhaps do it now; perhaps just record how much space to pop later.
520
521 If returning from the subroutine does pop the args, indicate that the
522 stack pointer will be changed. */
523
524 if (rounded_stack_size != 0)
525 {
526 if (ecf_flags & ECF_NORETURN)
527 /* Just pretend we did the pop. */
528 stack_pointer_delta -= rounded_stack_size;
529 else if (flag_defer_pop && inhibit_defer_pop == 0
530 && ! (ecf_flags & (ECF_CONST | ECF_PURE)))
531 pending_stack_adjust += rounded_stack_size;
532 else
533 adjust_stack (rounded_stack_size_rtx);
534 }
535 }
536 /* When we accumulate outgoing args, we must avoid any stack manipulations.
537 Restore the stack pointer to its original value now. Usually
538 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions.
539 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and
540 popping variants of functions exist as well.
541
542 ??? We may optimize similar to defer_pop above, but it is
543 probably not worthwhile.
544
545 ??? It will be worthwhile to enable combine_stack_adjustments even for
546 such machines. */
547 else if (n_popped)
548 anti_adjust_stack (GEN_INT (n_popped));
549 }
550
551 /* Determine if the function identified by NAME and FNDECL is one with
552 special properties we wish to know about.
553
554 For example, if the function might return more than one time (setjmp), then
555 set RETURNS_TWICE to a nonzero value.
556
557 Similarly set NORETURN if the function is in the longjmp family.
558
559 Set MAY_BE_ALLOCA for any memory allocation function that might allocate
560 space from the stack such as alloca. */
561
562 static int
563 special_function_p (const_tree fndecl, int flags)
564 {
565 tree name_decl = DECL_NAME (fndecl);
566
567 /* For instrumentation clones we want to derive flags
568 from the original name. */
569 if (cgraph_node::get (fndecl)
570 && cgraph_node::get (fndecl)->instrumentation_clone)
571 name_decl = DECL_NAME (cgraph_node::get (fndecl)->orig_decl);
572
573 if (fndecl && name_decl
574 && IDENTIFIER_LENGTH (name_decl) <= 17
575 /* Exclude functions not at the file scope, or not `extern',
576 since they are not the magic functions we would otherwise
577 think they are.
578 FIXME: this should be handled with attributes, not with this
579 hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong
580 because you can declare fork() inside a function if you
581 wish. */
582 && (DECL_CONTEXT (fndecl) == NULL_TREE
583 || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL)
584 && TREE_PUBLIC (fndecl))
585 {
586 const char *name = IDENTIFIER_POINTER (name_decl);
587 const char *tname = name;
588
589 /* We assume that alloca will always be called by name. It
590 makes no sense to pass it as a pointer-to-function to
591 anything that does not understand its behavior. */
592 if (((IDENTIFIER_LENGTH (name_decl) == 6
593 && name[0] == 'a'
594 && ! strcmp (name, "alloca"))
595 || (IDENTIFIER_LENGTH (name_decl) == 16
596 && name[0] == '_'
597 && ! strcmp (name, "__builtin_alloca"))))
598 flags |= ECF_MAY_BE_ALLOCA;
599
600 /* Disregard prefix _, __, __x or __builtin_. */
601 if (name[0] == '_')
602 {
603 if (name[1] == '_'
604 && name[2] == 'b'
605 && !strncmp (name + 3, "uiltin_", 7))
606 tname += 10;
607 else if (name[1] == '_' && name[2] == 'x')
608 tname += 3;
609 else if (name[1] == '_')
610 tname += 2;
611 else
612 tname += 1;
613 }
614
615 if (tname[0] == 's')
616 {
617 if ((tname[1] == 'e'
618 && (! strcmp (tname, "setjmp")
619 || ! strcmp (tname, "setjmp_syscall")))
620 || (tname[1] == 'i'
621 && ! strcmp (tname, "sigsetjmp"))
622 || (tname[1] == 'a'
623 && ! strcmp (tname, "savectx")))
624 flags |= ECF_RETURNS_TWICE | ECF_LEAF;
625
626 if (tname[1] == 'i'
627 && ! strcmp (tname, "siglongjmp"))
628 flags |= ECF_NORETURN;
629 }
630 else if ((tname[0] == 'q' && tname[1] == 's'
631 && ! strcmp (tname, "qsetjmp"))
632 || (tname[0] == 'v' && tname[1] == 'f'
633 && ! strcmp (tname, "vfork"))
634 || (tname[0] == 'g' && tname[1] == 'e'
635 && !strcmp (tname, "getcontext")))
636 flags |= ECF_RETURNS_TWICE | ECF_LEAF;
637
638 else if (tname[0] == 'l' && tname[1] == 'o'
639 && ! strcmp (tname, "longjmp"))
640 flags |= ECF_NORETURN;
641 }
642
643 return flags;
644 }
645
646 /* Similar to special_function_p; return a set of ERF_ flags for the
647 function FNDECL. */
648 static int
649 decl_return_flags (tree fndecl)
650 {
651 tree attr;
652 tree type = TREE_TYPE (fndecl);
653 if (!type)
654 return 0;
655
656 attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type));
657 if (!attr)
658 return 0;
659
660 attr = TREE_VALUE (TREE_VALUE (attr));
661 if (!attr || TREE_STRING_LENGTH (attr) < 1)
662 return 0;
663
664 switch (TREE_STRING_POINTER (attr)[0])
665 {
666 case '1':
667 case '2':
668 case '3':
669 case '4':
670 return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1');
671
672 case 'm':
673 return ERF_NOALIAS;
674
675 case '.':
676 default:
677 return 0;
678 }
679 }
680
681 /* Return nonzero when FNDECL represents a call to setjmp. */
682
683 int
684 setjmp_call_p (const_tree fndecl)
685 {
686 if (DECL_IS_RETURNS_TWICE (fndecl))
687 return ECF_RETURNS_TWICE;
688 return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE;
689 }
690
691
692 /* Return true if STMT is an alloca call. */
693
694 bool
695 gimple_alloca_call_p (const_gimple stmt)
696 {
697 tree fndecl;
698
699 if (!is_gimple_call (stmt))
700 return false;
701
702 fndecl = gimple_call_fndecl (stmt);
703 if (fndecl && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA))
704 return true;
705
706 return false;
707 }
708
709 /* Return true when exp contains alloca call. */
710
711 bool
712 alloca_call_p (const_tree exp)
713 {
714 tree fndecl;
715 if (TREE_CODE (exp) == CALL_EXPR
716 && (fndecl = get_callee_fndecl (exp))
717 && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA))
718 return true;
719 return false;
720 }
721
722 /* Return TRUE if FNDECL is either a TM builtin or a TM cloned
723 function. Return FALSE otherwise. */
724
725 static bool
726 is_tm_builtin (const_tree fndecl)
727 {
728 if (fndecl == NULL)
729 return false;
730
731 if (decl_is_tm_clone (fndecl))
732 return true;
733
734 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
735 {
736 switch (DECL_FUNCTION_CODE (fndecl))
737 {
738 case BUILT_IN_TM_COMMIT:
739 case BUILT_IN_TM_COMMIT_EH:
740 case BUILT_IN_TM_ABORT:
741 case BUILT_IN_TM_IRREVOCABLE:
742 case BUILT_IN_TM_GETTMCLONE_IRR:
743 case BUILT_IN_TM_MEMCPY:
744 case BUILT_IN_TM_MEMMOVE:
745 case BUILT_IN_TM_MEMSET:
746 CASE_BUILT_IN_TM_STORE (1):
747 CASE_BUILT_IN_TM_STORE (2):
748 CASE_BUILT_IN_TM_STORE (4):
749 CASE_BUILT_IN_TM_STORE (8):
750 CASE_BUILT_IN_TM_STORE (FLOAT):
751 CASE_BUILT_IN_TM_STORE (DOUBLE):
752 CASE_BUILT_IN_TM_STORE (LDOUBLE):
753 CASE_BUILT_IN_TM_STORE (M64):
754 CASE_BUILT_IN_TM_STORE (M128):
755 CASE_BUILT_IN_TM_STORE (M256):
756 CASE_BUILT_IN_TM_LOAD (1):
757 CASE_BUILT_IN_TM_LOAD (2):
758 CASE_BUILT_IN_TM_LOAD (4):
759 CASE_BUILT_IN_TM_LOAD (8):
760 CASE_BUILT_IN_TM_LOAD (FLOAT):
761 CASE_BUILT_IN_TM_LOAD (DOUBLE):
762 CASE_BUILT_IN_TM_LOAD (LDOUBLE):
763 CASE_BUILT_IN_TM_LOAD (M64):
764 CASE_BUILT_IN_TM_LOAD (M128):
765 CASE_BUILT_IN_TM_LOAD (M256):
766 case BUILT_IN_TM_LOG:
767 case BUILT_IN_TM_LOG_1:
768 case BUILT_IN_TM_LOG_2:
769 case BUILT_IN_TM_LOG_4:
770 case BUILT_IN_TM_LOG_8:
771 case BUILT_IN_TM_LOG_FLOAT:
772 case BUILT_IN_TM_LOG_DOUBLE:
773 case BUILT_IN_TM_LOG_LDOUBLE:
774 case BUILT_IN_TM_LOG_M64:
775 case BUILT_IN_TM_LOG_M128:
776 case BUILT_IN_TM_LOG_M256:
777 return true;
778 default:
779 break;
780 }
781 }
782 return false;
783 }
784
785 /* Detect flags (function attributes) from the function decl or type node. */
786
787 int
788 flags_from_decl_or_type (const_tree exp)
789 {
790 int flags = 0;
791
792 if (DECL_P (exp))
793 {
794 /* The function exp may have the `malloc' attribute. */
795 if (DECL_IS_MALLOC (exp))
796 flags |= ECF_MALLOC;
797
798 /* The function exp may have the `returns_twice' attribute. */
799 if (DECL_IS_RETURNS_TWICE (exp))
800 flags |= ECF_RETURNS_TWICE;
801
802 /* Process the pure and const attributes. */
803 if (TREE_READONLY (exp))
804 flags |= ECF_CONST;
805 if (DECL_PURE_P (exp))
806 flags |= ECF_PURE;
807 if (DECL_LOOPING_CONST_OR_PURE_P (exp))
808 flags |= ECF_LOOPING_CONST_OR_PURE;
809
810 if (DECL_IS_NOVOPS (exp))
811 flags |= ECF_NOVOPS;
812 if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp)))
813 flags |= ECF_LEAF;
814
815 if (TREE_NOTHROW (exp))
816 flags |= ECF_NOTHROW;
817
818 if (flag_tm)
819 {
820 if (is_tm_builtin (exp))
821 flags |= ECF_TM_BUILTIN;
822 else if ((flags & (ECF_CONST|ECF_NOVOPS)) != 0
823 || lookup_attribute ("transaction_pure",
824 TYPE_ATTRIBUTES (TREE_TYPE (exp))))
825 flags |= ECF_TM_PURE;
826 }
827
828 flags = special_function_p (exp, flags);
829 }
830 else if (TYPE_P (exp))
831 {
832 if (TYPE_READONLY (exp))
833 flags |= ECF_CONST;
834
835 if (flag_tm
836 && ((flags & ECF_CONST) != 0
837 || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp))))
838 flags |= ECF_TM_PURE;
839 }
840 else
841 gcc_unreachable ();
842
843 if (TREE_THIS_VOLATILE (exp))
844 {
845 flags |= ECF_NORETURN;
846 if (flags & (ECF_CONST|ECF_PURE))
847 flags |= ECF_LOOPING_CONST_OR_PURE;
848 }
849
850 return flags;
851 }
852
853 /* Detect flags from a CALL_EXPR. */
854
855 int
856 call_expr_flags (const_tree t)
857 {
858 int flags;
859 tree decl = get_callee_fndecl (t);
860
861 if (decl)
862 flags = flags_from_decl_or_type (decl);
863 else if (CALL_EXPR_FN (t) == NULL_TREE)
864 flags = internal_fn_flags (CALL_EXPR_IFN (t));
865 else
866 {
867 t = TREE_TYPE (CALL_EXPR_FN (t));
868 if (t && TREE_CODE (t) == POINTER_TYPE)
869 flags = flags_from_decl_or_type (TREE_TYPE (t));
870 else
871 flags = 0;
872 }
873
874 return flags;
875 }
876
877 /* Precompute all register parameters as described by ARGS, storing values
878 into fields within the ARGS array.
879
880 NUM_ACTUALS indicates the total number elements in the ARGS array.
881
882 Set REG_PARM_SEEN if we encounter a register parameter. */
883
884 static void
885 precompute_register_parameters (int num_actuals, struct arg_data *args,
886 int *reg_parm_seen)
887 {
888 int i;
889
890 *reg_parm_seen = 0;
891
892 for (i = 0; i < num_actuals; i++)
893 if (args[i].reg != 0 && ! args[i].pass_on_stack)
894 {
895 *reg_parm_seen = 1;
896
897 if (args[i].value == 0)
898 {
899 push_temp_slots ();
900 args[i].value = expand_normal (args[i].tree_value);
901 preserve_temp_slots (args[i].value);
902 pop_temp_slots ();
903 }
904
905 /* If we are to promote the function arg to a wider mode,
906 do it now. */
907
908 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value)))
909 args[i].value
910 = convert_modes (args[i].mode,
911 TYPE_MODE (TREE_TYPE (args[i].tree_value)),
912 args[i].value, args[i].unsignedp);
913
914 /* If the value is a non-legitimate constant, force it into a
915 pseudo now. TLS symbols sometimes need a call to resolve. */
916 if (CONSTANT_P (args[i].value)
917 && !targetm.legitimate_constant_p (args[i].mode, args[i].value))
918 args[i].value = force_reg (args[i].mode, args[i].value);
919
920 /* If we're going to have to load the value by parts, pull the
921 parts into pseudos. The part extraction process can involve
922 non-trivial computation. */
923 if (GET_CODE (args[i].reg) == PARALLEL)
924 {
925 tree type = TREE_TYPE (args[i].tree_value);
926 args[i].parallel_value
927 = emit_group_load_into_temps (args[i].reg, args[i].value,
928 type, int_size_in_bytes (type));
929 }
930
931 /* If the value is expensive, and we are inside an appropriately
932 short loop, put the value into a pseudo and then put the pseudo
933 into the hard reg.
934
935 For small register classes, also do this if this call uses
936 register parameters. This is to avoid reload conflicts while
937 loading the parameters registers. */
938
939 else if ((! (REG_P (args[i].value)
940 || (GET_CODE (args[i].value) == SUBREG
941 && REG_P (SUBREG_REG (args[i].value)))))
942 && args[i].mode != BLKmode
943 && set_src_cost (args[i].value, optimize_insn_for_speed_p ())
944 > COSTS_N_INSNS (1)
945 && ((*reg_parm_seen
946 && targetm.small_register_classes_for_mode_p (args[i].mode))
947 || optimize))
948 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value);
949 }
950 }
951
952 #ifdef REG_PARM_STACK_SPACE
953
954 /* The argument list is the property of the called routine and it
955 may clobber it. If the fixed area has been used for previous
956 parameters, we must save and restore it. */
957
958 static rtx
959 save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
960 {
961 int low;
962 int high;
963
964 /* Compute the boundary of the area that needs to be saved, if any. */
965 high = reg_parm_stack_space;
966 if (ARGS_GROW_DOWNWARD)
967 high += 1;
968
969 if (high > highest_outgoing_arg_in_use)
970 high = highest_outgoing_arg_in_use;
971
972 for (low = 0; low < high; low++)
973 if (stack_usage_map[low] != 0)
974 {
975 int num_to_save;
976 machine_mode save_mode;
977 int delta;
978 rtx addr;
979 rtx stack_area;
980 rtx save_area;
981
982 while (stack_usage_map[--high] == 0)
983 ;
984
985 *low_to_save = low;
986 *high_to_save = high;
987
988 num_to_save = high - low + 1;
989 save_mode = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1);
990
991 /* If we don't have the required alignment, must do this
992 in BLKmode. */
993 if ((low & (MIN (GET_MODE_SIZE (save_mode),
994 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1)))
995 save_mode = BLKmode;
996
997 if (ARGS_GROW_DOWNWARD)
998 delta = -high;
999 else
1000 delta = low;
1001
1002 addr = plus_constant (Pmode, argblock, delta);
1003 stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr));
1004
1005 set_mem_align (stack_area, PARM_BOUNDARY);
1006 if (save_mode == BLKmode)
1007 {
1008 save_area = assign_stack_temp (BLKmode, num_to_save);
1009 emit_block_move (validize_mem (save_area), stack_area,
1010 GEN_INT (num_to_save), BLOCK_OP_CALL_PARM);
1011 }
1012 else
1013 {
1014 save_area = gen_reg_rtx (save_mode);
1015 emit_move_insn (save_area, stack_area);
1016 }
1017
1018 return save_area;
1019 }
1020
1021 return NULL_RTX;
1022 }
1023
1024 static void
1025 restore_fixed_argument_area (rtx save_area, rtx argblock, int high_to_save, int low_to_save)
1026 {
1027 machine_mode save_mode = GET_MODE (save_area);
1028 int delta;
1029 rtx addr, stack_area;
1030
1031 if (ARGS_GROW_DOWNWARD)
1032 delta = -high_to_save;
1033 else
1034 delta = low_to_save;
1035
1036 addr = plus_constant (Pmode, argblock, delta);
1037 stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr));
1038 set_mem_align (stack_area, PARM_BOUNDARY);
1039
1040 if (save_mode != BLKmode)
1041 emit_move_insn (stack_area, save_area);
1042 else
1043 emit_block_move (stack_area, validize_mem (save_area),
1044 GEN_INT (high_to_save - low_to_save + 1),
1045 BLOCK_OP_CALL_PARM);
1046 }
1047 #endif /* REG_PARM_STACK_SPACE */
1048
1049 /* If any elements in ARGS refer to parameters that are to be passed in
1050 registers, but not in memory, and whose alignment does not permit a
1051 direct copy into registers. Copy the values into a group of pseudos
1052 which we will later copy into the appropriate hard registers.
1053
1054 Pseudos for each unaligned argument will be stored into the array
1055 args[argnum].aligned_regs. The caller is responsible for deallocating
1056 the aligned_regs array if it is nonzero. */
1057
1058 static void
1059 store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals)
1060 {
1061 int i, j;
1062
1063 for (i = 0; i < num_actuals; i++)
1064 if (args[i].reg != 0 && ! args[i].pass_on_stack
1065 && GET_CODE (args[i].reg) != PARALLEL
1066 && args[i].mode == BLKmode
1067 && MEM_P (args[i].value)
1068 && (MEM_ALIGN (args[i].value)
1069 < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD)))
1070 {
1071 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1072 int endian_correction = 0;
1073
1074 if (args[i].partial)
1075 {
1076 gcc_assert (args[i].partial % UNITS_PER_WORD == 0);
1077 args[i].n_aligned_regs = args[i].partial / UNITS_PER_WORD;
1078 }
1079 else
1080 {
1081 args[i].n_aligned_regs
1082 = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1083 }
1084
1085 args[i].aligned_regs = XNEWVEC (rtx, args[i].n_aligned_regs);
1086
1087 /* Structures smaller than a word are normally aligned to the
1088 least significant byte. On a BYTES_BIG_ENDIAN machine,
1089 this means we must skip the empty high order bytes when
1090 calculating the bit offset. */
1091 if (bytes < UNITS_PER_WORD
1092 #ifdef BLOCK_REG_PADDING
1093 && (BLOCK_REG_PADDING (args[i].mode,
1094 TREE_TYPE (args[i].tree_value), 1)
1095 == downward)
1096 #else
1097 && BYTES_BIG_ENDIAN
1098 #endif
1099 )
1100 endian_correction = BITS_PER_WORD - bytes * BITS_PER_UNIT;
1101
1102 for (j = 0; j < args[i].n_aligned_regs; j++)
1103 {
1104 rtx reg = gen_reg_rtx (word_mode);
1105 rtx word = operand_subword_force (args[i].value, j, BLKmode);
1106 int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD);
1107
1108 args[i].aligned_regs[j] = reg;
1109 word = extract_bit_field (word, bitsize, 0, 1, NULL_RTX,
1110 word_mode, word_mode);
1111
1112 /* There is no need to restrict this code to loading items
1113 in TYPE_ALIGN sized hunks. The bitfield instructions can
1114 load up entire word sized registers efficiently.
1115
1116 ??? This may not be needed anymore.
1117 We use to emit a clobber here but that doesn't let later
1118 passes optimize the instructions we emit. By storing 0 into
1119 the register later passes know the first AND to zero out the
1120 bitfield being set in the register is unnecessary. The store
1121 of 0 will be deleted as will at least the first AND. */
1122
1123 emit_move_insn (reg, const0_rtx);
1124
1125 bytes -= bitsize / BITS_PER_UNIT;
1126 store_bit_field (reg, bitsize, endian_correction, 0, 0,
1127 word_mode, word);
1128 }
1129 }
1130 }
1131
1132 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in
1133 CALL_EXPR EXP.
1134
1135 NUM_ACTUALS is the total number of parameters.
1136
1137 N_NAMED_ARGS is the total number of named arguments.
1138
1139 STRUCT_VALUE_ADDR_VALUE is the implicit argument for a struct return
1140 value, or null.
1141
1142 FNDECL is the tree code for the target of this call (if known)
1143
1144 ARGS_SO_FAR holds state needed by the target to know where to place
1145 the next argument.
1146
1147 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
1148 for arguments which are passed in registers.
1149
1150 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level
1151 and may be modified by this routine.
1152
1153 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer
1154 flags which may may be modified by this routine.
1155
1156 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference
1157 that requires allocation of stack space.
1158
1159 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to
1160 the thunked-to function. */
1161
1162 static void
1163 initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED,
1164 struct arg_data *args,
1165 struct args_size *args_size,
1166 int n_named_args ATTRIBUTE_UNUSED,
1167 tree exp, tree struct_value_addr_value,
1168 tree fndecl, tree fntype,
1169 cumulative_args_t args_so_far,
1170 int reg_parm_stack_space,
1171 rtx *old_stack_level, int *old_pending_adj,
1172 int *must_preallocate, int *ecf_flags,
1173 bool *may_tailcall, bool call_from_thunk_p)
1174 {
1175 CUMULATIVE_ARGS *args_so_far_pnt = get_cumulative_args (args_so_far);
1176 location_t loc = EXPR_LOCATION (exp);
1177
1178 /* Count arg position in order args appear. */
1179 int argpos;
1180
1181 int i;
1182
1183 args_size->constant = 0;
1184 args_size->var = 0;
1185
1186 bitmap_obstack_initialize (NULL);
1187
1188 /* In this loop, we consider args in the order they are written.
1189 We fill up ARGS from the back. */
1190
1191 i = num_actuals - 1;
1192 {
1193 int j = i, ptr_arg = -1;
1194 call_expr_arg_iterator iter;
1195 tree arg;
1196 bitmap slots = NULL;
1197
1198 if (struct_value_addr_value)
1199 {
1200 args[j].tree_value = struct_value_addr_value;
1201 j--;
1202
1203 /* If we pass structure address then we need to
1204 create bounds for it. Since created bounds is
1205 a call statement, we expand it right here to avoid
1206 fixing all other places where it may be expanded. */
1207 if (CALL_WITH_BOUNDS_P (exp))
1208 {
1209 args[j].value = gen_reg_rtx (targetm.chkp_bound_mode ());
1210 args[j].tree_value
1211 = chkp_make_bounds_for_struct_addr (struct_value_addr_value);
1212 expand_expr_real (args[j].tree_value, args[j].value, VOIDmode,
1213 EXPAND_NORMAL, 0, false);
1214 args[j].pointer_arg = j + 1;
1215 j--;
1216 }
1217 }
1218 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
1219 {
1220 tree argtype = TREE_TYPE (arg);
1221
1222 /* Remember last param with pointer and associate it
1223 with following pointer bounds. */
1224 if (CALL_WITH_BOUNDS_P (exp)
1225 && chkp_type_has_pointer (argtype))
1226 {
1227 if (slots)
1228 BITMAP_FREE (slots);
1229 ptr_arg = j;
1230 if (!BOUNDED_TYPE_P (argtype))
1231 {
1232 slots = BITMAP_ALLOC (NULL);
1233 chkp_find_bound_slots (argtype, slots);
1234 }
1235 }
1236 else if (POINTER_BOUNDS_TYPE_P (argtype))
1237 {
1238 /* We expect bounds in instrumented calls only.
1239 Otherwise it is a sign we lost flag due to some optimization
1240 and may emit call args incorrectly. */
1241 gcc_assert (CALL_WITH_BOUNDS_P (exp));
1242
1243 /* For structures look for the next available pointer. */
1244 if (ptr_arg != -1 && slots)
1245 {
1246 unsigned bnd_no = bitmap_first_set_bit (slots);
1247 args[j].pointer_offset =
1248 bnd_no * POINTER_SIZE / BITS_PER_UNIT;
1249
1250 bitmap_clear_bit (slots, bnd_no);
1251
1252 /* Check we have no more pointers in the structure. */
1253 if (bitmap_empty_p (slots))
1254 BITMAP_FREE (slots);
1255 }
1256 args[j].pointer_arg = ptr_arg;
1257
1258 /* Check we covered all pointers in the previous
1259 non bounds arg. */
1260 if (!slots)
1261 ptr_arg = -1;
1262 }
1263 else
1264 ptr_arg = -1;
1265
1266 if (targetm.calls.split_complex_arg
1267 && argtype
1268 && TREE_CODE (argtype) == COMPLEX_TYPE
1269 && targetm.calls.split_complex_arg (argtype))
1270 {
1271 tree subtype = TREE_TYPE (argtype);
1272 args[j].tree_value = build1 (REALPART_EXPR, subtype, arg);
1273 j--;
1274 args[j].tree_value = build1 (IMAGPART_EXPR, subtype, arg);
1275 }
1276 else
1277 args[j].tree_value = arg;
1278 j--;
1279 }
1280
1281 if (slots)
1282 BITMAP_FREE (slots);
1283 }
1284
1285 bitmap_obstack_release (NULL);
1286
1287 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */
1288 for (argpos = 0; argpos < num_actuals; i--, argpos++)
1289 {
1290 tree type = TREE_TYPE (args[i].tree_value);
1291 int unsignedp;
1292 machine_mode mode;
1293
1294 /* Replace erroneous argument with constant zero. */
1295 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
1296 args[i].tree_value = integer_zero_node, type = integer_type_node;
1297
1298 /* If TYPE is a transparent union or record, pass things the way
1299 we would pass the first field of the union or record. We have
1300 already verified that the modes are the same. */
1301 if ((TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == RECORD_TYPE)
1302 && TYPE_TRANSPARENT_AGGR (type))
1303 type = TREE_TYPE (first_field (type));
1304
1305 /* Decide where to pass this arg.
1306
1307 args[i].reg is nonzero if all or part is passed in registers.
1308
1309 args[i].partial is nonzero if part but not all is passed in registers,
1310 and the exact value says how many bytes are passed in registers.
1311
1312 args[i].pass_on_stack is nonzero if the argument must at least be
1313 computed on the stack. It may then be loaded back into registers
1314 if args[i].reg is nonzero.
1315
1316 These decisions are driven by the FUNCTION_... macros and must agree
1317 with those made by function.c. */
1318
1319 /* See if this argument should be passed by invisible reference. */
1320 if (pass_by_reference (args_so_far_pnt, TYPE_MODE (type),
1321 type, argpos < n_named_args))
1322 {
1323 bool callee_copies;
1324 tree base = NULL_TREE;
1325
1326 callee_copies
1327 = reference_callee_copied (args_so_far_pnt, TYPE_MODE (type),
1328 type, argpos < n_named_args);
1329
1330 /* If we're compiling a thunk, pass through invisible references
1331 instead of making a copy. */
1332 if (call_from_thunk_p
1333 || (callee_copies
1334 && !TREE_ADDRESSABLE (type)
1335 && (base = get_base_address (args[i].tree_value))
1336 && TREE_CODE (base) != SSA_NAME
1337 && (!DECL_P (base) || MEM_P (DECL_RTL (base)))))
1338 {
1339 /* We may have turned the parameter value into an SSA name.
1340 Go back to the original parameter so we can take the
1341 address. */
1342 if (TREE_CODE (args[i].tree_value) == SSA_NAME)
1343 {
1344 gcc_assert (SSA_NAME_IS_DEFAULT_DEF (args[i].tree_value));
1345 args[i].tree_value = SSA_NAME_VAR (args[i].tree_value);
1346 gcc_assert (TREE_CODE (args[i].tree_value) == PARM_DECL);
1347 }
1348 /* Argument setup code may have copied the value to register. We
1349 revert that optimization now because the tail call code must
1350 use the original location. */
1351 if (TREE_CODE (args[i].tree_value) == PARM_DECL
1352 && !MEM_P (DECL_RTL (args[i].tree_value))
1353 && DECL_INCOMING_RTL (args[i].tree_value)
1354 && MEM_P (DECL_INCOMING_RTL (args[i].tree_value)))
1355 set_decl_rtl (args[i].tree_value,
1356 DECL_INCOMING_RTL (args[i].tree_value));
1357
1358 mark_addressable (args[i].tree_value);
1359
1360 /* We can't use sibcalls if a callee-copied argument is
1361 stored in the current function's frame. */
1362 if (!call_from_thunk_p && DECL_P (base) && !TREE_STATIC (base))
1363 *may_tailcall = false;
1364
1365 args[i].tree_value = build_fold_addr_expr_loc (loc,
1366 args[i].tree_value);
1367 type = TREE_TYPE (args[i].tree_value);
1368
1369 if (*ecf_flags & ECF_CONST)
1370 *ecf_flags &= ~(ECF_CONST | ECF_LOOPING_CONST_OR_PURE);
1371 }
1372 else
1373 {
1374 /* We make a copy of the object and pass the address to the
1375 function being called. */
1376 rtx copy;
1377
1378 if (!COMPLETE_TYPE_P (type)
1379 || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
1380 || (flag_stack_check == GENERIC_STACK_CHECK
1381 && compare_tree_int (TYPE_SIZE_UNIT (type),
1382 STACK_CHECK_MAX_VAR_SIZE) > 0))
1383 {
1384 /* This is a variable-sized object. Make space on the stack
1385 for it. */
1386 rtx size_rtx = expr_size (args[i].tree_value);
1387
1388 if (*old_stack_level == 0)
1389 {
1390 emit_stack_save (SAVE_BLOCK, old_stack_level);
1391 *old_pending_adj = pending_stack_adjust;
1392 pending_stack_adjust = 0;
1393 }
1394
1395 /* We can pass TRUE as the 4th argument because we just
1396 saved the stack pointer and will restore it right after
1397 the call. */
1398 copy = allocate_dynamic_stack_space (size_rtx,
1399 TYPE_ALIGN (type),
1400 TYPE_ALIGN (type),
1401 true);
1402 copy = gen_rtx_MEM (BLKmode, copy);
1403 set_mem_attributes (copy, type, 1);
1404 }
1405 else
1406 copy = assign_temp (type, 1, 0);
1407
1408 store_expr (args[i].tree_value, copy, 0, false);
1409
1410 /* Just change the const function to pure and then let
1411 the next test clear the pure based on
1412 callee_copies. */
1413 if (*ecf_flags & ECF_CONST)
1414 {
1415 *ecf_flags &= ~ECF_CONST;
1416 *ecf_flags |= ECF_PURE;
1417 }
1418
1419 if (!callee_copies && *ecf_flags & ECF_PURE)
1420 *ecf_flags &= ~(ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
1421
1422 args[i].tree_value
1423 = build_fold_addr_expr_loc (loc, make_tree (type, copy));
1424 type = TREE_TYPE (args[i].tree_value);
1425 *may_tailcall = false;
1426 }
1427 }
1428
1429 unsignedp = TYPE_UNSIGNED (type);
1430 mode = promote_function_mode (type, TYPE_MODE (type), &unsignedp,
1431 fndecl ? TREE_TYPE (fndecl) : fntype, 0);
1432
1433 args[i].unsignedp = unsignedp;
1434 args[i].mode = mode;
1435
1436 args[i].reg = targetm.calls.function_arg (args_so_far, mode, type,
1437 argpos < n_named_args);
1438
1439 if (args[i].reg && CONST_INT_P (args[i].reg))
1440 {
1441 args[i].special_slot = args[i].reg;
1442 args[i].reg = NULL;
1443 }
1444
1445 /* If this is a sibling call and the machine has register windows, the
1446 register window has to be unwinded before calling the routine, so
1447 arguments have to go into the incoming registers. */
1448 if (targetm.calls.function_incoming_arg != targetm.calls.function_arg)
1449 args[i].tail_call_reg
1450 = targetm.calls.function_incoming_arg (args_so_far, mode, type,
1451 argpos < n_named_args);
1452 else
1453 args[i].tail_call_reg = args[i].reg;
1454
1455 if (args[i].reg)
1456 args[i].partial
1457 = targetm.calls.arg_partial_bytes (args_so_far, mode, type,
1458 argpos < n_named_args);
1459
1460 args[i].pass_on_stack = targetm.calls.must_pass_in_stack (mode, type);
1461
1462 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]),
1463 it means that we are to pass this arg in the register(s) designated
1464 by the PARALLEL, but also to pass it in the stack. */
1465 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL
1466 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0)
1467 args[i].pass_on_stack = 1;
1468
1469 /* If this is an addressable type, we must preallocate the stack
1470 since we must evaluate the object into its final location.
1471
1472 If this is to be passed in both registers and the stack, it is simpler
1473 to preallocate. */
1474 if (TREE_ADDRESSABLE (type)
1475 || (args[i].pass_on_stack && args[i].reg != 0))
1476 *must_preallocate = 1;
1477
1478 /* No stack allocation and padding for bounds. */
1479 if (POINTER_BOUNDS_P (args[i].tree_value))
1480 ;
1481 /* Compute the stack-size of this argument. */
1482 else if (args[i].reg == 0 || args[i].partial != 0
1483 || reg_parm_stack_space > 0
1484 || args[i].pass_on_stack)
1485 locate_and_pad_parm (mode, type,
1486 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1487 1,
1488 #else
1489 args[i].reg != 0,
1490 #endif
1491 reg_parm_stack_space,
1492 args[i].pass_on_stack ? 0 : args[i].partial,
1493 fndecl, args_size, &args[i].locate);
1494 #ifdef BLOCK_REG_PADDING
1495 else
1496 /* The argument is passed entirely in registers. See at which
1497 end it should be padded. */
1498 args[i].locate.where_pad =
1499 BLOCK_REG_PADDING (mode, type,
1500 int_size_in_bytes (type) <= UNITS_PER_WORD);
1501 #endif
1502
1503 /* Update ARGS_SIZE, the total stack space for args so far. */
1504
1505 args_size->constant += args[i].locate.size.constant;
1506 if (args[i].locate.size.var)
1507 ADD_PARM_SIZE (*args_size, args[i].locate.size.var);
1508
1509 /* Increment ARGS_SO_FAR, which has info about which arg-registers
1510 have been used, etc. */
1511
1512 targetm.calls.function_arg_advance (args_so_far, TYPE_MODE (type),
1513 type, argpos < n_named_args);
1514 }
1515 }
1516
1517 /* Update ARGS_SIZE to contain the total size for the argument block.
1518 Return the original constant component of the argument block's size.
1519
1520 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
1521 for arguments passed in registers. */
1522
1523 static int
1524 compute_argument_block_size (int reg_parm_stack_space,
1525 struct args_size *args_size,
1526 tree fndecl ATTRIBUTE_UNUSED,
1527 tree fntype ATTRIBUTE_UNUSED,
1528 int preferred_stack_boundary ATTRIBUTE_UNUSED)
1529 {
1530 int unadjusted_args_size = args_size->constant;
1531
1532 /* For accumulate outgoing args mode we don't need to align, since the frame
1533 will be already aligned. Align to STACK_BOUNDARY in order to prevent
1534 backends from generating misaligned frame sizes. */
1535 if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY)
1536 preferred_stack_boundary = STACK_BOUNDARY;
1537
1538 /* Compute the actual size of the argument block required. The variable
1539 and constant sizes must be combined, the size may have to be rounded,
1540 and there may be a minimum required size. */
1541
1542 if (args_size->var)
1543 {
1544 args_size->var = ARGS_SIZE_TREE (*args_size);
1545 args_size->constant = 0;
1546
1547 preferred_stack_boundary /= BITS_PER_UNIT;
1548 if (preferred_stack_boundary > 1)
1549 {
1550 /* We don't handle this case yet. To handle it correctly we have
1551 to add the delta, round and subtract the delta.
1552 Currently no machine description requires this support. */
1553 gcc_assert (!(stack_pointer_delta & (preferred_stack_boundary - 1)));
1554 args_size->var = round_up (args_size->var, preferred_stack_boundary);
1555 }
1556
1557 if (reg_parm_stack_space > 0)
1558 {
1559 args_size->var
1560 = size_binop (MAX_EXPR, args_size->var,
1561 ssize_int (reg_parm_stack_space));
1562
1563 /* The area corresponding to register parameters is not to count in
1564 the size of the block we need. So make the adjustment. */
1565 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
1566 args_size->var
1567 = size_binop (MINUS_EXPR, args_size->var,
1568 ssize_int (reg_parm_stack_space));
1569 }
1570 }
1571 else
1572 {
1573 preferred_stack_boundary /= BITS_PER_UNIT;
1574 if (preferred_stack_boundary < 1)
1575 preferred_stack_boundary = 1;
1576 args_size->constant = (((args_size->constant
1577 + stack_pointer_delta
1578 + preferred_stack_boundary - 1)
1579 / preferred_stack_boundary
1580 * preferred_stack_boundary)
1581 - stack_pointer_delta);
1582
1583 args_size->constant = MAX (args_size->constant,
1584 reg_parm_stack_space);
1585
1586 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
1587 args_size->constant -= reg_parm_stack_space;
1588 }
1589 return unadjusted_args_size;
1590 }
1591
1592 /* Precompute parameters as needed for a function call.
1593
1594 FLAGS is mask of ECF_* constants.
1595
1596 NUM_ACTUALS is the number of arguments.
1597
1598 ARGS is an array containing information for each argument; this
1599 routine fills in the INITIAL_VALUE and VALUE fields for each
1600 precomputed argument. */
1601
1602 static void
1603 precompute_arguments (int num_actuals, struct arg_data *args)
1604 {
1605 int i;
1606
1607 /* If this is a libcall, then precompute all arguments so that we do not
1608 get extraneous instructions emitted as part of the libcall sequence. */
1609
1610 /* If we preallocated the stack space, and some arguments must be passed
1611 on the stack, then we must precompute any parameter which contains a
1612 function call which will store arguments on the stack.
1613 Otherwise, evaluating the parameter may clobber previous parameters
1614 which have already been stored into the stack. (we have code to avoid
1615 such case by saving the outgoing stack arguments, but it results in
1616 worse code) */
1617 if (!ACCUMULATE_OUTGOING_ARGS)
1618 return;
1619
1620 for (i = 0; i < num_actuals; i++)
1621 {
1622 tree type;
1623 machine_mode mode;
1624
1625 if (TREE_CODE (args[i].tree_value) != CALL_EXPR)
1626 continue;
1627
1628 /* If this is an addressable type, we cannot pre-evaluate it. */
1629 type = TREE_TYPE (args[i].tree_value);
1630 gcc_assert (!TREE_ADDRESSABLE (type));
1631
1632 args[i].initial_value = args[i].value
1633 = expand_normal (args[i].tree_value);
1634
1635 mode = TYPE_MODE (type);
1636 if (mode != args[i].mode)
1637 {
1638 int unsignedp = args[i].unsignedp;
1639 args[i].value
1640 = convert_modes (args[i].mode, mode,
1641 args[i].value, args[i].unsignedp);
1642
1643 /* CSE will replace this only if it contains args[i].value
1644 pseudo, so convert it down to the declared mode using
1645 a SUBREG. */
1646 if (REG_P (args[i].value)
1647 && GET_MODE_CLASS (args[i].mode) == MODE_INT
1648 && promote_mode (type, mode, &unsignedp) != args[i].mode)
1649 {
1650 args[i].initial_value
1651 = gen_lowpart_SUBREG (mode, args[i].value);
1652 SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
1653 SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp);
1654 }
1655 }
1656 }
1657 }
1658
1659 /* Given the current state of MUST_PREALLOCATE and information about
1660 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE,
1661 compute and return the final value for MUST_PREALLOCATE. */
1662
1663 static int
1664 finalize_must_preallocate (int must_preallocate, int num_actuals,
1665 struct arg_data *args, struct args_size *args_size)
1666 {
1667 /* See if we have or want to preallocate stack space.
1668
1669 If we would have to push a partially-in-regs parm
1670 before other stack parms, preallocate stack space instead.
1671
1672 If the size of some parm is not a multiple of the required stack
1673 alignment, we must preallocate.
1674
1675 If the total size of arguments that would otherwise create a copy in
1676 a temporary (such as a CALL) is more than half the total argument list
1677 size, preallocation is faster.
1678
1679 Another reason to preallocate is if we have a machine (like the m88k)
1680 where stack alignment is required to be maintained between every
1681 pair of insns, not just when the call is made. However, we assume here
1682 that such machines either do not have push insns (and hence preallocation
1683 would occur anyway) or the problem is taken care of with
1684 PUSH_ROUNDING. */
1685
1686 if (! must_preallocate)
1687 {
1688 int partial_seen = 0;
1689 int copy_to_evaluate_size = 0;
1690 int i;
1691
1692 for (i = 0; i < num_actuals && ! must_preallocate; i++)
1693 {
1694 if (args[i].partial > 0 && ! args[i].pass_on_stack)
1695 partial_seen = 1;
1696 else if (partial_seen && args[i].reg == 0)
1697 must_preallocate = 1;
1698 /* We preallocate in case there are bounds passed
1699 in the bounds table to have precomputed address
1700 for bounds association. */
1701 else if (POINTER_BOUNDS_P (args[i].tree_value)
1702 && !args[i].reg)
1703 must_preallocate = 1;
1704
1705 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
1706 && (TREE_CODE (args[i].tree_value) == CALL_EXPR
1707 || TREE_CODE (args[i].tree_value) == TARGET_EXPR
1708 || TREE_CODE (args[i].tree_value) == COND_EXPR
1709 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))))
1710 copy_to_evaluate_size
1711 += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
1712 }
1713
1714 if (copy_to_evaluate_size * 2 >= args_size->constant
1715 && args_size->constant > 0)
1716 must_preallocate = 1;
1717 }
1718 return must_preallocate;
1719 }
1720
1721 /* If we preallocated stack space, compute the address of each argument
1722 and store it into the ARGS array.
1723
1724 We need not ensure it is a valid memory address here; it will be
1725 validized when it is used.
1726
1727 ARGBLOCK is an rtx for the address of the outgoing arguments. */
1728
1729 static void
1730 compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals)
1731 {
1732 if (argblock)
1733 {
1734 rtx arg_reg = argblock;
1735 int i, arg_offset = 0;
1736
1737 if (GET_CODE (argblock) == PLUS)
1738 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
1739
1740 for (i = 0; i < num_actuals; i++)
1741 {
1742 rtx offset = ARGS_SIZE_RTX (args[i].locate.offset);
1743 rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
1744 rtx addr;
1745 unsigned int align, boundary;
1746 unsigned int units_on_stack = 0;
1747 machine_mode partial_mode = VOIDmode;
1748
1749 /* Skip this parm if it will not be passed on the stack. */
1750 if (! args[i].pass_on_stack
1751 && args[i].reg != 0
1752 && args[i].partial == 0)
1753 continue;
1754
1755 /* Pointer Bounds are never passed on the stack. */
1756 if (POINTER_BOUNDS_P (args[i].tree_value))
1757 continue;
1758
1759 if (CONST_INT_P (offset))
1760 addr = plus_constant (Pmode, arg_reg, INTVAL (offset));
1761 else
1762 addr = gen_rtx_PLUS (Pmode, arg_reg, offset);
1763
1764 addr = plus_constant (Pmode, addr, arg_offset);
1765
1766 if (args[i].partial != 0)
1767 {
1768 /* Only part of the parameter is being passed on the stack.
1769 Generate a simple memory reference of the correct size. */
1770 units_on_stack = args[i].locate.size.constant;
1771 partial_mode = mode_for_size (units_on_stack * BITS_PER_UNIT,
1772 MODE_INT, 1);
1773 args[i].stack = gen_rtx_MEM (partial_mode, addr);
1774 set_mem_size (args[i].stack, units_on_stack);
1775 }
1776 else
1777 {
1778 args[i].stack = gen_rtx_MEM (args[i].mode, addr);
1779 set_mem_attributes (args[i].stack,
1780 TREE_TYPE (args[i].tree_value), 1);
1781 }
1782 align = BITS_PER_UNIT;
1783 boundary = args[i].locate.boundary;
1784 if (args[i].locate.where_pad != downward)
1785 align = boundary;
1786 else if (CONST_INT_P (offset))
1787 {
1788 align = INTVAL (offset) * BITS_PER_UNIT | boundary;
1789 align = align & -align;
1790 }
1791 set_mem_align (args[i].stack, align);
1792
1793 if (CONST_INT_P (slot_offset))
1794 addr = plus_constant (Pmode, arg_reg, INTVAL (slot_offset));
1795 else
1796 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset);
1797
1798 addr = plus_constant (Pmode, addr, arg_offset);
1799
1800 if (args[i].partial != 0)
1801 {
1802 /* Only part of the parameter is being passed on the stack.
1803 Generate a simple memory reference of the correct size.
1804 */
1805 args[i].stack_slot = gen_rtx_MEM (partial_mode, addr);
1806 set_mem_size (args[i].stack_slot, units_on_stack);
1807 }
1808 else
1809 {
1810 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr);
1811 set_mem_attributes (args[i].stack_slot,
1812 TREE_TYPE (args[i].tree_value), 1);
1813 }
1814 set_mem_align (args[i].stack_slot, args[i].locate.boundary);
1815
1816 /* Function incoming arguments may overlap with sibling call
1817 outgoing arguments and we cannot allow reordering of reads
1818 from function arguments with stores to outgoing arguments
1819 of sibling calls. */
1820 set_mem_alias_set (args[i].stack, 0);
1821 set_mem_alias_set (args[i].stack_slot, 0);
1822 }
1823 }
1824 }
1825
1826 /* Given a FNDECL and EXP, return an rtx suitable for use as a target address
1827 in a call instruction.
1828
1829 FNDECL is the tree node for the target function. For an indirect call
1830 FNDECL will be NULL_TREE.
1831
1832 ADDR is the operand 0 of CALL_EXPR for this call. */
1833
1834 static rtx
1835 rtx_for_function_call (tree fndecl, tree addr)
1836 {
1837 rtx funexp;
1838
1839 /* Get the function to call, in the form of RTL. */
1840 if (fndecl)
1841 {
1842 if (!TREE_USED (fndecl) && fndecl != current_function_decl)
1843 TREE_USED (fndecl) = 1;
1844
1845 /* Get a SYMBOL_REF rtx for the function address. */
1846 funexp = XEXP (DECL_RTL (fndecl), 0);
1847 }
1848 else
1849 /* Generate an rtx (probably a pseudo-register) for the address. */
1850 {
1851 push_temp_slots ();
1852 funexp = expand_normal (addr);
1853 pop_temp_slots (); /* FUNEXP can't be BLKmode. */
1854 }
1855 return funexp;
1856 }
1857
1858 /* Internal state for internal_arg_pointer_based_exp and its helpers. */
1859 static struct
1860 {
1861 /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan,
1862 or NULL_RTX if none has been scanned yet. */
1863 rtx_insn *scan_start;
1864 /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is
1865 based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the
1866 pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it
1867 with fixed offset, or PC if this is with variable or unknown offset. */
1868 vec<rtx> cache;
1869 } internal_arg_pointer_exp_state;
1870
1871 static rtx internal_arg_pointer_based_exp (const_rtx, bool);
1872
1873 /* Helper function for internal_arg_pointer_based_exp. Scan insns in
1874 the tail call sequence, starting with first insn that hasn't been
1875 scanned yet, and note for each pseudo on the LHS whether it is based
1876 on crtl->args.internal_arg_pointer or not, and what offset from that
1877 that pointer it has. */
1878
1879 static void
1880 internal_arg_pointer_based_exp_scan (void)
1881 {
1882 rtx_insn *insn, *scan_start = internal_arg_pointer_exp_state.scan_start;
1883
1884 if (scan_start == NULL_RTX)
1885 insn = get_insns ();
1886 else
1887 insn = NEXT_INSN (scan_start);
1888
1889 while (insn)
1890 {
1891 rtx set = single_set (insn);
1892 if (set && REG_P (SET_DEST (set)) && !HARD_REGISTER_P (SET_DEST (set)))
1893 {
1894 rtx val = NULL_RTX;
1895 unsigned int idx = REGNO (SET_DEST (set)) - FIRST_PSEUDO_REGISTER;
1896 /* Punt on pseudos set multiple times. */
1897 if (idx < internal_arg_pointer_exp_state.cache.length ()
1898 && (internal_arg_pointer_exp_state.cache[idx]
1899 != NULL_RTX))
1900 val = pc_rtx;
1901 else
1902 val = internal_arg_pointer_based_exp (SET_SRC (set), false);
1903 if (val != NULL_RTX)
1904 {
1905 if (idx >= internal_arg_pointer_exp_state.cache.length ())
1906 internal_arg_pointer_exp_state.cache
1907 .safe_grow_cleared (idx + 1);
1908 internal_arg_pointer_exp_state.cache[idx] = val;
1909 }
1910 }
1911 if (NEXT_INSN (insn) == NULL_RTX)
1912 scan_start = insn;
1913 insn = NEXT_INSN (insn);
1914 }
1915
1916 internal_arg_pointer_exp_state.scan_start = scan_start;
1917 }
1918
1919 /* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return
1920 NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on
1921 it with fixed offset, or PC if this is with variable or unknown offset.
1922 TOPLEVEL is true if the function is invoked at the topmost level. */
1923
1924 static rtx
1925 internal_arg_pointer_based_exp (const_rtx rtl, bool toplevel)
1926 {
1927 if (CONSTANT_P (rtl))
1928 return NULL_RTX;
1929
1930 if (rtl == crtl->args.internal_arg_pointer)
1931 return const0_rtx;
1932
1933 if (REG_P (rtl) && HARD_REGISTER_P (rtl))
1934 return NULL_RTX;
1935
1936 if (GET_CODE (rtl) == PLUS && CONST_INT_P (XEXP (rtl, 1)))
1937 {
1938 rtx val = internal_arg_pointer_based_exp (XEXP (rtl, 0), toplevel);
1939 if (val == NULL_RTX || val == pc_rtx)
1940 return val;
1941 return plus_constant (Pmode, val, INTVAL (XEXP (rtl, 1)));
1942 }
1943
1944 /* When called at the topmost level, scan pseudo assignments in between the
1945 last scanned instruction in the tail call sequence and the latest insn
1946 in that sequence. */
1947 if (toplevel)
1948 internal_arg_pointer_based_exp_scan ();
1949
1950 if (REG_P (rtl))
1951 {
1952 unsigned int idx = REGNO (rtl) - FIRST_PSEUDO_REGISTER;
1953 if (idx < internal_arg_pointer_exp_state.cache.length ())
1954 return internal_arg_pointer_exp_state.cache[idx];
1955
1956 return NULL_RTX;
1957 }
1958
1959 subrtx_iterator::array_type array;
1960 FOR_EACH_SUBRTX (iter, array, rtl, NONCONST)
1961 {
1962 const_rtx x = *iter;
1963 if (REG_P (x) && internal_arg_pointer_based_exp (x, false) != NULL_RTX)
1964 return pc_rtx;
1965 if (MEM_P (x))
1966 iter.skip_subrtxes ();
1967 }
1968
1969 return NULL_RTX;
1970 }
1971
1972 /* Return true if and only if SIZE storage units (usually bytes)
1973 starting from address ADDR overlap with already clobbered argument
1974 area. This function is used to determine if we should give up a
1975 sibcall. */
1976
1977 static bool
1978 mem_overlaps_already_clobbered_arg_p (rtx addr, unsigned HOST_WIDE_INT size)
1979 {
1980 HOST_WIDE_INT i;
1981 rtx val;
1982
1983 if (bitmap_empty_p (stored_args_map))
1984 return false;
1985 val = internal_arg_pointer_based_exp (addr, true);
1986 if (val == NULL_RTX)
1987 return false;
1988 else if (val == pc_rtx)
1989 return true;
1990 else
1991 i = INTVAL (val);
1992
1993 if (STACK_GROWS_DOWNWARD)
1994 i -= crtl->args.pretend_args_size;
1995 else
1996 i += crtl->args.pretend_args_size;
1997
1998
1999 if (ARGS_GROW_DOWNWARD)
2000 i = -i - size;
2001
2002 if (size > 0)
2003 {
2004 unsigned HOST_WIDE_INT k;
2005
2006 for (k = 0; k < size; k++)
2007 if (i + k < SBITMAP_SIZE (stored_args_map)
2008 && bitmap_bit_p (stored_args_map, i + k))
2009 return true;
2010 }
2011
2012 return false;
2013 }
2014
2015 /* Do the register loads required for any wholly-register parms or any
2016 parms which are passed both on the stack and in a register. Their
2017 expressions were already evaluated.
2018
2019 Mark all register-parms as living through the call, putting these USE
2020 insns in the CALL_INSN_FUNCTION_USAGE field.
2021
2022 When IS_SIBCALL, perform the check_sibcall_argument_overlap
2023 checking, setting *SIBCALL_FAILURE if appropriate. */
2024
2025 static void
2026 load_register_parameters (struct arg_data *args, int num_actuals,
2027 rtx *call_fusage, int flags, int is_sibcall,
2028 int *sibcall_failure)
2029 {
2030 int i, j;
2031
2032 for (i = 0; i < num_actuals; i++)
2033 {
2034 rtx reg = ((flags & ECF_SIBCALL)
2035 ? args[i].tail_call_reg : args[i].reg);
2036 if (reg)
2037 {
2038 int partial = args[i].partial;
2039 int nregs;
2040 int size = 0;
2041 rtx_insn *before_arg = get_last_insn ();
2042 /* Set non-negative if we must move a word at a time, even if
2043 just one word (e.g, partial == 4 && mode == DFmode). Set
2044 to -1 if we just use a normal move insn. This value can be
2045 zero if the argument is a zero size structure. */
2046 nregs = -1;
2047 if (GET_CODE (reg) == PARALLEL)
2048 ;
2049 else if (partial)
2050 {
2051 gcc_assert (partial % UNITS_PER_WORD == 0);
2052 nregs = partial / UNITS_PER_WORD;
2053 }
2054 else if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode)
2055 {
2056 size = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
2057 nregs = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
2058 }
2059 else
2060 size = GET_MODE_SIZE (args[i].mode);
2061
2062 /* Handle calls that pass values in multiple non-contiguous
2063 locations. The Irix 6 ABI has examples of this. */
2064
2065 if (GET_CODE (reg) == PARALLEL)
2066 emit_group_move (reg, args[i].parallel_value);
2067
2068 /* If simple case, just do move. If normal partial, store_one_arg
2069 has already loaded the register for us. In all other cases,
2070 load the register(s) from memory. */
2071
2072 else if (nregs == -1)
2073 {
2074 emit_move_insn (reg, args[i].value);
2075 #ifdef BLOCK_REG_PADDING
2076 /* Handle case where we have a value that needs shifting
2077 up to the msb. eg. a QImode value and we're padding
2078 upward on a BYTES_BIG_ENDIAN machine. */
2079 if (size < UNITS_PER_WORD
2080 && (args[i].locate.where_pad
2081 == (BYTES_BIG_ENDIAN ? upward : downward)))
2082 {
2083 rtx x;
2084 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
2085
2086 /* Assigning REG here rather than a temp makes CALL_FUSAGE
2087 report the whole reg as used. Strictly speaking, the
2088 call only uses SIZE bytes at the msb end, but it doesn't
2089 seem worth generating rtl to say that. */
2090 reg = gen_rtx_REG (word_mode, REGNO (reg));
2091 x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1);
2092 if (x != reg)
2093 emit_move_insn (reg, x);
2094 }
2095 #endif
2096 }
2097
2098 /* If we have pre-computed the values to put in the registers in
2099 the case of non-aligned structures, copy them in now. */
2100
2101 else if (args[i].n_aligned_regs != 0)
2102 for (j = 0; j < args[i].n_aligned_regs; j++)
2103 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j),
2104 args[i].aligned_regs[j]);
2105
2106 else if (partial == 0 || args[i].pass_on_stack)
2107 {
2108 rtx mem = validize_mem (copy_rtx (args[i].value));
2109
2110 /* Check for overlap with already clobbered argument area,
2111 providing that this has non-zero size. */
2112 if (is_sibcall
2113 && (size == 0
2114 || mem_overlaps_already_clobbered_arg_p
2115 (XEXP (args[i].value, 0), size)))
2116 *sibcall_failure = 1;
2117
2118 if (size % UNITS_PER_WORD == 0
2119 || MEM_ALIGN (mem) % BITS_PER_WORD == 0)
2120 move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode);
2121 else
2122 {
2123 if (nregs > 1)
2124 move_block_to_reg (REGNO (reg), mem, nregs - 1,
2125 args[i].mode);
2126 rtx dest = gen_rtx_REG (word_mode, REGNO (reg) + nregs - 1);
2127 unsigned int bitoff = (nregs - 1) * BITS_PER_WORD;
2128 unsigned int bitsize = size * BITS_PER_UNIT - bitoff;
2129 rtx x = extract_bit_field (mem, bitsize, bitoff, 1,
2130 dest, word_mode, word_mode);
2131 if (BYTES_BIG_ENDIAN)
2132 x = expand_shift (LSHIFT_EXPR, word_mode, x,
2133 BITS_PER_WORD - bitsize, dest, 1);
2134 if (x != dest)
2135 emit_move_insn (dest, x);
2136 }
2137
2138 /* Handle a BLKmode that needs shifting. */
2139 if (nregs == 1 && size < UNITS_PER_WORD
2140 #ifdef BLOCK_REG_PADDING
2141 && args[i].locate.where_pad == downward
2142 #else
2143 && BYTES_BIG_ENDIAN
2144 #endif
2145 )
2146 {
2147 rtx dest = gen_rtx_REG (word_mode, REGNO (reg));
2148 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
2149 enum tree_code dir = (BYTES_BIG_ENDIAN
2150 ? RSHIFT_EXPR : LSHIFT_EXPR);
2151 rtx x;
2152
2153 x = expand_shift (dir, word_mode, dest, shift, dest, 1);
2154 if (x != dest)
2155 emit_move_insn (dest, x);
2156 }
2157 }
2158
2159 /* When a parameter is a block, and perhaps in other cases, it is
2160 possible that it did a load from an argument slot that was
2161 already clobbered. */
2162 if (is_sibcall
2163 && check_sibcall_argument_overlap (before_arg, &args[i], 0))
2164 *sibcall_failure = 1;
2165
2166 /* Handle calls that pass values in multiple non-contiguous
2167 locations. The Irix 6 ABI has examples of this. */
2168 if (GET_CODE (reg) == PARALLEL)
2169 use_group_regs (call_fusage, reg);
2170 else if (nregs == -1)
2171 use_reg_mode (call_fusage, reg,
2172 TYPE_MODE (TREE_TYPE (args[i].tree_value)));
2173 else if (nregs > 0)
2174 use_regs (call_fusage, REGNO (reg), nregs);
2175 }
2176 }
2177 }
2178
2179 /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments
2180 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
2181 bytes, then we would need to push some additional bytes to pad the
2182 arguments. So, we compute an adjust to the stack pointer for an
2183 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
2184 bytes. Then, when the arguments are pushed the stack will be perfectly
2185 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should
2186 be popped after the call. Returns the adjustment. */
2187
2188 static int
2189 combine_pending_stack_adjustment_and_call (int unadjusted_args_size,
2190 struct args_size *args_size,
2191 unsigned int preferred_unit_stack_boundary)
2192 {
2193 /* The number of bytes to pop so that the stack will be
2194 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */
2195 HOST_WIDE_INT adjustment;
2196 /* The alignment of the stack after the arguments are pushed, if we
2197 just pushed the arguments without adjust the stack here. */
2198 unsigned HOST_WIDE_INT unadjusted_alignment;
2199
2200 unadjusted_alignment
2201 = ((stack_pointer_delta + unadjusted_args_size)
2202 % preferred_unit_stack_boundary);
2203
2204 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
2205 as possible -- leaving just enough left to cancel out the
2206 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the
2207 PENDING_STACK_ADJUST is non-negative, and congruent to
2208 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */
2209
2210 /* Begin by trying to pop all the bytes. */
2211 unadjusted_alignment
2212 = (unadjusted_alignment
2213 - (pending_stack_adjust % preferred_unit_stack_boundary));
2214 adjustment = pending_stack_adjust;
2215 /* Push enough additional bytes that the stack will be aligned
2216 after the arguments are pushed. */
2217 if (preferred_unit_stack_boundary > 1)
2218 {
2219 if (unadjusted_alignment > 0)
2220 adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
2221 else
2222 adjustment += unadjusted_alignment;
2223 }
2224
2225 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
2226 bytes after the call. The right number is the entire
2227 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
2228 by the arguments in the first place. */
2229 args_size->constant
2230 = pending_stack_adjust - adjustment + unadjusted_args_size;
2231
2232 return adjustment;
2233 }
2234
2235 /* Scan X expression if it does not dereference any argument slots
2236 we already clobbered by tail call arguments (as noted in stored_args_map
2237 bitmap).
2238 Return nonzero if X expression dereferences such argument slots,
2239 zero otherwise. */
2240
2241 static int
2242 check_sibcall_argument_overlap_1 (rtx x)
2243 {
2244 RTX_CODE code;
2245 int i, j;
2246 const char *fmt;
2247
2248 if (x == NULL_RTX)
2249 return 0;
2250
2251 code = GET_CODE (x);
2252
2253 /* We need not check the operands of the CALL expression itself. */
2254 if (code == CALL)
2255 return 0;
2256
2257 if (code == MEM)
2258 return mem_overlaps_already_clobbered_arg_p (XEXP (x, 0),
2259 GET_MODE_SIZE (GET_MODE (x)));
2260
2261 /* Scan all subexpressions. */
2262 fmt = GET_RTX_FORMAT (code);
2263 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2264 {
2265 if (*fmt == 'e')
2266 {
2267 if (check_sibcall_argument_overlap_1 (XEXP (x, i)))
2268 return 1;
2269 }
2270 else if (*fmt == 'E')
2271 {
2272 for (j = 0; j < XVECLEN (x, i); j++)
2273 if (check_sibcall_argument_overlap_1 (XVECEXP (x, i, j)))
2274 return 1;
2275 }
2276 }
2277 return 0;
2278 }
2279
2280 /* Scan sequence after INSN if it does not dereference any argument slots
2281 we already clobbered by tail call arguments (as noted in stored_args_map
2282 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to
2283 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP
2284 should be 0). Return nonzero if sequence after INSN dereferences such argument
2285 slots, zero otherwise. */
2286
2287 static int
2288 check_sibcall_argument_overlap (rtx_insn *insn, struct arg_data *arg,
2289 int mark_stored_args_map)
2290 {
2291 int low, high;
2292
2293 if (insn == NULL_RTX)
2294 insn = get_insns ();
2295 else
2296 insn = NEXT_INSN (insn);
2297
2298 for (; insn; insn = NEXT_INSN (insn))
2299 if (INSN_P (insn)
2300 && check_sibcall_argument_overlap_1 (PATTERN (insn)))
2301 break;
2302
2303 if (mark_stored_args_map)
2304 {
2305 if (ARGS_GROW_DOWNWARD)
2306 low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
2307 else
2308 low = arg->locate.slot_offset.constant;
2309
2310 for (high = low + arg->locate.size.constant; low < high; low++)
2311 bitmap_set_bit (stored_args_map, low);
2312 }
2313 return insn != NULL_RTX;
2314 }
2315
2316 /* Given that a function returns a value of mode MODE at the most
2317 significant end of hard register VALUE, shift VALUE left or right
2318 as specified by LEFT_P. Return true if some action was needed. */
2319
2320 bool
2321 shift_return_value (machine_mode mode, bool left_p, rtx value)
2322 {
2323 HOST_WIDE_INT shift;
2324
2325 gcc_assert (REG_P (value) && HARD_REGISTER_P (value));
2326 shift = GET_MODE_BITSIZE (GET_MODE (value)) - GET_MODE_BITSIZE (mode);
2327 if (shift == 0)
2328 return false;
2329
2330 /* Use ashr rather than lshr for right shifts. This is for the benefit
2331 of the MIPS port, which requires SImode values to be sign-extended
2332 when stored in 64-bit registers. */
2333 if (!force_expand_binop (GET_MODE (value), left_p ? ashl_optab : ashr_optab,
2334 value, GEN_INT (shift), value, 1, OPTAB_WIDEN))
2335 gcc_unreachable ();
2336 return true;
2337 }
2338
2339 /* If X is a likely-spilled register value, copy it to a pseudo
2340 register and return that register. Return X otherwise. */
2341
2342 static rtx
2343 avoid_likely_spilled_reg (rtx x)
2344 {
2345 rtx new_rtx;
2346
2347 if (REG_P (x)
2348 && HARD_REGISTER_P (x)
2349 && targetm.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x))))
2350 {
2351 /* Make sure that we generate a REG rather than a CONCAT.
2352 Moves into CONCATs can need nontrivial instructions,
2353 and the whole point of this function is to avoid
2354 using the hard register directly in such a situation. */
2355 generating_concat_p = 0;
2356 new_rtx = gen_reg_rtx (GET_MODE (x));
2357 generating_concat_p = 1;
2358 emit_move_insn (new_rtx, x);
2359 return new_rtx;
2360 }
2361 return x;
2362 }
2363
2364 /* Generate all the code for a CALL_EXPR exp
2365 and return an rtx for its value.
2366 Store the value in TARGET (specified as an rtx) if convenient.
2367 If the value is stored in TARGET then TARGET is returned.
2368 If IGNORE is nonzero, then we ignore the value of the function call. */
2369
2370 rtx
2371 expand_call (tree exp, rtx target, int ignore)
2372 {
2373 /* Nonzero if we are currently expanding a call. */
2374 static int currently_expanding_call = 0;
2375
2376 /* RTX for the function to be called. */
2377 rtx funexp;
2378 /* Sequence of insns to perform a normal "call". */
2379 rtx_insn *normal_call_insns = NULL;
2380 /* Sequence of insns to perform a tail "call". */
2381 rtx_insn *tail_call_insns = NULL;
2382 /* Data type of the function. */
2383 tree funtype;
2384 tree type_arg_types;
2385 tree rettype;
2386 /* Declaration of the function being called,
2387 or 0 if the function is computed (not known by name). */
2388 tree fndecl = 0;
2389 /* The type of the function being called. */
2390 tree fntype;
2391 bool try_tail_call = CALL_EXPR_TAILCALL (exp);
2392 int pass;
2393
2394 /* Register in which non-BLKmode value will be returned,
2395 or 0 if no value or if value is BLKmode. */
2396 rtx valreg;
2397 /* Register(s) in which bounds are returned. */
2398 rtx valbnd = NULL;
2399 /* Address where we should return a BLKmode value;
2400 0 if value not BLKmode. */
2401 rtx structure_value_addr = 0;
2402 /* Nonzero if that address is being passed by treating it as
2403 an extra, implicit first parameter. Otherwise,
2404 it is passed by being copied directly into struct_value_rtx. */
2405 int structure_value_addr_parm = 0;
2406 /* Holds the value of implicit argument for the struct value. */
2407 tree structure_value_addr_value = NULL_TREE;
2408 /* Size of aggregate value wanted, or zero if none wanted
2409 or if we are using the non-reentrant PCC calling convention
2410 or expecting the value in registers. */
2411 HOST_WIDE_INT struct_value_size = 0;
2412 /* Nonzero if called function returns an aggregate in memory PCC style,
2413 by returning the address of where to find it. */
2414 int pcc_struct_value = 0;
2415 rtx struct_value = 0;
2416
2417 /* Number of actual parameters in this call, including struct value addr. */
2418 int num_actuals;
2419 /* Number of named args. Args after this are anonymous ones
2420 and they must all go on the stack. */
2421 int n_named_args;
2422 /* Number of complex actual arguments that need to be split. */
2423 int num_complex_actuals = 0;
2424
2425 /* Vector of information about each argument.
2426 Arguments are numbered in the order they will be pushed,
2427 not the order they are written. */
2428 struct arg_data *args;
2429
2430 /* Total size in bytes of all the stack-parms scanned so far. */
2431 struct args_size args_size;
2432 struct args_size adjusted_args_size;
2433 /* Size of arguments before any adjustments (such as rounding). */
2434 int unadjusted_args_size;
2435 /* Data on reg parms scanned so far. */
2436 CUMULATIVE_ARGS args_so_far_v;
2437 cumulative_args_t args_so_far;
2438 /* Nonzero if a reg parm has been scanned. */
2439 int reg_parm_seen;
2440 /* Nonzero if this is an indirect function call. */
2441
2442 /* Nonzero if we must avoid push-insns in the args for this call.
2443 If stack space is allocated for register parameters, but not by the
2444 caller, then it is preallocated in the fixed part of the stack frame.
2445 So the entire argument block must then be preallocated (i.e., we
2446 ignore PUSH_ROUNDING in that case). */
2447
2448 int must_preallocate = !PUSH_ARGS;
2449
2450 /* Size of the stack reserved for parameter registers. */
2451 int reg_parm_stack_space = 0;
2452
2453 /* Address of space preallocated for stack parms
2454 (on machines that lack push insns), or 0 if space not preallocated. */
2455 rtx argblock = 0;
2456
2457 /* Mask of ECF_ and ERF_ flags. */
2458 int flags = 0;
2459 int return_flags = 0;
2460 #ifdef REG_PARM_STACK_SPACE
2461 /* Define the boundary of the register parm stack space that needs to be
2462 saved, if any. */
2463 int low_to_save, high_to_save;
2464 rtx save_area = 0; /* Place that it is saved */
2465 #endif
2466
2467 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
2468 char *initial_stack_usage_map = stack_usage_map;
2469 char *stack_usage_map_buf = NULL;
2470
2471 int old_stack_allocated;
2472
2473 /* State variables to track stack modifications. */
2474 rtx old_stack_level = 0;
2475 int old_stack_arg_under_construction = 0;
2476 int old_pending_adj = 0;
2477 int old_inhibit_defer_pop = inhibit_defer_pop;
2478
2479 /* Some stack pointer alterations we make are performed via
2480 allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
2481 which we then also need to save/restore along the way. */
2482 int old_stack_pointer_delta = 0;
2483
2484 rtx call_fusage;
2485 tree addr = CALL_EXPR_FN (exp);
2486 int i;
2487 /* The alignment of the stack, in bits. */
2488 unsigned HOST_WIDE_INT preferred_stack_boundary;
2489 /* The alignment of the stack, in bytes. */
2490 unsigned HOST_WIDE_INT preferred_unit_stack_boundary;
2491 /* The static chain value to use for this call. */
2492 rtx static_chain_value;
2493 /* See if this is "nothrow" function call. */
2494 if (TREE_NOTHROW (exp))
2495 flags |= ECF_NOTHROW;
2496
2497 /* See if we can find a DECL-node for the actual function, and get the
2498 function attributes (flags) from the function decl or type node. */
2499 fndecl = get_callee_fndecl (exp);
2500 if (fndecl)
2501 {
2502 fntype = TREE_TYPE (fndecl);
2503 flags |= flags_from_decl_or_type (fndecl);
2504 return_flags |= decl_return_flags (fndecl);
2505 }
2506 else
2507 {
2508 fntype = TREE_TYPE (TREE_TYPE (addr));
2509 flags |= flags_from_decl_or_type (fntype);
2510 }
2511 rettype = TREE_TYPE (exp);
2512
2513 struct_value = targetm.calls.struct_value_rtx (fntype, 0);
2514
2515 /* Warn if this value is an aggregate type,
2516 regardless of which calling convention we are using for it. */
2517 if (AGGREGATE_TYPE_P (rettype))
2518 warning (OPT_Waggregate_return, "function call has aggregate value");
2519
2520 /* If the result of a non looping pure or const function call is
2521 ignored (or void), and none of its arguments are volatile, we can
2522 avoid expanding the call and just evaluate the arguments for
2523 side-effects. */
2524 if ((flags & (ECF_CONST | ECF_PURE))
2525 && (!(flags & ECF_LOOPING_CONST_OR_PURE))
2526 && (ignore || target == const0_rtx
2527 || TYPE_MODE (rettype) == VOIDmode))
2528 {
2529 bool volatilep = false;
2530 tree arg;
2531 call_expr_arg_iterator iter;
2532
2533 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2534 if (TREE_THIS_VOLATILE (arg))
2535 {
2536 volatilep = true;
2537 break;
2538 }
2539
2540 if (! volatilep)
2541 {
2542 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2543 expand_expr (arg, const0_rtx, VOIDmode, EXPAND_NORMAL);
2544 return const0_rtx;
2545 }
2546 }
2547
2548 #ifdef REG_PARM_STACK_SPACE
2549 reg_parm_stack_space = REG_PARM_STACK_SPACE (!fndecl ? fntype : fndecl);
2550 #endif
2551
2552 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
2553 && reg_parm_stack_space > 0 && PUSH_ARGS)
2554 must_preallocate = 1;
2555
2556 /* Set up a place to return a structure. */
2557
2558 /* Cater to broken compilers. */
2559 if (aggregate_value_p (exp, fntype))
2560 {
2561 /* This call returns a big structure. */
2562 flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
2563
2564 #ifdef PCC_STATIC_STRUCT_RETURN
2565 {
2566 pcc_struct_value = 1;
2567 }
2568 #else /* not PCC_STATIC_STRUCT_RETURN */
2569 {
2570 struct_value_size = int_size_in_bytes (rettype);
2571
2572 /* Even if it is semantically safe to use the target as the return
2573 slot, it may be not sufficiently aligned for the return type. */
2574 if (CALL_EXPR_RETURN_SLOT_OPT (exp)
2575 && target
2576 && MEM_P (target)
2577 && !(MEM_ALIGN (target) < TYPE_ALIGN (rettype)
2578 && SLOW_UNALIGNED_ACCESS (TYPE_MODE (rettype),
2579 MEM_ALIGN (target))))
2580 structure_value_addr = XEXP (target, 0);
2581 else
2582 {
2583 /* For variable-sized objects, we must be called with a target
2584 specified. If we were to allocate space on the stack here,
2585 we would have no way of knowing when to free it. */
2586 rtx d = assign_temp (rettype, 1, 1);
2587 structure_value_addr = XEXP (d, 0);
2588 target = 0;
2589 }
2590 }
2591 #endif /* not PCC_STATIC_STRUCT_RETURN */
2592 }
2593
2594 /* Figure out the amount to which the stack should be aligned. */
2595 preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
2596 if (fndecl)
2597 {
2598 struct cgraph_rtl_info *i = cgraph_node::rtl_info (fndecl);
2599 /* Without automatic stack alignment, we can't increase preferred
2600 stack boundary. With automatic stack alignment, it is
2601 unnecessary since unless we can guarantee that all callers will
2602 align the outgoing stack properly, callee has to align its
2603 stack anyway. */
2604 if (i
2605 && i->preferred_incoming_stack_boundary
2606 && i->preferred_incoming_stack_boundary < preferred_stack_boundary)
2607 preferred_stack_boundary = i->preferred_incoming_stack_boundary;
2608 }
2609
2610 /* Operand 0 is a pointer-to-function; get the type of the function. */
2611 funtype = TREE_TYPE (addr);
2612 gcc_assert (POINTER_TYPE_P (funtype));
2613 funtype = TREE_TYPE (funtype);
2614
2615 /* Count whether there are actual complex arguments that need to be split
2616 into their real and imaginary parts. Munge the type_arg_types
2617 appropriately here as well. */
2618 if (targetm.calls.split_complex_arg)
2619 {
2620 call_expr_arg_iterator iter;
2621 tree arg;
2622 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
2623 {
2624 tree type = TREE_TYPE (arg);
2625 if (type && TREE_CODE (type) == COMPLEX_TYPE
2626 && targetm.calls.split_complex_arg (type))
2627 num_complex_actuals++;
2628 }
2629 type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype));
2630 }
2631 else
2632 type_arg_types = TYPE_ARG_TYPES (funtype);
2633
2634 if (flags & ECF_MAY_BE_ALLOCA)
2635 cfun->calls_alloca = 1;
2636
2637 /* If struct_value_rtx is 0, it means pass the address
2638 as if it were an extra parameter. Put the argument expression
2639 in structure_value_addr_value. */
2640 if (structure_value_addr && struct_value == 0)
2641 {
2642 /* If structure_value_addr is a REG other than
2643 virtual_outgoing_args_rtx, we can use always use it. If it
2644 is not a REG, we must always copy it into a register.
2645 If it is virtual_outgoing_args_rtx, we must copy it to another
2646 register in some cases. */
2647 rtx temp = (!REG_P (structure_value_addr)
2648 || (ACCUMULATE_OUTGOING_ARGS
2649 && stack_arg_under_construction
2650 && structure_value_addr == virtual_outgoing_args_rtx)
2651 ? copy_addr_to_reg (convert_memory_address
2652 (Pmode, structure_value_addr))
2653 : structure_value_addr);
2654
2655 structure_value_addr_value =
2656 make_tree (build_pointer_type (TREE_TYPE (funtype)), temp);
2657 structure_value_addr_parm = CALL_WITH_BOUNDS_P (exp) ? 2 : 1;
2658 }
2659
2660 /* Count the arguments and set NUM_ACTUALS. */
2661 num_actuals =
2662 call_expr_nargs (exp) + num_complex_actuals + structure_value_addr_parm;
2663
2664 /* Compute number of named args.
2665 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */
2666
2667 if (type_arg_types != 0)
2668 n_named_args
2669 = (list_length (type_arg_types)
2670 /* Count the struct value address, if it is passed as a parm. */
2671 + structure_value_addr_parm);
2672 else
2673 /* If we know nothing, treat all args as named. */
2674 n_named_args = num_actuals;
2675
2676 /* Start updating where the next arg would go.
2677
2678 On some machines (such as the PA) indirect calls have a different
2679 calling convention than normal calls. The fourth argument in
2680 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call
2681 or not. */
2682 INIT_CUMULATIVE_ARGS (args_so_far_v, funtype, NULL_RTX, fndecl, n_named_args);
2683 args_so_far = pack_cumulative_args (&args_so_far_v);
2684
2685 /* Now possibly adjust the number of named args.
2686 Normally, don't include the last named arg if anonymous args follow.
2687 We do include the last named arg if
2688 targetm.calls.strict_argument_naming() returns nonzero.
2689 (If no anonymous args follow, the result of list_length is actually
2690 one too large. This is harmless.)
2691
2692 If targetm.calls.pretend_outgoing_varargs_named() returns
2693 nonzero, and targetm.calls.strict_argument_naming() returns zero,
2694 this machine will be able to place unnamed args that were passed
2695 in registers into the stack. So treat all args as named. This
2696 allows the insns emitting for a specific argument list to be
2697 independent of the function declaration.
2698
2699 If targetm.calls.pretend_outgoing_varargs_named() returns zero,
2700 we do not have any reliable way to pass unnamed args in
2701 registers, so we must force them into memory. */
2702
2703 if (type_arg_types != 0
2704 && targetm.calls.strict_argument_naming (args_so_far))
2705 ;
2706 else if (type_arg_types != 0
2707 && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far))
2708 /* Don't include the last named arg. */
2709 --n_named_args;
2710 else
2711 /* Treat all args as named. */
2712 n_named_args = num_actuals;
2713
2714 /* Make a vector to hold all the information about each arg. */
2715 args = XALLOCAVEC (struct arg_data, num_actuals);
2716 memset (args, 0, num_actuals * sizeof (struct arg_data));
2717
2718 /* Build up entries in the ARGS array, compute the size of the
2719 arguments into ARGS_SIZE, etc. */
2720 initialize_argument_information (num_actuals, args, &args_size,
2721 n_named_args, exp,
2722 structure_value_addr_value, fndecl, fntype,
2723 args_so_far, reg_parm_stack_space,
2724 &old_stack_level, &old_pending_adj,
2725 &must_preallocate, &flags,
2726 &try_tail_call, CALL_FROM_THUNK_P (exp));
2727
2728 if (args_size.var)
2729 must_preallocate = 1;
2730
2731 /* Now make final decision about preallocating stack space. */
2732 must_preallocate = finalize_must_preallocate (must_preallocate,
2733 num_actuals, args,
2734 &args_size);
2735
2736 /* If the structure value address will reference the stack pointer, we
2737 must stabilize it. We don't need to do this if we know that we are
2738 not going to adjust the stack pointer in processing this call. */
2739
2740 if (structure_value_addr
2741 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr)
2742 || reg_mentioned_p (virtual_outgoing_args_rtx,
2743 structure_value_addr))
2744 && (args_size.var
2745 || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant)))
2746 structure_value_addr = copy_to_reg (structure_value_addr);
2747
2748 /* Tail calls can make things harder to debug, and we've traditionally
2749 pushed these optimizations into -O2. Don't try if we're already
2750 expanding a call, as that means we're an argument. Don't try if
2751 there's cleanups, as we know there's code to follow the call. */
2752
2753 if (currently_expanding_call++ != 0
2754 || !flag_optimize_sibling_calls
2755 || args_size.var
2756 || dbg_cnt (tail_call) == false)
2757 try_tail_call = 0;
2758
2759 /* Rest of purposes for tail call optimizations to fail. */
2760 if (
2761 #ifdef HAVE_sibcall_epilogue
2762 !HAVE_sibcall_epilogue
2763 #else
2764 1
2765 #endif
2766 || !try_tail_call
2767 /* Doing sibling call optimization needs some work, since
2768 structure_value_addr can be allocated on the stack.
2769 It does not seem worth the effort since few optimizable
2770 sibling calls will return a structure. */
2771 || structure_value_addr != NULL_RTX
2772 #ifdef REG_PARM_STACK_SPACE
2773 /* If outgoing reg parm stack space changes, we can not do sibcall. */
2774 || (OUTGOING_REG_PARM_STACK_SPACE (funtype)
2775 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl)))
2776 || (reg_parm_stack_space != REG_PARM_STACK_SPACE (current_function_decl))
2777 #endif
2778 /* Check whether the target is able to optimize the call
2779 into a sibcall. */
2780 || !targetm.function_ok_for_sibcall (fndecl, exp)
2781 /* Functions that do not return exactly once may not be sibcall
2782 optimized. */
2783 || (flags & (ECF_RETURNS_TWICE | ECF_NORETURN))
2784 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr)))
2785 /* If the called function is nested in the current one, it might access
2786 some of the caller's arguments, but could clobber them beforehand if
2787 the argument areas are shared. */
2788 || (fndecl && decl_function_context (fndecl) == current_function_decl)
2789 /* If this function requires more stack slots than the current
2790 function, we cannot change it into a sibling call.
2791 crtl->args.pretend_args_size is not part of the
2792 stack allocated by our caller. */
2793 || args_size.constant > (crtl->args.size
2794 - crtl->args.pretend_args_size)
2795 /* If the callee pops its own arguments, then it must pop exactly
2796 the same number of arguments as the current function. */
2797 || (targetm.calls.return_pops_args (fndecl, funtype, args_size.constant)
2798 != targetm.calls.return_pops_args (current_function_decl,
2799 TREE_TYPE (current_function_decl),
2800 crtl->args.size))
2801 || !lang_hooks.decls.ok_for_sibcall (fndecl))
2802 try_tail_call = 0;
2803
2804 /* Check if caller and callee disagree in promotion of function
2805 return value. */
2806 if (try_tail_call)
2807 {
2808 machine_mode caller_mode, caller_promoted_mode;
2809 machine_mode callee_mode, callee_promoted_mode;
2810 int caller_unsignedp, callee_unsignedp;
2811 tree caller_res = DECL_RESULT (current_function_decl);
2812
2813 caller_unsignedp = TYPE_UNSIGNED (TREE_TYPE (caller_res));
2814 caller_mode = DECL_MODE (caller_res);
2815 callee_unsignedp = TYPE_UNSIGNED (TREE_TYPE (funtype));
2816 callee_mode = TYPE_MODE (TREE_TYPE (funtype));
2817 caller_promoted_mode
2818 = promote_function_mode (TREE_TYPE (caller_res), caller_mode,
2819 &caller_unsignedp,
2820 TREE_TYPE (current_function_decl), 1);
2821 callee_promoted_mode
2822 = promote_function_mode (TREE_TYPE (funtype), callee_mode,
2823 &callee_unsignedp,
2824 funtype, 1);
2825 if (caller_mode != VOIDmode
2826 && (caller_promoted_mode != callee_promoted_mode
2827 || ((caller_mode != caller_promoted_mode
2828 || callee_mode != callee_promoted_mode)
2829 && (caller_unsignedp != callee_unsignedp
2830 || GET_MODE_BITSIZE (caller_mode)
2831 < GET_MODE_BITSIZE (callee_mode)))))
2832 try_tail_call = 0;
2833 }
2834
2835 /* Ensure current function's preferred stack boundary is at least
2836 what we need. Stack alignment may also increase preferred stack
2837 boundary. */
2838 if (crtl->preferred_stack_boundary < preferred_stack_boundary)
2839 crtl->preferred_stack_boundary = preferred_stack_boundary;
2840 else
2841 preferred_stack_boundary = crtl->preferred_stack_boundary;
2842
2843 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT;
2844
2845 /* We want to make two insn chains; one for a sibling call, the other
2846 for a normal call. We will select one of the two chains after
2847 initial RTL generation is complete. */
2848 for (pass = try_tail_call ? 0 : 1; pass < 2; pass++)
2849 {
2850 int sibcall_failure = 0;
2851 /* We want to emit any pending stack adjustments before the tail
2852 recursion "call". That way we know any adjustment after the tail
2853 recursion call can be ignored if we indeed use the tail
2854 call expansion. */
2855 saved_pending_stack_adjust save;
2856 rtx_insn *insns, *before_call, *after_args;
2857 rtx next_arg_reg;
2858
2859 if (pass == 0)
2860 {
2861 /* State variables we need to save and restore between
2862 iterations. */
2863 save_pending_stack_adjust (&save);
2864 }
2865 if (pass)
2866 flags &= ~ECF_SIBCALL;
2867 else
2868 flags |= ECF_SIBCALL;
2869
2870 /* Other state variables that we must reinitialize each time
2871 through the loop (that are not initialized by the loop itself). */
2872 argblock = 0;
2873 call_fusage = 0;
2874
2875 /* Start a new sequence for the normal call case.
2876
2877 From this point on, if the sibling call fails, we want to set
2878 sibcall_failure instead of continuing the loop. */
2879 start_sequence ();
2880
2881 /* Don't let pending stack adjusts add up to too much.
2882 Also, do all pending adjustments now if there is any chance
2883 this might be a call to alloca or if we are expanding a sibling
2884 call sequence.
2885 Also do the adjustments before a throwing call, otherwise
2886 exception handling can fail; PR 19225. */
2887 if (pending_stack_adjust >= 32
2888 || (pending_stack_adjust > 0
2889 && (flags & ECF_MAY_BE_ALLOCA))
2890 || (pending_stack_adjust > 0
2891 && flag_exceptions && !(flags & ECF_NOTHROW))
2892 || pass == 0)
2893 do_pending_stack_adjust ();
2894
2895 /* Precompute any arguments as needed. */
2896 if (pass)
2897 precompute_arguments (num_actuals, args);
2898
2899 /* Now we are about to start emitting insns that can be deleted
2900 if a libcall is deleted. */
2901 if (pass && (flags & ECF_MALLOC))
2902 start_sequence ();
2903
2904 if (pass == 0 && crtl->stack_protect_guard)
2905 stack_protect_epilogue ();
2906
2907 adjusted_args_size = args_size;
2908 /* Compute the actual size of the argument block required. The variable
2909 and constant sizes must be combined, the size may have to be rounded,
2910 and there may be a minimum required size. When generating a sibcall
2911 pattern, do not round up, since we'll be re-using whatever space our
2912 caller provided. */
2913 unadjusted_args_size
2914 = compute_argument_block_size (reg_parm_stack_space,
2915 &adjusted_args_size,
2916 fndecl, fntype,
2917 (pass == 0 ? 0
2918 : preferred_stack_boundary));
2919
2920 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
2921
2922 /* The argument block when performing a sibling call is the
2923 incoming argument block. */
2924 if (pass == 0)
2925 {
2926 argblock = crtl->args.internal_arg_pointer;
2927 if (STACK_GROWS_DOWNWARD)
2928 argblock
2929 = plus_constant (Pmode, argblock, crtl->args.pretend_args_size);
2930 else
2931 argblock
2932 = plus_constant (Pmode, argblock, -crtl->args.pretend_args_size);
2933
2934 stored_args_map = sbitmap_alloc (args_size.constant);
2935 bitmap_clear (stored_args_map);
2936 }
2937
2938 /* If we have no actual push instructions, or shouldn't use them,
2939 make space for all args right now. */
2940 else if (adjusted_args_size.var != 0)
2941 {
2942 if (old_stack_level == 0)
2943 {
2944 emit_stack_save (SAVE_BLOCK, &old_stack_level);
2945 old_stack_pointer_delta = stack_pointer_delta;
2946 old_pending_adj = pending_stack_adjust;
2947 pending_stack_adjust = 0;
2948 /* stack_arg_under_construction says whether a stack arg is
2949 being constructed at the old stack level. Pushing the stack
2950 gets a clean outgoing argument block. */
2951 old_stack_arg_under_construction = stack_arg_under_construction;
2952 stack_arg_under_construction = 0;
2953 }
2954 argblock = push_block (ARGS_SIZE_RTX (adjusted_args_size), 0, 0);
2955 if (flag_stack_usage_info)
2956 current_function_has_unbounded_dynamic_stack_size = 1;
2957 }
2958 else
2959 {
2960 /* Note that we must go through the motions of allocating an argument
2961 block even if the size is zero because we may be storing args
2962 in the area reserved for register arguments, which may be part of
2963 the stack frame. */
2964
2965 int needed = adjusted_args_size.constant;
2966
2967 /* Store the maximum argument space used. It will be pushed by
2968 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
2969 checking). */
2970
2971 if (needed > crtl->outgoing_args_size)
2972 crtl->outgoing_args_size = needed;
2973
2974 if (must_preallocate)
2975 {
2976 if (ACCUMULATE_OUTGOING_ARGS)
2977 {
2978 /* Since the stack pointer will never be pushed, it is
2979 possible for the evaluation of a parm to clobber
2980 something we have already written to the stack.
2981 Since most function calls on RISC machines do not use
2982 the stack, this is uncommon, but must work correctly.
2983
2984 Therefore, we save any area of the stack that was already
2985 written and that we are using. Here we set up to do this
2986 by making a new stack usage map from the old one. The
2987 actual save will be done by store_one_arg.
2988
2989 Another approach might be to try to reorder the argument
2990 evaluations to avoid this conflicting stack usage. */
2991
2992 /* Since we will be writing into the entire argument area,
2993 the map must be allocated for its entire size, not just
2994 the part that is the responsibility of the caller. */
2995 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
2996 needed += reg_parm_stack_space;
2997
2998 if (ARGS_GROW_DOWNWARD)
2999 highest_outgoing_arg_in_use
3000 = MAX (initial_highest_arg_in_use, needed + 1);
3001 else
3002 highest_outgoing_arg_in_use
3003 = MAX (initial_highest_arg_in_use, needed);
3004
3005 free (stack_usage_map_buf);
3006 stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
3007 stack_usage_map = stack_usage_map_buf;
3008
3009 if (initial_highest_arg_in_use)
3010 memcpy (stack_usage_map, initial_stack_usage_map,
3011 initial_highest_arg_in_use);
3012
3013 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
3014 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
3015 (highest_outgoing_arg_in_use
3016 - initial_highest_arg_in_use));
3017 needed = 0;
3018
3019 /* The address of the outgoing argument list must not be
3020 copied to a register here, because argblock would be left
3021 pointing to the wrong place after the call to
3022 allocate_dynamic_stack_space below. */
3023
3024 argblock = virtual_outgoing_args_rtx;
3025 }
3026 else
3027 {
3028 if (inhibit_defer_pop == 0)
3029 {
3030 /* Try to reuse some or all of the pending_stack_adjust
3031 to get this space. */
3032 needed
3033 = (combine_pending_stack_adjustment_and_call
3034 (unadjusted_args_size,
3035 &adjusted_args_size,
3036 preferred_unit_stack_boundary));
3037
3038 /* combine_pending_stack_adjustment_and_call computes
3039 an adjustment before the arguments are allocated.
3040 Account for them and see whether or not the stack
3041 needs to go up or down. */
3042 needed = unadjusted_args_size - needed;
3043
3044 if (needed < 0)
3045 {
3046 /* We're releasing stack space. */
3047 /* ??? We can avoid any adjustment at all if we're
3048 already aligned. FIXME. */
3049 pending_stack_adjust = -needed;
3050 do_pending_stack_adjust ();
3051 needed = 0;
3052 }
3053 else
3054 /* We need to allocate space. We'll do that in
3055 push_block below. */
3056 pending_stack_adjust = 0;
3057 }
3058
3059 /* Special case this because overhead of `push_block' in
3060 this case is non-trivial. */
3061 if (needed == 0)
3062 argblock = virtual_outgoing_args_rtx;
3063 else
3064 {
3065 argblock = push_block (GEN_INT (needed), 0, 0);
3066 if (ARGS_GROW_DOWNWARD)
3067 argblock = plus_constant (Pmode, argblock, needed);
3068 }
3069
3070 /* We only really need to call `copy_to_reg' in the case
3071 where push insns are going to be used to pass ARGBLOCK
3072 to a function call in ARGS. In that case, the stack
3073 pointer changes value from the allocation point to the
3074 call point, and hence the value of
3075 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might
3076 as well always do it. */
3077 argblock = copy_to_reg (argblock);
3078 }
3079 }
3080 }
3081
3082 if (ACCUMULATE_OUTGOING_ARGS)
3083 {
3084 /* The save/restore code in store_one_arg handles all
3085 cases except one: a constructor call (including a C
3086 function returning a BLKmode struct) to initialize
3087 an argument. */
3088 if (stack_arg_under_construction)
3089 {
3090 rtx push_size
3091 = GEN_INT (adjusted_args_size.constant
3092 + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype
3093 : TREE_TYPE (fndecl))) ? 0
3094 : reg_parm_stack_space));
3095 if (old_stack_level == 0)
3096 {
3097 emit_stack_save (SAVE_BLOCK, &old_stack_level);
3098 old_stack_pointer_delta = stack_pointer_delta;
3099 old_pending_adj = pending_stack_adjust;
3100 pending_stack_adjust = 0;
3101 /* stack_arg_under_construction says whether a stack
3102 arg is being constructed at the old stack level.
3103 Pushing the stack gets a clean outgoing argument
3104 block. */
3105 old_stack_arg_under_construction
3106 = stack_arg_under_construction;
3107 stack_arg_under_construction = 0;
3108 /* Make a new map for the new argument list. */
3109 free (stack_usage_map_buf);
3110 stack_usage_map_buf = XCNEWVEC (char, highest_outgoing_arg_in_use);
3111 stack_usage_map = stack_usage_map_buf;
3112 highest_outgoing_arg_in_use = 0;
3113 }
3114 /* We can pass TRUE as the 4th argument because we just
3115 saved the stack pointer and will restore it right after
3116 the call. */
3117 allocate_dynamic_stack_space (push_size, 0,
3118 BIGGEST_ALIGNMENT, true);
3119 }
3120
3121 /* If argument evaluation might modify the stack pointer,
3122 copy the address of the argument list to a register. */
3123 for (i = 0; i < num_actuals; i++)
3124 if (args[i].pass_on_stack)
3125 {
3126 argblock = copy_addr_to_reg (argblock);
3127 break;
3128 }
3129 }
3130
3131 compute_argument_addresses (args, argblock, num_actuals);
3132
3133 /* Perform stack alignment before the first push (the last arg). */
3134 if (argblock == 0
3135 && adjusted_args_size.constant > reg_parm_stack_space
3136 && adjusted_args_size.constant != unadjusted_args_size)
3137 {
3138 /* When the stack adjustment is pending, we get better code
3139 by combining the adjustments. */
3140 if (pending_stack_adjust
3141 && ! inhibit_defer_pop)
3142 {
3143 pending_stack_adjust
3144 = (combine_pending_stack_adjustment_and_call
3145 (unadjusted_args_size,
3146 &adjusted_args_size,
3147 preferred_unit_stack_boundary));
3148 do_pending_stack_adjust ();
3149 }
3150 else if (argblock == 0)
3151 anti_adjust_stack (GEN_INT (adjusted_args_size.constant
3152 - unadjusted_args_size));
3153 }
3154 /* Now that the stack is properly aligned, pops can't safely
3155 be deferred during the evaluation of the arguments. */
3156 NO_DEFER_POP;
3157
3158 /* Record the maximum pushed stack space size. We need to delay
3159 doing it this far to take into account the optimization done
3160 by combine_pending_stack_adjustment_and_call. */
3161 if (flag_stack_usage_info
3162 && !ACCUMULATE_OUTGOING_ARGS
3163 && pass
3164 && adjusted_args_size.var == 0)
3165 {
3166 int pushed = adjusted_args_size.constant + pending_stack_adjust;
3167 if (pushed > current_function_pushed_stack_size)
3168 current_function_pushed_stack_size = pushed;
3169 }
3170
3171 funexp = rtx_for_function_call (fndecl, addr);
3172
3173 /* Precompute all register parameters. It isn't safe to compute anything
3174 once we have started filling any specific hard regs. */
3175 precompute_register_parameters (num_actuals, args, &reg_parm_seen);
3176
3177 if (CALL_EXPR_STATIC_CHAIN (exp))
3178 static_chain_value = expand_normal (CALL_EXPR_STATIC_CHAIN (exp));
3179 else
3180 static_chain_value = 0;
3181
3182 #ifdef REG_PARM_STACK_SPACE
3183 /* Save the fixed argument area if it's part of the caller's frame and
3184 is clobbered by argument setup for this call. */
3185 if (ACCUMULATE_OUTGOING_ARGS && pass)
3186 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
3187 &low_to_save, &high_to_save);
3188 #endif
3189
3190 /* Now store (and compute if necessary) all non-register parms.
3191 These come before register parms, since they can require block-moves,
3192 which could clobber the registers used for register parms.
3193 Parms which have partial registers are not stored here,
3194 but we do preallocate space here if they want that. */
3195
3196 for (i = 0; i < num_actuals; i++)
3197 {
3198 /* Delay bounds until all other args are stored. */
3199 if (POINTER_BOUNDS_P (args[i].tree_value))
3200 continue;
3201 else if (args[i].reg == 0 || args[i].pass_on_stack)
3202 {
3203 rtx_insn *before_arg = get_last_insn ();
3204
3205 /* We don't allow passing huge (> 2^30 B) arguments
3206 by value. It would cause an overflow later on. */
3207 if (adjusted_args_size.constant
3208 >= (1 << (HOST_BITS_PER_INT - 2)))
3209 {
3210 sorry ("passing too large argument on stack");
3211 continue;
3212 }
3213
3214 if (store_one_arg (&args[i], argblock, flags,
3215 adjusted_args_size.var != 0,
3216 reg_parm_stack_space)
3217 || (pass == 0
3218 && check_sibcall_argument_overlap (before_arg,
3219 &args[i], 1)))
3220 sibcall_failure = 1;
3221 }
3222
3223 if (args[i].stack)
3224 call_fusage
3225 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[i].tree_value)),
3226 gen_rtx_USE (VOIDmode, args[i].stack),
3227 call_fusage);
3228 }
3229
3230 /* If we have a parm that is passed in registers but not in memory
3231 and whose alignment does not permit a direct copy into registers,
3232 make a group of pseudos that correspond to each register that we
3233 will later fill. */
3234 if (STRICT_ALIGNMENT)
3235 store_unaligned_arguments_into_pseudos (args, num_actuals);
3236
3237 /* Now store any partially-in-registers parm.
3238 This is the last place a block-move can happen. */
3239 if (reg_parm_seen)
3240 for (i = 0; i < num_actuals; i++)
3241 if (args[i].partial != 0 && ! args[i].pass_on_stack)
3242 {
3243 rtx_insn *before_arg = get_last_insn ();
3244
3245 if (store_one_arg (&args[i], argblock, flags,
3246 adjusted_args_size.var != 0,
3247 reg_parm_stack_space)
3248 || (pass == 0
3249 && check_sibcall_argument_overlap (before_arg,
3250 &args[i], 1)))
3251 sibcall_failure = 1;
3252 }
3253
3254 bool any_regs = false;
3255 for (i = 0; i < num_actuals; i++)
3256 if (args[i].reg != NULL_RTX)
3257 {
3258 any_regs = true;
3259 targetm.calls.call_args (args[i].reg, funtype);
3260 }
3261 if (!any_regs)
3262 targetm.calls.call_args (pc_rtx, funtype);
3263
3264 /* Figure out the register where the value, if any, will come back. */
3265 valreg = 0;
3266 valbnd = 0;
3267 if (TYPE_MODE (rettype) != VOIDmode
3268 && ! structure_value_addr)
3269 {
3270 if (pcc_struct_value)
3271 {
3272 valreg = hard_function_value (build_pointer_type (rettype),
3273 fndecl, NULL, (pass == 0));
3274 if (CALL_WITH_BOUNDS_P (exp))
3275 valbnd = targetm.calls.
3276 chkp_function_value_bounds (build_pointer_type (rettype),
3277 fndecl, (pass == 0));
3278 }
3279 else
3280 {
3281 valreg = hard_function_value (rettype, fndecl, fntype,
3282 (pass == 0));
3283 if (CALL_WITH_BOUNDS_P (exp))
3284 valbnd = targetm.calls.chkp_function_value_bounds (rettype,
3285 fndecl,
3286 (pass == 0));
3287 }
3288
3289 /* If VALREG is a PARALLEL whose first member has a zero
3290 offset, use that. This is for targets such as m68k that
3291 return the same value in multiple places. */
3292 if (GET_CODE (valreg) == PARALLEL)
3293 {
3294 rtx elem = XVECEXP (valreg, 0, 0);
3295 rtx where = XEXP (elem, 0);
3296 rtx offset = XEXP (elem, 1);
3297 if (offset == const0_rtx
3298 && GET_MODE (where) == GET_MODE (valreg))
3299 valreg = where;
3300 }
3301 }
3302
3303 /* Store all bounds not passed in registers. */
3304 for (i = 0; i < num_actuals; i++)
3305 {
3306 if (POINTER_BOUNDS_P (args[i].tree_value)
3307 && !args[i].reg)
3308 store_bounds (&args[i],
3309 args[i].pointer_arg == -1
3310 ? NULL
3311 : &args[args[i].pointer_arg]);
3312 }
3313
3314 /* If register arguments require space on the stack and stack space
3315 was not preallocated, allocate stack space here for arguments
3316 passed in registers. */
3317 if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))
3318 && !ACCUMULATE_OUTGOING_ARGS
3319 && must_preallocate == 0 && reg_parm_stack_space > 0)
3320 anti_adjust_stack (GEN_INT (reg_parm_stack_space));
3321
3322 /* Pass the function the address in which to return a
3323 structure value. */
3324 if (pass != 0 && structure_value_addr && ! structure_value_addr_parm)
3325 {
3326 structure_value_addr
3327 = convert_memory_address (Pmode, structure_value_addr);
3328 emit_move_insn (struct_value,
3329 force_reg (Pmode,
3330 force_operand (structure_value_addr,
3331 NULL_RTX)));
3332
3333 if (REG_P (struct_value))
3334 use_reg (&call_fusage, struct_value);
3335 }
3336
3337 after_args = get_last_insn ();
3338 funexp = prepare_call_address (fndecl ? fndecl : fntype, funexp,
3339 static_chain_value, &call_fusage,
3340 reg_parm_seen, pass == 0);
3341
3342 load_register_parameters (args, num_actuals, &call_fusage, flags,
3343 pass == 0, &sibcall_failure);
3344
3345 /* Save a pointer to the last insn before the call, so that we can
3346 later safely search backwards to find the CALL_INSN. */
3347 before_call = get_last_insn ();
3348
3349 /* Set up next argument register. For sibling calls on machines
3350 with register windows this should be the incoming register. */
3351 if (pass == 0)
3352 next_arg_reg = targetm.calls.function_incoming_arg (args_so_far,
3353 VOIDmode,
3354 void_type_node,
3355 true);
3356 else
3357 next_arg_reg = targetm.calls.function_arg (args_so_far,
3358 VOIDmode, void_type_node,
3359 true);
3360
3361 if (pass == 1 && (return_flags & ERF_RETURNS_ARG))
3362 {
3363 int arg_nr = return_flags & ERF_RETURN_ARG_MASK;
3364 arg_nr = num_actuals - arg_nr - 1;
3365 if (arg_nr >= 0
3366 && arg_nr < num_actuals
3367 && args[arg_nr].reg
3368 && valreg
3369 && REG_P (valreg)
3370 && GET_MODE (args[arg_nr].reg) == GET_MODE (valreg))
3371 call_fusage
3372 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[arg_nr].tree_value)),
3373 gen_rtx_SET (valreg, args[arg_nr].reg),
3374 call_fusage);
3375 }
3376 /* All arguments and registers used for the call must be set up by
3377 now! */
3378
3379 /* Stack must be properly aligned now. */
3380 gcc_assert (!pass
3381 || !(stack_pointer_delta % preferred_unit_stack_boundary));
3382
3383 /* Generate the actual call instruction. */
3384 emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,
3385 adjusted_args_size.constant, struct_value_size,
3386 next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage,
3387 flags, args_so_far);
3388
3389 if (flag_ipa_ra)
3390 {
3391 rtx_call_insn *last;
3392 rtx datum = NULL_RTX;
3393 if (fndecl != NULL_TREE)
3394 {
3395 datum = XEXP (DECL_RTL (fndecl), 0);
3396 gcc_assert (datum != NULL_RTX
3397 && GET_CODE (datum) == SYMBOL_REF);
3398 }
3399 last = last_call_insn ();
3400 add_reg_note (last, REG_CALL_DECL, datum);
3401 }
3402
3403 /* If the call setup or the call itself overlaps with anything
3404 of the argument setup we probably clobbered our call address.
3405 In that case we can't do sibcalls. */
3406 if (pass == 0
3407 && check_sibcall_argument_overlap (after_args, 0, 0))
3408 sibcall_failure = 1;
3409
3410 /* If a non-BLKmode value is returned at the most significant end
3411 of a register, shift the register right by the appropriate amount
3412 and update VALREG accordingly. BLKmode values are handled by the
3413 group load/store machinery below. */
3414 if (!structure_value_addr
3415 && !pcc_struct_value
3416 && TYPE_MODE (rettype) != VOIDmode
3417 && TYPE_MODE (rettype) != BLKmode
3418 && REG_P (valreg)
3419 && targetm.calls.return_in_msb (rettype))
3420 {
3421 if (shift_return_value (TYPE_MODE (rettype), false, valreg))
3422 sibcall_failure = 1;
3423 valreg = gen_rtx_REG (TYPE_MODE (rettype), REGNO (valreg));
3424 }
3425
3426 if (pass && (flags & ECF_MALLOC))
3427 {
3428 rtx temp = gen_reg_rtx (GET_MODE (valreg));
3429 rtx_insn *last, *insns;
3430
3431 /* The return value from a malloc-like function is a pointer. */
3432 if (TREE_CODE (rettype) == POINTER_TYPE)
3433 mark_reg_pointer (temp, MALLOC_ABI_ALIGNMENT);
3434
3435 emit_move_insn (temp, valreg);
3436
3437 /* The return value from a malloc-like function can not alias
3438 anything else. */
3439 last = get_last_insn ();
3440 add_reg_note (last, REG_NOALIAS, temp);
3441
3442 /* Write out the sequence. */
3443 insns = get_insns ();
3444 end_sequence ();
3445 emit_insn (insns);
3446 valreg = temp;
3447 }
3448
3449 /* For calls to `setjmp', etc., inform
3450 function.c:setjmp_warnings that it should complain if
3451 nonvolatile values are live. For functions that cannot
3452 return, inform flow that control does not fall through. */
3453
3454 if ((flags & ECF_NORETURN) || pass == 0)
3455 {
3456 /* The barrier must be emitted
3457 immediately after the CALL_INSN. Some ports emit more
3458 than just a CALL_INSN above, so we must search for it here. */
3459
3460 rtx_insn *last = get_last_insn ();
3461 while (!CALL_P (last))
3462 {
3463 last = PREV_INSN (last);
3464 /* There was no CALL_INSN? */
3465 gcc_assert (last != before_call);
3466 }
3467
3468 emit_barrier_after (last);
3469
3470 /* Stack adjustments after a noreturn call are dead code.
3471 However when NO_DEFER_POP is in effect, we must preserve
3472 stack_pointer_delta. */
3473 if (inhibit_defer_pop == 0)
3474 {
3475 stack_pointer_delta = old_stack_allocated;
3476 pending_stack_adjust = 0;
3477 }
3478 }
3479
3480 /* If value type not void, return an rtx for the value. */
3481
3482 if (TYPE_MODE (rettype) == VOIDmode
3483 || ignore)
3484 target = const0_rtx;
3485 else if (structure_value_addr)
3486 {
3487 if (target == 0 || !MEM_P (target))
3488 {
3489 target
3490 = gen_rtx_MEM (TYPE_MODE (rettype),
3491 memory_address (TYPE_MODE (rettype),
3492 structure_value_addr));
3493 set_mem_attributes (target, rettype, 1);
3494 }
3495 }
3496 else if (pcc_struct_value)
3497 {
3498 /* This is the special C++ case where we need to
3499 know what the true target was. We take care to
3500 never use this value more than once in one expression. */
3501 target = gen_rtx_MEM (TYPE_MODE (rettype),
3502 copy_to_reg (valreg));
3503 set_mem_attributes (target, rettype, 1);
3504 }
3505 /* Handle calls that return values in multiple non-contiguous locations.
3506 The Irix 6 ABI has examples of this. */
3507 else if (GET_CODE (valreg) == PARALLEL)
3508 {
3509 if (target == 0)
3510 target = emit_group_move_into_temps (valreg);
3511 else if (rtx_equal_p (target, valreg))
3512 ;
3513 else if (GET_CODE (target) == PARALLEL)
3514 /* Handle the result of a emit_group_move_into_temps
3515 call in the previous pass. */
3516 emit_group_move (target, valreg);
3517 else
3518 emit_group_store (target, valreg, rettype,
3519 int_size_in_bytes (rettype));
3520 }
3521 else if (target
3522 && GET_MODE (target) == TYPE_MODE (rettype)
3523 && GET_MODE (target) == GET_MODE (valreg))
3524 {
3525 bool may_overlap = false;
3526
3527 /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard
3528 reg to a plain register. */
3529 if (!REG_P (target) || HARD_REGISTER_P (target))
3530 valreg = avoid_likely_spilled_reg (valreg);
3531
3532 /* If TARGET is a MEM in the argument area, and we have
3533 saved part of the argument area, then we can't store
3534 directly into TARGET as it may get overwritten when we
3535 restore the argument save area below. Don't work too
3536 hard though and simply force TARGET to a register if it
3537 is a MEM; the optimizer is quite likely to sort it out. */
3538 if (ACCUMULATE_OUTGOING_ARGS && pass && MEM_P (target))
3539 for (i = 0; i < num_actuals; i++)
3540 if (args[i].save_area)
3541 {
3542 may_overlap = true;
3543 break;
3544 }
3545
3546 if (may_overlap)
3547 target = copy_to_reg (valreg);
3548 else
3549 {
3550 /* TARGET and VALREG cannot be equal at this point
3551 because the latter would not have
3552 REG_FUNCTION_VALUE_P true, while the former would if
3553 it were referring to the same register.
3554
3555 If they refer to the same register, this move will be
3556 a no-op, except when function inlining is being
3557 done. */
3558 emit_move_insn (target, valreg);
3559
3560 /* If we are setting a MEM, this code must be executed.
3561 Since it is emitted after the call insn, sibcall
3562 optimization cannot be performed in that case. */
3563 if (MEM_P (target))
3564 sibcall_failure = 1;
3565 }
3566 }
3567 else
3568 target = copy_to_reg (avoid_likely_spilled_reg (valreg));
3569
3570 /* If we promoted this return value, make the proper SUBREG.
3571 TARGET might be const0_rtx here, so be careful. */
3572 if (REG_P (target)
3573 && TYPE_MODE (rettype) != BLKmode
3574 && GET_MODE (target) != TYPE_MODE (rettype))
3575 {
3576 tree type = rettype;
3577 int unsignedp = TYPE_UNSIGNED (type);
3578 int offset = 0;
3579 machine_mode pmode;
3580
3581 /* Ensure we promote as expected, and get the new unsignedness. */
3582 pmode = promote_function_mode (type, TYPE_MODE (type), &unsignedp,
3583 funtype, 1);
3584 gcc_assert (GET_MODE (target) == pmode);
3585
3586 if ((WORDS_BIG_ENDIAN || BYTES_BIG_ENDIAN)
3587 && (GET_MODE_SIZE (GET_MODE (target))
3588 > GET_MODE_SIZE (TYPE_MODE (type))))
3589 {
3590 offset = GET_MODE_SIZE (GET_MODE (target))
3591 - GET_MODE_SIZE (TYPE_MODE (type));
3592 if (! BYTES_BIG_ENDIAN)
3593 offset = (offset / UNITS_PER_WORD) * UNITS_PER_WORD;
3594 else if (! WORDS_BIG_ENDIAN)
3595 offset %= UNITS_PER_WORD;
3596 }
3597
3598 target = gen_rtx_SUBREG (TYPE_MODE (type), target, offset);
3599 SUBREG_PROMOTED_VAR_P (target) = 1;
3600 SUBREG_PROMOTED_SET (target, unsignedp);
3601 }
3602
3603 /* If size of args is variable or this was a constructor call for a stack
3604 argument, restore saved stack-pointer value. */
3605
3606 if (old_stack_level)
3607 {
3608 rtx_insn *prev = get_last_insn ();
3609
3610 emit_stack_restore (SAVE_BLOCK, old_stack_level);
3611 stack_pointer_delta = old_stack_pointer_delta;
3612
3613 fixup_args_size_notes (prev, get_last_insn (), stack_pointer_delta);
3614
3615 pending_stack_adjust = old_pending_adj;
3616 old_stack_allocated = stack_pointer_delta - pending_stack_adjust;
3617 stack_arg_under_construction = old_stack_arg_under_construction;
3618 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3619 stack_usage_map = initial_stack_usage_map;
3620 sibcall_failure = 1;
3621 }
3622 else if (ACCUMULATE_OUTGOING_ARGS && pass)
3623 {
3624 #ifdef REG_PARM_STACK_SPACE
3625 if (save_area)
3626 restore_fixed_argument_area (save_area, argblock,
3627 high_to_save, low_to_save);
3628 #endif
3629
3630 /* If we saved any argument areas, restore them. */
3631 for (i = 0; i < num_actuals; i++)
3632 if (args[i].save_area)
3633 {
3634 machine_mode save_mode = GET_MODE (args[i].save_area);
3635 rtx stack_area
3636 = gen_rtx_MEM (save_mode,
3637 memory_address (save_mode,
3638 XEXP (args[i].stack_slot, 0)));
3639
3640 if (save_mode != BLKmode)
3641 emit_move_insn (stack_area, args[i].save_area);
3642 else
3643 emit_block_move (stack_area, args[i].save_area,
3644 GEN_INT (args[i].locate.size.constant),
3645 BLOCK_OP_CALL_PARM);
3646 }
3647
3648 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
3649 stack_usage_map = initial_stack_usage_map;
3650 }
3651
3652 /* If this was alloca, record the new stack level for nonlocal gotos.
3653 Check for the handler slots since we might not have a save area
3654 for non-local gotos. */
3655
3656 if ((flags & ECF_MAY_BE_ALLOCA) && cfun->nonlocal_goto_save_area != 0)
3657 update_nonlocal_goto_save_area ();
3658
3659 /* Free up storage we no longer need. */
3660 for (i = 0; i < num_actuals; ++i)
3661 free (args[i].aligned_regs);
3662
3663 targetm.calls.end_call_args ();
3664
3665 insns = get_insns ();
3666 end_sequence ();
3667
3668 if (pass == 0)
3669 {
3670 tail_call_insns = insns;
3671
3672 /* Restore the pending stack adjustment now that we have
3673 finished generating the sibling call sequence. */
3674
3675 restore_pending_stack_adjust (&save);
3676
3677 /* Prepare arg structure for next iteration. */
3678 for (i = 0; i < num_actuals; i++)
3679 {
3680 args[i].value = 0;
3681 args[i].aligned_regs = 0;
3682 args[i].stack = 0;
3683 }
3684
3685 sbitmap_free (stored_args_map);
3686 internal_arg_pointer_exp_state.scan_start = NULL;
3687 internal_arg_pointer_exp_state.cache.release ();
3688 }
3689 else
3690 {
3691 normal_call_insns = insns;
3692
3693 /* Verify that we've deallocated all the stack we used. */
3694 gcc_assert ((flags & ECF_NORETURN)
3695 || (old_stack_allocated
3696 == stack_pointer_delta - pending_stack_adjust));
3697 }
3698
3699 /* If something prevents making this a sibling call,
3700 zero out the sequence. */
3701 if (sibcall_failure)
3702 tail_call_insns = NULL;
3703 else
3704 break;
3705 }
3706
3707 /* If tail call production succeeded, we need to remove REG_EQUIV notes on
3708 arguments too, as argument area is now clobbered by the call. */
3709 if (tail_call_insns)
3710 {
3711 emit_insn (tail_call_insns);
3712 crtl->tail_call_emit = true;
3713 }
3714 else
3715 emit_insn (normal_call_insns);
3716
3717 currently_expanding_call--;
3718
3719 free (stack_usage_map_buf);
3720
3721 /* Join result with returned bounds so caller may use them if needed. */
3722 target = chkp_join_splitted_slot (target, valbnd);
3723
3724 return target;
3725 }
3726
3727 /* A sibling call sequence invalidates any REG_EQUIV notes made for
3728 this function's incoming arguments.
3729
3730 At the start of RTL generation we know the only REG_EQUIV notes
3731 in the rtl chain are those for incoming arguments, so we can look
3732 for REG_EQUIV notes between the start of the function and the
3733 NOTE_INSN_FUNCTION_BEG.
3734
3735 This is (slight) overkill. We could keep track of the highest
3736 argument we clobber and be more selective in removing notes, but it
3737 does not seem to be worth the effort. */
3738
3739 void
3740 fixup_tail_calls (void)
3741 {
3742 rtx_insn *insn;
3743
3744 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3745 {
3746 rtx note;
3747
3748 /* There are never REG_EQUIV notes for the incoming arguments
3749 after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */
3750 if (NOTE_P (insn)
3751 && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
3752 break;
3753
3754 note = find_reg_note (insn, REG_EQUIV, 0);
3755 if (note)
3756 remove_note (insn, note);
3757 note = find_reg_note (insn, REG_EQUIV, 0);
3758 gcc_assert (!note);
3759 }
3760 }
3761
3762 /* Traverse a list of TYPES and expand all complex types into their
3763 components. */
3764 static tree
3765 split_complex_types (tree types)
3766 {
3767 tree p;
3768
3769 /* Before allocating memory, check for the common case of no complex. */
3770 for (p = types; p; p = TREE_CHAIN (p))
3771 {
3772 tree type = TREE_VALUE (p);
3773 if (TREE_CODE (type) == COMPLEX_TYPE
3774 && targetm.calls.split_complex_arg (type))
3775 goto found;
3776 }
3777 return types;
3778
3779 found:
3780 types = copy_list (types);
3781
3782 for (p = types; p; p = TREE_CHAIN (p))
3783 {
3784 tree complex_type = TREE_VALUE (p);
3785
3786 if (TREE_CODE (complex_type) == COMPLEX_TYPE
3787 && targetm.calls.split_complex_arg (complex_type))
3788 {
3789 tree next, imag;
3790
3791 /* Rewrite complex type with component type. */
3792 TREE_VALUE (p) = TREE_TYPE (complex_type);
3793 next = TREE_CHAIN (p);
3794
3795 /* Add another component type for the imaginary part. */
3796 imag = build_tree_list (NULL_TREE, TREE_VALUE (p));
3797 TREE_CHAIN (p) = imag;
3798 TREE_CHAIN (imag) = next;
3799
3800 /* Skip the newly created node. */
3801 p = TREE_CHAIN (p);
3802 }
3803 }
3804
3805 return types;
3806 }
3807 \f
3808 /* Output a library call to function FUN (a SYMBOL_REF rtx).
3809 The RETVAL parameter specifies whether return value needs to be saved, other
3810 parameters are documented in the emit_library_call function below. */
3811
3812 static rtx
3813 emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
3814 enum libcall_type fn_type,
3815 machine_mode outmode, int nargs, va_list p)
3816 {
3817 /* Total size in bytes of all the stack-parms scanned so far. */
3818 struct args_size args_size;
3819 /* Size of arguments before any adjustments (such as rounding). */
3820 struct args_size original_args_size;
3821 int argnum;
3822 rtx fun;
3823 /* Todo, choose the correct decl type of orgfun. Sadly this information
3824 isn't present here, so we default to native calling abi here. */
3825 tree fndecl ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
3826 tree fntype ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */
3827 int count;
3828 rtx argblock = 0;
3829 CUMULATIVE_ARGS args_so_far_v;
3830 cumulative_args_t args_so_far;
3831 struct arg
3832 {
3833 rtx value;
3834 machine_mode mode;
3835 rtx reg;
3836 int partial;
3837 struct locate_and_pad_arg_data locate;
3838 rtx save_area;
3839 };
3840 struct arg *argvec;
3841 int old_inhibit_defer_pop = inhibit_defer_pop;
3842 rtx call_fusage = 0;
3843 rtx mem_value = 0;
3844 rtx valreg;
3845 int pcc_struct_value = 0;
3846 int struct_value_size = 0;
3847 int flags;
3848 int reg_parm_stack_space = 0;
3849 int needed;
3850 rtx_insn *before_call;
3851 bool have_push_fusage;
3852 tree tfom; /* type_for_mode (outmode, 0) */
3853
3854 #ifdef REG_PARM_STACK_SPACE
3855 /* Define the boundary of the register parm stack space that needs to be
3856 save, if any. */
3857 int low_to_save = 0, high_to_save = 0;
3858 rtx save_area = 0; /* Place that it is saved. */
3859 #endif
3860
3861 /* Size of the stack reserved for parameter registers. */
3862 int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
3863 char *initial_stack_usage_map = stack_usage_map;
3864 char *stack_usage_map_buf = NULL;
3865
3866 rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
3867
3868 #ifdef REG_PARM_STACK_SPACE
3869 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0);
3870 #endif
3871
3872 /* By default, library functions can not throw. */
3873 flags = ECF_NOTHROW;
3874
3875 switch (fn_type)
3876 {
3877 case LCT_NORMAL:
3878 break;
3879 case LCT_CONST:
3880 flags |= ECF_CONST;
3881 break;
3882 case LCT_PURE:
3883 flags |= ECF_PURE;
3884 break;
3885 case LCT_NORETURN:
3886 flags |= ECF_NORETURN;
3887 break;
3888 case LCT_THROW:
3889 flags = ECF_NORETURN;
3890 break;
3891 case LCT_RETURNS_TWICE:
3892 flags = ECF_RETURNS_TWICE;
3893 break;
3894 }
3895 fun = orgfun;
3896
3897 /* Ensure current function's preferred stack boundary is at least
3898 what we need. */
3899 if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
3900 crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
3901
3902 /* If this kind of value comes back in memory,
3903 decide where in memory it should come back. */
3904 if (outmode != VOIDmode)
3905 {
3906 tfom = lang_hooks.types.type_for_mode (outmode, 0);
3907 if (aggregate_value_p (tfom, 0))
3908 {
3909 #ifdef PCC_STATIC_STRUCT_RETURN
3910 rtx pointer_reg
3911 = hard_function_value (build_pointer_type (tfom), 0, 0, 0);
3912 mem_value = gen_rtx_MEM (outmode, pointer_reg);
3913 pcc_struct_value = 1;
3914 if (value == 0)
3915 value = gen_reg_rtx (outmode);
3916 #else /* not PCC_STATIC_STRUCT_RETURN */
3917 struct_value_size = GET_MODE_SIZE (outmode);
3918 if (value != 0 && MEM_P (value))
3919 mem_value = value;
3920 else
3921 mem_value = assign_temp (tfom, 1, 1);
3922 #endif
3923 /* This call returns a big structure. */
3924 flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE);
3925 }
3926 }
3927 else
3928 tfom = void_type_node;
3929
3930 /* ??? Unfinished: must pass the memory address as an argument. */
3931
3932 /* Copy all the libcall-arguments out of the varargs data
3933 and into a vector ARGVEC.
3934
3935 Compute how to pass each argument. We only support a very small subset
3936 of the full argument passing conventions to limit complexity here since
3937 library functions shouldn't have many args. */
3938
3939 argvec = XALLOCAVEC (struct arg, nargs + 1);
3940 memset (argvec, 0, (nargs + 1) * sizeof (struct arg));
3941
3942 #ifdef INIT_CUMULATIVE_LIBCALL_ARGS
3943 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v, outmode, fun);
3944 #else
3945 INIT_CUMULATIVE_ARGS (args_so_far_v, NULL_TREE, fun, 0, nargs);
3946 #endif
3947 args_so_far = pack_cumulative_args (&args_so_far_v);
3948
3949 args_size.constant = 0;
3950 args_size.var = 0;
3951
3952 count = 0;
3953
3954 push_temp_slots ();
3955
3956 /* If there's a structure value address to be passed,
3957 either pass it in the special place, or pass it as an extra argument. */
3958 if (mem_value && struct_value == 0 && ! pcc_struct_value)
3959 {
3960 rtx addr = XEXP (mem_value, 0);
3961
3962 nargs++;
3963
3964 /* Make sure it is a reasonable operand for a move or push insn. */
3965 if (!REG_P (addr) && !MEM_P (addr)
3966 && !(CONSTANT_P (addr)
3967 && targetm.legitimate_constant_p (Pmode, addr)))
3968 addr = force_operand (addr, NULL_RTX);
3969
3970 argvec[count].value = addr;
3971 argvec[count].mode = Pmode;
3972 argvec[count].partial = 0;
3973
3974 argvec[count].reg = targetm.calls.function_arg (args_so_far,
3975 Pmode, NULL_TREE, true);
3976 gcc_assert (targetm.calls.arg_partial_bytes (args_so_far, Pmode,
3977 NULL_TREE, 1) == 0);
3978
3979 locate_and_pad_parm (Pmode, NULL_TREE,
3980 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3981 1,
3982 #else
3983 argvec[count].reg != 0,
3984 #endif
3985 reg_parm_stack_space, 0,
3986 NULL_TREE, &args_size, &argvec[count].locate);
3987
3988 if (argvec[count].reg == 0 || argvec[count].partial != 0
3989 || reg_parm_stack_space > 0)
3990 args_size.constant += argvec[count].locate.size.constant;
3991
3992 targetm.calls.function_arg_advance (args_so_far, Pmode, (tree) 0, true);
3993
3994 count++;
3995 }
3996
3997 for (; count < nargs; count++)
3998 {
3999 rtx val = va_arg (p, rtx);
4000 machine_mode mode = (machine_mode) va_arg (p, int);
4001 int unsigned_p = 0;
4002
4003 /* We cannot convert the arg value to the mode the library wants here;
4004 must do it earlier where we know the signedness of the arg. */
4005 gcc_assert (mode != BLKmode
4006 && (GET_MODE (val) == mode || GET_MODE (val) == VOIDmode));
4007
4008 /* Make sure it is a reasonable operand for a move or push insn. */
4009 if (!REG_P (val) && !MEM_P (val)
4010 && !(CONSTANT_P (val) && targetm.legitimate_constant_p (mode, val)))
4011 val = force_operand (val, NULL_RTX);
4012
4013 if (pass_by_reference (&args_so_far_v, mode, NULL_TREE, 1))
4014 {
4015 rtx slot;
4016 int must_copy
4017 = !reference_callee_copied (&args_so_far_v, mode, NULL_TREE, 1);
4018
4019 /* If this was a CONST function, it is now PURE since it now
4020 reads memory. */
4021 if (flags & ECF_CONST)
4022 {
4023 flags &= ~ECF_CONST;
4024 flags |= ECF_PURE;
4025 }
4026
4027 if (MEM_P (val) && !must_copy)
4028 {
4029 tree val_expr = MEM_EXPR (val);
4030 if (val_expr)
4031 mark_addressable (val_expr);
4032 slot = val;
4033 }
4034 else
4035 {
4036 slot = assign_temp (lang_hooks.types.type_for_mode (mode, 0),
4037 1, 1);
4038 emit_move_insn (slot, val);
4039 }
4040
4041 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
4042 gen_rtx_USE (VOIDmode, slot),
4043 call_fusage);
4044 if (must_copy)
4045 call_fusage = gen_rtx_EXPR_LIST (VOIDmode,
4046 gen_rtx_CLOBBER (VOIDmode,
4047 slot),
4048 call_fusage);
4049
4050 mode = Pmode;
4051 val = force_operand (XEXP (slot, 0), NULL_RTX);
4052 }
4053
4054 mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0);
4055 argvec[count].mode = mode;
4056 argvec[count].value = convert_modes (mode, GET_MODE (val), val, unsigned_p);
4057 argvec[count].reg = targetm.calls.function_arg (args_so_far, mode,
4058 NULL_TREE, true);
4059
4060 argvec[count].partial
4061 = targetm.calls.arg_partial_bytes (args_so_far, mode, NULL_TREE, 1);
4062
4063 if (argvec[count].reg == 0
4064 || argvec[count].partial != 0
4065 || reg_parm_stack_space > 0)
4066 {
4067 locate_and_pad_parm (mode, NULL_TREE,
4068 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4069 1,
4070 #else
4071 argvec[count].reg != 0,
4072 #endif
4073 reg_parm_stack_space, argvec[count].partial,
4074 NULL_TREE, &args_size, &argvec[count].locate);
4075 args_size.constant += argvec[count].locate.size.constant;
4076 gcc_assert (!argvec[count].locate.size.var);
4077 }
4078 #ifdef BLOCK_REG_PADDING
4079 else
4080 /* The argument is passed entirely in registers. See at which
4081 end it should be padded. */
4082 argvec[count].locate.where_pad =
4083 BLOCK_REG_PADDING (mode, NULL_TREE,
4084 GET_MODE_SIZE (mode) <= UNITS_PER_WORD);
4085 #endif
4086
4087 targetm.calls.function_arg_advance (args_so_far, mode, (tree) 0, true);
4088 }
4089
4090 /* If this machine requires an external definition for library
4091 functions, write one out. */
4092 assemble_external_libcall (fun);
4093
4094 original_args_size = args_size;
4095 args_size.constant = (((args_size.constant
4096 + stack_pointer_delta
4097 + STACK_BYTES - 1)
4098 / STACK_BYTES
4099 * STACK_BYTES)
4100 - stack_pointer_delta);
4101
4102 args_size.constant = MAX (args_size.constant,
4103 reg_parm_stack_space);
4104
4105 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
4106 args_size.constant -= reg_parm_stack_space;
4107
4108 if (args_size.constant > crtl->outgoing_args_size)
4109 crtl->outgoing_args_size = args_size.constant;
4110
4111 if (flag_stack_usage_info && !ACCUMULATE_OUTGOING_ARGS)
4112 {
4113 int pushed = args_size.constant + pending_stack_adjust;
4114 if (pushed > current_function_pushed_stack_size)
4115 current_function_pushed_stack_size = pushed;
4116 }
4117
4118 if (ACCUMULATE_OUTGOING_ARGS)
4119 {
4120 /* Since the stack pointer will never be pushed, it is possible for
4121 the evaluation of a parm to clobber something we have already
4122 written to the stack. Since most function calls on RISC machines
4123 do not use the stack, this is uncommon, but must work correctly.
4124
4125 Therefore, we save any area of the stack that was already written
4126 and that we are using. Here we set up to do this by making a new
4127 stack usage map from the old one.
4128
4129 Another approach might be to try to reorder the argument
4130 evaluations to avoid this conflicting stack usage. */
4131
4132 needed = args_size.constant;
4133
4134 /* Since we will be writing into the entire argument area, the
4135 map must be allocated for its entire size, not just the part that
4136 is the responsibility of the caller. */
4137 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
4138 needed += reg_parm_stack_space;
4139
4140 if (ARGS_GROW_DOWNWARD)
4141 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
4142 needed + 1);
4143 else
4144 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, needed);
4145
4146 stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
4147 stack_usage_map = stack_usage_map_buf;
4148
4149 if (initial_highest_arg_in_use)
4150 memcpy (stack_usage_map, initial_stack_usage_map,
4151 initial_highest_arg_in_use);
4152
4153 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use)
4154 memset (&stack_usage_map[initial_highest_arg_in_use], 0,
4155 highest_outgoing_arg_in_use - initial_highest_arg_in_use);
4156 needed = 0;
4157
4158 /* We must be careful to use virtual regs before they're instantiated,
4159 and real regs afterwards. Loop optimization, for example, can create
4160 new libcalls after we've instantiated the virtual regs, and if we
4161 use virtuals anyway, they won't match the rtl patterns. */
4162
4163 if (virtuals_instantiated)
4164 argblock = plus_constant (Pmode, stack_pointer_rtx,
4165 STACK_POINTER_OFFSET);
4166 else
4167 argblock = virtual_outgoing_args_rtx;
4168 }
4169 else
4170 {
4171 if (!PUSH_ARGS)
4172 argblock = push_block (GEN_INT (args_size.constant), 0, 0);
4173 }
4174
4175 /* We push args individually in reverse order, perform stack alignment
4176 before the first push (the last arg). */
4177 if (argblock == 0)
4178 anti_adjust_stack (GEN_INT (args_size.constant
4179 - original_args_size.constant));
4180
4181 argnum = nargs - 1;
4182
4183 #ifdef REG_PARM_STACK_SPACE
4184 if (ACCUMULATE_OUTGOING_ARGS)
4185 {
4186 /* The argument list is the property of the called routine and it
4187 may clobber it. If the fixed area has been used for previous
4188 parameters, we must save and restore it. */
4189 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock,
4190 &low_to_save, &high_to_save);
4191 }
4192 #endif
4193
4194 /* When expanding a normal call, args are stored in push order,
4195 which is the reverse of what we have here. */
4196 bool any_regs = false;
4197 for (int i = nargs; i-- > 0; )
4198 if (argvec[i].reg != NULL_RTX)
4199 {
4200 targetm.calls.call_args (argvec[i].reg, NULL_TREE);
4201 any_regs = true;
4202 }
4203 if (!any_regs)
4204 targetm.calls.call_args (pc_rtx, NULL_TREE);
4205
4206 /* Push the args that need to be pushed. */
4207
4208 have_push_fusage = false;
4209
4210 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4211 are to be pushed. */
4212 for (count = 0; count < nargs; count++, argnum--)
4213 {
4214 machine_mode mode = argvec[argnum].mode;
4215 rtx val = argvec[argnum].value;
4216 rtx reg = argvec[argnum].reg;
4217 int partial = argvec[argnum].partial;
4218 unsigned int parm_align = argvec[argnum].locate.boundary;
4219 int lower_bound = 0, upper_bound = 0, i;
4220
4221 if (! (reg != 0 && partial == 0))
4222 {
4223 rtx use;
4224
4225 if (ACCUMULATE_OUTGOING_ARGS)
4226 {
4227 /* If this is being stored into a pre-allocated, fixed-size,
4228 stack area, save any previous data at that location. */
4229
4230 if (ARGS_GROW_DOWNWARD)
4231 {
4232 /* stack_slot is negative, but we want to index stack_usage_map
4233 with positive values. */
4234 upper_bound = -argvec[argnum].locate.slot_offset.constant + 1;
4235 lower_bound = upper_bound - argvec[argnum].locate.size.constant;
4236 }
4237 else
4238 {
4239 lower_bound = argvec[argnum].locate.slot_offset.constant;
4240 upper_bound = lower_bound + argvec[argnum].locate.size.constant;
4241 }
4242
4243 i = lower_bound;
4244 /* Don't worry about things in the fixed argument area;
4245 it has already been saved. */
4246 if (i < reg_parm_stack_space)
4247 i = reg_parm_stack_space;
4248 while (i < upper_bound && stack_usage_map[i] == 0)
4249 i++;
4250
4251 if (i < upper_bound)
4252 {
4253 /* We need to make a save area. */
4254 unsigned int size
4255 = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
4256 machine_mode save_mode
4257 = mode_for_size (size, MODE_INT, 1);
4258 rtx adr
4259 = plus_constant (Pmode, argblock,
4260 argvec[argnum].locate.offset.constant);
4261 rtx stack_area
4262 = gen_rtx_MEM (save_mode, memory_address (save_mode, adr));
4263
4264 if (save_mode == BLKmode)
4265 {
4266 argvec[argnum].save_area
4267 = assign_stack_temp (BLKmode,
4268 argvec[argnum].locate.size.constant
4269 );
4270
4271 emit_block_move (validize_mem
4272 (copy_rtx (argvec[argnum].save_area)),
4273 stack_area,
4274 GEN_INT (argvec[argnum].locate.size.constant),
4275 BLOCK_OP_CALL_PARM);
4276 }
4277 else
4278 {
4279 argvec[argnum].save_area = gen_reg_rtx (save_mode);
4280
4281 emit_move_insn (argvec[argnum].save_area, stack_area);
4282 }
4283 }
4284 }
4285
4286 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, parm_align,
4287 partial, reg, 0, argblock,
4288 GEN_INT (argvec[argnum].locate.offset.constant),
4289 reg_parm_stack_space,
4290 ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad));
4291
4292 /* Now mark the segment we just used. */
4293 if (ACCUMULATE_OUTGOING_ARGS)
4294 for (i = lower_bound; i < upper_bound; i++)
4295 stack_usage_map[i] = 1;
4296
4297 NO_DEFER_POP;
4298
4299 /* Indicate argument access so that alias.c knows that these
4300 values are live. */
4301 if (argblock)
4302 use = plus_constant (Pmode, argblock,
4303 argvec[argnum].locate.offset.constant);
4304 else if (have_push_fusage)
4305 continue;
4306 else
4307 {
4308 /* When arguments are pushed, trying to tell alias.c where
4309 exactly this argument is won't work, because the
4310 auto-increment causes confusion. So we merely indicate
4311 that we access something with a known mode somewhere on
4312 the stack. */
4313 use = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
4314 gen_rtx_SCRATCH (Pmode));
4315 have_push_fusage = true;
4316 }
4317 use = gen_rtx_MEM (argvec[argnum].mode, use);
4318 use = gen_rtx_USE (VOIDmode, use);
4319 call_fusage = gen_rtx_EXPR_LIST (VOIDmode, use, call_fusage);
4320 }
4321 }
4322
4323 argnum = nargs - 1;
4324
4325 fun = prepare_call_address (NULL, fun, NULL, &call_fusage, 0, 0);
4326
4327 /* Now load any reg parms into their regs. */
4328
4329 /* ARGNUM indexes the ARGVEC array in the order in which the arguments
4330 are to be pushed. */
4331 for (count = 0; count < nargs; count++, argnum--)
4332 {
4333 machine_mode mode = argvec[argnum].mode;
4334 rtx val = argvec[argnum].value;
4335 rtx reg = argvec[argnum].reg;
4336 int partial = argvec[argnum].partial;
4337 #ifdef BLOCK_REG_PADDING
4338 int size = 0;
4339 #endif
4340
4341 /* Handle calls that pass values in multiple non-contiguous
4342 locations. The PA64 has examples of this for library calls. */
4343 if (reg != 0 && GET_CODE (reg) == PARALLEL)
4344 emit_group_load (reg, val, NULL_TREE, GET_MODE_SIZE (mode));
4345 else if (reg != 0 && partial == 0)
4346 {
4347 emit_move_insn (reg, val);
4348 #ifdef BLOCK_REG_PADDING
4349 size = GET_MODE_SIZE (argvec[argnum].mode);
4350
4351 /* Copied from load_register_parameters. */
4352
4353 /* Handle case where we have a value that needs shifting
4354 up to the msb. eg. a QImode value and we're padding
4355 upward on a BYTES_BIG_ENDIAN machine. */
4356 if (size < UNITS_PER_WORD
4357 && (argvec[argnum].locate.where_pad
4358 == (BYTES_BIG_ENDIAN ? upward : downward)))
4359 {
4360 rtx x;
4361 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
4362
4363 /* Assigning REG here rather than a temp makes CALL_FUSAGE
4364 report the whole reg as used. Strictly speaking, the
4365 call only uses SIZE bytes at the msb end, but it doesn't
4366 seem worth generating rtl to say that. */
4367 reg = gen_rtx_REG (word_mode, REGNO (reg));
4368 x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1);
4369 if (x != reg)
4370 emit_move_insn (reg, x);
4371 }
4372 #endif
4373 }
4374
4375 NO_DEFER_POP;
4376 }
4377
4378 /* Any regs containing parms remain in use through the call. */
4379 for (count = 0; count < nargs; count++)
4380 {
4381 rtx reg = argvec[count].reg;
4382 if (reg != 0 && GET_CODE (reg) == PARALLEL)
4383 use_group_regs (&call_fusage, reg);
4384 else if (reg != 0)
4385 {
4386 int partial = argvec[count].partial;
4387 if (partial)
4388 {
4389 int nregs;
4390 gcc_assert (partial % UNITS_PER_WORD == 0);
4391 nregs = partial / UNITS_PER_WORD;
4392 use_regs (&call_fusage, REGNO (reg), nregs);
4393 }
4394 else
4395 use_reg (&call_fusage, reg);
4396 }
4397 }
4398
4399 /* Pass the function the address in which to return a structure value. */
4400 if (mem_value != 0 && struct_value != 0 && ! pcc_struct_value)
4401 {
4402 emit_move_insn (struct_value,
4403 force_reg (Pmode,
4404 force_operand (XEXP (mem_value, 0),
4405 NULL_RTX)));
4406 if (REG_P (struct_value))
4407 use_reg (&call_fusage, struct_value);
4408 }
4409
4410 /* Don't allow popping to be deferred, since then
4411 cse'ing of library calls could delete a call and leave the pop. */
4412 NO_DEFER_POP;
4413 valreg = (mem_value == 0 && outmode != VOIDmode
4414 ? hard_libcall_value (outmode, orgfun) : NULL_RTX);
4415
4416 /* Stack must be properly aligned now. */
4417 gcc_assert (!(stack_pointer_delta
4418 & (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)));
4419
4420 before_call = get_last_insn ();
4421
4422 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which
4423 will set inhibit_defer_pop to that value. */
4424 /* The return type is needed to decide how many bytes the function pops.
4425 Signedness plays no role in that, so for simplicity, we pretend it's
4426 always signed. We also assume that the list of arguments passed has
4427 no impact, so we pretend it is unknown. */
4428
4429 emit_call_1 (fun, NULL,
4430 get_identifier (XSTR (orgfun, 0)),
4431 build_function_type (tfom, NULL_TREE),
4432 original_args_size.constant, args_size.constant,
4433 struct_value_size,
4434 targetm.calls.function_arg (args_so_far,
4435 VOIDmode, void_type_node, true),
4436 valreg,
4437 old_inhibit_defer_pop + 1, call_fusage, flags, args_so_far);
4438
4439 if (flag_ipa_ra)
4440 {
4441 rtx last, datum = orgfun;
4442 gcc_assert (GET_CODE (datum) == SYMBOL_REF);
4443 last = last_call_insn ();
4444 add_reg_note (last, REG_CALL_DECL, datum);
4445 }
4446
4447 /* Right-shift returned value if necessary. */
4448 if (!pcc_struct_value
4449 && TYPE_MODE (tfom) != BLKmode
4450 && targetm.calls.return_in_msb (tfom))
4451 {
4452 shift_return_value (TYPE_MODE (tfom), false, valreg);
4453 valreg = gen_rtx_REG (TYPE_MODE (tfom), REGNO (valreg));
4454 }
4455
4456 targetm.calls.end_call_args ();
4457
4458 /* For calls to `setjmp', etc., inform function.c:setjmp_warnings
4459 that it should complain if nonvolatile values are live. For
4460 functions that cannot return, inform flow that control does not
4461 fall through. */
4462 if (flags & ECF_NORETURN)
4463 {
4464 /* The barrier note must be emitted
4465 immediately after the CALL_INSN. Some ports emit more than
4466 just a CALL_INSN above, so we must search for it here. */
4467 rtx_insn *last = get_last_insn ();
4468 while (!CALL_P (last))
4469 {
4470 last = PREV_INSN (last);
4471 /* There was no CALL_INSN? */
4472 gcc_assert (last != before_call);
4473 }
4474
4475 emit_barrier_after (last);
4476 }
4477
4478 /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW
4479 and LCT_RETURNS_TWICE, cannot perform non-local gotos. */
4480 if (flags & ECF_NOTHROW)
4481 {
4482 rtx_insn *last = get_last_insn ();
4483 while (!CALL_P (last))
4484 {
4485 last = PREV_INSN (last);
4486 /* There was no CALL_INSN? */
4487 gcc_assert (last != before_call);
4488 }
4489
4490 make_reg_eh_region_note_nothrow_nononlocal (last);
4491 }
4492
4493 /* Now restore inhibit_defer_pop to its actual original value. */
4494 OK_DEFER_POP;
4495
4496 pop_temp_slots ();
4497
4498 /* Copy the value to the right place. */
4499 if (outmode != VOIDmode && retval)
4500 {
4501 if (mem_value)
4502 {
4503 if (value == 0)
4504 value = mem_value;
4505 if (value != mem_value)
4506 emit_move_insn (value, mem_value);
4507 }
4508 else if (GET_CODE (valreg) == PARALLEL)
4509 {
4510 if (value == 0)
4511 value = gen_reg_rtx (outmode);
4512 emit_group_store (value, valreg, NULL_TREE, GET_MODE_SIZE (outmode));
4513 }
4514 else
4515 {
4516 /* Convert to the proper mode if a promotion has been active. */
4517 if (GET_MODE (valreg) != outmode)
4518 {
4519 int unsignedp = TYPE_UNSIGNED (tfom);
4520
4521 gcc_assert (promote_function_mode (tfom, outmode, &unsignedp,
4522 fndecl ? TREE_TYPE (fndecl) : fntype, 1)
4523 == GET_MODE (valreg));
4524 valreg = convert_modes (outmode, GET_MODE (valreg), valreg, 0);
4525 }
4526
4527 if (value != 0)
4528 emit_move_insn (value, valreg);
4529 else
4530 value = valreg;
4531 }
4532 }
4533
4534 if (ACCUMULATE_OUTGOING_ARGS)
4535 {
4536 #ifdef REG_PARM_STACK_SPACE
4537 if (save_area)
4538 restore_fixed_argument_area (save_area, argblock,
4539 high_to_save, low_to_save);
4540 #endif
4541
4542 /* If we saved any argument areas, restore them. */
4543 for (count = 0; count < nargs; count++)
4544 if (argvec[count].save_area)
4545 {
4546 machine_mode save_mode = GET_MODE (argvec[count].save_area);
4547 rtx adr = plus_constant (Pmode, argblock,
4548 argvec[count].locate.offset.constant);
4549 rtx stack_area = gen_rtx_MEM (save_mode,
4550 memory_address (save_mode, adr));
4551
4552 if (save_mode == BLKmode)
4553 emit_block_move (stack_area,
4554 validize_mem
4555 (copy_rtx (argvec[count].save_area)),
4556 GEN_INT (argvec[count].locate.size.constant),
4557 BLOCK_OP_CALL_PARM);
4558 else
4559 emit_move_insn (stack_area, argvec[count].save_area);
4560 }
4561
4562 highest_outgoing_arg_in_use = initial_highest_arg_in_use;
4563 stack_usage_map = initial_stack_usage_map;
4564 }
4565
4566 free (stack_usage_map_buf);
4567
4568 return value;
4569
4570 }
4571 \f
4572 /* Output a library call to function FUN (a SYMBOL_REF rtx)
4573 (emitting the queue unless NO_QUEUE is nonzero),
4574 for a value of mode OUTMODE,
4575 with NARGS different arguments, passed as alternating rtx values
4576 and machine_modes to convert them to.
4577
4578 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for
4579 `const' calls, LCT_PURE for `pure' calls, or other LCT_ value for
4580 other types of library calls. */
4581
4582 void
4583 emit_library_call (rtx orgfun, enum libcall_type fn_type,
4584 machine_mode outmode, int nargs, ...)
4585 {
4586 va_list p;
4587
4588 va_start (p, nargs);
4589 emit_library_call_value_1 (0, orgfun, NULL_RTX, fn_type, outmode, nargs, p);
4590 va_end (p);
4591 }
4592 \f
4593 /* Like emit_library_call except that an extra argument, VALUE,
4594 comes second and says where to store the result.
4595 (If VALUE is zero, this function chooses a convenient way
4596 to return the value.
4597
4598 This function returns an rtx for where the value is to be found.
4599 If VALUE is nonzero, VALUE is returned. */
4600
4601 rtx
4602 emit_library_call_value (rtx orgfun, rtx value,
4603 enum libcall_type fn_type,
4604 machine_mode outmode, int nargs, ...)
4605 {
4606 rtx result;
4607 va_list p;
4608
4609 va_start (p, nargs);
4610 result = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode,
4611 nargs, p);
4612 va_end (p);
4613
4614 return result;
4615 }
4616 \f
4617
4618 /* Store pointer bounds argument ARG into Bounds Table entry
4619 associated with PARM. */
4620 static void
4621 store_bounds (struct arg_data *arg, struct arg_data *parm)
4622 {
4623 rtx slot = NULL, ptr = NULL, addr = NULL;
4624
4625 /* We may pass bounds not associated with any pointer. */
4626 if (!parm)
4627 {
4628 gcc_assert (arg->special_slot);
4629 slot = arg->special_slot;
4630 ptr = const0_rtx;
4631 }
4632 /* Find pointer associated with bounds and where it is
4633 passed. */
4634 else
4635 {
4636 if (!parm->reg)
4637 {
4638 gcc_assert (!arg->special_slot);
4639
4640 addr = adjust_address (parm->stack, Pmode, arg->pointer_offset);
4641 }
4642 else if (REG_P (parm->reg))
4643 {
4644 gcc_assert (arg->special_slot);
4645 slot = arg->special_slot;
4646
4647 if (MEM_P (parm->value))
4648 addr = adjust_address (parm->value, Pmode, arg->pointer_offset);
4649 else if (REG_P (parm->value))
4650 ptr = gen_rtx_SUBREG (Pmode, parm->value, arg->pointer_offset);
4651 else
4652 {
4653 gcc_assert (!arg->pointer_offset);
4654 ptr = parm->value;
4655 }
4656 }
4657 else
4658 {
4659 gcc_assert (GET_CODE (parm->reg) == PARALLEL);
4660
4661 gcc_assert (arg->special_slot);
4662 slot = arg->special_slot;
4663
4664 if (parm->parallel_value)
4665 ptr = chkp_get_value_with_offs (parm->parallel_value,
4666 GEN_INT (arg->pointer_offset));
4667 else
4668 gcc_unreachable ();
4669 }
4670 }
4671
4672 /* Expand bounds. */
4673 if (!arg->value)
4674 arg->value = expand_normal (arg->tree_value);
4675
4676 targetm.calls.store_bounds_for_arg (ptr, addr, arg->value, slot);
4677 }
4678
4679 /* Store a single argument for a function call
4680 into the register or memory area where it must be passed.
4681 *ARG describes the argument value and where to pass it.
4682
4683 ARGBLOCK is the address of the stack-block for all the arguments,
4684 or 0 on a machine where arguments are pushed individually.
4685
4686 MAY_BE_ALLOCA nonzero says this could be a call to `alloca'
4687 so must be careful about how the stack is used.
4688
4689 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing
4690 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate
4691 that we need not worry about saving and restoring the stack.
4692
4693 FNDECL is the declaration of the function we are calling.
4694
4695 Return nonzero if this arg should cause sibcall failure,
4696 zero otherwise. */
4697
4698 static int
4699 store_one_arg (struct arg_data *arg, rtx argblock, int flags,
4700 int variable_size ATTRIBUTE_UNUSED, int reg_parm_stack_space)
4701 {
4702 tree pval = arg->tree_value;
4703 rtx reg = 0;
4704 int partial = 0;
4705 int used = 0;
4706 int i, lower_bound = 0, upper_bound = 0;
4707 int sibcall_failure = 0;
4708
4709 if (TREE_CODE (pval) == ERROR_MARK)
4710 return 1;
4711
4712 /* Push a new temporary level for any temporaries we make for
4713 this argument. */
4714 push_temp_slots ();
4715
4716 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL))
4717 {
4718 /* If this is being stored into a pre-allocated, fixed-size, stack area,
4719 save any previous data at that location. */
4720 if (argblock && ! variable_size && arg->stack)
4721 {
4722 if (ARGS_GROW_DOWNWARD)
4723 {
4724 /* stack_slot is negative, but we want to index stack_usage_map
4725 with positive values. */
4726 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4727 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
4728 else
4729 upper_bound = 0;
4730
4731 lower_bound = upper_bound - arg->locate.size.constant;
4732 }
4733 else
4734 {
4735 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
4736 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
4737 else
4738 lower_bound = 0;
4739
4740 upper_bound = lower_bound + arg->locate.size.constant;
4741 }
4742
4743 i = lower_bound;
4744 /* Don't worry about things in the fixed argument area;
4745 it has already been saved. */
4746 if (i < reg_parm_stack_space)
4747 i = reg_parm_stack_space;
4748 while (i < upper_bound && stack_usage_map[i] == 0)
4749 i++;
4750
4751 if (i < upper_bound)
4752 {
4753 /* We need to make a save area. */
4754 unsigned int size = arg->locate.size.constant * BITS_PER_UNIT;
4755 machine_mode save_mode = mode_for_size (size, MODE_INT, 1);
4756 rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0));
4757 rtx stack_area = gen_rtx_MEM (save_mode, adr);
4758
4759 if (save_mode == BLKmode)
4760 {
4761 arg->save_area
4762 = assign_temp (TREE_TYPE (arg->tree_value), 1, 1);
4763 preserve_temp_slots (arg->save_area);
4764 emit_block_move (validize_mem (copy_rtx (arg->save_area)),
4765 stack_area,
4766 GEN_INT (arg->locate.size.constant),
4767 BLOCK_OP_CALL_PARM);
4768 }
4769 else
4770 {
4771 arg->save_area = gen_reg_rtx (save_mode);
4772 emit_move_insn (arg->save_area, stack_area);
4773 }
4774 }
4775 }
4776 }
4777
4778 /* If this isn't going to be placed on both the stack and in registers,
4779 set up the register and number of words. */
4780 if (! arg->pass_on_stack)
4781 {
4782 if (flags & ECF_SIBCALL)
4783 reg = arg->tail_call_reg;
4784 else
4785 reg = arg->reg;
4786 partial = arg->partial;
4787 }
4788
4789 /* Being passed entirely in a register. We shouldn't be called in
4790 this case. */
4791 gcc_assert (reg == 0 || partial != 0);
4792
4793 /* If this arg needs special alignment, don't load the registers
4794 here. */
4795 if (arg->n_aligned_regs != 0)
4796 reg = 0;
4797
4798 /* If this is being passed partially in a register, we can't evaluate
4799 it directly into its stack slot. Otherwise, we can. */
4800 if (arg->value == 0)
4801 {
4802 /* stack_arg_under_construction is nonzero if a function argument is
4803 being evaluated directly into the outgoing argument list and
4804 expand_call must take special action to preserve the argument list
4805 if it is called recursively.
4806
4807 For scalar function arguments stack_usage_map is sufficient to
4808 determine which stack slots must be saved and restored. Scalar
4809 arguments in general have pass_on_stack == 0.
4810
4811 If this argument is initialized by a function which takes the
4812 address of the argument (a C++ constructor or a C function
4813 returning a BLKmode structure), then stack_usage_map is
4814 insufficient and expand_call must push the stack around the
4815 function call. Such arguments have pass_on_stack == 1.
4816
4817 Note that it is always safe to set stack_arg_under_construction,
4818 but this generates suboptimal code if set when not needed. */
4819
4820 if (arg->pass_on_stack)
4821 stack_arg_under_construction++;
4822
4823 arg->value = expand_expr (pval,
4824 (partial
4825 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode)
4826 ? NULL_RTX : arg->stack,
4827 VOIDmode, EXPAND_STACK_PARM);
4828
4829 /* If we are promoting object (or for any other reason) the mode
4830 doesn't agree, convert the mode. */
4831
4832 if (arg->mode != TYPE_MODE (TREE_TYPE (pval)))
4833 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)),
4834 arg->value, arg->unsignedp);
4835
4836 if (arg->pass_on_stack)
4837 stack_arg_under_construction--;
4838 }
4839
4840 /* Check for overlap with already clobbered argument area. */
4841 if ((flags & ECF_SIBCALL)
4842 && MEM_P (arg->value)
4843 && mem_overlaps_already_clobbered_arg_p (XEXP (arg->value, 0),
4844 arg->locate.size.constant))
4845 sibcall_failure = 1;
4846
4847 /* Don't allow anything left on stack from computation
4848 of argument to alloca. */
4849 if (flags & ECF_MAY_BE_ALLOCA)
4850 do_pending_stack_adjust ();
4851
4852 if (arg->value == arg->stack)
4853 /* If the value is already in the stack slot, we are done. */
4854 ;
4855 else if (arg->mode != BLKmode)
4856 {
4857 int size;
4858 unsigned int parm_align;
4859
4860 /* Argument is a scalar, not entirely passed in registers.
4861 (If part is passed in registers, arg->partial says how much
4862 and emit_push_insn will take care of putting it there.)
4863
4864 Push it, and if its size is less than the
4865 amount of space allocated to it,
4866 also bump stack pointer by the additional space.
4867 Note that in C the default argument promotions
4868 will prevent such mismatches. */
4869
4870 size = GET_MODE_SIZE (arg->mode);
4871 /* Compute how much space the push instruction will push.
4872 On many machines, pushing a byte will advance the stack
4873 pointer by a halfword. */
4874 #ifdef PUSH_ROUNDING
4875 size = PUSH_ROUNDING (size);
4876 #endif
4877 used = size;
4878
4879 /* Compute how much space the argument should get:
4880 round up to a multiple of the alignment for arguments. */
4881 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)))
4882 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
4883 / (PARM_BOUNDARY / BITS_PER_UNIT))
4884 * (PARM_BOUNDARY / BITS_PER_UNIT));
4885
4886 /* Compute the alignment of the pushed argument. */
4887 parm_align = arg->locate.boundary;
4888 if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward)
4889 {
4890 int pad = used - size;
4891 if (pad)
4892 {
4893 unsigned int pad_align = (pad & -pad) * BITS_PER_UNIT;
4894 parm_align = MIN (parm_align, pad_align);
4895 }
4896 }
4897
4898 /* This isn't already where we want it on the stack, so put it there.
4899 This can either be done with push or copy insns. */
4900 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
4901 parm_align, partial, reg, used - size, argblock,
4902 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
4903 ARGS_SIZE_RTX (arg->locate.alignment_pad));
4904
4905 /* Unless this is a partially-in-register argument, the argument is now
4906 in the stack. */
4907 if (partial == 0)
4908 arg->value = arg->stack;
4909 }
4910 else
4911 {
4912 /* BLKmode, at least partly to be pushed. */
4913
4914 unsigned int parm_align;
4915 int excess;
4916 rtx size_rtx;
4917
4918 /* Pushing a nonscalar.
4919 If part is passed in registers, PARTIAL says how much
4920 and emit_push_insn will take care of putting it there. */
4921
4922 /* Round its size up to a multiple
4923 of the allocation unit for arguments. */
4924
4925 if (arg->locate.size.var != 0)
4926 {
4927 excess = 0;
4928 size_rtx = ARGS_SIZE_RTX (arg->locate.size);
4929 }
4930 else
4931 {
4932 /* PUSH_ROUNDING has no effect on us, because emit_push_insn
4933 for BLKmode is careful to avoid it. */
4934 excess = (arg->locate.size.constant
4935 - int_size_in_bytes (TREE_TYPE (pval))
4936 + partial);
4937 size_rtx = expand_expr (size_in_bytes (TREE_TYPE (pval)),
4938 NULL_RTX, TYPE_MODE (sizetype),
4939 EXPAND_NORMAL);
4940 }
4941
4942 parm_align = arg->locate.boundary;
4943
4944 /* When an argument is padded down, the block is aligned to
4945 PARM_BOUNDARY, but the actual argument isn't. */
4946 if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward)
4947 {
4948 if (arg->locate.size.var)
4949 parm_align = BITS_PER_UNIT;
4950 else if (excess)
4951 {
4952 unsigned int excess_align = (excess & -excess) * BITS_PER_UNIT;
4953 parm_align = MIN (parm_align, excess_align);
4954 }
4955 }
4956
4957 if ((flags & ECF_SIBCALL) && MEM_P (arg->value))
4958 {
4959 /* emit_push_insn might not work properly if arg->value and
4960 argblock + arg->locate.offset areas overlap. */
4961 rtx x = arg->value;
4962 int i = 0;
4963
4964 if (XEXP (x, 0) == crtl->args.internal_arg_pointer
4965 || (GET_CODE (XEXP (x, 0)) == PLUS
4966 && XEXP (XEXP (x, 0), 0) ==
4967 crtl->args.internal_arg_pointer
4968 && CONST_INT_P (XEXP (XEXP (x, 0), 1))))
4969 {
4970 if (XEXP (x, 0) != crtl->args.internal_arg_pointer)
4971 i = INTVAL (XEXP (XEXP (x, 0), 1));
4972
4973 /* expand_call should ensure this. */
4974 gcc_assert (!arg->locate.offset.var
4975 && arg->locate.size.var == 0
4976 && CONST_INT_P (size_rtx));
4977
4978 if (arg->locate.offset.constant > i)
4979 {
4980 if (arg->locate.offset.constant < i + INTVAL (size_rtx))
4981 sibcall_failure = 1;
4982 }
4983 else if (arg->locate.offset.constant < i)
4984 {
4985 /* Use arg->locate.size.constant instead of size_rtx
4986 because we only care about the part of the argument
4987 on the stack. */
4988 if (i < (arg->locate.offset.constant
4989 + arg->locate.size.constant))
4990 sibcall_failure = 1;
4991 }
4992 else
4993 {
4994 /* Even though they appear to be at the same location,
4995 if part of the outgoing argument is in registers,
4996 they aren't really at the same location. Check for
4997 this by making sure that the incoming size is the
4998 same as the outgoing size. */
4999 if (arg->locate.size.constant != INTVAL (size_rtx))
5000 sibcall_failure = 1;
5001 }
5002 }
5003 }
5004
5005 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
5006 parm_align, partial, reg, excess, argblock,
5007 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
5008 ARGS_SIZE_RTX (arg->locate.alignment_pad));
5009
5010 /* Unless this is a partially-in-register argument, the argument is now
5011 in the stack.
5012
5013 ??? Unlike the case above, in which we want the actual
5014 address of the data, so that we can load it directly into a
5015 register, here we want the address of the stack slot, so that
5016 it's properly aligned for word-by-word copying or something
5017 like that. It's not clear that this is always correct. */
5018 if (partial == 0)
5019 arg->value = arg->stack_slot;
5020 }
5021
5022 if (arg->reg && GET_CODE (arg->reg) == PARALLEL)
5023 {
5024 tree type = TREE_TYPE (arg->tree_value);
5025 arg->parallel_value
5026 = emit_group_load_into_temps (arg->reg, arg->value, type,
5027 int_size_in_bytes (type));
5028 }
5029
5030 /* Mark all slots this store used. */
5031 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)
5032 && argblock && ! variable_size && arg->stack)
5033 for (i = lower_bound; i < upper_bound; i++)
5034 stack_usage_map[i] = 1;
5035
5036 /* Once we have pushed something, pops can't safely
5037 be deferred during the rest of the arguments. */
5038 NO_DEFER_POP;
5039
5040 /* Free any temporary slots made in processing this argument. */
5041 pop_temp_slots ();
5042
5043 return sibcall_failure;
5044 }
5045
5046 /* Nonzero if we do not know how to pass TYPE solely in registers. */
5047
5048 bool
5049 must_pass_in_stack_var_size (machine_mode mode ATTRIBUTE_UNUSED,
5050 const_tree type)
5051 {
5052 if (!type)
5053 return false;
5054
5055 /* If the type has variable size... */
5056 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
5057 return true;
5058
5059 /* If the type is marked as addressable (it is required
5060 to be constructed into the stack)... */
5061 if (TREE_ADDRESSABLE (type))
5062 return true;
5063
5064 return false;
5065 }
5066
5067 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one
5068 takes trailing padding of a structure into account. */
5069 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */
5070
5071 bool
5072 must_pass_in_stack_var_size_or_pad (machine_mode mode, const_tree type)
5073 {
5074 if (!type)
5075 return false;
5076
5077 /* If the type has variable size... */
5078 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
5079 return true;
5080
5081 /* If the type is marked as addressable (it is required
5082 to be constructed into the stack)... */
5083 if (TREE_ADDRESSABLE (type))
5084 return true;
5085
5086 /* If the padding and mode of the type is such that a copy into
5087 a register would put it into the wrong part of the register. */
5088 if (mode == BLKmode
5089 && int_size_in_bytes (type) % (PARM_BOUNDARY / BITS_PER_UNIT)
5090 && (FUNCTION_ARG_PADDING (mode, type)
5091 == (BYTES_BIG_ENDIAN ? upward : downward)))
5092 return true;
5093
5094 return false;
5095 }