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