* i386.c (notice_update_cc): Remove bogus pentium GCC code.
[official-gcc.git] / gcc / reload.c
blob4b48a6c317128f392ffe175d90c1dc9c7fafd785
1 /* Search an insn for pseudo regs that must be in hard regs and are not.
2 Copyright (C) 1987, 88, 89, 92-6, 1997 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
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.
29 Before processing the first insn of the function, call `init_reload'.
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.
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.
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.
54 Finally you must call `subst_reloads' to substitute the reload reg rtx's
55 into the locations already recorded.
57 NOTE SIDE EFFECTS:
59 find_reloads can alter the operands of the instruction it is called on.
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.
66 2. Pseudo-registers that are equivalent to constants are replaced
67 with those constants if they are not in hard registers.
69 1 happens every time find_reloads is called.
70 2 happens only when REPLACE is 1, which is only when
71 actually doing the reloads, not when just counting them.
74 Using a reload register for several reloads in one insn:
76 When an insn has reloads, it is considered as having three parts:
77 the input reloads, the insn itself after reloading, and the output reloads.
78 Reloads of values used in memory addresses are often needed for only one part.
80 When this is so, reload_when_needed records which part needs the reload.
81 Two reloads for different parts of the insn can share the same reload
82 register.
84 When a reload is used for addresses in multiple parts, or when it is
85 an ordinary operand, it is classified as RELOAD_OTHER, and cannot share
86 a register with any other reload. */
88 #define REG_OK_STRICT
90 #include <stdio.h>
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"
101 #include "output.h"
102 #include "expr.h"
104 #ifndef REGISTER_MOVE_COST
105 #define REGISTER_MOVE_COST(x, y) 2
106 #endif
108 #ifndef REGNO_MODE_OK_FOR_BASE_P
109 #define REGNO_MODE_OK_FOR_BASE_P(REGNO, MODE) REGNO_OK_FOR_BASE_P (REGNO)
110 #endif
112 #ifndef REG_MODE_OK_FOR_BASE_P
113 #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
114 #endif
116 /* The variables set up by `find_reloads' are:
118 n_reloads number of distinct reloads needed; max reload # + 1
119 tables indexed by reload number
120 reload_in rtx for value to reload from
121 reload_out rtx for where to store reload-reg afterward if nec
122 (often the same as reload_in)
123 reload_reg_class enum reg_class, saying what regs to reload into
124 reload_inmode enum machine_mode; mode this operand should have
125 when reloaded, on input.
126 reload_outmode enum machine_mode; mode this operand should have
127 when reloaded, on output.
128 reload_optional char, nonzero for an optional reload.
129 Optional reloads are ignored unless the
130 value is already sitting in a register.
131 reload_inc int, positive amount to increment or decrement by if
132 reload_in is a PRE_DEC, PRE_INC, POST_DEC, POST_INC.
133 Ignored otherwise (don't assume it is zero).
134 reload_in_reg rtx. A reg for which reload_in is the equivalent.
135 If reload_in is a symbol_ref which came from
136 reg_equiv_constant, then this is the pseudo
137 which has that symbol_ref as equivalent.
138 reload_reg_rtx rtx. This is the register to reload into.
139 If it is zero when `find_reloads' returns,
140 you must find a suitable register in the class
141 specified by reload_reg_class, and store here
142 an rtx for that register with mode from
143 reload_inmode or reload_outmode.
144 reload_nocombine char, nonzero if this reload shouldn't be
145 combined with another reload.
146 reload_opnum int, operand number being reloaded. This is
147 used to group related reloads and need not always
148 be equal to the actual operand number in the insn,
149 though it current will be; for in-out operands, it
150 is one of the two operand numbers.
151 reload_when_needed enum, classifies reload as needed either for
152 addressing an input reload, addressing an output,
153 for addressing a non-reloaded mem ref,
154 or for unspecified purposes (i.e., more than one
155 of the above).
156 reload_secondary_p int, 1 if this is a secondary register for one
157 or more reloads.
158 reload_secondary_in_reload
159 reload_secondary_out_reload
160 int, gives the reload number of a secondary
161 reload, when needed; otherwise -1
162 reload_secondary_in_icode
163 reload_secondary_out_icode
164 enum insn_code, if a secondary reload is required,
165 gives the INSN_CODE that uses the secondary
166 reload as a scratch register, or CODE_FOR_nothing
167 if the secondary reload register is to be an
168 intermediate register. */
169 int n_reloads;
171 rtx reload_in[MAX_RELOADS];
172 rtx reload_out[MAX_RELOADS];
173 enum reg_class reload_reg_class[MAX_RELOADS];
174 enum machine_mode reload_inmode[MAX_RELOADS];
175 enum machine_mode reload_outmode[MAX_RELOADS];
176 rtx reload_reg_rtx[MAX_RELOADS];
177 char reload_optional[MAX_RELOADS];
178 int reload_inc[MAX_RELOADS];
179 rtx reload_in_reg[MAX_RELOADS];
180 char reload_nocombine[MAX_RELOADS];
181 int reload_opnum[MAX_RELOADS];
182 enum reload_type reload_when_needed[MAX_RELOADS];
183 int reload_secondary_p[MAX_RELOADS];
184 int reload_secondary_in_reload[MAX_RELOADS];
185 int reload_secondary_out_reload[MAX_RELOADS];
186 enum insn_code reload_secondary_in_icode[MAX_RELOADS];
187 enum insn_code reload_secondary_out_icode[MAX_RELOADS];
189 /* All the "earlyclobber" operands of the current insn
190 are recorded here. */
191 int n_earlyclobbers;
192 rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
194 int reload_n_operands;
196 /* Replacing reloads.
198 If `replace_reloads' is nonzero, then as each reload is recorded
199 an entry is made for it in the table `replacements'.
200 Then later `subst_reloads' can look through that table and
201 perform all the replacements needed. */
203 /* Nonzero means record the places to replace. */
204 static int replace_reloads;
206 /* Each replacement is recorded with a structure like this. */
207 struct replacement
209 rtx *where; /* Location to store in */
210 rtx *subreg_loc; /* Location of SUBREG if WHERE is inside
211 a SUBREG; 0 otherwise. */
212 int what; /* which reload this is for */
213 enum machine_mode mode; /* mode it must have */
216 static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
218 /* Number of replacements currently recorded. */
219 static int n_replacements;
221 /* Used to track what is modified by an operand. */
222 struct decomposition
224 int reg_flag; /* Nonzero if referencing a register. */
225 int safe; /* Nonzero if this can't conflict with anything. */
226 rtx base; /* Base address for MEM. */
227 HOST_WIDE_INT start; /* Starting offset or register number. */
228 HOST_WIDE_INT end; /* Ending offset or register number. */
231 /* MEM-rtx's created for pseudo-regs in stack slots not directly addressable;
232 (see reg_equiv_address). */
233 static rtx memlocs[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
234 static int n_memlocs;
236 #ifdef SECONDARY_MEMORY_NEEDED
238 /* Save MEMs needed to copy from one class of registers to another. One MEM
239 is used per mode, but normally only one or two modes are ever used.
241 We keep two versions, before and after register elimination. The one
242 after register elimination is record separately for each operand. This
243 is done in case the address is not valid to be sure that we separately
244 reload each. */
246 static rtx secondary_memlocs[NUM_MACHINE_MODES];
247 static rtx secondary_memlocs_elim[NUM_MACHINE_MODES][MAX_RECOG_OPERANDS];
248 #endif
250 /* The instruction we are doing reloads for;
251 so we can test whether a register dies in it. */
252 static rtx this_insn;
254 /* Nonzero if this instruction is a user-specified asm with operands. */
255 static int this_insn_is_asm;
257 /* If hard_regs_live_known is nonzero,
258 we can tell which hard regs are currently live,
259 at least enough to succeed in choosing dummy reloads. */
260 static int hard_regs_live_known;
262 /* Indexed by hard reg number,
263 element is nonegative if hard reg has been spilled.
264 This vector is passed to `find_reloads' as an argument
265 and is not changed here. */
266 static short *static_reload_reg_p;
268 /* Set to 1 in subst_reg_equivs if it changes anything. */
269 static int subst_reg_equivs_changed;
271 /* On return from push_reload, holds the reload-number for the OUT
272 operand, which can be different for that from the input operand. */
273 static int output_reloadnum;
275 /* Compare two RTX's. */
276 #define MATCHES(x, y) \
277 (x == y || (x != 0 && (GET_CODE (x) == REG \
278 ? GET_CODE (y) == REG && REGNO (x) == REGNO (y) \
279 : rtx_equal_p (x, y) && ! side_effects_p (x))))
281 /* Indicates if two reloads purposes are for similar enough things that we
282 can merge their reloads. */
283 #define MERGABLE_RELOADS(when1, when2, op1, op2) \
284 ((when1) == RELOAD_OTHER || (when2) == RELOAD_OTHER \
285 || ((when1) == (when2) && (op1) == (op2)) \
286 || ((when1) == RELOAD_FOR_INPUT && (when2) == RELOAD_FOR_INPUT) \
287 || ((when1) == RELOAD_FOR_OPERAND_ADDRESS \
288 && (when2) == RELOAD_FOR_OPERAND_ADDRESS) \
289 || ((when1) == RELOAD_FOR_OTHER_ADDRESS \
290 && (when2) == RELOAD_FOR_OTHER_ADDRESS))
292 /* Nonzero if these two reload purposes produce RELOAD_OTHER when merged. */
293 #define MERGE_TO_OTHER(when1, when2, op1, op2) \
294 ((when1) != (when2) \
295 || ! ((op1) == (op2) \
296 || (when1) == RELOAD_FOR_INPUT \
297 || (when1) == RELOAD_FOR_OPERAND_ADDRESS \
298 || (when1) == RELOAD_FOR_OTHER_ADDRESS))
300 /* If we are going to reload an address, compute the reload type to
301 use. */
302 #define ADDR_TYPE(type) \
303 ((type) == RELOAD_FOR_INPUT_ADDRESS \
304 ? RELOAD_FOR_INPADDR_ADDRESS \
305 : ((type) == RELOAD_FOR_OUTPUT_ADDRESS \
306 ? RELOAD_FOR_OUTADDR_ADDRESS \
307 : (type)))
309 static int push_secondary_reload PROTO((int, rtx, int, int, enum reg_class,
310 enum machine_mode, enum reload_type,
311 enum insn_code *));
312 static enum reg_class find_valid_class PROTO((enum machine_mode, int));
313 static int push_reload PROTO((rtx, rtx, rtx *, rtx *, enum reg_class,
314 enum machine_mode, enum machine_mode,
315 int, int, int, enum reload_type));
316 static void push_replacement PROTO((rtx *, int, enum machine_mode));
317 static void combine_reloads PROTO((void));
318 static rtx find_dummy_reload PROTO((rtx, rtx, rtx *, rtx *,
319 enum machine_mode, enum machine_mode,
320 enum reg_class, int, int));
321 static int earlyclobber_operand_p PROTO((rtx));
322 static int hard_reg_set_here_p PROTO((int, int, rtx));
323 static struct decomposition decompose PROTO((rtx));
324 static int immune_p PROTO((rtx, rtx, struct decomposition));
325 static int alternative_allows_memconst PROTO((char *, int));
326 static rtx find_reloads_toplev PROTO((rtx, int, enum reload_type, int, int));
327 static rtx make_memloc PROTO((rtx, int));
328 static int find_reloads_address PROTO((enum machine_mode, rtx *, rtx, rtx *,
329 int, enum reload_type, int, rtx));
330 static rtx subst_reg_equivs PROTO((rtx));
331 static rtx subst_indexed_address PROTO((rtx));
332 static int find_reloads_address_1 PROTO((enum machine_mode, rtx, int, rtx *,
333 int, enum reload_type,int, rtx));
334 static void find_reloads_address_part PROTO((rtx, rtx *, enum reg_class,
335 enum machine_mode, int,
336 enum reload_type, int));
337 static int find_inc_amount PROTO((rtx, rtx));
339 #ifdef HAVE_SECONDARY_RELOADS
341 /* Determine if any secondary reloads are needed for loading (if IN_P is
342 non-zero) or storing (if IN_P is zero) X to or from a reload register of
343 register class RELOAD_CLASS in mode RELOAD_MODE. If secondary reloads
344 are needed, push them.
346 Return the reload number of the secondary reload we made, or -1 if
347 we didn't need one. *PICODE is set to the insn_code to use if we do
348 need a secondary reload. */
350 static int
351 push_secondary_reload (in_p, x, opnum, optional, reload_class, reload_mode,
352 type, picode)
353 int in_p;
354 rtx x;
355 int opnum;
356 int optional;
357 enum reg_class reload_class;
358 enum machine_mode reload_mode;
359 enum reload_type type;
360 enum insn_code *picode;
362 enum reg_class class = NO_REGS;
363 enum machine_mode mode = reload_mode;
364 enum insn_code icode = CODE_FOR_nothing;
365 enum reg_class t_class = NO_REGS;
366 enum machine_mode t_mode = VOIDmode;
367 enum insn_code t_icode = CODE_FOR_nothing;
368 enum reload_type secondary_type;
369 int i;
370 int s_reload, t_reload = -1;
372 if (type == RELOAD_FOR_INPUT_ADDRESS
373 || type == RELOAD_FOR_OUTPUT_ADDRESS
374 || type == RELOAD_FOR_INPADDR_ADDRESS
375 || type == RELOAD_FOR_OUTADDR_ADDRESS)
376 secondary_type = type;
377 else
378 secondary_type = in_p ? RELOAD_FOR_INPUT_ADDRESS : RELOAD_FOR_OUTPUT_ADDRESS;
380 *picode = CODE_FOR_nothing;
382 /* If X is a paradoxical SUBREG, use the inner value to determine both the
383 mode and object being reloaded. */
384 if (GET_CODE (x) == SUBREG
385 && (GET_MODE_SIZE (GET_MODE (x))
386 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
388 x = SUBREG_REG (x);
389 reload_mode = GET_MODE (x);
392 /* If X is a pseudo-register that has an equivalent MEM (actually, if it
393 is still a pseudo-register by now, it *must* have an equivalent MEM
394 but we don't want to assume that), use that equivalent when seeing if
395 a secondary reload is needed since whether or not a reload is needed
396 might be sensitive to the form of the MEM. */
398 if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER
399 && reg_equiv_mem[REGNO (x)] != 0)
400 x = reg_equiv_mem[REGNO (x)];
402 #ifdef SECONDARY_INPUT_RELOAD_CLASS
403 if (in_p)
404 class = SECONDARY_INPUT_RELOAD_CLASS (reload_class, reload_mode, x);
405 #endif
407 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
408 if (! in_p)
409 class = SECONDARY_OUTPUT_RELOAD_CLASS (reload_class, reload_mode, x);
410 #endif
412 /* If we don't need any secondary registers, done. */
413 if (class == NO_REGS)
414 return -1;
416 /* Get a possible insn to use. If the predicate doesn't accept X, don't
417 use the insn. */
419 icode = (in_p ? reload_in_optab[(int) reload_mode]
420 : reload_out_optab[(int) reload_mode]);
422 if (icode != CODE_FOR_nothing
423 && insn_operand_predicate[(int) icode][in_p]
424 && (! (insn_operand_predicate[(int) icode][in_p]) (x, reload_mode)))
425 icode = CODE_FOR_nothing;
427 /* If we will be using an insn, see if it can directly handle the reload
428 register we will be using. If it can, the secondary reload is for a
429 scratch register. If it can't, we will use the secondary reload for
430 an intermediate register and require a tertiary reload for the scratch
431 register. */
433 if (icode != CODE_FOR_nothing)
435 /* If IN_P is non-zero, the reload register will be the output in
436 operand 0. If IN_P is zero, the reload register will be the input
437 in operand 1. Outputs should have an initial "=", which we must
438 skip. */
440 char insn_letter = insn_operand_constraint[(int) icode][!in_p][in_p];
441 enum reg_class insn_class
442 = (insn_letter == 'r' ? GENERAL_REGS
443 : REG_CLASS_FROM_LETTER (insn_letter));
445 if (insn_class == NO_REGS
446 || (in_p && insn_operand_constraint[(int) icode][!in_p][0] != '=')
447 /* The scratch register's constraint must start with "=&". */
448 || insn_operand_constraint[(int) icode][2][0] != '='
449 || insn_operand_constraint[(int) icode][2][1] != '&')
450 abort ();
452 if (reg_class_subset_p (reload_class, insn_class))
453 mode = insn_operand_mode[(int) icode][2];
454 else
456 char t_letter = insn_operand_constraint[(int) icode][2][2];
457 class = insn_class;
458 t_mode = insn_operand_mode[(int) icode][2];
459 t_class = (t_letter == 'r' ? GENERAL_REGS
460 : REG_CLASS_FROM_LETTER (t_letter));
461 t_icode = icode;
462 icode = CODE_FOR_nothing;
466 /* This case isn't valid, so fail. Reload is allowed to use the same
467 register for RELOAD_FOR_INPUT_ADDRESS and RELOAD_FOR_INPUT reloads, but
468 in the case of a secondary register, we actually need two different
469 registers for correct code. We fail here to prevent the possibility of
470 silently generating incorrect code later.
472 The convention is that secondary input reloads are valid only if the
473 secondary_class is different from class. If you have such a case, you
474 can not use secondary reloads, you must work around the problem some
475 other way.
477 Allow this when MODE is not reload_mode and assume that the generated
478 code handles this case (it does on the Alpha, which is the only place
479 this currently happens). */
481 if (in_p && class == reload_class && mode == reload_mode)
482 abort ();
484 /* If we need a tertiary reload, see if we have one we can reuse or else
485 make a new one. */
487 if (t_class != NO_REGS)
489 for (t_reload = 0; t_reload < n_reloads; t_reload++)
490 if (reload_secondary_p[t_reload]
491 && (reg_class_subset_p (t_class, reload_reg_class[t_reload])
492 || reg_class_subset_p (reload_reg_class[t_reload], t_class))
493 && ((in_p && reload_inmode[t_reload] == t_mode)
494 || (! in_p && reload_outmode[t_reload] == t_mode))
495 && ((in_p && (reload_secondary_in_icode[t_reload]
496 == CODE_FOR_nothing))
497 || (! in_p &&(reload_secondary_out_icode[t_reload]
498 == CODE_FOR_nothing)))
499 && (reg_class_size[(int) t_class] == 1
500 #ifdef SMALL_REGISTER_CLASSES
501 || SMALL_REGISTER_CLASSES
502 #endif
504 && MERGABLE_RELOADS (secondary_type,
505 reload_when_needed[t_reload],
506 opnum, reload_opnum[t_reload]))
508 if (in_p)
509 reload_inmode[t_reload] = t_mode;
510 if (! in_p)
511 reload_outmode[t_reload] = t_mode;
513 if (reg_class_subset_p (t_class, reload_reg_class[t_reload]))
514 reload_reg_class[t_reload] = t_class;
516 reload_opnum[t_reload] = MIN (reload_opnum[t_reload], opnum);
517 reload_optional[t_reload] &= optional;
518 reload_secondary_p[t_reload] = 1;
519 if (MERGE_TO_OTHER (secondary_type, reload_when_needed[t_reload],
520 opnum, reload_opnum[t_reload]))
521 reload_when_needed[t_reload] = RELOAD_OTHER;
524 if (t_reload == n_reloads)
526 /* We need to make a new tertiary reload for this register class. */
527 reload_in[t_reload] = reload_out[t_reload] = 0;
528 reload_reg_class[t_reload] = t_class;
529 reload_inmode[t_reload] = in_p ? t_mode : VOIDmode;
530 reload_outmode[t_reload] = ! in_p ? t_mode : VOIDmode;
531 reload_reg_rtx[t_reload] = 0;
532 reload_optional[t_reload] = optional;
533 reload_inc[t_reload] = 0;
534 /* Maybe we could combine these, but it seems too tricky. */
535 reload_nocombine[t_reload] = 1;
536 reload_in_reg[t_reload] = 0;
537 reload_opnum[t_reload] = opnum;
538 reload_when_needed[t_reload] = secondary_type;
539 reload_secondary_in_reload[t_reload] = -1;
540 reload_secondary_out_reload[t_reload] = -1;
541 reload_secondary_in_icode[t_reload] = CODE_FOR_nothing;
542 reload_secondary_out_icode[t_reload] = CODE_FOR_nothing;
543 reload_secondary_p[t_reload] = 1;
545 n_reloads++;
549 /* See if we can reuse an existing secondary reload. */
550 for (s_reload = 0; s_reload < n_reloads; s_reload++)
551 if (reload_secondary_p[s_reload]
552 && (reg_class_subset_p (class, reload_reg_class[s_reload])
553 || reg_class_subset_p (reload_reg_class[s_reload], class))
554 && ((in_p && reload_inmode[s_reload] == mode)
555 || (! in_p && reload_outmode[s_reload] == mode))
556 && ((in_p && reload_secondary_in_reload[s_reload] == t_reload)
557 || (! in_p && reload_secondary_out_reload[s_reload] == t_reload))
558 && ((in_p && reload_secondary_in_icode[s_reload] == t_icode)
559 || (! in_p && reload_secondary_out_icode[s_reload] == t_icode))
560 && (reg_class_size[(int) class] == 1
561 #ifdef SMALL_REGISTER_CLASSES
562 || SMALL_REGISTER_CLASSES
563 #endif
565 && MERGABLE_RELOADS (secondary_type, reload_when_needed[s_reload],
566 opnum, reload_opnum[s_reload]))
568 if (in_p)
569 reload_inmode[s_reload] = mode;
570 if (! in_p)
571 reload_outmode[s_reload] = mode;
573 if (reg_class_subset_p (class, reload_reg_class[s_reload]))
574 reload_reg_class[s_reload] = class;
576 reload_opnum[s_reload] = MIN (reload_opnum[s_reload], opnum);
577 reload_optional[s_reload] &= optional;
578 reload_secondary_p[s_reload] = 1;
579 if (MERGE_TO_OTHER (secondary_type, reload_when_needed[s_reload],
580 opnum, reload_opnum[s_reload]))
581 reload_when_needed[s_reload] = RELOAD_OTHER;
584 if (s_reload == n_reloads)
586 /* We need to make a new secondary reload for this register class. */
587 reload_in[s_reload] = reload_out[s_reload] = 0;
588 reload_reg_class[s_reload] = class;
590 reload_inmode[s_reload] = in_p ? mode : VOIDmode;
591 reload_outmode[s_reload] = ! in_p ? mode : VOIDmode;
592 reload_reg_rtx[s_reload] = 0;
593 reload_optional[s_reload] = optional;
594 reload_inc[s_reload] = 0;
595 /* Maybe we could combine these, but it seems too tricky. */
596 reload_nocombine[s_reload] = 1;
597 reload_in_reg[s_reload] = 0;
598 reload_opnum[s_reload] = opnum;
599 reload_when_needed[s_reload] = secondary_type;
600 reload_secondary_in_reload[s_reload] = in_p ? t_reload : -1;
601 reload_secondary_out_reload[s_reload] = ! in_p ? t_reload : -1;
602 reload_secondary_in_icode[s_reload] = in_p ? t_icode : CODE_FOR_nothing;
603 reload_secondary_out_icode[s_reload]
604 = ! in_p ? t_icode : CODE_FOR_nothing;
605 reload_secondary_p[s_reload] = 1;
607 n_reloads++;
609 #ifdef SECONDARY_MEMORY_NEEDED
610 /* If we need a memory location to copy between the two reload regs,
611 set it up now. */
613 if (in_p && icode == CODE_FOR_nothing
614 && SECONDARY_MEMORY_NEEDED (class, reload_class, mode))
615 get_secondary_mem (x, mode, opnum, type);
617 if (! in_p && icode == CODE_FOR_nothing
618 && SECONDARY_MEMORY_NEEDED (reload_class, class, mode))
619 get_secondary_mem (x, mode, opnum, type);
620 #endif
623 *picode = icode;
624 return s_reload;
626 #endif /* HAVE_SECONDARY_RELOADS */
628 #ifdef SECONDARY_MEMORY_NEEDED
630 /* Return a memory location that will be used to copy X in mode MODE.
631 If we haven't already made a location for this mode in this insn,
632 call find_reloads_address on the location being returned. */
635 get_secondary_mem (x, mode, opnum, type)
636 rtx x;
637 enum machine_mode mode;
638 int opnum;
639 enum reload_type type;
641 rtx loc;
642 int mem_valid;
644 /* By default, if MODE is narrower than a word, widen it to a word.
645 This is required because most machines that require these memory
646 locations do not support short load and stores from all registers
647 (e.g., FP registers). */
649 #ifdef SECONDARY_MEMORY_NEEDED_MODE
650 mode = SECONDARY_MEMORY_NEEDED_MODE (mode);
651 #else
652 if (GET_MODE_BITSIZE (mode) < BITS_PER_WORD)
653 mode = mode_for_size (BITS_PER_WORD, GET_MODE_CLASS (mode), 0);
654 #endif
656 /* If we already have made a MEM for this operand in MODE, return it. */
657 if (secondary_memlocs_elim[(int) mode][opnum] != 0)
658 return secondary_memlocs_elim[(int) mode][opnum];
660 /* If this is the first time we've tried to get a MEM for this mode,
661 allocate a new one. `something_changed' in reload will get set
662 by noticing that the frame size has changed. */
664 if (secondary_memlocs[(int) mode] == 0)
666 #ifdef SECONDARY_MEMORY_NEEDED_RTX
667 secondary_memlocs[(int) mode] = SECONDARY_MEMORY_NEEDED_RTX (mode);
668 #else
669 secondary_memlocs[(int) mode]
670 = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
671 #endif
674 /* Get a version of the address doing any eliminations needed. If that
675 didn't give us a new MEM, make a new one if it isn't valid. */
677 loc = eliminate_regs (secondary_memlocs[(int) mode], VOIDmode, NULL_RTX, 0);
678 mem_valid = strict_memory_address_p (mode, XEXP (loc, 0));
680 if (! mem_valid && loc == secondary_memlocs[(int) mode])
681 loc = copy_rtx (loc);
683 /* The only time the call below will do anything is if the stack
684 offset is too large. In that case IND_LEVELS doesn't matter, so we
685 can just pass a zero. Adjust the type to be the address of the
686 corresponding object. If the address was valid, save the eliminated
687 address. If it wasn't valid, we need to make a reload each time, so
688 don't save it. */
690 if (! mem_valid)
692 type = (type == RELOAD_FOR_INPUT ? RELOAD_FOR_INPUT_ADDRESS
693 : type == RELOAD_FOR_OUTPUT ? RELOAD_FOR_OUTPUT_ADDRESS
694 : RELOAD_OTHER);
696 find_reloads_address (mode, NULL_PTR, XEXP (loc, 0), &XEXP (loc, 0),
697 opnum, type, 0, 0);
700 secondary_memlocs_elim[(int) mode][opnum] = loc;
701 return loc;
704 /* Clear any secondary memory locations we've made. */
706 void
707 clear_secondary_mem ()
709 bzero ((char *) secondary_memlocs, sizeof secondary_memlocs);
711 #endif /* SECONDARY_MEMORY_NEEDED */
713 /* Find the largest class for which every register number plus N is valid in
714 M1 (if in range). Abort if no such class exists. */
716 static enum reg_class
717 find_valid_class (m1, n)
718 enum machine_mode m1;
719 int n;
721 int class;
722 int regno;
723 enum reg_class best_class;
724 int best_size = 0;
726 for (class = 1; class < N_REG_CLASSES; class++)
728 int bad = 0;
729 for (regno = 0; regno < FIRST_PSEUDO_REGISTER && ! bad; regno++)
730 if (TEST_HARD_REG_BIT (reg_class_contents[class], regno)
731 && TEST_HARD_REG_BIT (reg_class_contents[class], regno + n)
732 && ! HARD_REGNO_MODE_OK (regno + n, m1))
733 bad = 1;
735 if (! bad && reg_class_size[class] > best_size)
736 best_class = class, best_size = reg_class_size[class];
739 if (best_size == 0)
740 abort ();
742 return best_class;
745 /* Record one reload that needs to be performed.
746 IN is an rtx saying where the data are to be found before this instruction.
747 OUT says where they must be stored after the instruction.
748 (IN is zero for data not read, and OUT is zero for data not written.)
749 INLOC and OUTLOC point to the places in the instructions where
750 IN and OUT were found.
751 If IN and OUT are both non-zero, it means the same register must be used
752 to reload both IN and OUT.
754 CLASS is a register class required for the reloaded data.
755 INMODE is the machine mode that the instruction requires
756 for the reg that replaces IN and OUTMODE is likewise for OUT.
758 If IN is zero, then OUT's location and mode should be passed as
759 INLOC and INMODE.
761 STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
763 OPTIONAL nonzero means this reload does not need to be performed:
764 it can be discarded if that is more convenient.
766 OPNUM and TYPE say what the purpose of this reload is.
768 The return value is the reload-number for this reload.
770 If both IN and OUT are nonzero, in some rare cases we might
771 want to make two separate reloads. (Actually we never do this now.)
772 Therefore, the reload-number for OUT is stored in
773 output_reloadnum when we return; the return value applies to IN.
774 Usually (presently always), when IN and OUT are nonzero,
775 the two reload-numbers are equal, but the caller should be careful to
776 distinguish them. */
778 static int
779 push_reload (in, out, inloc, outloc, class,
780 inmode, outmode, strict_low, optional, opnum, type)
781 register rtx in, out;
782 rtx *inloc, *outloc;
783 enum reg_class class;
784 enum machine_mode inmode, outmode;
785 int strict_low;
786 int optional;
787 int opnum;
788 enum reload_type type;
790 register int i;
791 int dont_share = 0;
792 int dont_remove_subreg = 0;
793 rtx *in_subreg_loc = 0, *out_subreg_loc = 0;
794 int secondary_in_reload = -1, secondary_out_reload = -1;
795 enum insn_code secondary_in_icode = CODE_FOR_nothing;
796 enum insn_code secondary_out_icode = CODE_FOR_nothing;
798 /* INMODE and/or OUTMODE could be VOIDmode if no mode
799 has been specified for the operand. In that case,
800 use the operand's mode as the mode to reload. */
801 if (inmode == VOIDmode && in != 0)
802 inmode = GET_MODE (in);
803 if (outmode == VOIDmode && out != 0)
804 outmode = GET_MODE (out);
806 /* If IN is a pseudo register everywhere-equivalent to a constant, and
807 it is not in a hard register, reload straight from the constant,
808 since we want to get rid of such pseudo registers.
809 Often this is done earlier, but not always in find_reloads_address. */
810 if (in != 0 && GET_CODE (in) == REG)
812 register int regno = REGNO (in);
814 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
815 && reg_equiv_constant[regno] != 0)
816 in = reg_equiv_constant[regno];
819 /* Likewise for OUT. Of course, OUT will never be equivalent to
820 an actual constant, but it might be equivalent to a memory location
821 (in the case of a parameter). */
822 if (out != 0 && GET_CODE (out) == REG)
824 register int regno = REGNO (out);
826 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
827 && reg_equiv_constant[regno] != 0)
828 out = reg_equiv_constant[regno];
831 /* If we have a read-write operand with an address side-effect,
832 change either IN or OUT so the side-effect happens only once. */
833 if (in != 0 && out != 0 && GET_CODE (in) == MEM && rtx_equal_p (in, out))
835 if (GET_CODE (XEXP (in, 0)) == POST_INC
836 || GET_CODE (XEXP (in, 0)) == POST_DEC)
837 in = gen_rtx (MEM, GET_MODE (in), XEXP (XEXP (in, 0), 0));
838 if (GET_CODE (XEXP (in, 0)) == PRE_INC
839 || GET_CODE (XEXP (in, 0)) == PRE_DEC)
840 out = gen_rtx (MEM, GET_MODE (out), XEXP (XEXP (out, 0), 0));
843 /* If we are reloading a (SUBREG constant ...), really reload just the
844 inside expression in its own mode. Similarly for (SUBREG (PLUS ...)).
845 If we have (SUBREG:M1 (MEM:M2 ...) ...) (or an inner REG that is still
846 a pseudo and hence will become a MEM) with M1 wider than M2 and the
847 register is a pseudo, also reload the inside expression.
848 For machines that extend byte loads, do this for any SUBREG of a pseudo
849 where both M1 and M2 are a word or smaller, M1 is wider than M2, and
850 M2 is an integral mode that gets extended when loaded.
851 Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
852 either M1 is not valid for R or M2 is wider than a word but we only
853 need one word to store an M2-sized quantity in R.
854 (However, if OUT is nonzero, we need to reload the reg *and*
855 the subreg, so do nothing here, and let following statement handle it.)
857 Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere;
858 we can't handle it here because CONST_INT does not indicate a mode.
860 Similarly, we must reload the inside expression if we have a
861 STRICT_LOW_PART (presumably, in == out in the cas).
863 Also reload the inner expression if it does not require a secondary
864 reload but the SUBREG does.
866 Finally, reload the inner expression if it is a register that is in
867 the class whose registers cannot be referenced in a different size
868 and M1 is not the same size as M2. If SUBREG_WORD is nonzero, we
869 cannot reload just the inside since we might end up with the wrong
870 register class. */
872 if (in != 0 && GET_CODE (in) == SUBREG && SUBREG_WORD (in) == 0
873 #ifdef CLASS_CANNOT_CHANGE_SIZE
874 && class != CLASS_CANNOT_CHANGE_SIZE
875 #endif
876 && (CONSTANT_P (SUBREG_REG (in))
877 || GET_CODE (SUBREG_REG (in)) == PLUS
878 || strict_low
879 || (((GET_CODE (SUBREG_REG (in)) == REG
880 && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER)
881 || GET_CODE (SUBREG_REG (in)) == MEM)
882 && ((GET_MODE_SIZE (inmode)
883 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
884 #ifdef LOAD_EXTEND_OP
885 || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
886 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
887 <= UNITS_PER_WORD)
888 && (GET_MODE_SIZE (inmode)
889 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
890 && INTEGRAL_MODE_P (GET_MODE (SUBREG_REG (in)))
891 && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (in))) != NIL)
892 #endif
894 || (GET_CODE (SUBREG_REG (in)) == REG
895 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
896 /* The case where out is nonzero
897 is handled differently in the following statement. */
898 && (out == 0 || SUBREG_WORD (in) == 0)
899 && ((GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
900 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
901 > UNITS_PER_WORD)
902 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
903 / UNITS_PER_WORD)
904 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (in)),
905 GET_MODE (SUBREG_REG (in)))))
906 || ! HARD_REGNO_MODE_OK ((REGNO (SUBREG_REG (in))
907 + SUBREG_WORD (in)),
908 inmode)))
909 #ifdef SECONDARY_INPUT_RELOAD_CLASS
910 || (SECONDARY_INPUT_RELOAD_CLASS (class, inmode, in) != NO_REGS
911 && (SECONDARY_INPUT_RELOAD_CLASS (class,
912 GET_MODE (SUBREG_REG (in)),
913 SUBREG_REG (in))
914 == NO_REGS))
915 #endif
916 #ifdef CLASS_CANNOT_CHANGE_SIZE
917 || (GET_CODE (SUBREG_REG (in)) == REG
918 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
919 && (TEST_HARD_REG_BIT
920 (reg_class_contents[(int) CLASS_CANNOT_CHANGE_SIZE],
921 REGNO (SUBREG_REG (in))))
922 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
923 != GET_MODE_SIZE (inmode)))
924 #endif
927 in_subreg_loc = inloc;
928 inloc = &SUBREG_REG (in);
929 in = *inloc;
930 #ifndef LOAD_EXTEND_OP
931 if (GET_CODE (in) == MEM)
932 /* This is supposed to happen only for paradoxical subregs made by
933 combine.c. (SUBREG (MEM)) isn't supposed to occur other ways. */
934 if (GET_MODE_SIZE (GET_MODE (in)) > GET_MODE_SIZE (inmode))
935 abort ();
936 #endif
937 inmode = GET_MODE (in);
940 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
941 either M1 is not valid for R or M2 is wider than a word but we only
942 need one word to store an M2-sized quantity in R.
944 However, we must reload the inner reg *as well as* the subreg in
945 that case. */
947 /* Similar issue for (SUBREG constant ...) if it was not handled by the
948 code above. This can happen if SUBREG_WORD != 0. */
950 if (in != 0 && GET_CODE (in) == SUBREG
951 && (CONSTANT_P (SUBREG_REG (in))
952 || (GET_CODE (SUBREG_REG (in)) == REG
953 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
954 && (! HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (in))
955 + SUBREG_WORD (in),
956 inmode)
957 || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
958 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
959 > UNITS_PER_WORD)
960 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
961 / UNITS_PER_WORD)
962 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (in)),
963 GET_MODE (SUBREG_REG (in)))))))))
965 /* This relies on the fact that emit_reload_insns outputs the
966 instructions for input reloads of type RELOAD_OTHER in the same
967 order as the reloads. Thus if the outer reload is also of type
968 RELOAD_OTHER, we are guaranteed that this inner reload will be
969 output before the outer reload. */
970 push_reload (SUBREG_REG (in), NULL_RTX, &SUBREG_REG (in), NULL_PTR,
971 find_valid_class (inmode, SUBREG_WORD (in)),
972 VOIDmode, VOIDmode, 0, 0, opnum, type);
973 dont_remove_subreg = 1;
976 /* Similarly for paradoxical and problematical SUBREGs on the output.
977 Note that there is no reason we need worry about the previous value
978 of SUBREG_REG (out); even if wider than out,
979 storing in a subreg is entitled to clobber it all
980 (except in the case of STRICT_LOW_PART,
981 and in that case the constraint should label it input-output.) */
982 if (out != 0 && GET_CODE (out) == SUBREG && SUBREG_WORD (out) == 0
983 #ifdef CLASS_CANNOT_CHANGE_SIZE
984 && class != CLASS_CANNOT_CHANGE_SIZE
985 #endif
986 && (CONSTANT_P (SUBREG_REG (out))
987 || strict_low
988 || (((GET_CODE (SUBREG_REG (out)) == REG
989 && REGNO (SUBREG_REG (out)) >= FIRST_PSEUDO_REGISTER)
990 || GET_CODE (SUBREG_REG (out)) == MEM)
991 && ((GET_MODE_SIZE (outmode)
992 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))))
993 || (GET_CODE (SUBREG_REG (out)) == REG
994 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
995 && ((GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
996 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
997 > UNITS_PER_WORD)
998 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
999 / UNITS_PER_WORD)
1000 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (out)),
1001 GET_MODE (SUBREG_REG (out)))))
1002 || ! HARD_REGNO_MODE_OK ((REGNO (SUBREG_REG (out))
1003 + SUBREG_WORD (out)),
1004 outmode)))
1005 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1006 || (SECONDARY_OUTPUT_RELOAD_CLASS (class, outmode, out) != NO_REGS
1007 && (SECONDARY_OUTPUT_RELOAD_CLASS (class,
1008 GET_MODE (SUBREG_REG (out)),
1009 SUBREG_REG (out))
1010 == NO_REGS))
1011 #endif
1012 #ifdef CLASS_CANNOT_CHANGE_SIZE
1013 || (GET_CODE (SUBREG_REG (out)) == REG
1014 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1015 && (TEST_HARD_REG_BIT
1016 (reg_class_contents[(int) CLASS_CANNOT_CHANGE_SIZE],
1017 REGNO (SUBREG_REG (out))))
1018 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1019 != GET_MODE_SIZE (outmode)))
1020 #endif
1023 out_subreg_loc = outloc;
1024 outloc = &SUBREG_REG (out);
1025 out = *outloc;
1026 #ifndef LOAD_EXTEND_OP
1027 if (GET_CODE (out) == MEM
1028 && GET_MODE_SIZE (GET_MODE (out)) > GET_MODE_SIZE (outmode))
1029 abort ();
1030 #endif
1031 outmode = GET_MODE (out);
1034 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
1035 either M1 is not valid for R or M2 is wider than a word but we only
1036 need one word to store an M2-sized quantity in R.
1038 However, we must reload the inner reg *as well as* the subreg in
1039 that case. In this case, the inner reg is an in-out reload. */
1041 if (out != 0 && GET_CODE (out) == SUBREG
1042 && GET_CODE (SUBREG_REG (out)) == REG
1043 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1044 && (! HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (out)) + SUBREG_WORD (out),
1045 outmode)
1046 || (GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
1047 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1048 > UNITS_PER_WORD)
1049 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1050 / UNITS_PER_WORD)
1051 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (out)),
1052 GET_MODE (SUBREG_REG (out)))))))
1054 /* This relies on the fact that emit_reload_insns outputs the
1055 instructions for output reloads of type RELOAD_OTHER in reverse
1056 order of the reloads. Thus if the outer reload is also of type
1057 RELOAD_OTHER, we are guaranteed that this inner reload will be
1058 output after the outer reload. */
1059 dont_remove_subreg = 1;
1060 push_reload (SUBREG_REG (out), SUBREG_REG (out), &SUBREG_REG (out),
1061 &SUBREG_REG (out),
1062 find_valid_class (outmode, SUBREG_WORD (out)),
1063 VOIDmode, VOIDmode, 0, 0,
1064 opnum, RELOAD_OTHER);
1067 /* If IN appears in OUT, we can't share any input-only reload for IN. */
1068 if (in != 0 && out != 0 && GET_CODE (out) == MEM
1069 && (GET_CODE (in) == REG || GET_CODE (in) == MEM)
1070 && reg_overlap_mentioned_for_reload_p (in, XEXP (out, 0)))
1071 dont_share = 1;
1073 /* If IN is a SUBREG of a hard register, make a new REG. This
1074 simplifies some of the cases below. */
1076 if (in != 0 && GET_CODE (in) == SUBREG && GET_CODE (SUBREG_REG (in)) == REG
1077 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1078 && ! dont_remove_subreg)
1079 in = gen_rtx (REG, GET_MODE (in),
1080 REGNO (SUBREG_REG (in)) + SUBREG_WORD (in));
1082 /* Similarly for OUT. */
1083 if (out != 0 && GET_CODE (out) == SUBREG
1084 && GET_CODE (SUBREG_REG (out)) == REG
1085 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1086 && ! dont_remove_subreg)
1087 out = gen_rtx (REG, GET_MODE (out),
1088 REGNO (SUBREG_REG (out)) + SUBREG_WORD (out));
1090 /* Narrow down the class of register wanted if that is
1091 desirable on this machine for efficiency. */
1092 if (in != 0)
1093 class = PREFERRED_RELOAD_CLASS (in, class);
1095 /* Output reloads may need analogous treatment, different in detail. */
1096 #ifdef PREFERRED_OUTPUT_RELOAD_CLASS
1097 if (out != 0)
1098 class = PREFERRED_OUTPUT_RELOAD_CLASS (out, class);
1099 #endif
1101 /* Make sure we use a class that can handle the actual pseudo
1102 inside any subreg. For example, on the 386, QImode regs
1103 can appear within SImode subregs. Although GENERAL_REGS
1104 can handle SImode, QImode needs a smaller class. */
1105 #ifdef LIMIT_RELOAD_CLASS
1106 if (in_subreg_loc)
1107 class = LIMIT_RELOAD_CLASS (inmode, class);
1108 else if (in != 0 && GET_CODE (in) == SUBREG)
1109 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (in)), class);
1111 if (out_subreg_loc)
1112 class = LIMIT_RELOAD_CLASS (outmode, class);
1113 if (out != 0 && GET_CODE (out) == SUBREG)
1114 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (out)), class);
1115 #endif
1117 /* Verify that this class is at least possible for the mode that
1118 is specified. */
1119 if (this_insn_is_asm)
1121 enum machine_mode mode;
1122 if (GET_MODE_SIZE (inmode) > GET_MODE_SIZE (outmode))
1123 mode = inmode;
1124 else
1125 mode = outmode;
1126 if (mode == VOIDmode)
1128 error_for_asm (this_insn, "cannot reload integer constant operand in `asm'");
1129 mode = word_mode;
1130 if (in != 0)
1131 inmode = word_mode;
1132 if (out != 0)
1133 outmode = word_mode;
1135 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1136 if (HARD_REGNO_MODE_OK (i, mode)
1137 && TEST_HARD_REG_BIT (reg_class_contents[(int) class], i))
1139 int nregs = HARD_REGNO_NREGS (i, mode);
1141 int j;
1142 for (j = 1; j < nregs; j++)
1143 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], i + j))
1144 break;
1145 if (j == nregs)
1146 break;
1148 if (i == FIRST_PSEUDO_REGISTER)
1150 error_for_asm (this_insn, "impossible register constraint in `asm'");
1151 class = ALL_REGS;
1155 if (class == NO_REGS)
1156 abort ();
1158 /* We can use an existing reload if the class is right
1159 and at least one of IN and OUT is a match
1160 and the other is at worst neutral.
1161 (A zero compared against anything is neutral.)
1163 If SMALL_REGISTER_CLASSES, don't use existing reloads unless they are
1164 for the same thing since that can cause us to need more reload registers
1165 than we otherwise would. */
1167 for (i = 0; i < n_reloads; i++)
1168 if ((reg_class_subset_p (class, reload_reg_class[i])
1169 || reg_class_subset_p (reload_reg_class[i], class))
1170 /* If the existing reload has a register, it must fit our class. */
1171 && (reload_reg_rtx[i] == 0
1172 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1173 true_regnum (reload_reg_rtx[i])))
1174 && ((in != 0 && MATCHES (reload_in[i], in) && ! dont_share
1175 && (out == 0 || reload_out[i] == 0 || MATCHES (reload_out[i], out)))
1177 (out != 0 && MATCHES (reload_out[i], out)
1178 && (in == 0 || reload_in[i] == 0 || MATCHES (reload_in[i], in))))
1179 && (reg_class_size[(int) class] == 1
1180 #ifdef SMALL_REGISTER_CLASSES
1181 || SMALL_REGISTER_CLASSES
1182 #endif
1184 && MERGABLE_RELOADS (type, reload_when_needed[i],
1185 opnum, reload_opnum[i]))
1186 break;
1188 /* Reloading a plain reg for input can match a reload to postincrement
1189 that reg, since the postincrement's value is the right value.
1190 Likewise, it can match a preincrement reload, since we regard
1191 the preincrementation as happening before any ref in this insn
1192 to that register. */
1193 if (i == n_reloads)
1194 for (i = 0; i < n_reloads; i++)
1195 if ((reg_class_subset_p (class, reload_reg_class[i])
1196 || reg_class_subset_p (reload_reg_class[i], class))
1197 /* If the existing reload has a register, it must fit our class. */
1198 && (reload_reg_rtx[i] == 0
1199 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1200 true_regnum (reload_reg_rtx[i])))
1201 && out == 0 && reload_out[i] == 0 && reload_in[i] != 0
1202 && ((GET_CODE (in) == REG
1203 && (GET_CODE (reload_in[i]) == POST_INC
1204 || GET_CODE (reload_in[i]) == POST_DEC
1205 || GET_CODE (reload_in[i]) == PRE_INC
1206 || GET_CODE (reload_in[i]) == PRE_DEC)
1207 && MATCHES (XEXP (reload_in[i], 0), in))
1209 (GET_CODE (reload_in[i]) == REG
1210 && (GET_CODE (in) == POST_INC
1211 || GET_CODE (in) == POST_DEC
1212 || GET_CODE (in) == PRE_INC
1213 || GET_CODE (in) == PRE_DEC)
1214 && MATCHES (XEXP (in, 0), reload_in[i])))
1215 && (reg_class_size[(int) class] == 1
1216 #ifdef SMALL_REGISTER_CLASSES
1217 || SMALL_REGISTER_CLASSES
1218 #endif
1220 && MERGABLE_RELOADS (type, reload_when_needed[i],
1221 opnum, reload_opnum[i]))
1223 /* Make sure reload_in ultimately has the increment,
1224 not the plain register. */
1225 if (GET_CODE (in) == REG)
1226 in = reload_in[i];
1227 break;
1230 if (i == n_reloads)
1232 /* See if we need a secondary reload register to move between CLASS
1233 and IN or CLASS and OUT. Get the icode and push any required reloads
1234 needed for each of them if so. */
1236 #ifdef SECONDARY_INPUT_RELOAD_CLASS
1237 if (in != 0)
1238 secondary_in_reload
1239 = push_secondary_reload (1, in, opnum, optional, class, inmode, type,
1240 &secondary_in_icode);
1241 #endif
1243 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1244 if (out != 0 && GET_CODE (out) != SCRATCH)
1245 secondary_out_reload
1246 = push_secondary_reload (0, out, opnum, optional, class, outmode,
1247 type, &secondary_out_icode);
1248 #endif
1250 /* We found no existing reload suitable for re-use.
1251 So add an additional reload. */
1253 i = n_reloads;
1254 reload_in[i] = in;
1255 reload_out[i] = out;
1256 reload_reg_class[i] = class;
1257 reload_inmode[i] = inmode;
1258 reload_outmode[i] = outmode;
1259 reload_reg_rtx[i] = 0;
1260 reload_optional[i] = optional;
1261 reload_inc[i] = 0;
1262 reload_nocombine[i] = 0;
1263 reload_in_reg[i] = inloc ? *inloc : 0;
1264 reload_opnum[i] = opnum;
1265 reload_when_needed[i] = type;
1266 reload_secondary_in_reload[i] = secondary_in_reload;
1267 reload_secondary_out_reload[i] = secondary_out_reload;
1268 reload_secondary_in_icode[i] = secondary_in_icode;
1269 reload_secondary_out_icode[i] = secondary_out_icode;
1270 reload_secondary_p[i] = 0;
1272 n_reloads++;
1274 #ifdef SECONDARY_MEMORY_NEEDED
1275 /* If a memory location is needed for the copy, make one. */
1276 if (in != 0 && GET_CODE (in) == REG
1277 && REGNO (in) < FIRST_PSEUDO_REGISTER
1278 && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (REGNO (in)),
1279 class, inmode))
1280 get_secondary_mem (in, inmode, opnum, type);
1282 if (out != 0 && GET_CODE (out) == REG
1283 && REGNO (out) < FIRST_PSEUDO_REGISTER
1284 && SECONDARY_MEMORY_NEEDED (class, REGNO_REG_CLASS (REGNO (out)),
1285 outmode))
1286 get_secondary_mem (out, outmode, opnum, type);
1287 #endif
1289 else
1291 /* We are reusing an existing reload,
1292 but we may have additional information for it.
1293 For example, we may now have both IN and OUT
1294 while the old one may have just one of them. */
1296 /* The modes can be different. If they are, we want to reload in
1297 the larger mode, so that the value is valid for both modes. */
1298 if (inmode != VOIDmode
1299 && GET_MODE_SIZE (inmode) > GET_MODE_SIZE (reload_inmode[i]))
1300 reload_inmode[i] = inmode;
1301 if (outmode != VOIDmode
1302 && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (reload_outmode[i]))
1303 reload_outmode[i] = outmode;
1304 if (in != 0)
1305 reload_in[i] = in;
1306 if (out != 0)
1307 reload_out[i] = out;
1308 if (reg_class_subset_p (class, reload_reg_class[i]))
1309 reload_reg_class[i] = class;
1310 reload_optional[i] &= optional;
1311 if (MERGE_TO_OTHER (type, reload_when_needed[i],
1312 opnum, reload_opnum[i]))
1313 reload_when_needed[i] = RELOAD_OTHER;
1314 reload_opnum[i] = MIN (reload_opnum[i], opnum);
1317 /* If the ostensible rtx being reload differs from the rtx found
1318 in the location to substitute, this reload is not safe to combine
1319 because we cannot reliably tell whether it appears in the insn. */
1321 if (in != 0 && in != *inloc)
1322 reload_nocombine[i] = 1;
1324 #if 0
1325 /* This was replaced by changes in find_reloads_address_1 and the new
1326 function inc_for_reload, which go with a new meaning of reload_inc. */
1328 /* If this is an IN/OUT reload in an insn that sets the CC,
1329 it must be for an autoincrement. It doesn't work to store
1330 the incremented value after the insn because that would clobber the CC.
1331 So we must do the increment of the value reloaded from,
1332 increment it, store it back, then decrement again. */
1333 if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
1335 out = 0;
1336 reload_out[i] = 0;
1337 reload_inc[i] = find_inc_amount (PATTERN (this_insn), in);
1338 /* If we did not find a nonzero amount-to-increment-by,
1339 that contradicts the belief that IN is being incremented
1340 in an address in this insn. */
1341 if (reload_inc[i] == 0)
1342 abort ();
1344 #endif
1346 /* If we will replace IN and OUT with the reload-reg,
1347 record where they are located so that substitution need
1348 not do a tree walk. */
1350 if (replace_reloads)
1352 if (inloc != 0)
1354 register struct replacement *r = &replacements[n_replacements++];
1355 r->what = i;
1356 r->subreg_loc = in_subreg_loc;
1357 r->where = inloc;
1358 r->mode = inmode;
1360 if (outloc != 0 && outloc != inloc)
1362 register struct replacement *r = &replacements[n_replacements++];
1363 r->what = i;
1364 r->where = outloc;
1365 r->subreg_loc = out_subreg_loc;
1366 r->mode = outmode;
1370 /* If this reload is just being introduced and it has both
1371 an incoming quantity and an outgoing quantity that are
1372 supposed to be made to match, see if either one of the two
1373 can serve as the place to reload into.
1375 If one of them is acceptable, set reload_reg_rtx[i]
1376 to that one. */
1378 if (in != 0 && out != 0 && in != out && reload_reg_rtx[i] == 0)
1380 reload_reg_rtx[i] = find_dummy_reload (in, out, inloc, outloc,
1381 inmode, outmode,
1382 reload_reg_class[i], i,
1383 earlyclobber_operand_p (out));
1385 /* If the outgoing register already contains the same value
1386 as the incoming one, we can dispense with loading it.
1387 The easiest way to tell the caller that is to give a phony
1388 value for the incoming operand (same as outgoing one). */
1389 if (reload_reg_rtx[i] == out
1390 && (GET_CODE (in) == REG || CONSTANT_P (in))
1391 && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
1392 static_reload_reg_p, i, inmode))
1393 reload_in[i] = out;
1396 /* If this is an input reload and the operand contains a register that
1397 dies in this insn and is used nowhere else, see if it is the right class
1398 to be used for this reload. Use it if so. (This occurs most commonly
1399 in the case of paradoxical SUBREGs and in-out reloads). We cannot do
1400 this if it is also an output reload that mentions the register unless
1401 the output is a SUBREG that clobbers an entire register.
1403 Note that the operand might be one of the spill regs, if it is a
1404 pseudo reg and we are in a block where spilling has not taken place.
1405 But if there is no spilling in this block, that is OK.
1406 An explicitly used hard reg cannot be a spill reg. */
1408 if (reload_reg_rtx[i] == 0 && in != 0)
1410 rtx note;
1411 int regno;
1413 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1414 if (REG_NOTE_KIND (note) == REG_DEAD
1415 && GET_CODE (XEXP (note, 0)) == REG
1416 && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1417 && reg_mentioned_p (XEXP (note, 0), in)
1418 && ! refers_to_regno_for_reload_p (regno,
1419 (regno
1420 + HARD_REGNO_NREGS (regno,
1421 inmode)),
1422 PATTERN (this_insn), inloc)
1423 /* If this is also an output reload, IN cannot be used as
1424 the reload register if it is set in this insn unless IN
1425 is also OUT. */
1426 && (out == 0 || in == out
1427 || ! hard_reg_set_here_p (regno,
1428 (regno
1429 + HARD_REGNO_NREGS (regno,
1430 inmode)),
1431 PATTERN (this_insn)))
1432 /* ??? Why is this code so different from the previous?
1433 Is there any simple coherent way to describe the two together?
1434 What's going on here. */
1435 && (in != out
1436 || (GET_CODE (in) == SUBREG
1437 && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1))
1438 / UNITS_PER_WORD)
1439 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1440 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
1441 /* Make sure the operand fits in the reg that dies. */
1442 && GET_MODE_SIZE (inmode) <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
1443 && HARD_REGNO_MODE_OK (regno, inmode)
1444 && GET_MODE_SIZE (outmode) <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
1445 && HARD_REGNO_MODE_OK (regno, outmode)
1446 && TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno)
1447 && !fixed_regs[regno])
1449 reload_reg_rtx[i] = gen_rtx (REG, inmode, regno);
1450 break;
1454 if (out)
1455 output_reloadnum = i;
1457 return i;
1460 /* Record an additional place we must replace a value
1461 for which we have already recorded a reload.
1462 RELOADNUM is the value returned by push_reload
1463 when the reload was recorded.
1464 This is used in insn patterns that use match_dup. */
1466 static void
1467 push_replacement (loc, reloadnum, mode)
1468 rtx *loc;
1469 int reloadnum;
1470 enum machine_mode mode;
1472 if (replace_reloads)
1474 register struct replacement *r = &replacements[n_replacements++];
1475 r->what = reloadnum;
1476 r->where = loc;
1477 r->subreg_loc = 0;
1478 r->mode = mode;
1482 /* Transfer all replacements that used to be in reload FROM to be in
1483 reload TO. */
1485 void
1486 transfer_replacements (to, from)
1487 int to, from;
1489 int i;
1491 for (i = 0; i < n_replacements; i++)
1492 if (replacements[i].what == from)
1493 replacements[i].what = to;
1496 /* If there is only one output reload, and it is not for an earlyclobber
1497 operand, try to combine it with a (logically unrelated) input reload
1498 to reduce the number of reload registers needed.
1500 This is safe if the input reload does not appear in
1501 the value being output-reloaded, because this implies
1502 it is not needed any more once the original insn completes.
1504 If that doesn't work, see we can use any of the registers that
1505 die in this insn as a reload register. We can if it is of the right
1506 class and does not appear in the value being output-reloaded. */
1508 static void
1509 combine_reloads ()
1511 int i;
1512 int output_reload = -1;
1513 int secondary_out = -1;
1514 rtx note;
1516 /* Find the output reload; return unless there is exactly one
1517 and that one is mandatory. */
1519 for (i = 0; i < n_reloads; i++)
1520 if (reload_out[i] != 0)
1522 if (output_reload >= 0)
1523 return;
1524 output_reload = i;
1527 if (output_reload < 0 || reload_optional[output_reload])
1528 return;
1530 /* An input-output reload isn't combinable. */
1532 if (reload_in[output_reload] != 0)
1533 return;
1535 /* If this reload is for an earlyclobber operand, we can't do anything. */
1536 if (earlyclobber_operand_p (reload_out[output_reload]))
1537 return;
1539 /* Check each input reload; can we combine it? */
1541 for (i = 0; i < n_reloads; i++)
1542 if (reload_in[i] && ! reload_optional[i] && ! reload_nocombine[i]
1543 /* Life span of this reload must not extend past main insn. */
1544 && reload_when_needed[i] != RELOAD_FOR_OUTPUT_ADDRESS
1545 && reload_when_needed[i] != RELOAD_FOR_OUTADDR_ADDRESS
1546 && reload_when_needed[i] != RELOAD_OTHER
1547 && (CLASS_MAX_NREGS (reload_reg_class[i], reload_inmode[i])
1548 == CLASS_MAX_NREGS (reload_reg_class[output_reload],
1549 reload_outmode[output_reload]))
1550 && reload_inc[i] == 0
1551 && reload_reg_rtx[i] == 0
1552 #ifdef SECONDARY_MEMORY_NEEDED
1553 /* Don't combine two reloads with different secondary
1554 memory locations. */
1555 && (secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[i]] == 0
1556 || secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]] == 0
1557 || rtx_equal_p (secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[i]],
1558 secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]]))
1559 #endif
1560 && (
1561 #ifdef SMALL_REGISTER_CLASSES
1562 SMALL_REGISTER_CLASSES
1563 #else
1565 #endif
1566 ? reload_reg_class[i] == reload_reg_class[output_reload]
1567 : (reg_class_subset_p (reload_reg_class[i],
1568 reload_reg_class[output_reload])
1569 || reg_class_subset_p (reload_reg_class[output_reload],
1570 reload_reg_class[i])))
1571 && (MATCHES (reload_in[i], reload_out[output_reload])
1572 /* Args reversed because the first arg seems to be
1573 the one that we imagine being modified
1574 while the second is the one that might be affected. */
1575 || (! reg_overlap_mentioned_for_reload_p (reload_out[output_reload],
1576 reload_in[i])
1577 /* However, if the input is a register that appears inside
1578 the output, then we also can't share.
1579 Imagine (set (mem (reg 69)) (plus (reg 69) ...)).
1580 If the same reload reg is used for both reg 69 and the
1581 result to be stored in memory, then that result
1582 will clobber the address of the memory ref. */
1583 && ! (GET_CODE (reload_in[i]) == REG
1584 && reg_overlap_mentioned_for_reload_p (reload_in[i],
1585 reload_out[output_reload]))))
1586 && (reg_class_size[(int) reload_reg_class[i]]
1587 #ifdef SMALL_REGISTER_CLASSES
1588 || SMALL_REGISTER_CLASSES
1589 #endif
1591 /* We will allow making things slightly worse by combining an
1592 input and an output, but no worse than that. */
1593 && (reload_when_needed[i] == RELOAD_FOR_INPUT
1594 || reload_when_needed[i] == RELOAD_FOR_OUTPUT))
1596 int j;
1598 /* We have found a reload to combine with! */
1599 reload_out[i] = reload_out[output_reload];
1600 reload_outmode[i] = reload_outmode[output_reload];
1601 /* Mark the old output reload as inoperative. */
1602 reload_out[output_reload] = 0;
1603 /* The combined reload is needed for the entire insn. */
1604 reload_when_needed[i] = RELOAD_OTHER;
1605 /* If the output reload had a secondary reload, copy it. */
1606 if (reload_secondary_out_reload[output_reload] != -1)
1608 reload_secondary_out_reload[i]
1609 = reload_secondary_out_reload[output_reload];
1610 reload_secondary_out_icode[i]
1611 = reload_secondary_out_icode[output_reload];
1614 #ifdef SECONDARY_MEMORY_NEEDED
1615 /* Copy any secondary MEM. */
1616 if (secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]] != 0)
1617 secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[i]]
1618 = secondary_memlocs_elim[(int) reload_outmode[output_reload]][reload_opnum[output_reload]];
1619 #endif
1620 /* If required, minimize the register class. */
1621 if (reg_class_subset_p (reload_reg_class[output_reload],
1622 reload_reg_class[i]))
1623 reload_reg_class[i] = reload_reg_class[output_reload];
1625 /* Transfer all replacements from the old reload to the combined. */
1626 for (j = 0; j < n_replacements; j++)
1627 if (replacements[j].what == output_reload)
1628 replacements[j].what = i;
1630 return;
1633 /* If this insn has only one operand that is modified or written (assumed
1634 to be the first), it must be the one corresponding to this reload. It
1635 is safe to use anything that dies in this insn for that output provided
1636 that it does not occur in the output (we already know it isn't an
1637 earlyclobber. If this is an asm insn, give up. */
1639 if (INSN_CODE (this_insn) == -1)
1640 return;
1642 for (i = 1; i < insn_n_operands[INSN_CODE (this_insn)]; i++)
1643 if (insn_operand_constraint[INSN_CODE (this_insn)][i][0] == '='
1644 || insn_operand_constraint[INSN_CODE (this_insn)][i][0] == '+')
1645 return;
1647 /* See if some hard register that dies in this insn and is not used in
1648 the output is the right class. Only works if the register we pick
1649 up can fully hold our output reload. */
1650 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1651 if (REG_NOTE_KIND (note) == REG_DEAD
1652 && GET_CODE (XEXP (note, 0)) == REG
1653 && ! reg_overlap_mentioned_for_reload_p (XEXP (note, 0),
1654 reload_out[output_reload])
1655 && REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1656 && HARD_REGNO_MODE_OK (REGNO (XEXP (note, 0)), reload_outmode[output_reload])
1657 && TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[output_reload]],
1658 REGNO (XEXP (note, 0)))
1659 && (HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), reload_outmode[output_reload])
1660 <= HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), GET_MODE (XEXP (note, 0))))
1661 /* Ensure that a secondary or tertiary reload for this output
1662 won't want this register. */
1663 && ((secondary_out = reload_secondary_out_reload[output_reload]) == -1
1664 || (! (TEST_HARD_REG_BIT
1665 (reg_class_contents[(int) reload_reg_class[secondary_out]],
1666 REGNO (XEXP (note, 0))))
1667 && ((secondary_out = reload_secondary_out_reload[secondary_out]) == -1
1668 || ! (TEST_HARD_REG_BIT
1669 (reg_class_contents[(int) reload_reg_class[secondary_out]],
1670 REGNO (XEXP (note, 0)))))))
1671 && ! fixed_regs[REGNO (XEXP (note, 0))])
1673 reload_reg_rtx[output_reload] = gen_rtx (REG,
1674 reload_outmode[output_reload],
1675 REGNO (XEXP (note, 0)));
1676 return;
1680 /* Try to find a reload register for an in-out reload (expressions IN and OUT).
1681 See if one of IN and OUT is a register that may be used;
1682 this is desirable since a spill-register won't be needed.
1683 If so, return the register rtx that proves acceptable.
1685 INLOC and OUTLOC are locations where IN and OUT appear in the insn.
1686 CLASS is the register class required for the reload.
1688 If FOR_REAL is >= 0, it is the number of the reload,
1689 and in some cases when it can be discovered that OUT doesn't need
1690 to be computed, clear out reload_out[FOR_REAL].
1692 If FOR_REAL is -1, this should not be done, because this call
1693 is just to see if a register can be found, not to find and install it.
1695 EARLYCLOBBER is non-zero if OUT is an earlyclobber operand. This
1696 puts an additional constraint on being able to use IN for OUT since
1697 IN must not appear elsewhere in the insn (it is assumed that IN itself
1698 is safe from the earlyclobber). */
1700 static rtx
1701 find_dummy_reload (real_in, real_out, inloc, outloc,
1702 inmode, outmode, class, for_real, earlyclobber)
1703 rtx real_in, real_out;
1704 rtx *inloc, *outloc;
1705 enum machine_mode inmode, outmode;
1706 enum reg_class class;
1707 int for_real;
1708 int earlyclobber;
1710 rtx in = real_in;
1711 rtx out = real_out;
1712 int in_offset = 0;
1713 int out_offset = 0;
1714 rtx value = 0;
1716 /* If operands exceed a word, we can't use either of them
1717 unless they have the same size. */
1718 if (GET_MODE_SIZE (outmode) != GET_MODE_SIZE (inmode)
1719 && (GET_MODE_SIZE (outmode) > UNITS_PER_WORD
1720 || GET_MODE_SIZE (inmode) > UNITS_PER_WORD))
1721 return 0;
1723 /* Find the inside of any subregs. */
1724 while (GET_CODE (out) == SUBREG)
1726 out_offset = SUBREG_WORD (out);
1727 out = SUBREG_REG (out);
1729 while (GET_CODE (in) == SUBREG)
1731 in_offset = SUBREG_WORD (in);
1732 in = SUBREG_REG (in);
1735 /* Narrow down the reg class, the same way push_reload will;
1736 otherwise we might find a dummy now, but push_reload won't. */
1737 class = PREFERRED_RELOAD_CLASS (in, class);
1739 /* See if OUT will do. */
1740 if (GET_CODE (out) == REG
1741 && REGNO (out) < FIRST_PSEUDO_REGISTER)
1743 register int regno = REGNO (out) + out_offset;
1744 int nwords = HARD_REGNO_NREGS (regno, outmode);
1745 rtx saved_rtx;
1747 /* When we consider whether the insn uses OUT,
1748 ignore references within IN. They don't prevent us
1749 from copying IN into OUT, because those refs would
1750 move into the insn that reloads IN.
1752 However, we only ignore IN in its role as this reload.
1753 If the insn uses IN elsewhere and it contains OUT,
1754 that counts. We can't be sure it's the "same" operand
1755 so it might not go through this reload. */
1756 saved_rtx = *inloc;
1757 *inloc = const0_rtx;
1759 if (regno < FIRST_PSEUDO_REGISTER
1760 /* A fixed reg that can overlap other regs better not be used
1761 for reloading in any way. */
1762 #ifdef OVERLAPPING_REGNO_P
1763 && ! (fixed_regs[regno] && OVERLAPPING_REGNO_P (regno))
1764 #endif
1765 && ! refers_to_regno_for_reload_p (regno, regno + nwords,
1766 PATTERN (this_insn), outloc))
1768 int i;
1769 for (i = 0; i < nwords; i++)
1770 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1771 regno + i))
1772 break;
1774 if (i == nwords)
1776 if (GET_CODE (real_out) == REG)
1777 value = real_out;
1778 else
1779 value = gen_rtx (REG, outmode, regno);
1783 *inloc = saved_rtx;
1786 /* Consider using IN if OUT was not acceptable
1787 or if OUT dies in this insn (like the quotient in a divmod insn).
1788 We can't use IN unless it is dies in this insn,
1789 which means we must know accurately which hard regs are live.
1790 Also, the result can't go in IN if IN is used within OUT,
1791 or if OUT is an earlyclobber and IN appears elsewhere in the insn. */
1792 if (hard_regs_live_known
1793 && GET_CODE (in) == REG
1794 && REGNO (in) < FIRST_PSEUDO_REGISTER
1795 && (value == 0
1796 || find_reg_note (this_insn, REG_UNUSED, real_out))
1797 && find_reg_note (this_insn, REG_DEAD, real_in)
1798 && !fixed_regs[REGNO (in)]
1799 && HARD_REGNO_MODE_OK (REGNO (in),
1800 /* The only case where out and real_out might
1801 have different modes is where real_out
1802 is a subreg, and in that case, out
1803 has a real mode. */
1804 (GET_MODE (out) != VOIDmode
1805 ? GET_MODE (out) : outmode)))
1807 register int regno = REGNO (in) + in_offset;
1808 int nwords = HARD_REGNO_NREGS (regno, inmode);
1810 if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, NULL_PTR)
1811 && ! hard_reg_set_here_p (regno, regno + nwords,
1812 PATTERN (this_insn))
1813 && (! earlyclobber
1814 || ! refers_to_regno_for_reload_p (regno, regno + nwords,
1815 PATTERN (this_insn), inloc)))
1817 int i;
1818 for (i = 0; i < nwords; i++)
1819 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1820 regno + i))
1821 break;
1823 if (i == nwords)
1825 /* If we were going to use OUT as the reload reg
1826 and changed our mind, it means OUT is a dummy that
1827 dies here. So don't bother copying value to it. */
1828 if (for_real >= 0 && value == real_out)
1829 reload_out[for_real] = 0;
1830 if (GET_CODE (real_in) == REG)
1831 value = real_in;
1832 else
1833 value = gen_rtx (REG, inmode, regno);
1838 return value;
1841 /* This page contains subroutines used mainly for determining
1842 whether the IN or an OUT of a reload can serve as the
1843 reload register. */
1845 /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
1847 static int
1848 earlyclobber_operand_p (x)
1849 rtx x;
1851 int i;
1853 for (i = 0; i < n_earlyclobbers; i++)
1854 if (reload_earlyclobbers[i] == x)
1855 return 1;
1857 return 0;
1860 /* Return 1 if expression X alters a hard reg in the range
1861 from BEG_REGNO (inclusive) to END_REGNO (exclusive),
1862 either explicitly or in the guise of a pseudo-reg allocated to REGNO.
1863 X should be the body of an instruction. */
1865 static int
1866 hard_reg_set_here_p (beg_regno, end_regno, x)
1867 register int beg_regno, end_regno;
1868 rtx x;
1870 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
1872 register rtx op0 = SET_DEST (x);
1873 while (GET_CODE (op0) == SUBREG)
1874 op0 = SUBREG_REG (op0);
1875 if (GET_CODE (op0) == REG)
1877 register int r = REGNO (op0);
1878 /* See if this reg overlaps range under consideration. */
1879 if (r < end_regno
1880 && r + HARD_REGNO_NREGS (r, GET_MODE (op0)) > beg_regno)
1881 return 1;
1884 else if (GET_CODE (x) == PARALLEL)
1886 register int i = XVECLEN (x, 0) - 1;
1887 for (; i >= 0; i--)
1888 if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i)))
1889 return 1;
1892 return 0;
1895 /* Return 1 if ADDR is a valid memory address for mode MODE,
1896 and check that each pseudo reg has the proper kind of
1897 hard reg. */
1900 strict_memory_address_p (mode, addr)
1901 enum machine_mode mode;
1902 register rtx addr;
1904 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1905 return 0;
1907 win:
1908 return 1;
1911 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
1912 if they are the same hard reg, and has special hacks for
1913 autoincrement and autodecrement.
1914 This is specifically intended for find_reloads to use
1915 in determining whether two operands match.
1916 X is the operand whose number is the lower of the two.
1918 The value is 2 if Y contains a pre-increment that matches
1919 a non-incrementing address in X. */
1921 /* ??? To be completely correct, we should arrange to pass
1922 for X the output operand and for Y the input operand.
1923 For now, we assume that the output operand has the lower number
1924 because that is natural in (SET output (... input ...)). */
1927 operands_match_p (x, y)
1928 register rtx x, y;
1930 register int i;
1931 register RTX_CODE code = GET_CODE (x);
1932 register char *fmt;
1933 int success_2;
1935 if (x == y)
1936 return 1;
1937 if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
1938 && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
1939 && GET_CODE (SUBREG_REG (y)) == REG)))
1941 register int j;
1943 if (code == SUBREG)
1945 i = REGNO (SUBREG_REG (x));
1946 if (i >= FIRST_PSEUDO_REGISTER)
1947 goto slow;
1948 i += SUBREG_WORD (x);
1950 else
1951 i = REGNO (x);
1953 if (GET_CODE (y) == SUBREG)
1955 j = REGNO (SUBREG_REG (y));
1956 if (j >= FIRST_PSEUDO_REGISTER)
1957 goto slow;
1958 j += SUBREG_WORD (y);
1960 else
1961 j = REGNO (y);
1963 /* On a WORDS_BIG_ENDIAN machine, point to the last register of a
1964 multiple hard register group, so that for example (reg:DI 0) and
1965 (reg:SI 1) will be considered the same register. */
1966 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
1967 && i < FIRST_PSEUDO_REGISTER)
1968 i += (GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD) - 1;
1969 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD
1970 && j < FIRST_PSEUDO_REGISTER)
1971 j += (GET_MODE_SIZE (GET_MODE (y)) / UNITS_PER_WORD) - 1;
1973 return i == j;
1975 /* If two operands must match, because they are really a single
1976 operand of an assembler insn, then two postincrements are invalid
1977 because the assembler insn would increment only once.
1978 On the other hand, an postincrement matches ordinary indexing
1979 if the postincrement is the output operand. */
1980 if (code == POST_DEC || code == POST_INC)
1981 return operands_match_p (XEXP (x, 0), y);
1982 /* Two preincrements are invalid
1983 because the assembler insn would increment only once.
1984 On the other hand, an preincrement matches ordinary indexing
1985 if the preincrement is the input operand.
1986 In this case, return 2, since some callers need to do special
1987 things when this happens. */
1988 if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC)
1989 return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
1991 slow:
1993 /* Now we have disposed of all the cases
1994 in which different rtx codes can match. */
1995 if (code != GET_CODE (y))
1996 return 0;
1997 if (code == LABEL_REF)
1998 return XEXP (x, 0) == XEXP (y, 0);
1999 if (code == SYMBOL_REF)
2000 return XSTR (x, 0) == XSTR (y, 0);
2002 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
2004 if (GET_MODE (x) != GET_MODE (y))
2005 return 0;
2007 /* Compare the elements. If any pair of corresponding elements
2008 fail to match, return 0 for the whole things. */
2010 success_2 = 0;
2011 fmt = GET_RTX_FORMAT (code);
2012 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2014 int val;
2015 switch (fmt[i])
2017 case 'w':
2018 if (XWINT (x, i) != XWINT (y, i))
2019 return 0;
2020 break;
2022 case 'i':
2023 if (XINT (x, i) != XINT (y, i))
2024 return 0;
2025 break;
2027 case 'e':
2028 val = operands_match_p (XEXP (x, i), XEXP (y, i));
2029 if (val == 0)
2030 return 0;
2031 /* If any subexpression returns 2,
2032 we should return 2 if we are successful. */
2033 if (val == 2)
2034 success_2 = 1;
2035 break;
2037 case '0':
2038 break;
2040 /* It is believed that rtx's at this level will never
2041 contain anything but integers and other rtx's,
2042 except for within LABEL_REFs and SYMBOL_REFs. */
2043 default:
2044 abort ();
2047 return 1 + success_2;
2050 /* Return the number of times character C occurs in string S. */
2053 n_occurrences (c, s)
2054 int c;
2055 char *s;
2057 int n = 0;
2058 while (*s)
2059 n += (*s++ == c);
2060 return n;
2063 /* Describe the range of registers or memory referenced by X.
2064 If X is a register, set REG_FLAG and put the first register
2065 number into START and the last plus one into END.
2066 If X is a memory reference, put a base address into BASE
2067 and a range of integer offsets into START and END.
2068 If X is pushing on the stack, we can assume it causes no trouble,
2069 so we set the SAFE field. */
2071 static struct decomposition
2072 decompose (x)
2073 rtx x;
2075 struct decomposition val;
2076 int all_const = 0;
2078 val.reg_flag = 0;
2079 val.safe = 0;
2080 val.base = 0;
2081 if (GET_CODE (x) == MEM)
2083 rtx base, offset = 0;
2084 rtx addr = XEXP (x, 0);
2086 if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
2087 || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
2089 val.base = XEXP (addr, 0);
2090 val.start = - GET_MODE_SIZE (GET_MODE (x));
2091 val.end = GET_MODE_SIZE (GET_MODE (x));
2092 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2093 return val;
2096 if (GET_CODE (addr) == CONST)
2098 addr = XEXP (addr, 0);
2099 all_const = 1;
2101 if (GET_CODE (addr) == PLUS)
2103 if (CONSTANT_P (XEXP (addr, 0)))
2105 base = XEXP (addr, 1);
2106 offset = XEXP (addr, 0);
2108 else if (CONSTANT_P (XEXP (addr, 1)))
2110 base = XEXP (addr, 0);
2111 offset = XEXP (addr, 1);
2115 if (offset == 0)
2117 base = addr;
2118 offset = const0_rtx;
2120 if (GET_CODE (offset) == CONST)
2121 offset = XEXP (offset, 0);
2122 if (GET_CODE (offset) == PLUS)
2124 if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
2126 base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 1));
2127 offset = XEXP (offset, 0);
2129 else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
2131 base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 0));
2132 offset = XEXP (offset, 1);
2134 else
2136 base = gen_rtx (PLUS, GET_MODE (base), base, offset);
2137 offset = const0_rtx;
2140 else if (GET_CODE (offset) != CONST_INT)
2142 base = gen_rtx (PLUS, GET_MODE (base), base, offset);
2143 offset = const0_rtx;
2146 if (all_const && GET_CODE (base) == PLUS)
2147 base = gen_rtx (CONST, GET_MODE (base), base);
2149 if (GET_CODE (offset) != CONST_INT)
2150 abort ();
2152 val.start = INTVAL (offset);
2153 val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
2154 val.base = base;
2155 return val;
2157 else if (GET_CODE (x) == REG)
2159 val.reg_flag = 1;
2160 val.start = true_regnum (x);
2161 if (val.start < 0)
2163 /* A pseudo with no hard reg. */
2164 val.start = REGNO (x);
2165 val.end = val.start + 1;
2167 else
2168 /* A hard reg. */
2169 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2171 else if (GET_CODE (x) == SUBREG)
2173 if (GET_CODE (SUBREG_REG (x)) != REG)
2174 /* This could be more precise, but it's good enough. */
2175 return decompose (SUBREG_REG (x));
2176 val.reg_flag = 1;
2177 val.start = true_regnum (x);
2178 if (val.start < 0)
2179 return decompose (SUBREG_REG (x));
2180 else
2181 /* A hard reg. */
2182 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2184 else if (CONSTANT_P (x)
2185 /* This hasn't been assigned yet, so it can't conflict yet. */
2186 || GET_CODE (x) == SCRATCH)
2187 val.safe = 1;
2188 else
2189 abort ();
2190 return val;
2193 /* Return 1 if altering Y will not modify the value of X.
2194 Y is also described by YDATA, which should be decompose (Y). */
2196 static int
2197 immune_p (x, y, ydata)
2198 rtx x, y;
2199 struct decomposition ydata;
2201 struct decomposition xdata;
2203 if (ydata.reg_flag)
2204 return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, NULL_PTR);
2205 if (ydata.safe)
2206 return 1;
2208 if (GET_CODE (y) != MEM)
2209 abort ();
2210 /* If Y is memory and X is not, Y can't affect X. */
2211 if (GET_CODE (x) != MEM)
2212 return 1;
2214 xdata = decompose (x);
2216 if (! rtx_equal_p (xdata.base, ydata.base))
2218 /* If bases are distinct symbolic constants, there is no overlap. */
2219 if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
2220 return 1;
2221 /* Constants and stack slots never overlap. */
2222 if (CONSTANT_P (xdata.base)
2223 && (ydata.base == frame_pointer_rtx
2224 || ydata.base == hard_frame_pointer_rtx
2225 || ydata.base == stack_pointer_rtx))
2226 return 1;
2227 if (CONSTANT_P (ydata.base)
2228 && (xdata.base == frame_pointer_rtx
2229 || xdata.base == hard_frame_pointer_rtx
2230 || xdata.base == stack_pointer_rtx))
2231 return 1;
2232 /* If either base is variable, we don't know anything. */
2233 return 0;
2237 return (xdata.start >= ydata.end || ydata.start >= xdata.end);
2240 /* Similar, but calls decompose. */
2243 safe_from_earlyclobber (op, clobber)
2244 rtx op, clobber;
2246 struct decomposition early_data;
2248 early_data = decompose (clobber);
2249 return immune_p (op, clobber, early_data);
2252 /* Main entry point of this file: search the body of INSN
2253 for values that need reloading and record them with push_reload.
2254 REPLACE nonzero means record also where the values occur
2255 so that subst_reloads can be used.
2257 IND_LEVELS says how many levels of indirection are supported by this
2258 machine; a value of zero means that a memory reference is not a valid
2259 memory address.
2261 LIVE_KNOWN says we have valid information about which hard
2262 regs are live at each point in the program; this is true when
2263 we are called from global_alloc but false when stupid register
2264 allocation has been done.
2266 RELOAD_REG_P if nonzero is a vector indexed by hard reg number
2267 which is nonnegative if the reg has been commandeered for reloading into.
2268 It is copied into STATIC_RELOAD_REG_P and referenced from there
2269 by various subroutines. */
2271 void
2272 find_reloads (insn, replace, ind_levels, live_known, reload_reg_p)
2273 rtx insn;
2274 int replace, ind_levels;
2275 int live_known;
2276 short *reload_reg_p;
2278 #ifdef REGISTER_CONSTRAINTS
2280 register int insn_code_number;
2281 register int i, j;
2282 int noperands;
2283 /* These are the constraints for the insn. We don't change them. */
2284 char *constraints1[MAX_RECOG_OPERANDS];
2285 /* These start out as the constraints for the insn
2286 and they are chewed up as we consider alternatives. */
2287 char *constraints[MAX_RECOG_OPERANDS];
2288 /* These are the preferred classes for an operand, or NO_REGS if it isn't
2289 a register. */
2290 enum reg_class preferred_class[MAX_RECOG_OPERANDS];
2291 char pref_or_nothing[MAX_RECOG_OPERANDS];
2292 /* Nonzero for a MEM operand whose entire address needs a reload. */
2293 int address_reloaded[MAX_RECOG_OPERANDS];
2294 /* Value of enum reload_type to use for operand. */
2295 enum reload_type operand_type[MAX_RECOG_OPERANDS];
2296 /* Value of enum reload_type to use within address of operand. */
2297 enum reload_type address_type[MAX_RECOG_OPERANDS];
2298 /* Save the usage of each operand. */
2299 enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS];
2300 int no_input_reloads = 0, no_output_reloads = 0;
2301 int n_alternatives;
2302 int this_alternative[MAX_RECOG_OPERANDS];
2303 char this_alternative_win[MAX_RECOG_OPERANDS];
2304 char this_alternative_offmemok[MAX_RECOG_OPERANDS];
2305 char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2306 int this_alternative_matches[MAX_RECOG_OPERANDS];
2307 int swapped;
2308 int goal_alternative[MAX_RECOG_OPERANDS];
2309 int this_alternative_number;
2310 int goal_alternative_number;
2311 int operand_reloadnum[MAX_RECOG_OPERANDS];
2312 int goal_alternative_matches[MAX_RECOG_OPERANDS];
2313 int goal_alternative_matched[MAX_RECOG_OPERANDS];
2314 char goal_alternative_win[MAX_RECOG_OPERANDS];
2315 char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
2316 char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2317 int goal_alternative_swapped;
2318 int best;
2319 int commutative;
2320 char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
2321 rtx substed_operand[MAX_RECOG_OPERANDS];
2322 rtx body = PATTERN (insn);
2323 rtx set = single_set (insn);
2324 int goal_earlyclobber, this_earlyclobber;
2325 enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
2327 this_insn = insn;
2328 this_insn_is_asm = 0; /* Tentative. */
2329 n_reloads = 0;
2330 n_replacements = 0;
2331 n_memlocs = 0;
2332 n_earlyclobbers = 0;
2333 replace_reloads = replace;
2334 hard_regs_live_known = live_known;
2335 static_reload_reg_p = reload_reg_p;
2337 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
2338 neither are insns that SET cc0. Insns that use CC0 are not allowed
2339 to have any input reloads. */
2340 if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == CALL_INSN)
2341 no_output_reloads = 1;
2343 #ifdef HAVE_cc0
2344 if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
2345 no_input_reloads = 1;
2346 if (reg_set_p (cc0_rtx, PATTERN (insn)))
2347 no_output_reloads = 1;
2348 #endif
2350 #ifdef SECONDARY_MEMORY_NEEDED
2351 /* The eliminated forms of any secondary memory locations are per-insn, so
2352 clear them out here. */
2354 bzero ((char *) secondary_memlocs_elim, sizeof secondary_memlocs_elim);
2355 #endif
2357 /* Find what kind of insn this is. NOPERANDS gets number of operands.
2358 Make OPERANDS point to a vector of operand values.
2359 Make OPERAND_LOCS point to a vector of pointers to
2360 where the operands were found.
2361 Fill CONSTRAINTS and CONSTRAINTS1 with pointers to the
2362 constraint-strings for this insn.
2363 Return if the insn needs no reload processing. */
2365 switch (GET_CODE (body))
2367 case USE:
2368 case CLOBBER:
2369 case ASM_INPUT:
2370 case ADDR_VEC:
2371 case ADDR_DIFF_VEC:
2372 return;
2374 case SET:
2375 /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2376 is cheap to move between them. If it is not, there may not be an insn
2377 to do the copy, so we may need a reload. */
2378 if (GET_CODE (SET_DEST (body)) == REG
2379 && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2380 && GET_CODE (SET_SRC (body)) == REG
2381 && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2382 && REGISTER_MOVE_COST (REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2383 REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2384 return;
2385 case PARALLEL:
2386 case ASM_OPERANDS:
2387 reload_n_operands = noperands = asm_noperands (body);
2388 if (noperands >= 0)
2390 /* This insn is an `asm' with operands. */
2392 insn_code_number = -1;
2393 this_insn_is_asm = 1;
2395 /* expand_asm_operands makes sure there aren't too many operands. */
2396 if (noperands > MAX_RECOG_OPERANDS)
2397 abort ();
2399 /* Now get the operand values and constraints out of the insn. */
2401 decode_asm_operands (body, recog_operand, recog_operand_loc,
2402 constraints, operand_mode);
2403 if (noperands > 0)
2405 bcopy ((char *) constraints, (char *) constraints1,
2406 noperands * sizeof (char *));
2407 n_alternatives = n_occurrences (',', constraints[0]) + 1;
2408 for (i = 1; i < noperands; i++)
2409 if (n_alternatives != n_occurrences (',', constraints[i]) + 1)
2411 error_for_asm (insn, "operand constraints differ in number of alternatives");
2412 /* Avoid further trouble with this insn. */
2413 PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
2414 n_reloads = 0;
2415 return;
2418 break;
2421 default:
2422 /* Ordinary insn: recognize it, get the operands via insn_extract
2423 and get the constraints. */
2425 insn_code_number = recog_memoized (insn);
2426 if (insn_code_number < 0)
2427 fatal_insn_not_found (insn);
2429 reload_n_operands = noperands = insn_n_operands[insn_code_number];
2430 n_alternatives = insn_n_alternatives[insn_code_number];
2431 /* Just return "no reloads" if insn has no operands with constraints. */
2432 if (n_alternatives == 0)
2433 return;
2434 insn_extract (insn);
2435 for (i = 0; i < noperands; i++)
2437 constraints[i] = constraints1[i]
2438 = insn_operand_constraint[insn_code_number][i];
2439 operand_mode[i] = insn_operand_mode[insn_code_number][i];
2443 if (noperands == 0)
2444 return;
2446 commutative = -1;
2448 /* If we will need to know, later, whether some pair of operands
2449 are the same, we must compare them now and save the result.
2450 Reloading the base and index registers will clobber them
2451 and afterward they will fail to match. */
2453 for (i = 0; i < noperands; i++)
2455 register char *p;
2456 register int c;
2458 substed_operand[i] = recog_operand[i];
2459 p = constraints[i];
2461 modified[i] = RELOAD_READ;
2463 /* Scan this operand's constraint to see if it is an output operand,
2464 an in-out operand, is commutative, or should match another. */
2466 while (c = *p++)
2468 if (c == '=')
2469 modified[i] = RELOAD_WRITE;
2470 else if (c == '+')
2471 modified[i] = RELOAD_READ_WRITE;
2472 else if (c == '%')
2474 /* The last operand should not be marked commutative. */
2475 if (i == noperands - 1)
2477 if (this_insn_is_asm)
2478 warning_for_asm (this_insn,
2479 "`%%' constraint used with last operand");
2480 else
2481 abort ();
2483 else
2484 commutative = i;
2486 else if (c >= '0' && c <= '9')
2488 c -= '0';
2489 operands_match[c][i]
2490 = operands_match_p (recog_operand[c], recog_operand[i]);
2492 /* An operand may not match itself. */
2493 if (c == i)
2495 if (this_insn_is_asm)
2496 warning_for_asm (this_insn,
2497 "operand %d has constraint %d", i, c);
2498 else
2499 abort ();
2502 /* If C can be commuted with C+1, and C might need to match I,
2503 then C+1 might also need to match I. */
2504 if (commutative >= 0)
2506 if (c == commutative || c == commutative + 1)
2508 int other = c + (c == commutative ? 1 : -1);
2509 operands_match[other][i]
2510 = operands_match_p (recog_operand[other], recog_operand[i]);
2512 if (i == commutative || i == commutative + 1)
2514 int other = i + (i == commutative ? 1 : -1);
2515 operands_match[c][other]
2516 = operands_match_p (recog_operand[c], recog_operand[other]);
2518 /* Note that C is supposed to be less than I.
2519 No need to consider altering both C and I because in
2520 that case we would alter one into the other. */
2526 /* Examine each operand that is a memory reference or memory address
2527 and reload parts of the addresses into index registers.
2528 Also here any references to pseudo regs that didn't get hard regs
2529 but are equivalent to constants get replaced in the insn itself
2530 with those constants. Nobody will ever see them again.
2532 Finally, set up the preferred classes of each operand. */
2534 for (i = 0; i < noperands; i++)
2536 register RTX_CODE code = GET_CODE (recog_operand[i]);
2538 address_reloaded[i] = 0;
2539 operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT
2540 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT
2541 : RELOAD_OTHER);
2542 address_type[i]
2543 = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS
2544 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS
2545 : RELOAD_OTHER);
2547 if (*constraints[i] == 0)
2548 /* Ignore things like match_operator operands. */
2550 else if (constraints[i][0] == 'p')
2552 find_reloads_address (VOIDmode, NULL_PTR,
2553 recog_operand[i], recog_operand_loc[i],
2554 i, operand_type[i], ind_levels, insn);
2556 /* If we now have a simple operand where we used to have a
2557 PLUS or MULT, re-recognize and try again. */
2558 if ((GET_RTX_CLASS (GET_CODE (*recog_operand_loc[i])) == 'o'
2559 || GET_CODE (*recog_operand_loc[i]) == SUBREG)
2560 && (GET_CODE (recog_operand[i]) == MULT
2561 || GET_CODE (recog_operand[i]) == PLUS))
2563 INSN_CODE (insn) = -1;
2564 find_reloads (insn, replace, ind_levels, live_known,
2565 reload_reg_p);
2566 return;
2569 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2571 else if (code == MEM)
2573 if (find_reloads_address (GET_MODE (recog_operand[i]),
2574 recog_operand_loc[i],
2575 XEXP (recog_operand[i], 0),
2576 &XEXP (recog_operand[i], 0),
2577 i, address_type[i], ind_levels, insn))
2578 address_reloaded[i] = 1;
2579 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2581 else if (code == SUBREG)
2582 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i]
2583 = find_reloads_toplev (recog_operand[i], i, address_type[i],
2584 ind_levels,
2585 set != 0
2586 && &SET_DEST (set) == recog_operand_loc[i]);
2587 else if (code == PLUS || GET_RTX_CLASS (code) == '1')
2588 /* We can get a PLUS as an "operand" as a result of register
2589 elimination. See eliminate_regs and gen_reload. We handle
2590 a unary operator by reloading the operand. */
2591 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i]
2592 = find_reloads_toplev (recog_operand[i], i, address_type[i],
2593 ind_levels, 0);
2594 else if (code == REG)
2596 /* This is equivalent to calling find_reloads_toplev.
2597 The code is duplicated for speed.
2598 When we find a pseudo always equivalent to a constant,
2599 we replace it by the constant. We must be sure, however,
2600 that we don't try to replace it in the insn in which it
2601 is being set. */
2602 register int regno = REGNO (recog_operand[i]);
2603 if (reg_equiv_constant[regno] != 0
2604 && (set == 0 || &SET_DEST (set) != recog_operand_loc[i]))
2605 substed_operand[i] = recog_operand[i]
2606 = reg_equiv_constant[regno];
2607 #if 0 /* This might screw code in reload1.c to delete prior output-reload
2608 that feeds this insn. */
2609 if (reg_equiv_mem[regno] != 0)
2610 substed_operand[i] = recog_operand[i]
2611 = reg_equiv_mem[regno];
2612 #endif
2613 if (reg_equiv_address[regno] != 0)
2615 /* If reg_equiv_address is not a constant address, copy it,
2616 since it may be shared. */
2617 /* We must rerun eliminate_regs, in case the elimination
2618 offsets have changed. */
2619 rtx address = XEXP (eliminate_regs (reg_equiv_memory_loc[regno],
2620 0, NULL_RTX, 0),
2623 if (rtx_varies_p (address))
2624 address = copy_rtx (address);
2626 /* If this is an output operand, we must output a CLOBBER
2627 after INSN so find_equiv_reg knows REGNO is being written.
2628 Mark this insn specially, do we can put our output reloads
2629 after it. */
2631 if (modified[i] != RELOAD_READ)
2632 PUT_MODE (emit_insn_after (gen_rtx (CLOBBER, VOIDmode,
2633 recog_operand[i]),
2634 insn),
2635 DImode);
2637 *recog_operand_loc[i] = recog_operand[i]
2638 = gen_rtx (MEM, GET_MODE (recog_operand[i]), address);
2639 RTX_UNCHANGING_P (recog_operand[i])
2640 = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
2641 find_reloads_address (GET_MODE (recog_operand[i]),
2642 recog_operand_loc[i],
2643 XEXP (recog_operand[i], 0),
2644 &XEXP (recog_operand[i], 0),
2645 i, address_type[i], ind_levels, insn);
2646 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2649 /* If the operand is still a register (we didn't replace it with an
2650 equivalent), get the preferred class to reload it into. */
2651 code = GET_CODE (recog_operand[i]);
2652 preferred_class[i]
2653 = ((code == REG && REGNO (recog_operand[i]) >= FIRST_PSEUDO_REGISTER)
2654 ? reg_preferred_class (REGNO (recog_operand[i])) : NO_REGS);
2655 pref_or_nothing[i]
2656 = (code == REG && REGNO (recog_operand[i]) >= FIRST_PSEUDO_REGISTER
2657 && reg_alternate_class (REGNO (recog_operand[i])) == NO_REGS);
2660 /* If this is simply a copy from operand 1 to operand 0, merge the
2661 preferred classes for the operands. */
2662 if (set != 0 && noperands >= 2 && recog_operand[0] == SET_DEST (set)
2663 && recog_operand[1] == SET_SRC (set))
2665 preferred_class[0] = preferred_class[1]
2666 = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2667 pref_or_nothing[0] |= pref_or_nothing[1];
2668 pref_or_nothing[1] |= pref_or_nothing[0];
2671 /* Now see what we need for pseudo-regs that didn't get hard regs
2672 or got the wrong kind of hard reg. For this, we must consider
2673 all the operands together against the register constraints. */
2675 best = MAX_RECOG_OPERANDS + 300;
2677 swapped = 0;
2678 goal_alternative_swapped = 0;
2679 try_swapped:
2681 /* The constraints are made of several alternatives.
2682 Each operand's constraint looks like foo,bar,... with commas
2683 separating the alternatives. The first alternatives for all
2684 operands go together, the second alternatives go together, etc.
2686 First loop over alternatives. */
2688 for (this_alternative_number = 0;
2689 this_alternative_number < n_alternatives;
2690 this_alternative_number++)
2692 /* Loop over operands for one constraint alternative. */
2693 /* LOSERS counts those that don't fit this alternative
2694 and would require loading. */
2695 int losers = 0;
2696 /* BAD is set to 1 if it some operand can't fit this alternative
2697 even after reloading. */
2698 int bad = 0;
2699 /* REJECT is a count of how undesirable this alternative says it is
2700 if any reloading is required. If the alternative matches exactly
2701 then REJECT is ignored, but otherwise it gets this much
2702 counted against it in addition to the reloading needed. Each
2703 ? counts three times here since we want the disparaging caused by
2704 a bad register class to only count 1/3 as much. */
2705 int reject = 0;
2707 this_earlyclobber = 0;
2709 for (i = 0; i < noperands; i++)
2711 register char *p = constraints[i];
2712 register int win = 0;
2713 /* 0 => this operand can be reloaded somehow for this alternative */
2714 int badop = 1;
2715 /* 0 => this operand can be reloaded if the alternative allows regs. */
2716 int winreg = 0;
2717 int c;
2718 register rtx operand = recog_operand[i];
2719 int offset = 0;
2720 /* Nonzero means this is a MEM that must be reloaded into a reg
2721 regardless of what the constraint says. */
2722 int force_reload = 0;
2723 int offmemok = 0;
2724 /* Nonzero if a constant forced into memory would be OK for this
2725 operand. */
2726 int constmemok = 0;
2727 int earlyclobber = 0;
2729 /* If the predicate accepts a unary operator, it means that
2730 we need to reload the operand. */
2731 if (GET_RTX_CLASS (GET_CODE (operand)) == '1')
2732 operand = XEXP (operand, 0);
2734 /* If the operand is a SUBREG, extract
2735 the REG or MEM (or maybe even a constant) within.
2736 (Constants can occur as a result of reg_equiv_constant.) */
2738 while (GET_CODE (operand) == SUBREG)
2740 offset += SUBREG_WORD (operand);
2741 operand = SUBREG_REG (operand);
2742 /* Force reload if this is a constant or PLUS or if there may may
2743 be a problem accessing OPERAND in the outer mode. */
2744 if (CONSTANT_P (operand)
2745 || GET_CODE (operand) == PLUS
2746 /* We must force a reload of paradoxical SUBREGs
2747 of a MEM because the alignment of the inner value
2748 may not be enough to do the outer reference. On
2749 big-endian machines, it may also reference outside
2750 the object.
2752 On machines that extend byte operations and we have a
2753 SUBREG where both the inner and outer modes are no wider
2754 than a word and the inner mode is narrower, is integral,
2755 and gets extended when loaded from memory, combine.c has
2756 made assumptions about the behavior of the machine in such
2757 register access. If the data is, in fact, in memory we
2758 must always load using the size assumed to be in the
2759 register and let the insn do the different-sized
2760 accesses. */
2761 || ((GET_CODE (operand) == MEM
2762 || (GET_CODE (operand)== REG
2763 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
2764 && (((GET_MODE_BITSIZE (GET_MODE (operand))
2765 < BIGGEST_ALIGNMENT)
2766 && (GET_MODE_SIZE (operand_mode[i])
2767 > GET_MODE_SIZE (GET_MODE (operand))))
2768 || (GET_CODE (operand) == MEM && BYTES_BIG_ENDIAN)
2769 #ifdef LOAD_EXTEND_OP
2770 || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2771 && (GET_MODE_SIZE (GET_MODE (operand))
2772 <= UNITS_PER_WORD)
2773 && (GET_MODE_SIZE (operand_mode[i])
2774 > GET_MODE_SIZE (GET_MODE (operand)))
2775 && INTEGRAL_MODE_P (GET_MODE (operand))
2776 && LOAD_EXTEND_OP (GET_MODE (operand)) != NIL)
2777 #endif
2779 /* Subreg of a hard reg which can't handle the subreg's mode
2780 or which would handle that mode in the wrong number of
2781 registers for subregging to work. */
2782 || (GET_CODE (operand) == REG
2783 && REGNO (operand) < FIRST_PSEUDO_REGISTER
2784 && ((GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2785 && (GET_MODE_SIZE (GET_MODE (operand))
2786 > UNITS_PER_WORD)
2787 && ((GET_MODE_SIZE (GET_MODE (operand))
2788 / UNITS_PER_WORD)
2789 != HARD_REGNO_NREGS (REGNO (operand),
2790 GET_MODE (operand))))
2791 || ! HARD_REGNO_MODE_OK (REGNO (operand) + offset,
2792 operand_mode[i]))))
2793 force_reload = 1;
2796 this_alternative[i] = (int) NO_REGS;
2797 this_alternative_win[i] = 0;
2798 this_alternative_offmemok[i] = 0;
2799 this_alternative_earlyclobber[i] = 0;
2800 this_alternative_matches[i] = -1;
2802 /* An empty constraint or empty alternative
2803 allows anything which matched the pattern. */
2804 if (*p == 0 || *p == ',')
2805 win = 1, badop = 0;
2807 /* Scan this alternative's specs for this operand;
2808 set WIN if the operand fits any letter in this alternative.
2809 Otherwise, clear BADOP if this operand could
2810 fit some letter after reloads,
2811 or set WINREG if this operand could fit after reloads
2812 provided the constraint allows some registers. */
2814 while (*p && (c = *p++) != ',')
2815 switch (c)
2817 case '=':
2818 case '+':
2819 case '*':
2820 break;
2822 case '%':
2823 /* The last operand should not be marked commutative. */
2824 if (i != noperands - 1)
2825 commutative = i;
2826 break;
2828 case '?':
2829 reject += 3;
2830 break;
2832 case '!':
2833 reject = 300;
2834 break;
2836 case '#':
2837 /* Ignore rest of this alternative as far as
2838 reloading is concerned. */
2839 while (*p && *p != ',') p++;
2840 break;
2842 case '0':
2843 case '1':
2844 case '2':
2845 case '3':
2846 case '4':
2847 c -= '0';
2848 this_alternative_matches[i] = c;
2849 /* We are supposed to match a previous operand.
2850 If we do, we win if that one did.
2851 If we do not, count both of the operands as losers.
2852 (This is too conservative, since most of the time
2853 only a single reload insn will be needed to make
2854 the two operands win. As a result, this alternative
2855 may be rejected when it is actually desirable.) */
2856 if ((swapped && (c != commutative || i != commutative + 1))
2857 /* If we are matching as if two operands were swapped,
2858 also pretend that operands_match had been computed
2859 with swapped.
2860 But if I is the second of those and C is the first,
2861 don't exchange them, because operands_match is valid
2862 only on one side of its diagonal. */
2863 ? (operands_match
2864 [(c == commutative || c == commutative + 1)
2865 ? 2*commutative + 1 - c : c]
2866 [(i == commutative || i == commutative + 1)
2867 ? 2*commutative + 1 - i : i])
2868 : operands_match[c][i])
2870 /* If we are matching a non-offsettable address where an
2871 offsettable address was expected, then we must reject
2872 this combination, because we can't reload it. */
2873 if (this_alternative_offmemok[c]
2874 && GET_CODE (recog_operand[c]) == MEM
2875 && this_alternative[c] == (int) NO_REGS
2876 && ! this_alternative_win[c])
2877 bad = 1;
2879 win = this_alternative_win[c];
2881 else
2883 /* Operands don't match. */
2884 rtx value;
2885 /* Retroactively mark the operand we had to match
2886 as a loser, if it wasn't already. */
2887 if (this_alternative_win[c])
2888 losers++;
2889 this_alternative_win[c] = 0;
2890 if (this_alternative[c] == (int) NO_REGS)
2891 bad = 1;
2892 /* But count the pair only once in the total badness of
2893 this alternative, if the pair can be a dummy reload. */
2894 value
2895 = find_dummy_reload (recog_operand[i], recog_operand[c],
2896 recog_operand_loc[i], recog_operand_loc[c],
2897 operand_mode[i], operand_mode[c],
2898 this_alternative[c], -1,
2899 this_alternative_earlyclobber[c]);
2901 if (value != 0)
2902 losers--;
2904 /* This can be fixed with reloads if the operand
2905 we are supposed to match can be fixed with reloads. */
2906 badop = 0;
2907 this_alternative[i] = this_alternative[c];
2909 /* If we have to reload this operand and some previous
2910 operand also had to match the same thing as this
2911 operand, we don't know how to do that. So reject this
2912 alternative. */
2913 if (! win || force_reload)
2914 for (j = 0; j < i; j++)
2915 if (this_alternative_matches[j]
2916 == this_alternative_matches[i])
2917 badop = 1;
2919 break;
2921 case 'p':
2922 /* All necessary reloads for an address_operand
2923 were handled in find_reloads_address. */
2924 this_alternative[i] = (int) BASE_REG_CLASS;
2925 win = 1;
2926 break;
2928 case 'm':
2929 if (force_reload)
2930 break;
2931 if (GET_CODE (operand) == MEM
2932 || (GET_CODE (operand) == REG
2933 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
2934 && reg_renumber[REGNO (operand)] < 0))
2935 win = 1;
2936 if (CONSTANT_P (operand))
2937 badop = 0;
2938 constmemok = 1;
2939 break;
2941 case '<':
2942 if (GET_CODE (operand) == MEM
2943 && ! address_reloaded[i]
2944 && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
2945 || GET_CODE (XEXP (operand, 0)) == POST_DEC))
2946 win = 1;
2947 break;
2949 case '>':
2950 if (GET_CODE (operand) == MEM
2951 && ! address_reloaded[i]
2952 && (GET_CODE (XEXP (operand, 0)) == PRE_INC
2953 || GET_CODE (XEXP (operand, 0)) == POST_INC))
2954 win = 1;
2955 break;
2957 /* Memory operand whose address is not offsettable. */
2958 case 'V':
2959 if (force_reload)
2960 break;
2961 if (GET_CODE (operand) == MEM
2962 && ! (ind_levels ? offsettable_memref_p (operand)
2963 : offsettable_nonstrict_memref_p (operand))
2964 /* Certain mem addresses will become offsettable
2965 after they themselves are reloaded. This is important;
2966 we don't want our own handling of unoffsettables
2967 to override the handling of reg_equiv_address. */
2968 && !(GET_CODE (XEXP (operand, 0)) == REG
2969 && (ind_levels == 0
2970 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0)))
2971 win = 1;
2972 break;
2974 /* Memory operand whose address is offsettable. */
2975 case 'o':
2976 if (force_reload)
2977 break;
2978 if ((GET_CODE (operand) == MEM
2979 /* If IND_LEVELS, find_reloads_address won't reload a
2980 pseudo that didn't get a hard reg, so we have to
2981 reject that case. */
2982 && (ind_levels ? offsettable_memref_p (operand)
2983 : offsettable_nonstrict_memref_p (operand)))
2984 /* A reloaded auto-increment address is offsettable,
2985 because it is now just a simple register indirect. */
2986 || (GET_CODE (operand) == MEM
2987 && address_reloaded[i]
2988 && (GET_CODE (XEXP (operand, 0)) == PRE_INC
2989 || GET_CODE (XEXP (operand, 0)) == PRE_DEC
2990 || GET_CODE (XEXP (operand, 0)) == POST_INC
2991 || GET_CODE (XEXP (operand, 0)) == POST_DEC))
2992 /* Certain mem addresses will become offsettable
2993 after they themselves are reloaded. This is important;
2994 we don't want our own handling of unoffsettables
2995 to override the handling of reg_equiv_address. */
2996 || (GET_CODE (operand) == MEM
2997 && GET_CODE (XEXP (operand, 0)) == REG
2998 && (ind_levels == 0
2999 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0))
3000 || (GET_CODE (operand) == REG
3001 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3002 && reg_renumber[REGNO (operand)] < 0
3003 /* If reg_equiv_address is nonzero, we will be
3004 loading it into a register; hence it will be
3005 offsettable, but we cannot say that reg_equiv_mem
3006 is offsettable without checking. */
3007 && ((reg_equiv_mem[REGNO (operand)] != 0
3008 && offsettable_memref_p (reg_equiv_mem[REGNO (operand)]))
3009 || (reg_equiv_address[REGNO (operand)] != 0))))
3010 win = 1;
3011 if (CONSTANT_P (operand) || GET_CODE (operand) == MEM)
3012 badop = 0;
3013 constmemok = 1;
3014 offmemok = 1;
3015 break;
3017 case '&':
3018 /* Output operand that is stored before the need for the
3019 input operands (and their index registers) is over. */
3020 earlyclobber = 1, this_earlyclobber = 1;
3021 break;
3023 case 'E':
3024 #ifndef REAL_ARITHMETIC
3025 /* Match any floating double constant, but only if
3026 we can examine the bits of it reliably. */
3027 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3028 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3029 && GET_MODE (operand) != VOIDmode && ! flag_pretend_float)
3030 break;
3031 #endif
3032 if (GET_CODE (operand) == CONST_DOUBLE)
3033 win = 1;
3034 break;
3036 case 'F':
3037 if (GET_CODE (operand) == CONST_DOUBLE)
3038 win = 1;
3039 break;
3041 case 'G':
3042 case 'H':
3043 if (GET_CODE (operand) == CONST_DOUBLE
3044 && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
3045 win = 1;
3046 break;
3048 case 's':
3049 if (GET_CODE (operand) == CONST_INT
3050 || (GET_CODE (operand) == CONST_DOUBLE
3051 && GET_MODE (operand) == VOIDmode))
3052 break;
3053 case 'i':
3054 if (CONSTANT_P (operand)
3055 #ifdef LEGITIMATE_PIC_OPERAND_P
3056 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand))
3057 #endif
3059 win = 1;
3060 break;
3062 case 'n':
3063 if (GET_CODE (operand) == CONST_INT
3064 || (GET_CODE (operand) == CONST_DOUBLE
3065 && GET_MODE (operand) == VOIDmode))
3066 win = 1;
3067 break;
3069 case 'I':
3070 case 'J':
3071 case 'K':
3072 case 'L':
3073 case 'M':
3074 case 'N':
3075 case 'O':
3076 case 'P':
3077 if (GET_CODE (operand) == CONST_INT
3078 && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
3079 win = 1;
3080 break;
3082 case 'X':
3083 win = 1;
3084 break;
3086 case 'g':
3087 if (! force_reload
3088 /* A PLUS is never a valid operand, but reload can make
3089 it from a register when eliminating registers. */
3090 && GET_CODE (operand) != PLUS
3091 /* A SCRATCH is not a valid operand. */
3092 && GET_CODE (operand) != SCRATCH
3093 #ifdef LEGITIMATE_PIC_OPERAND_P
3094 && (! CONSTANT_P (operand)
3095 || ! flag_pic
3096 || LEGITIMATE_PIC_OPERAND_P (operand))
3097 #endif
3098 && (GENERAL_REGS == ALL_REGS
3099 || GET_CODE (operand) != REG
3100 || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
3101 && reg_renumber[REGNO (operand)] < 0)))
3102 win = 1;
3103 /* Drop through into 'r' case */
3105 case 'r':
3106 this_alternative[i]
3107 = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
3108 goto reg;
3110 #ifdef EXTRA_CONSTRAINT
3111 case 'Q':
3112 case 'R':
3113 case 'S':
3114 case 'T':
3115 case 'U':
3116 if (EXTRA_CONSTRAINT (operand, c))
3117 win = 1;
3118 break;
3119 #endif
3121 default:
3122 this_alternative[i]
3123 = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
3125 reg:
3126 if (GET_MODE (operand) == BLKmode)
3127 break;
3128 winreg = 1;
3129 if (GET_CODE (operand) == REG
3130 && reg_fits_class_p (operand, this_alternative[i],
3131 offset, GET_MODE (recog_operand[i])))
3132 win = 1;
3133 break;
3136 constraints[i] = p;
3138 /* If this operand could be handled with a reg,
3139 and some reg is allowed, then this operand can be handled. */
3140 if (winreg && this_alternative[i] != (int) NO_REGS)
3141 badop = 0;
3143 /* Record which operands fit this alternative. */
3144 this_alternative_earlyclobber[i] = earlyclobber;
3145 if (win && ! force_reload)
3146 this_alternative_win[i] = 1;
3147 else
3149 int const_to_mem = 0;
3151 this_alternative_offmemok[i] = offmemok;
3152 losers++;
3153 if (badop)
3154 bad = 1;
3155 /* Alternative loses if it has no regs for a reg operand. */
3156 if (GET_CODE (operand) == REG
3157 && this_alternative[i] == (int) NO_REGS
3158 && this_alternative_matches[i] < 0)
3159 bad = 1;
3161 /* Alternative loses if it requires a type of reload not
3162 permitted for this insn. We can always reload SCRATCH
3163 and objects with a REG_UNUSED note. */
3164 if (GET_CODE (operand) != SCRATCH
3165 && modified[i] != RELOAD_READ && no_output_reloads
3166 && ! find_reg_note (insn, REG_UNUSED, operand))
3167 bad = 1;
3168 else if (modified[i] != RELOAD_WRITE && no_input_reloads)
3169 bad = 1;
3171 /* If this is a constant that is reloaded into the desired
3172 class by copying it to memory first, count that as another
3173 reload. This is consistent with other code and is
3174 required to avoid choosing another alternative when
3175 the constant is moved into memory by this function on
3176 an early reload pass. Note that the test here is
3177 precisely the same as in the code below that calls
3178 force_const_mem. */
3179 if (CONSTANT_P (operand)
3180 /* force_const_mem does not accept HIGH. */
3181 && GET_CODE (operand) != HIGH
3182 && (PREFERRED_RELOAD_CLASS (operand,
3183 (enum reg_class) this_alternative[i])
3184 == NO_REGS)
3185 && operand_mode[i] != VOIDmode)
3187 const_to_mem = 1;
3188 if (this_alternative[i] != (int) NO_REGS)
3189 losers++;
3192 /* If we can't reload this value at all, reject this
3193 alternative. Note that we could also lose due to
3194 LIMIT_RELOAD_RELOAD_CLASS, but we don't check that
3195 here. */
3197 if (! CONSTANT_P (operand)
3198 && (enum reg_class) this_alternative[i] != NO_REGS
3199 && (PREFERRED_RELOAD_CLASS (operand,
3200 (enum reg_class) this_alternative[i])
3201 == NO_REGS))
3202 bad = 1;
3204 /* We prefer to reload pseudos over reloading other things,
3205 since such reloads may be able to be eliminated later.
3206 If we are reloading a SCRATCH, we won't be generating any
3207 insns, just using a register, so it is also preferred.
3208 So bump REJECT in other cases. Don't do this in the
3209 case where we are forcing a constant into memory and
3210 it will then win since we don't want to have a different
3211 alternative match then. */
3212 if (! (GET_CODE (operand) == REG
3213 && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
3214 && GET_CODE (operand) != SCRATCH
3215 && ! (const_to_mem && constmemok))
3216 reject++;
3219 /* If this operand is a pseudo register that didn't get a hard
3220 reg and this alternative accepts some register, see if the
3221 class that we want is a subset of the preferred class for this
3222 register. If not, but it intersects that class, use the
3223 preferred class instead. If it does not intersect the preferred
3224 class, show that usage of this alternative should be discouraged;
3225 it will be discouraged more still if the register is `preferred
3226 or nothing'. We do this because it increases the chance of
3227 reusing our spill register in a later insn and avoiding a pair
3228 of memory stores and loads.
3230 Don't bother with this if this alternative will accept this
3231 operand.
3233 Don't do this for a multiword operand, since it is only a
3234 small win and has the risk of requiring more spill registers,
3235 which could cause a large loss.
3237 Don't do this if the preferred class has only one register
3238 because we might otherwise exhaust the class. */
3241 if (! win && this_alternative[i] != (int) NO_REGS
3242 && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3243 && reg_class_size[(int) preferred_class[i]] > 1)
3245 if (! reg_class_subset_p (this_alternative[i],
3246 preferred_class[i]))
3248 /* Since we don't have a way of forming the intersection,
3249 we just do something special if the preferred class
3250 is a subset of the class we have; that's the most
3251 common case anyway. */
3252 if (reg_class_subset_p (preferred_class[i],
3253 this_alternative[i]))
3254 this_alternative[i] = (int) preferred_class[i];
3255 else
3256 reject += (1 + pref_or_nothing[i]);
3261 /* Now see if any output operands that are marked "earlyclobber"
3262 in this alternative conflict with any input operands
3263 or any memory addresses. */
3265 for (i = 0; i < noperands; i++)
3266 if (this_alternative_earlyclobber[i]
3267 && this_alternative_win[i])
3269 struct decomposition early_data;
3271 early_data = decompose (recog_operand[i]);
3273 if (modified[i] == RELOAD_READ)
3275 if (this_insn_is_asm)
3276 warning_for_asm (this_insn,
3277 "`&' constraint used with input operand");
3278 else
3279 abort ();
3280 continue;
3283 if (this_alternative[i] == NO_REGS)
3285 this_alternative_earlyclobber[i] = 0;
3286 if (this_insn_is_asm)
3287 error_for_asm (this_insn,
3288 "`&' constraint used with no register class");
3289 else
3290 abort ();
3293 for (j = 0; j < noperands; j++)
3294 /* Is this an input operand or a memory ref? */
3295 if ((GET_CODE (recog_operand[j]) == MEM
3296 || modified[j] != RELOAD_WRITE)
3297 && j != i
3298 /* Ignore things like match_operator operands. */
3299 && *constraints1[j] != 0
3300 /* Don't count an input operand that is constrained to match
3301 the early clobber operand. */
3302 && ! (this_alternative_matches[j] == i
3303 && rtx_equal_p (recog_operand[i], recog_operand[j]))
3304 /* Is it altered by storing the earlyclobber operand? */
3305 && !immune_p (recog_operand[j], recog_operand[i], early_data))
3307 /* If the output is in a single-reg class,
3308 it's costly to reload it, so reload the input instead. */
3309 if (reg_class_size[this_alternative[i]] == 1
3310 && (GET_CODE (recog_operand[j]) == REG
3311 || GET_CODE (recog_operand[j]) == SUBREG))
3313 losers++;
3314 this_alternative_win[j] = 0;
3316 else
3317 break;
3319 /* If an earlyclobber operand conflicts with something,
3320 it must be reloaded, so request this and count the cost. */
3321 if (j != noperands)
3323 losers++;
3324 this_alternative_win[i] = 0;
3325 for (j = 0; j < noperands; j++)
3326 if (this_alternative_matches[j] == i
3327 && this_alternative_win[j])
3329 this_alternative_win[j] = 0;
3330 losers++;
3335 /* If one alternative accepts all the operands, no reload required,
3336 choose that alternative; don't consider the remaining ones. */
3337 if (losers == 0)
3339 /* Unswap these so that they are never swapped at `finish'. */
3340 if (commutative >= 0)
3342 recog_operand[commutative] = substed_operand[commutative];
3343 recog_operand[commutative + 1]
3344 = substed_operand[commutative + 1];
3346 for (i = 0; i < noperands; i++)
3348 goal_alternative_win[i] = 1;
3349 goal_alternative[i] = this_alternative[i];
3350 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3351 goal_alternative_matches[i] = this_alternative_matches[i];
3352 goal_alternative_earlyclobber[i]
3353 = this_alternative_earlyclobber[i];
3355 goal_alternative_number = this_alternative_number;
3356 goal_alternative_swapped = swapped;
3357 goal_earlyclobber = this_earlyclobber;
3358 goto finish;
3361 /* REJECT, set by the ! and ? constraint characters and when a register
3362 would be reloaded into a non-preferred class, discourages the use of
3363 this alternative for a reload goal. REJECT is incremented by three
3364 for each ? and one for each non-preferred class. */
3365 losers = losers * 3 + reject;
3367 /* If this alternative can be made to work by reloading,
3368 and it needs less reloading than the others checked so far,
3369 record it as the chosen goal for reloading. */
3370 if (! bad && best > losers)
3372 for (i = 0; i < noperands; i++)
3374 goal_alternative[i] = this_alternative[i];
3375 goal_alternative_win[i] = this_alternative_win[i];
3376 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3377 goal_alternative_matches[i] = this_alternative_matches[i];
3378 goal_alternative_earlyclobber[i]
3379 = this_alternative_earlyclobber[i];
3381 goal_alternative_swapped = swapped;
3382 best = losers;
3383 goal_alternative_number = this_alternative_number;
3384 goal_earlyclobber = this_earlyclobber;
3388 /* If insn is commutative (it's safe to exchange a certain pair of operands)
3389 then we need to try each alternative twice,
3390 the second time matching those two operands
3391 as if we had exchanged them.
3392 To do this, really exchange them in operands.
3394 If we have just tried the alternatives the second time,
3395 return operands to normal and drop through. */
3397 if (commutative >= 0)
3399 swapped = !swapped;
3400 if (swapped)
3402 register enum reg_class tclass;
3403 register int t;
3405 recog_operand[commutative] = substed_operand[commutative + 1];
3406 recog_operand[commutative + 1] = substed_operand[commutative];
3408 tclass = preferred_class[commutative];
3409 preferred_class[commutative] = preferred_class[commutative + 1];
3410 preferred_class[commutative + 1] = tclass;
3412 t = pref_or_nothing[commutative];
3413 pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
3414 pref_or_nothing[commutative + 1] = t;
3416 bcopy ((char *) constraints1, (char *) constraints,
3417 noperands * sizeof (char *));
3418 goto try_swapped;
3420 else
3422 recog_operand[commutative] = substed_operand[commutative];
3423 recog_operand[commutative + 1] = substed_operand[commutative + 1];
3427 /* The operands don't meet the constraints.
3428 goal_alternative describes the alternative
3429 that we could reach by reloading the fewest operands.
3430 Reload so as to fit it. */
3432 if (best == MAX_RECOG_OPERANDS + 300)
3434 /* No alternative works with reloads?? */
3435 if (insn_code_number >= 0)
3436 abort ();
3437 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3438 /* Avoid further trouble with this insn. */
3439 PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
3440 n_reloads = 0;
3441 return;
3444 /* Jump to `finish' from above if all operands are valid already.
3445 In that case, goal_alternative_win is all 1. */
3446 finish:
3448 /* Right now, for any pair of operands I and J that are required to match,
3449 with I < J,
3450 goal_alternative_matches[J] is I.
3451 Set up goal_alternative_matched as the inverse function:
3452 goal_alternative_matched[I] = J. */
3454 for (i = 0; i < noperands; i++)
3455 goal_alternative_matched[i] = -1;
3457 for (i = 0; i < noperands; i++)
3458 if (! goal_alternative_win[i]
3459 && goal_alternative_matches[i] >= 0)
3460 goal_alternative_matched[goal_alternative_matches[i]] = i;
3462 /* If the best alternative is with operands 1 and 2 swapped,
3463 consider them swapped before reporting the reloads. Update the
3464 operand numbers of any reloads already pushed. */
3466 if (goal_alternative_swapped)
3468 register rtx tem;
3470 tem = substed_operand[commutative];
3471 substed_operand[commutative] = substed_operand[commutative + 1];
3472 substed_operand[commutative + 1] = tem;
3473 tem = recog_operand[commutative];
3474 recog_operand[commutative] = recog_operand[commutative + 1];
3475 recog_operand[commutative + 1] = tem;
3477 for (i = 0; i < n_reloads; i++)
3479 if (reload_opnum[i] == commutative)
3480 reload_opnum[i] = commutative + 1;
3481 else if (reload_opnum[i] == commutative + 1)
3482 reload_opnum[i] = commutative;
3486 /* Perform whatever substitutions on the operands we are supposed
3487 to make due to commutativity or replacement of registers
3488 with equivalent constants or memory slots. */
3490 for (i = 0; i < noperands; i++)
3492 *recog_operand_loc[i] = substed_operand[i];
3493 /* While we are looping on operands, initialize this. */
3494 operand_reloadnum[i] = -1;
3496 /* If this is an earlyclobber operand, we need to widen the scope.
3497 The reload must remain valid from the start of the insn being
3498 reloaded until after the operand is stored into its destination.
3499 We approximate this with RELOAD_OTHER even though we know that we
3500 do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads.
3502 One special case that is worth checking is when we have an
3503 output that is earlyclobber but isn't used past the insn (typically
3504 a SCRATCH). In this case, we only need have the reload live
3505 through the insn itself, but not for any of our input or output
3506 reloads.
3508 In any case, anything needed to address this operand can remain
3509 however they were previously categorized. */
3511 if (goal_alternative_earlyclobber[i])
3512 operand_type[i]
3513 = (find_reg_note (insn, REG_UNUSED, recog_operand[i])
3514 ? RELOAD_FOR_INSN : RELOAD_OTHER);
3517 /* Any constants that aren't allowed and can't be reloaded
3518 into registers are here changed into memory references. */
3519 for (i = 0; i < noperands; i++)
3520 if (! goal_alternative_win[i]
3521 && CONSTANT_P (recog_operand[i])
3522 /* force_const_mem does not accept HIGH. */
3523 && GET_CODE (recog_operand[i]) != HIGH
3524 && (PREFERRED_RELOAD_CLASS (recog_operand[i],
3525 (enum reg_class) goal_alternative[i])
3526 == NO_REGS)
3527 && operand_mode[i] != VOIDmode)
3529 *recog_operand_loc[i] = recog_operand[i]
3530 = find_reloads_toplev (force_const_mem (operand_mode[i],
3531 recog_operand[i]),
3532 i, address_type[i], ind_levels, 0);
3533 if (alternative_allows_memconst (constraints1[i],
3534 goal_alternative_number))
3535 goal_alternative_win[i] = 1;
3538 /* Record the values of the earlyclobber operands for the caller. */
3539 if (goal_earlyclobber)
3540 for (i = 0; i < noperands; i++)
3541 if (goal_alternative_earlyclobber[i])
3542 reload_earlyclobbers[n_earlyclobbers++] = recog_operand[i];
3544 /* Now record reloads for all the operands that need them. */
3545 for (i = 0; i < noperands; i++)
3546 if (! goal_alternative_win[i])
3548 /* Operands that match previous ones have already been handled. */
3549 if (goal_alternative_matches[i] >= 0)
3551 /* Handle an operand with a nonoffsettable address
3552 appearing where an offsettable address will do
3553 by reloading the address into a base register.
3555 ??? We can also do this when the operand is a register and
3556 reg_equiv_mem is not offsettable, but this is a bit tricky,
3557 so we don't bother with it. It may not be worth doing. */
3558 else if (goal_alternative_matched[i] == -1
3559 && goal_alternative_offmemok[i]
3560 && GET_CODE (recog_operand[i]) == MEM)
3562 operand_reloadnum[i]
3563 = push_reload (XEXP (recog_operand[i], 0), NULL_RTX,
3564 &XEXP (recog_operand[i], 0), NULL_PTR,
3565 BASE_REG_CLASS, GET_MODE (XEXP (recog_operand[i], 0)),
3566 VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
3567 reload_inc[operand_reloadnum[i]]
3568 = GET_MODE_SIZE (GET_MODE (recog_operand[i]));
3570 /* If this operand is an output, we will have made any
3571 reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but
3572 now we are treating part of the operand as an input, so
3573 we must change these to RELOAD_FOR_INPUT_ADDRESS. */
3575 if (modified[i] == RELOAD_WRITE)
3577 for (j = 0; j < n_reloads; j++)
3579 if (reload_opnum[j] == i)
3581 if (reload_when_needed[j] == RELOAD_FOR_OUTPUT_ADDRESS)
3582 reload_when_needed[j] = RELOAD_FOR_INPUT_ADDRESS;
3583 else if (reload_when_needed[j]
3584 == RELOAD_FOR_OUTADDR_ADDRESS)
3585 reload_when_needed[j] = RELOAD_FOR_INPADDR_ADDRESS;
3590 else if (goal_alternative_matched[i] == -1)
3591 operand_reloadnum[i]
3592 = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
3593 modified[i] != RELOAD_READ ? recog_operand[i] : 0,
3594 (modified[i] != RELOAD_WRITE
3595 ? recog_operand_loc[i] : 0),
3596 modified[i] != RELOAD_READ ? recog_operand_loc[i] : 0,
3597 (enum reg_class) goal_alternative[i],
3598 (modified[i] == RELOAD_WRITE
3599 ? VOIDmode : operand_mode[i]),
3600 (modified[i] == RELOAD_READ
3601 ? VOIDmode : operand_mode[i]),
3602 (insn_code_number < 0 ? 0
3603 : insn_operand_strict_low[insn_code_number][i]),
3604 0, i, operand_type[i]);
3605 /* In a matching pair of operands, one must be input only
3606 and the other must be output only.
3607 Pass the input operand as IN and the other as OUT. */
3608 else if (modified[i] == RELOAD_READ
3609 && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
3611 operand_reloadnum[i]
3612 = push_reload (recog_operand[i],
3613 recog_operand[goal_alternative_matched[i]],
3614 recog_operand_loc[i],
3615 recog_operand_loc[goal_alternative_matched[i]],
3616 (enum reg_class) goal_alternative[i],
3617 operand_mode[i],
3618 operand_mode[goal_alternative_matched[i]],
3619 0, 0, i, RELOAD_OTHER);
3620 operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
3622 else if (modified[i] == RELOAD_WRITE
3623 && modified[goal_alternative_matched[i]] == RELOAD_READ)
3625 operand_reloadnum[goal_alternative_matched[i]]
3626 = push_reload (recog_operand[goal_alternative_matched[i]],
3627 recog_operand[i],
3628 recog_operand_loc[goal_alternative_matched[i]],
3629 recog_operand_loc[i],
3630 (enum reg_class) goal_alternative[i],
3631 operand_mode[goal_alternative_matched[i]],
3632 operand_mode[i],
3633 0, 0, i, RELOAD_OTHER);
3634 operand_reloadnum[i] = output_reloadnum;
3636 else if (insn_code_number >= 0)
3637 abort ();
3638 else
3640 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3641 /* Avoid further trouble with this insn. */
3642 PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
3643 n_reloads = 0;
3644 return;
3647 else if (goal_alternative_matched[i] < 0
3648 && goal_alternative_matches[i] < 0
3649 && optimize)
3651 /* For each non-matching operand that's a MEM or a pseudo-register
3652 that didn't get a hard register, make an optional reload.
3653 This may get done even if the insn needs no reloads otherwise. */
3655 rtx operand = recog_operand[i];
3657 while (GET_CODE (operand) == SUBREG)
3658 operand = XEXP (operand, 0);
3659 if ((GET_CODE (operand) == MEM
3660 || (GET_CODE (operand) == REG
3661 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3662 && (enum reg_class) goal_alternative[i] != NO_REGS
3663 && ! no_input_reloads
3664 /* Optional output reloads don't do anything and we mustn't
3665 make in-out reloads on insns that are not permitted output
3666 reloads. */
3667 && (modified[i] == RELOAD_READ
3668 || (modified[i] == RELOAD_READ_WRITE && ! no_output_reloads)))
3669 operand_reloadnum[i]
3670 = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
3671 modified[i] != RELOAD_READ ? recog_operand[i] : 0,
3672 (modified[i] != RELOAD_WRITE
3673 ? recog_operand_loc[i] : 0),
3674 (modified[i] != RELOAD_READ
3675 ? recog_operand_loc[i] : 0),
3676 (enum reg_class) goal_alternative[i],
3677 (modified[i] == RELOAD_WRITE
3678 ? VOIDmode : operand_mode[i]),
3679 (modified[i] == RELOAD_READ
3680 ? VOIDmode : operand_mode[i]),
3681 (insn_code_number < 0 ? 0
3682 : insn_operand_strict_low[insn_code_number][i]),
3683 1, i, operand_type[i]);
3685 else if (goal_alternative_matches[i] >= 0
3686 && goal_alternative_win[goal_alternative_matches[i]]
3687 && modified[i] == RELOAD_READ
3688 && modified[goal_alternative_matches[i]] == RELOAD_WRITE
3689 && ! no_input_reloads && ! no_output_reloads
3690 && optimize)
3692 /* Similarly, make an optional reload for a pair of matching
3693 objects that are in MEM or a pseudo that didn't get a hard reg. */
3695 rtx operand = recog_operand[i];
3697 while (GET_CODE (operand) == SUBREG)
3698 operand = XEXP (operand, 0);
3699 if ((GET_CODE (operand) == MEM
3700 || (GET_CODE (operand) == REG
3701 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3702 && ((enum reg_class) goal_alternative[goal_alternative_matches[i]]
3703 != NO_REGS))
3704 operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]]
3705 = push_reload (recog_operand[goal_alternative_matches[i]],
3706 recog_operand[i],
3707 recog_operand_loc[goal_alternative_matches[i]],
3708 recog_operand_loc[i],
3709 (enum reg_class) goal_alternative[goal_alternative_matches[i]],
3710 operand_mode[goal_alternative_matches[i]],
3711 operand_mode[i],
3712 0, 1, goal_alternative_matches[i], RELOAD_OTHER);
3715 /* If this insn pattern contains any MATCH_DUP's, make sure that
3716 they will be substituted if the operands they match are substituted.
3717 Also do now any substitutions we already did on the operands.
3719 Don't do this if we aren't making replacements because we might be
3720 propagating things allocated by frame pointer elimination into places
3721 it doesn't expect. */
3723 if (insn_code_number >= 0 && replace)
3724 for (i = insn_n_dups[insn_code_number] - 1; i >= 0; i--)
3726 int opno = recog_dup_num[i];
3727 *recog_dup_loc[i] = *recog_operand_loc[opno];
3728 if (operand_reloadnum[opno] >= 0)
3729 push_replacement (recog_dup_loc[i], operand_reloadnum[opno],
3730 insn_operand_mode[insn_code_number][opno]);
3733 #if 0
3734 /* This loses because reloading of prior insns can invalidate the equivalence
3735 (or at least find_equiv_reg isn't smart enough to find it any more),
3736 causing this insn to need more reload regs than it needed before.
3737 It may be too late to make the reload regs available.
3738 Now this optimization is done safely in choose_reload_regs. */
3740 /* For each reload of a reg into some other class of reg,
3741 search for an existing equivalent reg (same value now) in the right class.
3742 We can use it as long as we don't need to change its contents. */
3743 for (i = 0; i < n_reloads; i++)
3744 if (reload_reg_rtx[i] == 0
3745 && reload_in[i] != 0
3746 && GET_CODE (reload_in[i]) == REG
3747 && reload_out[i] == 0)
3749 reload_reg_rtx[i]
3750 = find_equiv_reg (reload_in[i], insn, reload_reg_class[i], -1,
3751 static_reload_reg_p, 0, reload_inmode[i]);
3752 /* Prevent generation of insn to load the value
3753 because the one we found already has the value. */
3754 if (reload_reg_rtx[i])
3755 reload_in[i] = reload_reg_rtx[i];
3757 #endif
3759 /* Perhaps an output reload can be combined with another
3760 to reduce needs by one. */
3761 if (!goal_earlyclobber)
3762 combine_reloads ();
3764 /* If we have a pair of reloads for parts of an address, they are reloading
3765 the same object, the operands themselves were not reloaded, and they
3766 are for two operands that are supposed to match, merge the reloads and
3767 change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS. */
3769 for (i = 0; i < n_reloads; i++)
3771 int k;
3773 for (j = i + 1; j < n_reloads; j++)
3774 if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3775 || reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3776 || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3777 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3778 && (reload_when_needed[j] == RELOAD_FOR_INPUT_ADDRESS
3779 || reload_when_needed[j] == RELOAD_FOR_OUTPUT_ADDRESS
3780 || reload_when_needed[j] == RELOAD_FOR_INPADDR_ADDRESS
3781 || reload_when_needed[j] == RELOAD_FOR_OUTADDR_ADDRESS)
3782 && rtx_equal_p (reload_in[i], reload_in[j])
3783 && (operand_reloadnum[reload_opnum[i]] < 0
3784 || reload_optional[operand_reloadnum[reload_opnum[i]]])
3785 && (operand_reloadnum[reload_opnum[j]] < 0
3786 || reload_optional[operand_reloadnum[reload_opnum[j]]])
3787 && (goal_alternative_matches[reload_opnum[i]] == reload_opnum[j]
3788 || (goal_alternative_matches[reload_opnum[j]]
3789 == reload_opnum[i])))
3791 for (k = 0; k < n_replacements; k++)
3792 if (replacements[k].what == j)
3793 replacements[k].what = i;
3795 if (reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3796 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3797 reload_when_needed[i] = RELOAD_FOR_OPADDR_ADDR;
3798 else
3799 reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
3800 reload_in[j] = 0;
3804 /* Scan all the reloads and update their type.
3805 If a reload is for the address of an operand and we didn't reload
3806 that operand, change the type. Similarly, change the operand number
3807 of a reload when two operands match. If a reload is optional, treat it
3808 as though the operand isn't reloaded.
3810 ??? This latter case is somewhat odd because if we do the optional
3811 reload, it means the object is hanging around. Thus we need only
3812 do the address reload if the optional reload was NOT done.
3814 Change secondary reloads to be the address type of their operand, not
3815 the normal type.
3817 If an operand's reload is now RELOAD_OTHER, change any
3818 RELOAD_FOR_INPUT_ADDRESS reloads of that operand to
3819 RELOAD_FOR_OTHER_ADDRESS. */
3821 for (i = 0; i < n_reloads; i++)
3823 if (reload_secondary_p[i]
3824 && reload_when_needed[i] == operand_type[reload_opnum[i]])
3825 reload_when_needed[i] = address_type[reload_opnum[i]];
3827 if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3828 || reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3829 || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3830 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3831 && (operand_reloadnum[reload_opnum[i]] < 0
3832 || reload_optional[operand_reloadnum[reload_opnum[i]]]))
3834 /* If we have a secondary reload to go along with this reload,
3835 change its type to RELOAD_FOR_OPADDR_ADDR. */
3837 if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3838 || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS)
3839 && reload_secondary_in_reload[i] != -1)
3841 int secondary_in_reload = reload_secondary_in_reload[i];
3843 reload_when_needed[secondary_in_reload]
3844 = RELOAD_FOR_OPADDR_ADDR;
3846 /* If there's a tertiary reload we have to change it also. */
3847 if (secondary_in_reload > 0
3848 && reload_secondary_in_reload[secondary_in_reload] != -1)
3849 reload_when_needed[reload_secondary_in_reload[secondary_in_reload]]
3850 = RELOAD_FOR_OPADDR_ADDR;
3853 if ((reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3854 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3855 && reload_secondary_out_reload[i] != -1)
3857 int secondary_out_reload = reload_secondary_out_reload[i];
3859 reload_when_needed[secondary_out_reload]
3860 = RELOAD_FOR_OPADDR_ADDR;
3862 /* If there's a tertiary reload we have to change it also. */
3863 if (secondary_out_reload
3864 && reload_secondary_out_reload[secondary_out_reload] != -1)
3865 reload_when_needed[reload_secondary_out_reload[secondary_out_reload]]
3866 = RELOAD_FOR_OPADDR_ADDR;
3868 if (reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3869 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3870 reload_when_needed[i] = RELOAD_FOR_OPADDR_ADDR;
3871 else
3872 reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
3875 if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3876 || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS)
3877 && operand_reloadnum[reload_opnum[i]] >= 0
3878 && (reload_when_needed[operand_reloadnum[reload_opnum[i]]]
3879 == RELOAD_OTHER))
3880 reload_when_needed[i] = RELOAD_FOR_OTHER_ADDRESS;
3882 if (goal_alternative_matches[reload_opnum[i]] >= 0)
3883 reload_opnum[i] = goal_alternative_matches[reload_opnum[i]];
3886 /* Scan all the reloads, and check for RELOAD_FOR_OPERAND_ADDRESS reloads.
3887 If we have more than one, then convert all RELOAD_FOR_OPADDR_ADDR
3888 reloads to RELOAD_FOR_OPERAND_ADDRESS reloads.
3890 choose_reload_regs assumes that RELOAD_FOR_OPADDR_ADDR reloads never
3891 conflict with RELOAD_FOR_OPERAND_ADDRESS reloads. This is true for a
3892 single pair of RELOAD_FOR_OPADDR_ADDR/RELOAD_FOR_OPERAND_ADDRESS reloads.
3893 However, if there is more than one RELOAD_FOR_OPERAND_ADDRESS reload,
3894 then a RELOAD_FOR_OPADDR_ADDR reload conflicts with all
3895 RELOAD_FOR_OPERAND_ADDRESS reloads other than the one that uses it.
3896 This is complicated by the fact that a single operand can have more
3897 than one RELOAD_FOR_OPERAND_ADDRESS reload. It is very difficult to fix
3898 choose_reload_regs without affecting code quality, and cases that
3899 actually fail are extremely rare, so it turns out to be better to fix
3900 the problem here by not generating cases that choose_reload_regs will
3901 fail for. */
3904 int op_addr_reloads = 0;
3905 for (i = 0; i < n_reloads; i++)
3906 if (reload_when_needed[i] == RELOAD_FOR_OPERAND_ADDRESS)
3907 op_addr_reloads++;
3909 if (op_addr_reloads > 1)
3910 for (i = 0; i < n_reloads; i++)
3911 if (reload_when_needed[i] == RELOAD_FOR_OPADDR_ADDR)
3912 reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
3915 /* See if we have any reloads that are now allowed to be merged
3916 because we've changed when the reload is needed to
3917 RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS. Only
3918 check for the most common cases. */
3920 for (i = 0; i < n_reloads; i++)
3921 if (reload_in[i] != 0 && reload_out[i] == 0
3922 && (reload_when_needed[i] == RELOAD_FOR_OPERAND_ADDRESS
3923 || reload_when_needed[i] == RELOAD_FOR_OPADDR_ADDR
3924 || reload_when_needed[i] == RELOAD_FOR_OTHER_ADDRESS))
3925 for (j = 0; j < n_reloads; j++)
3926 if (i != j && reload_in[j] != 0 && reload_out[j] == 0
3927 && reload_when_needed[j] == reload_when_needed[i]
3928 && MATCHES (reload_in[i], reload_in[j])
3929 && reload_reg_class[i] == reload_reg_class[j]
3930 && !reload_nocombine[i] && !reload_nocombine[j]
3931 && reload_reg_rtx[i] == reload_reg_rtx[j])
3933 reload_opnum[i] = MIN (reload_opnum[i], reload_opnum[j]);
3934 transfer_replacements (i, j);
3935 reload_in[j] = 0;
3938 #else /* no REGISTER_CONSTRAINTS */
3939 int noperands;
3940 int insn_code_number;
3941 int goal_earlyclobber = 0; /* Always 0, to make combine_reloads happen. */
3942 register int i;
3943 rtx body = PATTERN (insn);
3945 n_reloads = 0;
3946 n_replacements = 0;
3947 n_earlyclobbers = 0;
3948 replace_reloads = replace;
3949 this_insn = insn;
3951 /* Find what kind of insn this is. NOPERANDS gets number of operands.
3952 Store the operand values in RECOG_OPERAND and the locations
3953 of the words in the insn that point to them in RECOG_OPERAND_LOC.
3954 Return if the insn needs no reload processing. */
3956 switch (GET_CODE (body))
3958 case USE:
3959 case CLOBBER:
3960 case ASM_INPUT:
3961 case ADDR_VEC:
3962 case ADDR_DIFF_VEC:
3963 return;
3965 case PARALLEL:
3966 case SET:
3967 noperands = asm_noperands (body);
3968 if (noperands >= 0)
3970 /* This insn is an `asm' with operands.
3971 First, find out how many operands, and allocate space. */
3973 insn_code_number = -1;
3974 /* ??? This is a bug! ???
3975 Give up and delete this insn if it has too many operands. */
3976 if (noperands > MAX_RECOG_OPERANDS)
3977 abort ();
3979 /* Now get the operand values out of the insn. */
3981 decode_asm_operands (body, recog_operand, recog_operand_loc,
3982 NULL_PTR, NULL_PTR);
3983 break;
3986 default:
3987 /* Ordinary insn: recognize it, allocate space for operands and
3988 constraints, and get them out via insn_extract. */
3990 insn_code_number = recog_memoized (insn);
3991 noperands = insn_n_operands[insn_code_number];
3992 insn_extract (insn);
3995 if (noperands == 0)
3996 return;
3998 for (i = 0; i < noperands; i++)
4000 register RTX_CODE code = GET_CODE (recog_operand[i]);
4001 int is_set_dest = GET_CODE (body) == SET && (i == 0);
4003 if (insn_code_number >= 0)
4004 if (insn_operand_address_p[insn_code_number][i])
4005 find_reloads_address (VOIDmode, NULL_PTR,
4006 recog_operand[i], recog_operand_loc[i],
4007 i, RELOAD_FOR_INPUT, ind_levels, insn);
4009 /* In these cases, we can't tell if the operand is an input
4010 or an output, so be conservative. In practice it won't be
4011 problem. */
4013 if (code == MEM)
4014 find_reloads_address (GET_MODE (recog_operand[i]),
4015 recog_operand_loc[i],
4016 XEXP (recog_operand[i], 0),
4017 &XEXP (recog_operand[i], 0),
4018 i, RELOAD_OTHER, ind_levels, insn);
4019 if (code == SUBREG)
4020 recog_operand[i] = *recog_operand_loc[i]
4021 = find_reloads_toplev (recog_operand[i], i, RELOAD_OTHER,
4022 ind_levels, is_set_dest);
4023 if (code == REG)
4025 register int regno = REGNO (recog_operand[i]);
4026 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4027 recog_operand[i] = *recog_operand_loc[i]
4028 = reg_equiv_constant[regno];
4029 #if 0 /* This might screw code in reload1.c to delete prior output-reload
4030 that feeds this insn. */
4031 if (reg_equiv_mem[regno] != 0)
4032 recog_operand[i] = *recog_operand_loc[i]
4033 = reg_equiv_mem[regno];
4034 #endif
4038 /* Perhaps an output reload can be combined with another
4039 to reduce needs by one. */
4040 if (!goal_earlyclobber)
4041 combine_reloads ();
4042 #endif /* no REGISTER_CONSTRAINTS */
4045 /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
4046 accepts a memory operand with constant address. */
4048 static int
4049 alternative_allows_memconst (constraint, altnum)
4050 char *constraint;
4051 int altnum;
4053 register int c;
4054 /* Skip alternatives before the one requested. */
4055 while (altnum > 0)
4057 while (*constraint++ != ',');
4058 altnum--;
4060 /* Scan the requested alternative for 'm' or 'o'.
4061 If one of them is present, this alternative accepts memory constants. */
4062 while ((c = *constraint++) && c != ',' && c != '#')
4063 if (c == 'm' || c == 'o')
4064 return 1;
4065 return 0;
4068 /* Scan X for memory references and scan the addresses for reloading.
4069 Also checks for references to "constant" regs that we want to eliminate
4070 and replaces them with the values they stand for.
4071 We may alter X destructively if it contains a reference to such.
4072 If X is just a constant reg, we return the equivalent value
4073 instead of X.
4075 IND_LEVELS says how many levels of indirect addressing this machine
4076 supports.
4078 OPNUM and TYPE identify the purpose of the reload.
4080 IS_SET_DEST is true if X is the destination of a SET, which is not
4081 appropriate to be replaced by a constant. */
4083 static rtx
4084 find_reloads_toplev (x, opnum, type, ind_levels, is_set_dest)
4085 rtx x;
4086 int opnum;
4087 enum reload_type type;
4088 int ind_levels;
4089 int is_set_dest;
4091 register RTX_CODE code = GET_CODE (x);
4093 register char *fmt = GET_RTX_FORMAT (code);
4094 register int i;
4096 if (code == REG)
4098 /* This code is duplicated for speed in find_reloads. */
4099 register int regno = REGNO (x);
4100 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4101 x = reg_equiv_constant[regno];
4102 #if 0
4103 /* This creates (subreg (mem...)) which would cause an unnecessary
4104 reload of the mem. */
4105 else if (reg_equiv_mem[regno] != 0)
4106 x = reg_equiv_mem[regno];
4107 #endif
4108 else if (reg_equiv_address[regno] != 0)
4110 /* If reg_equiv_address varies, it may be shared, so copy it. */
4111 /* We must rerun eliminate_regs, in case the elimination
4112 offsets have changed. */
4113 rtx addr = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0,
4114 NULL_RTX, 0),
4117 if (rtx_varies_p (addr))
4118 addr = copy_rtx (addr);
4120 x = gen_rtx (MEM, GET_MODE (x), addr);
4121 RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4122 find_reloads_address (GET_MODE (x), NULL_PTR,
4123 XEXP (x, 0),
4124 &XEXP (x, 0), opnum, type, ind_levels, 0);
4126 return x;
4128 if (code == MEM)
4130 rtx tem = x;
4131 find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
4132 opnum, type, ind_levels, 0);
4133 return tem;
4136 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG)
4138 /* Check for SUBREG containing a REG that's equivalent to a constant.
4139 If the constant has a known value, truncate it right now.
4140 Similarly if we are extracting a single-word of a multi-word
4141 constant. If the constant is symbolic, allow it to be substituted
4142 normally. push_reload will strip the subreg later. If the
4143 constant is VOIDmode, abort because we will lose the mode of
4144 the register (this should never happen because one of the cases
4145 above should handle it). */
4147 register int regno = REGNO (SUBREG_REG (x));
4148 rtx tem;
4150 if (subreg_lowpart_p (x)
4151 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4152 && reg_equiv_constant[regno] != 0
4153 && (tem = gen_lowpart_common (GET_MODE (x),
4154 reg_equiv_constant[regno])) != 0)
4155 return tem;
4157 if (GET_MODE_BITSIZE (GET_MODE (x)) == BITS_PER_WORD
4158 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4159 && reg_equiv_constant[regno] != 0
4160 && (tem = operand_subword (reg_equiv_constant[regno],
4161 SUBREG_WORD (x), 0,
4162 GET_MODE (SUBREG_REG (x)))) != 0)
4163 return tem;
4165 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4166 && reg_equiv_constant[regno] != 0
4167 && GET_MODE (reg_equiv_constant[regno]) == VOIDmode)
4168 abort ();
4170 /* If the subreg contains a reg that will be converted to a mem,
4171 convert the subreg to a narrower memref now.
4172 Otherwise, we would get (subreg (mem ...) ...),
4173 which would force reload of the mem.
4175 We also need to do this if there is an equivalent MEM that is
4176 not offsettable. In that case, alter_subreg would produce an
4177 invalid address on big-endian machines.
4179 For machines that extend byte loads, we must not reload using
4180 a wider mode if we have a paradoxical SUBREG. find_reloads will
4181 force a reload in that case. So we should not do anything here. */
4183 else if (regno >= FIRST_PSEUDO_REGISTER
4184 #ifdef LOAD_EXTEND_OP
4185 && (GET_MODE_SIZE (GET_MODE (x))
4186 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
4187 #endif
4188 && (reg_equiv_address[regno] != 0
4189 || (reg_equiv_mem[regno] != 0
4190 && (! strict_memory_address_p (GET_MODE (x),
4191 XEXP (reg_equiv_mem[regno], 0))
4192 || ! offsettable_memref_p (reg_equiv_mem[regno])))))
4194 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
4195 /* We must rerun eliminate_regs, in case the elimination
4196 offsets have changed. */
4197 rtx addr = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0,
4198 NULL_RTX, 0),
4200 if (BYTES_BIG_ENDIAN)
4202 int size;
4203 size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
4204 offset += MIN (size, UNITS_PER_WORD);
4205 size = GET_MODE_SIZE (GET_MODE (x));
4206 offset -= MIN (size, UNITS_PER_WORD);
4208 addr = plus_constant (addr, offset);
4209 x = gen_rtx (MEM, GET_MODE (x), addr);
4210 RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4211 find_reloads_address (GET_MODE (x), NULL_PTR,
4212 XEXP (x, 0),
4213 &XEXP (x, 0), opnum, type, ind_levels, 0);
4218 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4220 if (fmt[i] == 'e')
4221 XEXP (x, i) = find_reloads_toplev (XEXP (x, i), opnum, type,
4222 ind_levels, is_set_dest);
4224 return x;
4227 /* Return a mem ref for the memory equivalent of reg REGNO.
4228 This mem ref is not shared with anything. */
4230 static rtx
4231 make_memloc (ad, regno)
4232 rtx ad;
4233 int regno;
4235 register int i;
4236 /* We must rerun eliminate_regs, in case the elimination
4237 offsets have changed. */
4238 rtx tem = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0, NULL_RTX, 0),
4241 #if 0 /* We cannot safely reuse a memloc made here;
4242 if the pseudo appears twice, and its mem needs a reload,
4243 it gets two separate reloads assigned, but it only
4244 gets substituted with the second of them;
4245 then it can get used before that reload reg gets loaded up. */
4246 for (i = 0; i < n_memlocs; i++)
4247 if (rtx_equal_p (tem, XEXP (memlocs[i], 0)))
4248 return memlocs[i];
4249 #endif
4251 /* If TEM might contain a pseudo, we must copy it to avoid
4252 modifying it when we do the substitution for the reload. */
4253 if (rtx_varies_p (tem))
4254 tem = copy_rtx (tem);
4256 tem = gen_rtx (MEM, GET_MODE (ad), tem);
4257 RTX_UNCHANGING_P (tem) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4258 memlocs[n_memlocs++] = tem;
4259 return tem;
4262 /* Record all reloads needed for handling memory address AD
4263 which appears in *LOC in a memory reference to mode MODE
4264 which itself is found in location *MEMREFLOC.
4265 Note that we take shortcuts assuming that no multi-reg machine mode
4266 occurs as part of an address.
4268 OPNUM and TYPE specify the purpose of this reload.
4270 IND_LEVELS says how many levels of indirect addressing this machine
4271 supports.
4273 INSN, if nonzero, is the insn in which we do the reload. It is used
4274 to determine if we may generate output reloads.
4276 Value is nonzero if this address is reloaded or replaced as a whole.
4277 This is interesting to the caller if the address is an autoincrement.
4279 Note that there is no verification that the address will be valid after
4280 this routine does its work. Instead, we rely on the fact that the address
4281 was valid when reload started. So we need only undo things that reload
4282 could have broken. These are wrong register types, pseudos not allocated
4283 to a hard register, and frame pointer elimination. */
4285 static int
4286 find_reloads_address (mode, memrefloc, ad, loc, opnum, type, ind_levels, insn)
4287 enum machine_mode mode;
4288 rtx *memrefloc;
4289 rtx ad;
4290 rtx *loc;
4291 int opnum;
4292 enum reload_type type;
4293 int ind_levels;
4294 rtx insn;
4296 register int regno;
4297 rtx tem;
4299 /* If the address is a register, see if it is a legitimate address and
4300 reload if not. We first handle the cases where we need not reload
4301 or where we must reload in a non-standard way. */
4303 if (GET_CODE (ad) == REG)
4305 regno = REGNO (ad);
4307 if (reg_equiv_constant[regno] != 0
4308 && strict_memory_address_p (mode, reg_equiv_constant[regno]))
4310 *loc = ad = reg_equiv_constant[regno];
4311 return 1;
4314 else if (reg_equiv_address[regno] != 0)
4316 tem = make_memloc (ad, regno);
4317 find_reloads_address (GET_MODE (tem), NULL_PTR, XEXP (tem, 0),
4318 &XEXP (tem, 0), opnum, ADDR_TYPE (type),
4319 ind_levels, insn);
4320 push_reload (tem, NULL_RTX, loc, NULL_PTR,
4321 reload_address_base_reg_class,
4322 GET_MODE (ad), VOIDmode, 0, 0,
4323 opnum, type);
4324 return 1;
4327 /* We can avoid a reload if the register's equivalent memory expression
4328 is valid as an indirect memory address.
4329 But not all addresses are valid in a mem used as an indirect address:
4330 only reg or reg+constant. */
4332 else if (reg_equiv_mem[regno] != 0 && ind_levels > 0
4333 && strict_memory_address_p (mode, reg_equiv_mem[regno])
4334 && (GET_CODE (XEXP (reg_equiv_mem[regno], 0)) == REG
4335 || (GET_CODE (XEXP (reg_equiv_mem[regno], 0)) == PLUS
4336 && GET_CODE (XEXP (XEXP (reg_equiv_mem[regno], 0), 0)) == REG
4337 && CONSTANT_P (XEXP (XEXP (reg_equiv_mem[regno], 0), 1)))))
4338 return 0;
4340 /* The only remaining case where we can avoid a reload is if this is a
4341 hard register that is valid as a base register and which is not the
4342 subject of a CLOBBER in this insn. */
4344 else if (regno < FIRST_PSEUDO_REGISTER
4345 && REGNO_MODE_OK_FOR_BASE_P (regno, mode)
4346 && ! regno_clobbered_p (regno, this_insn))
4347 return 0;
4349 /* If we do not have one of the cases above, we must do the reload. */
4350 push_reload (ad, NULL_RTX, loc, NULL_PTR, reload_address_base_reg_class,
4351 GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
4352 return 1;
4355 if (strict_memory_address_p (mode, ad))
4357 /* The address appears valid, so reloads are not needed.
4358 But the address may contain an eliminable register.
4359 This can happen because a machine with indirect addressing
4360 may consider a pseudo register by itself a valid address even when
4361 it has failed to get a hard reg.
4362 So do a tree-walk to find and eliminate all such regs. */
4364 /* But first quickly dispose of a common case. */
4365 if (GET_CODE (ad) == PLUS
4366 && GET_CODE (XEXP (ad, 1)) == CONST_INT
4367 && GET_CODE (XEXP (ad, 0)) == REG
4368 && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
4369 return 0;
4371 subst_reg_equivs_changed = 0;
4372 *loc = subst_reg_equivs (ad);
4374 if (! subst_reg_equivs_changed)
4375 return 0;
4377 /* Check result for validity after substitution. */
4378 if (strict_memory_address_p (mode, ad))
4379 return 0;
4382 /* The address is not valid. We have to figure out why. One possibility
4383 is that it is itself a MEM. This can happen when the frame pointer is
4384 being eliminated, a pseudo is not allocated to a hard register, and the
4385 offset between the frame and stack pointers is not its initial value.
4386 In that case the pseudo will have been replaced by a MEM referring to
4387 the stack pointer. */
4388 if (GET_CODE (ad) == MEM)
4390 /* First ensure that the address in this MEM is valid. Then, unless
4391 indirect addresses are valid, reload the MEM into a register. */
4392 tem = ad;
4393 find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
4394 opnum, ADDR_TYPE (type),
4395 ind_levels == 0 ? 0 : ind_levels - 1, insn);
4397 /* If tem was changed, then we must create a new memory reference to
4398 hold it and store it back into memrefloc. */
4399 if (tem != ad && memrefloc)
4401 *memrefloc = copy_rtx (*memrefloc);
4402 copy_replacements (tem, XEXP (*memrefloc, 0));
4403 loc = &XEXP (*memrefloc, 0);
4406 /* Check similar cases as for indirect addresses as above except
4407 that we can allow pseudos and a MEM since they should have been
4408 taken care of above. */
4410 if (ind_levels == 0
4411 || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
4412 || GET_CODE (XEXP (tem, 0)) == MEM
4413 || ! (GET_CODE (XEXP (tem, 0)) == REG
4414 || (GET_CODE (XEXP (tem, 0)) == PLUS
4415 && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG
4416 && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT)))
4418 /* Must use TEM here, not AD, since it is the one that will
4419 have any subexpressions reloaded, if needed. */
4420 push_reload (tem, NULL_RTX, loc, NULL_PTR,
4421 reload_address_base_reg_class, GET_MODE (tem),
4422 VOIDmode, 0,
4423 0, opnum, type);
4424 return 1;
4426 else
4427 return 0;
4430 /* If we have address of a stack slot but it's not valid because the
4431 displacement is too large, compute the sum in a register.
4432 Handle all base registers here, not just fp/ap/sp, because on some
4433 targets (namely SH) we can also get too large displacements from
4434 big-endian corrections. */
4435 else if (GET_CODE (ad) == PLUS
4436 && GET_CODE (XEXP (ad, 0)) == REG
4437 && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
4438 && REG_MODE_OK_FOR_BASE_P (XEXP (ad, 0), mode)
4439 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4441 /* Unshare the MEM rtx so we can safely alter it. */
4442 if (memrefloc)
4444 *memrefloc = copy_rtx (*memrefloc);
4445 loc = &XEXP (*memrefloc, 0);
4447 if (double_reg_address_ok)
4449 /* Unshare the sum as well. */
4450 *loc = ad = copy_rtx (ad);
4451 /* Reload the displacement into an index reg.
4452 We assume the frame pointer or arg pointer is a base reg. */
4453 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4454 reload_address_index_reg_class,
4455 GET_MODE (ad), opnum, type, ind_levels);
4457 else
4459 /* If the sum of two regs is not necessarily valid,
4460 reload the sum into a base reg.
4461 That will at least work. */
4462 find_reloads_address_part (ad, loc, reload_address_base_reg_class,
4463 Pmode, opnum, type, ind_levels);
4465 return 1;
4468 /* If we have an indexed stack slot, there are three possible reasons why
4469 it might be invalid: The index might need to be reloaded, the address
4470 might have been made by frame pointer elimination and hence have a
4471 constant out of range, or both reasons might apply.
4473 We can easily check for an index needing reload, but even if that is the
4474 case, we might also have an invalid constant. To avoid making the
4475 conservative assumption and requiring two reloads, we see if this address
4476 is valid when not interpreted strictly. If it is, the only problem is
4477 that the index needs a reload and find_reloads_address_1 will take care
4478 of it.
4480 There is still a case when we might generate an extra reload,
4481 however. In certain cases eliminate_regs will return a MEM for a REG
4482 (see the code there for details). In those cases, memory_address_p
4483 applied to our address will return 0 so we will think that our offset
4484 must be too large. But it might indeed be valid and the only problem
4485 is that a MEM is present where a REG should be. This case should be
4486 very rare and there doesn't seem to be any way to avoid it.
4488 If we decide to do something here, it must be that
4489 `double_reg_address_ok' is true and that this address rtl was made by
4490 eliminate_regs. We generate a reload of the fp/sp/ap + constant and
4491 rework the sum so that the reload register will be added to the index.
4492 This is safe because we know the address isn't shared.
4494 We check for fp/ap/sp as both the first and second operand of the
4495 innermost PLUS. */
4497 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4498 && GET_CODE (XEXP (ad, 0)) == PLUS
4499 && (XEXP (XEXP (ad, 0), 0) == frame_pointer_rtx
4500 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
4501 || XEXP (XEXP (ad, 0), 0) == hard_frame_pointer_rtx
4502 #endif
4503 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4504 || XEXP (XEXP (ad, 0), 0) == arg_pointer_rtx
4505 #endif
4506 || XEXP (XEXP (ad, 0), 0) == stack_pointer_rtx)
4507 && ! memory_address_p (mode, ad))
4509 *loc = ad = gen_rtx (PLUS, GET_MODE (ad),
4510 plus_constant (XEXP (XEXP (ad, 0), 0),
4511 INTVAL (XEXP (ad, 1))),
4512 XEXP (XEXP (ad, 0), 1));
4513 find_reloads_address_part (XEXP (ad, 0), &XEXP (ad, 0),
4514 reload_address_base_reg_class,
4515 GET_MODE (ad), opnum, type, ind_levels);
4516 find_reloads_address_1 (mode, XEXP (ad, 1), 1, &XEXP (ad, 1), opnum,
4517 type, 0, insn);
4519 return 1;
4522 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4523 && GET_CODE (XEXP (ad, 0)) == PLUS
4524 && (XEXP (XEXP (ad, 0), 1) == frame_pointer_rtx
4525 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4526 || XEXP (XEXP (ad, 0), 1) == hard_frame_pointer_rtx
4527 #endif
4528 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4529 || XEXP (XEXP (ad, 0), 1) == arg_pointer_rtx
4530 #endif
4531 || XEXP (XEXP (ad, 0), 1) == stack_pointer_rtx)
4532 && ! memory_address_p (mode, ad))
4534 *loc = ad = gen_rtx (PLUS, GET_MODE (ad),
4535 XEXP (XEXP (ad, 0), 0),
4536 plus_constant (XEXP (XEXP (ad, 0), 1),
4537 INTVAL (XEXP (ad, 1))));
4538 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4539 reload_address_base_reg_class,
4540 GET_MODE (ad), opnum, type, ind_levels);
4541 find_reloads_address_1 (mode, XEXP (ad, 0), 1, &XEXP (ad, 0), opnum,
4542 type, 0, insn);
4544 return 1;
4547 /* See if address becomes valid when an eliminable register
4548 in a sum is replaced. */
4550 tem = ad;
4551 if (GET_CODE (ad) == PLUS)
4552 tem = subst_indexed_address (ad);
4553 if (tem != ad && strict_memory_address_p (mode, tem))
4555 /* Ok, we win that way. Replace any additional eliminable
4556 registers. */
4558 subst_reg_equivs_changed = 0;
4559 tem = subst_reg_equivs (tem);
4561 /* Make sure that didn't make the address invalid again. */
4563 if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
4565 *loc = tem;
4566 return 0;
4570 /* If constants aren't valid addresses, reload the constant address
4571 into a register. */
4572 if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad))
4574 /* If AD is in address in the constant pool, the MEM rtx may be shared.
4575 Unshare it so we can safely alter it. */
4576 if (memrefloc && GET_CODE (ad) == SYMBOL_REF
4577 && CONSTANT_POOL_ADDRESS_P (ad))
4579 *memrefloc = copy_rtx (*memrefloc);
4580 loc = &XEXP (*memrefloc, 0);
4583 find_reloads_address_part (ad, loc, reload_address_base_reg_class,
4584 Pmode, opnum, type,
4585 ind_levels);
4586 return 1;
4589 return find_reloads_address_1 (mode, ad, 0, loc, opnum, type, ind_levels,
4590 insn);
4593 /* Find all pseudo regs appearing in AD
4594 that are eliminable in favor of equivalent values
4595 and do not have hard regs; replace them by their equivalents. */
4597 static rtx
4598 subst_reg_equivs (ad)
4599 rtx ad;
4601 register RTX_CODE code = GET_CODE (ad);
4602 register int i;
4603 register char *fmt;
4605 switch (code)
4607 case HIGH:
4608 case CONST_INT:
4609 case CONST:
4610 case CONST_DOUBLE:
4611 case SYMBOL_REF:
4612 case LABEL_REF:
4613 case PC:
4614 case CC0:
4615 return ad;
4617 case REG:
4619 register int regno = REGNO (ad);
4621 if (reg_equiv_constant[regno] != 0)
4623 subst_reg_equivs_changed = 1;
4624 return reg_equiv_constant[regno];
4627 return ad;
4629 case PLUS:
4630 /* Quickly dispose of a common case. */
4631 if (XEXP (ad, 0) == frame_pointer_rtx
4632 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4633 return ad;
4636 fmt = GET_RTX_FORMAT (code);
4637 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4638 if (fmt[i] == 'e')
4639 XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i));
4640 return ad;
4643 /* Compute the sum of X and Y, making canonicalizations assumed in an
4644 address, namely: sum constant integers, surround the sum of two
4645 constants with a CONST, put the constant as the second operand, and
4646 group the constant on the outermost sum.
4648 This routine assumes both inputs are already in canonical form. */
4651 form_sum (x, y)
4652 rtx x, y;
4654 rtx tem;
4655 enum machine_mode mode = GET_MODE (x);
4657 if (mode == VOIDmode)
4658 mode = GET_MODE (y);
4660 if (mode == VOIDmode)
4661 mode = Pmode;
4663 if (GET_CODE (x) == CONST_INT)
4664 return plus_constant (y, INTVAL (x));
4665 else if (GET_CODE (y) == CONST_INT)
4666 return plus_constant (x, INTVAL (y));
4667 else if (CONSTANT_P (x))
4668 tem = x, x = y, y = tem;
4670 if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
4671 return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
4673 /* Note that if the operands of Y are specified in the opposite
4674 order in the recursive calls below, infinite recursion will occur. */
4675 if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
4676 return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
4678 /* If both constant, encapsulate sum. Otherwise, just form sum. A
4679 constant will have been placed second. */
4680 if (CONSTANT_P (x) && CONSTANT_P (y))
4682 if (GET_CODE (x) == CONST)
4683 x = XEXP (x, 0);
4684 if (GET_CODE (y) == CONST)
4685 y = XEXP (y, 0);
4687 return gen_rtx (CONST, VOIDmode, gen_rtx (PLUS, mode, x, y));
4690 return gen_rtx (PLUS, mode, x, y);
4693 /* If ADDR is a sum containing a pseudo register that should be
4694 replaced with a constant (from reg_equiv_constant),
4695 return the result of doing so, and also apply the associative
4696 law so that the result is more likely to be a valid address.
4697 (But it is not guaranteed to be one.)
4699 Note that at most one register is replaced, even if more are
4700 replaceable. Also, we try to put the result into a canonical form
4701 so it is more likely to be a valid address.
4703 In all other cases, return ADDR. */
4705 static rtx
4706 subst_indexed_address (addr)
4707 rtx addr;
4709 rtx op0 = 0, op1 = 0, op2 = 0;
4710 rtx tem;
4711 int regno;
4713 if (GET_CODE (addr) == PLUS)
4715 /* Try to find a register to replace. */
4716 op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
4717 if (GET_CODE (op0) == REG
4718 && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
4719 && reg_renumber[regno] < 0
4720 && reg_equiv_constant[regno] != 0)
4721 op0 = reg_equiv_constant[regno];
4722 else if (GET_CODE (op1) == REG
4723 && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
4724 && reg_renumber[regno] < 0
4725 && reg_equiv_constant[regno] != 0)
4726 op1 = reg_equiv_constant[regno];
4727 else if (GET_CODE (op0) == PLUS
4728 && (tem = subst_indexed_address (op0)) != op0)
4729 op0 = tem;
4730 else if (GET_CODE (op1) == PLUS
4731 && (tem = subst_indexed_address (op1)) != op1)
4732 op1 = tem;
4733 else
4734 return addr;
4736 /* Pick out up to three things to add. */
4737 if (GET_CODE (op1) == PLUS)
4738 op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
4739 else if (GET_CODE (op0) == PLUS)
4740 op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
4742 /* Compute the sum. */
4743 if (op2 != 0)
4744 op1 = form_sum (op1, op2);
4745 if (op1 != 0)
4746 op0 = form_sum (op0, op1);
4748 return op0;
4750 return addr;
4753 /* Record the pseudo registers we must reload into hard registers in a
4754 subexpression of a would-be memory address, X referring to a value
4755 in mode MODE. (This function is not called if the address we find
4756 is strictly valid.)
4758 CONTEXT = 1 means we are considering regs as index regs,
4759 = 0 means we are considering them as base regs.
4761 OPNUM and TYPE specify the purpose of any reloads made.
4763 IND_LEVELS says how many levels of indirect addressing are
4764 supported at this point in the address.
4766 INSN, if nonzero, is the insn in which we do the reload. It is used
4767 to determine if we may generate output reloads.
4769 We return nonzero if X, as a whole, is reloaded or replaced. */
4771 /* Note that we take shortcuts assuming that no multi-reg machine mode
4772 occurs as part of an address.
4773 Also, this is not fully machine-customizable; it works for machines
4774 such as vaxes and 68000's and 32000's, but other possible machines
4775 could have addressing modes that this does not handle right. */
4777 static int
4778 find_reloads_address_1 (mode, x, context, loc, opnum, type, ind_levels, insn)
4779 enum machine_mode mode;
4780 rtx x;
4781 int context;
4782 rtx *loc;
4783 int opnum;
4784 enum reload_type type;
4785 int ind_levels;
4786 rtx insn;
4788 register RTX_CODE code = GET_CODE (x);
4790 switch (code)
4792 case PLUS:
4794 register rtx orig_op0 = XEXP (x, 0);
4795 register rtx orig_op1 = XEXP (x, 1);
4796 register RTX_CODE code0 = GET_CODE (orig_op0);
4797 register RTX_CODE code1 = GET_CODE (orig_op1);
4798 register rtx op0 = orig_op0;
4799 register rtx op1 = orig_op1;
4801 if (GET_CODE (op0) == SUBREG)
4803 op0 = SUBREG_REG (op0);
4804 code0 = GET_CODE (op0);
4805 if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER)
4806 op0 = gen_rtx (REG, word_mode,
4807 REGNO (op0) + SUBREG_WORD (orig_op0));
4810 if (GET_CODE (op1) == SUBREG)
4812 op1 = SUBREG_REG (op1);
4813 code1 = GET_CODE (op1);
4814 if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER)
4815 op1 = gen_rtx (REG, GET_MODE (op1),
4816 REGNO (op1) + SUBREG_WORD (orig_op1));
4819 if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
4820 || code0 == ZERO_EXTEND || code1 == MEM)
4822 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4823 type, ind_levels, insn);
4824 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4825 type, ind_levels, insn);
4828 else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
4829 || code1 == ZERO_EXTEND || code0 == MEM)
4831 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4832 type, ind_levels, insn);
4833 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4834 type, ind_levels, insn);
4837 else if (code0 == CONST_INT || code0 == CONST
4838 || code0 == SYMBOL_REF || code0 == LABEL_REF)
4839 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4840 type, ind_levels, insn);
4842 else if (code1 == CONST_INT || code1 == CONST
4843 || code1 == SYMBOL_REF || code1 == LABEL_REF)
4844 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4845 type, ind_levels, insn);
4847 else if (code0 == REG && code1 == REG)
4849 if (REG_OK_FOR_INDEX_P (op0)
4850 && REG_MODE_OK_FOR_BASE_P (op1, mode))
4851 return 0;
4852 else if (REG_OK_FOR_INDEX_P (op1)
4853 && REG_MODE_OK_FOR_BASE_P (op0, mode))
4854 return 0;
4855 else if (REG_MODE_OK_FOR_BASE_P (op1, mode))
4856 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4857 type, ind_levels, insn);
4858 else if (REG_MODE_OK_FOR_BASE_P (op0, mode))
4859 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4860 type, ind_levels, insn);
4861 else if (REG_OK_FOR_INDEX_P (op1))
4862 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4863 type, ind_levels, insn);
4864 else if (REG_OK_FOR_INDEX_P (op0))
4865 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4866 type, ind_levels, insn);
4867 else
4869 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4870 type, ind_levels, insn);
4871 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4872 type, ind_levels, insn);
4876 else if (code0 == REG)
4878 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4879 type, ind_levels, insn);
4880 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4881 type, ind_levels, insn);
4884 else if (code1 == REG)
4886 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4887 type, ind_levels, insn);
4888 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4889 type, ind_levels, insn);
4893 return 0;
4895 case POST_INC:
4896 case POST_DEC:
4897 case PRE_INC:
4898 case PRE_DEC:
4899 if (GET_CODE (XEXP (x, 0)) == REG)
4901 register int regno = REGNO (XEXP (x, 0));
4902 int value = 0;
4903 rtx x_orig = x;
4905 /* A register that is incremented cannot be constant! */
4906 if (regno >= FIRST_PSEUDO_REGISTER
4907 && reg_equiv_constant[regno] != 0)
4908 abort ();
4910 /* Handle a register that is equivalent to a memory location
4911 which cannot be addressed directly. */
4912 if (reg_equiv_address[regno] != 0)
4914 rtx tem = make_memloc (XEXP (x, 0), regno);
4915 /* First reload the memory location's address.
4916 We can't use ADDR_TYPE (type) here, because we need to
4917 write back the value after reading it, hence we actually
4918 need two registers. */
4919 find_reloads_address (GET_MODE (tem), 0, XEXP (tem, 0),
4920 &XEXP (tem, 0), opnum, type,
4921 ind_levels, insn);
4922 /* Put this inside a new increment-expression. */
4923 x = gen_rtx (GET_CODE (x), GET_MODE (x), tem);
4924 /* Proceed to reload that, as if it contained a register. */
4927 /* If we have a hard register that is ok as an index,
4928 don't make a reload. If an autoincrement of a nice register
4929 isn't "valid", it must be that no autoincrement is "valid".
4930 If that is true and something made an autoincrement anyway,
4931 this must be a special context where one is allowed.
4932 (For example, a "push" instruction.)
4933 We can't improve this address, so leave it alone. */
4935 /* Otherwise, reload the autoincrement into a suitable hard reg
4936 and record how much to increment by. */
4938 if (reg_renumber[regno] >= 0)
4939 regno = reg_renumber[regno];
4940 if ((regno >= FIRST_PSEUDO_REGISTER
4941 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
4942 : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
4944 register rtx link;
4945 int reloadnum;
4947 /* If we can output the register afterwards, do so, this
4948 saves the extra update.
4949 We can do so if we have an INSN - i.e. no JUMP_INSN nor
4950 CALL_INSN - and it does not set CC0.
4951 But don't do this if we cannot directly address the
4952 memory location, since this will make it harder to
4953 reuse address reloads, and increses register pressure.
4954 Also don't do this if we can probably update x directly. */
4955 rtx equiv = reg_equiv_mem[regno];
4956 int icode = (int) add_optab->handlers[(int) Pmode].insn_code;
4957 if (insn && GET_CODE (insn) == INSN && equiv
4958 #ifdef HAVE_cc0
4959 && ! sets_cc0_p (PATTERN (insn))
4960 #endif
4961 && ! (icode != CODE_FOR_nothing
4962 && (*insn_operand_predicate[icode][0]) (equiv, Pmode)
4963 && (*insn_operand_predicate[icode][1]) (equiv, Pmode)))
4965 loc = &XEXP (x, 0);
4966 x = XEXP (x, 0);
4967 reloadnum
4968 = push_reload (x, x, loc, loc,
4969 (context
4970 ? reload_address_index_reg_class
4971 : reload_address_base_reg_class),
4972 GET_MODE (x), GET_MODE (x), VOIDmode, 0,
4973 opnum, RELOAD_OTHER);
4975 else
4977 reloadnum
4978 = push_reload (x, NULL_RTX, loc, NULL_PTR,
4979 (context
4980 ? reload_address_index_reg_class
4981 : reload_address_base_reg_class),
4982 GET_MODE (x), GET_MODE (x), VOIDmode, 0,
4983 opnum, type);
4984 reload_inc[reloadnum]
4985 = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
4987 value = 1;
4990 #ifdef AUTO_INC_DEC
4991 /* Update the REG_INC notes. */
4993 for (link = REG_NOTES (this_insn);
4994 link; link = XEXP (link, 1))
4995 if (REG_NOTE_KIND (link) == REG_INC
4996 && REGNO (XEXP (link, 0)) == REGNO (XEXP (x_orig, 0)))
4997 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
4998 #endif
5000 return value;
5003 else if (GET_CODE (XEXP (x, 0)) == MEM)
5005 /* This is probably the result of a substitution, by eliminate_regs,
5006 of an equivalent address for a pseudo that was not allocated to a
5007 hard register. Verify that the specified address is valid and
5008 reload it into a register. */
5009 rtx tem = XEXP (x, 0);
5010 register rtx link;
5011 int reloadnum;
5013 /* Since we know we are going to reload this item, don't decrement
5014 for the indirection level.
5016 Note that this is actually conservative: it would be slightly
5017 more efficient to use the value of SPILL_INDIRECT_LEVELS from
5018 reload1.c here. */
5019 /* We can't use ADDR_TYPE (type) here, because we need to
5020 write back the value after reading it, hence we actually
5021 need two registers. */
5022 find_reloads_address (GET_MODE (x), &XEXP (x, 0),
5023 XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0),
5024 opnum, type, ind_levels, insn);
5026 reloadnum = push_reload (x, NULL_RTX, loc, NULL_PTR,
5027 (context
5028 ? reload_address_index_reg_class
5029 : reload_address_base_reg_class),
5030 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5031 reload_inc[reloadnum]
5032 = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
5034 link = FIND_REG_INC_NOTE (this_insn, tem);
5035 if (link != 0)
5036 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5038 return 1;
5040 return 0;
5042 case MEM:
5043 /* This is probably the result of a substitution, by eliminate_regs, of
5044 an equivalent address for a pseudo that was not allocated to a hard
5045 register. Verify that the specified address is valid and reload it
5046 into a register.
5048 Since we know we are going to reload this item, don't decrement for
5049 the indirection level.
5051 Note that this is actually conservative: it would be slightly more
5052 efficient to use the value of SPILL_INDIRECT_LEVELS from
5053 reload1.c here. */
5055 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5056 opnum, ADDR_TYPE (type), ind_levels, insn);
5057 push_reload (*loc, NULL_RTX, loc, NULL_PTR,
5058 (context ? reload_address_index_reg_class
5059 : reload_address_base_reg_class),
5060 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5061 return 1;
5063 case REG:
5065 register int regno = REGNO (x);
5067 if (reg_equiv_constant[regno] != 0)
5069 find_reloads_address_part (reg_equiv_constant[regno], loc,
5070 (context
5071 ? reload_address_index_reg_class
5072 : reload_address_base_reg_class),
5073 GET_MODE (x), opnum, type, ind_levels);
5074 return 1;
5077 #if 0 /* This might screw code in reload1.c to delete prior output-reload
5078 that feeds this insn. */
5079 if (reg_equiv_mem[regno] != 0)
5081 push_reload (reg_equiv_mem[regno], NULL_RTX, loc, NULL_PTR,
5082 (context
5083 ? reload_address_index_reg_class
5084 : reload_address_base_reg_class),
5085 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5086 return 1;
5088 #endif
5090 if (reg_equiv_address[regno] != 0)
5092 x = make_memloc (x, regno);
5093 find_reloads_address (GET_MODE (x), 0, XEXP (x, 0), &XEXP (x, 0),
5094 opnum, ADDR_TYPE (type), ind_levels, insn);
5097 if (reg_renumber[regno] >= 0)
5098 regno = reg_renumber[regno];
5100 if ((regno >= FIRST_PSEUDO_REGISTER
5101 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
5102 : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
5104 push_reload (x, NULL_RTX, loc, NULL_PTR,
5105 (context
5106 ? reload_address_index_reg_class
5107 : reload_address_base_reg_class),
5108 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5109 return 1;
5112 /* If a register appearing in an address is the subject of a CLOBBER
5113 in this insn, reload it into some other register to be safe.
5114 The CLOBBER is supposed to make the register unavailable
5115 from before this insn to after it. */
5116 if (regno_clobbered_p (regno, this_insn))
5118 push_reload (x, NULL_RTX, loc, NULL_PTR,
5119 (context
5120 ? reload_address_index_reg_class
5121 : reload_address_base_reg_class),
5122 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5123 return 1;
5126 return 0;
5128 case SUBREG:
5129 if (GET_CODE (SUBREG_REG (x)) == REG)
5131 /* If this is a SUBREG of a hard register and the resulting register
5132 is of the wrong class, reload the whole SUBREG. This avoids
5133 needless copies if SUBREG_REG is multi-word. */
5134 if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5136 int regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
5138 if (! (context ? REGNO_OK_FOR_INDEX_P (regno)
5139 : REGNO_MODE_OK_FOR_BASE_P (regno, mode)))
5141 push_reload (x, NULL_RTX, loc, NULL_PTR,
5142 (context
5143 ? reload_address_index_reg_class
5144 : reload_address_base_reg_class),
5145 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5146 return 1;
5149 /* If this is a SUBREG of a pseudo-register, and the pseudo-register
5150 is larger than the class size, then reload the whole SUBREG. */
5151 else
5153 enum reg_class class = (context
5154 ? reload_address_index_reg_class
5155 : reload_address_base_reg_class);
5156 if (CLASS_MAX_NREGS (class, GET_MODE (SUBREG_REG (x)))
5157 > reg_class_size[class])
5159 push_reload (x, NULL_RTX, loc, NULL_PTR, class,
5160 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5161 return 1;
5165 break;
5169 register char *fmt = GET_RTX_FORMAT (code);
5170 register int i;
5172 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5174 if (fmt[i] == 'e')
5175 find_reloads_address_1 (mode, XEXP (x, i), context, &XEXP (x, i),
5176 opnum, type, ind_levels, insn);
5180 return 0;
5183 /* X, which is found at *LOC, is a part of an address that needs to be
5184 reloaded into a register of class CLASS. If X is a constant, or if
5185 X is a PLUS that contains a constant, check that the constant is a
5186 legitimate operand and that we are supposed to be able to load
5187 it into the register.
5189 If not, force the constant into memory and reload the MEM instead.
5191 MODE is the mode to use, in case X is an integer constant.
5193 OPNUM and TYPE describe the purpose of any reloads made.
5195 IND_LEVELS says how many levels of indirect addressing this machine
5196 supports. */
5198 static void
5199 find_reloads_address_part (x, loc, class, mode, opnum, type, ind_levels)
5200 rtx x;
5201 rtx *loc;
5202 enum reg_class class;
5203 enum machine_mode mode;
5204 int opnum;
5205 enum reload_type type;
5206 int ind_levels;
5208 if (CONSTANT_P (x)
5209 && (! LEGITIMATE_CONSTANT_P (x)
5210 || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
5212 rtx tem = x = force_const_mem (mode, x);
5213 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5214 opnum, type, ind_levels, 0);
5217 else if (GET_CODE (x) == PLUS
5218 && CONSTANT_P (XEXP (x, 1))
5219 && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
5220 || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
5222 rtx tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
5224 x = gen_rtx (PLUS, GET_MODE (x), XEXP (x, 0), tem);
5225 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5226 opnum, type, ind_levels, 0);
5229 push_reload (x, NULL_RTX, loc, NULL_PTR, class,
5230 mode, VOIDmode, 0, 0, opnum, type);
5233 /* Substitute into the current INSN the registers into which we have reloaded
5234 the things that need reloading. The array `replacements'
5235 says contains the locations of all pointers that must be changed
5236 and says what to replace them with.
5238 Return the rtx that X translates into; usually X, but modified. */
5240 void
5241 subst_reloads ()
5243 register int i;
5245 for (i = 0; i < n_replacements; i++)
5247 register struct replacement *r = &replacements[i];
5248 register rtx reloadreg = reload_reg_rtx[r->what];
5249 if (reloadreg)
5251 /* Encapsulate RELOADREG so its machine mode matches what
5252 used to be there. Note that gen_lowpart_common will
5253 do the wrong thing if RELOADREG is multi-word. RELOADREG
5254 will always be a REG here. */
5255 if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
5256 reloadreg = gen_rtx (REG, r->mode, REGNO (reloadreg));
5258 /* If we are putting this into a SUBREG and RELOADREG is a
5259 SUBREG, we would be making nested SUBREGs, so we have to fix
5260 this up. Note that r->where == &SUBREG_REG (*r->subreg_loc). */
5262 if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG)
5264 if (GET_MODE (*r->subreg_loc)
5265 == GET_MODE (SUBREG_REG (reloadreg)))
5266 *r->subreg_loc = SUBREG_REG (reloadreg);
5267 else
5269 *r->where = SUBREG_REG (reloadreg);
5270 SUBREG_WORD (*r->subreg_loc) += SUBREG_WORD (reloadreg);
5273 else
5274 *r->where = reloadreg;
5276 /* If reload got no reg and isn't optional, something's wrong. */
5277 else if (! reload_optional[r->what])
5278 abort ();
5282 /* Make a copy of any replacements being done into X and move those copies
5283 to locations in Y, a copy of X. We only look at the highest level of
5284 the RTL. */
5286 void
5287 copy_replacements (x, y)
5288 rtx x;
5289 rtx y;
5291 int i, j;
5292 enum rtx_code code = GET_CODE (x);
5293 char *fmt = GET_RTX_FORMAT (code);
5294 struct replacement *r;
5296 /* We can't support X being a SUBREG because we might then need to know its
5297 location if something inside it was replaced. */
5298 if (code == SUBREG)
5299 abort ();
5301 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5302 if (fmt[i] == 'e')
5303 for (j = 0; j < n_replacements; j++)
5305 if (replacements[j].subreg_loc == &XEXP (x, i))
5307 r = &replacements[n_replacements++];
5308 r->where = replacements[j].where;
5309 r->subreg_loc = &XEXP (y, i);
5310 r->what = replacements[j].what;
5311 r->mode = replacements[j].mode;
5313 else if (replacements[j].where == &XEXP (x, i))
5315 r = &replacements[n_replacements++];
5316 r->where = &XEXP (y, i);
5317 r->subreg_loc = 0;
5318 r->what = replacements[j].what;
5319 r->mode = replacements[j].mode;
5324 /* If LOC was scheduled to be replaced by something, return the replacement.
5325 Otherwise, return *LOC. */
5328 find_replacement (loc)
5329 rtx *loc;
5331 struct replacement *r;
5333 for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
5335 rtx reloadreg = reload_reg_rtx[r->what];
5337 if (reloadreg && r->where == loc)
5339 if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
5340 reloadreg = gen_rtx (REG, r->mode, REGNO (reloadreg));
5342 return reloadreg;
5344 else if (reloadreg && r->subreg_loc == loc)
5346 /* RELOADREG must be either a REG or a SUBREG.
5348 ??? Is it actually still ever a SUBREG? If so, why? */
5350 if (GET_CODE (reloadreg) == REG)
5351 return gen_rtx (REG, GET_MODE (*loc),
5352 REGNO (reloadreg) + SUBREG_WORD (*loc));
5353 else if (GET_MODE (reloadreg) == GET_MODE (*loc))
5354 return reloadreg;
5355 else
5356 return gen_rtx (SUBREG, GET_MODE (*loc), SUBREG_REG (reloadreg),
5357 SUBREG_WORD (reloadreg) + SUBREG_WORD (*loc));
5361 return *loc;
5364 /* Return nonzero if register in range [REGNO, ENDREGNO)
5365 appears either explicitly or implicitly in X
5366 other than being stored into (except for earlyclobber operands).
5368 References contained within the substructure at LOC do not count.
5369 LOC may be zero, meaning don't ignore anything.
5371 This is similar to refers_to_regno_p in rtlanal.c except that we
5372 look at equivalences for pseudos that didn't get hard registers. */
5375 refers_to_regno_for_reload_p (regno, endregno, x, loc)
5376 int regno, endregno;
5377 rtx x;
5378 rtx *loc;
5380 register int i;
5381 register RTX_CODE code;
5382 register char *fmt;
5384 if (x == 0)
5385 return 0;
5387 repeat:
5388 code = GET_CODE (x);
5390 switch (code)
5392 case REG:
5393 i = REGNO (x);
5395 /* If this is a pseudo, a hard register must not have been allocated.
5396 X must therefore either be a constant or be in memory. */
5397 if (i >= FIRST_PSEUDO_REGISTER)
5399 if (reg_equiv_memory_loc[i])
5400 return refers_to_regno_for_reload_p (regno, endregno,
5401 reg_equiv_memory_loc[i],
5402 NULL_PTR);
5404 if (reg_equiv_constant[i])
5405 return 0;
5407 abort ();
5410 return (endregno > i
5411 && regno < i + (i < FIRST_PSEUDO_REGISTER
5412 ? HARD_REGNO_NREGS (i, GET_MODE (x))
5413 : 1));
5415 case SUBREG:
5416 /* If this is a SUBREG of a hard reg, we can see exactly which
5417 registers are being modified. Otherwise, handle normally. */
5418 if (GET_CODE (SUBREG_REG (x)) == REG
5419 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5421 int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
5422 int inner_endregno
5423 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
5424 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
5426 return endregno > inner_regno && regno < inner_endregno;
5428 break;
5430 case CLOBBER:
5431 case SET:
5432 if (&SET_DEST (x) != loc
5433 /* Note setting a SUBREG counts as referring to the REG it is in for
5434 a pseudo but not for hard registers since we can
5435 treat each word individually. */
5436 && ((GET_CODE (SET_DEST (x)) == SUBREG
5437 && loc != &SUBREG_REG (SET_DEST (x))
5438 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
5439 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
5440 && refers_to_regno_for_reload_p (regno, endregno,
5441 SUBREG_REG (SET_DEST (x)),
5442 loc))
5443 /* If the output is an earlyclobber operand, this is
5444 a conflict. */
5445 || ((GET_CODE (SET_DEST (x)) != REG
5446 || earlyclobber_operand_p (SET_DEST (x)))
5447 && refers_to_regno_for_reload_p (regno, endregno,
5448 SET_DEST (x), loc))))
5449 return 1;
5451 if (code == CLOBBER || loc == &SET_SRC (x))
5452 return 0;
5453 x = SET_SRC (x);
5454 goto repeat;
5457 /* X does not match, so try its subexpressions. */
5459 fmt = GET_RTX_FORMAT (code);
5460 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5462 if (fmt[i] == 'e' && loc != &XEXP (x, i))
5464 if (i == 0)
5466 x = XEXP (x, 0);
5467 goto repeat;
5469 else
5470 if (refers_to_regno_for_reload_p (regno, endregno,
5471 XEXP (x, i), loc))
5472 return 1;
5474 else if (fmt[i] == 'E')
5476 register int j;
5477 for (j = XVECLEN (x, i) - 1; j >=0; j--)
5478 if (loc != &XVECEXP (x, i, j)
5479 && refers_to_regno_for_reload_p (regno, endregno,
5480 XVECEXP (x, i, j), loc))
5481 return 1;
5484 return 0;
5487 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
5488 we check if any register number in X conflicts with the relevant register
5489 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
5490 contains a MEM (we don't bother checking for memory addresses that can't
5491 conflict because we expect this to be a rare case.
5493 This function is similar to reg_overlap_mention_p in rtlanal.c except
5494 that we look at equivalences for pseudos that didn't get hard registers. */
5497 reg_overlap_mentioned_for_reload_p (x, in)
5498 rtx x, in;
5500 int regno, endregno;
5502 if (GET_CODE (x) == SUBREG)
5504 regno = REGNO (SUBREG_REG (x));
5505 if (regno < FIRST_PSEUDO_REGISTER)
5506 regno += SUBREG_WORD (x);
5508 else if (GET_CODE (x) == REG)
5510 regno = REGNO (x);
5512 /* If this is a pseudo, it must not have been assigned a hard register.
5513 Therefore, it must either be in memory or be a constant. */
5515 if (regno >= FIRST_PSEUDO_REGISTER)
5517 if (reg_equiv_memory_loc[regno])
5518 return refers_to_mem_for_reload_p (in);
5519 else if (reg_equiv_constant[regno])
5520 return 0;
5521 abort ();
5524 else if (CONSTANT_P (x))
5525 return 0;
5526 else if (GET_CODE (x) == MEM)
5527 return refers_to_mem_for_reload_p (in);
5528 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
5529 || GET_CODE (x) == CC0)
5530 return reg_mentioned_p (x, in);
5531 else
5532 abort ();
5534 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
5535 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
5537 return refers_to_regno_for_reload_p (regno, endregno, in, NULL_PTR);
5540 /* Return nonzero if anything in X contains a MEM. Look also for pseudo
5541 registers. */
5544 refers_to_mem_for_reload_p (x)
5545 rtx x;
5547 char *fmt;
5548 int i;
5550 if (GET_CODE (x) == MEM)
5551 return 1;
5553 if (GET_CODE (x) == REG)
5554 return (REGNO (x) >= FIRST_PSEUDO_REGISTER
5555 && reg_equiv_memory_loc[REGNO (x)]);
5557 fmt = GET_RTX_FORMAT (GET_CODE (x));
5558 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
5559 if (fmt[i] == 'e'
5560 && (GET_CODE (XEXP (x, i)) == MEM
5561 || refers_to_mem_for_reload_p (XEXP (x, i))))
5562 return 1;
5564 return 0;
5567 /* Check the insns before INSN to see if there is a suitable register
5568 containing the same value as GOAL.
5569 If OTHER is -1, look for a register in class CLASS.
5570 Otherwise, just see if register number OTHER shares GOAL's value.
5572 Return an rtx for the register found, or zero if none is found.
5574 If RELOAD_REG_P is (short *)1,
5575 we reject any hard reg that appears in reload_reg_rtx
5576 because such a hard reg is also needed coming into this insn.
5578 If RELOAD_REG_P is any other nonzero value,
5579 it is a vector indexed by hard reg number
5580 and we reject any hard reg whose element in the vector is nonnegative
5581 as well as any that appears in reload_reg_rtx.
5583 If GOAL is zero, then GOALREG is a register number; we look
5584 for an equivalent for that register.
5586 MODE is the machine mode of the value we want an equivalence for.
5587 If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
5589 This function is used by jump.c as well as in the reload pass.
5591 If GOAL is the sum of the stack pointer and a constant, we treat it
5592 as if it were a constant except that sp is required to be unchanging. */
5595 find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode)
5596 register rtx goal;
5597 rtx insn;
5598 enum reg_class class;
5599 register int other;
5600 short *reload_reg_p;
5601 int goalreg;
5602 enum machine_mode mode;
5604 register rtx p = insn;
5605 rtx goaltry, valtry, value, where;
5606 register rtx pat;
5607 register int regno = -1;
5608 int valueno;
5609 int goal_mem = 0;
5610 int goal_const = 0;
5611 int goal_mem_addr_varies = 0;
5612 int need_stable_sp = 0;
5613 int nregs;
5614 int valuenregs;
5616 if (goal == 0)
5617 regno = goalreg;
5618 else if (GET_CODE (goal) == REG)
5619 regno = REGNO (goal);
5620 else if (GET_CODE (goal) == MEM)
5622 enum rtx_code code = GET_CODE (XEXP (goal, 0));
5623 if (MEM_VOLATILE_P (goal))
5624 return 0;
5625 if (flag_float_store && GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT)
5626 return 0;
5627 /* An address with side effects must be reexecuted. */
5628 switch (code)
5630 case POST_INC:
5631 case PRE_INC:
5632 case POST_DEC:
5633 case PRE_DEC:
5634 return 0;
5636 goal_mem = 1;
5638 else if (CONSTANT_P (goal))
5639 goal_const = 1;
5640 else if (GET_CODE (goal) == PLUS
5641 && XEXP (goal, 0) == stack_pointer_rtx
5642 && CONSTANT_P (XEXP (goal, 1)))
5643 goal_const = need_stable_sp = 1;
5644 else
5645 return 0;
5647 /* On some machines, certain regs must always be rejected
5648 because they don't behave the way ordinary registers do. */
5650 #ifdef OVERLAPPING_REGNO_P
5651 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5652 && OVERLAPPING_REGNO_P (regno))
5653 return 0;
5654 #endif
5656 /* Scan insns back from INSN, looking for one that copies
5657 a value into or out of GOAL.
5658 Stop and give up if we reach a label. */
5660 while (1)
5662 p = PREV_INSN (p);
5663 if (p == 0 || GET_CODE (p) == CODE_LABEL)
5664 return 0;
5665 if (GET_CODE (p) == INSN
5666 /* If we don't want spill regs ... */
5667 && (! (reload_reg_p != 0
5668 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
5669 /* ... then ignore insns introduced by reload; they aren't useful
5670 and can cause results in reload_as_needed to be different
5671 from what they were when calculating the need for spills.
5672 If we notice an input-reload insn here, we will reject it below,
5673 but it might hide a usable equivalent. That makes bad code.
5674 It may even abort: perhaps no reg was spilled for this insn
5675 because it was assumed we would find that equivalent. */
5676 || INSN_UID (p) < reload_first_uid))
5678 rtx tem;
5679 pat = single_set (p);
5680 /* First check for something that sets some reg equal to GOAL. */
5681 if (pat != 0
5682 && ((regno >= 0
5683 && true_regnum (SET_SRC (pat)) == regno
5684 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5686 (regno >= 0
5687 && true_regnum (SET_DEST (pat)) == regno
5688 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
5690 (goal_const && rtx_equal_p (SET_SRC (pat), goal)
5691 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5692 || (goal_mem
5693 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
5694 && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
5695 || (goal_mem
5696 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
5697 && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
5698 /* If we are looking for a constant,
5699 and something equivalent to that constant was copied
5700 into a reg, we can use that reg. */
5701 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5702 NULL_RTX))
5703 && rtx_equal_p (XEXP (tem, 0), goal)
5704 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5705 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5706 NULL_RTX))
5707 && GET_CODE (SET_DEST (pat)) == REG
5708 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
5709 && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
5710 && GET_CODE (goal) == CONST_INT
5711 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 0, 0,
5712 VOIDmode))
5713 && rtx_equal_p (goal, goaltry)
5714 && (valtry = operand_subword (SET_DEST (pat), 0, 0,
5715 VOIDmode))
5716 && (valueno = true_regnum (valtry)) >= 0)
5717 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5718 NULL_RTX))
5719 && GET_CODE (SET_DEST (pat)) == REG
5720 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
5721 && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
5722 && GET_CODE (goal) == CONST_INT
5723 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0,
5724 VOIDmode))
5725 && rtx_equal_p (goal, goaltry)
5726 && (valtry
5727 = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
5728 && (valueno = true_regnum (valtry)) >= 0)))
5729 if (other >= 0
5730 ? valueno == other
5731 : ((unsigned) valueno < FIRST_PSEUDO_REGISTER
5732 && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
5733 valueno)))
5735 value = valtry;
5736 where = p;
5737 break;
5742 /* We found a previous insn copying GOAL into a suitable other reg VALUE
5743 (or copying VALUE into GOAL, if GOAL is also a register).
5744 Now verify that VALUE is really valid. */
5746 /* VALUENO is the register number of VALUE; a hard register. */
5748 /* Don't try to re-use something that is killed in this insn. We want
5749 to be able to trust REG_UNUSED notes. */
5750 if (find_reg_note (where, REG_UNUSED, value))
5751 return 0;
5753 /* If we propose to get the value from the stack pointer or if GOAL is
5754 a MEM based on the stack pointer, we need a stable SP. */
5755 if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM
5756 || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
5757 goal)))
5758 need_stable_sp = 1;
5760 /* Reject VALUE if the copy-insn moved the wrong sort of datum. */
5761 if (GET_MODE (value) != mode)
5762 return 0;
5764 /* Reject VALUE if it was loaded from GOAL
5765 and is also a register that appears in the address of GOAL. */
5767 if (goal_mem && value == SET_DEST (single_set (where))
5768 && refers_to_regno_for_reload_p (valueno,
5769 (valueno
5770 + HARD_REGNO_NREGS (valueno, mode)),
5771 goal, NULL_PTR))
5772 return 0;
5774 /* Reject registers that overlap GOAL. */
5776 if (!goal_mem && !goal_const
5777 && regno + HARD_REGNO_NREGS (regno, mode) > valueno
5778 && regno < valueno + HARD_REGNO_NREGS (valueno, mode))
5779 return 0;
5781 /* Reject VALUE if it is one of the regs reserved for reloads.
5782 Reload1 knows how to reuse them anyway, and it would get
5783 confused if we allocated one without its knowledge.
5784 (Now that insns introduced by reload are ignored above,
5785 this case shouldn't happen, but I'm not positive.) */
5787 if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1
5788 && reload_reg_p[valueno] >= 0)
5789 return 0;
5791 /* On some machines, certain regs must always be rejected
5792 because they don't behave the way ordinary registers do. */
5794 #ifdef OVERLAPPING_REGNO_P
5795 if (OVERLAPPING_REGNO_P (valueno))
5796 return 0;
5797 #endif
5799 nregs = HARD_REGNO_NREGS (regno, mode);
5800 valuenregs = HARD_REGNO_NREGS (valueno, mode);
5802 /* Reject VALUE if it is a register being used for an input reload
5803 even if it is not one of those reserved. */
5805 if (reload_reg_p != 0)
5807 int i;
5808 for (i = 0; i < n_reloads; i++)
5809 if (reload_reg_rtx[i] != 0 && reload_in[i])
5811 int regno1 = REGNO (reload_reg_rtx[i]);
5812 int nregs1 = HARD_REGNO_NREGS (regno1,
5813 GET_MODE (reload_reg_rtx[i]));
5814 if (regno1 < valueno + valuenregs
5815 && regno1 + nregs1 > valueno)
5816 return 0;
5820 if (goal_mem)
5821 /* We must treat frame pointer as varying here,
5822 since it can vary--in a nonlocal goto as generated by expand_goto. */
5823 goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0));
5825 /* Now verify that the values of GOAL and VALUE remain unaltered
5826 until INSN is reached. */
5828 p = insn;
5829 while (1)
5831 p = PREV_INSN (p);
5832 if (p == where)
5833 return value;
5835 /* Don't trust the conversion past a function call
5836 if either of the two is in a call-clobbered register, or memory. */
5837 if (GET_CODE (p) == CALL_INSN
5838 && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5839 && call_used_regs[regno])
5841 (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
5842 && call_used_regs[valueno])
5844 goal_mem
5845 || need_stable_sp))
5846 return 0;
5848 #ifdef NON_SAVING_SETJMP
5849 if (NON_SAVING_SETJMP && GET_CODE (p) == NOTE
5850 && NOTE_LINE_NUMBER (p) == NOTE_INSN_SETJMP)
5851 return 0;
5852 #endif
5854 #ifdef INSN_CLOBBERS_REGNO_P
5855 if ((valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
5856 && INSN_CLOBBERS_REGNO_P (p, valueno))
5857 || (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5858 && INSN_CLOBBERS_REGNO_P (p, regno)))
5859 return 0;
5860 #endif
5862 if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
5864 /* If this insn P stores in either GOAL or VALUE, return 0.
5865 If GOAL is a memory ref and this insn writes memory, return 0.
5866 If GOAL is a memory ref and its address is not constant,
5867 and this insn P changes a register used in GOAL, return 0. */
5869 pat = PATTERN (p);
5870 if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
5872 register rtx dest = SET_DEST (pat);
5873 while (GET_CODE (dest) == SUBREG
5874 || GET_CODE (dest) == ZERO_EXTRACT
5875 || GET_CODE (dest) == SIGN_EXTRACT
5876 || GET_CODE (dest) == STRICT_LOW_PART)
5877 dest = XEXP (dest, 0);
5878 if (GET_CODE (dest) == REG)
5880 register int xregno = REGNO (dest);
5881 int xnregs;
5882 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5883 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5884 else
5885 xnregs = 1;
5886 if (xregno < regno + nregs && xregno + xnregs > regno)
5887 return 0;
5888 if (xregno < valueno + valuenregs
5889 && xregno + xnregs > valueno)
5890 return 0;
5891 if (goal_mem_addr_varies
5892 && reg_overlap_mentioned_for_reload_p (dest, goal))
5893 return 0;
5895 else if (goal_mem && GET_CODE (dest) == MEM
5896 && ! push_operand (dest, GET_MODE (dest)))
5897 return 0;
5898 else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER
5899 && reg_equiv_memory_loc[regno] != 0)
5900 return 0;
5901 else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
5902 return 0;
5904 else if (GET_CODE (pat) == PARALLEL)
5906 register int i;
5907 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
5909 register rtx v1 = XVECEXP (pat, 0, i);
5910 if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
5912 register rtx dest = SET_DEST (v1);
5913 while (GET_CODE (dest) == SUBREG
5914 || GET_CODE (dest) == ZERO_EXTRACT
5915 || GET_CODE (dest) == SIGN_EXTRACT
5916 || GET_CODE (dest) == STRICT_LOW_PART)
5917 dest = XEXP (dest, 0);
5918 if (GET_CODE (dest) == REG)
5920 register int xregno = REGNO (dest);
5921 int xnregs;
5922 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5923 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5924 else
5925 xnregs = 1;
5926 if (xregno < regno + nregs
5927 && xregno + xnregs > regno)
5928 return 0;
5929 if (xregno < valueno + valuenregs
5930 && xregno + xnregs > valueno)
5931 return 0;
5932 if (goal_mem_addr_varies
5933 && reg_overlap_mentioned_for_reload_p (dest,
5934 goal))
5935 return 0;
5937 else if (goal_mem && GET_CODE (dest) == MEM
5938 && ! push_operand (dest, GET_MODE (dest)))
5939 return 0;
5940 else if (need_stable_sp
5941 && push_operand (dest, GET_MODE (dest)))
5942 return 0;
5947 if (GET_CODE (p) == CALL_INSN && CALL_INSN_FUNCTION_USAGE (p))
5949 rtx link;
5951 for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0;
5952 link = XEXP (link, 1))
5954 pat = XEXP (link, 0);
5955 if (GET_CODE (pat) == CLOBBER)
5957 register rtx dest = SET_DEST (pat);
5958 while (GET_CODE (dest) == SUBREG
5959 || GET_CODE (dest) == ZERO_EXTRACT
5960 || GET_CODE (dest) == SIGN_EXTRACT
5961 || GET_CODE (dest) == STRICT_LOW_PART)
5962 dest = XEXP (dest, 0);
5963 if (GET_CODE (dest) == REG)
5965 register int xregno = REGNO (dest);
5966 int xnregs;
5967 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5968 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5969 else
5970 xnregs = 1;
5971 if (xregno < regno + nregs
5972 && xregno + xnregs > regno)
5973 return 0;
5974 if (xregno < valueno + valuenregs
5975 && xregno + xnregs > valueno)
5976 return 0;
5977 if (goal_mem_addr_varies
5978 && reg_overlap_mentioned_for_reload_p (dest,
5979 goal))
5980 return 0;
5982 else if (goal_mem && GET_CODE (dest) == MEM
5983 && ! push_operand (dest, GET_MODE (dest)))
5984 return 0;
5985 else if (need_stable_sp
5986 && push_operand (dest, GET_MODE (dest)))
5987 return 0;
5992 #ifdef AUTO_INC_DEC
5993 /* If this insn auto-increments or auto-decrements
5994 either regno or valueno, return 0 now.
5995 If GOAL is a memory ref and its address is not constant,
5996 and this insn P increments a register used in GOAL, return 0. */
5998 register rtx link;
6000 for (link = REG_NOTES (p); link; link = XEXP (link, 1))
6001 if (REG_NOTE_KIND (link) == REG_INC
6002 && GET_CODE (XEXP (link, 0)) == REG)
6004 register int incno = REGNO (XEXP (link, 0));
6005 if (incno < regno + nregs && incno >= regno)
6006 return 0;
6007 if (incno < valueno + valuenregs && incno >= valueno)
6008 return 0;
6009 if (goal_mem_addr_varies
6010 && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
6011 goal))
6012 return 0;
6015 #endif
6020 /* Find a place where INCED appears in an increment or decrement operator
6021 within X, and return the amount INCED is incremented or decremented by.
6022 The value is always positive. */
6024 static int
6025 find_inc_amount (x, inced)
6026 rtx x, inced;
6028 register enum rtx_code code = GET_CODE (x);
6029 register char *fmt;
6030 register int i;
6032 if (code == MEM)
6034 register rtx addr = XEXP (x, 0);
6035 if ((GET_CODE (addr) == PRE_DEC
6036 || GET_CODE (addr) == POST_DEC
6037 || GET_CODE (addr) == PRE_INC
6038 || GET_CODE (addr) == POST_INC)
6039 && XEXP (addr, 0) == inced)
6040 return GET_MODE_SIZE (GET_MODE (x));
6043 fmt = GET_RTX_FORMAT (code);
6044 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6046 if (fmt[i] == 'e')
6048 register int tem = find_inc_amount (XEXP (x, i), inced);
6049 if (tem != 0)
6050 return tem;
6052 if (fmt[i] == 'E')
6054 register int j;
6055 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6057 register int tem = find_inc_amount (XVECEXP (x, i, j), inced);
6058 if (tem != 0)
6059 return tem;
6064 return 0;
6067 /* Return 1 if register REGNO is the subject of a clobber in insn INSN. */
6070 regno_clobbered_p (regno, insn)
6071 int regno;
6072 rtx insn;
6074 if (GET_CODE (PATTERN (insn)) == CLOBBER
6075 && GET_CODE (XEXP (PATTERN (insn), 0)) == REG)
6076 return REGNO (XEXP (PATTERN (insn), 0)) == regno;
6078 if (GET_CODE (PATTERN (insn)) == PARALLEL)
6080 int i = XVECLEN (PATTERN (insn), 0) - 1;
6082 for (; i >= 0; i--)
6084 rtx elt = XVECEXP (PATTERN (insn), 0, i);
6085 if (GET_CODE (elt) == CLOBBER && GET_CODE (XEXP (elt, 0)) == REG
6086 && REGNO (XEXP (elt, 0)) == regno)
6087 return 1;
6091 return 0;
6094 static char *reload_when_needed_name[] =
6096 "RELOAD_FOR_INPUT",
6097 "RELOAD_FOR_OUTPUT",
6098 "RELOAD_FOR_INSN",
6099 "RELOAD_FOR_INPUT_ADDRESS",
6100 "RELOAD_FOR_INPADDR_ADDRESS",
6101 "RELOAD_FOR_OUTPUT_ADDRESS",
6102 "RELOAD_FOR_OUTADDR_ADDRESS",
6103 "RELOAD_FOR_OPERAND_ADDRESS",
6104 "RELOAD_FOR_OPADDR_ADDR",
6105 "RELOAD_OTHER",
6106 "RELOAD_FOR_OTHER_ADDRESS"
6109 static char *reg_class_names[] = REG_CLASS_NAMES;
6111 /* These functions are used to print the variables set by 'find_reloads' */
6113 void
6114 debug_reload_to_stream (f)
6115 FILE *f;
6117 int r;
6118 char *prefix;
6120 if (! f)
6121 f = stderr;
6122 for (r = 0; r < n_reloads; r++)
6124 fprintf (f, "Reload %d: ", r);
6126 if (reload_in[r] != 0)
6128 fprintf (f, "reload_in (%s) = ",
6129 GET_MODE_NAME (reload_inmode[r]));
6130 print_inline_rtx (f, reload_in[r], 24);
6131 fprintf (f, "\n\t");
6134 if (reload_out[r] != 0)
6136 fprintf (f, "reload_out (%s) = ",
6137 GET_MODE_NAME (reload_outmode[r]));
6138 print_inline_rtx (f, reload_out[r], 24);
6139 fprintf (f, "\n\t");
6142 fprintf (f, "%s, ", reg_class_names[(int) reload_reg_class[r]]);
6144 fprintf (f, "%s (opnum = %d)",
6145 reload_when_needed_name[(int) reload_when_needed[r]],
6146 reload_opnum[r]);
6148 if (reload_optional[r])
6149 fprintf (f, ", optional");
6151 if (reload_inc[r] != 0)
6152 fprintf (f, ", inc by %d", reload_inc[r]);
6154 if (reload_nocombine[r])
6155 fprintf (f, ", can't combine");
6157 if (reload_secondary_p[r])
6158 fprintf (f, ", secondary_reload_p");
6160 if (reload_in_reg[r] != 0)
6162 fprintf (f, "\n\treload_in_reg: ");
6163 print_inline_rtx (f, reload_in_reg[r], 24);
6166 if (reload_reg_rtx[r] != 0)
6168 fprintf (f, "\n\treload_reg_rtx: ");
6169 print_inline_rtx (f, reload_reg_rtx[r], 24);
6172 prefix = "\n\t";
6173 if (reload_secondary_in_reload[r] != -1)
6175 fprintf (f, "%ssecondary_in_reload = %d",
6176 prefix, reload_secondary_in_reload[r]);
6177 prefix = ", ";
6180 if (reload_secondary_out_reload[r] != -1)
6181 fprintf (f, "%ssecondary_out_reload = %d\n",
6182 prefix, reload_secondary_out_reload[r]);
6184 prefix = "\n\t";
6185 if (reload_secondary_in_icode[r] != CODE_FOR_nothing)
6187 fprintf (f, "%ssecondary_in_icode = %s", prefix, insn_name[r]);
6188 prefix = ", ";
6191 if (reload_secondary_out_icode[r] != CODE_FOR_nothing)
6192 fprintf (f, "%ssecondary_out_icode = %s", prefix, insn_name[r]);
6194 fprintf (f, "\n");
6198 void
6199 debug_reload ()
6201 debug_reload_to_stream (stderr);