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