2002-05-02 David S. Miller <davem@redhat.com>
[official-gcc.git] / gcc / reload.c
blob70547581e54d93cad5f7ca4e25c9debd432b2be5
1 /* Search an insn for pseudo regs that must be in hard regs and are not.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 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.
73 Using a reload register for several reloads in one insn:
75 When an insn has reloads, it is considered as having three parts:
76 the input reloads, the insn itself after reloading, and the output reloads.
77 Reloads of values used in memory addresses are often needed for only one part.
79 When this is so, reload_when_needed records which part needs the reload.
80 Two reloads for different parts of the insn can share the same reload
81 register.
83 When a reload is used for addresses in multiple parts, or when it is
84 an ordinary operand, it is classified as RELOAD_OTHER, and cannot share
85 a register with any other reload. */
87 #define REG_OK_STRICT
89 #include "config.h"
90 #include "system.h"
91 #include "rtl.h"
92 #include "tm_p.h"
93 #include "insn-config.h"
94 #include "expr.h"
95 #include "optabs.h"
96 #include "recog.h"
97 #include "reload.h"
98 #include "regs.h"
99 #include "hard-reg-set.h"
100 #include "flags.h"
101 #include "real.h"
102 #include "output.h"
103 #include "function.h"
104 #include "toplev.h"
106 #ifndef REGISTER_MOVE_COST
107 #define REGISTER_MOVE_COST(m, x, y) 2
108 #endif
110 #ifndef REGNO_MODE_OK_FOR_BASE_P
111 #define REGNO_MODE_OK_FOR_BASE_P(REGNO, MODE) REGNO_OK_FOR_BASE_P (REGNO)
112 #endif
114 #ifndef REG_MODE_OK_FOR_BASE_P
115 #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
116 #endif
118 /* All reloads of the current insn are recorded here. See reload.h for
119 comments. */
120 int n_reloads;
121 struct reload rld[MAX_RELOADS];
123 /* All the "earlyclobber" operands of the current insn
124 are recorded here. */
125 int n_earlyclobbers;
126 rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
128 int reload_n_operands;
130 /* Replacing reloads.
132 If `replace_reloads' is nonzero, then as each reload is recorded
133 an entry is made for it in the table `replacements'.
134 Then later `subst_reloads' can look through that table and
135 perform all the replacements needed. */
137 /* Nonzero means record the places to replace. */
138 static int replace_reloads;
140 /* Each replacement is recorded with a structure like this. */
141 struct replacement
143 rtx *where; /* Location to store in */
144 rtx *subreg_loc; /* Location of SUBREG if WHERE is inside
145 a SUBREG; 0 otherwise. */
146 int what; /* which reload this is for */
147 enum machine_mode mode; /* mode it must have */
150 static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
152 /* Number of replacements currently recorded. */
153 static int n_replacements;
155 /* Used to track what is modified by an operand. */
156 struct decomposition
158 int reg_flag; /* Nonzero if referencing a register. */
159 int safe; /* Nonzero if this can't conflict with anything. */
160 rtx base; /* Base address for MEM. */
161 HOST_WIDE_INT start; /* Starting offset or register number. */
162 HOST_WIDE_INT end; /* Ending offset or register number. */
165 #ifdef SECONDARY_MEMORY_NEEDED
167 /* Save MEMs needed to copy from one class of registers to another. One MEM
168 is used per mode, but normally only one or two modes are ever used.
170 We keep two versions, before and after register elimination. The one
171 after register elimination is record separately for each operand. This
172 is done in case the address is not valid to be sure that we separately
173 reload each. */
175 static rtx secondary_memlocs[NUM_MACHINE_MODES];
176 static rtx secondary_memlocs_elim[NUM_MACHINE_MODES][MAX_RECOG_OPERANDS];
177 #endif
179 /* The instruction we are doing reloads for;
180 so we can test whether a register dies in it. */
181 static rtx this_insn;
183 /* Nonzero if this instruction is a user-specified asm with operands. */
184 static int this_insn_is_asm;
186 /* If hard_regs_live_known is nonzero,
187 we can tell which hard regs are currently live,
188 at least enough to succeed in choosing dummy reloads. */
189 static int hard_regs_live_known;
191 /* Indexed by hard reg number,
192 element is nonnegative if hard reg has been spilled.
193 This vector is passed to `find_reloads' as an argument
194 and is not changed here. */
195 static short *static_reload_reg_p;
197 /* Set to 1 in subst_reg_equivs if it changes anything. */
198 static int subst_reg_equivs_changed;
200 /* On return from push_reload, holds the reload-number for the OUT
201 operand, which can be different for that from the input operand. */
202 static int output_reloadnum;
204 /* Compare two RTX's. */
205 #define MATCHES(x, y) \
206 (x == y || (x != 0 && (GET_CODE (x) == REG \
207 ? GET_CODE (y) == REG && REGNO (x) == REGNO (y) \
208 : rtx_equal_p (x, y) && ! side_effects_p (x))))
210 /* Indicates if two reloads purposes are for similar enough things that we
211 can merge their reloads. */
212 #define MERGABLE_RELOADS(when1, when2, op1, op2) \
213 ((when1) == RELOAD_OTHER || (when2) == RELOAD_OTHER \
214 || ((when1) == (when2) && (op1) == (op2)) \
215 || ((when1) == RELOAD_FOR_INPUT && (when2) == RELOAD_FOR_INPUT) \
216 || ((when1) == RELOAD_FOR_OPERAND_ADDRESS \
217 && (when2) == RELOAD_FOR_OPERAND_ADDRESS) \
218 || ((when1) == RELOAD_FOR_OTHER_ADDRESS \
219 && (when2) == RELOAD_FOR_OTHER_ADDRESS))
221 /* Nonzero if these two reload purposes produce RELOAD_OTHER when merged. */
222 #define MERGE_TO_OTHER(when1, when2, op1, op2) \
223 ((when1) != (when2) \
224 || ! ((op1) == (op2) \
225 || (when1) == RELOAD_FOR_INPUT \
226 || (when1) == RELOAD_FOR_OPERAND_ADDRESS \
227 || (when1) == RELOAD_FOR_OTHER_ADDRESS))
229 /* If we are going to reload an address, compute the reload type to
230 use. */
231 #define ADDR_TYPE(type) \
232 ((type) == RELOAD_FOR_INPUT_ADDRESS \
233 ? RELOAD_FOR_INPADDR_ADDRESS \
234 : ((type) == RELOAD_FOR_OUTPUT_ADDRESS \
235 ? RELOAD_FOR_OUTADDR_ADDRESS \
236 : (type)))
238 #ifdef HAVE_SECONDARY_RELOADS
239 static int push_secondary_reload PARAMS ((int, rtx, int, int, enum reg_class,
240 enum machine_mode, enum reload_type,
241 enum insn_code *));
242 #endif
243 static enum reg_class find_valid_class PARAMS ((enum machine_mode, int));
244 static int reload_inner_reg_of_subreg PARAMS ((rtx, enum machine_mode));
245 static void push_replacement PARAMS ((rtx *, int, enum machine_mode));
246 static void combine_reloads PARAMS ((void));
247 static int find_reusable_reload PARAMS ((rtx *, rtx, enum reg_class,
248 enum reload_type, int, int));
249 static rtx find_dummy_reload PARAMS ((rtx, rtx, rtx *, rtx *,
250 enum machine_mode, enum machine_mode,
251 enum reg_class, int, int));
252 static int hard_reg_set_here_p PARAMS ((unsigned int, unsigned int, rtx));
253 static struct decomposition decompose PARAMS ((rtx));
254 static int immune_p PARAMS ((rtx, rtx, struct decomposition));
255 static int alternative_allows_memconst PARAMS ((const char *, int));
256 static rtx find_reloads_toplev PARAMS ((rtx, int, enum reload_type, int,
257 int, rtx, int *));
258 static rtx make_memloc PARAMS ((rtx, int));
259 static int find_reloads_address PARAMS ((enum machine_mode, rtx *, rtx, rtx *,
260 int, enum reload_type, int, rtx));
261 static rtx subst_reg_equivs PARAMS ((rtx, rtx));
262 static rtx subst_indexed_address PARAMS ((rtx));
263 static void update_auto_inc_notes PARAMS ((rtx, int, int));
264 static int find_reloads_address_1 PARAMS ((enum machine_mode, rtx, int, rtx *,
265 int, enum reload_type,int, rtx));
266 static void find_reloads_address_part PARAMS ((rtx, rtx *, enum reg_class,
267 enum machine_mode, int,
268 enum reload_type, int));
269 static rtx find_reloads_subreg_address PARAMS ((rtx, int, int,
270 enum reload_type, int, rtx));
271 static void copy_replacements_1 PARAMS ((rtx *, rtx *, int));
272 static int find_inc_amount PARAMS ((rtx, rtx));
274 #ifdef HAVE_SECONDARY_RELOADS
276 /* Determine if any secondary reloads are needed for loading (if IN_P is
277 non-zero) or storing (if IN_P is zero) X to or from a reload register of
278 register class RELOAD_CLASS in mode RELOAD_MODE. If secondary reloads
279 are needed, push them.
281 Return the reload number of the secondary reload we made, or -1 if
282 we didn't need one. *PICODE is set to the insn_code to use if we do
283 need a secondary reload. */
285 static int
286 push_secondary_reload (in_p, x, opnum, optional, reload_class, reload_mode,
287 type, picode)
288 int in_p;
289 rtx x;
290 int opnum;
291 int optional;
292 enum reg_class reload_class;
293 enum machine_mode reload_mode;
294 enum reload_type type;
295 enum insn_code *picode;
297 enum reg_class class = NO_REGS;
298 enum machine_mode mode = reload_mode;
299 enum insn_code icode = CODE_FOR_nothing;
300 enum reg_class t_class = NO_REGS;
301 enum machine_mode t_mode = VOIDmode;
302 enum insn_code t_icode = CODE_FOR_nothing;
303 enum reload_type secondary_type;
304 int s_reload, t_reload = -1;
306 if (type == RELOAD_FOR_INPUT_ADDRESS
307 || type == RELOAD_FOR_OUTPUT_ADDRESS
308 || type == RELOAD_FOR_INPADDR_ADDRESS
309 || type == RELOAD_FOR_OUTADDR_ADDRESS)
310 secondary_type = type;
311 else
312 secondary_type = in_p ? RELOAD_FOR_INPUT_ADDRESS : RELOAD_FOR_OUTPUT_ADDRESS;
314 *picode = CODE_FOR_nothing;
316 /* If X is a paradoxical SUBREG, use the inner value to determine both the
317 mode and object being reloaded. */
318 if (GET_CODE (x) == SUBREG
319 && (GET_MODE_SIZE (GET_MODE (x))
320 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
322 x = SUBREG_REG (x);
323 reload_mode = GET_MODE (x);
326 /* If X is a pseudo-register that has an equivalent MEM (actually, if it
327 is still a pseudo-register by now, it *must* have an equivalent MEM
328 but we don't want to assume that), use that equivalent when seeing if
329 a secondary reload is needed since whether or not a reload is needed
330 might be sensitive to the form of the MEM. */
332 if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER
333 && reg_equiv_mem[REGNO (x)] != 0)
334 x = reg_equiv_mem[REGNO (x)];
336 #ifdef SECONDARY_INPUT_RELOAD_CLASS
337 if (in_p)
338 class = SECONDARY_INPUT_RELOAD_CLASS (reload_class, reload_mode, x);
339 #endif
341 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
342 if (! in_p)
343 class = SECONDARY_OUTPUT_RELOAD_CLASS (reload_class, reload_mode, x);
344 #endif
346 /* If we don't need any secondary registers, done. */
347 if (class == NO_REGS)
348 return -1;
350 /* Get a possible insn to use. If the predicate doesn't accept X, don't
351 use the insn. */
353 icode = (in_p ? reload_in_optab[(int) reload_mode]
354 : reload_out_optab[(int) reload_mode]);
356 if (icode != CODE_FOR_nothing
357 && insn_data[(int) icode].operand[in_p].predicate
358 && (! (insn_data[(int) icode].operand[in_p].predicate) (x, reload_mode)))
359 icode = CODE_FOR_nothing;
361 /* If we will be using an insn, see if it can directly handle the reload
362 register we will be using. If it can, the secondary reload is for a
363 scratch register. If it can't, we will use the secondary reload for
364 an intermediate register and require a tertiary reload for the scratch
365 register. */
367 if (icode != CODE_FOR_nothing)
369 /* If IN_P is non-zero, the reload register will be the output in
370 operand 0. If IN_P is zero, the reload register will be the input
371 in operand 1. Outputs should have an initial "=", which we must
372 skip. */
374 enum reg_class insn_class;
376 if (insn_data[(int) icode].operand[!in_p].constraint[0] == 0)
377 insn_class = ALL_REGS;
378 else
380 char insn_letter
381 = insn_data[(int) icode].operand[!in_p].constraint[in_p];
382 insn_class
383 = (insn_letter == 'r' ? GENERAL_REGS
384 : REG_CLASS_FROM_LETTER ((unsigned char) insn_letter));
386 if (insn_class == NO_REGS)
387 abort ();
388 if (in_p
389 && insn_data[(int) icode].operand[!in_p].constraint[0] != '=')
390 abort ();
393 /* The scratch register's constraint must start with "=&". */
394 if (insn_data[(int) icode].operand[2].constraint[0] != '='
395 || insn_data[(int) icode].operand[2].constraint[1] != '&')
396 abort ();
398 if (reg_class_subset_p (reload_class, insn_class))
399 mode = insn_data[(int) icode].operand[2].mode;
400 else
402 char t_letter = insn_data[(int) icode].operand[2].constraint[2];
403 class = insn_class;
404 t_mode = insn_data[(int) icode].operand[2].mode;
405 t_class = (t_letter == 'r' ? GENERAL_REGS
406 : REG_CLASS_FROM_LETTER ((unsigned char) t_letter));
407 t_icode = icode;
408 icode = CODE_FOR_nothing;
412 /* This case isn't valid, so fail. Reload is allowed to use the same
413 register for RELOAD_FOR_INPUT_ADDRESS and RELOAD_FOR_INPUT reloads, but
414 in the case of a secondary register, we actually need two different
415 registers for correct code. We fail here to prevent the possibility of
416 silently generating incorrect code later.
418 The convention is that secondary input reloads are valid only if the
419 secondary_class is different from class. If you have such a case, you
420 can not use secondary reloads, you must work around the problem some
421 other way.
423 Allow this when a reload_in/out pattern is being used. I.e. assume
424 that the generated code handles this case. */
426 if (in_p && class == reload_class && icode == CODE_FOR_nothing
427 && t_icode == CODE_FOR_nothing)
428 abort ();
430 /* If we need a tertiary reload, see if we have one we can reuse or else
431 make a new one. */
433 if (t_class != NO_REGS)
435 for (t_reload = 0; t_reload < n_reloads; t_reload++)
436 if (rld[t_reload].secondary_p
437 && (reg_class_subset_p (t_class, rld[t_reload].class)
438 || reg_class_subset_p (rld[t_reload].class, t_class))
439 && ((in_p && rld[t_reload].inmode == t_mode)
440 || (! in_p && rld[t_reload].outmode == t_mode))
441 && ((in_p && (rld[t_reload].secondary_in_icode
442 == CODE_FOR_nothing))
443 || (! in_p &&(rld[t_reload].secondary_out_icode
444 == CODE_FOR_nothing)))
445 && (reg_class_size[(int) t_class] == 1 || SMALL_REGISTER_CLASSES)
446 && MERGABLE_RELOADS (secondary_type,
447 rld[t_reload].when_needed,
448 opnum, rld[t_reload].opnum))
450 if (in_p)
451 rld[t_reload].inmode = t_mode;
452 if (! in_p)
453 rld[t_reload].outmode = t_mode;
455 if (reg_class_subset_p (t_class, rld[t_reload].class))
456 rld[t_reload].class = t_class;
458 rld[t_reload].opnum = MIN (rld[t_reload].opnum, opnum);
459 rld[t_reload].optional &= optional;
460 rld[t_reload].secondary_p = 1;
461 if (MERGE_TO_OTHER (secondary_type, rld[t_reload].when_needed,
462 opnum, rld[t_reload].opnum))
463 rld[t_reload].when_needed = RELOAD_OTHER;
466 if (t_reload == n_reloads)
468 /* We need to make a new tertiary reload for this register class. */
469 rld[t_reload].in = rld[t_reload].out = 0;
470 rld[t_reload].class = t_class;
471 rld[t_reload].inmode = in_p ? t_mode : VOIDmode;
472 rld[t_reload].outmode = ! in_p ? t_mode : VOIDmode;
473 rld[t_reload].reg_rtx = 0;
474 rld[t_reload].optional = optional;
475 rld[t_reload].inc = 0;
476 /* Maybe we could combine these, but it seems too tricky. */
477 rld[t_reload].nocombine = 1;
478 rld[t_reload].in_reg = 0;
479 rld[t_reload].out_reg = 0;
480 rld[t_reload].opnum = opnum;
481 rld[t_reload].when_needed = secondary_type;
482 rld[t_reload].secondary_in_reload = -1;
483 rld[t_reload].secondary_out_reload = -1;
484 rld[t_reload].secondary_in_icode = CODE_FOR_nothing;
485 rld[t_reload].secondary_out_icode = CODE_FOR_nothing;
486 rld[t_reload].secondary_p = 1;
488 n_reloads++;
492 /* See if we can reuse an existing secondary reload. */
493 for (s_reload = 0; s_reload < n_reloads; s_reload++)
494 if (rld[s_reload].secondary_p
495 && (reg_class_subset_p (class, rld[s_reload].class)
496 || reg_class_subset_p (rld[s_reload].class, class))
497 && ((in_p && rld[s_reload].inmode == mode)
498 || (! in_p && rld[s_reload].outmode == mode))
499 && ((in_p && rld[s_reload].secondary_in_reload == t_reload)
500 || (! in_p && rld[s_reload].secondary_out_reload == t_reload))
501 && ((in_p && rld[s_reload].secondary_in_icode == t_icode)
502 || (! in_p && rld[s_reload].secondary_out_icode == t_icode))
503 && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES)
504 && MERGABLE_RELOADS (secondary_type, rld[s_reload].when_needed,
505 opnum, rld[s_reload].opnum))
507 if (in_p)
508 rld[s_reload].inmode = mode;
509 if (! in_p)
510 rld[s_reload].outmode = mode;
512 if (reg_class_subset_p (class, rld[s_reload].class))
513 rld[s_reload].class = class;
515 rld[s_reload].opnum = MIN (rld[s_reload].opnum, opnum);
516 rld[s_reload].optional &= optional;
517 rld[s_reload].secondary_p = 1;
518 if (MERGE_TO_OTHER (secondary_type, rld[s_reload].when_needed,
519 opnum, rld[s_reload].opnum))
520 rld[s_reload].when_needed = RELOAD_OTHER;
523 if (s_reload == n_reloads)
525 #ifdef SECONDARY_MEMORY_NEEDED
526 /* If we need a memory location to copy between the two reload regs,
527 set it up now. Note that we do the input case before making
528 the reload and the output case after. This is due to the
529 way reloads are output. */
531 if (in_p && icode == CODE_FOR_nothing
532 && SECONDARY_MEMORY_NEEDED (class, reload_class, mode))
534 get_secondary_mem (x, reload_mode, opnum, type);
536 /* We may have just added new reloads. Make sure we add
537 the new reload at the end. */
538 s_reload = n_reloads;
540 #endif
542 /* We need to make a new secondary reload for this register class. */
543 rld[s_reload].in = rld[s_reload].out = 0;
544 rld[s_reload].class = class;
546 rld[s_reload].inmode = in_p ? mode : VOIDmode;
547 rld[s_reload].outmode = ! in_p ? mode : VOIDmode;
548 rld[s_reload].reg_rtx = 0;
549 rld[s_reload].optional = optional;
550 rld[s_reload].inc = 0;
551 /* Maybe we could combine these, but it seems too tricky. */
552 rld[s_reload].nocombine = 1;
553 rld[s_reload].in_reg = 0;
554 rld[s_reload].out_reg = 0;
555 rld[s_reload].opnum = opnum;
556 rld[s_reload].when_needed = secondary_type;
557 rld[s_reload].secondary_in_reload = in_p ? t_reload : -1;
558 rld[s_reload].secondary_out_reload = ! in_p ? t_reload : -1;
559 rld[s_reload].secondary_in_icode = in_p ? t_icode : CODE_FOR_nothing;
560 rld[s_reload].secondary_out_icode
561 = ! in_p ? t_icode : CODE_FOR_nothing;
562 rld[s_reload].secondary_p = 1;
564 n_reloads++;
566 #ifdef SECONDARY_MEMORY_NEEDED
567 if (! in_p && icode == CODE_FOR_nothing
568 && SECONDARY_MEMORY_NEEDED (reload_class, class, mode))
569 get_secondary_mem (x, mode, opnum, type);
570 #endif
573 *picode = icode;
574 return s_reload;
576 #endif /* HAVE_SECONDARY_RELOADS */
578 #ifdef SECONDARY_MEMORY_NEEDED
580 /* Return a memory location that will be used to copy X in mode MODE.
581 If we haven't already made a location for this mode in this insn,
582 call find_reloads_address on the location being returned. */
585 get_secondary_mem (x, mode, opnum, type)
586 rtx x ATTRIBUTE_UNUSED;
587 enum machine_mode mode;
588 int opnum;
589 enum reload_type type;
591 rtx loc;
592 int mem_valid;
594 /* By default, if MODE is narrower than a word, widen it to a word.
595 This is required because most machines that require these memory
596 locations do not support short load and stores from all registers
597 (e.g., FP registers). */
599 #ifdef SECONDARY_MEMORY_NEEDED_MODE
600 mode = SECONDARY_MEMORY_NEEDED_MODE (mode);
601 #else
602 if (GET_MODE_BITSIZE (mode) < BITS_PER_WORD && INTEGRAL_MODE_P (mode))
603 mode = mode_for_size (BITS_PER_WORD, GET_MODE_CLASS (mode), 0);
604 #endif
606 /* If we already have made a MEM for this operand in MODE, return it. */
607 if (secondary_memlocs_elim[(int) mode][opnum] != 0)
608 return secondary_memlocs_elim[(int) mode][opnum];
610 /* If this is the first time we've tried to get a MEM for this mode,
611 allocate a new one. `something_changed' in reload will get set
612 by noticing that the frame size has changed. */
614 if (secondary_memlocs[(int) mode] == 0)
616 #ifdef SECONDARY_MEMORY_NEEDED_RTX
617 secondary_memlocs[(int) mode] = SECONDARY_MEMORY_NEEDED_RTX (mode);
618 #else
619 secondary_memlocs[(int) mode]
620 = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
621 #endif
624 /* Get a version of the address doing any eliminations needed. If that
625 didn't give us a new MEM, make a new one if it isn't valid. */
627 loc = eliminate_regs (secondary_memlocs[(int) mode], VOIDmode, NULL_RTX);
628 mem_valid = strict_memory_address_p (mode, XEXP (loc, 0));
630 if (! mem_valid && loc == secondary_memlocs[(int) mode])
631 loc = copy_rtx (loc);
633 /* The only time the call below will do anything is if the stack
634 offset is too large. In that case IND_LEVELS doesn't matter, so we
635 can just pass a zero. Adjust the type to be the address of the
636 corresponding object. If the address was valid, save the eliminated
637 address. If it wasn't valid, we need to make a reload each time, so
638 don't save it. */
640 if (! mem_valid)
642 type = (type == RELOAD_FOR_INPUT ? RELOAD_FOR_INPUT_ADDRESS
643 : type == RELOAD_FOR_OUTPUT ? RELOAD_FOR_OUTPUT_ADDRESS
644 : RELOAD_OTHER);
646 find_reloads_address (mode, (rtx*) 0, XEXP (loc, 0), &XEXP (loc, 0),
647 opnum, type, 0, 0);
650 secondary_memlocs_elim[(int) mode][opnum] = loc;
651 return loc;
654 /* Clear any secondary memory locations we've made. */
656 void
657 clear_secondary_mem ()
659 memset ((char *) secondary_memlocs, 0, sizeof secondary_memlocs);
661 #endif /* SECONDARY_MEMORY_NEEDED */
663 /* Find the largest class for which every register number plus N is valid in
664 M1 (if in range). Abort if no such class exists. */
666 static enum reg_class
667 find_valid_class (m1, n)
668 enum machine_mode m1 ATTRIBUTE_UNUSED;
669 int n;
671 int class;
672 int regno;
673 enum reg_class best_class = NO_REGS;
674 unsigned int best_size = 0;
676 for (class = 1; class < N_REG_CLASSES; class++)
678 int bad = 0;
679 for (regno = 0; regno < FIRST_PSEUDO_REGISTER && ! bad; regno++)
680 if (TEST_HARD_REG_BIT (reg_class_contents[class], regno)
681 && TEST_HARD_REG_BIT (reg_class_contents[class], regno + n)
682 && ! HARD_REGNO_MODE_OK (regno + n, m1))
683 bad = 1;
685 if (! bad && reg_class_size[class] > best_size)
686 best_class = class, best_size = reg_class_size[class];
689 if (best_size == 0)
690 abort ();
692 return best_class;
695 /* Return the number of a previously made reload that can be combined with
696 a new one, or n_reloads if none of the existing reloads can be used.
697 OUT, CLASS, TYPE and OPNUM are the same arguments as passed to
698 push_reload, they determine the kind of the new reload that we try to
699 combine. P_IN points to the corresponding value of IN, which can be
700 modified by this function.
701 DONT_SHARE is nonzero if we can't share any input-only reload for IN. */
703 static int
704 find_reusable_reload (p_in, out, class, type, opnum, dont_share)
705 rtx *p_in, out;
706 enum reg_class class;
707 enum reload_type type;
708 int opnum, dont_share;
710 rtx in = *p_in;
711 int i;
712 /* We can't merge two reloads if the output of either one is
713 earlyclobbered. */
715 if (earlyclobber_operand_p (out))
716 return n_reloads;
718 /* We can use an existing reload if the class is right
719 and at least one of IN and OUT is a match
720 and the other is at worst neutral.
721 (A zero compared against anything is neutral.)
723 If SMALL_REGISTER_CLASSES, don't use existing reloads unless they are
724 for the same thing since that can cause us to need more reload registers
725 than we otherwise would. */
727 for (i = 0; i < n_reloads; i++)
728 if ((reg_class_subset_p (class, rld[i].class)
729 || reg_class_subset_p (rld[i].class, class))
730 /* If the existing reload has a register, it must fit our class. */
731 && (rld[i].reg_rtx == 0
732 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
733 true_regnum (rld[i].reg_rtx)))
734 && ((in != 0 && MATCHES (rld[i].in, in) && ! dont_share
735 && (out == 0 || rld[i].out == 0 || MATCHES (rld[i].out, out)))
736 || (out != 0 && MATCHES (rld[i].out, out)
737 && (in == 0 || rld[i].in == 0 || MATCHES (rld[i].in, in))))
738 && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
739 && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES)
740 && MERGABLE_RELOADS (type, rld[i].when_needed, opnum, rld[i].opnum))
741 return i;
743 /* Reloading a plain reg for input can match a reload to postincrement
744 that reg, since the postincrement's value is the right value.
745 Likewise, it can match a preincrement reload, since we regard
746 the preincrementation as happening before any ref in this insn
747 to that register. */
748 for (i = 0; i < n_reloads; i++)
749 if ((reg_class_subset_p (class, rld[i].class)
750 || reg_class_subset_p (rld[i].class, class))
751 /* If the existing reload has a register, it must fit our
752 class. */
753 && (rld[i].reg_rtx == 0
754 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
755 true_regnum (rld[i].reg_rtx)))
756 && out == 0 && rld[i].out == 0 && rld[i].in != 0
757 && ((GET_CODE (in) == REG
758 && GET_RTX_CLASS (GET_CODE (rld[i].in)) == 'a'
759 && MATCHES (XEXP (rld[i].in, 0), in))
760 || (GET_CODE (rld[i].in) == REG
761 && GET_RTX_CLASS (GET_CODE (in)) == 'a'
762 && MATCHES (XEXP (in, 0), rld[i].in)))
763 && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
764 && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES)
765 && MERGABLE_RELOADS (type, rld[i].when_needed,
766 opnum, rld[i].opnum))
768 /* Make sure reload_in ultimately has the increment,
769 not the plain register. */
770 if (GET_CODE (in) == REG)
771 *p_in = rld[i].in;
772 return i;
774 return n_reloads;
777 /* Return nonzero if X is a SUBREG which will require reloading of its
778 SUBREG_REG expression. */
780 static int
781 reload_inner_reg_of_subreg (x, mode)
782 rtx x;
783 enum machine_mode mode;
785 rtx inner;
787 /* Only SUBREGs are problematical. */
788 if (GET_CODE (x) != SUBREG)
789 return 0;
791 inner = SUBREG_REG (x);
793 /* If INNER is a constant or PLUS, then INNER must be reloaded. */
794 if (CONSTANT_P (inner) || GET_CODE (inner) == PLUS)
795 return 1;
797 /* If INNER is not a hard register, then INNER will not need to
798 be reloaded. */
799 if (GET_CODE (inner) != REG
800 || REGNO (inner) >= FIRST_PSEUDO_REGISTER)
801 return 0;
803 /* If INNER is not ok for MODE, then INNER will need reloading. */
804 if (! HARD_REGNO_MODE_OK (subreg_regno (x), mode))
805 return 1;
807 /* If the outer part is a word or smaller, INNER larger than a
808 word and the number of regs for INNER is not the same as the
809 number of words in INNER, then INNER will need reloading. */
810 return (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
811 && GET_MODE_SIZE (GET_MODE (inner)) > UNITS_PER_WORD
812 && ((GET_MODE_SIZE (GET_MODE (inner)) / UNITS_PER_WORD)
813 != HARD_REGNO_NREGS (REGNO (inner), GET_MODE (inner))));
816 /* Record one reload that needs to be performed.
817 IN is an rtx saying where the data are to be found before this instruction.
818 OUT says where they must be stored after the instruction.
819 (IN is zero for data not read, and OUT is zero for data not written.)
820 INLOC and OUTLOC point to the places in the instructions where
821 IN and OUT were found.
822 If IN and OUT are both non-zero, it means the same register must be used
823 to reload both IN and OUT.
825 CLASS is a register class required for the reloaded data.
826 INMODE is the machine mode that the instruction requires
827 for the reg that replaces IN and OUTMODE is likewise for OUT.
829 If IN is zero, then OUT's location and mode should be passed as
830 INLOC and INMODE.
832 STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
834 OPTIONAL nonzero means this reload does not need to be performed:
835 it can be discarded if that is more convenient.
837 OPNUM and TYPE say what the purpose of this reload is.
839 The return value is the reload-number for this reload.
841 If both IN and OUT are nonzero, in some rare cases we might
842 want to make two separate reloads. (Actually we never do this now.)
843 Therefore, the reload-number for OUT is stored in
844 output_reloadnum when we return; the return value applies to IN.
845 Usually (presently always), when IN and OUT are nonzero,
846 the two reload-numbers are equal, but the caller should be careful to
847 distinguish them. */
850 push_reload (in, out, inloc, outloc, class,
851 inmode, outmode, strict_low, optional, opnum, type)
852 rtx in, out;
853 rtx *inloc, *outloc;
854 enum reg_class class;
855 enum machine_mode inmode, outmode;
856 int strict_low;
857 int optional;
858 int opnum;
859 enum reload_type type;
861 int i;
862 int dont_share = 0;
863 int dont_remove_subreg = 0;
864 rtx *in_subreg_loc = 0, *out_subreg_loc = 0;
865 int secondary_in_reload = -1, secondary_out_reload = -1;
866 enum insn_code secondary_in_icode = CODE_FOR_nothing;
867 enum insn_code secondary_out_icode = CODE_FOR_nothing;
869 /* INMODE and/or OUTMODE could be VOIDmode if no mode
870 has been specified for the operand. In that case,
871 use the operand's mode as the mode to reload. */
872 if (inmode == VOIDmode && in != 0)
873 inmode = GET_MODE (in);
874 if (outmode == VOIDmode && out != 0)
875 outmode = GET_MODE (out);
877 /* If IN is a pseudo register everywhere-equivalent to a constant, and
878 it is not in a hard register, reload straight from the constant,
879 since we want to get rid of such pseudo registers.
880 Often this is done earlier, but not always in find_reloads_address. */
881 if (in != 0 && GET_CODE (in) == REG)
883 int regno = REGNO (in);
885 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
886 && reg_equiv_constant[regno] != 0)
887 in = reg_equiv_constant[regno];
890 /* Likewise for OUT. Of course, OUT will never be equivalent to
891 an actual constant, but it might be equivalent to a memory location
892 (in the case of a parameter). */
893 if (out != 0 && GET_CODE (out) == REG)
895 int regno = REGNO (out);
897 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
898 && reg_equiv_constant[regno] != 0)
899 out = reg_equiv_constant[regno];
902 /* If we have a read-write operand with an address side-effect,
903 change either IN or OUT so the side-effect happens only once. */
904 if (in != 0 && out != 0 && GET_CODE (in) == MEM && rtx_equal_p (in, out))
905 switch (GET_CODE (XEXP (in, 0)))
907 case POST_INC: case POST_DEC: case POST_MODIFY:
908 in = replace_equiv_address_nv (in, XEXP (XEXP (in, 0), 0));
909 break;
911 case PRE_INC: case PRE_DEC: case PRE_MODIFY:
912 out = replace_equiv_address_nv (out, XEXP (XEXP (out, 0), 0));
913 break;
915 default:
916 break;
919 /* If we are reloading a (SUBREG constant ...), really reload just the
920 inside expression in its own mode. Similarly for (SUBREG (PLUS ...)).
921 If we have (SUBREG:M1 (MEM:M2 ...) ...) (or an inner REG that is still
922 a pseudo and hence will become a MEM) with M1 wider than M2 and the
923 register is a pseudo, also reload the inside expression.
924 For machines that extend byte loads, do this for any SUBREG of a pseudo
925 where both M1 and M2 are a word or smaller, M1 is wider than M2, and
926 M2 is an integral mode that gets extended when loaded.
927 Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
928 either M1 is not valid for R or M2 is wider than a word but we only
929 need one word to store an M2-sized quantity in R.
930 (However, if OUT is nonzero, we need to reload the reg *and*
931 the subreg, so do nothing here, and let following statement handle it.)
933 Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere;
934 we can't handle it here because CONST_INT does not indicate a mode.
936 Similarly, we must reload the inside expression if we have a
937 STRICT_LOW_PART (presumably, in == out in the cas).
939 Also reload the inner expression if it does not require a secondary
940 reload but the SUBREG does.
942 Finally, reload the inner expression if it is a register that is in
943 the class whose registers cannot be referenced in a different size
944 and M1 is not the same size as M2. If subreg_lowpart_p is false, we
945 cannot reload just the inside since we might end up with the wrong
946 register class. But if it is inside a STRICT_LOW_PART, we have
947 no choice, so we hope we do get the right register class there. */
949 if (in != 0 && GET_CODE (in) == SUBREG
950 && (subreg_lowpart_p (in) || strict_low)
951 #ifdef CLASS_CANNOT_CHANGE_MODE
952 && (class != CLASS_CANNOT_CHANGE_MODE
953 || ! CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (SUBREG_REG (in)), inmode))
954 #endif
955 && (CONSTANT_P (SUBREG_REG (in))
956 || GET_CODE (SUBREG_REG (in)) == PLUS
957 || strict_low
958 || (((GET_CODE (SUBREG_REG (in)) == REG
959 && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER)
960 || GET_CODE (SUBREG_REG (in)) == MEM)
961 && ((GET_MODE_SIZE (inmode)
962 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
963 #ifdef LOAD_EXTEND_OP
964 || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
965 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
966 <= UNITS_PER_WORD)
967 && (GET_MODE_SIZE (inmode)
968 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
969 && INTEGRAL_MODE_P (GET_MODE (SUBREG_REG (in)))
970 && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (in))) != NIL)
971 #endif
972 #ifdef WORD_REGISTER_OPERATIONS
973 || ((GET_MODE_SIZE (inmode)
974 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
975 && ((GET_MODE_SIZE (inmode) - 1) / UNITS_PER_WORD ==
976 ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))) - 1)
977 / UNITS_PER_WORD)))
978 #endif
980 || (GET_CODE (SUBREG_REG (in)) == REG
981 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
982 /* The case where out is nonzero
983 is handled differently in the following statement. */
984 && (out == 0 || subreg_lowpart_p (in))
985 && ((GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
986 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
987 > UNITS_PER_WORD)
988 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
989 / UNITS_PER_WORD)
990 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (in)),
991 GET_MODE (SUBREG_REG (in)))))
992 || ! HARD_REGNO_MODE_OK (subreg_regno (in), inmode)))
993 #ifdef SECONDARY_INPUT_RELOAD_CLASS
994 || (SECONDARY_INPUT_RELOAD_CLASS (class, inmode, in) != NO_REGS
995 && (SECONDARY_INPUT_RELOAD_CLASS (class,
996 GET_MODE (SUBREG_REG (in)),
997 SUBREG_REG (in))
998 == NO_REGS))
999 #endif
1000 #ifdef CLASS_CANNOT_CHANGE_MODE
1001 || (GET_CODE (SUBREG_REG (in)) == REG
1002 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1003 && (TEST_HARD_REG_BIT
1004 (reg_class_contents[(int) CLASS_CANNOT_CHANGE_MODE],
1005 REGNO (SUBREG_REG (in))))
1006 && CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (SUBREG_REG (in)),
1007 inmode))
1008 #endif
1011 in_subreg_loc = inloc;
1012 inloc = &SUBREG_REG (in);
1013 in = *inloc;
1014 #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
1015 if (GET_CODE (in) == MEM)
1016 /* This is supposed to happen only for paradoxical subregs made by
1017 combine.c. (SUBREG (MEM)) isn't supposed to occur other ways. */
1018 if (GET_MODE_SIZE (GET_MODE (in)) > GET_MODE_SIZE (inmode))
1019 abort ();
1020 #endif
1021 inmode = GET_MODE (in);
1024 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
1025 either M1 is not valid for R or M2 is wider than a word but we only
1026 need one word to store an M2-sized quantity in R.
1028 However, we must reload the inner reg *as well as* the subreg in
1029 that case. */
1031 /* Similar issue for (SUBREG constant ...) if it was not handled by the
1032 code above. This can happen if SUBREG_BYTE != 0. */
1034 if (in != 0 && reload_inner_reg_of_subreg (in, inmode))
1036 enum reg_class in_class = class;
1038 if (GET_CODE (SUBREG_REG (in)) == REG)
1039 in_class
1040 = find_valid_class (inmode,
1041 subreg_regno_offset (REGNO (SUBREG_REG (in)),
1042 GET_MODE (SUBREG_REG (in)),
1043 SUBREG_BYTE (in),
1044 GET_MODE (in)));
1046 /* This relies on the fact that emit_reload_insns outputs the
1047 instructions for input reloads of type RELOAD_OTHER in the same
1048 order as the reloads. Thus if the outer reload is also of type
1049 RELOAD_OTHER, we are guaranteed that this inner reload will be
1050 output before the outer reload. */
1051 push_reload (SUBREG_REG (in), NULL_RTX, &SUBREG_REG (in), (rtx *) 0,
1052 in_class, VOIDmode, VOIDmode, 0, 0, opnum, type);
1053 dont_remove_subreg = 1;
1056 /* Similarly for paradoxical and problematical SUBREGs on the output.
1057 Note that there is no reason we need worry about the previous value
1058 of SUBREG_REG (out); even if wider than out,
1059 storing in a subreg is entitled to clobber it all
1060 (except in the case of STRICT_LOW_PART,
1061 and in that case the constraint should label it input-output.) */
1062 if (out != 0 && GET_CODE (out) == SUBREG
1063 && (subreg_lowpart_p (out) || strict_low)
1064 #ifdef CLASS_CANNOT_CHANGE_MODE
1065 && (class != CLASS_CANNOT_CHANGE_MODE
1066 || ! CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (SUBREG_REG (out)),
1067 outmode))
1068 #endif
1069 && (CONSTANT_P (SUBREG_REG (out))
1070 || strict_low
1071 || (((GET_CODE (SUBREG_REG (out)) == REG
1072 && REGNO (SUBREG_REG (out)) >= FIRST_PSEUDO_REGISTER)
1073 || GET_CODE (SUBREG_REG (out)) == MEM)
1074 && ((GET_MODE_SIZE (outmode)
1075 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))
1076 #ifdef WORD_REGISTER_OPERATIONS
1077 || ((GET_MODE_SIZE (outmode)
1078 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))
1079 && ((GET_MODE_SIZE (outmode) - 1) / UNITS_PER_WORD ==
1080 ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))) - 1)
1081 / UNITS_PER_WORD)))
1082 #endif
1084 || (GET_CODE (SUBREG_REG (out)) == REG
1085 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1086 && ((GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
1087 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1088 > UNITS_PER_WORD)
1089 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1090 / UNITS_PER_WORD)
1091 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (out)),
1092 GET_MODE (SUBREG_REG (out)))))
1093 || ! HARD_REGNO_MODE_OK (subreg_regno (out), outmode)))
1094 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1095 || (SECONDARY_OUTPUT_RELOAD_CLASS (class, outmode, out) != NO_REGS
1096 && (SECONDARY_OUTPUT_RELOAD_CLASS (class,
1097 GET_MODE (SUBREG_REG (out)),
1098 SUBREG_REG (out))
1099 == NO_REGS))
1100 #endif
1101 #ifdef CLASS_CANNOT_CHANGE_MODE
1102 || (GET_CODE (SUBREG_REG (out)) == REG
1103 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1104 && (TEST_HARD_REG_BIT
1105 (reg_class_contents[(int) CLASS_CANNOT_CHANGE_MODE],
1106 REGNO (SUBREG_REG (out))))
1107 && CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (SUBREG_REG (out)),
1108 outmode))
1109 #endif
1112 out_subreg_loc = outloc;
1113 outloc = &SUBREG_REG (out);
1114 out = *outloc;
1115 #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
1116 if (GET_CODE (out) == MEM
1117 && GET_MODE_SIZE (GET_MODE (out)) > GET_MODE_SIZE (outmode))
1118 abort ();
1119 #endif
1120 outmode = GET_MODE (out);
1123 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
1124 either M1 is not valid for R or M2 is wider than a word but we only
1125 need one word to store an M2-sized quantity in R.
1127 However, we must reload the inner reg *as well as* the subreg in
1128 that case. In this case, the inner reg is an in-out reload. */
1130 if (out != 0 && reload_inner_reg_of_subreg (out, outmode))
1132 /* This relies on the fact that emit_reload_insns outputs the
1133 instructions for output reloads of type RELOAD_OTHER in reverse
1134 order of the reloads. Thus if the outer reload is also of type
1135 RELOAD_OTHER, we are guaranteed that this inner reload will be
1136 output after the outer reload. */
1137 dont_remove_subreg = 1;
1138 push_reload (SUBREG_REG (out), SUBREG_REG (out), &SUBREG_REG (out),
1139 &SUBREG_REG (out),
1140 find_valid_class (outmode,
1141 subreg_regno_offset (REGNO (SUBREG_REG (out)),
1142 GET_MODE (SUBREG_REG (out)),
1143 SUBREG_BYTE (out),
1144 GET_MODE (out))),
1145 VOIDmode, VOIDmode, 0, 0,
1146 opnum, RELOAD_OTHER);
1149 /* If IN appears in OUT, we can't share any input-only reload for IN. */
1150 if (in != 0 && out != 0 && GET_CODE (out) == MEM
1151 && (GET_CODE (in) == REG || GET_CODE (in) == MEM)
1152 && reg_overlap_mentioned_for_reload_p (in, XEXP (out, 0)))
1153 dont_share = 1;
1155 /* If IN is a SUBREG of a hard register, make a new REG. This
1156 simplifies some of the cases below. */
1158 if (in != 0 && GET_CODE (in) == SUBREG && GET_CODE (SUBREG_REG (in)) == REG
1159 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1160 && ! dont_remove_subreg)
1161 in = gen_rtx_REG (GET_MODE (in), subreg_regno (in));
1163 /* Similarly for OUT. */
1164 if (out != 0 && GET_CODE (out) == SUBREG
1165 && GET_CODE (SUBREG_REG (out)) == REG
1166 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1167 && ! dont_remove_subreg)
1168 out = gen_rtx_REG (GET_MODE (out), subreg_regno (out));
1170 /* Narrow down the class of register wanted if that is
1171 desirable on this machine for efficiency. */
1172 if (in != 0)
1173 class = PREFERRED_RELOAD_CLASS (in, class);
1175 /* Output reloads may need analogous treatment, different in detail. */
1176 #ifdef PREFERRED_OUTPUT_RELOAD_CLASS
1177 if (out != 0)
1178 class = PREFERRED_OUTPUT_RELOAD_CLASS (out, class);
1179 #endif
1181 /* Make sure we use a class that can handle the actual pseudo
1182 inside any subreg. For example, on the 386, QImode regs
1183 can appear within SImode subregs. Although GENERAL_REGS
1184 can handle SImode, QImode needs a smaller class. */
1185 #ifdef LIMIT_RELOAD_CLASS
1186 if (in_subreg_loc)
1187 class = LIMIT_RELOAD_CLASS (inmode, class);
1188 else if (in != 0 && GET_CODE (in) == SUBREG)
1189 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (in)), class);
1191 if (out_subreg_loc)
1192 class = LIMIT_RELOAD_CLASS (outmode, class);
1193 if (out != 0 && GET_CODE (out) == SUBREG)
1194 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (out)), class);
1195 #endif
1197 /* Verify that this class is at least possible for the mode that
1198 is specified. */
1199 if (this_insn_is_asm)
1201 enum machine_mode mode;
1202 if (GET_MODE_SIZE (inmode) > GET_MODE_SIZE (outmode))
1203 mode = inmode;
1204 else
1205 mode = outmode;
1206 if (mode == VOIDmode)
1208 error_for_asm (this_insn, "cannot reload integer constant operand in `asm'");
1209 mode = word_mode;
1210 if (in != 0)
1211 inmode = word_mode;
1212 if (out != 0)
1213 outmode = word_mode;
1215 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1216 if (HARD_REGNO_MODE_OK (i, mode)
1217 && TEST_HARD_REG_BIT (reg_class_contents[(int) class], i))
1219 int nregs = HARD_REGNO_NREGS (i, mode);
1221 int j;
1222 for (j = 1; j < nregs; j++)
1223 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], i + j))
1224 break;
1225 if (j == nregs)
1226 break;
1228 if (i == FIRST_PSEUDO_REGISTER)
1230 error_for_asm (this_insn, "impossible register constraint in `asm'");
1231 class = ALL_REGS;
1235 /* Optional output reloads are always OK even if we have no register class,
1236 since the function of these reloads is only to have spill_reg_store etc.
1237 set, so that the storing insn can be deleted later. */
1238 if (class == NO_REGS
1239 && (optional == 0 || type != RELOAD_FOR_OUTPUT))
1240 abort ();
1242 i = find_reusable_reload (&in, out, class, type, opnum, dont_share);
1244 if (i == n_reloads)
1246 /* See if we need a secondary reload register to move between CLASS
1247 and IN or CLASS and OUT. Get the icode and push any required reloads
1248 needed for each of them if so. */
1250 #ifdef SECONDARY_INPUT_RELOAD_CLASS
1251 if (in != 0)
1252 secondary_in_reload
1253 = push_secondary_reload (1, in, opnum, optional, class, inmode, type,
1254 &secondary_in_icode);
1255 #endif
1257 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1258 if (out != 0 && GET_CODE (out) != SCRATCH)
1259 secondary_out_reload
1260 = push_secondary_reload (0, out, opnum, optional, class, outmode,
1261 type, &secondary_out_icode);
1262 #endif
1264 /* We found no existing reload suitable for re-use.
1265 So add an additional reload. */
1267 #ifdef SECONDARY_MEMORY_NEEDED
1268 /* If a memory location is needed for the copy, make one. */
1269 if (in != 0 && GET_CODE (in) == REG
1270 && REGNO (in) < FIRST_PSEUDO_REGISTER
1271 && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (REGNO (in)),
1272 class, inmode))
1273 get_secondary_mem (in, inmode, opnum, type);
1274 #endif
1276 i = n_reloads;
1277 rld[i].in = in;
1278 rld[i].out = out;
1279 rld[i].class = class;
1280 rld[i].inmode = inmode;
1281 rld[i].outmode = outmode;
1282 rld[i].reg_rtx = 0;
1283 rld[i].optional = optional;
1284 rld[i].inc = 0;
1285 rld[i].nocombine = 0;
1286 rld[i].in_reg = inloc ? *inloc : 0;
1287 rld[i].out_reg = outloc ? *outloc : 0;
1288 rld[i].opnum = opnum;
1289 rld[i].when_needed = type;
1290 rld[i].secondary_in_reload = secondary_in_reload;
1291 rld[i].secondary_out_reload = secondary_out_reload;
1292 rld[i].secondary_in_icode = secondary_in_icode;
1293 rld[i].secondary_out_icode = secondary_out_icode;
1294 rld[i].secondary_p = 0;
1296 n_reloads++;
1298 #ifdef SECONDARY_MEMORY_NEEDED
1299 if (out != 0 && GET_CODE (out) == REG
1300 && REGNO (out) < FIRST_PSEUDO_REGISTER
1301 && SECONDARY_MEMORY_NEEDED (class, REGNO_REG_CLASS (REGNO (out)),
1302 outmode))
1303 get_secondary_mem (out, outmode, opnum, type);
1304 #endif
1306 else
1308 /* We are reusing an existing reload,
1309 but we may have additional information for it.
1310 For example, we may now have both IN and OUT
1311 while the old one may have just one of them. */
1313 /* The modes can be different. If they are, we want to reload in
1314 the larger mode, so that the value is valid for both modes. */
1315 if (inmode != VOIDmode
1316 && GET_MODE_SIZE (inmode) > GET_MODE_SIZE (rld[i].inmode))
1317 rld[i].inmode = inmode;
1318 if (outmode != VOIDmode
1319 && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (rld[i].outmode))
1320 rld[i].outmode = outmode;
1321 if (in != 0)
1323 rtx in_reg = inloc ? *inloc : 0;
1324 /* If we merge reloads for two distinct rtl expressions that
1325 are identical in content, there might be duplicate address
1326 reloads. Remove the extra set now, so that if we later find
1327 that we can inherit this reload, we can get rid of the
1328 address reloads altogether.
1330 Do not do this if both reloads are optional since the result
1331 would be an optional reload which could potentially leave
1332 unresolved address replacements.
1334 It is not sufficient to call transfer_replacements since
1335 choose_reload_regs will remove the replacements for address
1336 reloads of inherited reloads which results in the same
1337 problem. */
1338 if (rld[i].in != in && rtx_equal_p (in, rld[i].in)
1339 && ! (rld[i].optional && optional))
1341 /* We must keep the address reload with the lower operand
1342 number alive. */
1343 if (opnum > rld[i].opnum)
1345 remove_address_replacements (in);
1346 in = rld[i].in;
1347 in_reg = rld[i].in_reg;
1349 else
1350 remove_address_replacements (rld[i].in);
1352 rld[i].in = in;
1353 rld[i].in_reg = in_reg;
1355 if (out != 0)
1357 rld[i].out = out;
1358 rld[i].out_reg = outloc ? *outloc : 0;
1360 if (reg_class_subset_p (class, rld[i].class))
1361 rld[i].class = class;
1362 rld[i].optional &= optional;
1363 if (MERGE_TO_OTHER (type, rld[i].when_needed,
1364 opnum, rld[i].opnum))
1365 rld[i].when_needed = RELOAD_OTHER;
1366 rld[i].opnum = MIN (rld[i].opnum, opnum);
1369 /* If the ostensible rtx being reloaded differs from the rtx found
1370 in the location to substitute, this reload is not safe to combine
1371 because we cannot reliably tell whether it appears in the insn. */
1373 if (in != 0 && in != *inloc)
1374 rld[i].nocombine = 1;
1376 #if 0
1377 /* This was replaced by changes in find_reloads_address_1 and the new
1378 function inc_for_reload, which go with a new meaning of reload_inc. */
1380 /* If this is an IN/OUT reload in an insn that sets the CC,
1381 it must be for an autoincrement. It doesn't work to store
1382 the incremented value after the insn because that would clobber the CC.
1383 So we must do the increment of the value reloaded from,
1384 increment it, store it back, then decrement again. */
1385 if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
1387 out = 0;
1388 rld[i].out = 0;
1389 rld[i].inc = find_inc_amount (PATTERN (this_insn), in);
1390 /* If we did not find a nonzero amount-to-increment-by,
1391 that contradicts the belief that IN is being incremented
1392 in an address in this insn. */
1393 if (rld[i].inc == 0)
1394 abort ();
1396 #endif
1398 /* If we will replace IN and OUT with the reload-reg,
1399 record where they are located so that substitution need
1400 not do a tree walk. */
1402 if (replace_reloads)
1404 if (inloc != 0)
1406 struct replacement *r = &replacements[n_replacements++];
1407 r->what = i;
1408 r->subreg_loc = in_subreg_loc;
1409 r->where = inloc;
1410 r->mode = inmode;
1412 if (outloc != 0 && outloc != inloc)
1414 struct replacement *r = &replacements[n_replacements++];
1415 r->what = i;
1416 r->where = outloc;
1417 r->subreg_loc = out_subreg_loc;
1418 r->mode = outmode;
1422 /* If this reload is just being introduced and it has both
1423 an incoming quantity and an outgoing quantity that are
1424 supposed to be made to match, see if either one of the two
1425 can serve as the place to reload into.
1427 If one of them is acceptable, set rld[i].reg_rtx
1428 to that one. */
1430 if (in != 0 && out != 0 && in != out && rld[i].reg_rtx == 0)
1432 rld[i].reg_rtx = find_dummy_reload (in, out, inloc, outloc,
1433 inmode, outmode,
1434 rld[i].class, i,
1435 earlyclobber_operand_p (out));
1437 /* If the outgoing register already contains the same value
1438 as the incoming one, we can dispense with loading it.
1439 The easiest way to tell the caller that is to give a phony
1440 value for the incoming operand (same as outgoing one). */
1441 if (rld[i].reg_rtx == out
1442 && (GET_CODE (in) == REG || CONSTANT_P (in))
1443 && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
1444 static_reload_reg_p, i, inmode))
1445 rld[i].in = out;
1448 /* If this is an input reload and the operand contains a register that
1449 dies in this insn and is used nowhere else, see if it is the right class
1450 to be used for this reload. Use it if so. (This occurs most commonly
1451 in the case of paradoxical SUBREGs and in-out reloads). We cannot do
1452 this if it is also an output reload that mentions the register unless
1453 the output is a SUBREG that clobbers an entire register.
1455 Note that the operand might be one of the spill regs, if it is a
1456 pseudo reg and we are in a block where spilling has not taken place.
1457 But if there is no spilling in this block, that is OK.
1458 An explicitly used hard reg cannot be a spill reg. */
1460 if (rld[i].reg_rtx == 0 && in != 0)
1462 rtx note;
1463 int regno;
1464 enum machine_mode rel_mode = inmode;
1466 if (out && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (inmode))
1467 rel_mode = outmode;
1469 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1470 if (REG_NOTE_KIND (note) == REG_DEAD
1471 && GET_CODE (XEXP (note, 0)) == REG
1472 && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1473 && reg_mentioned_p (XEXP (note, 0), in)
1474 && ! refers_to_regno_for_reload_p (regno,
1475 (regno
1476 + HARD_REGNO_NREGS (regno,
1477 rel_mode)),
1478 PATTERN (this_insn), inloc)
1479 /* If this is also an output reload, IN cannot be used as
1480 the reload register if it is set in this insn unless IN
1481 is also OUT. */
1482 && (out == 0 || in == out
1483 || ! hard_reg_set_here_p (regno,
1484 (regno
1485 + HARD_REGNO_NREGS (regno,
1486 rel_mode)),
1487 PATTERN (this_insn)))
1488 /* ??? Why is this code so different from the previous?
1489 Is there any simple coherent way to describe the two together?
1490 What's going on here. */
1491 && (in != out
1492 || (GET_CODE (in) == SUBREG
1493 && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1))
1494 / UNITS_PER_WORD)
1495 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1496 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
1497 /* Make sure the operand fits in the reg that dies. */
1498 && (GET_MODE_SIZE (rel_mode)
1499 <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0))))
1500 && HARD_REGNO_MODE_OK (regno, inmode)
1501 && HARD_REGNO_MODE_OK (regno, outmode))
1503 unsigned int offs;
1504 unsigned int nregs = MAX (HARD_REGNO_NREGS (regno, inmode),
1505 HARD_REGNO_NREGS (regno, outmode));
1507 for (offs = 0; offs < nregs; offs++)
1508 if (fixed_regs[regno + offs]
1509 || ! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1510 regno + offs))
1511 break;
1513 if (offs == nregs)
1515 rld[i].reg_rtx = gen_rtx_REG (rel_mode, regno);
1516 break;
1521 if (out)
1522 output_reloadnum = i;
1524 return i;
1527 /* Record an additional place we must replace a value
1528 for which we have already recorded a reload.
1529 RELOADNUM is the value returned by push_reload
1530 when the reload was recorded.
1531 This is used in insn patterns that use match_dup. */
1533 static void
1534 push_replacement (loc, reloadnum, mode)
1535 rtx *loc;
1536 int reloadnum;
1537 enum machine_mode mode;
1539 if (replace_reloads)
1541 struct replacement *r = &replacements[n_replacements++];
1542 r->what = reloadnum;
1543 r->where = loc;
1544 r->subreg_loc = 0;
1545 r->mode = mode;
1549 /* Transfer all replacements that used to be in reload FROM to be in
1550 reload TO. */
1552 void
1553 transfer_replacements (to, from)
1554 int to, from;
1556 int i;
1558 for (i = 0; i < n_replacements; i++)
1559 if (replacements[i].what == from)
1560 replacements[i].what = to;
1563 /* IN_RTX is the value loaded by a reload that we now decided to inherit,
1564 or a subpart of it. If we have any replacements registered for IN_RTX,
1565 cancel the reloads that were supposed to load them.
1566 Return non-zero if we canceled any reloads. */
1568 remove_address_replacements (in_rtx)
1569 rtx in_rtx;
1571 int i, j;
1572 char reload_flags[MAX_RELOADS];
1573 int something_changed = 0;
1575 memset (reload_flags, 0, sizeof reload_flags);
1576 for (i = 0, j = 0; i < n_replacements; i++)
1578 if (loc_mentioned_in_p (replacements[i].where, in_rtx))
1579 reload_flags[replacements[i].what] |= 1;
1580 else
1582 replacements[j++] = replacements[i];
1583 reload_flags[replacements[i].what] |= 2;
1586 /* Note that the following store must be done before the recursive calls. */
1587 n_replacements = j;
1589 for (i = n_reloads - 1; i >= 0; i--)
1591 if (reload_flags[i] == 1)
1593 deallocate_reload_reg (i);
1594 remove_address_replacements (rld[i].in);
1595 rld[i].in = 0;
1596 something_changed = 1;
1599 return something_changed;
1602 /* If there is only one output reload, and it is not for an earlyclobber
1603 operand, try to combine it with a (logically unrelated) input reload
1604 to reduce the number of reload registers needed.
1606 This is safe if the input reload does not appear in
1607 the value being output-reloaded, because this implies
1608 it is not needed any more once the original insn completes.
1610 If that doesn't work, see we can use any of the registers that
1611 die in this insn as a reload register. We can if it is of the right
1612 class and does not appear in the value being output-reloaded. */
1614 static void
1615 combine_reloads ()
1617 int i;
1618 int output_reload = -1;
1619 int secondary_out = -1;
1620 rtx note;
1622 /* Find the output reload; return unless there is exactly one
1623 and that one is mandatory. */
1625 for (i = 0; i < n_reloads; i++)
1626 if (rld[i].out != 0)
1628 if (output_reload >= 0)
1629 return;
1630 output_reload = i;
1633 if (output_reload < 0 || rld[output_reload].optional)
1634 return;
1636 /* An input-output reload isn't combinable. */
1638 if (rld[output_reload].in != 0)
1639 return;
1641 /* If this reload is for an earlyclobber operand, we can't do anything. */
1642 if (earlyclobber_operand_p (rld[output_reload].out))
1643 return;
1645 /* If there is a reload for part of the address of this operand, we would
1646 need to chnage it to RELOAD_FOR_OTHER_ADDRESS. But that would extend
1647 its life to the point where doing this combine would not lower the
1648 number of spill registers needed. */
1649 for (i = 0; i < n_reloads; i++)
1650 if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
1651 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
1652 && rld[i].opnum == rld[output_reload].opnum)
1653 return;
1655 /* Check each input reload; can we combine it? */
1657 for (i = 0; i < n_reloads; i++)
1658 if (rld[i].in && ! rld[i].optional && ! rld[i].nocombine
1659 /* Life span of this reload must not extend past main insn. */
1660 && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS
1661 && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS
1662 && rld[i].when_needed != RELOAD_OTHER
1663 && (CLASS_MAX_NREGS (rld[i].class, rld[i].inmode)
1664 == CLASS_MAX_NREGS (rld[output_reload].class,
1665 rld[output_reload].outmode))
1666 && rld[i].inc == 0
1667 && rld[i].reg_rtx == 0
1668 #ifdef SECONDARY_MEMORY_NEEDED
1669 /* Don't combine two reloads with different secondary
1670 memory locations. */
1671 && (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum] == 0
1672 || secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] == 0
1673 || rtx_equal_p (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum],
1674 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum]))
1675 #endif
1676 && (SMALL_REGISTER_CLASSES
1677 ? (rld[i].class == rld[output_reload].class)
1678 : (reg_class_subset_p (rld[i].class,
1679 rld[output_reload].class)
1680 || reg_class_subset_p (rld[output_reload].class,
1681 rld[i].class)))
1682 && (MATCHES (rld[i].in, rld[output_reload].out)
1683 /* Args reversed because the first arg seems to be
1684 the one that we imagine being modified
1685 while the second is the one that might be affected. */
1686 || (! reg_overlap_mentioned_for_reload_p (rld[output_reload].out,
1687 rld[i].in)
1688 /* However, if the input is a register that appears inside
1689 the output, then we also can't share.
1690 Imagine (set (mem (reg 69)) (plus (reg 69) ...)).
1691 If the same reload reg is used for both reg 69 and the
1692 result to be stored in memory, then that result
1693 will clobber the address of the memory ref. */
1694 && ! (GET_CODE (rld[i].in) == REG
1695 && reg_overlap_mentioned_for_reload_p (rld[i].in,
1696 rld[output_reload].out))))
1697 && ! reload_inner_reg_of_subreg (rld[i].in, rld[i].inmode)
1698 && (reg_class_size[(int) rld[i].class]
1699 || SMALL_REGISTER_CLASSES)
1700 /* We will allow making things slightly worse by combining an
1701 input and an output, but no worse than that. */
1702 && (rld[i].when_needed == RELOAD_FOR_INPUT
1703 || rld[i].when_needed == RELOAD_FOR_OUTPUT))
1705 int j;
1707 /* We have found a reload to combine with! */
1708 rld[i].out = rld[output_reload].out;
1709 rld[i].out_reg = rld[output_reload].out_reg;
1710 rld[i].outmode = rld[output_reload].outmode;
1711 /* Mark the old output reload as inoperative. */
1712 rld[output_reload].out = 0;
1713 /* The combined reload is needed for the entire insn. */
1714 rld[i].when_needed = RELOAD_OTHER;
1715 /* If the output reload had a secondary reload, copy it. */
1716 if (rld[output_reload].secondary_out_reload != -1)
1718 rld[i].secondary_out_reload
1719 = rld[output_reload].secondary_out_reload;
1720 rld[i].secondary_out_icode
1721 = rld[output_reload].secondary_out_icode;
1724 #ifdef SECONDARY_MEMORY_NEEDED
1725 /* Copy any secondary MEM. */
1726 if (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] != 0)
1727 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum]
1728 = secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum];
1729 #endif
1730 /* If required, minimize the register class. */
1731 if (reg_class_subset_p (rld[output_reload].class,
1732 rld[i].class))
1733 rld[i].class = rld[output_reload].class;
1735 /* Transfer all replacements from the old reload to the combined. */
1736 for (j = 0; j < n_replacements; j++)
1737 if (replacements[j].what == output_reload)
1738 replacements[j].what = i;
1740 return;
1743 /* If this insn has only one operand that is modified or written (assumed
1744 to be the first), it must be the one corresponding to this reload. It
1745 is safe to use anything that dies in this insn for that output provided
1746 that it does not occur in the output (we already know it isn't an
1747 earlyclobber. If this is an asm insn, give up. */
1749 if (INSN_CODE (this_insn) == -1)
1750 return;
1752 for (i = 1; i < insn_data[INSN_CODE (this_insn)].n_operands; i++)
1753 if (insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '='
1754 || insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '+')
1755 return;
1757 /* See if some hard register that dies in this insn and is not used in
1758 the output is the right class. Only works if the register we pick
1759 up can fully hold our output reload. */
1760 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1761 if (REG_NOTE_KIND (note) == REG_DEAD
1762 && GET_CODE (XEXP (note, 0)) == REG
1763 && ! reg_overlap_mentioned_for_reload_p (XEXP (note, 0),
1764 rld[output_reload].out)
1765 && REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1766 && HARD_REGNO_MODE_OK (REGNO (XEXP (note, 0)), rld[output_reload].outmode)
1767 && TEST_HARD_REG_BIT (reg_class_contents[(int) rld[output_reload].class],
1768 REGNO (XEXP (note, 0)))
1769 && (HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), rld[output_reload].outmode)
1770 <= HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), GET_MODE (XEXP (note, 0))))
1771 /* Ensure that a secondary or tertiary reload for this output
1772 won't want this register. */
1773 && ((secondary_out = rld[output_reload].secondary_out_reload) == -1
1774 || (! (TEST_HARD_REG_BIT
1775 (reg_class_contents[(int) rld[secondary_out].class],
1776 REGNO (XEXP (note, 0))))
1777 && ((secondary_out = rld[secondary_out].secondary_out_reload) == -1
1778 || ! (TEST_HARD_REG_BIT
1779 (reg_class_contents[(int) rld[secondary_out].class],
1780 REGNO (XEXP (note, 0)))))))
1781 && ! fixed_regs[REGNO (XEXP (note, 0))])
1783 rld[output_reload].reg_rtx
1784 = gen_rtx_REG (rld[output_reload].outmode,
1785 REGNO (XEXP (note, 0)));
1786 return;
1790 /* Try to find a reload register for an in-out reload (expressions IN and OUT).
1791 See if one of IN and OUT is a register that may be used;
1792 this is desirable since a spill-register won't be needed.
1793 If so, return the register rtx that proves acceptable.
1795 INLOC and OUTLOC are locations where IN and OUT appear in the insn.
1796 CLASS is the register class required for the reload.
1798 If FOR_REAL is >= 0, it is the number of the reload,
1799 and in some cases when it can be discovered that OUT doesn't need
1800 to be computed, clear out rld[FOR_REAL].out.
1802 If FOR_REAL is -1, this should not be done, because this call
1803 is just to see if a register can be found, not to find and install it.
1805 EARLYCLOBBER is non-zero if OUT is an earlyclobber operand. This
1806 puts an additional constraint on being able to use IN for OUT since
1807 IN must not appear elsewhere in the insn (it is assumed that IN itself
1808 is safe from the earlyclobber). */
1810 static rtx
1811 find_dummy_reload (real_in, real_out, inloc, outloc,
1812 inmode, outmode, class, for_real, earlyclobber)
1813 rtx real_in, real_out;
1814 rtx *inloc, *outloc;
1815 enum machine_mode inmode, outmode;
1816 enum reg_class class;
1817 int for_real;
1818 int earlyclobber;
1820 rtx in = real_in;
1821 rtx out = real_out;
1822 int in_offset = 0;
1823 int out_offset = 0;
1824 rtx value = 0;
1826 /* If operands exceed a word, we can't use either of them
1827 unless they have the same size. */
1828 if (GET_MODE_SIZE (outmode) != GET_MODE_SIZE (inmode)
1829 && (GET_MODE_SIZE (outmode) > UNITS_PER_WORD
1830 || GET_MODE_SIZE (inmode) > UNITS_PER_WORD))
1831 return 0;
1833 /* Note that {in,out}_offset are needed only when 'in' or 'out'
1834 respectively refers to a hard register. */
1836 /* Find the inside of any subregs. */
1837 while (GET_CODE (out) == SUBREG)
1839 if (GET_CODE (SUBREG_REG (out)) == REG
1840 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER)
1841 out_offset += subreg_regno_offset (REGNO (SUBREG_REG (out)),
1842 GET_MODE (SUBREG_REG (out)),
1843 SUBREG_BYTE (out),
1844 GET_MODE (out));
1845 out = SUBREG_REG (out);
1847 while (GET_CODE (in) == SUBREG)
1849 if (GET_CODE (SUBREG_REG (in)) == REG
1850 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER)
1851 in_offset += subreg_regno_offset (REGNO (SUBREG_REG (in)),
1852 GET_MODE (SUBREG_REG (in)),
1853 SUBREG_BYTE (in),
1854 GET_MODE (in));
1855 in = SUBREG_REG (in);
1858 /* Narrow down the reg class, the same way push_reload will;
1859 otherwise we might find a dummy now, but push_reload won't. */
1860 class = PREFERRED_RELOAD_CLASS (in, class);
1862 /* See if OUT will do. */
1863 if (GET_CODE (out) == REG
1864 && REGNO (out) < FIRST_PSEUDO_REGISTER)
1866 unsigned int regno = REGNO (out) + out_offset;
1867 unsigned int nwords = HARD_REGNO_NREGS (regno, outmode);
1868 rtx saved_rtx;
1870 /* When we consider whether the insn uses OUT,
1871 ignore references within IN. They don't prevent us
1872 from copying IN into OUT, because those refs would
1873 move into the insn that reloads IN.
1875 However, we only ignore IN in its role as this reload.
1876 If the insn uses IN elsewhere and it contains OUT,
1877 that counts. We can't be sure it's the "same" operand
1878 so it might not go through this reload. */
1879 saved_rtx = *inloc;
1880 *inloc = const0_rtx;
1882 if (regno < FIRST_PSEUDO_REGISTER
1883 && HARD_REGNO_MODE_OK (regno, outmode)
1884 && ! refers_to_regno_for_reload_p (regno, regno + nwords,
1885 PATTERN (this_insn), outloc))
1887 unsigned int i;
1889 for (i = 0; i < nwords; i++)
1890 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1891 regno + i))
1892 break;
1894 if (i == nwords)
1896 if (GET_CODE (real_out) == REG)
1897 value = real_out;
1898 else
1899 value = gen_rtx_REG (outmode, regno);
1903 *inloc = saved_rtx;
1906 /* Consider using IN if OUT was not acceptable
1907 or if OUT dies in this insn (like the quotient in a divmod insn).
1908 We can't use IN unless it is dies in this insn,
1909 which means we must know accurately which hard regs are live.
1910 Also, the result can't go in IN if IN is used within OUT,
1911 or if OUT is an earlyclobber and IN appears elsewhere in the insn. */
1912 if (hard_regs_live_known
1913 && GET_CODE (in) == REG
1914 && REGNO (in) < FIRST_PSEUDO_REGISTER
1915 && (value == 0
1916 || find_reg_note (this_insn, REG_UNUSED, real_out))
1917 && find_reg_note (this_insn, REG_DEAD, real_in)
1918 && !fixed_regs[REGNO (in)]
1919 && HARD_REGNO_MODE_OK (REGNO (in),
1920 /* The only case where out and real_out might
1921 have different modes is where real_out
1922 is a subreg, and in that case, out
1923 has a real mode. */
1924 (GET_MODE (out) != VOIDmode
1925 ? GET_MODE (out) : outmode)))
1927 unsigned int regno = REGNO (in) + in_offset;
1928 unsigned int nwords = HARD_REGNO_NREGS (regno, inmode);
1930 if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, (rtx*) 0)
1931 && ! hard_reg_set_here_p (regno, regno + nwords,
1932 PATTERN (this_insn))
1933 && (! earlyclobber
1934 || ! refers_to_regno_for_reload_p (regno, regno + nwords,
1935 PATTERN (this_insn), inloc)))
1937 unsigned int i;
1939 for (i = 0; i < nwords; i++)
1940 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1941 regno + i))
1942 break;
1944 if (i == nwords)
1946 /* If we were going to use OUT as the reload reg
1947 and changed our mind, it means OUT is a dummy that
1948 dies here. So don't bother copying value to it. */
1949 if (for_real >= 0 && value == real_out)
1950 rld[for_real].out = 0;
1951 if (GET_CODE (real_in) == REG)
1952 value = real_in;
1953 else
1954 value = gen_rtx_REG (inmode, regno);
1959 return value;
1962 /* This page contains subroutines used mainly for determining
1963 whether the IN or an OUT of a reload can serve as the
1964 reload register. */
1966 /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
1969 earlyclobber_operand_p (x)
1970 rtx x;
1972 int i;
1974 for (i = 0; i < n_earlyclobbers; i++)
1975 if (reload_earlyclobbers[i] == x)
1976 return 1;
1978 return 0;
1981 /* Return 1 if expression X alters a hard reg in the range
1982 from BEG_REGNO (inclusive) to END_REGNO (exclusive),
1983 either explicitly or in the guise of a pseudo-reg allocated to REGNO.
1984 X should be the body of an instruction. */
1986 static int
1987 hard_reg_set_here_p (beg_regno, end_regno, x)
1988 unsigned int beg_regno, end_regno;
1989 rtx x;
1991 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
1993 rtx op0 = SET_DEST (x);
1995 while (GET_CODE (op0) == SUBREG)
1996 op0 = SUBREG_REG (op0);
1997 if (GET_CODE (op0) == REG)
1999 unsigned int r = REGNO (op0);
2001 /* See if this reg overlaps range under consideration. */
2002 if (r < end_regno
2003 && r + HARD_REGNO_NREGS (r, GET_MODE (op0)) > beg_regno)
2004 return 1;
2007 else if (GET_CODE (x) == PARALLEL)
2009 int i = XVECLEN (x, 0) - 1;
2011 for (; i >= 0; i--)
2012 if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i)))
2013 return 1;
2016 return 0;
2019 /* Return 1 if ADDR is a valid memory address for mode MODE,
2020 and check that each pseudo reg has the proper kind of
2021 hard reg. */
2024 strict_memory_address_p (mode, addr)
2025 enum machine_mode mode ATTRIBUTE_UNUSED;
2026 rtx addr;
2028 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
2029 return 0;
2031 win:
2032 return 1;
2035 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
2036 if they are the same hard reg, and has special hacks for
2037 autoincrement and autodecrement.
2038 This is specifically intended for find_reloads to use
2039 in determining whether two operands match.
2040 X is the operand whose number is the lower of the two.
2042 The value is 2 if Y contains a pre-increment that matches
2043 a non-incrementing address in X. */
2045 /* ??? To be completely correct, we should arrange to pass
2046 for X the output operand and for Y the input operand.
2047 For now, we assume that the output operand has the lower number
2048 because that is natural in (SET output (... input ...)). */
2051 operands_match_p (x, y)
2052 rtx x, y;
2054 int i;
2055 RTX_CODE code = GET_CODE (x);
2056 const char *fmt;
2057 int success_2;
2059 if (x == y)
2060 return 1;
2061 if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
2062 && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
2063 && GET_CODE (SUBREG_REG (y)) == REG)))
2065 int j;
2067 if (code == SUBREG)
2069 i = REGNO (SUBREG_REG (x));
2070 if (i >= FIRST_PSEUDO_REGISTER)
2071 goto slow;
2072 i += subreg_regno_offset (REGNO (SUBREG_REG (x)),
2073 GET_MODE (SUBREG_REG (x)),
2074 SUBREG_BYTE (x),
2075 GET_MODE (x));
2077 else
2078 i = REGNO (x);
2080 if (GET_CODE (y) == SUBREG)
2082 j = REGNO (SUBREG_REG (y));
2083 if (j >= FIRST_PSEUDO_REGISTER)
2084 goto slow;
2085 j += subreg_regno_offset (REGNO (SUBREG_REG (y)),
2086 GET_MODE (SUBREG_REG (y)),
2087 SUBREG_BYTE (y),
2088 GET_MODE (y));
2090 else
2091 j = REGNO (y);
2093 /* On a WORDS_BIG_ENDIAN machine, point to the last register of a
2094 multiple hard register group, so that for example (reg:DI 0) and
2095 (reg:SI 1) will be considered the same register. */
2096 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
2097 && i < FIRST_PSEUDO_REGISTER)
2098 i += (GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD) - 1;
2099 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD
2100 && j < FIRST_PSEUDO_REGISTER)
2101 j += (GET_MODE_SIZE (GET_MODE (y)) / UNITS_PER_WORD) - 1;
2103 return i == j;
2105 /* If two operands must match, because they are really a single
2106 operand of an assembler insn, then two postincrements are invalid
2107 because the assembler insn would increment only once.
2108 On the other hand, an postincrement matches ordinary indexing
2109 if the postincrement is the output operand. */
2110 if (code == POST_DEC || code == POST_INC || code == POST_MODIFY)
2111 return operands_match_p (XEXP (x, 0), y);
2112 /* Two preincrements are invalid
2113 because the assembler insn would increment only once.
2114 On the other hand, an preincrement matches ordinary indexing
2115 if the preincrement is the input operand.
2116 In this case, return 2, since some callers need to do special
2117 things when this happens. */
2118 if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC
2119 || GET_CODE (y) == PRE_MODIFY)
2120 return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
2122 slow:
2124 /* Now we have disposed of all the cases
2125 in which different rtx codes can match. */
2126 if (code != GET_CODE (y))
2127 return 0;
2128 if (code == LABEL_REF)
2129 return XEXP (x, 0) == XEXP (y, 0);
2130 if (code == SYMBOL_REF)
2131 return XSTR (x, 0) == XSTR (y, 0);
2133 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
2135 if (GET_MODE (x) != GET_MODE (y))
2136 return 0;
2138 /* Compare the elements. If any pair of corresponding elements
2139 fail to match, return 0 for the whole things. */
2141 success_2 = 0;
2142 fmt = GET_RTX_FORMAT (code);
2143 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2145 int val, j;
2146 switch (fmt[i])
2148 case 'w':
2149 if (XWINT (x, i) != XWINT (y, i))
2150 return 0;
2151 break;
2153 case 'i':
2154 if (XINT (x, i) != XINT (y, i))
2155 return 0;
2156 break;
2158 case 'e':
2159 val = operands_match_p (XEXP (x, i), XEXP (y, i));
2160 if (val == 0)
2161 return 0;
2162 /* If any subexpression returns 2,
2163 we should return 2 if we are successful. */
2164 if (val == 2)
2165 success_2 = 1;
2166 break;
2168 case '0':
2169 break;
2171 case 'E':
2172 if (XVECLEN (x, i) != XVECLEN (y, i))
2173 return 0;
2174 for (j = XVECLEN (x, i) - 1; j >= 0; --j)
2176 val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j));
2177 if (val == 0)
2178 return 0;
2179 if (val == 2)
2180 success_2 = 1;
2182 break;
2184 /* It is believed that rtx's at this level will never
2185 contain anything but integers and other rtx's,
2186 except for within LABEL_REFs and SYMBOL_REFs. */
2187 default:
2188 abort ();
2191 return 1 + success_2;
2194 /* Describe the range of registers or memory referenced by X.
2195 If X is a register, set REG_FLAG and put the first register
2196 number into START and the last plus one into END.
2197 If X is a memory reference, put a base address into BASE
2198 and a range of integer offsets into START and END.
2199 If X is pushing on the stack, we can assume it causes no trouble,
2200 so we set the SAFE field. */
2202 static struct decomposition
2203 decompose (x)
2204 rtx x;
2206 struct decomposition val;
2207 int all_const = 0;
2209 val.reg_flag = 0;
2210 val.safe = 0;
2211 val.base = 0;
2212 if (GET_CODE (x) == MEM)
2214 rtx base = NULL_RTX, offset = 0;
2215 rtx addr = XEXP (x, 0);
2217 if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
2218 || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
2220 val.base = XEXP (addr, 0);
2221 val.start = -GET_MODE_SIZE (GET_MODE (x));
2222 val.end = GET_MODE_SIZE (GET_MODE (x));
2223 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2224 return val;
2227 if (GET_CODE (addr) == PRE_MODIFY || GET_CODE (addr) == POST_MODIFY)
2229 if (GET_CODE (XEXP (addr, 1)) == PLUS
2230 && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
2231 && CONSTANT_P (XEXP (XEXP (addr, 1), 1)))
2233 val.base = XEXP (addr, 0);
2234 val.start = -INTVAL (XEXP (XEXP (addr, 1), 1));
2235 val.end = INTVAL (XEXP (XEXP (addr, 1), 1));
2236 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2237 return val;
2241 if (GET_CODE (addr) == CONST)
2243 addr = XEXP (addr, 0);
2244 all_const = 1;
2246 if (GET_CODE (addr) == PLUS)
2248 if (CONSTANT_P (XEXP (addr, 0)))
2250 base = XEXP (addr, 1);
2251 offset = XEXP (addr, 0);
2253 else if (CONSTANT_P (XEXP (addr, 1)))
2255 base = XEXP (addr, 0);
2256 offset = XEXP (addr, 1);
2260 if (offset == 0)
2262 base = addr;
2263 offset = const0_rtx;
2265 if (GET_CODE (offset) == CONST)
2266 offset = XEXP (offset, 0);
2267 if (GET_CODE (offset) == PLUS)
2269 if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
2271 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 1));
2272 offset = XEXP (offset, 0);
2274 else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
2276 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 0));
2277 offset = XEXP (offset, 1);
2279 else
2281 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2282 offset = const0_rtx;
2285 else if (GET_CODE (offset) != CONST_INT)
2287 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2288 offset = const0_rtx;
2291 if (all_const && GET_CODE (base) == PLUS)
2292 base = gen_rtx_CONST (GET_MODE (base), base);
2294 if (GET_CODE (offset) != CONST_INT)
2295 abort ();
2297 val.start = INTVAL (offset);
2298 val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
2299 val.base = base;
2300 return val;
2302 else if (GET_CODE (x) == REG)
2304 val.reg_flag = 1;
2305 val.start = true_regnum (x);
2306 if (val.start < 0)
2308 /* A pseudo with no hard reg. */
2309 val.start = REGNO (x);
2310 val.end = val.start + 1;
2312 else
2313 /* A hard reg. */
2314 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2316 else if (GET_CODE (x) == SUBREG)
2318 if (GET_CODE (SUBREG_REG (x)) != REG)
2319 /* This could be more precise, but it's good enough. */
2320 return decompose (SUBREG_REG (x));
2321 val.reg_flag = 1;
2322 val.start = true_regnum (x);
2323 if (val.start < 0)
2324 return decompose (SUBREG_REG (x));
2325 else
2326 /* A hard reg. */
2327 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2329 else if (CONSTANT_P (x)
2330 /* This hasn't been assigned yet, so it can't conflict yet. */
2331 || GET_CODE (x) == SCRATCH)
2332 val.safe = 1;
2333 else
2334 abort ();
2335 return val;
2338 /* Return 1 if altering Y will not modify the value of X.
2339 Y is also described by YDATA, which should be decompose (Y). */
2341 static int
2342 immune_p (x, y, ydata)
2343 rtx x, y;
2344 struct decomposition ydata;
2346 struct decomposition xdata;
2348 if (ydata.reg_flag)
2349 return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, (rtx*) 0);
2350 if (ydata.safe)
2351 return 1;
2353 if (GET_CODE (y) != MEM)
2354 abort ();
2355 /* If Y is memory and X is not, Y can't affect X. */
2356 if (GET_CODE (x) != MEM)
2357 return 1;
2359 xdata = decompose (x);
2361 if (! rtx_equal_p (xdata.base, ydata.base))
2363 /* If bases are distinct symbolic constants, there is no overlap. */
2364 if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
2365 return 1;
2366 /* Constants and stack slots never overlap. */
2367 if (CONSTANT_P (xdata.base)
2368 && (ydata.base == frame_pointer_rtx
2369 || ydata.base == hard_frame_pointer_rtx
2370 || ydata.base == stack_pointer_rtx))
2371 return 1;
2372 if (CONSTANT_P (ydata.base)
2373 && (xdata.base == frame_pointer_rtx
2374 || xdata.base == hard_frame_pointer_rtx
2375 || xdata.base == stack_pointer_rtx))
2376 return 1;
2377 /* If either base is variable, we don't know anything. */
2378 return 0;
2381 return (xdata.start >= ydata.end || ydata.start >= xdata.end);
2384 /* Similar, but calls decompose. */
2387 safe_from_earlyclobber (op, clobber)
2388 rtx op, clobber;
2390 struct decomposition early_data;
2392 early_data = decompose (clobber);
2393 return immune_p (op, clobber, early_data);
2396 /* Main entry point of this file: search the body of INSN
2397 for values that need reloading and record them with push_reload.
2398 REPLACE nonzero means record also where the values occur
2399 so that subst_reloads can be used.
2401 IND_LEVELS says how many levels of indirection are supported by this
2402 machine; a value of zero means that a memory reference is not a valid
2403 memory address.
2405 LIVE_KNOWN says we have valid information about which hard
2406 regs are live at each point in the program; this is true when
2407 we are called from global_alloc but false when stupid register
2408 allocation has been done.
2410 RELOAD_REG_P if nonzero is a vector indexed by hard reg number
2411 which is nonnegative if the reg has been commandeered for reloading into.
2412 It is copied into STATIC_RELOAD_REG_P and referenced from there
2413 by various subroutines.
2415 Return TRUE if some operands need to be changed, because of swapping
2416 commutative operands, reg_equiv_address substitution, or whatever. */
2419 find_reloads (insn, replace, ind_levels, live_known, reload_reg_p)
2420 rtx insn;
2421 int replace, ind_levels;
2422 int live_known;
2423 short *reload_reg_p;
2425 int insn_code_number;
2426 int i, j;
2427 int noperands;
2428 /* These start out as the constraints for the insn
2429 and they are chewed up as we consider alternatives. */
2430 char *constraints[MAX_RECOG_OPERANDS];
2431 /* These are the preferred classes for an operand, or NO_REGS if it isn't
2432 a register. */
2433 enum reg_class preferred_class[MAX_RECOG_OPERANDS];
2434 char pref_or_nothing[MAX_RECOG_OPERANDS];
2435 /* Nonzero for a MEM operand whose entire address needs a reload. */
2436 int address_reloaded[MAX_RECOG_OPERANDS];
2437 /* Value of enum reload_type to use for operand. */
2438 enum reload_type operand_type[MAX_RECOG_OPERANDS];
2439 /* Value of enum reload_type to use within address of operand. */
2440 enum reload_type address_type[MAX_RECOG_OPERANDS];
2441 /* Save the usage of each operand. */
2442 enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS];
2443 int no_input_reloads = 0, no_output_reloads = 0;
2444 int n_alternatives;
2445 int this_alternative[MAX_RECOG_OPERANDS];
2446 char this_alternative_match_win[MAX_RECOG_OPERANDS];
2447 char this_alternative_win[MAX_RECOG_OPERANDS];
2448 char this_alternative_offmemok[MAX_RECOG_OPERANDS];
2449 char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2450 int this_alternative_matches[MAX_RECOG_OPERANDS];
2451 int swapped;
2452 int goal_alternative[MAX_RECOG_OPERANDS];
2453 int this_alternative_number;
2454 int goal_alternative_number = 0;
2455 int operand_reloadnum[MAX_RECOG_OPERANDS];
2456 int goal_alternative_matches[MAX_RECOG_OPERANDS];
2457 int goal_alternative_matched[MAX_RECOG_OPERANDS];
2458 char goal_alternative_match_win[MAX_RECOG_OPERANDS];
2459 char goal_alternative_win[MAX_RECOG_OPERANDS];
2460 char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
2461 char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2462 int goal_alternative_swapped;
2463 int best;
2464 int commutative;
2465 char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
2466 rtx substed_operand[MAX_RECOG_OPERANDS];
2467 rtx body = PATTERN (insn);
2468 rtx set = single_set (insn);
2469 int goal_earlyclobber = 0, this_earlyclobber;
2470 enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
2471 int retval = 0;
2473 this_insn = insn;
2474 n_reloads = 0;
2475 n_replacements = 0;
2476 n_earlyclobbers = 0;
2477 replace_reloads = replace;
2478 hard_regs_live_known = live_known;
2479 static_reload_reg_p = reload_reg_p;
2481 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
2482 neither are insns that SET cc0. Insns that use CC0 are not allowed
2483 to have any input reloads. */
2484 if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == CALL_INSN)
2485 no_output_reloads = 1;
2487 #ifdef HAVE_cc0
2488 if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
2489 no_input_reloads = 1;
2490 if (reg_set_p (cc0_rtx, PATTERN (insn)))
2491 no_output_reloads = 1;
2492 #endif
2494 #ifdef SECONDARY_MEMORY_NEEDED
2495 /* The eliminated forms of any secondary memory locations are per-insn, so
2496 clear them out here. */
2498 memset ((char *) secondary_memlocs_elim, 0, sizeof secondary_memlocs_elim);
2499 #endif
2501 /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2502 is cheap to move between them. If it is not, there may not be an insn
2503 to do the copy, so we may need a reload. */
2504 if (GET_CODE (body) == SET
2505 && GET_CODE (SET_DEST (body)) == REG
2506 && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2507 && GET_CODE (SET_SRC (body)) == REG
2508 && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2509 && REGISTER_MOVE_COST (GET_MODE (SET_SRC (body)),
2510 REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2511 REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2512 return 0;
2514 extract_insn (insn);
2516 noperands = reload_n_operands = recog_data.n_operands;
2517 n_alternatives = recog_data.n_alternatives;
2519 /* Just return "no reloads" if insn has no operands with constraints. */
2520 if (noperands == 0 || n_alternatives == 0)
2521 return 0;
2523 insn_code_number = INSN_CODE (insn);
2524 this_insn_is_asm = insn_code_number < 0;
2526 memcpy (operand_mode, recog_data.operand_mode,
2527 noperands * sizeof (enum machine_mode));
2528 memcpy (constraints, recog_data.constraints, noperands * sizeof (char *));
2530 commutative = -1;
2532 /* If we will need to know, later, whether some pair of operands
2533 are the same, we must compare them now and save the result.
2534 Reloading the base and index registers will clobber them
2535 and afterward they will fail to match. */
2537 for (i = 0; i < noperands; i++)
2539 char *p;
2540 int c;
2542 substed_operand[i] = recog_data.operand[i];
2543 p = constraints[i];
2545 modified[i] = RELOAD_READ;
2547 /* Scan this operand's constraint to see if it is an output operand,
2548 an in-out operand, is commutative, or should match another. */
2550 while ((c = *p++))
2552 if (c == '=')
2553 modified[i] = RELOAD_WRITE;
2554 else if (c == '+')
2555 modified[i] = RELOAD_READ_WRITE;
2556 else if (c == '%')
2558 /* The last operand should not be marked commutative. */
2559 if (i == noperands - 1)
2560 abort ();
2562 commutative = i;
2564 else if (ISDIGIT (c))
2566 c = strtoul (p - 1, &p, 10);
2568 operands_match[c][i]
2569 = operands_match_p (recog_data.operand[c],
2570 recog_data.operand[i]);
2572 /* An operand may not match itself. */
2573 if (c == i)
2574 abort ();
2576 /* If C can be commuted with C+1, and C might need to match I,
2577 then C+1 might also need to match I. */
2578 if (commutative >= 0)
2580 if (c == commutative || c == commutative + 1)
2582 int other = c + (c == commutative ? 1 : -1);
2583 operands_match[other][i]
2584 = operands_match_p (recog_data.operand[other],
2585 recog_data.operand[i]);
2587 if (i == commutative || i == commutative + 1)
2589 int other = i + (i == commutative ? 1 : -1);
2590 operands_match[c][other]
2591 = operands_match_p (recog_data.operand[c],
2592 recog_data.operand[other]);
2594 /* Note that C is supposed to be less than I.
2595 No need to consider altering both C and I because in
2596 that case we would alter one into the other. */
2602 /* Examine each operand that is a memory reference or memory address
2603 and reload parts of the addresses into index registers.
2604 Also here any references to pseudo regs that didn't get hard regs
2605 but are equivalent to constants get replaced in the insn itself
2606 with those constants. Nobody will ever see them again.
2608 Finally, set up the preferred classes of each operand. */
2610 for (i = 0; i < noperands; i++)
2612 RTX_CODE code = GET_CODE (recog_data.operand[i]);
2614 address_reloaded[i] = 0;
2615 operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT
2616 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT
2617 : RELOAD_OTHER);
2618 address_type[i]
2619 = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS
2620 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS
2621 : RELOAD_OTHER);
2623 if (*constraints[i] == 0)
2624 /* Ignore things like match_operator operands. */
2626 else if (constraints[i][0] == 'p')
2628 find_reloads_address (VOIDmode, (rtx*) 0,
2629 recog_data.operand[i],
2630 recog_data.operand_loc[i],
2631 i, operand_type[i], ind_levels, insn);
2633 /* If we now have a simple operand where we used to have a
2634 PLUS or MULT, re-recognize and try again. */
2635 if ((GET_RTX_CLASS (GET_CODE (*recog_data.operand_loc[i])) == 'o'
2636 || GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
2637 && (GET_CODE (recog_data.operand[i]) == MULT
2638 || GET_CODE (recog_data.operand[i]) == PLUS))
2640 INSN_CODE (insn) = -1;
2641 retval = find_reloads (insn, replace, ind_levels, live_known,
2642 reload_reg_p);
2643 return retval;
2646 recog_data.operand[i] = *recog_data.operand_loc[i];
2647 substed_operand[i] = recog_data.operand[i];
2649 else if (code == MEM)
2651 address_reloaded[i]
2652 = find_reloads_address (GET_MODE (recog_data.operand[i]),
2653 recog_data.operand_loc[i],
2654 XEXP (recog_data.operand[i], 0),
2655 &XEXP (recog_data.operand[i], 0),
2656 i, address_type[i], ind_levels, insn);
2657 recog_data.operand[i] = *recog_data.operand_loc[i];
2658 substed_operand[i] = recog_data.operand[i];
2660 else if (code == SUBREG)
2662 rtx reg = SUBREG_REG (recog_data.operand[i]);
2663 rtx op
2664 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2665 ind_levels,
2666 set != 0
2667 && &SET_DEST (set) == recog_data.operand_loc[i],
2668 insn,
2669 &address_reloaded[i]);
2671 /* If we made a MEM to load (a part of) the stackslot of a pseudo
2672 that didn't get a hard register, emit a USE with a REG_EQUAL
2673 note in front so that we might inherit a previous, possibly
2674 wider reload. */
2676 if (replace
2677 && GET_CODE (op) == MEM
2678 && GET_CODE (reg) == REG
2679 && (GET_MODE_SIZE (GET_MODE (reg))
2680 >= GET_MODE_SIZE (GET_MODE (op))))
2681 set_unique_reg_note (emit_insn_before (gen_rtx_USE (VOIDmode, reg),
2682 insn),
2683 REG_EQUAL, reg_equiv_memory_loc[REGNO (reg)]);
2685 substed_operand[i] = recog_data.operand[i] = op;
2687 else if (code == PLUS || GET_RTX_CLASS (code) == '1')
2688 /* We can get a PLUS as an "operand" as a result of register
2689 elimination. See eliminate_regs and gen_reload. We handle
2690 a unary operator by reloading the operand. */
2691 substed_operand[i] = recog_data.operand[i]
2692 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2693 ind_levels, 0, insn,
2694 &address_reloaded[i]);
2695 else if (code == REG)
2697 /* This is equivalent to calling find_reloads_toplev.
2698 The code is duplicated for speed.
2699 When we find a pseudo always equivalent to a constant,
2700 we replace it by the constant. We must be sure, however,
2701 that we don't try to replace it in the insn in which it
2702 is being set. */
2703 int regno = REGNO (recog_data.operand[i]);
2704 if (reg_equiv_constant[regno] != 0
2705 && (set == 0 || &SET_DEST (set) != recog_data.operand_loc[i]))
2707 /* Record the existing mode so that the check if constants are
2708 allowed will work when operand_mode isn't specified. */
2710 if (operand_mode[i] == VOIDmode)
2711 operand_mode[i] = GET_MODE (recog_data.operand[i]);
2713 substed_operand[i] = recog_data.operand[i]
2714 = reg_equiv_constant[regno];
2716 if (reg_equiv_memory_loc[regno] != 0
2717 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
2718 /* We need not give a valid is_set_dest argument since the case
2719 of a constant equivalence was checked above. */
2720 substed_operand[i] = recog_data.operand[i]
2721 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2722 ind_levels, 0, insn,
2723 &address_reloaded[i]);
2725 /* If the operand is still a register (we didn't replace it with an
2726 equivalent), get the preferred class to reload it into. */
2727 code = GET_CODE (recog_data.operand[i]);
2728 preferred_class[i]
2729 = ((code == REG && REGNO (recog_data.operand[i])
2730 >= FIRST_PSEUDO_REGISTER)
2731 ? reg_preferred_class (REGNO (recog_data.operand[i]))
2732 : NO_REGS);
2733 pref_or_nothing[i]
2734 = (code == REG
2735 && REGNO (recog_data.operand[i]) >= FIRST_PSEUDO_REGISTER
2736 && reg_alternate_class (REGNO (recog_data.operand[i])) == NO_REGS);
2739 /* If this is simply a copy from operand 1 to operand 0, merge the
2740 preferred classes for the operands. */
2741 if (set != 0 && noperands >= 2 && recog_data.operand[0] == SET_DEST (set)
2742 && recog_data.operand[1] == SET_SRC (set))
2744 preferred_class[0] = preferred_class[1]
2745 = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2746 pref_or_nothing[0] |= pref_or_nothing[1];
2747 pref_or_nothing[1] |= pref_or_nothing[0];
2750 /* Now see what we need for pseudo-regs that didn't get hard regs
2751 or got the wrong kind of hard reg. For this, we must consider
2752 all the operands together against the register constraints. */
2754 best = MAX_RECOG_OPERANDS * 2 + 600;
2756 swapped = 0;
2757 goal_alternative_swapped = 0;
2758 try_swapped:
2760 /* The constraints are made of several alternatives.
2761 Each operand's constraint looks like foo,bar,... with commas
2762 separating the alternatives. The first alternatives for all
2763 operands go together, the second alternatives go together, etc.
2765 First loop over alternatives. */
2767 for (this_alternative_number = 0;
2768 this_alternative_number < n_alternatives;
2769 this_alternative_number++)
2771 /* Loop over operands for one constraint alternative. */
2772 /* LOSERS counts those that don't fit this alternative
2773 and would require loading. */
2774 int losers = 0;
2775 /* BAD is set to 1 if it some operand can't fit this alternative
2776 even after reloading. */
2777 int bad = 0;
2778 /* REJECT is a count of how undesirable this alternative says it is
2779 if any reloading is required. If the alternative matches exactly
2780 then REJECT is ignored, but otherwise it gets this much
2781 counted against it in addition to the reloading needed. Each
2782 ? counts three times here since we want the disparaging caused by
2783 a bad register class to only count 1/3 as much. */
2784 int reject = 0;
2786 this_earlyclobber = 0;
2788 for (i = 0; i < noperands; i++)
2790 char *p = constraints[i];
2791 int win = 0;
2792 int did_match = 0;
2793 /* 0 => this operand can be reloaded somehow for this alternative. */
2794 int badop = 1;
2795 /* 0 => this operand can be reloaded if the alternative allows regs. */
2796 int winreg = 0;
2797 int c;
2798 rtx operand = recog_data.operand[i];
2799 int offset = 0;
2800 /* Nonzero means this is a MEM that must be reloaded into a reg
2801 regardless of what the constraint says. */
2802 int force_reload = 0;
2803 int offmemok = 0;
2804 /* Nonzero if a constant forced into memory would be OK for this
2805 operand. */
2806 int constmemok = 0;
2807 int earlyclobber = 0;
2809 /* If the predicate accepts a unary operator, it means that
2810 we need to reload the operand, but do not do this for
2811 match_operator and friends. */
2812 if (GET_RTX_CLASS (GET_CODE (operand)) == '1' && *p != 0)
2813 operand = XEXP (operand, 0);
2815 /* If the operand is a SUBREG, extract
2816 the REG or MEM (or maybe even a constant) within.
2817 (Constants can occur as a result of reg_equiv_constant.) */
2819 while (GET_CODE (operand) == SUBREG)
2821 /* Offset only matters when operand is a REG and
2822 it is a hard reg. This is because it is passed
2823 to reg_fits_class_p if it is a REG and all pseudos
2824 return 0 from that function. */
2825 if (GET_CODE (SUBREG_REG (operand)) == REG
2826 && REGNO (SUBREG_REG (operand)) < FIRST_PSEUDO_REGISTER)
2828 offset += subreg_regno_offset (REGNO (SUBREG_REG (operand)),
2829 GET_MODE (SUBREG_REG (operand)),
2830 SUBREG_BYTE (operand),
2831 GET_MODE (operand));
2833 operand = SUBREG_REG (operand);
2834 /* Force reload if this is a constant or PLUS or if there may
2835 be a problem accessing OPERAND in the outer mode. */
2836 if (CONSTANT_P (operand)
2837 || GET_CODE (operand) == PLUS
2838 /* We must force a reload of paradoxical SUBREGs
2839 of a MEM because the alignment of the inner value
2840 may not be enough to do the outer reference. On
2841 big-endian machines, it may also reference outside
2842 the object.
2844 On machines that extend byte operations and we have a
2845 SUBREG where both the inner and outer modes are no wider
2846 than a word and the inner mode is narrower, is integral,
2847 and gets extended when loaded from memory, combine.c has
2848 made assumptions about the behavior of the machine in such
2849 register access. If the data is, in fact, in memory we
2850 must always load using the size assumed to be in the
2851 register and let the insn do the different-sized
2852 accesses.
2854 This is doubly true if WORD_REGISTER_OPERATIONS. In
2855 this case eliminate_regs has left non-paradoxical
2856 subregs for push_reloads to see. Make sure it does
2857 by forcing the reload.
2859 ??? When is it right at this stage to have a subreg
2860 of a mem that is _not_ to be handled specialy? IMO
2861 those should have been reduced to just a mem. */
2862 || ((GET_CODE (operand) == MEM
2863 || (GET_CODE (operand)== REG
2864 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
2865 #ifndef WORD_REGISTER_OPERATIONS
2866 && (((GET_MODE_BITSIZE (GET_MODE (operand))
2867 < BIGGEST_ALIGNMENT)
2868 && (GET_MODE_SIZE (operand_mode[i])
2869 > GET_MODE_SIZE (GET_MODE (operand))))
2870 || (GET_CODE (operand) == MEM && BYTES_BIG_ENDIAN)
2871 #ifdef LOAD_EXTEND_OP
2872 || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2873 && (GET_MODE_SIZE (GET_MODE (operand))
2874 <= UNITS_PER_WORD)
2875 && (GET_MODE_SIZE (operand_mode[i])
2876 > GET_MODE_SIZE (GET_MODE (operand)))
2877 && INTEGRAL_MODE_P (GET_MODE (operand))
2878 && LOAD_EXTEND_OP (GET_MODE (operand)) != NIL)
2879 #endif
2881 #endif
2883 /* This following hunk of code should no longer be
2884 needed at all with SUBREG_BYTE. If you need this
2885 code back, please explain to me why so I can
2886 fix the real problem. -DaveM */
2887 #if 0
2888 /* Subreg of a hard reg which can't handle the subreg's mode
2889 or which would handle that mode in the wrong number of
2890 registers for subregging to work. */
2891 || (GET_CODE (operand) == REG
2892 && REGNO (operand) < FIRST_PSEUDO_REGISTER
2893 && ((GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2894 && (GET_MODE_SIZE (GET_MODE (operand))
2895 > UNITS_PER_WORD)
2896 && ((GET_MODE_SIZE (GET_MODE (operand))
2897 / UNITS_PER_WORD)
2898 != HARD_REGNO_NREGS (REGNO (operand),
2899 GET_MODE (operand))))
2900 || ! HARD_REGNO_MODE_OK (REGNO (operand) + offset,
2901 operand_mode[i])))
2902 #endif
2904 force_reload = 1;
2907 this_alternative[i] = (int) NO_REGS;
2908 this_alternative_win[i] = 0;
2909 this_alternative_match_win[i] = 0;
2910 this_alternative_offmemok[i] = 0;
2911 this_alternative_earlyclobber[i] = 0;
2912 this_alternative_matches[i] = -1;
2914 /* An empty constraint or empty alternative
2915 allows anything which matched the pattern. */
2916 if (*p == 0 || *p == ',')
2917 win = 1, badop = 0;
2919 /* Scan this alternative's specs for this operand;
2920 set WIN if the operand fits any letter in this alternative.
2921 Otherwise, clear BADOP if this operand could
2922 fit some letter after reloads,
2923 or set WINREG if this operand could fit after reloads
2924 provided the constraint allows some registers. */
2926 while (*p && (c = *p++) != ',')
2927 switch (c)
2929 case '=': case '+': case '*':
2930 break;
2932 case '%':
2933 /* The last operand should not be marked commutative. */
2934 if (i != noperands - 1)
2935 commutative = i;
2936 break;
2938 case '?':
2939 reject += 6;
2940 break;
2942 case '!':
2943 reject = 600;
2944 break;
2946 case '#':
2947 /* Ignore rest of this alternative as far as
2948 reloading is concerned. */
2949 while (*p && *p != ',')
2950 p++;
2951 break;
2953 case '0': case '1': case '2': case '3': case '4':
2954 case '5': case '6': case '7': case '8': case '9':
2955 c = strtoul (p - 1, &p, 10);
2957 this_alternative_matches[i] = c;
2958 /* We are supposed to match a previous operand.
2959 If we do, we win if that one did.
2960 If we do not, count both of the operands as losers.
2961 (This is too conservative, since most of the time
2962 only a single reload insn will be needed to make
2963 the two operands win. As a result, this alternative
2964 may be rejected when it is actually desirable.) */
2965 if ((swapped && (c != commutative || i != commutative + 1))
2966 /* If we are matching as if two operands were swapped,
2967 also pretend that operands_match had been computed
2968 with swapped.
2969 But if I is the second of those and C is the first,
2970 don't exchange them, because operands_match is valid
2971 only on one side of its diagonal. */
2972 ? (operands_match
2973 [(c == commutative || c == commutative + 1)
2974 ? 2 * commutative + 1 - c : c]
2975 [(i == commutative || i == commutative + 1)
2976 ? 2 * commutative + 1 - i : i])
2977 : operands_match[c][i])
2979 /* If we are matching a non-offsettable address where an
2980 offsettable address was expected, then we must reject
2981 this combination, because we can't reload it. */
2982 if (this_alternative_offmemok[c]
2983 && GET_CODE (recog_data.operand[c]) == MEM
2984 && this_alternative[c] == (int) NO_REGS
2985 && ! this_alternative_win[c])
2986 bad = 1;
2988 did_match = this_alternative_win[c];
2990 else
2992 /* Operands don't match. */
2993 rtx value;
2994 /* Retroactively mark the operand we had to match
2995 as a loser, if it wasn't already. */
2996 if (this_alternative_win[c])
2997 losers++;
2998 this_alternative_win[c] = 0;
2999 if (this_alternative[c] == (int) NO_REGS)
3000 bad = 1;
3001 /* But count the pair only once in the total badness of
3002 this alternative, if the pair can be a dummy reload. */
3003 value
3004 = find_dummy_reload (recog_data.operand[i],
3005 recog_data.operand[c],
3006 recog_data.operand_loc[i],
3007 recog_data.operand_loc[c],
3008 operand_mode[i], operand_mode[c],
3009 this_alternative[c], -1,
3010 this_alternative_earlyclobber[c]);
3012 if (value != 0)
3013 losers--;
3015 /* This can be fixed with reloads if the operand
3016 we are supposed to match can be fixed with reloads. */
3017 badop = 0;
3018 this_alternative[i] = this_alternative[c];
3020 /* If we have to reload this operand and some previous
3021 operand also had to match the same thing as this
3022 operand, we don't know how to do that. So reject this
3023 alternative. */
3024 if (! did_match || force_reload)
3025 for (j = 0; j < i; j++)
3026 if (this_alternative_matches[j]
3027 == this_alternative_matches[i])
3028 badop = 1;
3029 break;
3031 case 'p':
3032 /* All necessary reloads for an address_operand
3033 were handled in find_reloads_address. */
3034 this_alternative[i] = (int) MODE_BASE_REG_CLASS (VOIDmode);
3035 win = 1;
3036 badop = 0;
3037 break;
3039 case 'm':
3040 if (force_reload)
3041 break;
3042 if (GET_CODE (operand) == MEM
3043 || (GET_CODE (operand) == REG
3044 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3045 && reg_renumber[REGNO (operand)] < 0))
3046 win = 1;
3047 if (CONSTANT_P (operand)
3048 /* force_const_mem does not accept HIGH. */
3049 && GET_CODE (operand) != HIGH)
3050 badop = 0;
3051 constmemok = 1;
3052 break;
3054 case '<':
3055 if (GET_CODE (operand) == MEM
3056 && ! address_reloaded[i]
3057 && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
3058 || GET_CODE (XEXP (operand, 0)) == POST_DEC))
3059 win = 1;
3060 break;
3062 case '>':
3063 if (GET_CODE (operand) == MEM
3064 && ! address_reloaded[i]
3065 && (GET_CODE (XEXP (operand, 0)) == PRE_INC
3066 || GET_CODE (XEXP (operand, 0)) == POST_INC))
3067 win = 1;
3068 break;
3070 /* Memory operand whose address is not offsettable. */
3071 case 'V':
3072 if (force_reload)
3073 break;
3074 if (GET_CODE (operand) == MEM
3075 && ! (ind_levels ? offsettable_memref_p (operand)
3076 : offsettable_nonstrict_memref_p (operand))
3077 /* Certain mem addresses will become offsettable
3078 after they themselves are reloaded. This is important;
3079 we don't want our own handling of unoffsettables
3080 to override the handling of reg_equiv_address. */
3081 && !(GET_CODE (XEXP (operand, 0)) == REG
3082 && (ind_levels == 0
3083 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0)))
3084 win = 1;
3085 break;
3087 /* Memory operand whose address is offsettable. */
3088 case 'o':
3089 if (force_reload)
3090 break;
3091 if ((GET_CODE (operand) == MEM
3092 /* If IND_LEVELS, find_reloads_address won't reload a
3093 pseudo that didn't get a hard reg, so we have to
3094 reject that case. */
3095 && ((ind_levels ? offsettable_memref_p (operand)
3096 : offsettable_nonstrict_memref_p (operand))
3097 /* A reloaded address is offsettable because it is now
3098 just a simple register indirect. */
3099 || address_reloaded[i]))
3100 || (GET_CODE (operand) == REG
3101 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3102 && reg_renumber[REGNO (operand)] < 0
3103 /* If reg_equiv_address is nonzero, we will be
3104 loading it into a register; hence it will be
3105 offsettable, but we cannot say that reg_equiv_mem
3106 is offsettable without checking. */
3107 && ((reg_equiv_mem[REGNO (operand)] != 0
3108 && offsettable_memref_p (reg_equiv_mem[REGNO (operand)]))
3109 || (reg_equiv_address[REGNO (operand)] != 0))))
3110 win = 1;
3111 /* force_const_mem does not accept HIGH. */
3112 if ((CONSTANT_P (operand) && GET_CODE (operand) != HIGH)
3113 || GET_CODE (operand) == MEM)
3114 badop = 0;
3115 constmemok = 1;
3116 offmemok = 1;
3117 break;
3119 case '&':
3120 /* Output operand that is stored before the need for the
3121 input operands (and their index registers) is over. */
3122 earlyclobber = 1, this_earlyclobber = 1;
3123 break;
3125 case 'E':
3126 case 'F':
3127 if (GET_CODE (operand) == CONST_DOUBLE)
3128 win = 1;
3129 break;
3131 case 'G':
3132 case 'H':
3133 if (GET_CODE (operand) == CONST_DOUBLE
3134 && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
3135 win = 1;
3136 break;
3138 case 's':
3139 if (GET_CODE (operand) == CONST_INT
3140 || (GET_CODE (operand) == CONST_DOUBLE
3141 && GET_MODE (operand) == VOIDmode))
3142 break;
3143 case 'i':
3144 if (CONSTANT_P (operand)
3145 #ifdef LEGITIMATE_PIC_OPERAND_P
3146 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand))
3147 #endif
3149 win = 1;
3150 break;
3152 case 'n':
3153 if (GET_CODE (operand) == CONST_INT
3154 || (GET_CODE (operand) == CONST_DOUBLE
3155 && GET_MODE (operand) == VOIDmode))
3156 win = 1;
3157 break;
3159 case 'I':
3160 case 'J':
3161 case 'K':
3162 case 'L':
3163 case 'M':
3164 case 'N':
3165 case 'O':
3166 case 'P':
3167 if (GET_CODE (operand) == CONST_INT
3168 && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
3169 win = 1;
3170 break;
3172 case 'X':
3173 win = 1;
3174 break;
3176 case 'g':
3177 if (! force_reload
3178 /* A PLUS is never a valid operand, but reload can make
3179 it from a register when eliminating registers. */
3180 && GET_CODE (operand) != PLUS
3181 /* A SCRATCH is not a valid operand. */
3182 && GET_CODE (operand) != SCRATCH
3183 #ifdef LEGITIMATE_PIC_OPERAND_P
3184 && (! CONSTANT_P (operand)
3185 || ! flag_pic
3186 || LEGITIMATE_PIC_OPERAND_P (operand))
3187 #endif
3188 && (GENERAL_REGS == ALL_REGS
3189 || GET_CODE (operand) != REG
3190 || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
3191 && reg_renumber[REGNO (operand)] < 0)))
3192 win = 1;
3193 /* Drop through into 'r' case. */
3195 case 'r':
3196 this_alternative[i]
3197 = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
3198 goto reg;
3200 default:
3201 if (REG_CLASS_FROM_LETTER (c) == NO_REGS)
3203 #ifdef EXTRA_CONSTRAINT
3204 if (EXTRA_CONSTRAINT (operand, c))
3205 win = 1;
3206 #endif
3207 break;
3210 this_alternative[i]
3211 = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
3212 reg:
3213 if (GET_MODE (operand) == BLKmode)
3214 break;
3215 winreg = 1;
3216 if (GET_CODE (operand) == REG
3217 && reg_fits_class_p (operand, this_alternative[i],
3218 offset, GET_MODE (recog_data.operand[i])))
3219 win = 1;
3220 break;
3223 constraints[i] = p;
3225 /* If this operand could be handled with a reg,
3226 and some reg is allowed, then this operand can be handled. */
3227 if (winreg && this_alternative[i] != (int) NO_REGS)
3228 badop = 0;
3230 /* Record which operands fit this alternative. */
3231 this_alternative_earlyclobber[i] = earlyclobber;
3232 if (win && ! force_reload)
3233 this_alternative_win[i] = 1;
3234 else if (did_match && ! force_reload)
3235 this_alternative_match_win[i] = 1;
3236 else
3238 int const_to_mem = 0;
3240 this_alternative_offmemok[i] = offmemok;
3241 losers++;
3242 if (badop)
3243 bad = 1;
3244 /* Alternative loses if it has no regs for a reg operand. */
3245 if (GET_CODE (operand) == REG
3246 && this_alternative[i] == (int) NO_REGS
3247 && this_alternative_matches[i] < 0)
3248 bad = 1;
3250 /* If this is a constant that is reloaded into the desired
3251 class by copying it to memory first, count that as another
3252 reload. This is consistent with other code and is
3253 required to avoid choosing another alternative when
3254 the constant is moved into memory by this function on
3255 an early reload pass. Note that the test here is
3256 precisely the same as in the code below that calls
3257 force_const_mem. */
3258 if (CONSTANT_P (operand)
3259 /* force_const_mem does not accept HIGH. */
3260 && GET_CODE (operand) != HIGH
3261 && ((PREFERRED_RELOAD_CLASS (operand,
3262 (enum reg_class) this_alternative[i])
3263 == NO_REGS)
3264 || no_input_reloads)
3265 && operand_mode[i] != VOIDmode)
3267 const_to_mem = 1;
3268 if (this_alternative[i] != (int) NO_REGS)
3269 losers++;
3272 /* If we can't reload this value at all, reject this
3273 alternative. Note that we could also lose due to
3274 LIMIT_RELOAD_RELOAD_CLASS, but we don't check that
3275 here. */
3277 if (! CONSTANT_P (operand)
3278 && (enum reg_class) this_alternative[i] != NO_REGS
3279 && (PREFERRED_RELOAD_CLASS (operand,
3280 (enum reg_class) this_alternative[i])
3281 == NO_REGS))
3282 bad = 1;
3284 /* Alternative loses if it requires a type of reload not
3285 permitted for this insn. We can always reload SCRATCH
3286 and objects with a REG_UNUSED note. */
3287 else if (GET_CODE (operand) != SCRATCH
3288 && modified[i] != RELOAD_READ && no_output_reloads
3289 && ! find_reg_note (insn, REG_UNUSED, operand))
3290 bad = 1;
3291 else if (modified[i] != RELOAD_WRITE && no_input_reloads
3292 && ! const_to_mem)
3293 bad = 1;
3295 /* We prefer to reload pseudos over reloading other things,
3296 since such reloads may be able to be eliminated later.
3297 If we are reloading a SCRATCH, we won't be generating any
3298 insns, just using a register, so it is also preferred.
3299 So bump REJECT in other cases. Don't do this in the
3300 case where we are forcing a constant into memory and
3301 it will then win since we don't want to have a different
3302 alternative match then. */
3303 if (! (GET_CODE (operand) == REG
3304 && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
3305 && GET_CODE (operand) != SCRATCH
3306 && ! (const_to_mem && constmemok))
3307 reject += 2;
3309 /* Input reloads can be inherited more often than output
3310 reloads can be removed, so penalize output reloads. */
3311 if (operand_type[i] != RELOAD_FOR_INPUT
3312 && GET_CODE (operand) != SCRATCH)
3313 reject++;
3316 /* If this operand is a pseudo register that didn't get a hard
3317 reg and this alternative accepts some register, see if the
3318 class that we want is a subset of the preferred class for this
3319 register. If not, but it intersects that class, use the
3320 preferred class instead. If it does not intersect the preferred
3321 class, show that usage of this alternative should be discouraged;
3322 it will be discouraged more still if the register is `preferred
3323 or nothing'. We do this because it increases the chance of
3324 reusing our spill register in a later insn and avoiding a pair
3325 of memory stores and loads.
3327 Don't bother with this if this alternative will accept this
3328 operand.
3330 Don't do this for a multiword operand, since it is only a
3331 small win and has the risk of requiring more spill registers,
3332 which could cause a large loss.
3334 Don't do this if the preferred class has only one register
3335 because we might otherwise exhaust the class. */
3337 if (! win && ! did_match
3338 && this_alternative[i] != (int) NO_REGS
3339 && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3340 && reg_class_size[(int) preferred_class[i]] > 1)
3342 if (! reg_class_subset_p (this_alternative[i],
3343 preferred_class[i]))
3345 /* Since we don't have a way of forming the intersection,
3346 we just do something special if the preferred class
3347 is a subset of the class we have; that's the most
3348 common case anyway. */
3349 if (reg_class_subset_p (preferred_class[i],
3350 this_alternative[i]))
3351 this_alternative[i] = (int) preferred_class[i];
3352 else
3353 reject += (2 + 2 * pref_or_nothing[i]);
3358 /* Now see if any output operands that are marked "earlyclobber"
3359 in this alternative conflict with any input operands
3360 or any memory addresses. */
3362 for (i = 0; i < noperands; i++)
3363 if (this_alternative_earlyclobber[i]
3364 && (this_alternative_win[i] || this_alternative_match_win[i]))
3366 struct decomposition early_data;
3368 early_data = decompose (recog_data.operand[i]);
3370 if (modified[i] == RELOAD_READ)
3371 abort ();
3373 if (this_alternative[i] == NO_REGS)
3375 this_alternative_earlyclobber[i] = 0;
3376 if (this_insn_is_asm)
3377 error_for_asm (this_insn,
3378 "`&' constraint used with no register class");
3379 else
3380 abort ();
3383 for (j = 0; j < noperands; j++)
3384 /* Is this an input operand or a memory ref? */
3385 if ((GET_CODE (recog_data.operand[j]) == MEM
3386 || modified[j] != RELOAD_WRITE)
3387 && j != i
3388 /* Ignore things like match_operator operands. */
3389 && *recog_data.constraints[j] != 0
3390 /* Don't count an input operand that is constrained to match
3391 the early clobber operand. */
3392 && ! (this_alternative_matches[j] == i
3393 && rtx_equal_p (recog_data.operand[i],
3394 recog_data.operand[j]))
3395 /* Is it altered by storing the earlyclobber operand? */
3396 && !immune_p (recog_data.operand[j], recog_data.operand[i],
3397 early_data))
3399 /* If the output is in a single-reg class,
3400 it's costly to reload it, so reload the input instead. */
3401 if (reg_class_size[this_alternative[i]] == 1
3402 && (GET_CODE (recog_data.operand[j]) == REG
3403 || GET_CODE (recog_data.operand[j]) == SUBREG))
3405 losers++;
3406 this_alternative_win[j] = 0;
3407 this_alternative_match_win[j] = 0;
3409 else
3410 break;
3412 /* If an earlyclobber operand conflicts with something,
3413 it must be reloaded, so request this and count the cost. */
3414 if (j != noperands)
3416 losers++;
3417 this_alternative_win[i] = 0;
3418 this_alternative_match_win[j] = 0;
3419 for (j = 0; j < noperands; j++)
3420 if (this_alternative_matches[j] == i
3421 && this_alternative_match_win[j])
3423 this_alternative_win[j] = 0;
3424 this_alternative_match_win[j] = 0;
3425 losers++;
3430 /* If one alternative accepts all the operands, no reload required,
3431 choose that alternative; don't consider the remaining ones. */
3432 if (losers == 0)
3434 /* Unswap these so that they are never swapped at `finish'. */
3435 if (commutative >= 0)
3437 recog_data.operand[commutative] = substed_operand[commutative];
3438 recog_data.operand[commutative + 1]
3439 = substed_operand[commutative + 1];
3441 for (i = 0; i < noperands; i++)
3443 goal_alternative_win[i] = this_alternative_win[i];
3444 goal_alternative_match_win[i] = this_alternative_match_win[i];
3445 goal_alternative[i] = this_alternative[i];
3446 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3447 goal_alternative_matches[i] = this_alternative_matches[i];
3448 goal_alternative_earlyclobber[i]
3449 = this_alternative_earlyclobber[i];
3451 goal_alternative_number = this_alternative_number;
3452 goal_alternative_swapped = swapped;
3453 goal_earlyclobber = this_earlyclobber;
3454 goto finish;
3457 /* REJECT, set by the ! and ? constraint characters and when a register
3458 would be reloaded into a non-preferred class, discourages the use of
3459 this alternative for a reload goal. REJECT is incremented by six
3460 for each ? and two for each non-preferred class. */
3461 losers = losers * 6 + reject;
3463 /* If this alternative can be made to work by reloading,
3464 and it needs less reloading than the others checked so far,
3465 record it as the chosen goal for reloading. */
3466 if (! bad && best > losers)
3468 for (i = 0; i < noperands; i++)
3470 goal_alternative[i] = this_alternative[i];
3471 goal_alternative_win[i] = this_alternative_win[i];
3472 goal_alternative_match_win[i] = this_alternative_match_win[i];
3473 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3474 goal_alternative_matches[i] = this_alternative_matches[i];
3475 goal_alternative_earlyclobber[i]
3476 = this_alternative_earlyclobber[i];
3478 goal_alternative_swapped = swapped;
3479 best = losers;
3480 goal_alternative_number = this_alternative_number;
3481 goal_earlyclobber = this_earlyclobber;
3485 /* If insn is commutative (it's safe to exchange a certain pair of operands)
3486 then we need to try each alternative twice,
3487 the second time matching those two operands
3488 as if we had exchanged them.
3489 To do this, really exchange them in operands.
3491 If we have just tried the alternatives the second time,
3492 return operands to normal and drop through. */
3494 if (commutative >= 0)
3496 swapped = !swapped;
3497 if (swapped)
3499 enum reg_class tclass;
3500 int t;
3502 recog_data.operand[commutative] = substed_operand[commutative + 1];
3503 recog_data.operand[commutative + 1] = substed_operand[commutative];
3504 /* Swap the duplicates too. */
3505 for (i = 0; i < recog_data.n_dups; i++)
3506 if (recog_data.dup_num[i] == commutative
3507 || recog_data.dup_num[i] == commutative + 1)
3508 *recog_data.dup_loc[i]
3509 = recog_data.operand[(int) recog_data.dup_num[i]];
3511 tclass = preferred_class[commutative];
3512 preferred_class[commutative] = preferred_class[commutative + 1];
3513 preferred_class[commutative + 1] = tclass;
3515 t = pref_or_nothing[commutative];
3516 pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
3517 pref_or_nothing[commutative + 1] = t;
3519 memcpy (constraints, recog_data.constraints,
3520 noperands * sizeof (char *));
3521 goto try_swapped;
3523 else
3525 recog_data.operand[commutative] = substed_operand[commutative];
3526 recog_data.operand[commutative + 1]
3527 = substed_operand[commutative + 1];
3528 /* Unswap the duplicates too. */
3529 for (i = 0; i < recog_data.n_dups; i++)
3530 if (recog_data.dup_num[i] == commutative
3531 || recog_data.dup_num[i] == commutative + 1)
3532 *recog_data.dup_loc[i]
3533 = recog_data.operand[(int) recog_data.dup_num[i]];
3537 /* The operands don't meet the constraints.
3538 goal_alternative describes the alternative
3539 that we could reach by reloading the fewest operands.
3540 Reload so as to fit it. */
3542 if (best == MAX_RECOG_OPERANDS * 2 + 600)
3544 /* No alternative works with reloads?? */
3545 if (insn_code_number >= 0)
3546 fatal_insn ("unable to generate reloads for:", insn);
3547 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3548 /* Avoid further trouble with this insn. */
3549 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3550 n_reloads = 0;
3551 return 0;
3554 /* Jump to `finish' from above if all operands are valid already.
3555 In that case, goal_alternative_win is all 1. */
3556 finish:
3558 /* Right now, for any pair of operands I and J that are required to match,
3559 with I < J,
3560 goal_alternative_matches[J] is I.
3561 Set up goal_alternative_matched as the inverse function:
3562 goal_alternative_matched[I] = J. */
3564 for (i = 0; i < noperands; i++)
3565 goal_alternative_matched[i] = -1;
3567 for (i = 0; i < noperands; i++)
3568 if (! goal_alternative_win[i]
3569 && goal_alternative_matches[i] >= 0)
3570 goal_alternative_matched[goal_alternative_matches[i]] = i;
3572 for (i = 0; i < noperands; i++)
3573 goal_alternative_win[i] |= goal_alternative_match_win[i];
3575 /* If the best alternative is with operands 1 and 2 swapped,
3576 consider them swapped before reporting the reloads. Update the
3577 operand numbers of any reloads already pushed. */
3579 if (goal_alternative_swapped)
3581 rtx tem;
3583 tem = substed_operand[commutative];
3584 substed_operand[commutative] = substed_operand[commutative + 1];
3585 substed_operand[commutative + 1] = tem;
3586 tem = recog_data.operand[commutative];
3587 recog_data.operand[commutative] = recog_data.operand[commutative + 1];
3588 recog_data.operand[commutative + 1] = tem;
3589 tem = *recog_data.operand_loc[commutative];
3590 *recog_data.operand_loc[commutative]
3591 = *recog_data.operand_loc[commutative + 1];
3592 *recog_data.operand_loc[commutative + 1] = tem;
3594 for (i = 0; i < n_reloads; i++)
3596 if (rld[i].opnum == commutative)
3597 rld[i].opnum = commutative + 1;
3598 else if (rld[i].opnum == commutative + 1)
3599 rld[i].opnum = commutative;
3603 for (i = 0; i < noperands; i++)
3605 operand_reloadnum[i] = -1;
3607 /* If this is an earlyclobber operand, we need to widen the scope.
3608 The reload must remain valid from the start of the insn being
3609 reloaded until after the operand is stored into its destination.
3610 We approximate this with RELOAD_OTHER even though we know that we
3611 do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads.
3613 One special case that is worth checking is when we have an
3614 output that is earlyclobber but isn't used past the insn (typically
3615 a SCRATCH). In this case, we only need have the reload live
3616 through the insn itself, but not for any of our input or output
3617 reloads.
3618 But we must not accidentally narrow the scope of an existing
3619 RELOAD_OTHER reload - leave these alone.
3621 In any case, anything needed to address this operand can remain
3622 however they were previously categorized. */
3624 if (goal_alternative_earlyclobber[i] && operand_type[i] != RELOAD_OTHER)
3625 operand_type[i]
3626 = (find_reg_note (insn, REG_UNUSED, recog_data.operand[i])
3627 ? RELOAD_FOR_INSN : RELOAD_OTHER);
3630 /* Any constants that aren't allowed and can't be reloaded
3631 into registers are here changed into memory references. */
3632 for (i = 0; i < noperands; i++)
3633 if (! goal_alternative_win[i]
3634 && CONSTANT_P (recog_data.operand[i])
3635 /* force_const_mem does not accept HIGH. */
3636 && GET_CODE (recog_data.operand[i]) != HIGH
3637 && ((PREFERRED_RELOAD_CLASS (recog_data.operand[i],
3638 (enum reg_class) goal_alternative[i])
3639 == NO_REGS)
3640 || no_input_reloads)
3641 && operand_mode[i] != VOIDmode)
3643 substed_operand[i] = recog_data.operand[i]
3644 = find_reloads_toplev (force_const_mem (operand_mode[i],
3645 recog_data.operand[i]),
3646 i, address_type[i], ind_levels, 0, insn,
3647 NULL);
3648 if (alternative_allows_memconst (recog_data.constraints[i],
3649 goal_alternative_number))
3650 goal_alternative_win[i] = 1;
3653 /* Record the values of the earlyclobber operands for the caller. */
3654 if (goal_earlyclobber)
3655 for (i = 0; i < noperands; i++)
3656 if (goal_alternative_earlyclobber[i])
3657 reload_earlyclobbers[n_earlyclobbers++] = recog_data.operand[i];
3659 /* Now record reloads for all the operands that need them. */
3660 for (i = 0; i < noperands; i++)
3661 if (! goal_alternative_win[i])
3663 /* Operands that match previous ones have already been handled. */
3664 if (goal_alternative_matches[i] >= 0)
3666 /* Handle an operand with a nonoffsettable address
3667 appearing where an offsettable address will do
3668 by reloading the address into a base register.
3670 ??? We can also do this when the operand is a register and
3671 reg_equiv_mem is not offsettable, but this is a bit tricky,
3672 so we don't bother with it. It may not be worth doing. */
3673 else if (goal_alternative_matched[i] == -1
3674 && goal_alternative_offmemok[i]
3675 && GET_CODE (recog_data.operand[i]) == MEM)
3677 operand_reloadnum[i]
3678 = push_reload (XEXP (recog_data.operand[i], 0), NULL_RTX,
3679 &XEXP (recog_data.operand[i], 0), (rtx*) 0,
3680 MODE_BASE_REG_CLASS (VOIDmode),
3681 GET_MODE (XEXP (recog_data.operand[i], 0)),
3682 VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
3683 rld[operand_reloadnum[i]].inc
3684 = GET_MODE_SIZE (GET_MODE (recog_data.operand[i]));
3686 /* If this operand is an output, we will have made any
3687 reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but
3688 now we are treating part of the operand as an input, so
3689 we must change these to RELOAD_FOR_INPUT_ADDRESS. */
3691 if (modified[i] == RELOAD_WRITE)
3693 for (j = 0; j < n_reloads; j++)
3695 if (rld[j].opnum == i)
3697 if (rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS)
3698 rld[j].when_needed = RELOAD_FOR_INPUT_ADDRESS;
3699 else if (rld[j].when_needed
3700 == RELOAD_FOR_OUTADDR_ADDRESS)
3701 rld[j].when_needed = RELOAD_FOR_INPADDR_ADDRESS;
3706 else if (goal_alternative_matched[i] == -1)
3708 operand_reloadnum[i]
3709 = push_reload ((modified[i] != RELOAD_WRITE
3710 ? recog_data.operand[i] : 0),
3711 (modified[i] != RELOAD_READ
3712 ? recog_data.operand[i] : 0),
3713 (modified[i] != RELOAD_WRITE
3714 ? recog_data.operand_loc[i] : 0),
3715 (modified[i] != RELOAD_READ
3716 ? recog_data.operand_loc[i] : 0),
3717 (enum reg_class) goal_alternative[i],
3718 (modified[i] == RELOAD_WRITE
3719 ? VOIDmode : operand_mode[i]),
3720 (modified[i] == RELOAD_READ
3721 ? VOIDmode : operand_mode[i]),
3722 (insn_code_number < 0 ? 0
3723 : insn_data[insn_code_number].operand[i].strict_low),
3724 0, i, operand_type[i]);
3726 /* In a matching pair of operands, one must be input only
3727 and the other must be output only.
3728 Pass the input operand as IN and the other as OUT. */
3729 else if (modified[i] == RELOAD_READ
3730 && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
3732 operand_reloadnum[i]
3733 = push_reload (recog_data.operand[i],
3734 recog_data.operand[goal_alternative_matched[i]],
3735 recog_data.operand_loc[i],
3736 recog_data.operand_loc[goal_alternative_matched[i]],
3737 (enum reg_class) goal_alternative[i],
3738 operand_mode[i],
3739 operand_mode[goal_alternative_matched[i]],
3740 0, 0, i, RELOAD_OTHER);
3741 operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
3743 else if (modified[i] == RELOAD_WRITE
3744 && modified[goal_alternative_matched[i]] == RELOAD_READ)
3746 operand_reloadnum[goal_alternative_matched[i]]
3747 = push_reload (recog_data.operand[goal_alternative_matched[i]],
3748 recog_data.operand[i],
3749 recog_data.operand_loc[goal_alternative_matched[i]],
3750 recog_data.operand_loc[i],
3751 (enum reg_class) goal_alternative[i],
3752 operand_mode[goal_alternative_matched[i]],
3753 operand_mode[i],
3754 0, 0, i, RELOAD_OTHER);
3755 operand_reloadnum[i] = output_reloadnum;
3757 else if (insn_code_number >= 0)
3758 abort ();
3759 else
3761 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3762 /* Avoid further trouble with this insn. */
3763 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3764 n_reloads = 0;
3765 return 0;
3768 else if (goal_alternative_matched[i] < 0
3769 && goal_alternative_matches[i] < 0
3770 && optimize)
3772 /* For each non-matching operand that's a MEM or a pseudo-register
3773 that didn't get a hard register, make an optional reload.
3774 This may get done even if the insn needs no reloads otherwise. */
3776 rtx operand = recog_data.operand[i];
3778 while (GET_CODE (operand) == SUBREG)
3779 operand = SUBREG_REG (operand);
3780 if ((GET_CODE (operand) == MEM
3781 || (GET_CODE (operand) == REG
3782 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3783 /* If this is only for an output, the optional reload would not
3784 actually cause us to use a register now, just note that
3785 something is stored here. */
3786 && ((enum reg_class) goal_alternative[i] != NO_REGS
3787 || modified[i] == RELOAD_WRITE)
3788 && ! no_input_reloads
3789 /* An optional output reload might allow to delete INSN later.
3790 We mustn't make in-out reloads on insns that are not permitted
3791 output reloads.
3792 If this is an asm, we can't delete it; we must not even call
3793 push_reload for an optional output reload in this case,
3794 because we can't be sure that the constraint allows a register,
3795 and push_reload verifies the constraints for asms. */
3796 && (modified[i] == RELOAD_READ
3797 || (! no_output_reloads && ! this_insn_is_asm)))
3798 operand_reloadnum[i]
3799 = push_reload ((modified[i] != RELOAD_WRITE
3800 ? recog_data.operand[i] : 0),
3801 (modified[i] != RELOAD_READ
3802 ? recog_data.operand[i] : 0),
3803 (modified[i] != RELOAD_WRITE
3804 ? recog_data.operand_loc[i] : 0),
3805 (modified[i] != RELOAD_READ
3806 ? recog_data.operand_loc[i] : 0),
3807 (enum reg_class) goal_alternative[i],
3808 (modified[i] == RELOAD_WRITE
3809 ? VOIDmode : operand_mode[i]),
3810 (modified[i] == RELOAD_READ
3811 ? VOIDmode : operand_mode[i]),
3812 (insn_code_number < 0 ? 0
3813 : insn_data[insn_code_number].operand[i].strict_low),
3814 1, i, operand_type[i]);
3815 /* If a memory reference remains (either as a MEM or a pseudo that
3816 did not get a hard register), yet we can't make an optional
3817 reload, check if this is actually a pseudo register reference;
3818 we then need to emit a USE and/or a CLOBBER so that reload
3819 inheritance will do the right thing. */
3820 else if (replace
3821 && (GET_CODE (operand) == MEM
3822 || (GET_CODE (operand) == REG
3823 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3824 && reg_renumber [REGNO (operand)] < 0)))
3826 operand = *recog_data.operand_loc[i];
3828 while (GET_CODE (operand) == SUBREG)
3829 operand = SUBREG_REG (operand);
3830 if (GET_CODE (operand) == REG)
3832 if (modified[i] != RELOAD_WRITE)
3833 /* We mark the USE with QImode so that we recognize
3834 it as one that can be safely deleted at the end
3835 of reload. */
3836 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, operand),
3837 insn), QImode);
3838 if (modified[i] != RELOAD_READ)
3839 emit_insn_after (gen_rtx_CLOBBER (VOIDmode, operand), insn);
3843 else if (goal_alternative_matches[i] >= 0
3844 && goal_alternative_win[goal_alternative_matches[i]]
3845 && modified[i] == RELOAD_READ
3846 && modified[goal_alternative_matches[i]] == RELOAD_WRITE
3847 && ! no_input_reloads && ! no_output_reloads
3848 && optimize)
3850 /* Similarly, make an optional reload for a pair of matching
3851 objects that are in MEM or a pseudo that didn't get a hard reg. */
3853 rtx operand = recog_data.operand[i];
3855 while (GET_CODE (operand) == SUBREG)
3856 operand = SUBREG_REG (operand);
3857 if ((GET_CODE (operand) == MEM
3858 || (GET_CODE (operand) == REG
3859 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3860 && ((enum reg_class) goal_alternative[goal_alternative_matches[i]]
3861 != NO_REGS))
3862 operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]]
3863 = push_reload (recog_data.operand[goal_alternative_matches[i]],
3864 recog_data.operand[i],
3865 recog_data.operand_loc[goal_alternative_matches[i]],
3866 recog_data.operand_loc[i],
3867 (enum reg_class) goal_alternative[goal_alternative_matches[i]],
3868 operand_mode[goal_alternative_matches[i]],
3869 operand_mode[i],
3870 0, 1, goal_alternative_matches[i], RELOAD_OTHER);
3873 /* Perform whatever substitutions on the operands we are supposed
3874 to make due to commutativity or replacement of registers
3875 with equivalent constants or memory slots. */
3877 for (i = 0; i < noperands; i++)
3879 /* We only do this on the last pass through reload, because it is
3880 possible for some data (like reg_equiv_address) to be changed during
3881 later passes. Moreover, we loose the opportunity to get a useful
3882 reload_{in,out}_reg when we do these replacements. */
3884 if (replace)
3886 rtx substitution = substed_operand[i];
3888 *recog_data.operand_loc[i] = substitution;
3890 /* If we're replacing an operand with a LABEL_REF, we need
3891 to make sure that there's a REG_LABEL note attached to
3892 this instruction. */
3893 if (GET_CODE (insn) != JUMP_INSN
3894 && GET_CODE (substitution) == LABEL_REF
3895 && !find_reg_note (insn, REG_LABEL, XEXP (substitution, 0)))
3896 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
3897 XEXP (substitution, 0),
3898 REG_NOTES (insn));
3900 else
3901 retval |= (substed_operand[i] != *recog_data.operand_loc[i]);
3904 /* If this insn pattern contains any MATCH_DUP's, make sure that
3905 they will be substituted if the operands they match are substituted.
3906 Also do now any substitutions we already did on the operands.
3908 Don't do this if we aren't making replacements because we might be
3909 propagating things allocated by frame pointer elimination into places
3910 it doesn't expect. */
3912 if (insn_code_number >= 0 && replace)
3913 for (i = insn_data[insn_code_number].n_dups - 1; i >= 0; i--)
3915 int opno = recog_data.dup_num[i];
3916 *recog_data.dup_loc[i] = *recog_data.operand_loc[opno];
3917 if (operand_reloadnum[opno] >= 0)
3918 push_replacement (recog_data.dup_loc[i], operand_reloadnum[opno],
3919 insn_data[insn_code_number].operand[opno].mode);
3922 #if 0
3923 /* This loses because reloading of prior insns can invalidate the equivalence
3924 (or at least find_equiv_reg isn't smart enough to find it any more),
3925 causing this insn to need more reload regs than it needed before.
3926 It may be too late to make the reload regs available.
3927 Now this optimization is done safely in choose_reload_regs. */
3929 /* For each reload of a reg into some other class of reg,
3930 search for an existing equivalent reg (same value now) in the right class.
3931 We can use it as long as we don't need to change its contents. */
3932 for (i = 0; i < n_reloads; i++)
3933 if (rld[i].reg_rtx == 0
3934 && rld[i].in != 0
3935 && GET_CODE (rld[i].in) == REG
3936 && rld[i].out == 0)
3938 rld[i].reg_rtx
3939 = find_equiv_reg (rld[i].in, insn, rld[i].class, -1,
3940 static_reload_reg_p, 0, rld[i].inmode);
3941 /* Prevent generation of insn to load the value
3942 because the one we found already has the value. */
3943 if (rld[i].reg_rtx)
3944 rld[i].in = rld[i].reg_rtx;
3946 #endif
3948 /* Perhaps an output reload can be combined with another
3949 to reduce needs by one. */
3950 if (!goal_earlyclobber)
3951 combine_reloads ();
3953 /* If we have a pair of reloads for parts of an address, they are reloading
3954 the same object, the operands themselves were not reloaded, and they
3955 are for two operands that are supposed to match, merge the reloads and
3956 change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS. */
3958 for (i = 0; i < n_reloads; i++)
3960 int k;
3962 for (j = i + 1; j < n_reloads; j++)
3963 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
3964 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
3965 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
3966 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
3967 && (rld[j].when_needed == RELOAD_FOR_INPUT_ADDRESS
3968 || rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
3969 || rld[j].when_needed == RELOAD_FOR_INPADDR_ADDRESS
3970 || rld[j].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
3971 && rtx_equal_p (rld[i].in, rld[j].in)
3972 && (operand_reloadnum[rld[i].opnum] < 0
3973 || rld[operand_reloadnum[rld[i].opnum]].optional)
3974 && (operand_reloadnum[rld[j].opnum] < 0
3975 || rld[operand_reloadnum[rld[j].opnum]].optional)
3976 && (goal_alternative_matches[rld[i].opnum] == rld[j].opnum
3977 || (goal_alternative_matches[rld[j].opnum]
3978 == rld[i].opnum)))
3980 for (k = 0; k < n_replacements; k++)
3981 if (replacements[k].what == j)
3982 replacements[k].what = i;
3984 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
3985 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
3986 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
3987 else
3988 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
3989 rld[j].in = 0;
3993 /* Scan all the reloads and update their type.
3994 If a reload is for the address of an operand and we didn't reload
3995 that operand, change the type. Similarly, change the operand number
3996 of a reload when two operands match. If a reload is optional, treat it
3997 as though the operand isn't reloaded.
3999 ??? This latter case is somewhat odd because if we do the optional
4000 reload, it means the object is hanging around. Thus we need only
4001 do the address reload if the optional reload was NOT done.
4003 Change secondary reloads to be the address type of their operand, not
4004 the normal type.
4006 If an operand's reload is now RELOAD_OTHER, change any
4007 RELOAD_FOR_INPUT_ADDRESS reloads of that operand to
4008 RELOAD_FOR_OTHER_ADDRESS. */
4010 for (i = 0; i < n_reloads; i++)
4012 if (rld[i].secondary_p
4013 && rld[i].when_needed == operand_type[rld[i].opnum])
4014 rld[i].when_needed = address_type[rld[i].opnum];
4016 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4017 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4018 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4019 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4020 && (operand_reloadnum[rld[i].opnum] < 0
4021 || rld[operand_reloadnum[rld[i].opnum]].optional))
4023 /* If we have a secondary reload to go along with this reload,
4024 change its type to RELOAD_FOR_OPADDR_ADDR. */
4026 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4027 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4028 && rld[i].secondary_in_reload != -1)
4030 int secondary_in_reload = rld[i].secondary_in_reload;
4032 rld[secondary_in_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4034 /* If there's a tertiary reload we have to change it also. */
4035 if (secondary_in_reload > 0
4036 && rld[secondary_in_reload].secondary_in_reload != -1)
4037 rld[rld[secondary_in_reload].secondary_in_reload].when_needed
4038 = RELOAD_FOR_OPADDR_ADDR;
4041 if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4042 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4043 && rld[i].secondary_out_reload != -1)
4045 int secondary_out_reload = rld[i].secondary_out_reload;
4047 rld[secondary_out_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4049 /* If there's a tertiary reload we have to change it also. */
4050 if (secondary_out_reload
4051 && rld[secondary_out_reload].secondary_out_reload != -1)
4052 rld[rld[secondary_out_reload].secondary_out_reload].when_needed
4053 = RELOAD_FOR_OPADDR_ADDR;
4056 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4057 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4058 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
4059 else
4060 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
4063 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4064 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4065 && operand_reloadnum[rld[i].opnum] >= 0
4066 && (rld[operand_reloadnum[rld[i].opnum]].when_needed
4067 == RELOAD_OTHER))
4068 rld[i].when_needed = RELOAD_FOR_OTHER_ADDRESS;
4070 if (goal_alternative_matches[rld[i].opnum] >= 0)
4071 rld[i].opnum = goal_alternative_matches[rld[i].opnum];
4074 /* Scan all the reloads, and check for RELOAD_FOR_OPERAND_ADDRESS reloads.
4075 If we have more than one, then convert all RELOAD_FOR_OPADDR_ADDR
4076 reloads to RELOAD_FOR_OPERAND_ADDRESS reloads.
4078 choose_reload_regs assumes that RELOAD_FOR_OPADDR_ADDR reloads never
4079 conflict with RELOAD_FOR_OPERAND_ADDRESS reloads. This is true for a
4080 single pair of RELOAD_FOR_OPADDR_ADDR/RELOAD_FOR_OPERAND_ADDRESS reloads.
4081 However, if there is more than one RELOAD_FOR_OPERAND_ADDRESS reload,
4082 then a RELOAD_FOR_OPADDR_ADDR reload conflicts with all
4083 RELOAD_FOR_OPERAND_ADDRESS reloads other than the one that uses it.
4084 This is complicated by the fact that a single operand can have more
4085 than one RELOAD_FOR_OPERAND_ADDRESS reload. It is very difficult to fix
4086 choose_reload_regs without affecting code quality, and cases that
4087 actually fail are extremely rare, so it turns out to be better to fix
4088 the problem here by not generating cases that choose_reload_regs will
4089 fail for. */
4090 /* There is a similar problem with RELOAD_FOR_INPUT_ADDRESS /
4091 RELOAD_FOR_OUTPUT_ADDRESS when there is more than one of a kind for
4092 a single operand.
4093 We can reduce the register pressure by exploiting that a
4094 RELOAD_FOR_X_ADDR_ADDR that precedes all RELOAD_FOR_X_ADDRESS reloads
4095 does not conflict with any of them, if it is only used for the first of
4096 the RELOAD_FOR_X_ADDRESS reloads. */
4098 int first_op_addr_num = -2;
4099 int first_inpaddr_num[MAX_RECOG_OPERANDS];
4100 int first_outpaddr_num[MAX_RECOG_OPERANDS];
4101 int need_change = 0;
4102 /* We use last_op_addr_reload and the contents of the above arrays
4103 first as flags - -2 means no instance encountered, -1 means exactly
4104 one instance encountered.
4105 If more than one instance has been encountered, we store the reload
4106 number of the first reload of the kind in question; reload numbers
4107 are known to be non-negative. */
4108 for (i = 0; i < noperands; i++)
4109 first_inpaddr_num[i] = first_outpaddr_num[i] = -2;
4110 for (i = n_reloads - 1; i >= 0; i--)
4112 switch (rld[i].when_needed)
4114 case RELOAD_FOR_OPERAND_ADDRESS:
4115 if (++first_op_addr_num >= 0)
4117 first_op_addr_num = i;
4118 need_change = 1;
4120 break;
4121 case RELOAD_FOR_INPUT_ADDRESS:
4122 if (++first_inpaddr_num[rld[i].opnum] >= 0)
4124 first_inpaddr_num[rld[i].opnum] = i;
4125 need_change = 1;
4127 break;
4128 case RELOAD_FOR_OUTPUT_ADDRESS:
4129 if (++first_outpaddr_num[rld[i].opnum] >= 0)
4131 first_outpaddr_num[rld[i].opnum] = i;
4132 need_change = 1;
4134 break;
4135 default:
4136 break;
4140 if (need_change)
4142 for (i = 0; i < n_reloads; i++)
4144 int first_num;
4145 enum reload_type type;
4147 switch (rld[i].when_needed)
4149 case RELOAD_FOR_OPADDR_ADDR:
4150 first_num = first_op_addr_num;
4151 type = RELOAD_FOR_OPERAND_ADDRESS;
4152 break;
4153 case RELOAD_FOR_INPADDR_ADDRESS:
4154 first_num = first_inpaddr_num[rld[i].opnum];
4155 type = RELOAD_FOR_INPUT_ADDRESS;
4156 break;
4157 case RELOAD_FOR_OUTADDR_ADDRESS:
4158 first_num = first_outpaddr_num[rld[i].opnum];
4159 type = RELOAD_FOR_OUTPUT_ADDRESS;
4160 break;
4161 default:
4162 continue;
4164 if (first_num < 0)
4165 continue;
4166 else if (i > first_num)
4167 rld[i].when_needed = type;
4168 else
4170 /* Check if the only TYPE reload that uses reload I is
4171 reload FIRST_NUM. */
4172 for (j = n_reloads - 1; j > first_num; j--)
4174 if (rld[j].when_needed == type
4175 && (rld[i].secondary_p
4176 ? rld[j].secondary_in_reload == i
4177 : reg_mentioned_p (rld[i].in, rld[j].in)))
4179 rld[i].when_needed = type;
4180 break;
4188 /* See if we have any reloads that are now allowed to be merged
4189 because we've changed when the reload is needed to
4190 RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS. Only
4191 check for the most common cases. */
4193 for (i = 0; i < n_reloads; i++)
4194 if (rld[i].in != 0 && rld[i].out == 0
4195 && (rld[i].when_needed == RELOAD_FOR_OPERAND_ADDRESS
4196 || rld[i].when_needed == RELOAD_FOR_OPADDR_ADDR
4197 || rld[i].when_needed == RELOAD_FOR_OTHER_ADDRESS))
4198 for (j = 0; j < n_reloads; j++)
4199 if (i != j && rld[j].in != 0 && rld[j].out == 0
4200 && rld[j].when_needed == rld[i].when_needed
4201 && MATCHES (rld[i].in, rld[j].in)
4202 && rld[i].class == rld[j].class
4203 && !rld[i].nocombine && !rld[j].nocombine
4204 && rld[i].reg_rtx == rld[j].reg_rtx)
4206 rld[i].opnum = MIN (rld[i].opnum, rld[j].opnum);
4207 transfer_replacements (i, j);
4208 rld[j].in = 0;
4211 #ifdef HAVE_cc0
4212 /* If we made any reloads for addresses, see if they violate a
4213 "no input reloads" requirement for this insn. But loads that we
4214 do after the insn (such as for output addresses) are fine. */
4215 if (no_input_reloads)
4216 for (i = 0; i < n_reloads; i++)
4217 if (rld[i].in != 0
4218 && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS
4219 && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS)
4220 abort ();
4221 #endif
4223 /* Compute reload_mode and reload_nregs. */
4224 for (i = 0; i < n_reloads; i++)
4226 rld[i].mode
4227 = (rld[i].inmode == VOIDmode
4228 || (GET_MODE_SIZE (rld[i].outmode)
4229 > GET_MODE_SIZE (rld[i].inmode)))
4230 ? rld[i].outmode : rld[i].inmode;
4232 rld[i].nregs = CLASS_MAX_NREGS (rld[i].class, rld[i].mode);
4235 /* Special case a simple move with an input reload and a
4236 destination of a hard reg, if the hard reg is ok, use it. */
4237 for (i = 0; i < n_reloads; i++)
4238 if (rld[i].when_needed == RELOAD_FOR_INPUT
4239 && GET_CODE (PATTERN (insn)) == SET
4240 && GET_CODE (SET_DEST (PATTERN (insn))) == REG
4241 && SET_SRC (PATTERN (insn)) == rld[i].in)
4243 rtx dest = SET_DEST (PATTERN (insn));
4244 unsigned int regno = REGNO (dest);
4246 if (regno < FIRST_PSEUDO_REGISTER
4247 && TEST_HARD_REG_BIT (reg_class_contents[rld[i].class], regno)
4248 && HARD_REGNO_MODE_OK (regno, rld[i].mode))
4249 rld[i].reg_rtx = dest;
4252 return retval;
4255 /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
4256 accepts a memory operand with constant address. */
4258 static int
4259 alternative_allows_memconst (constraint, altnum)
4260 const char *constraint;
4261 int altnum;
4263 int c;
4264 /* Skip alternatives before the one requested. */
4265 while (altnum > 0)
4267 while (*constraint++ != ',');
4268 altnum--;
4270 /* Scan the requested alternative for 'm' or 'o'.
4271 If one of them is present, this alternative accepts memory constants. */
4272 while ((c = *constraint++) && c != ',' && c != '#')
4273 if (c == 'm' || c == 'o')
4274 return 1;
4275 return 0;
4278 /* Scan X for memory references and scan the addresses for reloading.
4279 Also checks for references to "constant" regs that we want to eliminate
4280 and replaces them with the values they stand for.
4281 We may alter X destructively if it contains a reference to such.
4282 If X is just a constant reg, we return the equivalent value
4283 instead of X.
4285 IND_LEVELS says how many levels of indirect addressing this machine
4286 supports.
4288 OPNUM and TYPE identify the purpose of the reload.
4290 IS_SET_DEST is true if X is the destination of a SET, which is not
4291 appropriate to be replaced by a constant.
4293 INSN, if nonzero, is the insn in which we do the reload. It is used
4294 to determine if we may generate output reloads, and where to put USEs
4295 for pseudos that we have to replace with stack slots.
4297 ADDRESS_RELOADED. If nonzero, is a pointer to where we put the
4298 result of find_reloads_address. */
4300 static rtx
4301 find_reloads_toplev (x, opnum, type, ind_levels, is_set_dest, insn,
4302 address_reloaded)
4303 rtx x;
4304 int opnum;
4305 enum reload_type type;
4306 int ind_levels;
4307 int is_set_dest;
4308 rtx insn;
4309 int *address_reloaded;
4311 RTX_CODE code = GET_CODE (x);
4313 const char *fmt = GET_RTX_FORMAT (code);
4314 int i;
4315 int copied;
4317 if (code == REG)
4319 /* This code is duplicated for speed in find_reloads. */
4320 int regno = REGNO (x);
4321 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4322 x = reg_equiv_constant[regno];
4323 #if 0
4324 /* This creates (subreg (mem...)) which would cause an unnecessary
4325 reload of the mem. */
4326 else if (reg_equiv_mem[regno] != 0)
4327 x = reg_equiv_mem[regno];
4328 #endif
4329 else if (reg_equiv_memory_loc[regno]
4330 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
4332 rtx mem = make_memloc (x, regno);
4333 if (reg_equiv_address[regno]
4334 || ! rtx_equal_p (mem, reg_equiv_mem[regno]))
4336 /* If this is not a toplevel operand, find_reloads doesn't see
4337 this substitution. We have to emit a USE of the pseudo so
4338 that delete_output_reload can see it. */
4339 if (replace_reloads && recog_data.operand[opnum] != x)
4340 /* We mark the USE with QImode so that we recognize it
4341 as one that can be safely deleted at the end of
4342 reload. */
4343 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, x), insn),
4344 QImode);
4345 x = mem;
4346 i = find_reloads_address (GET_MODE (x), &x, XEXP (x, 0), &XEXP (x, 0),
4347 opnum, type, ind_levels, insn);
4348 if (address_reloaded)
4349 *address_reloaded = i;
4352 return x;
4354 if (code == MEM)
4356 rtx tem = x;
4358 i = find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
4359 opnum, type, ind_levels, insn);
4360 if (address_reloaded)
4361 *address_reloaded = i;
4363 return tem;
4366 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG)
4368 /* Check for SUBREG containing a REG that's equivalent to a constant.
4369 If the constant has a known value, truncate it right now.
4370 Similarly if we are extracting a single-word of a multi-word
4371 constant. If the constant is symbolic, allow it to be substituted
4372 normally. push_reload will strip the subreg later. If the
4373 constant is VOIDmode, abort because we will lose the mode of
4374 the register (this should never happen because one of the cases
4375 above should handle it). */
4377 int regno = REGNO (SUBREG_REG (x));
4378 rtx tem;
4380 if (subreg_lowpart_p (x)
4381 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4382 && reg_equiv_constant[regno] != 0
4383 && (tem = gen_lowpart_common (GET_MODE (x),
4384 reg_equiv_constant[regno])) != 0)
4385 return tem;
4387 if (GET_MODE_BITSIZE (GET_MODE (x)) == BITS_PER_WORD
4388 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4389 && reg_equiv_constant[regno] != 0
4390 && (tem = operand_subword (reg_equiv_constant[regno],
4391 SUBREG_BYTE (x) / UNITS_PER_WORD, 0,
4392 GET_MODE (SUBREG_REG (x)))) != 0)
4394 /* TEM is now a word sized constant for the bits from X that
4395 we wanted. However, TEM may be the wrong representation.
4397 Use gen_lowpart_common to convert a CONST_INT into a
4398 CONST_DOUBLE and vice versa as needed according to by the mode
4399 of the SUBREG. */
4400 tem = gen_lowpart_common (GET_MODE (x), tem);
4401 if (!tem)
4402 abort ();
4403 return tem;
4406 /* If the SUBREG is wider than a word, the above test will fail.
4407 For example, we might have a SImode SUBREG of a DImode SUBREG_REG
4408 for a 16 bit target, or a DImode SUBREG of a TImode SUBREG_REG for
4409 a 32 bit target. We still can - and have to - handle this
4410 for non-paradoxical subregs of CONST_INTs. */
4411 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4412 && reg_equiv_constant[regno] != 0
4413 && GET_CODE (reg_equiv_constant[regno]) == CONST_INT
4414 && (GET_MODE_SIZE (GET_MODE (x))
4415 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
4417 int shift = SUBREG_BYTE (x) * BITS_PER_UNIT;
4418 if (WORDS_BIG_ENDIAN)
4419 shift = (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x)))
4420 - GET_MODE_BITSIZE (GET_MODE (x))
4421 - shift);
4422 /* Here we use the knowledge that CONST_INTs have a
4423 HOST_WIDE_INT field. */
4424 if (shift >= HOST_BITS_PER_WIDE_INT)
4425 shift = HOST_BITS_PER_WIDE_INT - 1;
4426 return GEN_INT (INTVAL (reg_equiv_constant[regno]) >> shift);
4429 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4430 && reg_equiv_constant[regno] != 0
4431 && GET_MODE (reg_equiv_constant[regno]) == VOIDmode)
4432 abort ();
4434 /* If the subreg contains a reg that will be converted to a mem,
4435 convert the subreg to a narrower memref now.
4436 Otherwise, we would get (subreg (mem ...) ...),
4437 which would force reload of the mem.
4439 We also need to do this if there is an equivalent MEM that is
4440 not offsettable. In that case, alter_subreg would produce an
4441 invalid address on big-endian machines.
4443 For machines that extend byte loads, we must not reload using
4444 a wider mode if we have a paradoxical SUBREG. find_reloads will
4445 force a reload in that case. So we should not do anything here. */
4447 else if (regno >= FIRST_PSEUDO_REGISTER
4448 #ifdef LOAD_EXTEND_OP
4449 && (GET_MODE_SIZE (GET_MODE (x))
4450 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
4451 #endif
4452 && (reg_equiv_address[regno] != 0
4453 || (reg_equiv_mem[regno] != 0
4454 && (! strict_memory_address_p (GET_MODE (x),
4455 XEXP (reg_equiv_mem[regno], 0))
4456 || ! offsettable_memref_p (reg_equiv_mem[regno])
4457 || num_not_at_initial_offset))))
4458 x = find_reloads_subreg_address (x, 1, opnum, type, ind_levels,
4459 insn);
4462 for (copied = 0, i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4464 if (fmt[i] == 'e')
4466 rtx new_part = find_reloads_toplev (XEXP (x, i), opnum, type,
4467 ind_levels, is_set_dest, insn,
4468 address_reloaded);
4469 /* If we have replaced a reg with it's equivalent memory loc -
4470 that can still be handled here e.g. if it's in a paradoxical
4471 subreg - we must make the change in a copy, rather than using
4472 a destructive change. This way, find_reloads can still elect
4473 not to do the change. */
4474 if (new_part != XEXP (x, i) && ! CONSTANT_P (new_part) && ! copied)
4476 x = shallow_copy_rtx (x);
4477 copied = 1;
4479 XEXP (x, i) = new_part;
4482 return x;
4485 /* Return a mem ref for the memory equivalent of reg REGNO.
4486 This mem ref is not shared with anything. */
4488 static rtx
4489 make_memloc (ad, regno)
4490 rtx ad;
4491 int regno;
4493 /* We must rerun eliminate_regs, in case the elimination
4494 offsets have changed. */
4495 rtx tem
4496 = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0, NULL_RTX), 0);
4498 /* If TEM might contain a pseudo, we must copy it to avoid
4499 modifying it when we do the substitution for the reload. */
4500 if (rtx_varies_p (tem, 0))
4501 tem = copy_rtx (tem);
4503 tem = replace_equiv_address_nv (reg_equiv_memory_loc[regno], tem);
4504 tem = adjust_address_nv (tem, GET_MODE (ad), 0);
4506 /* Copy the result if it's still the same as the equivalence, to avoid
4507 modifying it when we do the substitution for the reload. */
4508 if (tem == reg_equiv_memory_loc[regno])
4509 tem = copy_rtx (tem);
4510 return tem;
4513 /* Record all reloads needed for handling memory address AD
4514 which appears in *LOC in a memory reference to mode MODE
4515 which itself is found in location *MEMREFLOC.
4516 Note that we take shortcuts assuming that no multi-reg machine mode
4517 occurs as part of an address.
4519 OPNUM and TYPE specify the purpose of this reload.
4521 IND_LEVELS says how many levels of indirect addressing this machine
4522 supports.
4524 INSN, if nonzero, is the insn in which we do the reload. It is used
4525 to determine if we may generate output reloads, and where to put USEs
4526 for pseudos that we have to replace with stack slots.
4528 Value is nonzero if this address is reloaded or replaced as a whole.
4529 This is interesting to the caller if the address is an autoincrement.
4531 Note that there is no verification that the address will be valid after
4532 this routine does its work. Instead, we rely on the fact that the address
4533 was valid when reload started. So we need only undo things that reload
4534 could have broken. These are wrong register types, pseudos not allocated
4535 to a hard register, and frame pointer elimination. */
4537 static int
4538 find_reloads_address (mode, memrefloc, ad, loc, opnum, type, ind_levels, insn)
4539 enum machine_mode mode;
4540 rtx *memrefloc;
4541 rtx ad;
4542 rtx *loc;
4543 int opnum;
4544 enum reload_type type;
4545 int ind_levels;
4546 rtx insn;
4548 int regno;
4549 int removed_and = 0;
4550 rtx tem;
4552 /* If the address is a register, see if it is a legitimate address and
4553 reload if not. We first handle the cases where we need not reload
4554 or where we must reload in a non-standard way. */
4556 if (GET_CODE (ad) == REG)
4558 regno = REGNO (ad);
4560 /* If the register is equivalent to an invariant expression, substitute
4561 the invariant, and eliminate any eliminable register references. */
4562 tem = reg_equiv_constant[regno];
4563 if (tem != 0
4564 && (tem = eliminate_regs (tem, mode, insn))
4565 && strict_memory_address_p (mode, tem))
4567 *loc = ad = tem;
4568 return 0;
4571 tem = reg_equiv_memory_loc[regno];
4572 if (tem != 0)
4574 if (reg_equiv_address[regno] != 0 || num_not_at_initial_offset)
4576 tem = make_memloc (ad, regno);
4577 if (! strict_memory_address_p (GET_MODE (tem), XEXP (tem, 0)))
4579 find_reloads_address (GET_MODE (tem), (rtx*) 0, XEXP (tem, 0),
4580 &XEXP (tem, 0), opnum, ADDR_TYPE (type),
4581 ind_levels, insn);
4583 /* We can avoid a reload if the register's equivalent memory
4584 expression is valid as an indirect memory address.
4585 But not all addresses are valid in a mem used as an indirect
4586 address: only reg or reg+constant. */
4588 if (ind_levels > 0
4589 && strict_memory_address_p (mode, tem)
4590 && (GET_CODE (XEXP (tem, 0)) == REG
4591 || (GET_CODE (XEXP (tem, 0)) == PLUS
4592 && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG
4593 && CONSTANT_P (XEXP (XEXP (tem, 0), 1)))))
4595 /* TEM is not the same as what we'll be replacing the
4596 pseudo with after reload, put a USE in front of INSN
4597 in the final reload pass. */
4598 if (replace_reloads
4599 && num_not_at_initial_offset
4600 && ! rtx_equal_p (tem, reg_equiv_mem[regno]))
4602 *loc = tem;
4603 /* We mark the USE with QImode so that we
4604 recognize it as one that can be safely
4605 deleted at the end of reload. */
4606 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad),
4607 insn), QImode);
4609 /* This doesn't really count as replacing the address
4610 as a whole, since it is still a memory access. */
4612 return 0;
4614 ad = tem;
4618 /* The only remaining case where we can avoid a reload is if this is a
4619 hard register that is valid as a base register and which is not the
4620 subject of a CLOBBER in this insn. */
4622 else if (regno < FIRST_PSEUDO_REGISTER
4623 && REGNO_MODE_OK_FOR_BASE_P (regno, mode)
4624 && ! regno_clobbered_p (regno, this_insn, mode, 0))
4625 return 0;
4627 /* If we do not have one of the cases above, we must do the reload. */
4628 push_reload (ad, NULL_RTX, loc, (rtx*) 0, MODE_BASE_REG_CLASS (mode),
4629 GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
4630 return 1;
4633 if (strict_memory_address_p (mode, ad))
4635 /* The address appears valid, so reloads are not needed.
4636 But the address may contain an eliminable register.
4637 This can happen because a machine with indirect addressing
4638 may consider a pseudo register by itself a valid address even when
4639 it has failed to get a hard reg.
4640 So do a tree-walk to find and eliminate all such regs. */
4642 /* But first quickly dispose of a common case. */
4643 if (GET_CODE (ad) == PLUS
4644 && GET_CODE (XEXP (ad, 1)) == CONST_INT
4645 && GET_CODE (XEXP (ad, 0)) == REG
4646 && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
4647 return 0;
4649 subst_reg_equivs_changed = 0;
4650 *loc = subst_reg_equivs (ad, insn);
4652 if (! subst_reg_equivs_changed)
4653 return 0;
4655 /* Check result for validity after substitution. */
4656 if (strict_memory_address_p (mode, ad))
4657 return 0;
4660 #ifdef LEGITIMIZE_RELOAD_ADDRESS
4663 if (memrefloc)
4665 LEGITIMIZE_RELOAD_ADDRESS (ad, GET_MODE (*memrefloc), opnum, type,
4666 ind_levels, win);
4668 break;
4669 win:
4670 *memrefloc = copy_rtx (*memrefloc);
4671 XEXP (*memrefloc, 0) = ad;
4672 move_replacements (&ad, &XEXP (*memrefloc, 0));
4673 return 1;
4675 while (0);
4676 #endif
4678 /* The address is not valid. We have to figure out why. First see if
4679 we have an outer AND and remove it if so. Then analyze what's inside. */
4681 if (GET_CODE (ad) == AND)
4683 removed_and = 1;
4684 loc = &XEXP (ad, 0);
4685 ad = *loc;
4688 /* One possibility for why the address is invalid is that it is itself
4689 a MEM. This can happen when the frame pointer is being eliminated, a
4690 pseudo is not allocated to a hard register, and the offset between the
4691 frame and stack pointers is not its initial value. In that case the
4692 pseudo will have been replaced by a MEM referring to the
4693 stack pointer. */
4694 if (GET_CODE (ad) == MEM)
4696 /* First ensure that the address in this MEM is valid. Then, unless
4697 indirect addresses are valid, reload the MEM into a register. */
4698 tem = ad;
4699 find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
4700 opnum, ADDR_TYPE (type),
4701 ind_levels == 0 ? 0 : ind_levels - 1, insn);
4703 /* If tem was changed, then we must create a new memory reference to
4704 hold it and store it back into memrefloc. */
4705 if (tem != ad && memrefloc)
4707 *memrefloc = copy_rtx (*memrefloc);
4708 copy_replacements (tem, XEXP (*memrefloc, 0));
4709 loc = &XEXP (*memrefloc, 0);
4710 if (removed_and)
4711 loc = &XEXP (*loc, 0);
4714 /* Check similar cases as for indirect addresses as above except
4715 that we can allow pseudos and a MEM since they should have been
4716 taken care of above. */
4718 if (ind_levels == 0
4719 || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
4720 || GET_CODE (XEXP (tem, 0)) == MEM
4721 || ! (GET_CODE (XEXP (tem, 0)) == REG
4722 || (GET_CODE (XEXP (tem, 0)) == PLUS
4723 && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG
4724 && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT)))
4726 /* Must use TEM here, not AD, since it is the one that will
4727 have any subexpressions reloaded, if needed. */
4728 push_reload (tem, NULL_RTX, loc, (rtx*) 0,
4729 MODE_BASE_REG_CLASS (mode), GET_MODE (tem),
4730 VOIDmode, 0,
4731 0, opnum, type);
4732 return ! removed_and;
4734 else
4735 return 0;
4738 /* If we have address of a stack slot but it's not valid because the
4739 displacement is too large, compute the sum in a register.
4740 Handle all base registers here, not just fp/ap/sp, because on some
4741 targets (namely SH) we can also get too large displacements from
4742 big-endian corrections. */
4743 else if (GET_CODE (ad) == PLUS
4744 && GET_CODE (XEXP (ad, 0)) == REG
4745 && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
4746 && REG_MODE_OK_FOR_BASE_P (XEXP (ad, 0), mode)
4747 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4749 /* Unshare the MEM rtx so we can safely alter it. */
4750 if (memrefloc)
4752 *memrefloc = copy_rtx (*memrefloc);
4753 loc = &XEXP (*memrefloc, 0);
4754 if (removed_and)
4755 loc = &XEXP (*loc, 0);
4758 if (double_reg_address_ok)
4760 /* Unshare the sum as well. */
4761 *loc = ad = copy_rtx (ad);
4763 /* Reload the displacement into an index reg.
4764 We assume the frame pointer or arg pointer is a base reg. */
4765 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4766 INDEX_REG_CLASS, GET_MODE (ad), opnum,
4767 type, ind_levels);
4768 return 0;
4770 else
4772 /* If the sum of two regs is not necessarily valid,
4773 reload the sum into a base reg.
4774 That will at least work. */
4775 find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode),
4776 Pmode, opnum, type, ind_levels);
4778 return ! removed_and;
4781 /* If we have an indexed stack slot, there are three possible reasons why
4782 it might be invalid: The index might need to be reloaded, the address
4783 might have been made by frame pointer elimination and hence have a
4784 constant out of range, or both reasons might apply.
4786 We can easily check for an index needing reload, but even if that is the
4787 case, we might also have an invalid constant. To avoid making the
4788 conservative assumption and requiring two reloads, we see if this address
4789 is valid when not interpreted strictly. If it is, the only problem is
4790 that the index needs a reload and find_reloads_address_1 will take care
4791 of it.
4793 If we decide to do something here, it must be that
4794 `double_reg_address_ok' is true and that this address rtl was made by
4795 eliminate_regs. We generate a reload of the fp/sp/ap + constant and
4796 rework the sum so that the reload register will be added to the index.
4797 This is safe because we know the address isn't shared.
4799 We check for fp/ap/sp as both the first and second operand of the
4800 innermost PLUS. */
4802 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4803 && GET_CODE (XEXP (ad, 0)) == PLUS
4804 && (XEXP (XEXP (ad, 0), 0) == frame_pointer_rtx
4805 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
4806 || XEXP (XEXP (ad, 0), 0) == hard_frame_pointer_rtx
4807 #endif
4808 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4809 || XEXP (XEXP (ad, 0), 0) == arg_pointer_rtx
4810 #endif
4811 || XEXP (XEXP (ad, 0), 0) == stack_pointer_rtx)
4812 && ! memory_address_p (mode, ad))
4814 *loc = ad = gen_rtx_PLUS (GET_MODE (ad),
4815 plus_constant (XEXP (XEXP (ad, 0), 0),
4816 INTVAL (XEXP (ad, 1))),
4817 XEXP (XEXP (ad, 0), 1));
4818 find_reloads_address_part (XEXP (ad, 0), &XEXP (ad, 0),
4819 MODE_BASE_REG_CLASS (mode),
4820 GET_MODE (ad), opnum, type, ind_levels);
4821 find_reloads_address_1 (mode, XEXP (ad, 1), 1, &XEXP (ad, 1), opnum,
4822 type, 0, insn);
4824 return 0;
4827 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4828 && GET_CODE (XEXP (ad, 0)) == PLUS
4829 && (XEXP (XEXP (ad, 0), 1) == frame_pointer_rtx
4830 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4831 || XEXP (XEXP (ad, 0), 1) == hard_frame_pointer_rtx
4832 #endif
4833 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4834 || XEXP (XEXP (ad, 0), 1) == arg_pointer_rtx
4835 #endif
4836 || XEXP (XEXP (ad, 0), 1) == stack_pointer_rtx)
4837 && ! memory_address_p (mode, ad))
4839 *loc = ad = gen_rtx_PLUS (GET_MODE (ad),
4840 XEXP (XEXP (ad, 0), 0),
4841 plus_constant (XEXP (XEXP (ad, 0), 1),
4842 INTVAL (XEXP (ad, 1))));
4843 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4844 MODE_BASE_REG_CLASS (mode),
4845 GET_MODE (ad), opnum, type, ind_levels);
4846 find_reloads_address_1 (mode, XEXP (ad, 0), 1, &XEXP (ad, 0), opnum,
4847 type, 0, insn);
4849 return 0;
4852 /* See if address becomes valid when an eliminable register
4853 in a sum is replaced. */
4855 tem = ad;
4856 if (GET_CODE (ad) == PLUS)
4857 tem = subst_indexed_address (ad);
4858 if (tem != ad && strict_memory_address_p (mode, tem))
4860 /* Ok, we win that way. Replace any additional eliminable
4861 registers. */
4863 subst_reg_equivs_changed = 0;
4864 tem = subst_reg_equivs (tem, insn);
4866 /* Make sure that didn't make the address invalid again. */
4868 if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
4870 *loc = tem;
4871 return 0;
4875 /* If constants aren't valid addresses, reload the constant address
4876 into a register. */
4877 if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad))
4879 /* If AD is an address in the constant pool, the MEM rtx may be shared.
4880 Unshare it so we can safely alter it. */
4881 if (memrefloc && GET_CODE (ad) == SYMBOL_REF
4882 && CONSTANT_POOL_ADDRESS_P (ad))
4884 *memrefloc = copy_rtx (*memrefloc);
4885 loc = &XEXP (*memrefloc, 0);
4886 if (removed_and)
4887 loc = &XEXP (*loc, 0);
4890 find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode),
4891 Pmode, opnum, type, ind_levels);
4892 return ! removed_and;
4895 return find_reloads_address_1 (mode, ad, 0, loc, opnum, type, ind_levels,
4896 insn);
4899 /* Find all pseudo regs appearing in AD
4900 that are eliminable in favor of equivalent values
4901 and do not have hard regs; replace them by their equivalents.
4902 INSN, if nonzero, is the insn in which we do the reload. We put USEs in
4903 front of it for pseudos that we have to replace with stack slots. */
4905 static rtx
4906 subst_reg_equivs (ad, insn)
4907 rtx ad;
4908 rtx insn;
4910 RTX_CODE code = GET_CODE (ad);
4911 int i;
4912 const char *fmt;
4914 switch (code)
4916 case HIGH:
4917 case CONST_INT:
4918 case CONST:
4919 case CONST_DOUBLE:
4920 case CONST_VECTOR:
4921 case SYMBOL_REF:
4922 case LABEL_REF:
4923 case PC:
4924 case CC0:
4925 return ad;
4927 case REG:
4929 int regno = REGNO (ad);
4931 if (reg_equiv_constant[regno] != 0)
4933 subst_reg_equivs_changed = 1;
4934 return reg_equiv_constant[regno];
4936 if (reg_equiv_memory_loc[regno] && num_not_at_initial_offset)
4938 rtx mem = make_memloc (ad, regno);
4939 if (! rtx_equal_p (mem, reg_equiv_mem[regno]))
4941 subst_reg_equivs_changed = 1;
4942 /* We mark the USE with QImode so that we recognize it
4943 as one that can be safely deleted at the end of
4944 reload. */
4945 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad), insn),
4946 QImode);
4947 return mem;
4951 return ad;
4953 case PLUS:
4954 /* Quickly dispose of a common case. */
4955 if (XEXP (ad, 0) == frame_pointer_rtx
4956 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4957 return ad;
4958 break;
4960 default:
4961 break;
4964 fmt = GET_RTX_FORMAT (code);
4965 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4966 if (fmt[i] == 'e')
4967 XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i), insn);
4968 return ad;
4971 /* Compute the sum of X and Y, making canonicalizations assumed in an
4972 address, namely: sum constant integers, surround the sum of two
4973 constants with a CONST, put the constant as the second operand, and
4974 group the constant on the outermost sum.
4976 This routine assumes both inputs are already in canonical form. */
4979 form_sum (x, y)
4980 rtx x, y;
4982 rtx tem;
4983 enum machine_mode mode = GET_MODE (x);
4985 if (mode == VOIDmode)
4986 mode = GET_MODE (y);
4988 if (mode == VOIDmode)
4989 mode = Pmode;
4991 if (GET_CODE (x) == CONST_INT)
4992 return plus_constant (y, INTVAL (x));
4993 else if (GET_CODE (y) == CONST_INT)
4994 return plus_constant (x, INTVAL (y));
4995 else if (CONSTANT_P (x))
4996 tem = x, x = y, y = tem;
4998 if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
4999 return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
5001 /* Note that if the operands of Y are specified in the opposite
5002 order in the recursive calls below, infinite recursion will occur. */
5003 if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
5004 return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
5006 /* If both constant, encapsulate sum. Otherwise, just form sum. A
5007 constant will have been placed second. */
5008 if (CONSTANT_P (x) && CONSTANT_P (y))
5010 if (GET_CODE (x) == CONST)
5011 x = XEXP (x, 0);
5012 if (GET_CODE (y) == CONST)
5013 y = XEXP (y, 0);
5015 return gen_rtx_CONST (VOIDmode, gen_rtx_PLUS (mode, x, y));
5018 return gen_rtx_PLUS (mode, x, y);
5021 /* If ADDR is a sum containing a pseudo register that should be
5022 replaced with a constant (from reg_equiv_constant),
5023 return the result of doing so, and also apply the associative
5024 law so that the result is more likely to be a valid address.
5025 (But it is not guaranteed to be one.)
5027 Note that at most one register is replaced, even if more are
5028 replaceable. Also, we try to put the result into a canonical form
5029 so it is more likely to be a valid address.
5031 In all other cases, return ADDR. */
5033 static rtx
5034 subst_indexed_address (addr)
5035 rtx addr;
5037 rtx op0 = 0, op1 = 0, op2 = 0;
5038 rtx tem;
5039 int regno;
5041 if (GET_CODE (addr) == PLUS)
5043 /* Try to find a register to replace. */
5044 op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
5045 if (GET_CODE (op0) == REG
5046 && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
5047 && reg_renumber[regno] < 0
5048 && reg_equiv_constant[regno] != 0)
5049 op0 = reg_equiv_constant[regno];
5050 else if (GET_CODE (op1) == REG
5051 && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
5052 && reg_renumber[regno] < 0
5053 && reg_equiv_constant[regno] != 0)
5054 op1 = reg_equiv_constant[regno];
5055 else if (GET_CODE (op0) == PLUS
5056 && (tem = subst_indexed_address (op0)) != op0)
5057 op0 = tem;
5058 else if (GET_CODE (op1) == PLUS
5059 && (tem = subst_indexed_address (op1)) != op1)
5060 op1 = tem;
5061 else
5062 return addr;
5064 /* Pick out up to three things to add. */
5065 if (GET_CODE (op1) == PLUS)
5066 op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
5067 else if (GET_CODE (op0) == PLUS)
5068 op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
5070 /* Compute the sum. */
5071 if (op2 != 0)
5072 op1 = form_sum (op1, op2);
5073 if (op1 != 0)
5074 op0 = form_sum (op0, op1);
5076 return op0;
5078 return addr;
5081 /* Update the REG_INC notes for an insn. It updates all REG_INC
5082 notes for the instruction which refer to REGNO the to refer
5083 to the reload number.
5085 INSN is the insn for which any REG_INC notes need updating.
5087 REGNO is the register number which has been reloaded.
5089 RELOADNUM is the reload number. */
5091 static void
5092 update_auto_inc_notes (insn, regno, reloadnum)
5093 rtx insn ATTRIBUTE_UNUSED;
5094 int regno ATTRIBUTE_UNUSED;
5095 int reloadnum ATTRIBUTE_UNUSED;
5097 #ifdef AUTO_INC_DEC
5098 rtx link;
5100 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
5101 if (REG_NOTE_KIND (link) == REG_INC
5102 && REGNO (XEXP (link, 0)) == regno)
5103 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5104 #endif
5107 /* Record the pseudo registers we must reload into hard registers in a
5108 subexpression of a would-be memory address, X referring to a value
5109 in mode MODE. (This function is not called if the address we find
5110 is strictly valid.)
5112 CONTEXT = 1 means we are considering regs as index regs,
5113 = 0 means we are considering them as base regs.
5115 OPNUM and TYPE specify the purpose of any reloads made.
5117 IND_LEVELS says how many levels of indirect addressing are
5118 supported at this point in the address.
5120 INSN, if nonzero, is the insn in which we do the reload. It is used
5121 to determine if we may generate output reloads.
5123 We return nonzero if X, as a whole, is reloaded or replaced. */
5125 /* Note that we take shortcuts assuming that no multi-reg machine mode
5126 occurs as part of an address.
5127 Also, this is not fully machine-customizable; it works for machines
5128 such as VAXen and 68000's and 32000's, but other possible machines
5129 could have addressing modes that this does not handle right. */
5131 static int
5132 find_reloads_address_1 (mode, x, context, loc, opnum, type, ind_levels, insn)
5133 enum machine_mode mode;
5134 rtx x;
5135 int context;
5136 rtx *loc;
5137 int opnum;
5138 enum reload_type type;
5139 int ind_levels;
5140 rtx insn;
5142 RTX_CODE code = GET_CODE (x);
5144 switch (code)
5146 case PLUS:
5148 rtx orig_op0 = XEXP (x, 0);
5149 rtx orig_op1 = XEXP (x, 1);
5150 RTX_CODE code0 = GET_CODE (orig_op0);
5151 RTX_CODE code1 = GET_CODE (orig_op1);
5152 rtx op0 = orig_op0;
5153 rtx op1 = orig_op1;
5155 if (GET_CODE (op0) == SUBREG)
5157 op0 = SUBREG_REG (op0);
5158 code0 = GET_CODE (op0);
5159 if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER)
5160 op0 = gen_rtx_REG (word_mode,
5161 (REGNO (op0) +
5162 subreg_regno_offset (REGNO (SUBREG_REG (orig_op0)),
5163 GET_MODE (SUBREG_REG (orig_op0)),
5164 SUBREG_BYTE (orig_op0),
5165 GET_MODE (orig_op0))));
5168 if (GET_CODE (op1) == SUBREG)
5170 op1 = SUBREG_REG (op1);
5171 code1 = GET_CODE (op1);
5172 if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER)
5173 /* ??? Why is this given op1's mode and above for
5174 ??? op0 SUBREGs we use word_mode? */
5175 op1 = gen_rtx_REG (GET_MODE (op1),
5176 (REGNO (op1) +
5177 subreg_regno_offset (REGNO (SUBREG_REG (orig_op1)),
5178 GET_MODE (SUBREG_REG (orig_op1)),
5179 SUBREG_BYTE (orig_op1),
5180 GET_MODE (orig_op1))));
5183 if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
5184 || code0 == ZERO_EXTEND || code1 == MEM)
5186 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5187 type, ind_levels, insn);
5188 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5189 type, ind_levels, insn);
5192 else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
5193 || code1 == ZERO_EXTEND || code0 == MEM)
5195 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5196 type, ind_levels, insn);
5197 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5198 type, ind_levels, insn);
5201 else if (code0 == CONST_INT || code0 == CONST
5202 || code0 == SYMBOL_REF || code0 == LABEL_REF)
5203 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5204 type, ind_levels, insn);
5206 else if (code1 == CONST_INT || code1 == CONST
5207 || code1 == SYMBOL_REF || code1 == LABEL_REF)
5208 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5209 type, ind_levels, insn);
5211 else if (code0 == REG && code1 == REG)
5213 if (REG_OK_FOR_INDEX_P (op0)
5214 && REG_MODE_OK_FOR_BASE_P (op1, mode))
5215 return 0;
5216 else if (REG_OK_FOR_INDEX_P (op1)
5217 && REG_MODE_OK_FOR_BASE_P (op0, mode))
5218 return 0;
5219 else if (REG_MODE_OK_FOR_BASE_P (op1, mode))
5220 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5221 type, ind_levels, insn);
5222 else if (REG_MODE_OK_FOR_BASE_P (op0, mode))
5223 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5224 type, ind_levels, insn);
5225 else if (REG_OK_FOR_INDEX_P (op1))
5226 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5227 type, ind_levels, insn);
5228 else if (REG_OK_FOR_INDEX_P (op0))
5229 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5230 type, ind_levels, insn);
5231 else
5233 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5234 type, ind_levels, insn);
5235 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5236 type, ind_levels, insn);
5240 else if (code0 == REG)
5242 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5243 type, ind_levels, insn);
5244 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5245 type, ind_levels, insn);
5248 else if (code1 == REG)
5250 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5251 type, ind_levels, insn);
5252 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5253 type, ind_levels, insn);
5257 return 0;
5259 case POST_MODIFY:
5260 case PRE_MODIFY:
5262 rtx op0 = XEXP (x, 0);
5263 rtx op1 = XEXP (x, 1);
5265 if (GET_CODE (op1) != PLUS && GET_CODE (op1) != MINUS)
5266 return 0;
5268 /* Currently, we only support {PRE,POST}_MODIFY constructs
5269 where a base register is {inc,dec}remented by the contents
5270 of another register or by a constant value. Thus, these
5271 operands must match. */
5272 if (op0 != XEXP (op1, 0))
5273 abort ();
5275 /* Require index register (or constant). Let's just handle the
5276 register case in the meantime... If the target allows
5277 auto-modify by a constant then we could try replacing a pseudo
5278 register with its equivalent constant where applicable. */
5279 if (REG_P (XEXP (op1, 1)))
5280 if (!REGNO_OK_FOR_INDEX_P (REGNO (XEXP (op1, 1))))
5281 find_reloads_address_1 (mode, XEXP (op1, 1), 1, &XEXP (op1, 1),
5282 opnum, type, ind_levels, insn);
5284 if (REG_P (XEXP (op1, 0)))
5286 int regno = REGNO (XEXP (op1, 0));
5287 int reloadnum;
5289 /* A register that is incremented cannot be constant! */
5290 if (regno >= FIRST_PSEUDO_REGISTER
5291 && reg_equiv_constant[regno] != 0)
5292 abort ();
5294 /* Handle a register that is equivalent to a memory location
5295 which cannot be addressed directly. */
5296 if (reg_equiv_memory_loc[regno] != 0
5297 && (reg_equiv_address[regno] != 0
5298 || num_not_at_initial_offset))
5300 rtx tem = make_memloc (XEXP (x, 0), regno);
5302 if (reg_equiv_address[regno]
5303 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5305 /* First reload the memory location's address.
5306 We can't use ADDR_TYPE (type) here, because we need to
5307 write back the value after reading it, hence we actually
5308 need two registers. */
5309 find_reloads_address (GET_MODE (tem), 0, XEXP (tem, 0),
5310 &XEXP (tem, 0), opnum,
5311 RELOAD_OTHER,
5312 ind_levels, insn);
5314 /* Then reload the memory location into a base
5315 register. */
5316 reloadnum = push_reload (tem, tem, &XEXP (x, 0),
5317 &XEXP (op1, 0),
5318 MODE_BASE_REG_CLASS (mode),
5319 GET_MODE (x), GET_MODE (x), 0,
5320 0, opnum, RELOAD_OTHER);
5322 update_auto_inc_notes (this_insn, regno, reloadnum);
5323 return 0;
5327 if (reg_renumber[regno] >= 0)
5328 regno = reg_renumber[regno];
5330 /* We require a base register here... */
5331 if (!REGNO_MODE_OK_FOR_BASE_P (regno, GET_MODE (x)))
5333 reloadnum = push_reload (XEXP (op1, 0), XEXP (x, 0),
5334 &XEXP (op1, 0), &XEXP (x, 0),
5335 MODE_BASE_REG_CLASS (mode),
5336 GET_MODE (x), GET_MODE (x), 0, 0,
5337 opnum, RELOAD_OTHER);
5339 update_auto_inc_notes (this_insn, regno, reloadnum);
5340 return 0;
5343 else
5344 abort ();
5346 return 0;
5348 case POST_INC:
5349 case POST_DEC:
5350 case PRE_INC:
5351 case PRE_DEC:
5352 if (GET_CODE (XEXP (x, 0)) == REG)
5354 int regno = REGNO (XEXP (x, 0));
5355 int value = 0;
5356 rtx x_orig = x;
5358 /* A register that is incremented cannot be constant! */
5359 if (regno >= FIRST_PSEUDO_REGISTER
5360 && reg_equiv_constant[regno] != 0)
5361 abort ();
5363 /* Handle a register that is equivalent to a memory location
5364 which cannot be addressed directly. */
5365 if (reg_equiv_memory_loc[regno] != 0
5366 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5368 rtx tem = make_memloc (XEXP (x, 0), regno);
5369 if (reg_equiv_address[regno]
5370 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5372 /* First reload the memory location's address.
5373 We can't use ADDR_TYPE (type) here, because we need to
5374 write back the value after reading it, hence we actually
5375 need two registers. */
5376 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5377 &XEXP (tem, 0), opnum, type,
5378 ind_levels, insn);
5379 /* Put this inside a new increment-expression. */
5380 x = gen_rtx_fmt_e (GET_CODE (x), GET_MODE (x), tem);
5381 /* Proceed to reload that, as if it contained a register. */
5385 /* If we have a hard register that is ok as an index,
5386 don't make a reload. If an autoincrement of a nice register
5387 isn't "valid", it must be that no autoincrement is "valid".
5388 If that is true and something made an autoincrement anyway,
5389 this must be a special context where one is allowed.
5390 (For example, a "push" instruction.)
5391 We can't improve this address, so leave it alone. */
5393 /* Otherwise, reload the autoincrement into a suitable hard reg
5394 and record how much to increment by. */
5396 if (reg_renumber[regno] >= 0)
5397 regno = reg_renumber[regno];
5398 if ((regno >= FIRST_PSEUDO_REGISTER
5399 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
5400 : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
5402 int reloadnum;
5404 /* If we can output the register afterwards, do so, this
5405 saves the extra update.
5406 We can do so if we have an INSN - i.e. no JUMP_INSN nor
5407 CALL_INSN - and it does not set CC0.
5408 But don't do this if we cannot directly address the
5409 memory location, since this will make it harder to
5410 reuse address reloads, and increases register pressure.
5411 Also don't do this if we can probably update x directly. */
5412 rtx equiv = (GET_CODE (XEXP (x, 0)) == MEM
5413 ? XEXP (x, 0)
5414 : reg_equiv_mem[regno]);
5415 int icode = (int) add_optab->handlers[(int) Pmode].insn_code;
5416 if (insn && GET_CODE (insn) == INSN && equiv
5417 && memory_operand (equiv, GET_MODE (equiv))
5418 #ifdef HAVE_cc0
5419 && ! sets_cc0_p (PATTERN (insn))
5420 #endif
5421 && ! (icode != CODE_FOR_nothing
5422 && ((*insn_data[icode].operand[0].predicate)
5423 (equiv, Pmode))
5424 && ((*insn_data[icode].operand[1].predicate)
5425 (equiv, Pmode))))
5427 /* We use the original pseudo for loc, so that
5428 emit_reload_insns() knows which pseudo this
5429 reload refers to and updates the pseudo rtx, not
5430 its equivalent memory location, as well as the
5431 corresponding entry in reg_last_reload_reg. */
5432 loc = &XEXP (x_orig, 0);
5433 x = XEXP (x, 0);
5434 reloadnum
5435 = push_reload (x, x, loc, loc,
5436 (context ? INDEX_REG_CLASS :
5437 MODE_BASE_REG_CLASS (mode)),
5438 GET_MODE (x), GET_MODE (x), 0, 0,
5439 opnum, RELOAD_OTHER);
5441 else
5443 reloadnum
5444 = push_reload (x, NULL_RTX, loc, (rtx*) 0,
5445 (context ? INDEX_REG_CLASS :
5446 MODE_BASE_REG_CLASS (mode)),
5447 GET_MODE (x), GET_MODE (x), 0, 0,
5448 opnum, type);
5449 rld[reloadnum].inc
5450 = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
5452 value = 1;
5455 update_auto_inc_notes (this_insn, REGNO (XEXP (x_orig, 0)),
5456 reloadnum);
5458 return value;
5461 else if (GET_CODE (XEXP (x, 0)) == MEM)
5463 /* This is probably the result of a substitution, by eliminate_regs,
5464 of an equivalent address for a pseudo that was not allocated to a
5465 hard register. Verify that the specified address is valid and
5466 reload it into a register. */
5467 /* Variable `tem' might or might not be used in FIND_REG_INC_NOTE. */
5468 rtx tem ATTRIBUTE_UNUSED = XEXP (x, 0);
5469 rtx link;
5470 int reloadnum;
5472 /* Since we know we are going to reload this item, don't decrement
5473 for the indirection level.
5475 Note that this is actually conservative: it would be slightly
5476 more efficient to use the value of SPILL_INDIRECT_LEVELS from
5477 reload1.c here. */
5478 /* We can't use ADDR_TYPE (type) here, because we need to
5479 write back the value after reading it, hence we actually
5480 need two registers. */
5481 find_reloads_address (GET_MODE (x), &XEXP (x, 0),
5482 XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0),
5483 opnum, type, ind_levels, insn);
5485 reloadnum = push_reload (x, NULL_RTX, loc, (rtx*) 0,
5486 (context ? INDEX_REG_CLASS :
5487 MODE_BASE_REG_CLASS (mode)),
5488 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5489 rld[reloadnum].inc
5490 = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
5492 link = FIND_REG_INC_NOTE (this_insn, tem);
5493 if (link != 0)
5494 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5496 return 1;
5498 return 0;
5500 case MEM:
5501 /* This is probably the result of a substitution, by eliminate_regs, of
5502 an equivalent address for a pseudo that was not allocated to a hard
5503 register. Verify that the specified address is valid and reload it
5504 into a register.
5506 Since we know we are going to reload this item, don't decrement for
5507 the indirection level.
5509 Note that this is actually conservative: it would be slightly more
5510 efficient to use the value of SPILL_INDIRECT_LEVELS from
5511 reload1.c here. */
5513 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5514 opnum, ADDR_TYPE (type), ind_levels, insn);
5515 push_reload (*loc, NULL_RTX, loc, (rtx*) 0,
5516 (context ? INDEX_REG_CLASS : MODE_BASE_REG_CLASS (mode)),
5517 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5518 return 1;
5520 case REG:
5522 int regno = REGNO (x);
5524 if (reg_equiv_constant[regno] != 0)
5526 find_reloads_address_part (reg_equiv_constant[regno], loc,
5527 (context ? INDEX_REG_CLASS :
5528 MODE_BASE_REG_CLASS (mode)),
5529 GET_MODE (x), opnum, type, ind_levels);
5530 return 1;
5533 #if 0 /* This might screw code in reload1.c to delete prior output-reload
5534 that feeds this insn. */
5535 if (reg_equiv_mem[regno] != 0)
5537 push_reload (reg_equiv_mem[regno], NULL_RTX, loc, (rtx*) 0,
5538 (context ? INDEX_REG_CLASS :
5539 MODE_BASE_REG_CLASS (mode)),
5540 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5541 return 1;
5543 #endif
5545 if (reg_equiv_memory_loc[regno]
5546 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5548 rtx tem = make_memloc (x, regno);
5549 if (reg_equiv_address[regno] != 0
5550 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5552 x = tem;
5553 find_reloads_address (GET_MODE (x), &x, XEXP (x, 0),
5554 &XEXP (x, 0), opnum, ADDR_TYPE (type),
5555 ind_levels, insn);
5559 if (reg_renumber[regno] >= 0)
5560 regno = reg_renumber[regno];
5562 if ((regno >= FIRST_PSEUDO_REGISTER
5563 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
5564 : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
5566 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5567 (context ? INDEX_REG_CLASS : MODE_BASE_REG_CLASS (mode)),
5568 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5569 return 1;
5572 /* If a register appearing in an address is the subject of a CLOBBER
5573 in this insn, reload it into some other register to be safe.
5574 The CLOBBER is supposed to make the register unavailable
5575 from before this insn to after it. */
5576 if (regno_clobbered_p (regno, this_insn, GET_MODE (x), 0))
5578 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5579 (context ? INDEX_REG_CLASS : MODE_BASE_REG_CLASS (mode)),
5580 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5581 return 1;
5584 return 0;
5586 case SUBREG:
5587 if (GET_CODE (SUBREG_REG (x)) == REG)
5589 /* If this is a SUBREG of a hard register and the resulting register
5590 is of the wrong class, reload the whole SUBREG. This avoids
5591 needless copies if SUBREG_REG is multi-word. */
5592 if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5594 int regno = subreg_regno (x);
5596 if (! (context ? REGNO_OK_FOR_INDEX_P (regno)
5597 : REGNO_MODE_OK_FOR_BASE_P (regno, mode)))
5599 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5600 (context ? INDEX_REG_CLASS :
5601 MODE_BASE_REG_CLASS (mode)),
5602 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5603 return 1;
5606 /* If this is a SUBREG of a pseudo-register, and the pseudo-register
5607 is larger than the class size, then reload the whole SUBREG. */
5608 else
5610 enum reg_class class = (context ? INDEX_REG_CLASS
5611 : MODE_BASE_REG_CLASS (mode));
5612 if (CLASS_MAX_NREGS (class, GET_MODE (SUBREG_REG (x)))
5613 > reg_class_size[class])
5615 x = find_reloads_subreg_address (x, 0, opnum, type,
5616 ind_levels, insn);
5617 push_reload (x, NULL_RTX, loc, (rtx*) 0, class,
5618 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5619 return 1;
5623 break;
5625 default:
5626 break;
5630 const char *fmt = GET_RTX_FORMAT (code);
5631 int i;
5633 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5635 if (fmt[i] == 'e')
5636 find_reloads_address_1 (mode, XEXP (x, i), context, &XEXP (x, i),
5637 opnum, type, ind_levels, insn);
5641 return 0;
5644 /* X, which is found at *LOC, is a part of an address that needs to be
5645 reloaded into a register of class CLASS. If X is a constant, or if
5646 X is a PLUS that contains a constant, check that the constant is a
5647 legitimate operand and that we are supposed to be able to load
5648 it into the register.
5650 If not, force the constant into memory and reload the MEM instead.
5652 MODE is the mode to use, in case X is an integer constant.
5654 OPNUM and TYPE describe the purpose of any reloads made.
5656 IND_LEVELS says how many levels of indirect addressing this machine
5657 supports. */
5659 static void
5660 find_reloads_address_part (x, loc, class, mode, opnum, type, ind_levels)
5661 rtx x;
5662 rtx *loc;
5663 enum reg_class class;
5664 enum machine_mode mode;
5665 int opnum;
5666 enum reload_type type;
5667 int ind_levels;
5669 if (CONSTANT_P (x)
5670 && (! LEGITIMATE_CONSTANT_P (x)
5671 || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
5673 rtx tem;
5675 tem = x = force_const_mem (mode, x);
5676 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5677 opnum, type, ind_levels, 0);
5680 else if (GET_CODE (x) == PLUS
5681 && CONSTANT_P (XEXP (x, 1))
5682 && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
5683 || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
5685 rtx tem;
5687 tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
5688 x = gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), tem);
5689 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5690 opnum, type, ind_levels, 0);
5693 push_reload (x, NULL_RTX, loc, (rtx*) 0, class,
5694 mode, VOIDmode, 0, 0, opnum, type);
5697 /* X, a subreg of a pseudo, is a part of an address that needs to be
5698 reloaded.
5700 If the pseudo is equivalent to a memory location that cannot be directly
5701 addressed, make the necessary address reloads.
5703 If address reloads have been necessary, or if the address is changed
5704 by register elimination, return the rtx of the memory location;
5705 otherwise, return X.
5707 If FORCE_REPLACE is nonzero, unconditionally replace the subreg with the
5708 memory location.
5710 OPNUM and TYPE identify the purpose of the reload.
5712 IND_LEVELS says how many levels of indirect addressing are
5713 supported at this point in the address.
5715 INSN, if nonzero, is the insn in which we do the reload. It is used
5716 to determine where to put USEs for pseudos that we have to replace with
5717 stack slots. */
5719 static rtx
5720 find_reloads_subreg_address (x, force_replace, opnum, type,
5721 ind_levels, insn)
5722 rtx x;
5723 int force_replace;
5724 int opnum;
5725 enum reload_type type;
5726 int ind_levels;
5727 rtx insn;
5729 int regno = REGNO (SUBREG_REG (x));
5731 if (reg_equiv_memory_loc[regno])
5733 /* If the address is not directly addressable, or if the address is not
5734 offsettable, then it must be replaced. */
5735 if (! force_replace
5736 && (reg_equiv_address[regno]
5737 || ! offsettable_memref_p (reg_equiv_mem[regno])))
5738 force_replace = 1;
5740 if (force_replace || num_not_at_initial_offset)
5742 rtx tem = make_memloc (SUBREG_REG (x), regno);
5744 /* If the address changes because of register elimination, then
5745 it must be replaced. */
5746 if (force_replace
5747 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5749 int offset = SUBREG_BYTE (x);
5750 unsigned outer_size = GET_MODE_SIZE (GET_MODE (x));
5751 unsigned inner_size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
5753 XEXP (tem, 0) = plus_constant (XEXP (tem, 0), offset);
5754 PUT_MODE (tem, GET_MODE (x));
5756 /* If this was a paradoxical subreg that we replaced, the
5757 resulting memory must be sufficiently aligned to allow
5758 us to widen the mode of the memory. */
5759 if (outer_size > inner_size && STRICT_ALIGNMENT)
5761 rtx base;
5763 base = XEXP (tem, 0);
5764 if (GET_CODE (base) == PLUS)
5766 if (GET_CODE (XEXP (base, 1)) == CONST_INT
5767 && INTVAL (XEXP (base, 1)) % outer_size != 0)
5768 return x;
5769 base = XEXP (base, 0);
5771 if (GET_CODE (base) != REG
5772 || (REGNO_POINTER_ALIGN (REGNO (base))
5773 < outer_size * BITS_PER_UNIT))
5774 return x;
5777 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5778 &XEXP (tem, 0), opnum, ADDR_TYPE (type),
5779 ind_levels, insn);
5781 /* If this is not a toplevel operand, find_reloads doesn't see
5782 this substitution. We have to emit a USE of the pseudo so
5783 that delete_output_reload can see it. */
5784 if (replace_reloads && recog_data.operand[opnum] != x)
5785 /* We mark the USE with QImode so that we recognize it
5786 as one that can be safely deleted at the end of
5787 reload. */
5788 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode,
5789 SUBREG_REG (x)),
5790 insn), QImode);
5791 x = tem;
5795 return x;
5798 /* Substitute into the current INSN the registers into which we have reloaded
5799 the things that need reloading. The array `replacements'
5800 contains the locations of all pointers that must be changed
5801 and says what to replace them with.
5803 Return the rtx that X translates into; usually X, but modified. */
5805 void
5806 subst_reloads (insn)
5807 rtx insn;
5809 int i;
5811 for (i = 0; i < n_replacements; i++)
5813 struct replacement *r = &replacements[i];
5814 rtx reloadreg = rld[r->what].reg_rtx;
5815 if (reloadreg)
5817 #ifdef ENABLE_CHECKING
5818 /* Internal consistency test. Check that we don't modify
5819 anything in the equivalence arrays. Whenever something from
5820 those arrays needs to be reloaded, it must be unshared before
5821 being substituted into; the equivalence must not be modified.
5822 Otherwise, if the equivalence is used after that, it will
5823 have been modified, and the thing substituted (probably a
5824 register) is likely overwritten and not a usable equivalence. */
5825 int check_regno;
5827 for (check_regno = 0; check_regno < max_regno; check_regno++)
5829 #define CHECK_MODF(ARRAY) \
5830 if (ARRAY[check_regno] \
5831 && loc_mentioned_in_p (r->where, \
5832 ARRAY[check_regno])) \
5833 abort ()
5835 CHECK_MODF (reg_equiv_constant);
5836 CHECK_MODF (reg_equiv_memory_loc);
5837 CHECK_MODF (reg_equiv_address);
5838 CHECK_MODF (reg_equiv_mem);
5839 #undef CHECK_MODF
5841 #endif /* ENABLE_CHECKING */
5843 /* If we're replacing a LABEL_REF with a register, add a
5844 REG_LABEL note to indicate to flow which label this
5845 register refers to. */
5846 if (GET_CODE (*r->where) == LABEL_REF
5847 && GET_CODE (insn) == JUMP_INSN)
5848 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
5849 XEXP (*r->where, 0),
5850 REG_NOTES (insn));
5852 /* Encapsulate RELOADREG so its machine mode matches what
5853 used to be there. Note that gen_lowpart_common will
5854 do the wrong thing if RELOADREG is multi-word. RELOADREG
5855 will always be a REG here. */
5856 if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
5857 reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg));
5859 /* If we are putting this into a SUBREG and RELOADREG is a
5860 SUBREG, we would be making nested SUBREGs, so we have to fix
5861 this up. Note that r->where == &SUBREG_REG (*r->subreg_loc). */
5863 if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG)
5865 if (GET_MODE (*r->subreg_loc)
5866 == GET_MODE (SUBREG_REG (reloadreg)))
5867 *r->subreg_loc = SUBREG_REG (reloadreg);
5868 else
5870 int final_offset =
5871 SUBREG_BYTE (*r->subreg_loc) + SUBREG_BYTE (reloadreg);
5873 /* When working with SUBREGs the rule is that the byte
5874 offset must be a multiple of the SUBREG's mode. */
5875 final_offset = (final_offset /
5876 GET_MODE_SIZE (GET_MODE (*r->subreg_loc)));
5877 final_offset = (final_offset *
5878 GET_MODE_SIZE (GET_MODE (*r->subreg_loc)));
5880 *r->where = SUBREG_REG (reloadreg);
5881 SUBREG_BYTE (*r->subreg_loc) = final_offset;
5884 else
5885 *r->where = reloadreg;
5887 /* If reload got no reg and isn't optional, something's wrong. */
5888 else if (! rld[r->what].optional)
5889 abort ();
5893 /* Make a copy of any replacements being done into X and move those
5894 copies to locations in Y, a copy of X. */
5896 void
5897 copy_replacements (x, y)
5898 rtx x, y;
5900 /* We can't support X being a SUBREG because we might then need to know its
5901 location if something inside it was replaced. */
5902 if (GET_CODE (x) == SUBREG)
5903 abort ();
5905 copy_replacements_1 (&x, &y, n_replacements);
5908 static void
5909 copy_replacements_1 (px, py, orig_replacements)
5910 rtx *px;
5911 rtx *py;
5912 int orig_replacements;
5914 int i, j;
5915 rtx x, y;
5916 struct replacement *r;
5917 enum rtx_code code;
5918 const char *fmt;
5920 for (j = 0; j < orig_replacements; j++)
5922 if (replacements[j].subreg_loc == px)
5924 r = &replacements[n_replacements++];
5925 r->where = replacements[j].where;
5926 r->subreg_loc = py;
5927 r->what = replacements[j].what;
5928 r->mode = replacements[j].mode;
5930 else if (replacements[j].where == px)
5932 r = &replacements[n_replacements++];
5933 r->where = py;
5934 r->subreg_loc = 0;
5935 r->what = replacements[j].what;
5936 r->mode = replacements[j].mode;
5940 x = *px;
5941 y = *py;
5942 code = GET_CODE (x);
5943 fmt = GET_RTX_FORMAT (code);
5945 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5947 if (fmt[i] == 'e')
5948 copy_replacements_1 (&XEXP (x, i), &XEXP (y, i), orig_replacements);
5949 else if (fmt[i] == 'E')
5950 for (j = XVECLEN (x, i); --j >= 0; )
5951 copy_replacements_1 (&XVECEXP (x, i, j), &XVECEXP (y, i, j),
5952 orig_replacements);
5956 /* Change any replacements being done to *X to be done to *Y */
5958 void
5959 move_replacements (x, y)
5960 rtx *x;
5961 rtx *y;
5963 int i;
5965 for (i = 0; i < n_replacements; i++)
5966 if (replacements[i].subreg_loc == x)
5967 replacements[i].subreg_loc = y;
5968 else if (replacements[i].where == x)
5970 replacements[i].where = y;
5971 replacements[i].subreg_loc = 0;
5975 /* If LOC was scheduled to be replaced by something, return the replacement.
5976 Otherwise, return *LOC. */
5979 find_replacement (loc)
5980 rtx *loc;
5982 struct replacement *r;
5984 for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
5986 rtx reloadreg = rld[r->what].reg_rtx;
5988 if (reloadreg && r->where == loc)
5990 if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
5991 reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg));
5993 return reloadreg;
5995 else if (reloadreg && r->subreg_loc == loc)
5997 /* RELOADREG must be either a REG or a SUBREG.
5999 ??? Is it actually still ever a SUBREG? If so, why? */
6001 if (GET_CODE (reloadreg) == REG)
6002 return gen_rtx_REG (GET_MODE (*loc),
6003 (REGNO (reloadreg) +
6004 subreg_regno_offset (REGNO (SUBREG_REG (*loc)),
6005 GET_MODE (SUBREG_REG (*loc)),
6006 SUBREG_BYTE (*loc),
6007 GET_MODE (*loc))));
6008 else if (GET_MODE (reloadreg) == GET_MODE (*loc))
6009 return reloadreg;
6010 else
6012 int final_offset = SUBREG_BYTE (reloadreg) + SUBREG_BYTE (*loc);
6014 /* When working with SUBREGs the rule is that the byte
6015 offset must be a multiple of the SUBREG's mode. */
6016 final_offset = (final_offset / GET_MODE_SIZE (GET_MODE (*loc)));
6017 final_offset = (final_offset * GET_MODE_SIZE (GET_MODE (*loc)));
6018 return gen_rtx_SUBREG (GET_MODE (*loc), SUBREG_REG (reloadreg),
6019 final_offset);
6024 /* If *LOC is a PLUS, MINUS, or MULT, see if a replacement is scheduled for
6025 what's inside and make a new rtl if so. */
6026 if (GET_CODE (*loc) == PLUS || GET_CODE (*loc) == MINUS
6027 || GET_CODE (*loc) == MULT)
6029 rtx x = find_replacement (&XEXP (*loc, 0));
6030 rtx y = find_replacement (&XEXP (*loc, 1));
6032 if (x != XEXP (*loc, 0) || y != XEXP (*loc, 1))
6033 return gen_rtx_fmt_ee (GET_CODE (*loc), GET_MODE (*loc), x, y);
6036 return *loc;
6039 /* Return nonzero if register in range [REGNO, ENDREGNO)
6040 appears either explicitly or implicitly in X
6041 other than being stored into (except for earlyclobber operands).
6043 References contained within the substructure at LOC do not count.
6044 LOC may be zero, meaning don't ignore anything.
6046 This is similar to refers_to_regno_p in rtlanal.c except that we
6047 look at equivalences for pseudos that didn't get hard registers. */
6050 refers_to_regno_for_reload_p (regno, endregno, x, loc)
6051 unsigned int regno, endregno;
6052 rtx x;
6053 rtx *loc;
6055 int i;
6056 unsigned int r;
6057 RTX_CODE code;
6058 const char *fmt;
6060 if (x == 0)
6061 return 0;
6063 repeat:
6064 code = GET_CODE (x);
6066 switch (code)
6068 case REG:
6069 r = REGNO (x);
6071 /* If this is a pseudo, a hard register must not have been allocated.
6072 X must therefore either be a constant or be in memory. */
6073 if (r >= FIRST_PSEUDO_REGISTER)
6075 if (reg_equiv_memory_loc[r])
6076 return refers_to_regno_for_reload_p (regno, endregno,
6077 reg_equiv_memory_loc[r],
6078 (rtx*) 0);
6080 if (reg_equiv_constant[r])
6081 return 0;
6083 abort ();
6086 return (endregno > r
6087 && regno < r + (r < FIRST_PSEUDO_REGISTER
6088 ? HARD_REGNO_NREGS (r, GET_MODE (x))
6089 : 1));
6091 case SUBREG:
6092 /* If this is a SUBREG of a hard reg, we can see exactly which
6093 registers are being modified. Otherwise, handle normally. */
6094 if (GET_CODE (SUBREG_REG (x)) == REG
6095 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
6097 unsigned int inner_regno = subreg_regno (x);
6098 unsigned int inner_endregno
6099 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
6100 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
6102 return endregno > inner_regno && regno < inner_endregno;
6104 break;
6106 case CLOBBER:
6107 case SET:
6108 if (&SET_DEST (x) != loc
6109 /* Note setting a SUBREG counts as referring to the REG it is in for
6110 a pseudo but not for hard registers since we can
6111 treat each word individually. */
6112 && ((GET_CODE (SET_DEST (x)) == SUBREG
6113 && loc != &SUBREG_REG (SET_DEST (x))
6114 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
6115 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
6116 && refers_to_regno_for_reload_p (regno, endregno,
6117 SUBREG_REG (SET_DEST (x)),
6118 loc))
6119 /* If the output is an earlyclobber operand, this is
6120 a conflict. */
6121 || ((GET_CODE (SET_DEST (x)) != REG
6122 || earlyclobber_operand_p (SET_DEST (x)))
6123 && refers_to_regno_for_reload_p (regno, endregno,
6124 SET_DEST (x), loc))))
6125 return 1;
6127 if (code == CLOBBER || loc == &SET_SRC (x))
6128 return 0;
6129 x = SET_SRC (x);
6130 goto repeat;
6132 default:
6133 break;
6136 /* X does not match, so try its subexpressions. */
6138 fmt = GET_RTX_FORMAT (code);
6139 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6141 if (fmt[i] == 'e' && loc != &XEXP (x, i))
6143 if (i == 0)
6145 x = XEXP (x, 0);
6146 goto repeat;
6148 else
6149 if (refers_to_regno_for_reload_p (regno, endregno,
6150 XEXP (x, i), loc))
6151 return 1;
6153 else if (fmt[i] == 'E')
6155 int j;
6156 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6157 if (loc != &XVECEXP (x, i, j)
6158 && refers_to_regno_for_reload_p (regno, endregno,
6159 XVECEXP (x, i, j), loc))
6160 return 1;
6163 return 0;
6166 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
6167 we check if any register number in X conflicts with the relevant register
6168 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
6169 contains a MEM (we don't bother checking for memory addresses that can't
6170 conflict because we expect this to be a rare case.
6172 This function is similar to reg_overlap_mentioned_p in rtlanal.c except
6173 that we look at equivalences for pseudos that didn't get hard registers. */
6176 reg_overlap_mentioned_for_reload_p (x, in)
6177 rtx x, in;
6179 int regno, endregno;
6181 /* Overly conservative. */
6182 if (GET_CODE (x) == STRICT_LOW_PART
6183 || GET_RTX_CLASS (GET_CODE (x)) == 'a')
6184 x = XEXP (x, 0);
6186 /* If either argument is a constant, then modifying X can not affect IN. */
6187 if (CONSTANT_P (x) || CONSTANT_P (in))
6188 return 0;
6189 else if (GET_CODE (x) == SUBREG)
6191 regno = REGNO (SUBREG_REG (x));
6192 if (regno < FIRST_PSEUDO_REGISTER)
6193 regno += subreg_regno_offset (REGNO (SUBREG_REG (x)),
6194 GET_MODE (SUBREG_REG (x)),
6195 SUBREG_BYTE (x),
6196 GET_MODE (x));
6198 else if (GET_CODE (x) == REG)
6200 regno = REGNO (x);
6202 /* If this is a pseudo, it must not have been assigned a hard register.
6203 Therefore, it must either be in memory or be a constant. */
6205 if (regno >= FIRST_PSEUDO_REGISTER)
6207 if (reg_equiv_memory_loc[regno])
6208 return refers_to_mem_for_reload_p (in);
6209 else if (reg_equiv_constant[regno])
6210 return 0;
6211 abort ();
6214 else if (GET_CODE (x) == MEM)
6215 return refers_to_mem_for_reload_p (in);
6216 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
6217 || GET_CODE (x) == CC0)
6218 return reg_mentioned_p (x, in);
6219 else if (GET_CODE (x) == PLUS)
6220 return (reg_overlap_mentioned_for_reload_p (XEXP (x, 0), in)
6221 || reg_overlap_mentioned_for_reload_p (XEXP (x, 1), in));
6222 else
6223 abort ();
6225 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
6226 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
6228 return refers_to_regno_for_reload_p (regno, endregno, in, (rtx*) 0);
6231 /* Return nonzero if anything in X contains a MEM. Look also for pseudo
6232 registers. */
6235 refers_to_mem_for_reload_p (x)
6236 rtx x;
6238 const char *fmt;
6239 int i;
6241 if (GET_CODE (x) == MEM)
6242 return 1;
6244 if (GET_CODE (x) == REG)
6245 return (REGNO (x) >= FIRST_PSEUDO_REGISTER
6246 && reg_equiv_memory_loc[REGNO (x)]);
6248 fmt = GET_RTX_FORMAT (GET_CODE (x));
6249 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
6250 if (fmt[i] == 'e'
6251 && (GET_CODE (XEXP (x, i)) == MEM
6252 || refers_to_mem_for_reload_p (XEXP (x, i))))
6253 return 1;
6255 return 0;
6258 /* Check the insns before INSN to see if there is a suitable register
6259 containing the same value as GOAL.
6260 If OTHER is -1, look for a register in class CLASS.
6261 Otherwise, just see if register number OTHER shares GOAL's value.
6263 Return an rtx for the register found, or zero if none is found.
6265 If RELOAD_REG_P is (short *)1,
6266 we reject any hard reg that appears in reload_reg_rtx
6267 because such a hard reg is also needed coming into this insn.
6269 If RELOAD_REG_P is any other nonzero value,
6270 it is a vector indexed by hard reg number
6271 and we reject any hard reg whose element in the vector is nonnegative
6272 as well as any that appears in reload_reg_rtx.
6274 If GOAL is zero, then GOALREG is a register number; we look
6275 for an equivalent for that register.
6277 MODE is the machine mode of the value we want an equivalence for.
6278 If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
6280 This function is used by jump.c as well as in the reload pass.
6282 If GOAL is the sum of the stack pointer and a constant, we treat it
6283 as if it were a constant except that sp is required to be unchanging. */
6286 find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode)
6287 rtx goal;
6288 rtx insn;
6289 enum reg_class class;
6290 int other;
6291 short *reload_reg_p;
6292 int goalreg;
6293 enum machine_mode mode;
6295 rtx p = insn;
6296 rtx goaltry, valtry, value, where;
6297 rtx pat;
6298 int regno = -1;
6299 int valueno;
6300 int goal_mem = 0;
6301 int goal_const = 0;
6302 int goal_mem_addr_varies = 0;
6303 int need_stable_sp = 0;
6304 int nregs;
6305 int valuenregs;
6307 if (goal == 0)
6308 regno = goalreg;
6309 else if (GET_CODE (goal) == REG)
6310 regno = REGNO (goal);
6311 else if (GET_CODE (goal) == MEM)
6313 enum rtx_code code = GET_CODE (XEXP (goal, 0));
6314 if (MEM_VOLATILE_P (goal))
6315 return 0;
6316 if (flag_float_store && GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT)
6317 return 0;
6318 /* An address with side effects must be reexecuted. */
6319 switch (code)
6321 case POST_INC:
6322 case PRE_INC:
6323 case POST_DEC:
6324 case PRE_DEC:
6325 case POST_MODIFY:
6326 case PRE_MODIFY:
6327 return 0;
6328 default:
6329 break;
6331 goal_mem = 1;
6333 else if (CONSTANT_P (goal))
6334 goal_const = 1;
6335 else if (GET_CODE (goal) == PLUS
6336 && XEXP (goal, 0) == stack_pointer_rtx
6337 && CONSTANT_P (XEXP (goal, 1)))
6338 goal_const = need_stable_sp = 1;
6339 else if (GET_CODE (goal) == PLUS
6340 && XEXP (goal, 0) == frame_pointer_rtx
6341 && CONSTANT_P (XEXP (goal, 1)))
6342 goal_const = 1;
6343 else
6344 return 0;
6346 /* Scan insns back from INSN, looking for one that copies
6347 a value into or out of GOAL.
6348 Stop and give up if we reach a label. */
6350 while (1)
6352 p = PREV_INSN (p);
6353 if (p == 0 || GET_CODE (p) == CODE_LABEL)
6354 return 0;
6356 if (GET_CODE (p) == INSN
6357 /* If we don't want spill regs ... */
6358 && (! (reload_reg_p != 0
6359 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6360 /* ... then ignore insns introduced by reload; they aren't
6361 useful and can cause results in reload_as_needed to be
6362 different from what they were when calculating the need for
6363 spills. If we notice an input-reload insn here, we will
6364 reject it below, but it might hide a usable equivalent.
6365 That makes bad code. It may even abort: perhaps no reg was
6366 spilled for this insn because it was assumed we would find
6367 that equivalent. */
6368 || INSN_UID (p) < reload_first_uid))
6370 rtx tem;
6371 pat = single_set (p);
6373 /* First check for something that sets some reg equal to GOAL. */
6374 if (pat != 0
6375 && ((regno >= 0
6376 && true_regnum (SET_SRC (pat)) == regno
6377 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6379 (regno >= 0
6380 && true_regnum (SET_DEST (pat)) == regno
6381 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
6383 (goal_const && rtx_equal_p (SET_SRC (pat), goal)
6384 /* When looking for stack pointer + const,
6385 make sure we don't use a stack adjust. */
6386 && !reg_overlap_mentioned_for_reload_p (SET_DEST (pat), goal)
6387 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6388 || (goal_mem
6389 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
6390 && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
6391 || (goal_mem
6392 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
6393 && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
6394 /* If we are looking for a constant,
6395 and something equivalent to that constant was copied
6396 into a reg, we can use that reg. */
6397 || (goal_const && REG_NOTES (p) != 0
6398 && (tem = find_reg_note (p, REG_EQUIV, NULL_RTX))
6399 && ((rtx_equal_p (XEXP (tem, 0), goal)
6400 && (valueno
6401 = true_regnum (valtry = SET_DEST (pat))) >= 0)
6402 || (GET_CODE (SET_DEST (pat)) == REG
6403 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6404 && (GET_MODE_CLASS (GET_MODE (XEXP (tem, 0)))
6405 == MODE_FLOAT)
6406 && GET_CODE (goal) == CONST_INT
6407 && 0 != (goaltry
6408 = operand_subword (XEXP (tem, 0), 0, 0,
6409 VOIDmode))
6410 && rtx_equal_p (goal, goaltry)
6411 && (valtry
6412 = operand_subword (SET_DEST (pat), 0, 0,
6413 VOIDmode))
6414 && (valueno = true_regnum (valtry)) >= 0)))
6415 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
6416 NULL_RTX))
6417 && GET_CODE (SET_DEST (pat)) == REG
6418 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6419 && (GET_MODE_CLASS (GET_MODE (XEXP (tem, 0)))
6420 == MODE_FLOAT)
6421 && GET_CODE (goal) == CONST_INT
6422 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0,
6423 VOIDmode))
6424 && rtx_equal_p (goal, goaltry)
6425 && (valtry
6426 = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
6427 && (valueno = true_regnum (valtry)) >= 0)))
6429 if (other >= 0)
6431 if (valueno != other)
6432 continue;
6434 else if ((unsigned) valueno >= FIRST_PSEUDO_REGISTER)
6435 continue;
6436 else
6438 int i;
6440 for (i = HARD_REGNO_NREGS (valueno, mode) - 1; i >= 0; i--)
6441 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
6442 valueno + i))
6443 break;
6444 if (i >= 0)
6445 continue;
6447 value = valtry;
6448 where = p;
6449 break;
6454 /* We found a previous insn copying GOAL into a suitable other reg VALUE
6455 (or copying VALUE into GOAL, if GOAL is also a register).
6456 Now verify that VALUE is really valid. */
6458 /* VALUENO is the register number of VALUE; a hard register. */
6460 /* Don't try to re-use something that is killed in this insn. We want
6461 to be able to trust REG_UNUSED notes. */
6462 if (REG_NOTES (where) != 0 && find_reg_note (where, REG_UNUSED, value))
6463 return 0;
6465 /* If we propose to get the value from the stack pointer or if GOAL is
6466 a MEM based on the stack pointer, we need a stable SP. */
6467 if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM
6468 || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
6469 goal)))
6470 need_stable_sp = 1;
6472 /* Reject VALUE if the copy-insn moved the wrong sort of datum. */
6473 if (GET_MODE (value) != mode)
6474 return 0;
6476 /* Reject VALUE if it was loaded from GOAL
6477 and is also a register that appears in the address of GOAL. */
6479 if (goal_mem && value == SET_DEST (single_set (where))
6480 && refers_to_regno_for_reload_p (valueno,
6481 (valueno
6482 + HARD_REGNO_NREGS (valueno, mode)),
6483 goal, (rtx*) 0))
6484 return 0;
6486 /* Reject registers that overlap GOAL. */
6488 if (!goal_mem && !goal_const
6489 && regno + (int) HARD_REGNO_NREGS (regno, mode) > valueno
6490 && regno < valueno + (int) HARD_REGNO_NREGS (valueno, mode))
6491 return 0;
6493 nregs = HARD_REGNO_NREGS (regno, mode);
6494 valuenregs = HARD_REGNO_NREGS (valueno, mode);
6496 /* Reject VALUE if it is one of the regs reserved for reloads.
6497 Reload1 knows how to reuse them anyway, and it would get
6498 confused if we allocated one without its knowledge.
6499 (Now that insns introduced by reload are ignored above,
6500 this case shouldn't happen, but I'm not positive.) */
6502 if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6504 int i;
6505 for (i = 0; i < valuenregs; ++i)
6506 if (reload_reg_p[valueno + i] >= 0)
6507 return 0;
6510 /* Reject VALUE if it is a register being used for an input reload
6511 even if it is not one of those reserved. */
6513 if (reload_reg_p != 0)
6515 int i;
6516 for (i = 0; i < n_reloads; i++)
6517 if (rld[i].reg_rtx != 0 && rld[i].in)
6519 int regno1 = REGNO (rld[i].reg_rtx);
6520 int nregs1 = HARD_REGNO_NREGS (regno1,
6521 GET_MODE (rld[i].reg_rtx));
6522 if (regno1 < valueno + valuenregs
6523 && regno1 + nregs1 > valueno)
6524 return 0;
6528 if (goal_mem)
6529 /* We must treat frame pointer as varying here,
6530 since it can vary--in a nonlocal goto as generated by expand_goto. */
6531 goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0));
6533 /* Now verify that the values of GOAL and VALUE remain unaltered
6534 until INSN is reached. */
6536 p = insn;
6537 while (1)
6539 p = PREV_INSN (p);
6540 if (p == where)
6541 return value;
6543 /* Don't trust the conversion past a function call
6544 if either of the two is in a call-clobbered register, or memory. */
6545 if (GET_CODE (p) == CALL_INSN)
6547 int i;
6549 if (goal_mem || need_stable_sp)
6550 return 0;
6552 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
6553 for (i = 0; i < nregs; ++i)
6554 if (call_used_regs[regno + i])
6555 return 0;
6557 if (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER)
6558 for (i = 0; i < valuenregs; ++i)
6559 if (call_used_regs[valueno + i])
6560 return 0;
6561 #ifdef NON_SAVING_SETJMP
6562 if (NON_SAVING_SETJMP && find_reg_note (p, REG_SETJMP, NULL))
6563 return 0;
6564 #endif
6567 if (INSN_P (p))
6569 pat = PATTERN (p);
6571 /* Watch out for unspec_volatile, and volatile asms. */
6572 if (volatile_insn_p (pat))
6573 return 0;
6575 /* If this insn P stores in either GOAL or VALUE, return 0.
6576 If GOAL is a memory ref and this insn writes memory, return 0.
6577 If GOAL is a memory ref and its address is not constant,
6578 and this insn P changes a register used in GOAL, return 0. */
6580 if (GET_CODE (pat) == COND_EXEC)
6581 pat = COND_EXEC_CODE (pat);
6582 if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
6584 rtx dest = SET_DEST (pat);
6585 while (GET_CODE (dest) == SUBREG
6586 || GET_CODE (dest) == ZERO_EXTRACT
6587 || GET_CODE (dest) == SIGN_EXTRACT
6588 || GET_CODE (dest) == STRICT_LOW_PART)
6589 dest = XEXP (dest, 0);
6590 if (GET_CODE (dest) == REG)
6592 int xregno = REGNO (dest);
6593 int xnregs;
6594 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6595 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
6596 else
6597 xnregs = 1;
6598 if (xregno < regno + nregs && xregno + xnregs > regno)
6599 return 0;
6600 if (xregno < valueno + valuenregs
6601 && xregno + xnregs > valueno)
6602 return 0;
6603 if (goal_mem_addr_varies
6604 && reg_overlap_mentioned_for_reload_p (dest, goal))
6605 return 0;
6606 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6607 return 0;
6609 else if (goal_mem && GET_CODE (dest) == MEM
6610 && ! push_operand (dest, GET_MODE (dest)))
6611 return 0;
6612 else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER
6613 && reg_equiv_memory_loc[regno] != 0)
6614 return 0;
6615 else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
6616 return 0;
6618 else if (GET_CODE (pat) == PARALLEL)
6620 int i;
6621 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
6623 rtx v1 = XVECEXP (pat, 0, i);
6624 if (GET_CODE (v1) == COND_EXEC)
6625 v1 = COND_EXEC_CODE (v1);
6626 if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
6628 rtx dest = SET_DEST (v1);
6629 while (GET_CODE (dest) == SUBREG
6630 || GET_CODE (dest) == ZERO_EXTRACT
6631 || GET_CODE (dest) == SIGN_EXTRACT
6632 || GET_CODE (dest) == STRICT_LOW_PART)
6633 dest = XEXP (dest, 0);
6634 if (GET_CODE (dest) == REG)
6636 int xregno = REGNO (dest);
6637 int xnregs;
6638 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6639 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
6640 else
6641 xnregs = 1;
6642 if (xregno < regno + nregs
6643 && xregno + xnregs > regno)
6644 return 0;
6645 if (xregno < valueno + valuenregs
6646 && xregno + xnregs > valueno)
6647 return 0;
6648 if (goal_mem_addr_varies
6649 && reg_overlap_mentioned_for_reload_p (dest,
6650 goal))
6651 return 0;
6652 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6653 return 0;
6655 else if (goal_mem && GET_CODE (dest) == MEM
6656 && ! push_operand (dest, GET_MODE (dest)))
6657 return 0;
6658 else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER
6659 && reg_equiv_memory_loc[regno] != 0)
6660 return 0;
6661 else if (need_stable_sp
6662 && push_operand (dest, GET_MODE (dest)))
6663 return 0;
6668 if (GET_CODE (p) == CALL_INSN && CALL_INSN_FUNCTION_USAGE (p))
6670 rtx link;
6672 for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0;
6673 link = XEXP (link, 1))
6675 pat = XEXP (link, 0);
6676 if (GET_CODE (pat) == CLOBBER)
6678 rtx dest = SET_DEST (pat);
6680 if (GET_CODE (dest) == REG)
6682 int xregno = REGNO (dest);
6683 int xnregs
6684 = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
6686 if (xregno < regno + nregs
6687 && xregno + xnregs > regno)
6688 return 0;
6689 else if (xregno < valueno + valuenregs
6690 && xregno + xnregs > valueno)
6691 return 0;
6692 else if (goal_mem_addr_varies
6693 && reg_overlap_mentioned_for_reload_p (dest,
6694 goal))
6695 return 0;
6698 else if (goal_mem && GET_CODE (dest) == MEM
6699 && ! push_operand (dest, GET_MODE (dest)))
6700 return 0;
6701 else if (need_stable_sp
6702 && push_operand (dest, GET_MODE (dest)))
6703 return 0;
6708 #ifdef AUTO_INC_DEC
6709 /* If this insn auto-increments or auto-decrements
6710 either regno or valueno, return 0 now.
6711 If GOAL is a memory ref and its address is not constant,
6712 and this insn P increments a register used in GOAL, return 0. */
6714 rtx link;
6716 for (link = REG_NOTES (p); link; link = XEXP (link, 1))
6717 if (REG_NOTE_KIND (link) == REG_INC
6718 && GET_CODE (XEXP (link, 0)) == REG)
6720 int incno = REGNO (XEXP (link, 0));
6721 if (incno < regno + nregs && incno >= regno)
6722 return 0;
6723 if (incno < valueno + valuenregs && incno >= valueno)
6724 return 0;
6725 if (goal_mem_addr_varies
6726 && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
6727 goal))
6728 return 0;
6731 #endif
6736 /* Find a place where INCED appears in an increment or decrement operator
6737 within X, and return the amount INCED is incremented or decremented by.
6738 The value is always positive. */
6740 static int
6741 find_inc_amount (x, inced)
6742 rtx x, inced;
6744 enum rtx_code code = GET_CODE (x);
6745 const char *fmt;
6746 int i;
6748 if (code == MEM)
6750 rtx addr = XEXP (x, 0);
6751 if ((GET_CODE (addr) == PRE_DEC
6752 || GET_CODE (addr) == POST_DEC
6753 || GET_CODE (addr) == PRE_INC
6754 || GET_CODE (addr) == POST_INC)
6755 && XEXP (addr, 0) == inced)
6756 return GET_MODE_SIZE (GET_MODE (x));
6757 else if ((GET_CODE (addr) == PRE_MODIFY
6758 || GET_CODE (addr) == POST_MODIFY)
6759 && GET_CODE (XEXP (addr, 1)) == PLUS
6760 && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
6761 && XEXP (addr, 0) == inced
6762 && GET_CODE (XEXP (XEXP (addr, 1), 1)) == CONST_INT)
6764 i = INTVAL (XEXP (XEXP (addr, 1), 1));
6765 return i < 0 ? -i : i;
6769 fmt = GET_RTX_FORMAT (code);
6770 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6772 if (fmt[i] == 'e')
6774 int tem = find_inc_amount (XEXP (x, i), inced);
6775 if (tem != 0)
6776 return tem;
6778 if (fmt[i] == 'E')
6780 int j;
6781 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6783 int tem = find_inc_amount (XVECEXP (x, i, j), inced);
6784 if (tem != 0)
6785 return tem;
6790 return 0;
6793 /* Return 1 if register REGNO is the subject of a clobber in insn INSN.
6794 If SETS is nonzero, also consider SETs. */
6797 regno_clobbered_p (regno, insn, mode, sets)
6798 unsigned int regno;
6799 rtx insn;
6800 enum machine_mode mode;
6801 int sets;
6803 unsigned int nregs = HARD_REGNO_NREGS (regno, mode);
6804 unsigned int endregno = regno + nregs;
6806 if ((GET_CODE (PATTERN (insn)) == CLOBBER
6807 || (sets && GET_CODE (PATTERN (insn)) == SET))
6808 && GET_CODE (XEXP (PATTERN (insn), 0)) == REG)
6810 unsigned int test = REGNO (XEXP (PATTERN (insn), 0));
6812 return test >= regno && test < endregno;
6815 if (GET_CODE (PATTERN (insn)) == PARALLEL)
6817 int i = XVECLEN (PATTERN (insn), 0) - 1;
6819 for (; i >= 0; i--)
6821 rtx elt = XVECEXP (PATTERN (insn), 0, i);
6822 if ((GET_CODE (elt) == CLOBBER
6823 || (sets && GET_CODE (PATTERN (insn)) == SET))
6824 && GET_CODE (XEXP (elt, 0)) == REG)
6826 unsigned int test = REGNO (XEXP (elt, 0));
6828 if (test >= regno && test < endregno)
6829 return 1;
6834 return 0;
6837 static const char *const reload_when_needed_name[] =
6839 "RELOAD_FOR_INPUT",
6840 "RELOAD_FOR_OUTPUT",
6841 "RELOAD_FOR_INSN",
6842 "RELOAD_FOR_INPUT_ADDRESS",
6843 "RELOAD_FOR_INPADDR_ADDRESS",
6844 "RELOAD_FOR_OUTPUT_ADDRESS",
6845 "RELOAD_FOR_OUTADDR_ADDRESS",
6846 "RELOAD_FOR_OPERAND_ADDRESS",
6847 "RELOAD_FOR_OPADDR_ADDR",
6848 "RELOAD_OTHER",
6849 "RELOAD_FOR_OTHER_ADDRESS"
6852 static const char * const reg_class_names[] = REG_CLASS_NAMES;
6854 /* These functions are used to print the variables set by 'find_reloads' */
6856 void
6857 debug_reload_to_stream (f)
6858 FILE *f;
6860 int r;
6861 const char *prefix;
6863 if (! f)
6864 f = stderr;
6865 for (r = 0; r < n_reloads; r++)
6867 fprintf (f, "Reload %d: ", r);
6869 if (rld[r].in != 0)
6871 fprintf (f, "reload_in (%s) = ",
6872 GET_MODE_NAME (rld[r].inmode));
6873 print_inline_rtx (f, rld[r].in, 24);
6874 fprintf (f, "\n\t");
6877 if (rld[r].out != 0)
6879 fprintf (f, "reload_out (%s) = ",
6880 GET_MODE_NAME (rld[r].outmode));
6881 print_inline_rtx (f, rld[r].out, 24);
6882 fprintf (f, "\n\t");
6885 fprintf (f, "%s, ", reg_class_names[(int) rld[r].class]);
6887 fprintf (f, "%s (opnum = %d)",
6888 reload_when_needed_name[(int) rld[r].when_needed],
6889 rld[r].opnum);
6891 if (rld[r].optional)
6892 fprintf (f, ", optional");
6894 if (rld[r].nongroup)
6895 fprintf (f, ", nongroup");
6897 if (rld[r].inc != 0)
6898 fprintf (f, ", inc by %d", rld[r].inc);
6900 if (rld[r].nocombine)
6901 fprintf (f, ", can't combine");
6903 if (rld[r].secondary_p)
6904 fprintf (f, ", secondary_reload_p");
6906 if (rld[r].in_reg != 0)
6908 fprintf (f, "\n\treload_in_reg: ");
6909 print_inline_rtx (f, rld[r].in_reg, 24);
6912 if (rld[r].out_reg != 0)
6914 fprintf (f, "\n\treload_out_reg: ");
6915 print_inline_rtx (f, rld[r].out_reg, 24);
6918 if (rld[r].reg_rtx != 0)
6920 fprintf (f, "\n\treload_reg_rtx: ");
6921 print_inline_rtx (f, rld[r].reg_rtx, 24);
6924 prefix = "\n\t";
6925 if (rld[r].secondary_in_reload != -1)
6927 fprintf (f, "%ssecondary_in_reload = %d",
6928 prefix, rld[r].secondary_in_reload);
6929 prefix = ", ";
6932 if (rld[r].secondary_out_reload != -1)
6933 fprintf (f, "%ssecondary_out_reload = %d\n",
6934 prefix, rld[r].secondary_out_reload);
6936 prefix = "\n\t";
6937 if (rld[r].secondary_in_icode != CODE_FOR_nothing)
6939 fprintf (f, "%ssecondary_in_icode = %s", prefix,
6940 insn_data[rld[r].secondary_in_icode].name);
6941 prefix = ", ";
6944 if (rld[r].secondary_out_icode != CODE_FOR_nothing)
6945 fprintf (f, "%ssecondary_out_icode = %s", prefix,
6946 insn_data[rld[r].secondary_out_icode].name);
6948 fprintf (f, "\n");
6952 void
6953 debug_reload ()
6955 debug_reload_to_stream (stderr);