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