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