1*e4b17023SJohn Marino /* Search an insn for pseudo regs that must be in hard regs and are not.
2*e4b17023SJohn Marino Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3*e4b17023SJohn Marino 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4*e4b17023SJohn Marino Free Software Foundation, Inc.
5*e4b17023SJohn Marino
6*e4b17023SJohn Marino This file is part of GCC.
7*e4b17023SJohn Marino
8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
9*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
10*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
11*e4b17023SJohn Marino version.
12*e4b17023SJohn Marino
13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16*e4b17023SJohn Marino for more details.
17*e4b17023SJohn Marino
18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see
20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */
21*e4b17023SJohn Marino
22*e4b17023SJohn Marino /* This file contains subroutines used only from the file reload1.c.
23*e4b17023SJohn Marino It knows how to scan one insn for operands and values
24*e4b17023SJohn Marino that need to be copied into registers to make valid code.
25*e4b17023SJohn Marino It also finds other operands and values which are valid
26*e4b17023SJohn Marino but for which equivalent values in registers exist and
27*e4b17023SJohn Marino ought to be used instead.
28*e4b17023SJohn Marino
29*e4b17023SJohn Marino Before processing the first insn of the function, call `init_reload'.
30*e4b17023SJohn Marino init_reload actually has to be called earlier anyway.
31*e4b17023SJohn Marino
32*e4b17023SJohn Marino To scan an insn, call `find_reloads'. This does two things:
33*e4b17023SJohn Marino 1. sets up tables describing which values must be reloaded
34*e4b17023SJohn Marino for this insn, and what kind of hard regs they must be reloaded into;
35*e4b17023SJohn Marino 2. optionally record the locations where those values appear in
36*e4b17023SJohn Marino the data, so they can be replaced properly later.
37*e4b17023SJohn Marino This is done only if the second arg to `find_reloads' is nonzero.
38*e4b17023SJohn Marino
39*e4b17023SJohn Marino The third arg to `find_reloads' specifies the number of levels
40*e4b17023SJohn Marino of indirect addressing supported by the machine. If it is zero,
41*e4b17023SJohn Marino indirect addressing is not valid. If it is one, (MEM (REG n))
42*e4b17023SJohn Marino is valid even if (REG n) did not get a hard register; if it is two,
43*e4b17023SJohn Marino (MEM (MEM (REG n))) is also valid even if (REG n) did not get a
44*e4b17023SJohn Marino hard register, and similarly for higher values.
45*e4b17023SJohn Marino
46*e4b17023SJohn Marino Then you must choose the hard regs to reload those pseudo regs into,
47*e4b17023SJohn Marino and generate appropriate load insns before this insn and perhaps
48*e4b17023SJohn Marino also store insns after this insn. Set up the array `reload_reg_rtx'
49*e4b17023SJohn Marino to contain the REG rtx's for the registers you used. In some
50*e4b17023SJohn Marino cases `find_reloads' will return a nonzero value in `reload_reg_rtx'
51*e4b17023SJohn Marino for certain reloads. Then that tells you which register to use,
52*e4b17023SJohn Marino so you do not need to allocate one. But you still do need to add extra
53*e4b17023SJohn Marino instructions to copy the value into and out of that register.
54*e4b17023SJohn Marino
55*e4b17023SJohn Marino Finally you must call `subst_reloads' to substitute the reload reg rtx's
56*e4b17023SJohn Marino into the locations already recorded.
57*e4b17023SJohn Marino
58*e4b17023SJohn Marino NOTE SIDE EFFECTS:
59*e4b17023SJohn Marino
60*e4b17023SJohn Marino find_reloads can alter the operands of the instruction it is called on.
61*e4b17023SJohn Marino
62*e4b17023SJohn Marino 1. Two operands of any sort may be interchanged, if they are in a
63*e4b17023SJohn Marino commutative instruction.
64*e4b17023SJohn Marino This happens only if find_reloads thinks the instruction will compile
65*e4b17023SJohn Marino better that way.
66*e4b17023SJohn Marino
67*e4b17023SJohn Marino 2. Pseudo-registers that are equivalent to constants are replaced
68*e4b17023SJohn Marino with those constants if they are not in hard registers.
69*e4b17023SJohn Marino
70*e4b17023SJohn Marino 1 happens every time find_reloads is called.
71*e4b17023SJohn Marino 2 happens only when REPLACE is 1, which is only when
72*e4b17023SJohn Marino actually doing the reloads, not when just counting them.
73*e4b17023SJohn Marino
74*e4b17023SJohn Marino Using a reload register for several reloads in one insn:
75*e4b17023SJohn Marino
76*e4b17023SJohn Marino When an insn has reloads, it is considered as having three parts:
77*e4b17023SJohn Marino the input reloads, the insn itself after reloading, and the output reloads.
78*e4b17023SJohn Marino Reloads of values used in memory addresses are often needed for only one part.
79*e4b17023SJohn Marino
80*e4b17023SJohn Marino When this is so, reload_when_needed records which part needs the reload.
81*e4b17023SJohn Marino Two reloads for different parts of the insn can share the same reload
82*e4b17023SJohn Marino register.
83*e4b17023SJohn Marino
84*e4b17023SJohn Marino When a reload is used for addresses in multiple parts, or when it is
85*e4b17023SJohn Marino an ordinary operand, it is classified as RELOAD_OTHER, and cannot share
86*e4b17023SJohn Marino a register with any other reload. */
87*e4b17023SJohn Marino
88*e4b17023SJohn Marino #define REG_OK_STRICT
89*e4b17023SJohn Marino
90*e4b17023SJohn Marino /* We do not enable this with ENABLE_CHECKING, since it is awfully slow. */
91*e4b17023SJohn Marino #undef DEBUG_RELOAD
92*e4b17023SJohn Marino
93*e4b17023SJohn Marino #include "config.h"
94*e4b17023SJohn Marino #include "system.h"
95*e4b17023SJohn Marino #include "coretypes.h"
96*e4b17023SJohn Marino #include "tm.h"
97*e4b17023SJohn Marino #include "rtl-error.h"
98*e4b17023SJohn Marino #include "tm_p.h"
99*e4b17023SJohn Marino #include "insn-config.h"
100*e4b17023SJohn Marino #include "expr.h"
101*e4b17023SJohn Marino #include "optabs.h"
102*e4b17023SJohn Marino #include "recog.h"
103*e4b17023SJohn Marino #include "df.h"
104*e4b17023SJohn Marino #include "reload.h"
105*e4b17023SJohn Marino #include "regs.h"
106*e4b17023SJohn Marino #include "addresses.h"
107*e4b17023SJohn Marino #include "hard-reg-set.h"
108*e4b17023SJohn Marino #include "flags.h"
109*e4b17023SJohn Marino #include "output.h"
110*e4b17023SJohn Marino #include "function.h"
111*e4b17023SJohn Marino #include "params.h"
112*e4b17023SJohn Marino #include "target.h"
113*e4b17023SJohn Marino #include "ira.h"
114*e4b17023SJohn Marino
115*e4b17023SJohn Marino /* True if X is a constant that can be forced into the constant pool.
116*e4b17023SJohn Marino MODE is the mode of the operand, or VOIDmode if not known. */
117*e4b17023SJohn Marino #define CONST_POOL_OK_P(MODE, X) \
118*e4b17023SJohn Marino ((MODE) != VOIDmode \
119*e4b17023SJohn Marino && CONSTANT_P (X) \
120*e4b17023SJohn Marino && GET_CODE (X) != HIGH \
121*e4b17023SJohn Marino && !targetm.cannot_force_const_mem (MODE, X))
122*e4b17023SJohn Marino
123*e4b17023SJohn Marino /* True if C is a non-empty register class that has too few registers
124*e4b17023SJohn Marino to be safely used as a reload target class. */
125*e4b17023SJohn Marino
126*e4b17023SJohn Marino static inline bool
small_register_class_p(reg_class_t rclass)127*e4b17023SJohn Marino small_register_class_p (reg_class_t rclass)
128*e4b17023SJohn Marino {
129*e4b17023SJohn Marino return (reg_class_size [(int) rclass] == 1
130*e4b17023SJohn Marino || (reg_class_size [(int) rclass] >= 1
131*e4b17023SJohn Marino && targetm.class_likely_spilled_p (rclass)));
132*e4b17023SJohn Marino }
133*e4b17023SJohn Marino
134*e4b17023SJohn Marino
135*e4b17023SJohn Marino /* All reloads of the current insn are recorded here. See reload.h for
136*e4b17023SJohn Marino comments. */
137*e4b17023SJohn Marino int n_reloads;
138*e4b17023SJohn Marino struct reload rld[MAX_RELOADS];
139*e4b17023SJohn Marino
140*e4b17023SJohn Marino /* All the "earlyclobber" operands of the current insn
141*e4b17023SJohn Marino are recorded here. */
142*e4b17023SJohn Marino int n_earlyclobbers;
143*e4b17023SJohn Marino rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
144*e4b17023SJohn Marino
145*e4b17023SJohn Marino int reload_n_operands;
146*e4b17023SJohn Marino
147*e4b17023SJohn Marino /* Replacing reloads.
148*e4b17023SJohn Marino
149*e4b17023SJohn Marino If `replace_reloads' is nonzero, then as each reload is recorded
150*e4b17023SJohn Marino an entry is made for it in the table `replacements'.
151*e4b17023SJohn Marino Then later `subst_reloads' can look through that table and
152*e4b17023SJohn Marino perform all the replacements needed. */
153*e4b17023SJohn Marino
154*e4b17023SJohn Marino /* Nonzero means record the places to replace. */
155*e4b17023SJohn Marino static int replace_reloads;
156*e4b17023SJohn Marino
157*e4b17023SJohn Marino /* Each replacement is recorded with a structure like this. */
158*e4b17023SJohn Marino struct replacement
159*e4b17023SJohn Marino {
160*e4b17023SJohn Marino rtx *where; /* Location to store in */
161*e4b17023SJohn Marino int what; /* which reload this is for */
162*e4b17023SJohn Marino enum machine_mode mode; /* mode it must have */
163*e4b17023SJohn Marino };
164*e4b17023SJohn Marino
165*e4b17023SJohn Marino static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
166*e4b17023SJohn Marino
167*e4b17023SJohn Marino /* Number of replacements currently recorded. */
168*e4b17023SJohn Marino static int n_replacements;
169*e4b17023SJohn Marino
170*e4b17023SJohn Marino /* Used to track what is modified by an operand. */
171*e4b17023SJohn Marino struct decomposition
172*e4b17023SJohn Marino {
173*e4b17023SJohn Marino int reg_flag; /* Nonzero if referencing a register. */
174*e4b17023SJohn Marino int safe; /* Nonzero if this can't conflict with anything. */
175*e4b17023SJohn Marino rtx base; /* Base address for MEM. */
176*e4b17023SJohn Marino HOST_WIDE_INT start; /* Starting offset or register number. */
177*e4b17023SJohn Marino HOST_WIDE_INT end; /* Ending offset or register number. */
178*e4b17023SJohn Marino };
179*e4b17023SJohn Marino
180*e4b17023SJohn Marino #ifdef SECONDARY_MEMORY_NEEDED
181*e4b17023SJohn Marino
182*e4b17023SJohn Marino /* Save MEMs needed to copy from one class of registers to another. One MEM
183*e4b17023SJohn Marino is used per mode, but normally only one or two modes are ever used.
184*e4b17023SJohn Marino
185*e4b17023SJohn Marino We keep two versions, before and after register elimination. The one
186*e4b17023SJohn Marino after register elimination is record separately for each operand. This
187*e4b17023SJohn Marino is done in case the address is not valid to be sure that we separately
188*e4b17023SJohn Marino reload each. */
189*e4b17023SJohn Marino
190*e4b17023SJohn Marino static rtx secondary_memlocs[NUM_MACHINE_MODES];
191*e4b17023SJohn Marino static rtx secondary_memlocs_elim[NUM_MACHINE_MODES][MAX_RECOG_OPERANDS];
192*e4b17023SJohn Marino static int secondary_memlocs_elim_used = 0;
193*e4b17023SJohn Marino #endif
194*e4b17023SJohn Marino
195*e4b17023SJohn Marino /* The instruction we are doing reloads for;
196*e4b17023SJohn Marino so we can test whether a register dies in it. */
197*e4b17023SJohn Marino static rtx this_insn;
198*e4b17023SJohn Marino
199*e4b17023SJohn Marino /* Nonzero if this instruction is a user-specified asm with operands. */
200*e4b17023SJohn Marino static int this_insn_is_asm;
201*e4b17023SJohn Marino
202*e4b17023SJohn Marino /* If hard_regs_live_known is nonzero,
203*e4b17023SJohn Marino we can tell which hard regs are currently live,
204*e4b17023SJohn Marino at least enough to succeed in choosing dummy reloads. */
205*e4b17023SJohn Marino static int hard_regs_live_known;
206*e4b17023SJohn Marino
207*e4b17023SJohn Marino /* Indexed by hard reg number,
208*e4b17023SJohn Marino element is nonnegative if hard reg has been spilled.
209*e4b17023SJohn Marino This vector is passed to `find_reloads' as an argument
210*e4b17023SJohn Marino and is not changed here. */
211*e4b17023SJohn Marino static short *static_reload_reg_p;
212*e4b17023SJohn Marino
213*e4b17023SJohn Marino /* Set to 1 in subst_reg_equivs if it changes anything. */
214*e4b17023SJohn Marino static int subst_reg_equivs_changed;
215*e4b17023SJohn Marino
216*e4b17023SJohn Marino /* On return from push_reload, holds the reload-number for the OUT
217*e4b17023SJohn Marino operand, which can be different for that from the input operand. */
218*e4b17023SJohn Marino static int output_reloadnum;
219*e4b17023SJohn Marino
220*e4b17023SJohn Marino /* Compare two RTX's. */
221*e4b17023SJohn Marino #define MATCHES(x, y) \
222*e4b17023SJohn Marino (x == y || (x != 0 && (REG_P (x) \
223*e4b17023SJohn Marino ? REG_P (y) && REGNO (x) == REGNO (y) \
224*e4b17023SJohn Marino : rtx_equal_p (x, y) && ! side_effects_p (x))))
225*e4b17023SJohn Marino
226*e4b17023SJohn Marino /* Indicates if two reloads purposes are for similar enough things that we
227*e4b17023SJohn Marino can merge their reloads. */
228*e4b17023SJohn Marino #define MERGABLE_RELOADS(when1, when2, op1, op2) \
229*e4b17023SJohn Marino ((when1) == RELOAD_OTHER || (when2) == RELOAD_OTHER \
230*e4b17023SJohn Marino || ((when1) == (when2) && (op1) == (op2)) \
231*e4b17023SJohn Marino || ((when1) == RELOAD_FOR_INPUT && (when2) == RELOAD_FOR_INPUT) \
232*e4b17023SJohn Marino || ((when1) == RELOAD_FOR_OPERAND_ADDRESS \
233*e4b17023SJohn Marino && (when2) == RELOAD_FOR_OPERAND_ADDRESS) \
234*e4b17023SJohn Marino || ((when1) == RELOAD_FOR_OTHER_ADDRESS \
235*e4b17023SJohn Marino && (when2) == RELOAD_FOR_OTHER_ADDRESS))
236*e4b17023SJohn Marino
237*e4b17023SJohn Marino /* Nonzero if these two reload purposes produce RELOAD_OTHER when merged. */
238*e4b17023SJohn Marino #define MERGE_TO_OTHER(when1, when2, op1, op2) \
239*e4b17023SJohn Marino ((when1) != (when2) \
240*e4b17023SJohn Marino || ! ((op1) == (op2) \
241*e4b17023SJohn Marino || (when1) == RELOAD_FOR_INPUT \
242*e4b17023SJohn Marino || (when1) == RELOAD_FOR_OPERAND_ADDRESS \
243*e4b17023SJohn Marino || (when1) == RELOAD_FOR_OTHER_ADDRESS))
244*e4b17023SJohn Marino
245*e4b17023SJohn Marino /* If we are going to reload an address, compute the reload type to
246*e4b17023SJohn Marino use. */
247*e4b17023SJohn Marino #define ADDR_TYPE(type) \
248*e4b17023SJohn Marino ((type) == RELOAD_FOR_INPUT_ADDRESS \
249*e4b17023SJohn Marino ? RELOAD_FOR_INPADDR_ADDRESS \
250*e4b17023SJohn Marino : ((type) == RELOAD_FOR_OUTPUT_ADDRESS \
251*e4b17023SJohn Marino ? RELOAD_FOR_OUTADDR_ADDRESS \
252*e4b17023SJohn Marino : (type)))
253*e4b17023SJohn Marino
254*e4b17023SJohn Marino static int push_secondary_reload (int, rtx, int, int, enum reg_class,
255*e4b17023SJohn Marino enum machine_mode, enum reload_type,
256*e4b17023SJohn Marino enum insn_code *, secondary_reload_info *);
257*e4b17023SJohn Marino static enum reg_class find_valid_class (enum machine_mode, enum machine_mode,
258*e4b17023SJohn Marino int, unsigned int);
259*e4b17023SJohn Marino static void push_replacement (rtx *, int, enum machine_mode);
260*e4b17023SJohn Marino static void dup_replacements (rtx *, rtx *);
261*e4b17023SJohn Marino static void combine_reloads (void);
262*e4b17023SJohn Marino static int find_reusable_reload (rtx *, rtx, enum reg_class,
263*e4b17023SJohn Marino enum reload_type, int, int);
264*e4b17023SJohn Marino static rtx find_dummy_reload (rtx, rtx, rtx *, rtx *, enum machine_mode,
265*e4b17023SJohn Marino enum machine_mode, reg_class_t, int, int);
266*e4b17023SJohn Marino static int hard_reg_set_here_p (unsigned int, unsigned int, rtx);
267*e4b17023SJohn Marino static struct decomposition decompose (rtx);
268*e4b17023SJohn Marino static int immune_p (rtx, rtx, struct decomposition);
269*e4b17023SJohn Marino static bool alternative_allows_const_pool_ref (rtx, const char *, int);
270*e4b17023SJohn Marino static rtx find_reloads_toplev (rtx, int, enum reload_type, int, int, rtx,
271*e4b17023SJohn Marino int *);
272*e4b17023SJohn Marino static rtx make_memloc (rtx, int);
273*e4b17023SJohn Marino static int maybe_memory_address_addr_space_p (enum machine_mode, rtx,
274*e4b17023SJohn Marino addr_space_t, rtx *);
275*e4b17023SJohn Marino static int find_reloads_address (enum machine_mode, rtx *, rtx, rtx *,
276*e4b17023SJohn Marino int, enum reload_type, int, rtx);
277*e4b17023SJohn Marino static rtx subst_reg_equivs (rtx, rtx);
278*e4b17023SJohn Marino static rtx subst_indexed_address (rtx);
279*e4b17023SJohn Marino static void update_auto_inc_notes (rtx, int, int);
280*e4b17023SJohn Marino static int find_reloads_address_1 (enum machine_mode, addr_space_t, rtx, int,
281*e4b17023SJohn Marino enum rtx_code, enum rtx_code, rtx *,
282*e4b17023SJohn Marino int, enum reload_type,int, rtx);
283*e4b17023SJohn Marino static void find_reloads_address_part (rtx, rtx *, enum reg_class,
284*e4b17023SJohn Marino enum machine_mode, int,
285*e4b17023SJohn Marino enum reload_type, int);
286*e4b17023SJohn Marino static rtx find_reloads_subreg_address (rtx, int, int, enum reload_type,
287*e4b17023SJohn Marino int, rtx, int *);
288*e4b17023SJohn Marino static void copy_replacements_1 (rtx *, rtx *, int);
289*e4b17023SJohn Marino static int find_inc_amount (rtx, rtx);
290*e4b17023SJohn Marino static int refers_to_mem_for_reload_p (rtx);
291*e4b17023SJohn Marino static int refers_to_regno_for_reload_p (unsigned int, unsigned int,
292*e4b17023SJohn Marino rtx, rtx *);
293*e4b17023SJohn Marino
294*e4b17023SJohn Marino /* Add NEW to reg_equiv_alt_mem_list[REGNO] if it's not present in the
295*e4b17023SJohn Marino list yet. */
296*e4b17023SJohn Marino
297*e4b17023SJohn Marino static void
push_reg_equiv_alt_mem(int regno,rtx mem)298*e4b17023SJohn Marino push_reg_equiv_alt_mem (int regno, rtx mem)
299*e4b17023SJohn Marino {
300*e4b17023SJohn Marino rtx it;
301*e4b17023SJohn Marino
302*e4b17023SJohn Marino for (it = reg_equiv_alt_mem_list (regno); it; it = XEXP (it, 1))
303*e4b17023SJohn Marino if (rtx_equal_p (XEXP (it, 0), mem))
304*e4b17023SJohn Marino return;
305*e4b17023SJohn Marino
306*e4b17023SJohn Marino reg_equiv_alt_mem_list (regno)
307*e4b17023SJohn Marino = alloc_EXPR_LIST (REG_EQUIV, mem,
308*e4b17023SJohn Marino reg_equiv_alt_mem_list (regno));
309*e4b17023SJohn Marino }
310*e4b17023SJohn Marino
311*e4b17023SJohn Marino /* Determine if any secondary reloads are needed for loading (if IN_P is
312*e4b17023SJohn Marino nonzero) or storing (if IN_P is zero) X to or from a reload register of
313*e4b17023SJohn Marino register class RELOAD_CLASS in mode RELOAD_MODE. If secondary reloads
314*e4b17023SJohn Marino are needed, push them.
315*e4b17023SJohn Marino
316*e4b17023SJohn Marino Return the reload number of the secondary reload we made, or -1 if
317*e4b17023SJohn Marino we didn't need one. *PICODE is set to the insn_code to use if we do
318*e4b17023SJohn Marino need a secondary reload. */
319*e4b17023SJohn Marino
320*e4b17023SJohn Marino static int
push_secondary_reload(int in_p,rtx x,int opnum,int optional,enum reg_class reload_class,enum machine_mode reload_mode,enum reload_type type,enum insn_code * picode,secondary_reload_info * prev_sri)321*e4b17023SJohn Marino push_secondary_reload (int in_p, rtx x, int opnum, int optional,
322*e4b17023SJohn Marino enum reg_class reload_class,
323*e4b17023SJohn Marino enum machine_mode reload_mode, enum reload_type type,
324*e4b17023SJohn Marino enum insn_code *picode, secondary_reload_info *prev_sri)
325*e4b17023SJohn Marino {
326*e4b17023SJohn Marino enum reg_class rclass = NO_REGS;
327*e4b17023SJohn Marino enum reg_class scratch_class;
328*e4b17023SJohn Marino enum machine_mode mode = reload_mode;
329*e4b17023SJohn Marino enum insn_code icode = CODE_FOR_nothing;
330*e4b17023SJohn Marino enum insn_code t_icode = CODE_FOR_nothing;
331*e4b17023SJohn Marino enum reload_type secondary_type;
332*e4b17023SJohn Marino int s_reload, t_reload = -1;
333*e4b17023SJohn Marino const char *scratch_constraint;
334*e4b17023SJohn Marino char letter;
335*e4b17023SJohn Marino secondary_reload_info sri;
336*e4b17023SJohn Marino
337*e4b17023SJohn Marino if (type == RELOAD_FOR_INPUT_ADDRESS
338*e4b17023SJohn Marino || type == RELOAD_FOR_OUTPUT_ADDRESS
339*e4b17023SJohn Marino || type == RELOAD_FOR_INPADDR_ADDRESS
340*e4b17023SJohn Marino || type == RELOAD_FOR_OUTADDR_ADDRESS)
341*e4b17023SJohn Marino secondary_type = type;
342*e4b17023SJohn Marino else
343*e4b17023SJohn Marino secondary_type = in_p ? RELOAD_FOR_INPUT_ADDRESS : RELOAD_FOR_OUTPUT_ADDRESS;
344*e4b17023SJohn Marino
345*e4b17023SJohn Marino *picode = CODE_FOR_nothing;
346*e4b17023SJohn Marino
347*e4b17023SJohn Marino /* If X is a paradoxical SUBREG, use the inner value to determine both the
348*e4b17023SJohn Marino mode and object being reloaded. */
349*e4b17023SJohn Marino if (paradoxical_subreg_p (x))
350*e4b17023SJohn Marino {
351*e4b17023SJohn Marino x = SUBREG_REG (x);
352*e4b17023SJohn Marino reload_mode = GET_MODE (x);
353*e4b17023SJohn Marino }
354*e4b17023SJohn Marino
355*e4b17023SJohn Marino /* If X is a pseudo-register that has an equivalent MEM (actually, if it
356*e4b17023SJohn Marino is still a pseudo-register by now, it *must* have an equivalent MEM
357*e4b17023SJohn Marino but we don't want to assume that), use that equivalent when seeing if
358*e4b17023SJohn Marino a secondary reload is needed since whether or not a reload is needed
359*e4b17023SJohn Marino might be sensitive to the form of the MEM. */
360*e4b17023SJohn Marino
361*e4b17023SJohn Marino if (REG_P (x) && REGNO (x) >= FIRST_PSEUDO_REGISTER
362*e4b17023SJohn Marino && reg_equiv_mem (REGNO (x)))
363*e4b17023SJohn Marino x = reg_equiv_mem (REGNO (x));
364*e4b17023SJohn Marino
365*e4b17023SJohn Marino sri.icode = CODE_FOR_nothing;
366*e4b17023SJohn Marino sri.prev_sri = prev_sri;
367*e4b17023SJohn Marino rclass = (enum reg_class) targetm.secondary_reload (in_p, x, reload_class,
368*e4b17023SJohn Marino reload_mode, &sri);
369*e4b17023SJohn Marino icode = (enum insn_code) sri.icode;
370*e4b17023SJohn Marino
371*e4b17023SJohn Marino /* If we don't need any secondary registers, done. */
372*e4b17023SJohn Marino if (rclass == NO_REGS && icode == CODE_FOR_nothing)
373*e4b17023SJohn Marino return -1;
374*e4b17023SJohn Marino
375*e4b17023SJohn Marino if (rclass != NO_REGS)
376*e4b17023SJohn Marino t_reload = push_secondary_reload (in_p, x, opnum, optional, rclass,
377*e4b17023SJohn Marino reload_mode, type, &t_icode, &sri);
378*e4b17023SJohn Marino
379*e4b17023SJohn Marino /* If we will be using an insn, the secondary reload is for a
380*e4b17023SJohn Marino scratch register. */
381*e4b17023SJohn Marino
382*e4b17023SJohn Marino if (icode != CODE_FOR_nothing)
383*e4b17023SJohn Marino {
384*e4b17023SJohn Marino /* If IN_P is nonzero, the reload register will be the output in
385*e4b17023SJohn Marino operand 0. If IN_P is zero, the reload register will be the input
386*e4b17023SJohn Marino in operand 1. Outputs should have an initial "=", which we must
387*e4b17023SJohn Marino skip. */
388*e4b17023SJohn Marino
389*e4b17023SJohn Marino /* ??? It would be useful to be able to handle only two, or more than
390*e4b17023SJohn Marino three, operands, but for now we can only handle the case of having
391*e4b17023SJohn Marino exactly three: output, input and one temp/scratch. */
392*e4b17023SJohn Marino gcc_assert (insn_data[(int) icode].n_operands == 3);
393*e4b17023SJohn Marino
394*e4b17023SJohn Marino /* ??? We currently have no way to represent a reload that needs
395*e4b17023SJohn Marino an icode to reload from an intermediate tertiary reload register.
396*e4b17023SJohn Marino We should probably have a new field in struct reload to tag a
397*e4b17023SJohn Marino chain of scratch operand reloads onto. */
398*e4b17023SJohn Marino gcc_assert (rclass == NO_REGS);
399*e4b17023SJohn Marino
400*e4b17023SJohn Marino scratch_constraint = insn_data[(int) icode].operand[2].constraint;
401*e4b17023SJohn Marino gcc_assert (*scratch_constraint == '=');
402*e4b17023SJohn Marino scratch_constraint++;
403*e4b17023SJohn Marino if (*scratch_constraint == '&')
404*e4b17023SJohn Marino scratch_constraint++;
405*e4b17023SJohn Marino letter = *scratch_constraint;
406*e4b17023SJohn Marino scratch_class = (letter == 'r' ? GENERAL_REGS
407*e4b17023SJohn Marino : REG_CLASS_FROM_CONSTRAINT ((unsigned char) letter,
408*e4b17023SJohn Marino scratch_constraint));
409*e4b17023SJohn Marino
410*e4b17023SJohn Marino rclass = scratch_class;
411*e4b17023SJohn Marino mode = insn_data[(int) icode].operand[2].mode;
412*e4b17023SJohn Marino }
413*e4b17023SJohn Marino
414*e4b17023SJohn Marino /* This case isn't valid, so fail. Reload is allowed to use the same
415*e4b17023SJohn Marino register for RELOAD_FOR_INPUT_ADDRESS and RELOAD_FOR_INPUT reloads, but
416*e4b17023SJohn Marino in the case of a secondary register, we actually need two different
417*e4b17023SJohn Marino registers for correct code. We fail here to prevent the possibility of
418*e4b17023SJohn Marino silently generating incorrect code later.
419*e4b17023SJohn Marino
420*e4b17023SJohn Marino The convention is that secondary input reloads are valid only if the
421*e4b17023SJohn Marino secondary_class is different from class. If you have such a case, you
422*e4b17023SJohn Marino can not use secondary reloads, you must work around the problem some
423*e4b17023SJohn Marino other way.
424*e4b17023SJohn Marino
425*e4b17023SJohn Marino Allow this when a reload_in/out pattern is being used. I.e. assume
426*e4b17023SJohn Marino that the generated code handles this case. */
427*e4b17023SJohn Marino
428*e4b17023SJohn Marino gcc_assert (!in_p || rclass != reload_class || icode != CODE_FOR_nothing
429*e4b17023SJohn Marino || t_icode != CODE_FOR_nothing);
430*e4b17023SJohn Marino
431*e4b17023SJohn Marino /* See if we can reuse an existing secondary reload. */
432*e4b17023SJohn Marino for (s_reload = 0; s_reload < n_reloads; s_reload++)
433*e4b17023SJohn Marino if (rld[s_reload].secondary_p
434*e4b17023SJohn Marino && (reg_class_subset_p (rclass, rld[s_reload].rclass)
435*e4b17023SJohn Marino || reg_class_subset_p (rld[s_reload].rclass, rclass))
436*e4b17023SJohn Marino && ((in_p && rld[s_reload].inmode == mode)
437*e4b17023SJohn Marino || (! in_p && rld[s_reload].outmode == mode))
438*e4b17023SJohn Marino && ((in_p && rld[s_reload].secondary_in_reload == t_reload)
439*e4b17023SJohn Marino || (! in_p && rld[s_reload].secondary_out_reload == t_reload))
440*e4b17023SJohn Marino && ((in_p && rld[s_reload].secondary_in_icode == t_icode)
441*e4b17023SJohn Marino || (! in_p && rld[s_reload].secondary_out_icode == t_icode))
442*e4b17023SJohn Marino && (small_register_class_p (rclass)
443*e4b17023SJohn Marino || targetm.small_register_classes_for_mode_p (VOIDmode))
444*e4b17023SJohn Marino && MERGABLE_RELOADS (secondary_type, rld[s_reload].when_needed,
445*e4b17023SJohn Marino opnum, rld[s_reload].opnum))
446*e4b17023SJohn Marino {
447*e4b17023SJohn Marino if (in_p)
448*e4b17023SJohn Marino rld[s_reload].inmode = mode;
449*e4b17023SJohn Marino if (! in_p)
450*e4b17023SJohn Marino rld[s_reload].outmode = mode;
451*e4b17023SJohn Marino
452*e4b17023SJohn Marino if (reg_class_subset_p (rclass, rld[s_reload].rclass))
453*e4b17023SJohn Marino rld[s_reload].rclass = rclass;
454*e4b17023SJohn Marino
455*e4b17023SJohn Marino rld[s_reload].opnum = MIN (rld[s_reload].opnum, opnum);
456*e4b17023SJohn Marino rld[s_reload].optional &= optional;
457*e4b17023SJohn Marino rld[s_reload].secondary_p = 1;
458*e4b17023SJohn Marino if (MERGE_TO_OTHER (secondary_type, rld[s_reload].when_needed,
459*e4b17023SJohn Marino opnum, rld[s_reload].opnum))
460*e4b17023SJohn Marino rld[s_reload].when_needed = RELOAD_OTHER;
461*e4b17023SJohn Marino
462*e4b17023SJohn Marino break;
463*e4b17023SJohn Marino }
464*e4b17023SJohn Marino
465*e4b17023SJohn Marino if (s_reload == n_reloads)
466*e4b17023SJohn Marino {
467*e4b17023SJohn Marino #ifdef SECONDARY_MEMORY_NEEDED
468*e4b17023SJohn Marino /* If we need a memory location to copy between the two reload regs,
469*e4b17023SJohn Marino set it up now. Note that we do the input case before making
470*e4b17023SJohn Marino the reload and the output case after. This is due to the
471*e4b17023SJohn Marino way reloads are output. */
472*e4b17023SJohn Marino
473*e4b17023SJohn Marino if (in_p && icode == CODE_FOR_nothing
474*e4b17023SJohn Marino && SECONDARY_MEMORY_NEEDED (rclass, reload_class, mode))
475*e4b17023SJohn Marino {
476*e4b17023SJohn Marino get_secondary_mem (x, reload_mode, opnum, type);
477*e4b17023SJohn Marino
478*e4b17023SJohn Marino /* We may have just added new reloads. Make sure we add
479*e4b17023SJohn Marino the new reload at the end. */
480*e4b17023SJohn Marino s_reload = n_reloads;
481*e4b17023SJohn Marino }
482*e4b17023SJohn Marino #endif
483*e4b17023SJohn Marino
484*e4b17023SJohn Marino /* We need to make a new secondary reload for this register class. */
485*e4b17023SJohn Marino rld[s_reload].in = rld[s_reload].out = 0;
486*e4b17023SJohn Marino rld[s_reload].rclass = rclass;
487*e4b17023SJohn Marino
488*e4b17023SJohn Marino rld[s_reload].inmode = in_p ? mode : VOIDmode;
489*e4b17023SJohn Marino rld[s_reload].outmode = ! in_p ? mode : VOIDmode;
490*e4b17023SJohn Marino rld[s_reload].reg_rtx = 0;
491*e4b17023SJohn Marino rld[s_reload].optional = optional;
492*e4b17023SJohn Marino rld[s_reload].inc = 0;
493*e4b17023SJohn Marino /* Maybe we could combine these, but it seems too tricky. */
494*e4b17023SJohn Marino rld[s_reload].nocombine = 1;
495*e4b17023SJohn Marino rld[s_reload].in_reg = 0;
496*e4b17023SJohn Marino rld[s_reload].out_reg = 0;
497*e4b17023SJohn Marino rld[s_reload].opnum = opnum;
498*e4b17023SJohn Marino rld[s_reload].when_needed = secondary_type;
499*e4b17023SJohn Marino rld[s_reload].secondary_in_reload = in_p ? t_reload : -1;
500*e4b17023SJohn Marino rld[s_reload].secondary_out_reload = ! in_p ? t_reload : -1;
501*e4b17023SJohn Marino rld[s_reload].secondary_in_icode = in_p ? t_icode : CODE_FOR_nothing;
502*e4b17023SJohn Marino rld[s_reload].secondary_out_icode
503*e4b17023SJohn Marino = ! in_p ? t_icode : CODE_FOR_nothing;
504*e4b17023SJohn Marino rld[s_reload].secondary_p = 1;
505*e4b17023SJohn Marino
506*e4b17023SJohn Marino n_reloads++;
507*e4b17023SJohn Marino
508*e4b17023SJohn Marino #ifdef SECONDARY_MEMORY_NEEDED
509*e4b17023SJohn Marino if (! in_p && icode == CODE_FOR_nothing
510*e4b17023SJohn Marino && SECONDARY_MEMORY_NEEDED (reload_class, rclass, mode))
511*e4b17023SJohn Marino get_secondary_mem (x, mode, opnum, type);
512*e4b17023SJohn Marino #endif
513*e4b17023SJohn Marino }
514*e4b17023SJohn Marino
515*e4b17023SJohn Marino *picode = icode;
516*e4b17023SJohn Marino return s_reload;
517*e4b17023SJohn Marino }
518*e4b17023SJohn Marino
519*e4b17023SJohn Marino /* If a secondary reload is needed, return its class. If both an intermediate
520*e4b17023SJohn Marino register and a scratch register is needed, we return the class of the
521*e4b17023SJohn Marino intermediate register. */
522*e4b17023SJohn Marino reg_class_t
secondary_reload_class(bool in_p,reg_class_t rclass,enum machine_mode mode,rtx x)523*e4b17023SJohn Marino secondary_reload_class (bool in_p, reg_class_t rclass, enum machine_mode mode,
524*e4b17023SJohn Marino rtx x)
525*e4b17023SJohn Marino {
526*e4b17023SJohn Marino enum insn_code icode;
527*e4b17023SJohn Marino secondary_reload_info sri;
528*e4b17023SJohn Marino
529*e4b17023SJohn Marino sri.icode = CODE_FOR_nothing;
530*e4b17023SJohn Marino sri.prev_sri = NULL;
531*e4b17023SJohn Marino rclass
532*e4b17023SJohn Marino = (enum reg_class) targetm.secondary_reload (in_p, x, rclass, mode, &sri);
533*e4b17023SJohn Marino icode = (enum insn_code) sri.icode;
534*e4b17023SJohn Marino
535*e4b17023SJohn Marino /* If there are no secondary reloads at all, we return NO_REGS.
536*e4b17023SJohn Marino If an intermediate register is needed, we return its class. */
537*e4b17023SJohn Marino if (icode == CODE_FOR_nothing || rclass != NO_REGS)
538*e4b17023SJohn Marino return rclass;
539*e4b17023SJohn Marino
540*e4b17023SJohn Marino /* No intermediate register is needed, but we have a special reload
541*e4b17023SJohn Marino pattern, which we assume for now needs a scratch register. */
542*e4b17023SJohn Marino return scratch_reload_class (icode);
543*e4b17023SJohn Marino }
544*e4b17023SJohn Marino
545*e4b17023SJohn Marino /* ICODE is the insn_code of a reload pattern. Check that it has exactly
546*e4b17023SJohn Marino three operands, verify that operand 2 is an output operand, and return
547*e4b17023SJohn Marino its register class.
548*e4b17023SJohn Marino ??? We'd like to be able to handle any pattern with at least 2 operands,
549*e4b17023SJohn Marino for zero or more scratch registers, but that needs more infrastructure. */
550*e4b17023SJohn Marino enum reg_class
scratch_reload_class(enum insn_code icode)551*e4b17023SJohn Marino scratch_reload_class (enum insn_code icode)
552*e4b17023SJohn Marino {
553*e4b17023SJohn Marino const char *scratch_constraint;
554*e4b17023SJohn Marino char scratch_letter;
555*e4b17023SJohn Marino enum reg_class rclass;
556*e4b17023SJohn Marino
557*e4b17023SJohn Marino gcc_assert (insn_data[(int) icode].n_operands == 3);
558*e4b17023SJohn Marino scratch_constraint = insn_data[(int) icode].operand[2].constraint;
559*e4b17023SJohn Marino gcc_assert (*scratch_constraint == '=');
560*e4b17023SJohn Marino scratch_constraint++;
561*e4b17023SJohn Marino if (*scratch_constraint == '&')
562*e4b17023SJohn Marino scratch_constraint++;
563*e4b17023SJohn Marino scratch_letter = *scratch_constraint;
564*e4b17023SJohn Marino if (scratch_letter == 'r')
565*e4b17023SJohn Marino return GENERAL_REGS;
566*e4b17023SJohn Marino rclass = REG_CLASS_FROM_CONSTRAINT ((unsigned char) scratch_letter,
567*e4b17023SJohn Marino scratch_constraint);
568*e4b17023SJohn Marino gcc_assert (rclass != NO_REGS);
569*e4b17023SJohn Marino return rclass;
570*e4b17023SJohn Marino }
571*e4b17023SJohn Marino
572*e4b17023SJohn Marino #ifdef SECONDARY_MEMORY_NEEDED
573*e4b17023SJohn Marino
574*e4b17023SJohn Marino /* Return a memory location that will be used to copy X in mode MODE.
575*e4b17023SJohn Marino If we haven't already made a location for this mode in this insn,
576*e4b17023SJohn Marino call find_reloads_address on the location being returned. */
577*e4b17023SJohn Marino
578*e4b17023SJohn Marino rtx
get_secondary_mem(rtx x ATTRIBUTE_UNUSED,enum machine_mode mode,int opnum,enum reload_type type)579*e4b17023SJohn Marino get_secondary_mem (rtx x ATTRIBUTE_UNUSED, enum machine_mode mode,
580*e4b17023SJohn Marino int opnum, enum reload_type type)
581*e4b17023SJohn Marino {
582*e4b17023SJohn Marino rtx loc;
583*e4b17023SJohn Marino int mem_valid;
584*e4b17023SJohn Marino
585*e4b17023SJohn Marino /* By default, if MODE is narrower than a word, widen it to a word.
586*e4b17023SJohn Marino This is required because most machines that require these memory
587*e4b17023SJohn Marino locations do not support short load and stores from all registers
588*e4b17023SJohn Marino (e.g., FP registers). */
589*e4b17023SJohn Marino
590*e4b17023SJohn Marino #ifdef SECONDARY_MEMORY_NEEDED_MODE
591*e4b17023SJohn Marino mode = SECONDARY_MEMORY_NEEDED_MODE (mode);
592*e4b17023SJohn Marino #else
593*e4b17023SJohn Marino if (GET_MODE_BITSIZE (mode) < BITS_PER_WORD && INTEGRAL_MODE_P (mode))
594*e4b17023SJohn Marino mode = mode_for_size (BITS_PER_WORD, GET_MODE_CLASS (mode), 0);
595*e4b17023SJohn Marino #endif
596*e4b17023SJohn Marino
597*e4b17023SJohn Marino /* If we already have made a MEM for this operand in MODE, return it. */
598*e4b17023SJohn Marino if (secondary_memlocs_elim[(int) mode][opnum] != 0)
599*e4b17023SJohn Marino return secondary_memlocs_elim[(int) mode][opnum];
600*e4b17023SJohn Marino
601*e4b17023SJohn Marino /* If this is the first time we've tried to get a MEM for this mode,
602*e4b17023SJohn Marino allocate a new one. `something_changed' in reload will get set
603*e4b17023SJohn Marino by noticing that the frame size has changed. */
604*e4b17023SJohn Marino
605*e4b17023SJohn Marino if (secondary_memlocs[(int) mode] == 0)
606*e4b17023SJohn Marino {
607*e4b17023SJohn Marino #ifdef SECONDARY_MEMORY_NEEDED_RTX
608*e4b17023SJohn Marino secondary_memlocs[(int) mode] = SECONDARY_MEMORY_NEEDED_RTX (mode);
609*e4b17023SJohn Marino #else
610*e4b17023SJohn Marino secondary_memlocs[(int) mode]
611*e4b17023SJohn Marino = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
612*e4b17023SJohn Marino #endif
613*e4b17023SJohn Marino }
614*e4b17023SJohn Marino
615*e4b17023SJohn Marino /* Get a version of the address doing any eliminations needed. If that
616*e4b17023SJohn Marino didn't give us a new MEM, make a new one if it isn't valid. */
617*e4b17023SJohn Marino
618*e4b17023SJohn Marino loc = eliminate_regs (secondary_memlocs[(int) mode], VOIDmode, NULL_RTX);
619*e4b17023SJohn Marino mem_valid = strict_memory_address_addr_space_p (mode, XEXP (loc, 0),
620*e4b17023SJohn Marino MEM_ADDR_SPACE (loc));
621*e4b17023SJohn Marino
622*e4b17023SJohn Marino if (! mem_valid && loc == secondary_memlocs[(int) mode])
623*e4b17023SJohn Marino loc = copy_rtx (loc);
624*e4b17023SJohn Marino
625*e4b17023SJohn Marino /* The only time the call below will do anything is if the stack
626*e4b17023SJohn Marino offset is too large. In that case IND_LEVELS doesn't matter, so we
627*e4b17023SJohn Marino can just pass a zero. Adjust the type to be the address of the
628*e4b17023SJohn Marino corresponding object. If the address was valid, save the eliminated
629*e4b17023SJohn Marino address. If it wasn't valid, we need to make a reload each time, so
630*e4b17023SJohn Marino don't save it. */
631*e4b17023SJohn Marino
632*e4b17023SJohn Marino if (! mem_valid)
633*e4b17023SJohn Marino {
634*e4b17023SJohn Marino type = (type == RELOAD_FOR_INPUT ? RELOAD_FOR_INPUT_ADDRESS
635*e4b17023SJohn Marino : type == RELOAD_FOR_OUTPUT ? RELOAD_FOR_OUTPUT_ADDRESS
636*e4b17023SJohn Marino : RELOAD_OTHER);
637*e4b17023SJohn Marino
638*e4b17023SJohn Marino find_reloads_address (mode, &loc, XEXP (loc, 0), &XEXP (loc, 0),
639*e4b17023SJohn Marino opnum, type, 0, 0);
640*e4b17023SJohn Marino }
641*e4b17023SJohn Marino
642*e4b17023SJohn Marino secondary_memlocs_elim[(int) mode][opnum] = loc;
643*e4b17023SJohn Marino if (secondary_memlocs_elim_used <= (int)mode)
644*e4b17023SJohn Marino secondary_memlocs_elim_used = (int)mode + 1;
645*e4b17023SJohn Marino return loc;
646*e4b17023SJohn Marino }
647*e4b17023SJohn Marino
648*e4b17023SJohn Marino /* Clear any secondary memory locations we've made. */
649*e4b17023SJohn Marino
650*e4b17023SJohn Marino void
clear_secondary_mem(void)651*e4b17023SJohn Marino clear_secondary_mem (void)
652*e4b17023SJohn Marino {
653*e4b17023SJohn Marino memset (secondary_memlocs, 0, sizeof secondary_memlocs);
654*e4b17023SJohn Marino }
655*e4b17023SJohn Marino #endif /* SECONDARY_MEMORY_NEEDED */
656*e4b17023SJohn Marino
657*e4b17023SJohn Marino
658*e4b17023SJohn Marino /* Find the largest class which has at least one register valid in
659*e4b17023SJohn Marino mode INNER, and which for every such register, that register number
660*e4b17023SJohn Marino plus N is also valid in OUTER (if in range) and is cheap to move
661*e4b17023SJohn Marino into REGNO. Such a class must exist. */
662*e4b17023SJohn Marino
663*e4b17023SJohn Marino static enum reg_class
find_valid_class(enum machine_mode outer ATTRIBUTE_UNUSED,enum machine_mode inner ATTRIBUTE_UNUSED,int n,unsigned int dest_regno ATTRIBUTE_UNUSED)664*e4b17023SJohn Marino find_valid_class (enum machine_mode outer ATTRIBUTE_UNUSED,
665*e4b17023SJohn Marino enum machine_mode inner ATTRIBUTE_UNUSED, int n,
666*e4b17023SJohn Marino unsigned int dest_regno ATTRIBUTE_UNUSED)
667*e4b17023SJohn Marino {
668*e4b17023SJohn Marino int best_cost = -1;
669*e4b17023SJohn Marino int rclass;
670*e4b17023SJohn Marino int regno;
671*e4b17023SJohn Marino enum reg_class best_class = NO_REGS;
672*e4b17023SJohn Marino enum reg_class dest_class ATTRIBUTE_UNUSED = REGNO_REG_CLASS (dest_regno);
673*e4b17023SJohn Marino unsigned int best_size = 0;
674*e4b17023SJohn Marino int cost;
675*e4b17023SJohn Marino
676*e4b17023SJohn Marino for (rclass = 1; rclass < N_REG_CLASSES; rclass++)
677*e4b17023SJohn Marino {
678*e4b17023SJohn Marino int bad = 0;
679*e4b17023SJohn Marino int good = 0;
680*e4b17023SJohn Marino for (regno = 0; regno < FIRST_PSEUDO_REGISTER - n && ! bad; regno++)
681*e4b17023SJohn Marino if (TEST_HARD_REG_BIT (reg_class_contents[rclass], regno))
682*e4b17023SJohn Marino {
683*e4b17023SJohn Marino if (HARD_REGNO_MODE_OK (regno, inner))
684*e4b17023SJohn Marino {
685*e4b17023SJohn Marino good = 1;
686*e4b17023SJohn Marino if (! TEST_HARD_REG_BIT (reg_class_contents[rclass], regno + n)
687*e4b17023SJohn Marino || ! HARD_REGNO_MODE_OK (regno + n, outer))
688*e4b17023SJohn Marino bad = 1;
689*e4b17023SJohn Marino }
690*e4b17023SJohn Marino }
691*e4b17023SJohn Marino
692*e4b17023SJohn Marino if (bad || !good)
693*e4b17023SJohn Marino continue;
694*e4b17023SJohn Marino cost = register_move_cost (outer, (enum reg_class) rclass, dest_class);
695*e4b17023SJohn Marino
696*e4b17023SJohn Marino if ((reg_class_size[rclass] > best_size
697*e4b17023SJohn Marino && (best_cost < 0 || best_cost >= cost))
698*e4b17023SJohn Marino || best_cost > cost)
699*e4b17023SJohn Marino {
700*e4b17023SJohn Marino best_class = (enum reg_class) rclass;
701*e4b17023SJohn Marino best_size = reg_class_size[rclass];
702*e4b17023SJohn Marino best_cost = register_move_cost (outer, (enum reg_class) rclass,
703*e4b17023SJohn Marino dest_class);
704*e4b17023SJohn Marino }
705*e4b17023SJohn Marino }
706*e4b17023SJohn Marino
707*e4b17023SJohn Marino gcc_assert (best_size != 0);
708*e4b17023SJohn Marino
709*e4b17023SJohn Marino return best_class;
710*e4b17023SJohn Marino }
711*e4b17023SJohn Marino
712*e4b17023SJohn Marino /* Return the number of a previously made reload that can be combined with
713*e4b17023SJohn Marino a new one, or n_reloads if none of the existing reloads can be used.
714*e4b17023SJohn Marino OUT, RCLASS, TYPE and OPNUM are the same arguments as passed to
715*e4b17023SJohn Marino push_reload, they determine the kind of the new reload that we try to
716*e4b17023SJohn Marino combine. P_IN points to the corresponding value of IN, which can be
717*e4b17023SJohn Marino modified by this function.
718*e4b17023SJohn Marino DONT_SHARE is nonzero if we can't share any input-only reload for IN. */
719*e4b17023SJohn Marino
720*e4b17023SJohn Marino static int
find_reusable_reload(rtx * p_in,rtx out,enum reg_class rclass,enum reload_type type,int opnum,int dont_share)721*e4b17023SJohn Marino find_reusable_reload (rtx *p_in, rtx out, enum reg_class rclass,
722*e4b17023SJohn Marino enum reload_type type, int opnum, int dont_share)
723*e4b17023SJohn Marino {
724*e4b17023SJohn Marino rtx in = *p_in;
725*e4b17023SJohn Marino int i;
726*e4b17023SJohn Marino /* We can't merge two reloads if the output of either one is
727*e4b17023SJohn Marino earlyclobbered. */
728*e4b17023SJohn Marino
729*e4b17023SJohn Marino if (earlyclobber_operand_p (out))
730*e4b17023SJohn Marino return n_reloads;
731*e4b17023SJohn Marino
732*e4b17023SJohn Marino /* We can use an existing reload if the class is right
733*e4b17023SJohn Marino and at least one of IN and OUT is a match
734*e4b17023SJohn Marino and the other is at worst neutral.
735*e4b17023SJohn Marino (A zero compared against anything is neutral.)
736*e4b17023SJohn Marino
737*e4b17023SJohn Marino For targets with small register classes, don't use existing reloads
738*e4b17023SJohn Marino unless they are for the same thing since that can cause us to need
739*e4b17023SJohn Marino more reload registers than we otherwise would. */
740*e4b17023SJohn Marino
741*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
742*e4b17023SJohn Marino if ((reg_class_subset_p (rclass, rld[i].rclass)
743*e4b17023SJohn Marino || reg_class_subset_p (rld[i].rclass, rclass))
744*e4b17023SJohn Marino /* If the existing reload has a register, it must fit our class. */
745*e4b17023SJohn Marino && (rld[i].reg_rtx == 0
746*e4b17023SJohn Marino || TEST_HARD_REG_BIT (reg_class_contents[(int) rclass],
747*e4b17023SJohn Marino true_regnum (rld[i].reg_rtx)))
748*e4b17023SJohn Marino && ((in != 0 && MATCHES (rld[i].in, in) && ! dont_share
749*e4b17023SJohn Marino && (out == 0 || rld[i].out == 0 || MATCHES (rld[i].out, out)))
750*e4b17023SJohn Marino || (out != 0 && MATCHES (rld[i].out, out)
751*e4b17023SJohn Marino && (in == 0 || rld[i].in == 0 || MATCHES (rld[i].in, in))))
752*e4b17023SJohn Marino && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
753*e4b17023SJohn Marino && (small_register_class_p (rclass)
754*e4b17023SJohn Marino || targetm.small_register_classes_for_mode_p (VOIDmode))
755*e4b17023SJohn Marino && MERGABLE_RELOADS (type, rld[i].when_needed, opnum, rld[i].opnum))
756*e4b17023SJohn Marino return i;
757*e4b17023SJohn Marino
758*e4b17023SJohn Marino /* Reloading a plain reg for input can match a reload to postincrement
759*e4b17023SJohn Marino that reg, since the postincrement's value is the right value.
760*e4b17023SJohn Marino Likewise, it can match a preincrement reload, since we regard
761*e4b17023SJohn Marino the preincrementation as happening before any ref in this insn
762*e4b17023SJohn Marino to that register. */
763*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
764*e4b17023SJohn Marino if ((reg_class_subset_p (rclass, rld[i].rclass)
765*e4b17023SJohn Marino || reg_class_subset_p (rld[i].rclass, rclass))
766*e4b17023SJohn Marino /* If the existing reload has a register, it must fit our
767*e4b17023SJohn Marino class. */
768*e4b17023SJohn Marino && (rld[i].reg_rtx == 0
769*e4b17023SJohn Marino || TEST_HARD_REG_BIT (reg_class_contents[(int) rclass],
770*e4b17023SJohn Marino true_regnum (rld[i].reg_rtx)))
771*e4b17023SJohn Marino && out == 0 && rld[i].out == 0 && rld[i].in != 0
772*e4b17023SJohn Marino && ((REG_P (in)
773*e4b17023SJohn Marino && GET_RTX_CLASS (GET_CODE (rld[i].in)) == RTX_AUTOINC
774*e4b17023SJohn Marino && MATCHES (XEXP (rld[i].in, 0), in))
775*e4b17023SJohn Marino || (REG_P (rld[i].in)
776*e4b17023SJohn Marino && GET_RTX_CLASS (GET_CODE (in)) == RTX_AUTOINC
777*e4b17023SJohn Marino && MATCHES (XEXP (in, 0), rld[i].in)))
778*e4b17023SJohn Marino && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
779*e4b17023SJohn Marino && (small_register_class_p (rclass)
780*e4b17023SJohn Marino || targetm.small_register_classes_for_mode_p (VOIDmode))
781*e4b17023SJohn Marino && MERGABLE_RELOADS (type, rld[i].when_needed,
782*e4b17023SJohn Marino opnum, rld[i].opnum))
783*e4b17023SJohn Marino {
784*e4b17023SJohn Marino /* Make sure reload_in ultimately has the increment,
785*e4b17023SJohn Marino not the plain register. */
786*e4b17023SJohn Marino if (REG_P (in))
787*e4b17023SJohn Marino *p_in = rld[i].in;
788*e4b17023SJohn Marino return i;
789*e4b17023SJohn Marino }
790*e4b17023SJohn Marino return n_reloads;
791*e4b17023SJohn Marino }
792*e4b17023SJohn Marino
793*e4b17023SJohn Marino /* Return true if X is a SUBREG that will need reloading of its SUBREG_REG
794*e4b17023SJohn Marino expression. MODE is the mode that X will be used in. OUTPUT is true if
795*e4b17023SJohn Marino the function is invoked for the output part of an enclosing reload. */
796*e4b17023SJohn Marino
797*e4b17023SJohn Marino static bool
reload_inner_reg_of_subreg(rtx x,enum machine_mode mode,bool output)798*e4b17023SJohn Marino reload_inner_reg_of_subreg (rtx x, enum machine_mode mode, bool output)
799*e4b17023SJohn Marino {
800*e4b17023SJohn Marino rtx inner;
801*e4b17023SJohn Marino
802*e4b17023SJohn Marino /* Only SUBREGs are problematical. */
803*e4b17023SJohn Marino if (GET_CODE (x) != SUBREG)
804*e4b17023SJohn Marino return false;
805*e4b17023SJohn Marino
806*e4b17023SJohn Marino inner = SUBREG_REG (x);
807*e4b17023SJohn Marino
808*e4b17023SJohn Marino /* If INNER is a constant or PLUS, then INNER will need reloading. */
809*e4b17023SJohn Marino if (CONSTANT_P (inner) || GET_CODE (inner) == PLUS)
810*e4b17023SJohn Marino return true;
811*e4b17023SJohn Marino
812*e4b17023SJohn Marino /* If INNER is not a hard register, then INNER will not need reloading. */
813*e4b17023SJohn Marino if (!(REG_P (inner) && HARD_REGISTER_P (inner)))
814*e4b17023SJohn Marino return false;
815*e4b17023SJohn Marino
816*e4b17023SJohn Marino /* If INNER is not ok for MODE, then INNER will need reloading. */
817*e4b17023SJohn Marino if (!HARD_REGNO_MODE_OK (subreg_regno (x), mode))
818*e4b17023SJohn Marino return true;
819*e4b17023SJohn Marino
820*e4b17023SJohn Marino /* If this is for an output, and the outer part is a word or smaller,
821*e4b17023SJohn Marino INNER is larger than a word and the number of registers in INNER is
822*e4b17023SJohn Marino not the same as the number of words in INNER, then INNER will need
823*e4b17023SJohn Marino reloading (with an in-out reload). */
824*e4b17023SJohn Marino return (output
825*e4b17023SJohn Marino && GET_MODE_SIZE (mode) <= UNITS_PER_WORD
826*e4b17023SJohn Marino && GET_MODE_SIZE (GET_MODE (inner)) > UNITS_PER_WORD
827*e4b17023SJohn Marino && ((GET_MODE_SIZE (GET_MODE (inner)) / UNITS_PER_WORD)
828*e4b17023SJohn Marino != (int) hard_regno_nregs[REGNO (inner)][GET_MODE (inner)]));
829*e4b17023SJohn Marino }
830*e4b17023SJohn Marino
831*e4b17023SJohn Marino /* Return nonzero if IN can be reloaded into REGNO with mode MODE without
832*e4b17023SJohn Marino requiring an extra reload register. The caller has already found that
833*e4b17023SJohn Marino IN contains some reference to REGNO, so check that we can produce the
834*e4b17023SJohn Marino new value in a single step. E.g. if we have
835*e4b17023SJohn Marino (set (reg r13) (plus (reg r13) (const int 1))), and there is an
836*e4b17023SJohn Marino instruction that adds one to a register, this should succeed.
837*e4b17023SJohn Marino However, if we have something like
838*e4b17023SJohn Marino (set (reg r13) (plus (reg r13) (const int 999))), and the constant 999
839*e4b17023SJohn Marino needs to be loaded into a register first, we need a separate reload
840*e4b17023SJohn Marino register.
841*e4b17023SJohn Marino Such PLUS reloads are generated by find_reload_address_part.
842*e4b17023SJohn Marino The out-of-range PLUS expressions are usually introduced in the instruction
843*e4b17023SJohn Marino patterns by register elimination and substituting pseudos without a home
844*e4b17023SJohn Marino by their function-invariant equivalences. */
845*e4b17023SJohn Marino static int
can_reload_into(rtx in,int regno,enum machine_mode mode)846*e4b17023SJohn Marino can_reload_into (rtx in, int regno, enum machine_mode mode)
847*e4b17023SJohn Marino {
848*e4b17023SJohn Marino rtx dst, test_insn;
849*e4b17023SJohn Marino int r = 0;
850*e4b17023SJohn Marino struct recog_data save_recog_data;
851*e4b17023SJohn Marino
852*e4b17023SJohn Marino /* For matching constraints, we often get notional input reloads where
853*e4b17023SJohn Marino we want to use the original register as the reload register. I.e.
854*e4b17023SJohn Marino technically this is a non-optional input-output reload, but IN is
855*e4b17023SJohn Marino already a valid register, and has been chosen as the reload register.
856*e4b17023SJohn Marino Speed this up, since it trivially works. */
857*e4b17023SJohn Marino if (REG_P (in))
858*e4b17023SJohn Marino return 1;
859*e4b17023SJohn Marino
860*e4b17023SJohn Marino /* To test MEMs properly, we'd have to take into account all the reloads
861*e4b17023SJohn Marino that are already scheduled, which can become quite complicated.
862*e4b17023SJohn Marino And since we've already handled address reloads for this MEM, it
863*e4b17023SJohn Marino should always succeed anyway. */
864*e4b17023SJohn Marino if (MEM_P (in))
865*e4b17023SJohn Marino return 1;
866*e4b17023SJohn Marino
867*e4b17023SJohn Marino /* If we can make a simple SET insn that does the job, everything should
868*e4b17023SJohn Marino be fine. */
869*e4b17023SJohn Marino dst = gen_rtx_REG (mode, regno);
870*e4b17023SJohn Marino test_insn = make_insn_raw (gen_rtx_SET (VOIDmode, dst, in));
871*e4b17023SJohn Marino save_recog_data = recog_data;
872*e4b17023SJohn Marino if (recog_memoized (test_insn) >= 0)
873*e4b17023SJohn Marino {
874*e4b17023SJohn Marino extract_insn (test_insn);
875*e4b17023SJohn Marino r = constrain_operands (1);
876*e4b17023SJohn Marino }
877*e4b17023SJohn Marino recog_data = save_recog_data;
878*e4b17023SJohn Marino return r;
879*e4b17023SJohn Marino }
880*e4b17023SJohn Marino
881*e4b17023SJohn Marino /* Record one reload that needs to be performed.
882*e4b17023SJohn Marino IN is an rtx saying where the data are to be found before this instruction.
883*e4b17023SJohn Marino OUT says where they must be stored after the instruction.
884*e4b17023SJohn Marino (IN is zero for data not read, and OUT is zero for data not written.)
885*e4b17023SJohn Marino INLOC and OUTLOC point to the places in the instructions where
886*e4b17023SJohn Marino IN and OUT were found.
887*e4b17023SJohn Marino If IN and OUT are both nonzero, it means the same register must be used
888*e4b17023SJohn Marino to reload both IN and OUT.
889*e4b17023SJohn Marino
890*e4b17023SJohn Marino RCLASS is a register class required for the reloaded data.
891*e4b17023SJohn Marino INMODE is the machine mode that the instruction requires
892*e4b17023SJohn Marino for the reg that replaces IN and OUTMODE is likewise for OUT.
893*e4b17023SJohn Marino
894*e4b17023SJohn Marino If IN is zero, then OUT's location and mode should be passed as
895*e4b17023SJohn Marino INLOC and INMODE.
896*e4b17023SJohn Marino
897*e4b17023SJohn Marino STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
898*e4b17023SJohn Marino
899*e4b17023SJohn Marino OPTIONAL nonzero means this reload does not need to be performed:
900*e4b17023SJohn Marino it can be discarded if that is more convenient.
901*e4b17023SJohn Marino
902*e4b17023SJohn Marino OPNUM and TYPE say what the purpose of this reload is.
903*e4b17023SJohn Marino
904*e4b17023SJohn Marino The return value is the reload-number for this reload.
905*e4b17023SJohn Marino
906*e4b17023SJohn Marino If both IN and OUT are nonzero, in some rare cases we might
907*e4b17023SJohn Marino want to make two separate reloads. (Actually we never do this now.)
908*e4b17023SJohn Marino Therefore, the reload-number for OUT is stored in
909*e4b17023SJohn Marino output_reloadnum when we return; the return value applies to IN.
910*e4b17023SJohn Marino Usually (presently always), when IN and OUT are nonzero,
911*e4b17023SJohn Marino the two reload-numbers are equal, but the caller should be careful to
912*e4b17023SJohn Marino distinguish them. */
913*e4b17023SJohn Marino
914*e4b17023SJohn Marino int
push_reload(rtx in,rtx out,rtx * inloc,rtx * outloc,enum reg_class rclass,enum machine_mode inmode,enum machine_mode outmode,int strict_low,int optional,int opnum,enum reload_type type)915*e4b17023SJohn Marino push_reload (rtx in, rtx out, rtx *inloc, rtx *outloc,
916*e4b17023SJohn Marino enum reg_class rclass, enum machine_mode inmode,
917*e4b17023SJohn Marino enum machine_mode outmode, int strict_low, int optional,
918*e4b17023SJohn Marino int opnum, enum reload_type type)
919*e4b17023SJohn Marino {
920*e4b17023SJohn Marino int i;
921*e4b17023SJohn Marino int dont_share = 0;
922*e4b17023SJohn Marino int dont_remove_subreg = 0;
923*e4b17023SJohn Marino #ifdef LIMIT_RELOAD_CLASS
924*e4b17023SJohn Marino rtx *in_subreg_loc = 0, *out_subreg_loc = 0;
925*e4b17023SJohn Marino #endif
926*e4b17023SJohn Marino int secondary_in_reload = -1, secondary_out_reload = -1;
927*e4b17023SJohn Marino enum insn_code secondary_in_icode = CODE_FOR_nothing;
928*e4b17023SJohn Marino enum insn_code secondary_out_icode = CODE_FOR_nothing;
929*e4b17023SJohn Marino
930*e4b17023SJohn Marino /* INMODE and/or OUTMODE could be VOIDmode if no mode
931*e4b17023SJohn Marino has been specified for the operand. In that case,
932*e4b17023SJohn Marino use the operand's mode as the mode to reload. */
933*e4b17023SJohn Marino if (inmode == VOIDmode && in != 0)
934*e4b17023SJohn Marino inmode = GET_MODE (in);
935*e4b17023SJohn Marino if (outmode == VOIDmode && out != 0)
936*e4b17023SJohn Marino outmode = GET_MODE (out);
937*e4b17023SJohn Marino
938*e4b17023SJohn Marino /* If find_reloads and friends until now missed to replace a pseudo
939*e4b17023SJohn Marino with a constant of reg_equiv_constant something went wrong
940*e4b17023SJohn Marino beforehand.
941*e4b17023SJohn Marino Note that it can't simply be done here if we missed it earlier
942*e4b17023SJohn Marino since the constant might need to be pushed into the literal pool
943*e4b17023SJohn Marino and the resulting memref would probably need further
944*e4b17023SJohn Marino reloading. */
945*e4b17023SJohn Marino if (in != 0 && REG_P (in))
946*e4b17023SJohn Marino {
947*e4b17023SJohn Marino int regno = REGNO (in);
948*e4b17023SJohn Marino
949*e4b17023SJohn Marino gcc_assert (regno < FIRST_PSEUDO_REGISTER
950*e4b17023SJohn Marino || reg_renumber[regno] >= 0
951*e4b17023SJohn Marino || reg_equiv_constant (regno) == NULL_RTX);
952*e4b17023SJohn Marino }
953*e4b17023SJohn Marino
954*e4b17023SJohn Marino /* reg_equiv_constant only contains constants which are obviously
955*e4b17023SJohn Marino not appropriate as destination. So if we would need to replace
956*e4b17023SJohn Marino the destination pseudo with a constant we are in real
957*e4b17023SJohn Marino trouble. */
958*e4b17023SJohn Marino if (out != 0 && REG_P (out))
959*e4b17023SJohn Marino {
960*e4b17023SJohn Marino int regno = REGNO (out);
961*e4b17023SJohn Marino
962*e4b17023SJohn Marino gcc_assert (regno < FIRST_PSEUDO_REGISTER
963*e4b17023SJohn Marino || reg_renumber[regno] >= 0
964*e4b17023SJohn Marino || reg_equiv_constant (regno) == NULL_RTX);
965*e4b17023SJohn Marino }
966*e4b17023SJohn Marino
967*e4b17023SJohn Marino /* If we have a read-write operand with an address side-effect,
968*e4b17023SJohn Marino change either IN or OUT so the side-effect happens only once. */
969*e4b17023SJohn Marino if (in != 0 && out != 0 && MEM_P (in) && rtx_equal_p (in, out))
970*e4b17023SJohn Marino switch (GET_CODE (XEXP (in, 0)))
971*e4b17023SJohn Marino {
972*e4b17023SJohn Marino case POST_INC: case POST_DEC: case POST_MODIFY:
973*e4b17023SJohn Marino in = replace_equiv_address_nv (in, XEXP (XEXP (in, 0), 0));
974*e4b17023SJohn Marino break;
975*e4b17023SJohn Marino
976*e4b17023SJohn Marino case PRE_INC: case PRE_DEC: case PRE_MODIFY:
977*e4b17023SJohn Marino out = replace_equiv_address_nv (out, XEXP (XEXP (out, 0), 0));
978*e4b17023SJohn Marino break;
979*e4b17023SJohn Marino
980*e4b17023SJohn Marino default:
981*e4b17023SJohn Marino break;
982*e4b17023SJohn Marino }
983*e4b17023SJohn Marino
984*e4b17023SJohn Marino /* If we are reloading a (SUBREG constant ...), really reload just the
985*e4b17023SJohn Marino inside expression in its own mode. Similarly for (SUBREG (PLUS ...)).
986*e4b17023SJohn Marino If we have (SUBREG:M1 (MEM:M2 ...) ...) (or an inner REG that is still
987*e4b17023SJohn Marino a pseudo and hence will become a MEM) with M1 wider than M2 and the
988*e4b17023SJohn Marino register is a pseudo, also reload the inside expression.
989*e4b17023SJohn Marino For machines that extend byte loads, do this for any SUBREG of a pseudo
990*e4b17023SJohn Marino where both M1 and M2 are a word or smaller, M1 is wider than M2, and
991*e4b17023SJohn Marino M2 is an integral mode that gets extended when loaded.
992*e4b17023SJohn Marino Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R
993*e4b17023SJohn Marino where either M1 is not valid for R or M2 is wider than a word but we
994*e4b17023SJohn Marino only need one register to store an M2-sized quantity in R.
995*e4b17023SJohn Marino (However, if OUT is nonzero, we need to reload the reg *and*
996*e4b17023SJohn Marino the subreg, so do nothing here, and let following statement handle it.)
997*e4b17023SJohn Marino
998*e4b17023SJohn Marino Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere;
999*e4b17023SJohn Marino we can't handle it here because CONST_INT does not indicate a mode.
1000*e4b17023SJohn Marino
1001*e4b17023SJohn Marino Similarly, we must reload the inside expression if we have a
1002*e4b17023SJohn Marino STRICT_LOW_PART (presumably, in == out in this case).
1003*e4b17023SJohn Marino
1004*e4b17023SJohn Marino Also reload the inner expression if it does not require a secondary
1005*e4b17023SJohn Marino reload but the SUBREG does.
1006*e4b17023SJohn Marino
1007*e4b17023SJohn Marino Finally, reload the inner expression if it is a register that is in
1008*e4b17023SJohn Marino the class whose registers cannot be referenced in a different size
1009*e4b17023SJohn Marino and M1 is not the same size as M2. If subreg_lowpart_p is false, we
1010*e4b17023SJohn Marino cannot reload just the inside since we might end up with the wrong
1011*e4b17023SJohn Marino register class. But if it is inside a STRICT_LOW_PART, we have
1012*e4b17023SJohn Marino no choice, so we hope we do get the right register class there. */
1013*e4b17023SJohn Marino
1014*e4b17023SJohn Marino if (in != 0 && GET_CODE (in) == SUBREG
1015*e4b17023SJohn Marino && (subreg_lowpart_p (in) || strict_low)
1016*e4b17023SJohn Marino #ifdef CANNOT_CHANGE_MODE_CLASS
1017*e4b17023SJohn Marino && !CANNOT_CHANGE_MODE_CLASS (GET_MODE (SUBREG_REG (in)), inmode, rclass)
1018*e4b17023SJohn Marino #endif
1019*e4b17023SJohn Marino && contains_reg_of_mode[(int) rclass][(int) GET_MODE (SUBREG_REG (in))]
1020*e4b17023SJohn Marino && (CONSTANT_P (SUBREG_REG (in))
1021*e4b17023SJohn Marino || GET_CODE (SUBREG_REG (in)) == PLUS
1022*e4b17023SJohn Marino || strict_low
1023*e4b17023SJohn Marino || (((REG_P (SUBREG_REG (in))
1024*e4b17023SJohn Marino && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER)
1025*e4b17023SJohn Marino || MEM_P (SUBREG_REG (in)))
1026*e4b17023SJohn Marino && ((GET_MODE_PRECISION (inmode)
1027*e4b17023SJohn Marino > GET_MODE_PRECISION (GET_MODE (SUBREG_REG (in))))
1028*e4b17023SJohn Marino #ifdef LOAD_EXTEND_OP
1029*e4b17023SJohn Marino || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
1030*e4b17023SJohn Marino && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1031*e4b17023SJohn Marino <= UNITS_PER_WORD)
1032*e4b17023SJohn Marino && (GET_MODE_PRECISION (inmode)
1033*e4b17023SJohn Marino > GET_MODE_PRECISION (GET_MODE (SUBREG_REG (in))))
1034*e4b17023SJohn Marino && INTEGRAL_MODE_P (GET_MODE (SUBREG_REG (in)))
1035*e4b17023SJohn Marino && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (in))) != UNKNOWN)
1036*e4b17023SJohn Marino #endif
1037*e4b17023SJohn Marino #ifdef WORD_REGISTER_OPERATIONS
1038*e4b17023SJohn Marino || ((GET_MODE_PRECISION (inmode)
1039*e4b17023SJohn Marino < GET_MODE_PRECISION (GET_MODE (SUBREG_REG (in))))
1040*e4b17023SJohn Marino && ((GET_MODE_SIZE (inmode) - 1) / UNITS_PER_WORD ==
1041*e4b17023SJohn Marino ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))) - 1)
1042*e4b17023SJohn Marino / UNITS_PER_WORD)))
1043*e4b17023SJohn Marino #endif
1044*e4b17023SJohn Marino ))
1045*e4b17023SJohn Marino || (REG_P (SUBREG_REG (in))
1046*e4b17023SJohn Marino && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1047*e4b17023SJohn Marino /* The case where out is nonzero
1048*e4b17023SJohn Marino is handled differently in the following statement. */
1049*e4b17023SJohn Marino && (out == 0 || subreg_lowpart_p (in))
1050*e4b17023SJohn Marino && ((GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
1051*e4b17023SJohn Marino && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1052*e4b17023SJohn Marino > UNITS_PER_WORD)
1053*e4b17023SJohn Marino && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1054*e4b17023SJohn Marino / UNITS_PER_WORD)
1055*e4b17023SJohn Marino != (int) hard_regno_nregs[REGNO (SUBREG_REG (in))]
1056*e4b17023SJohn Marino [GET_MODE (SUBREG_REG (in))]))
1057*e4b17023SJohn Marino || ! HARD_REGNO_MODE_OK (subreg_regno (in), inmode)))
1058*e4b17023SJohn Marino || (secondary_reload_class (1, rclass, inmode, in) != NO_REGS
1059*e4b17023SJohn Marino && (secondary_reload_class (1, rclass, GET_MODE (SUBREG_REG (in)),
1060*e4b17023SJohn Marino SUBREG_REG (in))
1061*e4b17023SJohn Marino == NO_REGS))
1062*e4b17023SJohn Marino #ifdef CANNOT_CHANGE_MODE_CLASS
1063*e4b17023SJohn Marino || (REG_P (SUBREG_REG (in))
1064*e4b17023SJohn Marino && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1065*e4b17023SJohn Marino && REG_CANNOT_CHANGE_MODE_P
1066*e4b17023SJohn Marino (REGNO (SUBREG_REG (in)), GET_MODE (SUBREG_REG (in)), inmode))
1067*e4b17023SJohn Marino #endif
1068*e4b17023SJohn Marino ))
1069*e4b17023SJohn Marino {
1070*e4b17023SJohn Marino #ifdef LIMIT_RELOAD_CLASS
1071*e4b17023SJohn Marino in_subreg_loc = inloc;
1072*e4b17023SJohn Marino #endif
1073*e4b17023SJohn Marino inloc = &SUBREG_REG (in);
1074*e4b17023SJohn Marino in = *inloc;
1075*e4b17023SJohn Marino #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
1076*e4b17023SJohn Marino if (MEM_P (in))
1077*e4b17023SJohn Marino /* This is supposed to happen only for paradoxical subregs made by
1078*e4b17023SJohn Marino combine.c. (SUBREG (MEM)) isn't supposed to occur other ways. */
1079*e4b17023SJohn Marino gcc_assert (GET_MODE_SIZE (GET_MODE (in)) <= GET_MODE_SIZE (inmode));
1080*e4b17023SJohn Marino #endif
1081*e4b17023SJohn Marino inmode = GET_MODE (in);
1082*e4b17023SJohn Marino }
1083*e4b17023SJohn Marino
1084*e4b17023SJohn Marino /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R
1085*e4b17023SJohn Marino where M1 is not valid for R if it was not handled by the code above.
1086*e4b17023SJohn Marino
1087*e4b17023SJohn Marino Similar issue for (SUBREG constant ...) if it was not handled by the
1088*e4b17023SJohn Marino code above. This can happen if SUBREG_BYTE != 0.
1089*e4b17023SJohn Marino
1090*e4b17023SJohn Marino However, we must reload the inner reg *as well as* the subreg in
1091*e4b17023SJohn Marino that case. */
1092*e4b17023SJohn Marino
1093*e4b17023SJohn Marino if (in != 0 && reload_inner_reg_of_subreg (in, inmode, false))
1094*e4b17023SJohn Marino {
1095*e4b17023SJohn Marino enum reg_class in_class = rclass;
1096*e4b17023SJohn Marino
1097*e4b17023SJohn Marino if (REG_P (SUBREG_REG (in)))
1098*e4b17023SJohn Marino in_class
1099*e4b17023SJohn Marino = find_valid_class (inmode, GET_MODE (SUBREG_REG (in)),
1100*e4b17023SJohn Marino subreg_regno_offset (REGNO (SUBREG_REG (in)),
1101*e4b17023SJohn Marino GET_MODE (SUBREG_REG (in)),
1102*e4b17023SJohn Marino SUBREG_BYTE (in),
1103*e4b17023SJohn Marino GET_MODE (in)),
1104*e4b17023SJohn Marino REGNO (SUBREG_REG (in)));
1105*e4b17023SJohn Marino
1106*e4b17023SJohn Marino /* This relies on the fact that emit_reload_insns outputs the
1107*e4b17023SJohn Marino instructions for input reloads of type RELOAD_OTHER in the same
1108*e4b17023SJohn Marino order as the reloads. Thus if the outer reload is also of type
1109*e4b17023SJohn Marino RELOAD_OTHER, we are guaranteed that this inner reload will be
1110*e4b17023SJohn Marino output before the outer reload. */
1111*e4b17023SJohn Marino push_reload (SUBREG_REG (in), NULL_RTX, &SUBREG_REG (in), (rtx *) 0,
1112*e4b17023SJohn Marino in_class, VOIDmode, VOIDmode, 0, 0, opnum, type);
1113*e4b17023SJohn Marino dont_remove_subreg = 1;
1114*e4b17023SJohn Marino }
1115*e4b17023SJohn Marino
1116*e4b17023SJohn Marino /* Similarly for paradoxical and problematical SUBREGs on the output.
1117*e4b17023SJohn Marino Note that there is no reason we need worry about the previous value
1118*e4b17023SJohn Marino of SUBREG_REG (out); even if wider than out, storing in a subreg is
1119*e4b17023SJohn Marino entitled to clobber it all (except in the case of a word mode subreg
1120*e4b17023SJohn Marino or of a STRICT_LOW_PART, in that latter case the constraint should
1121*e4b17023SJohn Marino label it input-output.) */
1122*e4b17023SJohn Marino if (out != 0 && GET_CODE (out) == SUBREG
1123*e4b17023SJohn Marino && (subreg_lowpart_p (out) || strict_low)
1124*e4b17023SJohn Marino #ifdef CANNOT_CHANGE_MODE_CLASS
1125*e4b17023SJohn Marino && !CANNOT_CHANGE_MODE_CLASS (GET_MODE (SUBREG_REG (out)), outmode, rclass)
1126*e4b17023SJohn Marino #endif
1127*e4b17023SJohn Marino && contains_reg_of_mode[(int) rclass][(int) GET_MODE (SUBREG_REG (out))]
1128*e4b17023SJohn Marino && (CONSTANT_P (SUBREG_REG (out))
1129*e4b17023SJohn Marino || strict_low
1130*e4b17023SJohn Marino || (((REG_P (SUBREG_REG (out))
1131*e4b17023SJohn Marino && REGNO (SUBREG_REG (out)) >= FIRST_PSEUDO_REGISTER)
1132*e4b17023SJohn Marino || MEM_P (SUBREG_REG (out)))
1133*e4b17023SJohn Marino && ((GET_MODE_PRECISION (outmode)
1134*e4b17023SJohn Marino > GET_MODE_PRECISION (GET_MODE (SUBREG_REG (out))))
1135*e4b17023SJohn Marino #ifdef WORD_REGISTER_OPERATIONS
1136*e4b17023SJohn Marino || ((GET_MODE_PRECISION (outmode)
1137*e4b17023SJohn Marino < GET_MODE_PRECISION (GET_MODE (SUBREG_REG (out))))
1138*e4b17023SJohn Marino && ((GET_MODE_SIZE (outmode) - 1) / UNITS_PER_WORD ==
1139*e4b17023SJohn Marino ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))) - 1)
1140*e4b17023SJohn Marino / UNITS_PER_WORD)))
1141*e4b17023SJohn Marino #endif
1142*e4b17023SJohn Marino ))
1143*e4b17023SJohn Marino || (REG_P (SUBREG_REG (out))
1144*e4b17023SJohn Marino && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1145*e4b17023SJohn Marino /* The case of a word mode subreg
1146*e4b17023SJohn Marino is handled differently in the following statement. */
1147*e4b17023SJohn Marino && ! (GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
1148*e4b17023SJohn Marino && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1149*e4b17023SJohn Marino > UNITS_PER_WORD))
1150*e4b17023SJohn Marino && ! HARD_REGNO_MODE_OK (subreg_regno (out), outmode))
1151*e4b17023SJohn Marino || (secondary_reload_class (0, rclass, outmode, out) != NO_REGS
1152*e4b17023SJohn Marino && (secondary_reload_class (0, rclass, GET_MODE (SUBREG_REG (out)),
1153*e4b17023SJohn Marino SUBREG_REG (out))
1154*e4b17023SJohn Marino == NO_REGS))
1155*e4b17023SJohn Marino #ifdef CANNOT_CHANGE_MODE_CLASS
1156*e4b17023SJohn Marino || (REG_P (SUBREG_REG (out))
1157*e4b17023SJohn Marino && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1158*e4b17023SJohn Marino && REG_CANNOT_CHANGE_MODE_P (REGNO (SUBREG_REG (out)),
1159*e4b17023SJohn Marino GET_MODE (SUBREG_REG (out)),
1160*e4b17023SJohn Marino outmode))
1161*e4b17023SJohn Marino #endif
1162*e4b17023SJohn Marino ))
1163*e4b17023SJohn Marino {
1164*e4b17023SJohn Marino #ifdef LIMIT_RELOAD_CLASS
1165*e4b17023SJohn Marino out_subreg_loc = outloc;
1166*e4b17023SJohn Marino #endif
1167*e4b17023SJohn Marino outloc = &SUBREG_REG (out);
1168*e4b17023SJohn Marino out = *outloc;
1169*e4b17023SJohn Marino #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
1170*e4b17023SJohn Marino gcc_assert (!MEM_P (out)
1171*e4b17023SJohn Marino || GET_MODE_SIZE (GET_MODE (out))
1172*e4b17023SJohn Marino <= GET_MODE_SIZE (outmode));
1173*e4b17023SJohn Marino #endif
1174*e4b17023SJohn Marino outmode = GET_MODE (out);
1175*e4b17023SJohn Marino }
1176*e4b17023SJohn Marino
1177*e4b17023SJohn Marino /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R
1178*e4b17023SJohn Marino where either M1 is not valid for R or M2 is wider than a word but we
1179*e4b17023SJohn Marino only need one register to store an M2-sized quantity in R.
1180*e4b17023SJohn Marino
1181*e4b17023SJohn Marino However, we must reload the inner reg *as well as* the subreg in
1182*e4b17023SJohn Marino that case and the inner reg is an in-out reload. */
1183*e4b17023SJohn Marino
1184*e4b17023SJohn Marino if (out != 0 && reload_inner_reg_of_subreg (out, outmode, true))
1185*e4b17023SJohn Marino {
1186*e4b17023SJohn Marino enum reg_class in_out_class
1187*e4b17023SJohn Marino = find_valid_class (outmode, GET_MODE (SUBREG_REG (out)),
1188*e4b17023SJohn Marino subreg_regno_offset (REGNO (SUBREG_REG (out)),
1189*e4b17023SJohn Marino GET_MODE (SUBREG_REG (out)),
1190*e4b17023SJohn Marino SUBREG_BYTE (out),
1191*e4b17023SJohn Marino GET_MODE (out)),
1192*e4b17023SJohn Marino REGNO (SUBREG_REG (out)));
1193*e4b17023SJohn Marino
1194*e4b17023SJohn Marino /* This relies on the fact that emit_reload_insns outputs the
1195*e4b17023SJohn Marino instructions for output reloads of type RELOAD_OTHER in reverse
1196*e4b17023SJohn Marino order of the reloads. Thus if the outer reload is also of type
1197*e4b17023SJohn Marino RELOAD_OTHER, we are guaranteed that this inner reload will be
1198*e4b17023SJohn Marino output after the outer reload. */
1199*e4b17023SJohn Marino push_reload (SUBREG_REG (out), SUBREG_REG (out), &SUBREG_REG (out),
1200*e4b17023SJohn Marino &SUBREG_REG (out), in_out_class, VOIDmode, VOIDmode,
1201*e4b17023SJohn Marino 0, 0, opnum, RELOAD_OTHER);
1202*e4b17023SJohn Marino dont_remove_subreg = 1;
1203*e4b17023SJohn Marino }
1204*e4b17023SJohn Marino
1205*e4b17023SJohn Marino /* If IN appears in OUT, we can't share any input-only reload for IN. */
1206*e4b17023SJohn Marino if (in != 0 && out != 0 && MEM_P (out)
1207*e4b17023SJohn Marino && (REG_P (in) || MEM_P (in) || GET_CODE (in) == PLUS)
1208*e4b17023SJohn Marino && reg_overlap_mentioned_for_reload_p (in, XEXP (out, 0)))
1209*e4b17023SJohn Marino dont_share = 1;
1210*e4b17023SJohn Marino
1211*e4b17023SJohn Marino /* If IN is a SUBREG of a hard register, make a new REG. This
1212*e4b17023SJohn Marino simplifies some of the cases below. */
1213*e4b17023SJohn Marino
1214*e4b17023SJohn Marino if (in != 0 && GET_CODE (in) == SUBREG && REG_P (SUBREG_REG (in))
1215*e4b17023SJohn Marino && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1216*e4b17023SJohn Marino && ! dont_remove_subreg)
1217*e4b17023SJohn Marino in = gen_rtx_REG (GET_MODE (in), subreg_regno (in));
1218*e4b17023SJohn Marino
1219*e4b17023SJohn Marino /* Similarly for OUT. */
1220*e4b17023SJohn Marino if (out != 0 && GET_CODE (out) == SUBREG
1221*e4b17023SJohn Marino && REG_P (SUBREG_REG (out))
1222*e4b17023SJohn Marino && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1223*e4b17023SJohn Marino && ! dont_remove_subreg)
1224*e4b17023SJohn Marino out = gen_rtx_REG (GET_MODE (out), subreg_regno (out));
1225*e4b17023SJohn Marino
1226*e4b17023SJohn Marino /* Narrow down the class of register wanted if that is
1227*e4b17023SJohn Marino desirable on this machine for efficiency. */
1228*e4b17023SJohn Marino {
1229*e4b17023SJohn Marino reg_class_t preferred_class = rclass;
1230*e4b17023SJohn Marino
1231*e4b17023SJohn Marino if (in != 0)
1232*e4b17023SJohn Marino preferred_class = targetm.preferred_reload_class (in, rclass);
1233*e4b17023SJohn Marino
1234*e4b17023SJohn Marino /* Output reloads may need analogous treatment, different in detail. */
1235*e4b17023SJohn Marino if (out != 0)
1236*e4b17023SJohn Marino preferred_class
1237*e4b17023SJohn Marino = targetm.preferred_output_reload_class (out, preferred_class);
1238*e4b17023SJohn Marino
1239*e4b17023SJohn Marino /* Discard what the target said if we cannot do it. */
1240*e4b17023SJohn Marino if (preferred_class != NO_REGS
1241*e4b17023SJohn Marino || (optional && type == RELOAD_FOR_OUTPUT))
1242*e4b17023SJohn Marino rclass = (enum reg_class) preferred_class;
1243*e4b17023SJohn Marino }
1244*e4b17023SJohn Marino
1245*e4b17023SJohn Marino /* Make sure we use a class that can handle the actual pseudo
1246*e4b17023SJohn Marino inside any subreg. For example, on the 386, QImode regs
1247*e4b17023SJohn Marino can appear within SImode subregs. Although GENERAL_REGS
1248*e4b17023SJohn Marino can handle SImode, QImode needs a smaller class. */
1249*e4b17023SJohn Marino #ifdef LIMIT_RELOAD_CLASS
1250*e4b17023SJohn Marino if (in_subreg_loc)
1251*e4b17023SJohn Marino rclass = LIMIT_RELOAD_CLASS (inmode, rclass);
1252*e4b17023SJohn Marino else if (in != 0 && GET_CODE (in) == SUBREG)
1253*e4b17023SJohn Marino rclass = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (in)), rclass);
1254*e4b17023SJohn Marino
1255*e4b17023SJohn Marino if (out_subreg_loc)
1256*e4b17023SJohn Marino rclass = LIMIT_RELOAD_CLASS (outmode, rclass);
1257*e4b17023SJohn Marino if (out != 0 && GET_CODE (out) == SUBREG)
1258*e4b17023SJohn Marino rclass = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (out)), rclass);
1259*e4b17023SJohn Marino #endif
1260*e4b17023SJohn Marino
1261*e4b17023SJohn Marino /* Verify that this class is at least possible for the mode that
1262*e4b17023SJohn Marino is specified. */
1263*e4b17023SJohn Marino if (this_insn_is_asm)
1264*e4b17023SJohn Marino {
1265*e4b17023SJohn Marino enum machine_mode mode;
1266*e4b17023SJohn Marino if (GET_MODE_SIZE (inmode) > GET_MODE_SIZE (outmode))
1267*e4b17023SJohn Marino mode = inmode;
1268*e4b17023SJohn Marino else
1269*e4b17023SJohn Marino mode = outmode;
1270*e4b17023SJohn Marino if (mode == VOIDmode)
1271*e4b17023SJohn Marino {
1272*e4b17023SJohn Marino error_for_asm (this_insn, "cannot reload integer constant "
1273*e4b17023SJohn Marino "operand in %<asm%>");
1274*e4b17023SJohn Marino mode = word_mode;
1275*e4b17023SJohn Marino if (in != 0)
1276*e4b17023SJohn Marino inmode = word_mode;
1277*e4b17023SJohn Marino if (out != 0)
1278*e4b17023SJohn Marino outmode = word_mode;
1279*e4b17023SJohn Marino }
1280*e4b17023SJohn Marino for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1281*e4b17023SJohn Marino if (HARD_REGNO_MODE_OK (i, mode)
1282*e4b17023SJohn Marino && in_hard_reg_set_p (reg_class_contents[(int) rclass], mode, i))
1283*e4b17023SJohn Marino break;
1284*e4b17023SJohn Marino if (i == FIRST_PSEUDO_REGISTER)
1285*e4b17023SJohn Marino {
1286*e4b17023SJohn Marino error_for_asm (this_insn, "impossible register constraint "
1287*e4b17023SJohn Marino "in %<asm%>");
1288*e4b17023SJohn Marino /* Avoid further trouble with this insn. */
1289*e4b17023SJohn Marino PATTERN (this_insn) = gen_rtx_USE (VOIDmode, const0_rtx);
1290*e4b17023SJohn Marino /* We used to continue here setting class to ALL_REGS, but it triggers
1291*e4b17023SJohn Marino sanity check on i386 for:
1292*e4b17023SJohn Marino void foo(long double d)
1293*e4b17023SJohn Marino {
1294*e4b17023SJohn Marino asm("" :: "a" (d));
1295*e4b17023SJohn Marino }
1296*e4b17023SJohn Marino Returning zero here ought to be safe as we take care in
1297*e4b17023SJohn Marino find_reloads to not process the reloads when instruction was
1298*e4b17023SJohn Marino replaced by USE. */
1299*e4b17023SJohn Marino
1300*e4b17023SJohn Marino return 0;
1301*e4b17023SJohn Marino }
1302*e4b17023SJohn Marino }
1303*e4b17023SJohn Marino
1304*e4b17023SJohn Marino /* Optional output reloads are always OK even if we have no register class,
1305*e4b17023SJohn Marino since the function of these reloads is only to have spill_reg_store etc.
1306*e4b17023SJohn Marino set, so that the storing insn can be deleted later. */
1307*e4b17023SJohn Marino gcc_assert (rclass != NO_REGS
1308*e4b17023SJohn Marino || (optional != 0 && type == RELOAD_FOR_OUTPUT));
1309*e4b17023SJohn Marino
1310*e4b17023SJohn Marino i = find_reusable_reload (&in, out, rclass, type, opnum, dont_share);
1311*e4b17023SJohn Marino
1312*e4b17023SJohn Marino if (i == n_reloads)
1313*e4b17023SJohn Marino {
1314*e4b17023SJohn Marino /* See if we need a secondary reload register to move between CLASS
1315*e4b17023SJohn Marino and IN or CLASS and OUT. Get the icode and push any required reloads
1316*e4b17023SJohn Marino needed for each of them if so. */
1317*e4b17023SJohn Marino
1318*e4b17023SJohn Marino if (in != 0)
1319*e4b17023SJohn Marino secondary_in_reload
1320*e4b17023SJohn Marino = push_secondary_reload (1, in, opnum, optional, rclass, inmode, type,
1321*e4b17023SJohn Marino &secondary_in_icode, NULL);
1322*e4b17023SJohn Marino if (out != 0 && GET_CODE (out) != SCRATCH)
1323*e4b17023SJohn Marino secondary_out_reload
1324*e4b17023SJohn Marino = push_secondary_reload (0, out, opnum, optional, rclass, outmode,
1325*e4b17023SJohn Marino type, &secondary_out_icode, NULL);
1326*e4b17023SJohn Marino
1327*e4b17023SJohn Marino /* We found no existing reload suitable for re-use.
1328*e4b17023SJohn Marino So add an additional reload. */
1329*e4b17023SJohn Marino
1330*e4b17023SJohn Marino #ifdef SECONDARY_MEMORY_NEEDED
1331*e4b17023SJohn Marino /* If a memory location is needed for the copy, make one. */
1332*e4b17023SJohn Marino if (in != 0
1333*e4b17023SJohn Marino && (REG_P (in)
1334*e4b17023SJohn Marino || (GET_CODE (in) == SUBREG && REG_P (SUBREG_REG (in))))
1335*e4b17023SJohn Marino && reg_or_subregno (in) < FIRST_PSEUDO_REGISTER
1336*e4b17023SJohn Marino && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (reg_or_subregno (in)),
1337*e4b17023SJohn Marino rclass, inmode))
1338*e4b17023SJohn Marino get_secondary_mem (in, inmode, opnum, type);
1339*e4b17023SJohn Marino #endif
1340*e4b17023SJohn Marino
1341*e4b17023SJohn Marino i = n_reloads;
1342*e4b17023SJohn Marino rld[i].in = in;
1343*e4b17023SJohn Marino rld[i].out = out;
1344*e4b17023SJohn Marino rld[i].rclass = rclass;
1345*e4b17023SJohn Marino rld[i].inmode = inmode;
1346*e4b17023SJohn Marino rld[i].outmode = outmode;
1347*e4b17023SJohn Marino rld[i].reg_rtx = 0;
1348*e4b17023SJohn Marino rld[i].optional = optional;
1349*e4b17023SJohn Marino rld[i].inc = 0;
1350*e4b17023SJohn Marino rld[i].nocombine = 0;
1351*e4b17023SJohn Marino rld[i].in_reg = inloc ? *inloc : 0;
1352*e4b17023SJohn Marino rld[i].out_reg = outloc ? *outloc : 0;
1353*e4b17023SJohn Marino rld[i].opnum = opnum;
1354*e4b17023SJohn Marino rld[i].when_needed = type;
1355*e4b17023SJohn Marino rld[i].secondary_in_reload = secondary_in_reload;
1356*e4b17023SJohn Marino rld[i].secondary_out_reload = secondary_out_reload;
1357*e4b17023SJohn Marino rld[i].secondary_in_icode = secondary_in_icode;
1358*e4b17023SJohn Marino rld[i].secondary_out_icode = secondary_out_icode;
1359*e4b17023SJohn Marino rld[i].secondary_p = 0;
1360*e4b17023SJohn Marino
1361*e4b17023SJohn Marino n_reloads++;
1362*e4b17023SJohn Marino
1363*e4b17023SJohn Marino #ifdef SECONDARY_MEMORY_NEEDED
1364*e4b17023SJohn Marino if (out != 0
1365*e4b17023SJohn Marino && (REG_P (out)
1366*e4b17023SJohn Marino || (GET_CODE (out) == SUBREG && REG_P (SUBREG_REG (out))))
1367*e4b17023SJohn Marino && reg_or_subregno (out) < FIRST_PSEUDO_REGISTER
1368*e4b17023SJohn Marino && SECONDARY_MEMORY_NEEDED (rclass,
1369*e4b17023SJohn Marino REGNO_REG_CLASS (reg_or_subregno (out)),
1370*e4b17023SJohn Marino outmode))
1371*e4b17023SJohn Marino get_secondary_mem (out, outmode, opnum, type);
1372*e4b17023SJohn Marino #endif
1373*e4b17023SJohn Marino }
1374*e4b17023SJohn Marino else
1375*e4b17023SJohn Marino {
1376*e4b17023SJohn Marino /* We are reusing an existing reload,
1377*e4b17023SJohn Marino but we may have additional information for it.
1378*e4b17023SJohn Marino For example, we may now have both IN and OUT
1379*e4b17023SJohn Marino while the old one may have just one of them. */
1380*e4b17023SJohn Marino
1381*e4b17023SJohn Marino /* The modes can be different. If they are, we want to reload in
1382*e4b17023SJohn Marino the larger mode, so that the value is valid for both modes. */
1383*e4b17023SJohn Marino if (inmode != VOIDmode
1384*e4b17023SJohn Marino && GET_MODE_SIZE (inmode) > GET_MODE_SIZE (rld[i].inmode))
1385*e4b17023SJohn Marino rld[i].inmode = inmode;
1386*e4b17023SJohn Marino if (outmode != VOIDmode
1387*e4b17023SJohn Marino && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (rld[i].outmode))
1388*e4b17023SJohn Marino rld[i].outmode = outmode;
1389*e4b17023SJohn Marino if (in != 0)
1390*e4b17023SJohn Marino {
1391*e4b17023SJohn Marino rtx in_reg = inloc ? *inloc : 0;
1392*e4b17023SJohn Marino /* If we merge reloads for two distinct rtl expressions that
1393*e4b17023SJohn Marino are identical in content, there might be duplicate address
1394*e4b17023SJohn Marino reloads. Remove the extra set now, so that if we later find
1395*e4b17023SJohn Marino that we can inherit this reload, we can get rid of the
1396*e4b17023SJohn Marino address reloads altogether.
1397*e4b17023SJohn Marino
1398*e4b17023SJohn Marino Do not do this if both reloads are optional since the result
1399*e4b17023SJohn Marino would be an optional reload which could potentially leave
1400*e4b17023SJohn Marino unresolved address replacements.
1401*e4b17023SJohn Marino
1402*e4b17023SJohn Marino It is not sufficient to call transfer_replacements since
1403*e4b17023SJohn Marino choose_reload_regs will remove the replacements for address
1404*e4b17023SJohn Marino reloads of inherited reloads which results in the same
1405*e4b17023SJohn Marino problem. */
1406*e4b17023SJohn Marino if (rld[i].in != in && rtx_equal_p (in, rld[i].in)
1407*e4b17023SJohn Marino && ! (rld[i].optional && optional))
1408*e4b17023SJohn Marino {
1409*e4b17023SJohn Marino /* We must keep the address reload with the lower operand
1410*e4b17023SJohn Marino number alive. */
1411*e4b17023SJohn Marino if (opnum > rld[i].opnum)
1412*e4b17023SJohn Marino {
1413*e4b17023SJohn Marino remove_address_replacements (in);
1414*e4b17023SJohn Marino in = rld[i].in;
1415*e4b17023SJohn Marino in_reg = rld[i].in_reg;
1416*e4b17023SJohn Marino }
1417*e4b17023SJohn Marino else
1418*e4b17023SJohn Marino remove_address_replacements (rld[i].in);
1419*e4b17023SJohn Marino }
1420*e4b17023SJohn Marino /* When emitting reloads we don't necessarily look at the in-
1421*e4b17023SJohn Marino and outmode, but also directly at the operands (in and out).
1422*e4b17023SJohn Marino So we can't simply overwrite them with whatever we have found
1423*e4b17023SJohn Marino for this (to-be-merged) reload, we have to "merge" that too.
1424*e4b17023SJohn Marino Reusing another reload already verified that we deal with the
1425*e4b17023SJohn Marino same operands, just possibly in different modes. So we
1426*e4b17023SJohn Marino overwrite the operands only when the new mode is larger.
1427*e4b17023SJohn Marino See also PR33613. */
1428*e4b17023SJohn Marino if (!rld[i].in
1429*e4b17023SJohn Marino || GET_MODE_SIZE (GET_MODE (in))
1430*e4b17023SJohn Marino > GET_MODE_SIZE (GET_MODE (rld[i].in)))
1431*e4b17023SJohn Marino rld[i].in = in;
1432*e4b17023SJohn Marino if (!rld[i].in_reg
1433*e4b17023SJohn Marino || (in_reg
1434*e4b17023SJohn Marino && GET_MODE_SIZE (GET_MODE (in_reg))
1435*e4b17023SJohn Marino > GET_MODE_SIZE (GET_MODE (rld[i].in_reg))))
1436*e4b17023SJohn Marino rld[i].in_reg = in_reg;
1437*e4b17023SJohn Marino }
1438*e4b17023SJohn Marino if (out != 0)
1439*e4b17023SJohn Marino {
1440*e4b17023SJohn Marino if (!rld[i].out
1441*e4b17023SJohn Marino || (out
1442*e4b17023SJohn Marino && GET_MODE_SIZE (GET_MODE (out))
1443*e4b17023SJohn Marino > GET_MODE_SIZE (GET_MODE (rld[i].out))))
1444*e4b17023SJohn Marino rld[i].out = out;
1445*e4b17023SJohn Marino if (outloc
1446*e4b17023SJohn Marino && (!rld[i].out_reg
1447*e4b17023SJohn Marino || GET_MODE_SIZE (GET_MODE (*outloc))
1448*e4b17023SJohn Marino > GET_MODE_SIZE (GET_MODE (rld[i].out_reg))))
1449*e4b17023SJohn Marino rld[i].out_reg = *outloc;
1450*e4b17023SJohn Marino }
1451*e4b17023SJohn Marino if (reg_class_subset_p (rclass, rld[i].rclass))
1452*e4b17023SJohn Marino rld[i].rclass = rclass;
1453*e4b17023SJohn Marino rld[i].optional &= optional;
1454*e4b17023SJohn Marino if (MERGE_TO_OTHER (type, rld[i].when_needed,
1455*e4b17023SJohn Marino opnum, rld[i].opnum))
1456*e4b17023SJohn Marino rld[i].when_needed = RELOAD_OTHER;
1457*e4b17023SJohn Marino rld[i].opnum = MIN (rld[i].opnum, opnum);
1458*e4b17023SJohn Marino }
1459*e4b17023SJohn Marino
1460*e4b17023SJohn Marino /* If the ostensible rtx being reloaded differs from the rtx found
1461*e4b17023SJohn Marino in the location to substitute, this reload is not safe to combine
1462*e4b17023SJohn Marino because we cannot reliably tell whether it appears in the insn. */
1463*e4b17023SJohn Marino
1464*e4b17023SJohn Marino if (in != 0 && in != *inloc)
1465*e4b17023SJohn Marino rld[i].nocombine = 1;
1466*e4b17023SJohn Marino
1467*e4b17023SJohn Marino #if 0
1468*e4b17023SJohn Marino /* This was replaced by changes in find_reloads_address_1 and the new
1469*e4b17023SJohn Marino function inc_for_reload, which go with a new meaning of reload_inc. */
1470*e4b17023SJohn Marino
1471*e4b17023SJohn Marino /* If this is an IN/OUT reload in an insn that sets the CC,
1472*e4b17023SJohn Marino it must be for an autoincrement. It doesn't work to store
1473*e4b17023SJohn Marino the incremented value after the insn because that would clobber the CC.
1474*e4b17023SJohn Marino So we must do the increment of the value reloaded from,
1475*e4b17023SJohn Marino increment it, store it back, then decrement again. */
1476*e4b17023SJohn Marino if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
1477*e4b17023SJohn Marino {
1478*e4b17023SJohn Marino out = 0;
1479*e4b17023SJohn Marino rld[i].out = 0;
1480*e4b17023SJohn Marino rld[i].inc = find_inc_amount (PATTERN (this_insn), in);
1481*e4b17023SJohn Marino /* If we did not find a nonzero amount-to-increment-by,
1482*e4b17023SJohn Marino that contradicts the belief that IN is being incremented
1483*e4b17023SJohn Marino in an address in this insn. */
1484*e4b17023SJohn Marino gcc_assert (rld[i].inc != 0);
1485*e4b17023SJohn Marino }
1486*e4b17023SJohn Marino #endif
1487*e4b17023SJohn Marino
1488*e4b17023SJohn Marino /* If we will replace IN and OUT with the reload-reg,
1489*e4b17023SJohn Marino record where they are located so that substitution need
1490*e4b17023SJohn Marino not do a tree walk. */
1491*e4b17023SJohn Marino
1492*e4b17023SJohn Marino if (replace_reloads)
1493*e4b17023SJohn Marino {
1494*e4b17023SJohn Marino if (inloc != 0)
1495*e4b17023SJohn Marino {
1496*e4b17023SJohn Marino struct replacement *r = &replacements[n_replacements++];
1497*e4b17023SJohn Marino r->what = i;
1498*e4b17023SJohn Marino r->where = inloc;
1499*e4b17023SJohn Marino r->mode = inmode;
1500*e4b17023SJohn Marino }
1501*e4b17023SJohn Marino if (outloc != 0 && outloc != inloc)
1502*e4b17023SJohn Marino {
1503*e4b17023SJohn Marino struct replacement *r = &replacements[n_replacements++];
1504*e4b17023SJohn Marino r->what = i;
1505*e4b17023SJohn Marino r->where = outloc;
1506*e4b17023SJohn Marino r->mode = outmode;
1507*e4b17023SJohn Marino }
1508*e4b17023SJohn Marino }
1509*e4b17023SJohn Marino
1510*e4b17023SJohn Marino /* If this reload is just being introduced and it has both
1511*e4b17023SJohn Marino an incoming quantity and an outgoing quantity that are
1512*e4b17023SJohn Marino supposed to be made to match, see if either one of the two
1513*e4b17023SJohn Marino can serve as the place to reload into.
1514*e4b17023SJohn Marino
1515*e4b17023SJohn Marino If one of them is acceptable, set rld[i].reg_rtx
1516*e4b17023SJohn Marino to that one. */
1517*e4b17023SJohn Marino
1518*e4b17023SJohn Marino if (in != 0 && out != 0 && in != out && rld[i].reg_rtx == 0)
1519*e4b17023SJohn Marino {
1520*e4b17023SJohn Marino rld[i].reg_rtx = find_dummy_reload (in, out, inloc, outloc,
1521*e4b17023SJohn Marino inmode, outmode,
1522*e4b17023SJohn Marino rld[i].rclass, i,
1523*e4b17023SJohn Marino earlyclobber_operand_p (out));
1524*e4b17023SJohn Marino
1525*e4b17023SJohn Marino /* If the outgoing register already contains the same value
1526*e4b17023SJohn Marino as the incoming one, we can dispense with loading it.
1527*e4b17023SJohn Marino The easiest way to tell the caller that is to give a phony
1528*e4b17023SJohn Marino value for the incoming operand (same as outgoing one). */
1529*e4b17023SJohn Marino if (rld[i].reg_rtx == out
1530*e4b17023SJohn Marino && (REG_P (in) || CONSTANT_P (in))
1531*e4b17023SJohn Marino && 0 != find_equiv_reg (in, this_insn, NO_REGS, REGNO (out),
1532*e4b17023SJohn Marino static_reload_reg_p, i, inmode))
1533*e4b17023SJohn Marino rld[i].in = out;
1534*e4b17023SJohn Marino }
1535*e4b17023SJohn Marino
1536*e4b17023SJohn Marino /* If this is an input reload and the operand contains a register that
1537*e4b17023SJohn Marino dies in this insn and is used nowhere else, see if it is the right class
1538*e4b17023SJohn Marino to be used for this reload. Use it if so. (This occurs most commonly
1539*e4b17023SJohn Marino in the case of paradoxical SUBREGs and in-out reloads). We cannot do
1540*e4b17023SJohn Marino this if it is also an output reload that mentions the register unless
1541*e4b17023SJohn Marino the output is a SUBREG that clobbers an entire register.
1542*e4b17023SJohn Marino
1543*e4b17023SJohn Marino Note that the operand might be one of the spill regs, if it is a
1544*e4b17023SJohn Marino pseudo reg and we are in a block where spilling has not taken place.
1545*e4b17023SJohn Marino But if there is no spilling in this block, that is OK.
1546*e4b17023SJohn Marino An explicitly used hard reg cannot be a spill reg. */
1547*e4b17023SJohn Marino
1548*e4b17023SJohn Marino if (rld[i].reg_rtx == 0 && in != 0 && hard_regs_live_known)
1549*e4b17023SJohn Marino {
1550*e4b17023SJohn Marino rtx note;
1551*e4b17023SJohn Marino int regno;
1552*e4b17023SJohn Marino enum machine_mode rel_mode = inmode;
1553*e4b17023SJohn Marino
1554*e4b17023SJohn Marino if (out && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (inmode))
1555*e4b17023SJohn Marino rel_mode = outmode;
1556*e4b17023SJohn Marino
1557*e4b17023SJohn Marino for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1558*e4b17023SJohn Marino if (REG_NOTE_KIND (note) == REG_DEAD
1559*e4b17023SJohn Marino && REG_P (XEXP (note, 0))
1560*e4b17023SJohn Marino && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1561*e4b17023SJohn Marino && reg_mentioned_p (XEXP (note, 0), in)
1562*e4b17023SJohn Marino /* Check that a former pseudo is valid; see find_dummy_reload. */
1563*e4b17023SJohn Marino && (ORIGINAL_REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1564*e4b17023SJohn Marino || (! bitmap_bit_p (DF_LR_OUT (ENTRY_BLOCK_PTR),
1565*e4b17023SJohn Marino ORIGINAL_REGNO (XEXP (note, 0)))
1566*e4b17023SJohn Marino && hard_regno_nregs[regno][GET_MODE (XEXP (note, 0))] == 1))
1567*e4b17023SJohn Marino && ! refers_to_regno_for_reload_p (regno,
1568*e4b17023SJohn Marino end_hard_regno (rel_mode,
1569*e4b17023SJohn Marino regno),
1570*e4b17023SJohn Marino PATTERN (this_insn), inloc)
1571*e4b17023SJohn Marino /* If this is also an output reload, IN cannot be used as
1572*e4b17023SJohn Marino the reload register if it is set in this insn unless IN
1573*e4b17023SJohn Marino is also OUT. */
1574*e4b17023SJohn Marino && (out == 0 || in == out
1575*e4b17023SJohn Marino || ! hard_reg_set_here_p (regno,
1576*e4b17023SJohn Marino end_hard_regno (rel_mode, regno),
1577*e4b17023SJohn Marino PATTERN (this_insn)))
1578*e4b17023SJohn Marino /* ??? Why is this code so different from the previous?
1579*e4b17023SJohn Marino Is there any simple coherent way to describe the two together?
1580*e4b17023SJohn Marino What's going on here. */
1581*e4b17023SJohn Marino && (in != out
1582*e4b17023SJohn Marino || (GET_CODE (in) == SUBREG
1583*e4b17023SJohn Marino && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1))
1584*e4b17023SJohn Marino / UNITS_PER_WORD)
1585*e4b17023SJohn Marino == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1586*e4b17023SJohn Marino + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
1587*e4b17023SJohn Marino /* Make sure the operand fits in the reg that dies. */
1588*e4b17023SJohn Marino && (GET_MODE_SIZE (rel_mode)
1589*e4b17023SJohn Marino <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0))))
1590*e4b17023SJohn Marino && HARD_REGNO_MODE_OK (regno, inmode)
1591*e4b17023SJohn Marino && HARD_REGNO_MODE_OK (regno, outmode))
1592*e4b17023SJohn Marino {
1593*e4b17023SJohn Marino unsigned int offs;
1594*e4b17023SJohn Marino unsigned int nregs = MAX (hard_regno_nregs[regno][inmode],
1595*e4b17023SJohn Marino hard_regno_nregs[regno][outmode]);
1596*e4b17023SJohn Marino
1597*e4b17023SJohn Marino for (offs = 0; offs < nregs; offs++)
1598*e4b17023SJohn Marino if (fixed_regs[regno + offs]
1599*e4b17023SJohn Marino || ! TEST_HARD_REG_BIT (reg_class_contents[(int) rclass],
1600*e4b17023SJohn Marino regno + offs))
1601*e4b17023SJohn Marino break;
1602*e4b17023SJohn Marino
1603*e4b17023SJohn Marino if (offs == nregs
1604*e4b17023SJohn Marino && (! (refers_to_regno_for_reload_p
1605*e4b17023SJohn Marino (regno, end_hard_regno (inmode, regno), in, (rtx *) 0))
1606*e4b17023SJohn Marino || can_reload_into (in, regno, inmode)))
1607*e4b17023SJohn Marino {
1608*e4b17023SJohn Marino rld[i].reg_rtx = gen_rtx_REG (rel_mode, regno);
1609*e4b17023SJohn Marino break;
1610*e4b17023SJohn Marino }
1611*e4b17023SJohn Marino }
1612*e4b17023SJohn Marino }
1613*e4b17023SJohn Marino
1614*e4b17023SJohn Marino if (out)
1615*e4b17023SJohn Marino output_reloadnum = i;
1616*e4b17023SJohn Marino
1617*e4b17023SJohn Marino return i;
1618*e4b17023SJohn Marino }
1619*e4b17023SJohn Marino
1620*e4b17023SJohn Marino /* Record an additional place we must replace a value
1621*e4b17023SJohn Marino for which we have already recorded a reload.
1622*e4b17023SJohn Marino RELOADNUM is the value returned by push_reload
1623*e4b17023SJohn Marino when the reload was recorded.
1624*e4b17023SJohn Marino This is used in insn patterns that use match_dup. */
1625*e4b17023SJohn Marino
1626*e4b17023SJohn Marino static void
push_replacement(rtx * loc,int reloadnum,enum machine_mode mode)1627*e4b17023SJohn Marino push_replacement (rtx *loc, int reloadnum, enum machine_mode mode)
1628*e4b17023SJohn Marino {
1629*e4b17023SJohn Marino if (replace_reloads)
1630*e4b17023SJohn Marino {
1631*e4b17023SJohn Marino struct replacement *r = &replacements[n_replacements++];
1632*e4b17023SJohn Marino r->what = reloadnum;
1633*e4b17023SJohn Marino r->where = loc;
1634*e4b17023SJohn Marino r->mode = mode;
1635*e4b17023SJohn Marino }
1636*e4b17023SJohn Marino }
1637*e4b17023SJohn Marino
1638*e4b17023SJohn Marino /* Duplicate any replacement we have recorded to apply at
1639*e4b17023SJohn Marino location ORIG_LOC to also be performed at DUP_LOC.
1640*e4b17023SJohn Marino This is used in insn patterns that use match_dup. */
1641*e4b17023SJohn Marino
1642*e4b17023SJohn Marino static void
dup_replacements(rtx * dup_loc,rtx * orig_loc)1643*e4b17023SJohn Marino dup_replacements (rtx *dup_loc, rtx *orig_loc)
1644*e4b17023SJohn Marino {
1645*e4b17023SJohn Marino int i, n = n_replacements;
1646*e4b17023SJohn Marino
1647*e4b17023SJohn Marino for (i = 0; i < n; i++)
1648*e4b17023SJohn Marino {
1649*e4b17023SJohn Marino struct replacement *r = &replacements[i];
1650*e4b17023SJohn Marino if (r->where == orig_loc)
1651*e4b17023SJohn Marino push_replacement (dup_loc, r->what, r->mode);
1652*e4b17023SJohn Marino }
1653*e4b17023SJohn Marino }
1654*e4b17023SJohn Marino
1655*e4b17023SJohn Marino /* Transfer all replacements that used to be in reload FROM to be in
1656*e4b17023SJohn Marino reload TO. */
1657*e4b17023SJohn Marino
1658*e4b17023SJohn Marino void
transfer_replacements(int to,int from)1659*e4b17023SJohn Marino transfer_replacements (int to, int from)
1660*e4b17023SJohn Marino {
1661*e4b17023SJohn Marino int i;
1662*e4b17023SJohn Marino
1663*e4b17023SJohn Marino for (i = 0; i < n_replacements; i++)
1664*e4b17023SJohn Marino if (replacements[i].what == from)
1665*e4b17023SJohn Marino replacements[i].what = to;
1666*e4b17023SJohn Marino }
1667*e4b17023SJohn Marino
1668*e4b17023SJohn Marino /* IN_RTX is the value loaded by a reload that we now decided to inherit,
1669*e4b17023SJohn Marino or a subpart of it. If we have any replacements registered for IN_RTX,
1670*e4b17023SJohn Marino cancel the reloads that were supposed to load them.
1671*e4b17023SJohn Marino Return nonzero if we canceled any reloads. */
1672*e4b17023SJohn Marino int
remove_address_replacements(rtx in_rtx)1673*e4b17023SJohn Marino remove_address_replacements (rtx in_rtx)
1674*e4b17023SJohn Marino {
1675*e4b17023SJohn Marino int i, j;
1676*e4b17023SJohn Marino char reload_flags[MAX_RELOADS];
1677*e4b17023SJohn Marino int something_changed = 0;
1678*e4b17023SJohn Marino
1679*e4b17023SJohn Marino memset (reload_flags, 0, sizeof reload_flags);
1680*e4b17023SJohn Marino for (i = 0, j = 0; i < n_replacements; i++)
1681*e4b17023SJohn Marino {
1682*e4b17023SJohn Marino if (loc_mentioned_in_p (replacements[i].where, in_rtx))
1683*e4b17023SJohn Marino reload_flags[replacements[i].what] |= 1;
1684*e4b17023SJohn Marino else
1685*e4b17023SJohn Marino {
1686*e4b17023SJohn Marino replacements[j++] = replacements[i];
1687*e4b17023SJohn Marino reload_flags[replacements[i].what] |= 2;
1688*e4b17023SJohn Marino }
1689*e4b17023SJohn Marino }
1690*e4b17023SJohn Marino /* Note that the following store must be done before the recursive calls. */
1691*e4b17023SJohn Marino n_replacements = j;
1692*e4b17023SJohn Marino
1693*e4b17023SJohn Marino for (i = n_reloads - 1; i >= 0; i--)
1694*e4b17023SJohn Marino {
1695*e4b17023SJohn Marino if (reload_flags[i] == 1)
1696*e4b17023SJohn Marino {
1697*e4b17023SJohn Marino deallocate_reload_reg (i);
1698*e4b17023SJohn Marino remove_address_replacements (rld[i].in);
1699*e4b17023SJohn Marino rld[i].in = 0;
1700*e4b17023SJohn Marino something_changed = 1;
1701*e4b17023SJohn Marino }
1702*e4b17023SJohn Marino }
1703*e4b17023SJohn Marino return something_changed;
1704*e4b17023SJohn Marino }
1705*e4b17023SJohn Marino
1706*e4b17023SJohn Marino /* If there is only one output reload, and it is not for an earlyclobber
1707*e4b17023SJohn Marino operand, try to combine it with a (logically unrelated) input reload
1708*e4b17023SJohn Marino to reduce the number of reload registers needed.
1709*e4b17023SJohn Marino
1710*e4b17023SJohn Marino This is safe if the input reload does not appear in
1711*e4b17023SJohn Marino the value being output-reloaded, because this implies
1712*e4b17023SJohn Marino it is not needed any more once the original insn completes.
1713*e4b17023SJohn Marino
1714*e4b17023SJohn Marino If that doesn't work, see we can use any of the registers that
1715*e4b17023SJohn Marino die in this insn as a reload register. We can if it is of the right
1716*e4b17023SJohn Marino class and does not appear in the value being output-reloaded. */
1717*e4b17023SJohn Marino
1718*e4b17023SJohn Marino static void
combine_reloads(void)1719*e4b17023SJohn Marino combine_reloads (void)
1720*e4b17023SJohn Marino {
1721*e4b17023SJohn Marino int i, regno;
1722*e4b17023SJohn Marino int output_reload = -1;
1723*e4b17023SJohn Marino int secondary_out = -1;
1724*e4b17023SJohn Marino rtx note;
1725*e4b17023SJohn Marino
1726*e4b17023SJohn Marino /* Find the output reload; return unless there is exactly one
1727*e4b17023SJohn Marino and that one is mandatory. */
1728*e4b17023SJohn Marino
1729*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
1730*e4b17023SJohn Marino if (rld[i].out != 0)
1731*e4b17023SJohn Marino {
1732*e4b17023SJohn Marino if (output_reload >= 0)
1733*e4b17023SJohn Marino return;
1734*e4b17023SJohn Marino output_reload = i;
1735*e4b17023SJohn Marino }
1736*e4b17023SJohn Marino
1737*e4b17023SJohn Marino if (output_reload < 0 || rld[output_reload].optional)
1738*e4b17023SJohn Marino return;
1739*e4b17023SJohn Marino
1740*e4b17023SJohn Marino /* An input-output reload isn't combinable. */
1741*e4b17023SJohn Marino
1742*e4b17023SJohn Marino if (rld[output_reload].in != 0)
1743*e4b17023SJohn Marino return;
1744*e4b17023SJohn Marino
1745*e4b17023SJohn Marino /* If this reload is for an earlyclobber operand, we can't do anything. */
1746*e4b17023SJohn Marino if (earlyclobber_operand_p (rld[output_reload].out))
1747*e4b17023SJohn Marino return;
1748*e4b17023SJohn Marino
1749*e4b17023SJohn Marino /* If there is a reload for part of the address of this operand, we would
1750*e4b17023SJohn Marino need to change it to RELOAD_FOR_OTHER_ADDRESS. But that would extend
1751*e4b17023SJohn Marino its life to the point where doing this combine would not lower the
1752*e4b17023SJohn Marino number of spill registers needed. */
1753*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
1754*e4b17023SJohn Marino if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
1755*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
1756*e4b17023SJohn Marino && rld[i].opnum == rld[output_reload].opnum)
1757*e4b17023SJohn Marino return;
1758*e4b17023SJohn Marino
1759*e4b17023SJohn Marino /* Check each input reload; can we combine it? */
1760*e4b17023SJohn Marino
1761*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
1762*e4b17023SJohn Marino if (rld[i].in && ! rld[i].optional && ! rld[i].nocombine
1763*e4b17023SJohn Marino /* Life span of this reload must not extend past main insn. */
1764*e4b17023SJohn Marino && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS
1765*e4b17023SJohn Marino && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS
1766*e4b17023SJohn Marino && rld[i].when_needed != RELOAD_OTHER
1767*e4b17023SJohn Marino && (ira_reg_class_max_nregs [(int)rld[i].rclass][(int) rld[i].inmode]
1768*e4b17023SJohn Marino == ira_reg_class_max_nregs [(int) rld[output_reload].rclass]
1769*e4b17023SJohn Marino [(int) rld[output_reload].outmode])
1770*e4b17023SJohn Marino && rld[i].inc == 0
1771*e4b17023SJohn Marino && rld[i].reg_rtx == 0
1772*e4b17023SJohn Marino #ifdef SECONDARY_MEMORY_NEEDED
1773*e4b17023SJohn Marino /* Don't combine two reloads with different secondary
1774*e4b17023SJohn Marino memory locations. */
1775*e4b17023SJohn Marino && (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum] == 0
1776*e4b17023SJohn Marino || secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] == 0
1777*e4b17023SJohn Marino || rtx_equal_p (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum],
1778*e4b17023SJohn Marino secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum]))
1779*e4b17023SJohn Marino #endif
1780*e4b17023SJohn Marino && (targetm.small_register_classes_for_mode_p (VOIDmode)
1781*e4b17023SJohn Marino ? (rld[i].rclass == rld[output_reload].rclass)
1782*e4b17023SJohn Marino : (reg_class_subset_p (rld[i].rclass,
1783*e4b17023SJohn Marino rld[output_reload].rclass)
1784*e4b17023SJohn Marino || reg_class_subset_p (rld[output_reload].rclass,
1785*e4b17023SJohn Marino rld[i].rclass)))
1786*e4b17023SJohn Marino && (MATCHES (rld[i].in, rld[output_reload].out)
1787*e4b17023SJohn Marino /* Args reversed because the first arg seems to be
1788*e4b17023SJohn Marino the one that we imagine being modified
1789*e4b17023SJohn Marino while the second is the one that might be affected. */
1790*e4b17023SJohn Marino || (! reg_overlap_mentioned_for_reload_p (rld[output_reload].out,
1791*e4b17023SJohn Marino rld[i].in)
1792*e4b17023SJohn Marino /* However, if the input is a register that appears inside
1793*e4b17023SJohn Marino the output, then we also can't share.
1794*e4b17023SJohn Marino Imagine (set (mem (reg 69)) (plus (reg 69) ...)).
1795*e4b17023SJohn Marino If the same reload reg is used for both reg 69 and the
1796*e4b17023SJohn Marino result to be stored in memory, then that result
1797*e4b17023SJohn Marino will clobber the address of the memory ref. */
1798*e4b17023SJohn Marino && ! (REG_P (rld[i].in)
1799*e4b17023SJohn Marino && reg_overlap_mentioned_for_reload_p (rld[i].in,
1800*e4b17023SJohn Marino rld[output_reload].out))))
1801*e4b17023SJohn Marino && ! reload_inner_reg_of_subreg (rld[i].in, rld[i].inmode,
1802*e4b17023SJohn Marino rld[i].when_needed != RELOAD_FOR_INPUT)
1803*e4b17023SJohn Marino && (reg_class_size[(int) rld[i].rclass]
1804*e4b17023SJohn Marino || targetm.small_register_classes_for_mode_p (VOIDmode))
1805*e4b17023SJohn Marino /* We will allow making things slightly worse by combining an
1806*e4b17023SJohn Marino input and an output, but no worse than that. */
1807*e4b17023SJohn Marino && (rld[i].when_needed == RELOAD_FOR_INPUT
1808*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OUTPUT))
1809*e4b17023SJohn Marino {
1810*e4b17023SJohn Marino int j;
1811*e4b17023SJohn Marino
1812*e4b17023SJohn Marino /* We have found a reload to combine with! */
1813*e4b17023SJohn Marino rld[i].out = rld[output_reload].out;
1814*e4b17023SJohn Marino rld[i].out_reg = rld[output_reload].out_reg;
1815*e4b17023SJohn Marino rld[i].outmode = rld[output_reload].outmode;
1816*e4b17023SJohn Marino /* Mark the old output reload as inoperative. */
1817*e4b17023SJohn Marino rld[output_reload].out = 0;
1818*e4b17023SJohn Marino /* The combined reload is needed for the entire insn. */
1819*e4b17023SJohn Marino rld[i].when_needed = RELOAD_OTHER;
1820*e4b17023SJohn Marino /* If the output reload had a secondary reload, copy it. */
1821*e4b17023SJohn Marino if (rld[output_reload].secondary_out_reload != -1)
1822*e4b17023SJohn Marino {
1823*e4b17023SJohn Marino rld[i].secondary_out_reload
1824*e4b17023SJohn Marino = rld[output_reload].secondary_out_reload;
1825*e4b17023SJohn Marino rld[i].secondary_out_icode
1826*e4b17023SJohn Marino = rld[output_reload].secondary_out_icode;
1827*e4b17023SJohn Marino }
1828*e4b17023SJohn Marino
1829*e4b17023SJohn Marino #ifdef SECONDARY_MEMORY_NEEDED
1830*e4b17023SJohn Marino /* Copy any secondary MEM. */
1831*e4b17023SJohn Marino if (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] != 0)
1832*e4b17023SJohn Marino secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum]
1833*e4b17023SJohn Marino = secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum];
1834*e4b17023SJohn Marino #endif
1835*e4b17023SJohn Marino /* If required, minimize the register class. */
1836*e4b17023SJohn Marino if (reg_class_subset_p (rld[output_reload].rclass,
1837*e4b17023SJohn Marino rld[i].rclass))
1838*e4b17023SJohn Marino rld[i].rclass = rld[output_reload].rclass;
1839*e4b17023SJohn Marino
1840*e4b17023SJohn Marino /* Transfer all replacements from the old reload to the combined. */
1841*e4b17023SJohn Marino for (j = 0; j < n_replacements; j++)
1842*e4b17023SJohn Marino if (replacements[j].what == output_reload)
1843*e4b17023SJohn Marino replacements[j].what = i;
1844*e4b17023SJohn Marino
1845*e4b17023SJohn Marino return;
1846*e4b17023SJohn Marino }
1847*e4b17023SJohn Marino
1848*e4b17023SJohn Marino /* If this insn has only one operand that is modified or written (assumed
1849*e4b17023SJohn Marino to be the first), it must be the one corresponding to this reload. It
1850*e4b17023SJohn Marino is safe to use anything that dies in this insn for that output provided
1851*e4b17023SJohn Marino that it does not occur in the output (we already know it isn't an
1852*e4b17023SJohn Marino earlyclobber. If this is an asm insn, give up. */
1853*e4b17023SJohn Marino
1854*e4b17023SJohn Marino if (INSN_CODE (this_insn) == -1)
1855*e4b17023SJohn Marino return;
1856*e4b17023SJohn Marino
1857*e4b17023SJohn Marino for (i = 1; i < insn_data[INSN_CODE (this_insn)].n_operands; i++)
1858*e4b17023SJohn Marino if (insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '='
1859*e4b17023SJohn Marino || insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '+')
1860*e4b17023SJohn Marino return;
1861*e4b17023SJohn Marino
1862*e4b17023SJohn Marino /* See if some hard register that dies in this insn and is not used in
1863*e4b17023SJohn Marino the output is the right class. Only works if the register we pick
1864*e4b17023SJohn Marino up can fully hold our output reload. */
1865*e4b17023SJohn Marino for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1866*e4b17023SJohn Marino if (REG_NOTE_KIND (note) == REG_DEAD
1867*e4b17023SJohn Marino && REG_P (XEXP (note, 0))
1868*e4b17023SJohn Marino && !reg_overlap_mentioned_for_reload_p (XEXP (note, 0),
1869*e4b17023SJohn Marino rld[output_reload].out)
1870*e4b17023SJohn Marino && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1871*e4b17023SJohn Marino && HARD_REGNO_MODE_OK (regno, rld[output_reload].outmode)
1872*e4b17023SJohn Marino && TEST_HARD_REG_BIT (reg_class_contents[(int) rld[output_reload].rclass],
1873*e4b17023SJohn Marino regno)
1874*e4b17023SJohn Marino && (hard_regno_nregs[regno][rld[output_reload].outmode]
1875*e4b17023SJohn Marino <= hard_regno_nregs[regno][GET_MODE (XEXP (note, 0))])
1876*e4b17023SJohn Marino /* Ensure that a secondary or tertiary reload for this output
1877*e4b17023SJohn Marino won't want this register. */
1878*e4b17023SJohn Marino && ((secondary_out = rld[output_reload].secondary_out_reload) == -1
1879*e4b17023SJohn Marino || (!(TEST_HARD_REG_BIT
1880*e4b17023SJohn Marino (reg_class_contents[(int) rld[secondary_out].rclass], regno))
1881*e4b17023SJohn Marino && ((secondary_out = rld[secondary_out].secondary_out_reload) == -1
1882*e4b17023SJohn Marino || !(TEST_HARD_REG_BIT
1883*e4b17023SJohn Marino (reg_class_contents[(int) rld[secondary_out].rclass],
1884*e4b17023SJohn Marino regno)))))
1885*e4b17023SJohn Marino && !fixed_regs[regno]
1886*e4b17023SJohn Marino /* Check that a former pseudo is valid; see find_dummy_reload. */
1887*e4b17023SJohn Marino && (ORIGINAL_REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1888*e4b17023SJohn Marino || (!bitmap_bit_p (DF_LR_OUT (ENTRY_BLOCK_PTR),
1889*e4b17023SJohn Marino ORIGINAL_REGNO (XEXP (note, 0)))
1890*e4b17023SJohn Marino && hard_regno_nregs[regno][GET_MODE (XEXP (note, 0))] == 1)))
1891*e4b17023SJohn Marino {
1892*e4b17023SJohn Marino rld[output_reload].reg_rtx
1893*e4b17023SJohn Marino = gen_rtx_REG (rld[output_reload].outmode, regno);
1894*e4b17023SJohn Marino return;
1895*e4b17023SJohn Marino }
1896*e4b17023SJohn Marino }
1897*e4b17023SJohn Marino
1898*e4b17023SJohn Marino /* Try to find a reload register for an in-out reload (expressions IN and OUT).
1899*e4b17023SJohn Marino See if one of IN and OUT is a register that may be used;
1900*e4b17023SJohn Marino this is desirable since a spill-register won't be needed.
1901*e4b17023SJohn Marino If so, return the register rtx that proves acceptable.
1902*e4b17023SJohn Marino
1903*e4b17023SJohn Marino INLOC and OUTLOC are locations where IN and OUT appear in the insn.
1904*e4b17023SJohn Marino RCLASS is the register class required for the reload.
1905*e4b17023SJohn Marino
1906*e4b17023SJohn Marino If FOR_REAL is >= 0, it is the number of the reload,
1907*e4b17023SJohn Marino and in some cases when it can be discovered that OUT doesn't need
1908*e4b17023SJohn Marino to be computed, clear out rld[FOR_REAL].out.
1909*e4b17023SJohn Marino
1910*e4b17023SJohn Marino If FOR_REAL is -1, this should not be done, because this call
1911*e4b17023SJohn Marino is just to see if a register can be found, not to find and install it.
1912*e4b17023SJohn Marino
1913*e4b17023SJohn Marino EARLYCLOBBER is nonzero if OUT is an earlyclobber operand. This
1914*e4b17023SJohn Marino puts an additional constraint on being able to use IN for OUT since
1915*e4b17023SJohn Marino IN must not appear elsewhere in the insn (it is assumed that IN itself
1916*e4b17023SJohn Marino is safe from the earlyclobber). */
1917*e4b17023SJohn Marino
1918*e4b17023SJohn Marino static rtx
find_dummy_reload(rtx real_in,rtx real_out,rtx * inloc,rtx * outloc,enum machine_mode inmode,enum machine_mode outmode,reg_class_t rclass,int for_real,int earlyclobber)1919*e4b17023SJohn Marino find_dummy_reload (rtx real_in, rtx real_out, rtx *inloc, rtx *outloc,
1920*e4b17023SJohn Marino enum machine_mode inmode, enum machine_mode outmode,
1921*e4b17023SJohn Marino reg_class_t rclass, int for_real, int earlyclobber)
1922*e4b17023SJohn Marino {
1923*e4b17023SJohn Marino rtx in = real_in;
1924*e4b17023SJohn Marino rtx out = real_out;
1925*e4b17023SJohn Marino int in_offset = 0;
1926*e4b17023SJohn Marino int out_offset = 0;
1927*e4b17023SJohn Marino rtx value = 0;
1928*e4b17023SJohn Marino
1929*e4b17023SJohn Marino /* If operands exceed a word, we can't use either of them
1930*e4b17023SJohn Marino unless they have the same size. */
1931*e4b17023SJohn Marino if (GET_MODE_SIZE (outmode) != GET_MODE_SIZE (inmode)
1932*e4b17023SJohn Marino && (GET_MODE_SIZE (outmode) > UNITS_PER_WORD
1933*e4b17023SJohn Marino || GET_MODE_SIZE (inmode) > UNITS_PER_WORD))
1934*e4b17023SJohn Marino return 0;
1935*e4b17023SJohn Marino
1936*e4b17023SJohn Marino /* Note that {in,out}_offset are needed only when 'in' or 'out'
1937*e4b17023SJohn Marino respectively refers to a hard register. */
1938*e4b17023SJohn Marino
1939*e4b17023SJohn Marino /* Find the inside of any subregs. */
1940*e4b17023SJohn Marino while (GET_CODE (out) == SUBREG)
1941*e4b17023SJohn Marino {
1942*e4b17023SJohn Marino if (REG_P (SUBREG_REG (out))
1943*e4b17023SJohn Marino && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER)
1944*e4b17023SJohn Marino out_offset += subreg_regno_offset (REGNO (SUBREG_REG (out)),
1945*e4b17023SJohn Marino GET_MODE (SUBREG_REG (out)),
1946*e4b17023SJohn Marino SUBREG_BYTE (out),
1947*e4b17023SJohn Marino GET_MODE (out));
1948*e4b17023SJohn Marino out = SUBREG_REG (out);
1949*e4b17023SJohn Marino }
1950*e4b17023SJohn Marino while (GET_CODE (in) == SUBREG)
1951*e4b17023SJohn Marino {
1952*e4b17023SJohn Marino if (REG_P (SUBREG_REG (in))
1953*e4b17023SJohn Marino && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER)
1954*e4b17023SJohn Marino in_offset += subreg_regno_offset (REGNO (SUBREG_REG (in)),
1955*e4b17023SJohn Marino GET_MODE (SUBREG_REG (in)),
1956*e4b17023SJohn Marino SUBREG_BYTE (in),
1957*e4b17023SJohn Marino GET_MODE (in));
1958*e4b17023SJohn Marino in = SUBREG_REG (in);
1959*e4b17023SJohn Marino }
1960*e4b17023SJohn Marino
1961*e4b17023SJohn Marino /* Narrow down the reg class, the same way push_reload will;
1962*e4b17023SJohn Marino otherwise we might find a dummy now, but push_reload won't. */
1963*e4b17023SJohn Marino {
1964*e4b17023SJohn Marino reg_class_t preferred_class = targetm.preferred_reload_class (in, rclass);
1965*e4b17023SJohn Marino if (preferred_class != NO_REGS)
1966*e4b17023SJohn Marino rclass = (enum reg_class) preferred_class;
1967*e4b17023SJohn Marino }
1968*e4b17023SJohn Marino
1969*e4b17023SJohn Marino /* See if OUT will do. */
1970*e4b17023SJohn Marino if (REG_P (out)
1971*e4b17023SJohn Marino && REGNO (out) < FIRST_PSEUDO_REGISTER)
1972*e4b17023SJohn Marino {
1973*e4b17023SJohn Marino unsigned int regno = REGNO (out) + out_offset;
1974*e4b17023SJohn Marino unsigned int nwords = hard_regno_nregs[regno][outmode];
1975*e4b17023SJohn Marino rtx saved_rtx;
1976*e4b17023SJohn Marino
1977*e4b17023SJohn Marino /* When we consider whether the insn uses OUT,
1978*e4b17023SJohn Marino ignore references within IN. They don't prevent us
1979*e4b17023SJohn Marino from copying IN into OUT, because those refs would
1980*e4b17023SJohn Marino move into the insn that reloads IN.
1981*e4b17023SJohn Marino
1982*e4b17023SJohn Marino However, we only ignore IN in its role as this reload.
1983*e4b17023SJohn Marino If the insn uses IN elsewhere and it contains OUT,
1984*e4b17023SJohn Marino that counts. We can't be sure it's the "same" operand
1985*e4b17023SJohn Marino so it might not go through this reload. */
1986*e4b17023SJohn Marino saved_rtx = *inloc;
1987*e4b17023SJohn Marino *inloc = const0_rtx;
1988*e4b17023SJohn Marino
1989*e4b17023SJohn Marino if (regno < FIRST_PSEUDO_REGISTER
1990*e4b17023SJohn Marino && HARD_REGNO_MODE_OK (regno, outmode)
1991*e4b17023SJohn Marino && ! refers_to_regno_for_reload_p (regno, regno + nwords,
1992*e4b17023SJohn Marino PATTERN (this_insn), outloc))
1993*e4b17023SJohn Marino {
1994*e4b17023SJohn Marino unsigned int i;
1995*e4b17023SJohn Marino
1996*e4b17023SJohn Marino for (i = 0; i < nwords; i++)
1997*e4b17023SJohn Marino if (! TEST_HARD_REG_BIT (reg_class_contents[(int) rclass],
1998*e4b17023SJohn Marino regno + i))
1999*e4b17023SJohn Marino break;
2000*e4b17023SJohn Marino
2001*e4b17023SJohn Marino if (i == nwords)
2002*e4b17023SJohn Marino {
2003*e4b17023SJohn Marino if (REG_P (real_out))
2004*e4b17023SJohn Marino value = real_out;
2005*e4b17023SJohn Marino else
2006*e4b17023SJohn Marino value = gen_rtx_REG (outmode, regno);
2007*e4b17023SJohn Marino }
2008*e4b17023SJohn Marino }
2009*e4b17023SJohn Marino
2010*e4b17023SJohn Marino *inloc = saved_rtx;
2011*e4b17023SJohn Marino }
2012*e4b17023SJohn Marino
2013*e4b17023SJohn Marino /* Consider using IN if OUT was not acceptable
2014*e4b17023SJohn Marino or if OUT dies in this insn (like the quotient in a divmod insn).
2015*e4b17023SJohn Marino We can't use IN unless it is dies in this insn,
2016*e4b17023SJohn Marino which means we must know accurately which hard regs are live.
2017*e4b17023SJohn Marino Also, the result can't go in IN if IN is used within OUT,
2018*e4b17023SJohn Marino or if OUT is an earlyclobber and IN appears elsewhere in the insn. */
2019*e4b17023SJohn Marino if (hard_regs_live_known
2020*e4b17023SJohn Marino && REG_P (in)
2021*e4b17023SJohn Marino && REGNO (in) < FIRST_PSEUDO_REGISTER
2022*e4b17023SJohn Marino && (value == 0
2023*e4b17023SJohn Marino || find_reg_note (this_insn, REG_UNUSED, real_out))
2024*e4b17023SJohn Marino && find_reg_note (this_insn, REG_DEAD, real_in)
2025*e4b17023SJohn Marino && !fixed_regs[REGNO (in)]
2026*e4b17023SJohn Marino && HARD_REGNO_MODE_OK (REGNO (in),
2027*e4b17023SJohn Marino /* The only case where out and real_out might
2028*e4b17023SJohn Marino have different modes is where real_out
2029*e4b17023SJohn Marino is a subreg, and in that case, out
2030*e4b17023SJohn Marino has a real mode. */
2031*e4b17023SJohn Marino (GET_MODE (out) != VOIDmode
2032*e4b17023SJohn Marino ? GET_MODE (out) : outmode))
2033*e4b17023SJohn Marino && (ORIGINAL_REGNO (in) < FIRST_PSEUDO_REGISTER
2034*e4b17023SJohn Marino /* However only do this if we can be sure that this input
2035*e4b17023SJohn Marino operand doesn't correspond with an uninitialized pseudo.
2036*e4b17023SJohn Marino global can assign some hardreg to it that is the same as
2037*e4b17023SJohn Marino the one assigned to a different, also live pseudo (as it
2038*e4b17023SJohn Marino can ignore the conflict). We must never introduce writes
2039*e4b17023SJohn Marino to such hardregs, as they would clobber the other live
2040*e4b17023SJohn Marino pseudo. See PR 20973. */
2041*e4b17023SJohn Marino || (!bitmap_bit_p (DF_LR_OUT (ENTRY_BLOCK_PTR),
2042*e4b17023SJohn Marino ORIGINAL_REGNO (in))
2043*e4b17023SJohn Marino /* Similarly, only do this if we can be sure that the death
2044*e4b17023SJohn Marino note is still valid. global can assign some hardreg to
2045*e4b17023SJohn Marino the pseudo referenced in the note and simultaneously a
2046*e4b17023SJohn Marino subword of this hardreg to a different, also live pseudo,
2047*e4b17023SJohn Marino because only another subword of the hardreg is actually
2048*e4b17023SJohn Marino used in the insn. This cannot happen if the pseudo has
2049*e4b17023SJohn Marino been assigned exactly one hardreg. See PR 33732. */
2050*e4b17023SJohn Marino && hard_regno_nregs[REGNO (in)][GET_MODE (in)] == 1)))
2051*e4b17023SJohn Marino {
2052*e4b17023SJohn Marino unsigned int regno = REGNO (in) + in_offset;
2053*e4b17023SJohn Marino unsigned int nwords = hard_regno_nregs[regno][inmode];
2054*e4b17023SJohn Marino
2055*e4b17023SJohn Marino if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, (rtx*) 0)
2056*e4b17023SJohn Marino && ! hard_reg_set_here_p (regno, regno + nwords,
2057*e4b17023SJohn Marino PATTERN (this_insn))
2058*e4b17023SJohn Marino && (! earlyclobber
2059*e4b17023SJohn Marino || ! refers_to_regno_for_reload_p (regno, regno + nwords,
2060*e4b17023SJohn Marino PATTERN (this_insn), inloc)))
2061*e4b17023SJohn Marino {
2062*e4b17023SJohn Marino unsigned int i;
2063*e4b17023SJohn Marino
2064*e4b17023SJohn Marino for (i = 0; i < nwords; i++)
2065*e4b17023SJohn Marino if (! TEST_HARD_REG_BIT (reg_class_contents[(int) rclass],
2066*e4b17023SJohn Marino regno + i))
2067*e4b17023SJohn Marino break;
2068*e4b17023SJohn Marino
2069*e4b17023SJohn Marino if (i == nwords)
2070*e4b17023SJohn Marino {
2071*e4b17023SJohn Marino /* If we were going to use OUT as the reload reg
2072*e4b17023SJohn Marino and changed our mind, it means OUT is a dummy that
2073*e4b17023SJohn Marino dies here. So don't bother copying value to it. */
2074*e4b17023SJohn Marino if (for_real >= 0 && value == real_out)
2075*e4b17023SJohn Marino rld[for_real].out = 0;
2076*e4b17023SJohn Marino if (REG_P (real_in))
2077*e4b17023SJohn Marino value = real_in;
2078*e4b17023SJohn Marino else
2079*e4b17023SJohn Marino value = gen_rtx_REG (inmode, regno);
2080*e4b17023SJohn Marino }
2081*e4b17023SJohn Marino }
2082*e4b17023SJohn Marino }
2083*e4b17023SJohn Marino
2084*e4b17023SJohn Marino return value;
2085*e4b17023SJohn Marino }
2086*e4b17023SJohn Marino
2087*e4b17023SJohn Marino /* This page contains subroutines used mainly for determining
2088*e4b17023SJohn Marino whether the IN or an OUT of a reload can serve as the
2089*e4b17023SJohn Marino reload register. */
2090*e4b17023SJohn Marino
2091*e4b17023SJohn Marino /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
2092*e4b17023SJohn Marino
2093*e4b17023SJohn Marino int
earlyclobber_operand_p(rtx x)2094*e4b17023SJohn Marino earlyclobber_operand_p (rtx x)
2095*e4b17023SJohn Marino {
2096*e4b17023SJohn Marino int i;
2097*e4b17023SJohn Marino
2098*e4b17023SJohn Marino for (i = 0; i < n_earlyclobbers; i++)
2099*e4b17023SJohn Marino if (reload_earlyclobbers[i] == x)
2100*e4b17023SJohn Marino return 1;
2101*e4b17023SJohn Marino
2102*e4b17023SJohn Marino return 0;
2103*e4b17023SJohn Marino }
2104*e4b17023SJohn Marino
2105*e4b17023SJohn Marino /* Return 1 if expression X alters a hard reg in the range
2106*e4b17023SJohn Marino from BEG_REGNO (inclusive) to END_REGNO (exclusive),
2107*e4b17023SJohn Marino either explicitly or in the guise of a pseudo-reg allocated to REGNO.
2108*e4b17023SJohn Marino X should be the body of an instruction. */
2109*e4b17023SJohn Marino
2110*e4b17023SJohn Marino static int
hard_reg_set_here_p(unsigned int beg_regno,unsigned int end_regno,rtx x)2111*e4b17023SJohn Marino hard_reg_set_here_p (unsigned int beg_regno, unsigned int end_regno, rtx x)
2112*e4b17023SJohn Marino {
2113*e4b17023SJohn Marino if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
2114*e4b17023SJohn Marino {
2115*e4b17023SJohn Marino rtx op0 = SET_DEST (x);
2116*e4b17023SJohn Marino
2117*e4b17023SJohn Marino while (GET_CODE (op0) == SUBREG)
2118*e4b17023SJohn Marino op0 = SUBREG_REG (op0);
2119*e4b17023SJohn Marino if (REG_P (op0))
2120*e4b17023SJohn Marino {
2121*e4b17023SJohn Marino unsigned int r = REGNO (op0);
2122*e4b17023SJohn Marino
2123*e4b17023SJohn Marino /* See if this reg overlaps range under consideration. */
2124*e4b17023SJohn Marino if (r < end_regno
2125*e4b17023SJohn Marino && end_hard_regno (GET_MODE (op0), r) > beg_regno)
2126*e4b17023SJohn Marino return 1;
2127*e4b17023SJohn Marino }
2128*e4b17023SJohn Marino }
2129*e4b17023SJohn Marino else if (GET_CODE (x) == PARALLEL)
2130*e4b17023SJohn Marino {
2131*e4b17023SJohn Marino int i = XVECLEN (x, 0) - 1;
2132*e4b17023SJohn Marino
2133*e4b17023SJohn Marino for (; i >= 0; i--)
2134*e4b17023SJohn Marino if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i)))
2135*e4b17023SJohn Marino return 1;
2136*e4b17023SJohn Marino }
2137*e4b17023SJohn Marino
2138*e4b17023SJohn Marino return 0;
2139*e4b17023SJohn Marino }
2140*e4b17023SJohn Marino
2141*e4b17023SJohn Marino /* Return 1 if ADDR is a valid memory address for mode MODE
2142*e4b17023SJohn Marino in address space AS, and check that each pseudo reg has the
2143*e4b17023SJohn Marino proper kind of hard reg. */
2144*e4b17023SJohn Marino
2145*e4b17023SJohn Marino int
strict_memory_address_addr_space_p(enum machine_mode mode ATTRIBUTE_UNUSED,rtx addr,addr_space_t as)2146*e4b17023SJohn Marino strict_memory_address_addr_space_p (enum machine_mode mode ATTRIBUTE_UNUSED,
2147*e4b17023SJohn Marino rtx addr, addr_space_t as)
2148*e4b17023SJohn Marino {
2149*e4b17023SJohn Marino #ifdef GO_IF_LEGITIMATE_ADDRESS
2150*e4b17023SJohn Marino gcc_assert (ADDR_SPACE_GENERIC_P (as));
2151*e4b17023SJohn Marino GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
2152*e4b17023SJohn Marino return 0;
2153*e4b17023SJohn Marino
2154*e4b17023SJohn Marino win:
2155*e4b17023SJohn Marino return 1;
2156*e4b17023SJohn Marino #else
2157*e4b17023SJohn Marino return targetm.addr_space.legitimate_address_p (mode, addr, 1, as);
2158*e4b17023SJohn Marino #endif
2159*e4b17023SJohn Marino }
2160*e4b17023SJohn Marino
2161*e4b17023SJohn Marino /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
2162*e4b17023SJohn Marino if they are the same hard reg, and has special hacks for
2163*e4b17023SJohn Marino autoincrement and autodecrement.
2164*e4b17023SJohn Marino This is specifically intended for find_reloads to use
2165*e4b17023SJohn Marino in determining whether two operands match.
2166*e4b17023SJohn Marino X is the operand whose number is the lower of the two.
2167*e4b17023SJohn Marino
2168*e4b17023SJohn Marino The value is 2 if Y contains a pre-increment that matches
2169*e4b17023SJohn Marino a non-incrementing address in X. */
2170*e4b17023SJohn Marino
2171*e4b17023SJohn Marino /* ??? To be completely correct, we should arrange to pass
2172*e4b17023SJohn Marino for X the output operand and for Y the input operand.
2173*e4b17023SJohn Marino For now, we assume that the output operand has the lower number
2174*e4b17023SJohn Marino because that is natural in (SET output (... input ...)). */
2175*e4b17023SJohn Marino
2176*e4b17023SJohn Marino int
operands_match_p(rtx x,rtx y)2177*e4b17023SJohn Marino operands_match_p (rtx x, rtx y)
2178*e4b17023SJohn Marino {
2179*e4b17023SJohn Marino int i;
2180*e4b17023SJohn Marino RTX_CODE code = GET_CODE (x);
2181*e4b17023SJohn Marino const char *fmt;
2182*e4b17023SJohn Marino int success_2;
2183*e4b17023SJohn Marino
2184*e4b17023SJohn Marino if (x == y)
2185*e4b17023SJohn Marino return 1;
2186*e4b17023SJohn Marino if ((code == REG || (code == SUBREG && REG_P (SUBREG_REG (x))))
2187*e4b17023SJohn Marino && (REG_P (y) || (GET_CODE (y) == SUBREG
2188*e4b17023SJohn Marino && REG_P (SUBREG_REG (y)))))
2189*e4b17023SJohn Marino {
2190*e4b17023SJohn Marino int j;
2191*e4b17023SJohn Marino
2192*e4b17023SJohn Marino if (code == SUBREG)
2193*e4b17023SJohn Marino {
2194*e4b17023SJohn Marino i = REGNO (SUBREG_REG (x));
2195*e4b17023SJohn Marino if (i >= FIRST_PSEUDO_REGISTER)
2196*e4b17023SJohn Marino goto slow;
2197*e4b17023SJohn Marino i += subreg_regno_offset (REGNO (SUBREG_REG (x)),
2198*e4b17023SJohn Marino GET_MODE (SUBREG_REG (x)),
2199*e4b17023SJohn Marino SUBREG_BYTE (x),
2200*e4b17023SJohn Marino GET_MODE (x));
2201*e4b17023SJohn Marino }
2202*e4b17023SJohn Marino else
2203*e4b17023SJohn Marino i = REGNO (x);
2204*e4b17023SJohn Marino
2205*e4b17023SJohn Marino if (GET_CODE (y) == SUBREG)
2206*e4b17023SJohn Marino {
2207*e4b17023SJohn Marino j = REGNO (SUBREG_REG (y));
2208*e4b17023SJohn Marino if (j >= FIRST_PSEUDO_REGISTER)
2209*e4b17023SJohn Marino goto slow;
2210*e4b17023SJohn Marino j += subreg_regno_offset (REGNO (SUBREG_REG (y)),
2211*e4b17023SJohn Marino GET_MODE (SUBREG_REG (y)),
2212*e4b17023SJohn Marino SUBREG_BYTE (y),
2213*e4b17023SJohn Marino GET_MODE (y));
2214*e4b17023SJohn Marino }
2215*e4b17023SJohn Marino else
2216*e4b17023SJohn Marino j = REGNO (y);
2217*e4b17023SJohn Marino
2218*e4b17023SJohn Marino /* On a REG_WORDS_BIG_ENDIAN machine, point to the last register of a
2219*e4b17023SJohn Marino multiple hard register group of scalar integer registers, so that
2220*e4b17023SJohn Marino for example (reg:DI 0) and (reg:SI 1) will be considered the same
2221*e4b17023SJohn Marino register. */
2222*e4b17023SJohn Marino if (REG_WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
2223*e4b17023SJohn Marino && SCALAR_INT_MODE_P (GET_MODE (x))
2224*e4b17023SJohn Marino && i < FIRST_PSEUDO_REGISTER)
2225*e4b17023SJohn Marino i += hard_regno_nregs[i][GET_MODE (x)] - 1;
2226*e4b17023SJohn Marino if (REG_WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD
2227*e4b17023SJohn Marino && SCALAR_INT_MODE_P (GET_MODE (y))
2228*e4b17023SJohn Marino && j < FIRST_PSEUDO_REGISTER)
2229*e4b17023SJohn Marino j += hard_regno_nregs[j][GET_MODE (y)] - 1;
2230*e4b17023SJohn Marino
2231*e4b17023SJohn Marino return i == j;
2232*e4b17023SJohn Marino }
2233*e4b17023SJohn Marino /* If two operands must match, because they are really a single
2234*e4b17023SJohn Marino operand of an assembler insn, then two postincrements are invalid
2235*e4b17023SJohn Marino because the assembler insn would increment only once.
2236*e4b17023SJohn Marino On the other hand, a postincrement matches ordinary indexing
2237*e4b17023SJohn Marino if the postincrement is the output operand. */
2238*e4b17023SJohn Marino if (code == POST_DEC || code == POST_INC || code == POST_MODIFY)
2239*e4b17023SJohn Marino return operands_match_p (XEXP (x, 0), y);
2240*e4b17023SJohn Marino /* Two preincrements are invalid
2241*e4b17023SJohn Marino because the assembler insn would increment only once.
2242*e4b17023SJohn Marino On the other hand, a preincrement matches ordinary indexing
2243*e4b17023SJohn Marino if the preincrement is the input operand.
2244*e4b17023SJohn Marino In this case, return 2, since some callers need to do special
2245*e4b17023SJohn Marino things when this happens. */
2246*e4b17023SJohn Marino if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC
2247*e4b17023SJohn Marino || GET_CODE (y) == PRE_MODIFY)
2248*e4b17023SJohn Marino return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
2249*e4b17023SJohn Marino
2250*e4b17023SJohn Marino slow:
2251*e4b17023SJohn Marino
2252*e4b17023SJohn Marino /* Now we have disposed of all the cases in which different rtx codes
2253*e4b17023SJohn Marino can match. */
2254*e4b17023SJohn Marino if (code != GET_CODE (y))
2255*e4b17023SJohn Marino return 0;
2256*e4b17023SJohn Marino
2257*e4b17023SJohn Marino /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
2258*e4b17023SJohn Marino if (GET_MODE (x) != GET_MODE (y))
2259*e4b17023SJohn Marino return 0;
2260*e4b17023SJohn Marino
2261*e4b17023SJohn Marino /* MEMs refering to different address space are not equivalent. */
2262*e4b17023SJohn Marino if (code == MEM && MEM_ADDR_SPACE (x) != MEM_ADDR_SPACE (y))
2263*e4b17023SJohn Marino return 0;
2264*e4b17023SJohn Marino
2265*e4b17023SJohn Marino switch (code)
2266*e4b17023SJohn Marino {
2267*e4b17023SJohn Marino case CONST_INT:
2268*e4b17023SJohn Marino case CONST_DOUBLE:
2269*e4b17023SJohn Marino case CONST_FIXED:
2270*e4b17023SJohn Marino return 0;
2271*e4b17023SJohn Marino
2272*e4b17023SJohn Marino case LABEL_REF:
2273*e4b17023SJohn Marino return XEXP (x, 0) == XEXP (y, 0);
2274*e4b17023SJohn Marino case SYMBOL_REF:
2275*e4b17023SJohn Marino return XSTR (x, 0) == XSTR (y, 0);
2276*e4b17023SJohn Marino
2277*e4b17023SJohn Marino default:
2278*e4b17023SJohn Marino break;
2279*e4b17023SJohn Marino }
2280*e4b17023SJohn Marino
2281*e4b17023SJohn Marino /* Compare the elements. If any pair of corresponding elements
2282*e4b17023SJohn Marino fail to match, return 0 for the whole things. */
2283*e4b17023SJohn Marino
2284*e4b17023SJohn Marino success_2 = 0;
2285*e4b17023SJohn Marino fmt = GET_RTX_FORMAT (code);
2286*e4b17023SJohn Marino for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2287*e4b17023SJohn Marino {
2288*e4b17023SJohn Marino int val, j;
2289*e4b17023SJohn Marino switch (fmt[i])
2290*e4b17023SJohn Marino {
2291*e4b17023SJohn Marino case 'w':
2292*e4b17023SJohn Marino if (XWINT (x, i) != XWINT (y, i))
2293*e4b17023SJohn Marino return 0;
2294*e4b17023SJohn Marino break;
2295*e4b17023SJohn Marino
2296*e4b17023SJohn Marino case 'i':
2297*e4b17023SJohn Marino if (XINT (x, i) != XINT (y, i))
2298*e4b17023SJohn Marino return 0;
2299*e4b17023SJohn Marino break;
2300*e4b17023SJohn Marino
2301*e4b17023SJohn Marino case 'e':
2302*e4b17023SJohn Marino val = operands_match_p (XEXP (x, i), XEXP (y, i));
2303*e4b17023SJohn Marino if (val == 0)
2304*e4b17023SJohn Marino return 0;
2305*e4b17023SJohn Marino /* If any subexpression returns 2,
2306*e4b17023SJohn Marino we should return 2 if we are successful. */
2307*e4b17023SJohn Marino if (val == 2)
2308*e4b17023SJohn Marino success_2 = 1;
2309*e4b17023SJohn Marino break;
2310*e4b17023SJohn Marino
2311*e4b17023SJohn Marino case '0':
2312*e4b17023SJohn Marino break;
2313*e4b17023SJohn Marino
2314*e4b17023SJohn Marino case 'E':
2315*e4b17023SJohn Marino if (XVECLEN (x, i) != XVECLEN (y, i))
2316*e4b17023SJohn Marino return 0;
2317*e4b17023SJohn Marino for (j = XVECLEN (x, i) - 1; j >= 0; --j)
2318*e4b17023SJohn Marino {
2319*e4b17023SJohn Marino val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j));
2320*e4b17023SJohn Marino if (val == 0)
2321*e4b17023SJohn Marino return 0;
2322*e4b17023SJohn Marino if (val == 2)
2323*e4b17023SJohn Marino success_2 = 1;
2324*e4b17023SJohn Marino }
2325*e4b17023SJohn Marino break;
2326*e4b17023SJohn Marino
2327*e4b17023SJohn Marino /* It is believed that rtx's at this level will never
2328*e4b17023SJohn Marino contain anything but integers and other rtx's,
2329*e4b17023SJohn Marino except for within LABEL_REFs and SYMBOL_REFs. */
2330*e4b17023SJohn Marino default:
2331*e4b17023SJohn Marino gcc_unreachable ();
2332*e4b17023SJohn Marino }
2333*e4b17023SJohn Marino }
2334*e4b17023SJohn Marino return 1 + success_2;
2335*e4b17023SJohn Marino }
2336*e4b17023SJohn Marino
2337*e4b17023SJohn Marino /* Describe the range of registers or memory referenced by X.
2338*e4b17023SJohn Marino If X is a register, set REG_FLAG and put the first register
2339*e4b17023SJohn Marino number into START and the last plus one into END.
2340*e4b17023SJohn Marino If X is a memory reference, put a base address into BASE
2341*e4b17023SJohn Marino and a range of integer offsets into START and END.
2342*e4b17023SJohn Marino If X is pushing on the stack, we can assume it causes no trouble,
2343*e4b17023SJohn Marino so we set the SAFE field. */
2344*e4b17023SJohn Marino
2345*e4b17023SJohn Marino static struct decomposition
decompose(rtx x)2346*e4b17023SJohn Marino decompose (rtx x)
2347*e4b17023SJohn Marino {
2348*e4b17023SJohn Marino struct decomposition val;
2349*e4b17023SJohn Marino int all_const = 0;
2350*e4b17023SJohn Marino
2351*e4b17023SJohn Marino memset (&val, 0, sizeof (val));
2352*e4b17023SJohn Marino
2353*e4b17023SJohn Marino switch (GET_CODE (x))
2354*e4b17023SJohn Marino {
2355*e4b17023SJohn Marino case MEM:
2356*e4b17023SJohn Marino {
2357*e4b17023SJohn Marino rtx base = NULL_RTX, offset = 0;
2358*e4b17023SJohn Marino rtx addr = XEXP (x, 0);
2359*e4b17023SJohn Marino
2360*e4b17023SJohn Marino if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
2361*e4b17023SJohn Marino || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
2362*e4b17023SJohn Marino {
2363*e4b17023SJohn Marino val.base = XEXP (addr, 0);
2364*e4b17023SJohn Marino val.start = -GET_MODE_SIZE (GET_MODE (x));
2365*e4b17023SJohn Marino val.end = GET_MODE_SIZE (GET_MODE (x));
2366*e4b17023SJohn Marino val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2367*e4b17023SJohn Marino return val;
2368*e4b17023SJohn Marino }
2369*e4b17023SJohn Marino
2370*e4b17023SJohn Marino if (GET_CODE (addr) == PRE_MODIFY || GET_CODE (addr) == POST_MODIFY)
2371*e4b17023SJohn Marino {
2372*e4b17023SJohn Marino if (GET_CODE (XEXP (addr, 1)) == PLUS
2373*e4b17023SJohn Marino && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
2374*e4b17023SJohn Marino && CONSTANT_P (XEXP (XEXP (addr, 1), 1)))
2375*e4b17023SJohn Marino {
2376*e4b17023SJohn Marino val.base = XEXP (addr, 0);
2377*e4b17023SJohn Marino val.start = -INTVAL (XEXP (XEXP (addr, 1), 1));
2378*e4b17023SJohn Marino val.end = INTVAL (XEXP (XEXP (addr, 1), 1));
2379*e4b17023SJohn Marino val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2380*e4b17023SJohn Marino return val;
2381*e4b17023SJohn Marino }
2382*e4b17023SJohn Marino }
2383*e4b17023SJohn Marino
2384*e4b17023SJohn Marino if (GET_CODE (addr) == CONST)
2385*e4b17023SJohn Marino {
2386*e4b17023SJohn Marino addr = XEXP (addr, 0);
2387*e4b17023SJohn Marino all_const = 1;
2388*e4b17023SJohn Marino }
2389*e4b17023SJohn Marino if (GET_CODE (addr) == PLUS)
2390*e4b17023SJohn Marino {
2391*e4b17023SJohn Marino if (CONSTANT_P (XEXP (addr, 0)))
2392*e4b17023SJohn Marino {
2393*e4b17023SJohn Marino base = XEXP (addr, 1);
2394*e4b17023SJohn Marino offset = XEXP (addr, 0);
2395*e4b17023SJohn Marino }
2396*e4b17023SJohn Marino else if (CONSTANT_P (XEXP (addr, 1)))
2397*e4b17023SJohn Marino {
2398*e4b17023SJohn Marino base = XEXP (addr, 0);
2399*e4b17023SJohn Marino offset = XEXP (addr, 1);
2400*e4b17023SJohn Marino }
2401*e4b17023SJohn Marino }
2402*e4b17023SJohn Marino
2403*e4b17023SJohn Marino if (offset == 0)
2404*e4b17023SJohn Marino {
2405*e4b17023SJohn Marino base = addr;
2406*e4b17023SJohn Marino offset = const0_rtx;
2407*e4b17023SJohn Marino }
2408*e4b17023SJohn Marino if (GET_CODE (offset) == CONST)
2409*e4b17023SJohn Marino offset = XEXP (offset, 0);
2410*e4b17023SJohn Marino if (GET_CODE (offset) == PLUS)
2411*e4b17023SJohn Marino {
2412*e4b17023SJohn Marino if (CONST_INT_P (XEXP (offset, 0)))
2413*e4b17023SJohn Marino {
2414*e4b17023SJohn Marino base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 1));
2415*e4b17023SJohn Marino offset = XEXP (offset, 0);
2416*e4b17023SJohn Marino }
2417*e4b17023SJohn Marino else if (CONST_INT_P (XEXP (offset, 1)))
2418*e4b17023SJohn Marino {
2419*e4b17023SJohn Marino base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 0));
2420*e4b17023SJohn Marino offset = XEXP (offset, 1);
2421*e4b17023SJohn Marino }
2422*e4b17023SJohn Marino else
2423*e4b17023SJohn Marino {
2424*e4b17023SJohn Marino base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2425*e4b17023SJohn Marino offset = const0_rtx;
2426*e4b17023SJohn Marino }
2427*e4b17023SJohn Marino }
2428*e4b17023SJohn Marino else if (!CONST_INT_P (offset))
2429*e4b17023SJohn Marino {
2430*e4b17023SJohn Marino base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2431*e4b17023SJohn Marino offset = const0_rtx;
2432*e4b17023SJohn Marino }
2433*e4b17023SJohn Marino
2434*e4b17023SJohn Marino if (all_const && GET_CODE (base) == PLUS)
2435*e4b17023SJohn Marino base = gen_rtx_CONST (GET_MODE (base), base);
2436*e4b17023SJohn Marino
2437*e4b17023SJohn Marino gcc_assert (CONST_INT_P (offset));
2438*e4b17023SJohn Marino
2439*e4b17023SJohn Marino val.start = INTVAL (offset);
2440*e4b17023SJohn Marino val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
2441*e4b17023SJohn Marino val.base = base;
2442*e4b17023SJohn Marino }
2443*e4b17023SJohn Marino break;
2444*e4b17023SJohn Marino
2445*e4b17023SJohn Marino case REG:
2446*e4b17023SJohn Marino val.reg_flag = 1;
2447*e4b17023SJohn Marino val.start = true_regnum (x);
2448*e4b17023SJohn Marino if (val.start < 0 || val.start >= FIRST_PSEUDO_REGISTER)
2449*e4b17023SJohn Marino {
2450*e4b17023SJohn Marino /* A pseudo with no hard reg. */
2451*e4b17023SJohn Marino val.start = REGNO (x);
2452*e4b17023SJohn Marino val.end = val.start + 1;
2453*e4b17023SJohn Marino }
2454*e4b17023SJohn Marino else
2455*e4b17023SJohn Marino /* A hard reg. */
2456*e4b17023SJohn Marino val.end = end_hard_regno (GET_MODE (x), val.start);
2457*e4b17023SJohn Marino break;
2458*e4b17023SJohn Marino
2459*e4b17023SJohn Marino case SUBREG:
2460*e4b17023SJohn Marino if (!REG_P (SUBREG_REG (x)))
2461*e4b17023SJohn Marino /* This could be more precise, but it's good enough. */
2462*e4b17023SJohn Marino return decompose (SUBREG_REG (x));
2463*e4b17023SJohn Marino val.reg_flag = 1;
2464*e4b17023SJohn Marino val.start = true_regnum (x);
2465*e4b17023SJohn Marino if (val.start < 0 || val.start >= FIRST_PSEUDO_REGISTER)
2466*e4b17023SJohn Marino return decompose (SUBREG_REG (x));
2467*e4b17023SJohn Marino else
2468*e4b17023SJohn Marino /* A hard reg. */
2469*e4b17023SJohn Marino val.end = val.start + subreg_nregs (x);
2470*e4b17023SJohn Marino break;
2471*e4b17023SJohn Marino
2472*e4b17023SJohn Marino case SCRATCH:
2473*e4b17023SJohn Marino /* This hasn't been assigned yet, so it can't conflict yet. */
2474*e4b17023SJohn Marino val.safe = 1;
2475*e4b17023SJohn Marino break;
2476*e4b17023SJohn Marino
2477*e4b17023SJohn Marino default:
2478*e4b17023SJohn Marino gcc_assert (CONSTANT_P (x));
2479*e4b17023SJohn Marino val.safe = 1;
2480*e4b17023SJohn Marino break;
2481*e4b17023SJohn Marino }
2482*e4b17023SJohn Marino return val;
2483*e4b17023SJohn Marino }
2484*e4b17023SJohn Marino
2485*e4b17023SJohn Marino /* Return 1 if altering Y will not modify the value of X.
2486*e4b17023SJohn Marino Y is also described by YDATA, which should be decompose (Y). */
2487*e4b17023SJohn Marino
2488*e4b17023SJohn Marino static int
immune_p(rtx x,rtx y,struct decomposition ydata)2489*e4b17023SJohn Marino immune_p (rtx x, rtx y, struct decomposition ydata)
2490*e4b17023SJohn Marino {
2491*e4b17023SJohn Marino struct decomposition xdata;
2492*e4b17023SJohn Marino
2493*e4b17023SJohn Marino if (ydata.reg_flag)
2494*e4b17023SJohn Marino return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, (rtx*) 0);
2495*e4b17023SJohn Marino if (ydata.safe)
2496*e4b17023SJohn Marino return 1;
2497*e4b17023SJohn Marino
2498*e4b17023SJohn Marino gcc_assert (MEM_P (y));
2499*e4b17023SJohn Marino /* If Y is memory and X is not, Y can't affect X. */
2500*e4b17023SJohn Marino if (!MEM_P (x))
2501*e4b17023SJohn Marino return 1;
2502*e4b17023SJohn Marino
2503*e4b17023SJohn Marino xdata = decompose (x);
2504*e4b17023SJohn Marino
2505*e4b17023SJohn Marino if (! rtx_equal_p (xdata.base, ydata.base))
2506*e4b17023SJohn Marino {
2507*e4b17023SJohn Marino /* If bases are distinct symbolic constants, there is no overlap. */
2508*e4b17023SJohn Marino if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
2509*e4b17023SJohn Marino return 1;
2510*e4b17023SJohn Marino /* Constants and stack slots never overlap. */
2511*e4b17023SJohn Marino if (CONSTANT_P (xdata.base)
2512*e4b17023SJohn Marino && (ydata.base == frame_pointer_rtx
2513*e4b17023SJohn Marino || ydata.base == hard_frame_pointer_rtx
2514*e4b17023SJohn Marino || ydata.base == stack_pointer_rtx))
2515*e4b17023SJohn Marino return 1;
2516*e4b17023SJohn Marino if (CONSTANT_P (ydata.base)
2517*e4b17023SJohn Marino && (xdata.base == frame_pointer_rtx
2518*e4b17023SJohn Marino || xdata.base == hard_frame_pointer_rtx
2519*e4b17023SJohn Marino || xdata.base == stack_pointer_rtx))
2520*e4b17023SJohn Marino return 1;
2521*e4b17023SJohn Marino /* If either base is variable, we don't know anything. */
2522*e4b17023SJohn Marino return 0;
2523*e4b17023SJohn Marino }
2524*e4b17023SJohn Marino
2525*e4b17023SJohn Marino return (xdata.start >= ydata.end || ydata.start >= xdata.end);
2526*e4b17023SJohn Marino }
2527*e4b17023SJohn Marino
2528*e4b17023SJohn Marino /* Similar, but calls decompose. */
2529*e4b17023SJohn Marino
2530*e4b17023SJohn Marino int
safe_from_earlyclobber(rtx op,rtx clobber)2531*e4b17023SJohn Marino safe_from_earlyclobber (rtx op, rtx clobber)
2532*e4b17023SJohn Marino {
2533*e4b17023SJohn Marino struct decomposition early_data;
2534*e4b17023SJohn Marino
2535*e4b17023SJohn Marino early_data = decompose (clobber);
2536*e4b17023SJohn Marino return immune_p (op, clobber, early_data);
2537*e4b17023SJohn Marino }
2538*e4b17023SJohn Marino
2539*e4b17023SJohn Marino /* Main entry point of this file: search the body of INSN
2540*e4b17023SJohn Marino for values that need reloading and record them with push_reload.
2541*e4b17023SJohn Marino REPLACE nonzero means record also where the values occur
2542*e4b17023SJohn Marino so that subst_reloads can be used.
2543*e4b17023SJohn Marino
2544*e4b17023SJohn Marino IND_LEVELS says how many levels of indirection are supported by this
2545*e4b17023SJohn Marino machine; a value of zero means that a memory reference is not a valid
2546*e4b17023SJohn Marino memory address.
2547*e4b17023SJohn Marino
2548*e4b17023SJohn Marino LIVE_KNOWN says we have valid information about which hard
2549*e4b17023SJohn Marino regs are live at each point in the program; this is true when
2550*e4b17023SJohn Marino we are called from global_alloc but false when stupid register
2551*e4b17023SJohn Marino allocation has been done.
2552*e4b17023SJohn Marino
2553*e4b17023SJohn Marino RELOAD_REG_P if nonzero is a vector indexed by hard reg number
2554*e4b17023SJohn Marino which is nonnegative if the reg has been commandeered for reloading into.
2555*e4b17023SJohn Marino It is copied into STATIC_RELOAD_REG_P and referenced from there
2556*e4b17023SJohn Marino by various subroutines.
2557*e4b17023SJohn Marino
2558*e4b17023SJohn Marino Return TRUE if some operands need to be changed, because of swapping
2559*e4b17023SJohn Marino commutative operands, reg_equiv_address substitution, or whatever. */
2560*e4b17023SJohn Marino
2561*e4b17023SJohn Marino int
find_reloads(rtx insn,int replace,int ind_levels,int live_known,short * reload_reg_p)2562*e4b17023SJohn Marino find_reloads (rtx insn, int replace, int ind_levels, int live_known,
2563*e4b17023SJohn Marino short *reload_reg_p)
2564*e4b17023SJohn Marino {
2565*e4b17023SJohn Marino int insn_code_number;
2566*e4b17023SJohn Marino int i, j;
2567*e4b17023SJohn Marino int noperands;
2568*e4b17023SJohn Marino /* These start out as the constraints for the insn
2569*e4b17023SJohn Marino and they are chewed up as we consider alternatives. */
2570*e4b17023SJohn Marino const char *constraints[MAX_RECOG_OPERANDS];
2571*e4b17023SJohn Marino /* These are the preferred classes for an operand, or NO_REGS if it isn't
2572*e4b17023SJohn Marino a register. */
2573*e4b17023SJohn Marino enum reg_class preferred_class[MAX_RECOG_OPERANDS];
2574*e4b17023SJohn Marino char pref_or_nothing[MAX_RECOG_OPERANDS];
2575*e4b17023SJohn Marino /* Nonzero for a MEM operand whose entire address needs a reload.
2576*e4b17023SJohn Marino May be -1 to indicate the entire address may or may not need a reload. */
2577*e4b17023SJohn Marino int address_reloaded[MAX_RECOG_OPERANDS];
2578*e4b17023SJohn Marino /* Nonzero for an address operand that needs to be completely reloaded.
2579*e4b17023SJohn Marino May be -1 to indicate the entire operand may or may not need a reload. */
2580*e4b17023SJohn Marino int address_operand_reloaded[MAX_RECOG_OPERANDS];
2581*e4b17023SJohn Marino /* Value of enum reload_type to use for operand. */
2582*e4b17023SJohn Marino enum reload_type operand_type[MAX_RECOG_OPERANDS];
2583*e4b17023SJohn Marino /* Value of enum reload_type to use within address of operand. */
2584*e4b17023SJohn Marino enum reload_type address_type[MAX_RECOG_OPERANDS];
2585*e4b17023SJohn Marino /* Save the usage of each operand. */
2586*e4b17023SJohn Marino enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS];
2587*e4b17023SJohn Marino int no_input_reloads = 0, no_output_reloads = 0;
2588*e4b17023SJohn Marino int n_alternatives;
2589*e4b17023SJohn Marino reg_class_t this_alternative[MAX_RECOG_OPERANDS];
2590*e4b17023SJohn Marino char this_alternative_match_win[MAX_RECOG_OPERANDS];
2591*e4b17023SJohn Marino char this_alternative_win[MAX_RECOG_OPERANDS];
2592*e4b17023SJohn Marino char this_alternative_offmemok[MAX_RECOG_OPERANDS];
2593*e4b17023SJohn Marino char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2594*e4b17023SJohn Marino int this_alternative_matches[MAX_RECOG_OPERANDS];
2595*e4b17023SJohn Marino int swapped;
2596*e4b17023SJohn Marino reg_class_t goal_alternative[MAX_RECOG_OPERANDS];
2597*e4b17023SJohn Marino int this_alternative_number;
2598*e4b17023SJohn Marino int goal_alternative_number = 0;
2599*e4b17023SJohn Marino int operand_reloadnum[MAX_RECOG_OPERANDS];
2600*e4b17023SJohn Marino int goal_alternative_matches[MAX_RECOG_OPERANDS];
2601*e4b17023SJohn Marino int goal_alternative_matched[MAX_RECOG_OPERANDS];
2602*e4b17023SJohn Marino char goal_alternative_match_win[MAX_RECOG_OPERANDS];
2603*e4b17023SJohn Marino char goal_alternative_win[MAX_RECOG_OPERANDS];
2604*e4b17023SJohn Marino char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
2605*e4b17023SJohn Marino char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2606*e4b17023SJohn Marino int goal_alternative_swapped;
2607*e4b17023SJohn Marino int best;
2608*e4b17023SJohn Marino int commutative;
2609*e4b17023SJohn Marino char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
2610*e4b17023SJohn Marino rtx substed_operand[MAX_RECOG_OPERANDS];
2611*e4b17023SJohn Marino rtx body = PATTERN (insn);
2612*e4b17023SJohn Marino rtx set = single_set (insn);
2613*e4b17023SJohn Marino int goal_earlyclobber = 0, this_earlyclobber;
2614*e4b17023SJohn Marino enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
2615*e4b17023SJohn Marino int retval = 0;
2616*e4b17023SJohn Marino
2617*e4b17023SJohn Marino this_insn = insn;
2618*e4b17023SJohn Marino n_reloads = 0;
2619*e4b17023SJohn Marino n_replacements = 0;
2620*e4b17023SJohn Marino n_earlyclobbers = 0;
2621*e4b17023SJohn Marino replace_reloads = replace;
2622*e4b17023SJohn Marino hard_regs_live_known = live_known;
2623*e4b17023SJohn Marino static_reload_reg_p = reload_reg_p;
2624*e4b17023SJohn Marino
2625*e4b17023SJohn Marino /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
2626*e4b17023SJohn Marino neither are insns that SET cc0. Insns that use CC0 are not allowed
2627*e4b17023SJohn Marino to have any input reloads. */
2628*e4b17023SJohn Marino if (JUMP_P (insn) || CALL_P (insn))
2629*e4b17023SJohn Marino no_output_reloads = 1;
2630*e4b17023SJohn Marino
2631*e4b17023SJohn Marino #ifdef HAVE_cc0
2632*e4b17023SJohn Marino if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
2633*e4b17023SJohn Marino no_input_reloads = 1;
2634*e4b17023SJohn Marino if (reg_set_p (cc0_rtx, PATTERN (insn)))
2635*e4b17023SJohn Marino no_output_reloads = 1;
2636*e4b17023SJohn Marino #endif
2637*e4b17023SJohn Marino
2638*e4b17023SJohn Marino #ifdef SECONDARY_MEMORY_NEEDED
2639*e4b17023SJohn Marino /* The eliminated forms of any secondary memory locations are per-insn, so
2640*e4b17023SJohn Marino clear them out here. */
2641*e4b17023SJohn Marino
2642*e4b17023SJohn Marino if (secondary_memlocs_elim_used)
2643*e4b17023SJohn Marino {
2644*e4b17023SJohn Marino memset (secondary_memlocs_elim, 0,
2645*e4b17023SJohn Marino sizeof (secondary_memlocs_elim[0]) * secondary_memlocs_elim_used);
2646*e4b17023SJohn Marino secondary_memlocs_elim_used = 0;
2647*e4b17023SJohn Marino }
2648*e4b17023SJohn Marino #endif
2649*e4b17023SJohn Marino
2650*e4b17023SJohn Marino /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2651*e4b17023SJohn Marino is cheap to move between them. If it is not, there may not be an insn
2652*e4b17023SJohn Marino to do the copy, so we may need a reload. */
2653*e4b17023SJohn Marino if (GET_CODE (body) == SET
2654*e4b17023SJohn Marino && REG_P (SET_DEST (body))
2655*e4b17023SJohn Marino && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2656*e4b17023SJohn Marino && REG_P (SET_SRC (body))
2657*e4b17023SJohn Marino && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2658*e4b17023SJohn Marino && register_move_cost (GET_MODE (SET_SRC (body)),
2659*e4b17023SJohn Marino REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2660*e4b17023SJohn Marino REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2661*e4b17023SJohn Marino return 0;
2662*e4b17023SJohn Marino
2663*e4b17023SJohn Marino extract_insn (insn);
2664*e4b17023SJohn Marino
2665*e4b17023SJohn Marino noperands = reload_n_operands = recog_data.n_operands;
2666*e4b17023SJohn Marino n_alternatives = recog_data.n_alternatives;
2667*e4b17023SJohn Marino
2668*e4b17023SJohn Marino /* Just return "no reloads" if insn has no operands with constraints. */
2669*e4b17023SJohn Marino if (noperands == 0 || n_alternatives == 0)
2670*e4b17023SJohn Marino return 0;
2671*e4b17023SJohn Marino
2672*e4b17023SJohn Marino insn_code_number = INSN_CODE (insn);
2673*e4b17023SJohn Marino this_insn_is_asm = insn_code_number < 0;
2674*e4b17023SJohn Marino
2675*e4b17023SJohn Marino memcpy (operand_mode, recog_data.operand_mode,
2676*e4b17023SJohn Marino noperands * sizeof (enum machine_mode));
2677*e4b17023SJohn Marino memcpy (constraints, recog_data.constraints,
2678*e4b17023SJohn Marino noperands * sizeof (const char *));
2679*e4b17023SJohn Marino
2680*e4b17023SJohn Marino commutative = -1;
2681*e4b17023SJohn Marino
2682*e4b17023SJohn Marino /* If we will need to know, later, whether some pair of operands
2683*e4b17023SJohn Marino are the same, we must compare them now and save the result.
2684*e4b17023SJohn Marino Reloading the base and index registers will clobber them
2685*e4b17023SJohn Marino and afterward they will fail to match. */
2686*e4b17023SJohn Marino
2687*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
2688*e4b17023SJohn Marino {
2689*e4b17023SJohn Marino const char *p;
2690*e4b17023SJohn Marino int c;
2691*e4b17023SJohn Marino char *end;
2692*e4b17023SJohn Marino
2693*e4b17023SJohn Marino substed_operand[i] = recog_data.operand[i];
2694*e4b17023SJohn Marino p = constraints[i];
2695*e4b17023SJohn Marino
2696*e4b17023SJohn Marino modified[i] = RELOAD_READ;
2697*e4b17023SJohn Marino
2698*e4b17023SJohn Marino /* Scan this operand's constraint to see if it is an output operand,
2699*e4b17023SJohn Marino an in-out operand, is commutative, or should match another. */
2700*e4b17023SJohn Marino
2701*e4b17023SJohn Marino while ((c = *p))
2702*e4b17023SJohn Marino {
2703*e4b17023SJohn Marino p += CONSTRAINT_LEN (c, p);
2704*e4b17023SJohn Marino switch (c)
2705*e4b17023SJohn Marino {
2706*e4b17023SJohn Marino case '=':
2707*e4b17023SJohn Marino modified[i] = RELOAD_WRITE;
2708*e4b17023SJohn Marino break;
2709*e4b17023SJohn Marino case '+':
2710*e4b17023SJohn Marino modified[i] = RELOAD_READ_WRITE;
2711*e4b17023SJohn Marino break;
2712*e4b17023SJohn Marino case '%':
2713*e4b17023SJohn Marino {
2714*e4b17023SJohn Marino /* The last operand should not be marked commutative. */
2715*e4b17023SJohn Marino gcc_assert (i != noperands - 1);
2716*e4b17023SJohn Marino
2717*e4b17023SJohn Marino /* We currently only support one commutative pair of
2718*e4b17023SJohn Marino operands. Some existing asm code currently uses more
2719*e4b17023SJohn Marino than one pair. Previously, that would usually work,
2720*e4b17023SJohn Marino but sometimes it would crash the compiler. We
2721*e4b17023SJohn Marino continue supporting that case as well as we can by
2722*e4b17023SJohn Marino silently ignoring all but the first pair. In the
2723*e4b17023SJohn Marino future we may handle it correctly. */
2724*e4b17023SJohn Marino if (commutative < 0)
2725*e4b17023SJohn Marino commutative = i;
2726*e4b17023SJohn Marino else
2727*e4b17023SJohn Marino gcc_assert (this_insn_is_asm);
2728*e4b17023SJohn Marino }
2729*e4b17023SJohn Marino break;
2730*e4b17023SJohn Marino /* Use of ISDIGIT is tempting here, but it may get expensive because
2731*e4b17023SJohn Marino of locale support we don't want. */
2732*e4b17023SJohn Marino case '0': case '1': case '2': case '3': case '4':
2733*e4b17023SJohn Marino case '5': case '6': case '7': case '8': case '9':
2734*e4b17023SJohn Marino {
2735*e4b17023SJohn Marino c = strtoul (p - 1, &end, 10);
2736*e4b17023SJohn Marino p = end;
2737*e4b17023SJohn Marino
2738*e4b17023SJohn Marino operands_match[c][i]
2739*e4b17023SJohn Marino = operands_match_p (recog_data.operand[c],
2740*e4b17023SJohn Marino recog_data.operand[i]);
2741*e4b17023SJohn Marino
2742*e4b17023SJohn Marino /* An operand may not match itself. */
2743*e4b17023SJohn Marino gcc_assert (c != i);
2744*e4b17023SJohn Marino
2745*e4b17023SJohn Marino /* If C can be commuted with C+1, and C might need to match I,
2746*e4b17023SJohn Marino then C+1 might also need to match I. */
2747*e4b17023SJohn Marino if (commutative >= 0)
2748*e4b17023SJohn Marino {
2749*e4b17023SJohn Marino if (c == commutative || c == commutative + 1)
2750*e4b17023SJohn Marino {
2751*e4b17023SJohn Marino int other = c + (c == commutative ? 1 : -1);
2752*e4b17023SJohn Marino operands_match[other][i]
2753*e4b17023SJohn Marino = operands_match_p (recog_data.operand[other],
2754*e4b17023SJohn Marino recog_data.operand[i]);
2755*e4b17023SJohn Marino }
2756*e4b17023SJohn Marino if (i == commutative || i == commutative + 1)
2757*e4b17023SJohn Marino {
2758*e4b17023SJohn Marino int other = i + (i == commutative ? 1 : -1);
2759*e4b17023SJohn Marino operands_match[c][other]
2760*e4b17023SJohn Marino = operands_match_p (recog_data.operand[c],
2761*e4b17023SJohn Marino recog_data.operand[other]);
2762*e4b17023SJohn Marino }
2763*e4b17023SJohn Marino /* Note that C is supposed to be less than I.
2764*e4b17023SJohn Marino No need to consider altering both C and I because in
2765*e4b17023SJohn Marino that case we would alter one into the other. */
2766*e4b17023SJohn Marino }
2767*e4b17023SJohn Marino }
2768*e4b17023SJohn Marino }
2769*e4b17023SJohn Marino }
2770*e4b17023SJohn Marino }
2771*e4b17023SJohn Marino
2772*e4b17023SJohn Marino /* Examine each operand that is a memory reference or memory address
2773*e4b17023SJohn Marino and reload parts of the addresses into index registers.
2774*e4b17023SJohn Marino Also here any references to pseudo regs that didn't get hard regs
2775*e4b17023SJohn Marino but are equivalent to constants get replaced in the insn itself
2776*e4b17023SJohn Marino with those constants. Nobody will ever see them again.
2777*e4b17023SJohn Marino
2778*e4b17023SJohn Marino Finally, set up the preferred classes of each operand. */
2779*e4b17023SJohn Marino
2780*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
2781*e4b17023SJohn Marino {
2782*e4b17023SJohn Marino RTX_CODE code = GET_CODE (recog_data.operand[i]);
2783*e4b17023SJohn Marino
2784*e4b17023SJohn Marino address_reloaded[i] = 0;
2785*e4b17023SJohn Marino address_operand_reloaded[i] = 0;
2786*e4b17023SJohn Marino operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT
2787*e4b17023SJohn Marino : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT
2788*e4b17023SJohn Marino : RELOAD_OTHER);
2789*e4b17023SJohn Marino address_type[i]
2790*e4b17023SJohn Marino = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS
2791*e4b17023SJohn Marino : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS
2792*e4b17023SJohn Marino : RELOAD_OTHER);
2793*e4b17023SJohn Marino
2794*e4b17023SJohn Marino if (*constraints[i] == 0)
2795*e4b17023SJohn Marino /* Ignore things like match_operator operands. */
2796*e4b17023SJohn Marino ;
2797*e4b17023SJohn Marino else if (constraints[i][0] == 'p'
2798*e4b17023SJohn Marino || EXTRA_ADDRESS_CONSTRAINT (constraints[i][0], constraints[i]))
2799*e4b17023SJohn Marino {
2800*e4b17023SJohn Marino address_operand_reloaded[i]
2801*e4b17023SJohn Marino = find_reloads_address (recog_data.operand_mode[i], (rtx*) 0,
2802*e4b17023SJohn Marino recog_data.operand[i],
2803*e4b17023SJohn Marino recog_data.operand_loc[i],
2804*e4b17023SJohn Marino i, operand_type[i], ind_levels, insn);
2805*e4b17023SJohn Marino
2806*e4b17023SJohn Marino /* If we now have a simple operand where we used to have a
2807*e4b17023SJohn Marino PLUS or MULT, re-recognize and try again. */
2808*e4b17023SJohn Marino if ((OBJECT_P (*recog_data.operand_loc[i])
2809*e4b17023SJohn Marino || GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
2810*e4b17023SJohn Marino && (GET_CODE (recog_data.operand[i]) == MULT
2811*e4b17023SJohn Marino || GET_CODE (recog_data.operand[i]) == PLUS))
2812*e4b17023SJohn Marino {
2813*e4b17023SJohn Marino INSN_CODE (insn) = -1;
2814*e4b17023SJohn Marino retval = find_reloads (insn, replace, ind_levels, live_known,
2815*e4b17023SJohn Marino reload_reg_p);
2816*e4b17023SJohn Marino return retval;
2817*e4b17023SJohn Marino }
2818*e4b17023SJohn Marino
2819*e4b17023SJohn Marino recog_data.operand[i] = *recog_data.operand_loc[i];
2820*e4b17023SJohn Marino substed_operand[i] = recog_data.operand[i];
2821*e4b17023SJohn Marino
2822*e4b17023SJohn Marino /* Address operands are reloaded in their existing mode,
2823*e4b17023SJohn Marino no matter what is specified in the machine description. */
2824*e4b17023SJohn Marino operand_mode[i] = GET_MODE (recog_data.operand[i]);
2825*e4b17023SJohn Marino
2826*e4b17023SJohn Marino /* If the address is a single CONST_INT pick address mode
2827*e4b17023SJohn Marino instead otherwise we will later not know in which mode
2828*e4b17023SJohn Marino the reload should be performed. */
2829*e4b17023SJohn Marino if (operand_mode[i] == VOIDmode)
2830*e4b17023SJohn Marino operand_mode[i] = Pmode;
2831*e4b17023SJohn Marino
2832*e4b17023SJohn Marino }
2833*e4b17023SJohn Marino else if (code == MEM)
2834*e4b17023SJohn Marino {
2835*e4b17023SJohn Marino address_reloaded[i]
2836*e4b17023SJohn Marino = find_reloads_address (GET_MODE (recog_data.operand[i]),
2837*e4b17023SJohn Marino recog_data.operand_loc[i],
2838*e4b17023SJohn Marino XEXP (recog_data.operand[i], 0),
2839*e4b17023SJohn Marino &XEXP (recog_data.operand[i], 0),
2840*e4b17023SJohn Marino i, address_type[i], ind_levels, insn);
2841*e4b17023SJohn Marino recog_data.operand[i] = *recog_data.operand_loc[i];
2842*e4b17023SJohn Marino substed_operand[i] = recog_data.operand[i];
2843*e4b17023SJohn Marino }
2844*e4b17023SJohn Marino else if (code == SUBREG)
2845*e4b17023SJohn Marino {
2846*e4b17023SJohn Marino rtx reg = SUBREG_REG (recog_data.operand[i]);
2847*e4b17023SJohn Marino rtx op
2848*e4b17023SJohn Marino = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2849*e4b17023SJohn Marino ind_levels,
2850*e4b17023SJohn Marino set != 0
2851*e4b17023SJohn Marino && &SET_DEST (set) == recog_data.operand_loc[i],
2852*e4b17023SJohn Marino insn,
2853*e4b17023SJohn Marino &address_reloaded[i]);
2854*e4b17023SJohn Marino
2855*e4b17023SJohn Marino /* If we made a MEM to load (a part of) the stackslot of a pseudo
2856*e4b17023SJohn Marino that didn't get a hard register, emit a USE with a REG_EQUAL
2857*e4b17023SJohn Marino note in front so that we might inherit a previous, possibly
2858*e4b17023SJohn Marino wider reload. */
2859*e4b17023SJohn Marino
2860*e4b17023SJohn Marino if (replace
2861*e4b17023SJohn Marino && MEM_P (op)
2862*e4b17023SJohn Marino && REG_P (reg)
2863*e4b17023SJohn Marino && (GET_MODE_SIZE (GET_MODE (reg))
2864*e4b17023SJohn Marino >= GET_MODE_SIZE (GET_MODE (op)))
2865*e4b17023SJohn Marino && reg_equiv_constant (REGNO (reg)) == 0)
2866*e4b17023SJohn Marino set_unique_reg_note (emit_insn_before (gen_rtx_USE (VOIDmode, reg),
2867*e4b17023SJohn Marino insn),
2868*e4b17023SJohn Marino REG_EQUAL, reg_equiv_memory_loc (REGNO (reg)));
2869*e4b17023SJohn Marino
2870*e4b17023SJohn Marino substed_operand[i] = recog_data.operand[i] = op;
2871*e4b17023SJohn Marino }
2872*e4b17023SJohn Marino else if (code == PLUS || GET_RTX_CLASS (code) == RTX_UNARY)
2873*e4b17023SJohn Marino /* We can get a PLUS as an "operand" as a result of register
2874*e4b17023SJohn Marino elimination. See eliminate_regs and gen_reload. We handle
2875*e4b17023SJohn Marino a unary operator by reloading the operand. */
2876*e4b17023SJohn Marino substed_operand[i] = recog_data.operand[i]
2877*e4b17023SJohn Marino = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2878*e4b17023SJohn Marino ind_levels, 0, insn,
2879*e4b17023SJohn Marino &address_reloaded[i]);
2880*e4b17023SJohn Marino else if (code == REG)
2881*e4b17023SJohn Marino {
2882*e4b17023SJohn Marino /* This is equivalent to calling find_reloads_toplev.
2883*e4b17023SJohn Marino The code is duplicated for speed.
2884*e4b17023SJohn Marino When we find a pseudo always equivalent to a constant,
2885*e4b17023SJohn Marino we replace it by the constant. We must be sure, however,
2886*e4b17023SJohn Marino that we don't try to replace it in the insn in which it
2887*e4b17023SJohn Marino is being set. */
2888*e4b17023SJohn Marino int regno = REGNO (recog_data.operand[i]);
2889*e4b17023SJohn Marino if (reg_equiv_constant (regno) != 0
2890*e4b17023SJohn Marino && (set == 0 || &SET_DEST (set) != recog_data.operand_loc[i]))
2891*e4b17023SJohn Marino {
2892*e4b17023SJohn Marino /* Record the existing mode so that the check if constants are
2893*e4b17023SJohn Marino allowed will work when operand_mode isn't specified. */
2894*e4b17023SJohn Marino
2895*e4b17023SJohn Marino if (operand_mode[i] == VOIDmode)
2896*e4b17023SJohn Marino operand_mode[i] = GET_MODE (recog_data.operand[i]);
2897*e4b17023SJohn Marino
2898*e4b17023SJohn Marino substed_operand[i] = recog_data.operand[i]
2899*e4b17023SJohn Marino = reg_equiv_constant (regno);
2900*e4b17023SJohn Marino }
2901*e4b17023SJohn Marino if (reg_equiv_memory_loc (regno) != 0
2902*e4b17023SJohn Marino && (reg_equiv_address (regno) != 0 || num_not_at_initial_offset))
2903*e4b17023SJohn Marino /* We need not give a valid is_set_dest argument since the case
2904*e4b17023SJohn Marino of a constant equivalence was checked above. */
2905*e4b17023SJohn Marino substed_operand[i] = recog_data.operand[i]
2906*e4b17023SJohn Marino = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2907*e4b17023SJohn Marino ind_levels, 0, insn,
2908*e4b17023SJohn Marino &address_reloaded[i]);
2909*e4b17023SJohn Marino }
2910*e4b17023SJohn Marino /* If the operand is still a register (we didn't replace it with an
2911*e4b17023SJohn Marino equivalent), get the preferred class to reload it into. */
2912*e4b17023SJohn Marino code = GET_CODE (recog_data.operand[i]);
2913*e4b17023SJohn Marino preferred_class[i]
2914*e4b17023SJohn Marino = ((code == REG && REGNO (recog_data.operand[i])
2915*e4b17023SJohn Marino >= FIRST_PSEUDO_REGISTER)
2916*e4b17023SJohn Marino ? reg_preferred_class (REGNO (recog_data.operand[i]))
2917*e4b17023SJohn Marino : NO_REGS);
2918*e4b17023SJohn Marino pref_or_nothing[i]
2919*e4b17023SJohn Marino = (code == REG
2920*e4b17023SJohn Marino && REGNO (recog_data.operand[i]) >= FIRST_PSEUDO_REGISTER
2921*e4b17023SJohn Marino && reg_alternate_class (REGNO (recog_data.operand[i])) == NO_REGS);
2922*e4b17023SJohn Marino }
2923*e4b17023SJohn Marino
2924*e4b17023SJohn Marino /* If this is simply a copy from operand 1 to operand 0, merge the
2925*e4b17023SJohn Marino preferred classes for the operands. */
2926*e4b17023SJohn Marino if (set != 0 && noperands >= 2 && recog_data.operand[0] == SET_DEST (set)
2927*e4b17023SJohn Marino && recog_data.operand[1] == SET_SRC (set))
2928*e4b17023SJohn Marino {
2929*e4b17023SJohn Marino preferred_class[0] = preferred_class[1]
2930*e4b17023SJohn Marino = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2931*e4b17023SJohn Marino pref_or_nothing[0] |= pref_or_nothing[1];
2932*e4b17023SJohn Marino pref_or_nothing[1] |= pref_or_nothing[0];
2933*e4b17023SJohn Marino }
2934*e4b17023SJohn Marino
2935*e4b17023SJohn Marino /* Now see what we need for pseudo-regs that didn't get hard regs
2936*e4b17023SJohn Marino or got the wrong kind of hard reg. For this, we must consider
2937*e4b17023SJohn Marino all the operands together against the register constraints. */
2938*e4b17023SJohn Marino
2939*e4b17023SJohn Marino best = MAX_RECOG_OPERANDS * 2 + 600;
2940*e4b17023SJohn Marino
2941*e4b17023SJohn Marino swapped = 0;
2942*e4b17023SJohn Marino goal_alternative_swapped = 0;
2943*e4b17023SJohn Marino try_swapped:
2944*e4b17023SJohn Marino
2945*e4b17023SJohn Marino /* The constraints are made of several alternatives.
2946*e4b17023SJohn Marino Each operand's constraint looks like foo,bar,... with commas
2947*e4b17023SJohn Marino separating the alternatives. The first alternatives for all
2948*e4b17023SJohn Marino operands go together, the second alternatives go together, etc.
2949*e4b17023SJohn Marino
2950*e4b17023SJohn Marino First loop over alternatives. */
2951*e4b17023SJohn Marino
2952*e4b17023SJohn Marino for (this_alternative_number = 0;
2953*e4b17023SJohn Marino this_alternative_number < n_alternatives;
2954*e4b17023SJohn Marino this_alternative_number++)
2955*e4b17023SJohn Marino {
2956*e4b17023SJohn Marino /* Loop over operands for one constraint alternative. */
2957*e4b17023SJohn Marino /* LOSERS counts those that don't fit this alternative
2958*e4b17023SJohn Marino and would require loading. */
2959*e4b17023SJohn Marino int losers = 0;
2960*e4b17023SJohn Marino /* BAD is set to 1 if it some operand can't fit this alternative
2961*e4b17023SJohn Marino even after reloading. */
2962*e4b17023SJohn Marino int bad = 0;
2963*e4b17023SJohn Marino /* REJECT is a count of how undesirable this alternative says it is
2964*e4b17023SJohn Marino if any reloading is required. If the alternative matches exactly
2965*e4b17023SJohn Marino then REJECT is ignored, but otherwise it gets this much
2966*e4b17023SJohn Marino counted against it in addition to the reloading needed. Each
2967*e4b17023SJohn Marino ? counts three times here since we want the disparaging caused by
2968*e4b17023SJohn Marino a bad register class to only count 1/3 as much. */
2969*e4b17023SJohn Marino int reject = 0;
2970*e4b17023SJohn Marino
2971*e4b17023SJohn Marino if (!recog_data.alternative_enabled_p[this_alternative_number])
2972*e4b17023SJohn Marino {
2973*e4b17023SJohn Marino int i;
2974*e4b17023SJohn Marino
2975*e4b17023SJohn Marino for (i = 0; i < recog_data.n_operands; i++)
2976*e4b17023SJohn Marino constraints[i] = skip_alternative (constraints[i]);
2977*e4b17023SJohn Marino
2978*e4b17023SJohn Marino continue;
2979*e4b17023SJohn Marino }
2980*e4b17023SJohn Marino
2981*e4b17023SJohn Marino this_earlyclobber = 0;
2982*e4b17023SJohn Marino
2983*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
2984*e4b17023SJohn Marino {
2985*e4b17023SJohn Marino const char *p = constraints[i];
2986*e4b17023SJohn Marino char *end;
2987*e4b17023SJohn Marino int len;
2988*e4b17023SJohn Marino int win = 0;
2989*e4b17023SJohn Marino int did_match = 0;
2990*e4b17023SJohn Marino /* 0 => this operand can be reloaded somehow for this alternative. */
2991*e4b17023SJohn Marino int badop = 1;
2992*e4b17023SJohn Marino /* 0 => this operand can be reloaded if the alternative allows regs. */
2993*e4b17023SJohn Marino int winreg = 0;
2994*e4b17023SJohn Marino int c;
2995*e4b17023SJohn Marino int m;
2996*e4b17023SJohn Marino rtx operand = recog_data.operand[i];
2997*e4b17023SJohn Marino int offset = 0;
2998*e4b17023SJohn Marino /* Nonzero means this is a MEM that must be reloaded into a reg
2999*e4b17023SJohn Marino regardless of what the constraint says. */
3000*e4b17023SJohn Marino int force_reload = 0;
3001*e4b17023SJohn Marino int offmemok = 0;
3002*e4b17023SJohn Marino /* Nonzero if a constant forced into memory would be OK for this
3003*e4b17023SJohn Marino operand. */
3004*e4b17023SJohn Marino int constmemok = 0;
3005*e4b17023SJohn Marino int earlyclobber = 0;
3006*e4b17023SJohn Marino
3007*e4b17023SJohn Marino /* If the predicate accepts a unary operator, it means that
3008*e4b17023SJohn Marino we need to reload the operand, but do not do this for
3009*e4b17023SJohn Marino match_operator and friends. */
3010*e4b17023SJohn Marino if (UNARY_P (operand) && *p != 0)
3011*e4b17023SJohn Marino operand = XEXP (operand, 0);
3012*e4b17023SJohn Marino
3013*e4b17023SJohn Marino /* If the operand is a SUBREG, extract
3014*e4b17023SJohn Marino the REG or MEM (or maybe even a constant) within.
3015*e4b17023SJohn Marino (Constants can occur as a result of reg_equiv_constant.) */
3016*e4b17023SJohn Marino
3017*e4b17023SJohn Marino while (GET_CODE (operand) == SUBREG)
3018*e4b17023SJohn Marino {
3019*e4b17023SJohn Marino /* Offset only matters when operand is a REG and
3020*e4b17023SJohn Marino it is a hard reg. This is because it is passed
3021*e4b17023SJohn Marino to reg_fits_class_p if it is a REG and all pseudos
3022*e4b17023SJohn Marino return 0 from that function. */
3023*e4b17023SJohn Marino if (REG_P (SUBREG_REG (operand))
3024*e4b17023SJohn Marino && REGNO (SUBREG_REG (operand)) < FIRST_PSEUDO_REGISTER)
3025*e4b17023SJohn Marino {
3026*e4b17023SJohn Marino if (simplify_subreg_regno (REGNO (SUBREG_REG (operand)),
3027*e4b17023SJohn Marino GET_MODE (SUBREG_REG (operand)),
3028*e4b17023SJohn Marino SUBREG_BYTE (operand),
3029*e4b17023SJohn Marino GET_MODE (operand)) < 0)
3030*e4b17023SJohn Marino force_reload = 1;
3031*e4b17023SJohn Marino offset += subreg_regno_offset (REGNO (SUBREG_REG (operand)),
3032*e4b17023SJohn Marino GET_MODE (SUBREG_REG (operand)),
3033*e4b17023SJohn Marino SUBREG_BYTE (operand),
3034*e4b17023SJohn Marino GET_MODE (operand));
3035*e4b17023SJohn Marino }
3036*e4b17023SJohn Marino operand = SUBREG_REG (operand);
3037*e4b17023SJohn Marino /* Force reload if this is a constant or PLUS or if there may
3038*e4b17023SJohn Marino be a problem accessing OPERAND in the outer mode. */
3039*e4b17023SJohn Marino if (CONSTANT_P (operand)
3040*e4b17023SJohn Marino || GET_CODE (operand) == PLUS
3041*e4b17023SJohn Marino /* We must force a reload of paradoxical SUBREGs
3042*e4b17023SJohn Marino of a MEM because the alignment of the inner value
3043*e4b17023SJohn Marino may not be enough to do the outer reference. On
3044*e4b17023SJohn Marino big-endian machines, it may also reference outside
3045*e4b17023SJohn Marino the object.
3046*e4b17023SJohn Marino
3047*e4b17023SJohn Marino On machines that extend byte operations and we have a
3048*e4b17023SJohn Marino SUBREG where both the inner and outer modes are no wider
3049*e4b17023SJohn Marino than a word and the inner mode is narrower, is integral,
3050*e4b17023SJohn Marino and gets extended when loaded from memory, combine.c has
3051*e4b17023SJohn Marino made assumptions about the behavior of the machine in such
3052*e4b17023SJohn Marino register access. If the data is, in fact, in memory we
3053*e4b17023SJohn Marino must always load using the size assumed to be in the
3054*e4b17023SJohn Marino register and let the insn do the different-sized
3055*e4b17023SJohn Marino accesses.
3056*e4b17023SJohn Marino
3057*e4b17023SJohn Marino This is doubly true if WORD_REGISTER_OPERATIONS. In
3058*e4b17023SJohn Marino this case eliminate_regs has left non-paradoxical
3059*e4b17023SJohn Marino subregs for push_reload to see. Make sure it does
3060*e4b17023SJohn Marino by forcing the reload.
3061*e4b17023SJohn Marino
3062*e4b17023SJohn Marino ??? When is it right at this stage to have a subreg
3063*e4b17023SJohn Marino of a mem that is _not_ to be handled specially? IMO
3064*e4b17023SJohn Marino those should have been reduced to just a mem. */
3065*e4b17023SJohn Marino || ((MEM_P (operand)
3066*e4b17023SJohn Marino || (REG_P (operand)
3067*e4b17023SJohn Marino && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3068*e4b17023SJohn Marino #ifndef WORD_REGISTER_OPERATIONS
3069*e4b17023SJohn Marino && (((GET_MODE_BITSIZE (GET_MODE (operand))
3070*e4b17023SJohn Marino < BIGGEST_ALIGNMENT)
3071*e4b17023SJohn Marino && (GET_MODE_SIZE (operand_mode[i])
3072*e4b17023SJohn Marino > GET_MODE_SIZE (GET_MODE (operand))))
3073*e4b17023SJohn Marino || BYTES_BIG_ENDIAN
3074*e4b17023SJohn Marino #ifdef LOAD_EXTEND_OP
3075*e4b17023SJohn Marino || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3076*e4b17023SJohn Marino && (GET_MODE_SIZE (GET_MODE (operand))
3077*e4b17023SJohn Marino <= UNITS_PER_WORD)
3078*e4b17023SJohn Marino && (GET_MODE_SIZE (operand_mode[i])
3079*e4b17023SJohn Marino > GET_MODE_SIZE (GET_MODE (operand)))
3080*e4b17023SJohn Marino && INTEGRAL_MODE_P (GET_MODE (operand))
3081*e4b17023SJohn Marino && LOAD_EXTEND_OP (GET_MODE (operand)) != UNKNOWN)
3082*e4b17023SJohn Marino #endif
3083*e4b17023SJohn Marino )
3084*e4b17023SJohn Marino #endif
3085*e4b17023SJohn Marino )
3086*e4b17023SJohn Marino )
3087*e4b17023SJohn Marino force_reload = 1;
3088*e4b17023SJohn Marino }
3089*e4b17023SJohn Marino
3090*e4b17023SJohn Marino this_alternative[i] = NO_REGS;
3091*e4b17023SJohn Marino this_alternative_win[i] = 0;
3092*e4b17023SJohn Marino this_alternative_match_win[i] = 0;
3093*e4b17023SJohn Marino this_alternative_offmemok[i] = 0;
3094*e4b17023SJohn Marino this_alternative_earlyclobber[i] = 0;
3095*e4b17023SJohn Marino this_alternative_matches[i] = -1;
3096*e4b17023SJohn Marino
3097*e4b17023SJohn Marino /* An empty constraint or empty alternative
3098*e4b17023SJohn Marino allows anything which matched the pattern. */
3099*e4b17023SJohn Marino if (*p == 0 || *p == ',')
3100*e4b17023SJohn Marino win = 1, badop = 0;
3101*e4b17023SJohn Marino
3102*e4b17023SJohn Marino /* Scan this alternative's specs for this operand;
3103*e4b17023SJohn Marino set WIN if the operand fits any letter in this alternative.
3104*e4b17023SJohn Marino Otherwise, clear BADOP if this operand could
3105*e4b17023SJohn Marino fit some letter after reloads,
3106*e4b17023SJohn Marino or set WINREG if this operand could fit after reloads
3107*e4b17023SJohn Marino provided the constraint allows some registers. */
3108*e4b17023SJohn Marino
3109*e4b17023SJohn Marino do
3110*e4b17023SJohn Marino switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
3111*e4b17023SJohn Marino {
3112*e4b17023SJohn Marino case '\0':
3113*e4b17023SJohn Marino len = 0;
3114*e4b17023SJohn Marino break;
3115*e4b17023SJohn Marino case ',':
3116*e4b17023SJohn Marino c = '\0';
3117*e4b17023SJohn Marino break;
3118*e4b17023SJohn Marino
3119*e4b17023SJohn Marino case '=': case '+': case '*':
3120*e4b17023SJohn Marino break;
3121*e4b17023SJohn Marino
3122*e4b17023SJohn Marino case '%':
3123*e4b17023SJohn Marino /* We only support one commutative marker, the first
3124*e4b17023SJohn Marino one. We already set commutative above. */
3125*e4b17023SJohn Marino break;
3126*e4b17023SJohn Marino
3127*e4b17023SJohn Marino case '?':
3128*e4b17023SJohn Marino reject += 6;
3129*e4b17023SJohn Marino break;
3130*e4b17023SJohn Marino
3131*e4b17023SJohn Marino case '!':
3132*e4b17023SJohn Marino reject = 600;
3133*e4b17023SJohn Marino break;
3134*e4b17023SJohn Marino
3135*e4b17023SJohn Marino case '#':
3136*e4b17023SJohn Marino /* Ignore rest of this alternative as far as
3137*e4b17023SJohn Marino reloading is concerned. */
3138*e4b17023SJohn Marino do
3139*e4b17023SJohn Marino p++;
3140*e4b17023SJohn Marino while (*p && *p != ',');
3141*e4b17023SJohn Marino len = 0;
3142*e4b17023SJohn Marino break;
3143*e4b17023SJohn Marino
3144*e4b17023SJohn Marino case '0': case '1': case '2': case '3': case '4':
3145*e4b17023SJohn Marino case '5': case '6': case '7': case '8': case '9':
3146*e4b17023SJohn Marino m = strtoul (p, &end, 10);
3147*e4b17023SJohn Marino p = end;
3148*e4b17023SJohn Marino len = 0;
3149*e4b17023SJohn Marino
3150*e4b17023SJohn Marino this_alternative_matches[i] = m;
3151*e4b17023SJohn Marino /* We are supposed to match a previous operand.
3152*e4b17023SJohn Marino If we do, we win if that one did.
3153*e4b17023SJohn Marino If we do not, count both of the operands as losers.
3154*e4b17023SJohn Marino (This is too conservative, since most of the time
3155*e4b17023SJohn Marino only a single reload insn will be needed to make
3156*e4b17023SJohn Marino the two operands win. As a result, this alternative
3157*e4b17023SJohn Marino may be rejected when it is actually desirable.) */
3158*e4b17023SJohn Marino if ((swapped && (m != commutative || i != commutative + 1))
3159*e4b17023SJohn Marino /* If we are matching as if two operands were swapped,
3160*e4b17023SJohn Marino also pretend that operands_match had been computed
3161*e4b17023SJohn Marino with swapped.
3162*e4b17023SJohn Marino But if I is the second of those and C is the first,
3163*e4b17023SJohn Marino don't exchange them, because operands_match is valid
3164*e4b17023SJohn Marino only on one side of its diagonal. */
3165*e4b17023SJohn Marino ? (operands_match
3166*e4b17023SJohn Marino [(m == commutative || m == commutative + 1)
3167*e4b17023SJohn Marino ? 2 * commutative + 1 - m : m]
3168*e4b17023SJohn Marino [(i == commutative || i == commutative + 1)
3169*e4b17023SJohn Marino ? 2 * commutative + 1 - i : i])
3170*e4b17023SJohn Marino : operands_match[m][i])
3171*e4b17023SJohn Marino {
3172*e4b17023SJohn Marino /* If we are matching a non-offsettable address where an
3173*e4b17023SJohn Marino offsettable address was expected, then we must reject
3174*e4b17023SJohn Marino this combination, because we can't reload it. */
3175*e4b17023SJohn Marino if (this_alternative_offmemok[m]
3176*e4b17023SJohn Marino && MEM_P (recog_data.operand[m])
3177*e4b17023SJohn Marino && this_alternative[m] == NO_REGS
3178*e4b17023SJohn Marino && ! this_alternative_win[m])
3179*e4b17023SJohn Marino bad = 1;
3180*e4b17023SJohn Marino
3181*e4b17023SJohn Marino did_match = this_alternative_win[m];
3182*e4b17023SJohn Marino }
3183*e4b17023SJohn Marino else
3184*e4b17023SJohn Marino {
3185*e4b17023SJohn Marino /* Operands don't match. */
3186*e4b17023SJohn Marino rtx value;
3187*e4b17023SJohn Marino int loc1, loc2;
3188*e4b17023SJohn Marino /* Retroactively mark the operand we had to match
3189*e4b17023SJohn Marino as a loser, if it wasn't already. */
3190*e4b17023SJohn Marino if (this_alternative_win[m])
3191*e4b17023SJohn Marino losers++;
3192*e4b17023SJohn Marino this_alternative_win[m] = 0;
3193*e4b17023SJohn Marino if (this_alternative[m] == NO_REGS)
3194*e4b17023SJohn Marino bad = 1;
3195*e4b17023SJohn Marino /* But count the pair only once in the total badness of
3196*e4b17023SJohn Marino this alternative, if the pair can be a dummy reload.
3197*e4b17023SJohn Marino The pointers in operand_loc are not swapped; swap
3198*e4b17023SJohn Marino them by hand if necessary. */
3199*e4b17023SJohn Marino if (swapped && i == commutative)
3200*e4b17023SJohn Marino loc1 = commutative + 1;
3201*e4b17023SJohn Marino else if (swapped && i == commutative + 1)
3202*e4b17023SJohn Marino loc1 = commutative;
3203*e4b17023SJohn Marino else
3204*e4b17023SJohn Marino loc1 = i;
3205*e4b17023SJohn Marino if (swapped && m == commutative)
3206*e4b17023SJohn Marino loc2 = commutative + 1;
3207*e4b17023SJohn Marino else if (swapped && m == commutative + 1)
3208*e4b17023SJohn Marino loc2 = commutative;
3209*e4b17023SJohn Marino else
3210*e4b17023SJohn Marino loc2 = m;
3211*e4b17023SJohn Marino value
3212*e4b17023SJohn Marino = find_dummy_reload (recog_data.operand[i],
3213*e4b17023SJohn Marino recog_data.operand[m],
3214*e4b17023SJohn Marino recog_data.operand_loc[loc1],
3215*e4b17023SJohn Marino recog_data.operand_loc[loc2],
3216*e4b17023SJohn Marino operand_mode[i], operand_mode[m],
3217*e4b17023SJohn Marino this_alternative[m], -1,
3218*e4b17023SJohn Marino this_alternative_earlyclobber[m]);
3219*e4b17023SJohn Marino
3220*e4b17023SJohn Marino if (value != 0)
3221*e4b17023SJohn Marino losers--;
3222*e4b17023SJohn Marino }
3223*e4b17023SJohn Marino /* This can be fixed with reloads if the operand
3224*e4b17023SJohn Marino we are supposed to match can be fixed with reloads. */
3225*e4b17023SJohn Marino badop = 0;
3226*e4b17023SJohn Marino this_alternative[i] = this_alternative[m];
3227*e4b17023SJohn Marino
3228*e4b17023SJohn Marino /* If we have to reload this operand and some previous
3229*e4b17023SJohn Marino operand also had to match the same thing as this
3230*e4b17023SJohn Marino operand, we don't know how to do that. So reject this
3231*e4b17023SJohn Marino alternative. */
3232*e4b17023SJohn Marino if (! did_match || force_reload)
3233*e4b17023SJohn Marino for (j = 0; j < i; j++)
3234*e4b17023SJohn Marino if (this_alternative_matches[j]
3235*e4b17023SJohn Marino == this_alternative_matches[i])
3236*e4b17023SJohn Marino badop = 1;
3237*e4b17023SJohn Marino break;
3238*e4b17023SJohn Marino
3239*e4b17023SJohn Marino case 'p':
3240*e4b17023SJohn Marino /* All necessary reloads for an address_operand
3241*e4b17023SJohn Marino were handled in find_reloads_address. */
3242*e4b17023SJohn Marino this_alternative[i]
3243*e4b17023SJohn Marino = base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
3244*e4b17023SJohn Marino ADDRESS, SCRATCH);
3245*e4b17023SJohn Marino win = 1;
3246*e4b17023SJohn Marino badop = 0;
3247*e4b17023SJohn Marino break;
3248*e4b17023SJohn Marino
3249*e4b17023SJohn Marino case TARGET_MEM_CONSTRAINT:
3250*e4b17023SJohn Marino if (force_reload)
3251*e4b17023SJohn Marino break;
3252*e4b17023SJohn Marino if (MEM_P (operand)
3253*e4b17023SJohn Marino || (REG_P (operand)
3254*e4b17023SJohn Marino && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3255*e4b17023SJohn Marino && reg_renumber[REGNO (operand)] < 0))
3256*e4b17023SJohn Marino win = 1;
3257*e4b17023SJohn Marino if (CONST_POOL_OK_P (operand_mode[i], operand))
3258*e4b17023SJohn Marino badop = 0;
3259*e4b17023SJohn Marino constmemok = 1;
3260*e4b17023SJohn Marino break;
3261*e4b17023SJohn Marino
3262*e4b17023SJohn Marino case '<':
3263*e4b17023SJohn Marino if (MEM_P (operand)
3264*e4b17023SJohn Marino && ! address_reloaded[i]
3265*e4b17023SJohn Marino && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
3266*e4b17023SJohn Marino || GET_CODE (XEXP (operand, 0)) == POST_DEC))
3267*e4b17023SJohn Marino win = 1;
3268*e4b17023SJohn Marino break;
3269*e4b17023SJohn Marino
3270*e4b17023SJohn Marino case '>':
3271*e4b17023SJohn Marino if (MEM_P (operand)
3272*e4b17023SJohn Marino && ! address_reloaded[i]
3273*e4b17023SJohn Marino && (GET_CODE (XEXP (operand, 0)) == PRE_INC
3274*e4b17023SJohn Marino || GET_CODE (XEXP (operand, 0)) == POST_INC))
3275*e4b17023SJohn Marino win = 1;
3276*e4b17023SJohn Marino break;
3277*e4b17023SJohn Marino
3278*e4b17023SJohn Marino /* Memory operand whose address is not offsettable. */
3279*e4b17023SJohn Marino case 'V':
3280*e4b17023SJohn Marino if (force_reload)
3281*e4b17023SJohn Marino break;
3282*e4b17023SJohn Marino if (MEM_P (operand)
3283*e4b17023SJohn Marino && ! (ind_levels ? offsettable_memref_p (operand)
3284*e4b17023SJohn Marino : offsettable_nonstrict_memref_p (operand))
3285*e4b17023SJohn Marino /* Certain mem addresses will become offsettable
3286*e4b17023SJohn Marino after they themselves are reloaded. This is important;
3287*e4b17023SJohn Marino we don't want our own handling of unoffsettables
3288*e4b17023SJohn Marino to override the handling of reg_equiv_address. */
3289*e4b17023SJohn Marino && !(REG_P (XEXP (operand, 0))
3290*e4b17023SJohn Marino && (ind_levels == 0
3291*e4b17023SJohn Marino || reg_equiv_address (REGNO (XEXP (operand, 0))) != 0)))
3292*e4b17023SJohn Marino win = 1;
3293*e4b17023SJohn Marino break;
3294*e4b17023SJohn Marino
3295*e4b17023SJohn Marino /* Memory operand whose address is offsettable. */
3296*e4b17023SJohn Marino case 'o':
3297*e4b17023SJohn Marino if (force_reload)
3298*e4b17023SJohn Marino break;
3299*e4b17023SJohn Marino if ((MEM_P (operand)
3300*e4b17023SJohn Marino /* If IND_LEVELS, find_reloads_address won't reload a
3301*e4b17023SJohn Marino pseudo that didn't get a hard reg, so we have to
3302*e4b17023SJohn Marino reject that case. */
3303*e4b17023SJohn Marino && ((ind_levels ? offsettable_memref_p (operand)
3304*e4b17023SJohn Marino : offsettable_nonstrict_memref_p (operand))
3305*e4b17023SJohn Marino /* A reloaded address is offsettable because it is now
3306*e4b17023SJohn Marino just a simple register indirect. */
3307*e4b17023SJohn Marino || address_reloaded[i] == 1))
3308*e4b17023SJohn Marino || (REG_P (operand)
3309*e4b17023SJohn Marino && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3310*e4b17023SJohn Marino && reg_renumber[REGNO (operand)] < 0
3311*e4b17023SJohn Marino /* If reg_equiv_address is nonzero, we will be
3312*e4b17023SJohn Marino loading it into a register; hence it will be
3313*e4b17023SJohn Marino offsettable, but we cannot say that reg_equiv_mem
3314*e4b17023SJohn Marino is offsettable without checking. */
3315*e4b17023SJohn Marino && ((reg_equiv_mem (REGNO (operand)) != 0
3316*e4b17023SJohn Marino && offsettable_memref_p (reg_equiv_mem (REGNO (operand))))
3317*e4b17023SJohn Marino || (reg_equiv_address (REGNO (operand)) != 0))))
3318*e4b17023SJohn Marino win = 1;
3319*e4b17023SJohn Marino if (CONST_POOL_OK_P (operand_mode[i], operand)
3320*e4b17023SJohn Marino || MEM_P (operand))
3321*e4b17023SJohn Marino badop = 0;
3322*e4b17023SJohn Marino constmemok = 1;
3323*e4b17023SJohn Marino offmemok = 1;
3324*e4b17023SJohn Marino break;
3325*e4b17023SJohn Marino
3326*e4b17023SJohn Marino case '&':
3327*e4b17023SJohn Marino /* Output operand that is stored before the need for the
3328*e4b17023SJohn Marino input operands (and their index registers) is over. */
3329*e4b17023SJohn Marino earlyclobber = 1, this_earlyclobber = 1;
3330*e4b17023SJohn Marino break;
3331*e4b17023SJohn Marino
3332*e4b17023SJohn Marino case 'E':
3333*e4b17023SJohn Marino case 'F':
3334*e4b17023SJohn Marino if (GET_CODE (operand) == CONST_DOUBLE
3335*e4b17023SJohn Marino || (GET_CODE (operand) == CONST_VECTOR
3336*e4b17023SJohn Marino && (GET_MODE_CLASS (GET_MODE (operand))
3337*e4b17023SJohn Marino == MODE_VECTOR_FLOAT)))
3338*e4b17023SJohn Marino win = 1;
3339*e4b17023SJohn Marino break;
3340*e4b17023SJohn Marino
3341*e4b17023SJohn Marino case 'G':
3342*e4b17023SJohn Marino case 'H':
3343*e4b17023SJohn Marino if (GET_CODE (operand) == CONST_DOUBLE
3344*e4b17023SJohn Marino && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (operand, c, p))
3345*e4b17023SJohn Marino win = 1;
3346*e4b17023SJohn Marino break;
3347*e4b17023SJohn Marino
3348*e4b17023SJohn Marino case 's':
3349*e4b17023SJohn Marino if (CONST_INT_P (operand)
3350*e4b17023SJohn Marino || (GET_CODE (operand) == CONST_DOUBLE
3351*e4b17023SJohn Marino && GET_MODE (operand) == VOIDmode))
3352*e4b17023SJohn Marino break;
3353*e4b17023SJohn Marino case 'i':
3354*e4b17023SJohn Marino if (CONSTANT_P (operand)
3355*e4b17023SJohn Marino && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand)))
3356*e4b17023SJohn Marino win = 1;
3357*e4b17023SJohn Marino break;
3358*e4b17023SJohn Marino
3359*e4b17023SJohn Marino case 'n':
3360*e4b17023SJohn Marino if (CONST_INT_P (operand)
3361*e4b17023SJohn Marino || (GET_CODE (operand) == CONST_DOUBLE
3362*e4b17023SJohn Marino && GET_MODE (operand) == VOIDmode))
3363*e4b17023SJohn Marino win = 1;
3364*e4b17023SJohn Marino break;
3365*e4b17023SJohn Marino
3366*e4b17023SJohn Marino case 'I':
3367*e4b17023SJohn Marino case 'J':
3368*e4b17023SJohn Marino case 'K':
3369*e4b17023SJohn Marino case 'L':
3370*e4b17023SJohn Marino case 'M':
3371*e4b17023SJohn Marino case 'N':
3372*e4b17023SJohn Marino case 'O':
3373*e4b17023SJohn Marino case 'P':
3374*e4b17023SJohn Marino if (CONST_INT_P (operand)
3375*e4b17023SJohn Marino && CONST_OK_FOR_CONSTRAINT_P (INTVAL (operand), c, p))
3376*e4b17023SJohn Marino win = 1;
3377*e4b17023SJohn Marino break;
3378*e4b17023SJohn Marino
3379*e4b17023SJohn Marino case 'X':
3380*e4b17023SJohn Marino force_reload = 0;
3381*e4b17023SJohn Marino win = 1;
3382*e4b17023SJohn Marino break;
3383*e4b17023SJohn Marino
3384*e4b17023SJohn Marino case 'g':
3385*e4b17023SJohn Marino if (! force_reload
3386*e4b17023SJohn Marino /* A PLUS is never a valid operand, but reload can make
3387*e4b17023SJohn Marino it from a register when eliminating registers. */
3388*e4b17023SJohn Marino && GET_CODE (operand) != PLUS
3389*e4b17023SJohn Marino /* A SCRATCH is not a valid operand. */
3390*e4b17023SJohn Marino && GET_CODE (operand) != SCRATCH
3391*e4b17023SJohn Marino && (! CONSTANT_P (operand)
3392*e4b17023SJohn Marino || ! flag_pic
3393*e4b17023SJohn Marino || LEGITIMATE_PIC_OPERAND_P (operand))
3394*e4b17023SJohn Marino && (GENERAL_REGS == ALL_REGS
3395*e4b17023SJohn Marino || !REG_P (operand)
3396*e4b17023SJohn Marino || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
3397*e4b17023SJohn Marino && reg_renumber[REGNO (operand)] < 0)))
3398*e4b17023SJohn Marino win = 1;
3399*e4b17023SJohn Marino /* Drop through into 'r' case. */
3400*e4b17023SJohn Marino
3401*e4b17023SJohn Marino case 'r':
3402*e4b17023SJohn Marino this_alternative[i]
3403*e4b17023SJohn Marino = reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
3404*e4b17023SJohn Marino goto reg;
3405*e4b17023SJohn Marino
3406*e4b17023SJohn Marino default:
3407*e4b17023SJohn Marino if (REG_CLASS_FROM_CONSTRAINT (c, p) == NO_REGS)
3408*e4b17023SJohn Marino {
3409*e4b17023SJohn Marino #ifdef EXTRA_CONSTRAINT_STR
3410*e4b17023SJohn Marino if (EXTRA_MEMORY_CONSTRAINT (c, p))
3411*e4b17023SJohn Marino {
3412*e4b17023SJohn Marino if (force_reload)
3413*e4b17023SJohn Marino break;
3414*e4b17023SJohn Marino if (EXTRA_CONSTRAINT_STR (operand, c, p))
3415*e4b17023SJohn Marino win = 1;
3416*e4b17023SJohn Marino /* If the address was already reloaded,
3417*e4b17023SJohn Marino we win as well. */
3418*e4b17023SJohn Marino else if (MEM_P (operand)
3419*e4b17023SJohn Marino && address_reloaded[i] == 1)
3420*e4b17023SJohn Marino win = 1;
3421*e4b17023SJohn Marino /* Likewise if the address will be reloaded because
3422*e4b17023SJohn Marino reg_equiv_address is nonzero. For reg_equiv_mem
3423*e4b17023SJohn Marino we have to check. */
3424*e4b17023SJohn Marino else if (REG_P (operand)
3425*e4b17023SJohn Marino && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3426*e4b17023SJohn Marino && reg_renumber[REGNO (operand)] < 0
3427*e4b17023SJohn Marino && ((reg_equiv_mem (REGNO (operand)) != 0
3428*e4b17023SJohn Marino && EXTRA_CONSTRAINT_STR (reg_equiv_mem (REGNO (operand)), c, p))
3429*e4b17023SJohn Marino || (reg_equiv_address (REGNO (operand)) != 0)))
3430*e4b17023SJohn Marino win = 1;
3431*e4b17023SJohn Marino
3432*e4b17023SJohn Marino /* If we didn't already win, we can reload
3433*e4b17023SJohn Marino constants via force_const_mem, and other
3434*e4b17023SJohn Marino MEMs by reloading the address like for 'o'. */
3435*e4b17023SJohn Marino if (CONST_POOL_OK_P (operand_mode[i], operand)
3436*e4b17023SJohn Marino || MEM_P (operand))
3437*e4b17023SJohn Marino badop = 0;
3438*e4b17023SJohn Marino constmemok = 1;
3439*e4b17023SJohn Marino offmemok = 1;
3440*e4b17023SJohn Marino break;
3441*e4b17023SJohn Marino }
3442*e4b17023SJohn Marino if (EXTRA_ADDRESS_CONSTRAINT (c, p))
3443*e4b17023SJohn Marino {
3444*e4b17023SJohn Marino if (EXTRA_CONSTRAINT_STR (operand, c, p))
3445*e4b17023SJohn Marino win = 1;
3446*e4b17023SJohn Marino
3447*e4b17023SJohn Marino /* If we didn't already win, we can reload
3448*e4b17023SJohn Marino the address into a base register. */
3449*e4b17023SJohn Marino this_alternative[i]
3450*e4b17023SJohn Marino = base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
3451*e4b17023SJohn Marino ADDRESS, SCRATCH);
3452*e4b17023SJohn Marino badop = 0;
3453*e4b17023SJohn Marino break;
3454*e4b17023SJohn Marino }
3455*e4b17023SJohn Marino
3456*e4b17023SJohn Marino if (EXTRA_CONSTRAINT_STR (operand, c, p))
3457*e4b17023SJohn Marino win = 1;
3458*e4b17023SJohn Marino #endif
3459*e4b17023SJohn Marino break;
3460*e4b17023SJohn Marino }
3461*e4b17023SJohn Marino
3462*e4b17023SJohn Marino this_alternative[i]
3463*e4b17023SJohn Marino = (reg_class_subunion
3464*e4b17023SJohn Marino [this_alternative[i]]
3465*e4b17023SJohn Marino [(int) REG_CLASS_FROM_CONSTRAINT (c, p)]);
3466*e4b17023SJohn Marino reg:
3467*e4b17023SJohn Marino if (GET_MODE (operand) == BLKmode)
3468*e4b17023SJohn Marino break;
3469*e4b17023SJohn Marino winreg = 1;
3470*e4b17023SJohn Marino if (REG_P (operand)
3471*e4b17023SJohn Marino && reg_fits_class_p (operand, this_alternative[i],
3472*e4b17023SJohn Marino offset, GET_MODE (recog_data.operand[i])))
3473*e4b17023SJohn Marino win = 1;
3474*e4b17023SJohn Marino break;
3475*e4b17023SJohn Marino }
3476*e4b17023SJohn Marino while ((p += len), c);
3477*e4b17023SJohn Marino
3478*e4b17023SJohn Marino constraints[i] = p;
3479*e4b17023SJohn Marino
3480*e4b17023SJohn Marino /* If this operand could be handled with a reg,
3481*e4b17023SJohn Marino and some reg is allowed, then this operand can be handled. */
3482*e4b17023SJohn Marino if (winreg && this_alternative[i] != NO_REGS
3483*e4b17023SJohn Marino && (win || !class_only_fixed_regs[this_alternative[i]]))
3484*e4b17023SJohn Marino badop = 0;
3485*e4b17023SJohn Marino
3486*e4b17023SJohn Marino /* Record which operands fit this alternative. */
3487*e4b17023SJohn Marino this_alternative_earlyclobber[i] = earlyclobber;
3488*e4b17023SJohn Marino if (win && ! force_reload)
3489*e4b17023SJohn Marino this_alternative_win[i] = 1;
3490*e4b17023SJohn Marino else if (did_match && ! force_reload)
3491*e4b17023SJohn Marino this_alternative_match_win[i] = 1;
3492*e4b17023SJohn Marino else
3493*e4b17023SJohn Marino {
3494*e4b17023SJohn Marino int const_to_mem = 0;
3495*e4b17023SJohn Marino
3496*e4b17023SJohn Marino this_alternative_offmemok[i] = offmemok;
3497*e4b17023SJohn Marino losers++;
3498*e4b17023SJohn Marino if (badop)
3499*e4b17023SJohn Marino bad = 1;
3500*e4b17023SJohn Marino /* Alternative loses if it has no regs for a reg operand. */
3501*e4b17023SJohn Marino if (REG_P (operand)
3502*e4b17023SJohn Marino && this_alternative[i] == NO_REGS
3503*e4b17023SJohn Marino && this_alternative_matches[i] < 0)
3504*e4b17023SJohn Marino bad = 1;
3505*e4b17023SJohn Marino
3506*e4b17023SJohn Marino /* If this is a constant that is reloaded into the desired
3507*e4b17023SJohn Marino class by copying it to memory first, count that as another
3508*e4b17023SJohn Marino reload. This is consistent with other code and is
3509*e4b17023SJohn Marino required to avoid choosing another alternative when
3510*e4b17023SJohn Marino the constant is moved into memory by this function on
3511*e4b17023SJohn Marino an early reload pass. Note that the test here is
3512*e4b17023SJohn Marino precisely the same as in the code below that calls
3513*e4b17023SJohn Marino force_const_mem. */
3514*e4b17023SJohn Marino if (CONST_POOL_OK_P (operand_mode[i], operand)
3515*e4b17023SJohn Marino && ((targetm.preferred_reload_class (operand,
3516*e4b17023SJohn Marino this_alternative[i])
3517*e4b17023SJohn Marino == NO_REGS)
3518*e4b17023SJohn Marino || no_input_reloads))
3519*e4b17023SJohn Marino {
3520*e4b17023SJohn Marino const_to_mem = 1;
3521*e4b17023SJohn Marino if (this_alternative[i] != NO_REGS)
3522*e4b17023SJohn Marino losers++;
3523*e4b17023SJohn Marino }
3524*e4b17023SJohn Marino
3525*e4b17023SJohn Marino /* Alternative loses if it requires a type of reload not
3526*e4b17023SJohn Marino permitted for this insn. We can always reload SCRATCH
3527*e4b17023SJohn Marino and objects with a REG_UNUSED note. */
3528*e4b17023SJohn Marino if (GET_CODE (operand) != SCRATCH
3529*e4b17023SJohn Marino && modified[i] != RELOAD_READ && no_output_reloads
3530*e4b17023SJohn Marino && ! find_reg_note (insn, REG_UNUSED, operand))
3531*e4b17023SJohn Marino bad = 1;
3532*e4b17023SJohn Marino else if (modified[i] != RELOAD_WRITE && no_input_reloads
3533*e4b17023SJohn Marino && ! const_to_mem)
3534*e4b17023SJohn Marino bad = 1;
3535*e4b17023SJohn Marino
3536*e4b17023SJohn Marino /* If we can't reload this value at all, reject this
3537*e4b17023SJohn Marino alternative. Note that we could also lose due to
3538*e4b17023SJohn Marino LIMIT_RELOAD_CLASS, but we don't check that
3539*e4b17023SJohn Marino here. */
3540*e4b17023SJohn Marino
3541*e4b17023SJohn Marino if (! CONSTANT_P (operand) && this_alternative[i] != NO_REGS)
3542*e4b17023SJohn Marino {
3543*e4b17023SJohn Marino if (targetm.preferred_reload_class (operand, this_alternative[i])
3544*e4b17023SJohn Marino == NO_REGS)
3545*e4b17023SJohn Marino reject = 600;
3546*e4b17023SJohn Marino
3547*e4b17023SJohn Marino if (operand_type[i] == RELOAD_FOR_OUTPUT
3548*e4b17023SJohn Marino && (targetm.preferred_output_reload_class (operand,
3549*e4b17023SJohn Marino this_alternative[i])
3550*e4b17023SJohn Marino == NO_REGS))
3551*e4b17023SJohn Marino reject = 600;
3552*e4b17023SJohn Marino }
3553*e4b17023SJohn Marino
3554*e4b17023SJohn Marino /* We prefer to reload pseudos over reloading other things,
3555*e4b17023SJohn Marino since such reloads may be able to be eliminated later.
3556*e4b17023SJohn Marino If we are reloading a SCRATCH, we won't be generating any
3557*e4b17023SJohn Marino insns, just using a register, so it is also preferred.
3558*e4b17023SJohn Marino So bump REJECT in other cases. Don't do this in the
3559*e4b17023SJohn Marino case where we are forcing a constant into memory and
3560*e4b17023SJohn Marino it will then win since we don't want to have a different
3561*e4b17023SJohn Marino alternative match then. */
3562*e4b17023SJohn Marino if (! (REG_P (operand)
3563*e4b17023SJohn Marino && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
3564*e4b17023SJohn Marino && GET_CODE (operand) != SCRATCH
3565*e4b17023SJohn Marino && ! (const_to_mem && constmemok))
3566*e4b17023SJohn Marino reject += 2;
3567*e4b17023SJohn Marino
3568*e4b17023SJohn Marino /* Input reloads can be inherited more often than output
3569*e4b17023SJohn Marino reloads can be removed, so penalize output reloads. */
3570*e4b17023SJohn Marino if (operand_type[i] != RELOAD_FOR_INPUT
3571*e4b17023SJohn Marino && GET_CODE (operand) != SCRATCH)
3572*e4b17023SJohn Marino reject++;
3573*e4b17023SJohn Marino }
3574*e4b17023SJohn Marino
3575*e4b17023SJohn Marino /* If this operand is a pseudo register that didn't get a hard
3576*e4b17023SJohn Marino reg and this alternative accepts some register, see if the
3577*e4b17023SJohn Marino class that we want is a subset of the preferred class for this
3578*e4b17023SJohn Marino register. If not, but it intersects that class, use the
3579*e4b17023SJohn Marino preferred class instead. If it does not intersect the preferred
3580*e4b17023SJohn Marino class, show that usage of this alternative should be discouraged;
3581*e4b17023SJohn Marino it will be discouraged more still if the register is `preferred
3582*e4b17023SJohn Marino or nothing'. We do this because it increases the chance of
3583*e4b17023SJohn Marino reusing our spill register in a later insn and avoiding a pair
3584*e4b17023SJohn Marino of memory stores and loads.
3585*e4b17023SJohn Marino
3586*e4b17023SJohn Marino Don't bother with this if this alternative will accept this
3587*e4b17023SJohn Marino operand.
3588*e4b17023SJohn Marino
3589*e4b17023SJohn Marino Don't do this for a multiword operand, since it is only a
3590*e4b17023SJohn Marino small win and has the risk of requiring more spill registers,
3591*e4b17023SJohn Marino which could cause a large loss.
3592*e4b17023SJohn Marino
3593*e4b17023SJohn Marino Don't do this if the preferred class has only one register
3594*e4b17023SJohn Marino because we might otherwise exhaust the class. */
3595*e4b17023SJohn Marino
3596*e4b17023SJohn Marino if (! win && ! did_match
3597*e4b17023SJohn Marino && this_alternative[i] != NO_REGS
3598*e4b17023SJohn Marino && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3599*e4b17023SJohn Marino && reg_class_size [(int) preferred_class[i]] > 0
3600*e4b17023SJohn Marino && ! small_register_class_p (preferred_class[i]))
3601*e4b17023SJohn Marino {
3602*e4b17023SJohn Marino if (! reg_class_subset_p (this_alternative[i],
3603*e4b17023SJohn Marino preferred_class[i]))
3604*e4b17023SJohn Marino {
3605*e4b17023SJohn Marino /* Since we don't have a way of forming the intersection,
3606*e4b17023SJohn Marino we just do something special if the preferred class
3607*e4b17023SJohn Marino is a subset of the class we have; that's the most
3608*e4b17023SJohn Marino common case anyway. */
3609*e4b17023SJohn Marino if (reg_class_subset_p (preferred_class[i],
3610*e4b17023SJohn Marino this_alternative[i]))
3611*e4b17023SJohn Marino this_alternative[i] = preferred_class[i];
3612*e4b17023SJohn Marino else
3613*e4b17023SJohn Marino reject += (2 + 2 * pref_or_nothing[i]);
3614*e4b17023SJohn Marino }
3615*e4b17023SJohn Marino }
3616*e4b17023SJohn Marino }
3617*e4b17023SJohn Marino
3618*e4b17023SJohn Marino /* Now see if any output operands that are marked "earlyclobber"
3619*e4b17023SJohn Marino in this alternative conflict with any input operands
3620*e4b17023SJohn Marino or any memory addresses. */
3621*e4b17023SJohn Marino
3622*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
3623*e4b17023SJohn Marino if (this_alternative_earlyclobber[i]
3624*e4b17023SJohn Marino && (this_alternative_win[i] || this_alternative_match_win[i]))
3625*e4b17023SJohn Marino {
3626*e4b17023SJohn Marino struct decomposition early_data;
3627*e4b17023SJohn Marino
3628*e4b17023SJohn Marino early_data = decompose (recog_data.operand[i]);
3629*e4b17023SJohn Marino
3630*e4b17023SJohn Marino gcc_assert (modified[i] != RELOAD_READ);
3631*e4b17023SJohn Marino
3632*e4b17023SJohn Marino if (this_alternative[i] == NO_REGS)
3633*e4b17023SJohn Marino {
3634*e4b17023SJohn Marino this_alternative_earlyclobber[i] = 0;
3635*e4b17023SJohn Marino gcc_assert (this_insn_is_asm);
3636*e4b17023SJohn Marino error_for_asm (this_insn,
3637*e4b17023SJohn Marino "%<&%> constraint used with no register class");
3638*e4b17023SJohn Marino }
3639*e4b17023SJohn Marino
3640*e4b17023SJohn Marino for (j = 0; j < noperands; j++)
3641*e4b17023SJohn Marino /* Is this an input operand or a memory ref? */
3642*e4b17023SJohn Marino if ((MEM_P (recog_data.operand[j])
3643*e4b17023SJohn Marino || modified[j] != RELOAD_WRITE)
3644*e4b17023SJohn Marino && j != i
3645*e4b17023SJohn Marino /* Ignore things like match_operator operands. */
3646*e4b17023SJohn Marino && !recog_data.is_operator[j]
3647*e4b17023SJohn Marino /* Don't count an input operand that is constrained to match
3648*e4b17023SJohn Marino the early clobber operand. */
3649*e4b17023SJohn Marino && ! (this_alternative_matches[j] == i
3650*e4b17023SJohn Marino && rtx_equal_p (recog_data.operand[i],
3651*e4b17023SJohn Marino recog_data.operand[j]))
3652*e4b17023SJohn Marino /* Is it altered by storing the earlyclobber operand? */
3653*e4b17023SJohn Marino && !immune_p (recog_data.operand[j], recog_data.operand[i],
3654*e4b17023SJohn Marino early_data))
3655*e4b17023SJohn Marino {
3656*e4b17023SJohn Marino /* If the output is in a non-empty few-regs class,
3657*e4b17023SJohn Marino it's costly to reload it, so reload the input instead. */
3658*e4b17023SJohn Marino if (small_register_class_p (this_alternative[i])
3659*e4b17023SJohn Marino && (REG_P (recog_data.operand[j])
3660*e4b17023SJohn Marino || GET_CODE (recog_data.operand[j]) == SUBREG))
3661*e4b17023SJohn Marino {
3662*e4b17023SJohn Marino losers++;
3663*e4b17023SJohn Marino this_alternative_win[j] = 0;
3664*e4b17023SJohn Marino this_alternative_match_win[j] = 0;
3665*e4b17023SJohn Marino }
3666*e4b17023SJohn Marino else
3667*e4b17023SJohn Marino break;
3668*e4b17023SJohn Marino }
3669*e4b17023SJohn Marino /* If an earlyclobber operand conflicts with something,
3670*e4b17023SJohn Marino it must be reloaded, so request this and count the cost. */
3671*e4b17023SJohn Marino if (j != noperands)
3672*e4b17023SJohn Marino {
3673*e4b17023SJohn Marino losers++;
3674*e4b17023SJohn Marino this_alternative_win[i] = 0;
3675*e4b17023SJohn Marino this_alternative_match_win[j] = 0;
3676*e4b17023SJohn Marino for (j = 0; j < noperands; j++)
3677*e4b17023SJohn Marino if (this_alternative_matches[j] == i
3678*e4b17023SJohn Marino && this_alternative_match_win[j])
3679*e4b17023SJohn Marino {
3680*e4b17023SJohn Marino this_alternative_win[j] = 0;
3681*e4b17023SJohn Marino this_alternative_match_win[j] = 0;
3682*e4b17023SJohn Marino losers++;
3683*e4b17023SJohn Marino }
3684*e4b17023SJohn Marino }
3685*e4b17023SJohn Marino }
3686*e4b17023SJohn Marino
3687*e4b17023SJohn Marino /* If one alternative accepts all the operands, no reload required,
3688*e4b17023SJohn Marino choose that alternative; don't consider the remaining ones. */
3689*e4b17023SJohn Marino if (losers == 0)
3690*e4b17023SJohn Marino {
3691*e4b17023SJohn Marino /* Unswap these so that they are never swapped at `finish'. */
3692*e4b17023SJohn Marino if (commutative >= 0)
3693*e4b17023SJohn Marino {
3694*e4b17023SJohn Marino recog_data.operand[commutative] = substed_operand[commutative];
3695*e4b17023SJohn Marino recog_data.operand[commutative + 1]
3696*e4b17023SJohn Marino = substed_operand[commutative + 1];
3697*e4b17023SJohn Marino }
3698*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
3699*e4b17023SJohn Marino {
3700*e4b17023SJohn Marino goal_alternative_win[i] = this_alternative_win[i];
3701*e4b17023SJohn Marino goal_alternative_match_win[i] = this_alternative_match_win[i];
3702*e4b17023SJohn Marino goal_alternative[i] = this_alternative[i];
3703*e4b17023SJohn Marino goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3704*e4b17023SJohn Marino goal_alternative_matches[i] = this_alternative_matches[i];
3705*e4b17023SJohn Marino goal_alternative_earlyclobber[i]
3706*e4b17023SJohn Marino = this_alternative_earlyclobber[i];
3707*e4b17023SJohn Marino }
3708*e4b17023SJohn Marino goal_alternative_number = this_alternative_number;
3709*e4b17023SJohn Marino goal_alternative_swapped = swapped;
3710*e4b17023SJohn Marino goal_earlyclobber = this_earlyclobber;
3711*e4b17023SJohn Marino goto finish;
3712*e4b17023SJohn Marino }
3713*e4b17023SJohn Marino
3714*e4b17023SJohn Marino /* REJECT, set by the ! and ? constraint characters and when a register
3715*e4b17023SJohn Marino would be reloaded into a non-preferred class, discourages the use of
3716*e4b17023SJohn Marino this alternative for a reload goal. REJECT is incremented by six
3717*e4b17023SJohn Marino for each ? and two for each non-preferred class. */
3718*e4b17023SJohn Marino losers = losers * 6 + reject;
3719*e4b17023SJohn Marino
3720*e4b17023SJohn Marino /* If this alternative can be made to work by reloading,
3721*e4b17023SJohn Marino and it needs less reloading than the others checked so far,
3722*e4b17023SJohn Marino record it as the chosen goal for reloading. */
3723*e4b17023SJohn Marino if (! bad)
3724*e4b17023SJohn Marino {
3725*e4b17023SJohn Marino if (best > losers)
3726*e4b17023SJohn Marino {
3727*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
3728*e4b17023SJohn Marino {
3729*e4b17023SJohn Marino goal_alternative[i] = this_alternative[i];
3730*e4b17023SJohn Marino goal_alternative_win[i] = this_alternative_win[i];
3731*e4b17023SJohn Marino goal_alternative_match_win[i]
3732*e4b17023SJohn Marino = this_alternative_match_win[i];
3733*e4b17023SJohn Marino goal_alternative_offmemok[i]
3734*e4b17023SJohn Marino = this_alternative_offmemok[i];
3735*e4b17023SJohn Marino goal_alternative_matches[i] = this_alternative_matches[i];
3736*e4b17023SJohn Marino goal_alternative_earlyclobber[i]
3737*e4b17023SJohn Marino = this_alternative_earlyclobber[i];
3738*e4b17023SJohn Marino }
3739*e4b17023SJohn Marino goal_alternative_swapped = swapped;
3740*e4b17023SJohn Marino best = losers;
3741*e4b17023SJohn Marino goal_alternative_number = this_alternative_number;
3742*e4b17023SJohn Marino goal_earlyclobber = this_earlyclobber;
3743*e4b17023SJohn Marino }
3744*e4b17023SJohn Marino }
3745*e4b17023SJohn Marino }
3746*e4b17023SJohn Marino
3747*e4b17023SJohn Marino /* If insn is commutative (it's safe to exchange a certain pair of operands)
3748*e4b17023SJohn Marino then we need to try each alternative twice,
3749*e4b17023SJohn Marino the second time matching those two operands
3750*e4b17023SJohn Marino as if we had exchanged them.
3751*e4b17023SJohn Marino To do this, really exchange them in operands.
3752*e4b17023SJohn Marino
3753*e4b17023SJohn Marino If we have just tried the alternatives the second time,
3754*e4b17023SJohn Marino return operands to normal and drop through. */
3755*e4b17023SJohn Marino
3756*e4b17023SJohn Marino if (commutative >= 0)
3757*e4b17023SJohn Marino {
3758*e4b17023SJohn Marino swapped = !swapped;
3759*e4b17023SJohn Marino if (swapped)
3760*e4b17023SJohn Marino {
3761*e4b17023SJohn Marino enum reg_class tclass;
3762*e4b17023SJohn Marino int t;
3763*e4b17023SJohn Marino
3764*e4b17023SJohn Marino recog_data.operand[commutative] = substed_operand[commutative + 1];
3765*e4b17023SJohn Marino recog_data.operand[commutative + 1] = substed_operand[commutative];
3766*e4b17023SJohn Marino /* Swap the duplicates too. */
3767*e4b17023SJohn Marino for (i = 0; i < recog_data.n_dups; i++)
3768*e4b17023SJohn Marino if (recog_data.dup_num[i] == commutative
3769*e4b17023SJohn Marino || recog_data.dup_num[i] == commutative + 1)
3770*e4b17023SJohn Marino *recog_data.dup_loc[i]
3771*e4b17023SJohn Marino = recog_data.operand[(int) recog_data.dup_num[i]];
3772*e4b17023SJohn Marino
3773*e4b17023SJohn Marino tclass = preferred_class[commutative];
3774*e4b17023SJohn Marino preferred_class[commutative] = preferred_class[commutative + 1];
3775*e4b17023SJohn Marino preferred_class[commutative + 1] = tclass;
3776*e4b17023SJohn Marino
3777*e4b17023SJohn Marino t = pref_or_nothing[commutative];
3778*e4b17023SJohn Marino pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
3779*e4b17023SJohn Marino pref_or_nothing[commutative + 1] = t;
3780*e4b17023SJohn Marino
3781*e4b17023SJohn Marino t = address_reloaded[commutative];
3782*e4b17023SJohn Marino address_reloaded[commutative] = address_reloaded[commutative + 1];
3783*e4b17023SJohn Marino address_reloaded[commutative + 1] = t;
3784*e4b17023SJohn Marino
3785*e4b17023SJohn Marino memcpy (constraints, recog_data.constraints,
3786*e4b17023SJohn Marino noperands * sizeof (const char *));
3787*e4b17023SJohn Marino goto try_swapped;
3788*e4b17023SJohn Marino }
3789*e4b17023SJohn Marino else
3790*e4b17023SJohn Marino {
3791*e4b17023SJohn Marino recog_data.operand[commutative] = substed_operand[commutative];
3792*e4b17023SJohn Marino recog_data.operand[commutative + 1]
3793*e4b17023SJohn Marino = substed_operand[commutative + 1];
3794*e4b17023SJohn Marino /* Unswap the duplicates too. */
3795*e4b17023SJohn Marino for (i = 0; i < recog_data.n_dups; i++)
3796*e4b17023SJohn Marino if (recog_data.dup_num[i] == commutative
3797*e4b17023SJohn Marino || recog_data.dup_num[i] == commutative + 1)
3798*e4b17023SJohn Marino *recog_data.dup_loc[i]
3799*e4b17023SJohn Marino = recog_data.operand[(int) recog_data.dup_num[i]];
3800*e4b17023SJohn Marino }
3801*e4b17023SJohn Marino }
3802*e4b17023SJohn Marino
3803*e4b17023SJohn Marino /* The operands don't meet the constraints.
3804*e4b17023SJohn Marino goal_alternative describes the alternative
3805*e4b17023SJohn Marino that we could reach by reloading the fewest operands.
3806*e4b17023SJohn Marino Reload so as to fit it. */
3807*e4b17023SJohn Marino
3808*e4b17023SJohn Marino if (best == MAX_RECOG_OPERANDS * 2 + 600)
3809*e4b17023SJohn Marino {
3810*e4b17023SJohn Marino /* No alternative works with reloads?? */
3811*e4b17023SJohn Marino if (insn_code_number >= 0)
3812*e4b17023SJohn Marino fatal_insn ("unable to generate reloads for:", insn);
3813*e4b17023SJohn Marino error_for_asm (insn, "inconsistent operand constraints in an %<asm%>");
3814*e4b17023SJohn Marino /* Avoid further trouble with this insn. */
3815*e4b17023SJohn Marino PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3816*e4b17023SJohn Marino n_reloads = 0;
3817*e4b17023SJohn Marino return 0;
3818*e4b17023SJohn Marino }
3819*e4b17023SJohn Marino
3820*e4b17023SJohn Marino /* Jump to `finish' from above if all operands are valid already.
3821*e4b17023SJohn Marino In that case, goal_alternative_win is all 1. */
3822*e4b17023SJohn Marino finish:
3823*e4b17023SJohn Marino
3824*e4b17023SJohn Marino /* Right now, for any pair of operands I and J that are required to match,
3825*e4b17023SJohn Marino with I < J,
3826*e4b17023SJohn Marino goal_alternative_matches[J] is I.
3827*e4b17023SJohn Marino Set up goal_alternative_matched as the inverse function:
3828*e4b17023SJohn Marino goal_alternative_matched[I] = J. */
3829*e4b17023SJohn Marino
3830*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
3831*e4b17023SJohn Marino goal_alternative_matched[i] = -1;
3832*e4b17023SJohn Marino
3833*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
3834*e4b17023SJohn Marino if (! goal_alternative_win[i]
3835*e4b17023SJohn Marino && goal_alternative_matches[i] >= 0)
3836*e4b17023SJohn Marino goal_alternative_matched[goal_alternative_matches[i]] = i;
3837*e4b17023SJohn Marino
3838*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
3839*e4b17023SJohn Marino goal_alternative_win[i] |= goal_alternative_match_win[i];
3840*e4b17023SJohn Marino
3841*e4b17023SJohn Marino /* If the best alternative is with operands 1 and 2 swapped,
3842*e4b17023SJohn Marino consider them swapped before reporting the reloads. Update the
3843*e4b17023SJohn Marino operand numbers of any reloads already pushed. */
3844*e4b17023SJohn Marino
3845*e4b17023SJohn Marino if (goal_alternative_swapped)
3846*e4b17023SJohn Marino {
3847*e4b17023SJohn Marino rtx tem;
3848*e4b17023SJohn Marino
3849*e4b17023SJohn Marino tem = substed_operand[commutative];
3850*e4b17023SJohn Marino substed_operand[commutative] = substed_operand[commutative + 1];
3851*e4b17023SJohn Marino substed_operand[commutative + 1] = tem;
3852*e4b17023SJohn Marino tem = recog_data.operand[commutative];
3853*e4b17023SJohn Marino recog_data.operand[commutative] = recog_data.operand[commutative + 1];
3854*e4b17023SJohn Marino recog_data.operand[commutative + 1] = tem;
3855*e4b17023SJohn Marino tem = *recog_data.operand_loc[commutative];
3856*e4b17023SJohn Marino *recog_data.operand_loc[commutative]
3857*e4b17023SJohn Marino = *recog_data.operand_loc[commutative + 1];
3858*e4b17023SJohn Marino *recog_data.operand_loc[commutative + 1] = tem;
3859*e4b17023SJohn Marino
3860*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
3861*e4b17023SJohn Marino {
3862*e4b17023SJohn Marino if (rld[i].opnum == commutative)
3863*e4b17023SJohn Marino rld[i].opnum = commutative + 1;
3864*e4b17023SJohn Marino else if (rld[i].opnum == commutative + 1)
3865*e4b17023SJohn Marino rld[i].opnum = commutative;
3866*e4b17023SJohn Marino }
3867*e4b17023SJohn Marino }
3868*e4b17023SJohn Marino
3869*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
3870*e4b17023SJohn Marino {
3871*e4b17023SJohn Marino operand_reloadnum[i] = -1;
3872*e4b17023SJohn Marino
3873*e4b17023SJohn Marino /* If this is an earlyclobber operand, we need to widen the scope.
3874*e4b17023SJohn Marino The reload must remain valid from the start of the insn being
3875*e4b17023SJohn Marino reloaded until after the operand is stored into its destination.
3876*e4b17023SJohn Marino We approximate this with RELOAD_OTHER even though we know that we
3877*e4b17023SJohn Marino do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads.
3878*e4b17023SJohn Marino
3879*e4b17023SJohn Marino One special case that is worth checking is when we have an
3880*e4b17023SJohn Marino output that is earlyclobber but isn't used past the insn (typically
3881*e4b17023SJohn Marino a SCRATCH). In this case, we only need have the reload live
3882*e4b17023SJohn Marino through the insn itself, but not for any of our input or output
3883*e4b17023SJohn Marino reloads.
3884*e4b17023SJohn Marino But we must not accidentally narrow the scope of an existing
3885*e4b17023SJohn Marino RELOAD_OTHER reload - leave these alone.
3886*e4b17023SJohn Marino
3887*e4b17023SJohn Marino In any case, anything needed to address this operand can remain
3888*e4b17023SJohn Marino however they were previously categorized. */
3889*e4b17023SJohn Marino
3890*e4b17023SJohn Marino if (goal_alternative_earlyclobber[i] && operand_type[i] != RELOAD_OTHER)
3891*e4b17023SJohn Marino operand_type[i]
3892*e4b17023SJohn Marino = (find_reg_note (insn, REG_UNUSED, recog_data.operand[i])
3893*e4b17023SJohn Marino ? RELOAD_FOR_INSN : RELOAD_OTHER);
3894*e4b17023SJohn Marino }
3895*e4b17023SJohn Marino
3896*e4b17023SJohn Marino /* Any constants that aren't allowed and can't be reloaded
3897*e4b17023SJohn Marino into registers are here changed into memory references. */
3898*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
3899*e4b17023SJohn Marino if (! goal_alternative_win[i])
3900*e4b17023SJohn Marino {
3901*e4b17023SJohn Marino rtx op = recog_data.operand[i];
3902*e4b17023SJohn Marino rtx subreg = NULL_RTX;
3903*e4b17023SJohn Marino rtx plus = NULL_RTX;
3904*e4b17023SJohn Marino enum machine_mode mode = operand_mode[i];
3905*e4b17023SJohn Marino
3906*e4b17023SJohn Marino /* Reloads of SUBREGs of CONSTANT RTXs are handled later in
3907*e4b17023SJohn Marino push_reload so we have to let them pass here. */
3908*e4b17023SJohn Marino if (GET_CODE (op) == SUBREG)
3909*e4b17023SJohn Marino {
3910*e4b17023SJohn Marino subreg = op;
3911*e4b17023SJohn Marino op = SUBREG_REG (op);
3912*e4b17023SJohn Marino mode = GET_MODE (op);
3913*e4b17023SJohn Marino }
3914*e4b17023SJohn Marino
3915*e4b17023SJohn Marino if (GET_CODE (op) == PLUS)
3916*e4b17023SJohn Marino {
3917*e4b17023SJohn Marino plus = op;
3918*e4b17023SJohn Marino op = XEXP (op, 1);
3919*e4b17023SJohn Marino }
3920*e4b17023SJohn Marino
3921*e4b17023SJohn Marino if (CONST_POOL_OK_P (mode, op)
3922*e4b17023SJohn Marino && ((targetm.preferred_reload_class (op, goal_alternative[i])
3923*e4b17023SJohn Marino == NO_REGS)
3924*e4b17023SJohn Marino || no_input_reloads))
3925*e4b17023SJohn Marino {
3926*e4b17023SJohn Marino int this_address_reloaded;
3927*e4b17023SJohn Marino rtx tem = force_const_mem (mode, op);
3928*e4b17023SJohn Marino
3929*e4b17023SJohn Marino /* If we stripped a SUBREG or a PLUS above add it back. */
3930*e4b17023SJohn Marino if (plus != NULL_RTX)
3931*e4b17023SJohn Marino tem = gen_rtx_PLUS (mode, XEXP (plus, 0), tem);
3932*e4b17023SJohn Marino
3933*e4b17023SJohn Marino if (subreg != NULL_RTX)
3934*e4b17023SJohn Marino tem = gen_rtx_SUBREG (operand_mode[i], tem, SUBREG_BYTE (subreg));
3935*e4b17023SJohn Marino
3936*e4b17023SJohn Marino this_address_reloaded = 0;
3937*e4b17023SJohn Marino substed_operand[i] = recog_data.operand[i]
3938*e4b17023SJohn Marino = find_reloads_toplev (tem, i, address_type[i], ind_levels,
3939*e4b17023SJohn Marino 0, insn, &this_address_reloaded);
3940*e4b17023SJohn Marino
3941*e4b17023SJohn Marino /* If the alternative accepts constant pool refs directly
3942*e4b17023SJohn Marino there will be no reload needed at all. */
3943*e4b17023SJohn Marino if (plus == NULL_RTX
3944*e4b17023SJohn Marino && subreg == NULL_RTX
3945*e4b17023SJohn Marino && alternative_allows_const_pool_ref (this_address_reloaded == 0
3946*e4b17023SJohn Marino ? substed_operand[i]
3947*e4b17023SJohn Marino : NULL,
3948*e4b17023SJohn Marino recog_data.constraints[i],
3949*e4b17023SJohn Marino goal_alternative_number))
3950*e4b17023SJohn Marino goal_alternative_win[i] = 1;
3951*e4b17023SJohn Marino }
3952*e4b17023SJohn Marino }
3953*e4b17023SJohn Marino
3954*e4b17023SJohn Marino /* Record the values of the earlyclobber operands for the caller. */
3955*e4b17023SJohn Marino if (goal_earlyclobber)
3956*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
3957*e4b17023SJohn Marino if (goal_alternative_earlyclobber[i])
3958*e4b17023SJohn Marino reload_earlyclobbers[n_earlyclobbers++] = recog_data.operand[i];
3959*e4b17023SJohn Marino
3960*e4b17023SJohn Marino /* Now record reloads for all the operands that need them. */
3961*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
3962*e4b17023SJohn Marino if (! goal_alternative_win[i])
3963*e4b17023SJohn Marino {
3964*e4b17023SJohn Marino /* Operands that match previous ones have already been handled. */
3965*e4b17023SJohn Marino if (goal_alternative_matches[i] >= 0)
3966*e4b17023SJohn Marino ;
3967*e4b17023SJohn Marino /* Handle an operand with a nonoffsettable address
3968*e4b17023SJohn Marino appearing where an offsettable address will do
3969*e4b17023SJohn Marino by reloading the address into a base register.
3970*e4b17023SJohn Marino
3971*e4b17023SJohn Marino ??? We can also do this when the operand is a register and
3972*e4b17023SJohn Marino reg_equiv_mem is not offsettable, but this is a bit tricky,
3973*e4b17023SJohn Marino so we don't bother with it. It may not be worth doing. */
3974*e4b17023SJohn Marino else if (goal_alternative_matched[i] == -1
3975*e4b17023SJohn Marino && goal_alternative_offmemok[i]
3976*e4b17023SJohn Marino && MEM_P (recog_data.operand[i]))
3977*e4b17023SJohn Marino {
3978*e4b17023SJohn Marino /* If the address to be reloaded is a VOIDmode constant,
3979*e4b17023SJohn Marino use the default address mode as mode of the reload register,
3980*e4b17023SJohn Marino as would have been done by find_reloads_address. */
3981*e4b17023SJohn Marino addr_space_t as = MEM_ADDR_SPACE (recog_data.operand[i]);
3982*e4b17023SJohn Marino enum machine_mode address_mode;
3983*e4b17023SJohn Marino address_mode = GET_MODE (XEXP (recog_data.operand[i], 0));
3984*e4b17023SJohn Marino if (address_mode == VOIDmode)
3985*e4b17023SJohn Marino address_mode = targetm.addr_space.address_mode (as);
3986*e4b17023SJohn Marino
3987*e4b17023SJohn Marino operand_reloadnum[i]
3988*e4b17023SJohn Marino = push_reload (XEXP (recog_data.operand[i], 0), NULL_RTX,
3989*e4b17023SJohn Marino &XEXP (recog_data.operand[i], 0), (rtx*) 0,
3990*e4b17023SJohn Marino base_reg_class (VOIDmode, as, MEM, SCRATCH),
3991*e4b17023SJohn Marino address_mode,
3992*e4b17023SJohn Marino VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
3993*e4b17023SJohn Marino rld[operand_reloadnum[i]].inc
3994*e4b17023SJohn Marino = GET_MODE_SIZE (GET_MODE (recog_data.operand[i]));
3995*e4b17023SJohn Marino
3996*e4b17023SJohn Marino /* If this operand is an output, we will have made any
3997*e4b17023SJohn Marino reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but
3998*e4b17023SJohn Marino now we are treating part of the operand as an input, so
3999*e4b17023SJohn Marino we must change these to RELOAD_FOR_INPUT_ADDRESS. */
4000*e4b17023SJohn Marino
4001*e4b17023SJohn Marino if (modified[i] == RELOAD_WRITE)
4002*e4b17023SJohn Marino {
4003*e4b17023SJohn Marino for (j = 0; j < n_reloads; j++)
4004*e4b17023SJohn Marino {
4005*e4b17023SJohn Marino if (rld[j].opnum == i)
4006*e4b17023SJohn Marino {
4007*e4b17023SJohn Marino if (rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS)
4008*e4b17023SJohn Marino rld[j].when_needed = RELOAD_FOR_INPUT_ADDRESS;
4009*e4b17023SJohn Marino else if (rld[j].when_needed
4010*e4b17023SJohn Marino == RELOAD_FOR_OUTADDR_ADDRESS)
4011*e4b17023SJohn Marino rld[j].when_needed = RELOAD_FOR_INPADDR_ADDRESS;
4012*e4b17023SJohn Marino }
4013*e4b17023SJohn Marino }
4014*e4b17023SJohn Marino }
4015*e4b17023SJohn Marino }
4016*e4b17023SJohn Marino else if (goal_alternative_matched[i] == -1)
4017*e4b17023SJohn Marino {
4018*e4b17023SJohn Marino operand_reloadnum[i]
4019*e4b17023SJohn Marino = push_reload ((modified[i] != RELOAD_WRITE
4020*e4b17023SJohn Marino ? recog_data.operand[i] : 0),
4021*e4b17023SJohn Marino (modified[i] != RELOAD_READ
4022*e4b17023SJohn Marino ? recog_data.operand[i] : 0),
4023*e4b17023SJohn Marino (modified[i] != RELOAD_WRITE
4024*e4b17023SJohn Marino ? recog_data.operand_loc[i] : 0),
4025*e4b17023SJohn Marino (modified[i] != RELOAD_READ
4026*e4b17023SJohn Marino ? recog_data.operand_loc[i] : 0),
4027*e4b17023SJohn Marino (enum reg_class) goal_alternative[i],
4028*e4b17023SJohn Marino (modified[i] == RELOAD_WRITE
4029*e4b17023SJohn Marino ? VOIDmode : operand_mode[i]),
4030*e4b17023SJohn Marino (modified[i] == RELOAD_READ
4031*e4b17023SJohn Marino ? VOIDmode : operand_mode[i]),
4032*e4b17023SJohn Marino (insn_code_number < 0 ? 0
4033*e4b17023SJohn Marino : insn_data[insn_code_number].operand[i].strict_low),
4034*e4b17023SJohn Marino 0, i, operand_type[i]);
4035*e4b17023SJohn Marino }
4036*e4b17023SJohn Marino /* In a matching pair of operands, one must be input only
4037*e4b17023SJohn Marino and the other must be output only.
4038*e4b17023SJohn Marino Pass the input operand as IN and the other as OUT. */
4039*e4b17023SJohn Marino else if (modified[i] == RELOAD_READ
4040*e4b17023SJohn Marino && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
4041*e4b17023SJohn Marino {
4042*e4b17023SJohn Marino operand_reloadnum[i]
4043*e4b17023SJohn Marino = push_reload (recog_data.operand[i],
4044*e4b17023SJohn Marino recog_data.operand[goal_alternative_matched[i]],
4045*e4b17023SJohn Marino recog_data.operand_loc[i],
4046*e4b17023SJohn Marino recog_data.operand_loc[goal_alternative_matched[i]],
4047*e4b17023SJohn Marino (enum reg_class) goal_alternative[i],
4048*e4b17023SJohn Marino operand_mode[i],
4049*e4b17023SJohn Marino operand_mode[goal_alternative_matched[i]],
4050*e4b17023SJohn Marino 0, 0, i, RELOAD_OTHER);
4051*e4b17023SJohn Marino operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
4052*e4b17023SJohn Marino }
4053*e4b17023SJohn Marino else if (modified[i] == RELOAD_WRITE
4054*e4b17023SJohn Marino && modified[goal_alternative_matched[i]] == RELOAD_READ)
4055*e4b17023SJohn Marino {
4056*e4b17023SJohn Marino operand_reloadnum[goal_alternative_matched[i]]
4057*e4b17023SJohn Marino = push_reload (recog_data.operand[goal_alternative_matched[i]],
4058*e4b17023SJohn Marino recog_data.operand[i],
4059*e4b17023SJohn Marino recog_data.operand_loc[goal_alternative_matched[i]],
4060*e4b17023SJohn Marino recog_data.operand_loc[i],
4061*e4b17023SJohn Marino (enum reg_class) goal_alternative[i],
4062*e4b17023SJohn Marino operand_mode[goal_alternative_matched[i]],
4063*e4b17023SJohn Marino operand_mode[i],
4064*e4b17023SJohn Marino 0, 0, i, RELOAD_OTHER);
4065*e4b17023SJohn Marino operand_reloadnum[i] = output_reloadnum;
4066*e4b17023SJohn Marino }
4067*e4b17023SJohn Marino else
4068*e4b17023SJohn Marino {
4069*e4b17023SJohn Marino gcc_assert (insn_code_number < 0);
4070*e4b17023SJohn Marino error_for_asm (insn, "inconsistent operand constraints "
4071*e4b17023SJohn Marino "in an %<asm%>");
4072*e4b17023SJohn Marino /* Avoid further trouble with this insn. */
4073*e4b17023SJohn Marino PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
4074*e4b17023SJohn Marino n_reloads = 0;
4075*e4b17023SJohn Marino return 0;
4076*e4b17023SJohn Marino }
4077*e4b17023SJohn Marino }
4078*e4b17023SJohn Marino else if (goal_alternative_matched[i] < 0
4079*e4b17023SJohn Marino && goal_alternative_matches[i] < 0
4080*e4b17023SJohn Marino && address_operand_reloaded[i] != 1
4081*e4b17023SJohn Marino && optimize)
4082*e4b17023SJohn Marino {
4083*e4b17023SJohn Marino /* For each non-matching operand that's a MEM or a pseudo-register
4084*e4b17023SJohn Marino that didn't get a hard register, make an optional reload.
4085*e4b17023SJohn Marino This may get done even if the insn needs no reloads otherwise. */
4086*e4b17023SJohn Marino
4087*e4b17023SJohn Marino rtx operand = recog_data.operand[i];
4088*e4b17023SJohn Marino
4089*e4b17023SJohn Marino while (GET_CODE (operand) == SUBREG)
4090*e4b17023SJohn Marino operand = SUBREG_REG (operand);
4091*e4b17023SJohn Marino if ((MEM_P (operand)
4092*e4b17023SJohn Marino || (REG_P (operand)
4093*e4b17023SJohn Marino && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
4094*e4b17023SJohn Marino /* If this is only for an output, the optional reload would not
4095*e4b17023SJohn Marino actually cause us to use a register now, just note that
4096*e4b17023SJohn Marino something is stored here. */
4097*e4b17023SJohn Marino && (goal_alternative[i] != NO_REGS
4098*e4b17023SJohn Marino || modified[i] == RELOAD_WRITE)
4099*e4b17023SJohn Marino && ! no_input_reloads
4100*e4b17023SJohn Marino /* An optional output reload might allow to delete INSN later.
4101*e4b17023SJohn Marino We mustn't make in-out reloads on insns that are not permitted
4102*e4b17023SJohn Marino output reloads.
4103*e4b17023SJohn Marino If this is an asm, we can't delete it; we must not even call
4104*e4b17023SJohn Marino push_reload for an optional output reload in this case,
4105*e4b17023SJohn Marino because we can't be sure that the constraint allows a register,
4106*e4b17023SJohn Marino and push_reload verifies the constraints for asms. */
4107*e4b17023SJohn Marino && (modified[i] == RELOAD_READ
4108*e4b17023SJohn Marino || (! no_output_reloads && ! this_insn_is_asm)))
4109*e4b17023SJohn Marino operand_reloadnum[i]
4110*e4b17023SJohn Marino = push_reload ((modified[i] != RELOAD_WRITE
4111*e4b17023SJohn Marino ? recog_data.operand[i] : 0),
4112*e4b17023SJohn Marino (modified[i] != RELOAD_READ
4113*e4b17023SJohn Marino ? recog_data.operand[i] : 0),
4114*e4b17023SJohn Marino (modified[i] != RELOAD_WRITE
4115*e4b17023SJohn Marino ? recog_data.operand_loc[i] : 0),
4116*e4b17023SJohn Marino (modified[i] != RELOAD_READ
4117*e4b17023SJohn Marino ? recog_data.operand_loc[i] : 0),
4118*e4b17023SJohn Marino (enum reg_class) goal_alternative[i],
4119*e4b17023SJohn Marino (modified[i] == RELOAD_WRITE
4120*e4b17023SJohn Marino ? VOIDmode : operand_mode[i]),
4121*e4b17023SJohn Marino (modified[i] == RELOAD_READ
4122*e4b17023SJohn Marino ? VOIDmode : operand_mode[i]),
4123*e4b17023SJohn Marino (insn_code_number < 0 ? 0
4124*e4b17023SJohn Marino : insn_data[insn_code_number].operand[i].strict_low),
4125*e4b17023SJohn Marino 1, i, operand_type[i]);
4126*e4b17023SJohn Marino /* If a memory reference remains (either as a MEM or a pseudo that
4127*e4b17023SJohn Marino did not get a hard register), yet we can't make an optional
4128*e4b17023SJohn Marino reload, check if this is actually a pseudo register reference;
4129*e4b17023SJohn Marino we then need to emit a USE and/or a CLOBBER so that reload
4130*e4b17023SJohn Marino inheritance will do the right thing. */
4131*e4b17023SJohn Marino else if (replace
4132*e4b17023SJohn Marino && (MEM_P (operand)
4133*e4b17023SJohn Marino || (REG_P (operand)
4134*e4b17023SJohn Marino && REGNO (operand) >= FIRST_PSEUDO_REGISTER
4135*e4b17023SJohn Marino && reg_renumber [REGNO (operand)] < 0)))
4136*e4b17023SJohn Marino {
4137*e4b17023SJohn Marino operand = *recog_data.operand_loc[i];
4138*e4b17023SJohn Marino
4139*e4b17023SJohn Marino while (GET_CODE (operand) == SUBREG)
4140*e4b17023SJohn Marino operand = SUBREG_REG (operand);
4141*e4b17023SJohn Marino if (REG_P (operand))
4142*e4b17023SJohn Marino {
4143*e4b17023SJohn Marino if (modified[i] != RELOAD_WRITE)
4144*e4b17023SJohn Marino /* We mark the USE with QImode so that we recognize
4145*e4b17023SJohn Marino it as one that can be safely deleted at the end
4146*e4b17023SJohn Marino of reload. */
4147*e4b17023SJohn Marino PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, operand),
4148*e4b17023SJohn Marino insn), QImode);
4149*e4b17023SJohn Marino if (modified[i] != RELOAD_READ)
4150*e4b17023SJohn Marino emit_insn_after (gen_clobber (operand), insn);
4151*e4b17023SJohn Marino }
4152*e4b17023SJohn Marino }
4153*e4b17023SJohn Marino }
4154*e4b17023SJohn Marino else if (goal_alternative_matches[i] >= 0
4155*e4b17023SJohn Marino && goal_alternative_win[goal_alternative_matches[i]]
4156*e4b17023SJohn Marino && modified[i] == RELOAD_READ
4157*e4b17023SJohn Marino && modified[goal_alternative_matches[i]] == RELOAD_WRITE
4158*e4b17023SJohn Marino && ! no_input_reloads && ! no_output_reloads
4159*e4b17023SJohn Marino && optimize)
4160*e4b17023SJohn Marino {
4161*e4b17023SJohn Marino /* Similarly, make an optional reload for a pair of matching
4162*e4b17023SJohn Marino objects that are in MEM or a pseudo that didn't get a hard reg. */
4163*e4b17023SJohn Marino
4164*e4b17023SJohn Marino rtx operand = recog_data.operand[i];
4165*e4b17023SJohn Marino
4166*e4b17023SJohn Marino while (GET_CODE (operand) == SUBREG)
4167*e4b17023SJohn Marino operand = SUBREG_REG (operand);
4168*e4b17023SJohn Marino if ((MEM_P (operand)
4169*e4b17023SJohn Marino || (REG_P (operand)
4170*e4b17023SJohn Marino && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
4171*e4b17023SJohn Marino && (goal_alternative[goal_alternative_matches[i]] != NO_REGS))
4172*e4b17023SJohn Marino operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]]
4173*e4b17023SJohn Marino = push_reload (recog_data.operand[goal_alternative_matches[i]],
4174*e4b17023SJohn Marino recog_data.operand[i],
4175*e4b17023SJohn Marino recog_data.operand_loc[goal_alternative_matches[i]],
4176*e4b17023SJohn Marino recog_data.operand_loc[i],
4177*e4b17023SJohn Marino (enum reg_class) goal_alternative[goal_alternative_matches[i]],
4178*e4b17023SJohn Marino operand_mode[goal_alternative_matches[i]],
4179*e4b17023SJohn Marino operand_mode[i],
4180*e4b17023SJohn Marino 0, 1, goal_alternative_matches[i], RELOAD_OTHER);
4181*e4b17023SJohn Marino }
4182*e4b17023SJohn Marino
4183*e4b17023SJohn Marino /* Perform whatever substitutions on the operands we are supposed
4184*e4b17023SJohn Marino to make due to commutativity or replacement of registers
4185*e4b17023SJohn Marino with equivalent constants or memory slots. */
4186*e4b17023SJohn Marino
4187*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
4188*e4b17023SJohn Marino {
4189*e4b17023SJohn Marino /* We only do this on the last pass through reload, because it is
4190*e4b17023SJohn Marino possible for some data (like reg_equiv_address) to be changed during
4191*e4b17023SJohn Marino later passes. Moreover, we lose the opportunity to get a useful
4192*e4b17023SJohn Marino reload_{in,out}_reg when we do these replacements. */
4193*e4b17023SJohn Marino
4194*e4b17023SJohn Marino if (replace)
4195*e4b17023SJohn Marino {
4196*e4b17023SJohn Marino rtx substitution = substed_operand[i];
4197*e4b17023SJohn Marino
4198*e4b17023SJohn Marino *recog_data.operand_loc[i] = substitution;
4199*e4b17023SJohn Marino
4200*e4b17023SJohn Marino /* If we're replacing an operand with a LABEL_REF, we need to
4201*e4b17023SJohn Marino make sure that there's a REG_LABEL_OPERAND note attached to
4202*e4b17023SJohn Marino this instruction. */
4203*e4b17023SJohn Marino if (GET_CODE (substitution) == LABEL_REF
4204*e4b17023SJohn Marino && !find_reg_note (insn, REG_LABEL_OPERAND,
4205*e4b17023SJohn Marino XEXP (substitution, 0))
4206*e4b17023SJohn Marino /* For a JUMP_P, if it was a branch target it must have
4207*e4b17023SJohn Marino already been recorded as such. */
4208*e4b17023SJohn Marino && (!JUMP_P (insn)
4209*e4b17023SJohn Marino || !label_is_jump_target_p (XEXP (substitution, 0),
4210*e4b17023SJohn Marino insn)))
4211*e4b17023SJohn Marino {
4212*e4b17023SJohn Marino add_reg_note (insn, REG_LABEL_OPERAND, XEXP (substitution, 0));
4213*e4b17023SJohn Marino if (LABEL_P (XEXP (substitution, 0)))
4214*e4b17023SJohn Marino ++LABEL_NUSES (XEXP (substitution, 0));
4215*e4b17023SJohn Marino }
4216*e4b17023SJohn Marino
4217*e4b17023SJohn Marino }
4218*e4b17023SJohn Marino else
4219*e4b17023SJohn Marino retval |= (substed_operand[i] != *recog_data.operand_loc[i]);
4220*e4b17023SJohn Marino }
4221*e4b17023SJohn Marino
4222*e4b17023SJohn Marino /* If this insn pattern contains any MATCH_DUP's, make sure that
4223*e4b17023SJohn Marino they will be substituted if the operands they match are substituted.
4224*e4b17023SJohn Marino Also do now any substitutions we already did on the operands.
4225*e4b17023SJohn Marino
4226*e4b17023SJohn Marino Don't do this if we aren't making replacements because we might be
4227*e4b17023SJohn Marino propagating things allocated by frame pointer elimination into places
4228*e4b17023SJohn Marino it doesn't expect. */
4229*e4b17023SJohn Marino
4230*e4b17023SJohn Marino if (insn_code_number >= 0 && replace)
4231*e4b17023SJohn Marino for (i = insn_data[insn_code_number].n_dups - 1; i >= 0; i--)
4232*e4b17023SJohn Marino {
4233*e4b17023SJohn Marino int opno = recog_data.dup_num[i];
4234*e4b17023SJohn Marino *recog_data.dup_loc[i] = *recog_data.operand_loc[opno];
4235*e4b17023SJohn Marino dup_replacements (recog_data.dup_loc[i], recog_data.operand_loc[opno]);
4236*e4b17023SJohn Marino }
4237*e4b17023SJohn Marino
4238*e4b17023SJohn Marino #if 0
4239*e4b17023SJohn Marino /* This loses because reloading of prior insns can invalidate the equivalence
4240*e4b17023SJohn Marino (or at least find_equiv_reg isn't smart enough to find it any more),
4241*e4b17023SJohn Marino causing this insn to need more reload regs than it needed before.
4242*e4b17023SJohn Marino It may be too late to make the reload regs available.
4243*e4b17023SJohn Marino Now this optimization is done safely in choose_reload_regs. */
4244*e4b17023SJohn Marino
4245*e4b17023SJohn Marino /* For each reload of a reg into some other class of reg,
4246*e4b17023SJohn Marino search for an existing equivalent reg (same value now) in the right class.
4247*e4b17023SJohn Marino We can use it as long as we don't need to change its contents. */
4248*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
4249*e4b17023SJohn Marino if (rld[i].reg_rtx == 0
4250*e4b17023SJohn Marino && rld[i].in != 0
4251*e4b17023SJohn Marino && REG_P (rld[i].in)
4252*e4b17023SJohn Marino && rld[i].out == 0)
4253*e4b17023SJohn Marino {
4254*e4b17023SJohn Marino rld[i].reg_rtx
4255*e4b17023SJohn Marino = find_equiv_reg (rld[i].in, insn, rld[i].rclass, -1,
4256*e4b17023SJohn Marino static_reload_reg_p, 0, rld[i].inmode);
4257*e4b17023SJohn Marino /* Prevent generation of insn to load the value
4258*e4b17023SJohn Marino because the one we found already has the value. */
4259*e4b17023SJohn Marino if (rld[i].reg_rtx)
4260*e4b17023SJohn Marino rld[i].in = rld[i].reg_rtx;
4261*e4b17023SJohn Marino }
4262*e4b17023SJohn Marino #endif
4263*e4b17023SJohn Marino
4264*e4b17023SJohn Marino /* If we detected error and replaced asm instruction by USE, forget about the
4265*e4b17023SJohn Marino reloads. */
4266*e4b17023SJohn Marino if (GET_CODE (PATTERN (insn)) == USE
4267*e4b17023SJohn Marino && CONST_INT_P (XEXP (PATTERN (insn), 0)))
4268*e4b17023SJohn Marino n_reloads = 0;
4269*e4b17023SJohn Marino
4270*e4b17023SJohn Marino /* Perhaps an output reload can be combined with another
4271*e4b17023SJohn Marino to reduce needs by one. */
4272*e4b17023SJohn Marino if (!goal_earlyclobber)
4273*e4b17023SJohn Marino combine_reloads ();
4274*e4b17023SJohn Marino
4275*e4b17023SJohn Marino /* If we have a pair of reloads for parts of an address, they are reloading
4276*e4b17023SJohn Marino the same object, the operands themselves were not reloaded, and they
4277*e4b17023SJohn Marino are for two operands that are supposed to match, merge the reloads and
4278*e4b17023SJohn Marino change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS. */
4279*e4b17023SJohn Marino
4280*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
4281*e4b17023SJohn Marino {
4282*e4b17023SJohn Marino int k;
4283*e4b17023SJohn Marino
4284*e4b17023SJohn Marino for (j = i + 1; j < n_reloads; j++)
4285*e4b17023SJohn Marino if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4286*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4287*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4288*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4289*e4b17023SJohn Marino && (rld[j].when_needed == RELOAD_FOR_INPUT_ADDRESS
4290*e4b17023SJohn Marino || rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4291*e4b17023SJohn Marino || rld[j].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4292*e4b17023SJohn Marino || rld[j].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4293*e4b17023SJohn Marino && rtx_equal_p (rld[i].in, rld[j].in)
4294*e4b17023SJohn Marino && (operand_reloadnum[rld[i].opnum] < 0
4295*e4b17023SJohn Marino || rld[operand_reloadnum[rld[i].opnum]].optional)
4296*e4b17023SJohn Marino && (operand_reloadnum[rld[j].opnum] < 0
4297*e4b17023SJohn Marino || rld[operand_reloadnum[rld[j].opnum]].optional)
4298*e4b17023SJohn Marino && (goal_alternative_matches[rld[i].opnum] == rld[j].opnum
4299*e4b17023SJohn Marino || (goal_alternative_matches[rld[j].opnum]
4300*e4b17023SJohn Marino == rld[i].opnum)))
4301*e4b17023SJohn Marino {
4302*e4b17023SJohn Marino for (k = 0; k < n_replacements; k++)
4303*e4b17023SJohn Marino if (replacements[k].what == j)
4304*e4b17023SJohn Marino replacements[k].what = i;
4305*e4b17023SJohn Marino
4306*e4b17023SJohn Marino if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4307*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4308*e4b17023SJohn Marino rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
4309*e4b17023SJohn Marino else
4310*e4b17023SJohn Marino rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
4311*e4b17023SJohn Marino rld[j].in = 0;
4312*e4b17023SJohn Marino }
4313*e4b17023SJohn Marino }
4314*e4b17023SJohn Marino
4315*e4b17023SJohn Marino /* Scan all the reloads and update their type.
4316*e4b17023SJohn Marino If a reload is for the address of an operand and we didn't reload
4317*e4b17023SJohn Marino that operand, change the type. Similarly, change the operand number
4318*e4b17023SJohn Marino of a reload when two operands match. If a reload is optional, treat it
4319*e4b17023SJohn Marino as though the operand isn't reloaded.
4320*e4b17023SJohn Marino
4321*e4b17023SJohn Marino ??? This latter case is somewhat odd because if we do the optional
4322*e4b17023SJohn Marino reload, it means the object is hanging around. Thus we need only
4323*e4b17023SJohn Marino do the address reload if the optional reload was NOT done.
4324*e4b17023SJohn Marino
4325*e4b17023SJohn Marino Change secondary reloads to be the address type of their operand, not
4326*e4b17023SJohn Marino the normal type.
4327*e4b17023SJohn Marino
4328*e4b17023SJohn Marino If an operand's reload is now RELOAD_OTHER, change any
4329*e4b17023SJohn Marino RELOAD_FOR_INPUT_ADDRESS reloads of that operand to
4330*e4b17023SJohn Marino RELOAD_FOR_OTHER_ADDRESS. */
4331*e4b17023SJohn Marino
4332*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
4333*e4b17023SJohn Marino {
4334*e4b17023SJohn Marino if (rld[i].secondary_p
4335*e4b17023SJohn Marino && rld[i].when_needed == operand_type[rld[i].opnum])
4336*e4b17023SJohn Marino rld[i].when_needed = address_type[rld[i].opnum];
4337*e4b17023SJohn Marino
4338*e4b17023SJohn Marino if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4339*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4340*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4341*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4342*e4b17023SJohn Marino && (operand_reloadnum[rld[i].opnum] < 0
4343*e4b17023SJohn Marino || rld[operand_reloadnum[rld[i].opnum]].optional))
4344*e4b17023SJohn Marino {
4345*e4b17023SJohn Marino /* If we have a secondary reload to go along with this reload,
4346*e4b17023SJohn Marino change its type to RELOAD_FOR_OPADDR_ADDR. */
4347*e4b17023SJohn Marino
4348*e4b17023SJohn Marino if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4349*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4350*e4b17023SJohn Marino && rld[i].secondary_in_reload != -1)
4351*e4b17023SJohn Marino {
4352*e4b17023SJohn Marino int secondary_in_reload = rld[i].secondary_in_reload;
4353*e4b17023SJohn Marino
4354*e4b17023SJohn Marino rld[secondary_in_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4355*e4b17023SJohn Marino
4356*e4b17023SJohn Marino /* If there's a tertiary reload we have to change it also. */
4357*e4b17023SJohn Marino if (secondary_in_reload > 0
4358*e4b17023SJohn Marino && rld[secondary_in_reload].secondary_in_reload != -1)
4359*e4b17023SJohn Marino rld[rld[secondary_in_reload].secondary_in_reload].when_needed
4360*e4b17023SJohn Marino = RELOAD_FOR_OPADDR_ADDR;
4361*e4b17023SJohn Marino }
4362*e4b17023SJohn Marino
4363*e4b17023SJohn Marino if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4364*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4365*e4b17023SJohn Marino && rld[i].secondary_out_reload != -1)
4366*e4b17023SJohn Marino {
4367*e4b17023SJohn Marino int secondary_out_reload = rld[i].secondary_out_reload;
4368*e4b17023SJohn Marino
4369*e4b17023SJohn Marino rld[secondary_out_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4370*e4b17023SJohn Marino
4371*e4b17023SJohn Marino /* If there's a tertiary reload we have to change it also. */
4372*e4b17023SJohn Marino if (secondary_out_reload
4373*e4b17023SJohn Marino && rld[secondary_out_reload].secondary_out_reload != -1)
4374*e4b17023SJohn Marino rld[rld[secondary_out_reload].secondary_out_reload].when_needed
4375*e4b17023SJohn Marino = RELOAD_FOR_OPADDR_ADDR;
4376*e4b17023SJohn Marino }
4377*e4b17023SJohn Marino
4378*e4b17023SJohn Marino if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4379*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4380*e4b17023SJohn Marino rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
4381*e4b17023SJohn Marino else
4382*e4b17023SJohn Marino rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
4383*e4b17023SJohn Marino }
4384*e4b17023SJohn Marino
4385*e4b17023SJohn Marino if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4386*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4387*e4b17023SJohn Marino && operand_reloadnum[rld[i].opnum] >= 0
4388*e4b17023SJohn Marino && (rld[operand_reloadnum[rld[i].opnum]].when_needed
4389*e4b17023SJohn Marino == RELOAD_OTHER))
4390*e4b17023SJohn Marino rld[i].when_needed = RELOAD_FOR_OTHER_ADDRESS;
4391*e4b17023SJohn Marino
4392*e4b17023SJohn Marino if (goal_alternative_matches[rld[i].opnum] >= 0)
4393*e4b17023SJohn Marino rld[i].opnum = goal_alternative_matches[rld[i].opnum];
4394*e4b17023SJohn Marino }
4395*e4b17023SJohn Marino
4396*e4b17023SJohn Marino /* Scan all the reloads, and check for RELOAD_FOR_OPERAND_ADDRESS reloads.
4397*e4b17023SJohn Marino If we have more than one, then convert all RELOAD_FOR_OPADDR_ADDR
4398*e4b17023SJohn Marino reloads to RELOAD_FOR_OPERAND_ADDRESS reloads.
4399*e4b17023SJohn Marino
4400*e4b17023SJohn Marino choose_reload_regs assumes that RELOAD_FOR_OPADDR_ADDR reloads never
4401*e4b17023SJohn Marino conflict with RELOAD_FOR_OPERAND_ADDRESS reloads. This is true for a
4402*e4b17023SJohn Marino single pair of RELOAD_FOR_OPADDR_ADDR/RELOAD_FOR_OPERAND_ADDRESS reloads.
4403*e4b17023SJohn Marino However, if there is more than one RELOAD_FOR_OPERAND_ADDRESS reload,
4404*e4b17023SJohn Marino then a RELOAD_FOR_OPADDR_ADDR reload conflicts with all
4405*e4b17023SJohn Marino RELOAD_FOR_OPERAND_ADDRESS reloads other than the one that uses it.
4406*e4b17023SJohn Marino This is complicated by the fact that a single operand can have more
4407*e4b17023SJohn Marino than one RELOAD_FOR_OPERAND_ADDRESS reload. It is very difficult to fix
4408*e4b17023SJohn Marino choose_reload_regs without affecting code quality, and cases that
4409*e4b17023SJohn Marino actually fail are extremely rare, so it turns out to be better to fix
4410*e4b17023SJohn Marino the problem here by not generating cases that choose_reload_regs will
4411*e4b17023SJohn Marino fail for. */
4412*e4b17023SJohn Marino /* There is a similar problem with RELOAD_FOR_INPUT_ADDRESS /
4413*e4b17023SJohn Marino RELOAD_FOR_OUTPUT_ADDRESS when there is more than one of a kind for
4414*e4b17023SJohn Marino a single operand.
4415*e4b17023SJohn Marino We can reduce the register pressure by exploiting that a
4416*e4b17023SJohn Marino RELOAD_FOR_X_ADDR_ADDR that precedes all RELOAD_FOR_X_ADDRESS reloads
4417*e4b17023SJohn Marino does not conflict with any of them, if it is only used for the first of
4418*e4b17023SJohn Marino the RELOAD_FOR_X_ADDRESS reloads. */
4419*e4b17023SJohn Marino {
4420*e4b17023SJohn Marino int first_op_addr_num = -2;
4421*e4b17023SJohn Marino int first_inpaddr_num[MAX_RECOG_OPERANDS];
4422*e4b17023SJohn Marino int first_outpaddr_num[MAX_RECOG_OPERANDS];
4423*e4b17023SJohn Marino int need_change = 0;
4424*e4b17023SJohn Marino /* We use last_op_addr_reload and the contents of the above arrays
4425*e4b17023SJohn Marino first as flags - -2 means no instance encountered, -1 means exactly
4426*e4b17023SJohn Marino one instance encountered.
4427*e4b17023SJohn Marino If more than one instance has been encountered, we store the reload
4428*e4b17023SJohn Marino number of the first reload of the kind in question; reload numbers
4429*e4b17023SJohn Marino are known to be non-negative. */
4430*e4b17023SJohn Marino for (i = 0; i < noperands; i++)
4431*e4b17023SJohn Marino first_inpaddr_num[i] = first_outpaddr_num[i] = -2;
4432*e4b17023SJohn Marino for (i = n_reloads - 1; i >= 0; i--)
4433*e4b17023SJohn Marino {
4434*e4b17023SJohn Marino switch (rld[i].when_needed)
4435*e4b17023SJohn Marino {
4436*e4b17023SJohn Marino case RELOAD_FOR_OPERAND_ADDRESS:
4437*e4b17023SJohn Marino if (++first_op_addr_num >= 0)
4438*e4b17023SJohn Marino {
4439*e4b17023SJohn Marino first_op_addr_num = i;
4440*e4b17023SJohn Marino need_change = 1;
4441*e4b17023SJohn Marino }
4442*e4b17023SJohn Marino break;
4443*e4b17023SJohn Marino case RELOAD_FOR_INPUT_ADDRESS:
4444*e4b17023SJohn Marino if (++first_inpaddr_num[rld[i].opnum] >= 0)
4445*e4b17023SJohn Marino {
4446*e4b17023SJohn Marino first_inpaddr_num[rld[i].opnum] = i;
4447*e4b17023SJohn Marino need_change = 1;
4448*e4b17023SJohn Marino }
4449*e4b17023SJohn Marino break;
4450*e4b17023SJohn Marino case RELOAD_FOR_OUTPUT_ADDRESS:
4451*e4b17023SJohn Marino if (++first_outpaddr_num[rld[i].opnum] >= 0)
4452*e4b17023SJohn Marino {
4453*e4b17023SJohn Marino first_outpaddr_num[rld[i].opnum] = i;
4454*e4b17023SJohn Marino need_change = 1;
4455*e4b17023SJohn Marino }
4456*e4b17023SJohn Marino break;
4457*e4b17023SJohn Marino default:
4458*e4b17023SJohn Marino break;
4459*e4b17023SJohn Marino }
4460*e4b17023SJohn Marino }
4461*e4b17023SJohn Marino
4462*e4b17023SJohn Marino if (need_change)
4463*e4b17023SJohn Marino {
4464*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
4465*e4b17023SJohn Marino {
4466*e4b17023SJohn Marino int first_num;
4467*e4b17023SJohn Marino enum reload_type type;
4468*e4b17023SJohn Marino
4469*e4b17023SJohn Marino switch (rld[i].when_needed)
4470*e4b17023SJohn Marino {
4471*e4b17023SJohn Marino case RELOAD_FOR_OPADDR_ADDR:
4472*e4b17023SJohn Marino first_num = first_op_addr_num;
4473*e4b17023SJohn Marino type = RELOAD_FOR_OPERAND_ADDRESS;
4474*e4b17023SJohn Marino break;
4475*e4b17023SJohn Marino case RELOAD_FOR_INPADDR_ADDRESS:
4476*e4b17023SJohn Marino first_num = first_inpaddr_num[rld[i].opnum];
4477*e4b17023SJohn Marino type = RELOAD_FOR_INPUT_ADDRESS;
4478*e4b17023SJohn Marino break;
4479*e4b17023SJohn Marino case RELOAD_FOR_OUTADDR_ADDRESS:
4480*e4b17023SJohn Marino first_num = first_outpaddr_num[rld[i].opnum];
4481*e4b17023SJohn Marino type = RELOAD_FOR_OUTPUT_ADDRESS;
4482*e4b17023SJohn Marino break;
4483*e4b17023SJohn Marino default:
4484*e4b17023SJohn Marino continue;
4485*e4b17023SJohn Marino }
4486*e4b17023SJohn Marino if (first_num < 0)
4487*e4b17023SJohn Marino continue;
4488*e4b17023SJohn Marino else if (i > first_num)
4489*e4b17023SJohn Marino rld[i].when_needed = type;
4490*e4b17023SJohn Marino else
4491*e4b17023SJohn Marino {
4492*e4b17023SJohn Marino /* Check if the only TYPE reload that uses reload I is
4493*e4b17023SJohn Marino reload FIRST_NUM. */
4494*e4b17023SJohn Marino for (j = n_reloads - 1; j > first_num; j--)
4495*e4b17023SJohn Marino {
4496*e4b17023SJohn Marino if (rld[j].when_needed == type
4497*e4b17023SJohn Marino && (rld[i].secondary_p
4498*e4b17023SJohn Marino ? rld[j].secondary_in_reload == i
4499*e4b17023SJohn Marino : reg_mentioned_p (rld[i].in, rld[j].in)))
4500*e4b17023SJohn Marino {
4501*e4b17023SJohn Marino rld[i].when_needed = type;
4502*e4b17023SJohn Marino break;
4503*e4b17023SJohn Marino }
4504*e4b17023SJohn Marino }
4505*e4b17023SJohn Marino }
4506*e4b17023SJohn Marino }
4507*e4b17023SJohn Marino }
4508*e4b17023SJohn Marino }
4509*e4b17023SJohn Marino
4510*e4b17023SJohn Marino /* See if we have any reloads that are now allowed to be merged
4511*e4b17023SJohn Marino because we've changed when the reload is needed to
4512*e4b17023SJohn Marino RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS. Only
4513*e4b17023SJohn Marino check for the most common cases. */
4514*e4b17023SJohn Marino
4515*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
4516*e4b17023SJohn Marino if (rld[i].in != 0 && rld[i].out == 0
4517*e4b17023SJohn Marino && (rld[i].when_needed == RELOAD_FOR_OPERAND_ADDRESS
4518*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OPADDR_ADDR
4519*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OTHER_ADDRESS))
4520*e4b17023SJohn Marino for (j = 0; j < n_reloads; j++)
4521*e4b17023SJohn Marino if (i != j && rld[j].in != 0 && rld[j].out == 0
4522*e4b17023SJohn Marino && rld[j].when_needed == rld[i].when_needed
4523*e4b17023SJohn Marino && MATCHES (rld[i].in, rld[j].in)
4524*e4b17023SJohn Marino && rld[i].rclass == rld[j].rclass
4525*e4b17023SJohn Marino && !rld[i].nocombine && !rld[j].nocombine
4526*e4b17023SJohn Marino && rld[i].reg_rtx == rld[j].reg_rtx)
4527*e4b17023SJohn Marino {
4528*e4b17023SJohn Marino rld[i].opnum = MIN (rld[i].opnum, rld[j].opnum);
4529*e4b17023SJohn Marino transfer_replacements (i, j);
4530*e4b17023SJohn Marino rld[j].in = 0;
4531*e4b17023SJohn Marino }
4532*e4b17023SJohn Marino
4533*e4b17023SJohn Marino #ifdef HAVE_cc0
4534*e4b17023SJohn Marino /* If we made any reloads for addresses, see if they violate a
4535*e4b17023SJohn Marino "no input reloads" requirement for this insn. But loads that we
4536*e4b17023SJohn Marino do after the insn (such as for output addresses) are fine. */
4537*e4b17023SJohn Marino if (no_input_reloads)
4538*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
4539*e4b17023SJohn Marino gcc_assert (rld[i].in == 0
4540*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS
4541*e4b17023SJohn Marino || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS);
4542*e4b17023SJohn Marino #endif
4543*e4b17023SJohn Marino
4544*e4b17023SJohn Marino /* Compute reload_mode and reload_nregs. */
4545*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
4546*e4b17023SJohn Marino {
4547*e4b17023SJohn Marino rld[i].mode
4548*e4b17023SJohn Marino = (rld[i].inmode == VOIDmode
4549*e4b17023SJohn Marino || (GET_MODE_SIZE (rld[i].outmode)
4550*e4b17023SJohn Marino > GET_MODE_SIZE (rld[i].inmode)))
4551*e4b17023SJohn Marino ? rld[i].outmode : rld[i].inmode;
4552*e4b17023SJohn Marino
4553*e4b17023SJohn Marino rld[i].nregs = ira_reg_class_max_nregs [rld[i].rclass][rld[i].mode];
4554*e4b17023SJohn Marino }
4555*e4b17023SJohn Marino
4556*e4b17023SJohn Marino /* Special case a simple move with an input reload and a
4557*e4b17023SJohn Marino destination of a hard reg, if the hard reg is ok, use it. */
4558*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
4559*e4b17023SJohn Marino if (rld[i].when_needed == RELOAD_FOR_INPUT
4560*e4b17023SJohn Marino && GET_CODE (PATTERN (insn)) == SET
4561*e4b17023SJohn Marino && REG_P (SET_DEST (PATTERN (insn)))
4562*e4b17023SJohn Marino && (SET_SRC (PATTERN (insn)) == rld[i].in
4563*e4b17023SJohn Marino || SET_SRC (PATTERN (insn)) == rld[i].in_reg)
4564*e4b17023SJohn Marino && !elimination_target_reg_p (SET_DEST (PATTERN (insn))))
4565*e4b17023SJohn Marino {
4566*e4b17023SJohn Marino rtx dest = SET_DEST (PATTERN (insn));
4567*e4b17023SJohn Marino unsigned int regno = REGNO (dest);
4568*e4b17023SJohn Marino
4569*e4b17023SJohn Marino if (regno < FIRST_PSEUDO_REGISTER
4570*e4b17023SJohn Marino && TEST_HARD_REG_BIT (reg_class_contents[rld[i].rclass], regno)
4571*e4b17023SJohn Marino && HARD_REGNO_MODE_OK (regno, rld[i].mode))
4572*e4b17023SJohn Marino {
4573*e4b17023SJohn Marino int nr = hard_regno_nregs[regno][rld[i].mode];
4574*e4b17023SJohn Marino int ok = 1, nri;
4575*e4b17023SJohn Marino
4576*e4b17023SJohn Marino for (nri = 1; nri < nr; nri ++)
4577*e4b17023SJohn Marino if (! TEST_HARD_REG_BIT (reg_class_contents[rld[i].rclass], regno + nri))
4578*e4b17023SJohn Marino ok = 0;
4579*e4b17023SJohn Marino
4580*e4b17023SJohn Marino if (ok)
4581*e4b17023SJohn Marino rld[i].reg_rtx = dest;
4582*e4b17023SJohn Marino }
4583*e4b17023SJohn Marino }
4584*e4b17023SJohn Marino
4585*e4b17023SJohn Marino return retval;
4586*e4b17023SJohn Marino }
4587*e4b17023SJohn Marino
4588*e4b17023SJohn Marino /* Return true if alternative number ALTNUM in constraint-string
4589*e4b17023SJohn Marino CONSTRAINT is guaranteed to accept a reloaded constant-pool reference.
4590*e4b17023SJohn Marino MEM gives the reference if it didn't need any reloads, otherwise it
4591*e4b17023SJohn Marino is null. */
4592*e4b17023SJohn Marino
4593*e4b17023SJohn Marino static bool
alternative_allows_const_pool_ref(rtx mem ATTRIBUTE_UNUSED,const char * constraint,int altnum)4594*e4b17023SJohn Marino alternative_allows_const_pool_ref (rtx mem ATTRIBUTE_UNUSED,
4595*e4b17023SJohn Marino const char *constraint, int altnum)
4596*e4b17023SJohn Marino {
4597*e4b17023SJohn Marino int c;
4598*e4b17023SJohn Marino
4599*e4b17023SJohn Marino /* Skip alternatives before the one requested. */
4600*e4b17023SJohn Marino while (altnum > 0)
4601*e4b17023SJohn Marino {
4602*e4b17023SJohn Marino while (*constraint++ != ',')
4603*e4b17023SJohn Marino ;
4604*e4b17023SJohn Marino altnum--;
4605*e4b17023SJohn Marino }
4606*e4b17023SJohn Marino /* Scan the requested alternative for TARGET_MEM_CONSTRAINT or 'o'.
4607*e4b17023SJohn Marino If one of them is present, this alternative accepts the result of
4608*e4b17023SJohn Marino passing a constant-pool reference through find_reloads_toplev.
4609*e4b17023SJohn Marino
4610*e4b17023SJohn Marino The same is true of extra memory constraints if the address
4611*e4b17023SJohn Marino was reloaded into a register. However, the target may elect
4612*e4b17023SJohn Marino to disallow the original constant address, forcing it to be
4613*e4b17023SJohn Marino reloaded into a register instead. */
4614*e4b17023SJohn Marino for (; (c = *constraint) && c != ',' && c != '#';
4615*e4b17023SJohn Marino constraint += CONSTRAINT_LEN (c, constraint))
4616*e4b17023SJohn Marino {
4617*e4b17023SJohn Marino if (c == TARGET_MEM_CONSTRAINT || c == 'o')
4618*e4b17023SJohn Marino return true;
4619*e4b17023SJohn Marino #ifdef EXTRA_CONSTRAINT_STR
4620*e4b17023SJohn Marino if (EXTRA_MEMORY_CONSTRAINT (c, constraint)
4621*e4b17023SJohn Marino && (mem == NULL || EXTRA_CONSTRAINT_STR (mem, c, constraint)))
4622*e4b17023SJohn Marino return true;
4623*e4b17023SJohn Marino #endif
4624*e4b17023SJohn Marino }
4625*e4b17023SJohn Marino return false;
4626*e4b17023SJohn Marino }
4627*e4b17023SJohn Marino
4628*e4b17023SJohn Marino /* Scan X for memory references and scan the addresses for reloading.
4629*e4b17023SJohn Marino Also checks for references to "constant" regs that we want to eliminate
4630*e4b17023SJohn Marino and replaces them with the values they stand for.
4631*e4b17023SJohn Marino We may alter X destructively if it contains a reference to such.
4632*e4b17023SJohn Marino If X is just a constant reg, we return the equivalent value
4633*e4b17023SJohn Marino instead of X.
4634*e4b17023SJohn Marino
4635*e4b17023SJohn Marino IND_LEVELS says how many levels of indirect addressing this machine
4636*e4b17023SJohn Marino supports.
4637*e4b17023SJohn Marino
4638*e4b17023SJohn Marino OPNUM and TYPE identify the purpose of the reload.
4639*e4b17023SJohn Marino
4640*e4b17023SJohn Marino IS_SET_DEST is true if X is the destination of a SET, which is not
4641*e4b17023SJohn Marino appropriate to be replaced by a constant.
4642*e4b17023SJohn Marino
4643*e4b17023SJohn Marino INSN, if nonzero, is the insn in which we do the reload. It is used
4644*e4b17023SJohn Marino to determine if we may generate output reloads, and where to put USEs
4645*e4b17023SJohn Marino for pseudos that we have to replace with stack slots.
4646*e4b17023SJohn Marino
4647*e4b17023SJohn Marino ADDRESS_RELOADED. If nonzero, is a pointer to where we put the
4648*e4b17023SJohn Marino result of find_reloads_address. */
4649*e4b17023SJohn Marino
4650*e4b17023SJohn Marino static rtx
find_reloads_toplev(rtx x,int opnum,enum reload_type type,int ind_levels,int is_set_dest,rtx insn,int * address_reloaded)4651*e4b17023SJohn Marino find_reloads_toplev (rtx x, int opnum, enum reload_type type,
4652*e4b17023SJohn Marino int ind_levels, int is_set_dest, rtx insn,
4653*e4b17023SJohn Marino int *address_reloaded)
4654*e4b17023SJohn Marino {
4655*e4b17023SJohn Marino RTX_CODE code = GET_CODE (x);
4656*e4b17023SJohn Marino
4657*e4b17023SJohn Marino const char *fmt = GET_RTX_FORMAT (code);
4658*e4b17023SJohn Marino int i;
4659*e4b17023SJohn Marino int copied;
4660*e4b17023SJohn Marino
4661*e4b17023SJohn Marino if (code == REG)
4662*e4b17023SJohn Marino {
4663*e4b17023SJohn Marino /* This code is duplicated for speed in find_reloads. */
4664*e4b17023SJohn Marino int regno = REGNO (x);
4665*e4b17023SJohn Marino if (reg_equiv_constant (regno) != 0 && !is_set_dest)
4666*e4b17023SJohn Marino x = reg_equiv_constant (regno);
4667*e4b17023SJohn Marino #if 0
4668*e4b17023SJohn Marino /* This creates (subreg (mem...)) which would cause an unnecessary
4669*e4b17023SJohn Marino reload of the mem. */
4670*e4b17023SJohn Marino else if (reg_equiv_mem (regno) != 0)
4671*e4b17023SJohn Marino x = reg_equiv_mem (regno);
4672*e4b17023SJohn Marino #endif
4673*e4b17023SJohn Marino else if (reg_equiv_memory_loc (regno)
4674*e4b17023SJohn Marino && (reg_equiv_address (regno) != 0 || num_not_at_initial_offset))
4675*e4b17023SJohn Marino {
4676*e4b17023SJohn Marino rtx mem = make_memloc (x, regno);
4677*e4b17023SJohn Marino if (reg_equiv_address (regno)
4678*e4b17023SJohn Marino || ! rtx_equal_p (mem, reg_equiv_mem (regno)))
4679*e4b17023SJohn Marino {
4680*e4b17023SJohn Marino /* If this is not a toplevel operand, find_reloads doesn't see
4681*e4b17023SJohn Marino this substitution. We have to emit a USE of the pseudo so
4682*e4b17023SJohn Marino that delete_output_reload can see it. */
4683*e4b17023SJohn Marino if (replace_reloads && recog_data.operand[opnum] != x)
4684*e4b17023SJohn Marino /* We mark the USE with QImode so that we recognize it
4685*e4b17023SJohn Marino as one that can be safely deleted at the end of
4686*e4b17023SJohn Marino reload. */
4687*e4b17023SJohn Marino PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, x), insn),
4688*e4b17023SJohn Marino QImode);
4689*e4b17023SJohn Marino x = mem;
4690*e4b17023SJohn Marino i = find_reloads_address (GET_MODE (x), &x, XEXP (x, 0), &XEXP (x, 0),
4691*e4b17023SJohn Marino opnum, type, ind_levels, insn);
4692*e4b17023SJohn Marino if (!rtx_equal_p (x, mem))
4693*e4b17023SJohn Marino push_reg_equiv_alt_mem (regno, x);
4694*e4b17023SJohn Marino if (address_reloaded)
4695*e4b17023SJohn Marino *address_reloaded = i;
4696*e4b17023SJohn Marino }
4697*e4b17023SJohn Marino }
4698*e4b17023SJohn Marino return x;
4699*e4b17023SJohn Marino }
4700*e4b17023SJohn Marino if (code == MEM)
4701*e4b17023SJohn Marino {
4702*e4b17023SJohn Marino rtx tem = x;
4703*e4b17023SJohn Marino
4704*e4b17023SJohn Marino i = find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
4705*e4b17023SJohn Marino opnum, type, ind_levels, insn);
4706*e4b17023SJohn Marino if (address_reloaded)
4707*e4b17023SJohn Marino *address_reloaded = i;
4708*e4b17023SJohn Marino
4709*e4b17023SJohn Marino return tem;
4710*e4b17023SJohn Marino }
4711*e4b17023SJohn Marino
4712*e4b17023SJohn Marino if (code == SUBREG && REG_P (SUBREG_REG (x)))
4713*e4b17023SJohn Marino {
4714*e4b17023SJohn Marino /* Check for SUBREG containing a REG that's equivalent to a
4715*e4b17023SJohn Marino constant. If the constant has a known value, truncate it
4716*e4b17023SJohn Marino right now. Similarly if we are extracting a single-word of a
4717*e4b17023SJohn Marino multi-word constant. If the constant is symbolic, allow it
4718*e4b17023SJohn Marino to be substituted normally. push_reload will strip the
4719*e4b17023SJohn Marino subreg later. The constant must not be VOIDmode, because we
4720*e4b17023SJohn Marino will lose the mode of the register (this should never happen
4721*e4b17023SJohn Marino because one of the cases above should handle it). */
4722*e4b17023SJohn Marino
4723*e4b17023SJohn Marino int regno = REGNO (SUBREG_REG (x));
4724*e4b17023SJohn Marino rtx tem;
4725*e4b17023SJohn Marino
4726*e4b17023SJohn Marino if (regno >= FIRST_PSEUDO_REGISTER
4727*e4b17023SJohn Marino && reg_renumber[regno] < 0
4728*e4b17023SJohn Marino && reg_equiv_constant (regno) != 0)
4729*e4b17023SJohn Marino {
4730*e4b17023SJohn Marino tem =
4731*e4b17023SJohn Marino simplify_gen_subreg (GET_MODE (x), reg_equiv_constant (regno),
4732*e4b17023SJohn Marino GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
4733*e4b17023SJohn Marino gcc_assert (tem);
4734*e4b17023SJohn Marino if (CONSTANT_P (tem)
4735*e4b17023SJohn Marino && !targetm.legitimate_constant_p (GET_MODE (x), tem))
4736*e4b17023SJohn Marino {
4737*e4b17023SJohn Marino tem = force_const_mem (GET_MODE (x), tem);
4738*e4b17023SJohn Marino i = find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
4739*e4b17023SJohn Marino &XEXP (tem, 0), opnum, type,
4740*e4b17023SJohn Marino ind_levels, insn);
4741*e4b17023SJohn Marino if (address_reloaded)
4742*e4b17023SJohn Marino *address_reloaded = i;
4743*e4b17023SJohn Marino }
4744*e4b17023SJohn Marino return tem;
4745*e4b17023SJohn Marino }
4746*e4b17023SJohn Marino
4747*e4b17023SJohn Marino /* If the subreg contains a reg that will be converted to a mem,
4748*e4b17023SJohn Marino convert the subreg to a narrower memref now.
4749*e4b17023SJohn Marino Otherwise, we would get (subreg (mem ...) ...),
4750*e4b17023SJohn Marino which would force reload of the mem.
4751*e4b17023SJohn Marino
4752*e4b17023SJohn Marino We also need to do this if there is an equivalent MEM that is
4753*e4b17023SJohn Marino not offsettable. In that case, alter_subreg would produce an
4754*e4b17023SJohn Marino invalid address on big-endian machines.
4755*e4b17023SJohn Marino
4756*e4b17023SJohn Marino For machines that extend byte loads, we must not reload using
4757*e4b17023SJohn Marino a wider mode if we have a paradoxical SUBREG. find_reloads will
4758*e4b17023SJohn Marino force a reload in that case. So we should not do anything here. */
4759*e4b17023SJohn Marino
4760*e4b17023SJohn Marino if (regno >= FIRST_PSEUDO_REGISTER
4761*e4b17023SJohn Marino #ifdef LOAD_EXTEND_OP
4762*e4b17023SJohn Marino && !paradoxical_subreg_p (x)
4763*e4b17023SJohn Marino #endif
4764*e4b17023SJohn Marino && (reg_equiv_address (regno) != 0
4765*e4b17023SJohn Marino || (reg_equiv_mem (regno) != 0
4766*e4b17023SJohn Marino && (! strict_memory_address_addr_space_p
4767*e4b17023SJohn Marino (GET_MODE (x), XEXP (reg_equiv_mem (regno), 0),
4768*e4b17023SJohn Marino MEM_ADDR_SPACE (reg_equiv_mem (regno)))
4769*e4b17023SJohn Marino || ! offsettable_memref_p (reg_equiv_mem (regno))
4770*e4b17023SJohn Marino || num_not_at_initial_offset))))
4771*e4b17023SJohn Marino x = find_reloads_subreg_address (x, 1, opnum, type, ind_levels,
4772*e4b17023SJohn Marino insn, address_reloaded);
4773*e4b17023SJohn Marino }
4774*e4b17023SJohn Marino
4775*e4b17023SJohn Marino for (copied = 0, i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4776*e4b17023SJohn Marino {
4777*e4b17023SJohn Marino if (fmt[i] == 'e')
4778*e4b17023SJohn Marino {
4779*e4b17023SJohn Marino rtx new_part = find_reloads_toplev (XEXP (x, i), opnum, type,
4780*e4b17023SJohn Marino ind_levels, is_set_dest, insn,
4781*e4b17023SJohn Marino address_reloaded);
4782*e4b17023SJohn Marino /* If we have replaced a reg with it's equivalent memory loc -
4783*e4b17023SJohn Marino that can still be handled here e.g. if it's in a paradoxical
4784*e4b17023SJohn Marino subreg - we must make the change in a copy, rather than using
4785*e4b17023SJohn Marino a destructive change. This way, find_reloads can still elect
4786*e4b17023SJohn Marino not to do the change. */
4787*e4b17023SJohn Marino if (new_part != XEXP (x, i) && ! CONSTANT_P (new_part) && ! copied)
4788*e4b17023SJohn Marino {
4789*e4b17023SJohn Marino x = shallow_copy_rtx (x);
4790*e4b17023SJohn Marino copied = 1;
4791*e4b17023SJohn Marino }
4792*e4b17023SJohn Marino XEXP (x, i) = new_part;
4793*e4b17023SJohn Marino }
4794*e4b17023SJohn Marino }
4795*e4b17023SJohn Marino return x;
4796*e4b17023SJohn Marino }
4797*e4b17023SJohn Marino
4798*e4b17023SJohn Marino /* Return a mem ref for the memory equivalent of reg REGNO.
4799*e4b17023SJohn Marino This mem ref is not shared with anything. */
4800*e4b17023SJohn Marino
4801*e4b17023SJohn Marino static rtx
make_memloc(rtx ad,int regno)4802*e4b17023SJohn Marino make_memloc (rtx ad, int regno)
4803*e4b17023SJohn Marino {
4804*e4b17023SJohn Marino /* We must rerun eliminate_regs, in case the elimination
4805*e4b17023SJohn Marino offsets have changed. */
4806*e4b17023SJohn Marino rtx tem
4807*e4b17023SJohn Marino = XEXP (eliminate_regs (reg_equiv_memory_loc (regno), VOIDmode, NULL_RTX),
4808*e4b17023SJohn Marino 0);
4809*e4b17023SJohn Marino
4810*e4b17023SJohn Marino /* If TEM might contain a pseudo, we must copy it to avoid
4811*e4b17023SJohn Marino modifying it when we do the substitution for the reload. */
4812*e4b17023SJohn Marino if (rtx_varies_p (tem, 0))
4813*e4b17023SJohn Marino tem = copy_rtx (tem);
4814*e4b17023SJohn Marino
4815*e4b17023SJohn Marino tem = replace_equiv_address_nv (reg_equiv_memory_loc (regno), tem);
4816*e4b17023SJohn Marino tem = adjust_address_nv (tem, GET_MODE (ad), 0);
4817*e4b17023SJohn Marino
4818*e4b17023SJohn Marino /* Copy the result if it's still the same as the equivalence, to avoid
4819*e4b17023SJohn Marino modifying it when we do the substitution for the reload. */
4820*e4b17023SJohn Marino if (tem == reg_equiv_memory_loc (regno))
4821*e4b17023SJohn Marino tem = copy_rtx (tem);
4822*e4b17023SJohn Marino return tem;
4823*e4b17023SJohn Marino }
4824*e4b17023SJohn Marino
4825*e4b17023SJohn Marino /* Returns true if AD could be turned into a valid memory reference
4826*e4b17023SJohn Marino to mode MODE in address space AS by reloading the part pointed to
4827*e4b17023SJohn Marino by PART into a register. */
4828*e4b17023SJohn Marino
4829*e4b17023SJohn Marino static int
maybe_memory_address_addr_space_p(enum machine_mode mode,rtx ad,addr_space_t as,rtx * part)4830*e4b17023SJohn Marino maybe_memory_address_addr_space_p (enum machine_mode mode, rtx ad,
4831*e4b17023SJohn Marino addr_space_t as, rtx *part)
4832*e4b17023SJohn Marino {
4833*e4b17023SJohn Marino int retv;
4834*e4b17023SJohn Marino rtx tem = *part;
4835*e4b17023SJohn Marino rtx reg = gen_rtx_REG (GET_MODE (tem), max_reg_num ());
4836*e4b17023SJohn Marino
4837*e4b17023SJohn Marino *part = reg;
4838*e4b17023SJohn Marino retv = memory_address_addr_space_p (mode, ad, as);
4839*e4b17023SJohn Marino *part = tem;
4840*e4b17023SJohn Marino
4841*e4b17023SJohn Marino return retv;
4842*e4b17023SJohn Marino }
4843*e4b17023SJohn Marino
4844*e4b17023SJohn Marino /* Record all reloads needed for handling memory address AD
4845*e4b17023SJohn Marino which appears in *LOC in a memory reference to mode MODE
4846*e4b17023SJohn Marino which itself is found in location *MEMREFLOC.
4847*e4b17023SJohn Marino Note that we take shortcuts assuming that no multi-reg machine mode
4848*e4b17023SJohn Marino occurs as part of an address.
4849*e4b17023SJohn Marino
4850*e4b17023SJohn Marino OPNUM and TYPE specify the purpose of this reload.
4851*e4b17023SJohn Marino
4852*e4b17023SJohn Marino IND_LEVELS says how many levels of indirect addressing this machine
4853*e4b17023SJohn Marino supports.
4854*e4b17023SJohn Marino
4855*e4b17023SJohn Marino INSN, if nonzero, is the insn in which we do the reload. It is used
4856*e4b17023SJohn Marino to determine if we may generate output reloads, and where to put USEs
4857*e4b17023SJohn Marino for pseudos that we have to replace with stack slots.
4858*e4b17023SJohn Marino
4859*e4b17023SJohn Marino Value is one if this address is reloaded or replaced as a whole; it is
4860*e4b17023SJohn Marino zero if the top level of this address was not reloaded or replaced, and
4861*e4b17023SJohn Marino it is -1 if it may or may not have been reloaded or replaced.
4862*e4b17023SJohn Marino
4863*e4b17023SJohn Marino Note that there is no verification that the address will be valid after
4864*e4b17023SJohn Marino this routine does its work. Instead, we rely on the fact that the address
4865*e4b17023SJohn Marino was valid when reload started. So we need only undo things that reload
4866*e4b17023SJohn Marino could have broken. These are wrong register types, pseudos not allocated
4867*e4b17023SJohn Marino to a hard register, and frame pointer elimination. */
4868*e4b17023SJohn Marino
4869*e4b17023SJohn Marino static int
find_reloads_address(enum machine_mode mode,rtx * memrefloc,rtx ad,rtx * loc,int opnum,enum reload_type type,int ind_levels,rtx insn)4870*e4b17023SJohn Marino find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
4871*e4b17023SJohn Marino rtx *loc, int opnum, enum reload_type type,
4872*e4b17023SJohn Marino int ind_levels, rtx insn)
4873*e4b17023SJohn Marino {
4874*e4b17023SJohn Marino addr_space_t as = memrefloc? MEM_ADDR_SPACE (*memrefloc)
4875*e4b17023SJohn Marino : ADDR_SPACE_GENERIC;
4876*e4b17023SJohn Marino int regno;
4877*e4b17023SJohn Marino int removed_and = 0;
4878*e4b17023SJohn Marino int op_index;
4879*e4b17023SJohn Marino rtx tem;
4880*e4b17023SJohn Marino
4881*e4b17023SJohn Marino /* If the address is a register, see if it is a legitimate address and
4882*e4b17023SJohn Marino reload if not. We first handle the cases where we need not reload
4883*e4b17023SJohn Marino or where we must reload in a non-standard way. */
4884*e4b17023SJohn Marino
4885*e4b17023SJohn Marino if (REG_P (ad))
4886*e4b17023SJohn Marino {
4887*e4b17023SJohn Marino regno = REGNO (ad);
4888*e4b17023SJohn Marino
4889*e4b17023SJohn Marino if (reg_equiv_constant (regno) != 0)
4890*e4b17023SJohn Marino {
4891*e4b17023SJohn Marino find_reloads_address_part (reg_equiv_constant (regno), loc,
4892*e4b17023SJohn Marino base_reg_class (mode, as, MEM, SCRATCH),
4893*e4b17023SJohn Marino GET_MODE (ad), opnum, type, ind_levels);
4894*e4b17023SJohn Marino return 1;
4895*e4b17023SJohn Marino }
4896*e4b17023SJohn Marino
4897*e4b17023SJohn Marino tem = reg_equiv_memory_loc (regno);
4898*e4b17023SJohn Marino if (tem != 0)
4899*e4b17023SJohn Marino {
4900*e4b17023SJohn Marino if (reg_equiv_address (regno) != 0 || num_not_at_initial_offset)
4901*e4b17023SJohn Marino {
4902*e4b17023SJohn Marino tem = make_memloc (ad, regno);
4903*e4b17023SJohn Marino if (! strict_memory_address_addr_space_p (GET_MODE (tem),
4904*e4b17023SJohn Marino XEXP (tem, 0),
4905*e4b17023SJohn Marino MEM_ADDR_SPACE (tem)))
4906*e4b17023SJohn Marino {
4907*e4b17023SJohn Marino rtx orig = tem;
4908*e4b17023SJohn Marino
4909*e4b17023SJohn Marino find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
4910*e4b17023SJohn Marino &XEXP (tem, 0), opnum,
4911*e4b17023SJohn Marino ADDR_TYPE (type), ind_levels, insn);
4912*e4b17023SJohn Marino if (!rtx_equal_p (tem, orig))
4913*e4b17023SJohn Marino push_reg_equiv_alt_mem (regno, tem);
4914*e4b17023SJohn Marino }
4915*e4b17023SJohn Marino /* We can avoid a reload if the register's equivalent memory
4916*e4b17023SJohn Marino expression is valid as an indirect memory address.
4917*e4b17023SJohn Marino But not all addresses are valid in a mem used as an indirect
4918*e4b17023SJohn Marino address: only reg or reg+constant. */
4919*e4b17023SJohn Marino
4920*e4b17023SJohn Marino if (ind_levels > 0
4921*e4b17023SJohn Marino && strict_memory_address_addr_space_p (mode, tem, as)
4922*e4b17023SJohn Marino && (REG_P (XEXP (tem, 0))
4923*e4b17023SJohn Marino || (GET_CODE (XEXP (tem, 0)) == PLUS
4924*e4b17023SJohn Marino && REG_P (XEXP (XEXP (tem, 0), 0))
4925*e4b17023SJohn Marino && CONSTANT_P (XEXP (XEXP (tem, 0), 1)))))
4926*e4b17023SJohn Marino {
4927*e4b17023SJohn Marino /* TEM is not the same as what we'll be replacing the
4928*e4b17023SJohn Marino pseudo with after reload, put a USE in front of INSN
4929*e4b17023SJohn Marino in the final reload pass. */
4930*e4b17023SJohn Marino if (replace_reloads
4931*e4b17023SJohn Marino && num_not_at_initial_offset
4932*e4b17023SJohn Marino && ! rtx_equal_p (tem, reg_equiv_mem (regno)))
4933*e4b17023SJohn Marino {
4934*e4b17023SJohn Marino *loc = tem;
4935*e4b17023SJohn Marino /* We mark the USE with QImode so that we
4936*e4b17023SJohn Marino recognize it as one that can be safely
4937*e4b17023SJohn Marino deleted at the end of reload. */
4938*e4b17023SJohn Marino PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad),
4939*e4b17023SJohn Marino insn), QImode);
4940*e4b17023SJohn Marino
4941*e4b17023SJohn Marino /* This doesn't really count as replacing the address
4942*e4b17023SJohn Marino as a whole, since it is still a memory access. */
4943*e4b17023SJohn Marino }
4944*e4b17023SJohn Marino return 0;
4945*e4b17023SJohn Marino }
4946*e4b17023SJohn Marino ad = tem;
4947*e4b17023SJohn Marino }
4948*e4b17023SJohn Marino }
4949*e4b17023SJohn Marino
4950*e4b17023SJohn Marino /* The only remaining case where we can avoid a reload is if this is a
4951*e4b17023SJohn Marino hard register that is valid as a base register and which is not the
4952*e4b17023SJohn Marino subject of a CLOBBER in this insn. */
4953*e4b17023SJohn Marino
4954*e4b17023SJohn Marino else if (regno < FIRST_PSEUDO_REGISTER
4955*e4b17023SJohn Marino && regno_ok_for_base_p (regno, mode, as, MEM, SCRATCH)
4956*e4b17023SJohn Marino && ! regno_clobbered_p (regno, this_insn, mode, 0))
4957*e4b17023SJohn Marino return 0;
4958*e4b17023SJohn Marino
4959*e4b17023SJohn Marino /* If we do not have one of the cases above, we must do the reload. */
4960*e4b17023SJohn Marino push_reload (ad, NULL_RTX, loc, (rtx*) 0,
4961*e4b17023SJohn Marino base_reg_class (mode, as, MEM, SCRATCH),
4962*e4b17023SJohn Marino GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
4963*e4b17023SJohn Marino return 1;
4964*e4b17023SJohn Marino }
4965*e4b17023SJohn Marino
4966*e4b17023SJohn Marino if (strict_memory_address_addr_space_p (mode, ad, as))
4967*e4b17023SJohn Marino {
4968*e4b17023SJohn Marino /* The address appears valid, so reloads are not needed.
4969*e4b17023SJohn Marino But the address may contain an eliminable register.
4970*e4b17023SJohn Marino This can happen because a machine with indirect addressing
4971*e4b17023SJohn Marino may consider a pseudo register by itself a valid address even when
4972*e4b17023SJohn Marino it has failed to get a hard reg.
4973*e4b17023SJohn Marino So do a tree-walk to find and eliminate all such regs. */
4974*e4b17023SJohn Marino
4975*e4b17023SJohn Marino /* But first quickly dispose of a common case. */
4976*e4b17023SJohn Marino if (GET_CODE (ad) == PLUS
4977*e4b17023SJohn Marino && CONST_INT_P (XEXP (ad, 1))
4978*e4b17023SJohn Marino && REG_P (XEXP (ad, 0))
4979*e4b17023SJohn Marino && reg_equiv_constant (REGNO (XEXP (ad, 0))) == 0)
4980*e4b17023SJohn Marino return 0;
4981*e4b17023SJohn Marino
4982*e4b17023SJohn Marino subst_reg_equivs_changed = 0;
4983*e4b17023SJohn Marino *loc = subst_reg_equivs (ad, insn);
4984*e4b17023SJohn Marino
4985*e4b17023SJohn Marino if (! subst_reg_equivs_changed)
4986*e4b17023SJohn Marino return 0;
4987*e4b17023SJohn Marino
4988*e4b17023SJohn Marino /* Check result for validity after substitution. */
4989*e4b17023SJohn Marino if (strict_memory_address_addr_space_p (mode, ad, as))
4990*e4b17023SJohn Marino return 0;
4991*e4b17023SJohn Marino }
4992*e4b17023SJohn Marino
4993*e4b17023SJohn Marino #ifdef LEGITIMIZE_RELOAD_ADDRESS
4994*e4b17023SJohn Marino do
4995*e4b17023SJohn Marino {
4996*e4b17023SJohn Marino if (memrefloc && ADDR_SPACE_GENERIC_P (as))
4997*e4b17023SJohn Marino {
4998*e4b17023SJohn Marino LEGITIMIZE_RELOAD_ADDRESS (ad, GET_MODE (*memrefloc), opnum, type,
4999*e4b17023SJohn Marino ind_levels, win);
5000*e4b17023SJohn Marino }
5001*e4b17023SJohn Marino break;
5002*e4b17023SJohn Marino win:
5003*e4b17023SJohn Marino *memrefloc = copy_rtx (*memrefloc);
5004*e4b17023SJohn Marino XEXP (*memrefloc, 0) = ad;
5005*e4b17023SJohn Marino move_replacements (&ad, &XEXP (*memrefloc, 0));
5006*e4b17023SJohn Marino return -1;
5007*e4b17023SJohn Marino }
5008*e4b17023SJohn Marino while (0);
5009*e4b17023SJohn Marino #endif
5010*e4b17023SJohn Marino
5011*e4b17023SJohn Marino /* The address is not valid. We have to figure out why. First see if
5012*e4b17023SJohn Marino we have an outer AND and remove it if so. Then analyze what's inside. */
5013*e4b17023SJohn Marino
5014*e4b17023SJohn Marino if (GET_CODE (ad) == AND)
5015*e4b17023SJohn Marino {
5016*e4b17023SJohn Marino removed_and = 1;
5017*e4b17023SJohn Marino loc = &XEXP (ad, 0);
5018*e4b17023SJohn Marino ad = *loc;
5019*e4b17023SJohn Marino }
5020*e4b17023SJohn Marino
5021*e4b17023SJohn Marino /* One possibility for why the address is invalid is that it is itself
5022*e4b17023SJohn Marino a MEM. This can happen when the frame pointer is being eliminated, a
5023*e4b17023SJohn Marino pseudo is not allocated to a hard register, and the offset between the
5024*e4b17023SJohn Marino frame and stack pointers is not its initial value. In that case the
5025*e4b17023SJohn Marino pseudo will have been replaced by a MEM referring to the
5026*e4b17023SJohn Marino stack pointer. */
5027*e4b17023SJohn Marino if (MEM_P (ad))
5028*e4b17023SJohn Marino {
5029*e4b17023SJohn Marino /* First ensure that the address in this MEM is valid. Then, unless
5030*e4b17023SJohn Marino indirect addresses are valid, reload the MEM into a register. */
5031*e4b17023SJohn Marino tem = ad;
5032*e4b17023SJohn Marino find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
5033*e4b17023SJohn Marino opnum, ADDR_TYPE (type),
5034*e4b17023SJohn Marino ind_levels == 0 ? 0 : ind_levels - 1, insn);
5035*e4b17023SJohn Marino
5036*e4b17023SJohn Marino /* If tem was changed, then we must create a new memory reference to
5037*e4b17023SJohn Marino hold it and store it back into memrefloc. */
5038*e4b17023SJohn Marino if (tem != ad && memrefloc)
5039*e4b17023SJohn Marino {
5040*e4b17023SJohn Marino *memrefloc = copy_rtx (*memrefloc);
5041*e4b17023SJohn Marino copy_replacements (tem, XEXP (*memrefloc, 0));
5042*e4b17023SJohn Marino loc = &XEXP (*memrefloc, 0);
5043*e4b17023SJohn Marino if (removed_and)
5044*e4b17023SJohn Marino loc = &XEXP (*loc, 0);
5045*e4b17023SJohn Marino }
5046*e4b17023SJohn Marino
5047*e4b17023SJohn Marino /* Check similar cases as for indirect addresses as above except
5048*e4b17023SJohn Marino that we can allow pseudos and a MEM since they should have been
5049*e4b17023SJohn Marino taken care of above. */
5050*e4b17023SJohn Marino
5051*e4b17023SJohn Marino if (ind_levels == 0
5052*e4b17023SJohn Marino || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
5053*e4b17023SJohn Marino || MEM_P (XEXP (tem, 0))
5054*e4b17023SJohn Marino || ! (REG_P (XEXP (tem, 0))
5055*e4b17023SJohn Marino || (GET_CODE (XEXP (tem, 0)) == PLUS
5056*e4b17023SJohn Marino && REG_P (XEXP (XEXP (tem, 0), 0))
5057*e4b17023SJohn Marino && CONST_INT_P (XEXP (XEXP (tem, 0), 1)))))
5058*e4b17023SJohn Marino {
5059*e4b17023SJohn Marino /* Must use TEM here, not AD, since it is the one that will
5060*e4b17023SJohn Marino have any subexpressions reloaded, if needed. */
5061*e4b17023SJohn Marino push_reload (tem, NULL_RTX, loc, (rtx*) 0,
5062*e4b17023SJohn Marino base_reg_class (mode, as, MEM, SCRATCH), GET_MODE (tem),
5063*e4b17023SJohn Marino VOIDmode, 0,
5064*e4b17023SJohn Marino 0, opnum, type);
5065*e4b17023SJohn Marino return ! removed_and;
5066*e4b17023SJohn Marino }
5067*e4b17023SJohn Marino else
5068*e4b17023SJohn Marino return 0;
5069*e4b17023SJohn Marino }
5070*e4b17023SJohn Marino
5071*e4b17023SJohn Marino /* If we have address of a stack slot but it's not valid because the
5072*e4b17023SJohn Marino displacement is too large, compute the sum in a register.
5073*e4b17023SJohn Marino Handle all base registers here, not just fp/ap/sp, because on some
5074*e4b17023SJohn Marino targets (namely SH) we can also get too large displacements from
5075*e4b17023SJohn Marino big-endian corrections. */
5076*e4b17023SJohn Marino else if (GET_CODE (ad) == PLUS
5077*e4b17023SJohn Marino && REG_P (XEXP (ad, 0))
5078*e4b17023SJohn Marino && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
5079*e4b17023SJohn Marino && CONST_INT_P (XEXP (ad, 1))
5080*e4b17023SJohn Marino && (regno_ok_for_base_p (REGNO (XEXP (ad, 0)), mode, as, PLUS,
5081*e4b17023SJohn Marino CONST_INT)
5082*e4b17023SJohn Marino /* Similarly, if we were to reload the base register and the
5083*e4b17023SJohn Marino mem+offset address is still invalid, then we want to reload
5084*e4b17023SJohn Marino the whole address, not just the base register. */
5085*e4b17023SJohn Marino || ! maybe_memory_address_addr_space_p
5086*e4b17023SJohn Marino (mode, ad, as, &(XEXP (ad, 0)))))
5087*e4b17023SJohn Marino
5088*e4b17023SJohn Marino {
5089*e4b17023SJohn Marino /* Unshare the MEM rtx so we can safely alter it. */
5090*e4b17023SJohn Marino if (memrefloc)
5091*e4b17023SJohn Marino {
5092*e4b17023SJohn Marino *memrefloc = copy_rtx (*memrefloc);
5093*e4b17023SJohn Marino loc = &XEXP (*memrefloc, 0);
5094*e4b17023SJohn Marino if (removed_and)
5095*e4b17023SJohn Marino loc = &XEXP (*loc, 0);
5096*e4b17023SJohn Marino }
5097*e4b17023SJohn Marino
5098*e4b17023SJohn Marino if (double_reg_address_ok
5099*e4b17023SJohn Marino && regno_ok_for_base_p (REGNO (XEXP (ad, 0)), mode, as,
5100*e4b17023SJohn Marino PLUS, CONST_INT))
5101*e4b17023SJohn Marino {
5102*e4b17023SJohn Marino /* Unshare the sum as well. */
5103*e4b17023SJohn Marino *loc = ad = copy_rtx (ad);
5104*e4b17023SJohn Marino
5105*e4b17023SJohn Marino /* Reload the displacement into an index reg.
5106*e4b17023SJohn Marino We assume the frame pointer or arg pointer is a base reg. */
5107*e4b17023SJohn Marino find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
5108*e4b17023SJohn Marino INDEX_REG_CLASS, GET_MODE (ad), opnum,
5109*e4b17023SJohn Marino type, ind_levels);
5110*e4b17023SJohn Marino return 0;
5111*e4b17023SJohn Marino }
5112*e4b17023SJohn Marino else
5113*e4b17023SJohn Marino {
5114*e4b17023SJohn Marino /* If the sum of two regs is not necessarily valid,
5115*e4b17023SJohn Marino reload the sum into a base reg.
5116*e4b17023SJohn Marino That will at least work. */
5117*e4b17023SJohn Marino find_reloads_address_part (ad, loc,
5118*e4b17023SJohn Marino base_reg_class (mode, as, MEM, SCRATCH),
5119*e4b17023SJohn Marino GET_MODE (ad), opnum, type, ind_levels);
5120*e4b17023SJohn Marino }
5121*e4b17023SJohn Marino return ! removed_and;
5122*e4b17023SJohn Marino }
5123*e4b17023SJohn Marino
5124*e4b17023SJohn Marino /* If we have an indexed stack slot, there are three possible reasons why
5125*e4b17023SJohn Marino it might be invalid: The index might need to be reloaded, the address
5126*e4b17023SJohn Marino might have been made by frame pointer elimination and hence have a
5127*e4b17023SJohn Marino constant out of range, or both reasons might apply.
5128*e4b17023SJohn Marino
5129*e4b17023SJohn Marino We can easily check for an index needing reload, but even if that is the
5130*e4b17023SJohn Marino case, we might also have an invalid constant. To avoid making the
5131*e4b17023SJohn Marino conservative assumption and requiring two reloads, we see if this address
5132*e4b17023SJohn Marino is valid when not interpreted strictly. If it is, the only problem is
5133*e4b17023SJohn Marino that the index needs a reload and find_reloads_address_1 will take care
5134*e4b17023SJohn Marino of it.
5135*e4b17023SJohn Marino
5136*e4b17023SJohn Marino Handle all base registers here, not just fp/ap/sp, because on some
5137*e4b17023SJohn Marino targets (namely SPARC) we can also get invalid addresses from preventive
5138*e4b17023SJohn Marino subreg big-endian corrections made by find_reloads_toplev. We
5139*e4b17023SJohn Marino can also get expressions involving LO_SUM (rather than PLUS) from
5140*e4b17023SJohn Marino find_reloads_subreg_address.
5141*e4b17023SJohn Marino
5142*e4b17023SJohn Marino If we decide to do something, it must be that `double_reg_address_ok'
5143*e4b17023SJohn Marino is true. We generate a reload of the base register + constant and
5144*e4b17023SJohn Marino rework the sum so that the reload register will be added to the index.
5145*e4b17023SJohn Marino This is safe because we know the address isn't shared.
5146*e4b17023SJohn Marino
5147*e4b17023SJohn Marino We check for the base register as both the first and second operand of
5148*e4b17023SJohn Marino the innermost PLUS and/or LO_SUM. */
5149*e4b17023SJohn Marino
5150*e4b17023SJohn Marino for (op_index = 0; op_index < 2; ++op_index)
5151*e4b17023SJohn Marino {
5152*e4b17023SJohn Marino rtx operand, addend;
5153*e4b17023SJohn Marino enum rtx_code inner_code;
5154*e4b17023SJohn Marino
5155*e4b17023SJohn Marino if (GET_CODE (ad) != PLUS)
5156*e4b17023SJohn Marino continue;
5157*e4b17023SJohn Marino
5158*e4b17023SJohn Marino inner_code = GET_CODE (XEXP (ad, 0));
5159*e4b17023SJohn Marino if (!(GET_CODE (ad) == PLUS
5160*e4b17023SJohn Marino && CONST_INT_P (XEXP (ad, 1))
5161*e4b17023SJohn Marino && (inner_code == PLUS || inner_code == LO_SUM)))
5162*e4b17023SJohn Marino continue;
5163*e4b17023SJohn Marino
5164*e4b17023SJohn Marino operand = XEXP (XEXP (ad, 0), op_index);
5165*e4b17023SJohn Marino if (!REG_P (operand) || REGNO (operand) >= FIRST_PSEUDO_REGISTER)
5166*e4b17023SJohn Marino continue;
5167*e4b17023SJohn Marino
5168*e4b17023SJohn Marino addend = XEXP (XEXP (ad, 0), 1 - op_index);
5169*e4b17023SJohn Marino
5170*e4b17023SJohn Marino if ((regno_ok_for_base_p (REGNO (operand), mode, as, inner_code,
5171*e4b17023SJohn Marino GET_CODE (addend))
5172*e4b17023SJohn Marino || operand == frame_pointer_rtx
5173*e4b17023SJohn Marino #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
5174*e4b17023SJohn Marino || operand == hard_frame_pointer_rtx
5175*e4b17023SJohn Marino #endif
5176*e4b17023SJohn Marino #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
5177*e4b17023SJohn Marino || operand == arg_pointer_rtx
5178*e4b17023SJohn Marino #endif
5179*e4b17023SJohn Marino || operand == stack_pointer_rtx)
5180*e4b17023SJohn Marino && ! maybe_memory_address_addr_space_p
5181*e4b17023SJohn Marino (mode, ad, as, &XEXP (XEXP (ad, 0), 1 - op_index)))
5182*e4b17023SJohn Marino {
5183*e4b17023SJohn Marino rtx offset_reg;
5184*e4b17023SJohn Marino enum reg_class cls;
5185*e4b17023SJohn Marino
5186*e4b17023SJohn Marino offset_reg = plus_constant (operand, INTVAL (XEXP (ad, 1)));
5187*e4b17023SJohn Marino
5188*e4b17023SJohn Marino /* Form the adjusted address. */
5189*e4b17023SJohn Marino if (GET_CODE (XEXP (ad, 0)) == PLUS)
5190*e4b17023SJohn Marino ad = gen_rtx_PLUS (GET_MODE (ad),
5191*e4b17023SJohn Marino op_index == 0 ? offset_reg : addend,
5192*e4b17023SJohn Marino op_index == 0 ? addend : offset_reg);
5193*e4b17023SJohn Marino else
5194*e4b17023SJohn Marino ad = gen_rtx_LO_SUM (GET_MODE (ad),
5195*e4b17023SJohn Marino op_index == 0 ? offset_reg : addend,
5196*e4b17023SJohn Marino op_index == 0 ? addend : offset_reg);
5197*e4b17023SJohn Marino *loc = ad;
5198*e4b17023SJohn Marino
5199*e4b17023SJohn Marino cls = base_reg_class (mode, as, MEM, GET_CODE (addend));
5200*e4b17023SJohn Marino find_reloads_address_part (XEXP (ad, op_index),
5201*e4b17023SJohn Marino &XEXP (ad, op_index), cls,
5202*e4b17023SJohn Marino GET_MODE (ad), opnum, type, ind_levels);
5203*e4b17023SJohn Marino find_reloads_address_1 (mode, as,
5204*e4b17023SJohn Marino XEXP (ad, 1 - op_index), 1, GET_CODE (ad),
5205*e4b17023SJohn Marino GET_CODE (XEXP (ad, op_index)),
5206*e4b17023SJohn Marino &XEXP (ad, 1 - op_index), opnum,
5207*e4b17023SJohn Marino type, 0, insn);
5208*e4b17023SJohn Marino
5209*e4b17023SJohn Marino return 0;
5210*e4b17023SJohn Marino }
5211*e4b17023SJohn Marino }
5212*e4b17023SJohn Marino
5213*e4b17023SJohn Marino /* See if address becomes valid when an eliminable register
5214*e4b17023SJohn Marino in a sum is replaced. */
5215*e4b17023SJohn Marino
5216*e4b17023SJohn Marino tem = ad;
5217*e4b17023SJohn Marino if (GET_CODE (ad) == PLUS)
5218*e4b17023SJohn Marino tem = subst_indexed_address (ad);
5219*e4b17023SJohn Marino if (tem != ad && strict_memory_address_addr_space_p (mode, tem, as))
5220*e4b17023SJohn Marino {
5221*e4b17023SJohn Marino /* Ok, we win that way. Replace any additional eliminable
5222*e4b17023SJohn Marino registers. */
5223*e4b17023SJohn Marino
5224*e4b17023SJohn Marino subst_reg_equivs_changed = 0;
5225*e4b17023SJohn Marino tem = subst_reg_equivs (tem, insn);
5226*e4b17023SJohn Marino
5227*e4b17023SJohn Marino /* Make sure that didn't make the address invalid again. */
5228*e4b17023SJohn Marino
5229*e4b17023SJohn Marino if (! subst_reg_equivs_changed
5230*e4b17023SJohn Marino || strict_memory_address_addr_space_p (mode, tem, as))
5231*e4b17023SJohn Marino {
5232*e4b17023SJohn Marino *loc = tem;
5233*e4b17023SJohn Marino return 0;
5234*e4b17023SJohn Marino }
5235*e4b17023SJohn Marino }
5236*e4b17023SJohn Marino
5237*e4b17023SJohn Marino /* If constants aren't valid addresses, reload the constant address
5238*e4b17023SJohn Marino into a register. */
5239*e4b17023SJohn Marino if (CONSTANT_P (ad) && ! strict_memory_address_addr_space_p (mode, ad, as))
5240*e4b17023SJohn Marino {
5241*e4b17023SJohn Marino enum machine_mode address_mode = GET_MODE (ad);
5242*e4b17023SJohn Marino if (address_mode == VOIDmode)
5243*e4b17023SJohn Marino address_mode = targetm.addr_space.address_mode (as);
5244*e4b17023SJohn Marino
5245*e4b17023SJohn Marino /* If AD is an address in the constant pool, the MEM rtx may be shared.
5246*e4b17023SJohn Marino Unshare it so we can safely alter it. */
5247*e4b17023SJohn Marino if (memrefloc && GET_CODE (ad) == SYMBOL_REF
5248*e4b17023SJohn Marino && CONSTANT_POOL_ADDRESS_P (ad))
5249*e4b17023SJohn Marino {
5250*e4b17023SJohn Marino *memrefloc = copy_rtx (*memrefloc);
5251*e4b17023SJohn Marino loc = &XEXP (*memrefloc, 0);
5252*e4b17023SJohn Marino if (removed_and)
5253*e4b17023SJohn Marino loc = &XEXP (*loc, 0);
5254*e4b17023SJohn Marino }
5255*e4b17023SJohn Marino
5256*e4b17023SJohn Marino find_reloads_address_part (ad, loc,
5257*e4b17023SJohn Marino base_reg_class (mode, as, MEM, SCRATCH),
5258*e4b17023SJohn Marino address_mode, opnum, type, ind_levels);
5259*e4b17023SJohn Marino return ! removed_and;
5260*e4b17023SJohn Marino }
5261*e4b17023SJohn Marino
5262*e4b17023SJohn Marino return find_reloads_address_1 (mode, as, ad, 0, MEM, SCRATCH, loc,
5263*e4b17023SJohn Marino opnum, type, ind_levels, insn);
5264*e4b17023SJohn Marino }
5265*e4b17023SJohn Marino
5266*e4b17023SJohn Marino /* Find all pseudo regs appearing in AD
5267*e4b17023SJohn Marino that are eliminable in favor of equivalent values
5268*e4b17023SJohn Marino and do not have hard regs; replace them by their equivalents.
5269*e4b17023SJohn Marino INSN, if nonzero, is the insn in which we do the reload. We put USEs in
5270*e4b17023SJohn Marino front of it for pseudos that we have to replace with stack slots. */
5271*e4b17023SJohn Marino
5272*e4b17023SJohn Marino static rtx
subst_reg_equivs(rtx ad,rtx insn)5273*e4b17023SJohn Marino subst_reg_equivs (rtx ad, rtx insn)
5274*e4b17023SJohn Marino {
5275*e4b17023SJohn Marino RTX_CODE code = GET_CODE (ad);
5276*e4b17023SJohn Marino int i;
5277*e4b17023SJohn Marino const char *fmt;
5278*e4b17023SJohn Marino
5279*e4b17023SJohn Marino switch (code)
5280*e4b17023SJohn Marino {
5281*e4b17023SJohn Marino case HIGH:
5282*e4b17023SJohn Marino case CONST_INT:
5283*e4b17023SJohn Marino case CONST:
5284*e4b17023SJohn Marino case CONST_DOUBLE:
5285*e4b17023SJohn Marino case CONST_FIXED:
5286*e4b17023SJohn Marino case CONST_VECTOR:
5287*e4b17023SJohn Marino case SYMBOL_REF:
5288*e4b17023SJohn Marino case LABEL_REF:
5289*e4b17023SJohn Marino case PC:
5290*e4b17023SJohn Marino case CC0:
5291*e4b17023SJohn Marino return ad;
5292*e4b17023SJohn Marino
5293*e4b17023SJohn Marino case REG:
5294*e4b17023SJohn Marino {
5295*e4b17023SJohn Marino int regno = REGNO (ad);
5296*e4b17023SJohn Marino
5297*e4b17023SJohn Marino if (reg_equiv_constant (regno) != 0)
5298*e4b17023SJohn Marino {
5299*e4b17023SJohn Marino subst_reg_equivs_changed = 1;
5300*e4b17023SJohn Marino return reg_equiv_constant (regno);
5301*e4b17023SJohn Marino }
5302*e4b17023SJohn Marino if (reg_equiv_memory_loc (regno) && num_not_at_initial_offset)
5303*e4b17023SJohn Marino {
5304*e4b17023SJohn Marino rtx mem = make_memloc (ad, regno);
5305*e4b17023SJohn Marino if (! rtx_equal_p (mem, reg_equiv_mem (regno)))
5306*e4b17023SJohn Marino {
5307*e4b17023SJohn Marino subst_reg_equivs_changed = 1;
5308*e4b17023SJohn Marino /* We mark the USE with QImode so that we recognize it
5309*e4b17023SJohn Marino as one that can be safely deleted at the end of
5310*e4b17023SJohn Marino reload. */
5311*e4b17023SJohn Marino PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad), insn),
5312*e4b17023SJohn Marino QImode);
5313*e4b17023SJohn Marino return mem;
5314*e4b17023SJohn Marino }
5315*e4b17023SJohn Marino }
5316*e4b17023SJohn Marino }
5317*e4b17023SJohn Marino return ad;
5318*e4b17023SJohn Marino
5319*e4b17023SJohn Marino case PLUS:
5320*e4b17023SJohn Marino /* Quickly dispose of a common case. */
5321*e4b17023SJohn Marino if (XEXP (ad, 0) == frame_pointer_rtx
5322*e4b17023SJohn Marino && CONST_INT_P (XEXP (ad, 1)))
5323*e4b17023SJohn Marino return ad;
5324*e4b17023SJohn Marino break;
5325*e4b17023SJohn Marino
5326*e4b17023SJohn Marino default:
5327*e4b17023SJohn Marino break;
5328*e4b17023SJohn Marino }
5329*e4b17023SJohn Marino
5330*e4b17023SJohn Marino fmt = GET_RTX_FORMAT (code);
5331*e4b17023SJohn Marino for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5332*e4b17023SJohn Marino if (fmt[i] == 'e')
5333*e4b17023SJohn Marino XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i), insn);
5334*e4b17023SJohn Marino return ad;
5335*e4b17023SJohn Marino }
5336*e4b17023SJohn Marino
5337*e4b17023SJohn Marino /* Compute the sum of X and Y, making canonicalizations assumed in an
5338*e4b17023SJohn Marino address, namely: sum constant integers, surround the sum of two
5339*e4b17023SJohn Marino constants with a CONST, put the constant as the second operand, and
5340*e4b17023SJohn Marino group the constant on the outermost sum.
5341*e4b17023SJohn Marino
5342*e4b17023SJohn Marino This routine assumes both inputs are already in canonical form. */
5343*e4b17023SJohn Marino
5344*e4b17023SJohn Marino rtx
form_sum(enum machine_mode mode,rtx x,rtx y)5345*e4b17023SJohn Marino form_sum (enum machine_mode mode, rtx x, rtx y)
5346*e4b17023SJohn Marino {
5347*e4b17023SJohn Marino rtx tem;
5348*e4b17023SJohn Marino
5349*e4b17023SJohn Marino gcc_assert (GET_MODE (x) == mode || GET_MODE (x) == VOIDmode);
5350*e4b17023SJohn Marino gcc_assert (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode);
5351*e4b17023SJohn Marino
5352*e4b17023SJohn Marino if (CONST_INT_P (x))
5353*e4b17023SJohn Marino return plus_constant (y, INTVAL (x));
5354*e4b17023SJohn Marino else if (CONST_INT_P (y))
5355*e4b17023SJohn Marino return plus_constant (x, INTVAL (y));
5356*e4b17023SJohn Marino else if (CONSTANT_P (x))
5357*e4b17023SJohn Marino tem = x, x = y, y = tem;
5358*e4b17023SJohn Marino
5359*e4b17023SJohn Marino if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
5360*e4b17023SJohn Marino return form_sum (mode, XEXP (x, 0), form_sum (mode, XEXP (x, 1), y));
5361*e4b17023SJohn Marino
5362*e4b17023SJohn Marino /* Note that if the operands of Y are specified in the opposite
5363*e4b17023SJohn Marino order in the recursive calls below, infinite recursion will occur. */
5364*e4b17023SJohn Marino if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
5365*e4b17023SJohn Marino return form_sum (mode, form_sum (mode, x, XEXP (y, 0)), XEXP (y, 1));
5366*e4b17023SJohn Marino
5367*e4b17023SJohn Marino /* If both constant, encapsulate sum. Otherwise, just form sum. A
5368*e4b17023SJohn Marino constant will have been placed second. */
5369*e4b17023SJohn Marino if (CONSTANT_P (x) && CONSTANT_P (y))
5370*e4b17023SJohn Marino {
5371*e4b17023SJohn Marino if (GET_CODE (x) == CONST)
5372*e4b17023SJohn Marino x = XEXP (x, 0);
5373*e4b17023SJohn Marino if (GET_CODE (y) == CONST)
5374*e4b17023SJohn Marino y = XEXP (y, 0);
5375*e4b17023SJohn Marino
5376*e4b17023SJohn Marino return gen_rtx_CONST (VOIDmode, gen_rtx_PLUS (mode, x, y));
5377*e4b17023SJohn Marino }
5378*e4b17023SJohn Marino
5379*e4b17023SJohn Marino return gen_rtx_PLUS (mode, x, y);
5380*e4b17023SJohn Marino }
5381*e4b17023SJohn Marino
5382*e4b17023SJohn Marino /* If ADDR is a sum containing a pseudo register that should be
5383*e4b17023SJohn Marino replaced with a constant (from reg_equiv_constant),
5384*e4b17023SJohn Marino return the result of doing so, and also apply the associative
5385*e4b17023SJohn Marino law so that the result is more likely to be a valid address.
5386*e4b17023SJohn Marino (But it is not guaranteed to be one.)
5387*e4b17023SJohn Marino
5388*e4b17023SJohn Marino Note that at most one register is replaced, even if more are
5389*e4b17023SJohn Marino replaceable. Also, we try to put the result into a canonical form
5390*e4b17023SJohn Marino so it is more likely to be a valid address.
5391*e4b17023SJohn Marino
5392*e4b17023SJohn Marino In all other cases, return ADDR. */
5393*e4b17023SJohn Marino
5394*e4b17023SJohn Marino static rtx
subst_indexed_address(rtx addr)5395*e4b17023SJohn Marino subst_indexed_address (rtx addr)
5396*e4b17023SJohn Marino {
5397*e4b17023SJohn Marino rtx op0 = 0, op1 = 0, op2 = 0;
5398*e4b17023SJohn Marino rtx tem;
5399*e4b17023SJohn Marino int regno;
5400*e4b17023SJohn Marino
5401*e4b17023SJohn Marino if (GET_CODE (addr) == PLUS)
5402*e4b17023SJohn Marino {
5403*e4b17023SJohn Marino /* Try to find a register to replace. */
5404*e4b17023SJohn Marino op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
5405*e4b17023SJohn Marino if (REG_P (op0)
5406*e4b17023SJohn Marino && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
5407*e4b17023SJohn Marino && reg_renumber[regno] < 0
5408*e4b17023SJohn Marino && reg_equiv_constant (regno) != 0)
5409*e4b17023SJohn Marino op0 = reg_equiv_constant (regno);
5410*e4b17023SJohn Marino else if (REG_P (op1)
5411*e4b17023SJohn Marino && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
5412*e4b17023SJohn Marino && reg_renumber[regno] < 0
5413*e4b17023SJohn Marino && reg_equiv_constant (regno) != 0)
5414*e4b17023SJohn Marino op1 = reg_equiv_constant (regno);
5415*e4b17023SJohn Marino else if (GET_CODE (op0) == PLUS
5416*e4b17023SJohn Marino && (tem = subst_indexed_address (op0)) != op0)
5417*e4b17023SJohn Marino op0 = tem;
5418*e4b17023SJohn Marino else if (GET_CODE (op1) == PLUS
5419*e4b17023SJohn Marino && (tem = subst_indexed_address (op1)) != op1)
5420*e4b17023SJohn Marino op1 = tem;
5421*e4b17023SJohn Marino else
5422*e4b17023SJohn Marino return addr;
5423*e4b17023SJohn Marino
5424*e4b17023SJohn Marino /* Pick out up to three things to add. */
5425*e4b17023SJohn Marino if (GET_CODE (op1) == PLUS)
5426*e4b17023SJohn Marino op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
5427*e4b17023SJohn Marino else if (GET_CODE (op0) == PLUS)
5428*e4b17023SJohn Marino op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
5429*e4b17023SJohn Marino
5430*e4b17023SJohn Marino /* Compute the sum. */
5431*e4b17023SJohn Marino if (op2 != 0)
5432*e4b17023SJohn Marino op1 = form_sum (GET_MODE (addr), op1, op2);
5433*e4b17023SJohn Marino if (op1 != 0)
5434*e4b17023SJohn Marino op0 = form_sum (GET_MODE (addr), op0, op1);
5435*e4b17023SJohn Marino
5436*e4b17023SJohn Marino return op0;
5437*e4b17023SJohn Marino }
5438*e4b17023SJohn Marino return addr;
5439*e4b17023SJohn Marino }
5440*e4b17023SJohn Marino
5441*e4b17023SJohn Marino /* Update the REG_INC notes for an insn. It updates all REG_INC
5442*e4b17023SJohn Marino notes for the instruction which refer to REGNO the to refer
5443*e4b17023SJohn Marino to the reload number.
5444*e4b17023SJohn Marino
5445*e4b17023SJohn Marino INSN is the insn for which any REG_INC notes need updating.
5446*e4b17023SJohn Marino
5447*e4b17023SJohn Marino REGNO is the register number which has been reloaded.
5448*e4b17023SJohn Marino
5449*e4b17023SJohn Marino RELOADNUM is the reload number. */
5450*e4b17023SJohn Marino
5451*e4b17023SJohn Marino static void
update_auto_inc_notes(rtx insn ATTRIBUTE_UNUSED,int regno ATTRIBUTE_UNUSED,int reloadnum ATTRIBUTE_UNUSED)5452*e4b17023SJohn Marino update_auto_inc_notes (rtx insn ATTRIBUTE_UNUSED, int regno ATTRIBUTE_UNUSED,
5453*e4b17023SJohn Marino int reloadnum ATTRIBUTE_UNUSED)
5454*e4b17023SJohn Marino {
5455*e4b17023SJohn Marino #ifdef AUTO_INC_DEC
5456*e4b17023SJohn Marino rtx link;
5457*e4b17023SJohn Marino
5458*e4b17023SJohn Marino for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
5459*e4b17023SJohn Marino if (REG_NOTE_KIND (link) == REG_INC
5460*e4b17023SJohn Marino && (int) REGNO (XEXP (link, 0)) == regno)
5461*e4b17023SJohn Marino push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5462*e4b17023SJohn Marino #endif
5463*e4b17023SJohn Marino }
5464*e4b17023SJohn Marino
5465*e4b17023SJohn Marino /* Record the pseudo registers we must reload into hard registers in a
5466*e4b17023SJohn Marino subexpression of a would-be memory address, X referring to a value
5467*e4b17023SJohn Marino in mode MODE. (This function is not called if the address we find
5468*e4b17023SJohn Marino is strictly valid.)
5469*e4b17023SJohn Marino
5470*e4b17023SJohn Marino CONTEXT = 1 means we are considering regs as index regs,
5471*e4b17023SJohn Marino = 0 means we are considering them as base regs.
5472*e4b17023SJohn Marino OUTER_CODE is the code of the enclosing RTX, typically a MEM, a PLUS,
5473*e4b17023SJohn Marino or an autoinc code.
5474*e4b17023SJohn Marino If CONTEXT == 0 and OUTER_CODE is a PLUS or LO_SUM, then INDEX_CODE
5475*e4b17023SJohn Marino is the code of the index part of the address. Otherwise, pass SCRATCH
5476*e4b17023SJohn Marino for this argument.
5477*e4b17023SJohn Marino OPNUM and TYPE specify the purpose of any reloads made.
5478*e4b17023SJohn Marino
5479*e4b17023SJohn Marino IND_LEVELS says how many levels of indirect addressing are
5480*e4b17023SJohn Marino supported at this point in the address.
5481*e4b17023SJohn Marino
5482*e4b17023SJohn Marino INSN, if nonzero, is the insn in which we do the reload. It is used
5483*e4b17023SJohn Marino to determine if we may generate output reloads.
5484*e4b17023SJohn Marino
5485*e4b17023SJohn Marino We return nonzero if X, as a whole, is reloaded or replaced. */
5486*e4b17023SJohn Marino
5487*e4b17023SJohn Marino /* Note that we take shortcuts assuming that no multi-reg machine mode
5488*e4b17023SJohn Marino occurs as part of an address.
5489*e4b17023SJohn Marino Also, this is not fully machine-customizable; it works for machines
5490*e4b17023SJohn Marino such as VAXen and 68000's and 32000's, but other possible machines
5491*e4b17023SJohn Marino could have addressing modes that this does not handle right.
5492*e4b17023SJohn Marino If you add push_reload calls here, you need to make sure gen_reload
5493*e4b17023SJohn Marino handles those cases gracefully. */
5494*e4b17023SJohn Marino
5495*e4b17023SJohn Marino static int
find_reloads_address_1(enum machine_mode mode,addr_space_t as,rtx x,int context,enum rtx_code outer_code,enum rtx_code index_code,rtx * loc,int opnum,enum reload_type type,int ind_levels,rtx insn)5496*e4b17023SJohn Marino find_reloads_address_1 (enum machine_mode mode, addr_space_t as,
5497*e4b17023SJohn Marino rtx x, int context,
5498*e4b17023SJohn Marino enum rtx_code outer_code, enum rtx_code index_code,
5499*e4b17023SJohn Marino rtx *loc, int opnum, enum reload_type type,
5500*e4b17023SJohn Marino int ind_levels, rtx insn)
5501*e4b17023SJohn Marino {
5502*e4b17023SJohn Marino #define REG_OK_FOR_CONTEXT(CONTEXT, REGNO, MODE, AS, OUTER, INDEX) \
5503*e4b17023SJohn Marino ((CONTEXT) == 0 \
5504*e4b17023SJohn Marino ? regno_ok_for_base_p (REGNO, MODE, AS, OUTER, INDEX) \
5505*e4b17023SJohn Marino : REGNO_OK_FOR_INDEX_P (REGNO))
5506*e4b17023SJohn Marino
5507*e4b17023SJohn Marino enum reg_class context_reg_class;
5508*e4b17023SJohn Marino RTX_CODE code = GET_CODE (x);
5509*e4b17023SJohn Marino
5510*e4b17023SJohn Marino if (context == 1)
5511*e4b17023SJohn Marino context_reg_class = INDEX_REG_CLASS;
5512*e4b17023SJohn Marino else
5513*e4b17023SJohn Marino context_reg_class = base_reg_class (mode, as, outer_code, index_code);
5514*e4b17023SJohn Marino
5515*e4b17023SJohn Marino switch (code)
5516*e4b17023SJohn Marino {
5517*e4b17023SJohn Marino case PLUS:
5518*e4b17023SJohn Marino {
5519*e4b17023SJohn Marino rtx orig_op0 = XEXP (x, 0);
5520*e4b17023SJohn Marino rtx orig_op1 = XEXP (x, 1);
5521*e4b17023SJohn Marino RTX_CODE code0 = GET_CODE (orig_op0);
5522*e4b17023SJohn Marino RTX_CODE code1 = GET_CODE (orig_op1);
5523*e4b17023SJohn Marino rtx op0 = orig_op0;
5524*e4b17023SJohn Marino rtx op1 = orig_op1;
5525*e4b17023SJohn Marino
5526*e4b17023SJohn Marino if (GET_CODE (op0) == SUBREG)
5527*e4b17023SJohn Marino {
5528*e4b17023SJohn Marino op0 = SUBREG_REG (op0);
5529*e4b17023SJohn Marino code0 = GET_CODE (op0);
5530*e4b17023SJohn Marino if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER)
5531*e4b17023SJohn Marino op0 = gen_rtx_REG (word_mode,
5532*e4b17023SJohn Marino (REGNO (op0) +
5533*e4b17023SJohn Marino subreg_regno_offset (REGNO (SUBREG_REG (orig_op0)),
5534*e4b17023SJohn Marino GET_MODE (SUBREG_REG (orig_op0)),
5535*e4b17023SJohn Marino SUBREG_BYTE (orig_op0),
5536*e4b17023SJohn Marino GET_MODE (orig_op0))));
5537*e4b17023SJohn Marino }
5538*e4b17023SJohn Marino
5539*e4b17023SJohn Marino if (GET_CODE (op1) == SUBREG)
5540*e4b17023SJohn Marino {
5541*e4b17023SJohn Marino op1 = SUBREG_REG (op1);
5542*e4b17023SJohn Marino code1 = GET_CODE (op1);
5543*e4b17023SJohn Marino if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER)
5544*e4b17023SJohn Marino /* ??? Why is this given op1's mode and above for
5545*e4b17023SJohn Marino ??? op0 SUBREGs we use word_mode? */
5546*e4b17023SJohn Marino op1 = gen_rtx_REG (GET_MODE (op1),
5547*e4b17023SJohn Marino (REGNO (op1) +
5548*e4b17023SJohn Marino subreg_regno_offset (REGNO (SUBREG_REG (orig_op1)),
5549*e4b17023SJohn Marino GET_MODE (SUBREG_REG (orig_op1)),
5550*e4b17023SJohn Marino SUBREG_BYTE (orig_op1),
5551*e4b17023SJohn Marino GET_MODE (orig_op1))));
5552*e4b17023SJohn Marino }
5553*e4b17023SJohn Marino /* Plus in the index register may be created only as a result of
5554*e4b17023SJohn Marino register rematerialization for expression like &localvar*4. Reload it.
5555*e4b17023SJohn Marino It may be possible to combine the displacement on the outer level,
5556*e4b17023SJohn Marino but it is probably not worthwhile to do so. */
5557*e4b17023SJohn Marino if (context == 1)
5558*e4b17023SJohn Marino {
5559*e4b17023SJohn Marino find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5560*e4b17023SJohn Marino opnum, ADDR_TYPE (type), ind_levels, insn);
5561*e4b17023SJohn Marino push_reload (*loc, NULL_RTX, loc, (rtx*) 0,
5562*e4b17023SJohn Marino context_reg_class,
5563*e4b17023SJohn Marino GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5564*e4b17023SJohn Marino return 1;
5565*e4b17023SJohn Marino }
5566*e4b17023SJohn Marino
5567*e4b17023SJohn Marino if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
5568*e4b17023SJohn Marino || code0 == ZERO_EXTEND || code1 == MEM)
5569*e4b17023SJohn Marino {
5570*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op0, 1, PLUS, SCRATCH,
5571*e4b17023SJohn Marino &XEXP (x, 0), opnum, type, ind_levels,
5572*e4b17023SJohn Marino insn);
5573*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op1, 0, PLUS, code0,
5574*e4b17023SJohn Marino &XEXP (x, 1), opnum, type, ind_levels,
5575*e4b17023SJohn Marino insn);
5576*e4b17023SJohn Marino }
5577*e4b17023SJohn Marino
5578*e4b17023SJohn Marino else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
5579*e4b17023SJohn Marino || code1 == ZERO_EXTEND || code0 == MEM)
5580*e4b17023SJohn Marino {
5581*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op0, 0, PLUS, code1,
5582*e4b17023SJohn Marino &XEXP (x, 0), opnum, type, ind_levels,
5583*e4b17023SJohn Marino insn);
5584*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op1, 1, PLUS, SCRATCH,
5585*e4b17023SJohn Marino &XEXP (x, 1), opnum, type, ind_levels,
5586*e4b17023SJohn Marino insn);
5587*e4b17023SJohn Marino }
5588*e4b17023SJohn Marino
5589*e4b17023SJohn Marino else if (code0 == CONST_INT || code0 == CONST
5590*e4b17023SJohn Marino || code0 == SYMBOL_REF || code0 == LABEL_REF)
5591*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op1, 0, PLUS, code0,
5592*e4b17023SJohn Marino &XEXP (x, 1), opnum, type, ind_levels,
5593*e4b17023SJohn Marino insn);
5594*e4b17023SJohn Marino
5595*e4b17023SJohn Marino else if (code1 == CONST_INT || code1 == CONST
5596*e4b17023SJohn Marino || code1 == SYMBOL_REF || code1 == LABEL_REF)
5597*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op0, 0, PLUS, code1,
5598*e4b17023SJohn Marino &XEXP (x, 0), opnum, type, ind_levels,
5599*e4b17023SJohn Marino insn);
5600*e4b17023SJohn Marino
5601*e4b17023SJohn Marino else if (code0 == REG && code1 == REG)
5602*e4b17023SJohn Marino {
5603*e4b17023SJohn Marino if (REGNO_OK_FOR_INDEX_P (REGNO (op1))
5604*e4b17023SJohn Marino && regno_ok_for_base_p (REGNO (op0), mode, as, PLUS, REG))
5605*e4b17023SJohn Marino return 0;
5606*e4b17023SJohn Marino else if (REGNO_OK_FOR_INDEX_P (REGNO (op0))
5607*e4b17023SJohn Marino && regno_ok_for_base_p (REGNO (op1), mode, as, PLUS, REG))
5608*e4b17023SJohn Marino return 0;
5609*e4b17023SJohn Marino else if (regno_ok_for_base_p (REGNO (op0), mode, as, PLUS, REG))
5610*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op1, 1, PLUS, SCRATCH,
5611*e4b17023SJohn Marino &XEXP (x, 1), opnum, type, ind_levels,
5612*e4b17023SJohn Marino insn);
5613*e4b17023SJohn Marino else if (REGNO_OK_FOR_INDEX_P (REGNO (op1)))
5614*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op0, 0, PLUS, REG,
5615*e4b17023SJohn Marino &XEXP (x, 0), opnum, type, ind_levels,
5616*e4b17023SJohn Marino insn);
5617*e4b17023SJohn Marino else if (regno_ok_for_base_p (REGNO (op1), mode, as, PLUS, REG))
5618*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op0, 1, PLUS, SCRATCH,
5619*e4b17023SJohn Marino &XEXP (x, 0), opnum, type, ind_levels,
5620*e4b17023SJohn Marino insn);
5621*e4b17023SJohn Marino else if (REGNO_OK_FOR_INDEX_P (REGNO (op0)))
5622*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op1, 0, PLUS, REG,
5623*e4b17023SJohn Marino &XEXP (x, 1), opnum, type, ind_levels,
5624*e4b17023SJohn Marino insn);
5625*e4b17023SJohn Marino else
5626*e4b17023SJohn Marino {
5627*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op0, 0, PLUS, REG,
5628*e4b17023SJohn Marino &XEXP (x, 0), opnum, type, ind_levels,
5629*e4b17023SJohn Marino insn);
5630*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op1, 1, PLUS, SCRATCH,
5631*e4b17023SJohn Marino &XEXP (x, 1), opnum, type, ind_levels,
5632*e4b17023SJohn Marino insn);
5633*e4b17023SJohn Marino }
5634*e4b17023SJohn Marino }
5635*e4b17023SJohn Marino
5636*e4b17023SJohn Marino else if (code0 == REG)
5637*e4b17023SJohn Marino {
5638*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op0, 1, PLUS, SCRATCH,
5639*e4b17023SJohn Marino &XEXP (x, 0), opnum, type, ind_levels,
5640*e4b17023SJohn Marino insn);
5641*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op1, 0, PLUS, REG,
5642*e4b17023SJohn Marino &XEXP (x, 1), opnum, type, ind_levels,
5643*e4b17023SJohn Marino insn);
5644*e4b17023SJohn Marino }
5645*e4b17023SJohn Marino
5646*e4b17023SJohn Marino else if (code1 == REG)
5647*e4b17023SJohn Marino {
5648*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op1, 1, PLUS, SCRATCH,
5649*e4b17023SJohn Marino &XEXP (x, 1), opnum, type, ind_levels,
5650*e4b17023SJohn Marino insn);
5651*e4b17023SJohn Marino find_reloads_address_1 (mode, as, orig_op0, 0, PLUS, REG,
5652*e4b17023SJohn Marino &XEXP (x, 0), opnum, type, ind_levels,
5653*e4b17023SJohn Marino insn);
5654*e4b17023SJohn Marino }
5655*e4b17023SJohn Marino }
5656*e4b17023SJohn Marino
5657*e4b17023SJohn Marino return 0;
5658*e4b17023SJohn Marino
5659*e4b17023SJohn Marino case POST_MODIFY:
5660*e4b17023SJohn Marino case PRE_MODIFY:
5661*e4b17023SJohn Marino {
5662*e4b17023SJohn Marino rtx op0 = XEXP (x, 0);
5663*e4b17023SJohn Marino rtx op1 = XEXP (x, 1);
5664*e4b17023SJohn Marino enum rtx_code index_code;
5665*e4b17023SJohn Marino int regno;
5666*e4b17023SJohn Marino int reloadnum;
5667*e4b17023SJohn Marino
5668*e4b17023SJohn Marino if (GET_CODE (op1) != PLUS && GET_CODE (op1) != MINUS)
5669*e4b17023SJohn Marino return 0;
5670*e4b17023SJohn Marino
5671*e4b17023SJohn Marino /* Currently, we only support {PRE,POST}_MODIFY constructs
5672*e4b17023SJohn Marino where a base register is {inc,dec}remented by the contents
5673*e4b17023SJohn Marino of another register or by a constant value. Thus, these
5674*e4b17023SJohn Marino operands must match. */
5675*e4b17023SJohn Marino gcc_assert (op0 == XEXP (op1, 0));
5676*e4b17023SJohn Marino
5677*e4b17023SJohn Marino /* Require index register (or constant). Let's just handle the
5678*e4b17023SJohn Marino register case in the meantime... If the target allows
5679*e4b17023SJohn Marino auto-modify by a constant then we could try replacing a pseudo
5680*e4b17023SJohn Marino register with its equivalent constant where applicable.
5681*e4b17023SJohn Marino
5682*e4b17023SJohn Marino We also handle the case where the register was eliminated
5683*e4b17023SJohn Marino resulting in a PLUS subexpression.
5684*e4b17023SJohn Marino
5685*e4b17023SJohn Marino If we later decide to reload the whole PRE_MODIFY or
5686*e4b17023SJohn Marino POST_MODIFY, inc_for_reload might clobber the reload register
5687*e4b17023SJohn Marino before reading the index. The index register might therefore
5688*e4b17023SJohn Marino need to live longer than a TYPE reload normally would, so be
5689*e4b17023SJohn Marino conservative and class it as RELOAD_OTHER. */
5690*e4b17023SJohn Marino if ((REG_P (XEXP (op1, 1))
5691*e4b17023SJohn Marino && !REGNO_OK_FOR_INDEX_P (REGNO (XEXP (op1, 1))))
5692*e4b17023SJohn Marino || GET_CODE (XEXP (op1, 1)) == PLUS)
5693*e4b17023SJohn Marino find_reloads_address_1 (mode, as, XEXP (op1, 1), 1, code, SCRATCH,
5694*e4b17023SJohn Marino &XEXP (op1, 1), opnum, RELOAD_OTHER,
5695*e4b17023SJohn Marino ind_levels, insn);
5696*e4b17023SJohn Marino
5697*e4b17023SJohn Marino gcc_assert (REG_P (XEXP (op1, 0)));
5698*e4b17023SJohn Marino
5699*e4b17023SJohn Marino regno = REGNO (XEXP (op1, 0));
5700*e4b17023SJohn Marino index_code = GET_CODE (XEXP (op1, 1));
5701*e4b17023SJohn Marino
5702*e4b17023SJohn Marino /* A register that is incremented cannot be constant! */
5703*e4b17023SJohn Marino gcc_assert (regno < FIRST_PSEUDO_REGISTER
5704*e4b17023SJohn Marino || reg_equiv_constant (regno) == 0);
5705*e4b17023SJohn Marino
5706*e4b17023SJohn Marino /* Handle a register that is equivalent to a memory location
5707*e4b17023SJohn Marino which cannot be addressed directly. */
5708*e4b17023SJohn Marino if (reg_equiv_memory_loc (regno) != 0
5709*e4b17023SJohn Marino && (reg_equiv_address (regno) != 0
5710*e4b17023SJohn Marino || num_not_at_initial_offset))
5711*e4b17023SJohn Marino {
5712*e4b17023SJohn Marino rtx tem = make_memloc (XEXP (x, 0), regno);
5713*e4b17023SJohn Marino
5714*e4b17023SJohn Marino if (reg_equiv_address (regno)
5715*e4b17023SJohn Marino || ! rtx_equal_p (tem, reg_equiv_mem (regno)))
5716*e4b17023SJohn Marino {
5717*e4b17023SJohn Marino rtx orig = tem;
5718*e4b17023SJohn Marino
5719*e4b17023SJohn Marino /* First reload the memory location's address.
5720*e4b17023SJohn Marino We can't use ADDR_TYPE (type) here, because we need to
5721*e4b17023SJohn Marino write back the value after reading it, hence we actually
5722*e4b17023SJohn Marino need two registers. */
5723*e4b17023SJohn Marino find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5724*e4b17023SJohn Marino &XEXP (tem, 0), opnum,
5725*e4b17023SJohn Marino RELOAD_OTHER,
5726*e4b17023SJohn Marino ind_levels, insn);
5727*e4b17023SJohn Marino
5728*e4b17023SJohn Marino if (!rtx_equal_p (tem, orig))
5729*e4b17023SJohn Marino push_reg_equiv_alt_mem (regno, tem);
5730*e4b17023SJohn Marino
5731*e4b17023SJohn Marino /* Then reload the memory location into a base
5732*e4b17023SJohn Marino register. */
5733*e4b17023SJohn Marino reloadnum = push_reload (tem, tem, &XEXP (x, 0),
5734*e4b17023SJohn Marino &XEXP (op1, 0),
5735*e4b17023SJohn Marino base_reg_class (mode, as,
5736*e4b17023SJohn Marino code, index_code),
5737*e4b17023SJohn Marino GET_MODE (x), GET_MODE (x), 0,
5738*e4b17023SJohn Marino 0, opnum, RELOAD_OTHER);
5739*e4b17023SJohn Marino
5740*e4b17023SJohn Marino update_auto_inc_notes (this_insn, regno, reloadnum);
5741*e4b17023SJohn Marino return 0;
5742*e4b17023SJohn Marino }
5743*e4b17023SJohn Marino }
5744*e4b17023SJohn Marino
5745*e4b17023SJohn Marino if (reg_renumber[regno] >= 0)
5746*e4b17023SJohn Marino regno = reg_renumber[regno];
5747*e4b17023SJohn Marino
5748*e4b17023SJohn Marino /* We require a base register here... */
5749*e4b17023SJohn Marino if (!regno_ok_for_base_p (regno, GET_MODE (x), as, code, index_code))
5750*e4b17023SJohn Marino {
5751*e4b17023SJohn Marino reloadnum = push_reload (XEXP (op1, 0), XEXP (x, 0),
5752*e4b17023SJohn Marino &XEXP (op1, 0), &XEXP (x, 0),
5753*e4b17023SJohn Marino base_reg_class (mode, as,
5754*e4b17023SJohn Marino code, index_code),
5755*e4b17023SJohn Marino GET_MODE (x), GET_MODE (x), 0, 0,
5756*e4b17023SJohn Marino opnum, RELOAD_OTHER);
5757*e4b17023SJohn Marino
5758*e4b17023SJohn Marino update_auto_inc_notes (this_insn, regno, reloadnum);
5759*e4b17023SJohn Marino return 0;
5760*e4b17023SJohn Marino }
5761*e4b17023SJohn Marino }
5762*e4b17023SJohn Marino return 0;
5763*e4b17023SJohn Marino
5764*e4b17023SJohn Marino case POST_INC:
5765*e4b17023SJohn Marino case POST_DEC:
5766*e4b17023SJohn Marino case PRE_INC:
5767*e4b17023SJohn Marino case PRE_DEC:
5768*e4b17023SJohn Marino if (REG_P (XEXP (x, 0)))
5769*e4b17023SJohn Marino {
5770*e4b17023SJohn Marino int regno = REGNO (XEXP (x, 0));
5771*e4b17023SJohn Marino int value = 0;
5772*e4b17023SJohn Marino rtx x_orig = x;
5773*e4b17023SJohn Marino
5774*e4b17023SJohn Marino /* A register that is incremented cannot be constant! */
5775*e4b17023SJohn Marino gcc_assert (regno < FIRST_PSEUDO_REGISTER
5776*e4b17023SJohn Marino || reg_equiv_constant (regno) == 0);
5777*e4b17023SJohn Marino
5778*e4b17023SJohn Marino /* Handle a register that is equivalent to a memory location
5779*e4b17023SJohn Marino which cannot be addressed directly. */
5780*e4b17023SJohn Marino if (reg_equiv_memory_loc (regno) != 0
5781*e4b17023SJohn Marino && (reg_equiv_address (regno) != 0 || num_not_at_initial_offset))
5782*e4b17023SJohn Marino {
5783*e4b17023SJohn Marino rtx tem = make_memloc (XEXP (x, 0), regno);
5784*e4b17023SJohn Marino if (reg_equiv_address (regno)
5785*e4b17023SJohn Marino || ! rtx_equal_p (tem, reg_equiv_mem (regno)))
5786*e4b17023SJohn Marino {
5787*e4b17023SJohn Marino rtx orig = tem;
5788*e4b17023SJohn Marino
5789*e4b17023SJohn Marino /* First reload the memory location's address.
5790*e4b17023SJohn Marino We can't use ADDR_TYPE (type) here, because we need to
5791*e4b17023SJohn Marino write back the value after reading it, hence we actually
5792*e4b17023SJohn Marino need two registers. */
5793*e4b17023SJohn Marino find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5794*e4b17023SJohn Marino &XEXP (tem, 0), opnum, type,
5795*e4b17023SJohn Marino ind_levels, insn);
5796*e4b17023SJohn Marino if (!rtx_equal_p (tem, orig))
5797*e4b17023SJohn Marino push_reg_equiv_alt_mem (regno, tem);
5798*e4b17023SJohn Marino /* Put this inside a new increment-expression. */
5799*e4b17023SJohn Marino x = gen_rtx_fmt_e (GET_CODE (x), GET_MODE (x), tem);
5800*e4b17023SJohn Marino /* Proceed to reload that, as if it contained a register. */
5801*e4b17023SJohn Marino }
5802*e4b17023SJohn Marino }
5803*e4b17023SJohn Marino
5804*e4b17023SJohn Marino /* If we have a hard register that is ok in this incdec context,
5805*e4b17023SJohn Marino don't make a reload. If the register isn't nice enough for
5806*e4b17023SJohn Marino autoincdec, we can reload it. But, if an autoincrement of a
5807*e4b17023SJohn Marino register that we here verified as playing nice, still outside
5808*e4b17023SJohn Marino isn't "valid", it must be that no autoincrement is "valid".
5809*e4b17023SJohn Marino If that is true and something made an autoincrement anyway,
5810*e4b17023SJohn Marino this must be a special context where one is allowed.
5811*e4b17023SJohn Marino (For example, a "push" instruction.)
5812*e4b17023SJohn Marino We can't improve this address, so leave it alone. */
5813*e4b17023SJohn Marino
5814*e4b17023SJohn Marino /* Otherwise, reload the autoincrement into a suitable hard reg
5815*e4b17023SJohn Marino and record how much to increment by. */
5816*e4b17023SJohn Marino
5817*e4b17023SJohn Marino if (reg_renumber[regno] >= 0)
5818*e4b17023SJohn Marino regno = reg_renumber[regno];
5819*e4b17023SJohn Marino if (regno >= FIRST_PSEUDO_REGISTER
5820*e4b17023SJohn Marino || !REG_OK_FOR_CONTEXT (context, regno, mode, as, code,
5821*e4b17023SJohn Marino index_code))
5822*e4b17023SJohn Marino {
5823*e4b17023SJohn Marino int reloadnum;
5824*e4b17023SJohn Marino
5825*e4b17023SJohn Marino /* If we can output the register afterwards, do so, this
5826*e4b17023SJohn Marino saves the extra update.
5827*e4b17023SJohn Marino We can do so if we have an INSN - i.e. no JUMP_INSN nor
5828*e4b17023SJohn Marino CALL_INSN - and it does not set CC0.
5829*e4b17023SJohn Marino But don't do this if we cannot directly address the
5830*e4b17023SJohn Marino memory location, since this will make it harder to
5831*e4b17023SJohn Marino reuse address reloads, and increases register pressure.
5832*e4b17023SJohn Marino Also don't do this if we can probably update x directly. */
5833*e4b17023SJohn Marino rtx equiv = (MEM_P (XEXP (x, 0))
5834*e4b17023SJohn Marino ? XEXP (x, 0)
5835*e4b17023SJohn Marino : reg_equiv_mem (regno));
5836*e4b17023SJohn Marino enum insn_code icode = optab_handler (add_optab, GET_MODE (x));
5837*e4b17023SJohn Marino if (insn && NONJUMP_INSN_P (insn) && equiv
5838*e4b17023SJohn Marino && memory_operand (equiv, GET_MODE (equiv))
5839*e4b17023SJohn Marino #ifdef HAVE_cc0
5840*e4b17023SJohn Marino && ! sets_cc0_p (PATTERN (insn))
5841*e4b17023SJohn Marino #endif
5842*e4b17023SJohn Marino && ! (icode != CODE_FOR_nothing
5843*e4b17023SJohn Marino && insn_operand_matches (icode, 0, equiv)
5844*e4b17023SJohn Marino && insn_operand_matches (icode, 1, equiv)))
5845*e4b17023SJohn Marino {
5846*e4b17023SJohn Marino /* We use the original pseudo for loc, so that
5847*e4b17023SJohn Marino emit_reload_insns() knows which pseudo this
5848*e4b17023SJohn Marino reload refers to and updates the pseudo rtx, not
5849*e4b17023SJohn Marino its equivalent memory location, as well as the
5850*e4b17023SJohn Marino corresponding entry in reg_last_reload_reg. */
5851*e4b17023SJohn Marino loc = &XEXP (x_orig, 0);
5852*e4b17023SJohn Marino x = XEXP (x, 0);
5853*e4b17023SJohn Marino reloadnum
5854*e4b17023SJohn Marino = push_reload (x, x, loc, loc,
5855*e4b17023SJohn Marino context_reg_class,
5856*e4b17023SJohn Marino GET_MODE (x), GET_MODE (x), 0, 0,
5857*e4b17023SJohn Marino opnum, RELOAD_OTHER);
5858*e4b17023SJohn Marino }
5859*e4b17023SJohn Marino else
5860*e4b17023SJohn Marino {
5861*e4b17023SJohn Marino reloadnum
5862*e4b17023SJohn Marino = push_reload (x, x, loc, (rtx*) 0,
5863*e4b17023SJohn Marino context_reg_class,
5864*e4b17023SJohn Marino GET_MODE (x), GET_MODE (x), 0, 0,
5865*e4b17023SJohn Marino opnum, type);
5866*e4b17023SJohn Marino rld[reloadnum].inc
5867*e4b17023SJohn Marino = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
5868*e4b17023SJohn Marino
5869*e4b17023SJohn Marino value = 1;
5870*e4b17023SJohn Marino }
5871*e4b17023SJohn Marino
5872*e4b17023SJohn Marino update_auto_inc_notes (this_insn, REGNO (XEXP (x_orig, 0)),
5873*e4b17023SJohn Marino reloadnum);
5874*e4b17023SJohn Marino }
5875*e4b17023SJohn Marino return value;
5876*e4b17023SJohn Marino }
5877*e4b17023SJohn Marino return 0;
5878*e4b17023SJohn Marino
5879*e4b17023SJohn Marino case TRUNCATE:
5880*e4b17023SJohn Marino case SIGN_EXTEND:
5881*e4b17023SJohn Marino case ZERO_EXTEND:
5882*e4b17023SJohn Marino /* Look for parts to reload in the inner expression and reload them
5883*e4b17023SJohn Marino too, in addition to this operation. Reloading all inner parts in
5884*e4b17023SJohn Marino addition to this one shouldn't be necessary, but at this point,
5885*e4b17023SJohn Marino we don't know if we can possibly omit any part that *can* be
5886*e4b17023SJohn Marino reloaded. Targets that are better off reloading just either part
5887*e4b17023SJohn Marino (or perhaps even a different part of an outer expression), should
5888*e4b17023SJohn Marino define LEGITIMIZE_RELOAD_ADDRESS. */
5889*e4b17023SJohn Marino find_reloads_address_1 (GET_MODE (XEXP (x, 0)), as, XEXP (x, 0),
5890*e4b17023SJohn Marino context, code, SCRATCH, &XEXP (x, 0), opnum,
5891*e4b17023SJohn Marino type, ind_levels, insn);
5892*e4b17023SJohn Marino push_reload (x, NULL_RTX, loc, (rtx*) 0,
5893*e4b17023SJohn Marino context_reg_class,
5894*e4b17023SJohn Marino GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5895*e4b17023SJohn Marino return 1;
5896*e4b17023SJohn Marino
5897*e4b17023SJohn Marino case MEM:
5898*e4b17023SJohn Marino /* This is probably the result of a substitution, by eliminate_regs, of
5899*e4b17023SJohn Marino an equivalent address for a pseudo that was not allocated to a hard
5900*e4b17023SJohn Marino register. Verify that the specified address is valid and reload it
5901*e4b17023SJohn Marino into a register.
5902*e4b17023SJohn Marino
5903*e4b17023SJohn Marino Since we know we are going to reload this item, don't decrement for
5904*e4b17023SJohn Marino the indirection level.
5905*e4b17023SJohn Marino
5906*e4b17023SJohn Marino Note that this is actually conservative: it would be slightly more
5907*e4b17023SJohn Marino efficient to use the value of SPILL_INDIRECT_LEVELS from
5908*e4b17023SJohn Marino reload1.c here. */
5909*e4b17023SJohn Marino
5910*e4b17023SJohn Marino find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5911*e4b17023SJohn Marino opnum, ADDR_TYPE (type), ind_levels, insn);
5912*e4b17023SJohn Marino push_reload (*loc, NULL_RTX, loc, (rtx*) 0,
5913*e4b17023SJohn Marino context_reg_class,
5914*e4b17023SJohn Marino GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5915*e4b17023SJohn Marino return 1;
5916*e4b17023SJohn Marino
5917*e4b17023SJohn Marino case REG:
5918*e4b17023SJohn Marino {
5919*e4b17023SJohn Marino int regno = REGNO (x);
5920*e4b17023SJohn Marino
5921*e4b17023SJohn Marino if (reg_equiv_constant (regno) != 0)
5922*e4b17023SJohn Marino {
5923*e4b17023SJohn Marino find_reloads_address_part (reg_equiv_constant (regno), loc,
5924*e4b17023SJohn Marino context_reg_class,
5925*e4b17023SJohn Marino GET_MODE (x), opnum, type, ind_levels);
5926*e4b17023SJohn Marino return 1;
5927*e4b17023SJohn Marino }
5928*e4b17023SJohn Marino
5929*e4b17023SJohn Marino #if 0 /* This might screw code in reload1.c to delete prior output-reload
5930*e4b17023SJohn Marino that feeds this insn. */
5931*e4b17023SJohn Marino if (reg_equiv_mem (regno) != 0)
5932*e4b17023SJohn Marino {
5933*e4b17023SJohn Marino push_reload (reg_equiv_mem (regno), NULL_RTX, loc, (rtx*) 0,
5934*e4b17023SJohn Marino context_reg_class,
5935*e4b17023SJohn Marino GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5936*e4b17023SJohn Marino return 1;
5937*e4b17023SJohn Marino }
5938*e4b17023SJohn Marino #endif
5939*e4b17023SJohn Marino
5940*e4b17023SJohn Marino if (reg_equiv_memory_loc (regno)
5941*e4b17023SJohn Marino && (reg_equiv_address (regno) != 0 || num_not_at_initial_offset))
5942*e4b17023SJohn Marino {
5943*e4b17023SJohn Marino rtx tem = make_memloc (x, regno);
5944*e4b17023SJohn Marino if (reg_equiv_address (regno) != 0
5945*e4b17023SJohn Marino || ! rtx_equal_p (tem, reg_equiv_mem (regno)))
5946*e4b17023SJohn Marino {
5947*e4b17023SJohn Marino x = tem;
5948*e4b17023SJohn Marino find_reloads_address (GET_MODE (x), &x, XEXP (x, 0),
5949*e4b17023SJohn Marino &XEXP (x, 0), opnum, ADDR_TYPE (type),
5950*e4b17023SJohn Marino ind_levels, insn);
5951*e4b17023SJohn Marino if (!rtx_equal_p (x, tem))
5952*e4b17023SJohn Marino push_reg_equiv_alt_mem (regno, x);
5953*e4b17023SJohn Marino }
5954*e4b17023SJohn Marino }
5955*e4b17023SJohn Marino
5956*e4b17023SJohn Marino if (reg_renumber[regno] >= 0)
5957*e4b17023SJohn Marino regno = reg_renumber[regno];
5958*e4b17023SJohn Marino
5959*e4b17023SJohn Marino if (regno >= FIRST_PSEUDO_REGISTER
5960*e4b17023SJohn Marino || !REG_OK_FOR_CONTEXT (context, regno, mode, as, outer_code,
5961*e4b17023SJohn Marino index_code))
5962*e4b17023SJohn Marino {
5963*e4b17023SJohn Marino push_reload (x, NULL_RTX, loc, (rtx*) 0,
5964*e4b17023SJohn Marino context_reg_class,
5965*e4b17023SJohn Marino GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5966*e4b17023SJohn Marino return 1;
5967*e4b17023SJohn Marino }
5968*e4b17023SJohn Marino
5969*e4b17023SJohn Marino /* If a register appearing in an address is the subject of a CLOBBER
5970*e4b17023SJohn Marino in this insn, reload it into some other register to be safe.
5971*e4b17023SJohn Marino The CLOBBER is supposed to make the register unavailable
5972*e4b17023SJohn Marino from before this insn to after it. */
5973*e4b17023SJohn Marino if (regno_clobbered_p (regno, this_insn, GET_MODE (x), 0))
5974*e4b17023SJohn Marino {
5975*e4b17023SJohn Marino push_reload (x, NULL_RTX, loc, (rtx*) 0,
5976*e4b17023SJohn Marino context_reg_class,
5977*e4b17023SJohn Marino GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5978*e4b17023SJohn Marino return 1;
5979*e4b17023SJohn Marino }
5980*e4b17023SJohn Marino }
5981*e4b17023SJohn Marino return 0;
5982*e4b17023SJohn Marino
5983*e4b17023SJohn Marino case SUBREG:
5984*e4b17023SJohn Marino if (REG_P (SUBREG_REG (x)))
5985*e4b17023SJohn Marino {
5986*e4b17023SJohn Marino /* If this is a SUBREG of a hard register and the resulting register
5987*e4b17023SJohn Marino is of the wrong class, reload the whole SUBREG. This avoids
5988*e4b17023SJohn Marino needless copies if SUBREG_REG is multi-word. */
5989*e4b17023SJohn Marino if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5990*e4b17023SJohn Marino {
5991*e4b17023SJohn Marino int regno ATTRIBUTE_UNUSED = subreg_regno (x);
5992*e4b17023SJohn Marino
5993*e4b17023SJohn Marino if (!REG_OK_FOR_CONTEXT (context, regno, mode, as, outer_code,
5994*e4b17023SJohn Marino index_code))
5995*e4b17023SJohn Marino {
5996*e4b17023SJohn Marino push_reload (x, NULL_RTX, loc, (rtx*) 0,
5997*e4b17023SJohn Marino context_reg_class,
5998*e4b17023SJohn Marino GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5999*e4b17023SJohn Marino return 1;
6000*e4b17023SJohn Marino }
6001*e4b17023SJohn Marino }
6002*e4b17023SJohn Marino /* If this is a SUBREG of a pseudo-register, and the pseudo-register
6003*e4b17023SJohn Marino is larger than the class size, then reload the whole SUBREG. */
6004*e4b17023SJohn Marino else
6005*e4b17023SJohn Marino {
6006*e4b17023SJohn Marino enum reg_class rclass = context_reg_class;
6007*e4b17023SJohn Marino if (ira_reg_class_max_nregs [rclass][GET_MODE (SUBREG_REG (x))]
6008*e4b17023SJohn Marino > reg_class_size[(int) rclass])
6009*e4b17023SJohn Marino {
6010*e4b17023SJohn Marino x = find_reloads_subreg_address (x, 0, opnum,
6011*e4b17023SJohn Marino ADDR_TYPE (type),
6012*e4b17023SJohn Marino ind_levels, insn, NULL);
6013*e4b17023SJohn Marino push_reload (x, NULL_RTX, loc, (rtx*) 0, rclass,
6014*e4b17023SJohn Marino GET_MODE (x), VOIDmode, 0, 0, opnum, type);
6015*e4b17023SJohn Marino return 1;
6016*e4b17023SJohn Marino }
6017*e4b17023SJohn Marino }
6018*e4b17023SJohn Marino }
6019*e4b17023SJohn Marino break;
6020*e4b17023SJohn Marino
6021*e4b17023SJohn Marino default:
6022*e4b17023SJohn Marino break;
6023*e4b17023SJohn Marino }
6024*e4b17023SJohn Marino
6025*e4b17023SJohn Marino {
6026*e4b17023SJohn Marino const char *fmt = GET_RTX_FORMAT (code);
6027*e4b17023SJohn Marino int i;
6028*e4b17023SJohn Marino
6029*e4b17023SJohn Marino for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6030*e4b17023SJohn Marino {
6031*e4b17023SJohn Marino if (fmt[i] == 'e')
6032*e4b17023SJohn Marino /* Pass SCRATCH for INDEX_CODE, since CODE can never be a PLUS once
6033*e4b17023SJohn Marino we get here. */
6034*e4b17023SJohn Marino find_reloads_address_1 (mode, as, XEXP (x, i), context,
6035*e4b17023SJohn Marino code, SCRATCH, &XEXP (x, i),
6036*e4b17023SJohn Marino opnum, type, ind_levels, insn);
6037*e4b17023SJohn Marino }
6038*e4b17023SJohn Marino }
6039*e4b17023SJohn Marino
6040*e4b17023SJohn Marino #undef REG_OK_FOR_CONTEXT
6041*e4b17023SJohn Marino return 0;
6042*e4b17023SJohn Marino }
6043*e4b17023SJohn Marino
6044*e4b17023SJohn Marino /* X, which is found at *LOC, is a part of an address that needs to be
6045*e4b17023SJohn Marino reloaded into a register of class RCLASS. If X is a constant, or if
6046*e4b17023SJohn Marino X is a PLUS that contains a constant, check that the constant is a
6047*e4b17023SJohn Marino legitimate operand and that we are supposed to be able to load
6048*e4b17023SJohn Marino it into the register.
6049*e4b17023SJohn Marino
6050*e4b17023SJohn Marino If not, force the constant into memory and reload the MEM instead.
6051*e4b17023SJohn Marino
6052*e4b17023SJohn Marino MODE is the mode to use, in case X is an integer constant.
6053*e4b17023SJohn Marino
6054*e4b17023SJohn Marino OPNUM and TYPE describe the purpose of any reloads made.
6055*e4b17023SJohn Marino
6056*e4b17023SJohn Marino IND_LEVELS says how many levels of indirect addressing this machine
6057*e4b17023SJohn Marino supports. */
6058*e4b17023SJohn Marino
6059*e4b17023SJohn Marino static void
find_reloads_address_part(rtx x,rtx * loc,enum reg_class rclass,enum machine_mode mode,int opnum,enum reload_type type,int ind_levels)6060*e4b17023SJohn Marino find_reloads_address_part (rtx x, rtx *loc, enum reg_class rclass,
6061*e4b17023SJohn Marino enum machine_mode mode, int opnum,
6062*e4b17023SJohn Marino enum reload_type type, int ind_levels)
6063*e4b17023SJohn Marino {
6064*e4b17023SJohn Marino if (CONSTANT_P (x)
6065*e4b17023SJohn Marino && (!targetm.legitimate_constant_p (mode, x)
6066*e4b17023SJohn Marino || targetm.preferred_reload_class (x, rclass) == NO_REGS))
6067*e4b17023SJohn Marino {
6068*e4b17023SJohn Marino x = force_const_mem (mode, x);
6069*e4b17023SJohn Marino find_reloads_address (mode, &x, XEXP (x, 0), &XEXP (x, 0),
6070*e4b17023SJohn Marino opnum, type, ind_levels, 0);
6071*e4b17023SJohn Marino }
6072*e4b17023SJohn Marino
6073*e4b17023SJohn Marino else if (GET_CODE (x) == PLUS
6074*e4b17023SJohn Marino && CONSTANT_P (XEXP (x, 1))
6075*e4b17023SJohn Marino && (!targetm.legitimate_constant_p (GET_MODE (x), XEXP (x, 1))
6076*e4b17023SJohn Marino || targetm.preferred_reload_class (XEXP (x, 1), rclass)
6077*e4b17023SJohn Marino == NO_REGS))
6078*e4b17023SJohn Marino {
6079*e4b17023SJohn Marino rtx tem;
6080*e4b17023SJohn Marino
6081*e4b17023SJohn Marino tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
6082*e4b17023SJohn Marino x = gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), tem);
6083*e4b17023SJohn Marino find_reloads_address (mode, &XEXP (x, 1), XEXP (tem, 0), &XEXP (tem, 0),
6084*e4b17023SJohn Marino opnum, type, ind_levels, 0);
6085*e4b17023SJohn Marino }
6086*e4b17023SJohn Marino
6087*e4b17023SJohn Marino push_reload (x, NULL_RTX, loc, (rtx*) 0, rclass,
6088*e4b17023SJohn Marino mode, VOIDmode, 0, 0, opnum, type);
6089*e4b17023SJohn Marino }
6090*e4b17023SJohn Marino
6091*e4b17023SJohn Marino /* X, a subreg of a pseudo, is a part of an address that needs to be
6092*e4b17023SJohn Marino reloaded.
6093*e4b17023SJohn Marino
6094*e4b17023SJohn Marino If the pseudo is equivalent to a memory location that cannot be directly
6095*e4b17023SJohn Marino addressed, make the necessary address reloads.
6096*e4b17023SJohn Marino
6097*e4b17023SJohn Marino If address reloads have been necessary, or if the address is changed
6098*e4b17023SJohn Marino by register elimination, return the rtx of the memory location;
6099*e4b17023SJohn Marino otherwise, return X.
6100*e4b17023SJohn Marino
6101*e4b17023SJohn Marino If FORCE_REPLACE is nonzero, unconditionally replace the subreg with the
6102*e4b17023SJohn Marino memory location.
6103*e4b17023SJohn Marino
6104*e4b17023SJohn Marino OPNUM and TYPE identify the purpose of the reload.
6105*e4b17023SJohn Marino
6106*e4b17023SJohn Marino IND_LEVELS says how many levels of indirect addressing are
6107*e4b17023SJohn Marino supported at this point in the address.
6108*e4b17023SJohn Marino
6109*e4b17023SJohn Marino INSN, if nonzero, is the insn in which we do the reload. It is used
6110*e4b17023SJohn Marino to determine where to put USEs for pseudos that we have to replace with
6111*e4b17023SJohn Marino stack slots. */
6112*e4b17023SJohn Marino
6113*e4b17023SJohn Marino static rtx
find_reloads_subreg_address(rtx x,int force_replace,int opnum,enum reload_type type,int ind_levels,rtx insn,int * address_reloaded)6114*e4b17023SJohn Marino find_reloads_subreg_address (rtx x, int force_replace, int opnum,
6115*e4b17023SJohn Marino enum reload_type type, int ind_levels, rtx insn,
6116*e4b17023SJohn Marino int *address_reloaded)
6117*e4b17023SJohn Marino {
6118*e4b17023SJohn Marino int regno = REGNO (SUBREG_REG (x));
6119*e4b17023SJohn Marino int reloaded = 0;
6120*e4b17023SJohn Marino
6121*e4b17023SJohn Marino if (reg_equiv_memory_loc (regno))
6122*e4b17023SJohn Marino {
6123*e4b17023SJohn Marino /* If the address is not directly addressable, or if the address is not
6124*e4b17023SJohn Marino offsettable, then it must be replaced. */
6125*e4b17023SJohn Marino if (! force_replace
6126*e4b17023SJohn Marino && (reg_equiv_address (regno)
6127*e4b17023SJohn Marino || ! offsettable_memref_p (reg_equiv_mem (regno))))
6128*e4b17023SJohn Marino force_replace = 1;
6129*e4b17023SJohn Marino
6130*e4b17023SJohn Marino if (force_replace || num_not_at_initial_offset)
6131*e4b17023SJohn Marino {
6132*e4b17023SJohn Marino rtx tem = make_memloc (SUBREG_REG (x), regno);
6133*e4b17023SJohn Marino
6134*e4b17023SJohn Marino /* If the address changes because of register elimination, then
6135*e4b17023SJohn Marino it must be replaced. */
6136*e4b17023SJohn Marino if (force_replace
6137*e4b17023SJohn Marino || ! rtx_equal_p (tem, reg_equiv_mem (regno)))
6138*e4b17023SJohn Marino {
6139*e4b17023SJohn Marino unsigned outer_size = GET_MODE_SIZE (GET_MODE (x));
6140*e4b17023SJohn Marino unsigned inner_size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
6141*e4b17023SJohn Marino int offset;
6142*e4b17023SJohn Marino rtx orig = tem;
6143*e4b17023SJohn Marino
6144*e4b17023SJohn Marino /* For big-endian paradoxical subregs, SUBREG_BYTE does not
6145*e4b17023SJohn Marino hold the correct (negative) byte offset. */
6146*e4b17023SJohn Marino if (BYTES_BIG_ENDIAN && outer_size > inner_size)
6147*e4b17023SJohn Marino offset = inner_size - outer_size;
6148*e4b17023SJohn Marino else
6149*e4b17023SJohn Marino offset = SUBREG_BYTE (x);
6150*e4b17023SJohn Marino
6151*e4b17023SJohn Marino XEXP (tem, 0) = plus_constant (XEXP (tem, 0), offset);
6152*e4b17023SJohn Marino PUT_MODE (tem, GET_MODE (x));
6153*e4b17023SJohn Marino if (MEM_OFFSET_KNOWN_P (tem))
6154*e4b17023SJohn Marino set_mem_offset (tem, MEM_OFFSET (tem) + offset);
6155*e4b17023SJohn Marino if (MEM_SIZE_KNOWN_P (tem)
6156*e4b17023SJohn Marino && MEM_SIZE (tem) != (HOST_WIDE_INT) outer_size)
6157*e4b17023SJohn Marino set_mem_size (tem, outer_size);
6158*e4b17023SJohn Marino
6159*e4b17023SJohn Marino /* If this was a paradoxical subreg that we replaced, the
6160*e4b17023SJohn Marino resulting memory must be sufficiently aligned to allow
6161*e4b17023SJohn Marino us to widen the mode of the memory. */
6162*e4b17023SJohn Marino if (outer_size > inner_size)
6163*e4b17023SJohn Marino {
6164*e4b17023SJohn Marino rtx base;
6165*e4b17023SJohn Marino
6166*e4b17023SJohn Marino base = XEXP (tem, 0);
6167*e4b17023SJohn Marino if (GET_CODE (base) == PLUS)
6168*e4b17023SJohn Marino {
6169*e4b17023SJohn Marino if (CONST_INT_P (XEXP (base, 1))
6170*e4b17023SJohn Marino && INTVAL (XEXP (base, 1)) % outer_size != 0)
6171*e4b17023SJohn Marino return x;
6172*e4b17023SJohn Marino base = XEXP (base, 0);
6173*e4b17023SJohn Marino }
6174*e4b17023SJohn Marino if (!REG_P (base)
6175*e4b17023SJohn Marino || (REGNO_POINTER_ALIGN (REGNO (base))
6176*e4b17023SJohn Marino < outer_size * BITS_PER_UNIT))
6177*e4b17023SJohn Marino return x;
6178*e4b17023SJohn Marino }
6179*e4b17023SJohn Marino
6180*e4b17023SJohn Marino reloaded = find_reloads_address (GET_MODE (tem), &tem,
6181*e4b17023SJohn Marino XEXP (tem, 0), &XEXP (tem, 0),
6182*e4b17023SJohn Marino opnum, type, ind_levels, insn);
6183*e4b17023SJohn Marino /* ??? Do we need to handle nonzero offsets somehow? */
6184*e4b17023SJohn Marino if (!offset && !rtx_equal_p (tem, orig))
6185*e4b17023SJohn Marino push_reg_equiv_alt_mem (regno, tem);
6186*e4b17023SJohn Marino
6187*e4b17023SJohn Marino /* For some processors an address may be valid in the
6188*e4b17023SJohn Marino original mode but not in a smaller mode. For
6189*e4b17023SJohn Marino example, ARM accepts a scaled index register in
6190*e4b17023SJohn Marino SImode but not in HImode. Note that this is only
6191*e4b17023SJohn Marino a problem if the address in reg_equiv_mem is already
6192*e4b17023SJohn Marino invalid in the new mode; other cases would be fixed
6193*e4b17023SJohn Marino by find_reloads_address as usual.
6194*e4b17023SJohn Marino
6195*e4b17023SJohn Marino ??? We attempt to handle such cases here by doing an
6196*e4b17023SJohn Marino additional reload of the full address after the
6197*e4b17023SJohn Marino usual processing by find_reloads_address. Note that
6198*e4b17023SJohn Marino this may not work in the general case, but it seems
6199*e4b17023SJohn Marino to cover the cases where this situation currently
6200*e4b17023SJohn Marino occurs. A more general fix might be to reload the
6201*e4b17023SJohn Marino *value* instead of the address, but this would not
6202*e4b17023SJohn Marino be expected by the callers of this routine as-is.
6203*e4b17023SJohn Marino
6204*e4b17023SJohn Marino If find_reloads_address already completed replaced
6205*e4b17023SJohn Marino the address, there is nothing further to do. */
6206*e4b17023SJohn Marino if (reloaded == 0
6207*e4b17023SJohn Marino && reg_equiv_mem (regno) != 0
6208*e4b17023SJohn Marino && !strict_memory_address_addr_space_p
6209*e4b17023SJohn Marino (GET_MODE (x), XEXP (reg_equiv_mem (regno), 0),
6210*e4b17023SJohn Marino MEM_ADDR_SPACE (reg_equiv_mem (regno))))
6211*e4b17023SJohn Marino {
6212*e4b17023SJohn Marino push_reload (XEXP (tem, 0), NULL_RTX, &XEXP (tem, 0), (rtx*) 0,
6213*e4b17023SJohn Marino base_reg_class (GET_MODE (tem),
6214*e4b17023SJohn Marino MEM_ADDR_SPACE (tem),
6215*e4b17023SJohn Marino MEM, SCRATCH),
6216*e4b17023SJohn Marino GET_MODE (XEXP (tem, 0)), VOIDmode, 0, 0,
6217*e4b17023SJohn Marino opnum, type);
6218*e4b17023SJohn Marino reloaded = 1;
6219*e4b17023SJohn Marino }
6220*e4b17023SJohn Marino /* If this is not a toplevel operand, find_reloads doesn't see
6221*e4b17023SJohn Marino this substitution. We have to emit a USE of the pseudo so
6222*e4b17023SJohn Marino that delete_output_reload can see it. */
6223*e4b17023SJohn Marino if (replace_reloads && recog_data.operand[opnum] != x)
6224*e4b17023SJohn Marino /* We mark the USE with QImode so that we recognize it
6225*e4b17023SJohn Marino as one that can be safely deleted at the end of
6226*e4b17023SJohn Marino reload. */
6227*e4b17023SJohn Marino PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode,
6228*e4b17023SJohn Marino SUBREG_REG (x)),
6229*e4b17023SJohn Marino insn), QImode);
6230*e4b17023SJohn Marino x = tem;
6231*e4b17023SJohn Marino }
6232*e4b17023SJohn Marino }
6233*e4b17023SJohn Marino }
6234*e4b17023SJohn Marino if (address_reloaded)
6235*e4b17023SJohn Marino *address_reloaded = reloaded;
6236*e4b17023SJohn Marino
6237*e4b17023SJohn Marino return x;
6238*e4b17023SJohn Marino }
6239*e4b17023SJohn Marino
6240*e4b17023SJohn Marino /* Substitute into the current INSN the registers into which we have reloaded
6241*e4b17023SJohn Marino the things that need reloading. The array `replacements'
6242*e4b17023SJohn Marino contains the locations of all pointers that must be changed
6243*e4b17023SJohn Marino and says what to replace them with.
6244*e4b17023SJohn Marino
6245*e4b17023SJohn Marino Return the rtx that X translates into; usually X, but modified. */
6246*e4b17023SJohn Marino
6247*e4b17023SJohn Marino void
subst_reloads(rtx insn)6248*e4b17023SJohn Marino subst_reloads (rtx insn)
6249*e4b17023SJohn Marino {
6250*e4b17023SJohn Marino int i;
6251*e4b17023SJohn Marino
6252*e4b17023SJohn Marino for (i = 0; i < n_replacements; i++)
6253*e4b17023SJohn Marino {
6254*e4b17023SJohn Marino struct replacement *r = &replacements[i];
6255*e4b17023SJohn Marino rtx reloadreg = rld[r->what].reg_rtx;
6256*e4b17023SJohn Marino if (reloadreg)
6257*e4b17023SJohn Marino {
6258*e4b17023SJohn Marino #ifdef DEBUG_RELOAD
6259*e4b17023SJohn Marino /* This checking takes a very long time on some platforms
6260*e4b17023SJohn Marino causing the gcc.c-torture/compile/limits-fnargs.c test
6261*e4b17023SJohn Marino to time out during testing. See PR 31850.
6262*e4b17023SJohn Marino
6263*e4b17023SJohn Marino Internal consistency test. Check that we don't modify
6264*e4b17023SJohn Marino anything in the equivalence arrays. Whenever something from
6265*e4b17023SJohn Marino those arrays needs to be reloaded, it must be unshared before
6266*e4b17023SJohn Marino being substituted into; the equivalence must not be modified.
6267*e4b17023SJohn Marino Otherwise, if the equivalence is used after that, it will
6268*e4b17023SJohn Marino have been modified, and the thing substituted (probably a
6269*e4b17023SJohn Marino register) is likely overwritten and not a usable equivalence. */
6270*e4b17023SJohn Marino int check_regno;
6271*e4b17023SJohn Marino
6272*e4b17023SJohn Marino for (check_regno = 0; check_regno < max_regno; check_regno++)
6273*e4b17023SJohn Marino {
6274*e4b17023SJohn Marino #define CHECK_MODF(ARRAY) \
6275*e4b17023SJohn Marino gcc_assert (!VEC_index (reg_equivs_t, reg_equivs, check_regno).ARRAY \
6276*e4b17023SJohn Marino || !loc_mentioned_in_p (r->where, \
6277*e4b17023SJohn Marino VEC_index (reg_equivs_t, reg_equivs, check_regno).ARRAY))
6278*e4b17023SJohn Marino
6279*e4b17023SJohn Marino CHECK_MODF (equiv_constant);
6280*e4b17023SJohn Marino CHECK_MODF (equiv_memory_loc);
6281*e4b17023SJohn Marino CHECK_MODF (equiv_address);
6282*e4b17023SJohn Marino CHECK_MODF (equiv_mem);
6283*e4b17023SJohn Marino #undef CHECK_MODF
6284*e4b17023SJohn Marino }
6285*e4b17023SJohn Marino #endif /* DEBUG_RELOAD */
6286*e4b17023SJohn Marino
6287*e4b17023SJohn Marino /* If we're replacing a LABEL_REF with a register, there must
6288*e4b17023SJohn Marino already be an indication (to e.g. flow) which label this
6289*e4b17023SJohn Marino register refers to. */
6290*e4b17023SJohn Marino gcc_assert (GET_CODE (*r->where) != LABEL_REF
6291*e4b17023SJohn Marino || !JUMP_P (insn)
6292*e4b17023SJohn Marino || find_reg_note (insn,
6293*e4b17023SJohn Marino REG_LABEL_OPERAND,
6294*e4b17023SJohn Marino XEXP (*r->where, 0))
6295*e4b17023SJohn Marino || label_is_jump_target_p (XEXP (*r->where, 0), insn));
6296*e4b17023SJohn Marino
6297*e4b17023SJohn Marino /* Encapsulate RELOADREG so its machine mode matches what
6298*e4b17023SJohn Marino used to be there. Note that gen_lowpart_common will
6299*e4b17023SJohn Marino do the wrong thing if RELOADREG is multi-word. RELOADREG
6300*e4b17023SJohn Marino will always be a REG here. */
6301*e4b17023SJohn Marino if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
6302*e4b17023SJohn Marino reloadreg = reload_adjust_reg_for_mode (reloadreg, r->mode);
6303*e4b17023SJohn Marino
6304*e4b17023SJohn Marino *r->where = reloadreg;
6305*e4b17023SJohn Marino }
6306*e4b17023SJohn Marino /* If reload got no reg and isn't optional, something's wrong. */
6307*e4b17023SJohn Marino else
6308*e4b17023SJohn Marino gcc_assert (rld[r->what].optional);
6309*e4b17023SJohn Marino }
6310*e4b17023SJohn Marino }
6311*e4b17023SJohn Marino
6312*e4b17023SJohn Marino /* Make a copy of any replacements being done into X and move those
6313*e4b17023SJohn Marino copies to locations in Y, a copy of X. */
6314*e4b17023SJohn Marino
6315*e4b17023SJohn Marino void
copy_replacements(rtx x,rtx y)6316*e4b17023SJohn Marino copy_replacements (rtx x, rtx y)
6317*e4b17023SJohn Marino {
6318*e4b17023SJohn Marino copy_replacements_1 (&x, &y, n_replacements);
6319*e4b17023SJohn Marino }
6320*e4b17023SJohn Marino
6321*e4b17023SJohn Marino static void
copy_replacements_1(rtx * px,rtx * py,int orig_replacements)6322*e4b17023SJohn Marino copy_replacements_1 (rtx *px, rtx *py, int orig_replacements)
6323*e4b17023SJohn Marino {
6324*e4b17023SJohn Marino int i, j;
6325*e4b17023SJohn Marino rtx x, y;
6326*e4b17023SJohn Marino struct replacement *r;
6327*e4b17023SJohn Marino enum rtx_code code;
6328*e4b17023SJohn Marino const char *fmt;
6329*e4b17023SJohn Marino
6330*e4b17023SJohn Marino for (j = 0; j < orig_replacements; j++)
6331*e4b17023SJohn Marino if (replacements[j].where == px)
6332*e4b17023SJohn Marino {
6333*e4b17023SJohn Marino r = &replacements[n_replacements++];
6334*e4b17023SJohn Marino r->where = py;
6335*e4b17023SJohn Marino r->what = replacements[j].what;
6336*e4b17023SJohn Marino r->mode = replacements[j].mode;
6337*e4b17023SJohn Marino }
6338*e4b17023SJohn Marino
6339*e4b17023SJohn Marino x = *px;
6340*e4b17023SJohn Marino y = *py;
6341*e4b17023SJohn Marino code = GET_CODE (x);
6342*e4b17023SJohn Marino fmt = GET_RTX_FORMAT (code);
6343*e4b17023SJohn Marino
6344*e4b17023SJohn Marino for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6345*e4b17023SJohn Marino {
6346*e4b17023SJohn Marino if (fmt[i] == 'e')
6347*e4b17023SJohn Marino copy_replacements_1 (&XEXP (x, i), &XEXP (y, i), orig_replacements);
6348*e4b17023SJohn Marino else if (fmt[i] == 'E')
6349*e4b17023SJohn Marino for (j = XVECLEN (x, i); --j >= 0; )
6350*e4b17023SJohn Marino copy_replacements_1 (&XVECEXP (x, i, j), &XVECEXP (y, i, j),
6351*e4b17023SJohn Marino orig_replacements);
6352*e4b17023SJohn Marino }
6353*e4b17023SJohn Marino }
6354*e4b17023SJohn Marino
6355*e4b17023SJohn Marino /* Change any replacements being done to *X to be done to *Y. */
6356*e4b17023SJohn Marino
6357*e4b17023SJohn Marino void
move_replacements(rtx * x,rtx * y)6358*e4b17023SJohn Marino move_replacements (rtx *x, rtx *y)
6359*e4b17023SJohn Marino {
6360*e4b17023SJohn Marino int i;
6361*e4b17023SJohn Marino
6362*e4b17023SJohn Marino for (i = 0; i < n_replacements; i++)
6363*e4b17023SJohn Marino if (replacements[i].where == x)
6364*e4b17023SJohn Marino replacements[i].where = y;
6365*e4b17023SJohn Marino }
6366*e4b17023SJohn Marino
6367*e4b17023SJohn Marino /* If LOC was scheduled to be replaced by something, return the replacement.
6368*e4b17023SJohn Marino Otherwise, return *LOC. */
6369*e4b17023SJohn Marino
6370*e4b17023SJohn Marino rtx
find_replacement(rtx * loc)6371*e4b17023SJohn Marino find_replacement (rtx *loc)
6372*e4b17023SJohn Marino {
6373*e4b17023SJohn Marino struct replacement *r;
6374*e4b17023SJohn Marino
6375*e4b17023SJohn Marino for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
6376*e4b17023SJohn Marino {
6377*e4b17023SJohn Marino rtx reloadreg = rld[r->what].reg_rtx;
6378*e4b17023SJohn Marino
6379*e4b17023SJohn Marino if (reloadreg && r->where == loc)
6380*e4b17023SJohn Marino {
6381*e4b17023SJohn Marino if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
6382*e4b17023SJohn Marino reloadreg = reload_adjust_reg_for_mode (reloadreg, r->mode);
6383*e4b17023SJohn Marino
6384*e4b17023SJohn Marino return reloadreg;
6385*e4b17023SJohn Marino }
6386*e4b17023SJohn Marino else if (reloadreg && GET_CODE (*loc) == SUBREG
6387*e4b17023SJohn Marino && r->where == &SUBREG_REG (*loc))
6388*e4b17023SJohn Marino {
6389*e4b17023SJohn Marino if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
6390*e4b17023SJohn Marino reloadreg = reload_adjust_reg_for_mode (reloadreg, r->mode);
6391*e4b17023SJohn Marino
6392*e4b17023SJohn Marino return simplify_gen_subreg (GET_MODE (*loc), reloadreg,
6393*e4b17023SJohn Marino GET_MODE (SUBREG_REG (*loc)),
6394*e4b17023SJohn Marino SUBREG_BYTE (*loc));
6395*e4b17023SJohn Marino }
6396*e4b17023SJohn Marino }
6397*e4b17023SJohn Marino
6398*e4b17023SJohn Marino /* If *LOC is a PLUS, MINUS, or MULT, see if a replacement is scheduled for
6399*e4b17023SJohn Marino what's inside and make a new rtl if so. */
6400*e4b17023SJohn Marino if (GET_CODE (*loc) == PLUS || GET_CODE (*loc) == MINUS
6401*e4b17023SJohn Marino || GET_CODE (*loc) == MULT)
6402*e4b17023SJohn Marino {
6403*e4b17023SJohn Marino rtx x = find_replacement (&XEXP (*loc, 0));
6404*e4b17023SJohn Marino rtx y = find_replacement (&XEXP (*loc, 1));
6405*e4b17023SJohn Marino
6406*e4b17023SJohn Marino if (x != XEXP (*loc, 0) || y != XEXP (*loc, 1))
6407*e4b17023SJohn Marino return gen_rtx_fmt_ee (GET_CODE (*loc), GET_MODE (*loc), x, y);
6408*e4b17023SJohn Marino }
6409*e4b17023SJohn Marino
6410*e4b17023SJohn Marino return *loc;
6411*e4b17023SJohn Marino }
6412*e4b17023SJohn Marino
6413*e4b17023SJohn Marino /* Return nonzero if register in range [REGNO, ENDREGNO)
6414*e4b17023SJohn Marino appears either explicitly or implicitly in X
6415*e4b17023SJohn Marino other than being stored into (except for earlyclobber operands).
6416*e4b17023SJohn Marino
6417*e4b17023SJohn Marino References contained within the substructure at LOC do not count.
6418*e4b17023SJohn Marino LOC may be zero, meaning don't ignore anything.
6419*e4b17023SJohn Marino
6420*e4b17023SJohn Marino This is similar to refers_to_regno_p in rtlanal.c except that we
6421*e4b17023SJohn Marino look at equivalences for pseudos that didn't get hard registers. */
6422*e4b17023SJohn Marino
6423*e4b17023SJohn Marino static int
refers_to_regno_for_reload_p(unsigned int regno,unsigned int endregno,rtx x,rtx * loc)6424*e4b17023SJohn Marino refers_to_regno_for_reload_p (unsigned int regno, unsigned int endregno,
6425*e4b17023SJohn Marino rtx x, rtx *loc)
6426*e4b17023SJohn Marino {
6427*e4b17023SJohn Marino int i;
6428*e4b17023SJohn Marino unsigned int r;
6429*e4b17023SJohn Marino RTX_CODE code;
6430*e4b17023SJohn Marino const char *fmt;
6431*e4b17023SJohn Marino
6432*e4b17023SJohn Marino if (x == 0)
6433*e4b17023SJohn Marino return 0;
6434*e4b17023SJohn Marino
6435*e4b17023SJohn Marino repeat:
6436*e4b17023SJohn Marino code = GET_CODE (x);
6437*e4b17023SJohn Marino
6438*e4b17023SJohn Marino switch (code)
6439*e4b17023SJohn Marino {
6440*e4b17023SJohn Marino case REG:
6441*e4b17023SJohn Marino r = REGNO (x);
6442*e4b17023SJohn Marino
6443*e4b17023SJohn Marino /* If this is a pseudo, a hard register must not have been allocated.
6444*e4b17023SJohn Marino X must therefore either be a constant or be in memory. */
6445*e4b17023SJohn Marino if (r >= FIRST_PSEUDO_REGISTER)
6446*e4b17023SJohn Marino {
6447*e4b17023SJohn Marino if (reg_equiv_memory_loc (r))
6448*e4b17023SJohn Marino return refers_to_regno_for_reload_p (regno, endregno,
6449*e4b17023SJohn Marino reg_equiv_memory_loc (r),
6450*e4b17023SJohn Marino (rtx*) 0);
6451*e4b17023SJohn Marino
6452*e4b17023SJohn Marino gcc_assert (reg_equiv_constant (r) || reg_equiv_invariant (r));
6453*e4b17023SJohn Marino return 0;
6454*e4b17023SJohn Marino }
6455*e4b17023SJohn Marino
6456*e4b17023SJohn Marino return (endregno > r
6457*e4b17023SJohn Marino && regno < r + (r < FIRST_PSEUDO_REGISTER
6458*e4b17023SJohn Marino ? hard_regno_nregs[r][GET_MODE (x)]
6459*e4b17023SJohn Marino : 1));
6460*e4b17023SJohn Marino
6461*e4b17023SJohn Marino case SUBREG:
6462*e4b17023SJohn Marino /* If this is a SUBREG of a hard reg, we can see exactly which
6463*e4b17023SJohn Marino registers are being modified. Otherwise, handle normally. */
6464*e4b17023SJohn Marino if (REG_P (SUBREG_REG (x))
6465*e4b17023SJohn Marino && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
6466*e4b17023SJohn Marino {
6467*e4b17023SJohn Marino unsigned int inner_regno = subreg_regno (x);
6468*e4b17023SJohn Marino unsigned int inner_endregno
6469*e4b17023SJohn Marino = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
6470*e4b17023SJohn Marino ? subreg_nregs (x) : 1);
6471*e4b17023SJohn Marino
6472*e4b17023SJohn Marino return endregno > inner_regno && regno < inner_endregno;
6473*e4b17023SJohn Marino }
6474*e4b17023SJohn Marino break;
6475*e4b17023SJohn Marino
6476*e4b17023SJohn Marino case CLOBBER:
6477*e4b17023SJohn Marino case SET:
6478*e4b17023SJohn Marino if (&SET_DEST (x) != loc
6479*e4b17023SJohn Marino /* Note setting a SUBREG counts as referring to the REG it is in for
6480*e4b17023SJohn Marino a pseudo but not for hard registers since we can
6481*e4b17023SJohn Marino treat each word individually. */
6482*e4b17023SJohn Marino && ((GET_CODE (SET_DEST (x)) == SUBREG
6483*e4b17023SJohn Marino && loc != &SUBREG_REG (SET_DEST (x))
6484*e4b17023SJohn Marino && REG_P (SUBREG_REG (SET_DEST (x)))
6485*e4b17023SJohn Marino && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
6486*e4b17023SJohn Marino && refers_to_regno_for_reload_p (regno, endregno,
6487*e4b17023SJohn Marino SUBREG_REG (SET_DEST (x)),
6488*e4b17023SJohn Marino loc))
6489*e4b17023SJohn Marino /* If the output is an earlyclobber operand, this is
6490*e4b17023SJohn Marino a conflict. */
6491*e4b17023SJohn Marino || ((!REG_P (SET_DEST (x))
6492*e4b17023SJohn Marino || earlyclobber_operand_p (SET_DEST (x)))
6493*e4b17023SJohn Marino && refers_to_regno_for_reload_p (regno, endregno,
6494*e4b17023SJohn Marino SET_DEST (x), loc))))
6495*e4b17023SJohn Marino return 1;
6496*e4b17023SJohn Marino
6497*e4b17023SJohn Marino if (code == CLOBBER || loc == &SET_SRC (x))
6498*e4b17023SJohn Marino return 0;
6499*e4b17023SJohn Marino x = SET_SRC (x);
6500*e4b17023SJohn Marino goto repeat;
6501*e4b17023SJohn Marino
6502*e4b17023SJohn Marino default:
6503*e4b17023SJohn Marino break;
6504*e4b17023SJohn Marino }
6505*e4b17023SJohn Marino
6506*e4b17023SJohn Marino /* X does not match, so try its subexpressions. */
6507*e4b17023SJohn Marino
6508*e4b17023SJohn Marino fmt = GET_RTX_FORMAT (code);
6509*e4b17023SJohn Marino for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6510*e4b17023SJohn Marino {
6511*e4b17023SJohn Marino if (fmt[i] == 'e' && loc != &XEXP (x, i))
6512*e4b17023SJohn Marino {
6513*e4b17023SJohn Marino if (i == 0)
6514*e4b17023SJohn Marino {
6515*e4b17023SJohn Marino x = XEXP (x, 0);
6516*e4b17023SJohn Marino goto repeat;
6517*e4b17023SJohn Marino }
6518*e4b17023SJohn Marino else
6519*e4b17023SJohn Marino if (refers_to_regno_for_reload_p (regno, endregno,
6520*e4b17023SJohn Marino XEXP (x, i), loc))
6521*e4b17023SJohn Marino return 1;
6522*e4b17023SJohn Marino }
6523*e4b17023SJohn Marino else if (fmt[i] == 'E')
6524*e4b17023SJohn Marino {
6525*e4b17023SJohn Marino int j;
6526*e4b17023SJohn Marino for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6527*e4b17023SJohn Marino if (loc != &XVECEXP (x, i, j)
6528*e4b17023SJohn Marino && refers_to_regno_for_reload_p (regno, endregno,
6529*e4b17023SJohn Marino XVECEXP (x, i, j), loc))
6530*e4b17023SJohn Marino return 1;
6531*e4b17023SJohn Marino }
6532*e4b17023SJohn Marino }
6533*e4b17023SJohn Marino return 0;
6534*e4b17023SJohn Marino }
6535*e4b17023SJohn Marino
6536*e4b17023SJohn Marino /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
6537*e4b17023SJohn Marino we check if any register number in X conflicts with the relevant register
6538*e4b17023SJohn Marino numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
6539*e4b17023SJohn Marino contains a MEM (we don't bother checking for memory addresses that can't
6540*e4b17023SJohn Marino conflict because we expect this to be a rare case.
6541*e4b17023SJohn Marino
6542*e4b17023SJohn Marino This function is similar to reg_overlap_mentioned_p in rtlanal.c except
6543*e4b17023SJohn Marino that we look at equivalences for pseudos that didn't get hard registers. */
6544*e4b17023SJohn Marino
6545*e4b17023SJohn Marino int
reg_overlap_mentioned_for_reload_p(rtx x,rtx in)6546*e4b17023SJohn Marino reg_overlap_mentioned_for_reload_p (rtx x, rtx in)
6547*e4b17023SJohn Marino {
6548*e4b17023SJohn Marino int regno, endregno;
6549*e4b17023SJohn Marino
6550*e4b17023SJohn Marino /* Overly conservative. */
6551*e4b17023SJohn Marino if (GET_CODE (x) == STRICT_LOW_PART
6552*e4b17023SJohn Marino || GET_RTX_CLASS (GET_CODE (x)) == RTX_AUTOINC)
6553*e4b17023SJohn Marino x = XEXP (x, 0);
6554*e4b17023SJohn Marino
6555*e4b17023SJohn Marino /* If either argument is a constant, then modifying X can not affect IN. */
6556*e4b17023SJohn Marino if (CONSTANT_P (x) || CONSTANT_P (in))
6557*e4b17023SJohn Marino return 0;
6558*e4b17023SJohn Marino else if (GET_CODE (x) == SUBREG && MEM_P (SUBREG_REG (x)))
6559*e4b17023SJohn Marino return refers_to_mem_for_reload_p (in);
6560*e4b17023SJohn Marino else if (GET_CODE (x) == SUBREG)
6561*e4b17023SJohn Marino {
6562*e4b17023SJohn Marino regno = REGNO (SUBREG_REG (x));
6563*e4b17023SJohn Marino if (regno < FIRST_PSEUDO_REGISTER)
6564*e4b17023SJohn Marino regno += subreg_regno_offset (REGNO (SUBREG_REG (x)),
6565*e4b17023SJohn Marino GET_MODE (SUBREG_REG (x)),
6566*e4b17023SJohn Marino SUBREG_BYTE (x),
6567*e4b17023SJohn Marino GET_MODE (x));
6568*e4b17023SJohn Marino endregno = regno + (regno < FIRST_PSEUDO_REGISTER
6569*e4b17023SJohn Marino ? subreg_nregs (x) : 1);
6570*e4b17023SJohn Marino
6571*e4b17023SJohn Marino return refers_to_regno_for_reload_p (regno, endregno, in, (rtx*) 0);
6572*e4b17023SJohn Marino }
6573*e4b17023SJohn Marino else if (REG_P (x))
6574*e4b17023SJohn Marino {
6575*e4b17023SJohn Marino regno = REGNO (x);
6576*e4b17023SJohn Marino
6577*e4b17023SJohn Marino /* If this is a pseudo, it must not have been assigned a hard register.
6578*e4b17023SJohn Marino Therefore, it must either be in memory or be a constant. */
6579*e4b17023SJohn Marino
6580*e4b17023SJohn Marino if (regno >= FIRST_PSEUDO_REGISTER)
6581*e4b17023SJohn Marino {
6582*e4b17023SJohn Marino if (reg_equiv_memory_loc (regno))
6583*e4b17023SJohn Marino return refers_to_mem_for_reload_p (in);
6584*e4b17023SJohn Marino gcc_assert (reg_equiv_constant (regno));
6585*e4b17023SJohn Marino return 0;
6586*e4b17023SJohn Marino }
6587*e4b17023SJohn Marino
6588*e4b17023SJohn Marino endregno = END_HARD_REGNO (x);
6589*e4b17023SJohn Marino
6590*e4b17023SJohn Marino return refers_to_regno_for_reload_p (regno, endregno, in, (rtx*) 0);
6591*e4b17023SJohn Marino }
6592*e4b17023SJohn Marino else if (MEM_P (x))
6593*e4b17023SJohn Marino return refers_to_mem_for_reload_p (in);
6594*e4b17023SJohn Marino else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
6595*e4b17023SJohn Marino || GET_CODE (x) == CC0)
6596*e4b17023SJohn Marino return reg_mentioned_p (x, in);
6597*e4b17023SJohn Marino else
6598*e4b17023SJohn Marino {
6599*e4b17023SJohn Marino gcc_assert (GET_CODE (x) == PLUS);
6600*e4b17023SJohn Marino
6601*e4b17023SJohn Marino /* We actually want to know if X is mentioned somewhere inside IN.
6602*e4b17023SJohn Marino We must not say that (plus (sp) (const_int 124)) is in
6603*e4b17023SJohn Marino (plus (sp) (const_int 64)), since that can lead to incorrect reload
6604*e4b17023SJohn Marino allocation when spuriously changing a RELOAD_FOR_OUTPUT_ADDRESS
6605*e4b17023SJohn Marino into a RELOAD_OTHER on behalf of another RELOAD_OTHER. */
6606*e4b17023SJohn Marino while (MEM_P (in))
6607*e4b17023SJohn Marino in = XEXP (in, 0);
6608*e4b17023SJohn Marino if (REG_P (in))
6609*e4b17023SJohn Marino return 0;
6610*e4b17023SJohn Marino else if (GET_CODE (in) == PLUS)
6611*e4b17023SJohn Marino return (rtx_equal_p (x, in)
6612*e4b17023SJohn Marino || reg_overlap_mentioned_for_reload_p (x, XEXP (in, 0))
6613*e4b17023SJohn Marino || reg_overlap_mentioned_for_reload_p (x, XEXP (in, 1)));
6614*e4b17023SJohn Marino else return (reg_overlap_mentioned_for_reload_p (XEXP (x, 0), in)
6615*e4b17023SJohn Marino || reg_overlap_mentioned_for_reload_p (XEXP (x, 1), in));
6616*e4b17023SJohn Marino }
6617*e4b17023SJohn Marino
6618*e4b17023SJohn Marino gcc_unreachable ();
6619*e4b17023SJohn Marino }
6620*e4b17023SJohn Marino
6621*e4b17023SJohn Marino /* Return nonzero if anything in X contains a MEM. Look also for pseudo
6622*e4b17023SJohn Marino registers. */
6623*e4b17023SJohn Marino
6624*e4b17023SJohn Marino static int
refers_to_mem_for_reload_p(rtx x)6625*e4b17023SJohn Marino refers_to_mem_for_reload_p (rtx x)
6626*e4b17023SJohn Marino {
6627*e4b17023SJohn Marino const char *fmt;
6628*e4b17023SJohn Marino int i;
6629*e4b17023SJohn Marino
6630*e4b17023SJohn Marino if (MEM_P (x))
6631*e4b17023SJohn Marino return 1;
6632*e4b17023SJohn Marino
6633*e4b17023SJohn Marino if (REG_P (x))
6634*e4b17023SJohn Marino return (REGNO (x) >= FIRST_PSEUDO_REGISTER
6635*e4b17023SJohn Marino && reg_equiv_memory_loc (REGNO (x)));
6636*e4b17023SJohn Marino
6637*e4b17023SJohn Marino fmt = GET_RTX_FORMAT (GET_CODE (x));
6638*e4b17023SJohn Marino for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
6639*e4b17023SJohn Marino if (fmt[i] == 'e'
6640*e4b17023SJohn Marino && (MEM_P (XEXP (x, i))
6641*e4b17023SJohn Marino || refers_to_mem_for_reload_p (XEXP (x, i))))
6642*e4b17023SJohn Marino return 1;
6643*e4b17023SJohn Marino
6644*e4b17023SJohn Marino return 0;
6645*e4b17023SJohn Marino }
6646*e4b17023SJohn Marino
6647*e4b17023SJohn Marino /* Check the insns before INSN to see if there is a suitable register
6648*e4b17023SJohn Marino containing the same value as GOAL.
6649*e4b17023SJohn Marino If OTHER is -1, look for a register in class RCLASS.
6650*e4b17023SJohn Marino Otherwise, just see if register number OTHER shares GOAL's value.
6651*e4b17023SJohn Marino
6652*e4b17023SJohn Marino Return an rtx for the register found, or zero if none is found.
6653*e4b17023SJohn Marino
6654*e4b17023SJohn Marino If RELOAD_REG_P is (short *)1,
6655*e4b17023SJohn Marino we reject any hard reg that appears in reload_reg_rtx
6656*e4b17023SJohn Marino because such a hard reg is also needed coming into this insn.
6657*e4b17023SJohn Marino
6658*e4b17023SJohn Marino If RELOAD_REG_P is any other nonzero value,
6659*e4b17023SJohn Marino it is a vector indexed by hard reg number
6660*e4b17023SJohn Marino and we reject any hard reg whose element in the vector is nonnegative
6661*e4b17023SJohn Marino as well as any that appears in reload_reg_rtx.
6662*e4b17023SJohn Marino
6663*e4b17023SJohn Marino If GOAL is zero, then GOALREG is a register number; we look
6664*e4b17023SJohn Marino for an equivalent for that register.
6665*e4b17023SJohn Marino
6666*e4b17023SJohn Marino MODE is the machine mode of the value we want an equivalence for.
6667*e4b17023SJohn Marino If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
6668*e4b17023SJohn Marino
6669*e4b17023SJohn Marino This function is used by jump.c as well as in the reload pass.
6670*e4b17023SJohn Marino
6671*e4b17023SJohn Marino If GOAL is the sum of the stack pointer and a constant, we treat it
6672*e4b17023SJohn Marino as if it were a constant except that sp is required to be unchanging. */
6673*e4b17023SJohn Marino
6674*e4b17023SJohn Marino rtx
find_equiv_reg(rtx goal,rtx insn,enum reg_class rclass,int other,short * reload_reg_p,int goalreg,enum machine_mode mode)6675*e4b17023SJohn Marino find_equiv_reg (rtx goal, rtx insn, enum reg_class rclass, int other,
6676*e4b17023SJohn Marino short *reload_reg_p, int goalreg, enum machine_mode mode)
6677*e4b17023SJohn Marino {
6678*e4b17023SJohn Marino rtx p = insn;
6679*e4b17023SJohn Marino rtx goaltry, valtry, value, where;
6680*e4b17023SJohn Marino rtx pat;
6681*e4b17023SJohn Marino int regno = -1;
6682*e4b17023SJohn Marino int valueno;
6683*e4b17023SJohn Marino int goal_mem = 0;
6684*e4b17023SJohn Marino int goal_const = 0;
6685*e4b17023SJohn Marino int goal_mem_addr_varies = 0;
6686*e4b17023SJohn Marino int need_stable_sp = 0;
6687*e4b17023SJohn Marino int nregs;
6688*e4b17023SJohn Marino int valuenregs;
6689*e4b17023SJohn Marino int num = 0;
6690*e4b17023SJohn Marino
6691*e4b17023SJohn Marino if (goal == 0)
6692*e4b17023SJohn Marino regno = goalreg;
6693*e4b17023SJohn Marino else if (REG_P (goal))
6694*e4b17023SJohn Marino regno = REGNO (goal);
6695*e4b17023SJohn Marino else if (MEM_P (goal))
6696*e4b17023SJohn Marino {
6697*e4b17023SJohn Marino enum rtx_code code = GET_CODE (XEXP (goal, 0));
6698*e4b17023SJohn Marino if (MEM_VOLATILE_P (goal))
6699*e4b17023SJohn Marino return 0;
6700*e4b17023SJohn Marino if (flag_float_store && SCALAR_FLOAT_MODE_P (GET_MODE (goal)))
6701*e4b17023SJohn Marino return 0;
6702*e4b17023SJohn Marino /* An address with side effects must be reexecuted. */
6703*e4b17023SJohn Marino switch (code)
6704*e4b17023SJohn Marino {
6705*e4b17023SJohn Marino case POST_INC:
6706*e4b17023SJohn Marino case PRE_INC:
6707*e4b17023SJohn Marino case POST_DEC:
6708*e4b17023SJohn Marino case PRE_DEC:
6709*e4b17023SJohn Marino case POST_MODIFY:
6710*e4b17023SJohn Marino case PRE_MODIFY:
6711*e4b17023SJohn Marino return 0;
6712*e4b17023SJohn Marino default:
6713*e4b17023SJohn Marino break;
6714*e4b17023SJohn Marino }
6715*e4b17023SJohn Marino goal_mem = 1;
6716*e4b17023SJohn Marino }
6717*e4b17023SJohn Marino else if (CONSTANT_P (goal))
6718*e4b17023SJohn Marino goal_const = 1;
6719*e4b17023SJohn Marino else if (GET_CODE (goal) == PLUS
6720*e4b17023SJohn Marino && XEXP (goal, 0) == stack_pointer_rtx
6721*e4b17023SJohn Marino && CONSTANT_P (XEXP (goal, 1)))
6722*e4b17023SJohn Marino goal_const = need_stable_sp = 1;
6723*e4b17023SJohn Marino else if (GET_CODE (goal) == PLUS
6724*e4b17023SJohn Marino && XEXP (goal, 0) == frame_pointer_rtx
6725*e4b17023SJohn Marino && CONSTANT_P (XEXP (goal, 1)))
6726*e4b17023SJohn Marino goal_const = 1;
6727*e4b17023SJohn Marino else
6728*e4b17023SJohn Marino return 0;
6729*e4b17023SJohn Marino
6730*e4b17023SJohn Marino num = 0;
6731*e4b17023SJohn Marino /* Scan insns back from INSN, looking for one that copies
6732*e4b17023SJohn Marino a value into or out of GOAL.
6733*e4b17023SJohn Marino Stop and give up if we reach a label. */
6734*e4b17023SJohn Marino
6735*e4b17023SJohn Marino while (1)
6736*e4b17023SJohn Marino {
6737*e4b17023SJohn Marino p = PREV_INSN (p);
6738*e4b17023SJohn Marino if (p && DEBUG_INSN_P (p))
6739*e4b17023SJohn Marino continue;
6740*e4b17023SJohn Marino num++;
6741*e4b17023SJohn Marino if (p == 0 || LABEL_P (p)
6742*e4b17023SJohn Marino || num > PARAM_VALUE (PARAM_MAX_RELOAD_SEARCH_INSNS))
6743*e4b17023SJohn Marino return 0;
6744*e4b17023SJohn Marino
6745*e4b17023SJohn Marino /* Don't reuse register contents from before a setjmp-type
6746*e4b17023SJohn Marino function call; on the second return (from the longjmp) it
6747*e4b17023SJohn Marino might have been clobbered by a later reuse. It doesn't
6748*e4b17023SJohn Marino seem worthwhile to actually go and see if it is actually
6749*e4b17023SJohn Marino reused even if that information would be readily available;
6750*e4b17023SJohn Marino just don't reuse it across the setjmp call. */
6751*e4b17023SJohn Marino if (CALL_P (p) && find_reg_note (p, REG_SETJMP, NULL_RTX))
6752*e4b17023SJohn Marino return 0;
6753*e4b17023SJohn Marino
6754*e4b17023SJohn Marino if (NONJUMP_INSN_P (p)
6755*e4b17023SJohn Marino /* If we don't want spill regs ... */
6756*e4b17023SJohn Marino && (! (reload_reg_p != 0
6757*e4b17023SJohn Marino && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6758*e4b17023SJohn Marino /* ... then ignore insns introduced by reload; they aren't
6759*e4b17023SJohn Marino useful and can cause results in reload_as_needed to be
6760*e4b17023SJohn Marino different from what they were when calculating the need for
6761*e4b17023SJohn Marino spills. If we notice an input-reload insn here, we will
6762*e4b17023SJohn Marino reject it below, but it might hide a usable equivalent.
6763*e4b17023SJohn Marino That makes bad code. It may even fail: perhaps no reg was
6764*e4b17023SJohn Marino spilled for this insn because it was assumed we would find
6765*e4b17023SJohn Marino that equivalent. */
6766*e4b17023SJohn Marino || INSN_UID (p) < reload_first_uid))
6767*e4b17023SJohn Marino {
6768*e4b17023SJohn Marino rtx tem;
6769*e4b17023SJohn Marino pat = single_set (p);
6770*e4b17023SJohn Marino
6771*e4b17023SJohn Marino /* First check for something that sets some reg equal to GOAL. */
6772*e4b17023SJohn Marino if (pat != 0
6773*e4b17023SJohn Marino && ((regno >= 0
6774*e4b17023SJohn Marino && true_regnum (SET_SRC (pat)) == regno
6775*e4b17023SJohn Marino && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6776*e4b17023SJohn Marino ||
6777*e4b17023SJohn Marino (regno >= 0
6778*e4b17023SJohn Marino && true_regnum (SET_DEST (pat)) == regno
6779*e4b17023SJohn Marino && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
6780*e4b17023SJohn Marino ||
6781*e4b17023SJohn Marino (goal_const && rtx_equal_p (SET_SRC (pat), goal)
6782*e4b17023SJohn Marino /* When looking for stack pointer + const,
6783*e4b17023SJohn Marino make sure we don't use a stack adjust. */
6784*e4b17023SJohn Marino && !reg_overlap_mentioned_for_reload_p (SET_DEST (pat), goal)
6785*e4b17023SJohn Marino && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6786*e4b17023SJohn Marino || (goal_mem
6787*e4b17023SJohn Marino && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
6788*e4b17023SJohn Marino && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
6789*e4b17023SJohn Marino || (goal_mem
6790*e4b17023SJohn Marino && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
6791*e4b17023SJohn Marino && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
6792*e4b17023SJohn Marino /* If we are looking for a constant,
6793*e4b17023SJohn Marino and something equivalent to that constant was copied
6794*e4b17023SJohn Marino into a reg, we can use that reg. */
6795*e4b17023SJohn Marino || (goal_const && REG_NOTES (p) != 0
6796*e4b17023SJohn Marino && (tem = find_reg_note (p, REG_EQUIV, NULL_RTX))
6797*e4b17023SJohn Marino && ((rtx_equal_p (XEXP (tem, 0), goal)
6798*e4b17023SJohn Marino && (valueno
6799*e4b17023SJohn Marino = true_regnum (valtry = SET_DEST (pat))) >= 0)
6800*e4b17023SJohn Marino || (REG_P (SET_DEST (pat))
6801*e4b17023SJohn Marino && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6802*e4b17023SJohn Marino && SCALAR_FLOAT_MODE_P (GET_MODE (XEXP (tem, 0)))
6803*e4b17023SJohn Marino && CONST_INT_P (goal)
6804*e4b17023SJohn Marino && 0 != (goaltry
6805*e4b17023SJohn Marino = operand_subword (XEXP (tem, 0), 0, 0,
6806*e4b17023SJohn Marino VOIDmode))
6807*e4b17023SJohn Marino && rtx_equal_p (goal, goaltry)
6808*e4b17023SJohn Marino && (valtry
6809*e4b17023SJohn Marino = operand_subword (SET_DEST (pat), 0, 0,
6810*e4b17023SJohn Marino VOIDmode))
6811*e4b17023SJohn Marino && (valueno = true_regnum (valtry)) >= 0)))
6812*e4b17023SJohn Marino || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
6813*e4b17023SJohn Marino NULL_RTX))
6814*e4b17023SJohn Marino && REG_P (SET_DEST (pat))
6815*e4b17023SJohn Marino && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6816*e4b17023SJohn Marino && SCALAR_FLOAT_MODE_P (GET_MODE (XEXP (tem, 0)))
6817*e4b17023SJohn Marino && CONST_INT_P (goal)
6818*e4b17023SJohn Marino && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0,
6819*e4b17023SJohn Marino VOIDmode))
6820*e4b17023SJohn Marino && rtx_equal_p (goal, goaltry)
6821*e4b17023SJohn Marino && (valtry
6822*e4b17023SJohn Marino = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
6823*e4b17023SJohn Marino && (valueno = true_regnum (valtry)) >= 0)))
6824*e4b17023SJohn Marino {
6825*e4b17023SJohn Marino if (other >= 0)
6826*e4b17023SJohn Marino {
6827*e4b17023SJohn Marino if (valueno != other)
6828*e4b17023SJohn Marino continue;
6829*e4b17023SJohn Marino }
6830*e4b17023SJohn Marino else if ((unsigned) valueno >= FIRST_PSEUDO_REGISTER)
6831*e4b17023SJohn Marino continue;
6832*e4b17023SJohn Marino else if (!in_hard_reg_set_p (reg_class_contents[(int) rclass],
6833*e4b17023SJohn Marino mode, valueno))
6834*e4b17023SJohn Marino continue;
6835*e4b17023SJohn Marino value = valtry;
6836*e4b17023SJohn Marino where = p;
6837*e4b17023SJohn Marino break;
6838*e4b17023SJohn Marino }
6839*e4b17023SJohn Marino }
6840*e4b17023SJohn Marino }
6841*e4b17023SJohn Marino
6842*e4b17023SJohn Marino /* We found a previous insn copying GOAL into a suitable other reg VALUE
6843*e4b17023SJohn Marino (or copying VALUE into GOAL, if GOAL is also a register).
6844*e4b17023SJohn Marino Now verify that VALUE is really valid. */
6845*e4b17023SJohn Marino
6846*e4b17023SJohn Marino /* VALUENO is the register number of VALUE; a hard register. */
6847*e4b17023SJohn Marino
6848*e4b17023SJohn Marino /* Don't try to re-use something that is killed in this insn. We want
6849*e4b17023SJohn Marino to be able to trust REG_UNUSED notes. */
6850*e4b17023SJohn Marino if (REG_NOTES (where) != 0 && find_reg_note (where, REG_UNUSED, value))
6851*e4b17023SJohn Marino return 0;
6852*e4b17023SJohn Marino
6853*e4b17023SJohn Marino /* If we propose to get the value from the stack pointer or if GOAL is
6854*e4b17023SJohn Marino a MEM based on the stack pointer, we need a stable SP. */
6855*e4b17023SJohn Marino if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM
6856*e4b17023SJohn Marino || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
6857*e4b17023SJohn Marino goal)))
6858*e4b17023SJohn Marino need_stable_sp = 1;
6859*e4b17023SJohn Marino
6860*e4b17023SJohn Marino /* Reject VALUE if the copy-insn moved the wrong sort of datum. */
6861*e4b17023SJohn Marino if (GET_MODE (value) != mode)
6862*e4b17023SJohn Marino return 0;
6863*e4b17023SJohn Marino
6864*e4b17023SJohn Marino /* Reject VALUE if it was loaded from GOAL
6865*e4b17023SJohn Marino and is also a register that appears in the address of GOAL. */
6866*e4b17023SJohn Marino
6867*e4b17023SJohn Marino if (goal_mem && value == SET_DEST (single_set (where))
6868*e4b17023SJohn Marino && refers_to_regno_for_reload_p (valueno, end_hard_regno (mode, valueno),
6869*e4b17023SJohn Marino goal, (rtx*) 0))
6870*e4b17023SJohn Marino return 0;
6871*e4b17023SJohn Marino
6872*e4b17023SJohn Marino /* Reject registers that overlap GOAL. */
6873*e4b17023SJohn Marino
6874*e4b17023SJohn Marino if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
6875*e4b17023SJohn Marino nregs = hard_regno_nregs[regno][mode];
6876*e4b17023SJohn Marino else
6877*e4b17023SJohn Marino nregs = 1;
6878*e4b17023SJohn Marino valuenregs = hard_regno_nregs[valueno][mode];
6879*e4b17023SJohn Marino
6880*e4b17023SJohn Marino if (!goal_mem && !goal_const
6881*e4b17023SJohn Marino && regno + nregs > valueno && regno < valueno + valuenregs)
6882*e4b17023SJohn Marino return 0;
6883*e4b17023SJohn Marino
6884*e4b17023SJohn Marino /* Reject VALUE if it is one of the regs reserved for reloads.
6885*e4b17023SJohn Marino Reload1 knows how to reuse them anyway, and it would get
6886*e4b17023SJohn Marino confused if we allocated one without its knowledge.
6887*e4b17023SJohn Marino (Now that insns introduced by reload are ignored above,
6888*e4b17023SJohn Marino this case shouldn't happen, but I'm not positive.) */
6889*e4b17023SJohn Marino
6890*e4b17023SJohn Marino if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6891*e4b17023SJohn Marino {
6892*e4b17023SJohn Marino int i;
6893*e4b17023SJohn Marino for (i = 0; i < valuenregs; ++i)
6894*e4b17023SJohn Marino if (reload_reg_p[valueno + i] >= 0)
6895*e4b17023SJohn Marino return 0;
6896*e4b17023SJohn Marino }
6897*e4b17023SJohn Marino
6898*e4b17023SJohn Marino /* Reject VALUE if it is a register being used for an input reload
6899*e4b17023SJohn Marino even if it is not one of those reserved. */
6900*e4b17023SJohn Marino
6901*e4b17023SJohn Marino if (reload_reg_p != 0)
6902*e4b17023SJohn Marino {
6903*e4b17023SJohn Marino int i;
6904*e4b17023SJohn Marino for (i = 0; i < n_reloads; i++)
6905*e4b17023SJohn Marino if (rld[i].reg_rtx != 0 && rld[i].in)
6906*e4b17023SJohn Marino {
6907*e4b17023SJohn Marino int regno1 = REGNO (rld[i].reg_rtx);
6908*e4b17023SJohn Marino int nregs1 = hard_regno_nregs[regno1]
6909*e4b17023SJohn Marino [GET_MODE (rld[i].reg_rtx)];
6910*e4b17023SJohn Marino if (regno1 < valueno + valuenregs
6911*e4b17023SJohn Marino && regno1 + nregs1 > valueno)
6912*e4b17023SJohn Marino return 0;
6913*e4b17023SJohn Marino }
6914*e4b17023SJohn Marino }
6915*e4b17023SJohn Marino
6916*e4b17023SJohn Marino if (goal_mem)
6917*e4b17023SJohn Marino /* We must treat frame pointer as varying here,
6918*e4b17023SJohn Marino since it can vary--in a nonlocal goto as generated by expand_goto. */
6919*e4b17023SJohn Marino goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0));
6920*e4b17023SJohn Marino
6921*e4b17023SJohn Marino /* Now verify that the values of GOAL and VALUE remain unaltered
6922*e4b17023SJohn Marino until INSN is reached. */
6923*e4b17023SJohn Marino
6924*e4b17023SJohn Marino p = insn;
6925*e4b17023SJohn Marino while (1)
6926*e4b17023SJohn Marino {
6927*e4b17023SJohn Marino p = PREV_INSN (p);
6928*e4b17023SJohn Marino if (p == where)
6929*e4b17023SJohn Marino return value;
6930*e4b17023SJohn Marino
6931*e4b17023SJohn Marino /* Don't trust the conversion past a function call
6932*e4b17023SJohn Marino if either of the two is in a call-clobbered register, or memory. */
6933*e4b17023SJohn Marino if (CALL_P (p))
6934*e4b17023SJohn Marino {
6935*e4b17023SJohn Marino int i;
6936*e4b17023SJohn Marino
6937*e4b17023SJohn Marino if (goal_mem || need_stable_sp)
6938*e4b17023SJohn Marino return 0;
6939*e4b17023SJohn Marino
6940*e4b17023SJohn Marino if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
6941*e4b17023SJohn Marino for (i = 0; i < nregs; ++i)
6942*e4b17023SJohn Marino if (call_used_regs[regno + i]
6943*e4b17023SJohn Marino || HARD_REGNO_CALL_PART_CLOBBERED (regno + i, mode))
6944*e4b17023SJohn Marino return 0;
6945*e4b17023SJohn Marino
6946*e4b17023SJohn Marino if (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER)
6947*e4b17023SJohn Marino for (i = 0; i < valuenregs; ++i)
6948*e4b17023SJohn Marino if (call_used_regs[valueno + i]
6949*e4b17023SJohn Marino || HARD_REGNO_CALL_PART_CLOBBERED (valueno + i, mode))
6950*e4b17023SJohn Marino return 0;
6951*e4b17023SJohn Marino }
6952*e4b17023SJohn Marino
6953*e4b17023SJohn Marino if (INSN_P (p))
6954*e4b17023SJohn Marino {
6955*e4b17023SJohn Marino pat = PATTERN (p);
6956*e4b17023SJohn Marino
6957*e4b17023SJohn Marino /* Watch out for unspec_volatile, and volatile asms. */
6958*e4b17023SJohn Marino if (volatile_insn_p (pat))
6959*e4b17023SJohn Marino return 0;
6960*e4b17023SJohn Marino
6961*e4b17023SJohn Marino /* If this insn P stores in either GOAL or VALUE, return 0.
6962*e4b17023SJohn Marino If GOAL is a memory ref and this insn writes memory, return 0.
6963*e4b17023SJohn Marino If GOAL is a memory ref and its address is not constant,
6964*e4b17023SJohn Marino and this insn P changes a register used in GOAL, return 0. */
6965*e4b17023SJohn Marino
6966*e4b17023SJohn Marino if (GET_CODE (pat) == COND_EXEC)
6967*e4b17023SJohn Marino pat = COND_EXEC_CODE (pat);
6968*e4b17023SJohn Marino if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
6969*e4b17023SJohn Marino {
6970*e4b17023SJohn Marino rtx dest = SET_DEST (pat);
6971*e4b17023SJohn Marino while (GET_CODE (dest) == SUBREG
6972*e4b17023SJohn Marino || GET_CODE (dest) == ZERO_EXTRACT
6973*e4b17023SJohn Marino || GET_CODE (dest) == STRICT_LOW_PART)
6974*e4b17023SJohn Marino dest = XEXP (dest, 0);
6975*e4b17023SJohn Marino if (REG_P (dest))
6976*e4b17023SJohn Marino {
6977*e4b17023SJohn Marino int xregno = REGNO (dest);
6978*e4b17023SJohn Marino int xnregs;
6979*e4b17023SJohn Marino if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6980*e4b17023SJohn Marino xnregs = hard_regno_nregs[xregno][GET_MODE (dest)];
6981*e4b17023SJohn Marino else
6982*e4b17023SJohn Marino xnregs = 1;
6983*e4b17023SJohn Marino if (xregno < regno + nregs && xregno + xnregs > regno)
6984*e4b17023SJohn Marino return 0;
6985*e4b17023SJohn Marino if (xregno < valueno + valuenregs
6986*e4b17023SJohn Marino && xregno + xnregs > valueno)
6987*e4b17023SJohn Marino return 0;
6988*e4b17023SJohn Marino if (goal_mem_addr_varies
6989*e4b17023SJohn Marino && reg_overlap_mentioned_for_reload_p (dest, goal))
6990*e4b17023SJohn Marino return 0;
6991*e4b17023SJohn Marino if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6992*e4b17023SJohn Marino return 0;
6993*e4b17023SJohn Marino }
6994*e4b17023SJohn Marino else if (goal_mem && MEM_P (dest)
6995*e4b17023SJohn Marino && ! push_operand (dest, GET_MODE (dest)))
6996*e4b17023SJohn Marino return 0;
6997*e4b17023SJohn Marino else if (MEM_P (dest) && regno >= FIRST_PSEUDO_REGISTER
6998*e4b17023SJohn Marino && reg_equiv_memory_loc (regno) != 0)
6999*e4b17023SJohn Marino return 0;
7000*e4b17023SJohn Marino else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
7001*e4b17023SJohn Marino return 0;
7002*e4b17023SJohn Marino }
7003*e4b17023SJohn Marino else if (GET_CODE (pat) == PARALLEL)
7004*e4b17023SJohn Marino {
7005*e4b17023SJohn Marino int i;
7006*e4b17023SJohn Marino for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
7007*e4b17023SJohn Marino {
7008*e4b17023SJohn Marino rtx v1 = XVECEXP (pat, 0, i);
7009*e4b17023SJohn Marino if (GET_CODE (v1) == COND_EXEC)
7010*e4b17023SJohn Marino v1 = COND_EXEC_CODE (v1);
7011*e4b17023SJohn Marino if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
7012*e4b17023SJohn Marino {
7013*e4b17023SJohn Marino rtx dest = SET_DEST (v1);
7014*e4b17023SJohn Marino while (GET_CODE (dest) == SUBREG
7015*e4b17023SJohn Marino || GET_CODE (dest) == ZERO_EXTRACT
7016*e4b17023SJohn Marino || GET_CODE (dest) == STRICT_LOW_PART)
7017*e4b17023SJohn Marino dest = XEXP (dest, 0);
7018*e4b17023SJohn Marino if (REG_P (dest))
7019*e4b17023SJohn Marino {
7020*e4b17023SJohn Marino int xregno = REGNO (dest);
7021*e4b17023SJohn Marino int xnregs;
7022*e4b17023SJohn Marino if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
7023*e4b17023SJohn Marino xnregs = hard_regno_nregs[xregno][GET_MODE (dest)];
7024*e4b17023SJohn Marino else
7025*e4b17023SJohn Marino xnregs = 1;
7026*e4b17023SJohn Marino if (xregno < regno + nregs
7027*e4b17023SJohn Marino && xregno + xnregs > regno)
7028*e4b17023SJohn Marino return 0;
7029*e4b17023SJohn Marino if (xregno < valueno + valuenregs
7030*e4b17023SJohn Marino && xregno + xnregs > valueno)
7031*e4b17023SJohn Marino return 0;
7032*e4b17023SJohn Marino if (goal_mem_addr_varies
7033*e4b17023SJohn Marino && reg_overlap_mentioned_for_reload_p (dest,
7034*e4b17023SJohn Marino goal))
7035*e4b17023SJohn Marino return 0;
7036*e4b17023SJohn Marino if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
7037*e4b17023SJohn Marino return 0;
7038*e4b17023SJohn Marino }
7039*e4b17023SJohn Marino else if (goal_mem && MEM_P (dest)
7040*e4b17023SJohn Marino && ! push_operand (dest, GET_MODE (dest)))
7041*e4b17023SJohn Marino return 0;
7042*e4b17023SJohn Marino else if (MEM_P (dest) && regno >= FIRST_PSEUDO_REGISTER
7043*e4b17023SJohn Marino && reg_equiv_memory_loc (regno) != 0)
7044*e4b17023SJohn Marino return 0;
7045*e4b17023SJohn Marino else if (need_stable_sp
7046*e4b17023SJohn Marino && push_operand (dest, GET_MODE (dest)))
7047*e4b17023SJohn Marino return 0;
7048*e4b17023SJohn Marino }
7049*e4b17023SJohn Marino }
7050*e4b17023SJohn Marino }
7051*e4b17023SJohn Marino
7052*e4b17023SJohn Marino if (CALL_P (p) && CALL_INSN_FUNCTION_USAGE (p))
7053*e4b17023SJohn Marino {
7054*e4b17023SJohn Marino rtx link;
7055*e4b17023SJohn Marino
7056*e4b17023SJohn Marino for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0;
7057*e4b17023SJohn Marino link = XEXP (link, 1))
7058*e4b17023SJohn Marino {
7059*e4b17023SJohn Marino pat = XEXP (link, 0);
7060*e4b17023SJohn Marino if (GET_CODE (pat) == CLOBBER)
7061*e4b17023SJohn Marino {
7062*e4b17023SJohn Marino rtx dest = SET_DEST (pat);
7063*e4b17023SJohn Marino
7064*e4b17023SJohn Marino if (REG_P (dest))
7065*e4b17023SJohn Marino {
7066*e4b17023SJohn Marino int xregno = REGNO (dest);
7067*e4b17023SJohn Marino int xnregs
7068*e4b17023SJohn Marino = hard_regno_nregs[xregno][GET_MODE (dest)];
7069*e4b17023SJohn Marino
7070*e4b17023SJohn Marino if (xregno < regno + nregs
7071*e4b17023SJohn Marino && xregno + xnregs > regno)
7072*e4b17023SJohn Marino return 0;
7073*e4b17023SJohn Marino else if (xregno < valueno + valuenregs
7074*e4b17023SJohn Marino && xregno + xnregs > valueno)
7075*e4b17023SJohn Marino return 0;
7076*e4b17023SJohn Marino else if (goal_mem_addr_varies
7077*e4b17023SJohn Marino && reg_overlap_mentioned_for_reload_p (dest,
7078*e4b17023SJohn Marino goal))
7079*e4b17023SJohn Marino return 0;
7080*e4b17023SJohn Marino }
7081*e4b17023SJohn Marino
7082*e4b17023SJohn Marino else if (goal_mem && MEM_P (dest)
7083*e4b17023SJohn Marino && ! push_operand (dest, GET_MODE (dest)))
7084*e4b17023SJohn Marino return 0;
7085*e4b17023SJohn Marino else if (need_stable_sp
7086*e4b17023SJohn Marino && push_operand (dest, GET_MODE (dest)))
7087*e4b17023SJohn Marino return 0;
7088*e4b17023SJohn Marino }
7089*e4b17023SJohn Marino }
7090*e4b17023SJohn Marino }
7091*e4b17023SJohn Marino
7092*e4b17023SJohn Marino #ifdef AUTO_INC_DEC
7093*e4b17023SJohn Marino /* If this insn auto-increments or auto-decrements
7094*e4b17023SJohn Marino either regno or valueno, return 0 now.
7095*e4b17023SJohn Marino If GOAL is a memory ref and its address is not constant,
7096*e4b17023SJohn Marino and this insn P increments a register used in GOAL, return 0. */
7097*e4b17023SJohn Marino {
7098*e4b17023SJohn Marino rtx link;
7099*e4b17023SJohn Marino
7100*e4b17023SJohn Marino for (link = REG_NOTES (p); link; link = XEXP (link, 1))
7101*e4b17023SJohn Marino if (REG_NOTE_KIND (link) == REG_INC
7102*e4b17023SJohn Marino && REG_P (XEXP (link, 0)))
7103*e4b17023SJohn Marino {
7104*e4b17023SJohn Marino int incno = REGNO (XEXP (link, 0));
7105*e4b17023SJohn Marino if (incno < regno + nregs && incno >= regno)
7106*e4b17023SJohn Marino return 0;
7107*e4b17023SJohn Marino if (incno < valueno + valuenregs && incno >= valueno)
7108*e4b17023SJohn Marino return 0;
7109*e4b17023SJohn Marino if (goal_mem_addr_varies
7110*e4b17023SJohn Marino && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
7111*e4b17023SJohn Marino goal))
7112*e4b17023SJohn Marino return 0;
7113*e4b17023SJohn Marino }
7114*e4b17023SJohn Marino }
7115*e4b17023SJohn Marino #endif
7116*e4b17023SJohn Marino }
7117*e4b17023SJohn Marino }
7118*e4b17023SJohn Marino }
7119*e4b17023SJohn Marino
7120*e4b17023SJohn Marino /* Find a place where INCED appears in an increment or decrement operator
7121*e4b17023SJohn Marino within X, and return the amount INCED is incremented or decremented by.
7122*e4b17023SJohn Marino The value is always positive. */
7123*e4b17023SJohn Marino
7124*e4b17023SJohn Marino static int
find_inc_amount(rtx x,rtx inced)7125*e4b17023SJohn Marino find_inc_amount (rtx x, rtx inced)
7126*e4b17023SJohn Marino {
7127*e4b17023SJohn Marino enum rtx_code code = GET_CODE (x);
7128*e4b17023SJohn Marino const char *fmt;
7129*e4b17023SJohn Marino int i;
7130*e4b17023SJohn Marino
7131*e4b17023SJohn Marino if (code == MEM)
7132*e4b17023SJohn Marino {
7133*e4b17023SJohn Marino rtx addr = XEXP (x, 0);
7134*e4b17023SJohn Marino if ((GET_CODE (addr) == PRE_DEC
7135*e4b17023SJohn Marino || GET_CODE (addr) == POST_DEC
7136*e4b17023SJohn Marino || GET_CODE (addr) == PRE_INC
7137*e4b17023SJohn Marino || GET_CODE (addr) == POST_INC)
7138*e4b17023SJohn Marino && XEXP (addr, 0) == inced)
7139*e4b17023SJohn Marino return GET_MODE_SIZE (GET_MODE (x));
7140*e4b17023SJohn Marino else if ((GET_CODE (addr) == PRE_MODIFY
7141*e4b17023SJohn Marino || GET_CODE (addr) == POST_MODIFY)
7142*e4b17023SJohn Marino && GET_CODE (XEXP (addr, 1)) == PLUS
7143*e4b17023SJohn Marino && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
7144*e4b17023SJohn Marino && XEXP (addr, 0) == inced
7145*e4b17023SJohn Marino && CONST_INT_P (XEXP (XEXP (addr, 1), 1)))
7146*e4b17023SJohn Marino {
7147*e4b17023SJohn Marino i = INTVAL (XEXP (XEXP (addr, 1), 1));
7148*e4b17023SJohn Marino return i < 0 ? -i : i;
7149*e4b17023SJohn Marino }
7150*e4b17023SJohn Marino }
7151*e4b17023SJohn Marino
7152*e4b17023SJohn Marino fmt = GET_RTX_FORMAT (code);
7153*e4b17023SJohn Marino for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
7154*e4b17023SJohn Marino {
7155*e4b17023SJohn Marino if (fmt[i] == 'e')
7156*e4b17023SJohn Marino {
7157*e4b17023SJohn Marino int tem = find_inc_amount (XEXP (x, i), inced);
7158*e4b17023SJohn Marino if (tem != 0)
7159*e4b17023SJohn Marino return tem;
7160*e4b17023SJohn Marino }
7161*e4b17023SJohn Marino if (fmt[i] == 'E')
7162*e4b17023SJohn Marino {
7163*e4b17023SJohn Marino int j;
7164*e4b17023SJohn Marino for (j = XVECLEN (x, i) - 1; j >= 0; j--)
7165*e4b17023SJohn Marino {
7166*e4b17023SJohn Marino int tem = find_inc_amount (XVECEXP (x, i, j), inced);
7167*e4b17023SJohn Marino if (tem != 0)
7168*e4b17023SJohn Marino return tem;
7169*e4b17023SJohn Marino }
7170*e4b17023SJohn Marino }
7171*e4b17023SJohn Marino }
7172*e4b17023SJohn Marino
7173*e4b17023SJohn Marino return 0;
7174*e4b17023SJohn Marino }
7175*e4b17023SJohn Marino
7176*e4b17023SJohn Marino /* Return 1 if registers from REGNO to ENDREGNO are the subjects of a
7177*e4b17023SJohn Marino REG_INC note in insn INSN. REGNO must refer to a hard register. */
7178*e4b17023SJohn Marino
7179*e4b17023SJohn Marino #ifdef AUTO_INC_DEC
7180*e4b17023SJohn Marino static int
reg_inc_found_and_valid_p(unsigned int regno,unsigned int endregno,rtx insn)7181*e4b17023SJohn Marino reg_inc_found_and_valid_p (unsigned int regno, unsigned int endregno,
7182*e4b17023SJohn Marino rtx insn)
7183*e4b17023SJohn Marino {
7184*e4b17023SJohn Marino rtx link;
7185*e4b17023SJohn Marino
7186*e4b17023SJohn Marino gcc_assert (insn);
7187*e4b17023SJohn Marino
7188*e4b17023SJohn Marino if (! INSN_P (insn))
7189*e4b17023SJohn Marino return 0;
7190*e4b17023SJohn Marino
7191*e4b17023SJohn Marino for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
7192*e4b17023SJohn Marino if (REG_NOTE_KIND (link) == REG_INC)
7193*e4b17023SJohn Marino {
7194*e4b17023SJohn Marino unsigned int test = (int) REGNO (XEXP (link, 0));
7195*e4b17023SJohn Marino if (test >= regno && test < endregno)
7196*e4b17023SJohn Marino return 1;
7197*e4b17023SJohn Marino }
7198*e4b17023SJohn Marino return 0;
7199*e4b17023SJohn Marino }
7200*e4b17023SJohn Marino #else
7201*e4b17023SJohn Marino
7202*e4b17023SJohn Marino #define reg_inc_found_and_valid_p(regno,endregno,insn) 0
7203*e4b17023SJohn Marino
7204*e4b17023SJohn Marino #endif
7205*e4b17023SJohn Marino
7206*e4b17023SJohn Marino /* Return 1 if register REGNO is the subject of a clobber in insn INSN.
7207*e4b17023SJohn Marino If SETS is 1, also consider SETs. If SETS is 2, enable checking
7208*e4b17023SJohn Marino REG_INC. REGNO must refer to a hard register. */
7209*e4b17023SJohn Marino
7210*e4b17023SJohn Marino int
regno_clobbered_p(unsigned int regno,rtx insn,enum machine_mode mode,int sets)7211*e4b17023SJohn Marino regno_clobbered_p (unsigned int regno, rtx insn, enum machine_mode mode,
7212*e4b17023SJohn Marino int sets)
7213*e4b17023SJohn Marino {
7214*e4b17023SJohn Marino unsigned int nregs, endregno;
7215*e4b17023SJohn Marino
7216*e4b17023SJohn Marino /* regno must be a hard register. */
7217*e4b17023SJohn Marino gcc_assert (regno < FIRST_PSEUDO_REGISTER);
7218*e4b17023SJohn Marino
7219*e4b17023SJohn Marino nregs = hard_regno_nregs[regno][mode];
7220*e4b17023SJohn Marino endregno = regno + nregs;
7221*e4b17023SJohn Marino
7222*e4b17023SJohn Marino if ((GET_CODE (PATTERN (insn)) == CLOBBER
7223*e4b17023SJohn Marino || (sets == 1 && GET_CODE (PATTERN (insn)) == SET))
7224*e4b17023SJohn Marino && REG_P (XEXP (PATTERN (insn), 0)))
7225*e4b17023SJohn Marino {
7226*e4b17023SJohn Marino unsigned int test = REGNO (XEXP (PATTERN (insn), 0));
7227*e4b17023SJohn Marino
7228*e4b17023SJohn Marino return test >= regno && test < endregno;
7229*e4b17023SJohn Marino }
7230*e4b17023SJohn Marino
7231*e4b17023SJohn Marino if (sets == 2 && reg_inc_found_and_valid_p (regno, endregno, insn))
7232*e4b17023SJohn Marino return 1;
7233*e4b17023SJohn Marino
7234*e4b17023SJohn Marino if (GET_CODE (PATTERN (insn)) == PARALLEL)
7235*e4b17023SJohn Marino {
7236*e4b17023SJohn Marino int i = XVECLEN (PATTERN (insn), 0) - 1;
7237*e4b17023SJohn Marino
7238*e4b17023SJohn Marino for (; i >= 0; i--)
7239*e4b17023SJohn Marino {
7240*e4b17023SJohn Marino rtx elt = XVECEXP (PATTERN (insn), 0, i);
7241*e4b17023SJohn Marino if ((GET_CODE (elt) == CLOBBER
7242*e4b17023SJohn Marino || (sets == 1 && GET_CODE (elt) == SET))
7243*e4b17023SJohn Marino && REG_P (XEXP (elt, 0)))
7244*e4b17023SJohn Marino {
7245*e4b17023SJohn Marino unsigned int test = REGNO (XEXP (elt, 0));
7246*e4b17023SJohn Marino
7247*e4b17023SJohn Marino if (test >= regno && test < endregno)
7248*e4b17023SJohn Marino return 1;
7249*e4b17023SJohn Marino }
7250*e4b17023SJohn Marino if (sets == 2
7251*e4b17023SJohn Marino && reg_inc_found_and_valid_p (regno, endregno, elt))
7252*e4b17023SJohn Marino return 1;
7253*e4b17023SJohn Marino }
7254*e4b17023SJohn Marino }
7255*e4b17023SJohn Marino
7256*e4b17023SJohn Marino return 0;
7257*e4b17023SJohn Marino }
7258*e4b17023SJohn Marino
7259*e4b17023SJohn Marino /* Find the low part, with mode MODE, of a hard regno RELOADREG. */
7260*e4b17023SJohn Marino rtx
reload_adjust_reg_for_mode(rtx reloadreg,enum machine_mode mode)7261*e4b17023SJohn Marino reload_adjust_reg_for_mode (rtx reloadreg, enum machine_mode mode)
7262*e4b17023SJohn Marino {
7263*e4b17023SJohn Marino int regno;
7264*e4b17023SJohn Marino
7265*e4b17023SJohn Marino if (GET_MODE (reloadreg) == mode)
7266*e4b17023SJohn Marino return reloadreg;
7267*e4b17023SJohn Marino
7268*e4b17023SJohn Marino regno = REGNO (reloadreg);
7269*e4b17023SJohn Marino
7270*e4b17023SJohn Marino if (REG_WORDS_BIG_ENDIAN)
7271*e4b17023SJohn Marino regno += (int) hard_regno_nregs[regno][GET_MODE (reloadreg)]
7272*e4b17023SJohn Marino - (int) hard_regno_nregs[regno][mode];
7273*e4b17023SJohn Marino
7274*e4b17023SJohn Marino return gen_rtx_REG (mode, regno);
7275*e4b17023SJohn Marino }
7276*e4b17023SJohn Marino
7277*e4b17023SJohn Marino static const char *const reload_when_needed_name[] =
7278*e4b17023SJohn Marino {
7279*e4b17023SJohn Marino "RELOAD_FOR_INPUT",
7280*e4b17023SJohn Marino "RELOAD_FOR_OUTPUT",
7281*e4b17023SJohn Marino "RELOAD_FOR_INSN",
7282*e4b17023SJohn Marino "RELOAD_FOR_INPUT_ADDRESS",
7283*e4b17023SJohn Marino "RELOAD_FOR_INPADDR_ADDRESS",
7284*e4b17023SJohn Marino "RELOAD_FOR_OUTPUT_ADDRESS",
7285*e4b17023SJohn Marino "RELOAD_FOR_OUTADDR_ADDRESS",
7286*e4b17023SJohn Marino "RELOAD_FOR_OPERAND_ADDRESS",
7287*e4b17023SJohn Marino "RELOAD_FOR_OPADDR_ADDR",
7288*e4b17023SJohn Marino "RELOAD_OTHER",
7289*e4b17023SJohn Marino "RELOAD_FOR_OTHER_ADDRESS"
7290*e4b17023SJohn Marino };
7291*e4b17023SJohn Marino
7292*e4b17023SJohn Marino /* These functions are used to print the variables set by 'find_reloads' */
7293*e4b17023SJohn Marino
7294*e4b17023SJohn Marino DEBUG_FUNCTION void
debug_reload_to_stream(FILE * f)7295*e4b17023SJohn Marino debug_reload_to_stream (FILE *f)
7296*e4b17023SJohn Marino {
7297*e4b17023SJohn Marino int r;
7298*e4b17023SJohn Marino const char *prefix;
7299*e4b17023SJohn Marino
7300*e4b17023SJohn Marino if (! f)
7301*e4b17023SJohn Marino f = stderr;
7302*e4b17023SJohn Marino for (r = 0; r < n_reloads; r++)
7303*e4b17023SJohn Marino {
7304*e4b17023SJohn Marino fprintf (f, "Reload %d: ", r);
7305*e4b17023SJohn Marino
7306*e4b17023SJohn Marino if (rld[r].in != 0)
7307*e4b17023SJohn Marino {
7308*e4b17023SJohn Marino fprintf (f, "reload_in (%s) = ",
7309*e4b17023SJohn Marino GET_MODE_NAME (rld[r].inmode));
7310*e4b17023SJohn Marino print_inline_rtx (f, rld[r].in, 24);
7311*e4b17023SJohn Marino fprintf (f, "\n\t");
7312*e4b17023SJohn Marino }
7313*e4b17023SJohn Marino
7314*e4b17023SJohn Marino if (rld[r].out != 0)
7315*e4b17023SJohn Marino {
7316*e4b17023SJohn Marino fprintf (f, "reload_out (%s) = ",
7317*e4b17023SJohn Marino GET_MODE_NAME (rld[r].outmode));
7318*e4b17023SJohn Marino print_inline_rtx (f, rld[r].out, 24);
7319*e4b17023SJohn Marino fprintf (f, "\n\t");
7320*e4b17023SJohn Marino }
7321*e4b17023SJohn Marino
7322*e4b17023SJohn Marino fprintf (f, "%s, ", reg_class_names[(int) rld[r].rclass]);
7323*e4b17023SJohn Marino
7324*e4b17023SJohn Marino fprintf (f, "%s (opnum = %d)",
7325*e4b17023SJohn Marino reload_when_needed_name[(int) rld[r].when_needed],
7326*e4b17023SJohn Marino rld[r].opnum);
7327*e4b17023SJohn Marino
7328*e4b17023SJohn Marino if (rld[r].optional)
7329*e4b17023SJohn Marino fprintf (f, ", optional");
7330*e4b17023SJohn Marino
7331*e4b17023SJohn Marino if (rld[r].nongroup)
7332*e4b17023SJohn Marino fprintf (f, ", nongroup");
7333*e4b17023SJohn Marino
7334*e4b17023SJohn Marino if (rld[r].inc != 0)
7335*e4b17023SJohn Marino fprintf (f, ", inc by %d", rld[r].inc);
7336*e4b17023SJohn Marino
7337*e4b17023SJohn Marino if (rld[r].nocombine)
7338*e4b17023SJohn Marino fprintf (f, ", can't combine");
7339*e4b17023SJohn Marino
7340*e4b17023SJohn Marino if (rld[r].secondary_p)
7341*e4b17023SJohn Marino fprintf (f, ", secondary_reload_p");
7342*e4b17023SJohn Marino
7343*e4b17023SJohn Marino if (rld[r].in_reg != 0)
7344*e4b17023SJohn Marino {
7345*e4b17023SJohn Marino fprintf (f, "\n\treload_in_reg: ");
7346*e4b17023SJohn Marino print_inline_rtx (f, rld[r].in_reg, 24);
7347*e4b17023SJohn Marino }
7348*e4b17023SJohn Marino
7349*e4b17023SJohn Marino if (rld[r].out_reg != 0)
7350*e4b17023SJohn Marino {
7351*e4b17023SJohn Marino fprintf (f, "\n\treload_out_reg: ");
7352*e4b17023SJohn Marino print_inline_rtx (f, rld[r].out_reg, 24);
7353*e4b17023SJohn Marino }
7354*e4b17023SJohn Marino
7355*e4b17023SJohn Marino if (rld[r].reg_rtx != 0)
7356*e4b17023SJohn Marino {
7357*e4b17023SJohn Marino fprintf (f, "\n\treload_reg_rtx: ");
7358*e4b17023SJohn Marino print_inline_rtx (f, rld[r].reg_rtx, 24);
7359*e4b17023SJohn Marino }
7360*e4b17023SJohn Marino
7361*e4b17023SJohn Marino prefix = "\n\t";
7362*e4b17023SJohn Marino if (rld[r].secondary_in_reload != -1)
7363*e4b17023SJohn Marino {
7364*e4b17023SJohn Marino fprintf (f, "%ssecondary_in_reload = %d",
7365*e4b17023SJohn Marino prefix, rld[r].secondary_in_reload);
7366*e4b17023SJohn Marino prefix = ", ";
7367*e4b17023SJohn Marino }
7368*e4b17023SJohn Marino
7369*e4b17023SJohn Marino if (rld[r].secondary_out_reload != -1)
7370*e4b17023SJohn Marino fprintf (f, "%ssecondary_out_reload = %d\n",
7371*e4b17023SJohn Marino prefix, rld[r].secondary_out_reload);
7372*e4b17023SJohn Marino
7373*e4b17023SJohn Marino prefix = "\n\t";
7374*e4b17023SJohn Marino if (rld[r].secondary_in_icode != CODE_FOR_nothing)
7375*e4b17023SJohn Marino {
7376*e4b17023SJohn Marino fprintf (f, "%ssecondary_in_icode = %s", prefix,
7377*e4b17023SJohn Marino insn_data[rld[r].secondary_in_icode].name);
7378*e4b17023SJohn Marino prefix = ", ";
7379*e4b17023SJohn Marino }
7380*e4b17023SJohn Marino
7381*e4b17023SJohn Marino if (rld[r].secondary_out_icode != CODE_FOR_nothing)
7382*e4b17023SJohn Marino fprintf (f, "%ssecondary_out_icode = %s", prefix,
7383*e4b17023SJohn Marino insn_data[rld[r].secondary_out_icode].name);
7384*e4b17023SJohn Marino
7385*e4b17023SJohn Marino fprintf (f, "\n");
7386*e4b17023SJohn Marino }
7387*e4b17023SJohn Marino }
7388*e4b17023SJohn Marino
7389*e4b17023SJohn Marino DEBUG_FUNCTION void
debug_reload(void)7390*e4b17023SJohn Marino debug_reload (void)
7391*e4b17023SJohn Marino {
7392*e4b17023SJohn Marino debug_reload_to_stream (stderr);
7393*e4b17023SJohn Marino }
7394