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