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