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