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