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