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