(TARGET_FILE_SWITCHING): Define.
[official-gcc.git] / gcc / reload.c
blob4a69835052a8a578dc17d0b88c144ca5f5d5329d
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 if (GET_CODE (x) == MEM)
2082 rtx base, offset = 0;
2083 rtx addr = XEXP (x, 0);
2085 if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
2086 || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
2088 val.base = XEXP (addr, 0);
2089 val.start = - GET_MODE_SIZE (GET_MODE (x));
2090 val.end = GET_MODE_SIZE (GET_MODE (x));
2091 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2092 return val;
2095 if (GET_CODE (addr) == CONST)
2097 addr = XEXP (addr, 0);
2098 all_const = 1;
2100 if (GET_CODE (addr) == PLUS)
2102 if (CONSTANT_P (XEXP (addr, 0)))
2104 base = XEXP (addr, 1);
2105 offset = XEXP (addr, 0);
2107 else if (CONSTANT_P (XEXP (addr, 1)))
2109 base = XEXP (addr, 0);
2110 offset = XEXP (addr, 1);
2114 if (offset == 0)
2116 base = addr;
2117 offset = const0_rtx;
2119 if (GET_CODE (offset) == CONST)
2120 offset = XEXP (offset, 0);
2121 if (GET_CODE (offset) == PLUS)
2123 if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
2125 base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 1));
2126 offset = XEXP (offset, 0);
2128 else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
2130 base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 0));
2131 offset = XEXP (offset, 1);
2133 else
2135 base = gen_rtx (PLUS, GET_MODE (base), base, offset);
2136 offset = const0_rtx;
2139 else if (GET_CODE (offset) != CONST_INT)
2141 base = gen_rtx (PLUS, GET_MODE (base), base, offset);
2142 offset = const0_rtx;
2145 if (all_const && GET_CODE (base) == PLUS)
2146 base = gen_rtx (CONST, GET_MODE (base), base);
2148 if (GET_CODE (offset) != CONST_INT)
2149 abort ();
2151 val.start = INTVAL (offset);
2152 val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
2153 val.base = base;
2154 return val;
2156 else if (GET_CODE (x) == REG)
2158 val.reg_flag = 1;
2159 val.start = true_regnum (x);
2160 if (val.start < 0)
2162 /* A pseudo with no hard reg. */
2163 val.start = REGNO (x);
2164 val.end = val.start + 1;
2166 else
2167 /* A hard reg. */
2168 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2170 else if (GET_CODE (x) == SUBREG)
2172 if (GET_CODE (SUBREG_REG (x)) != REG)
2173 /* This could be more precise, but it's good enough. */
2174 return decompose (SUBREG_REG (x));
2175 val.reg_flag = 1;
2176 val.start = true_regnum (x);
2177 if (val.start < 0)
2178 return decompose (SUBREG_REG (x));
2179 else
2180 /* A hard reg. */
2181 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2183 else if (CONSTANT_P (x)
2184 /* This hasn't been assigned yet, so it can't conflict yet. */
2185 || GET_CODE (x) == SCRATCH)
2186 val.safe = 1;
2187 else
2188 abort ();
2189 return val;
2192 /* Return 1 if altering Y will not modify the value of X.
2193 Y is also described by YDATA, which should be decompose (Y). */
2195 static int
2196 immune_p (x, y, ydata)
2197 rtx x, y;
2198 struct decomposition ydata;
2200 struct decomposition xdata;
2202 if (ydata.reg_flag)
2203 return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, NULL_PTR);
2204 if (ydata.safe)
2205 return 1;
2207 if (GET_CODE (y) != MEM)
2208 abort ();
2209 /* If Y is memory and X is not, Y can't affect X. */
2210 if (GET_CODE (x) != MEM)
2211 return 1;
2213 xdata = decompose (x);
2215 if (! rtx_equal_p (xdata.base, ydata.base))
2217 /* If bases are distinct symbolic constants, there is no overlap. */
2218 if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
2219 return 1;
2220 /* Constants and stack slots never overlap. */
2221 if (CONSTANT_P (xdata.base)
2222 && (ydata.base == frame_pointer_rtx
2223 || ydata.base == hard_frame_pointer_rtx
2224 || ydata.base == stack_pointer_rtx))
2225 return 1;
2226 if (CONSTANT_P (ydata.base)
2227 && (xdata.base == frame_pointer_rtx
2228 || xdata.base == hard_frame_pointer_rtx
2229 || xdata.base == stack_pointer_rtx))
2230 return 1;
2231 /* If either base is variable, we don't know anything. */
2232 return 0;
2236 return (xdata.start >= ydata.end || ydata.start >= xdata.end);
2239 /* Similar, but calls decompose. */
2242 safe_from_earlyclobber (op, clobber)
2243 rtx op, clobber;
2245 struct decomposition early_data;
2247 early_data = decompose (clobber);
2248 return immune_p (op, clobber, early_data);
2251 /* Main entry point of this file: search the body of INSN
2252 for values that need reloading and record them with push_reload.
2253 REPLACE nonzero means record also where the values occur
2254 so that subst_reloads can be used.
2256 IND_LEVELS says how many levels of indirection are supported by this
2257 machine; a value of zero means that a memory reference is not a valid
2258 memory address.
2260 LIVE_KNOWN says we have valid information about which hard
2261 regs are live at each point in the program; this is true when
2262 we are called from global_alloc but false when stupid register
2263 allocation has been done.
2265 RELOAD_REG_P if nonzero is a vector indexed by hard reg number
2266 which is nonnegative if the reg has been commandeered for reloading into.
2267 It is copied into STATIC_RELOAD_REG_P and referenced from there
2268 by various subroutines. */
2270 void
2271 find_reloads (insn, replace, ind_levels, live_known, reload_reg_p)
2272 rtx insn;
2273 int replace, ind_levels;
2274 int live_known;
2275 short *reload_reg_p;
2277 #ifdef REGISTER_CONSTRAINTS
2279 register int insn_code_number;
2280 register int i, j;
2281 int noperands;
2282 /* These are the constraints for the insn. We don't change them. */
2283 char *constraints1[MAX_RECOG_OPERANDS];
2284 /* These start out as the constraints for the insn
2285 and they are chewed up as we consider alternatives. */
2286 char *constraints[MAX_RECOG_OPERANDS];
2287 /* These are the preferred classes for an operand, or NO_REGS if it isn't
2288 a register. */
2289 enum reg_class preferred_class[MAX_RECOG_OPERANDS];
2290 char pref_or_nothing[MAX_RECOG_OPERANDS];
2291 /* Nonzero for a MEM operand whose entire address needs a reload. */
2292 int address_reloaded[MAX_RECOG_OPERANDS];
2293 /* Value of enum reload_type to use for operand. */
2294 enum reload_type operand_type[MAX_RECOG_OPERANDS];
2295 /* Value of enum reload_type to use within address of operand. */
2296 enum reload_type address_type[MAX_RECOG_OPERANDS];
2297 /* Save the usage of each operand. */
2298 enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS];
2299 int no_input_reloads = 0, no_output_reloads = 0;
2300 int n_alternatives;
2301 int this_alternative[MAX_RECOG_OPERANDS];
2302 char this_alternative_win[MAX_RECOG_OPERANDS];
2303 char this_alternative_offmemok[MAX_RECOG_OPERANDS];
2304 char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2305 int this_alternative_matches[MAX_RECOG_OPERANDS];
2306 int swapped;
2307 int goal_alternative[MAX_RECOG_OPERANDS];
2308 int this_alternative_number;
2309 int goal_alternative_number;
2310 int operand_reloadnum[MAX_RECOG_OPERANDS];
2311 int goal_alternative_matches[MAX_RECOG_OPERANDS];
2312 int goal_alternative_matched[MAX_RECOG_OPERANDS];
2313 char goal_alternative_win[MAX_RECOG_OPERANDS];
2314 char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
2315 char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2316 int goal_alternative_swapped;
2317 int best;
2318 int commutative;
2319 char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
2320 rtx substed_operand[MAX_RECOG_OPERANDS];
2321 rtx body = PATTERN (insn);
2322 rtx set = single_set (insn);
2323 int goal_earlyclobber, this_earlyclobber;
2324 enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
2326 this_insn = insn;
2327 this_insn_is_asm = 0; /* Tentative. */
2328 n_reloads = 0;
2329 n_replacements = 0;
2330 n_memlocs = 0;
2331 n_earlyclobbers = 0;
2332 replace_reloads = replace;
2333 hard_regs_live_known = live_known;
2334 static_reload_reg_p = reload_reg_p;
2336 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
2337 neither are insns that SET cc0. Insns that use CC0 are not allowed
2338 to have any input reloads. */
2339 if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == CALL_INSN)
2340 no_output_reloads = 1;
2342 #ifdef HAVE_cc0
2343 if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
2344 no_input_reloads = 1;
2345 if (reg_set_p (cc0_rtx, PATTERN (insn)))
2346 no_output_reloads = 1;
2347 #endif
2349 #ifdef SECONDARY_MEMORY_NEEDED
2350 /* The eliminated forms of any secondary memory locations are per-insn, so
2351 clear them out here. */
2353 bzero ((char *) secondary_memlocs_elim, sizeof secondary_memlocs_elim);
2354 #endif
2356 /* Find what kind of insn this is. NOPERANDS gets number of operands.
2357 Make OPERANDS point to a vector of operand values.
2358 Make OPERAND_LOCS point to a vector of pointers to
2359 where the operands were found.
2360 Fill CONSTRAINTS and CONSTRAINTS1 with pointers to the
2361 constraint-strings for this insn.
2362 Return if the insn needs no reload processing. */
2364 switch (GET_CODE (body))
2366 case USE:
2367 case CLOBBER:
2368 case ASM_INPUT:
2369 case ADDR_VEC:
2370 case ADDR_DIFF_VEC:
2371 return;
2373 case SET:
2374 /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2375 is cheap to move between them. If it is not, there may not be an insn
2376 to do the copy, so we may need a reload. */
2377 if (GET_CODE (SET_DEST (body)) == REG
2378 && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2379 && GET_CODE (SET_SRC (body)) == REG
2380 && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2381 && REGISTER_MOVE_COST (REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2382 REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2383 return;
2384 case PARALLEL:
2385 case ASM_OPERANDS:
2386 reload_n_operands = noperands = asm_noperands (body);
2387 if (noperands >= 0)
2389 /* This insn is an `asm' with operands. */
2391 insn_code_number = -1;
2392 this_insn_is_asm = 1;
2394 /* expand_asm_operands makes sure there aren't too many operands. */
2395 if (noperands > MAX_RECOG_OPERANDS)
2396 abort ();
2398 /* Now get the operand values and constraints out of the insn. */
2400 decode_asm_operands (body, recog_operand, recog_operand_loc,
2401 constraints, operand_mode);
2402 if (noperands > 0)
2404 bcopy ((char *) constraints, (char *) constraints1,
2405 noperands * sizeof (char *));
2406 n_alternatives = n_occurrences (',', constraints[0]) + 1;
2407 for (i = 1; i < noperands; i++)
2408 if (n_alternatives != n_occurrences (',', constraints[i]) + 1)
2410 error_for_asm (insn, "operand constraints differ in number of alternatives");
2411 /* Avoid further trouble with this insn. */
2412 PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
2413 n_reloads = 0;
2414 return;
2417 break;
2420 default:
2421 /* Ordinary insn: recognize it, get the operands via insn_extract
2422 and get the constraints. */
2424 insn_code_number = recog_memoized (insn);
2425 if (insn_code_number < 0)
2426 fatal_insn_not_found (insn);
2428 reload_n_operands = noperands = insn_n_operands[insn_code_number];
2429 n_alternatives = insn_n_alternatives[insn_code_number];
2430 /* Just return "no reloads" if insn has no operands with constraints. */
2431 if (n_alternatives == 0)
2432 return;
2433 insn_extract (insn);
2434 for (i = 0; i < noperands; i++)
2436 constraints[i] = constraints1[i]
2437 = insn_operand_constraint[insn_code_number][i];
2438 operand_mode[i] = insn_operand_mode[insn_code_number][i];
2442 if (noperands == 0)
2443 return;
2445 commutative = -1;
2447 /* If we will need to know, later, whether some pair of operands
2448 are the same, we must compare them now and save the result.
2449 Reloading the base and index registers will clobber them
2450 and afterward they will fail to match. */
2452 for (i = 0; i < noperands; i++)
2454 register char *p;
2455 register int c;
2457 substed_operand[i] = recog_operand[i];
2458 p = constraints[i];
2460 modified[i] = RELOAD_READ;
2462 /* Scan this operand's constraint to see if it is an output operand,
2463 an in-out operand, is commutative, or should match another. */
2465 while (c = *p++)
2467 if (c == '=')
2468 modified[i] = RELOAD_WRITE;
2469 else if (c == '+')
2470 modified[i] = RELOAD_READ_WRITE;
2471 else if (c == '%')
2473 /* The last operand should not be marked commutative. */
2474 if (i == noperands - 1)
2476 if (this_insn_is_asm)
2477 warning_for_asm (this_insn,
2478 "`%%' constraint used with last operand");
2479 else
2480 abort ();
2482 else
2483 commutative = i;
2485 else if (c >= '0' && c <= '9')
2487 c -= '0';
2488 operands_match[c][i]
2489 = operands_match_p (recog_operand[c], recog_operand[i]);
2491 /* An operand may not match itself. */
2492 if (c == i)
2494 if (this_insn_is_asm)
2495 warning_for_asm (this_insn,
2496 "operand %d has constraint %d", i, c);
2497 else
2498 abort ();
2501 /* If C can be commuted with C+1, and C might need to match I,
2502 then C+1 might also need to match I. */
2503 if (commutative >= 0)
2505 if (c == commutative || c == commutative + 1)
2507 int other = c + (c == commutative ? 1 : -1);
2508 operands_match[other][i]
2509 = operands_match_p (recog_operand[other], recog_operand[i]);
2511 if (i == commutative || i == commutative + 1)
2513 int other = i + (i == commutative ? 1 : -1);
2514 operands_match[c][other]
2515 = operands_match_p (recog_operand[c], recog_operand[other]);
2517 /* Note that C is supposed to be less than I.
2518 No need to consider altering both C and I because in
2519 that case we would alter one into the other. */
2525 /* Examine each operand that is a memory reference or memory address
2526 and reload parts of the addresses into index registers.
2527 Also here any references to pseudo regs that didn't get hard regs
2528 but are equivalent to constants get replaced in the insn itself
2529 with those constants. Nobody will ever see them again.
2531 Finally, set up the preferred classes of each operand. */
2533 for (i = 0; i < noperands; i++)
2535 register RTX_CODE code = GET_CODE (recog_operand[i]);
2537 address_reloaded[i] = 0;
2538 operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT
2539 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT
2540 : RELOAD_OTHER);
2541 address_type[i]
2542 = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS
2543 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS
2544 : RELOAD_OTHER);
2546 if (*constraints[i] == 0)
2547 /* Ignore things like match_operator operands. */
2549 else if (constraints[i][0] == 'p')
2551 find_reloads_address (VOIDmode, NULL_PTR,
2552 recog_operand[i], recog_operand_loc[i],
2553 i, operand_type[i], ind_levels, insn);
2555 /* If we now have a simple operand where we used to have a
2556 PLUS or MULT, re-recognize and try again. */
2557 if ((GET_RTX_CLASS (GET_CODE (*recog_operand_loc[i])) == 'o'
2558 || GET_CODE (*recog_operand_loc[i]) == SUBREG)
2559 && (GET_CODE (recog_operand[i]) == MULT
2560 || GET_CODE (recog_operand[i]) == PLUS))
2562 INSN_CODE (insn) = -1;
2563 find_reloads (insn, replace, ind_levels, live_known,
2564 reload_reg_p);
2565 return;
2568 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2570 else if (code == MEM)
2572 if (find_reloads_address (GET_MODE (recog_operand[i]),
2573 recog_operand_loc[i],
2574 XEXP (recog_operand[i], 0),
2575 &XEXP (recog_operand[i], 0),
2576 i, address_type[i], ind_levels, insn))
2577 address_reloaded[i] = 1;
2578 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2580 else if (code == SUBREG)
2581 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i]
2582 = find_reloads_toplev (recog_operand[i], i, address_type[i],
2583 ind_levels,
2584 set != 0
2585 && &SET_DEST (set) == recog_operand_loc[i]);
2586 else if (code == PLUS || GET_RTX_CLASS (code) == '1')
2587 /* We can get a PLUS as an "operand" as a result of register
2588 elimination. See eliminate_regs and gen_reload. We handle
2589 a unary operator by reloading the operand. */
2590 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i]
2591 = find_reloads_toplev (recog_operand[i], i, address_type[i],
2592 ind_levels, 0);
2593 else if (code == REG)
2595 /* This is equivalent to calling find_reloads_toplev.
2596 The code is duplicated for speed.
2597 When we find a pseudo always equivalent to a constant,
2598 we replace it by the constant. We must be sure, however,
2599 that we don't try to replace it in the insn in which it
2600 is being set. */
2601 register int regno = REGNO (recog_operand[i]);
2602 if (reg_equiv_constant[regno] != 0
2603 && (set == 0 || &SET_DEST (set) != recog_operand_loc[i]))
2604 substed_operand[i] = recog_operand[i]
2605 = reg_equiv_constant[regno];
2606 #if 0 /* This might screw code in reload1.c to delete prior output-reload
2607 that feeds this insn. */
2608 if (reg_equiv_mem[regno] != 0)
2609 substed_operand[i] = recog_operand[i]
2610 = reg_equiv_mem[regno];
2611 #endif
2612 if (reg_equiv_address[regno] != 0)
2614 /* If reg_equiv_address is not a constant address, copy it,
2615 since it may be shared. */
2616 /* We must rerun eliminate_regs, in case the elimination
2617 offsets have changed. */
2618 rtx address = XEXP (eliminate_regs (reg_equiv_memory_loc[regno],
2619 0, NULL_RTX, 0),
2622 if (rtx_varies_p (address))
2623 address = copy_rtx (address);
2625 /* If this is an output operand, we must output a CLOBBER
2626 after INSN so find_equiv_reg knows REGNO is being written.
2627 Mark this insn specially, do we can put our output reloads
2628 after it. */
2630 if (modified[i] != RELOAD_READ)
2631 PUT_MODE (emit_insn_after (gen_rtx (CLOBBER, VOIDmode,
2632 recog_operand[i]),
2633 insn),
2634 DImode);
2636 *recog_operand_loc[i] = recog_operand[i]
2637 = gen_rtx (MEM, GET_MODE (recog_operand[i]), address);
2638 RTX_UNCHANGING_P (recog_operand[i])
2639 = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
2640 find_reloads_address (GET_MODE (recog_operand[i]),
2641 recog_operand_loc[i],
2642 XEXP (recog_operand[i], 0),
2643 &XEXP (recog_operand[i], 0),
2644 i, address_type[i], ind_levels, insn);
2645 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2648 /* If the operand is still a register (we didn't replace it with an
2649 equivalent), get the preferred class to reload it into. */
2650 code = GET_CODE (recog_operand[i]);
2651 preferred_class[i]
2652 = ((code == REG && REGNO (recog_operand[i]) >= FIRST_PSEUDO_REGISTER)
2653 ? reg_preferred_class (REGNO (recog_operand[i])) : NO_REGS);
2654 pref_or_nothing[i]
2655 = (code == REG && REGNO (recog_operand[i]) >= FIRST_PSEUDO_REGISTER
2656 && reg_alternate_class (REGNO (recog_operand[i])) == NO_REGS);
2659 /* If this is simply a copy from operand 1 to operand 0, merge the
2660 preferred classes for the operands. */
2661 if (set != 0 && noperands >= 2 && recog_operand[0] == SET_DEST (set)
2662 && recog_operand[1] == SET_SRC (set))
2664 preferred_class[0] = preferred_class[1]
2665 = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2666 pref_or_nothing[0] |= pref_or_nothing[1];
2667 pref_or_nothing[1] |= pref_or_nothing[0];
2670 /* Now see what we need for pseudo-regs that didn't get hard regs
2671 or got the wrong kind of hard reg. For this, we must consider
2672 all the operands together against the register constraints. */
2674 best = MAX_RECOG_OPERANDS + 300;
2676 swapped = 0;
2677 goal_alternative_swapped = 0;
2678 try_swapped:
2680 /* The constraints are made of several alternatives.
2681 Each operand's constraint looks like foo,bar,... with commas
2682 separating the alternatives. The first alternatives for all
2683 operands go together, the second alternatives go together, etc.
2685 First loop over alternatives. */
2687 for (this_alternative_number = 0;
2688 this_alternative_number < n_alternatives;
2689 this_alternative_number++)
2691 /* Loop over operands for one constraint alternative. */
2692 /* LOSERS counts those that don't fit this alternative
2693 and would require loading. */
2694 int losers = 0;
2695 /* BAD is set to 1 if it some operand can't fit this alternative
2696 even after reloading. */
2697 int bad = 0;
2698 /* REJECT is a count of how undesirable this alternative says it is
2699 if any reloading is required. If the alternative matches exactly
2700 then REJECT is ignored, but otherwise it gets this much
2701 counted against it in addition to the reloading needed. Each
2702 ? counts three times here since we want the disparaging caused by
2703 a bad register class to only count 1/3 as much. */
2704 int reject = 0;
2706 this_earlyclobber = 0;
2708 for (i = 0; i < noperands; i++)
2710 register char *p = constraints[i];
2711 register int win = 0;
2712 /* 0 => this operand can be reloaded somehow for this alternative */
2713 int badop = 1;
2714 /* 0 => this operand can be reloaded if the alternative allows regs. */
2715 int winreg = 0;
2716 int c;
2717 register rtx operand = recog_operand[i];
2718 int offset = 0;
2719 /* Nonzero means this is a MEM that must be reloaded into a reg
2720 regardless of what the constraint says. */
2721 int force_reload = 0;
2722 int offmemok = 0;
2723 /* Nonzero if a constant forced into memory would be OK for this
2724 operand. */
2725 int constmemok = 0;
2726 int earlyclobber = 0;
2728 /* If the predicate accepts a unary operator, it means that
2729 we need to reload the operand. */
2730 if (GET_RTX_CLASS (GET_CODE (operand)) == '1')
2731 operand = XEXP (operand, 0);
2733 /* If the operand is a SUBREG, extract
2734 the REG or MEM (or maybe even a constant) within.
2735 (Constants can occur as a result of reg_equiv_constant.) */
2737 while (GET_CODE (operand) == SUBREG)
2739 offset += SUBREG_WORD (operand);
2740 operand = SUBREG_REG (operand);
2741 /* Force reload if this is a constant or PLUS or if there may may
2742 be a problem accessing OPERAND in the outer mode. */
2743 if (CONSTANT_P (operand)
2744 || GET_CODE (operand) == PLUS
2745 /* We must force a reload of paradoxical SUBREGs
2746 of a MEM because the alignment of the inner value
2747 may not be enough to do the outer reference. On
2748 big-endian machines, it may also reference outside
2749 the object.
2751 On machines that extend byte operations and we have a
2752 SUBREG where both the inner and outer modes are no wider
2753 than a word and the inner mode is narrower, is integral,
2754 and gets extended when loaded from memory, combine.c has
2755 made assumptions about the behavior of the machine in such
2756 register access. If the data is, in fact, in memory we
2757 must always load using the size assumed to be in the
2758 register and let the insn do the different-sized
2759 accesses. */
2760 || ((GET_CODE (operand) == MEM
2761 || (GET_CODE (operand)== REG
2762 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
2763 && (((GET_MODE_BITSIZE (GET_MODE (operand))
2764 < BIGGEST_ALIGNMENT)
2765 && (GET_MODE_SIZE (operand_mode[i])
2766 > GET_MODE_SIZE (GET_MODE (operand))))
2767 || (GET_CODE (operand) == MEM && BYTES_BIG_ENDIAN)
2768 #ifdef LOAD_EXTEND_OP
2769 || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2770 && (GET_MODE_SIZE (GET_MODE (operand))
2771 <= UNITS_PER_WORD)
2772 && (GET_MODE_SIZE (operand_mode[i])
2773 > GET_MODE_SIZE (GET_MODE (operand)))
2774 && INTEGRAL_MODE_P (GET_MODE (operand))
2775 && LOAD_EXTEND_OP (GET_MODE (operand)) != NIL)
2776 #endif
2778 /* Subreg of a hard reg which can't handle the subreg's mode
2779 or which would handle that mode in the wrong number of
2780 registers for subregging to work. */
2781 || (GET_CODE (operand) == REG
2782 && REGNO (operand) < FIRST_PSEUDO_REGISTER
2783 && ((GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2784 && (GET_MODE_SIZE (GET_MODE (operand))
2785 > UNITS_PER_WORD)
2786 && ((GET_MODE_SIZE (GET_MODE (operand))
2787 / UNITS_PER_WORD)
2788 != HARD_REGNO_NREGS (REGNO (operand),
2789 GET_MODE (operand))))
2790 || ! HARD_REGNO_MODE_OK (REGNO (operand) + offset,
2791 operand_mode[i]))))
2792 force_reload = 1;
2795 this_alternative[i] = (int) NO_REGS;
2796 this_alternative_win[i] = 0;
2797 this_alternative_offmemok[i] = 0;
2798 this_alternative_earlyclobber[i] = 0;
2799 this_alternative_matches[i] = -1;
2801 /* An empty constraint or empty alternative
2802 allows anything which matched the pattern. */
2803 if (*p == 0 || *p == ',')
2804 win = 1, badop = 0;
2806 /* Scan this alternative's specs for this operand;
2807 set WIN if the operand fits any letter in this alternative.
2808 Otherwise, clear BADOP if this operand could
2809 fit some letter after reloads,
2810 or set WINREG if this operand could fit after reloads
2811 provided the constraint allows some registers. */
2813 while (*p && (c = *p++) != ',')
2814 switch (c)
2816 case '=':
2817 case '+':
2818 case '*':
2819 break;
2821 case '%':
2822 /* The last operand should not be marked commutative. */
2823 if (i != noperands - 1)
2824 commutative = i;
2825 break;
2827 case '?':
2828 reject += 3;
2829 break;
2831 case '!':
2832 reject = 300;
2833 break;
2835 case '#':
2836 /* Ignore rest of this alternative as far as
2837 reloading is concerned. */
2838 while (*p && *p != ',') p++;
2839 break;
2841 case '0':
2842 case '1':
2843 case '2':
2844 case '3':
2845 case '4':
2846 c -= '0';
2847 this_alternative_matches[i] = c;
2848 /* We are supposed to match a previous operand.
2849 If we do, we win if that one did.
2850 If we do not, count both of the operands as losers.
2851 (This is too conservative, since most of the time
2852 only a single reload insn will be needed to make
2853 the two operands win. As a result, this alternative
2854 may be rejected when it is actually desirable.) */
2855 if ((swapped && (c != commutative || i != commutative + 1))
2856 /* If we are matching as if two operands were swapped,
2857 also pretend that operands_match had been computed
2858 with swapped.
2859 But if I is the second of those and C is the first,
2860 don't exchange them, because operands_match is valid
2861 only on one side of its diagonal. */
2862 ? (operands_match
2863 [(c == commutative || c == commutative + 1)
2864 ? 2*commutative + 1 - c : c]
2865 [(i == commutative || i == commutative + 1)
2866 ? 2*commutative + 1 - i : i])
2867 : operands_match[c][i])
2868 win = this_alternative_win[c];
2869 else
2871 /* Operands don't match. */
2872 rtx value;
2873 /* Retroactively mark the operand we had to match
2874 as a loser, if it wasn't already. */
2875 if (this_alternative_win[c])
2876 losers++;
2877 this_alternative_win[c] = 0;
2878 if (this_alternative[c] == (int) NO_REGS)
2879 bad = 1;
2880 /* But count the pair only once in the total badness of
2881 this alternative, if the pair can be a dummy reload. */
2882 value
2883 = find_dummy_reload (recog_operand[i], recog_operand[c],
2884 recog_operand_loc[i], recog_operand_loc[c],
2885 operand_mode[i], operand_mode[c],
2886 this_alternative[c], -1,
2887 this_alternative_earlyclobber[c]);
2889 if (value != 0)
2890 losers--;
2892 /* This can be fixed with reloads if the operand
2893 we are supposed to match can be fixed with reloads. */
2894 badop = 0;
2895 this_alternative[i] = this_alternative[c];
2897 /* If we have to reload this operand and some previous
2898 operand also had to match the same thing as this
2899 operand, we don't know how to do that. So reject this
2900 alternative. */
2901 if (! win || force_reload)
2902 for (j = 0; j < i; j++)
2903 if (this_alternative_matches[j]
2904 == this_alternative_matches[i])
2905 badop = 1;
2907 break;
2909 case 'p':
2910 /* All necessary reloads for an address_operand
2911 were handled in find_reloads_address. */
2912 this_alternative[i] = (int) BASE_REG_CLASS;
2913 win = 1;
2914 break;
2916 case 'm':
2917 if (force_reload)
2918 break;
2919 if (GET_CODE (operand) == MEM
2920 || (GET_CODE (operand) == REG
2921 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
2922 && reg_renumber[REGNO (operand)] < 0))
2923 win = 1;
2924 if (CONSTANT_P (operand))
2925 badop = 0;
2926 constmemok = 1;
2927 break;
2929 case '<':
2930 if (GET_CODE (operand) == MEM
2931 && ! address_reloaded[i]
2932 && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
2933 || GET_CODE (XEXP (operand, 0)) == POST_DEC))
2934 win = 1;
2935 break;
2937 case '>':
2938 if (GET_CODE (operand) == MEM
2939 && ! address_reloaded[i]
2940 && (GET_CODE (XEXP (operand, 0)) == PRE_INC
2941 || GET_CODE (XEXP (operand, 0)) == POST_INC))
2942 win = 1;
2943 break;
2945 /* Memory operand whose address is not offsettable. */
2946 case 'V':
2947 if (force_reload)
2948 break;
2949 if (GET_CODE (operand) == MEM
2950 && ! (ind_levels ? offsettable_memref_p (operand)
2951 : offsettable_nonstrict_memref_p (operand))
2952 /* Certain mem addresses will become offsettable
2953 after they themselves are reloaded. This is important;
2954 we don't want our own handling of unoffsettables
2955 to override the handling of reg_equiv_address. */
2956 && !(GET_CODE (XEXP (operand, 0)) == REG
2957 && (ind_levels == 0
2958 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0)))
2959 win = 1;
2960 break;
2962 /* Memory operand whose address is offsettable. */
2963 case 'o':
2964 if (force_reload)
2965 break;
2966 if ((GET_CODE (operand) == MEM
2967 /* If IND_LEVELS, find_reloads_address won't reload a
2968 pseudo that didn't get a hard reg, so we have to
2969 reject that case. */
2970 && (ind_levels ? offsettable_memref_p (operand)
2971 : offsettable_nonstrict_memref_p (operand)))
2972 /* A reloaded auto-increment address is offsettable,
2973 because it is now just a simple register indirect. */
2974 || (GET_CODE (operand) == MEM
2975 && address_reloaded[i]
2976 && (GET_CODE (XEXP (operand, 0)) == PRE_INC
2977 || GET_CODE (XEXP (operand, 0)) == PRE_DEC
2978 || GET_CODE (XEXP (operand, 0)) == POST_INC
2979 || GET_CODE (XEXP (operand, 0)) == POST_DEC))
2980 /* Certain mem addresses will become offsettable
2981 after they themselves are reloaded. This is important;
2982 we don't want our own handling of unoffsettables
2983 to override the handling of reg_equiv_address. */
2984 || (GET_CODE (operand) == MEM
2985 && GET_CODE (XEXP (operand, 0)) == REG
2986 && (ind_levels == 0
2987 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0))
2988 || (GET_CODE (operand) == REG
2989 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
2990 && reg_renumber[REGNO (operand)] < 0
2991 /* If reg_equiv_address is nonzero, we will be
2992 loading it into a register; hence it will be
2993 offsettable, but we cannot say that reg_equiv_mem
2994 is offsettable without checking. */
2995 && ((reg_equiv_mem[REGNO (operand)] != 0
2996 && offsettable_memref_p (reg_equiv_mem[REGNO (operand)]))
2997 || (reg_equiv_address[REGNO (operand)] != 0))))
2998 win = 1;
2999 if (CONSTANT_P (operand) || GET_CODE (operand) == MEM)
3000 badop = 0;
3001 constmemok = 1;
3002 offmemok = 1;
3003 break;
3005 case '&':
3006 /* Output operand that is stored before the need for the
3007 input operands (and their index registers) is over. */
3008 earlyclobber = 1, this_earlyclobber = 1;
3009 break;
3011 case 'E':
3012 #ifndef REAL_ARITHMETIC
3013 /* Match any floating double constant, but only if
3014 we can examine the bits of it reliably. */
3015 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3016 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3017 && GET_MODE (operand) != VOIDmode && ! flag_pretend_float)
3018 break;
3019 #endif
3020 if (GET_CODE (operand) == CONST_DOUBLE)
3021 win = 1;
3022 break;
3024 case 'F':
3025 if (GET_CODE (operand) == CONST_DOUBLE)
3026 win = 1;
3027 break;
3029 case 'G':
3030 case 'H':
3031 if (GET_CODE (operand) == CONST_DOUBLE
3032 && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
3033 win = 1;
3034 break;
3036 case 's':
3037 if (GET_CODE (operand) == CONST_INT
3038 || (GET_CODE (operand) == CONST_DOUBLE
3039 && GET_MODE (operand) == VOIDmode))
3040 break;
3041 case 'i':
3042 if (CONSTANT_P (operand)
3043 #ifdef LEGITIMATE_PIC_OPERAND_P
3044 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand))
3045 #endif
3047 win = 1;
3048 break;
3050 case 'n':
3051 if (GET_CODE (operand) == CONST_INT
3052 || (GET_CODE (operand) == CONST_DOUBLE
3053 && GET_MODE (operand) == VOIDmode))
3054 win = 1;
3055 break;
3057 case 'I':
3058 case 'J':
3059 case 'K':
3060 case 'L':
3061 case 'M':
3062 case 'N':
3063 case 'O':
3064 case 'P':
3065 if (GET_CODE (operand) == CONST_INT
3066 && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
3067 win = 1;
3068 break;
3070 case 'X':
3071 win = 1;
3072 break;
3074 case 'g':
3075 if (! force_reload
3076 /* A PLUS is never a valid operand, but reload can make
3077 it from a register when eliminating registers. */
3078 && GET_CODE (operand) != PLUS
3079 /* A SCRATCH is not a valid operand. */
3080 && GET_CODE (operand) != SCRATCH
3081 #ifdef LEGITIMATE_PIC_OPERAND_P
3082 && (! CONSTANT_P (operand)
3083 || ! flag_pic
3084 || LEGITIMATE_PIC_OPERAND_P (operand))
3085 #endif
3086 && (GENERAL_REGS == ALL_REGS
3087 || GET_CODE (operand) != REG
3088 || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
3089 && reg_renumber[REGNO (operand)] < 0)))
3090 win = 1;
3091 /* Drop through into 'r' case */
3093 case 'r':
3094 this_alternative[i]
3095 = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
3096 goto reg;
3098 #ifdef EXTRA_CONSTRAINT
3099 case 'Q':
3100 case 'R':
3101 case 'S':
3102 case 'T':
3103 case 'U':
3104 if (EXTRA_CONSTRAINT (operand, c))
3105 win = 1;
3106 break;
3107 #endif
3109 default:
3110 this_alternative[i]
3111 = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
3113 reg:
3114 if (GET_MODE (operand) == BLKmode)
3115 break;
3116 winreg = 1;
3117 if (GET_CODE (operand) == REG
3118 && reg_fits_class_p (operand, this_alternative[i],
3119 offset, GET_MODE (recog_operand[i])))
3120 win = 1;
3121 break;
3124 constraints[i] = p;
3126 /* If this operand could be handled with a reg,
3127 and some reg is allowed, then this operand can be handled. */
3128 if (winreg && this_alternative[i] != (int) NO_REGS)
3129 badop = 0;
3131 /* Record which operands fit this alternative. */
3132 this_alternative_earlyclobber[i] = earlyclobber;
3133 if (win && ! force_reload)
3134 this_alternative_win[i] = 1;
3135 else
3137 int const_to_mem = 0;
3139 this_alternative_offmemok[i] = offmemok;
3140 losers++;
3141 if (badop)
3142 bad = 1;
3143 /* Alternative loses if it has no regs for a reg operand. */
3144 if (GET_CODE (operand) == REG
3145 && this_alternative[i] == (int) NO_REGS
3146 && this_alternative_matches[i] < 0)
3147 bad = 1;
3149 /* Alternative loses if it requires a type of reload not
3150 permitted for this insn. We can always reload SCRATCH
3151 and objects with a REG_UNUSED note. */
3152 if (GET_CODE (operand) != SCRATCH
3153 && modified[i] != RELOAD_READ && no_output_reloads
3154 && ! find_reg_note (insn, REG_UNUSED, operand))
3155 bad = 1;
3156 else if (modified[i] != RELOAD_WRITE && no_input_reloads)
3157 bad = 1;
3159 /* If this is a constant that is reloaded into the desired
3160 class by copying it to memory first, count that as another
3161 reload. This is consistent with other code and is
3162 required to avoid choosing another alternative when
3163 the constant is moved into memory by this function on
3164 an early reload pass. Note that the test here is
3165 precisely the same as in the code below that calls
3166 force_const_mem. */
3167 if (CONSTANT_P (operand)
3168 /* force_const_mem does not accept HIGH. */
3169 && GET_CODE (operand) != HIGH
3170 && (PREFERRED_RELOAD_CLASS (operand,
3171 (enum reg_class) this_alternative[i])
3172 == NO_REGS)
3173 && operand_mode[i] != VOIDmode)
3175 const_to_mem = 1;
3176 if (this_alternative[i] != (int) NO_REGS)
3177 losers++;
3180 /* If we can't reload this value at all, reject this
3181 alternative. Note that we could also lose due to
3182 LIMIT_RELOAD_RELOAD_CLASS, but we don't check that
3183 here. */
3185 if (! CONSTANT_P (operand)
3186 && (enum reg_class) this_alternative[i] != NO_REGS
3187 && (PREFERRED_RELOAD_CLASS (operand,
3188 (enum reg_class) this_alternative[i])
3189 == NO_REGS))
3190 bad = 1;
3192 /* We prefer to reload pseudos over reloading other things,
3193 since such reloads may be able to be eliminated later.
3194 If we are reloading a SCRATCH, we won't be generating any
3195 insns, just using a register, so it is also preferred.
3196 So bump REJECT in other cases. Don't do this in the
3197 case where we are forcing a constant into memory and
3198 it will then win since we don't want to have a different
3199 alternative match then. */
3200 if (! (GET_CODE (operand) == REG
3201 && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
3202 && GET_CODE (operand) != SCRATCH
3203 && ! (const_to_mem && constmemok))
3204 reject++;
3207 /* If this operand is a pseudo register that didn't get a hard
3208 reg and this alternative accepts some register, see if the
3209 class that we want is a subset of the preferred class for this
3210 register. If not, but it intersects that class, use the
3211 preferred class instead. If it does not intersect the preferred
3212 class, show that usage of this alternative should be discouraged;
3213 it will be discouraged more still if the register is `preferred
3214 or nothing'. We do this because it increases the chance of
3215 reusing our spill register in a later insn and avoiding a pair
3216 of memory stores and loads.
3218 Don't bother with this if this alternative will accept this
3219 operand.
3221 Don't do this for a multiword operand, since it is only a
3222 small win and has the risk of requiring more spill registers,
3223 which could cause a large loss.
3225 Don't do this if the preferred class has only one register
3226 because we might otherwise exhaust the class. */
3229 if (! win && this_alternative[i] != (int) NO_REGS
3230 && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3231 && reg_class_size[(int) preferred_class[i]] > 1)
3233 if (! reg_class_subset_p (this_alternative[i],
3234 preferred_class[i]))
3236 /* Since we don't have a way of forming the intersection,
3237 we just do something special if the preferred class
3238 is a subset of the class we have; that's the most
3239 common case anyway. */
3240 if (reg_class_subset_p (preferred_class[i],
3241 this_alternative[i]))
3242 this_alternative[i] = (int) preferred_class[i];
3243 else
3244 reject += (1 + pref_or_nothing[i]);
3249 /* Now see if any output operands that are marked "earlyclobber"
3250 in this alternative conflict with any input operands
3251 or any memory addresses. */
3253 for (i = 0; i < noperands; i++)
3254 if (this_alternative_earlyclobber[i]
3255 && this_alternative_win[i])
3257 struct decomposition early_data;
3259 early_data = decompose (recog_operand[i]);
3261 if (modified[i] == RELOAD_READ)
3263 if (this_insn_is_asm)
3264 warning_for_asm (this_insn,
3265 "`&' constraint used with input operand");
3266 else
3267 abort ();
3268 continue;
3271 if (this_alternative[i] == NO_REGS)
3273 this_alternative_earlyclobber[i] = 0;
3274 if (this_insn_is_asm)
3275 error_for_asm (this_insn,
3276 "`&' constraint used with no register class");
3277 else
3278 abort ();
3281 for (j = 0; j < noperands; j++)
3282 /* Is this an input operand or a memory ref? */
3283 if ((GET_CODE (recog_operand[j]) == MEM
3284 || modified[j] != RELOAD_WRITE)
3285 && j != i
3286 /* Ignore things like match_operator operands. */
3287 && *constraints1[j] != 0
3288 /* Don't count an input operand that is constrained to match
3289 the early clobber operand. */
3290 && ! (this_alternative_matches[j] == i
3291 && rtx_equal_p (recog_operand[i], recog_operand[j]))
3292 /* Is it altered by storing the earlyclobber operand? */
3293 && !immune_p (recog_operand[j], recog_operand[i], early_data))
3295 /* If the output is in a single-reg class,
3296 it's costly to reload it, so reload the input instead. */
3297 if (reg_class_size[this_alternative[i]] == 1
3298 && (GET_CODE (recog_operand[j]) == REG
3299 || GET_CODE (recog_operand[j]) == SUBREG))
3301 losers++;
3302 this_alternative_win[j] = 0;
3304 else
3305 break;
3307 /* If an earlyclobber operand conflicts with something,
3308 it must be reloaded, so request this and count the cost. */
3309 if (j != noperands)
3311 losers++;
3312 this_alternative_win[i] = 0;
3313 for (j = 0; j < noperands; j++)
3314 if (this_alternative_matches[j] == i
3315 && this_alternative_win[j])
3317 this_alternative_win[j] = 0;
3318 losers++;
3323 /* If one alternative accepts all the operands, no reload required,
3324 choose that alternative; don't consider the remaining ones. */
3325 if (losers == 0)
3327 /* Unswap these so that they are never swapped at `finish'. */
3328 if (commutative >= 0)
3330 recog_operand[commutative] = substed_operand[commutative];
3331 recog_operand[commutative + 1]
3332 = substed_operand[commutative + 1];
3334 for (i = 0; i < noperands; i++)
3336 goal_alternative_win[i] = 1;
3337 goal_alternative[i] = this_alternative[i];
3338 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3339 goal_alternative_matches[i] = this_alternative_matches[i];
3340 goal_alternative_earlyclobber[i]
3341 = this_alternative_earlyclobber[i];
3343 goal_alternative_number = this_alternative_number;
3344 goal_alternative_swapped = swapped;
3345 goal_earlyclobber = this_earlyclobber;
3346 goto finish;
3349 /* REJECT, set by the ! and ? constraint characters and when a register
3350 would be reloaded into a non-preferred class, discourages the use of
3351 this alternative for a reload goal. REJECT is incremented by three
3352 for each ? and one for each non-preferred class. */
3353 losers = losers * 3 + reject;
3355 /* If this alternative can be made to work by reloading,
3356 and it needs less reloading than the others checked so far,
3357 record it as the chosen goal for reloading. */
3358 if (! bad && best > losers)
3360 for (i = 0; i < noperands; i++)
3362 goal_alternative[i] = this_alternative[i];
3363 goal_alternative_win[i] = this_alternative_win[i];
3364 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3365 goal_alternative_matches[i] = this_alternative_matches[i];
3366 goal_alternative_earlyclobber[i]
3367 = this_alternative_earlyclobber[i];
3369 goal_alternative_swapped = swapped;
3370 best = losers;
3371 goal_alternative_number = this_alternative_number;
3372 goal_earlyclobber = this_earlyclobber;
3376 /* If insn is commutative (it's safe to exchange a certain pair of operands)
3377 then we need to try each alternative twice,
3378 the second time matching those two operands
3379 as if we had exchanged them.
3380 To do this, really exchange them in operands.
3382 If we have just tried the alternatives the second time,
3383 return operands to normal and drop through. */
3385 if (commutative >= 0)
3387 swapped = !swapped;
3388 if (swapped)
3390 register enum reg_class tclass;
3391 register int t;
3393 recog_operand[commutative] = substed_operand[commutative + 1];
3394 recog_operand[commutative + 1] = substed_operand[commutative];
3396 tclass = preferred_class[commutative];
3397 preferred_class[commutative] = preferred_class[commutative + 1];
3398 preferred_class[commutative + 1] = tclass;
3400 t = pref_or_nothing[commutative];
3401 pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
3402 pref_or_nothing[commutative + 1] = t;
3404 bcopy ((char *) constraints1, (char *) constraints,
3405 noperands * sizeof (char *));
3406 goto try_swapped;
3408 else
3410 recog_operand[commutative] = substed_operand[commutative];
3411 recog_operand[commutative + 1] = substed_operand[commutative + 1];
3415 /* The operands don't meet the constraints.
3416 goal_alternative describes the alternative
3417 that we could reach by reloading the fewest operands.
3418 Reload so as to fit it. */
3420 if (best == MAX_RECOG_OPERANDS + 300)
3422 /* No alternative works with reloads?? */
3423 if (insn_code_number >= 0)
3424 abort ();
3425 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3426 /* Avoid further trouble with this insn. */
3427 PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
3428 n_reloads = 0;
3429 return;
3432 /* Jump to `finish' from above if all operands are valid already.
3433 In that case, goal_alternative_win is all 1. */
3434 finish:
3436 /* Right now, for any pair of operands I and J that are required to match,
3437 with I < J,
3438 goal_alternative_matches[J] is I.
3439 Set up goal_alternative_matched as the inverse function:
3440 goal_alternative_matched[I] = J. */
3442 for (i = 0; i < noperands; i++)
3443 goal_alternative_matched[i] = -1;
3445 for (i = 0; i < noperands; i++)
3446 if (! goal_alternative_win[i]
3447 && goal_alternative_matches[i] >= 0)
3448 goal_alternative_matched[goal_alternative_matches[i]] = i;
3450 /* If the best alternative is with operands 1 and 2 swapped,
3451 consider them swapped before reporting the reloads. Update the
3452 operand numbers of any reloads already pushed. */
3454 if (goal_alternative_swapped)
3456 register rtx tem;
3458 tem = substed_operand[commutative];
3459 substed_operand[commutative] = substed_operand[commutative + 1];
3460 substed_operand[commutative + 1] = tem;
3461 tem = recog_operand[commutative];
3462 recog_operand[commutative] = recog_operand[commutative + 1];
3463 recog_operand[commutative + 1] = tem;
3465 for (i = 0; i < n_reloads; i++)
3467 if (reload_opnum[i] == commutative)
3468 reload_opnum[i] = commutative + 1;
3469 else if (reload_opnum[i] == commutative + 1)
3470 reload_opnum[i] = commutative;
3474 /* Perform whatever substitutions on the operands we are supposed
3475 to make due to commutativity or replacement of registers
3476 with equivalent constants or memory slots. */
3478 for (i = 0; i < noperands; i++)
3480 *recog_operand_loc[i] = substed_operand[i];
3481 /* While we are looping on operands, initialize this. */
3482 operand_reloadnum[i] = -1;
3484 /* If this is an earlyclobber operand, we need to widen the scope.
3485 The reload must remain valid from the start of the insn being
3486 reloaded until after the operand is stored into its destination.
3487 We approximate this with RELOAD_OTHER even though we know that we
3488 do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads.
3490 One special case that is worth checking is when we have an
3491 output that is earlyclobber but isn't used past the insn (typically
3492 a SCRATCH). In this case, we only need have the reload live
3493 through the insn itself, but not for any of our input or output
3494 reloads.
3496 In any case, anything needed to address this operand can remain
3497 however they were previously categorized. */
3499 if (goal_alternative_earlyclobber[i])
3500 operand_type[i]
3501 = (find_reg_note (insn, REG_UNUSED, recog_operand[i])
3502 ? RELOAD_FOR_INSN : RELOAD_OTHER);
3505 /* Any constants that aren't allowed and can't be reloaded
3506 into registers are here changed into memory references. */
3507 for (i = 0; i < noperands; i++)
3508 if (! goal_alternative_win[i]
3509 && CONSTANT_P (recog_operand[i])
3510 /* force_const_mem does not accept HIGH. */
3511 && GET_CODE (recog_operand[i]) != HIGH
3512 && (PREFERRED_RELOAD_CLASS (recog_operand[i],
3513 (enum reg_class) goal_alternative[i])
3514 == NO_REGS)
3515 && operand_mode[i] != VOIDmode)
3517 *recog_operand_loc[i] = recog_operand[i]
3518 = find_reloads_toplev (force_const_mem (operand_mode[i],
3519 recog_operand[i]),
3520 i, address_type[i], ind_levels, 0);
3521 if (alternative_allows_memconst (constraints1[i],
3522 goal_alternative_number))
3523 goal_alternative_win[i] = 1;
3526 /* Record the values of the earlyclobber operands for the caller. */
3527 if (goal_earlyclobber)
3528 for (i = 0; i < noperands; i++)
3529 if (goal_alternative_earlyclobber[i])
3530 reload_earlyclobbers[n_earlyclobbers++] = recog_operand[i];
3532 /* Now record reloads for all the operands that need them. */
3533 for (i = 0; i < noperands; i++)
3534 if (! goal_alternative_win[i])
3536 /* Operands that match previous ones have already been handled. */
3537 if (goal_alternative_matches[i] >= 0)
3539 /* Handle an operand with a nonoffsettable address
3540 appearing where an offsettable address will do
3541 by reloading the address into a base register.
3543 ??? We can also do this when the operand is a register and
3544 reg_equiv_mem is not offsettable, but this is a bit tricky,
3545 so we don't bother with it. It may not be worth doing. */
3546 else if (goal_alternative_matched[i] == -1
3547 && goal_alternative_offmemok[i]
3548 && GET_CODE (recog_operand[i]) == MEM)
3550 operand_reloadnum[i]
3551 = push_reload (XEXP (recog_operand[i], 0), NULL_RTX,
3552 &XEXP (recog_operand[i], 0), NULL_PTR,
3553 BASE_REG_CLASS, GET_MODE (XEXP (recog_operand[i], 0)),
3554 VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
3555 reload_inc[operand_reloadnum[i]]
3556 = GET_MODE_SIZE (GET_MODE (recog_operand[i]));
3558 /* If this operand is an output, we will have made any
3559 reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but
3560 now we are treating part of the operand as an input, so
3561 we must change these to RELOAD_FOR_INPUT_ADDRESS. */
3563 if (modified[i] == RELOAD_WRITE)
3565 for (j = 0; j < n_reloads; j++)
3567 if (reload_opnum[j] == i)
3569 if (reload_when_needed[j] == RELOAD_FOR_OUTPUT_ADDRESS)
3570 reload_when_needed[j] = RELOAD_FOR_INPUT_ADDRESS;
3571 else if (reload_when_needed[j]
3572 == RELOAD_FOR_OUTADDR_ADDRESS)
3573 reload_when_needed[j] = RELOAD_FOR_INPADDR_ADDRESS;
3578 else if (goal_alternative_matched[i] == -1)
3579 operand_reloadnum[i] =
3580 push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
3581 modified[i] != RELOAD_READ ? recog_operand[i] : 0,
3582 (modified[i] != RELOAD_WRITE ?
3583 recog_operand_loc[i] : 0),
3584 modified[i] != RELOAD_READ ? recog_operand_loc[i] : 0,
3585 (enum reg_class) goal_alternative[i],
3586 (modified[i] == RELOAD_WRITE
3587 ? VOIDmode : operand_mode[i]),
3588 (modified[i] == RELOAD_READ
3589 ? VOIDmode : operand_mode[i]),
3590 (insn_code_number < 0 ? 0
3591 : insn_operand_strict_low[insn_code_number][i]),
3592 0, i, operand_type[i]);
3593 /* In a matching pair of operands, one must be input only
3594 and the other must be output only.
3595 Pass the input operand as IN and the other as OUT. */
3596 else if (modified[i] == RELOAD_READ
3597 && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
3599 operand_reloadnum[i]
3600 = push_reload (recog_operand[i],
3601 recog_operand[goal_alternative_matched[i]],
3602 recog_operand_loc[i],
3603 recog_operand_loc[goal_alternative_matched[i]],
3604 (enum reg_class) goal_alternative[i],
3605 operand_mode[i],
3606 operand_mode[goal_alternative_matched[i]],
3607 0, 0, i, RELOAD_OTHER);
3608 operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
3610 else if (modified[i] == RELOAD_WRITE
3611 && modified[goal_alternative_matched[i]] == RELOAD_READ)
3613 operand_reloadnum[goal_alternative_matched[i]]
3614 = push_reload (recog_operand[goal_alternative_matched[i]],
3615 recog_operand[i],
3616 recog_operand_loc[goal_alternative_matched[i]],
3617 recog_operand_loc[i],
3618 (enum reg_class) goal_alternative[i],
3619 operand_mode[goal_alternative_matched[i]],
3620 operand_mode[i],
3621 0, 0, i, RELOAD_OTHER);
3622 operand_reloadnum[i] = output_reloadnum;
3624 else if (insn_code_number >= 0)
3625 abort ();
3626 else
3628 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3629 /* Avoid further trouble with this insn. */
3630 PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
3631 n_reloads = 0;
3632 return;
3635 else if (goal_alternative_matched[i] < 0
3636 && goal_alternative_matches[i] < 0
3637 && optimize)
3639 /* For each non-matching operand that's a MEM or a pseudo-register
3640 that didn't get a hard register, make an optional reload.
3641 This may get done even if the insn needs no reloads otherwise. */
3643 rtx operand = recog_operand[i];
3645 while (GET_CODE (operand) == SUBREG)
3646 operand = XEXP (operand, 0);
3647 if ((GET_CODE (operand) == MEM
3648 || (GET_CODE (operand) == REG
3649 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3650 && (enum reg_class) goal_alternative[i] != NO_REGS
3651 && ! no_input_reloads
3652 /* Optional output reloads don't do anything and we mustn't
3653 make in-out reloads on insns that are not permitted output
3654 reloads. */
3655 && (modified[i] == RELOAD_READ
3656 || (modified[i] == RELOAD_READ_WRITE && ! no_output_reloads)))
3657 operand_reloadnum[i]
3658 = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
3659 modified[i] != RELOAD_READ ? recog_operand[i] : 0,
3660 (modified[i] != RELOAD_WRITE
3661 ? recog_operand_loc[i] : 0),
3662 (modified[i] != RELOAD_READ
3663 ? recog_operand_loc[i] : 0),
3664 (enum reg_class) goal_alternative[i],
3665 (modified[i] == RELOAD_WRITE
3666 ? VOIDmode : operand_mode[i]),
3667 (modified[i] == RELOAD_READ
3668 ? VOIDmode : operand_mode[i]),
3669 (insn_code_number < 0 ? 0
3670 : insn_operand_strict_low[insn_code_number][i]),
3671 1, i, operand_type[i]);
3673 else if (goal_alternative_matches[i] >= 0
3674 && goal_alternative_win[goal_alternative_matches[i]]
3675 && modified[i] == RELOAD_READ
3676 && modified[goal_alternative_matches[i]] == RELOAD_WRITE
3677 && ! no_input_reloads && ! no_output_reloads
3678 && optimize)
3680 /* Similarly, make an optional reload for a pair of matching
3681 objects that are in MEM or a pseudo that didn't get a hard reg. */
3683 rtx operand = recog_operand[i];
3685 while (GET_CODE (operand) == SUBREG)
3686 operand = XEXP (operand, 0);
3687 if ((GET_CODE (operand) == MEM
3688 || (GET_CODE (operand) == REG
3689 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3690 && ((enum reg_class) goal_alternative[goal_alternative_matches[i]]
3691 != NO_REGS))
3692 operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]]
3693 = push_reload (recog_operand[goal_alternative_matches[i]],
3694 recog_operand[i],
3695 recog_operand_loc[goal_alternative_matches[i]],
3696 recog_operand_loc[i],
3697 (enum reg_class) goal_alternative[goal_alternative_matches[i]],
3698 operand_mode[goal_alternative_matches[i]],
3699 operand_mode[i],
3700 0, 1, goal_alternative_matches[i], RELOAD_OTHER);
3703 /* If this insn pattern contains any MATCH_DUP's, make sure that
3704 they will be substituted if the operands they match are substituted.
3705 Also do now any substitutions we already did on the operands.
3707 Don't do this if we aren't making replacements because we might be
3708 propagating things allocated by frame pointer elimination into places
3709 it doesn't expect. */
3711 if (insn_code_number >= 0 && replace)
3712 for (i = insn_n_dups[insn_code_number] - 1; i >= 0; i--)
3714 int opno = recog_dup_num[i];
3715 *recog_dup_loc[i] = *recog_operand_loc[opno];
3716 if (operand_reloadnum[opno] >= 0)
3717 push_replacement (recog_dup_loc[i], operand_reloadnum[opno],
3718 insn_operand_mode[insn_code_number][opno]);
3721 #if 0
3722 /* This loses because reloading of prior insns can invalidate the equivalence
3723 (or at least find_equiv_reg isn't smart enough to find it any more),
3724 causing this insn to need more reload regs than it needed before.
3725 It may be too late to make the reload regs available.
3726 Now this optimization is done safely in choose_reload_regs. */
3728 /* For each reload of a reg into some other class of reg,
3729 search for an existing equivalent reg (same value now) in the right class.
3730 We can use it as long as we don't need to change its contents. */
3731 for (i = 0; i < n_reloads; i++)
3732 if (reload_reg_rtx[i] == 0
3733 && reload_in[i] != 0
3734 && GET_CODE (reload_in[i]) == REG
3735 && reload_out[i] == 0)
3737 reload_reg_rtx[i]
3738 = find_equiv_reg (reload_in[i], insn, reload_reg_class[i], -1,
3739 static_reload_reg_p, 0, reload_inmode[i]);
3740 /* Prevent generation of insn to load the value
3741 because the one we found already has the value. */
3742 if (reload_reg_rtx[i])
3743 reload_in[i] = reload_reg_rtx[i];
3745 #endif
3747 /* Perhaps an output reload can be combined with another
3748 to reduce needs by one. */
3749 if (!goal_earlyclobber)
3750 combine_reloads ();
3752 /* If we have a pair of reloads for parts of an address, they are reloading
3753 the same object, the operands themselves were not reloaded, and they
3754 are for two operands that are supposed to match, merge the reloads and
3755 change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS. */
3757 for (i = 0; i < n_reloads; i++)
3759 int k;
3761 for (j = i + 1; j < n_reloads; j++)
3762 if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3763 || reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3764 || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3765 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3766 && (reload_when_needed[j] == RELOAD_FOR_INPUT_ADDRESS
3767 || reload_when_needed[j] == RELOAD_FOR_OUTPUT_ADDRESS
3768 || reload_when_needed[j] == RELOAD_FOR_INPADDR_ADDRESS
3769 || reload_when_needed[j] == RELOAD_FOR_OUTADDR_ADDRESS)
3770 && rtx_equal_p (reload_in[i], reload_in[j])
3771 && (operand_reloadnum[reload_opnum[i]] < 0
3772 || reload_optional[operand_reloadnum[reload_opnum[i]]])
3773 && (operand_reloadnum[reload_opnum[j]] < 0
3774 || reload_optional[operand_reloadnum[reload_opnum[j]]])
3775 && (goal_alternative_matches[reload_opnum[i]] == reload_opnum[j]
3776 || (goal_alternative_matches[reload_opnum[j]]
3777 == reload_opnum[i])))
3779 for (k = 0; k < n_replacements; k++)
3780 if (replacements[k].what == j)
3781 replacements[k].what = i;
3783 if (reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3784 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3785 reload_when_needed[i] = RELOAD_FOR_OPADDR_ADDR;
3786 else
3787 reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
3788 reload_in[j] = 0;
3792 /* Scan all the reloads and update their type.
3793 If a reload is for the address of an operand and we didn't reload
3794 that operand, change the type. Similarly, change the operand number
3795 of a reload when two operands match. If a reload is optional, treat it
3796 as though the operand isn't reloaded.
3798 ??? This latter case is somewhat odd because if we do the optional
3799 reload, it means the object is hanging around. Thus we need only
3800 do the address reload if the optional reload was NOT done.
3802 Change secondary reloads to be the address type of their operand, not
3803 the normal type.
3805 If an operand's reload is now RELOAD_OTHER, change any
3806 RELOAD_FOR_INPUT_ADDRESS reloads of that operand to
3807 RELOAD_FOR_OTHER_ADDRESS. */
3809 for (i = 0; i < n_reloads; i++)
3811 if (reload_secondary_p[i]
3812 && reload_when_needed[i] == operand_type[reload_opnum[i]])
3813 reload_when_needed[i] = address_type[reload_opnum[i]];
3815 if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3816 || reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3817 || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3818 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3819 && (operand_reloadnum[reload_opnum[i]] < 0
3820 || reload_optional[operand_reloadnum[reload_opnum[i]]]))
3822 /* If we have a secondary reload to go along with this reload,
3823 change its type to RELOAD_FOR_OPADDR_ADDR. */
3825 if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3826 || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS)
3827 && reload_secondary_in_reload[i] != -1)
3829 int secondary_in_reload = reload_secondary_in_reload[i];
3831 reload_when_needed[secondary_in_reload] =
3832 RELOAD_FOR_OPADDR_ADDR;
3834 /* If there's a tertiary reload we have to change it also. */
3835 if (secondary_in_reload > 0
3836 && reload_secondary_in_reload[secondary_in_reload] != -1)
3837 reload_when_needed[reload_secondary_in_reload[secondary_in_reload]]
3838 = RELOAD_FOR_OPADDR_ADDR;
3841 if ((reload_when_needed[i] == RELOAD_FOR_OUTPUT_ADDRESS
3842 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3843 && reload_secondary_out_reload[i] != -1)
3845 int secondary_out_reload = reload_secondary_out_reload[i];
3847 reload_when_needed[secondary_out_reload] =
3848 RELOAD_FOR_OPADDR_ADDR;
3850 /* If there's a tertiary reload we have to change it also. */
3851 if (secondary_out_reload
3852 && reload_secondary_out_reload[secondary_out_reload] != -1)
3853 reload_when_needed[reload_secondary_out_reload[secondary_out_reload]]
3854 = RELOAD_FOR_OPADDR_ADDR;
3856 if (reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS
3857 || reload_when_needed[i] == RELOAD_FOR_OUTADDR_ADDRESS)
3858 reload_when_needed[i] = RELOAD_FOR_OPADDR_ADDR;
3859 else
3860 reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
3863 if ((reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
3864 || reload_when_needed[i] == RELOAD_FOR_INPADDR_ADDRESS)
3865 && operand_reloadnum[reload_opnum[i]] >= 0
3866 && (reload_when_needed[operand_reloadnum[reload_opnum[i]]]
3867 == RELOAD_OTHER))
3868 reload_when_needed[i] = RELOAD_FOR_OTHER_ADDRESS;
3870 if (goal_alternative_matches[reload_opnum[i]] >= 0)
3871 reload_opnum[i] = goal_alternative_matches[reload_opnum[i]];
3874 /* See if we have any reloads that are now allowed to be merged
3875 because we've changed when the reload is needed to
3876 RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS. Only
3877 check for the most common cases. */
3879 for (i = 0; i < n_reloads; i++)
3880 if (reload_in[i] != 0 && reload_out[i] == 0
3881 && (reload_when_needed[i] == RELOAD_FOR_OPERAND_ADDRESS
3882 || reload_when_needed[i] == RELOAD_FOR_OPADDR_ADDR
3883 || reload_when_needed[i] == RELOAD_FOR_OTHER_ADDRESS))
3884 for (j = 0; j < n_reloads; j++)
3885 if (i != j && reload_in[j] != 0 && reload_out[j] == 0
3886 && reload_when_needed[j] == reload_when_needed[i]
3887 && MATCHES (reload_in[i], reload_in[j])
3888 && reload_reg_class[i] == reload_reg_class[j]
3889 && !reload_nocombine[i] && !reload_nocombine[j]
3890 && reload_reg_rtx[i] == reload_reg_rtx[j])
3892 reload_opnum[i] = MIN (reload_opnum[i], reload_opnum[j]);
3893 transfer_replacements (i, j);
3894 reload_in[j] = 0;
3897 #else /* no REGISTER_CONSTRAINTS */
3898 int noperands;
3899 int insn_code_number;
3900 int goal_earlyclobber = 0; /* Always 0, to make combine_reloads happen. */
3901 register int i;
3902 rtx body = PATTERN (insn);
3904 n_reloads = 0;
3905 n_replacements = 0;
3906 n_earlyclobbers = 0;
3907 replace_reloads = replace;
3908 this_insn = insn;
3910 /* Find what kind of insn this is. NOPERANDS gets number of operands.
3911 Store the operand values in RECOG_OPERAND and the locations
3912 of the words in the insn that point to them in RECOG_OPERAND_LOC.
3913 Return if the insn needs no reload processing. */
3915 switch (GET_CODE (body))
3917 case USE:
3918 case CLOBBER:
3919 case ASM_INPUT:
3920 case ADDR_VEC:
3921 case ADDR_DIFF_VEC:
3922 return;
3924 case PARALLEL:
3925 case SET:
3926 noperands = asm_noperands (body);
3927 if (noperands >= 0)
3929 /* This insn is an `asm' with operands.
3930 First, find out how many operands, and allocate space. */
3932 insn_code_number = -1;
3933 /* ??? This is a bug! ???
3934 Give up and delete this insn if it has too many operands. */
3935 if (noperands > MAX_RECOG_OPERANDS)
3936 abort ();
3938 /* Now get the operand values out of the insn. */
3940 decode_asm_operands (body, recog_operand, recog_operand_loc,
3941 NULL_PTR, NULL_PTR);
3942 break;
3945 default:
3946 /* Ordinary insn: recognize it, allocate space for operands and
3947 constraints, and get them out via insn_extract. */
3949 insn_code_number = recog_memoized (insn);
3950 noperands = insn_n_operands[insn_code_number];
3951 insn_extract (insn);
3954 if (noperands == 0)
3955 return;
3957 for (i = 0; i < noperands; i++)
3959 register RTX_CODE code = GET_CODE (recog_operand[i]);
3960 int is_set_dest = GET_CODE (body) == SET && (i == 0);
3962 if (insn_code_number >= 0)
3963 if (insn_operand_address_p[insn_code_number][i])
3964 find_reloads_address (VOIDmode, NULL_PTR,
3965 recog_operand[i], recog_operand_loc[i],
3966 i, RELOAD_FOR_INPUT, ind_levels, insn);
3968 /* In these cases, we can't tell if the operand is an input
3969 or an output, so be conservative. In practice it won't be
3970 problem. */
3972 if (code == MEM)
3973 find_reloads_address (GET_MODE (recog_operand[i]),
3974 recog_operand_loc[i],
3975 XEXP (recog_operand[i], 0),
3976 &XEXP (recog_operand[i], 0),
3977 i, RELOAD_OTHER, ind_levels, insn);
3978 if (code == SUBREG)
3979 recog_operand[i] = *recog_operand_loc[i]
3980 = find_reloads_toplev (recog_operand[i], i, RELOAD_OTHER,
3981 ind_levels, is_set_dest);
3982 if (code == REG)
3984 register int regno = REGNO (recog_operand[i]);
3985 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
3986 recog_operand[i] = *recog_operand_loc[i]
3987 = reg_equiv_constant[regno];
3988 #if 0 /* This might screw code in reload1.c to delete prior output-reload
3989 that feeds this insn. */
3990 if (reg_equiv_mem[regno] != 0)
3991 recog_operand[i] = *recog_operand_loc[i]
3992 = reg_equiv_mem[regno];
3993 #endif
3997 /* Perhaps an output reload can be combined with another
3998 to reduce needs by one. */
3999 if (!goal_earlyclobber)
4000 combine_reloads ();
4001 #endif /* no REGISTER_CONSTRAINTS */
4004 /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
4005 accepts a memory operand with constant address. */
4007 static int
4008 alternative_allows_memconst (constraint, altnum)
4009 char *constraint;
4010 int altnum;
4012 register int c;
4013 /* Skip alternatives before the one requested. */
4014 while (altnum > 0)
4016 while (*constraint++ != ',');
4017 altnum--;
4019 /* Scan the requested alternative for 'm' or 'o'.
4020 If one of them is present, this alternative accepts memory constants. */
4021 while ((c = *constraint++) && c != ',' && c != '#')
4022 if (c == 'm' || c == 'o')
4023 return 1;
4024 return 0;
4027 /* Scan X for memory references and scan the addresses for reloading.
4028 Also checks for references to "constant" regs that we want to eliminate
4029 and replaces them with the values they stand for.
4030 We may alter X destructively if it contains a reference to such.
4031 If X is just a constant reg, we return the equivalent value
4032 instead of X.
4034 IND_LEVELS says how many levels of indirect addressing this machine
4035 supports.
4037 OPNUM and TYPE identify the purpose of the reload.
4039 IS_SET_DEST is true if X is the destination of a SET, which is not
4040 appropriate to be replaced by a constant. */
4042 static rtx
4043 find_reloads_toplev (x, opnum, type, ind_levels, is_set_dest)
4044 rtx x;
4045 int opnum;
4046 enum reload_type type;
4047 int ind_levels;
4048 int is_set_dest;
4050 register RTX_CODE code = GET_CODE (x);
4052 register char *fmt = GET_RTX_FORMAT (code);
4053 register int i;
4055 if (code == REG)
4057 /* This code is duplicated for speed in find_reloads. */
4058 register int regno = REGNO (x);
4059 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4060 x = reg_equiv_constant[regno];
4061 #if 0
4062 /* This creates (subreg (mem...)) which would cause an unnecessary
4063 reload of the mem. */
4064 else if (reg_equiv_mem[regno] != 0)
4065 x = reg_equiv_mem[regno];
4066 #endif
4067 else if (reg_equiv_address[regno] != 0)
4069 /* If reg_equiv_address varies, it may be shared, so copy it. */
4070 /* We must rerun eliminate_regs, in case the elimination
4071 offsets have changed. */
4072 rtx addr = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0,
4073 NULL_RTX, 0),
4076 if (rtx_varies_p (addr))
4077 addr = copy_rtx (addr);
4079 x = gen_rtx (MEM, GET_MODE (x), addr);
4080 RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4081 find_reloads_address (GET_MODE (x), NULL_PTR,
4082 XEXP (x, 0),
4083 &XEXP (x, 0), opnum, type, ind_levels, 0);
4085 return x;
4087 if (code == MEM)
4089 rtx tem = x;
4090 find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
4091 opnum, type, ind_levels, 0);
4092 return tem;
4095 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG)
4097 /* Check for SUBREG containing a REG that's equivalent to a constant.
4098 If the constant has a known value, truncate it right now.
4099 Similarly if we are extracting a single-word of a multi-word
4100 constant. If the constant is symbolic, allow it to be substituted
4101 normally. push_reload will strip the subreg later. If the
4102 constant is VOIDmode, abort because we will lose the mode of
4103 the register (this should never happen because one of the cases
4104 above should handle it). */
4106 register int regno = REGNO (SUBREG_REG (x));
4107 rtx tem;
4109 if (subreg_lowpart_p (x)
4110 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4111 && reg_equiv_constant[regno] != 0
4112 && (tem = gen_lowpart_common (GET_MODE (x),
4113 reg_equiv_constant[regno])) != 0)
4114 return tem;
4116 if (GET_MODE_BITSIZE (GET_MODE (x)) == BITS_PER_WORD
4117 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4118 && reg_equiv_constant[regno] != 0
4119 && (tem = operand_subword (reg_equiv_constant[regno],
4120 SUBREG_WORD (x), 0,
4121 GET_MODE (SUBREG_REG (x)))) != 0)
4122 return tem;
4124 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4125 && reg_equiv_constant[regno] != 0
4126 && GET_MODE (reg_equiv_constant[regno]) == VOIDmode)
4127 abort ();
4129 /* If the subreg contains a reg that will be converted to a mem,
4130 convert the subreg to a narrower memref now.
4131 Otherwise, we would get (subreg (mem ...) ...),
4132 which would force reload of the mem.
4134 We also need to do this if there is an equivalent MEM that is
4135 not offsettable. In that case, alter_subreg would produce an
4136 invalid address on big-endian machines.
4138 For machines that extend byte loads, we must not reload using
4139 a wider mode if we have a paradoxical SUBREG. find_reloads will
4140 force a reload in that case. So we should not do anything here. */
4142 else if (regno >= FIRST_PSEUDO_REGISTER
4143 #ifdef LOAD_EXTEND_OP
4144 && (GET_MODE_SIZE (GET_MODE (x))
4145 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
4146 #endif
4147 && (reg_equiv_address[regno] != 0
4148 || (reg_equiv_mem[regno] != 0
4149 && (! strict_memory_address_p (GET_MODE (x),
4150 XEXP (reg_equiv_mem[regno], 0))
4151 || ! offsettable_memref_p (reg_equiv_mem[regno])))))
4153 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
4154 /* We must rerun eliminate_regs, in case the elimination
4155 offsets have changed. */
4156 rtx addr = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0,
4157 NULL_RTX, 0),
4159 if (BYTES_BIG_ENDIAN)
4161 int size;
4162 size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
4163 offset += MIN (size, UNITS_PER_WORD);
4164 size = GET_MODE_SIZE (GET_MODE (x));
4165 offset -= MIN (size, UNITS_PER_WORD);
4167 addr = plus_constant (addr, offset);
4168 x = gen_rtx (MEM, GET_MODE (x), addr);
4169 RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4170 find_reloads_address (GET_MODE (x), NULL_PTR,
4171 XEXP (x, 0),
4172 &XEXP (x, 0), opnum, type, ind_levels, 0);
4177 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4179 if (fmt[i] == 'e')
4180 XEXP (x, i) = find_reloads_toplev (XEXP (x, i), opnum, type,
4181 ind_levels, is_set_dest);
4183 return x;
4186 /* Return a mem ref for the memory equivalent of reg REGNO.
4187 This mem ref is not shared with anything. */
4189 static rtx
4190 make_memloc (ad, regno)
4191 rtx ad;
4192 int regno;
4194 register int i;
4195 /* We must rerun eliminate_regs, in case the elimination
4196 offsets have changed. */
4197 rtx tem = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0, NULL_RTX, 0),
4200 #if 0 /* We cannot safely reuse a memloc made here;
4201 if the pseudo appears twice, and its mem needs a reload,
4202 it gets two separate reloads assigned, but it only
4203 gets substituted with the second of them;
4204 then it can get used before that reload reg gets loaded up. */
4205 for (i = 0; i < n_memlocs; i++)
4206 if (rtx_equal_p (tem, XEXP (memlocs[i], 0)))
4207 return memlocs[i];
4208 #endif
4210 /* If TEM might contain a pseudo, we must copy it to avoid
4211 modifying it when we do the substitution for the reload. */
4212 if (rtx_varies_p (tem))
4213 tem = copy_rtx (tem);
4215 tem = gen_rtx (MEM, GET_MODE (ad), tem);
4216 RTX_UNCHANGING_P (tem) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4217 memlocs[n_memlocs++] = tem;
4218 return tem;
4221 /* Record all reloads needed for handling memory address AD
4222 which appears in *LOC in a memory reference to mode MODE
4223 which itself is found in location *MEMREFLOC.
4224 Note that we take shortcuts assuming that no multi-reg machine mode
4225 occurs as part of an address.
4227 OPNUM and TYPE specify the purpose of this reload.
4229 IND_LEVELS says how many levels of indirect addressing this machine
4230 supports.
4232 INSN, if nonzero, is the insn in which we do the reload. It is used
4233 to determine if we may generate output reloads.
4235 Value is nonzero if this address is reloaded or replaced as a whole.
4236 This is interesting to the caller if the address is an autoincrement.
4238 Note that there is no verification that the address will be valid after
4239 this routine does its work. Instead, we rely on the fact that the address
4240 was valid when reload started. So we need only undo things that reload
4241 could have broken. These are wrong register types, pseudos not allocated
4242 to a hard register, and frame pointer elimination. */
4244 static int
4245 find_reloads_address (mode, memrefloc, ad, loc, opnum, type, ind_levels, insn)
4246 enum machine_mode mode;
4247 rtx *memrefloc;
4248 rtx ad;
4249 rtx *loc;
4250 int opnum;
4251 enum reload_type type;
4252 int ind_levels;
4253 rtx insn;
4255 register int regno;
4256 rtx tem;
4258 /* If the address is a register, see if it is a legitimate address and
4259 reload if not. We first handle the cases where we need not reload
4260 or where we must reload in a non-standard way. */
4262 if (GET_CODE (ad) == REG)
4264 regno = REGNO (ad);
4266 if (reg_equiv_constant[regno] != 0
4267 && strict_memory_address_p (mode, reg_equiv_constant[regno]))
4269 *loc = ad = reg_equiv_constant[regno];
4270 return 1;
4273 else if (reg_equiv_address[regno] != 0)
4275 tem = make_memloc (ad, regno);
4276 find_reloads_address (GET_MODE (tem), NULL_PTR, XEXP (tem, 0),
4277 &XEXP (tem, 0), opnum, ADDR_TYPE (type),
4278 ind_levels, insn);
4279 push_reload (tem, NULL_RTX, loc, NULL_PTR,
4280 reload_address_base_reg_class,
4281 GET_MODE (ad), VOIDmode, 0, 0,
4282 opnum, type);
4283 return 1;
4286 /* We can avoid a reload if the register's equivalent memory expression
4287 is valid as an indirect memory address.
4288 But not all addresses are valid in a mem used as an indirect address:
4289 only reg or reg+constant. */
4291 else if (reg_equiv_mem[regno] != 0 && ind_levels > 0
4292 && strict_memory_address_p (mode, reg_equiv_mem[regno])
4293 && (GET_CODE (XEXP (reg_equiv_mem[regno], 0)) == REG
4294 || (GET_CODE (XEXP (reg_equiv_mem[regno], 0)) == PLUS
4295 && GET_CODE (XEXP (XEXP (reg_equiv_mem[regno], 0), 0)) == REG
4296 && CONSTANT_P (XEXP (XEXP (reg_equiv_mem[regno], 0), 1)))))
4297 return 0;
4299 /* The only remaining case where we can avoid a reload is if this is a
4300 hard register that is valid as a base register and which is not the
4301 subject of a CLOBBER in this insn. */
4303 else if (regno < FIRST_PSEUDO_REGISTER
4304 && REGNO_MODE_OK_FOR_BASE_P (regno, mode)
4305 && ! regno_clobbered_p (regno, this_insn))
4306 return 0;
4308 /* If we do not have one of the cases above, we must do the reload. */
4309 push_reload (ad, NULL_RTX, loc, NULL_PTR, reload_address_base_reg_class,
4310 GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
4311 return 1;
4314 if (strict_memory_address_p (mode, ad))
4316 /* The address appears valid, so reloads are not needed.
4317 But the address may contain an eliminable register.
4318 This can happen because a machine with indirect addressing
4319 may consider a pseudo register by itself a valid address even when
4320 it has failed to get a hard reg.
4321 So do a tree-walk to find and eliminate all such regs. */
4323 /* But first quickly dispose of a common case. */
4324 if (GET_CODE (ad) == PLUS
4325 && GET_CODE (XEXP (ad, 1)) == CONST_INT
4326 && GET_CODE (XEXP (ad, 0)) == REG
4327 && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
4328 return 0;
4330 subst_reg_equivs_changed = 0;
4331 *loc = subst_reg_equivs (ad);
4333 if (! subst_reg_equivs_changed)
4334 return 0;
4336 /* Check result for validity after substitution. */
4337 if (strict_memory_address_p (mode, ad))
4338 return 0;
4341 /* The address is not valid. We have to figure out why. One possibility
4342 is that it is itself a MEM. This can happen when the frame pointer is
4343 being eliminated, a pseudo is not allocated to a hard register, and the
4344 offset between the frame and stack pointers is not its initial value.
4345 In that case the pseudo will have been replaced by a MEM referring to
4346 the stack pointer. */
4347 if (GET_CODE (ad) == MEM)
4349 /* First ensure that the address in this MEM is valid. Then, unless
4350 indirect addresses are valid, reload the MEM into a register. */
4351 tem = ad;
4352 find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
4353 opnum, ADDR_TYPE (type),
4354 ind_levels == 0 ? 0 : ind_levels - 1, insn);
4356 /* If tem was changed, then we must create a new memory reference to
4357 hold it and store it back into memrefloc. */
4358 if (tem != ad && memrefloc)
4360 *memrefloc = copy_rtx (*memrefloc);
4361 copy_replacements (tem, XEXP (*memrefloc, 0));
4362 loc = &XEXP (*memrefloc, 0);
4365 /* Check similar cases as for indirect addresses as above except
4366 that we can allow pseudos and a MEM since they should have been
4367 taken care of above. */
4369 if (ind_levels == 0
4370 || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
4371 || GET_CODE (XEXP (tem, 0)) == MEM
4372 || ! (GET_CODE (XEXP (tem, 0)) == REG
4373 || (GET_CODE (XEXP (tem, 0)) == PLUS
4374 && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG
4375 && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT)))
4377 /* Must use TEM here, not AD, since it is the one that will
4378 have any subexpressions reloaded, if needed. */
4379 push_reload (tem, NULL_RTX, loc, NULL_PTR,
4380 reload_address_base_reg_class, GET_MODE (tem),
4381 VOIDmode, 0,
4382 0, opnum, type);
4383 return 1;
4385 else
4386 return 0;
4389 /* If we have address of a stack slot but it's not valid because the
4390 displacement is too large, compute the sum in a register.
4391 Handle all base registers here, not just fp/ap/sp, because on some
4392 targets (namely SH) we can also get too large displacements from
4393 big-endian corrections. */
4394 else if (GET_CODE (ad) == PLUS
4395 && GET_CODE (XEXP (ad, 0)) == REG
4396 && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
4397 && REG_MODE_OK_FOR_BASE_P (XEXP (ad, 0), mode)
4398 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4400 /* Unshare the MEM rtx so we can safely alter it. */
4401 if (memrefloc)
4403 *memrefloc = copy_rtx (*memrefloc);
4404 loc = &XEXP (*memrefloc, 0);
4406 if (double_reg_address_ok)
4408 /* Unshare the sum as well. */
4409 *loc = ad = copy_rtx (ad);
4410 /* Reload the displacement into an index reg.
4411 We assume the frame pointer or arg pointer is a base reg. */
4412 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4413 reload_address_index_reg_class,
4414 GET_MODE (ad), opnum, type, ind_levels);
4416 else
4418 /* If the sum of two regs is not necessarily valid,
4419 reload the sum into a base reg.
4420 That will at least work. */
4421 find_reloads_address_part (ad, loc, reload_address_base_reg_class,
4422 Pmode, opnum, type, ind_levels);
4424 return 1;
4427 /* If we have an indexed stack slot, there are three possible reasons why
4428 it might be invalid: The index might need to be reloaded, the address
4429 might have been made by frame pointer elimination and hence have a
4430 constant out of range, or both reasons might apply.
4432 We can easily check for an index needing reload, but even if that is the
4433 case, we might also have an invalid constant. To avoid making the
4434 conservative assumption and requiring two reloads, we see if this address
4435 is valid when not interpreted strictly. If it is, the only problem is
4436 that the index needs a reload and find_reloads_address_1 will take care
4437 of it.
4439 There is still a case when we might generate an extra reload,
4440 however. In certain cases eliminate_regs will return a MEM for a REG
4441 (see the code there for details). In those cases, memory_address_p
4442 applied to our address will return 0 so we will think that our offset
4443 must be too large. But it might indeed be valid and the only problem
4444 is that a MEM is present where a REG should be. This case should be
4445 very rare and there doesn't seem to be any way to avoid it.
4447 If we decide to do something here, it must be that
4448 `double_reg_address_ok' is true and that this address rtl was made by
4449 eliminate_regs. We generate a reload of the fp/sp/ap + constant and
4450 rework the sum so that the reload register will be added to the index.
4451 This is safe because we know the address isn't shared.
4453 We check for fp/ap/sp as both the first and second operand of the
4454 innermost PLUS. */
4456 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4457 && GET_CODE (XEXP (ad, 0)) == PLUS
4458 && (XEXP (XEXP (ad, 0), 0) == frame_pointer_rtx
4459 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
4460 || XEXP (XEXP (ad, 0), 0) == hard_frame_pointer_rtx
4461 #endif
4462 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4463 || XEXP (XEXP (ad, 0), 0) == arg_pointer_rtx
4464 #endif
4465 || XEXP (XEXP (ad, 0), 0) == stack_pointer_rtx)
4466 && ! memory_address_p (mode, ad))
4468 *loc = ad = gen_rtx (PLUS, GET_MODE (ad),
4469 plus_constant (XEXP (XEXP (ad, 0), 0),
4470 INTVAL (XEXP (ad, 1))),
4471 XEXP (XEXP (ad, 0), 1));
4472 find_reloads_address_part (XEXP (ad, 0), &XEXP (ad, 0),
4473 reload_address_base_reg_class,
4474 GET_MODE (ad), opnum, type, ind_levels);
4475 find_reloads_address_1 (mode, XEXP (ad, 1), 1, &XEXP (ad, 1), opnum,
4476 type, 0, insn);
4478 return 1;
4481 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4482 && GET_CODE (XEXP (ad, 0)) == PLUS
4483 && (XEXP (XEXP (ad, 0), 1) == frame_pointer_rtx
4484 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4485 || XEXP (XEXP (ad, 0), 1) == hard_frame_pointer_rtx
4486 #endif
4487 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4488 || XEXP (XEXP (ad, 0), 1) == arg_pointer_rtx
4489 #endif
4490 || XEXP (XEXP (ad, 0), 1) == stack_pointer_rtx)
4491 && ! memory_address_p (mode, ad))
4493 *loc = ad = gen_rtx (PLUS, GET_MODE (ad),
4494 XEXP (XEXP (ad, 0), 0),
4495 plus_constant (XEXP (XEXP (ad, 0), 1),
4496 INTVAL (XEXP (ad, 1))));
4497 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4498 reload_address_base_reg_class,
4499 GET_MODE (ad), opnum, type, ind_levels);
4500 find_reloads_address_1 (mode, XEXP (ad, 0), 1, &XEXP (ad, 0), opnum,
4501 type, 0, insn);
4503 return 1;
4506 /* See if address becomes valid when an eliminable register
4507 in a sum is replaced. */
4509 tem = ad;
4510 if (GET_CODE (ad) == PLUS)
4511 tem = subst_indexed_address (ad);
4512 if (tem != ad && strict_memory_address_p (mode, tem))
4514 /* Ok, we win that way. Replace any additional eliminable
4515 registers. */
4517 subst_reg_equivs_changed = 0;
4518 tem = subst_reg_equivs (tem);
4520 /* Make sure that didn't make the address invalid again. */
4522 if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
4524 *loc = tem;
4525 return 0;
4529 /* If constants aren't valid addresses, reload the constant address
4530 into a register. */
4531 if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad))
4533 /* If AD is in address in the constant pool, the MEM rtx may be shared.
4534 Unshare it so we can safely alter it. */
4535 if (memrefloc && GET_CODE (ad) == SYMBOL_REF
4536 && CONSTANT_POOL_ADDRESS_P (ad))
4538 *memrefloc = copy_rtx (*memrefloc);
4539 loc = &XEXP (*memrefloc, 0);
4542 find_reloads_address_part (ad, loc, reload_address_base_reg_class,
4543 Pmode, opnum, type,
4544 ind_levels);
4545 return 1;
4548 return find_reloads_address_1 (mode, ad, 0, loc, opnum, type, ind_levels,
4549 insn);
4552 /* Find all pseudo regs appearing in AD
4553 that are eliminable in favor of equivalent values
4554 and do not have hard regs; replace them by their equivalents. */
4556 static rtx
4557 subst_reg_equivs (ad)
4558 rtx ad;
4560 register RTX_CODE code = GET_CODE (ad);
4561 register int i;
4562 register char *fmt;
4564 switch (code)
4566 case HIGH:
4567 case CONST_INT:
4568 case CONST:
4569 case CONST_DOUBLE:
4570 case SYMBOL_REF:
4571 case LABEL_REF:
4572 case PC:
4573 case CC0:
4574 return ad;
4576 case REG:
4578 register int regno = REGNO (ad);
4580 if (reg_equiv_constant[regno] != 0)
4582 subst_reg_equivs_changed = 1;
4583 return reg_equiv_constant[regno];
4586 return ad;
4588 case PLUS:
4589 /* Quickly dispose of a common case. */
4590 if (XEXP (ad, 0) == frame_pointer_rtx
4591 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4592 return ad;
4595 fmt = GET_RTX_FORMAT (code);
4596 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4597 if (fmt[i] == 'e')
4598 XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i));
4599 return ad;
4602 /* Compute the sum of X and Y, making canonicalizations assumed in an
4603 address, namely: sum constant integers, surround the sum of two
4604 constants with a CONST, put the constant as the second operand, and
4605 group the constant on the outermost sum.
4607 This routine assumes both inputs are already in canonical form. */
4610 form_sum (x, y)
4611 rtx x, y;
4613 rtx tem;
4614 enum machine_mode mode = GET_MODE (x);
4616 if (mode == VOIDmode)
4617 mode = GET_MODE (y);
4619 if (mode == VOIDmode)
4620 mode = Pmode;
4622 if (GET_CODE (x) == CONST_INT)
4623 return plus_constant (y, INTVAL (x));
4624 else if (GET_CODE (y) == CONST_INT)
4625 return plus_constant (x, INTVAL (y));
4626 else if (CONSTANT_P (x))
4627 tem = x, x = y, y = tem;
4629 if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
4630 return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
4632 /* Note that if the operands of Y are specified in the opposite
4633 order in the recursive calls below, infinite recursion will occur. */
4634 if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
4635 return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
4637 /* If both constant, encapsulate sum. Otherwise, just form sum. A
4638 constant will have been placed second. */
4639 if (CONSTANT_P (x) && CONSTANT_P (y))
4641 if (GET_CODE (x) == CONST)
4642 x = XEXP (x, 0);
4643 if (GET_CODE (y) == CONST)
4644 y = XEXP (y, 0);
4646 return gen_rtx (CONST, VOIDmode, gen_rtx (PLUS, mode, x, y));
4649 return gen_rtx (PLUS, mode, x, y);
4652 /* If ADDR is a sum containing a pseudo register that should be
4653 replaced with a constant (from reg_equiv_constant),
4654 return the result of doing so, and also apply the associative
4655 law so that the result is more likely to be a valid address.
4656 (But it is not guaranteed to be one.)
4658 Note that at most one register is replaced, even if more are
4659 replaceable. Also, we try to put the result into a canonical form
4660 so it is more likely to be a valid address.
4662 In all other cases, return ADDR. */
4664 static rtx
4665 subst_indexed_address (addr)
4666 rtx addr;
4668 rtx op0 = 0, op1 = 0, op2 = 0;
4669 rtx tem;
4670 int regno;
4672 if (GET_CODE (addr) == PLUS)
4674 /* Try to find a register to replace. */
4675 op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
4676 if (GET_CODE (op0) == REG
4677 && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
4678 && reg_renumber[regno] < 0
4679 && reg_equiv_constant[regno] != 0)
4680 op0 = reg_equiv_constant[regno];
4681 else if (GET_CODE (op1) == REG
4682 && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
4683 && reg_renumber[regno] < 0
4684 && reg_equiv_constant[regno] != 0)
4685 op1 = reg_equiv_constant[regno];
4686 else if (GET_CODE (op0) == PLUS
4687 && (tem = subst_indexed_address (op0)) != op0)
4688 op0 = tem;
4689 else if (GET_CODE (op1) == PLUS
4690 && (tem = subst_indexed_address (op1)) != op1)
4691 op1 = tem;
4692 else
4693 return addr;
4695 /* Pick out up to three things to add. */
4696 if (GET_CODE (op1) == PLUS)
4697 op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
4698 else if (GET_CODE (op0) == PLUS)
4699 op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
4701 /* Compute the sum. */
4702 if (op2 != 0)
4703 op1 = form_sum (op1, op2);
4704 if (op1 != 0)
4705 op0 = form_sum (op0, op1);
4707 return op0;
4709 return addr;
4712 /* Record the pseudo registers we must reload into hard registers in a
4713 subexpression of a would-be memory address, X referring to a value
4714 in mode MODE. (This function is not called if the address we find
4715 is strictly valid.)
4717 CONTEXT = 1 means we are considering regs as index regs,
4718 = 0 means we are considering them as base regs.
4720 OPNUM and TYPE specify the purpose of any reloads made.
4722 IND_LEVELS says how many levels of indirect addressing are
4723 supported at this point in the address.
4725 INSN, if nonzero, is the insn in which we do the reload. It is used
4726 to determine if we may generate output reloads.
4728 We return nonzero if X, as a whole, is reloaded or replaced. */
4730 /* Note that we take shortcuts assuming that no multi-reg machine mode
4731 occurs as part of an address.
4732 Also, this is not fully machine-customizable; it works for machines
4733 such as vaxes and 68000's and 32000's, but other possible machines
4734 could have addressing modes that this does not handle right. */
4736 static int
4737 find_reloads_address_1 (mode, x, context, loc, opnum, type, ind_levels, insn)
4738 enum machine_mode mode;
4739 rtx x;
4740 int context;
4741 rtx *loc;
4742 int opnum;
4743 enum reload_type type;
4744 int ind_levels;
4745 rtx insn;
4747 register RTX_CODE code = GET_CODE (x);
4749 switch (code)
4751 case PLUS:
4753 register rtx orig_op0 = XEXP (x, 0);
4754 register rtx orig_op1 = XEXP (x, 1);
4755 register RTX_CODE code0 = GET_CODE (orig_op0);
4756 register RTX_CODE code1 = GET_CODE (orig_op1);
4757 register rtx op0 = orig_op0;
4758 register rtx op1 = orig_op1;
4760 if (GET_CODE (op0) == SUBREG)
4762 op0 = SUBREG_REG (op0);
4763 code0 = GET_CODE (op0);
4764 if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER)
4765 op0 = gen_rtx (REG, word_mode,
4766 REGNO (op0) + SUBREG_WORD (orig_op0));
4769 if (GET_CODE (op1) == SUBREG)
4771 op1 = SUBREG_REG (op1);
4772 code1 = GET_CODE (op1);
4773 if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER)
4774 op1 = gen_rtx (REG, GET_MODE (op1),
4775 REGNO (op1) + SUBREG_WORD (orig_op1));
4778 if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
4779 || code0 == ZERO_EXTEND || code1 == MEM)
4781 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4782 type, ind_levels, insn);
4783 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4784 type, ind_levels, insn);
4787 else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
4788 || code1 == ZERO_EXTEND || code0 == MEM)
4790 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4791 type, ind_levels, insn);
4792 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4793 type, ind_levels, insn);
4796 else if (code0 == CONST_INT || code0 == CONST
4797 || code0 == SYMBOL_REF || code0 == LABEL_REF)
4798 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4799 type, ind_levels, insn);
4801 else if (code1 == CONST_INT || code1 == CONST
4802 || code1 == SYMBOL_REF || code1 == LABEL_REF)
4803 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4804 type, ind_levels, insn);
4806 else if (code0 == REG && code1 == REG)
4808 if (REG_OK_FOR_INDEX_P (op0)
4809 && REG_MODE_OK_FOR_BASE_P (op1, mode))
4810 return 0;
4811 else if (REG_OK_FOR_INDEX_P (op1)
4812 && REG_MODE_OK_FOR_BASE_P (op0, mode))
4813 return 0;
4814 else if (REG_MODE_OK_FOR_BASE_P (op1, mode))
4815 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4816 type, ind_levels, insn);
4817 else if (REG_MODE_OK_FOR_BASE_P (op0, mode))
4818 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4819 type, ind_levels, insn);
4820 else if (REG_OK_FOR_INDEX_P (op1))
4821 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4822 type, ind_levels, insn);
4823 else if (REG_OK_FOR_INDEX_P (op0))
4824 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4825 type, ind_levels, insn);
4826 else
4828 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4829 type, ind_levels, insn);
4830 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4831 type, ind_levels, insn);
4835 else if (code0 == REG)
4837 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
4838 type, ind_levels, insn);
4839 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
4840 type, ind_levels, insn);
4843 else if (code1 == REG)
4845 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
4846 type, ind_levels, insn);
4847 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
4848 type, ind_levels, insn);
4852 return 0;
4854 case POST_INC:
4855 case POST_DEC:
4856 case PRE_INC:
4857 case PRE_DEC:
4858 if (GET_CODE (XEXP (x, 0)) == REG)
4860 register int regno = REGNO (XEXP (x, 0));
4861 int value = 0;
4862 rtx x_orig = x;
4864 /* A register that is incremented cannot be constant! */
4865 if (regno >= FIRST_PSEUDO_REGISTER
4866 && reg_equiv_constant[regno] != 0)
4867 abort ();
4869 /* Handle a register that is equivalent to a memory location
4870 which cannot be addressed directly. */
4871 if (reg_equiv_address[regno] != 0)
4873 rtx tem = make_memloc (XEXP (x, 0), regno);
4874 /* First reload the memory location's address.
4875 We can't use ADDR_TYPE (type) here, because we need to
4876 write back the value after reading it, hence we actually
4877 need two registers. */
4878 find_reloads_address (GET_MODE (tem), 0, XEXP (tem, 0),
4879 &XEXP (tem, 0), opnum, type,
4880 ind_levels, insn);
4881 /* Put this inside a new increment-expression. */
4882 x = gen_rtx (GET_CODE (x), GET_MODE (x), tem);
4883 /* Proceed to reload that, as if it contained a register. */
4886 /* If we have a hard register that is ok as an index,
4887 don't make a reload. If an autoincrement of a nice register
4888 isn't "valid", it must be that no autoincrement is "valid".
4889 If that is true and something made an autoincrement anyway,
4890 this must be a special context where one is allowed.
4891 (For example, a "push" instruction.)
4892 We can't improve this address, so leave it alone. */
4894 /* Otherwise, reload the autoincrement into a suitable hard reg
4895 and record how much to increment by. */
4897 if (reg_renumber[regno] >= 0)
4898 regno = reg_renumber[regno];
4899 if ((regno >= FIRST_PSEUDO_REGISTER
4900 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
4901 : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
4903 register rtx link;
4904 int reloadnum;
4906 /* If we can output the register afterwards, do so, this
4907 saves the extra update.
4908 We can do so if we have an INSN - i.e. no JUMP_INSN nor
4909 CALL_INSN - and it does not set CC0.
4910 But don't do this if we cannot directly address the
4911 memory location, since this will make it harder to
4912 reuse address reloads, and increses register pressure.
4913 Also don't do this if we can probably update x directly. */
4914 rtx equiv = reg_equiv_mem[regno];
4915 int icode = (int) add_optab->handlers[(int) Pmode].insn_code;
4916 if (insn && GET_CODE (insn) == INSN && equiv
4917 #ifdef HAVE_cc0
4918 && ! sets_cc0_p (PATTERN (insn))
4919 #endif
4920 && ! (icode != CODE_FOR_nothing
4921 && (*insn_operand_predicate[icode][0]) (equiv, Pmode)
4922 && (*insn_operand_predicate[icode][1]) (equiv, Pmode)))
4924 loc = &XEXP (x, 0);
4925 x = XEXP (x, 0);
4926 reloadnum
4927 = push_reload (x, x, loc, loc,
4928 (context
4929 ? reload_address_index_reg_class
4930 : reload_address_base_reg_class),
4931 GET_MODE (x), GET_MODE (x), VOIDmode, 0,
4932 opnum, RELOAD_OTHER);
4934 else
4936 reloadnum
4937 = push_reload (x, NULL_RTX, loc, NULL_PTR,
4938 (context
4939 ? reload_address_index_reg_class
4940 : reload_address_base_reg_class),
4941 GET_MODE (x), GET_MODE (x), VOIDmode, 0,
4942 opnum, type);
4943 reload_inc[reloadnum]
4944 = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
4946 value = 1;
4949 #ifdef AUTO_INC_DEC
4950 /* Update the REG_INC notes. */
4952 for (link = REG_NOTES (this_insn);
4953 link; link = XEXP (link, 1))
4954 if (REG_NOTE_KIND (link) == REG_INC
4955 && REGNO (XEXP (link, 0)) == REGNO (XEXP (x_orig, 0)))
4956 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
4957 #endif
4959 return value;
4962 else if (GET_CODE (XEXP (x, 0)) == MEM)
4964 /* This is probably the result of a substitution, by eliminate_regs,
4965 of an equivalent address for a pseudo that was not allocated to a
4966 hard register. Verify that the specified address is valid and
4967 reload it into a register. */
4968 rtx tem = XEXP (x, 0);
4969 register rtx link;
4970 int reloadnum;
4972 /* Since we know we are going to reload this item, don't decrement
4973 for the indirection level.
4975 Note that this is actually conservative: it would be slightly
4976 more efficient to use the value of SPILL_INDIRECT_LEVELS from
4977 reload1.c here. */
4978 /* We can't use ADDR_TYPE (type) here, because we need to
4979 write back the value after reading it, hence we actually
4980 need two registers. */
4981 find_reloads_address (GET_MODE (x), &XEXP (x, 0),
4982 XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0),
4983 opnum, type, ind_levels, insn);
4985 reloadnum = push_reload (x, NULL_RTX, loc, NULL_PTR,
4986 (context
4987 ? reload_address_index_reg_class
4988 : reload_address_base_reg_class),
4989 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
4990 reload_inc[reloadnum]
4991 = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
4993 link = FIND_REG_INC_NOTE (this_insn, tem);
4994 if (link != 0)
4995 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
4997 return 1;
4999 return 0;
5001 case MEM:
5002 /* This is probably the result of a substitution, by eliminate_regs, of
5003 an equivalent address for a pseudo that was not allocated to a hard
5004 register. Verify that the specified address is valid and reload it
5005 into a register.
5007 Since we know we are going to reload this item, don't decrement for
5008 the indirection level.
5010 Note that this is actually conservative: it would be slightly more
5011 efficient to use the value of SPILL_INDIRECT_LEVELS from
5012 reload1.c here. */
5014 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5015 opnum, ADDR_TYPE (type), ind_levels, insn);
5016 push_reload (*loc, NULL_RTX, loc, NULL_PTR,
5017 (context ? reload_address_index_reg_class
5018 : reload_address_base_reg_class),
5019 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5020 return 1;
5022 case REG:
5024 register int regno = REGNO (x);
5026 if (reg_equiv_constant[regno] != 0)
5028 find_reloads_address_part (reg_equiv_constant[regno], loc,
5029 (context
5030 ? reload_address_index_reg_class
5031 : reload_address_base_reg_class),
5032 GET_MODE (x), opnum, type, ind_levels);
5033 return 1;
5036 #if 0 /* This might screw code in reload1.c to delete prior output-reload
5037 that feeds this insn. */
5038 if (reg_equiv_mem[regno] != 0)
5040 push_reload (reg_equiv_mem[regno], NULL_RTX, loc, NULL_PTR,
5041 (context
5042 ? reload_address_index_reg_class
5043 : reload_address_base_reg_class),
5044 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5045 return 1;
5047 #endif
5049 if (reg_equiv_address[regno] != 0)
5051 x = make_memloc (x, regno);
5052 find_reloads_address (GET_MODE (x), 0, XEXP (x, 0), &XEXP (x, 0),
5053 opnum, ADDR_TYPE (type), ind_levels, insn);
5056 if (reg_renumber[regno] >= 0)
5057 regno = reg_renumber[regno];
5059 if ((regno >= FIRST_PSEUDO_REGISTER
5060 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
5061 : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
5063 push_reload (x, NULL_RTX, loc, NULL_PTR,
5064 (context
5065 ? reload_address_index_reg_class
5066 : reload_address_base_reg_class),
5067 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5068 return 1;
5071 /* If a register appearing in an address is the subject of a CLOBBER
5072 in this insn, reload it into some other register to be safe.
5073 The CLOBBER is supposed to make the register unavailable
5074 from before this insn to after it. */
5075 if (regno_clobbered_p (regno, this_insn))
5077 push_reload (x, NULL_RTX, loc, NULL_PTR,
5078 (context
5079 ? reload_address_index_reg_class
5080 : reload_address_base_reg_class),
5081 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5082 return 1;
5085 return 0;
5087 case SUBREG:
5088 if (GET_CODE (SUBREG_REG (x)) == REG)
5090 /* If this is a SUBREG of a hard register and the resulting register
5091 is of the wrong class, reload the whole SUBREG. This avoids
5092 needless copies if SUBREG_REG is multi-word. */
5093 if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5095 int regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
5097 if (! (context ? REGNO_OK_FOR_INDEX_P (regno)
5098 : REGNO_MODE_OK_FOR_BASE_P (regno, mode)))
5100 push_reload (x, NULL_RTX, loc, NULL_PTR,
5101 (context
5102 ? reload_address_index_reg_class
5103 : reload_address_base_reg_class),
5104 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5105 return 1;
5108 /* If this is a SUBREG of a pseudo-register, and the pseudo-register
5109 is larger than the class size, then reload the whole SUBREG. */
5110 else
5112 enum reg_class class = (context
5113 ? reload_address_index_reg_class
5114 : reload_address_base_reg_class);
5115 if (CLASS_MAX_NREGS (class, GET_MODE (SUBREG_REG (x)))
5116 > reg_class_size[class])
5118 push_reload (x, NULL_RTX, loc, NULL_PTR, class,
5119 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5120 return 1;
5124 break;
5128 register char *fmt = GET_RTX_FORMAT (code);
5129 register int i;
5131 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5133 if (fmt[i] == 'e')
5134 find_reloads_address_1 (mode, XEXP (x, i), context, &XEXP (x, i),
5135 opnum, type, ind_levels, insn);
5139 return 0;
5142 /* X, which is found at *LOC, is a part of an address that needs to be
5143 reloaded into a register of class CLASS. If X is a constant, or if
5144 X is a PLUS that contains a constant, check that the constant is a
5145 legitimate operand and that we are supposed to be able to load
5146 it into the register.
5148 If not, force the constant into memory and reload the MEM instead.
5150 MODE is the mode to use, in case X is an integer constant.
5152 OPNUM and TYPE describe the purpose of any reloads made.
5154 IND_LEVELS says how many levels of indirect addressing this machine
5155 supports. */
5157 static void
5158 find_reloads_address_part (x, loc, class, mode, opnum, type, ind_levels)
5159 rtx x;
5160 rtx *loc;
5161 enum reg_class class;
5162 enum machine_mode mode;
5163 int opnum;
5164 enum reload_type type;
5165 int ind_levels;
5167 if (CONSTANT_P (x)
5168 && (! LEGITIMATE_CONSTANT_P (x)
5169 || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
5171 rtx tem = x = force_const_mem (mode, x);
5172 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5173 opnum, type, ind_levels, 0);
5176 else if (GET_CODE (x) == PLUS
5177 && CONSTANT_P (XEXP (x, 1))
5178 && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
5179 || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
5181 rtx tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
5183 x = gen_rtx (PLUS, GET_MODE (x), XEXP (x, 0), tem);
5184 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5185 opnum, type, ind_levels, 0);
5188 push_reload (x, NULL_RTX, loc, NULL_PTR, class,
5189 mode, VOIDmode, 0, 0, opnum, type);
5192 /* Substitute into the current INSN the registers into which we have reloaded
5193 the things that need reloading. The array `replacements'
5194 says contains the locations of all pointers that must be changed
5195 and says what to replace them with.
5197 Return the rtx that X translates into; usually X, but modified. */
5199 void
5200 subst_reloads ()
5202 register int i;
5204 for (i = 0; i < n_replacements; i++)
5206 register struct replacement *r = &replacements[i];
5207 register rtx reloadreg = reload_reg_rtx[r->what];
5208 if (reloadreg)
5210 /* Encapsulate RELOADREG so its machine mode matches what
5211 used to be there. Note that gen_lowpart_common will
5212 do the wrong thing if RELOADREG is multi-word. RELOADREG
5213 will always be a REG here. */
5214 if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
5215 reloadreg = gen_rtx (REG, r->mode, REGNO (reloadreg));
5217 /* If we are putting this into a SUBREG and RELOADREG is a
5218 SUBREG, we would be making nested SUBREGs, so we have to fix
5219 this up. Note that r->where == &SUBREG_REG (*r->subreg_loc). */
5221 if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG)
5223 if (GET_MODE (*r->subreg_loc)
5224 == GET_MODE (SUBREG_REG (reloadreg)))
5225 *r->subreg_loc = SUBREG_REG (reloadreg);
5226 else
5228 *r->where = SUBREG_REG (reloadreg);
5229 SUBREG_WORD (*r->subreg_loc) += SUBREG_WORD (reloadreg);
5232 else
5233 *r->where = reloadreg;
5235 /* If reload got no reg and isn't optional, something's wrong. */
5236 else if (! reload_optional[r->what])
5237 abort ();
5241 /* Make a copy of any replacements being done into X and move those copies
5242 to locations in Y, a copy of X. We only look at the highest level of
5243 the RTL. */
5245 void
5246 copy_replacements (x, y)
5247 rtx x;
5248 rtx y;
5250 int i, j;
5251 enum rtx_code code = GET_CODE (x);
5252 char *fmt = GET_RTX_FORMAT (code);
5253 struct replacement *r;
5255 /* We can't support X being a SUBREG because we might then need to know its
5256 location if something inside it was replaced. */
5257 if (code == SUBREG)
5258 abort ();
5260 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5261 if (fmt[i] == 'e')
5262 for (j = 0; j < n_replacements; j++)
5264 if (replacements[j].subreg_loc == &XEXP (x, i))
5266 r = &replacements[n_replacements++];
5267 r->where = replacements[j].where;
5268 r->subreg_loc = &XEXP (y, i);
5269 r->what = replacements[j].what;
5270 r->mode = replacements[j].mode;
5272 else if (replacements[j].where == &XEXP (x, i))
5274 r = &replacements[n_replacements++];
5275 r->where = &XEXP (y, i);
5276 r->subreg_loc = 0;
5277 r->what = replacements[j].what;
5278 r->mode = replacements[j].mode;
5283 /* If LOC was scheduled to be replaced by something, return the replacement.
5284 Otherwise, return *LOC. */
5287 find_replacement (loc)
5288 rtx *loc;
5290 struct replacement *r;
5292 for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
5294 rtx reloadreg = reload_reg_rtx[r->what];
5296 if (reloadreg && r->where == loc)
5298 if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
5299 reloadreg = gen_rtx (REG, r->mode, REGNO (reloadreg));
5301 return reloadreg;
5303 else if (reloadreg && r->subreg_loc == loc)
5305 /* RELOADREG must be either a REG or a SUBREG.
5307 ??? Is it actually still ever a SUBREG? If so, why? */
5309 if (GET_CODE (reloadreg) == REG)
5310 return gen_rtx (REG, GET_MODE (*loc),
5311 REGNO (reloadreg) + SUBREG_WORD (*loc));
5312 else if (GET_MODE (reloadreg) == GET_MODE (*loc))
5313 return reloadreg;
5314 else
5315 return gen_rtx (SUBREG, GET_MODE (*loc), SUBREG_REG (reloadreg),
5316 SUBREG_WORD (reloadreg) + SUBREG_WORD (*loc));
5320 return *loc;
5323 /* Return nonzero if register in range [REGNO, ENDREGNO)
5324 appears either explicitly or implicitly in X
5325 other than being stored into (except for earlyclobber operands).
5327 References contained within the substructure at LOC do not count.
5328 LOC may be zero, meaning don't ignore anything.
5330 This is similar to refers_to_regno_p in rtlanal.c except that we
5331 look at equivalences for pseudos that didn't get hard registers. */
5334 refers_to_regno_for_reload_p (regno, endregno, x, loc)
5335 int regno, endregno;
5336 rtx x;
5337 rtx *loc;
5339 register int i;
5340 register RTX_CODE code;
5341 register char *fmt;
5343 if (x == 0)
5344 return 0;
5346 repeat:
5347 code = GET_CODE (x);
5349 switch (code)
5351 case REG:
5352 i = REGNO (x);
5354 /* If this is a pseudo, a hard register must not have been allocated.
5355 X must therefore either be a constant or be in memory. */
5356 if (i >= FIRST_PSEUDO_REGISTER)
5358 if (reg_equiv_memory_loc[i])
5359 return refers_to_regno_for_reload_p (regno, endregno,
5360 reg_equiv_memory_loc[i],
5361 NULL_PTR);
5363 if (reg_equiv_constant[i])
5364 return 0;
5366 abort ();
5369 return (endregno > i
5370 && regno < i + (i < FIRST_PSEUDO_REGISTER
5371 ? HARD_REGNO_NREGS (i, GET_MODE (x))
5372 : 1));
5374 case SUBREG:
5375 /* If this is a SUBREG of a hard reg, we can see exactly which
5376 registers are being modified. Otherwise, handle normally. */
5377 if (GET_CODE (SUBREG_REG (x)) == REG
5378 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5380 int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
5381 int inner_endregno
5382 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
5383 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
5385 return endregno > inner_regno && regno < inner_endregno;
5387 break;
5389 case CLOBBER:
5390 case SET:
5391 if (&SET_DEST (x) != loc
5392 /* Note setting a SUBREG counts as referring to the REG it is in for
5393 a pseudo but not for hard registers since we can
5394 treat each word individually. */
5395 && ((GET_CODE (SET_DEST (x)) == SUBREG
5396 && loc != &SUBREG_REG (SET_DEST (x))
5397 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
5398 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
5399 && refers_to_regno_for_reload_p (regno, endregno,
5400 SUBREG_REG (SET_DEST (x)),
5401 loc))
5402 /* If the output is an earlyclobber operand, this is
5403 a conflict. */
5404 || ((GET_CODE (SET_DEST (x)) != REG
5405 || earlyclobber_operand_p (SET_DEST (x)))
5406 && refers_to_regno_for_reload_p (regno, endregno,
5407 SET_DEST (x), loc))))
5408 return 1;
5410 if (code == CLOBBER || loc == &SET_SRC (x))
5411 return 0;
5412 x = SET_SRC (x);
5413 goto repeat;
5416 /* X does not match, so try its subexpressions. */
5418 fmt = GET_RTX_FORMAT (code);
5419 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5421 if (fmt[i] == 'e' && loc != &XEXP (x, i))
5423 if (i == 0)
5425 x = XEXP (x, 0);
5426 goto repeat;
5428 else
5429 if (refers_to_regno_for_reload_p (regno, endregno,
5430 XEXP (x, i), loc))
5431 return 1;
5433 else if (fmt[i] == 'E')
5435 register int j;
5436 for (j = XVECLEN (x, i) - 1; j >=0; j--)
5437 if (loc != &XVECEXP (x, i, j)
5438 && refers_to_regno_for_reload_p (regno, endregno,
5439 XVECEXP (x, i, j), loc))
5440 return 1;
5443 return 0;
5446 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
5447 we check if any register number in X conflicts with the relevant register
5448 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
5449 contains a MEM (we don't bother checking for memory addresses that can't
5450 conflict because we expect this to be a rare case.
5452 This function is similar to reg_overlap_mention_p in rtlanal.c except
5453 that we look at equivalences for pseudos that didn't get hard registers. */
5456 reg_overlap_mentioned_for_reload_p (x, in)
5457 rtx x, in;
5459 int regno, endregno;
5461 if (GET_CODE (x) == SUBREG)
5463 regno = REGNO (SUBREG_REG (x));
5464 if (regno < FIRST_PSEUDO_REGISTER)
5465 regno += SUBREG_WORD (x);
5467 else if (GET_CODE (x) == REG)
5469 regno = REGNO (x);
5471 /* If this is a pseudo, it must not have been assigned a hard register.
5472 Therefore, it must either be in memory or be a constant. */
5474 if (regno >= FIRST_PSEUDO_REGISTER)
5476 if (reg_equiv_memory_loc[regno])
5477 return refers_to_mem_for_reload_p (in);
5478 else if (reg_equiv_constant[regno])
5479 return 0;
5480 abort ();
5483 else if (CONSTANT_P (x))
5484 return 0;
5485 else if (GET_CODE (x) == MEM)
5486 return refers_to_mem_for_reload_p (in);
5487 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
5488 || GET_CODE (x) == CC0)
5489 return reg_mentioned_p (x, in);
5490 else
5491 abort ();
5493 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
5494 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
5496 return refers_to_regno_for_reload_p (regno, endregno, in, NULL_PTR);
5499 /* Return nonzero if anything in X contains a MEM. Look also for pseudo
5500 registers. */
5503 refers_to_mem_for_reload_p (x)
5504 rtx x;
5506 char *fmt;
5507 int i;
5509 if (GET_CODE (x) == MEM)
5510 return 1;
5512 if (GET_CODE (x) == REG)
5513 return (REGNO (x) >= FIRST_PSEUDO_REGISTER
5514 && reg_equiv_memory_loc[REGNO (x)]);
5516 fmt = GET_RTX_FORMAT (GET_CODE (x));
5517 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
5518 if (fmt[i] == 'e'
5519 && (GET_CODE (XEXP (x, i)) == MEM
5520 || refers_to_mem_for_reload_p (XEXP (x, i))))
5521 return 1;
5523 return 0;
5526 /* Check the insns before INSN to see if there is a suitable register
5527 containing the same value as GOAL.
5528 If OTHER is -1, look for a register in class CLASS.
5529 Otherwise, just see if register number OTHER shares GOAL's value.
5531 Return an rtx for the register found, or zero if none is found.
5533 If RELOAD_REG_P is (short *)1,
5534 we reject any hard reg that appears in reload_reg_rtx
5535 because such a hard reg is also needed coming into this insn.
5537 If RELOAD_REG_P is any other nonzero value,
5538 it is a vector indexed by hard reg number
5539 and we reject any hard reg whose element in the vector is nonnegative
5540 as well as any that appears in reload_reg_rtx.
5542 If GOAL is zero, then GOALREG is a register number; we look
5543 for an equivalent for that register.
5545 MODE is the machine mode of the value we want an equivalence for.
5546 If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
5548 This function is used by jump.c as well as in the reload pass.
5550 If GOAL is the sum of the stack pointer and a constant, we treat it
5551 as if it were a constant except that sp is required to be unchanging. */
5554 find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode)
5555 register rtx goal;
5556 rtx insn;
5557 enum reg_class class;
5558 register int other;
5559 short *reload_reg_p;
5560 int goalreg;
5561 enum machine_mode mode;
5563 register rtx p = insn;
5564 rtx goaltry, valtry, value, where;
5565 register rtx pat;
5566 register int regno = -1;
5567 int valueno;
5568 int goal_mem = 0;
5569 int goal_const = 0;
5570 int goal_mem_addr_varies = 0;
5571 int need_stable_sp = 0;
5572 int nregs;
5573 int valuenregs;
5575 if (goal == 0)
5576 regno = goalreg;
5577 else if (GET_CODE (goal) == REG)
5578 regno = REGNO (goal);
5579 else if (GET_CODE (goal) == MEM)
5581 enum rtx_code code = GET_CODE (XEXP (goal, 0));
5582 if (MEM_VOLATILE_P (goal))
5583 return 0;
5584 if (flag_float_store && GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT)
5585 return 0;
5586 /* An address with side effects must be reexecuted. */
5587 switch (code)
5589 case POST_INC:
5590 case PRE_INC:
5591 case POST_DEC:
5592 case PRE_DEC:
5593 return 0;
5595 goal_mem = 1;
5597 else if (CONSTANT_P (goal))
5598 goal_const = 1;
5599 else if (GET_CODE (goal) == PLUS
5600 && XEXP (goal, 0) == stack_pointer_rtx
5601 && CONSTANT_P (XEXP (goal, 1)))
5602 goal_const = need_stable_sp = 1;
5603 else
5604 return 0;
5606 /* On some machines, certain regs must always be rejected
5607 because they don't behave the way ordinary registers do. */
5609 #ifdef OVERLAPPING_REGNO_P
5610 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5611 && OVERLAPPING_REGNO_P (regno))
5612 return 0;
5613 #endif
5615 /* Scan insns back from INSN, looking for one that copies
5616 a value into or out of GOAL.
5617 Stop and give up if we reach a label. */
5619 while (1)
5621 p = PREV_INSN (p);
5622 if (p == 0 || GET_CODE (p) == CODE_LABEL)
5623 return 0;
5624 if (GET_CODE (p) == INSN
5625 /* If we don't want spill regs ... */
5626 && (! (reload_reg_p != 0
5627 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
5628 /* ... then ignore insns introduced by reload; they aren't useful
5629 and can cause results in reload_as_needed to be different
5630 from what they were when calculating the need for spills.
5631 If we notice an input-reload insn here, we will reject it below,
5632 but it might hide a usable equivalent. That makes bad code.
5633 It may even abort: perhaps no reg was spilled for this insn
5634 because it was assumed we would find that equivalent. */
5635 || INSN_UID (p) < reload_first_uid))
5637 rtx tem;
5638 pat = single_set (p);
5639 /* First check for something that sets some reg equal to GOAL. */
5640 if (pat != 0
5641 && ((regno >= 0
5642 && true_regnum (SET_SRC (pat)) == regno
5643 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5645 (regno >= 0
5646 && true_regnum (SET_DEST (pat)) == regno
5647 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
5649 (goal_const && rtx_equal_p (SET_SRC (pat), goal)
5650 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5651 || (goal_mem
5652 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
5653 && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
5654 || (goal_mem
5655 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
5656 && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
5657 /* If we are looking for a constant,
5658 and something equivalent to that constant was copied
5659 into a reg, we can use that reg. */
5660 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5661 NULL_RTX))
5662 && rtx_equal_p (XEXP (tem, 0), goal)
5663 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
5664 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5665 NULL_RTX))
5666 && GET_CODE (SET_DEST (pat)) == REG
5667 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
5668 && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
5669 && GET_CODE (goal) == CONST_INT
5670 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 0, 0,
5671 VOIDmode))
5672 && rtx_equal_p (goal, goaltry)
5673 && (valtry = operand_subword (SET_DEST (pat), 0, 0,
5674 VOIDmode))
5675 && (valueno = true_regnum (valtry)) >= 0)
5676 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
5677 NULL_RTX))
5678 && GET_CODE (SET_DEST (pat)) == REG
5679 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
5680 && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
5681 && GET_CODE (goal) == CONST_INT
5682 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0,
5683 VOIDmode))
5684 && rtx_equal_p (goal, goaltry)
5685 && (valtry
5686 = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
5687 && (valueno = true_regnum (valtry)) >= 0)))
5688 if (other >= 0
5689 ? valueno == other
5690 : ((unsigned) valueno < FIRST_PSEUDO_REGISTER
5691 && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
5692 valueno)))
5694 value = valtry;
5695 where = p;
5696 break;
5701 /* We found a previous insn copying GOAL into a suitable other reg VALUE
5702 (or copying VALUE into GOAL, if GOAL is also a register).
5703 Now verify that VALUE is really valid. */
5705 /* VALUENO is the register number of VALUE; a hard register. */
5707 /* Don't try to re-use something that is killed in this insn. We want
5708 to be able to trust REG_UNUSED notes. */
5709 if (find_reg_note (where, REG_UNUSED, value))
5710 return 0;
5712 /* If we propose to get the value from the stack pointer or if GOAL is
5713 a MEM based on the stack pointer, we need a stable SP. */
5714 if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM
5715 || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
5716 goal)))
5717 need_stable_sp = 1;
5719 /* Reject VALUE if the copy-insn moved the wrong sort of datum. */
5720 if (GET_MODE (value) != mode)
5721 return 0;
5723 /* Reject VALUE if it was loaded from GOAL
5724 and is also a register that appears in the address of GOAL. */
5726 if (goal_mem && value == SET_DEST (single_set (where))
5727 && refers_to_regno_for_reload_p (valueno,
5728 (valueno
5729 + HARD_REGNO_NREGS (valueno, mode)),
5730 goal, NULL_PTR))
5731 return 0;
5733 /* Reject registers that overlap GOAL. */
5735 if (!goal_mem && !goal_const
5736 && regno + HARD_REGNO_NREGS (regno, mode) > valueno
5737 && regno < valueno + HARD_REGNO_NREGS (valueno, mode))
5738 return 0;
5740 /* Reject VALUE if it is one of the regs reserved for reloads.
5741 Reload1 knows how to reuse them anyway, and it would get
5742 confused if we allocated one without its knowledge.
5743 (Now that insns introduced by reload are ignored above,
5744 this case shouldn't happen, but I'm not positive.) */
5746 if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1
5747 && reload_reg_p[valueno] >= 0)
5748 return 0;
5750 /* On some machines, certain regs must always be rejected
5751 because they don't behave the way ordinary registers do. */
5753 #ifdef OVERLAPPING_REGNO_P
5754 if (OVERLAPPING_REGNO_P (valueno))
5755 return 0;
5756 #endif
5758 nregs = HARD_REGNO_NREGS (regno, mode);
5759 valuenregs = HARD_REGNO_NREGS (valueno, mode);
5761 /* Reject VALUE if it is a register being used for an input reload
5762 even if it is not one of those reserved. */
5764 if (reload_reg_p != 0)
5766 int i;
5767 for (i = 0; i < n_reloads; i++)
5768 if (reload_reg_rtx[i] != 0 && reload_in[i])
5770 int regno1 = REGNO (reload_reg_rtx[i]);
5771 int nregs1 = HARD_REGNO_NREGS (regno1,
5772 GET_MODE (reload_reg_rtx[i]));
5773 if (regno1 < valueno + valuenregs
5774 && regno1 + nregs1 > valueno)
5775 return 0;
5779 if (goal_mem)
5780 /* We must treat frame pointer as varying here,
5781 since it can vary--in a nonlocal goto as generated by expand_goto. */
5782 goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0));
5784 /* Now verify that the values of GOAL and VALUE remain unaltered
5785 until INSN is reached. */
5787 p = insn;
5788 while (1)
5790 p = PREV_INSN (p);
5791 if (p == where)
5792 return value;
5794 /* Don't trust the conversion past a function call
5795 if either of the two is in a call-clobbered register, or memory. */
5796 if (GET_CODE (p) == CALL_INSN
5797 && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5798 && call_used_regs[regno])
5800 (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
5801 && call_used_regs[valueno])
5803 goal_mem
5804 || need_stable_sp))
5805 return 0;
5807 #ifdef NON_SAVING_SETJMP
5808 if (NON_SAVING_SETJMP && GET_CODE (p) == NOTE
5809 && NOTE_LINE_NUMBER (p) == NOTE_INSN_SETJMP)
5810 return 0;
5811 #endif
5813 #ifdef INSN_CLOBBERS_REGNO_P
5814 if ((valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
5815 && INSN_CLOBBERS_REGNO_P (p, valueno))
5816 || (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5817 && INSN_CLOBBERS_REGNO_P (p, regno)))
5818 return 0;
5819 #endif
5821 if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
5823 /* If this insn P stores in either GOAL or VALUE, return 0.
5824 If GOAL is a memory ref and this insn writes memory, return 0.
5825 If GOAL is a memory ref and its address is not constant,
5826 and this insn P changes a register used in GOAL, return 0. */
5828 pat = PATTERN (p);
5829 if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
5831 register rtx dest = SET_DEST (pat);
5832 while (GET_CODE (dest) == SUBREG
5833 || GET_CODE (dest) == ZERO_EXTRACT
5834 || GET_CODE (dest) == SIGN_EXTRACT
5835 || GET_CODE (dest) == STRICT_LOW_PART)
5836 dest = XEXP (dest, 0);
5837 if (GET_CODE (dest) == REG)
5839 register int xregno = REGNO (dest);
5840 int xnregs;
5841 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5842 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5843 else
5844 xnregs = 1;
5845 if (xregno < regno + nregs && xregno + xnregs > regno)
5846 return 0;
5847 if (xregno < valueno + valuenregs
5848 && xregno + xnregs > valueno)
5849 return 0;
5850 if (goal_mem_addr_varies
5851 && reg_overlap_mentioned_for_reload_p (dest, goal))
5852 return 0;
5854 else if (goal_mem && GET_CODE (dest) == MEM
5855 && ! push_operand (dest, GET_MODE (dest)))
5856 return 0;
5857 else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER
5858 && reg_equiv_memory_loc[regno] != 0)
5859 return 0;
5860 else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
5861 return 0;
5863 else if (GET_CODE (pat) == PARALLEL)
5865 register int i;
5866 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
5868 register rtx v1 = XVECEXP (pat, 0, i);
5869 if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
5871 register rtx dest = SET_DEST (v1);
5872 while (GET_CODE (dest) == SUBREG
5873 || GET_CODE (dest) == ZERO_EXTRACT
5874 || GET_CODE (dest) == SIGN_EXTRACT
5875 || GET_CODE (dest) == STRICT_LOW_PART)
5876 dest = XEXP (dest, 0);
5877 if (GET_CODE (dest) == REG)
5879 register int xregno = REGNO (dest);
5880 int xnregs;
5881 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5882 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5883 else
5884 xnregs = 1;
5885 if (xregno < regno + nregs
5886 && 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,
5893 goal))
5894 return 0;
5896 else if (goal_mem && GET_CODE (dest) == MEM
5897 && ! push_operand (dest, GET_MODE (dest)))
5898 return 0;
5899 else if (need_stable_sp
5900 && push_operand (dest, GET_MODE (dest)))
5901 return 0;
5906 if (GET_CODE (p) == CALL_INSN && CALL_INSN_FUNCTION_USAGE (p))
5908 rtx link;
5910 for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0;
5911 link = XEXP (link, 1))
5913 pat = XEXP (link, 0);
5914 if (GET_CODE (pat) == CLOBBER)
5916 register rtx dest = SET_DEST (pat);
5917 while (GET_CODE (dest) == SUBREG
5918 || GET_CODE (dest) == ZERO_EXTRACT
5919 || GET_CODE (dest) == SIGN_EXTRACT
5920 || GET_CODE (dest) == STRICT_LOW_PART)
5921 dest = XEXP (dest, 0);
5922 if (GET_CODE (dest) == REG)
5924 register int xregno = REGNO (dest);
5925 int xnregs;
5926 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5927 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5928 else
5929 xnregs = 1;
5930 if (xregno < regno + nregs
5931 && xregno + xnregs > regno)
5932 return 0;
5933 if (xregno < valueno + valuenregs
5934 && xregno + xnregs > valueno)
5935 return 0;
5936 if (goal_mem_addr_varies
5937 && reg_overlap_mentioned_for_reload_p (dest,
5938 goal))
5939 return 0;
5941 else if (goal_mem && GET_CODE (dest) == MEM
5942 && ! push_operand (dest, GET_MODE (dest)))
5943 return 0;
5944 else if (need_stable_sp
5945 && push_operand (dest, GET_MODE (dest)))
5946 return 0;
5951 #ifdef AUTO_INC_DEC
5952 /* If this insn auto-increments or auto-decrements
5953 either regno or valueno, return 0 now.
5954 If GOAL is a memory ref and its address is not constant,
5955 and this insn P increments a register used in GOAL, return 0. */
5957 register rtx link;
5959 for (link = REG_NOTES (p); link; link = XEXP (link, 1))
5960 if (REG_NOTE_KIND (link) == REG_INC
5961 && GET_CODE (XEXP (link, 0)) == REG)
5963 register int incno = REGNO (XEXP (link, 0));
5964 if (incno < regno + nregs && incno >= regno)
5965 return 0;
5966 if (incno < valueno + valuenregs && incno >= valueno)
5967 return 0;
5968 if (goal_mem_addr_varies
5969 && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
5970 goal))
5971 return 0;
5974 #endif
5979 /* Find a place where INCED appears in an increment or decrement operator
5980 within X, and return the amount INCED is incremented or decremented by.
5981 The value is always positive. */
5983 static int
5984 find_inc_amount (x, inced)
5985 rtx x, inced;
5987 register enum rtx_code code = GET_CODE (x);
5988 register char *fmt;
5989 register int i;
5991 if (code == MEM)
5993 register rtx addr = XEXP (x, 0);
5994 if ((GET_CODE (addr) == PRE_DEC
5995 || GET_CODE (addr) == POST_DEC
5996 || GET_CODE (addr) == PRE_INC
5997 || GET_CODE (addr) == POST_INC)
5998 && XEXP (addr, 0) == inced)
5999 return GET_MODE_SIZE (GET_MODE (x));
6002 fmt = GET_RTX_FORMAT (code);
6003 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6005 if (fmt[i] == 'e')
6007 register int tem = find_inc_amount (XEXP (x, i), inced);
6008 if (tem != 0)
6009 return tem;
6011 if (fmt[i] == 'E')
6013 register int j;
6014 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6016 register int tem = find_inc_amount (XVECEXP (x, i, j), inced);
6017 if (tem != 0)
6018 return tem;
6023 return 0;
6026 /* Return 1 if register REGNO is the subject of a clobber in insn INSN. */
6029 regno_clobbered_p (regno, insn)
6030 int regno;
6031 rtx insn;
6033 if (GET_CODE (PATTERN (insn)) == CLOBBER
6034 && GET_CODE (XEXP (PATTERN (insn), 0)) == REG)
6035 return REGNO (XEXP (PATTERN (insn), 0)) == regno;
6037 if (GET_CODE (PATTERN (insn)) == PARALLEL)
6039 int i = XVECLEN (PATTERN (insn), 0) - 1;
6041 for (; i >= 0; i--)
6043 rtx elt = XVECEXP (PATTERN (insn), 0, i);
6044 if (GET_CODE (elt) == CLOBBER && GET_CODE (XEXP (elt, 0)) == REG
6045 && REGNO (XEXP (elt, 0)) == regno)
6046 return 1;
6050 return 0;
6053 static char *reload_when_needed_name[] =
6055 "RELOAD_FOR_INPUT",
6056 "RELOAD_FOR_OUTPUT",
6057 "RELOAD_FOR_INSN",
6058 "RELOAD_FOR_INPUT_ADDRESS",
6059 "RELOAD_FOR_INPADDR_ADDRESS",
6060 "RELOAD_FOR_OUTPUT_ADDRESS",
6061 "RELOAD_FOR_OUTADDR_ADDRESS",
6062 "RELOAD_FOR_OPERAND_ADDRESS",
6063 "RELOAD_FOR_OPADDR_ADDR",
6064 "RELOAD_OTHER",
6065 "RELOAD_FOR_OTHER_ADDRESS"
6068 static char *reg_class_names[] = REG_CLASS_NAMES;
6070 /* This function is used to print the variables set by 'find_reloads' */
6072 void
6073 debug_reload()
6075 int r;
6077 fprintf (stderr, "\nn_reloads = %d\n", n_reloads);
6079 for (r = 0; r < n_reloads; r++)
6081 fprintf (stderr, "\nRELOAD %d\n", r);
6083 if (reload_in[r])
6085 fprintf (stderr, "\nreload_in (%s) = ",
6086 GET_MODE_NAME (reload_inmode[r]));
6087 debug_rtx (reload_in[r]);
6090 if (reload_out[r])
6092 fprintf (stderr, "\nreload_out (%s) = ",
6093 GET_MODE_NAME (reload_outmode[r]));
6094 debug_rtx (reload_out[r]);
6097 fprintf (stderr, "%s, ", reg_class_names[(int) reload_reg_class[r]]);
6099 fprintf (stderr, "%s (opnum = %d)",
6100 reload_when_needed_name[(int)reload_when_needed[r]],
6101 reload_opnum[r]);
6103 if (reload_optional[r])
6104 fprintf (stderr, ", optional");
6106 if (reload_in[r])
6107 fprintf (stderr, ", inc by %d\n", reload_inc[r]);
6109 if (reload_nocombine[r])
6110 fprintf (stderr, ", can't combine");
6112 if (reload_secondary_p[r])
6113 fprintf (stderr, ", secondary_reload_p");
6115 if (reload_in_reg[r])
6117 fprintf (stderr, "\nreload_in_reg:\t\t\t");
6118 debug_rtx (reload_in_reg[r]);
6121 if (reload_reg_rtx[r])
6123 fprintf (stderr, "\nreload_reg_rtx:\t\t\t");
6124 debug_rtx (reload_reg_rtx[r]);
6127 if (reload_secondary_in_reload[r] != -1)
6129 fprintf (stderr, "\nsecondary_in_reload = ");
6130 fprintf (stderr, "%d ", reload_secondary_in_reload[r]);
6133 if (reload_secondary_out_reload[r] != -1)
6135 if (reload_secondary_in_reload[r] != -1)
6136 fprintf (stderr, ", secondary_out_reload = ");
6137 else
6138 fprintf (stderr, "\nsecondary_out_reload = ");
6140 fprintf (stderr, "%d", reload_secondary_out_reload[r]);
6144 if (reload_secondary_in_icode[r] != CODE_FOR_nothing)
6146 fprintf (stderr, "\nsecondary_in_icode = ");
6147 fprintf (stderr, "%s", insn_name[r]);
6150 if (reload_secondary_out_icode[r] != CODE_FOR_nothing)
6152 if (reload_secondary_in_icode[r] != CODE_FOR_nothing)
6153 fprintf (stderr, ", secondary_out_icode = ");
6154 else
6155 fprintf (stderr, "\nsecondary_out_icode = ");
6157 fprintf (stderr, "%s ", insn_name[r]);
6159 fprintf (stderr, "\n");
6162 fprintf (stderr, "\n");