* tree.c (save_expr): Allow either side of a dyadic operand to be
[official-gcc.git] / gcc / reload.c
blobad3f375a2ecb8b2b0dcb5ab282e3b769d4020fea
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 "coretypes.h"
92 #include "tm.h"
93 #include "rtl.h"
94 #include "tm_p.h"
95 #include "insn-config.h"
96 #include "expr.h"
97 #include "optabs.h"
98 #include "recog.h"
99 #include "reload.h"
100 #include "regs.h"
101 #include "hard-reg-set.h"
102 #include "flags.h"
103 #include "real.h"
104 #include "output.h"
105 #include "function.h"
106 #include "toplev.h"
108 #ifndef REGISTER_MOVE_COST
109 #define REGISTER_MOVE_COST(m, x, y) 2
110 #endif
112 #ifndef REGNO_MODE_OK_FOR_BASE_P
113 #define REGNO_MODE_OK_FOR_BASE_P(REGNO, MODE) REGNO_OK_FOR_BASE_P (REGNO)
114 #endif
116 #ifndef REG_MODE_OK_FOR_BASE_P
117 #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
118 #endif
120 /* All reloads of the current insn are recorded here. See reload.h for
121 comments. */
122 int n_reloads;
123 struct reload rld[MAX_RELOADS];
125 /* All the "earlyclobber" operands of the current insn
126 are recorded here. */
127 int n_earlyclobbers;
128 rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
130 int reload_n_operands;
132 /* Replacing reloads.
134 If `replace_reloads' is nonzero, then as each reload is recorded
135 an entry is made for it in the table `replacements'.
136 Then later `subst_reloads' can look through that table and
137 perform all the replacements needed. */
139 /* Nonzero means record the places to replace. */
140 static int replace_reloads;
142 /* Each replacement is recorded with a structure like this. */
143 struct replacement
145 rtx *where; /* Location to store in */
146 rtx *subreg_loc; /* Location of SUBREG if WHERE is inside
147 a SUBREG; 0 otherwise. */
148 int what; /* which reload this is for */
149 enum machine_mode mode; /* mode it must have */
152 static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
154 /* Number of replacements currently recorded. */
155 static int n_replacements;
157 /* Used to track what is modified by an operand. */
158 struct decomposition
160 int reg_flag; /* Nonzero if referencing a register. */
161 int safe; /* Nonzero if this can't conflict with anything. */
162 rtx base; /* Base address for MEM. */
163 HOST_WIDE_INT start; /* Starting offset or register number. */
164 HOST_WIDE_INT end; /* Ending offset or register number. */
167 #ifdef SECONDARY_MEMORY_NEEDED
169 /* Save MEMs needed to copy from one class of registers to another. One MEM
170 is used per mode, but normally only one or two modes are ever used.
172 We keep two versions, before and after register elimination. The one
173 after register elimination is record separately for each operand. This
174 is done in case the address is not valid to be sure that we separately
175 reload each. */
177 static rtx secondary_memlocs[NUM_MACHINE_MODES];
178 static rtx secondary_memlocs_elim[NUM_MACHINE_MODES][MAX_RECOG_OPERANDS];
179 #endif
181 /* The instruction we are doing reloads for;
182 so we can test whether a register dies in it. */
183 static rtx this_insn;
185 /* Nonzero if this instruction is a user-specified asm with operands. */
186 static int this_insn_is_asm;
188 /* If hard_regs_live_known is nonzero,
189 we can tell which hard regs are currently live,
190 at least enough to succeed in choosing dummy reloads. */
191 static int hard_regs_live_known;
193 /* Indexed by hard reg number,
194 element is nonnegative if hard reg has been spilled.
195 This vector is passed to `find_reloads' as an argument
196 and is not changed here. */
197 static short *static_reload_reg_p;
199 /* Set to 1 in subst_reg_equivs if it changes anything. */
200 static int subst_reg_equivs_changed;
202 /* On return from push_reload, holds the reload-number for the OUT
203 operand, which can be different for that from the input operand. */
204 static int output_reloadnum;
206 /* Compare two RTX's. */
207 #define MATCHES(x, y) \
208 (x == y || (x != 0 && (GET_CODE (x) == REG \
209 ? GET_CODE (y) == REG && REGNO (x) == REGNO (y) \
210 : rtx_equal_p (x, y) && ! side_effects_p (x))))
212 /* Indicates if two reloads purposes are for similar enough things that we
213 can merge their reloads. */
214 #define MERGABLE_RELOADS(when1, when2, op1, op2) \
215 ((when1) == RELOAD_OTHER || (when2) == RELOAD_OTHER \
216 || ((when1) == (when2) && (op1) == (op2)) \
217 || ((when1) == RELOAD_FOR_INPUT && (when2) == RELOAD_FOR_INPUT) \
218 || ((when1) == RELOAD_FOR_OPERAND_ADDRESS \
219 && (when2) == RELOAD_FOR_OPERAND_ADDRESS) \
220 || ((when1) == RELOAD_FOR_OTHER_ADDRESS \
221 && (when2) == RELOAD_FOR_OTHER_ADDRESS))
223 /* Nonzero if these two reload purposes produce RELOAD_OTHER when merged. */
224 #define MERGE_TO_OTHER(when1, when2, op1, op2) \
225 ((when1) != (when2) \
226 || ! ((op1) == (op2) \
227 || (when1) == RELOAD_FOR_INPUT \
228 || (when1) == RELOAD_FOR_OPERAND_ADDRESS \
229 || (when1) == RELOAD_FOR_OTHER_ADDRESS))
231 /* If we are going to reload an address, compute the reload type to
232 use. */
233 #define ADDR_TYPE(type) \
234 ((type) == RELOAD_FOR_INPUT_ADDRESS \
235 ? RELOAD_FOR_INPADDR_ADDRESS \
236 : ((type) == RELOAD_FOR_OUTPUT_ADDRESS \
237 ? RELOAD_FOR_OUTADDR_ADDRESS \
238 : (type)))
240 #ifdef HAVE_SECONDARY_RELOADS
241 static int push_secondary_reload PARAMS ((int, rtx, int, int, enum reg_class,
242 enum machine_mode, enum reload_type,
243 enum insn_code *));
244 #endif
245 static enum reg_class find_valid_class PARAMS ((enum machine_mode, int,
246 unsigned int));
247 static int reload_inner_reg_of_subreg PARAMS ((rtx, enum machine_mode, int));
248 static void push_replacement PARAMS ((rtx *, int, enum machine_mode));
249 static void dup_replacements PARAMS ((rtx *, rtx *));
250 static void combine_reloads PARAMS ((void));
251 static int find_reusable_reload PARAMS ((rtx *, rtx, enum reg_class,
252 enum reload_type, int, int));
253 static rtx find_dummy_reload PARAMS ((rtx, rtx, rtx *, rtx *,
254 enum machine_mode, enum machine_mode,
255 enum reg_class, int, int));
256 static int hard_reg_set_here_p PARAMS ((unsigned int, unsigned int, rtx));
257 static struct decomposition decompose PARAMS ((rtx));
258 static int immune_p PARAMS ((rtx, rtx, struct decomposition));
259 static int alternative_allows_memconst PARAMS ((const char *, int));
260 static rtx find_reloads_toplev PARAMS ((rtx, int, enum reload_type, int,
261 int, rtx, int *));
262 static rtx make_memloc PARAMS ((rtx, int));
263 static int find_reloads_address PARAMS ((enum machine_mode, rtx *, rtx, rtx *,
264 int, enum reload_type, int, rtx));
265 static rtx subst_reg_equivs PARAMS ((rtx, rtx));
266 static rtx subst_indexed_address PARAMS ((rtx));
267 static void update_auto_inc_notes PARAMS ((rtx, int, int));
268 static int find_reloads_address_1 PARAMS ((enum machine_mode, rtx, int, rtx *,
269 int, enum reload_type,int, rtx));
270 static void find_reloads_address_part PARAMS ((rtx, rtx *, enum reg_class,
271 enum machine_mode, int,
272 enum reload_type, int));
273 static rtx find_reloads_subreg_address PARAMS ((rtx, int, int,
274 enum reload_type, int, rtx));
275 static void copy_replacements_1 PARAMS ((rtx *, rtx *, int));
276 static int find_inc_amount PARAMS ((rtx, rtx));
278 #ifdef HAVE_SECONDARY_RELOADS
280 /* Determine if any secondary reloads are needed for loading (if IN_P is
281 nonzero) or storing (if IN_P is zero) X to or from a reload register of
282 register class RELOAD_CLASS in mode RELOAD_MODE. If secondary reloads
283 are needed, push them.
285 Return the reload number of the secondary reload we made, or -1 if
286 we didn't need one. *PICODE is set to the insn_code to use if we do
287 need a secondary reload. */
289 static int
290 push_secondary_reload (in_p, x, opnum, optional, reload_class, reload_mode,
291 type, picode)
292 int in_p;
293 rtx x;
294 int opnum;
295 int optional;
296 enum reg_class reload_class;
297 enum machine_mode reload_mode;
298 enum reload_type type;
299 enum insn_code *picode;
301 enum reg_class class = NO_REGS;
302 enum machine_mode mode = reload_mode;
303 enum insn_code icode = CODE_FOR_nothing;
304 enum reg_class t_class = NO_REGS;
305 enum machine_mode t_mode = VOIDmode;
306 enum insn_code t_icode = CODE_FOR_nothing;
307 enum reload_type secondary_type;
308 int s_reload, t_reload = -1;
310 if (type == RELOAD_FOR_INPUT_ADDRESS
311 || type == RELOAD_FOR_OUTPUT_ADDRESS
312 || type == RELOAD_FOR_INPADDR_ADDRESS
313 || type == RELOAD_FOR_OUTADDR_ADDRESS)
314 secondary_type = type;
315 else
316 secondary_type = in_p ? RELOAD_FOR_INPUT_ADDRESS : RELOAD_FOR_OUTPUT_ADDRESS;
318 *picode = CODE_FOR_nothing;
320 /* If X is a paradoxical SUBREG, use the inner value to determine both the
321 mode and object being reloaded. */
322 if (GET_CODE (x) == SUBREG
323 && (GET_MODE_SIZE (GET_MODE (x))
324 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
326 x = SUBREG_REG (x);
327 reload_mode = GET_MODE (x);
330 /* If X is a pseudo-register that has an equivalent MEM (actually, if it
331 is still a pseudo-register by now, it *must* have an equivalent MEM
332 but we don't want to assume that), use that equivalent when seeing if
333 a secondary reload is needed since whether or not a reload is needed
334 might be sensitive to the form of the MEM. */
336 if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER
337 && reg_equiv_mem[REGNO (x)] != 0)
338 x = reg_equiv_mem[REGNO (x)];
340 #ifdef SECONDARY_INPUT_RELOAD_CLASS
341 if (in_p)
342 class = SECONDARY_INPUT_RELOAD_CLASS (reload_class, reload_mode, x);
343 #endif
345 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
346 if (! in_p)
347 class = SECONDARY_OUTPUT_RELOAD_CLASS (reload_class, reload_mode, x);
348 #endif
350 /* If we don't need any secondary registers, done. */
351 if (class == NO_REGS)
352 return -1;
354 /* Get a possible insn to use. If the predicate doesn't accept X, don't
355 use the insn. */
357 icode = (in_p ? reload_in_optab[(int) reload_mode]
358 : reload_out_optab[(int) reload_mode]);
360 if (icode != CODE_FOR_nothing
361 && insn_data[(int) icode].operand[in_p].predicate
362 && (! (insn_data[(int) icode].operand[in_p].predicate) (x, reload_mode)))
363 icode = CODE_FOR_nothing;
365 /* If we will be using an insn, see if it can directly handle the reload
366 register we will be using. If it can, the secondary reload is for a
367 scratch register. If it can't, we will use the secondary reload for
368 an intermediate register and require a tertiary reload for the scratch
369 register. */
371 if (icode != CODE_FOR_nothing)
373 /* If IN_P is nonzero, the reload register will be the output in
374 operand 0. If IN_P is zero, the reload register will be the input
375 in operand 1. Outputs should have an initial "=", which we must
376 skip. */
378 enum reg_class insn_class;
380 if (insn_data[(int) icode].operand[!in_p].constraint[0] == 0)
381 insn_class = ALL_REGS;
382 else
384 char insn_letter
385 = insn_data[(int) icode].operand[!in_p].constraint[in_p];
386 insn_class
387 = (insn_letter == 'r' ? GENERAL_REGS
388 : REG_CLASS_FROM_LETTER ((unsigned char) insn_letter));
390 if (insn_class == NO_REGS)
391 abort ();
392 if (in_p
393 && insn_data[(int) icode].operand[!in_p].constraint[0] != '=')
394 abort ();
397 /* The scratch register's constraint must start with "=&". */
398 if (insn_data[(int) icode].operand[2].constraint[0] != '='
399 || insn_data[(int) icode].operand[2].constraint[1] != '&')
400 abort ();
402 if (reg_class_subset_p (reload_class, insn_class))
403 mode = insn_data[(int) icode].operand[2].mode;
404 else
406 char t_letter = insn_data[(int) icode].operand[2].constraint[2];
407 class = insn_class;
408 t_mode = insn_data[(int) icode].operand[2].mode;
409 t_class = (t_letter == 'r' ? GENERAL_REGS
410 : REG_CLASS_FROM_LETTER ((unsigned char) t_letter));
411 t_icode = icode;
412 icode = CODE_FOR_nothing;
416 /* This case isn't valid, so fail. Reload is allowed to use the same
417 register for RELOAD_FOR_INPUT_ADDRESS and RELOAD_FOR_INPUT reloads, but
418 in the case of a secondary register, we actually need two different
419 registers for correct code. We fail here to prevent the possibility of
420 silently generating incorrect code later.
422 The convention is that secondary input reloads are valid only if the
423 secondary_class is different from class. If you have such a case, you
424 can not use secondary reloads, you must work around the problem some
425 other way.
427 Allow this when a reload_in/out pattern is being used. I.e. assume
428 that the generated code handles this case. */
430 if (in_p && class == reload_class && icode == CODE_FOR_nothing
431 && t_icode == CODE_FOR_nothing)
432 abort ();
434 /* If we need a tertiary reload, see if we have one we can reuse or else
435 make a new one. */
437 if (t_class != NO_REGS)
439 for (t_reload = 0; t_reload < n_reloads; t_reload++)
440 if (rld[t_reload].secondary_p
441 && (reg_class_subset_p (t_class, rld[t_reload].class)
442 || reg_class_subset_p (rld[t_reload].class, t_class))
443 && ((in_p && rld[t_reload].inmode == t_mode)
444 || (! in_p && rld[t_reload].outmode == t_mode))
445 && ((in_p && (rld[t_reload].secondary_in_icode
446 == CODE_FOR_nothing))
447 || (! in_p &&(rld[t_reload].secondary_out_icode
448 == CODE_FOR_nothing)))
449 && (reg_class_size[(int) t_class] == 1 || SMALL_REGISTER_CLASSES)
450 && MERGABLE_RELOADS (secondary_type,
451 rld[t_reload].when_needed,
452 opnum, rld[t_reload].opnum))
454 if (in_p)
455 rld[t_reload].inmode = t_mode;
456 if (! in_p)
457 rld[t_reload].outmode = t_mode;
459 if (reg_class_subset_p (t_class, rld[t_reload].class))
460 rld[t_reload].class = t_class;
462 rld[t_reload].opnum = MIN (rld[t_reload].opnum, opnum);
463 rld[t_reload].optional &= optional;
464 rld[t_reload].secondary_p = 1;
465 if (MERGE_TO_OTHER (secondary_type, rld[t_reload].when_needed,
466 opnum, rld[t_reload].opnum))
467 rld[t_reload].when_needed = RELOAD_OTHER;
470 if (t_reload == n_reloads)
472 /* We need to make a new tertiary reload for this register class. */
473 rld[t_reload].in = rld[t_reload].out = 0;
474 rld[t_reload].class = t_class;
475 rld[t_reload].inmode = in_p ? t_mode : VOIDmode;
476 rld[t_reload].outmode = ! in_p ? t_mode : VOIDmode;
477 rld[t_reload].reg_rtx = 0;
478 rld[t_reload].optional = optional;
479 rld[t_reload].inc = 0;
480 /* Maybe we could combine these, but it seems too tricky. */
481 rld[t_reload].nocombine = 1;
482 rld[t_reload].in_reg = 0;
483 rld[t_reload].out_reg = 0;
484 rld[t_reload].opnum = opnum;
485 rld[t_reload].when_needed = secondary_type;
486 rld[t_reload].secondary_in_reload = -1;
487 rld[t_reload].secondary_out_reload = -1;
488 rld[t_reload].secondary_in_icode = CODE_FOR_nothing;
489 rld[t_reload].secondary_out_icode = CODE_FOR_nothing;
490 rld[t_reload].secondary_p = 1;
492 n_reloads++;
496 /* See if we can reuse an existing secondary reload. */
497 for (s_reload = 0; s_reload < n_reloads; s_reload++)
498 if (rld[s_reload].secondary_p
499 && (reg_class_subset_p (class, rld[s_reload].class)
500 || reg_class_subset_p (rld[s_reload].class, class))
501 && ((in_p && rld[s_reload].inmode == mode)
502 || (! in_p && rld[s_reload].outmode == mode))
503 && ((in_p && rld[s_reload].secondary_in_reload == t_reload)
504 || (! in_p && rld[s_reload].secondary_out_reload == t_reload))
505 && ((in_p && rld[s_reload].secondary_in_icode == t_icode)
506 || (! in_p && rld[s_reload].secondary_out_icode == t_icode))
507 && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES)
508 && MERGABLE_RELOADS (secondary_type, rld[s_reload].when_needed,
509 opnum, rld[s_reload].opnum))
511 if (in_p)
512 rld[s_reload].inmode = mode;
513 if (! in_p)
514 rld[s_reload].outmode = mode;
516 if (reg_class_subset_p (class, rld[s_reload].class))
517 rld[s_reload].class = class;
519 rld[s_reload].opnum = MIN (rld[s_reload].opnum, opnum);
520 rld[s_reload].optional &= optional;
521 rld[s_reload].secondary_p = 1;
522 if (MERGE_TO_OTHER (secondary_type, rld[s_reload].when_needed,
523 opnum, rld[s_reload].opnum))
524 rld[s_reload].when_needed = RELOAD_OTHER;
527 if (s_reload == n_reloads)
529 #ifdef SECONDARY_MEMORY_NEEDED
530 /* If we need a memory location to copy between the two reload regs,
531 set it up now. Note that we do the input case before making
532 the reload and the output case after. This is due to the
533 way reloads are output. */
535 if (in_p && icode == CODE_FOR_nothing
536 && SECONDARY_MEMORY_NEEDED (class, reload_class, mode))
538 get_secondary_mem (x, reload_mode, opnum, type);
540 /* We may have just added new reloads. Make sure we add
541 the new reload at the end. */
542 s_reload = n_reloads;
544 #endif
546 /* We need to make a new secondary reload for this register class. */
547 rld[s_reload].in = rld[s_reload].out = 0;
548 rld[s_reload].class = class;
550 rld[s_reload].inmode = in_p ? mode : VOIDmode;
551 rld[s_reload].outmode = ! in_p ? mode : VOIDmode;
552 rld[s_reload].reg_rtx = 0;
553 rld[s_reload].optional = optional;
554 rld[s_reload].inc = 0;
555 /* Maybe we could combine these, but it seems too tricky. */
556 rld[s_reload].nocombine = 1;
557 rld[s_reload].in_reg = 0;
558 rld[s_reload].out_reg = 0;
559 rld[s_reload].opnum = opnum;
560 rld[s_reload].when_needed = secondary_type;
561 rld[s_reload].secondary_in_reload = in_p ? t_reload : -1;
562 rld[s_reload].secondary_out_reload = ! in_p ? t_reload : -1;
563 rld[s_reload].secondary_in_icode = in_p ? t_icode : CODE_FOR_nothing;
564 rld[s_reload].secondary_out_icode
565 = ! in_p ? t_icode : CODE_FOR_nothing;
566 rld[s_reload].secondary_p = 1;
568 n_reloads++;
570 #ifdef SECONDARY_MEMORY_NEEDED
571 if (! in_p && icode == CODE_FOR_nothing
572 && SECONDARY_MEMORY_NEEDED (reload_class, class, mode))
573 get_secondary_mem (x, mode, opnum, type);
574 #endif
577 *picode = icode;
578 return s_reload;
580 #endif /* HAVE_SECONDARY_RELOADS */
582 #ifdef SECONDARY_MEMORY_NEEDED
584 /* Return a memory location that will be used to copy X in mode MODE.
585 If we haven't already made a location for this mode in this insn,
586 call find_reloads_address on the location being returned. */
589 get_secondary_mem (x, mode, opnum, type)
590 rtx x ATTRIBUTE_UNUSED;
591 enum machine_mode mode;
592 int opnum;
593 enum reload_type type;
595 rtx loc;
596 int mem_valid;
598 /* By default, if MODE is narrower than a word, widen it to a word.
599 This is required because most machines that require these memory
600 locations do not support short load and stores from all registers
601 (e.g., FP registers). */
603 #ifdef SECONDARY_MEMORY_NEEDED_MODE
604 mode = SECONDARY_MEMORY_NEEDED_MODE (mode);
605 #else
606 if (GET_MODE_BITSIZE (mode) < BITS_PER_WORD && INTEGRAL_MODE_P (mode))
607 mode = mode_for_size (BITS_PER_WORD, GET_MODE_CLASS (mode), 0);
608 #endif
610 /* If we already have made a MEM for this operand in MODE, return it. */
611 if (secondary_memlocs_elim[(int) mode][opnum] != 0)
612 return secondary_memlocs_elim[(int) mode][opnum];
614 /* If this is the first time we've tried to get a MEM for this mode,
615 allocate a new one. `something_changed' in reload will get set
616 by noticing that the frame size has changed. */
618 if (secondary_memlocs[(int) mode] == 0)
620 #ifdef SECONDARY_MEMORY_NEEDED_RTX
621 secondary_memlocs[(int) mode] = SECONDARY_MEMORY_NEEDED_RTX (mode);
622 #else
623 secondary_memlocs[(int) mode]
624 = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
625 #endif
628 /* Get a version of the address doing any eliminations needed. If that
629 didn't give us a new MEM, make a new one if it isn't valid. */
631 loc = eliminate_regs (secondary_memlocs[(int) mode], VOIDmode, NULL_RTX);
632 mem_valid = strict_memory_address_p (mode, XEXP (loc, 0));
634 if (! mem_valid && loc == secondary_memlocs[(int) mode])
635 loc = copy_rtx (loc);
637 /* The only time the call below will do anything is if the stack
638 offset is too large. In that case IND_LEVELS doesn't matter, so we
639 can just pass a zero. Adjust the type to be the address of the
640 corresponding object. If the address was valid, save the eliminated
641 address. If it wasn't valid, we need to make a reload each time, so
642 don't save it. */
644 if (! mem_valid)
646 type = (type == RELOAD_FOR_INPUT ? RELOAD_FOR_INPUT_ADDRESS
647 : type == RELOAD_FOR_OUTPUT ? RELOAD_FOR_OUTPUT_ADDRESS
648 : RELOAD_OTHER);
650 find_reloads_address (mode, &loc, XEXP (loc, 0), &XEXP (loc, 0),
651 opnum, type, 0, 0);
654 secondary_memlocs_elim[(int) mode][opnum] = loc;
655 return loc;
658 /* Clear any secondary memory locations we've made. */
660 void
661 clear_secondary_mem ()
663 memset ((char *) secondary_memlocs, 0, sizeof secondary_memlocs);
665 #endif /* SECONDARY_MEMORY_NEEDED */
667 /* Find the largest class for which every register number plus N is valid in
668 M1 (if in range) and is cheap to move into REGNO.
669 Abort if no such class exists. */
671 static enum reg_class
672 find_valid_class (m1, n, dest_regno)
673 enum machine_mode m1 ATTRIBUTE_UNUSED;
674 int n;
675 unsigned int dest_regno ATTRIBUTE_UNUSED;
677 int best_cost = -1;
678 int class;
679 int regno;
680 enum reg_class best_class = NO_REGS;
681 enum reg_class dest_class ATTRIBUTE_UNUSED = REGNO_REG_CLASS (dest_regno);
682 unsigned int best_size = 0;
683 int cost;
685 for (class = 1; class < N_REG_CLASSES; class++)
687 int bad = 0;
688 for (regno = 0; regno < FIRST_PSEUDO_REGISTER && ! bad; regno++)
689 if (TEST_HARD_REG_BIT (reg_class_contents[class], regno)
690 && TEST_HARD_REG_BIT (reg_class_contents[class], regno + n)
691 && ! HARD_REGNO_MODE_OK (regno + n, m1))
692 bad = 1;
694 if (bad)
695 continue;
696 cost = REGISTER_MOVE_COST (m1, class, dest_class);
698 if ((reg_class_size[class] > best_size
699 && (best_cost < 0 || best_cost >= cost))
700 || best_cost > cost)
702 best_class = class;
703 best_size = reg_class_size[class];
704 best_cost = REGISTER_MOVE_COST (m1, class, dest_class);
708 if (best_size == 0)
709 abort ();
711 return best_class;
714 /* Return the number of a previously made reload that can be combined with
715 a new one, or n_reloads if none of the existing reloads can be used.
716 OUT, CLASS, TYPE and OPNUM are the same arguments as passed to
717 push_reload, they determine the kind of the new reload that we try to
718 combine. P_IN points to the corresponding value of IN, which can be
719 modified by this function.
720 DONT_SHARE is nonzero if we can't share any input-only reload for IN. */
722 static int
723 find_reusable_reload (p_in, out, class, type, opnum, dont_share)
724 rtx *p_in, out;
725 enum reg_class class;
726 enum reload_type type;
727 int opnum, dont_share;
729 rtx in = *p_in;
730 int i;
731 /* We can't merge two reloads if the output of either one is
732 earlyclobbered. */
734 if (earlyclobber_operand_p (out))
735 return n_reloads;
737 /* We can use an existing reload if the class is right
738 and at least one of IN and OUT is a match
739 and the other is at worst neutral.
740 (A zero compared against anything is neutral.)
742 If SMALL_REGISTER_CLASSES, don't use existing reloads unless they are
743 for the same thing since that can cause us to need more reload registers
744 than we otherwise would. */
746 for (i = 0; i < n_reloads; i++)
747 if ((reg_class_subset_p (class, rld[i].class)
748 || reg_class_subset_p (rld[i].class, class))
749 /* If the existing reload has a register, it must fit our class. */
750 && (rld[i].reg_rtx == 0
751 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
752 true_regnum (rld[i].reg_rtx)))
753 && ((in != 0 && MATCHES (rld[i].in, in) && ! dont_share
754 && (out == 0 || rld[i].out == 0 || MATCHES (rld[i].out, out)))
755 || (out != 0 && MATCHES (rld[i].out, out)
756 && (in == 0 || rld[i].in == 0 || MATCHES (rld[i].in, in))))
757 && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
758 && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES)
759 && MERGABLE_RELOADS (type, rld[i].when_needed, opnum, rld[i].opnum))
760 return i;
762 /* Reloading a plain reg for input can match a reload to postincrement
763 that reg, since the postincrement's value is the right value.
764 Likewise, it can match a preincrement reload, since we regard
765 the preincrementation as happening before any ref in this insn
766 to that register. */
767 for (i = 0; i < n_reloads; i++)
768 if ((reg_class_subset_p (class, rld[i].class)
769 || reg_class_subset_p (rld[i].class, class))
770 /* If the existing reload has a register, it must fit our
771 class. */
772 && (rld[i].reg_rtx == 0
773 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
774 true_regnum (rld[i].reg_rtx)))
775 && out == 0 && rld[i].out == 0 && rld[i].in != 0
776 && ((GET_CODE (in) == REG
777 && GET_RTX_CLASS (GET_CODE (rld[i].in)) == 'a'
778 && MATCHES (XEXP (rld[i].in, 0), in))
779 || (GET_CODE (rld[i].in) == REG
780 && GET_RTX_CLASS (GET_CODE (in)) == 'a'
781 && MATCHES (XEXP (in, 0), rld[i].in)))
782 && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
783 && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES)
784 && MERGABLE_RELOADS (type, rld[i].when_needed,
785 opnum, rld[i].opnum))
787 /* Make sure reload_in ultimately has the increment,
788 not the plain register. */
789 if (GET_CODE (in) == REG)
790 *p_in = rld[i].in;
791 return i;
793 return n_reloads;
796 /* Return nonzero if X is a SUBREG which will require reloading of its
797 SUBREG_REG expression. */
799 static int
800 reload_inner_reg_of_subreg (x, mode, output)
801 rtx x;
802 enum machine_mode mode;
803 int output;
805 rtx inner;
807 /* Only SUBREGs are problematical. */
808 if (GET_CODE (x) != SUBREG)
809 return 0;
811 inner = SUBREG_REG (x);
813 /* If INNER is a constant or PLUS, then INNER must be reloaded. */
814 if (CONSTANT_P (inner) || GET_CODE (inner) == PLUS)
815 return 1;
817 /* If INNER is not a hard register, then INNER will not need to
818 be reloaded. */
819 if (GET_CODE (inner) != REG
820 || REGNO (inner) >= FIRST_PSEUDO_REGISTER)
821 return 0;
823 /* If INNER is not ok for MODE, then INNER will need reloading. */
824 if (! HARD_REGNO_MODE_OK (subreg_regno (x), mode))
825 return 1;
827 /* If the outer part is a word or smaller, INNER larger than a
828 word and the number of regs for INNER is not the same as the
829 number of words in INNER, then INNER will need reloading. */
830 return (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
831 && output
832 && GET_MODE_SIZE (GET_MODE (inner)) > UNITS_PER_WORD
833 && ((GET_MODE_SIZE (GET_MODE (inner)) / UNITS_PER_WORD)
834 != (int) HARD_REGNO_NREGS (REGNO (inner), GET_MODE (inner))));
837 /* Record one reload that needs to be performed.
838 IN is an rtx saying where the data are to be found before this instruction.
839 OUT says where they must be stored after the instruction.
840 (IN is zero for data not read, and OUT is zero for data not written.)
841 INLOC and OUTLOC point to the places in the instructions where
842 IN and OUT were found.
843 If IN and OUT are both nonzero, it means the same register must be used
844 to reload both IN and OUT.
846 CLASS is a register class required for the reloaded data.
847 INMODE is the machine mode that the instruction requires
848 for the reg that replaces IN and OUTMODE is likewise for OUT.
850 If IN is zero, then OUT's location and mode should be passed as
851 INLOC and INMODE.
853 STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
855 OPTIONAL nonzero means this reload does not need to be performed:
856 it can be discarded if that is more convenient.
858 OPNUM and TYPE say what the purpose of this reload is.
860 The return value is the reload-number for this reload.
862 If both IN and OUT are nonzero, in some rare cases we might
863 want to make two separate reloads. (Actually we never do this now.)
864 Therefore, the reload-number for OUT is stored in
865 output_reloadnum when we return; the return value applies to IN.
866 Usually (presently always), when IN and OUT are nonzero,
867 the two reload-numbers are equal, but the caller should be careful to
868 distinguish them. */
871 push_reload (in, out, inloc, outloc, class,
872 inmode, outmode, strict_low, optional, opnum, type)
873 rtx in, out;
874 rtx *inloc, *outloc;
875 enum reg_class class;
876 enum machine_mode inmode, outmode;
877 int strict_low;
878 int optional;
879 int opnum;
880 enum reload_type type;
882 int i;
883 int dont_share = 0;
884 int dont_remove_subreg = 0;
885 rtx *in_subreg_loc = 0, *out_subreg_loc = 0;
886 int secondary_in_reload = -1, secondary_out_reload = -1;
887 enum insn_code secondary_in_icode = CODE_FOR_nothing;
888 enum insn_code secondary_out_icode = CODE_FOR_nothing;
890 /* INMODE and/or OUTMODE could be VOIDmode if no mode
891 has been specified for the operand. In that case,
892 use the operand's mode as the mode to reload. */
893 if (inmode == VOIDmode && in != 0)
894 inmode = GET_MODE (in);
895 if (outmode == VOIDmode && out != 0)
896 outmode = GET_MODE (out);
898 /* If IN is a pseudo register everywhere-equivalent to a constant, and
899 it is not in a hard register, reload straight from the constant,
900 since we want to get rid of such pseudo registers.
901 Often this is done earlier, but not always in find_reloads_address. */
902 if (in != 0 && GET_CODE (in) == REG)
904 int regno = REGNO (in);
906 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
907 && reg_equiv_constant[regno] != 0)
908 in = reg_equiv_constant[regno];
911 /* Likewise for OUT. Of course, OUT will never be equivalent to
912 an actual constant, but it might be equivalent to a memory location
913 (in the case of a parameter). */
914 if (out != 0 && GET_CODE (out) == REG)
916 int regno = REGNO (out);
918 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
919 && reg_equiv_constant[regno] != 0)
920 out = reg_equiv_constant[regno];
923 /* If we have a read-write operand with an address side-effect,
924 change either IN or OUT so the side-effect happens only once. */
925 if (in != 0 && out != 0 && GET_CODE (in) == MEM && rtx_equal_p (in, out))
926 switch (GET_CODE (XEXP (in, 0)))
928 case POST_INC: case POST_DEC: case POST_MODIFY:
929 in = replace_equiv_address_nv (in, XEXP (XEXP (in, 0), 0));
930 break;
932 case PRE_INC: case PRE_DEC: case PRE_MODIFY:
933 out = replace_equiv_address_nv (out, XEXP (XEXP (out, 0), 0));
934 break;
936 default:
937 break;
940 /* If we are reloading a (SUBREG constant ...), really reload just the
941 inside expression in its own mode. Similarly for (SUBREG (PLUS ...)).
942 If we have (SUBREG:M1 (MEM:M2 ...) ...) (or an inner REG that is still
943 a pseudo and hence will become a MEM) with M1 wider than M2 and the
944 register is a pseudo, also reload the inside expression.
945 For machines that extend byte loads, do this for any SUBREG of a pseudo
946 where both M1 and M2 are a word or smaller, M1 is wider than M2, and
947 M2 is an integral mode that gets extended when loaded.
948 Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
949 either M1 is not valid for R or M2 is wider than a word but we only
950 need one word to store an M2-sized quantity in R.
951 (However, if OUT is nonzero, we need to reload the reg *and*
952 the subreg, so do nothing here, and let following statement handle it.)
954 Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere;
955 we can't handle it here because CONST_INT does not indicate a mode.
957 Similarly, we must reload the inside expression if we have a
958 STRICT_LOW_PART (presumably, in == out in the cas).
960 Also reload the inner expression if it does not require a secondary
961 reload but the SUBREG does.
963 Finally, reload the inner expression if it is a register that is in
964 the class whose registers cannot be referenced in a different size
965 and M1 is not the same size as M2. If subreg_lowpart_p is false, we
966 cannot reload just the inside since we might end up with the wrong
967 register class. But if it is inside a STRICT_LOW_PART, we have
968 no choice, so we hope we do get the right register class there. */
970 if (in != 0 && GET_CODE (in) == SUBREG
971 && (subreg_lowpart_p (in) || strict_low)
972 #ifdef CANNOT_CHANGE_MODE_CLASS
973 && !reg_classes_intersect_p
974 (class, CANNOT_CHANGE_MODE_CLASS (GET_MODE (SUBREG_REG (in)),
975 inmode))
976 #endif
977 && (CONSTANT_P (SUBREG_REG (in))
978 || GET_CODE (SUBREG_REG (in)) == PLUS
979 || strict_low
980 || (((GET_CODE (SUBREG_REG (in)) == REG
981 && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER)
982 || GET_CODE (SUBREG_REG (in)) == MEM)
983 && ((GET_MODE_SIZE (inmode)
984 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
985 #ifdef LOAD_EXTEND_OP
986 || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
987 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
988 <= UNITS_PER_WORD)
989 && (GET_MODE_SIZE (inmode)
990 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
991 && INTEGRAL_MODE_P (GET_MODE (SUBREG_REG (in)))
992 && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (in))) != NIL)
993 #endif
994 #ifdef WORD_REGISTER_OPERATIONS
995 || ((GET_MODE_SIZE (inmode)
996 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
997 && ((GET_MODE_SIZE (inmode) - 1) / UNITS_PER_WORD ==
998 ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))) - 1)
999 / UNITS_PER_WORD)))
1000 #endif
1002 || (GET_CODE (SUBREG_REG (in)) == REG
1003 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1004 /* The case where out is nonzero
1005 is handled differently in the following statement. */
1006 && (out == 0 || subreg_lowpart_p (in))
1007 && ((GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
1008 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1009 > UNITS_PER_WORD)
1010 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1011 / UNITS_PER_WORD)
1012 != (int) HARD_REGNO_NREGS (REGNO (SUBREG_REG (in)),
1013 GET_MODE (SUBREG_REG (in)))))
1014 || ! HARD_REGNO_MODE_OK (subreg_regno (in), inmode)))
1015 #ifdef SECONDARY_INPUT_RELOAD_CLASS
1016 || (SECONDARY_INPUT_RELOAD_CLASS (class, inmode, in) != NO_REGS
1017 && (SECONDARY_INPUT_RELOAD_CLASS (class,
1018 GET_MODE (SUBREG_REG (in)),
1019 SUBREG_REG (in))
1020 == NO_REGS))
1021 #endif
1022 #ifdef CANNOT_CHANGE_MODE_CLASS
1023 || (GET_CODE (SUBREG_REG (in)) == REG
1024 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1025 && REG_CANNOT_CHANGE_MODE_P
1026 (REGNO (SUBREG_REG (in)), GET_MODE (SUBREG_REG (in)), inmode))
1027 #endif
1030 in_subreg_loc = inloc;
1031 inloc = &SUBREG_REG (in);
1032 in = *inloc;
1033 #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
1034 if (GET_CODE (in) == MEM)
1035 /* This is supposed to happen only for paradoxical subregs made by
1036 combine.c. (SUBREG (MEM)) isn't supposed to occur other ways. */
1037 if (GET_MODE_SIZE (GET_MODE (in)) > GET_MODE_SIZE (inmode))
1038 abort ();
1039 #endif
1040 inmode = GET_MODE (in);
1043 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
1044 either M1 is not valid for R or M2 is wider than a word but we only
1045 need one word to store an M2-sized quantity in R.
1047 However, we must reload the inner reg *as well as* the subreg in
1048 that case. */
1050 /* Similar issue for (SUBREG constant ...) if it was not handled by the
1051 code above. This can happen if SUBREG_BYTE != 0. */
1053 if (in != 0 && reload_inner_reg_of_subreg (in, inmode, 0))
1055 enum reg_class in_class = class;
1057 if (GET_CODE (SUBREG_REG (in)) == REG)
1058 in_class
1059 = find_valid_class (inmode,
1060 subreg_regno_offset (REGNO (SUBREG_REG (in)),
1061 GET_MODE (SUBREG_REG (in)),
1062 SUBREG_BYTE (in),
1063 GET_MODE (in)),
1064 REGNO (SUBREG_REG (in)));
1066 /* This relies on the fact that emit_reload_insns outputs the
1067 instructions for input reloads of type RELOAD_OTHER in the same
1068 order as the reloads. Thus if the outer reload is also of type
1069 RELOAD_OTHER, we are guaranteed that this inner reload will be
1070 output before the outer reload. */
1071 push_reload (SUBREG_REG (in), NULL_RTX, &SUBREG_REG (in), (rtx *) 0,
1072 in_class, VOIDmode, VOIDmode, 0, 0, opnum, type);
1073 dont_remove_subreg = 1;
1076 /* Similarly for paradoxical and problematical SUBREGs on the output.
1077 Note that there is no reason we need worry about the previous value
1078 of SUBREG_REG (out); even if wider than out,
1079 storing in a subreg is entitled to clobber it all
1080 (except in the case of STRICT_LOW_PART,
1081 and in that case the constraint should label it input-output.) */
1082 if (out != 0 && GET_CODE (out) == SUBREG
1083 && (subreg_lowpart_p (out) || strict_low)
1084 #ifdef CANNOT_CHANGE_MODE_CLASS
1085 && !reg_classes_intersect_p
1086 (class, CANNOT_CHANGE_MODE_CLASS (GET_MODE (SUBREG_REG (out)),
1087 outmode))
1088 #endif
1089 && (CONSTANT_P (SUBREG_REG (out))
1090 || strict_low
1091 || (((GET_CODE (SUBREG_REG (out)) == REG
1092 && REGNO (SUBREG_REG (out)) >= FIRST_PSEUDO_REGISTER)
1093 || GET_CODE (SUBREG_REG (out)) == MEM)
1094 && ((GET_MODE_SIZE (outmode)
1095 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))
1096 #ifdef WORD_REGISTER_OPERATIONS
1097 || ((GET_MODE_SIZE (outmode)
1098 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))
1099 && ((GET_MODE_SIZE (outmode) - 1) / UNITS_PER_WORD ==
1100 ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))) - 1)
1101 / UNITS_PER_WORD)))
1102 #endif
1104 || (GET_CODE (SUBREG_REG (out)) == REG
1105 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1106 && ((GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
1107 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1108 > UNITS_PER_WORD)
1109 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1110 / UNITS_PER_WORD)
1111 != (int) HARD_REGNO_NREGS (REGNO (SUBREG_REG (out)),
1112 GET_MODE (SUBREG_REG (out)))))
1113 || ! HARD_REGNO_MODE_OK (subreg_regno (out), outmode)))
1114 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1115 || (SECONDARY_OUTPUT_RELOAD_CLASS (class, outmode, out) != NO_REGS
1116 && (SECONDARY_OUTPUT_RELOAD_CLASS (class,
1117 GET_MODE (SUBREG_REG (out)),
1118 SUBREG_REG (out))
1119 == NO_REGS))
1120 #endif
1121 #ifdef CANNOT_CHANGE_MODE_CLASS
1122 || (GET_CODE (SUBREG_REG (out)) == REG
1123 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1124 && REG_CANNOT_CHANGE_MODE_P (REGNO (SUBREG_REG (out)),
1125 GET_MODE (SUBREG_REG (out)),
1126 outmode))
1127 #endif
1130 out_subreg_loc = outloc;
1131 outloc = &SUBREG_REG (out);
1132 out = *outloc;
1133 #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
1134 if (GET_CODE (out) == MEM
1135 && GET_MODE_SIZE (GET_MODE (out)) > GET_MODE_SIZE (outmode))
1136 abort ();
1137 #endif
1138 outmode = GET_MODE (out);
1141 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
1142 either M1 is not valid for R or M2 is wider than a word but we only
1143 need one word to store an M2-sized quantity in R.
1145 However, we must reload the inner reg *as well as* the subreg in
1146 that case. In this case, the inner reg is an in-out reload. */
1148 if (out != 0 && reload_inner_reg_of_subreg (out, outmode, 1))
1150 /* This relies on the fact that emit_reload_insns outputs the
1151 instructions for output reloads of type RELOAD_OTHER in reverse
1152 order of the reloads. Thus if the outer reload is also of type
1153 RELOAD_OTHER, we are guaranteed that this inner reload will be
1154 output after the outer reload. */
1155 dont_remove_subreg = 1;
1156 push_reload (SUBREG_REG (out), SUBREG_REG (out), &SUBREG_REG (out),
1157 &SUBREG_REG (out),
1158 find_valid_class (outmode,
1159 subreg_regno_offset (REGNO (SUBREG_REG (out)),
1160 GET_MODE (SUBREG_REG (out)),
1161 SUBREG_BYTE (out),
1162 GET_MODE (out)),
1163 REGNO (SUBREG_REG (out))),
1164 VOIDmode, VOIDmode, 0, 0,
1165 opnum, RELOAD_OTHER);
1168 /* If IN appears in OUT, we can't share any input-only reload for IN. */
1169 if (in != 0 && out != 0 && GET_CODE (out) == MEM
1170 && (GET_CODE (in) == REG || GET_CODE (in) == MEM)
1171 && reg_overlap_mentioned_for_reload_p (in, XEXP (out, 0)))
1172 dont_share = 1;
1174 /* If IN is a SUBREG of a hard register, make a new REG. This
1175 simplifies some of the cases below. */
1177 if (in != 0 && GET_CODE (in) == SUBREG && GET_CODE (SUBREG_REG (in)) == REG
1178 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1179 && ! dont_remove_subreg)
1180 in = gen_rtx_REG (GET_MODE (in), subreg_regno (in));
1182 /* Similarly for OUT. */
1183 if (out != 0 && GET_CODE (out) == SUBREG
1184 && GET_CODE (SUBREG_REG (out)) == REG
1185 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1186 && ! dont_remove_subreg)
1187 out = gen_rtx_REG (GET_MODE (out), subreg_regno (out));
1189 /* Narrow down the class of register wanted if that is
1190 desirable on this machine for efficiency. */
1191 if (in != 0)
1192 class = PREFERRED_RELOAD_CLASS (in, class);
1194 /* Output reloads may need analogous treatment, different in detail. */
1195 #ifdef PREFERRED_OUTPUT_RELOAD_CLASS
1196 if (out != 0)
1197 class = PREFERRED_OUTPUT_RELOAD_CLASS (out, class);
1198 #endif
1200 /* Make sure we use a class that can handle the actual pseudo
1201 inside any subreg. For example, on the 386, QImode regs
1202 can appear within SImode subregs. Although GENERAL_REGS
1203 can handle SImode, QImode needs a smaller class. */
1204 #ifdef LIMIT_RELOAD_CLASS
1205 if (in_subreg_loc)
1206 class = LIMIT_RELOAD_CLASS (inmode, class);
1207 else if (in != 0 && GET_CODE (in) == SUBREG)
1208 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (in)), class);
1210 if (out_subreg_loc)
1211 class = LIMIT_RELOAD_CLASS (outmode, class);
1212 if (out != 0 && GET_CODE (out) == SUBREG)
1213 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (out)), class);
1214 #endif
1216 /* Verify that this class is at least possible for the mode that
1217 is specified. */
1218 if (this_insn_is_asm)
1220 enum machine_mode mode;
1221 if (GET_MODE_SIZE (inmode) > GET_MODE_SIZE (outmode))
1222 mode = inmode;
1223 else
1224 mode = outmode;
1225 if (mode == VOIDmode)
1227 error_for_asm (this_insn, "cannot reload integer constant operand in `asm'");
1228 mode = word_mode;
1229 if (in != 0)
1230 inmode = word_mode;
1231 if (out != 0)
1232 outmode = word_mode;
1234 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1235 if (HARD_REGNO_MODE_OK (i, mode)
1236 && TEST_HARD_REG_BIT (reg_class_contents[(int) class], i))
1238 int nregs = HARD_REGNO_NREGS (i, mode);
1240 int j;
1241 for (j = 1; j < nregs; j++)
1242 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], i + j))
1243 break;
1244 if (j == nregs)
1245 break;
1247 if (i == FIRST_PSEUDO_REGISTER)
1249 error_for_asm (this_insn, "impossible register constraint in `asm'");
1250 class = ALL_REGS;
1254 /* Optional output reloads are always OK even if we have no register class,
1255 since the function of these reloads is only to have spill_reg_store etc.
1256 set, so that the storing insn can be deleted later. */
1257 if (class == NO_REGS
1258 && (optional == 0 || type != RELOAD_FOR_OUTPUT))
1259 abort ();
1261 i = find_reusable_reload (&in, out, class, type, opnum, dont_share);
1263 if (i == n_reloads)
1265 /* See if we need a secondary reload register to move between CLASS
1266 and IN or CLASS and OUT. Get the icode and push any required reloads
1267 needed for each of them if so. */
1269 #ifdef SECONDARY_INPUT_RELOAD_CLASS
1270 if (in != 0)
1271 secondary_in_reload
1272 = push_secondary_reload (1, in, opnum, optional, class, inmode, type,
1273 &secondary_in_icode);
1274 #endif
1276 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1277 if (out != 0 && GET_CODE (out) != SCRATCH)
1278 secondary_out_reload
1279 = push_secondary_reload (0, out, opnum, optional, class, outmode,
1280 type, &secondary_out_icode);
1281 #endif
1283 /* We found no existing reload suitable for re-use.
1284 So add an additional reload. */
1286 #ifdef SECONDARY_MEMORY_NEEDED
1287 /* If a memory location is needed for the copy, make one. */
1288 if (in != 0 && (GET_CODE (in) == REG || GET_CODE (in) == SUBREG)
1289 && reg_or_subregno (in) < FIRST_PSEUDO_REGISTER
1290 && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (reg_or_subregno (in)),
1291 class, inmode))
1292 get_secondary_mem (in, inmode, opnum, type);
1293 #endif
1295 i = n_reloads;
1296 rld[i].in = in;
1297 rld[i].out = out;
1298 rld[i].class = class;
1299 rld[i].inmode = inmode;
1300 rld[i].outmode = outmode;
1301 rld[i].reg_rtx = 0;
1302 rld[i].optional = optional;
1303 rld[i].inc = 0;
1304 rld[i].nocombine = 0;
1305 rld[i].in_reg = inloc ? *inloc : 0;
1306 rld[i].out_reg = outloc ? *outloc : 0;
1307 rld[i].opnum = opnum;
1308 rld[i].when_needed = type;
1309 rld[i].secondary_in_reload = secondary_in_reload;
1310 rld[i].secondary_out_reload = secondary_out_reload;
1311 rld[i].secondary_in_icode = secondary_in_icode;
1312 rld[i].secondary_out_icode = secondary_out_icode;
1313 rld[i].secondary_p = 0;
1315 n_reloads++;
1317 #ifdef SECONDARY_MEMORY_NEEDED
1318 if (out != 0 && (GET_CODE (out) == REG || GET_CODE (out) == SUBREG)
1319 && reg_or_subregno (out) < FIRST_PSEUDO_REGISTER
1320 && SECONDARY_MEMORY_NEEDED (class,
1321 REGNO_REG_CLASS (reg_or_subregno (out)),
1322 outmode))
1323 get_secondary_mem (out, outmode, opnum, type);
1324 #endif
1326 else
1328 /* We are reusing an existing reload,
1329 but we may have additional information for it.
1330 For example, we may now have both IN and OUT
1331 while the old one may have just one of them. */
1333 /* The modes can be different. If they are, we want to reload in
1334 the larger mode, so that the value is valid for both modes. */
1335 if (inmode != VOIDmode
1336 && GET_MODE_SIZE (inmode) > GET_MODE_SIZE (rld[i].inmode))
1337 rld[i].inmode = inmode;
1338 if (outmode != VOIDmode
1339 && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (rld[i].outmode))
1340 rld[i].outmode = outmode;
1341 if (in != 0)
1343 rtx in_reg = inloc ? *inloc : 0;
1344 /* If we merge reloads for two distinct rtl expressions that
1345 are identical in content, there might be duplicate address
1346 reloads. Remove the extra set now, so that if we later find
1347 that we can inherit this reload, we can get rid of the
1348 address reloads altogether.
1350 Do not do this if both reloads are optional since the result
1351 would be an optional reload which could potentially leave
1352 unresolved address replacements.
1354 It is not sufficient to call transfer_replacements since
1355 choose_reload_regs will remove the replacements for address
1356 reloads of inherited reloads which results in the same
1357 problem. */
1358 if (rld[i].in != in && rtx_equal_p (in, rld[i].in)
1359 && ! (rld[i].optional && optional))
1361 /* We must keep the address reload with the lower operand
1362 number alive. */
1363 if (opnum > rld[i].opnum)
1365 remove_address_replacements (in);
1366 in = rld[i].in;
1367 in_reg = rld[i].in_reg;
1369 else
1370 remove_address_replacements (rld[i].in);
1372 rld[i].in = in;
1373 rld[i].in_reg = in_reg;
1375 if (out != 0)
1377 rld[i].out = out;
1378 rld[i].out_reg = outloc ? *outloc : 0;
1380 if (reg_class_subset_p (class, rld[i].class))
1381 rld[i].class = class;
1382 rld[i].optional &= optional;
1383 if (MERGE_TO_OTHER (type, rld[i].when_needed,
1384 opnum, rld[i].opnum))
1385 rld[i].when_needed = RELOAD_OTHER;
1386 rld[i].opnum = MIN (rld[i].opnum, opnum);
1389 /* If the ostensible rtx being reloaded differs from the rtx found
1390 in the location to substitute, this reload is not safe to combine
1391 because we cannot reliably tell whether it appears in the insn. */
1393 if (in != 0 && in != *inloc)
1394 rld[i].nocombine = 1;
1396 #if 0
1397 /* This was replaced by changes in find_reloads_address_1 and the new
1398 function inc_for_reload, which go with a new meaning of reload_inc. */
1400 /* If this is an IN/OUT reload in an insn that sets the CC,
1401 it must be for an autoincrement. It doesn't work to store
1402 the incremented value after the insn because that would clobber the CC.
1403 So we must do the increment of the value reloaded from,
1404 increment it, store it back, then decrement again. */
1405 if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
1407 out = 0;
1408 rld[i].out = 0;
1409 rld[i].inc = find_inc_amount (PATTERN (this_insn), in);
1410 /* If we did not find a nonzero amount-to-increment-by,
1411 that contradicts the belief that IN is being incremented
1412 in an address in this insn. */
1413 if (rld[i].inc == 0)
1414 abort ();
1416 #endif
1418 /* If we will replace IN and OUT with the reload-reg,
1419 record where they are located so that substitution need
1420 not do a tree walk. */
1422 if (replace_reloads)
1424 if (inloc != 0)
1426 struct replacement *r = &replacements[n_replacements++];
1427 r->what = i;
1428 r->subreg_loc = in_subreg_loc;
1429 r->where = inloc;
1430 r->mode = inmode;
1432 if (outloc != 0 && outloc != inloc)
1434 struct replacement *r = &replacements[n_replacements++];
1435 r->what = i;
1436 r->where = outloc;
1437 r->subreg_loc = out_subreg_loc;
1438 r->mode = outmode;
1442 /* If this reload is just being introduced and it has both
1443 an incoming quantity and an outgoing quantity that are
1444 supposed to be made to match, see if either one of the two
1445 can serve as the place to reload into.
1447 If one of them is acceptable, set rld[i].reg_rtx
1448 to that one. */
1450 if (in != 0 && out != 0 && in != out && rld[i].reg_rtx == 0)
1452 rld[i].reg_rtx = find_dummy_reload (in, out, inloc, outloc,
1453 inmode, outmode,
1454 rld[i].class, i,
1455 earlyclobber_operand_p (out));
1457 /* If the outgoing register already contains the same value
1458 as the incoming one, we can dispense with loading it.
1459 The easiest way to tell the caller that is to give a phony
1460 value for the incoming operand (same as outgoing one). */
1461 if (rld[i].reg_rtx == out
1462 && (GET_CODE (in) == REG || CONSTANT_P (in))
1463 && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
1464 static_reload_reg_p, i, inmode))
1465 rld[i].in = out;
1468 /* If this is an input reload and the operand contains a register that
1469 dies in this insn and is used nowhere else, see if it is the right class
1470 to be used for this reload. Use it if so. (This occurs most commonly
1471 in the case of paradoxical SUBREGs and in-out reloads). We cannot do
1472 this if it is also an output reload that mentions the register unless
1473 the output is a SUBREG that clobbers an entire register.
1475 Note that the operand might be one of the spill regs, if it is a
1476 pseudo reg and we are in a block where spilling has not taken place.
1477 But if there is no spilling in this block, that is OK.
1478 An explicitly used hard reg cannot be a spill reg. */
1480 if (rld[i].reg_rtx == 0 && in != 0)
1482 rtx note;
1483 int regno;
1484 enum machine_mode rel_mode = inmode;
1486 if (out && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (inmode))
1487 rel_mode = outmode;
1489 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1490 if (REG_NOTE_KIND (note) == REG_DEAD
1491 && GET_CODE (XEXP (note, 0)) == REG
1492 && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1493 && reg_mentioned_p (XEXP (note, 0), in)
1494 && ! refers_to_regno_for_reload_p (regno,
1495 (regno
1496 + HARD_REGNO_NREGS (regno,
1497 rel_mode)),
1498 PATTERN (this_insn), inloc)
1499 /* If this is also an output reload, IN cannot be used as
1500 the reload register if it is set in this insn unless IN
1501 is also OUT. */
1502 && (out == 0 || in == out
1503 || ! hard_reg_set_here_p (regno,
1504 (regno
1505 + HARD_REGNO_NREGS (regno,
1506 rel_mode)),
1507 PATTERN (this_insn)))
1508 /* ??? Why is this code so different from the previous?
1509 Is there any simple coherent way to describe the two together?
1510 What's going on here. */
1511 && (in != out
1512 || (GET_CODE (in) == SUBREG
1513 && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1))
1514 / UNITS_PER_WORD)
1515 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1516 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
1517 /* Make sure the operand fits in the reg that dies. */
1518 && (GET_MODE_SIZE (rel_mode)
1519 <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0))))
1520 && HARD_REGNO_MODE_OK (regno, inmode)
1521 && HARD_REGNO_MODE_OK (regno, outmode))
1523 unsigned int offs;
1524 unsigned int nregs = MAX (HARD_REGNO_NREGS (regno, inmode),
1525 HARD_REGNO_NREGS (regno, outmode));
1527 for (offs = 0; offs < nregs; offs++)
1528 if (fixed_regs[regno + offs]
1529 || ! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1530 regno + offs))
1531 break;
1533 if (offs == nregs)
1535 rld[i].reg_rtx = gen_rtx_REG (rel_mode, regno);
1536 break;
1541 if (out)
1542 output_reloadnum = i;
1544 return i;
1547 /* Record an additional place we must replace a value
1548 for which we have already recorded a reload.
1549 RELOADNUM is the value returned by push_reload
1550 when the reload was recorded.
1551 This is used in insn patterns that use match_dup. */
1553 static void
1554 push_replacement (loc, reloadnum, mode)
1555 rtx *loc;
1556 int reloadnum;
1557 enum machine_mode mode;
1559 if (replace_reloads)
1561 struct replacement *r = &replacements[n_replacements++];
1562 r->what = reloadnum;
1563 r->where = loc;
1564 r->subreg_loc = 0;
1565 r->mode = mode;
1569 /* Duplicate any replacement we have recorded to apply at
1570 location ORIG_LOC to also be performed at DUP_LOC.
1571 This is used in insn patterns that use match_dup. */
1573 static void
1574 dup_replacements (dup_loc, orig_loc)
1575 rtx *dup_loc;
1576 rtx *orig_loc;
1578 int i, n = n_replacements;
1580 for (i = 0; i < n; i++)
1582 struct replacement *r = &replacements[i];
1583 if (r->where == orig_loc)
1584 push_replacement (dup_loc, r->what, r->mode);
1588 /* Transfer all replacements that used to be in reload FROM to be in
1589 reload TO. */
1591 void
1592 transfer_replacements (to, from)
1593 int to, from;
1595 int i;
1597 for (i = 0; i < n_replacements; i++)
1598 if (replacements[i].what == from)
1599 replacements[i].what = to;
1602 /* IN_RTX is the value loaded by a reload that we now decided to inherit,
1603 or a subpart of it. If we have any replacements registered for IN_RTX,
1604 cancel the reloads that were supposed to load them.
1605 Return nonzero if we canceled any reloads. */
1607 remove_address_replacements (in_rtx)
1608 rtx in_rtx;
1610 int i, j;
1611 char reload_flags[MAX_RELOADS];
1612 int something_changed = 0;
1614 memset (reload_flags, 0, sizeof reload_flags);
1615 for (i = 0, j = 0; i < n_replacements; i++)
1617 if (loc_mentioned_in_p (replacements[i].where, in_rtx))
1618 reload_flags[replacements[i].what] |= 1;
1619 else
1621 replacements[j++] = replacements[i];
1622 reload_flags[replacements[i].what] |= 2;
1625 /* Note that the following store must be done before the recursive calls. */
1626 n_replacements = j;
1628 for (i = n_reloads - 1; i >= 0; i--)
1630 if (reload_flags[i] == 1)
1632 deallocate_reload_reg (i);
1633 remove_address_replacements (rld[i].in);
1634 rld[i].in = 0;
1635 something_changed = 1;
1638 return something_changed;
1641 /* If there is only one output reload, and it is not for an earlyclobber
1642 operand, try to combine it with a (logically unrelated) input reload
1643 to reduce the number of reload registers needed.
1645 This is safe if the input reload does not appear in
1646 the value being output-reloaded, because this implies
1647 it is not needed any more once the original insn completes.
1649 If that doesn't work, see we can use any of the registers that
1650 die in this insn as a reload register. We can if it is of the right
1651 class and does not appear in the value being output-reloaded. */
1653 static void
1654 combine_reloads ()
1656 int i;
1657 int output_reload = -1;
1658 int secondary_out = -1;
1659 rtx note;
1661 /* Find the output reload; return unless there is exactly one
1662 and that one is mandatory. */
1664 for (i = 0; i < n_reloads; i++)
1665 if (rld[i].out != 0)
1667 if (output_reload >= 0)
1668 return;
1669 output_reload = i;
1672 if (output_reload < 0 || rld[output_reload].optional)
1673 return;
1675 /* An input-output reload isn't combinable. */
1677 if (rld[output_reload].in != 0)
1678 return;
1680 /* If this reload is for an earlyclobber operand, we can't do anything. */
1681 if (earlyclobber_operand_p (rld[output_reload].out))
1682 return;
1684 /* If there is a reload for part of the address of this operand, we would
1685 need to chnage it to RELOAD_FOR_OTHER_ADDRESS. But that would extend
1686 its life to the point where doing this combine would not lower the
1687 number of spill registers needed. */
1688 for (i = 0; i < n_reloads; i++)
1689 if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
1690 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
1691 && rld[i].opnum == rld[output_reload].opnum)
1692 return;
1694 /* Check each input reload; can we combine it? */
1696 for (i = 0; i < n_reloads; i++)
1697 if (rld[i].in && ! rld[i].optional && ! rld[i].nocombine
1698 /* Life span of this reload must not extend past main insn. */
1699 && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS
1700 && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS
1701 && rld[i].when_needed != RELOAD_OTHER
1702 && (CLASS_MAX_NREGS (rld[i].class, rld[i].inmode)
1703 == CLASS_MAX_NREGS (rld[output_reload].class,
1704 rld[output_reload].outmode))
1705 && rld[i].inc == 0
1706 && rld[i].reg_rtx == 0
1707 #ifdef SECONDARY_MEMORY_NEEDED
1708 /* Don't combine two reloads with different secondary
1709 memory locations. */
1710 && (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum] == 0
1711 || secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] == 0
1712 || rtx_equal_p (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum],
1713 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum]))
1714 #endif
1715 && (SMALL_REGISTER_CLASSES
1716 ? (rld[i].class == rld[output_reload].class)
1717 : (reg_class_subset_p (rld[i].class,
1718 rld[output_reload].class)
1719 || reg_class_subset_p (rld[output_reload].class,
1720 rld[i].class)))
1721 && (MATCHES (rld[i].in, rld[output_reload].out)
1722 /* Args reversed because the first arg seems to be
1723 the one that we imagine being modified
1724 while the second is the one that might be affected. */
1725 || (! reg_overlap_mentioned_for_reload_p (rld[output_reload].out,
1726 rld[i].in)
1727 /* However, if the input is a register that appears inside
1728 the output, then we also can't share.
1729 Imagine (set (mem (reg 69)) (plus (reg 69) ...)).
1730 If the same reload reg is used for both reg 69 and the
1731 result to be stored in memory, then that result
1732 will clobber the address of the memory ref. */
1733 && ! (GET_CODE (rld[i].in) == REG
1734 && reg_overlap_mentioned_for_reload_p (rld[i].in,
1735 rld[output_reload].out))))
1736 && ! reload_inner_reg_of_subreg (rld[i].in, rld[i].inmode,
1737 rld[i].when_needed != RELOAD_FOR_INPUT)
1738 && (reg_class_size[(int) rld[i].class]
1739 || SMALL_REGISTER_CLASSES)
1740 /* We will allow making things slightly worse by combining an
1741 input and an output, but no worse than that. */
1742 && (rld[i].when_needed == RELOAD_FOR_INPUT
1743 || rld[i].when_needed == RELOAD_FOR_OUTPUT))
1745 int j;
1747 /* We have found a reload to combine with! */
1748 rld[i].out = rld[output_reload].out;
1749 rld[i].out_reg = rld[output_reload].out_reg;
1750 rld[i].outmode = rld[output_reload].outmode;
1751 /* Mark the old output reload as inoperative. */
1752 rld[output_reload].out = 0;
1753 /* The combined reload is needed for the entire insn. */
1754 rld[i].when_needed = RELOAD_OTHER;
1755 /* If the output reload had a secondary reload, copy it. */
1756 if (rld[output_reload].secondary_out_reload != -1)
1758 rld[i].secondary_out_reload
1759 = rld[output_reload].secondary_out_reload;
1760 rld[i].secondary_out_icode
1761 = rld[output_reload].secondary_out_icode;
1764 #ifdef SECONDARY_MEMORY_NEEDED
1765 /* Copy any secondary MEM. */
1766 if (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] != 0)
1767 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum]
1768 = secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum];
1769 #endif
1770 /* If required, minimize the register class. */
1771 if (reg_class_subset_p (rld[output_reload].class,
1772 rld[i].class))
1773 rld[i].class = rld[output_reload].class;
1775 /* Transfer all replacements from the old reload to the combined. */
1776 for (j = 0; j < n_replacements; j++)
1777 if (replacements[j].what == output_reload)
1778 replacements[j].what = i;
1780 return;
1783 /* If this insn has only one operand that is modified or written (assumed
1784 to be the first), it must be the one corresponding to this reload. It
1785 is safe to use anything that dies in this insn for that output provided
1786 that it does not occur in the output (we already know it isn't an
1787 earlyclobber. If this is an asm insn, give up. */
1789 if (INSN_CODE (this_insn) == -1)
1790 return;
1792 for (i = 1; i < insn_data[INSN_CODE (this_insn)].n_operands; i++)
1793 if (insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '='
1794 || insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '+')
1795 return;
1797 /* See if some hard register that dies in this insn and is not used in
1798 the output is the right class. Only works if the register we pick
1799 up can fully hold our output reload. */
1800 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1801 if (REG_NOTE_KIND (note) == REG_DEAD
1802 && GET_CODE (XEXP (note, 0)) == REG
1803 && ! reg_overlap_mentioned_for_reload_p (XEXP (note, 0),
1804 rld[output_reload].out)
1805 && REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1806 && HARD_REGNO_MODE_OK (REGNO (XEXP (note, 0)), rld[output_reload].outmode)
1807 && TEST_HARD_REG_BIT (reg_class_contents[(int) rld[output_reload].class],
1808 REGNO (XEXP (note, 0)))
1809 && (HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), rld[output_reload].outmode)
1810 <= HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), GET_MODE (XEXP (note, 0))))
1811 /* Ensure that a secondary or tertiary reload for this output
1812 won't want this register. */
1813 && ((secondary_out = rld[output_reload].secondary_out_reload) == -1
1814 || (! (TEST_HARD_REG_BIT
1815 (reg_class_contents[(int) rld[secondary_out].class],
1816 REGNO (XEXP (note, 0))))
1817 && ((secondary_out = rld[secondary_out].secondary_out_reload) == -1
1818 || ! (TEST_HARD_REG_BIT
1819 (reg_class_contents[(int) rld[secondary_out].class],
1820 REGNO (XEXP (note, 0)))))))
1821 && ! fixed_regs[REGNO (XEXP (note, 0))])
1823 rld[output_reload].reg_rtx
1824 = gen_rtx_REG (rld[output_reload].outmode,
1825 REGNO (XEXP (note, 0)));
1826 return;
1830 /* Try to find a reload register for an in-out reload (expressions IN and OUT).
1831 See if one of IN and OUT is a register that may be used;
1832 this is desirable since a spill-register won't be needed.
1833 If so, return the register rtx that proves acceptable.
1835 INLOC and OUTLOC are locations where IN and OUT appear in the insn.
1836 CLASS is the register class required for the reload.
1838 If FOR_REAL is >= 0, it is the number of the reload,
1839 and in some cases when it can be discovered that OUT doesn't need
1840 to be computed, clear out rld[FOR_REAL].out.
1842 If FOR_REAL is -1, this should not be done, because this call
1843 is just to see if a register can be found, not to find and install it.
1845 EARLYCLOBBER is nonzero if OUT is an earlyclobber operand. This
1846 puts an additional constraint on being able to use IN for OUT since
1847 IN must not appear elsewhere in the insn (it is assumed that IN itself
1848 is safe from the earlyclobber). */
1850 static rtx
1851 find_dummy_reload (real_in, real_out, inloc, outloc,
1852 inmode, outmode, class, for_real, earlyclobber)
1853 rtx real_in, real_out;
1854 rtx *inloc, *outloc;
1855 enum machine_mode inmode, outmode;
1856 enum reg_class class;
1857 int for_real;
1858 int earlyclobber;
1860 rtx in = real_in;
1861 rtx out = real_out;
1862 int in_offset = 0;
1863 int out_offset = 0;
1864 rtx value = 0;
1866 /* If operands exceed a word, we can't use either of them
1867 unless they have the same size. */
1868 if (GET_MODE_SIZE (outmode) != GET_MODE_SIZE (inmode)
1869 && (GET_MODE_SIZE (outmode) > UNITS_PER_WORD
1870 || GET_MODE_SIZE (inmode) > UNITS_PER_WORD))
1871 return 0;
1873 /* Note that {in,out}_offset are needed only when 'in' or 'out'
1874 respectively refers to a hard register. */
1876 /* Find the inside of any subregs. */
1877 while (GET_CODE (out) == SUBREG)
1879 if (GET_CODE (SUBREG_REG (out)) == REG
1880 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER)
1881 out_offset += subreg_regno_offset (REGNO (SUBREG_REG (out)),
1882 GET_MODE (SUBREG_REG (out)),
1883 SUBREG_BYTE (out),
1884 GET_MODE (out));
1885 out = SUBREG_REG (out);
1887 while (GET_CODE (in) == SUBREG)
1889 if (GET_CODE (SUBREG_REG (in)) == REG
1890 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER)
1891 in_offset += subreg_regno_offset (REGNO (SUBREG_REG (in)),
1892 GET_MODE (SUBREG_REG (in)),
1893 SUBREG_BYTE (in),
1894 GET_MODE (in));
1895 in = SUBREG_REG (in);
1898 /* Narrow down the reg class, the same way push_reload will;
1899 otherwise we might find a dummy now, but push_reload won't. */
1900 class = PREFERRED_RELOAD_CLASS (in, class);
1902 /* See if OUT will do. */
1903 if (GET_CODE (out) == REG
1904 && REGNO (out) < FIRST_PSEUDO_REGISTER)
1906 unsigned int regno = REGNO (out) + out_offset;
1907 unsigned int nwords = HARD_REGNO_NREGS (regno, outmode);
1908 rtx saved_rtx;
1910 /* When we consider whether the insn uses OUT,
1911 ignore references within IN. They don't prevent us
1912 from copying IN into OUT, because those refs would
1913 move into the insn that reloads IN.
1915 However, we only ignore IN in its role as this reload.
1916 If the insn uses IN elsewhere and it contains OUT,
1917 that counts. We can't be sure it's the "same" operand
1918 so it might not go through this reload. */
1919 saved_rtx = *inloc;
1920 *inloc = const0_rtx;
1922 if (regno < FIRST_PSEUDO_REGISTER
1923 && HARD_REGNO_MODE_OK (regno, outmode)
1924 && ! refers_to_regno_for_reload_p (regno, regno + nwords,
1925 PATTERN (this_insn), outloc))
1927 unsigned int i;
1929 for (i = 0; i < nwords; i++)
1930 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1931 regno + i))
1932 break;
1934 if (i == nwords)
1936 if (GET_CODE (real_out) == REG)
1937 value = real_out;
1938 else
1939 value = gen_rtx_REG (outmode, regno);
1943 *inloc = saved_rtx;
1946 /* Consider using IN if OUT was not acceptable
1947 or if OUT dies in this insn (like the quotient in a divmod insn).
1948 We can't use IN unless it is dies in this insn,
1949 which means we must know accurately which hard regs are live.
1950 Also, the result can't go in IN if IN is used within OUT,
1951 or if OUT is an earlyclobber and IN appears elsewhere in the insn. */
1952 if (hard_regs_live_known
1953 && GET_CODE (in) == REG
1954 && REGNO (in) < FIRST_PSEUDO_REGISTER
1955 && (value == 0
1956 || find_reg_note (this_insn, REG_UNUSED, real_out))
1957 && find_reg_note (this_insn, REG_DEAD, real_in)
1958 && !fixed_regs[REGNO (in)]
1959 && HARD_REGNO_MODE_OK (REGNO (in),
1960 /* The only case where out and real_out might
1961 have different modes is where real_out
1962 is a subreg, and in that case, out
1963 has a real mode. */
1964 (GET_MODE (out) != VOIDmode
1965 ? GET_MODE (out) : outmode)))
1967 unsigned int regno = REGNO (in) + in_offset;
1968 unsigned int nwords = HARD_REGNO_NREGS (regno, inmode);
1970 if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, (rtx*) 0)
1971 && ! hard_reg_set_here_p (regno, regno + nwords,
1972 PATTERN (this_insn))
1973 && (! earlyclobber
1974 || ! refers_to_regno_for_reload_p (regno, regno + nwords,
1975 PATTERN (this_insn), inloc)))
1977 unsigned int i;
1979 for (i = 0; i < nwords; i++)
1980 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1981 regno + i))
1982 break;
1984 if (i == nwords)
1986 /* If we were going to use OUT as the reload reg
1987 and changed our mind, it means OUT is a dummy that
1988 dies here. So don't bother copying value to it. */
1989 if (for_real >= 0 && value == real_out)
1990 rld[for_real].out = 0;
1991 if (GET_CODE (real_in) == REG)
1992 value = real_in;
1993 else
1994 value = gen_rtx_REG (inmode, regno);
1999 return value;
2002 /* This page contains subroutines used mainly for determining
2003 whether the IN or an OUT of a reload can serve as the
2004 reload register. */
2006 /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
2009 earlyclobber_operand_p (x)
2010 rtx x;
2012 int i;
2014 for (i = 0; i < n_earlyclobbers; i++)
2015 if (reload_earlyclobbers[i] == x)
2016 return 1;
2018 return 0;
2021 /* Return 1 if expression X alters a hard reg in the range
2022 from BEG_REGNO (inclusive) to END_REGNO (exclusive),
2023 either explicitly or in the guise of a pseudo-reg allocated to REGNO.
2024 X should be the body of an instruction. */
2026 static int
2027 hard_reg_set_here_p (beg_regno, end_regno, x)
2028 unsigned int beg_regno, end_regno;
2029 rtx x;
2031 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
2033 rtx op0 = SET_DEST (x);
2035 while (GET_CODE (op0) == SUBREG)
2036 op0 = SUBREG_REG (op0);
2037 if (GET_CODE (op0) == REG)
2039 unsigned int r = REGNO (op0);
2041 /* See if this reg overlaps range under consideration. */
2042 if (r < end_regno
2043 && r + HARD_REGNO_NREGS (r, GET_MODE (op0)) > beg_regno)
2044 return 1;
2047 else if (GET_CODE (x) == PARALLEL)
2049 int i = XVECLEN (x, 0) - 1;
2051 for (; i >= 0; i--)
2052 if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i)))
2053 return 1;
2056 return 0;
2059 /* Return 1 if ADDR is a valid memory address for mode MODE,
2060 and check that each pseudo reg has the proper kind of
2061 hard reg. */
2064 strict_memory_address_p (mode, addr)
2065 enum machine_mode mode ATTRIBUTE_UNUSED;
2066 rtx addr;
2068 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
2069 return 0;
2071 win:
2072 return 1;
2075 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
2076 if they are the same hard reg, and has special hacks for
2077 autoincrement and autodecrement.
2078 This is specifically intended for find_reloads to use
2079 in determining whether two operands match.
2080 X is the operand whose number is the lower of the two.
2082 The value is 2 if Y contains a pre-increment that matches
2083 a non-incrementing address in X. */
2085 /* ??? To be completely correct, we should arrange to pass
2086 for X the output operand and for Y the input operand.
2087 For now, we assume that the output operand has the lower number
2088 because that is natural in (SET output (... input ...)). */
2091 operands_match_p (x, y)
2092 rtx x, y;
2094 int i;
2095 RTX_CODE code = GET_CODE (x);
2096 const char *fmt;
2097 int success_2;
2099 if (x == y)
2100 return 1;
2101 if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
2102 && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
2103 && GET_CODE (SUBREG_REG (y)) == REG)))
2105 int j;
2107 if (code == SUBREG)
2109 i = REGNO (SUBREG_REG (x));
2110 if (i >= FIRST_PSEUDO_REGISTER)
2111 goto slow;
2112 i += subreg_regno_offset (REGNO (SUBREG_REG (x)),
2113 GET_MODE (SUBREG_REG (x)),
2114 SUBREG_BYTE (x),
2115 GET_MODE (x));
2117 else
2118 i = REGNO (x);
2120 if (GET_CODE (y) == SUBREG)
2122 j = REGNO (SUBREG_REG (y));
2123 if (j >= FIRST_PSEUDO_REGISTER)
2124 goto slow;
2125 j += subreg_regno_offset (REGNO (SUBREG_REG (y)),
2126 GET_MODE (SUBREG_REG (y)),
2127 SUBREG_BYTE (y),
2128 GET_MODE (y));
2130 else
2131 j = REGNO (y);
2133 /* On a WORDS_BIG_ENDIAN machine, point to the last register of a
2134 multiple hard register group, so that for example (reg:DI 0) and
2135 (reg:SI 1) will be considered the same register. */
2136 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
2137 && i < FIRST_PSEUDO_REGISTER)
2138 i += (GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD) - 1;
2139 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD
2140 && j < FIRST_PSEUDO_REGISTER)
2141 j += (GET_MODE_SIZE (GET_MODE (y)) / UNITS_PER_WORD) - 1;
2143 return i == j;
2145 /* If two operands must match, because they are really a single
2146 operand of an assembler insn, then two postincrements are invalid
2147 because the assembler insn would increment only once.
2148 On the other hand, a postincrement matches ordinary indexing
2149 if the postincrement is the output operand. */
2150 if (code == POST_DEC || code == POST_INC || code == POST_MODIFY)
2151 return operands_match_p (XEXP (x, 0), y);
2152 /* Two preincrements are invalid
2153 because the assembler insn would increment only once.
2154 On the other hand, a preincrement matches ordinary indexing
2155 if the preincrement is the input operand.
2156 In this case, return 2, since some callers need to do special
2157 things when this happens. */
2158 if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC
2159 || GET_CODE (y) == PRE_MODIFY)
2160 return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
2162 slow:
2164 /* Now we have disposed of all the cases
2165 in which different rtx codes can match. */
2166 if (code != GET_CODE (y))
2167 return 0;
2168 if (code == LABEL_REF)
2169 return XEXP (x, 0) == XEXP (y, 0);
2170 if (code == SYMBOL_REF)
2171 return XSTR (x, 0) == XSTR (y, 0);
2173 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
2175 if (GET_MODE (x) != GET_MODE (y))
2176 return 0;
2178 /* Compare the elements. If any pair of corresponding elements
2179 fail to match, return 0 for the whole things. */
2181 success_2 = 0;
2182 fmt = GET_RTX_FORMAT (code);
2183 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2185 int val, j;
2186 switch (fmt[i])
2188 case 'w':
2189 if (XWINT (x, i) != XWINT (y, i))
2190 return 0;
2191 break;
2193 case 'i':
2194 if (XINT (x, i) != XINT (y, i))
2195 return 0;
2196 break;
2198 case 'e':
2199 val = operands_match_p (XEXP (x, i), XEXP (y, i));
2200 if (val == 0)
2201 return 0;
2202 /* If any subexpression returns 2,
2203 we should return 2 if we are successful. */
2204 if (val == 2)
2205 success_2 = 1;
2206 break;
2208 case '0':
2209 break;
2211 case 'E':
2212 if (XVECLEN (x, i) != XVECLEN (y, i))
2213 return 0;
2214 for (j = XVECLEN (x, i) - 1; j >= 0; --j)
2216 val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j));
2217 if (val == 0)
2218 return 0;
2219 if (val == 2)
2220 success_2 = 1;
2222 break;
2224 /* It is believed that rtx's at this level will never
2225 contain anything but integers and other rtx's,
2226 except for within LABEL_REFs and SYMBOL_REFs. */
2227 default:
2228 abort ();
2231 return 1 + success_2;
2234 /* Describe the range of registers or memory referenced by X.
2235 If X is a register, set REG_FLAG and put the first register
2236 number into START and the last plus one into END.
2237 If X is a memory reference, put a base address into BASE
2238 and a range of integer offsets into START and END.
2239 If X is pushing on the stack, we can assume it causes no trouble,
2240 so we set the SAFE field. */
2242 static struct decomposition
2243 decompose (x)
2244 rtx x;
2246 struct decomposition val;
2247 int all_const = 0;
2249 val.reg_flag = 0;
2250 val.safe = 0;
2251 val.base = 0;
2252 if (GET_CODE (x) == MEM)
2254 rtx base = NULL_RTX, offset = 0;
2255 rtx addr = XEXP (x, 0);
2257 if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
2258 || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
2260 val.base = XEXP (addr, 0);
2261 val.start = -GET_MODE_SIZE (GET_MODE (x));
2262 val.end = GET_MODE_SIZE (GET_MODE (x));
2263 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2264 return val;
2267 if (GET_CODE (addr) == PRE_MODIFY || GET_CODE (addr) == POST_MODIFY)
2269 if (GET_CODE (XEXP (addr, 1)) == PLUS
2270 && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
2271 && CONSTANT_P (XEXP (XEXP (addr, 1), 1)))
2273 val.base = XEXP (addr, 0);
2274 val.start = -INTVAL (XEXP (XEXP (addr, 1), 1));
2275 val.end = INTVAL (XEXP (XEXP (addr, 1), 1));
2276 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2277 return val;
2281 if (GET_CODE (addr) == CONST)
2283 addr = XEXP (addr, 0);
2284 all_const = 1;
2286 if (GET_CODE (addr) == PLUS)
2288 if (CONSTANT_P (XEXP (addr, 0)))
2290 base = XEXP (addr, 1);
2291 offset = XEXP (addr, 0);
2293 else if (CONSTANT_P (XEXP (addr, 1)))
2295 base = XEXP (addr, 0);
2296 offset = XEXP (addr, 1);
2300 if (offset == 0)
2302 base = addr;
2303 offset = const0_rtx;
2305 if (GET_CODE (offset) == CONST)
2306 offset = XEXP (offset, 0);
2307 if (GET_CODE (offset) == PLUS)
2309 if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
2311 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 1));
2312 offset = XEXP (offset, 0);
2314 else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
2316 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 0));
2317 offset = XEXP (offset, 1);
2319 else
2321 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2322 offset = const0_rtx;
2325 else if (GET_CODE (offset) != CONST_INT)
2327 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2328 offset = const0_rtx;
2331 if (all_const && GET_CODE (base) == PLUS)
2332 base = gen_rtx_CONST (GET_MODE (base), base);
2334 if (GET_CODE (offset) != CONST_INT)
2335 abort ();
2337 val.start = INTVAL (offset);
2338 val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
2339 val.base = base;
2340 return val;
2342 else if (GET_CODE (x) == REG)
2344 val.reg_flag = 1;
2345 val.start = true_regnum (x);
2346 if (val.start < 0)
2348 /* A pseudo with no hard reg. */
2349 val.start = REGNO (x);
2350 val.end = val.start + 1;
2352 else
2353 /* A hard reg. */
2354 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2356 else if (GET_CODE (x) == SUBREG)
2358 if (GET_CODE (SUBREG_REG (x)) != REG)
2359 /* This could be more precise, but it's good enough. */
2360 return decompose (SUBREG_REG (x));
2361 val.reg_flag = 1;
2362 val.start = true_regnum (x);
2363 if (val.start < 0)
2364 return decompose (SUBREG_REG (x));
2365 else
2366 /* A hard reg. */
2367 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2369 else if (CONSTANT_P (x)
2370 /* This hasn't been assigned yet, so it can't conflict yet. */
2371 || GET_CODE (x) == SCRATCH)
2372 val.safe = 1;
2373 else
2374 abort ();
2375 return val;
2378 /* Return 1 if altering Y will not modify the value of X.
2379 Y is also described by YDATA, which should be decompose (Y). */
2381 static int
2382 immune_p (x, y, ydata)
2383 rtx x, y;
2384 struct decomposition ydata;
2386 struct decomposition xdata;
2388 if (ydata.reg_flag)
2389 return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, (rtx*) 0);
2390 if (ydata.safe)
2391 return 1;
2393 if (GET_CODE (y) != MEM)
2394 abort ();
2395 /* If Y is memory and X is not, Y can't affect X. */
2396 if (GET_CODE (x) != MEM)
2397 return 1;
2399 xdata = decompose (x);
2401 if (! rtx_equal_p (xdata.base, ydata.base))
2403 /* If bases are distinct symbolic constants, there is no overlap. */
2404 if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
2405 return 1;
2406 /* Constants and stack slots never overlap. */
2407 if (CONSTANT_P (xdata.base)
2408 && (ydata.base == frame_pointer_rtx
2409 || ydata.base == hard_frame_pointer_rtx
2410 || ydata.base == stack_pointer_rtx))
2411 return 1;
2412 if (CONSTANT_P (ydata.base)
2413 && (xdata.base == frame_pointer_rtx
2414 || xdata.base == hard_frame_pointer_rtx
2415 || xdata.base == stack_pointer_rtx))
2416 return 1;
2417 /* If either base is variable, we don't know anything. */
2418 return 0;
2421 return (xdata.start >= ydata.end || ydata.start >= xdata.end);
2424 /* Similar, but calls decompose. */
2427 safe_from_earlyclobber (op, clobber)
2428 rtx op, clobber;
2430 struct decomposition early_data;
2432 early_data = decompose (clobber);
2433 return immune_p (op, clobber, early_data);
2436 /* Main entry point of this file: search the body of INSN
2437 for values that need reloading and record them with push_reload.
2438 REPLACE nonzero means record also where the values occur
2439 so that subst_reloads can be used.
2441 IND_LEVELS says how many levels of indirection are supported by this
2442 machine; a value of zero means that a memory reference is not a valid
2443 memory address.
2445 LIVE_KNOWN says we have valid information about which hard
2446 regs are live at each point in the program; this is true when
2447 we are called from global_alloc but false when stupid register
2448 allocation has been done.
2450 RELOAD_REG_P if nonzero is a vector indexed by hard reg number
2451 which is nonnegative if the reg has been commandeered for reloading into.
2452 It is copied into STATIC_RELOAD_REG_P and referenced from there
2453 by various subroutines.
2455 Return TRUE if some operands need to be changed, because of swapping
2456 commutative operands, reg_equiv_address substitution, or whatever. */
2459 find_reloads (insn, replace, ind_levels, live_known, reload_reg_p)
2460 rtx insn;
2461 int replace, ind_levels;
2462 int live_known;
2463 short *reload_reg_p;
2465 int insn_code_number;
2466 int i, j;
2467 int noperands;
2468 /* These start out as the constraints for the insn
2469 and they are chewed up as we consider alternatives. */
2470 char *constraints[MAX_RECOG_OPERANDS];
2471 /* These are the preferred classes for an operand, or NO_REGS if it isn't
2472 a register. */
2473 enum reg_class preferred_class[MAX_RECOG_OPERANDS];
2474 char pref_or_nothing[MAX_RECOG_OPERANDS];
2475 /* Nonzero for a MEM operand whose entire address needs a reload. */
2476 int address_reloaded[MAX_RECOG_OPERANDS];
2477 /* Value of enum reload_type to use for operand. */
2478 enum reload_type operand_type[MAX_RECOG_OPERANDS];
2479 /* Value of enum reload_type to use within address of operand. */
2480 enum reload_type address_type[MAX_RECOG_OPERANDS];
2481 /* Save the usage of each operand. */
2482 enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS];
2483 int no_input_reloads = 0, no_output_reloads = 0;
2484 int n_alternatives;
2485 int this_alternative[MAX_RECOG_OPERANDS];
2486 char this_alternative_match_win[MAX_RECOG_OPERANDS];
2487 char this_alternative_win[MAX_RECOG_OPERANDS];
2488 char this_alternative_offmemok[MAX_RECOG_OPERANDS];
2489 char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2490 int this_alternative_matches[MAX_RECOG_OPERANDS];
2491 int swapped;
2492 int goal_alternative[MAX_RECOG_OPERANDS];
2493 int this_alternative_number;
2494 int goal_alternative_number = 0;
2495 int operand_reloadnum[MAX_RECOG_OPERANDS];
2496 int goal_alternative_matches[MAX_RECOG_OPERANDS];
2497 int goal_alternative_matched[MAX_RECOG_OPERANDS];
2498 char goal_alternative_match_win[MAX_RECOG_OPERANDS];
2499 char goal_alternative_win[MAX_RECOG_OPERANDS];
2500 char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
2501 char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2502 int goal_alternative_swapped;
2503 int best;
2504 int commutative;
2505 char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
2506 rtx substed_operand[MAX_RECOG_OPERANDS];
2507 rtx body = PATTERN (insn);
2508 rtx set = single_set (insn);
2509 int goal_earlyclobber = 0, this_earlyclobber;
2510 enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
2511 int retval = 0;
2513 this_insn = insn;
2514 n_reloads = 0;
2515 n_replacements = 0;
2516 n_earlyclobbers = 0;
2517 replace_reloads = replace;
2518 hard_regs_live_known = live_known;
2519 static_reload_reg_p = reload_reg_p;
2521 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
2522 neither are insns that SET cc0. Insns that use CC0 are not allowed
2523 to have any input reloads. */
2524 if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == CALL_INSN)
2525 no_output_reloads = 1;
2527 #ifdef HAVE_cc0
2528 if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
2529 no_input_reloads = 1;
2530 if (reg_set_p (cc0_rtx, PATTERN (insn)))
2531 no_output_reloads = 1;
2532 #endif
2534 #ifdef SECONDARY_MEMORY_NEEDED
2535 /* The eliminated forms of any secondary memory locations are per-insn, so
2536 clear them out here. */
2538 memset ((char *) secondary_memlocs_elim, 0, sizeof secondary_memlocs_elim);
2539 #endif
2541 /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2542 is cheap to move between them. If it is not, there may not be an insn
2543 to do the copy, so we may need a reload. */
2544 if (GET_CODE (body) == SET
2545 && GET_CODE (SET_DEST (body)) == REG
2546 && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2547 && GET_CODE (SET_SRC (body)) == REG
2548 && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2549 && REGISTER_MOVE_COST (GET_MODE (SET_SRC (body)),
2550 REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2551 REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2552 return 0;
2554 extract_insn (insn);
2556 noperands = reload_n_operands = recog_data.n_operands;
2557 n_alternatives = recog_data.n_alternatives;
2559 /* Just return "no reloads" if insn has no operands with constraints. */
2560 if (noperands == 0 || n_alternatives == 0)
2561 return 0;
2563 insn_code_number = INSN_CODE (insn);
2564 this_insn_is_asm = insn_code_number < 0;
2566 memcpy (operand_mode, recog_data.operand_mode,
2567 noperands * sizeof (enum machine_mode));
2568 memcpy (constraints, recog_data.constraints, noperands * sizeof (char *));
2570 commutative = -1;
2572 /* If we will need to know, later, whether some pair of operands
2573 are the same, we must compare them now and save the result.
2574 Reloading the base and index registers will clobber them
2575 and afterward they will fail to match. */
2577 for (i = 0; i < noperands; i++)
2579 char *p;
2580 int c;
2582 substed_operand[i] = recog_data.operand[i];
2583 p = constraints[i];
2585 modified[i] = RELOAD_READ;
2587 /* Scan this operand's constraint to see if it is an output operand,
2588 an in-out operand, is commutative, or should match another. */
2590 while ((c = *p++))
2592 if (c == '=')
2593 modified[i] = RELOAD_WRITE;
2594 else if (c == '+')
2595 modified[i] = RELOAD_READ_WRITE;
2596 else if (c == '%')
2598 /* The last operand should not be marked commutative. */
2599 if (i == noperands - 1)
2600 abort ();
2602 commutative = i;
2604 else if (ISDIGIT (c))
2606 c = strtoul (p - 1, &p, 10);
2608 operands_match[c][i]
2609 = operands_match_p (recog_data.operand[c],
2610 recog_data.operand[i]);
2612 /* An operand may not match itself. */
2613 if (c == i)
2614 abort ();
2616 /* If C can be commuted with C+1, and C might need to match I,
2617 then C+1 might also need to match I. */
2618 if (commutative >= 0)
2620 if (c == commutative || c == commutative + 1)
2622 int other = c + (c == commutative ? 1 : -1);
2623 operands_match[other][i]
2624 = operands_match_p (recog_data.operand[other],
2625 recog_data.operand[i]);
2627 if (i == commutative || i == commutative + 1)
2629 int other = i + (i == commutative ? 1 : -1);
2630 operands_match[c][other]
2631 = operands_match_p (recog_data.operand[c],
2632 recog_data.operand[other]);
2634 /* Note that C is supposed to be less than I.
2635 No need to consider altering both C and I because in
2636 that case we would alter one into the other. */
2642 /* Examine each operand that is a memory reference or memory address
2643 and reload parts of the addresses into index registers.
2644 Also here any references to pseudo regs that didn't get hard regs
2645 but are equivalent to constants get replaced in the insn itself
2646 with those constants. Nobody will ever see them again.
2648 Finally, set up the preferred classes of each operand. */
2650 for (i = 0; i < noperands; i++)
2652 RTX_CODE code = GET_CODE (recog_data.operand[i]);
2654 address_reloaded[i] = 0;
2655 operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT
2656 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT
2657 : RELOAD_OTHER);
2658 address_type[i]
2659 = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS
2660 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS
2661 : RELOAD_OTHER);
2663 if (*constraints[i] == 0)
2664 /* Ignore things like match_operator operands. */
2666 else if (constraints[i][0] == 'p'
2667 || EXTRA_ADDRESS_CONSTRAINT (constraints[i][0]))
2669 find_reloads_address (recog_data.operand_mode[i], (rtx*) 0,
2670 recog_data.operand[i],
2671 recog_data.operand_loc[i],
2672 i, operand_type[i], ind_levels, insn);
2674 /* If we now have a simple operand where we used to have a
2675 PLUS or MULT, re-recognize and try again. */
2676 if ((GET_RTX_CLASS (GET_CODE (*recog_data.operand_loc[i])) == 'o'
2677 || GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
2678 && (GET_CODE (recog_data.operand[i]) == MULT
2679 || GET_CODE (recog_data.operand[i]) == PLUS))
2681 INSN_CODE (insn) = -1;
2682 retval = find_reloads (insn, replace, ind_levels, live_known,
2683 reload_reg_p);
2684 return retval;
2687 recog_data.operand[i] = *recog_data.operand_loc[i];
2688 substed_operand[i] = recog_data.operand[i];
2690 else if (code == MEM)
2692 address_reloaded[i]
2693 = find_reloads_address (GET_MODE (recog_data.operand[i]),
2694 recog_data.operand_loc[i],
2695 XEXP (recog_data.operand[i], 0),
2696 &XEXP (recog_data.operand[i], 0),
2697 i, address_type[i], ind_levels, insn);
2698 recog_data.operand[i] = *recog_data.operand_loc[i];
2699 substed_operand[i] = recog_data.operand[i];
2701 else if (code == SUBREG)
2703 rtx reg = SUBREG_REG (recog_data.operand[i]);
2704 rtx op
2705 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2706 ind_levels,
2707 set != 0
2708 && &SET_DEST (set) == recog_data.operand_loc[i],
2709 insn,
2710 &address_reloaded[i]);
2712 /* If we made a MEM to load (a part of) the stackslot of a pseudo
2713 that didn't get a hard register, emit a USE with a REG_EQUAL
2714 note in front so that we might inherit a previous, possibly
2715 wider reload. */
2717 if (replace
2718 && GET_CODE (op) == MEM
2719 && GET_CODE (reg) == REG
2720 && (GET_MODE_SIZE (GET_MODE (reg))
2721 >= GET_MODE_SIZE (GET_MODE (op))))
2722 set_unique_reg_note (emit_insn_before (gen_rtx_USE (VOIDmode, reg),
2723 insn),
2724 REG_EQUAL, reg_equiv_memory_loc[REGNO (reg)]);
2726 substed_operand[i] = recog_data.operand[i] = op;
2728 else if (code == PLUS || GET_RTX_CLASS (code) == '1')
2729 /* We can get a PLUS as an "operand" as a result of register
2730 elimination. See eliminate_regs and gen_reload. We handle
2731 a unary operator by reloading the operand. */
2732 substed_operand[i] = recog_data.operand[i]
2733 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2734 ind_levels, 0, insn,
2735 &address_reloaded[i]);
2736 else if (code == REG)
2738 /* This is equivalent to calling find_reloads_toplev.
2739 The code is duplicated for speed.
2740 When we find a pseudo always equivalent to a constant,
2741 we replace it by the constant. We must be sure, however,
2742 that we don't try to replace it in the insn in which it
2743 is being set. */
2744 int regno = REGNO (recog_data.operand[i]);
2745 if (reg_equiv_constant[regno] != 0
2746 && (set == 0 || &SET_DEST (set) != recog_data.operand_loc[i]))
2748 /* Record the existing mode so that the check if constants are
2749 allowed will work when operand_mode isn't specified. */
2751 if (operand_mode[i] == VOIDmode)
2752 operand_mode[i] = GET_MODE (recog_data.operand[i]);
2754 substed_operand[i] = recog_data.operand[i]
2755 = reg_equiv_constant[regno];
2757 if (reg_equiv_memory_loc[regno] != 0
2758 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
2759 /* We need not give a valid is_set_dest argument since the case
2760 of a constant equivalence was checked above. */
2761 substed_operand[i] = recog_data.operand[i]
2762 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2763 ind_levels, 0, insn,
2764 &address_reloaded[i]);
2766 /* If the operand is still a register (we didn't replace it with an
2767 equivalent), get the preferred class to reload it into. */
2768 code = GET_CODE (recog_data.operand[i]);
2769 preferred_class[i]
2770 = ((code == REG && REGNO (recog_data.operand[i])
2771 >= FIRST_PSEUDO_REGISTER)
2772 ? reg_preferred_class (REGNO (recog_data.operand[i]))
2773 : NO_REGS);
2774 pref_or_nothing[i]
2775 = (code == REG
2776 && REGNO (recog_data.operand[i]) >= FIRST_PSEUDO_REGISTER
2777 && reg_alternate_class (REGNO (recog_data.operand[i])) == NO_REGS);
2780 /* If this is simply a copy from operand 1 to operand 0, merge the
2781 preferred classes for the operands. */
2782 if (set != 0 && noperands >= 2 && recog_data.operand[0] == SET_DEST (set)
2783 && recog_data.operand[1] == SET_SRC (set))
2785 preferred_class[0] = preferred_class[1]
2786 = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2787 pref_or_nothing[0] |= pref_or_nothing[1];
2788 pref_or_nothing[1] |= pref_or_nothing[0];
2791 /* Now see what we need for pseudo-regs that didn't get hard regs
2792 or got the wrong kind of hard reg. For this, we must consider
2793 all the operands together against the register constraints. */
2795 best = MAX_RECOG_OPERANDS * 2 + 600;
2797 swapped = 0;
2798 goal_alternative_swapped = 0;
2799 try_swapped:
2801 /* The constraints are made of several alternatives.
2802 Each operand's constraint looks like foo,bar,... with commas
2803 separating the alternatives. The first alternatives for all
2804 operands go together, the second alternatives go together, etc.
2806 First loop over alternatives. */
2808 for (this_alternative_number = 0;
2809 this_alternative_number < n_alternatives;
2810 this_alternative_number++)
2812 /* Loop over operands for one constraint alternative. */
2813 /* LOSERS counts those that don't fit this alternative
2814 and would require loading. */
2815 int losers = 0;
2816 /* BAD is set to 1 if it some operand can't fit this alternative
2817 even after reloading. */
2818 int bad = 0;
2819 /* REJECT is a count of how undesirable this alternative says it is
2820 if any reloading is required. If the alternative matches exactly
2821 then REJECT is ignored, but otherwise it gets this much
2822 counted against it in addition to the reloading needed. Each
2823 ? counts three times here since we want the disparaging caused by
2824 a bad register class to only count 1/3 as much. */
2825 int reject = 0;
2827 this_earlyclobber = 0;
2829 for (i = 0; i < noperands; i++)
2831 char *p = constraints[i];
2832 int win = 0;
2833 int did_match = 0;
2834 /* 0 => this operand can be reloaded somehow for this alternative. */
2835 int badop = 1;
2836 /* 0 => this operand can be reloaded if the alternative allows regs. */
2837 int winreg = 0;
2838 int c;
2839 rtx operand = recog_data.operand[i];
2840 int offset = 0;
2841 /* Nonzero means this is a MEM that must be reloaded into a reg
2842 regardless of what the constraint says. */
2843 int force_reload = 0;
2844 int offmemok = 0;
2845 /* Nonzero if a constant forced into memory would be OK for this
2846 operand. */
2847 int constmemok = 0;
2848 int earlyclobber = 0;
2850 /* If the predicate accepts a unary operator, it means that
2851 we need to reload the operand, but do not do this for
2852 match_operator and friends. */
2853 if (GET_RTX_CLASS (GET_CODE (operand)) == '1' && *p != 0)
2854 operand = XEXP (operand, 0);
2856 /* If the operand is a SUBREG, extract
2857 the REG or MEM (or maybe even a constant) within.
2858 (Constants can occur as a result of reg_equiv_constant.) */
2860 while (GET_CODE (operand) == SUBREG)
2862 /* Offset only matters when operand is a REG and
2863 it is a hard reg. This is because it is passed
2864 to reg_fits_class_p if it is a REG and all pseudos
2865 return 0 from that function. */
2866 if (GET_CODE (SUBREG_REG (operand)) == REG
2867 && REGNO (SUBREG_REG (operand)) < FIRST_PSEUDO_REGISTER)
2869 offset += subreg_regno_offset (REGNO (SUBREG_REG (operand)),
2870 GET_MODE (SUBREG_REG (operand)),
2871 SUBREG_BYTE (operand),
2872 GET_MODE (operand));
2874 operand = SUBREG_REG (operand);
2875 /* Force reload if this is a constant or PLUS or if there may
2876 be a problem accessing OPERAND in the outer mode. */
2877 if (CONSTANT_P (operand)
2878 || GET_CODE (operand) == PLUS
2879 /* We must force a reload of paradoxical SUBREGs
2880 of a MEM because the alignment of the inner value
2881 may not be enough to do the outer reference. On
2882 big-endian machines, it may also reference outside
2883 the object.
2885 On machines that extend byte operations and we have a
2886 SUBREG where both the inner and outer modes are no wider
2887 than a word and the inner mode is narrower, is integral,
2888 and gets extended when loaded from memory, combine.c has
2889 made assumptions about the behavior of the machine in such
2890 register access. If the data is, in fact, in memory we
2891 must always load using the size assumed to be in the
2892 register and let the insn do the different-sized
2893 accesses.
2895 This is doubly true if WORD_REGISTER_OPERATIONS. In
2896 this case eliminate_regs has left non-paradoxical
2897 subregs for push_reloads to see. Make sure it does
2898 by forcing the reload.
2900 ??? When is it right at this stage to have a subreg
2901 of a mem that is _not_ to be handled specialy? IMO
2902 those should have been reduced to just a mem. */
2903 || ((GET_CODE (operand) == MEM
2904 || (GET_CODE (operand)== REG
2905 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
2906 #ifndef WORD_REGISTER_OPERATIONS
2907 && (((GET_MODE_BITSIZE (GET_MODE (operand))
2908 < BIGGEST_ALIGNMENT)
2909 && (GET_MODE_SIZE (operand_mode[i])
2910 > GET_MODE_SIZE (GET_MODE (operand))))
2911 || (GET_CODE (operand) == MEM && BYTES_BIG_ENDIAN)
2912 #ifdef LOAD_EXTEND_OP
2913 || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2914 && (GET_MODE_SIZE (GET_MODE (operand))
2915 <= UNITS_PER_WORD)
2916 && (GET_MODE_SIZE (operand_mode[i])
2917 > GET_MODE_SIZE (GET_MODE (operand)))
2918 && INTEGRAL_MODE_P (GET_MODE (operand))
2919 && LOAD_EXTEND_OP (GET_MODE (operand)) != NIL)
2920 #endif
2922 #endif
2924 /* This following hunk of code should no longer be
2925 needed at all with SUBREG_BYTE. If you need this
2926 code back, please explain to me why so I can
2927 fix the real problem. -DaveM */
2928 #if 0
2929 /* Subreg of a hard reg which can't handle the subreg's mode
2930 or which would handle that mode in the wrong number of
2931 registers for subregging to work. */
2932 || (GET_CODE (operand) == REG
2933 && REGNO (operand) < FIRST_PSEUDO_REGISTER
2934 && ((GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2935 && (GET_MODE_SIZE (GET_MODE (operand))
2936 > UNITS_PER_WORD)
2937 && ((GET_MODE_SIZE (GET_MODE (operand))
2938 / UNITS_PER_WORD)
2939 != HARD_REGNO_NREGS (REGNO (operand),
2940 GET_MODE (operand))))
2941 || ! HARD_REGNO_MODE_OK (REGNO (operand) + offset,
2942 operand_mode[i])))
2943 #endif
2945 force_reload = 1;
2948 this_alternative[i] = (int) NO_REGS;
2949 this_alternative_win[i] = 0;
2950 this_alternative_match_win[i] = 0;
2951 this_alternative_offmemok[i] = 0;
2952 this_alternative_earlyclobber[i] = 0;
2953 this_alternative_matches[i] = -1;
2955 /* An empty constraint or empty alternative
2956 allows anything which matched the pattern. */
2957 if (*p == 0 || *p == ',')
2958 win = 1, badop = 0;
2960 /* Scan this alternative's specs for this operand;
2961 set WIN if the operand fits any letter in this alternative.
2962 Otherwise, clear BADOP if this operand could
2963 fit some letter after reloads,
2964 or set WINREG if this operand could fit after reloads
2965 provided the constraint allows some registers. */
2967 while (*p && (c = *p++) != ',')
2968 switch (c)
2970 case '=': case '+': case '*':
2971 break;
2973 case '%':
2974 /* The last operand should not be marked commutative. */
2975 if (i != noperands - 1)
2976 commutative = i;
2977 break;
2979 case '?':
2980 reject += 6;
2981 break;
2983 case '!':
2984 reject = 600;
2985 break;
2987 case '#':
2988 /* Ignore rest of this alternative as far as
2989 reloading is concerned. */
2990 while (*p && *p != ',')
2991 p++;
2992 break;
2994 case '0': case '1': case '2': case '3': case '4':
2995 case '5': case '6': case '7': case '8': case '9':
2996 c = strtoul (p - 1, &p, 10);
2998 this_alternative_matches[i] = c;
2999 /* We are supposed to match a previous operand.
3000 If we do, we win if that one did.
3001 If we do not, count both of the operands as losers.
3002 (This is too conservative, since most of the time
3003 only a single reload insn will be needed to make
3004 the two operands win. As a result, this alternative
3005 may be rejected when it is actually desirable.) */
3006 if ((swapped && (c != commutative || i != commutative + 1))
3007 /* If we are matching as if two operands were swapped,
3008 also pretend that operands_match had been computed
3009 with swapped.
3010 But if I is the second of those and C is the first,
3011 don't exchange them, because operands_match is valid
3012 only on one side of its diagonal. */
3013 ? (operands_match
3014 [(c == commutative || c == commutative + 1)
3015 ? 2 * commutative + 1 - c : c]
3016 [(i == commutative || i == commutative + 1)
3017 ? 2 * commutative + 1 - i : i])
3018 : operands_match[c][i])
3020 /* If we are matching a non-offsettable address where an
3021 offsettable address was expected, then we must reject
3022 this combination, because we can't reload it. */
3023 if (this_alternative_offmemok[c]
3024 && GET_CODE (recog_data.operand[c]) == MEM
3025 && this_alternative[c] == (int) NO_REGS
3026 && ! this_alternative_win[c])
3027 bad = 1;
3029 did_match = this_alternative_win[c];
3031 else
3033 /* Operands don't match. */
3034 rtx value;
3035 /* Retroactively mark the operand we had to match
3036 as a loser, if it wasn't already. */
3037 if (this_alternative_win[c])
3038 losers++;
3039 this_alternative_win[c] = 0;
3040 if (this_alternative[c] == (int) NO_REGS)
3041 bad = 1;
3042 /* But count the pair only once in the total badness of
3043 this alternative, if the pair can be a dummy reload. */
3044 value
3045 = find_dummy_reload (recog_data.operand[i],
3046 recog_data.operand[c],
3047 recog_data.operand_loc[i],
3048 recog_data.operand_loc[c],
3049 operand_mode[i], operand_mode[c],
3050 this_alternative[c], -1,
3051 this_alternative_earlyclobber[c]);
3053 if (value != 0)
3054 losers--;
3056 /* This can be fixed with reloads if the operand
3057 we are supposed to match can be fixed with reloads. */
3058 badop = 0;
3059 this_alternative[i] = this_alternative[c];
3061 /* If we have to reload this operand and some previous
3062 operand also had to match the same thing as this
3063 operand, we don't know how to do that. So reject this
3064 alternative. */
3065 if (! did_match || force_reload)
3066 for (j = 0; j < i; j++)
3067 if (this_alternative_matches[j]
3068 == this_alternative_matches[i])
3069 badop = 1;
3070 break;
3072 case 'p':
3073 /* All necessary reloads for an address_operand
3074 were handled in find_reloads_address. */
3075 this_alternative[i] = (int) MODE_BASE_REG_CLASS (VOIDmode);
3076 win = 1;
3077 badop = 0;
3078 break;
3080 case 'm':
3081 if (force_reload)
3082 break;
3083 if (GET_CODE (operand) == MEM
3084 || (GET_CODE (operand) == REG
3085 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3086 && reg_renumber[REGNO (operand)] < 0))
3087 win = 1;
3088 if (CONSTANT_P (operand)
3089 /* force_const_mem does not accept HIGH. */
3090 && GET_CODE (operand) != HIGH)
3091 badop = 0;
3092 constmemok = 1;
3093 break;
3095 case '<':
3096 if (GET_CODE (operand) == MEM
3097 && ! address_reloaded[i]
3098 && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
3099 || GET_CODE (XEXP (operand, 0)) == POST_DEC))
3100 win = 1;
3101 break;
3103 case '>':
3104 if (GET_CODE (operand) == MEM
3105 && ! address_reloaded[i]
3106 && (GET_CODE (XEXP (operand, 0)) == PRE_INC
3107 || GET_CODE (XEXP (operand, 0)) == POST_INC))
3108 win = 1;
3109 break;
3111 /* Memory operand whose address is not offsettable. */
3112 case 'V':
3113 if (force_reload)
3114 break;
3115 if (GET_CODE (operand) == MEM
3116 && ! (ind_levels ? offsettable_memref_p (operand)
3117 : offsettable_nonstrict_memref_p (operand))
3118 /* Certain mem addresses will become offsettable
3119 after they themselves are reloaded. This is important;
3120 we don't want our own handling of unoffsettables
3121 to override the handling of reg_equiv_address. */
3122 && !(GET_CODE (XEXP (operand, 0)) == REG
3123 && (ind_levels == 0
3124 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0)))
3125 win = 1;
3126 break;
3128 /* Memory operand whose address is offsettable. */
3129 case 'o':
3130 if (force_reload)
3131 break;
3132 if ((GET_CODE (operand) == MEM
3133 /* If IND_LEVELS, find_reloads_address won't reload a
3134 pseudo that didn't get a hard reg, so we have to
3135 reject that case. */
3136 && ((ind_levels ? offsettable_memref_p (operand)
3137 : offsettable_nonstrict_memref_p (operand))
3138 /* A reloaded address is offsettable because it is now
3139 just a simple register indirect. */
3140 || address_reloaded[i]))
3141 || (GET_CODE (operand) == REG
3142 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3143 && reg_renumber[REGNO (operand)] < 0
3144 /* If reg_equiv_address is nonzero, we will be
3145 loading it into a register; hence it will be
3146 offsettable, but we cannot say that reg_equiv_mem
3147 is offsettable without checking. */
3148 && ((reg_equiv_mem[REGNO (operand)] != 0
3149 && offsettable_memref_p (reg_equiv_mem[REGNO (operand)]))
3150 || (reg_equiv_address[REGNO (operand)] != 0))))
3151 win = 1;
3152 /* force_const_mem does not accept HIGH. */
3153 if ((CONSTANT_P (operand) && GET_CODE (operand) != HIGH)
3154 || GET_CODE (operand) == MEM)
3155 badop = 0;
3156 constmemok = 1;
3157 offmemok = 1;
3158 break;
3160 case '&':
3161 /* Output operand that is stored before the need for the
3162 input operands (and their index registers) is over. */
3163 earlyclobber = 1, this_earlyclobber = 1;
3164 break;
3166 case 'E':
3167 case 'F':
3168 if (GET_CODE (operand) == CONST_DOUBLE
3169 || (GET_CODE (operand) == CONST_VECTOR
3170 && (GET_MODE_CLASS (GET_MODE (operand))
3171 == MODE_VECTOR_FLOAT)))
3172 win = 1;
3173 break;
3175 case 'G':
3176 case 'H':
3177 if (GET_CODE (operand) == CONST_DOUBLE
3178 && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
3179 win = 1;
3180 break;
3182 case 's':
3183 if (GET_CODE (operand) == CONST_INT
3184 || (GET_CODE (operand) == CONST_DOUBLE
3185 && GET_MODE (operand) == VOIDmode))
3186 break;
3187 case 'i':
3188 if (CONSTANT_P (operand)
3189 #ifdef LEGITIMATE_PIC_OPERAND_P
3190 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand))
3191 #endif
3193 win = 1;
3194 break;
3196 case 'n':
3197 if (GET_CODE (operand) == CONST_INT
3198 || (GET_CODE (operand) == CONST_DOUBLE
3199 && GET_MODE (operand) == VOIDmode))
3200 win = 1;
3201 break;
3203 case 'I':
3204 case 'J':
3205 case 'K':
3206 case 'L':
3207 case 'M':
3208 case 'N':
3209 case 'O':
3210 case 'P':
3211 if (GET_CODE (operand) == CONST_INT
3212 && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
3213 win = 1;
3214 break;
3216 case 'X':
3217 win = 1;
3218 break;
3220 case 'g':
3221 if (! force_reload
3222 /* A PLUS is never a valid operand, but reload can make
3223 it from a register when eliminating registers. */
3224 && GET_CODE (operand) != PLUS
3225 /* A SCRATCH is not a valid operand. */
3226 && GET_CODE (operand) != SCRATCH
3227 #ifdef LEGITIMATE_PIC_OPERAND_P
3228 && (! CONSTANT_P (operand)
3229 || ! flag_pic
3230 || LEGITIMATE_PIC_OPERAND_P (operand))
3231 #endif
3232 && (GENERAL_REGS == ALL_REGS
3233 || GET_CODE (operand) != REG
3234 || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
3235 && reg_renumber[REGNO (operand)] < 0)))
3236 win = 1;
3237 /* Drop through into 'r' case. */
3239 case 'r':
3240 this_alternative[i]
3241 = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
3242 goto reg;
3244 default:
3245 if (REG_CLASS_FROM_LETTER (c) == NO_REGS)
3247 #ifdef EXTRA_CONSTRAINT
3248 if (EXTRA_MEMORY_CONSTRAINT (c))
3250 if (force_reload)
3251 break;
3252 if (EXTRA_CONSTRAINT (operand, c))
3253 win = 1;
3254 /* If the address was already reloaded,
3255 we win as well. */
3256 if (GET_CODE (operand) == MEM && address_reloaded[i])
3257 win = 1;
3258 /* Likewise if the address will be reloaded because
3259 reg_equiv_address is nonzero. For reg_equiv_mem
3260 we have to check. */
3261 if (GET_CODE (operand) == REG
3262 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3263 && reg_renumber[REGNO (operand)] < 0
3264 && ((reg_equiv_mem[REGNO (operand)] != 0
3265 && EXTRA_CONSTRAINT (reg_equiv_mem[REGNO (operand)], c))
3266 || (reg_equiv_address[REGNO (operand)] != 0)))
3267 win = 1;
3269 /* If we didn't already win, we can reload
3270 constants via force_const_mem, and other
3271 MEMs by reloading the address like for 'o'. */
3272 if ((CONSTANT_P (operand) && GET_CODE (operand) != HIGH)
3273 || GET_CODE (operand) == MEM)
3274 badop = 0;
3275 constmemok = 1;
3276 offmemok = 1;
3277 break;
3279 if (EXTRA_ADDRESS_CONSTRAINT (c))
3281 if (EXTRA_CONSTRAINT (operand, c))
3282 win = 1;
3284 /* If we didn't already win, we can reload
3285 the address into a base register. */
3286 this_alternative[i] = (int) MODE_BASE_REG_CLASS (VOIDmode);
3287 badop = 0;
3289 /* Address constraints are reloaded in Pmode, no matter
3290 what mode is given in the machine description. */
3291 operand_mode[i] = Pmode;
3292 break;
3295 if (EXTRA_CONSTRAINT (operand, c))
3296 win = 1;
3297 #endif
3298 break;
3301 this_alternative[i]
3302 = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
3303 reg:
3304 if (GET_MODE (operand) == BLKmode)
3305 break;
3306 winreg = 1;
3307 if (GET_CODE (operand) == REG
3308 && reg_fits_class_p (operand, this_alternative[i],
3309 offset, GET_MODE (recog_data.operand[i])))
3310 win = 1;
3311 break;
3314 constraints[i] = p;
3316 /* If this operand could be handled with a reg,
3317 and some reg is allowed, then this operand can be handled. */
3318 if (winreg && this_alternative[i] != (int) NO_REGS)
3319 badop = 0;
3321 /* Record which operands fit this alternative. */
3322 this_alternative_earlyclobber[i] = earlyclobber;
3323 if (win && ! force_reload)
3324 this_alternative_win[i] = 1;
3325 else if (did_match && ! force_reload)
3326 this_alternative_match_win[i] = 1;
3327 else
3329 int const_to_mem = 0;
3331 this_alternative_offmemok[i] = offmemok;
3332 losers++;
3333 if (badop)
3334 bad = 1;
3335 /* Alternative loses if it has no regs for a reg operand. */
3336 if (GET_CODE (operand) == REG
3337 && this_alternative[i] == (int) NO_REGS
3338 && this_alternative_matches[i] < 0)
3339 bad = 1;
3341 /* If this is a constant that is reloaded into the desired
3342 class by copying it to memory first, count that as another
3343 reload. This is consistent with other code and is
3344 required to avoid choosing another alternative when
3345 the constant is moved into memory by this function on
3346 an early reload pass. Note that the test here is
3347 precisely the same as in the code below that calls
3348 force_const_mem. */
3349 if (CONSTANT_P (operand)
3350 /* force_const_mem does not accept HIGH. */
3351 && GET_CODE (operand) != HIGH
3352 && ((PREFERRED_RELOAD_CLASS (operand,
3353 (enum reg_class) this_alternative[i])
3354 == NO_REGS)
3355 || no_input_reloads)
3356 && operand_mode[i] != VOIDmode)
3358 const_to_mem = 1;
3359 if (this_alternative[i] != (int) NO_REGS)
3360 losers++;
3363 /* If we can't reload this value at all, reject this
3364 alternative. Note that we could also lose due to
3365 LIMIT_RELOAD_RELOAD_CLASS, but we don't check that
3366 here. */
3368 if (! CONSTANT_P (operand)
3369 && (enum reg_class) this_alternative[i] != NO_REGS
3370 && (PREFERRED_RELOAD_CLASS (operand,
3371 (enum reg_class) this_alternative[i])
3372 == NO_REGS))
3373 bad = 1;
3375 /* Alternative loses if it requires a type of reload not
3376 permitted for this insn. We can always reload SCRATCH
3377 and objects with a REG_UNUSED note. */
3378 else if (GET_CODE (operand) != SCRATCH
3379 && modified[i] != RELOAD_READ && no_output_reloads
3380 && ! find_reg_note (insn, REG_UNUSED, operand))
3381 bad = 1;
3382 else if (modified[i] != RELOAD_WRITE && no_input_reloads
3383 && ! const_to_mem)
3384 bad = 1;
3386 /* We prefer to reload pseudos over reloading other things,
3387 since such reloads may be able to be eliminated later.
3388 If we are reloading a SCRATCH, we won't be generating any
3389 insns, just using a register, so it is also preferred.
3390 So bump REJECT in other cases. Don't do this in the
3391 case where we are forcing a constant into memory and
3392 it will then win since we don't want to have a different
3393 alternative match then. */
3394 if (! (GET_CODE (operand) == REG
3395 && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
3396 && GET_CODE (operand) != SCRATCH
3397 && ! (const_to_mem && constmemok))
3398 reject += 2;
3400 /* Input reloads can be inherited more often than output
3401 reloads can be removed, so penalize output reloads. */
3402 if (operand_type[i] != RELOAD_FOR_INPUT
3403 && GET_CODE (operand) != SCRATCH)
3404 reject++;
3407 /* If this operand is a pseudo register that didn't get a hard
3408 reg and this alternative accepts some register, see if the
3409 class that we want is a subset of the preferred class for this
3410 register. If not, but it intersects that class, use the
3411 preferred class instead. If it does not intersect the preferred
3412 class, show that usage of this alternative should be discouraged;
3413 it will be discouraged more still if the register is `preferred
3414 or nothing'. We do this because it increases the chance of
3415 reusing our spill register in a later insn and avoiding a pair
3416 of memory stores and loads.
3418 Don't bother with this if this alternative will accept this
3419 operand.
3421 Don't do this for a multiword operand, since it is only a
3422 small win and has the risk of requiring more spill registers,
3423 which could cause a large loss.
3425 Don't do this if the preferred class has only one register
3426 because we might otherwise exhaust the class. */
3428 if (! win && ! did_match
3429 && this_alternative[i] != (int) NO_REGS
3430 && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3431 && reg_class_size[(int) preferred_class[i]] > 1)
3433 if (! reg_class_subset_p (this_alternative[i],
3434 preferred_class[i]))
3436 /* Since we don't have a way of forming the intersection,
3437 we just do something special if the preferred class
3438 is a subset of the class we have; that's the most
3439 common case anyway. */
3440 if (reg_class_subset_p (preferred_class[i],
3441 this_alternative[i]))
3442 this_alternative[i] = (int) preferred_class[i];
3443 else
3444 reject += (2 + 2 * pref_or_nothing[i]);
3449 /* Now see if any output operands that are marked "earlyclobber"
3450 in this alternative conflict with any input operands
3451 or any memory addresses. */
3453 for (i = 0; i < noperands; i++)
3454 if (this_alternative_earlyclobber[i]
3455 && (this_alternative_win[i] || this_alternative_match_win[i]))
3457 struct decomposition early_data;
3459 early_data = decompose (recog_data.operand[i]);
3461 if (modified[i] == RELOAD_READ)
3462 abort ();
3464 if (this_alternative[i] == NO_REGS)
3466 this_alternative_earlyclobber[i] = 0;
3467 if (this_insn_is_asm)
3468 error_for_asm (this_insn,
3469 "`&' constraint used with no register class");
3470 else
3471 abort ();
3474 for (j = 0; j < noperands; j++)
3475 /* Is this an input operand or a memory ref? */
3476 if ((GET_CODE (recog_data.operand[j]) == MEM
3477 || modified[j] != RELOAD_WRITE)
3478 && j != i
3479 /* Ignore things like match_operator operands. */
3480 && *recog_data.constraints[j] != 0
3481 /* Don't count an input operand that is constrained to match
3482 the early clobber operand. */
3483 && ! (this_alternative_matches[j] == i
3484 && rtx_equal_p (recog_data.operand[i],
3485 recog_data.operand[j]))
3486 /* Is it altered by storing the earlyclobber operand? */
3487 && !immune_p (recog_data.operand[j], recog_data.operand[i],
3488 early_data))
3490 /* If the output is in a single-reg class,
3491 it's costly to reload it, so reload the input instead. */
3492 if (reg_class_size[this_alternative[i]] == 1
3493 && (GET_CODE (recog_data.operand[j]) == REG
3494 || GET_CODE (recog_data.operand[j]) == SUBREG))
3496 losers++;
3497 this_alternative_win[j] = 0;
3498 this_alternative_match_win[j] = 0;
3500 else
3501 break;
3503 /* If an earlyclobber operand conflicts with something,
3504 it must be reloaded, so request this and count the cost. */
3505 if (j != noperands)
3507 losers++;
3508 this_alternative_win[i] = 0;
3509 this_alternative_match_win[j] = 0;
3510 for (j = 0; j < noperands; j++)
3511 if (this_alternative_matches[j] == i
3512 && this_alternative_match_win[j])
3514 this_alternative_win[j] = 0;
3515 this_alternative_match_win[j] = 0;
3516 losers++;
3521 /* If one alternative accepts all the operands, no reload required,
3522 choose that alternative; don't consider the remaining ones. */
3523 if (losers == 0)
3525 /* Unswap these so that they are never swapped at `finish'. */
3526 if (commutative >= 0)
3528 recog_data.operand[commutative] = substed_operand[commutative];
3529 recog_data.operand[commutative + 1]
3530 = substed_operand[commutative + 1];
3532 for (i = 0; i < noperands; i++)
3534 goal_alternative_win[i] = this_alternative_win[i];
3535 goal_alternative_match_win[i] = this_alternative_match_win[i];
3536 goal_alternative[i] = this_alternative[i];
3537 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3538 goal_alternative_matches[i] = this_alternative_matches[i];
3539 goal_alternative_earlyclobber[i]
3540 = this_alternative_earlyclobber[i];
3542 goal_alternative_number = this_alternative_number;
3543 goal_alternative_swapped = swapped;
3544 goal_earlyclobber = this_earlyclobber;
3545 goto finish;
3548 /* REJECT, set by the ! and ? constraint characters and when a register
3549 would be reloaded into a non-preferred class, discourages the use of
3550 this alternative for a reload goal. REJECT is incremented by six
3551 for each ? and two for each non-preferred class. */
3552 losers = losers * 6 + reject;
3554 /* If this alternative can be made to work by reloading,
3555 and it needs less reloading than the others checked so far,
3556 record it as the chosen goal for reloading. */
3557 if (! bad && best > losers)
3559 for (i = 0; i < noperands; i++)
3561 goal_alternative[i] = this_alternative[i];
3562 goal_alternative_win[i] = this_alternative_win[i];
3563 goal_alternative_match_win[i] = this_alternative_match_win[i];
3564 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3565 goal_alternative_matches[i] = this_alternative_matches[i];
3566 goal_alternative_earlyclobber[i]
3567 = this_alternative_earlyclobber[i];
3569 goal_alternative_swapped = swapped;
3570 best = losers;
3571 goal_alternative_number = this_alternative_number;
3572 goal_earlyclobber = this_earlyclobber;
3576 /* If insn is commutative (it's safe to exchange a certain pair of operands)
3577 then we need to try each alternative twice,
3578 the second time matching those two operands
3579 as if we had exchanged them.
3580 To do this, really exchange them in operands.
3582 If we have just tried the alternatives the second time,
3583 return operands to normal and drop through. */
3585 if (commutative >= 0)
3587 swapped = !swapped;
3588 if (swapped)
3590 enum reg_class tclass;
3591 int t;
3593 recog_data.operand[commutative] = substed_operand[commutative + 1];
3594 recog_data.operand[commutative + 1] = substed_operand[commutative];
3595 /* Swap the duplicates too. */
3596 for (i = 0; i < recog_data.n_dups; i++)
3597 if (recog_data.dup_num[i] == commutative
3598 || recog_data.dup_num[i] == commutative + 1)
3599 *recog_data.dup_loc[i]
3600 = recog_data.operand[(int) recog_data.dup_num[i]];
3602 tclass = preferred_class[commutative];
3603 preferred_class[commutative] = preferred_class[commutative + 1];
3604 preferred_class[commutative + 1] = tclass;
3606 t = pref_or_nothing[commutative];
3607 pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
3608 pref_or_nothing[commutative + 1] = t;
3610 memcpy (constraints, recog_data.constraints,
3611 noperands * sizeof (char *));
3612 goto try_swapped;
3614 else
3616 recog_data.operand[commutative] = substed_operand[commutative];
3617 recog_data.operand[commutative + 1]
3618 = substed_operand[commutative + 1];
3619 /* Unswap the duplicates too. */
3620 for (i = 0; i < recog_data.n_dups; i++)
3621 if (recog_data.dup_num[i] == commutative
3622 || recog_data.dup_num[i] == commutative + 1)
3623 *recog_data.dup_loc[i]
3624 = recog_data.operand[(int) recog_data.dup_num[i]];
3628 /* The operands don't meet the constraints.
3629 goal_alternative describes the alternative
3630 that we could reach by reloading the fewest operands.
3631 Reload so as to fit it. */
3633 if (best == MAX_RECOG_OPERANDS * 2 + 600)
3635 /* No alternative works with reloads?? */
3636 if (insn_code_number >= 0)
3637 fatal_insn ("unable to generate reloads for:", insn);
3638 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3639 /* Avoid further trouble with this insn. */
3640 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3641 n_reloads = 0;
3642 return 0;
3645 /* Jump to `finish' from above if all operands are valid already.
3646 In that case, goal_alternative_win is all 1. */
3647 finish:
3649 /* Right now, for any pair of operands I and J that are required to match,
3650 with I < J,
3651 goal_alternative_matches[J] is I.
3652 Set up goal_alternative_matched as the inverse function:
3653 goal_alternative_matched[I] = J. */
3655 for (i = 0; i < noperands; i++)
3656 goal_alternative_matched[i] = -1;
3658 for (i = 0; i < noperands; i++)
3659 if (! goal_alternative_win[i]
3660 && goal_alternative_matches[i] >= 0)
3661 goal_alternative_matched[goal_alternative_matches[i]] = i;
3663 for (i = 0; i < noperands; i++)
3664 goal_alternative_win[i] |= goal_alternative_match_win[i];
3666 /* If the best alternative is with operands 1 and 2 swapped,
3667 consider them swapped before reporting the reloads. Update the
3668 operand numbers of any reloads already pushed. */
3670 if (goal_alternative_swapped)
3672 rtx tem;
3674 tem = substed_operand[commutative];
3675 substed_operand[commutative] = substed_operand[commutative + 1];
3676 substed_operand[commutative + 1] = tem;
3677 tem = recog_data.operand[commutative];
3678 recog_data.operand[commutative] = recog_data.operand[commutative + 1];
3679 recog_data.operand[commutative + 1] = tem;
3680 tem = *recog_data.operand_loc[commutative];
3681 *recog_data.operand_loc[commutative]
3682 = *recog_data.operand_loc[commutative + 1];
3683 *recog_data.operand_loc[commutative + 1] = tem;
3685 for (i = 0; i < n_reloads; i++)
3687 if (rld[i].opnum == commutative)
3688 rld[i].opnum = commutative + 1;
3689 else if (rld[i].opnum == commutative + 1)
3690 rld[i].opnum = commutative;
3694 for (i = 0; i < noperands; i++)
3696 operand_reloadnum[i] = -1;
3698 /* If this is an earlyclobber operand, we need to widen the scope.
3699 The reload must remain valid from the start of the insn being
3700 reloaded until after the operand is stored into its destination.
3701 We approximate this with RELOAD_OTHER even though we know that we
3702 do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads.
3704 One special case that is worth checking is when we have an
3705 output that is earlyclobber but isn't used past the insn (typically
3706 a SCRATCH). In this case, we only need have the reload live
3707 through the insn itself, but not for any of our input or output
3708 reloads.
3709 But we must not accidentally narrow the scope of an existing
3710 RELOAD_OTHER reload - leave these alone.
3712 In any case, anything needed to address this operand can remain
3713 however they were previously categorized. */
3715 if (goal_alternative_earlyclobber[i] && operand_type[i] != RELOAD_OTHER)
3716 operand_type[i]
3717 = (find_reg_note (insn, REG_UNUSED, recog_data.operand[i])
3718 ? RELOAD_FOR_INSN : RELOAD_OTHER);
3721 /* Any constants that aren't allowed and can't be reloaded
3722 into registers are here changed into memory references. */
3723 for (i = 0; i < noperands; i++)
3724 if (! goal_alternative_win[i]
3725 && CONSTANT_P (recog_data.operand[i])
3726 /* force_const_mem does not accept HIGH. */
3727 && GET_CODE (recog_data.operand[i]) != HIGH
3728 && ((PREFERRED_RELOAD_CLASS (recog_data.operand[i],
3729 (enum reg_class) goal_alternative[i])
3730 == NO_REGS)
3731 || no_input_reloads)
3732 && operand_mode[i] != VOIDmode)
3734 substed_operand[i] = recog_data.operand[i]
3735 = find_reloads_toplev (force_const_mem (operand_mode[i],
3736 recog_data.operand[i]),
3737 i, address_type[i], ind_levels, 0, insn,
3738 NULL);
3739 if (alternative_allows_memconst (recog_data.constraints[i],
3740 goal_alternative_number))
3741 goal_alternative_win[i] = 1;
3744 /* Record the values of the earlyclobber operands for the caller. */
3745 if (goal_earlyclobber)
3746 for (i = 0; i < noperands; i++)
3747 if (goal_alternative_earlyclobber[i])
3748 reload_earlyclobbers[n_earlyclobbers++] = recog_data.operand[i];
3750 /* Now record reloads for all the operands that need them. */
3751 for (i = 0; i < noperands; i++)
3752 if (! goal_alternative_win[i])
3754 /* Operands that match previous ones have already been handled. */
3755 if (goal_alternative_matches[i] >= 0)
3757 /* Handle an operand with a nonoffsettable address
3758 appearing where an offsettable address will do
3759 by reloading the address into a base register.
3761 ??? We can also do this when the operand is a register and
3762 reg_equiv_mem is not offsettable, but this is a bit tricky,
3763 so we don't bother with it. It may not be worth doing. */
3764 else if (goal_alternative_matched[i] == -1
3765 && goal_alternative_offmemok[i]
3766 && GET_CODE (recog_data.operand[i]) == MEM)
3768 operand_reloadnum[i]
3769 = push_reload (XEXP (recog_data.operand[i], 0), NULL_RTX,
3770 &XEXP (recog_data.operand[i], 0), (rtx*) 0,
3771 MODE_BASE_REG_CLASS (VOIDmode),
3772 GET_MODE (XEXP (recog_data.operand[i], 0)),
3773 VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
3774 rld[operand_reloadnum[i]].inc
3775 = GET_MODE_SIZE (GET_MODE (recog_data.operand[i]));
3777 /* If this operand is an output, we will have made any
3778 reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but
3779 now we are treating part of the operand as an input, so
3780 we must change these to RELOAD_FOR_INPUT_ADDRESS. */
3782 if (modified[i] == RELOAD_WRITE)
3784 for (j = 0; j < n_reloads; j++)
3786 if (rld[j].opnum == i)
3788 if (rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS)
3789 rld[j].when_needed = RELOAD_FOR_INPUT_ADDRESS;
3790 else if (rld[j].when_needed
3791 == RELOAD_FOR_OUTADDR_ADDRESS)
3792 rld[j].when_needed = RELOAD_FOR_INPADDR_ADDRESS;
3797 else if (goal_alternative_matched[i] == -1)
3799 operand_reloadnum[i]
3800 = push_reload ((modified[i] != RELOAD_WRITE
3801 ? recog_data.operand[i] : 0),
3802 (modified[i] != RELOAD_READ
3803 ? recog_data.operand[i] : 0),
3804 (modified[i] != RELOAD_WRITE
3805 ? recog_data.operand_loc[i] : 0),
3806 (modified[i] != RELOAD_READ
3807 ? recog_data.operand_loc[i] : 0),
3808 (enum reg_class) goal_alternative[i],
3809 (modified[i] == RELOAD_WRITE
3810 ? VOIDmode : operand_mode[i]),
3811 (modified[i] == RELOAD_READ
3812 ? VOIDmode : operand_mode[i]),
3813 (insn_code_number < 0 ? 0
3814 : insn_data[insn_code_number].operand[i].strict_low),
3815 0, i, operand_type[i]);
3817 /* In a matching pair of operands, one must be input only
3818 and the other must be output only.
3819 Pass the input operand as IN and the other as OUT. */
3820 else if (modified[i] == RELOAD_READ
3821 && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
3823 operand_reloadnum[i]
3824 = push_reload (recog_data.operand[i],
3825 recog_data.operand[goal_alternative_matched[i]],
3826 recog_data.operand_loc[i],
3827 recog_data.operand_loc[goal_alternative_matched[i]],
3828 (enum reg_class) goal_alternative[i],
3829 operand_mode[i],
3830 operand_mode[goal_alternative_matched[i]],
3831 0, 0, i, RELOAD_OTHER);
3832 operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
3834 else if (modified[i] == RELOAD_WRITE
3835 && modified[goal_alternative_matched[i]] == RELOAD_READ)
3837 operand_reloadnum[goal_alternative_matched[i]]
3838 = push_reload (recog_data.operand[goal_alternative_matched[i]],
3839 recog_data.operand[i],
3840 recog_data.operand_loc[goal_alternative_matched[i]],
3841 recog_data.operand_loc[i],
3842 (enum reg_class) goal_alternative[i],
3843 operand_mode[goal_alternative_matched[i]],
3844 operand_mode[i],
3845 0, 0, i, RELOAD_OTHER);
3846 operand_reloadnum[i] = output_reloadnum;
3848 else if (insn_code_number >= 0)
3849 abort ();
3850 else
3852 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3853 /* Avoid further trouble with this insn. */
3854 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3855 n_reloads = 0;
3856 return 0;
3859 else if (goal_alternative_matched[i] < 0
3860 && goal_alternative_matches[i] < 0
3861 && optimize)
3863 /* For each non-matching operand that's a MEM or a pseudo-register
3864 that didn't get a hard register, make an optional reload.
3865 This may get done even if the insn needs no reloads otherwise. */
3867 rtx operand = recog_data.operand[i];
3869 while (GET_CODE (operand) == SUBREG)
3870 operand = SUBREG_REG (operand);
3871 if ((GET_CODE (operand) == MEM
3872 || (GET_CODE (operand) == REG
3873 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3874 /* If this is only for an output, the optional reload would not
3875 actually cause us to use a register now, just note that
3876 something is stored here. */
3877 && ((enum reg_class) goal_alternative[i] != NO_REGS
3878 || modified[i] == RELOAD_WRITE)
3879 && ! no_input_reloads
3880 /* An optional output reload might allow to delete INSN later.
3881 We mustn't make in-out reloads on insns that are not permitted
3882 output reloads.
3883 If this is an asm, we can't delete it; we must not even call
3884 push_reload for an optional output reload in this case,
3885 because we can't be sure that the constraint allows a register,
3886 and push_reload verifies the constraints for asms. */
3887 && (modified[i] == RELOAD_READ
3888 || (! no_output_reloads && ! this_insn_is_asm)))
3889 operand_reloadnum[i]
3890 = push_reload ((modified[i] != RELOAD_WRITE
3891 ? recog_data.operand[i] : 0),
3892 (modified[i] != RELOAD_READ
3893 ? recog_data.operand[i] : 0),
3894 (modified[i] != RELOAD_WRITE
3895 ? recog_data.operand_loc[i] : 0),
3896 (modified[i] != RELOAD_READ
3897 ? recog_data.operand_loc[i] : 0),
3898 (enum reg_class) goal_alternative[i],
3899 (modified[i] == RELOAD_WRITE
3900 ? VOIDmode : operand_mode[i]),
3901 (modified[i] == RELOAD_READ
3902 ? VOIDmode : operand_mode[i]),
3903 (insn_code_number < 0 ? 0
3904 : insn_data[insn_code_number].operand[i].strict_low),
3905 1, i, operand_type[i]);
3906 /* If a memory reference remains (either as a MEM or a pseudo that
3907 did not get a hard register), yet we can't make an optional
3908 reload, check if this is actually a pseudo register reference;
3909 we then need to emit a USE and/or a CLOBBER so that reload
3910 inheritance will do the right thing. */
3911 else if (replace
3912 && (GET_CODE (operand) == MEM
3913 || (GET_CODE (operand) == REG
3914 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3915 && reg_renumber [REGNO (operand)] < 0)))
3917 operand = *recog_data.operand_loc[i];
3919 while (GET_CODE (operand) == SUBREG)
3920 operand = SUBREG_REG (operand);
3921 if (GET_CODE (operand) == REG)
3923 if (modified[i] != RELOAD_WRITE)
3924 /* We mark the USE with QImode so that we recognize
3925 it as one that can be safely deleted at the end
3926 of reload. */
3927 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, operand),
3928 insn), QImode);
3929 if (modified[i] != RELOAD_READ)
3930 emit_insn_after (gen_rtx_CLOBBER (VOIDmode, operand), insn);
3934 else if (goal_alternative_matches[i] >= 0
3935 && goal_alternative_win[goal_alternative_matches[i]]
3936 && modified[i] == RELOAD_READ
3937 && modified[goal_alternative_matches[i]] == RELOAD_WRITE
3938 && ! no_input_reloads && ! no_output_reloads
3939 && optimize)
3941 /* Similarly, make an optional reload for a pair of matching
3942 objects that are in MEM or a pseudo that didn't get a hard reg. */
3944 rtx operand = recog_data.operand[i];
3946 while (GET_CODE (operand) == SUBREG)
3947 operand = SUBREG_REG (operand);
3948 if ((GET_CODE (operand) == MEM
3949 || (GET_CODE (operand) == REG
3950 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3951 && ((enum reg_class) goal_alternative[goal_alternative_matches[i]]
3952 != NO_REGS))
3953 operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]]
3954 = push_reload (recog_data.operand[goal_alternative_matches[i]],
3955 recog_data.operand[i],
3956 recog_data.operand_loc[goal_alternative_matches[i]],
3957 recog_data.operand_loc[i],
3958 (enum reg_class) goal_alternative[goal_alternative_matches[i]],
3959 operand_mode[goal_alternative_matches[i]],
3960 operand_mode[i],
3961 0, 1, goal_alternative_matches[i], RELOAD_OTHER);
3964 /* Perform whatever substitutions on the operands we are supposed
3965 to make due to commutativity or replacement of registers
3966 with equivalent constants or memory slots. */
3968 for (i = 0; i < noperands; i++)
3970 /* We only do this on the last pass through reload, because it is
3971 possible for some data (like reg_equiv_address) to be changed during
3972 later passes. Moreover, we loose the opportunity to get a useful
3973 reload_{in,out}_reg when we do these replacements. */
3975 if (replace)
3977 rtx substitution = substed_operand[i];
3979 *recog_data.operand_loc[i] = substitution;
3981 /* If we're replacing an operand with a LABEL_REF, we need
3982 to make sure that there's a REG_LABEL note attached to
3983 this instruction. */
3984 if (GET_CODE (insn) != JUMP_INSN
3985 && GET_CODE (substitution) == LABEL_REF
3986 && !find_reg_note (insn, REG_LABEL, XEXP (substitution, 0)))
3987 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
3988 XEXP (substitution, 0),
3989 REG_NOTES (insn));
3991 else
3992 retval |= (substed_operand[i] != *recog_data.operand_loc[i]);
3995 /* If this insn pattern contains any MATCH_DUP's, make sure that
3996 they will be substituted if the operands they match are substituted.
3997 Also do now any substitutions we already did on the operands.
3999 Don't do this if we aren't making replacements because we might be
4000 propagating things allocated by frame pointer elimination into places
4001 it doesn't expect. */
4003 if (insn_code_number >= 0 && replace)
4004 for (i = insn_data[insn_code_number].n_dups - 1; i >= 0; i--)
4006 int opno = recog_data.dup_num[i];
4007 *recog_data.dup_loc[i] = *recog_data.operand_loc[opno];
4008 dup_replacements (recog_data.dup_loc[i], recog_data.operand_loc[opno]);
4011 #if 0
4012 /* This loses because reloading of prior insns can invalidate the equivalence
4013 (or at least find_equiv_reg isn't smart enough to find it any more),
4014 causing this insn to need more reload regs than it needed before.
4015 It may be too late to make the reload regs available.
4016 Now this optimization is done safely in choose_reload_regs. */
4018 /* For each reload of a reg into some other class of reg,
4019 search for an existing equivalent reg (same value now) in the right class.
4020 We can use it as long as we don't need to change its contents. */
4021 for (i = 0; i < n_reloads; i++)
4022 if (rld[i].reg_rtx == 0
4023 && rld[i].in != 0
4024 && GET_CODE (rld[i].in) == REG
4025 && rld[i].out == 0)
4027 rld[i].reg_rtx
4028 = find_equiv_reg (rld[i].in, insn, rld[i].class, -1,
4029 static_reload_reg_p, 0, rld[i].inmode);
4030 /* Prevent generation of insn to load the value
4031 because the one we found already has the value. */
4032 if (rld[i].reg_rtx)
4033 rld[i].in = rld[i].reg_rtx;
4035 #endif
4037 /* Perhaps an output reload can be combined with another
4038 to reduce needs by one. */
4039 if (!goal_earlyclobber)
4040 combine_reloads ();
4042 /* If we have a pair of reloads for parts of an address, they are reloading
4043 the same object, the operands themselves were not reloaded, and they
4044 are for two operands that are supposed to match, merge the reloads and
4045 change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS. */
4047 for (i = 0; i < n_reloads; i++)
4049 int k;
4051 for (j = i + 1; j < n_reloads; j++)
4052 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4053 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4054 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4055 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4056 && (rld[j].when_needed == RELOAD_FOR_INPUT_ADDRESS
4057 || rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4058 || rld[j].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4059 || rld[j].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4060 && rtx_equal_p (rld[i].in, rld[j].in)
4061 && (operand_reloadnum[rld[i].opnum] < 0
4062 || rld[operand_reloadnum[rld[i].opnum]].optional)
4063 && (operand_reloadnum[rld[j].opnum] < 0
4064 || rld[operand_reloadnum[rld[j].opnum]].optional)
4065 && (goal_alternative_matches[rld[i].opnum] == rld[j].opnum
4066 || (goal_alternative_matches[rld[j].opnum]
4067 == rld[i].opnum)))
4069 for (k = 0; k < n_replacements; k++)
4070 if (replacements[k].what == j)
4071 replacements[k].what = i;
4073 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4074 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4075 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
4076 else
4077 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
4078 rld[j].in = 0;
4082 /* Scan all the reloads and update their type.
4083 If a reload is for the address of an operand and we didn't reload
4084 that operand, change the type. Similarly, change the operand number
4085 of a reload when two operands match. If a reload is optional, treat it
4086 as though the operand isn't reloaded.
4088 ??? This latter case is somewhat odd because if we do the optional
4089 reload, it means the object is hanging around. Thus we need only
4090 do the address reload if the optional reload was NOT done.
4092 Change secondary reloads to be the address type of their operand, not
4093 the normal type.
4095 If an operand's reload is now RELOAD_OTHER, change any
4096 RELOAD_FOR_INPUT_ADDRESS reloads of that operand to
4097 RELOAD_FOR_OTHER_ADDRESS. */
4099 for (i = 0; i < n_reloads; i++)
4101 if (rld[i].secondary_p
4102 && rld[i].when_needed == operand_type[rld[i].opnum])
4103 rld[i].when_needed = address_type[rld[i].opnum];
4105 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4106 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4107 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4108 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4109 && (operand_reloadnum[rld[i].opnum] < 0
4110 || rld[operand_reloadnum[rld[i].opnum]].optional))
4112 /* If we have a secondary reload to go along with this reload,
4113 change its type to RELOAD_FOR_OPADDR_ADDR. */
4115 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4116 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4117 && rld[i].secondary_in_reload != -1)
4119 int secondary_in_reload = rld[i].secondary_in_reload;
4121 rld[secondary_in_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4123 /* If there's a tertiary reload we have to change it also. */
4124 if (secondary_in_reload > 0
4125 && rld[secondary_in_reload].secondary_in_reload != -1)
4126 rld[rld[secondary_in_reload].secondary_in_reload].when_needed
4127 = RELOAD_FOR_OPADDR_ADDR;
4130 if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4131 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4132 && rld[i].secondary_out_reload != -1)
4134 int secondary_out_reload = rld[i].secondary_out_reload;
4136 rld[secondary_out_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4138 /* If there's a tertiary reload we have to change it also. */
4139 if (secondary_out_reload
4140 && rld[secondary_out_reload].secondary_out_reload != -1)
4141 rld[rld[secondary_out_reload].secondary_out_reload].when_needed
4142 = RELOAD_FOR_OPADDR_ADDR;
4145 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4146 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4147 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
4148 else
4149 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
4152 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4153 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4154 && operand_reloadnum[rld[i].opnum] >= 0
4155 && (rld[operand_reloadnum[rld[i].opnum]].when_needed
4156 == RELOAD_OTHER))
4157 rld[i].when_needed = RELOAD_FOR_OTHER_ADDRESS;
4159 if (goal_alternative_matches[rld[i].opnum] >= 0)
4160 rld[i].opnum = goal_alternative_matches[rld[i].opnum];
4163 /* Scan all the reloads, and check for RELOAD_FOR_OPERAND_ADDRESS reloads.
4164 If we have more than one, then convert all RELOAD_FOR_OPADDR_ADDR
4165 reloads to RELOAD_FOR_OPERAND_ADDRESS reloads.
4167 choose_reload_regs assumes that RELOAD_FOR_OPADDR_ADDR reloads never
4168 conflict with RELOAD_FOR_OPERAND_ADDRESS reloads. This is true for a
4169 single pair of RELOAD_FOR_OPADDR_ADDR/RELOAD_FOR_OPERAND_ADDRESS reloads.
4170 However, if there is more than one RELOAD_FOR_OPERAND_ADDRESS reload,
4171 then a RELOAD_FOR_OPADDR_ADDR reload conflicts with all
4172 RELOAD_FOR_OPERAND_ADDRESS reloads other than the one that uses it.
4173 This is complicated by the fact that a single operand can have more
4174 than one RELOAD_FOR_OPERAND_ADDRESS reload. It is very difficult to fix
4175 choose_reload_regs without affecting code quality, and cases that
4176 actually fail are extremely rare, so it turns out to be better to fix
4177 the problem here by not generating cases that choose_reload_regs will
4178 fail for. */
4179 /* There is a similar problem with RELOAD_FOR_INPUT_ADDRESS /
4180 RELOAD_FOR_OUTPUT_ADDRESS when there is more than one of a kind for
4181 a single operand.
4182 We can reduce the register pressure by exploiting that a
4183 RELOAD_FOR_X_ADDR_ADDR that precedes all RELOAD_FOR_X_ADDRESS reloads
4184 does not conflict with any of them, if it is only used for the first of
4185 the RELOAD_FOR_X_ADDRESS reloads. */
4187 int first_op_addr_num = -2;
4188 int first_inpaddr_num[MAX_RECOG_OPERANDS];
4189 int first_outpaddr_num[MAX_RECOG_OPERANDS];
4190 int need_change = 0;
4191 /* We use last_op_addr_reload and the contents of the above arrays
4192 first as flags - -2 means no instance encountered, -1 means exactly
4193 one instance encountered.
4194 If more than one instance has been encountered, we store the reload
4195 number of the first reload of the kind in question; reload numbers
4196 are known to be non-negative. */
4197 for (i = 0; i < noperands; i++)
4198 first_inpaddr_num[i] = first_outpaddr_num[i] = -2;
4199 for (i = n_reloads - 1; i >= 0; i--)
4201 switch (rld[i].when_needed)
4203 case RELOAD_FOR_OPERAND_ADDRESS:
4204 if (++first_op_addr_num >= 0)
4206 first_op_addr_num = i;
4207 need_change = 1;
4209 break;
4210 case RELOAD_FOR_INPUT_ADDRESS:
4211 if (++first_inpaddr_num[rld[i].opnum] >= 0)
4213 first_inpaddr_num[rld[i].opnum] = i;
4214 need_change = 1;
4216 break;
4217 case RELOAD_FOR_OUTPUT_ADDRESS:
4218 if (++first_outpaddr_num[rld[i].opnum] >= 0)
4220 first_outpaddr_num[rld[i].opnum] = i;
4221 need_change = 1;
4223 break;
4224 default:
4225 break;
4229 if (need_change)
4231 for (i = 0; i < n_reloads; i++)
4233 int first_num;
4234 enum reload_type type;
4236 switch (rld[i].when_needed)
4238 case RELOAD_FOR_OPADDR_ADDR:
4239 first_num = first_op_addr_num;
4240 type = RELOAD_FOR_OPERAND_ADDRESS;
4241 break;
4242 case RELOAD_FOR_INPADDR_ADDRESS:
4243 first_num = first_inpaddr_num[rld[i].opnum];
4244 type = RELOAD_FOR_INPUT_ADDRESS;
4245 break;
4246 case RELOAD_FOR_OUTADDR_ADDRESS:
4247 first_num = first_outpaddr_num[rld[i].opnum];
4248 type = RELOAD_FOR_OUTPUT_ADDRESS;
4249 break;
4250 default:
4251 continue;
4253 if (first_num < 0)
4254 continue;
4255 else if (i > first_num)
4256 rld[i].when_needed = type;
4257 else
4259 /* Check if the only TYPE reload that uses reload I is
4260 reload FIRST_NUM. */
4261 for (j = n_reloads - 1; j > first_num; j--)
4263 if (rld[j].when_needed == type
4264 && (rld[i].secondary_p
4265 ? rld[j].secondary_in_reload == i
4266 : reg_mentioned_p (rld[i].in, rld[j].in)))
4268 rld[i].when_needed = type;
4269 break;
4277 /* See if we have any reloads that are now allowed to be merged
4278 because we've changed when the reload is needed to
4279 RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS. Only
4280 check for the most common cases. */
4282 for (i = 0; i < n_reloads; i++)
4283 if (rld[i].in != 0 && rld[i].out == 0
4284 && (rld[i].when_needed == RELOAD_FOR_OPERAND_ADDRESS
4285 || rld[i].when_needed == RELOAD_FOR_OPADDR_ADDR
4286 || rld[i].when_needed == RELOAD_FOR_OTHER_ADDRESS))
4287 for (j = 0; j < n_reloads; j++)
4288 if (i != j && rld[j].in != 0 && rld[j].out == 0
4289 && rld[j].when_needed == rld[i].when_needed
4290 && MATCHES (rld[i].in, rld[j].in)
4291 && rld[i].class == rld[j].class
4292 && !rld[i].nocombine && !rld[j].nocombine
4293 && rld[i].reg_rtx == rld[j].reg_rtx)
4295 rld[i].opnum = MIN (rld[i].opnum, rld[j].opnum);
4296 transfer_replacements (i, j);
4297 rld[j].in = 0;
4300 #ifdef HAVE_cc0
4301 /* If we made any reloads for addresses, see if they violate a
4302 "no input reloads" requirement for this insn. But loads that we
4303 do after the insn (such as for output addresses) are fine. */
4304 if (no_input_reloads)
4305 for (i = 0; i < n_reloads; i++)
4306 if (rld[i].in != 0
4307 && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS
4308 && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS)
4309 abort ();
4310 #endif
4312 /* Compute reload_mode and reload_nregs. */
4313 for (i = 0; i < n_reloads; i++)
4315 rld[i].mode
4316 = (rld[i].inmode == VOIDmode
4317 || (GET_MODE_SIZE (rld[i].outmode)
4318 > GET_MODE_SIZE (rld[i].inmode)))
4319 ? rld[i].outmode : rld[i].inmode;
4321 rld[i].nregs = CLASS_MAX_NREGS (rld[i].class, rld[i].mode);
4324 /* Special case a simple move with an input reload and a
4325 destination of a hard reg, if the hard reg is ok, use it. */
4326 for (i = 0; i < n_reloads; i++)
4327 if (rld[i].when_needed == RELOAD_FOR_INPUT
4328 && GET_CODE (PATTERN (insn)) == SET
4329 && GET_CODE (SET_DEST (PATTERN (insn))) == REG
4330 && SET_SRC (PATTERN (insn)) == rld[i].in)
4332 rtx dest = SET_DEST (PATTERN (insn));
4333 unsigned int regno = REGNO (dest);
4335 if (regno < FIRST_PSEUDO_REGISTER
4336 && TEST_HARD_REG_BIT (reg_class_contents[rld[i].class], regno)
4337 && HARD_REGNO_MODE_OK (regno, rld[i].mode))
4338 rld[i].reg_rtx = dest;
4341 return retval;
4344 /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
4345 accepts a memory operand with constant address. */
4347 static int
4348 alternative_allows_memconst (constraint, altnum)
4349 const char *constraint;
4350 int altnum;
4352 int c;
4353 /* Skip alternatives before the one requested. */
4354 while (altnum > 0)
4356 while (*constraint++ != ',');
4357 altnum--;
4359 /* Scan the requested alternative for 'm' or 'o'.
4360 If one of them is present, this alternative accepts memory constants. */
4361 while ((c = *constraint++) && c != ',' && c != '#')
4362 if (c == 'm' || c == 'o' || EXTRA_MEMORY_CONSTRAINT (c))
4363 return 1;
4364 return 0;
4367 /* Scan X for memory references and scan the addresses for reloading.
4368 Also checks for references to "constant" regs that we want to eliminate
4369 and replaces them with the values they stand for.
4370 We may alter X destructively if it contains a reference to such.
4371 If X is just a constant reg, we return the equivalent value
4372 instead of X.
4374 IND_LEVELS says how many levels of indirect addressing this machine
4375 supports.
4377 OPNUM and TYPE identify the purpose of the reload.
4379 IS_SET_DEST is true if X is the destination of a SET, which is not
4380 appropriate to be replaced by a constant.
4382 INSN, if nonzero, is the insn in which we do the reload. It is used
4383 to determine if we may generate output reloads, and where to put USEs
4384 for pseudos that we have to replace with stack slots.
4386 ADDRESS_RELOADED. If nonzero, is a pointer to where we put the
4387 result of find_reloads_address. */
4389 static rtx
4390 find_reloads_toplev (x, opnum, type, ind_levels, is_set_dest, insn,
4391 address_reloaded)
4392 rtx x;
4393 int opnum;
4394 enum reload_type type;
4395 int ind_levels;
4396 int is_set_dest;
4397 rtx insn;
4398 int *address_reloaded;
4400 RTX_CODE code = GET_CODE (x);
4402 const char *fmt = GET_RTX_FORMAT (code);
4403 int i;
4404 int copied;
4406 if (code == REG)
4408 /* This code is duplicated for speed in find_reloads. */
4409 int regno = REGNO (x);
4410 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4411 x = reg_equiv_constant[regno];
4412 #if 0
4413 /* This creates (subreg (mem...)) which would cause an unnecessary
4414 reload of the mem. */
4415 else if (reg_equiv_mem[regno] != 0)
4416 x = reg_equiv_mem[regno];
4417 #endif
4418 else if (reg_equiv_memory_loc[regno]
4419 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
4421 rtx mem = make_memloc (x, regno);
4422 if (reg_equiv_address[regno]
4423 || ! rtx_equal_p (mem, reg_equiv_mem[regno]))
4425 /* If this is not a toplevel operand, find_reloads doesn't see
4426 this substitution. We have to emit a USE of the pseudo so
4427 that delete_output_reload can see it. */
4428 if (replace_reloads && recog_data.operand[opnum] != x)
4429 /* We mark the USE with QImode so that we recognize it
4430 as one that can be safely deleted at the end of
4431 reload. */
4432 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, x), insn),
4433 QImode);
4434 x = mem;
4435 i = find_reloads_address (GET_MODE (x), &x, XEXP (x, 0), &XEXP (x, 0),
4436 opnum, type, ind_levels, insn);
4437 if (address_reloaded)
4438 *address_reloaded = i;
4441 return x;
4443 if (code == MEM)
4445 rtx tem = x;
4447 i = find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
4448 opnum, type, ind_levels, insn);
4449 if (address_reloaded)
4450 *address_reloaded = i;
4452 return tem;
4455 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG)
4457 /* Check for SUBREG containing a REG that's equivalent to a constant.
4458 If the constant has a known value, truncate it right now.
4459 Similarly if we are extracting a single-word of a multi-word
4460 constant. If the constant is symbolic, allow it to be substituted
4461 normally. push_reload will strip the subreg later. If the
4462 constant is VOIDmode, abort because we will lose the mode of
4463 the register (this should never happen because one of the cases
4464 above should handle it). */
4466 int regno = REGNO (SUBREG_REG (x));
4467 rtx tem;
4469 if (subreg_lowpart_p (x)
4470 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4471 && reg_equiv_constant[regno] != 0
4472 && (tem = gen_lowpart_common (GET_MODE (x),
4473 reg_equiv_constant[regno])) != 0)
4474 return tem;
4476 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4477 && reg_equiv_constant[regno] != 0)
4479 tem =
4480 simplify_gen_subreg (GET_MODE (x), reg_equiv_constant[regno],
4481 GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
4482 if (!tem)
4483 abort ();
4484 return tem;
4487 /* If the subreg contains a reg that will be converted to a mem,
4488 convert the subreg to a narrower memref now.
4489 Otherwise, we would get (subreg (mem ...) ...),
4490 which would force reload of the mem.
4492 We also need to do this if there is an equivalent MEM that is
4493 not offsettable. In that case, alter_subreg would produce an
4494 invalid address on big-endian machines.
4496 For machines that extend byte loads, we must not reload using
4497 a wider mode if we have a paradoxical SUBREG. find_reloads will
4498 force a reload in that case. So we should not do anything here. */
4500 else if (regno >= FIRST_PSEUDO_REGISTER
4501 #ifdef LOAD_EXTEND_OP
4502 && (GET_MODE_SIZE (GET_MODE (x))
4503 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
4504 #endif
4505 && (reg_equiv_address[regno] != 0
4506 || (reg_equiv_mem[regno] != 0
4507 && (! strict_memory_address_p (GET_MODE (x),
4508 XEXP (reg_equiv_mem[regno], 0))
4509 || ! offsettable_memref_p (reg_equiv_mem[regno])
4510 || num_not_at_initial_offset))))
4511 x = find_reloads_subreg_address (x, 1, opnum, type, ind_levels,
4512 insn);
4515 for (copied = 0, i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4517 if (fmt[i] == 'e')
4519 rtx new_part = find_reloads_toplev (XEXP (x, i), opnum, type,
4520 ind_levels, is_set_dest, insn,
4521 address_reloaded);
4522 /* If we have replaced a reg with it's equivalent memory loc -
4523 that can still be handled here e.g. if it's in a paradoxical
4524 subreg - we must make the change in a copy, rather than using
4525 a destructive change. This way, find_reloads can still elect
4526 not to do the change. */
4527 if (new_part != XEXP (x, i) && ! CONSTANT_P (new_part) && ! copied)
4529 x = shallow_copy_rtx (x);
4530 copied = 1;
4532 XEXP (x, i) = new_part;
4535 return x;
4538 /* Return a mem ref for the memory equivalent of reg REGNO.
4539 This mem ref is not shared with anything. */
4541 static rtx
4542 make_memloc (ad, regno)
4543 rtx ad;
4544 int regno;
4546 /* We must rerun eliminate_regs, in case the elimination
4547 offsets have changed. */
4548 rtx tem
4549 = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0, NULL_RTX), 0);
4551 /* If TEM might contain a pseudo, we must copy it to avoid
4552 modifying it when we do the substitution for the reload. */
4553 if (rtx_varies_p (tem, 0))
4554 tem = copy_rtx (tem);
4556 tem = replace_equiv_address_nv (reg_equiv_memory_loc[regno], tem);
4557 tem = adjust_address_nv (tem, GET_MODE (ad), 0);
4559 /* Copy the result if it's still the same as the equivalence, to avoid
4560 modifying it when we do the substitution for the reload. */
4561 if (tem == reg_equiv_memory_loc[regno])
4562 tem = copy_rtx (tem);
4563 return tem;
4566 /* Record all reloads needed for handling memory address AD
4567 which appears in *LOC in a memory reference to mode MODE
4568 which itself is found in location *MEMREFLOC.
4569 Note that we take shortcuts assuming that no multi-reg machine mode
4570 occurs as part of an address.
4572 OPNUM and TYPE specify the purpose of this reload.
4574 IND_LEVELS says how many levels of indirect addressing this machine
4575 supports.
4577 INSN, if nonzero, is the insn in which we do the reload. It is used
4578 to determine if we may generate output reloads, and where to put USEs
4579 for pseudos that we have to replace with stack slots.
4581 Value is nonzero if this address is reloaded or replaced as a whole.
4582 This is interesting to the caller if the address is an autoincrement.
4584 Note that there is no verification that the address will be valid after
4585 this routine does its work. Instead, we rely on the fact that the address
4586 was valid when reload started. So we need only undo things that reload
4587 could have broken. These are wrong register types, pseudos not allocated
4588 to a hard register, and frame pointer elimination. */
4590 static int
4591 find_reloads_address (mode, memrefloc, ad, loc, opnum, type, ind_levels, insn)
4592 enum machine_mode mode;
4593 rtx *memrefloc;
4594 rtx ad;
4595 rtx *loc;
4596 int opnum;
4597 enum reload_type type;
4598 int ind_levels;
4599 rtx insn;
4601 int regno;
4602 int removed_and = 0;
4603 rtx tem;
4605 /* If the address is a register, see if it is a legitimate address and
4606 reload if not. We first handle the cases where we need not reload
4607 or where we must reload in a non-standard way. */
4609 if (GET_CODE (ad) == REG)
4611 regno = REGNO (ad);
4613 /* If the register is equivalent to an invariant expression, substitute
4614 the invariant, and eliminate any eliminable register references. */
4615 tem = reg_equiv_constant[regno];
4616 if (tem != 0
4617 && (tem = eliminate_regs (tem, mode, insn))
4618 && strict_memory_address_p (mode, tem))
4620 *loc = ad = tem;
4621 return 0;
4624 tem = reg_equiv_memory_loc[regno];
4625 if (tem != 0)
4627 if (reg_equiv_address[regno] != 0 || num_not_at_initial_offset)
4629 tem = make_memloc (ad, regno);
4630 if (! strict_memory_address_p (GET_MODE (tem), XEXP (tem, 0)))
4632 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
4633 &XEXP (tem, 0), opnum,
4634 ADDR_TYPE (type), ind_levels, insn);
4636 /* We can avoid a reload if the register's equivalent memory
4637 expression is valid as an indirect memory address.
4638 But not all addresses are valid in a mem used as an indirect
4639 address: only reg or reg+constant. */
4641 if (ind_levels > 0
4642 && strict_memory_address_p (mode, tem)
4643 && (GET_CODE (XEXP (tem, 0)) == REG
4644 || (GET_CODE (XEXP (tem, 0)) == PLUS
4645 && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG
4646 && CONSTANT_P (XEXP (XEXP (tem, 0), 1)))))
4648 /* TEM is not the same as what we'll be replacing the
4649 pseudo with after reload, put a USE in front of INSN
4650 in the final reload pass. */
4651 if (replace_reloads
4652 && num_not_at_initial_offset
4653 && ! rtx_equal_p (tem, reg_equiv_mem[regno]))
4655 *loc = tem;
4656 /* We mark the USE with QImode so that we
4657 recognize it as one that can be safely
4658 deleted at the end of reload. */
4659 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad),
4660 insn), QImode);
4662 /* This doesn't really count as replacing the address
4663 as a whole, since it is still a memory access. */
4665 return 0;
4667 ad = tem;
4671 /* The only remaining case where we can avoid a reload is if this is a
4672 hard register that is valid as a base register and which is not the
4673 subject of a CLOBBER in this insn. */
4675 else if (regno < FIRST_PSEUDO_REGISTER
4676 && REGNO_MODE_OK_FOR_BASE_P (regno, mode)
4677 && ! regno_clobbered_p (regno, this_insn, mode, 0))
4678 return 0;
4680 /* If we do not have one of the cases above, we must do the reload. */
4681 push_reload (ad, NULL_RTX, loc, (rtx*) 0, MODE_BASE_REG_CLASS (mode),
4682 GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
4683 return 1;
4686 if (strict_memory_address_p (mode, ad))
4688 /* The address appears valid, so reloads are not needed.
4689 But the address may contain an eliminable register.
4690 This can happen because a machine with indirect addressing
4691 may consider a pseudo register by itself a valid address even when
4692 it has failed to get a hard reg.
4693 So do a tree-walk to find and eliminate all such regs. */
4695 /* But first quickly dispose of a common case. */
4696 if (GET_CODE (ad) == PLUS
4697 && GET_CODE (XEXP (ad, 1)) == CONST_INT
4698 && GET_CODE (XEXP (ad, 0)) == REG
4699 && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
4700 return 0;
4702 subst_reg_equivs_changed = 0;
4703 *loc = subst_reg_equivs (ad, insn);
4705 if (! subst_reg_equivs_changed)
4706 return 0;
4708 /* Check result for validity after substitution. */
4709 if (strict_memory_address_p (mode, ad))
4710 return 0;
4713 #ifdef LEGITIMIZE_RELOAD_ADDRESS
4716 if (memrefloc)
4718 LEGITIMIZE_RELOAD_ADDRESS (ad, GET_MODE (*memrefloc), opnum, type,
4719 ind_levels, win);
4721 break;
4722 win:
4723 *memrefloc = copy_rtx (*memrefloc);
4724 XEXP (*memrefloc, 0) = ad;
4725 move_replacements (&ad, &XEXP (*memrefloc, 0));
4726 return 1;
4728 while (0);
4729 #endif
4731 /* The address is not valid. We have to figure out why. First see if
4732 we have an outer AND and remove it if so. Then analyze what's inside. */
4734 if (GET_CODE (ad) == AND)
4736 removed_and = 1;
4737 loc = &XEXP (ad, 0);
4738 ad = *loc;
4741 /* One possibility for why the address is invalid is that it is itself
4742 a MEM. This can happen when the frame pointer is being eliminated, a
4743 pseudo is not allocated to a hard register, and the offset between the
4744 frame and stack pointers is not its initial value. In that case the
4745 pseudo will have been replaced by a MEM referring to the
4746 stack pointer. */
4747 if (GET_CODE (ad) == MEM)
4749 /* First ensure that the address in this MEM is valid. Then, unless
4750 indirect addresses are valid, reload the MEM into a register. */
4751 tem = ad;
4752 find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
4753 opnum, ADDR_TYPE (type),
4754 ind_levels == 0 ? 0 : ind_levels - 1, insn);
4756 /* If tem was changed, then we must create a new memory reference to
4757 hold it and store it back into memrefloc. */
4758 if (tem != ad && memrefloc)
4760 *memrefloc = copy_rtx (*memrefloc);
4761 copy_replacements (tem, XEXP (*memrefloc, 0));
4762 loc = &XEXP (*memrefloc, 0);
4763 if (removed_and)
4764 loc = &XEXP (*loc, 0);
4767 /* Check similar cases as for indirect addresses as above except
4768 that we can allow pseudos and a MEM since they should have been
4769 taken care of above. */
4771 if (ind_levels == 0
4772 || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
4773 || GET_CODE (XEXP (tem, 0)) == MEM
4774 || ! (GET_CODE (XEXP (tem, 0)) == REG
4775 || (GET_CODE (XEXP (tem, 0)) == PLUS
4776 && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG
4777 && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT)))
4779 /* Must use TEM here, not AD, since it is the one that will
4780 have any subexpressions reloaded, if needed. */
4781 push_reload (tem, NULL_RTX, loc, (rtx*) 0,
4782 MODE_BASE_REG_CLASS (mode), GET_MODE (tem),
4783 VOIDmode, 0,
4784 0, opnum, type);
4785 return ! removed_and;
4787 else
4788 return 0;
4791 /* If we have address of a stack slot but it's not valid because the
4792 displacement is too large, compute the sum in a register.
4793 Handle all base registers here, not just fp/ap/sp, because on some
4794 targets (namely SH) we can also get too large displacements from
4795 big-endian corrections. */
4796 else if (GET_CODE (ad) == PLUS
4797 && GET_CODE (XEXP (ad, 0)) == REG
4798 && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
4799 && REG_MODE_OK_FOR_BASE_P (XEXP (ad, 0), mode)
4800 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4802 /* Unshare the MEM rtx so we can safely alter it. */
4803 if (memrefloc)
4805 *memrefloc = copy_rtx (*memrefloc);
4806 loc = &XEXP (*memrefloc, 0);
4807 if (removed_and)
4808 loc = &XEXP (*loc, 0);
4811 if (double_reg_address_ok)
4813 /* Unshare the sum as well. */
4814 *loc = ad = copy_rtx (ad);
4816 /* Reload the displacement into an index reg.
4817 We assume the frame pointer or arg pointer is a base reg. */
4818 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4819 INDEX_REG_CLASS, GET_MODE (ad), opnum,
4820 type, ind_levels);
4821 return 0;
4823 else
4825 /* If the sum of two regs is not necessarily valid,
4826 reload the sum into a base reg.
4827 That will at least work. */
4828 find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode),
4829 Pmode, opnum, type, ind_levels);
4831 return ! removed_and;
4834 /* If we have an indexed stack slot, there are three possible reasons why
4835 it might be invalid: The index might need to be reloaded, the address
4836 might have been made by frame pointer elimination and hence have a
4837 constant out of range, or both reasons might apply.
4839 We can easily check for an index needing reload, but even if that is the
4840 case, we might also have an invalid constant. To avoid making the
4841 conservative assumption and requiring two reloads, we see if this address
4842 is valid when not interpreted strictly. If it is, the only problem is
4843 that the index needs a reload and find_reloads_address_1 will take care
4844 of it.
4846 If we decide to do something here, it must be that
4847 `double_reg_address_ok' is true and that this address rtl was made by
4848 eliminate_regs. We generate a reload of the fp/sp/ap + constant and
4849 rework the sum so that the reload register will be added to the index.
4850 This is safe because we know the address isn't shared.
4852 We check for fp/ap/sp as both the first and second operand of the
4853 innermost PLUS. */
4855 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4856 && GET_CODE (XEXP (ad, 0)) == PLUS
4857 && (XEXP (XEXP (ad, 0), 0) == frame_pointer_rtx
4858 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
4859 || XEXP (XEXP (ad, 0), 0) == hard_frame_pointer_rtx
4860 #endif
4861 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4862 || XEXP (XEXP (ad, 0), 0) == arg_pointer_rtx
4863 #endif
4864 || XEXP (XEXP (ad, 0), 0) == stack_pointer_rtx)
4865 && ! memory_address_p (mode, ad))
4867 *loc = ad = gen_rtx_PLUS (GET_MODE (ad),
4868 plus_constant (XEXP (XEXP (ad, 0), 0),
4869 INTVAL (XEXP (ad, 1))),
4870 XEXP (XEXP (ad, 0), 1));
4871 find_reloads_address_part (XEXP (ad, 0), &XEXP (ad, 0),
4872 MODE_BASE_REG_CLASS (mode),
4873 GET_MODE (ad), opnum, type, ind_levels);
4874 find_reloads_address_1 (mode, XEXP (ad, 1), 1, &XEXP (ad, 1), opnum,
4875 type, 0, insn);
4877 return 0;
4880 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4881 && GET_CODE (XEXP (ad, 0)) == PLUS
4882 && (XEXP (XEXP (ad, 0), 1) == frame_pointer_rtx
4883 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4884 || XEXP (XEXP (ad, 0), 1) == hard_frame_pointer_rtx
4885 #endif
4886 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4887 || XEXP (XEXP (ad, 0), 1) == arg_pointer_rtx
4888 #endif
4889 || XEXP (XEXP (ad, 0), 1) == stack_pointer_rtx)
4890 && ! memory_address_p (mode, ad))
4892 *loc = ad = gen_rtx_PLUS (GET_MODE (ad),
4893 XEXP (XEXP (ad, 0), 0),
4894 plus_constant (XEXP (XEXP (ad, 0), 1),
4895 INTVAL (XEXP (ad, 1))));
4896 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4897 MODE_BASE_REG_CLASS (mode),
4898 GET_MODE (ad), opnum, type, ind_levels);
4899 find_reloads_address_1 (mode, XEXP (ad, 0), 1, &XEXP (ad, 0), opnum,
4900 type, 0, insn);
4902 return 0;
4905 /* See if address becomes valid when an eliminable register
4906 in a sum is replaced. */
4908 tem = ad;
4909 if (GET_CODE (ad) == PLUS)
4910 tem = subst_indexed_address (ad);
4911 if (tem != ad && strict_memory_address_p (mode, tem))
4913 /* Ok, we win that way. Replace any additional eliminable
4914 registers. */
4916 subst_reg_equivs_changed = 0;
4917 tem = subst_reg_equivs (tem, insn);
4919 /* Make sure that didn't make the address invalid again. */
4921 if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
4923 *loc = tem;
4924 return 0;
4928 /* If constants aren't valid addresses, reload the constant address
4929 into a register. */
4930 if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad))
4932 /* If AD is an address in the constant pool, the MEM rtx may be shared.
4933 Unshare it so we can safely alter it. */
4934 if (memrefloc && GET_CODE (ad) == SYMBOL_REF
4935 && CONSTANT_POOL_ADDRESS_P (ad))
4937 *memrefloc = copy_rtx (*memrefloc);
4938 loc = &XEXP (*memrefloc, 0);
4939 if (removed_and)
4940 loc = &XEXP (*loc, 0);
4943 find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode),
4944 Pmode, opnum, type, ind_levels);
4945 return ! removed_and;
4948 return find_reloads_address_1 (mode, ad, 0, loc, opnum, type, ind_levels,
4949 insn);
4952 /* Find all pseudo regs appearing in AD
4953 that are eliminable in favor of equivalent values
4954 and do not have hard regs; replace them by their equivalents.
4955 INSN, if nonzero, is the insn in which we do the reload. We put USEs in
4956 front of it for pseudos that we have to replace with stack slots. */
4958 static rtx
4959 subst_reg_equivs (ad, insn)
4960 rtx ad;
4961 rtx insn;
4963 RTX_CODE code = GET_CODE (ad);
4964 int i;
4965 const char *fmt;
4967 switch (code)
4969 case HIGH:
4970 case CONST_INT:
4971 case CONST:
4972 case CONST_DOUBLE:
4973 case CONST_VECTOR:
4974 case SYMBOL_REF:
4975 case LABEL_REF:
4976 case PC:
4977 case CC0:
4978 return ad;
4980 case REG:
4982 int regno = REGNO (ad);
4984 if (reg_equiv_constant[regno] != 0)
4986 subst_reg_equivs_changed = 1;
4987 return reg_equiv_constant[regno];
4989 if (reg_equiv_memory_loc[regno] && num_not_at_initial_offset)
4991 rtx mem = make_memloc (ad, regno);
4992 if (! rtx_equal_p (mem, reg_equiv_mem[regno]))
4994 subst_reg_equivs_changed = 1;
4995 /* We mark the USE with QImode so that we recognize it
4996 as one that can be safely deleted at the end of
4997 reload. */
4998 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad), insn),
4999 QImode);
5000 return mem;
5004 return ad;
5006 case PLUS:
5007 /* Quickly dispose of a common case. */
5008 if (XEXP (ad, 0) == frame_pointer_rtx
5009 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
5010 return ad;
5011 break;
5013 default:
5014 break;
5017 fmt = GET_RTX_FORMAT (code);
5018 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5019 if (fmt[i] == 'e')
5020 XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i), insn);
5021 return ad;
5024 /* Compute the sum of X and Y, making canonicalizations assumed in an
5025 address, namely: sum constant integers, surround the sum of two
5026 constants with a CONST, put the constant as the second operand, and
5027 group the constant on the outermost sum.
5029 This routine assumes both inputs are already in canonical form. */
5032 form_sum (x, y)
5033 rtx x, y;
5035 rtx tem;
5036 enum machine_mode mode = GET_MODE (x);
5038 if (mode == VOIDmode)
5039 mode = GET_MODE (y);
5041 if (mode == VOIDmode)
5042 mode = Pmode;
5044 if (GET_CODE (x) == CONST_INT)
5045 return plus_constant (y, INTVAL (x));
5046 else if (GET_CODE (y) == CONST_INT)
5047 return plus_constant (x, INTVAL (y));
5048 else if (CONSTANT_P (x))
5049 tem = x, x = y, y = tem;
5051 if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
5052 return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
5054 /* Note that if the operands of Y are specified in the opposite
5055 order in the recursive calls below, infinite recursion will occur. */
5056 if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
5057 return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
5059 /* If both constant, encapsulate sum. Otherwise, just form sum. A
5060 constant will have been placed second. */
5061 if (CONSTANT_P (x) && CONSTANT_P (y))
5063 if (GET_CODE (x) == CONST)
5064 x = XEXP (x, 0);
5065 if (GET_CODE (y) == CONST)
5066 y = XEXP (y, 0);
5068 return gen_rtx_CONST (VOIDmode, gen_rtx_PLUS (mode, x, y));
5071 return gen_rtx_PLUS (mode, x, y);
5074 /* If ADDR is a sum containing a pseudo register that should be
5075 replaced with a constant (from reg_equiv_constant),
5076 return the result of doing so, and also apply the associative
5077 law so that the result is more likely to be a valid address.
5078 (But it is not guaranteed to be one.)
5080 Note that at most one register is replaced, even if more are
5081 replaceable. Also, we try to put the result into a canonical form
5082 so it is more likely to be a valid address.
5084 In all other cases, return ADDR. */
5086 static rtx
5087 subst_indexed_address (addr)
5088 rtx addr;
5090 rtx op0 = 0, op1 = 0, op2 = 0;
5091 rtx tem;
5092 int regno;
5094 if (GET_CODE (addr) == PLUS)
5096 /* Try to find a register to replace. */
5097 op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
5098 if (GET_CODE (op0) == REG
5099 && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
5100 && reg_renumber[regno] < 0
5101 && reg_equiv_constant[regno] != 0)
5102 op0 = reg_equiv_constant[regno];
5103 else if (GET_CODE (op1) == REG
5104 && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
5105 && reg_renumber[regno] < 0
5106 && reg_equiv_constant[regno] != 0)
5107 op1 = reg_equiv_constant[regno];
5108 else if (GET_CODE (op0) == PLUS
5109 && (tem = subst_indexed_address (op0)) != op0)
5110 op0 = tem;
5111 else if (GET_CODE (op1) == PLUS
5112 && (tem = subst_indexed_address (op1)) != op1)
5113 op1 = tem;
5114 else
5115 return addr;
5117 /* Pick out up to three things to add. */
5118 if (GET_CODE (op1) == PLUS)
5119 op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
5120 else if (GET_CODE (op0) == PLUS)
5121 op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
5123 /* Compute the sum. */
5124 if (op2 != 0)
5125 op1 = form_sum (op1, op2);
5126 if (op1 != 0)
5127 op0 = form_sum (op0, op1);
5129 return op0;
5131 return addr;
5134 /* Update the REG_INC notes for an insn. It updates all REG_INC
5135 notes for the instruction which refer to REGNO the to refer
5136 to the reload number.
5138 INSN is the insn for which any REG_INC notes need updating.
5140 REGNO is the register number which has been reloaded.
5142 RELOADNUM is the reload number. */
5144 static void
5145 update_auto_inc_notes (insn, regno, reloadnum)
5146 rtx insn ATTRIBUTE_UNUSED;
5147 int regno ATTRIBUTE_UNUSED;
5148 int reloadnum ATTRIBUTE_UNUSED;
5150 #ifdef AUTO_INC_DEC
5151 rtx link;
5153 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
5154 if (REG_NOTE_KIND (link) == REG_INC
5155 && REGNO (XEXP (link, 0)) == regno)
5156 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5157 #endif
5160 /* Record the pseudo registers we must reload into hard registers in a
5161 subexpression of a would-be memory address, X referring to a value
5162 in mode MODE. (This function is not called if the address we find
5163 is strictly valid.)
5165 CONTEXT = 1 means we are considering regs as index regs,
5166 = 0 means we are considering them as base regs.
5168 OPNUM and TYPE specify the purpose of any reloads made.
5170 IND_LEVELS says how many levels of indirect addressing are
5171 supported at this point in the address.
5173 INSN, if nonzero, is the insn in which we do the reload. It is used
5174 to determine if we may generate output reloads.
5176 We return nonzero if X, as a whole, is reloaded or replaced. */
5178 /* Note that we take shortcuts assuming that no multi-reg machine mode
5179 occurs as part of an address.
5180 Also, this is not fully machine-customizable; it works for machines
5181 such as VAXen and 68000's and 32000's, but other possible machines
5182 could have addressing modes that this does not handle right. */
5184 static int
5185 find_reloads_address_1 (mode, x, context, loc, opnum, type, ind_levels, insn)
5186 enum machine_mode mode;
5187 rtx x;
5188 int context;
5189 rtx *loc;
5190 int opnum;
5191 enum reload_type type;
5192 int ind_levels;
5193 rtx insn;
5195 RTX_CODE code = GET_CODE (x);
5197 switch (code)
5199 case PLUS:
5201 rtx orig_op0 = XEXP (x, 0);
5202 rtx orig_op1 = XEXP (x, 1);
5203 RTX_CODE code0 = GET_CODE (orig_op0);
5204 RTX_CODE code1 = GET_CODE (orig_op1);
5205 rtx op0 = orig_op0;
5206 rtx op1 = orig_op1;
5208 if (GET_CODE (op0) == SUBREG)
5210 op0 = SUBREG_REG (op0);
5211 code0 = GET_CODE (op0);
5212 if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER)
5213 op0 = gen_rtx_REG (word_mode,
5214 (REGNO (op0) +
5215 subreg_regno_offset (REGNO (SUBREG_REG (orig_op0)),
5216 GET_MODE (SUBREG_REG (orig_op0)),
5217 SUBREG_BYTE (orig_op0),
5218 GET_MODE (orig_op0))));
5221 if (GET_CODE (op1) == SUBREG)
5223 op1 = SUBREG_REG (op1);
5224 code1 = GET_CODE (op1);
5225 if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER)
5226 /* ??? Why is this given op1's mode and above for
5227 ??? op0 SUBREGs we use word_mode? */
5228 op1 = gen_rtx_REG (GET_MODE (op1),
5229 (REGNO (op1) +
5230 subreg_regno_offset (REGNO (SUBREG_REG (orig_op1)),
5231 GET_MODE (SUBREG_REG (orig_op1)),
5232 SUBREG_BYTE (orig_op1),
5233 GET_MODE (orig_op1))));
5236 if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
5237 || code0 == ZERO_EXTEND || code1 == MEM)
5239 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5240 type, ind_levels, insn);
5241 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5242 type, ind_levels, insn);
5245 else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
5246 || code1 == ZERO_EXTEND || code0 == MEM)
5248 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5249 type, ind_levels, insn);
5250 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5251 type, ind_levels, insn);
5254 else if (code0 == CONST_INT || code0 == CONST
5255 || code0 == SYMBOL_REF || code0 == LABEL_REF)
5256 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5257 type, ind_levels, insn);
5259 else if (code1 == CONST_INT || code1 == CONST
5260 || code1 == SYMBOL_REF || code1 == LABEL_REF)
5261 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5262 type, ind_levels, insn);
5264 else if (code0 == REG && code1 == REG)
5266 if (REG_OK_FOR_INDEX_P (op0)
5267 && REG_MODE_OK_FOR_BASE_P (op1, mode))
5268 return 0;
5269 else if (REG_OK_FOR_INDEX_P (op1)
5270 && REG_MODE_OK_FOR_BASE_P (op0, mode))
5271 return 0;
5272 else if (REG_MODE_OK_FOR_BASE_P (op1, mode))
5273 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5274 type, ind_levels, insn);
5275 else if (REG_MODE_OK_FOR_BASE_P (op0, mode))
5276 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5277 type, ind_levels, insn);
5278 else if (REG_OK_FOR_INDEX_P (op1))
5279 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5280 type, ind_levels, insn);
5281 else if (REG_OK_FOR_INDEX_P (op0))
5282 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5283 type, ind_levels, insn);
5284 else
5286 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5287 type, ind_levels, insn);
5288 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5289 type, ind_levels, insn);
5293 else if (code0 == REG)
5295 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5296 type, ind_levels, insn);
5297 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5298 type, ind_levels, insn);
5301 else if (code1 == REG)
5303 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5304 type, ind_levels, insn);
5305 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5306 type, ind_levels, insn);
5310 return 0;
5312 case POST_MODIFY:
5313 case PRE_MODIFY:
5315 rtx op0 = XEXP (x, 0);
5316 rtx op1 = XEXP (x, 1);
5318 if (GET_CODE (op1) != PLUS && GET_CODE (op1) != MINUS)
5319 return 0;
5321 /* Currently, we only support {PRE,POST}_MODIFY constructs
5322 where a base register is {inc,dec}remented by the contents
5323 of another register or by a constant value. Thus, these
5324 operands must match. */
5325 if (op0 != XEXP (op1, 0))
5326 abort ();
5328 /* Require index register (or constant). Let's just handle the
5329 register case in the meantime... If the target allows
5330 auto-modify by a constant then we could try replacing a pseudo
5331 register with its equivalent constant where applicable. */
5332 if (REG_P (XEXP (op1, 1)))
5333 if (!REGNO_OK_FOR_INDEX_P (REGNO (XEXP (op1, 1))))
5334 find_reloads_address_1 (mode, XEXP (op1, 1), 1, &XEXP (op1, 1),
5335 opnum, type, ind_levels, insn);
5337 if (REG_P (XEXP (op1, 0)))
5339 int regno = REGNO (XEXP (op1, 0));
5340 int reloadnum;
5342 /* A register that is incremented cannot be constant! */
5343 if (regno >= FIRST_PSEUDO_REGISTER
5344 && reg_equiv_constant[regno] != 0)
5345 abort ();
5347 /* Handle a register that is equivalent to a memory location
5348 which cannot be addressed directly. */
5349 if (reg_equiv_memory_loc[regno] != 0
5350 && (reg_equiv_address[regno] != 0
5351 || num_not_at_initial_offset))
5353 rtx tem = make_memloc (XEXP (x, 0), regno);
5355 if (reg_equiv_address[regno]
5356 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5358 /* First reload the memory location's address.
5359 We can't use ADDR_TYPE (type) here, because we need to
5360 write back the value after reading it, hence we actually
5361 need two registers. */
5362 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5363 &XEXP (tem, 0), opnum,
5364 RELOAD_OTHER,
5365 ind_levels, insn);
5367 /* Then reload the memory location into a base
5368 register. */
5369 reloadnum = push_reload (tem, tem, &XEXP (x, 0),
5370 &XEXP (op1, 0),
5371 MODE_BASE_REG_CLASS (mode),
5372 GET_MODE (x), GET_MODE (x), 0,
5373 0, opnum, RELOAD_OTHER);
5375 update_auto_inc_notes (this_insn, regno, reloadnum);
5376 return 0;
5380 if (reg_renumber[regno] >= 0)
5381 regno = reg_renumber[regno];
5383 /* We require a base register here... */
5384 if (!REGNO_MODE_OK_FOR_BASE_P (regno, GET_MODE (x)))
5386 reloadnum = push_reload (XEXP (op1, 0), XEXP (x, 0),
5387 &XEXP (op1, 0), &XEXP (x, 0),
5388 MODE_BASE_REG_CLASS (mode),
5389 GET_MODE (x), GET_MODE (x), 0, 0,
5390 opnum, RELOAD_OTHER);
5392 update_auto_inc_notes (this_insn, regno, reloadnum);
5393 return 0;
5396 else
5397 abort ();
5399 return 0;
5401 case POST_INC:
5402 case POST_DEC:
5403 case PRE_INC:
5404 case PRE_DEC:
5405 if (GET_CODE (XEXP (x, 0)) == REG)
5407 int regno = REGNO (XEXP (x, 0));
5408 int value = 0;
5409 rtx x_orig = x;
5411 /* A register that is incremented cannot be constant! */
5412 if (regno >= FIRST_PSEUDO_REGISTER
5413 && reg_equiv_constant[regno] != 0)
5414 abort ();
5416 /* Handle a register that is equivalent to a memory location
5417 which cannot be addressed directly. */
5418 if (reg_equiv_memory_loc[regno] != 0
5419 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5421 rtx tem = make_memloc (XEXP (x, 0), regno);
5422 if (reg_equiv_address[regno]
5423 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5425 /* First reload the memory location's address.
5426 We can't use ADDR_TYPE (type) here, because we need to
5427 write back the value after reading it, hence we actually
5428 need two registers. */
5429 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5430 &XEXP (tem, 0), opnum, type,
5431 ind_levels, insn);
5432 /* Put this inside a new increment-expression. */
5433 x = gen_rtx_fmt_e (GET_CODE (x), GET_MODE (x), tem);
5434 /* Proceed to reload that, as if it contained a register. */
5438 /* If we have a hard register that is ok as an index,
5439 don't make a reload. If an autoincrement of a nice register
5440 isn't "valid", it must be that no autoincrement is "valid".
5441 If that is true and something made an autoincrement anyway,
5442 this must be a special context where one is allowed.
5443 (For example, a "push" instruction.)
5444 We can't improve this address, so leave it alone. */
5446 /* Otherwise, reload the autoincrement into a suitable hard reg
5447 and record how much to increment by. */
5449 if (reg_renumber[regno] >= 0)
5450 regno = reg_renumber[regno];
5451 if ((regno >= FIRST_PSEUDO_REGISTER
5452 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
5453 : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
5455 int reloadnum;
5457 /* If we can output the register afterwards, do so, this
5458 saves the extra update.
5459 We can do so if we have an INSN - i.e. no JUMP_INSN nor
5460 CALL_INSN - and it does not set CC0.
5461 But don't do this if we cannot directly address the
5462 memory location, since this will make it harder to
5463 reuse address reloads, and increases register pressure.
5464 Also don't do this if we can probably update x directly. */
5465 rtx equiv = (GET_CODE (XEXP (x, 0)) == MEM
5466 ? XEXP (x, 0)
5467 : reg_equiv_mem[regno]);
5468 int icode = (int) add_optab->handlers[(int) Pmode].insn_code;
5469 if (insn && GET_CODE (insn) == INSN && equiv
5470 && memory_operand (equiv, GET_MODE (equiv))
5471 #ifdef HAVE_cc0
5472 && ! sets_cc0_p (PATTERN (insn))
5473 #endif
5474 && ! (icode != CODE_FOR_nothing
5475 && ((*insn_data[icode].operand[0].predicate)
5476 (equiv, Pmode))
5477 && ((*insn_data[icode].operand[1].predicate)
5478 (equiv, Pmode))))
5480 /* We use the original pseudo for loc, so that
5481 emit_reload_insns() knows which pseudo this
5482 reload refers to and updates the pseudo rtx, not
5483 its equivalent memory location, as well as the
5484 corresponding entry in reg_last_reload_reg. */
5485 loc = &XEXP (x_orig, 0);
5486 x = XEXP (x, 0);
5487 reloadnum
5488 = push_reload (x, x, loc, loc,
5489 (context ? INDEX_REG_CLASS :
5490 MODE_BASE_REG_CLASS (mode)),
5491 GET_MODE (x), GET_MODE (x), 0, 0,
5492 opnum, RELOAD_OTHER);
5494 else
5496 reloadnum
5497 = push_reload (x, NULL_RTX, loc, (rtx*) 0,
5498 (context ? INDEX_REG_CLASS :
5499 MODE_BASE_REG_CLASS (mode)),
5500 GET_MODE (x), GET_MODE (x), 0, 0,
5501 opnum, type);
5502 rld[reloadnum].inc
5503 = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
5505 value = 1;
5508 update_auto_inc_notes (this_insn, REGNO (XEXP (x_orig, 0)),
5509 reloadnum);
5511 return value;
5514 else if (GET_CODE (XEXP (x, 0)) == MEM)
5516 /* This is probably the result of a substitution, by eliminate_regs,
5517 of an equivalent address for a pseudo that was not allocated to a
5518 hard register. Verify that the specified address is valid and
5519 reload it into a register. */
5520 /* Variable `tem' might or might not be used in FIND_REG_INC_NOTE. */
5521 rtx tem ATTRIBUTE_UNUSED = XEXP (x, 0);
5522 rtx link;
5523 int reloadnum;
5525 /* Since we know we are going to reload this item, don't decrement
5526 for the indirection level.
5528 Note that this is actually conservative: it would be slightly
5529 more efficient to use the value of SPILL_INDIRECT_LEVELS from
5530 reload1.c here. */
5531 /* We can't use ADDR_TYPE (type) here, because we need to
5532 write back the value after reading it, hence we actually
5533 need two registers. */
5534 find_reloads_address (GET_MODE (x), &XEXP (x, 0),
5535 XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0),
5536 opnum, type, ind_levels, insn);
5538 reloadnum = push_reload (x, NULL_RTX, loc, (rtx*) 0,
5539 (context ? INDEX_REG_CLASS :
5540 MODE_BASE_REG_CLASS (mode)),
5541 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5542 rld[reloadnum].inc
5543 = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
5545 link = FIND_REG_INC_NOTE (this_insn, tem);
5546 if (link != 0)
5547 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5549 return 1;
5551 return 0;
5553 case MEM:
5554 /* This is probably the result of a substitution, by eliminate_regs, of
5555 an equivalent address for a pseudo that was not allocated to a hard
5556 register. Verify that the specified address is valid and reload it
5557 into a register.
5559 Since we know we are going to reload this item, don't decrement for
5560 the indirection level.
5562 Note that this is actually conservative: it would be slightly more
5563 efficient to use the value of SPILL_INDIRECT_LEVELS from
5564 reload1.c here. */
5566 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5567 opnum, ADDR_TYPE (type), ind_levels, insn);
5568 push_reload (*loc, NULL_RTX, loc, (rtx*) 0,
5569 (context ? INDEX_REG_CLASS : MODE_BASE_REG_CLASS (mode)),
5570 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5571 return 1;
5573 case REG:
5575 int regno = REGNO (x);
5577 if (reg_equiv_constant[regno] != 0)
5579 find_reloads_address_part (reg_equiv_constant[regno], loc,
5580 (context ? INDEX_REG_CLASS :
5581 MODE_BASE_REG_CLASS (mode)),
5582 GET_MODE (x), opnum, type, ind_levels);
5583 return 1;
5586 #if 0 /* This might screw code in reload1.c to delete prior output-reload
5587 that feeds this insn. */
5588 if (reg_equiv_mem[regno] != 0)
5590 push_reload (reg_equiv_mem[regno], NULL_RTX, loc, (rtx*) 0,
5591 (context ? INDEX_REG_CLASS :
5592 MODE_BASE_REG_CLASS (mode)),
5593 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5594 return 1;
5596 #endif
5598 if (reg_equiv_memory_loc[regno]
5599 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5601 rtx tem = make_memloc (x, regno);
5602 if (reg_equiv_address[regno] != 0
5603 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5605 x = tem;
5606 find_reloads_address (GET_MODE (x), &x, XEXP (x, 0),
5607 &XEXP (x, 0), opnum, ADDR_TYPE (type),
5608 ind_levels, insn);
5612 if (reg_renumber[regno] >= 0)
5613 regno = reg_renumber[regno];
5615 if ((regno >= FIRST_PSEUDO_REGISTER
5616 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
5617 : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
5619 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5620 (context ? INDEX_REG_CLASS : MODE_BASE_REG_CLASS (mode)),
5621 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5622 return 1;
5625 /* If a register appearing in an address is the subject of a CLOBBER
5626 in this insn, reload it into some other register to be safe.
5627 The CLOBBER is supposed to make the register unavailable
5628 from before this insn to after it. */
5629 if (regno_clobbered_p (regno, this_insn, GET_MODE (x), 0))
5631 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5632 (context ? INDEX_REG_CLASS : MODE_BASE_REG_CLASS (mode)),
5633 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5634 return 1;
5637 return 0;
5639 case SUBREG:
5640 if (GET_CODE (SUBREG_REG (x)) == REG)
5642 /* If this is a SUBREG of a hard register and the resulting register
5643 is of the wrong class, reload the whole SUBREG. This avoids
5644 needless copies if SUBREG_REG is multi-word. */
5645 if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5647 int regno ATTRIBUTE_UNUSED = subreg_regno (x);
5649 if (! (context ? REGNO_OK_FOR_INDEX_P (regno)
5650 : REGNO_MODE_OK_FOR_BASE_P (regno, mode)))
5652 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5653 (context ? INDEX_REG_CLASS :
5654 MODE_BASE_REG_CLASS (mode)),
5655 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5656 return 1;
5659 /* If this is a SUBREG of a pseudo-register, and the pseudo-register
5660 is larger than the class size, then reload the whole SUBREG. */
5661 else
5663 enum reg_class class = (context ? INDEX_REG_CLASS
5664 : MODE_BASE_REG_CLASS (mode));
5665 if ((unsigned) CLASS_MAX_NREGS (class, GET_MODE (SUBREG_REG (x)))
5666 > reg_class_size[class])
5668 x = find_reloads_subreg_address (x, 0, opnum, type,
5669 ind_levels, insn);
5670 push_reload (x, NULL_RTX, loc, (rtx*) 0, class,
5671 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5672 return 1;
5676 break;
5678 default:
5679 break;
5683 const char *fmt = GET_RTX_FORMAT (code);
5684 int i;
5686 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5688 if (fmt[i] == 'e')
5689 find_reloads_address_1 (mode, XEXP (x, i), context, &XEXP (x, i),
5690 opnum, type, ind_levels, insn);
5694 return 0;
5697 /* X, which is found at *LOC, is a part of an address that needs to be
5698 reloaded into a register of class CLASS. If X is a constant, or if
5699 X is a PLUS that contains a constant, check that the constant is a
5700 legitimate operand and that we are supposed to be able to load
5701 it into the register.
5703 If not, force the constant into memory and reload the MEM instead.
5705 MODE is the mode to use, in case X is an integer constant.
5707 OPNUM and TYPE describe the purpose of any reloads made.
5709 IND_LEVELS says how many levels of indirect addressing this machine
5710 supports. */
5712 static void
5713 find_reloads_address_part (x, loc, class, mode, opnum, type, ind_levels)
5714 rtx x;
5715 rtx *loc;
5716 enum reg_class class;
5717 enum machine_mode mode;
5718 int opnum;
5719 enum reload_type type;
5720 int ind_levels;
5722 if (CONSTANT_P (x)
5723 && (! LEGITIMATE_CONSTANT_P (x)
5724 || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
5726 rtx tem;
5728 tem = x = force_const_mem (mode, x);
5729 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5730 opnum, type, ind_levels, 0);
5733 else if (GET_CODE (x) == PLUS
5734 && CONSTANT_P (XEXP (x, 1))
5735 && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
5736 || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
5738 rtx tem;
5740 tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
5741 x = gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), tem);
5742 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5743 opnum, type, ind_levels, 0);
5746 push_reload (x, NULL_RTX, loc, (rtx*) 0, class,
5747 mode, VOIDmode, 0, 0, opnum, type);
5750 /* X, a subreg of a pseudo, is a part of an address that needs to be
5751 reloaded.
5753 If the pseudo is equivalent to a memory location that cannot be directly
5754 addressed, make the necessary address reloads.
5756 If address reloads have been necessary, or if the address is changed
5757 by register elimination, return the rtx of the memory location;
5758 otherwise, return X.
5760 If FORCE_REPLACE is nonzero, unconditionally replace the subreg with the
5761 memory location.
5763 OPNUM and TYPE identify the purpose of the reload.
5765 IND_LEVELS says how many levels of indirect addressing are
5766 supported at this point in the address.
5768 INSN, if nonzero, is the insn in which we do the reload. It is used
5769 to determine where to put USEs for pseudos that we have to replace with
5770 stack slots. */
5772 static rtx
5773 find_reloads_subreg_address (x, force_replace, opnum, type,
5774 ind_levels, insn)
5775 rtx x;
5776 int force_replace;
5777 int opnum;
5778 enum reload_type type;
5779 int ind_levels;
5780 rtx insn;
5782 int regno = REGNO (SUBREG_REG (x));
5784 if (reg_equiv_memory_loc[regno])
5786 /* If the address is not directly addressable, or if the address is not
5787 offsettable, then it must be replaced. */
5788 if (! force_replace
5789 && (reg_equiv_address[regno]
5790 || ! offsettable_memref_p (reg_equiv_mem[regno])))
5791 force_replace = 1;
5793 if (force_replace || num_not_at_initial_offset)
5795 rtx tem = make_memloc (SUBREG_REG (x), regno);
5797 /* If the address changes because of register elimination, then
5798 it must be replaced. */
5799 if (force_replace
5800 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5802 int offset = SUBREG_BYTE (x);
5803 unsigned outer_size = GET_MODE_SIZE (GET_MODE (x));
5804 unsigned inner_size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
5806 XEXP (tem, 0) = plus_constant (XEXP (tem, 0), offset);
5807 PUT_MODE (tem, GET_MODE (x));
5809 /* If this was a paradoxical subreg that we replaced, the
5810 resulting memory must be sufficiently aligned to allow
5811 us to widen the mode of the memory. */
5812 if (outer_size > inner_size && STRICT_ALIGNMENT)
5814 rtx base;
5816 base = XEXP (tem, 0);
5817 if (GET_CODE (base) == PLUS)
5819 if (GET_CODE (XEXP (base, 1)) == CONST_INT
5820 && INTVAL (XEXP (base, 1)) % outer_size != 0)
5821 return x;
5822 base = XEXP (base, 0);
5824 if (GET_CODE (base) != REG
5825 || (REGNO_POINTER_ALIGN (REGNO (base))
5826 < outer_size * BITS_PER_UNIT))
5827 return x;
5830 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5831 &XEXP (tem, 0), opnum, ADDR_TYPE (type),
5832 ind_levels, insn);
5834 /* If this is not a toplevel operand, find_reloads doesn't see
5835 this substitution. We have to emit a USE of the pseudo so
5836 that delete_output_reload can see it. */
5837 if (replace_reloads && recog_data.operand[opnum] != x)
5838 /* We mark the USE with QImode so that we recognize it
5839 as one that can be safely deleted at the end of
5840 reload. */
5841 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode,
5842 SUBREG_REG (x)),
5843 insn), QImode);
5844 x = tem;
5848 return x;
5851 /* Substitute into the current INSN the registers into which we have reloaded
5852 the things that need reloading. The array `replacements'
5853 contains the locations of all pointers that must be changed
5854 and says what to replace them with.
5856 Return the rtx that X translates into; usually X, but modified. */
5858 void
5859 subst_reloads (insn)
5860 rtx insn;
5862 int i;
5864 for (i = 0; i < n_replacements; i++)
5866 struct replacement *r = &replacements[i];
5867 rtx reloadreg = rld[r->what].reg_rtx;
5868 if (reloadreg)
5870 #ifdef ENABLE_CHECKING
5871 /* Internal consistency test. Check that we don't modify
5872 anything in the equivalence arrays. Whenever something from
5873 those arrays needs to be reloaded, it must be unshared before
5874 being substituted into; the equivalence must not be modified.
5875 Otherwise, if the equivalence is used after that, it will
5876 have been modified, and the thing substituted (probably a
5877 register) is likely overwritten and not a usable equivalence. */
5878 int check_regno;
5880 for (check_regno = 0; check_regno < max_regno; check_regno++)
5882 #define CHECK_MODF(ARRAY) \
5883 if (ARRAY[check_regno] \
5884 && loc_mentioned_in_p (r->where, \
5885 ARRAY[check_regno])) \
5886 abort ()
5888 CHECK_MODF (reg_equiv_constant);
5889 CHECK_MODF (reg_equiv_memory_loc);
5890 CHECK_MODF (reg_equiv_address);
5891 CHECK_MODF (reg_equiv_mem);
5892 #undef CHECK_MODF
5894 #endif /* ENABLE_CHECKING */
5896 /* If we're replacing a LABEL_REF with a register, add a
5897 REG_LABEL note to indicate to flow which label this
5898 register refers to. */
5899 if (GET_CODE (*r->where) == LABEL_REF
5900 && GET_CODE (insn) == JUMP_INSN)
5901 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
5902 XEXP (*r->where, 0),
5903 REG_NOTES (insn));
5905 /* Encapsulate RELOADREG so its machine mode matches what
5906 used to be there. Note that gen_lowpart_common will
5907 do the wrong thing if RELOADREG is multi-word. RELOADREG
5908 will always be a REG here. */
5909 if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
5910 reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg));
5912 /* If we are putting this into a SUBREG and RELOADREG is a
5913 SUBREG, we would be making nested SUBREGs, so we have to fix
5914 this up. Note that r->where == &SUBREG_REG (*r->subreg_loc). */
5916 if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG)
5918 if (GET_MODE (*r->subreg_loc)
5919 == GET_MODE (SUBREG_REG (reloadreg)))
5920 *r->subreg_loc = SUBREG_REG (reloadreg);
5921 else
5923 int final_offset =
5924 SUBREG_BYTE (*r->subreg_loc) + SUBREG_BYTE (reloadreg);
5926 /* When working with SUBREGs the rule is that the byte
5927 offset must be a multiple of the SUBREG's mode. */
5928 final_offset = (final_offset /
5929 GET_MODE_SIZE (GET_MODE (*r->subreg_loc)));
5930 final_offset = (final_offset *
5931 GET_MODE_SIZE (GET_MODE (*r->subreg_loc)));
5933 *r->where = SUBREG_REG (reloadreg);
5934 SUBREG_BYTE (*r->subreg_loc) = final_offset;
5937 else
5938 *r->where = reloadreg;
5940 /* If reload got no reg and isn't optional, something's wrong. */
5941 else if (! rld[r->what].optional)
5942 abort ();
5946 /* Make a copy of any replacements being done into X and move those
5947 copies to locations in Y, a copy of X. */
5949 void
5950 copy_replacements (x, y)
5951 rtx x, y;
5953 /* We can't support X being a SUBREG because we might then need to know its
5954 location if something inside it was replaced. */
5955 if (GET_CODE (x) == SUBREG)
5956 abort ();
5958 copy_replacements_1 (&x, &y, n_replacements);
5961 static void
5962 copy_replacements_1 (px, py, orig_replacements)
5963 rtx *px;
5964 rtx *py;
5965 int orig_replacements;
5967 int i, j;
5968 rtx x, y;
5969 struct replacement *r;
5970 enum rtx_code code;
5971 const char *fmt;
5973 for (j = 0; j < orig_replacements; j++)
5975 if (replacements[j].subreg_loc == px)
5977 r = &replacements[n_replacements++];
5978 r->where = replacements[j].where;
5979 r->subreg_loc = py;
5980 r->what = replacements[j].what;
5981 r->mode = replacements[j].mode;
5983 else if (replacements[j].where == px)
5985 r = &replacements[n_replacements++];
5986 r->where = py;
5987 r->subreg_loc = 0;
5988 r->what = replacements[j].what;
5989 r->mode = replacements[j].mode;
5993 x = *px;
5994 y = *py;
5995 code = GET_CODE (x);
5996 fmt = GET_RTX_FORMAT (code);
5998 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6000 if (fmt[i] == 'e')
6001 copy_replacements_1 (&XEXP (x, i), &XEXP (y, i), orig_replacements);
6002 else if (fmt[i] == 'E')
6003 for (j = XVECLEN (x, i); --j >= 0; )
6004 copy_replacements_1 (&XVECEXP (x, i, j), &XVECEXP (y, i, j),
6005 orig_replacements);
6009 /* Change any replacements being done to *X to be done to *Y. */
6011 void
6012 move_replacements (x, y)
6013 rtx *x;
6014 rtx *y;
6016 int i;
6018 for (i = 0; i < n_replacements; i++)
6019 if (replacements[i].subreg_loc == x)
6020 replacements[i].subreg_loc = y;
6021 else if (replacements[i].where == x)
6023 replacements[i].where = y;
6024 replacements[i].subreg_loc = 0;
6028 /* If LOC was scheduled to be replaced by something, return the replacement.
6029 Otherwise, return *LOC. */
6032 find_replacement (loc)
6033 rtx *loc;
6035 struct replacement *r;
6037 for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
6039 rtx reloadreg = rld[r->what].reg_rtx;
6041 if (reloadreg && r->where == loc)
6043 if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
6044 reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg));
6046 return reloadreg;
6048 else if (reloadreg && r->subreg_loc == loc)
6050 /* RELOADREG must be either a REG or a SUBREG.
6052 ??? Is it actually still ever a SUBREG? If so, why? */
6054 if (GET_CODE (reloadreg) == REG)
6055 return gen_rtx_REG (GET_MODE (*loc),
6056 (REGNO (reloadreg) +
6057 subreg_regno_offset (REGNO (SUBREG_REG (*loc)),
6058 GET_MODE (SUBREG_REG (*loc)),
6059 SUBREG_BYTE (*loc),
6060 GET_MODE (*loc))));
6061 else if (GET_MODE (reloadreg) == GET_MODE (*loc))
6062 return reloadreg;
6063 else
6065 int final_offset = SUBREG_BYTE (reloadreg) + SUBREG_BYTE (*loc);
6067 /* When working with SUBREGs the rule is that the byte
6068 offset must be a multiple of the SUBREG's mode. */
6069 final_offset = (final_offset / GET_MODE_SIZE (GET_MODE (*loc)));
6070 final_offset = (final_offset * GET_MODE_SIZE (GET_MODE (*loc)));
6071 return gen_rtx_SUBREG (GET_MODE (*loc), SUBREG_REG (reloadreg),
6072 final_offset);
6077 /* If *LOC is a PLUS, MINUS, or MULT, see if a replacement is scheduled for
6078 what's inside and make a new rtl if so. */
6079 if (GET_CODE (*loc) == PLUS || GET_CODE (*loc) == MINUS
6080 || GET_CODE (*loc) == MULT)
6082 rtx x = find_replacement (&XEXP (*loc, 0));
6083 rtx y = find_replacement (&XEXP (*loc, 1));
6085 if (x != XEXP (*loc, 0) || y != XEXP (*loc, 1))
6086 return gen_rtx_fmt_ee (GET_CODE (*loc), GET_MODE (*loc), x, y);
6089 return *loc;
6092 /* Return nonzero if register in range [REGNO, ENDREGNO)
6093 appears either explicitly or implicitly in X
6094 other than being stored into (except for earlyclobber operands).
6096 References contained within the substructure at LOC do not count.
6097 LOC may be zero, meaning don't ignore anything.
6099 This is similar to refers_to_regno_p in rtlanal.c except that we
6100 look at equivalences for pseudos that didn't get hard registers. */
6103 refers_to_regno_for_reload_p (regno, endregno, x, loc)
6104 unsigned int regno, endregno;
6105 rtx x;
6106 rtx *loc;
6108 int i;
6109 unsigned int r;
6110 RTX_CODE code;
6111 const char *fmt;
6113 if (x == 0)
6114 return 0;
6116 repeat:
6117 code = GET_CODE (x);
6119 switch (code)
6121 case REG:
6122 r = REGNO (x);
6124 /* If this is a pseudo, a hard register must not have been allocated.
6125 X must therefore either be a constant or be in memory. */
6126 if (r >= FIRST_PSEUDO_REGISTER)
6128 if (reg_equiv_memory_loc[r])
6129 return refers_to_regno_for_reload_p (regno, endregno,
6130 reg_equiv_memory_loc[r],
6131 (rtx*) 0);
6133 if (reg_equiv_constant[r])
6134 return 0;
6136 abort ();
6139 return (endregno > r
6140 && regno < r + (r < FIRST_PSEUDO_REGISTER
6141 ? HARD_REGNO_NREGS (r, GET_MODE (x))
6142 : 1));
6144 case SUBREG:
6145 /* If this is a SUBREG of a hard reg, we can see exactly which
6146 registers are being modified. Otherwise, handle normally. */
6147 if (GET_CODE (SUBREG_REG (x)) == REG
6148 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
6150 unsigned int inner_regno = subreg_regno (x);
6151 unsigned int inner_endregno
6152 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
6153 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
6155 return endregno > inner_regno && regno < inner_endregno;
6157 break;
6159 case CLOBBER:
6160 case SET:
6161 if (&SET_DEST (x) != loc
6162 /* Note setting a SUBREG counts as referring to the REG it is in for
6163 a pseudo but not for hard registers since we can
6164 treat each word individually. */
6165 && ((GET_CODE (SET_DEST (x)) == SUBREG
6166 && loc != &SUBREG_REG (SET_DEST (x))
6167 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
6168 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
6169 && refers_to_regno_for_reload_p (regno, endregno,
6170 SUBREG_REG (SET_DEST (x)),
6171 loc))
6172 /* If the output is an earlyclobber operand, this is
6173 a conflict. */
6174 || ((GET_CODE (SET_DEST (x)) != REG
6175 || earlyclobber_operand_p (SET_DEST (x)))
6176 && refers_to_regno_for_reload_p (regno, endregno,
6177 SET_DEST (x), loc))))
6178 return 1;
6180 if (code == CLOBBER || loc == &SET_SRC (x))
6181 return 0;
6182 x = SET_SRC (x);
6183 goto repeat;
6185 default:
6186 break;
6189 /* X does not match, so try its subexpressions. */
6191 fmt = GET_RTX_FORMAT (code);
6192 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6194 if (fmt[i] == 'e' && loc != &XEXP (x, i))
6196 if (i == 0)
6198 x = XEXP (x, 0);
6199 goto repeat;
6201 else
6202 if (refers_to_regno_for_reload_p (regno, endregno,
6203 XEXP (x, i), loc))
6204 return 1;
6206 else if (fmt[i] == 'E')
6208 int j;
6209 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6210 if (loc != &XVECEXP (x, i, j)
6211 && refers_to_regno_for_reload_p (regno, endregno,
6212 XVECEXP (x, i, j), loc))
6213 return 1;
6216 return 0;
6219 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
6220 we check if any register number in X conflicts with the relevant register
6221 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
6222 contains a MEM (we don't bother checking for memory addresses that can't
6223 conflict because we expect this to be a rare case.
6225 This function is similar to reg_overlap_mentioned_p in rtlanal.c except
6226 that we look at equivalences for pseudos that didn't get hard registers. */
6229 reg_overlap_mentioned_for_reload_p (x, in)
6230 rtx x, in;
6232 int regno, endregno;
6234 /* Overly conservative. */
6235 if (GET_CODE (x) == STRICT_LOW_PART
6236 || GET_RTX_CLASS (GET_CODE (x)) == 'a')
6237 x = XEXP (x, 0);
6239 /* If either argument is a constant, then modifying X can not affect IN. */
6240 if (CONSTANT_P (x) || CONSTANT_P (in))
6241 return 0;
6242 else if (GET_CODE (x) == SUBREG)
6244 regno = REGNO (SUBREG_REG (x));
6245 if (regno < FIRST_PSEUDO_REGISTER)
6246 regno += subreg_regno_offset (REGNO (SUBREG_REG (x)),
6247 GET_MODE (SUBREG_REG (x)),
6248 SUBREG_BYTE (x),
6249 GET_MODE (x));
6251 else if (GET_CODE (x) == REG)
6253 regno = REGNO (x);
6255 /* If this is a pseudo, it must not have been assigned a hard register.
6256 Therefore, it must either be in memory or be a constant. */
6258 if (regno >= FIRST_PSEUDO_REGISTER)
6260 if (reg_equiv_memory_loc[regno])
6261 return refers_to_mem_for_reload_p (in);
6262 else if (reg_equiv_constant[regno])
6263 return 0;
6264 abort ();
6267 else if (GET_CODE (x) == MEM)
6268 return refers_to_mem_for_reload_p (in);
6269 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
6270 || GET_CODE (x) == CC0)
6271 return reg_mentioned_p (x, in);
6272 else if (GET_CODE (x) == PLUS)
6273 return (reg_overlap_mentioned_for_reload_p (XEXP (x, 0), in)
6274 || reg_overlap_mentioned_for_reload_p (XEXP (x, 1), in));
6275 else
6276 abort ();
6278 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
6279 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
6281 return refers_to_regno_for_reload_p (regno, endregno, in, (rtx*) 0);
6284 /* Return nonzero if anything in X contains a MEM. Look also for pseudo
6285 registers. */
6288 refers_to_mem_for_reload_p (x)
6289 rtx x;
6291 const char *fmt;
6292 int i;
6294 if (GET_CODE (x) == MEM)
6295 return 1;
6297 if (GET_CODE (x) == REG)
6298 return (REGNO (x) >= FIRST_PSEUDO_REGISTER
6299 && reg_equiv_memory_loc[REGNO (x)]);
6301 fmt = GET_RTX_FORMAT (GET_CODE (x));
6302 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
6303 if (fmt[i] == 'e'
6304 && (GET_CODE (XEXP (x, i)) == MEM
6305 || refers_to_mem_for_reload_p (XEXP (x, i))))
6306 return 1;
6308 return 0;
6311 /* Check the insns before INSN to see if there is a suitable register
6312 containing the same value as GOAL.
6313 If OTHER is -1, look for a register in class CLASS.
6314 Otherwise, just see if register number OTHER shares GOAL's value.
6316 Return an rtx for the register found, or zero if none is found.
6318 If RELOAD_REG_P is (short *)1,
6319 we reject any hard reg that appears in reload_reg_rtx
6320 because such a hard reg is also needed coming into this insn.
6322 If RELOAD_REG_P is any other nonzero value,
6323 it is a vector indexed by hard reg number
6324 and we reject any hard reg whose element in the vector is nonnegative
6325 as well as any that appears in reload_reg_rtx.
6327 If GOAL is zero, then GOALREG is a register number; we look
6328 for an equivalent for that register.
6330 MODE is the machine mode of the value we want an equivalence for.
6331 If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
6333 This function is used by jump.c as well as in the reload pass.
6335 If GOAL is the sum of the stack pointer and a constant, we treat it
6336 as if it were a constant except that sp is required to be unchanging. */
6339 find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode)
6340 rtx goal;
6341 rtx insn;
6342 enum reg_class class;
6343 int other;
6344 short *reload_reg_p;
6345 int goalreg;
6346 enum machine_mode mode;
6348 rtx p = insn;
6349 rtx goaltry, valtry, value, where;
6350 rtx pat;
6351 int regno = -1;
6352 int valueno;
6353 int goal_mem = 0;
6354 int goal_const = 0;
6355 int goal_mem_addr_varies = 0;
6356 int need_stable_sp = 0;
6357 int nregs;
6358 int valuenregs;
6360 if (goal == 0)
6361 regno = goalreg;
6362 else if (GET_CODE (goal) == REG)
6363 regno = REGNO (goal);
6364 else if (GET_CODE (goal) == MEM)
6366 enum rtx_code code = GET_CODE (XEXP (goal, 0));
6367 if (MEM_VOLATILE_P (goal))
6368 return 0;
6369 if (flag_float_store && GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT)
6370 return 0;
6371 /* An address with side effects must be reexecuted. */
6372 switch (code)
6374 case POST_INC:
6375 case PRE_INC:
6376 case POST_DEC:
6377 case PRE_DEC:
6378 case POST_MODIFY:
6379 case PRE_MODIFY:
6380 return 0;
6381 default:
6382 break;
6384 goal_mem = 1;
6386 else if (CONSTANT_P (goal))
6387 goal_const = 1;
6388 else if (GET_CODE (goal) == PLUS
6389 && XEXP (goal, 0) == stack_pointer_rtx
6390 && CONSTANT_P (XEXP (goal, 1)))
6391 goal_const = need_stable_sp = 1;
6392 else if (GET_CODE (goal) == PLUS
6393 && XEXP (goal, 0) == frame_pointer_rtx
6394 && CONSTANT_P (XEXP (goal, 1)))
6395 goal_const = 1;
6396 else
6397 return 0;
6399 /* Scan insns back from INSN, looking for one that copies
6400 a value into or out of GOAL.
6401 Stop and give up if we reach a label. */
6403 while (1)
6405 p = PREV_INSN (p);
6406 if (p == 0 || GET_CODE (p) == CODE_LABEL)
6407 return 0;
6409 if (GET_CODE (p) == INSN
6410 /* If we don't want spill regs ... */
6411 && (! (reload_reg_p != 0
6412 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6413 /* ... then ignore insns introduced by reload; they aren't
6414 useful and can cause results in reload_as_needed to be
6415 different from what they were when calculating the need for
6416 spills. If we notice an input-reload insn here, we will
6417 reject it below, but it might hide a usable equivalent.
6418 That makes bad code. It may even abort: perhaps no reg was
6419 spilled for this insn because it was assumed we would find
6420 that equivalent. */
6421 || INSN_UID (p) < reload_first_uid))
6423 rtx tem;
6424 pat = single_set (p);
6426 /* First check for something that sets some reg equal to GOAL. */
6427 if (pat != 0
6428 && ((regno >= 0
6429 && true_regnum (SET_SRC (pat)) == regno
6430 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6432 (regno >= 0
6433 && true_regnum (SET_DEST (pat)) == regno
6434 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
6436 (goal_const && rtx_equal_p (SET_SRC (pat), goal)
6437 /* When looking for stack pointer + const,
6438 make sure we don't use a stack adjust. */
6439 && !reg_overlap_mentioned_for_reload_p (SET_DEST (pat), goal)
6440 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6441 || (goal_mem
6442 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
6443 && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
6444 || (goal_mem
6445 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
6446 && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
6447 /* If we are looking for a constant,
6448 and something equivalent to that constant was copied
6449 into a reg, we can use that reg. */
6450 || (goal_const && REG_NOTES (p) != 0
6451 && (tem = find_reg_note (p, REG_EQUIV, NULL_RTX))
6452 && ((rtx_equal_p (XEXP (tem, 0), goal)
6453 && (valueno
6454 = true_regnum (valtry = SET_DEST (pat))) >= 0)
6455 || (GET_CODE (SET_DEST (pat)) == REG
6456 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6457 && (GET_MODE_CLASS (GET_MODE (XEXP (tem, 0)))
6458 == MODE_FLOAT)
6459 && GET_CODE (goal) == CONST_INT
6460 && 0 != (goaltry
6461 = operand_subword (XEXP (tem, 0), 0, 0,
6462 VOIDmode))
6463 && rtx_equal_p (goal, goaltry)
6464 && (valtry
6465 = operand_subword (SET_DEST (pat), 0, 0,
6466 VOIDmode))
6467 && (valueno = true_regnum (valtry)) >= 0)))
6468 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
6469 NULL_RTX))
6470 && GET_CODE (SET_DEST (pat)) == REG
6471 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6472 && (GET_MODE_CLASS (GET_MODE (XEXP (tem, 0)))
6473 == MODE_FLOAT)
6474 && GET_CODE (goal) == CONST_INT
6475 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0,
6476 VOIDmode))
6477 && rtx_equal_p (goal, goaltry)
6478 && (valtry
6479 = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
6480 && (valueno = true_regnum (valtry)) >= 0)))
6482 if (other >= 0)
6484 if (valueno != other)
6485 continue;
6487 else if ((unsigned) valueno >= FIRST_PSEUDO_REGISTER)
6488 continue;
6489 else
6491 int i;
6493 for (i = HARD_REGNO_NREGS (valueno, mode) - 1; i >= 0; i--)
6494 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
6495 valueno + i))
6496 break;
6497 if (i >= 0)
6498 continue;
6500 value = valtry;
6501 where = p;
6502 break;
6507 /* We found a previous insn copying GOAL into a suitable other reg VALUE
6508 (or copying VALUE into GOAL, if GOAL is also a register).
6509 Now verify that VALUE is really valid. */
6511 /* VALUENO is the register number of VALUE; a hard register. */
6513 /* Don't try to re-use something that is killed in this insn. We want
6514 to be able to trust REG_UNUSED notes. */
6515 if (REG_NOTES (where) != 0 && find_reg_note (where, REG_UNUSED, value))
6516 return 0;
6518 /* If we propose to get the value from the stack pointer or if GOAL is
6519 a MEM based on the stack pointer, we need a stable SP. */
6520 if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM
6521 || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
6522 goal)))
6523 need_stable_sp = 1;
6525 /* Reject VALUE if the copy-insn moved the wrong sort of datum. */
6526 if (GET_MODE (value) != mode)
6527 return 0;
6529 /* Reject VALUE if it was loaded from GOAL
6530 and is also a register that appears in the address of GOAL. */
6532 if (goal_mem && value == SET_DEST (single_set (where))
6533 && refers_to_regno_for_reload_p (valueno,
6534 (valueno
6535 + HARD_REGNO_NREGS (valueno, mode)),
6536 goal, (rtx*) 0))
6537 return 0;
6539 /* Reject registers that overlap GOAL. */
6541 if (!goal_mem && !goal_const
6542 && regno + (int) HARD_REGNO_NREGS (regno, mode) > valueno
6543 && regno < valueno + (int) HARD_REGNO_NREGS (valueno, mode))
6544 return 0;
6546 nregs = HARD_REGNO_NREGS (regno, mode);
6547 valuenregs = HARD_REGNO_NREGS (valueno, mode);
6549 /* Reject VALUE if it is one of the regs reserved for reloads.
6550 Reload1 knows how to reuse them anyway, and it would get
6551 confused if we allocated one without its knowledge.
6552 (Now that insns introduced by reload are ignored above,
6553 this case shouldn't happen, but I'm not positive.) */
6555 if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6557 int i;
6558 for (i = 0; i < valuenregs; ++i)
6559 if (reload_reg_p[valueno + i] >= 0)
6560 return 0;
6563 /* Reject VALUE if it is a register being used for an input reload
6564 even if it is not one of those reserved. */
6566 if (reload_reg_p != 0)
6568 int i;
6569 for (i = 0; i < n_reloads; i++)
6570 if (rld[i].reg_rtx != 0 && rld[i].in)
6572 int regno1 = REGNO (rld[i].reg_rtx);
6573 int nregs1 = HARD_REGNO_NREGS (regno1,
6574 GET_MODE (rld[i].reg_rtx));
6575 if (regno1 < valueno + valuenregs
6576 && regno1 + nregs1 > valueno)
6577 return 0;
6581 if (goal_mem)
6582 /* We must treat frame pointer as varying here,
6583 since it can vary--in a nonlocal goto as generated by expand_goto. */
6584 goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0));
6586 /* Now verify that the values of GOAL and VALUE remain unaltered
6587 until INSN is reached. */
6589 p = insn;
6590 while (1)
6592 p = PREV_INSN (p);
6593 if (p == where)
6594 return value;
6596 /* Don't trust the conversion past a function call
6597 if either of the two is in a call-clobbered register, or memory. */
6598 if (GET_CODE (p) == CALL_INSN)
6600 int i;
6602 if (goal_mem || need_stable_sp)
6603 return 0;
6605 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
6606 for (i = 0; i < nregs; ++i)
6607 if (call_used_regs[regno + i])
6608 return 0;
6610 if (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER)
6611 for (i = 0; i < valuenregs; ++i)
6612 if (call_used_regs[valueno + i])
6613 return 0;
6614 #ifdef NON_SAVING_SETJMP
6615 if (NON_SAVING_SETJMP && find_reg_note (p, REG_SETJMP, NULL))
6616 return 0;
6617 #endif
6620 if (INSN_P (p))
6622 pat = PATTERN (p);
6624 /* Watch out for unspec_volatile, and volatile asms. */
6625 if (volatile_insn_p (pat))
6626 return 0;
6628 /* If this insn P stores in either GOAL or VALUE, return 0.
6629 If GOAL is a memory ref and this insn writes memory, return 0.
6630 If GOAL is a memory ref and its address is not constant,
6631 and this insn P changes a register used in GOAL, return 0. */
6633 if (GET_CODE (pat) == COND_EXEC)
6634 pat = COND_EXEC_CODE (pat);
6635 if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
6637 rtx dest = SET_DEST (pat);
6638 while (GET_CODE (dest) == SUBREG
6639 || GET_CODE (dest) == ZERO_EXTRACT
6640 || GET_CODE (dest) == SIGN_EXTRACT
6641 || GET_CODE (dest) == STRICT_LOW_PART)
6642 dest = XEXP (dest, 0);
6643 if (GET_CODE (dest) == REG)
6645 int xregno = REGNO (dest);
6646 int xnregs;
6647 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6648 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
6649 else
6650 xnregs = 1;
6651 if (xregno < regno + nregs && xregno + xnregs > regno)
6652 return 0;
6653 if (xregno < valueno + valuenregs
6654 && xregno + xnregs > valueno)
6655 return 0;
6656 if (goal_mem_addr_varies
6657 && reg_overlap_mentioned_for_reload_p (dest, goal))
6658 return 0;
6659 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6660 return 0;
6662 else if (goal_mem && GET_CODE (dest) == MEM
6663 && ! push_operand (dest, GET_MODE (dest)))
6664 return 0;
6665 else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER
6666 && reg_equiv_memory_loc[regno] != 0)
6667 return 0;
6668 else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
6669 return 0;
6671 else if (GET_CODE (pat) == PARALLEL)
6673 int i;
6674 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
6676 rtx v1 = XVECEXP (pat, 0, i);
6677 if (GET_CODE (v1) == COND_EXEC)
6678 v1 = COND_EXEC_CODE (v1);
6679 if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
6681 rtx dest = SET_DEST (v1);
6682 while (GET_CODE (dest) == SUBREG
6683 || GET_CODE (dest) == ZERO_EXTRACT
6684 || GET_CODE (dest) == SIGN_EXTRACT
6685 || GET_CODE (dest) == STRICT_LOW_PART)
6686 dest = XEXP (dest, 0);
6687 if (GET_CODE (dest) == REG)
6689 int xregno = REGNO (dest);
6690 int xnregs;
6691 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6692 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
6693 else
6694 xnregs = 1;
6695 if (xregno < regno + nregs
6696 && xregno + xnregs > regno)
6697 return 0;
6698 if (xregno < valueno + valuenregs
6699 && xregno + xnregs > valueno)
6700 return 0;
6701 if (goal_mem_addr_varies
6702 && reg_overlap_mentioned_for_reload_p (dest,
6703 goal))
6704 return 0;
6705 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6706 return 0;
6708 else if (goal_mem && GET_CODE (dest) == MEM
6709 && ! push_operand (dest, GET_MODE (dest)))
6710 return 0;
6711 else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER
6712 && reg_equiv_memory_loc[regno] != 0)
6713 return 0;
6714 else if (need_stable_sp
6715 && push_operand (dest, GET_MODE (dest)))
6716 return 0;
6721 if (GET_CODE (p) == CALL_INSN && CALL_INSN_FUNCTION_USAGE (p))
6723 rtx link;
6725 for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0;
6726 link = XEXP (link, 1))
6728 pat = XEXP (link, 0);
6729 if (GET_CODE (pat) == CLOBBER)
6731 rtx dest = SET_DEST (pat);
6733 if (GET_CODE (dest) == REG)
6735 int xregno = REGNO (dest);
6736 int xnregs
6737 = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
6739 if (xregno < regno + nregs
6740 && xregno + xnregs > regno)
6741 return 0;
6742 else if (xregno < valueno + valuenregs
6743 && xregno + xnregs > valueno)
6744 return 0;
6745 else if (goal_mem_addr_varies
6746 && reg_overlap_mentioned_for_reload_p (dest,
6747 goal))
6748 return 0;
6751 else if (goal_mem && GET_CODE (dest) == MEM
6752 && ! push_operand (dest, GET_MODE (dest)))
6753 return 0;
6754 else if (need_stable_sp
6755 && push_operand (dest, GET_MODE (dest)))
6756 return 0;
6761 #ifdef AUTO_INC_DEC
6762 /* If this insn auto-increments or auto-decrements
6763 either regno or valueno, return 0 now.
6764 If GOAL is a memory ref and its address is not constant,
6765 and this insn P increments a register used in GOAL, return 0. */
6767 rtx link;
6769 for (link = REG_NOTES (p); link; link = XEXP (link, 1))
6770 if (REG_NOTE_KIND (link) == REG_INC
6771 && GET_CODE (XEXP (link, 0)) == REG)
6773 int incno = REGNO (XEXP (link, 0));
6774 if (incno < regno + nregs && incno >= regno)
6775 return 0;
6776 if (incno < valueno + valuenregs && incno >= valueno)
6777 return 0;
6778 if (goal_mem_addr_varies
6779 && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
6780 goal))
6781 return 0;
6784 #endif
6789 /* Find a place where INCED appears in an increment or decrement operator
6790 within X, and return the amount INCED is incremented or decremented by.
6791 The value is always positive. */
6793 static int
6794 find_inc_amount (x, inced)
6795 rtx x, inced;
6797 enum rtx_code code = GET_CODE (x);
6798 const char *fmt;
6799 int i;
6801 if (code == MEM)
6803 rtx addr = XEXP (x, 0);
6804 if ((GET_CODE (addr) == PRE_DEC
6805 || GET_CODE (addr) == POST_DEC
6806 || GET_CODE (addr) == PRE_INC
6807 || GET_CODE (addr) == POST_INC)
6808 && XEXP (addr, 0) == inced)
6809 return GET_MODE_SIZE (GET_MODE (x));
6810 else if ((GET_CODE (addr) == PRE_MODIFY
6811 || GET_CODE (addr) == POST_MODIFY)
6812 && GET_CODE (XEXP (addr, 1)) == PLUS
6813 && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
6814 && XEXP (addr, 0) == inced
6815 && GET_CODE (XEXP (XEXP (addr, 1), 1)) == CONST_INT)
6817 i = INTVAL (XEXP (XEXP (addr, 1), 1));
6818 return i < 0 ? -i : i;
6822 fmt = GET_RTX_FORMAT (code);
6823 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6825 if (fmt[i] == 'e')
6827 int tem = find_inc_amount (XEXP (x, i), inced);
6828 if (tem != 0)
6829 return tem;
6831 if (fmt[i] == 'E')
6833 int j;
6834 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6836 int tem = find_inc_amount (XVECEXP (x, i, j), inced);
6837 if (tem != 0)
6838 return tem;
6843 return 0;
6846 /* Return 1 if register REGNO is the subject of a clobber in insn INSN.
6847 If SETS is nonzero, also consider SETs. */
6850 regno_clobbered_p (regno, insn, mode, sets)
6851 unsigned int regno;
6852 rtx insn;
6853 enum machine_mode mode;
6854 int sets;
6856 unsigned int nregs = HARD_REGNO_NREGS (regno, mode);
6857 unsigned int endregno = regno + nregs;
6859 if ((GET_CODE (PATTERN (insn)) == CLOBBER
6860 || (sets && GET_CODE (PATTERN (insn)) == SET))
6861 && GET_CODE (XEXP (PATTERN (insn), 0)) == REG)
6863 unsigned int test = REGNO (XEXP (PATTERN (insn), 0));
6865 return test >= regno && test < endregno;
6868 if (GET_CODE (PATTERN (insn)) == PARALLEL)
6870 int i = XVECLEN (PATTERN (insn), 0) - 1;
6872 for (; i >= 0; i--)
6874 rtx elt = XVECEXP (PATTERN (insn), 0, i);
6875 if ((GET_CODE (elt) == CLOBBER
6876 || (sets && GET_CODE (PATTERN (insn)) == SET))
6877 && GET_CODE (XEXP (elt, 0)) == REG)
6879 unsigned int test = REGNO (XEXP (elt, 0));
6881 if (test >= regno && test < endregno)
6882 return 1;
6887 return 0;
6890 static const char *const reload_when_needed_name[] =
6892 "RELOAD_FOR_INPUT",
6893 "RELOAD_FOR_OUTPUT",
6894 "RELOAD_FOR_INSN",
6895 "RELOAD_FOR_INPUT_ADDRESS",
6896 "RELOAD_FOR_INPADDR_ADDRESS",
6897 "RELOAD_FOR_OUTPUT_ADDRESS",
6898 "RELOAD_FOR_OUTADDR_ADDRESS",
6899 "RELOAD_FOR_OPERAND_ADDRESS",
6900 "RELOAD_FOR_OPADDR_ADDR",
6901 "RELOAD_OTHER",
6902 "RELOAD_FOR_OTHER_ADDRESS"
6905 static const char * const reg_class_names[] = REG_CLASS_NAMES;
6907 /* These functions are used to print the variables set by 'find_reloads' */
6909 void
6910 debug_reload_to_stream (f)
6911 FILE *f;
6913 int r;
6914 const char *prefix;
6916 if (! f)
6917 f = stderr;
6918 for (r = 0; r < n_reloads; r++)
6920 fprintf (f, "Reload %d: ", r);
6922 if (rld[r].in != 0)
6924 fprintf (f, "reload_in (%s) = ",
6925 GET_MODE_NAME (rld[r].inmode));
6926 print_inline_rtx (f, rld[r].in, 24);
6927 fprintf (f, "\n\t");
6930 if (rld[r].out != 0)
6932 fprintf (f, "reload_out (%s) = ",
6933 GET_MODE_NAME (rld[r].outmode));
6934 print_inline_rtx (f, rld[r].out, 24);
6935 fprintf (f, "\n\t");
6938 fprintf (f, "%s, ", reg_class_names[(int) rld[r].class]);
6940 fprintf (f, "%s (opnum = %d)",
6941 reload_when_needed_name[(int) rld[r].when_needed],
6942 rld[r].opnum);
6944 if (rld[r].optional)
6945 fprintf (f, ", optional");
6947 if (rld[r].nongroup)
6948 fprintf (f, ", nongroup");
6950 if (rld[r].inc != 0)
6951 fprintf (f, ", inc by %d", rld[r].inc);
6953 if (rld[r].nocombine)
6954 fprintf (f, ", can't combine");
6956 if (rld[r].secondary_p)
6957 fprintf (f, ", secondary_reload_p");
6959 if (rld[r].in_reg != 0)
6961 fprintf (f, "\n\treload_in_reg: ");
6962 print_inline_rtx (f, rld[r].in_reg, 24);
6965 if (rld[r].out_reg != 0)
6967 fprintf (f, "\n\treload_out_reg: ");
6968 print_inline_rtx (f, rld[r].out_reg, 24);
6971 if (rld[r].reg_rtx != 0)
6973 fprintf (f, "\n\treload_reg_rtx: ");
6974 print_inline_rtx (f, rld[r].reg_rtx, 24);
6977 prefix = "\n\t";
6978 if (rld[r].secondary_in_reload != -1)
6980 fprintf (f, "%ssecondary_in_reload = %d",
6981 prefix, rld[r].secondary_in_reload);
6982 prefix = ", ";
6985 if (rld[r].secondary_out_reload != -1)
6986 fprintf (f, "%ssecondary_out_reload = %d\n",
6987 prefix, rld[r].secondary_out_reload);
6989 prefix = "\n\t";
6990 if (rld[r].secondary_in_icode != CODE_FOR_nothing)
6992 fprintf (f, "%ssecondary_in_icode = %s", prefix,
6993 insn_data[rld[r].secondary_in_icode].name);
6994 prefix = ", ";
6997 if (rld[r].secondary_out_icode != CODE_FOR_nothing)
6998 fprintf (f, "%ssecondary_out_icode = %s", prefix,
6999 insn_data[rld[r].secondary_out_icode].name);
7001 fprintf (f, "\n");
7005 void
7006 debug_reload ()
7008 debug_reload_to_stream (stderr);