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