Do not generate error message about unrecognised command line switches of
[official-gcc.git] / gcc / reload.c
blob011d0a904e13fbcf55cc4f77d302798bb6e2e1b7
1 /* Search an insn for pseudo regs that must be in hard regs and are not.
2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file contains subroutines used only from the file reload1.c.
23 It knows how to scan one insn for operands and values
24 that need to be copied into registers to make valid code.
25 It also finds other operands and values which are valid
26 but for which equivalent values in registers exist and
27 ought to be used instead.
29 Before processing the first insn of the function, call `init_reload'.
31 To scan an insn, call `find_reloads'. This does two things:
32 1. sets up tables describing which values must be reloaded
33 for this insn, and what kind of hard regs they must be reloaded into;
34 2. optionally record the locations where those values appear in
35 the data, so they can be replaced properly later.
36 This is done only if the second arg to `find_reloads' is nonzero.
38 The third arg to `find_reloads' specifies the number of levels
39 of indirect addressing supported by the machine. If it is zero,
40 indirect addressing is not valid. If it is one, (MEM (REG n))
41 is valid even if (REG n) did not get a hard register; if it is two,
42 (MEM (MEM (REG n))) is also valid even if (REG n) did not get a
43 hard register, and similarly for higher values.
45 Then you must choose the hard regs to reload those pseudo regs into,
46 and generate appropriate load insns before this insn and perhaps
47 also store insns after this insn. Set up the array `reload_reg_rtx'
48 to contain the REG rtx's for the registers you used. In some
49 cases `find_reloads' will return a nonzero value in `reload_reg_rtx'
50 for certain reloads. Then that tells you which register to use,
51 so you do not need to allocate one. But you still do need to add extra
52 instructions to copy the value into and out of that register.
54 Finally you must call `subst_reloads' to substitute the reload reg rtx's
55 into the locations already recorded.
57 NOTE SIDE EFFECTS:
59 find_reloads can alter the operands of the instruction it is called on.
61 1. Two operands of any sort may be interchanged, if they are in a
62 commutative instruction.
63 This happens only if find_reloads thinks the instruction will compile
64 better that way.
66 2. Pseudo-registers that are equivalent to constants are replaced
67 with those constants if they are not in hard registers.
69 1 happens every time find_reloads is called.
70 2 happens only when REPLACE is 1, which is only when
71 actually doing the reloads, not when just counting them.
74 Using a reload register for several reloads in one insn:
76 When an insn has reloads, it is considered as having three parts:
77 the input reloads, the insn itself after reloading, and the output reloads.
78 Reloads of values used in memory addresses are often needed for only one part.
80 When this is so, reload_when_needed records which part needs the reload.
81 Two reloads for different parts of the insn can share the same reload
82 register.
84 When a reload is used for addresses in multiple parts, or when it is
85 an ordinary operand, it is classified as RELOAD_OTHER, and cannot share
86 a register with any other reload. */
88 #define REG_OK_STRICT
90 #include "config.h"
91 #include "system.h"
92 #include "rtl.h"
93 #include "tm_p.h"
94 #include "insn-config.h"
95 #include "insn-codes.h"
96 #include "recog.h"
97 #include "reload.h"
98 #include "regs.h"
99 #include "hard-reg-set.h"
100 #include "flags.h"
101 #include "real.h"
102 #include "output.h"
103 #include "function.h"
104 #include "expr.h"
105 #include "toplev.h"
107 #ifndef REGISTER_MOVE_COST
108 #define REGISTER_MOVE_COST(x, y) 2
109 #endif
111 #ifndef REGNO_MODE_OK_FOR_BASE_P
112 #define REGNO_MODE_OK_FOR_BASE_P(REGNO, MODE) REGNO_OK_FOR_BASE_P (REGNO)
113 #endif
115 #ifndef REG_MODE_OK_FOR_BASE_P
116 #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
117 #endif
119 /* All reloads of the current insn are recorded here. See reload.h for
120 comments. */
121 int n_reloads;
122 struct reload rld[MAX_RELOADS];
124 /* All the "earlyclobber" operands of the current insn
125 are recorded here. */
126 int n_earlyclobbers;
127 rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
129 int reload_n_operands;
131 /* Replacing reloads.
133 If `replace_reloads' is nonzero, then as each reload is recorded
134 an entry is made for it in the table `replacements'.
135 Then later `subst_reloads' can look through that table and
136 perform all the replacements needed. */
138 /* Nonzero means record the places to replace. */
139 static int replace_reloads;
141 /* Each replacement is recorded with a structure like this. */
142 struct replacement
144 rtx *where; /* Location to store in */
145 rtx *subreg_loc; /* Location of SUBREG if WHERE is inside
146 a SUBREG; 0 otherwise. */
147 int what; /* which reload this is for */
148 enum machine_mode mode; /* mode it must have */
151 static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
153 /* Number of replacements currently recorded. */
154 static int n_replacements;
156 /* Used to track what is modified by an operand. */
157 struct decomposition
159 int reg_flag; /* Nonzero if referencing a register. */
160 int safe; /* Nonzero if this can't conflict with anything. */
161 rtx base; /* Base address for MEM. */
162 HOST_WIDE_INT start; /* Starting offset or register number. */
163 HOST_WIDE_INT end; /* Ending offset or register number. */
166 #ifdef SECONDARY_MEMORY_NEEDED
168 /* Save MEMs needed to copy from one class of registers to another. One MEM
169 is used per mode, but normally only one or two modes are ever used.
171 We keep two versions, before and after register elimination. The one
172 after register elimination is record separately for each operand. This
173 is done in case the address is not valid to be sure that we separately
174 reload each. */
176 static rtx secondary_memlocs[NUM_MACHINE_MODES];
177 static rtx secondary_memlocs_elim[NUM_MACHINE_MODES][MAX_RECOG_OPERANDS];
178 #endif
180 /* The instruction we are doing reloads for;
181 so we can test whether a register dies in it. */
182 static rtx this_insn;
184 /* Nonzero if this instruction is a user-specified asm with operands. */
185 static int this_insn_is_asm;
187 /* If hard_regs_live_known is nonzero,
188 we can tell which hard regs are currently live,
189 at least enough to succeed in choosing dummy reloads. */
190 static int hard_regs_live_known;
192 /* Indexed by hard reg number,
193 element is nonnegative if hard reg has been spilled.
194 This vector is passed to `find_reloads' as an argument
195 and is not changed here. */
196 static short *static_reload_reg_p;
198 /* Set to 1 in subst_reg_equivs if it changes anything. */
199 static int subst_reg_equivs_changed;
201 /* On return from push_reload, holds the reload-number for the OUT
202 operand, which can be different for that from the input operand. */
203 static int output_reloadnum;
205 /* Compare two RTX's. */
206 #define MATCHES(x, y) \
207 (x == y || (x != 0 && (GET_CODE (x) == REG \
208 ? GET_CODE (y) == REG && REGNO (x) == REGNO (y) \
209 : rtx_equal_p (x, y) && ! side_effects_p (x))))
211 /* Indicates if two reloads purposes are for similar enough things that we
212 can merge their reloads. */
213 #define MERGABLE_RELOADS(when1, when2, op1, op2) \
214 ((when1) == RELOAD_OTHER || (when2) == RELOAD_OTHER \
215 || ((when1) == (when2) && (op1) == (op2)) \
216 || ((when1) == RELOAD_FOR_INPUT && (when2) == RELOAD_FOR_INPUT) \
217 || ((when1) == RELOAD_FOR_OPERAND_ADDRESS \
218 && (when2) == RELOAD_FOR_OPERAND_ADDRESS) \
219 || ((when1) == RELOAD_FOR_OTHER_ADDRESS \
220 && (when2) == RELOAD_FOR_OTHER_ADDRESS))
222 /* Nonzero if these two reload purposes produce RELOAD_OTHER when merged. */
223 #define MERGE_TO_OTHER(when1, when2, op1, op2) \
224 ((when1) != (when2) \
225 || ! ((op1) == (op2) \
226 || (when1) == RELOAD_FOR_INPUT \
227 || (when1) == RELOAD_FOR_OPERAND_ADDRESS \
228 || (when1) == RELOAD_FOR_OTHER_ADDRESS))
230 /* If we are going to reload an address, compute the reload type to
231 use. */
232 #define ADDR_TYPE(type) \
233 ((type) == RELOAD_FOR_INPUT_ADDRESS \
234 ? RELOAD_FOR_INPADDR_ADDRESS \
235 : ((type) == RELOAD_FOR_OUTPUT_ADDRESS \
236 ? RELOAD_FOR_OUTADDR_ADDRESS \
237 : (type)))
239 #ifdef HAVE_SECONDARY_RELOADS
240 static int push_secondary_reload PROTO((int, rtx, int, int, enum reg_class,
241 enum machine_mode, enum reload_type,
242 enum insn_code *));
243 #endif
244 static enum reg_class find_valid_class PROTO((enum machine_mode, int));
245 static int push_reload PROTO((rtx, rtx, rtx *, rtx *, enum reg_class,
246 enum machine_mode, enum machine_mode,
247 int, int, int, enum reload_type));
248 static void push_replacement PROTO((rtx *, int, enum machine_mode));
249 static void combine_reloads PROTO((void));
250 static int find_reusable_reload PROTO((rtx *, rtx, enum reg_class,
251 enum reload_type, int, int));
252 static rtx find_dummy_reload PROTO((rtx, rtx, rtx *, rtx *,
253 enum machine_mode, enum machine_mode,
254 enum reg_class, int, int));
255 static int earlyclobber_operand_p PROTO((rtx));
256 static int hard_reg_set_here_p PROTO((int, int, rtx));
257 static struct decomposition decompose PROTO((rtx));
258 static int immune_p PROTO((rtx, rtx, struct decomposition));
259 static int alternative_allows_memconst PROTO((const char *, int));
260 static rtx find_reloads_toplev PROTO((rtx, int, enum reload_type, int, int, rtx));
261 static rtx make_memloc PROTO((rtx, int));
262 static int find_reloads_address PROTO((enum machine_mode, rtx *, rtx, rtx *,
263 int, enum reload_type, int, rtx));
264 static rtx subst_reg_equivs PROTO((rtx, rtx));
265 static rtx subst_indexed_address PROTO((rtx));
266 static int find_reloads_address_1 PROTO((enum machine_mode, rtx, int, rtx *,
267 int, enum reload_type,int, rtx));
268 static void find_reloads_address_part PROTO((rtx, rtx *, enum reg_class,
269 enum machine_mode, int,
270 enum reload_type, int));
271 static rtx find_reloads_subreg_address PROTO((rtx, int, int, enum reload_type,
272 int, rtx));
273 static int find_inc_amount PROTO((rtx, rtx));
274 static int loc_mentioned_in_p PROTO((rtx *, rtx));
275 extern void debug_reload_to_stream PROTO((FILE *));
276 extern void debug_reload PROTO((void));
278 #ifdef HAVE_SECONDARY_RELOADS
280 /* Determine if any secondary reloads are needed for loading (if IN_P is
281 non-zero) 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 non-zero, 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 char insn_letter
379 = insn_data[(int) icode].operand[!in_p].constraint[in_p];
380 enum reg_class insn_class
381 = (insn_letter == 'r' ? GENERAL_REGS
382 : REG_CLASS_FROM_LETTER ((unsigned char) insn_letter));
384 if (insn_class == NO_REGS
385 || (in_p
386 && insn_data[(int) icode].operand[!in_p].constraint[0] != '=')
387 /* The scratch register's constraint must start with "=&". */
388 || insn_data[(int) icode].operand[2].constraint[0] != '='
389 || insn_data[(int) icode].operand[2].constraint[1] != '&')
390 abort ();
392 if (reg_class_subset_p (reload_class, insn_class))
393 mode = insn_data[(int) icode].operand[2].mode;
394 else
396 char t_letter = insn_data[(int) icode].operand[2].constraint[2];
397 class = insn_class;
398 t_mode = insn_data[(int) icode].operand[2].mode;
399 t_class = (t_letter == 'r' ? GENERAL_REGS
400 : REG_CLASS_FROM_LETTER ((unsigned char) t_letter));
401 t_icode = icode;
402 icode = CODE_FOR_nothing;
406 /* This case isn't valid, so fail. Reload is allowed to use the same
407 register for RELOAD_FOR_INPUT_ADDRESS and RELOAD_FOR_INPUT reloads, but
408 in the case of a secondary register, we actually need two different
409 registers for correct code. We fail here to prevent the possibility of
410 silently generating incorrect code later.
412 The convention is that secondary input reloads are valid only if the
413 secondary_class is different from class. If you have such a case, you
414 can not use secondary reloads, you must work around the problem some
415 other way.
417 Allow this when MODE is not reload_mode and assume that the generated
418 code handles this case (it does on the Alpha, which is the only place
419 this currently happens). */
421 if (in_p && class == reload_class && mode == reload_mode)
422 abort ();
424 /* If we need a tertiary reload, see if we have one we can reuse or else
425 make a new one. */
427 if (t_class != NO_REGS)
429 for (t_reload = 0; t_reload < n_reloads; t_reload++)
430 if (rld[t_reload].secondary_p
431 && (reg_class_subset_p (t_class, rld[t_reload].class)
432 || reg_class_subset_p (rld[t_reload].class, t_class))
433 && ((in_p && rld[t_reload].inmode == t_mode)
434 || (! in_p && rld[t_reload].outmode == t_mode))
435 && ((in_p && (rld[t_reload].secondary_in_icode
436 == CODE_FOR_nothing))
437 || (! in_p &&(rld[t_reload].secondary_out_icode
438 == CODE_FOR_nothing)))
439 && (reg_class_size[(int) t_class] == 1 || SMALL_REGISTER_CLASSES)
440 && MERGABLE_RELOADS (secondary_type,
441 rld[t_reload].when_needed,
442 opnum, rld[t_reload].opnum))
444 if (in_p)
445 rld[t_reload].inmode = t_mode;
446 if (! in_p)
447 rld[t_reload].outmode = t_mode;
449 if (reg_class_subset_p (t_class, rld[t_reload].class))
450 rld[t_reload].class = t_class;
452 rld[t_reload].opnum = MIN (rld[t_reload].opnum, opnum);
453 rld[t_reload].optional &= optional;
454 rld[t_reload].secondary_p = 1;
455 if (MERGE_TO_OTHER (secondary_type, rld[t_reload].when_needed,
456 opnum, rld[t_reload].opnum))
457 rld[t_reload].when_needed = RELOAD_OTHER;
460 if (t_reload == n_reloads)
462 /* We need to make a new tertiary reload for this register class. */
463 rld[t_reload].in = rld[t_reload].out = 0;
464 rld[t_reload].class = t_class;
465 rld[t_reload].inmode = in_p ? t_mode : VOIDmode;
466 rld[t_reload].outmode = ! in_p ? t_mode : VOIDmode;
467 rld[t_reload].reg_rtx = 0;
468 rld[t_reload].optional = optional;
469 rld[t_reload].nongroup = 0;
470 rld[t_reload].inc = 0;
471 /* Maybe we could combine these, but it seems too tricky. */
472 rld[t_reload].nocombine = 1;
473 rld[t_reload].in_reg = 0;
474 rld[t_reload].out_reg = 0;
475 rld[t_reload].opnum = opnum;
476 rld[t_reload].when_needed = secondary_type;
477 rld[t_reload].secondary_in_reload = -1;
478 rld[t_reload].secondary_out_reload = -1;
479 rld[t_reload].secondary_in_icode = CODE_FOR_nothing;
480 rld[t_reload].secondary_out_icode = CODE_FOR_nothing;
481 rld[t_reload].secondary_p = 1;
483 n_reloads++;
487 /* See if we can reuse an existing secondary reload. */
488 for (s_reload = 0; s_reload < n_reloads; s_reload++)
489 if (rld[s_reload].secondary_p
490 && (reg_class_subset_p (class, rld[s_reload].class)
491 || reg_class_subset_p (rld[s_reload].class, class))
492 && ((in_p && rld[s_reload].inmode == mode)
493 || (! in_p && rld[s_reload].outmode == mode))
494 && ((in_p && rld[s_reload].secondary_in_reload == t_reload)
495 || (! in_p && rld[s_reload].secondary_out_reload == t_reload))
496 && ((in_p && rld[s_reload].secondary_in_icode == t_icode)
497 || (! in_p && rld[s_reload].secondary_out_icode == t_icode))
498 && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES)
499 && MERGABLE_RELOADS (secondary_type, rld[s_reload].when_needed,
500 opnum, rld[s_reload].opnum))
502 if (in_p)
503 rld[s_reload].inmode = mode;
504 if (! in_p)
505 rld[s_reload].outmode = mode;
507 if (reg_class_subset_p (class, rld[s_reload].class))
508 rld[s_reload].class = class;
510 rld[s_reload].opnum = MIN (rld[s_reload].opnum, opnum);
511 rld[s_reload].optional &= optional;
512 rld[s_reload].secondary_p = 1;
513 if (MERGE_TO_OTHER (secondary_type, rld[s_reload].when_needed,
514 opnum, rld[s_reload].opnum))
515 rld[s_reload].when_needed = RELOAD_OTHER;
518 if (s_reload == n_reloads)
520 #ifdef SECONDARY_MEMORY_NEEDED
521 /* If we need a memory location to copy between the two reload regs,
522 set it up now. Note that we do the input case before making
523 the reload and the output case after. This is due to the
524 way reloads are output. */
526 if (in_p && icode == CODE_FOR_nothing
527 && SECONDARY_MEMORY_NEEDED (class, reload_class, mode))
528 get_secondary_mem (x, reload_mode, opnum, type);
529 #endif
531 /* We need to make a new secondary reload for this register class. */
532 rld[s_reload].in = rld[s_reload].out = 0;
533 rld[s_reload].class = class;
535 rld[s_reload].inmode = in_p ? mode : VOIDmode;
536 rld[s_reload].outmode = ! in_p ? mode : VOIDmode;
537 rld[s_reload].reg_rtx = 0;
538 rld[s_reload].optional = optional;
539 rld[s_reload].nongroup = 0;
540 rld[s_reload].inc = 0;
541 /* Maybe we could combine these, but it seems too tricky. */
542 rld[s_reload].nocombine = 1;
543 rld[s_reload].in_reg = 0;
544 rld[s_reload].out_reg = 0;
545 rld[s_reload].opnum = opnum;
546 rld[s_reload].when_needed = secondary_type;
547 rld[s_reload].secondary_in_reload = in_p ? t_reload : -1;
548 rld[s_reload].secondary_out_reload = ! in_p ? t_reload : -1;
549 rld[s_reload].secondary_in_icode = in_p ? t_icode : CODE_FOR_nothing;
550 rld[s_reload].secondary_out_icode
551 = ! in_p ? t_icode : CODE_FOR_nothing;
552 rld[s_reload].secondary_p = 1;
554 n_reloads++;
556 #ifdef SECONDARY_MEMORY_NEEDED
557 if (! in_p && icode == CODE_FOR_nothing
558 && SECONDARY_MEMORY_NEEDED (reload_class, class, mode))
559 get_secondary_mem (x, mode, opnum, type);
560 #endif
563 *picode = icode;
564 return s_reload;
566 #endif /* HAVE_SECONDARY_RELOADS */
568 #ifdef SECONDARY_MEMORY_NEEDED
570 /* Return a memory location that will be used to copy X in mode MODE.
571 If we haven't already made a location for this mode in this insn,
572 call find_reloads_address on the location being returned. */
575 get_secondary_mem (x, mode, opnum, type)
576 rtx x ATTRIBUTE_UNUSED;
577 enum machine_mode mode;
578 int opnum;
579 enum reload_type type;
581 rtx loc;
582 int mem_valid;
584 /* By default, if MODE is narrower than a word, widen it to a word.
585 This is required because most machines that require these memory
586 locations do not support short load and stores from all registers
587 (e.g., FP registers). */
589 #ifdef SECONDARY_MEMORY_NEEDED_MODE
590 mode = SECONDARY_MEMORY_NEEDED_MODE (mode);
591 #else
592 if (GET_MODE_BITSIZE (mode) < BITS_PER_WORD)
593 mode = mode_for_size (BITS_PER_WORD, GET_MODE_CLASS (mode), 0);
594 #endif
596 /* If we already have made a MEM for this operand in MODE, return it. */
597 if (secondary_memlocs_elim[(int) mode][opnum] != 0)
598 return secondary_memlocs_elim[(int) mode][opnum];
600 /* If this is the first time we've tried to get a MEM for this mode,
601 allocate a new one. `something_changed' in reload will get set
602 by noticing that the frame size has changed. */
604 if (secondary_memlocs[(int) mode] == 0)
606 #ifdef SECONDARY_MEMORY_NEEDED_RTX
607 secondary_memlocs[(int) mode] = SECONDARY_MEMORY_NEEDED_RTX (mode);
608 #else
609 secondary_memlocs[(int) mode]
610 = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
611 #endif
614 /* Get a version of the address doing any eliminations needed. If that
615 didn't give us a new MEM, make a new one if it isn't valid. */
617 loc = eliminate_regs (secondary_memlocs[(int) mode], VOIDmode, NULL_RTX);
618 mem_valid = strict_memory_address_p (mode, XEXP (loc, 0));
620 if (! mem_valid && loc == secondary_memlocs[(int) mode])
621 loc = copy_rtx (loc);
623 /* The only time the call below will do anything is if the stack
624 offset is too large. In that case IND_LEVELS doesn't matter, so we
625 can just pass a zero. Adjust the type to be the address of the
626 corresponding object. If the address was valid, save the eliminated
627 address. If it wasn't valid, we need to make a reload each time, so
628 don't save it. */
630 if (! mem_valid)
632 type = (type == RELOAD_FOR_INPUT ? RELOAD_FOR_INPUT_ADDRESS
633 : type == RELOAD_FOR_OUTPUT ? RELOAD_FOR_OUTPUT_ADDRESS
634 : RELOAD_OTHER);
636 find_reloads_address (mode, NULL_PTR, XEXP (loc, 0), &XEXP (loc, 0),
637 opnum, type, 0, 0);
640 secondary_memlocs_elim[(int) mode][opnum] = loc;
641 return loc;
644 /* Clear any secondary memory locations we've made. */
646 void
647 clear_secondary_mem ()
649 bzero ((char *) secondary_memlocs, sizeof secondary_memlocs);
651 #endif /* SECONDARY_MEMORY_NEEDED */
653 /* Find the largest class for which every register number plus N is valid in
654 M1 (if in range). Abort if no such class exists. */
656 static enum reg_class
657 find_valid_class (m1, n)
658 enum machine_mode m1;
659 int n;
661 int class;
662 int regno;
663 enum reg_class best_class = NO_REGS;
664 int best_size = 0;
666 for (class = 1; class < N_REG_CLASSES; class++)
668 int bad = 0;
669 for (regno = 0; regno < FIRST_PSEUDO_REGISTER && ! bad; regno++)
670 if (TEST_HARD_REG_BIT (reg_class_contents[class], regno)
671 && TEST_HARD_REG_BIT (reg_class_contents[class], regno + n)
672 && ! HARD_REGNO_MODE_OK (regno + n, m1))
673 bad = 1;
675 if (! bad && reg_class_size[class] > best_size)
676 best_class = class, best_size = reg_class_size[class];
679 if (best_size == 0)
680 abort ();
682 return best_class;
685 /* Return the number of a previously made reload that can be combined with
686 a new one, or n_reloads if none of the existing reloads can be used.
687 OUT, CLASS, TYPE and OPNUM are the same arguments as passed to
688 push_reload, they determine the kind of the new reload that we try to
689 combine. P_IN points to the corresponding value of IN, which can be
690 modified by this function.
691 DONT_SHARE is nonzero if we can't share any input-only reload for IN. */
692 static int
693 find_reusable_reload (p_in, out, class, type, opnum, dont_share)
694 rtx *p_in, out;
695 enum reg_class class;
696 enum reload_type type;
697 int opnum, dont_share;
699 rtx in = *p_in;
700 int i;
701 /* We can't merge two reloads if the output of either one is
702 earlyclobbered. */
704 if (earlyclobber_operand_p (out))
705 return n_reloads;
707 /* We can use an existing reload if the class is right
708 and at least one of IN and OUT is a match
709 and the other is at worst neutral.
710 (A zero compared against anything is neutral.)
712 If SMALL_REGISTER_CLASSES, don't use existing reloads unless they are
713 for the same thing since that can cause us to need more reload registers
714 than we otherwise would. */
716 for (i = 0; i < n_reloads; i++)
717 if ((reg_class_subset_p (class, rld[i].class)
718 || reg_class_subset_p (rld[i].class, class))
719 /* If the existing reload has a register, it must fit our class. */
720 && (rld[i].reg_rtx == 0
721 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
722 true_regnum (rld[i].reg_rtx)))
723 && ((in != 0 && MATCHES (rld[i].in, in) && ! dont_share
724 && (out == 0 || rld[i].out == 0 || MATCHES (rld[i].out, out)))
725 || (out != 0 && MATCHES (rld[i].out, out)
726 && (in == 0 || rld[i].in == 0 || MATCHES (rld[i].in, in))))
727 && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
728 && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES)
729 && MERGABLE_RELOADS (type, rld[i].when_needed, opnum, rld[i].opnum))
730 return i;
732 /* Reloading a plain reg for input can match a reload to postincrement
733 that reg, since the postincrement's value is the right value.
734 Likewise, it can match a preincrement reload, since we regard
735 the preincrementation as happening before any ref in this insn
736 to that register. */
737 for (i = 0; i < n_reloads; i++)
738 if ((reg_class_subset_p (class, rld[i].class)
739 || reg_class_subset_p (rld[i].class, class))
740 /* If the existing reload has a register, it must fit our
741 class. */
742 && (rld[i].reg_rtx == 0
743 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
744 true_regnum (rld[i].reg_rtx)))
745 && out == 0 && rld[i].out == 0 && rld[i].in != 0
746 && ((GET_CODE (in) == REG
747 && (GET_CODE (rld[i].in) == POST_INC
748 || GET_CODE (rld[i].in) == POST_DEC
749 || GET_CODE (rld[i].in) == PRE_INC
750 || GET_CODE (rld[i].in) == PRE_DEC)
751 && MATCHES (XEXP (rld[i].in, 0), in))
753 (GET_CODE (rld[i].in) == REG
754 && (GET_CODE (in) == POST_INC
755 || GET_CODE (in) == POST_DEC
756 || GET_CODE (in) == PRE_INC
757 || GET_CODE (in) == PRE_DEC)
758 && MATCHES (XEXP (in, 0), rld[i].in)))
759 && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
760 && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES)
761 && MERGABLE_RELOADS (type, rld[i].when_needed,
762 opnum, rld[i].opnum))
764 /* Make sure reload_in ultimately has the increment,
765 not the plain register. */
766 if (GET_CODE (in) == REG)
767 *p_in = rld[i].in;
768 return i;
770 return n_reloads;
773 /* Record one reload that needs to be performed.
774 IN is an rtx saying where the data are to be found before this instruction.
775 OUT says where they must be stored after the instruction.
776 (IN is zero for data not read, and OUT is zero for data not written.)
777 INLOC and OUTLOC point to the places in the instructions where
778 IN and OUT were found.
779 If IN and OUT are both non-zero, it means the same register must be used
780 to reload both IN and OUT.
782 CLASS is a register class required for the reloaded data.
783 INMODE is the machine mode that the instruction requires
784 for the reg that replaces IN and OUTMODE is likewise for OUT.
786 If IN is zero, then OUT's location and mode should be passed as
787 INLOC and INMODE.
789 STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
791 OPTIONAL nonzero means this reload does not need to be performed:
792 it can be discarded if that is more convenient.
794 OPNUM and TYPE say what the purpose of this reload is.
796 The return value is the reload-number for this reload.
798 If both IN and OUT are nonzero, in some rare cases we might
799 want to make two separate reloads. (Actually we never do this now.)
800 Therefore, the reload-number for OUT is stored in
801 output_reloadnum when we return; the return value applies to IN.
802 Usually (presently always), when IN and OUT are nonzero,
803 the two reload-numbers are equal, but the caller should be careful to
804 distinguish them. */
806 static int
807 push_reload (in, out, inloc, outloc, class,
808 inmode, outmode, strict_low, optional, opnum, type)
809 rtx in, out;
810 rtx *inloc, *outloc;
811 enum reg_class class;
812 enum machine_mode inmode, outmode;
813 int strict_low;
814 int optional;
815 int opnum;
816 enum reload_type type;
818 register int i;
819 int dont_share = 0;
820 int dont_remove_subreg = 0;
821 rtx *in_subreg_loc = 0, *out_subreg_loc = 0;
822 int secondary_in_reload = -1, secondary_out_reload = -1;
823 enum insn_code secondary_in_icode = CODE_FOR_nothing;
824 enum insn_code secondary_out_icode = CODE_FOR_nothing;
826 /* INMODE and/or OUTMODE could be VOIDmode if no mode
827 has been specified for the operand. In that case,
828 use the operand's mode as the mode to reload. */
829 if (inmode == VOIDmode && in != 0)
830 inmode = GET_MODE (in);
831 if (outmode == VOIDmode && out != 0)
832 outmode = GET_MODE (out);
834 /* If IN is a pseudo register everywhere-equivalent to a constant, and
835 it is not in a hard register, reload straight from the constant,
836 since we want to get rid of such pseudo registers.
837 Often this is done earlier, but not always in find_reloads_address. */
838 if (in != 0 && GET_CODE (in) == REG)
840 register int regno = REGNO (in);
842 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
843 && reg_equiv_constant[regno] != 0)
844 in = reg_equiv_constant[regno];
847 /* Likewise for OUT. Of course, OUT will never be equivalent to
848 an actual constant, but it might be equivalent to a memory location
849 (in the case of a parameter). */
850 if (out != 0 && GET_CODE (out) == REG)
852 register int regno = REGNO (out);
854 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
855 && reg_equiv_constant[regno] != 0)
856 out = reg_equiv_constant[regno];
859 /* If we have a read-write operand with an address side-effect,
860 change either IN or OUT so the side-effect happens only once. */
861 if (in != 0 && out != 0 && GET_CODE (in) == MEM && rtx_equal_p (in, out))
863 if (GET_CODE (XEXP (in, 0)) == POST_INC
864 || GET_CODE (XEXP (in, 0)) == POST_DEC)
865 in = gen_rtx_MEM (GET_MODE (in), XEXP (XEXP (in, 0), 0));
866 if (GET_CODE (XEXP (in, 0)) == PRE_INC
867 || GET_CODE (XEXP (in, 0)) == PRE_DEC)
868 out = gen_rtx_MEM (GET_MODE (out), XEXP (XEXP (out, 0), 0));
871 /* If we are reloading a (SUBREG constant ...), really reload just the
872 inside expression in its own mode. Similarly for (SUBREG (PLUS ...)).
873 If we have (SUBREG:M1 (MEM:M2 ...) ...) (or an inner REG that is still
874 a pseudo and hence will become a MEM) with M1 wider than M2 and the
875 register is a pseudo, also reload the inside expression.
876 For machines that extend byte loads, do this for any SUBREG of a pseudo
877 where both M1 and M2 are a word or smaller, M1 is wider than M2, and
878 M2 is an integral mode that gets extended when loaded.
879 Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
880 either M1 is not valid for R or M2 is wider than a word but we only
881 need one word to store an M2-sized quantity in R.
882 (However, if OUT is nonzero, we need to reload the reg *and*
883 the subreg, so do nothing here, and let following statement handle it.)
885 Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere;
886 we can't handle it here because CONST_INT does not indicate a mode.
888 Similarly, we must reload the inside expression if we have a
889 STRICT_LOW_PART (presumably, in == out in the cas).
891 Also reload the inner expression if it does not require a secondary
892 reload but the SUBREG does.
894 Finally, reload the inner expression if it is a register that is in
895 the class whose registers cannot be referenced in a different size
896 and M1 is not the same size as M2. If SUBREG_WORD is nonzero, we
897 cannot reload just the inside since we might end up with the wrong
898 register class. But if it is inside a STRICT_LOW_PART, we have
899 no choice, so we hope we do get the right register class there. */
901 if (in != 0 && GET_CODE (in) == SUBREG
902 && (SUBREG_WORD (in) == 0 || strict_low)
903 #ifdef CLASS_CANNOT_CHANGE_SIZE
904 && class != CLASS_CANNOT_CHANGE_SIZE
905 #endif
906 && (CONSTANT_P (SUBREG_REG (in))
907 || GET_CODE (SUBREG_REG (in)) == PLUS
908 || strict_low
909 || (((GET_CODE (SUBREG_REG (in)) == REG
910 && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER)
911 || GET_CODE (SUBREG_REG (in)) == MEM)
912 && ((GET_MODE_SIZE (inmode)
913 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
914 #ifdef LOAD_EXTEND_OP
915 || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
916 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
917 <= UNITS_PER_WORD)
918 && (GET_MODE_SIZE (inmode)
919 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
920 && INTEGRAL_MODE_P (GET_MODE (SUBREG_REG (in)))
921 && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (in))) != NIL)
922 #endif
923 #ifdef WORD_REGISTER_OPERATIONS
924 || ((GET_MODE_SIZE (inmode)
925 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
926 && ((GET_MODE_SIZE (inmode) - 1) / UNITS_PER_WORD ==
927 ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))) - 1)
928 / UNITS_PER_WORD)))
929 #endif
931 || (GET_CODE (SUBREG_REG (in)) == REG
932 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
933 /* The case where out is nonzero
934 is handled differently in the following statement. */
935 && (out == 0 || SUBREG_WORD (in) == 0)
936 && ((GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
937 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
938 > UNITS_PER_WORD)
939 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
940 / UNITS_PER_WORD)
941 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (in)),
942 GET_MODE (SUBREG_REG (in)))))
943 || ! HARD_REGNO_MODE_OK ((REGNO (SUBREG_REG (in))
944 + SUBREG_WORD (in)),
945 inmode)))
946 #ifdef SECONDARY_INPUT_RELOAD_CLASS
947 || (SECONDARY_INPUT_RELOAD_CLASS (class, inmode, in) != NO_REGS
948 && (SECONDARY_INPUT_RELOAD_CLASS (class,
949 GET_MODE (SUBREG_REG (in)),
950 SUBREG_REG (in))
951 == NO_REGS))
952 #endif
953 #ifdef CLASS_CANNOT_CHANGE_SIZE
954 || (GET_CODE (SUBREG_REG (in)) == REG
955 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
956 && (TEST_HARD_REG_BIT
957 (reg_class_contents[(int) CLASS_CANNOT_CHANGE_SIZE],
958 REGNO (SUBREG_REG (in))))
959 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
960 != GET_MODE_SIZE (inmode)))
961 #endif
964 in_subreg_loc = inloc;
965 inloc = &SUBREG_REG (in);
966 in = *inloc;
967 #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
968 if (GET_CODE (in) == MEM)
969 /* This is supposed to happen only for paradoxical subregs made by
970 combine.c. (SUBREG (MEM)) isn't supposed to occur other ways. */
971 if (GET_MODE_SIZE (GET_MODE (in)) > GET_MODE_SIZE (inmode))
972 abort ();
973 #endif
974 inmode = GET_MODE (in);
977 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
978 either M1 is not valid for R or M2 is wider than a word but we only
979 need one word to store an M2-sized quantity in R.
981 However, we must reload the inner reg *as well as* the subreg in
982 that case. */
984 /* Similar issue for (SUBREG constant ...) if it was not handled by the
985 code above. This can happen if SUBREG_WORD != 0. */
987 if (in != 0 && GET_CODE (in) == SUBREG
988 && (CONSTANT_P (SUBREG_REG (in))
989 || (GET_CODE (SUBREG_REG (in)) == REG
990 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
991 && (! HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (in))
992 + SUBREG_WORD (in),
993 inmode)
994 || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
995 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
996 > UNITS_PER_WORD)
997 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
998 / UNITS_PER_WORD)
999 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (in)),
1000 GET_MODE (SUBREG_REG (in)))))))))
1002 /* This relies on the fact that emit_reload_insns outputs the
1003 instructions for input reloads of type RELOAD_OTHER in the same
1004 order as the reloads. Thus if the outer reload is also of type
1005 RELOAD_OTHER, we are guaranteed that this inner reload will be
1006 output before the outer reload. */
1007 push_reload (SUBREG_REG (in), NULL_RTX, &SUBREG_REG (in), NULL_PTR,
1008 find_valid_class (inmode, SUBREG_WORD (in)),
1009 VOIDmode, VOIDmode, 0, 0, opnum, type);
1010 dont_remove_subreg = 1;
1013 /* Similarly for paradoxical and problematical SUBREGs on the output.
1014 Note that there is no reason we need worry about the previous value
1015 of SUBREG_REG (out); even if wider than out,
1016 storing in a subreg is entitled to clobber it all
1017 (except in the case of STRICT_LOW_PART,
1018 and in that case the constraint should label it input-output.) */
1019 if (out != 0 && GET_CODE (out) == SUBREG
1020 && (SUBREG_WORD (out) == 0 || strict_low)
1021 #ifdef CLASS_CANNOT_CHANGE_SIZE
1022 && class != CLASS_CANNOT_CHANGE_SIZE
1023 #endif
1024 && (CONSTANT_P (SUBREG_REG (out))
1025 || strict_low
1026 || (((GET_CODE (SUBREG_REG (out)) == REG
1027 && REGNO (SUBREG_REG (out)) >= FIRST_PSEUDO_REGISTER)
1028 || GET_CODE (SUBREG_REG (out)) == MEM)
1029 && ((GET_MODE_SIZE (outmode)
1030 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))
1031 #ifdef WORD_REGISTER_OPERATIONS
1032 || ((GET_MODE_SIZE (outmode)
1033 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))
1034 && ((GET_MODE_SIZE (outmode) - 1) / UNITS_PER_WORD ==
1035 ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))) - 1)
1036 / UNITS_PER_WORD)))
1037 #endif
1039 || (GET_CODE (SUBREG_REG (out)) == REG
1040 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1041 && ((GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
1042 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1043 > UNITS_PER_WORD)
1044 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1045 / UNITS_PER_WORD)
1046 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (out)),
1047 GET_MODE (SUBREG_REG (out)))))
1048 || ! HARD_REGNO_MODE_OK ((REGNO (SUBREG_REG (out))
1049 + SUBREG_WORD (out)),
1050 outmode)))
1051 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1052 || (SECONDARY_OUTPUT_RELOAD_CLASS (class, outmode, out) != NO_REGS
1053 && (SECONDARY_OUTPUT_RELOAD_CLASS (class,
1054 GET_MODE (SUBREG_REG (out)),
1055 SUBREG_REG (out))
1056 == NO_REGS))
1057 #endif
1058 #ifdef CLASS_CANNOT_CHANGE_SIZE
1059 || (GET_CODE (SUBREG_REG (out)) == REG
1060 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1061 && (TEST_HARD_REG_BIT
1062 (reg_class_contents[(int) CLASS_CANNOT_CHANGE_SIZE],
1063 REGNO (SUBREG_REG (out))))
1064 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1065 != GET_MODE_SIZE (outmode)))
1066 #endif
1069 out_subreg_loc = outloc;
1070 outloc = &SUBREG_REG (out);
1071 out = *outloc;
1072 #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
1073 if (GET_CODE (out) == MEM
1074 && GET_MODE_SIZE (GET_MODE (out)) > GET_MODE_SIZE (outmode))
1075 abort ();
1076 #endif
1077 outmode = GET_MODE (out);
1080 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
1081 either M1 is not valid for R or M2 is wider than a word but we only
1082 need one word to store an M2-sized quantity in R.
1084 However, we must reload the inner reg *as well as* the subreg in
1085 that case. In this case, the inner reg is an in-out reload. */
1087 if (out != 0 && GET_CODE (out) == SUBREG
1088 && GET_CODE (SUBREG_REG (out)) == REG
1089 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1090 && (! HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (out)) + SUBREG_WORD (out),
1091 outmode)
1092 || (GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
1093 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1094 > UNITS_PER_WORD)
1095 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1096 / UNITS_PER_WORD)
1097 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (out)),
1098 GET_MODE (SUBREG_REG (out)))))))
1100 /* This relies on the fact that emit_reload_insns outputs the
1101 instructions for output reloads of type RELOAD_OTHER in reverse
1102 order of the reloads. Thus if the outer reload is also of type
1103 RELOAD_OTHER, we are guaranteed that this inner reload will be
1104 output after the outer reload. */
1105 dont_remove_subreg = 1;
1106 push_reload (SUBREG_REG (out), SUBREG_REG (out), &SUBREG_REG (out),
1107 &SUBREG_REG (out),
1108 find_valid_class (outmode, SUBREG_WORD (out)),
1109 VOIDmode, VOIDmode, 0, 0,
1110 opnum, RELOAD_OTHER);
1113 /* If IN appears in OUT, we can't share any input-only reload for IN. */
1114 if (in != 0 && out != 0 && GET_CODE (out) == MEM
1115 && (GET_CODE (in) == REG || GET_CODE (in) == MEM)
1116 && reg_overlap_mentioned_for_reload_p (in, XEXP (out, 0)))
1117 dont_share = 1;
1119 /* If IN is a SUBREG of a hard register, make a new REG. This
1120 simplifies some of the cases below. */
1122 if (in != 0 && GET_CODE (in) == SUBREG && GET_CODE (SUBREG_REG (in)) == REG
1123 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1124 && ! dont_remove_subreg)
1125 in = gen_rtx_REG (GET_MODE (in),
1126 REGNO (SUBREG_REG (in)) + SUBREG_WORD (in));
1128 /* Similarly for OUT. */
1129 if (out != 0 && GET_CODE (out) == SUBREG
1130 && GET_CODE (SUBREG_REG (out)) == REG
1131 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1132 && ! dont_remove_subreg)
1133 out = gen_rtx_REG (GET_MODE (out),
1134 REGNO (SUBREG_REG (out)) + SUBREG_WORD (out));
1136 /* Narrow down the class of register wanted if that is
1137 desirable on this machine for efficiency. */
1138 if (in != 0)
1139 class = PREFERRED_RELOAD_CLASS (in, class);
1141 /* Output reloads may need analogous treatment, different in detail. */
1142 #ifdef PREFERRED_OUTPUT_RELOAD_CLASS
1143 if (out != 0)
1144 class = PREFERRED_OUTPUT_RELOAD_CLASS (out, class);
1145 #endif
1147 /* Make sure we use a class that can handle the actual pseudo
1148 inside any subreg. For example, on the 386, QImode regs
1149 can appear within SImode subregs. Although GENERAL_REGS
1150 can handle SImode, QImode needs a smaller class. */
1151 #ifdef LIMIT_RELOAD_CLASS
1152 if (in_subreg_loc)
1153 class = LIMIT_RELOAD_CLASS (inmode, class);
1154 else if (in != 0 && GET_CODE (in) == SUBREG)
1155 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (in)), class);
1157 if (out_subreg_loc)
1158 class = LIMIT_RELOAD_CLASS (outmode, class);
1159 if (out != 0 && GET_CODE (out) == SUBREG)
1160 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (out)), class);
1161 #endif
1163 /* Verify that this class is at least possible for the mode that
1164 is specified. */
1165 if (this_insn_is_asm)
1167 enum machine_mode mode;
1168 if (GET_MODE_SIZE (inmode) > GET_MODE_SIZE (outmode))
1169 mode = inmode;
1170 else
1171 mode = outmode;
1172 if (mode == VOIDmode)
1174 error_for_asm (this_insn, "cannot reload integer constant operand in `asm'");
1175 mode = word_mode;
1176 if (in != 0)
1177 inmode = word_mode;
1178 if (out != 0)
1179 outmode = word_mode;
1181 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1182 if (HARD_REGNO_MODE_OK (i, mode)
1183 && TEST_HARD_REG_BIT (reg_class_contents[(int) class], i))
1185 int nregs = HARD_REGNO_NREGS (i, mode);
1187 int j;
1188 for (j = 1; j < nregs; j++)
1189 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], i + j))
1190 break;
1191 if (j == nregs)
1192 break;
1194 if (i == FIRST_PSEUDO_REGISTER)
1196 error_for_asm (this_insn, "impossible register constraint in `asm'");
1197 class = ALL_REGS;
1201 /* Optional output reloads are always OK even if we have no register class,
1202 since the function of these reloads is only to have spill_reg_store etc.
1203 set, so that the storing insn can be deleted later. */
1204 if (class == NO_REGS
1205 && (optional == 0 || type != RELOAD_FOR_OUTPUT))
1206 abort ();
1208 i = find_reusable_reload (&in, out, class, type, opnum, dont_share);
1210 if (i == n_reloads)
1212 /* See if we need a secondary reload register to move between CLASS
1213 and IN or CLASS and OUT. Get the icode and push any required reloads
1214 needed for each of them if so. */
1216 #ifdef SECONDARY_INPUT_RELOAD_CLASS
1217 if (in != 0)
1218 secondary_in_reload
1219 = push_secondary_reload (1, in, opnum, optional, class, inmode, type,
1220 &secondary_in_icode);
1221 #endif
1223 #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
1224 if (out != 0 && GET_CODE (out) != SCRATCH)
1225 secondary_out_reload
1226 = push_secondary_reload (0, out, opnum, optional, class, outmode,
1227 type, &secondary_out_icode);
1228 #endif
1230 /* We found no existing reload suitable for re-use.
1231 So add an additional reload. */
1233 #ifdef SECONDARY_MEMORY_NEEDED
1234 /* If a memory location is needed for the copy, make one. */
1235 if (in != 0 && GET_CODE (in) == REG
1236 && REGNO (in) < FIRST_PSEUDO_REGISTER
1237 && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (REGNO (in)),
1238 class, inmode))
1239 get_secondary_mem (in, inmode, opnum, type);
1240 #endif
1242 i = n_reloads;
1243 rld[i].in = in;
1244 rld[i].out = out;
1245 rld[i].class = class;
1246 rld[i].inmode = inmode;
1247 rld[i].outmode = outmode;
1248 rld[i].reg_rtx = 0;
1249 rld[i].optional = optional;
1250 rld[i].nongroup = 0;
1251 rld[i].inc = 0;
1252 rld[i].nocombine = 0;
1253 rld[i].in_reg = inloc ? *inloc : 0;
1254 rld[i].out_reg = outloc ? *outloc : 0;
1255 rld[i].opnum = opnum;
1256 rld[i].when_needed = type;
1257 rld[i].secondary_in_reload = secondary_in_reload;
1258 rld[i].secondary_out_reload = secondary_out_reload;
1259 rld[i].secondary_in_icode = secondary_in_icode;
1260 rld[i].secondary_out_icode = secondary_out_icode;
1261 rld[i].secondary_p = 0;
1263 n_reloads++;
1265 #ifdef SECONDARY_MEMORY_NEEDED
1266 if (out != 0 && GET_CODE (out) == REG
1267 && REGNO (out) < FIRST_PSEUDO_REGISTER
1268 && SECONDARY_MEMORY_NEEDED (class, REGNO_REG_CLASS (REGNO (out)),
1269 outmode))
1270 get_secondary_mem (out, outmode, opnum, type);
1271 #endif
1273 else
1275 /* We are reusing an existing reload,
1276 but we may have additional information for it.
1277 For example, we may now have both IN and OUT
1278 while the old one may have just one of them. */
1280 /* The modes can be different. If they are, we want to reload in
1281 the larger mode, so that the value is valid for both modes. */
1282 if (inmode != VOIDmode
1283 && GET_MODE_SIZE (inmode) > GET_MODE_SIZE (rld[i].inmode))
1284 rld[i].inmode = inmode;
1285 if (outmode != VOIDmode
1286 && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (rld[i].outmode))
1287 rld[i].outmode = outmode;
1288 if (in != 0)
1290 rtx in_reg = inloc ? *inloc : 0;
1291 /* If we merge reloads for two distinct rtl expressions that
1292 are identical in content, there might be duplicate address
1293 reloads. Remove the extra set now, so that if we later find
1294 that we can inherit this reload, we can get rid of the
1295 address reloads altogether.
1297 Do not do this if both reloads are optional since the result
1298 would be an optional reload which could potentially leave
1299 unresolved address replacements.
1301 It is not sufficient to call transfer_replacements since
1302 choose_reload_regs will remove the replacements for address
1303 reloads of inherited reloads which results in the same
1304 problem. */
1305 if (rld[i].in != in && rtx_equal_p (in, rld[i].in)
1306 && ! (rld[i].optional && optional))
1308 /* We must keep the address reload with the lower operand
1309 number alive. */
1310 if (opnum > rld[i].opnum)
1312 remove_address_replacements (in);
1313 in = rld[i].in;
1314 in_reg = rld[i].in_reg;
1316 else
1317 remove_address_replacements (rld[i].in);
1319 rld[i].in = in;
1320 rld[i].in_reg = in_reg;
1322 if (out != 0)
1324 rld[i].out = out;
1325 rld[i].out_reg = outloc ? *outloc : 0;
1327 if (reg_class_subset_p (class, rld[i].class))
1328 rld[i].class = class;
1329 rld[i].optional &= optional;
1330 if (MERGE_TO_OTHER (type, rld[i].when_needed,
1331 opnum, rld[i].opnum))
1332 rld[i].when_needed = RELOAD_OTHER;
1333 rld[i].opnum = MIN (rld[i].opnum, opnum);
1336 /* If the ostensible rtx being reload differs from the rtx found
1337 in the location to substitute, this reload is not safe to combine
1338 because we cannot reliably tell whether it appears in the insn. */
1340 if (in != 0 && in != *inloc)
1341 rld[i].nocombine = 1;
1343 #if 0
1344 /* This was replaced by changes in find_reloads_address_1 and the new
1345 function inc_for_reload, which go with a new meaning of reload_inc. */
1347 /* If this is an IN/OUT reload in an insn that sets the CC,
1348 it must be for an autoincrement. It doesn't work to store
1349 the incremented value after the insn because that would clobber the CC.
1350 So we must do the increment of the value reloaded from,
1351 increment it, store it back, then decrement again. */
1352 if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
1354 out = 0;
1355 rld[i].out = 0;
1356 rld[i].inc = find_inc_amount (PATTERN (this_insn), in);
1357 /* If we did not find a nonzero amount-to-increment-by,
1358 that contradicts the belief that IN is being incremented
1359 in an address in this insn. */
1360 if (rld[i].inc == 0)
1361 abort ();
1363 #endif
1365 /* If we will replace IN and OUT with the reload-reg,
1366 record where they are located so that substitution need
1367 not do a tree walk. */
1369 if (replace_reloads)
1371 if (inloc != 0)
1373 register struct replacement *r = &replacements[n_replacements++];
1374 r->what = i;
1375 r->subreg_loc = in_subreg_loc;
1376 r->where = inloc;
1377 r->mode = inmode;
1379 if (outloc != 0 && outloc != inloc)
1381 register struct replacement *r = &replacements[n_replacements++];
1382 r->what = i;
1383 r->where = outloc;
1384 r->subreg_loc = out_subreg_loc;
1385 r->mode = outmode;
1389 /* If this reload is just being introduced and it has both
1390 an incoming quantity and an outgoing quantity that are
1391 supposed to be made to match, see if either one of the two
1392 can serve as the place to reload into.
1394 If one of them is acceptable, set rld[i].reg_rtx
1395 to that one. */
1397 if (in != 0 && out != 0 && in != out && rld[i].reg_rtx == 0)
1399 rld[i].reg_rtx = find_dummy_reload (in, out, inloc, outloc,
1400 inmode, outmode,
1401 rld[i].class, i,
1402 earlyclobber_operand_p (out));
1404 /* If the outgoing register already contains the same value
1405 as the incoming one, we can dispense with loading it.
1406 The easiest way to tell the caller that is to give a phony
1407 value for the incoming operand (same as outgoing one). */
1408 if (rld[i].reg_rtx == out
1409 && (GET_CODE (in) == REG || CONSTANT_P (in))
1410 && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
1411 static_reload_reg_p, i, inmode))
1412 rld[i].in = out;
1415 /* If this is an input reload and the operand contains a register that
1416 dies in this insn and is used nowhere else, see if it is the right class
1417 to be used for this reload. Use it if so. (This occurs most commonly
1418 in the case of paradoxical SUBREGs and in-out reloads). We cannot do
1419 this if it is also an output reload that mentions the register unless
1420 the output is a SUBREG that clobbers an entire register.
1422 Note that the operand might be one of the spill regs, if it is a
1423 pseudo reg and we are in a block where spilling has not taken place.
1424 But if there is no spilling in this block, that is OK.
1425 An explicitly used hard reg cannot be a spill reg. */
1427 if (rld[i].reg_rtx == 0 && in != 0)
1429 rtx note;
1430 int regno;
1432 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1433 if (REG_NOTE_KIND (note) == REG_DEAD
1434 && GET_CODE (XEXP (note, 0)) == REG
1435 && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1436 && reg_mentioned_p (XEXP (note, 0), in)
1437 && ! refers_to_regno_for_reload_p (regno,
1438 (regno
1439 + HARD_REGNO_NREGS (regno,
1440 inmode)),
1441 PATTERN (this_insn), inloc)
1442 /* If this is also an output reload, IN cannot be used as
1443 the reload register if it is set in this insn unless IN
1444 is also OUT. */
1445 && (out == 0 || in == out
1446 || ! hard_reg_set_here_p (regno,
1447 (regno
1448 + HARD_REGNO_NREGS (regno,
1449 inmode)),
1450 PATTERN (this_insn)))
1451 /* ??? Why is this code so different from the previous?
1452 Is there any simple coherent way to describe the two together?
1453 What's going on here. */
1454 && (in != out
1455 || (GET_CODE (in) == SUBREG
1456 && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1))
1457 / UNITS_PER_WORD)
1458 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1459 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
1460 /* Make sure the operand fits in the reg that dies. */
1461 && GET_MODE_SIZE (inmode) <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
1462 && HARD_REGNO_MODE_OK (regno, inmode)
1463 && GET_MODE_SIZE (outmode) <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
1464 && HARD_REGNO_MODE_OK (regno, outmode)
1465 && TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno)
1466 && !fixed_regs[regno])
1468 rld[i].reg_rtx = gen_rtx_REG (inmode, regno);
1469 break;
1473 if (out)
1474 output_reloadnum = i;
1476 return i;
1479 /* Record an additional place we must replace a value
1480 for which we have already recorded a reload.
1481 RELOADNUM is the value returned by push_reload
1482 when the reload was recorded.
1483 This is used in insn patterns that use match_dup. */
1485 static void
1486 push_replacement (loc, reloadnum, mode)
1487 rtx *loc;
1488 int reloadnum;
1489 enum machine_mode mode;
1491 if (replace_reloads)
1493 register struct replacement *r = &replacements[n_replacements++];
1494 r->what = reloadnum;
1495 r->where = loc;
1496 r->subreg_loc = 0;
1497 r->mode = mode;
1501 /* Transfer all replacements that used to be in reload FROM to be in
1502 reload TO. */
1504 void
1505 transfer_replacements (to, from)
1506 int to, from;
1508 int i;
1510 for (i = 0; i < n_replacements; i++)
1511 if (replacements[i].what == from)
1512 replacements[i].what = to;
1515 /* IN_RTX is the value loaded by a reload that we now decided to inherit,
1516 or a subpart of it. If we have any replacements registered for IN_RTX,
1517 cancel the reloads that were supposed to load them.
1518 Return non-zero if we canceled any reloads. */
1520 remove_address_replacements (in_rtx)
1521 rtx in_rtx;
1523 int i, j;
1524 char reload_flags[MAX_RELOADS];
1525 int something_changed = 0;
1527 bzero (reload_flags, sizeof reload_flags);
1528 for (i = 0, j = 0; i < n_replacements; i++)
1530 if (loc_mentioned_in_p (replacements[i].where, in_rtx))
1531 reload_flags[replacements[i].what] |= 1;
1532 else
1534 replacements[j++] = replacements[i];
1535 reload_flags[replacements[i].what] |= 2;
1538 /* Note that the following store must be done before the recursive calls. */
1539 n_replacements = j;
1541 for (i = n_reloads - 1; i >= 0; i--)
1543 if (reload_flags[i] == 1)
1545 deallocate_reload_reg (i);
1546 remove_address_replacements (rld[i].in);
1547 rld[i].in = 0;
1548 something_changed = 1;
1551 return something_changed;
1554 /* Return non-zero if IN contains a piece of rtl that has the address LOC */
1555 static int
1556 loc_mentioned_in_p (loc, in)
1557 rtx *loc, in;
1559 enum rtx_code code = GET_CODE (in);
1560 const char *fmt = GET_RTX_FORMAT (code);
1561 int i, j;
1563 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1565 if (loc == &in->fld[i].rtx)
1566 return 1;
1567 if (fmt[i] == 'e')
1569 if (loc_mentioned_in_p (loc, XEXP (in, i)))
1570 return 1;
1572 else if (fmt[i] == 'E')
1573 for (j = XVECLEN (in, i) - 1; i >= 0; i--)
1574 if (loc_mentioned_in_p (loc, XVECEXP (in, i, j)))
1575 return 1;
1577 return 0;
1580 /* If there is only one output reload, and it is not for an earlyclobber
1581 operand, try to combine it with a (logically unrelated) input reload
1582 to reduce the number of reload registers needed.
1584 This is safe if the input reload does not appear in
1585 the value being output-reloaded, because this implies
1586 it is not needed any more once the original insn completes.
1588 If that doesn't work, see we can use any of the registers that
1589 die in this insn as a reload register. We can if it is of the right
1590 class and does not appear in the value being output-reloaded. */
1592 static void
1593 combine_reloads ()
1595 int i;
1596 int output_reload = -1;
1597 int secondary_out = -1;
1598 rtx note;
1600 /* Find the output reload; return unless there is exactly one
1601 and that one is mandatory. */
1603 for (i = 0; i < n_reloads; i++)
1604 if (rld[i].out != 0)
1606 if (output_reload >= 0)
1607 return;
1608 output_reload = i;
1611 if (output_reload < 0 || rld[output_reload].optional)
1612 return;
1614 /* An input-output reload isn't combinable. */
1616 if (rld[output_reload].in != 0)
1617 return;
1619 /* If this reload is for an earlyclobber operand, we can't do anything. */
1620 if (earlyclobber_operand_p (rld[output_reload].out))
1621 return;
1623 /* Check each input reload; can we combine it? */
1625 for (i = 0; i < n_reloads; i++)
1626 if (rld[i].in && ! rld[i].optional && ! rld[i].nocombine
1627 /* Life span of this reload must not extend past main insn. */
1628 && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS
1629 && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS
1630 && rld[i].when_needed != RELOAD_OTHER
1631 && (CLASS_MAX_NREGS (rld[i].class, rld[i].inmode)
1632 == CLASS_MAX_NREGS (rld[output_reload].class,
1633 rld[output_reload].outmode))
1634 && rld[i].inc == 0
1635 && rld[i].reg_rtx == 0
1636 #ifdef SECONDARY_MEMORY_NEEDED
1637 /* Don't combine two reloads with different secondary
1638 memory locations. */
1639 && (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum] == 0
1640 || secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] == 0
1641 || rtx_equal_p (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum],
1642 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum]))
1643 #endif
1644 && (SMALL_REGISTER_CLASSES
1645 ? (rld[i].class == rld[output_reload].class)
1646 : (reg_class_subset_p (rld[i].class,
1647 rld[output_reload].class)
1648 || reg_class_subset_p (rld[output_reload].class,
1649 rld[i].class)))
1650 && (MATCHES (rld[i].in, rld[output_reload].out)
1651 /* Args reversed because the first arg seems to be
1652 the one that we imagine being modified
1653 while the second is the one that might be affected. */
1654 || (! reg_overlap_mentioned_for_reload_p (rld[output_reload].out,
1655 rld[i].in)
1656 /* However, if the input is a register that appears inside
1657 the output, then we also can't share.
1658 Imagine (set (mem (reg 69)) (plus (reg 69) ...)).
1659 If the same reload reg is used for both reg 69 and the
1660 result to be stored in memory, then that result
1661 will clobber the address of the memory ref. */
1662 && ! (GET_CODE (rld[i].in) == REG
1663 && reg_overlap_mentioned_for_reload_p (rld[i].in,
1664 rld[output_reload].out))))
1665 && (reg_class_size[(int) rld[i].class]
1666 || SMALL_REGISTER_CLASSES)
1667 /* We will allow making things slightly worse by combining an
1668 input and an output, but no worse than that. */
1669 && (rld[i].when_needed == RELOAD_FOR_INPUT
1670 || rld[i].when_needed == RELOAD_FOR_OUTPUT))
1672 int j;
1674 /* We have found a reload to combine with! */
1675 rld[i].out = rld[output_reload].out;
1676 rld[i].out_reg = rld[output_reload].out_reg;
1677 rld[i].outmode = rld[output_reload].outmode;
1678 /* Mark the old output reload as inoperative. */
1679 rld[output_reload].out = 0;
1680 /* The combined reload is needed for the entire insn. */
1681 rld[i].when_needed = RELOAD_OTHER;
1682 /* If the output reload had a secondary reload, copy it. */
1683 if (rld[output_reload].secondary_out_reload != -1)
1685 rld[i].secondary_out_reload
1686 = rld[output_reload].secondary_out_reload;
1687 rld[i].secondary_out_icode
1688 = rld[output_reload].secondary_out_icode;
1691 #ifdef SECONDARY_MEMORY_NEEDED
1692 /* Copy any secondary MEM. */
1693 if (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] != 0)
1694 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum]
1695 = secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum];
1696 #endif
1697 /* If required, minimize the register class. */
1698 if (reg_class_subset_p (rld[output_reload].class,
1699 rld[i].class))
1700 rld[i].class = rld[output_reload].class;
1702 /* Transfer all replacements from the old reload to the combined. */
1703 for (j = 0; j < n_replacements; j++)
1704 if (replacements[j].what == output_reload)
1705 replacements[j].what = i;
1707 return;
1710 /* If this insn has only one operand that is modified or written (assumed
1711 to be the first), it must be the one corresponding to this reload. It
1712 is safe to use anything that dies in this insn for that output provided
1713 that it does not occur in the output (we already know it isn't an
1714 earlyclobber. If this is an asm insn, give up. */
1716 if (INSN_CODE (this_insn) == -1)
1717 return;
1719 for (i = 1; i < insn_data[INSN_CODE (this_insn)].n_operands; i++)
1720 if (insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '='
1721 || insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '+')
1722 return;
1724 /* See if some hard register that dies in this insn and is not used in
1725 the output is the right class. Only works if the register we pick
1726 up can fully hold our output reload. */
1727 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1728 if (REG_NOTE_KIND (note) == REG_DEAD
1729 && GET_CODE (XEXP (note, 0)) == REG
1730 && ! reg_overlap_mentioned_for_reload_p (XEXP (note, 0),
1731 rld[output_reload].out)
1732 && REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1733 && HARD_REGNO_MODE_OK (REGNO (XEXP (note, 0)), rld[output_reload].outmode)
1734 && TEST_HARD_REG_BIT (reg_class_contents[(int) rld[output_reload].class],
1735 REGNO (XEXP (note, 0)))
1736 && (HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), rld[output_reload].outmode)
1737 <= HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), GET_MODE (XEXP (note, 0))))
1738 /* Ensure that a secondary or tertiary reload for this output
1739 won't want this register. */
1740 && ((secondary_out = rld[output_reload].secondary_out_reload) == -1
1741 || (! (TEST_HARD_REG_BIT
1742 (reg_class_contents[(int) rld[secondary_out].class],
1743 REGNO (XEXP (note, 0))))
1744 && ((secondary_out = rld[secondary_out].secondary_out_reload) == -1
1745 || ! (TEST_HARD_REG_BIT
1746 (reg_class_contents[(int) rld[secondary_out].class],
1747 REGNO (XEXP (note, 0)))))))
1748 && ! fixed_regs[REGNO (XEXP (note, 0))])
1750 rld[output_reload].reg_rtx
1751 = gen_rtx_REG (rld[output_reload].outmode,
1752 REGNO (XEXP (note, 0)));
1753 return;
1757 /* Try to find a reload register for an in-out reload (expressions IN and OUT).
1758 See if one of IN and OUT is a register that may be used;
1759 this is desirable since a spill-register won't be needed.
1760 If so, return the register rtx that proves acceptable.
1762 INLOC and OUTLOC are locations where IN and OUT appear in the insn.
1763 CLASS is the register class required for the reload.
1765 If FOR_REAL is >= 0, it is the number of the reload,
1766 and in some cases when it can be discovered that OUT doesn't need
1767 to be computed, clear out rld[FOR_REAL].out.
1769 If FOR_REAL is -1, this should not be done, because this call
1770 is just to see if a register can be found, not to find and install it.
1772 EARLYCLOBBER is non-zero if OUT is an earlyclobber operand. This
1773 puts an additional constraint on being able to use IN for OUT since
1774 IN must not appear elsewhere in the insn (it is assumed that IN itself
1775 is safe from the earlyclobber). */
1777 static rtx
1778 find_dummy_reload (real_in, real_out, inloc, outloc,
1779 inmode, outmode, class, for_real, earlyclobber)
1780 rtx real_in, real_out;
1781 rtx *inloc, *outloc;
1782 enum machine_mode inmode, outmode;
1783 enum reg_class class;
1784 int for_real;
1785 int earlyclobber;
1787 rtx in = real_in;
1788 rtx out = real_out;
1789 int in_offset = 0;
1790 int out_offset = 0;
1791 rtx value = 0;
1793 /* If operands exceed a word, we can't use either of them
1794 unless they have the same size. */
1795 if (GET_MODE_SIZE (outmode) != GET_MODE_SIZE (inmode)
1796 && (GET_MODE_SIZE (outmode) > UNITS_PER_WORD
1797 || GET_MODE_SIZE (inmode) > UNITS_PER_WORD))
1798 return 0;
1800 /* Find the inside of any subregs. */
1801 while (GET_CODE (out) == SUBREG)
1803 out_offset = SUBREG_WORD (out);
1804 out = SUBREG_REG (out);
1806 while (GET_CODE (in) == SUBREG)
1808 in_offset = SUBREG_WORD (in);
1809 in = SUBREG_REG (in);
1812 /* Narrow down the reg class, the same way push_reload will;
1813 otherwise we might find a dummy now, but push_reload won't. */
1814 class = PREFERRED_RELOAD_CLASS (in, class);
1816 /* See if OUT will do. */
1817 if (GET_CODE (out) == REG
1818 && REGNO (out) < FIRST_PSEUDO_REGISTER)
1820 register int regno = REGNO (out) + out_offset;
1821 int nwords = HARD_REGNO_NREGS (regno, outmode);
1822 rtx saved_rtx;
1824 /* When we consider whether the insn uses OUT,
1825 ignore references within IN. They don't prevent us
1826 from copying IN into OUT, because those refs would
1827 move into the insn that reloads IN.
1829 However, we only ignore IN in its role as this reload.
1830 If the insn uses IN elsewhere and it contains OUT,
1831 that counts. We can't be sure it's the "same" operand
1832 so it might not go through this reload. */
1833 saved_rtx = *inloc;
1834 *inloc = const0_rtx;
1836 if (regno < FIRST_PSEUDO_REGISTER
1837 /* A fixed reg that can overlap other regs better not be used
1838 for reloading in any way. */
1839 #ifdef OVERLAPPING_REGNO_P
1840 && ! (fixed_regs[regno] && OVERLAPPING_REGNO_P (regno))
1841 #endif
1842 && ! refers_to_regno_for_reload_p (regno, regno + nwords,
1843 PATTERN (this_insn), outloc))
1845 int i;
1846 for (i = 0; i < nwords; i++)
1847 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1848 regno + i))
1849 break;
1851 if (i == nwords)
1853 if (GET_CODE (real_out) == REG)
1854 value = real_out;
1855 else
1856 value = gen_rtx_REG (outmode, regno);
1860 *inloc = saved_rtx;
1863 /* Consider using IN if OUT was not acceptable
1864 or if OUT dies in this insn (like the quotient in a divmod insn).
1865 We can't use IN unless it is dies in this insn,
1866 which means we must know accurately which hard regs are live.
1867 Also, the result can't go in IN if IN is used within OUT,
1868 or if OUT is an earlyclobber and IN appears elsewhere in the insn. */
1869 if (hard_regs_live_known
1870 && GET_CODE (in) == REG
1871 && REGNO (in) < FIRST_PSEUDO_REGISTER
1872 && (value == 0
1873 || find_reg_note (this_insn, REG_UNUSED, real_out))
1874 && find_reg_note (this_insn, REG_DEAD, real_in)
1875 && !fixed_regs[REGNO (in)]
1876 && HARD_REGNO_MODE_OK (REGNO (in),
1877 /* The only case where out and real_out might
1878 have different modes is where real_out
1879 is a subreg, and in that case, out
1880 has a real mode. */
1881 (GET_MODE (out) != VOIDmode
1882 ? GET_MODE (out) : outmode)))
1884 register int regno = REGNO (in) + in_offset;
1885 int nwords = HARD_REGNO_NREGS (regno, inmode);
1887 if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, NULL_PTR)
1888 && ! hard_reg_set_here_p (regno, regno + nwords,
1889 PATTERN (this_insn))
1890 && (! earlyclobber
1891 || ! refers_to_regno_for_reload_p (regno, regno + nwords,
1892 PATTERN (this_insn), inloc)))
1894 int i;
1895 for (i = 0; i < nwords; i++)
1896 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1897 regno + i))
1898 break;
1900 if (i == nwords)
1902 /* If we were going to use OUT as the reload reg
1903 and changed our mind, it means OUT is a dummy that
1904 dies here. So don't bother copying value to it. */
1905 if (for_real >= 0 && value == real_out)
1906 rld[for_real].out = 0;
1907 if (GET_CODE (real_in) == REG)
1908 value = real_in;
1909 else
1910 value = gen_rtx_REG (inmode, regno);
1915 return value;
1918 /* This page contains subroutines used mainly for determining
1919 whether the IN or an OUT of a reload can serve as the
1920 reload register. */
1922 /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
1924 static int
1925 earlyclobber_operand_p (x)
1926 rtx x;
1928 int i;
1930 for (i = 0; i < n_earlyclobbers; i++)
1931 if (reload_earlyclobbers[i] == x)
1932 return 1;
1934 return 0;
1937 /* Return 1 if expression X alters a hard reg in the range
1938 from BEG_REGNO (inclusive) to END_REGNO (exclusive),
1939 either explicitly or in the guise of a pseudo-reg allocated to REGNO.
1940 X should be the body of an instruction. */
1942 static int
1943 hard_reg_set_here_p (beg_regno, end_regno, x)
1944 register int beg_regno, end_regno;
1945 rtx x;
1947 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
1949 register rtx op0 = SET_DEST (x);
1950 while (GET_CODE (op0) == SUBREG)
1951 op0 = SUBREG_REG (op0);
1952 if (GET_CODE (op0) == REG)
1954 register int r = REGNO (op0);
1955 /* See if this reg overlaps range under consideration. */
1956 if (r < end_regno
1957 && r + HARD_REGNO_NREGS (r, GET_MODE (op0)) > beg_regno)
1958 return 1;
1961 else if (GET_CODE (x) == PARALLEL)
1963 register int i = XVECLEN (x, 0) - 1;
1964 for (; i >= 0; i--)
1965 if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i)))
1966 return 1;
1969 return 0;
1972 /* Return 1 if ADDR is a valid memory address for mode MODE,
1973 and check that each pseudo reg has the proper kind of
1974 hard reg. */
1977 strict_memory_address_p (mode, addr)
1978 enum machine_mode mode;
1979 register rtx addr;
1981 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1982 return 0;
1984 win:
1985 return 1;
1988 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
1989 if they are the same hard reg, and has special hacks for
1990 autoincrement and autodecrement.
1991 This is specifically intended for find_reloads to use
1992 in determining whether two operands match.
1993 X is the operand whose number is the lower of the two.
1995 The value is 2 if Y contains a pre-increment that matches
1996 a non-incrementing address in X. */
1998 /* ??? To be completely correct, we should arrange to pass
1999 for X the output operand and for Y the input operand.
2000 For now, we assume that the output operand has the lower number
2001 because that is natural in (SET output (... input ...)). */
2004 operands_match_p (x, y)
2005 register rtx x, y;
2007 register int i;
2008 register RTX_CODE code = GET_CODE (x);
2009 register const char *fmt;
2010 int success_2;
2012 if (x == y)
2013 return 1;
2014 if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
2015 && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
2016 && GET_CODE (SUBREG_REG (y)) == REG)))
2018 register int j;
2020 if (code == SUBREG)
2022 i = REGNO (SUBREG_REG (x));
2023 if (i >= FIRST_PSEUDO_REGISTER)
2024 goto slow;
2025 i += SUBREG_WORD (x);
2027 else
2028 i = REGNO (x);
2030 if (GET_CODE (y) == SUBREG)
2032 j = REGNO (SUBREG_REG (y));
2033 if (j >= FIRST_PSEUDO_REGISTER)
2034 goto slow;
2035 j += SUBREG_WORD (y);
2037 else
2038 j = REGNO (y);
2040 /* On a WORDS_BIG_ENDIAN machine, point to the last register of a
2041 multiple hard register group, so that for example (reg:DI 0) and
2042 (reg:SI 1) will be considered the same register. */
2043 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
2044 && i < FIRST_PSEUDO_REGISTER)
2045 i += (GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD) - 1;
2046 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD
2047 && j < FIRST_PSEUDO_REGISTER)
2048 j += (GET_MODE_SIZE (GET_MODE (y)) / UNITS_PER_WORD) - 1;
2050 return i == j;
2052 /* If two operands must match, because they are really a single
2053 operand of an assembler insn, then two postincrements are invalid
2054 because the assembler insn would increment only once.
2055 On the other hand, an postincrement matches ordinary indexing
2056 if the postincrement is the output operand. */
2057 if (code == POST_DEC || code == POST_INC)
2058 return operands_match_p (XEXP (x, 0), y);
2059 /* Two preincrements are invalid
2060 because the assembler insn would increment only once.
2061 On the other hand, an preincrement matches ordinary indexing
2062 if the preincrement is the input operand.
2063 In this case, return 2, since some callers need to do special
2064 things when this happens. */
2065 if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC)
2066 return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
2068 slow:
2070 /* Now we have disposed of all the cases
2071 in which different rtx codes can match. */
2072 if (code != GET_CODE (y))
2073 return 0;
2074 if (code == LABEL_REF)
2075 return XEXP (x, 0) == XEXP (y, 0);
2076 if (code == SYMBOL_REF)
2077 return XSTR (x, 0) == XSTR (y, 0);
2079 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
2081 if (GET_MODE (x) != GET_MODE (y))
2082 return 0;
2084 /* Compare the elements. If any pair of corresponding elements
2085 fail to match, return 0 for the whole things. */
2087 success_2 = 0;
2088 fmt = GET_RTX_FORMAT (code);
2089 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2091 int val, j;
2092 switch (fmt[i])
2094 case 'w':
2095 if (XWINT (x, i) != XWINT (y, i))
2096 return 0;
2097 break;
2099 case 'i':
2100 if (XINT (x, i) != XINT (y, i))
2101 return 0;
2102 break;
2104 case 'e':
2105 val = operands_match_p (XEXP (x, i), XEXP (y, i));
2106 if (val == 0)
2107 return 0;
2108 /* If any subexpression returns 2,
2109 we should return 2 if we are successful. */
2110 if (val == 2)
2111 success_2 = 1;
2112 break;
2114 case '0':
2115 break;
2117 case 'E':
2118 if (XVECLEN (x, i) != XVECLEN (y, i))
2119 return 0;
2120 for (j = XVECLEN (x, i) - 1; j >= 0; --j)
2122 val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j));
2123 if (val == 0)
2124 return 0;
2125 if (val == 2)
2126 success_2 = 1;
2128 break;
2130 /* It is believed that rtx's at this level will never
2131 contain anything but integers and other rtx's,
2132 except for within LABEL_REFs and SYMBOL_REFs. */
2133 default:
2134 abort ();
2137 return 1 + success_2;
2140 /* Describe the range of registers or memory referenced by X.
2141 If X is a register, set REG_FLAG and put the first register
2142 number into START and the last plus one into END.
2143 If X is a memory reference, put a base address into BASE
2144 and a range of integer offsets into START and END.
2145 If X is pushing on the stack, we can assume it causes no trouble,
2146 so we set the SAFE field. */
2148 static struct decomposition
2149 decompose (x)
2150 rtx x;
2152 struct decomposition val;
2153 int all_const = 0;
2155 val.reg_flag = 0;
2156 val.safe = 0;
2157 val.base = 0;
2158 if (GET_CODE (x) == MEM)
2160 rtx base = NULL_RTX, offset = 0;
2161 rtx addr = XEXP (x, 0);
2163 if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
2164 || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
2166 val.base = XEXP (addr, 0);
2167 val.start = - GET_MODE_SIZE (GET_MODE (x));
2168 val.end = GET_MODE_SIZE (GET_MODE (x));
2169 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2170 return val;
2173 if (GET_CODE (addr) == CONST)
2175 addr = XEXP (addr, 0);
2176 all_const = 1;
2178 if (GET_CODE (addr) == PLUS)
2180 if (CONSTANT_P (XEXP (addr, 0)))
2182 base = XEXP (addr, 1);
2183 offset = XEXP (addr, 0);
2185 else if (CONSTANT_P (XEXP (addr, 1)))
2187 base = XEXP (addr, 0);
2188 offset = XEXP (addr, 1);
2192 if (offset == 0)
2194 base = addr;
2195 offset = const0_rtx;
2197 if (GET_CODE (offset) == CONST)
2198 offset = XEXP (offset, 0);
2199 if (GET_CODE (offset) == PLUS)
2201 if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
2203 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 1));
2204 offset = XEXP (offset, 0);
2206 else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
2208 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 0));
2209 offset = XEXP (offset, 1);
2211 else
2213 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2214 offset = const0_rtx;
2217 else if (GET_CODE (offset) != CONST_INT)
2219 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2220 offset = const0_rtx;
2223 if (all_const && GET_CODE (base) == PLUS)
2224 base = gen_rtx_CONST (GET_MODE (base), base);
2226 if (GET_CODE (offset) != CONST_INT)
2227 abort ();
2229 val.start = INTVAL (offset);
2230 val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
2231 val.base = base;
2232 return val;
2234 else if (GET_CODE (x) == REG)
2236 val.reg_flag = 1;
2237 val.start = true_regnum (x);
2238 if (val.start < 0)
2240 /* A pseudo with no hard reg. */
2241 val.start = REGNO (x);
2242 val.end = val.start + 1;
2244 else
2245 /* A hard reg. */
2246 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2248 else if (GET_CODE (x) == SUBREG)
2250 if (GET_CODE (SUBREG_REG (x)) != REG)
2251 /* This could be more precise, but it's good enough. */
2252 return decompose (SUBREG_REG (x));
2253 val.reg_flag = 1;
2254 val.start = true_regnum (x);
2255 if (val.start < 0)
2256 return decompose (SUBREG_REG (x));
2257 else
2258 /* A hard reg. */
2259 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
2261 else if (CONSTANT_P (x)
2262 /* This hasn't been assigned yet, so it can't conflict yet. */
2263 || GET_CODE (x) == SCRATCH)
2264 val.safe = 1;
2265 else
2266 abort ();
2267 return val;
2270 /* Return 1 if altering Y will not modify the value of X.
2271 Y is also described by YDATA, which should be decompose (Y). */
2273 static int
2274 immune_p (x, y, ydata)
2275 rtx x, y;
2276 struct decomposition ydata;
2278 struct decomposition xdata;
2280 if (ydata.reg_flag)
2281 return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, NULL_PTR);
2282 if (ydata.safe)
2283 return 1;
2285 if (GET_CODE (y) != MEM)
2286 abort ();
2287 /* If Y is memory and X is not, Y can't affect X. */
2288 if (GET_CODE (x) != MEM)
2289 return 1;
2291 xdata = decompose (x);
2293 if (! rtx_equal_p (xdata.base, ydata.base))
2295 /* If bases are distinct symbolic constants, there is no overlap. */
2296 if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
2297 return 1;
2298 /* Constants and stack slots never overlap. */
2299 if (CONSTANT_P (xdata.base)
2300 && (ydata.base == frame_pointer_rtx
2301 || ydata.base == hard_frame_pointer_rtx
2302 || ydata.base == stack_pointer_rtx))
2303 return 1;
2304 if (CONSTANT_P (ydata.base)
2305 && (xdata.base == frame_pointer_rtx
2306 || xdata.base == hard_frame_pointer_rtx
2307 || xdata.base == stack_pointer_rtx))
2308 return 1;
2309 /* If either base is variable, we don't know anything. */
2310 return 0;
2314 return (xdata.start >= ydata.end || ydata.start >= xdata.end);
2317 /* Similar, but calls decompose. */
2320 safe_from_earlyclobber (op, clobber)
2321 rtx op, clobber;
2323 struct decomposition early_data;
2325 early_data = decompose (clobber);
2326 return immune_p (op, clobber, early_data);
2329 /* Main entry point of this file: search the body of INSN
2330 for values that need reloading and record them with push_reload.
2331 REPLACE nonzero means record also where the values occur
2332 so that subst_reloads can be used.
2334 IND_LEVELS says how many levels of indirection are supported by this
2335 machine; a value of zero means that a memory reference is not a valid
2336 memory address.
2338 LIVE_KNOWN says we have valid information about which hard
2339 regs are live at each point in the program; this is true when
2340 we are called from global_alloc but false when stupid register
2341 allocation has been done.
2343 RELOAD_REG_P if nonzero is a vector indexed by hard reg number
2344 which is nonnegative if the reg has been commandeered for reloading into.
2345 It is copied into STATIC_RELOAD_REG_P and referenced from there
2346 by various subroutines.
2348 Return TRUE if some operands need to be changed, because of swapping
2349 commutative operands, reg_equiv_address substitution, or whatever. */
2352 find_reloads (insn, replace, ind_levels, live_known, reload_reg_p)
2353 rtx insn;
2354 int replace, ind_levels;
2355 int live_known;
2356 short *reload_reg_p;
2358 register int insn_code_number;
2359 register int i, j;
2360 int noperands;
2361 /* These start out as the constraints for the insn
2362 and they are chewed up as we consider alternatives. */
2363 char *constraints[MAX_RECOG_OPERANDS];
2364 /* These are the preferred classes for an operand, or NO_REGS if it isn't
2365 a register. */
2366 enum reg_class preferred_class[MAX_RECOG_OPERANDS];
2367 char pref_or_nothing[MAX_RECOG_OPERANDS];
2368 /* Nonzero for a MEM operand whose entire address needs a reload. */
2369 int address_reloaded[MAX_RECOG_OPERANDS];
2370 /* Value of enum reload_type to use for operand. */
2371 enum reload_type operand_type[MAX_RECOG_OPERANDS];
2372 /* Value of enum reload_type to use within address of operand. */
2373 enum reload_type address_type[MAX_RECOG_OPERANDS];
2374 /* Save the usage of each operand. */
2375 enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS];
2376 int no_input_reloads = 0, no_output_reloads = 0;
2377 int n_alternatives;
2378 int this_alternative[MAX_RECOG_OPERANDS];
2379 char this_alternative_win[MAX_RECOG_OPERANDS];
2380 char this_alternative_offmemok[MAX_RECOG_OPERANDS];
2381 char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2382 int this_alternative_matches[MAX_RECOG_OPERANDS];
2383 int swapped;
2384 int goal_alternative[MAX_RECOG_OPERANDS];
2385 int this_alternative_number;
2386 int goal_alternative_number;
2387 int operand_reloadnum[MAX_RECOG_OPERANDS];
2388 int goal_alternative_matches[MAX_RECOG_OPERANDS];
2389 int goal_alternative_matched[MAX_RECOG_OPERANDS];
2390 char goal_alternative_win[MAX_RECOG_OPERANDS];
2391 char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
2392 char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2393 int goal_alternative_swapped;
2394 int best;
2395 int commutative;
2396 int changed;
2397 char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
2398 rtx substed_operand[MAX_RECOG_OPERANDS];
2399 rtx body = PATTERN (insn);
2400 rtx set = single_set (insn);
2401 int goal_earlyclobber, this_earlyclobber;
2402 enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
2403 int retval = 0;
2405 this_insn = insn;
2406 n_reloads = 0;
2407 n_replacements = 0;
2408 n_earlyclobbers = 0;
2409 replace_reloads = replace;
2410 hard_regs_live_known = live_known;
2411 static_reload_reg_p = reload_reg_p;
2413 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
2414 neither are insns that SET cc0. Insns that use CC0 are not allowed
2415 to have any input reloads. */
2416 if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == CALL_INSN)
2417 no_output_reloads = 1;
2419 #ifdef HAVE_cc0
2420 if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
2421 no_input_reloads = 1;
2422 if (reg_set_p (cc0_rtx, PATTERN (insn)))
2423 no_output_reloads = 1;
2424 #endif
2426 #ifdef SECONDARY_MEMORY_NEEDED
2427 /* The eliminated forms of any secondary memory locations are per-insn, so
2428 clear them out here. */
2430 bzero ((char *) secondary_memlocs_elim, sizeof secondary_memlocs_elim);
2431 #endif
2433 /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2434 is cheap to move between them. If it is not, there may not be an insn
2435 to do the copy, so we may need a reload. */
2436 if (GET_CODE (body) == SET
2437 && GET_CODE (SET_DEST (body)) == REG
2438 && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2439 && GET_CODE (SET_SRC (body)) == REG
2440 && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2441 && REGISTER_MOVE_COST (REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2442 REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2443 return 0;
2445 extract_insn (insn);
2447 noperands = reload_n_operands = recog_data.n_operands;
2448 n_alternatives = recog_data.n_alternatives;
2450 /* Just return "no reloads" if insn has no operands with constraints. */
2451 if (noperands == 0 || n_alternatives == 0)
2452 return 0;
2454 insn_code_number = INSN_CODE (insn);
2455 this_insn_is_asm = insn_code_number < 0;
2457 memcpy (operand_mode, recog_data.operand_mode,
2458 noperands * sizeof (enum machine_mode));
2459 memcpy (constraints, recog_data.constraints, noperands * sizeof (char *));
2461 commutative = -1;
2463 /* If we will need to know, later, whether some pair of operands
2464 are the same, we must compare them now and save the result.
2465 Reloading the base and index registers will clobber them
2466 and afterward they will fail to match. */
2468 for (i = 0; i < noperands; i++)
2470 register char *p;
2471 register int c;
2473 substed_operand[i] = recog_data.operand[i];
2474 p = constraints[i];
2476 modified[i] = RELOAD_READ;
2478 /* Scan this operand's constraint to see if it is an output operand,
2479 an in-out operand, is commutative, or should match another. */
2481 while ((c = *p++))
2483 if (c == '=')
2484 modified[i] = RELOAD_WRITE;
2485 else if (c == '+')
2486 modified[i] = RELOAD_READ_WRITE;
2487 else if (c == '%')
2489 /* The last operand should not be marked commutative. */
2490 if (i == noperands - 1)
2491 abort ();
2493 commutative = i;
2495 else if (c >= '0' && c <= '9')
2497 c -= '0';
2498 operands_match[c][i]
2499 = operands_match_p (recog_data.operand[c],
2500 recog_data.operand[i]);
2502 /* An operand may not match itself. */
2503 if (c == i)
2504 abort ();
2506 /* If C can be commuted with C+1, and C might need to match I,
2507 then C+1 might also need to match I. */
2508 if (commutative >= 0)
2510 if (c == commutative || c == commutative + 1)
2512 int other = c + (c == commutative ? 1 : -1);
2513 operands_match[other][i]
2514 = operands_match_p (recog_data.operand[other],
2515 recog_data.operand[i]);
2517 if (i == commutative || i == commutative + 1)
2519 int other = i + (i == commutative ? 1 : -1);
2520 operands_match[c][other]
2521 = operands_match_p (recog_data.operand[c],
2522 recog_data.operand[other]);
2524 /* Note that C is supposed to be less than I.
2525 No need to consider altering both C and I because in
2526 that case we would alter one into the other. */
2532 /* Examine each operand that is a memory reference or memory address
2533 and reload parts of the addresses into index registers.
2534 Also here any references to pseudo regs that didn't get hard regs
2535 but are equivalent to constants get replaced in the insn itself
2536 with those constants. Nobody will ever see them again.
2538 Finally, set up the preferred classes of each operand. */
2540 for (i = 0; i < noperands; i++)
2542 register RTX_CODE code = GET_CODE (recog_data.operand[i]);
2544 address_reloaded[i] = 0;
2545 operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT
2546 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT
2547 : RELOAD_OTHER);
2548 address_type[i]
2549 = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS
2550 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS
2551 : RELOAD_OTHER);
2553 if (*constraints[i] == 0)
2554 /* Ignore things like match_operator operands. */
2556 else if (constraints[i][0] == 'p')
2558 find_reloads_address (VOIDmode, NULL_PTR,
2559 recog_data.operand[i],
2560 recog_data.operand_loc[i],
2561 i, operand_type[i], ind_levels, insn);
2563 /* If we now have a simple operand where we used to have a
2564 PLUS or MULT, re-recognize and try again. */
2565 if ((GET_RTX_CLASS (GET_CODE (*recog_data.operand_loc[i])) == 'o'
2566 || GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
2567 && (GET_CODE (recog_data.operand[i]) == MULT
2568 || GET_CODE (recog_data.operand[i]) == PLUS))
2570 INSN_CODE (insn) = -1;
2571 retval = find_reloads (insn, replace, ind_levels, live_known,
2572 reload_reg_p);
2573 return retval;
2576 recog_data.operand[i] = *recog_data.operand_loc[i];
2577 substed_operand[i] = recog_data.operand[i];
2579 else if (code == MEM)
2581 address_reloaded[i]
2582 = find_reloads_address (GET_MODE (recog_data.operand[i]),
2583 recog_data.operand_loc[i],
2584 XEXP (recog_data.operand[i], 0),
2585 &XEXP (recog_data.operand[i], 0),
2586 i, address_type[i], ind_levels, insn);
2587 recog_data.operand[i] = *recog_data.operand_loc[i];
2588 substed_operand[i] = recog_data.operand[i];
2590 else if (code == SUBREG)
2592 rtx reg = SUBREG_REG (recog_data.operand[i]);
2593 rtx op
2594 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2595 ind_levels,
2596 set != 0
2597 && &SET_DEST (set) == recog_data.operand_loc[i],
2598 insn);
2600 /* If we made a MEM to load (a part of) the stackslot of a pseudo
2601 that didn't get a hard register, emit a USE with a REG_EQUAL
2602 note in front so that we might inherit a previous, possibly
2603 wider reload. */
2605 if (replace
2606 && GET_CODE (op) == MEM
2607 && GET_CODE (reg) == REG
2608 && (GET_MODE_SIZE (GET_MODE (reg))
2609 >= GET_MODE_SIZE (GET_MODE (op))))
2610 REG_NOTES (emit_insn_before (gen_rtx_USE (VOIDmode, reg), insn))
2611 = gen_rtx_EXPR_LIST (REG_EQUAL,
2612 reg_equiv_memory_loc[REGNO (reg)], NULL_RTX);
2614 substed_operand[i] = recog_data.operand[i] = op;
2616 else if (code == PLUS || GET_RTX_CLASS (code) == '1')
2617 /* We can get a PLUS as an "operand" as a result of register
2618 elimination. See eliminate_regs and gen_reload. We handle
2619 a unary operator by reloading the operand. */
2620 substed_operand[i] = recog_data.operand[i]
2621 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2622 ind_levels, 0, insn);
2623 else if (code == REG)
2625 /* This is equivalent to calling find_reloads_toplev.
2626 The code is duplicated for speed.
2627 When we find a pseudo always equivalent to a constant,
2628 we replace it by the constant. We must be sure, however,
2629 that we don't try to replace it in the insn in which it
2630 is being set. */
2631 register int regno = REGNO (recog_data.operand[i]);
2632 if (reg_equiv_constant[regno] != 0
2633 && (set == 0 || &SET_DEST (set) != recog_data.operand_loc[i]))
2635 /* Record the existing mode so that the check if constants are
2636 allowed will work when operand_mode isn't specified. */
2638 if (operand_mode[i] == VOIDmode)
2639 operand_mode[i] = GET_MODE (recog_data.operand[i]);
2641 substed_operand[i] = recog_data.operand[i]
2642 = reg_equiv_constant[regno];
2644 if (reg_equiv_memory_loc[regno] != 0
2645 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
2646 /* We need not give a valid is_set_dest argument since the case
2647 of a constant equivalence was checked above. */
2648 substed_operand[i] = recog_data.operand[i]
2649 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2650 ind_levels, 0, insn);
2652 /* If the operand is still a register (we didn't replace it with an
2653 equivalent), get the preferred class to reload it into. */
2654 code = GET_CODE (recog_data.operand[i]);
2655 preferred_class[i]
2656 = ((code == REG && REGNO (recog_data.operand[i])
2657 >= FIRST_PSEUDO_REGISTER)
2658 ? reg_preferred_class (REGNO (recog_data.operand[i]))
2659 : NO_REGS);
2660 pref_or_nothing[i]
2661 = (code == REG
2662 && REGNO (recog_data.operand[i]) >= FIRST_PSEUDO_REGISTER
2663 && reg_alternate_class (REGNO (recog_data.operand[i])) == NO_REGS);
2666 #ifdef HAVE_cc0
2667 /* If we made any reloads for addresses, see if they violate a
2668 "no input reloads" requirement for this insn. */
2669 if (no_input_reloads)
2670 for (i = 0; i < n_reloads; i++)
2671 if (rld[i].in != 0)
2672 abort ();
2673 #endif
2675 /* If this is simply a copy from operand 1 to operand 0, merge the
2676 preferred classes for the operands. */
2677 if (set != 0 && noperands >= 2 && recog_data.operand[0] == SET_DEST (set)
2678 && recog_data.operand[1] == SET_SRC (set))
2680 preferred_class[0] = preferred_class[1]
2681 = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2682 pref_or_nothing[0] |= pref_or_nothing[1];
2683 pref_or_nothing[1] |= pref_or_nothing[0];
2686 /* Now see what we need for pseudo-regs that didn't get hard regs
2687 or got the wrong kind of hard reg. For this, we must consider
2688 all the operands together against the register constraints. */
2690 best = MAX_RECOG_OPERANDS * 2 + 600;
2692 swapped = 0;
2693 goal_alternative_swapped = 0;
2694 try_swapped:
2696 /* The constraints are made of several alternatives.
2697 Each operand's constraint looks like foo,bar,... with commas
2698 separating the alternatives. The first alternatives for all
2699 operands go together, the second alternatives go together, etc.
2701 First loop over alternatives. */
2703 for (this_alternative_number = 0;
2704 this_alternative_number < n_alternatives;
2705 this_alternative_number++)
2707 /* Loop over operands for one constraint alternative. */
2708 /* LOSERS counts those that don't fit this alternative
2709 and would require loading. */
2710 int losers = 0;
2711 /* BAD is set to 1 if it some operand can't fit this alternative
2712 even after reloading. */
2713 int bad = 0;
2714 /* REJECT is a count of how undesirable this alternative says it is
2715 if any reloading is required. If the alternative matches exactly
2716 then REJECT is ignored, but otherwise it gets this much
2717 counted against it in addition to the reloading needed. Each
2718 ? counts three times here since we want the disparaging caused by
2719 a bad register class to only count 1/3 as much. */
2720 int reject = 0;
2722 this_earlyclobber = 0;
2724 for (i = 0; i < noperands; i++)
2726 register char *p = constraints[i];
2727 register int win = 0;
2728 /* 0 => this operand can be reloaded somehow for this alternative */
2729 int badop = 1;
2730 /* 0 => this operand can be reloaded if the alternative allows regs. */
2731 int winreg = 0;
2732 int c;
2733 register rtx operand = recog_data.operand[i];
2734 int offset = 0;
2735 /* Nonzero means this is a MEM that must be reloaded into a reg
2736 regardless of what the constraint says. */
2737 int force_reload = 0;
2738 int offmemok = 0;
2739 /* Nonzero if a constant forced into memory would be OK for this
2740 operand. */
2741 int constmemok = 0;
2742 int earlyclobber = 0;
2744 /* If the predicate accepts a unary operator, it means that
2745 we need to reload the operand, but do not do this for
2746 match_operator and friends. */
2747 if (GET_RTX_CLASS (GET_CODE (operand)) == '1' && *p != 0)
2748 operand = XEXP (operand, 0);
2750 /* If the operand is a SUBREG, extract
2751 the REG or MEM (or maybe even a constant) within.
2752 (Constants can occur as a result of reg_equiv_constant.) */
2754 while (GET_CODE (operand) == SUBREG)
2756 offset += SUBREG_WORD (operand);
2757 operand = SUBREG_REG (operand);
2758 /* Force reload if this is a constant or PLUS or if there may
2759 be a problem accessing OPERAND in the outer mode. */
2760 if (CONSTANT_P (operand)
2761 || GET_CODE (operand) == PLUS
2762 /* We must force a reload of paradoxical SUBREGs
2763 of a MEM because the alignment of the inner value
2764 may not be enough to do the outer reference. On
2765 big-endian machines, it may also reference outside
2766 the object.
2768 On machines that extend byte operations and we have a
2769 SUBREG where both the inner and outer modes are no wider
2770 than a word and the inner mode is narrower, is integral,
2771 and gets extended when loaded from memory, combine.c has
2772 made assumptions about the behavior of the machine in such
2773 register access. If the data is, in fact, in memory we
2774 must always load using the size assumed to be in the
2775 register and let the insn do the different-sized
2776 accesses.
2778 This is doubly true if WORD_REGISTER_OPERATIONS. In
2779 this case eliminate_regs has left non-paradoxical
2780 subregs for push_reloads to see. Make sure it does
2781 by forcing the reload.
2783 ??? When is it right at this stage to have a subreg
2784 of a mem that is _not_ to be handled specialy? IMO
2785 those should have been reduced to just a mem. */
2786 || ((GET_CODE (operand) == MEM
2787 || (GET_CODE (operand)== REG
2788 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
2789 #ifndef WORD_REGISTER_OPERATIONS
2790 && (((GET_MODE_BITSIZE (GET_MODE (operand))
2791 < BIGGEST_ALIGNMENT)
2792 && (GET_MODE_SIZE (operand_mode[i])
2793 > GET_MODE_SIZE (GET_MODE (operand))))
2794 || (GET_CODE (operand) == MEM && BYTES_BIG_ENDIAN)
2795 #ifdef LOAD_EXTEND_OP
2796 || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2797 && (GET_MODE_SIZE (GET_MODE (operand))
2798 <= UNITS_PER_WORD)
2799 && (GET_MODE_SIZE (operand_mode[i])
2800 > GET_MODE_SIZE (GET_MODE (operand)))
2801 && INTEGRAL_MODE_P (GET_MODE (operand))
2802 && LOAD_EXTEND_OP (GET_MODE (operand)) != NIL)
2803 #endif
2805 #endif
2807 /* Subreg of a hard reg which can't handle the subreg's mode
2808 or which would handle that mode in the wrong number of
2809 registers for subregging to work. */
2810 || (GET_CODE (operand) == REG
2811 && REGNO (operand) < FIRST_PSEUDO_REGISTER
2812 && ((GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2813 && (GET_MODE_SIZE (GET_MODE (operand))
2814 > UNITS_PER_WORD)
2815 && ((GET_MODE_SIZE (GET_MODE (operand))
2816 / UNITS_PER_WORD)
2817 != HARD_REGNO_NREGS (REGNO (operand),
2818 GET_MODE (operand))))
2819 || ! HARD_REGNO_MODE_OK (REGNO (operand) + offset,
2820 operand_mode[i]))))
2821 force_reload = 1;
2824 this_alternative[i] = (int) NO_REGS;
2825 this_alternative_win[i] = 0;
2826 this_alternative_offmemok[i] = 0;
2827 this_alternative_earlyclobber[i] = 0;
2828 this_alternative_matches[i] = -1;
2830 /* An empty constraint or empty alternative
2831 allows anything which matched the pattern. */
2832 if (*p == 0 || *p == ',')
2833 win = 1, badop = 0;
2835 /* Scan this alternative's specs for this operand;
2836 set WIN if the operand fits any letter in this alternative.
2837 Otherwise, clear BADOP if this operand could
2838 fit some letter after reloads,
2839 or set WINREG if this operand could fit after reloads
2840 provided the constraint allows some registers. */
2842 while (*p && (c = *p++) != ',')
2843 switch (c)
2845 case '=': case '+': case '*':
2846 break;
2848 case '%':
2849 /* The last operand should not be marked commutative. */
2850 if (i != noperands - 1)
2851 commutative = i;
2852 break;
2854 case '?':
2855 reject += 6;
2856 break;
2858 case '!':
2859 reject = 600;
2860 break;
2862 case '#':
2863 /* Ignore rest of this alternative as far as
2864 reloading is concerned. */
2865 while (*p && *p != ',') p++;
2866 break;
2868 case '0': case '1': case '2': case '3': case '4':
2869 case '5': case '6': case '7': case '8': case '9':
2871 c -= '0';
2872 this_alternative_matches[i] = c;
2873 /* We are supposed to match a previous operand.
2874 If we do, we win if that one did.
2875 If we do not, count both of the operands as losers.
2876 (This is too conservative, since most of the time
2877 only a single reload insn will be needed to make
2878 the two operands win. As a result, this alternative
2879 may be rejected when it is actually desirable.) */
2880 if ((swapped && (c != commutative || i != commutative + 1))
2881 /* If we are matching as if two operands were swapped,
2882 also pretend that operands_match had been computed
2883 with swapped.
2884 But if I is the second of those and C is the first,
2885 don't exchange them, because operands_match is valid
2886 only on one side of its diagonal. */
2887 ? (operands_match
2888 [(c == commutative || c == commutative + 1)
2889 ? 2*commutative + 1 - c : c]
2890 [(i == commutative || i == commutative + 1)
2891 ? 2*commutative + 1 - i : i])
2892 : operands_match[c][i])
2894 /* If we are matching a non-offsettable address where an
2895 offsettable address was expected, then we must reject
2896 this combination, because we can't reload it. */
2897 if (this_alternative_offmemok[c]
2898 && GET_CODE (recog_data.operand[c]) == MEM
2899 && this_alternative[c] == (int) NO_REGS
2900 && ! this_alternative_win[c])
2901 bad = 1;
2903 win = this_alternative_win[c];
2905 else
2907 /* Operands don't match. */
2908 rtx value;
2909 /* Retroactively mark the operand we had to match
2910 as a loser, if it wasn't already. */
2911 if (this_alternative_win[c])
2912 losers++;
2913 this_alternative_win[c] = 0;
2914 if (this_alternative[c] == (int) NO_REGS)
2915 bad = 1;
2916 /* But count the pair only once in the total badness of
2917 this alternative, if the pair can be a dummy reload. */
2918 value
2919 = find_dummy_reload (recog_data.operand[i],
2920 recog_data.operand[c],
2921 recog_data.operand_loc[i],
2922 recog_data.operand_loc[c],
2923 operand_mode[i], operand_mode[c],
2924 this_alternative[c], -1,
2925 this_alternative_earlyclobber[c]);
2927 if (value != 0)
2928 losers--;
2930 /* This can be fixed with reloads if the operand
2931 we are supposed to match can be fixed with reloads. */
2932 badop = 0;
2933 this_alternative[i] = this_alternative[c];
2935 /* If we have to reload this operand and some previous
2936 operand also had to match the same thing as this
2937 operand, we don't know how to do that. So reject this
2938 alternative. */
2939 if (! win || force_reload)
2940 for (j = 0; j < i; j++)
2941 if (this_alternative_matches[j]
2942 == this_alternative_matches[i])
2943 badop = 1;
2945 break;
2947 case 'p':
2948 /* All necessary reloads for an address_operand
2949 were handled in find_reloads_address. */
2950 this_alternative[i] = (int) BASE_REG_CLASS;
2951 win = 1;
2952 break;
2954 case 'm':
2955 if (force_reload)
2956 break;
2957 if (GET_CODE (operand) == MEM
2958 || (GET_CODE (operand) == REG
2959 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
2960 && reg_renumber[REGNO (operand)] < 0))
2961 win = 1;
2962 if (CONSTANT_P (operand)
2963 /* force_const_mem does not accept HIGH. */
2964 && GET_CODE (operand) != HIGH)
2965 badop = 0;
2966 constmemok = 1;
2967 break;
2969 case '<':
2970 if (GET_CODE (operand) == MEM
2971 && ! address_reloaded[i]
2972 && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
2973 || GET_CODE (XEXP (operand, 0)) == POST_DEC))
2974 win = 1;
2975 break;
2977 case '>':
2978 if (GET_CODE (operand) == MEM
2979 && ! address_reloaded[i]
2980 && (GET_CODE (XEXP (operand, 0)) == PRE_INC
2981 || GET_CODE (XEXP (operand, 0)) == POST_INC))
2982 win = 1;
2983 break;
2985 /* Memory operand whose address is not offsettable. */
2986 case 'V':
2987 if (force_reload)
2988 break;
2989 if (GET_CODE (operand) == MEM
2990 && ! (ind_levels ? offsettable_memref_p (operand)
2991 : offsettable_nonstrict_memref_p (operand))
2992 /* Certain mem addresses will become offsettable
2993 after they themselves are reloaded. This is important;
2994 we don't want our own handling of unoffsettables
2995 to override the handling of reg_equiv_address. */
2996 && !(GET_CODE (XEXP (operand, 0)) == REG
2997 && (ind_levels == 0
2998 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0)))
2999 win = 1;
3000 break;
3002 /* Memory operand whose address is offsettable. */
3003 case 'o':
3004 if (force_reload)
3005 break;
3006 if ((GET_CODE (operand) == MEM
3007 /* If IND_LEVELS, find_reloads_address won't reload a
3008 pseudo that didn't get a hard reg, so we have to
3009 reject that case. */
3010 && ((ind_levels ? offsettable_memref_p (operand)
3011 : offsettable_nonstrict_memref_p (operand))
3012 /* A reloaded address is offsettable because it is now
3013 just a simple register indirect. */
3014 || address_reloaded[i]))
3015 || (GET_CODE (operand) == REG
3016 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3017 && reg_renumber[REGNO (operand)] < 0
3018 /* If reg_equiv_address is nonzero, we will be
3019 loading it into a register; hence it will be
3020 offsettable, but we cannot say that reg_equiv_mem
3021 is offsettable without checking. */
3022 && ((reg_equiv_mem[REGNO (operand)] != 0
3023 && offsettable_memref_p (reg_equiv_mem[REGNO (operand)]))
3024 || (reg_equiv_address[REGNO (operand)] != 0))))
3025 win = 1;
3026 /* force_const_mem does not accept HIGH. */
3027 if ((CONSTANT_P (operand) && GET_CODE (operand) != HIGH)
3028 || GET_CODE (operand) == MEM)
3029 badop = 0;
3030 constmemok = 1;
3031 offmemok = 1;
3032 break;
3034 case '&':
3035 /* Output operand that is stored before the need for the
3036 input operands (and their index registers) is over. */
3037 earlyclobber = 1, this_earlyclobber = 1;
3038 break;
3040 case 'E':
3041 #ifndef REAL_ARITHMETIC
3042 /* Match any floating double constant, but only if
3043 we can examine the bits of it reliably. */
3044 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3045 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3046 && GET_MODE (operand) != VOIDmode && ! flag_pretend_float)
3047 break;
3048 #endif
3049 if (GET_CODE (operand) == CONST_DOUBLE)
3050 win = 1;
3051 break;
3053 case 'F':
3054 if (GET_CODE (operand) == CONST_DOUBLE)
3055 win = 1;
3056 break;
3058 case 'G':
3059 case 'H':
3060 if (GET_CODE (operand) == CONST_DOUBLE
3061 && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
3062 win = 1;
3063 break;
3065 case 's':
3066 if (GET_CODE (operand) == CONST_INT
3067 || (GET_CODE (operand) == CONST_DOUBLE
3068 && GET_MODE (operand) == VOIDmode))
3069 break;
3070 case 'i':
3071 if (CONSTANT_P (operand)
3072 #ifdef LEGITIMATE_PIC_OPERAND_P
3073 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand))
3074 #endif
3076 win = 1;
3077 break;
3079 case 'n':
3080 if (GET_CODE (operand) == CONST_INT
3081 || (GET_CODE (operand) == CONST_DOUBLE
3082 && GET_MODE (operand) == VOIDmode))
3083 win = 1;
3084 break;
3086 case 'I':
3087 case 'J':
3088 case 'K':
3089 case 'L':
3090 case 'M':
3091 case 'N':
3092 case 'O':
3093 case 'P':
3094 if (GET_CODE (operand) == CONST_INT
3095 && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
3096 win = 1;
3097 break;
3099 case 'X':
3100 win = 1;
3101 break;
3103 case 'g':
3104 if (! force_reload
3105 /* A PLUS is never a valid operand, but reload can make
3106 it from a register when eliminating registers. */
3107 && GET_CODE (operand) != PLUS
3108 /* A SCRATCH is not a valid operand. */
3109 && GET_CODE (operand) != SCRATCH
3110 #ifdef LEGITIMATE_PIC_OPERAND_P
3111 && (! CONSTANT_P (operand)
3112 || ! flag_pic
3113 || LEGITIMATE_PIC_OPERAND_P (operand))
3114 #endif
3115 && (GENERAL_REGS == ALL_REGS
3116 || GET_CODE (operand) != REG
3117 || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
3118 && reg_renumber[REGNO (operand)] < 0)))
3119 win = 1;
3120 /* Drop through into 'r' case */
3122 case 'r':
3123 this_alternative[i]
3124 = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
3125 goto reg;
3127 #ifdef EXTRA_CONSTRAINT
3128 case 'Q':
3129 case 'R':
3130 case 'S':
3131 case 'T':
3132 case 'U':
3133 if (EXTRA_CONSTRAINT (operand, c))
3134 win = 1;
3135 break;
3136 #endif
3138 default:
3139 this_alternative[i]
3140 = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
3142 reg:
3143 if (GET_MODE (operand) == BLKmode)
3144 break;
3145 winreg = 1;
3146 if (GET_CODE (operand) == REG
3147 && reg_fits_class_p (operand, this_alternative[i],
3148 offset, GET_MODE (recog_data.operand[i])))
3149 win = 1;
3150 break;
3153 constraints[i] = p;
3155 /* If this operand could be handled with a reg,
3156 and some reg is allowed, then this operand can be handled. */
3157 if (winreg && this_alternative[i] != (int) NO_REGS)
3158 badop = 0;
3160 /* Record which operands fit this alternative. */
3161 this_alternative_earlyclobber[i] = earlyclobber;
3162 if (win && ! force_reload)
3163 this_alternative_win[i] = 1;
3164 else
3166 int const_to_mem = 0;
3168 this_alternative_offmemok[i] = offmemok;
3169 losers++;
3170 if (badop)
3171 bad = 1;
3172 /* Alternative loses if it has no regs for a reg operand. */
3173 if (GET_CODE (operand) == REG
3174 && this_alternative[i] == (int) NO_REGS
3175 && this_alternative_matches[i] < 0)
3176 bad = 1;
3178 /* If this is a constant that is reloaded into the desired
3179 class by copying it to memory first, count that as another
3180 reload. This is consistent with other code and is
3181 required to avoid choosing another alternative when
3182 the constant is moved into memory by this function on
3183 an early reload pass. Note that the test here is
3184 precisely the same as in the code below that calls
3185 force_const_mem. */
3186 if (CONSTANT_P (operand)
3187 /* force_const_mem does not accept HIGH. */
3188 && GET_CODE (operand) != HIGH
3189 && ((PREFERRED_RELOAD_CLASS (operand,
3190 (enum reg_class) this_alternative[i])
3191 == NO_REGS)
3192 || no_input_reloads)
3193 && operand_mode[i] != VOIDmode)
3195 const_to_mem = 1;
3196 if (this_alternative[i] != (int) NO_REGS)
3197 losers++;
3200 /* If we can't reload this value at all, reject this
3201 alternative. Note that we could also lose due to
3202 LIMIT_RELOAD_RELOAD_CLASS, but we don't check that
3203 here. */
3205 if (! CONSTANT_P (operand)
3206 && (enum reg_class) this_alternative[i] != NO_REGS
3207 && (PREFERRED_RELOAD_CLASS (operand,
3208 (enum reg_class) this_alternative[i])
3209 == NO_REGS))
3210 bad = 1;
3212 /* Alternative loses if it requires a type of reload not
3213 permitted for this insn. We can always reload SCRATCH
3214 and objects with a REG_UNUSED note. */
3215 else if (GET_CODE (operand) != SCRATCH
3216 && modified[i] != RELOAD_READ && no_output_reloads
3217 && ! find_reg_note (insn, REG_UNUSED, operand))
3218 bad = 1;
3219 else if (modified[i] != RELOAD_WRITE && no_input_reloads
3220 && ! const_to_mem)
3221 bad = 1;
3224 /* We prefer to reload pseudos over reloading other things,
3225 since such reloads may be able to be eliminated later.
3226 If we are reloading a SCRATCH, we won't be generating any
3227 insns, just using a register, so it is also preferred.
3228 So bump REJECT in other cases. Don't do this in the
3229 case where we are forcing a constant into memory and
3230 it will then win since we don't want to have a different
3231 alternative match then. */
3232 if (! (GET_CODE (operand) == REG
3233 && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
3234 && GET_CODE (operand) != SCRATCH
3235 && ! (const_to_mem && constmemok))
3236 reject += 2;
3238 /* Input reloads can be inherited more often than output
3239 reloads can be removed, so penalize output reloads. */
3240 if (operand_type[i] != RELOAD_FOR_INPUT
3241 && GET_CODE (operand) != SCRATCH)
3242 reject++;
3245 /* If this operand is a pseudo register that didn't get a hard
3246 reg and this alternative accepts some register, see if the
3247 class that we want is a subset of the preferred class for this
3248 register. If not, but it intersects that class, use the
3249 preferred class instead. If it does not intersect the preferred
3250 class, show that usage of this alternative should be discouraged;
3251 it will be discouraged more still if the register is `preferred
3252 or nothing'. We do this because it increases the chance of
3253 reusing our spill register in a later insn and avoiding a pair
3254 of memory stores and loads.
3256 Don't bother with this if this alternative will accept this
3257 operand.
3259 Don't do this for a multiword operand, since it is only a
3260 small win and has the risk of requiring more spill registers,
3261 which could cause a large loss.
3263 Don't do this if the preferred class has only one register
3264 because we might otherwise exhaust the class. */
3267 if (! win && this_alternative[i] != (int) NO_REGS
3268 && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3269 && reg_class_size[(int) preferred_class[i]] > 1)
3271 if (! reg_class_subset_p (this_alternative[i],
3272 preferred_class[i]))
3274 /* Since we don't have a way of forming the intersection,
3275 we just do something special if the preferred class
3276 is a subset of the class we have; that's the most
3277 common case anyway. */
3278 if (reg_class_subset_p (preferred_class[i],
3279 this_alternative[i]))
3280 this_alternative[i] = (int) preferred_class[i];
3281 else
3282 reject += (2 + 2 * pref_or_nothing[i]);
3287 /* Now see if any output operands that are marked "earlyclobber"
3288 in this alternative conflict with any input operands
3289 or any memory addresses. */
3291 for (i = 0; i < noperands; i++)
3292 if (this_alternative_earlyclobber[i]
3293 && this_alternative_win[i])
3295 struct decomposition early_data;
3297 early_data = decompose (recog_data.operand[i]);
3299 if (modified[i] == RELOAD_READ)
3300 abort ();
3302 if (this_alternative[i] == NO_REGS)
3304 this_alternative_earlyclobber[i] = 0;
3305 if (this_insn_is_asm)
3306 error_for_asm (this_insn,
3307 "`&' constraint used with no register class");
3308 else
3309 abort ();
3312 for (j = 0; j < noperands; j++)
3313 /* Is this an input operand or a memory ref? */
3314 if ((GET_CODE (recog_data.operand[j]) == MEM
3315 || modified[j] != RELOAD_WRITE)
3316 && j != i
3317 /* Ignore things like match_operator operands. */
3318 && *recog_data.constraints[j] != 0
3319 /* Don't count an input operand that is constrained to match
3320 the early clobber operand. */
3321 && ! (this_alternative_matches[j] == i
3322 && rtx_equal_p (recog_data.operand[i],
3323 recog_data.operand[j]))
3324 /* Is it altered by storing the earlyclobber operand? */
3325 && !immune_p (recog_data.operand[j], recog_data.operand[i],
3326 early_data))
3328 /* If the output is in a single-reg class,
3329 it's costly to reload it, so reload the input instead. */
3330 if (reg_class_size[this_alternative[i]] == 1
3331 && (GET_CODE (recog_data.operand[j]) == REG
3332 || GET_CODE (recog_data.operand[j]) == SUBREG))
3334 losers++;
3335 this_alternative_win[j] = 0;
3337 else
3338 break;
3340 /* If an earlyclobber operand conflicts with something,
3341 it must be reloaded, so request this and count the cost. */
3342 if (j != noperands)
3344 losers++;
3345 this_alternative_win[i] = 0;
3346 for (j = 0; j < noperands; j++)
3347 if (this_alternative_matches[j] == i
3348 && this_alternative_win[j])
3350 this_alternative_win[j] = 0;
3351 losers++;
3356 /* If one alternative accepts all the operands, no reload required,
3357 choose that alternative; don't consider the remaining ones. */
3358 if (losers == 0)
3360 /* Unswap these so that they are never swapped at `finish'. */
3361 if (commutative >= 0)
3363 recog_data.operand[commutative] = substed_operand[commutative];
3364 recog_data.operand[commutative + 1]
3365 = substed_operand[commutative + 1];
3367 for (i = 0; i < noperands; i++)
3369 goal_alternative_win[i] = 1;
3370 goal_alternative[i] = this_alternative[i];
3371 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3372 goal_alternative_matches[i] = this_alternative_matches[i];
3373 goal_alternative_earlyclobber[i]
3374 = this_alternative_earlyclobber[i];
3376 goal_alternative_number = this_alternative_number;
3377 goal_alternative_swapped = swapped;
3378 goal_earlyclobber = this_earlyclobber;
3379 goto finish;
3382 /* REJECT, set by the ! and ? constraint characters and when a register
3383 would be reloaded into a non-preferred class, discourages the use of
3384 this alternative for a reload goal. REJECT is incremented by six
3385 for each ? and two for each non-preferred class. */
3386 losers = losers * 6 + reject;
3388 /* If this alternative can be made to work by reloading,
3389 and it needs less reloading than the others checked so far,
3390 record it as the chosen goal for reloading. */
3391 if (! bad && best > losers)
3393 for (i = 0; i < noperands; i++)
3395 goal_alternative[i] = this_alternative[i];
3396 goal_alternative_win[i] = this_alternative_win[i];
3397 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3398 goal_alternative_matches[i] = this_alternative_matches[i];
3399 goal_alternative_earlyclobber[i]
3400 = this_alternative_earlyclobber[i];
3402 goal_alternative_swapped = swapped;
3403 best = losers;
3404 goal_alternative_number = this_alternative_number;
3405 goal_earlyclobber = this_earlyclobber;
3409 /* If insn is commutative (it's safe to exchange a certain pair of operands)
3410 then we need to try each alternative twice,
3411 the second time matching those two operands
3412 as if we had exchanged them.
3413 To do this, really exchange them in operands.
3415 If we have just tried the alternatives the second time,
3416 return operands to normal and drop through. */
3418 if (commutative >= 0)
3420 swapped = !swapped;
3421 if (swapped)
3423 register enum reg_class tclass;
3424 register int t;
3426 recog_data.operand[commutative] = substed_operand[commutative + 1];
3427 recog_data.operand[commutative + 1] = substed_operand[commutative];
3429 tclass = preferred_class[commutative];
3430 preferred_class[commutative] = preferred_class[commutative + 1];
3431 preferred_class[commutative + 1] = tclass;
3433 t = pref_or_nothing[commutative];
3434 pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
3435 pref_or_nothing[commutative + 1] = t;
3437 memcpy (constraints, recog_data.constraints,
3438 noperands * sizeof (char *));
3439 goto try_swapped;
3441 else
3443 recog_data.operand[commutative] = substed_operand[commutative];
3444 recog_data.operand[commutative + 1]
3445 = substed_operand[commutative + 1];
3449 /* The operands don't meet the constraints.
3450 goal_alternative describes the alternative
3451 that we could reach by reloading the fewest operands.
3452 Reload so as to fit it. */
3454 if (best == MAX_RECOG_OPERANDS * 2 + 600)
3456 /* No alternative works with reloads?? */
3457 if (insn_code_number >= 0)
3458 fatal_insn ("Unable to generate reloads for:", insn);
3459 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3460 /* Avoid further trouble with this insn. */
3461 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3462 n_reloads = 0;
3463 return 0;
3466 /* Jump to `finish' from above if all operands are valid already.
3467 In that case, goal_alternative_win is all 1. */
3468 finish:
3470 /* Right now, for any pair of operands I and J that are required to match,
3471 with I < J,
3472 goal_alternative_matches[J] is I.
3473 Set up goal_alternative_matched as the inverse function:
3474 goal_alternative_matched[I] = J. */
3476 for (i = 0; i < noperands; i++)
3477 goal_alternative_matched[i] = -1;
3479 for (i = 0; i < noperands; i++)
3480 if (! goal_alternative_win[i]
3481 && goal_alternative_matches[i] >= 0)
3482 goal_alternative_matched[goal_alternative_matches[i]] = i;
3484 /* If the best alternative is with operands 1 and 2 swapped,
3485 consider them swapped before reporting the reloads. Update the
3486 operand numbers of any reloads already pushed. */
3488 if (goal_alternative_swapped)
3490 register rtx tem;
3492 tem = substed_operand[commutative];
3493 substed_operand[commutative] = substed_operand[commutative + 1];
3494 substed_operand[commutative + 1] = tem;
3495 tem = recog_data.operand[commutative];
3496 recog_data.operand[commutative] = recog_data.operand[commutative + 1];
3497 recog_data.operand[commutative + 1] = tem;
3498 tem = *recog_data.operand_loc[commutative];
3499 *recog_data.operand_loc[commutative]
3500 = *recog_data.operand_loc[commutative + 1];
3501 *recog_data.operand_loc[commutative+1] = tem;
3503 for (i = 0; i < n_reloads; i++)
3505 if (rld[i].opnum == commutative)
3506 rld[i].opnum = commutative + 1;
3507 else if (rld[i].opnum == commutative + 1)
3508 rld[i].opnum = commutative;
3512 for (i = 0; i < noperands; i++)
3514 operand_reloadnum[i] = -1;
3516 /* If this is an earlyclobber operand, we need to widen the scope.
3517 The reload must remain valid from the start of the insn being
3518 reloaded until after the operand is stored into its destination.
3519 We approximate this with RELOAD_OTHER even though we know that we
3520 do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads.
3522 One special case that is worth checking is when we have an
3523 output that is earlyclobber but isn't used past the insn (typically
3524 a SCRATCH). In this case, we only need have the reload live
3525 through the insn itself, but not for any of our input or output
3526 reloads.
3527 But we must not accidentally narrow the scope of an existing
3528 RELOAD_OTHER reload - leave these alone.
3530 In any case, anything needed to address this operand can remain
3531 however they were previously categorized. */
3533 if (goal_alternative_earlyclobber[i] && operand_type[i] != RELOAD_OTHER)
3534 operand_type[i]
3535 = (find_reg_note (insn, REG_UNUSED, recog_data.operand[i])
3536 ? RELOAD_FOR_INSN : RELOAD_OTHER);
3539 /* Any constants that aren't allowed and can't be reloaded
3540 into registers are here changed into memory references. */
3541 for (i = 0; i < noperands; i++)
3542 if (! goal_alternative_win[i]
3543 && CONSTANT_P (recog_data.operand[i])
3544 /* force_const_mem does not accept HIGH. */
3545 && GET_CODE (recog_data.operand[i]) != HIGH
3546 && ((PREFERRED_RELOAD_CLASS (recog_data.operand[i],
3547 (enum reg_class) goal_alternative[i])
3548 == NO_REGS)
3549 || no_input_reloads)
3550 && operand_mode[i] != VOIDmode)
3552 substed_operand[i] = recog_data.operand[i]
3553 = find_reloads_toplev (force_const_mem (operand_mode[i],
3554 recog_data.operand[i]),
3555 i, address_type[i], ind_levels, 0, insn);
3556 if (alternative_allows_memconst (recog_data.constraints[i],
3557 goal_alternative_number))
3558 goal_alternative_win[i] = 1;
3561 /* Record the values of the earlyclobber operands for the caller. */
3562 if (goal_earlyclobber)
3563 for (i = 0; i < noperands; i++)
3564 if (goal_alternative_earlyclobber[i])
3565 reload_earlyclobbers[n_earlyclobbers++] = recog_data.operand[i];
3567 /* Now record reloads for all the operands that need them. */
3568 for (i = 0; i < noperands; i++)
3569 if (! goal_alternative_win[i])
3571 /* Operands that match previous ones have already been handled. */
3572 if (goal_alternative_matches[i] >= 0)
3574 /* Handle an operand with a nonoffsettable address
3575 appearing where an offsettable address will do
3576 by reloading the address into a base register.
3578 ??? We can also do this when the operand is a register and
3579 reg_equiv_mem is not offsettable, but this is a bit tricky,
3580 so we don't bother with it. It may not be worth doing. */
3581 else if (goal_alternative_matched[i] == -1
3582 && goal_alternative_offmemok[i]
3583 && GET_CODE (recog_data.operand[i]) == MEM)
3585 operand_reloadnum[i]
3586 = push_reload (XEXP (recog_data.operand[i], 0), NULL_RTX,
3587 &XEXP (recog_data.operand[i], 0), NULL_PTR,
3588 BASE_REG_CLASS,
3589 GET_MODE (XEXP (recog_data.operand[i], 0)),
3590 VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
3591 rld[operand_reloadnum[i]].inc
3592 = GET_MODE_SIZE (GET_MODE (recog_data.operand[i]));
3594 /* If this operand is an output, we will have made any
3595 reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but
3596 now we are treating part of the operand as an input, so
3597 we must change these to RELOAD_FOR_INPUT_ADDRESS. */
3599 if (modified[i] == RELOAD_WRITE)
3601 for (j = 0; j < n_reloads; j++)
3603 if (rld[j].opnum == i)
3605 if (rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS)
3606 rld[j].when_needed = RELOAD_FOR_INPUT_ADDRESS;
3607 else if (rld[j].when_needed
3608 == RELOAD_FOR_OUTADDR_ADDRESS)
3609 rld[j].when_needed = RELOAD_FOR_INPADDR_ADDRESS;
3614 else if (goal_alternative_matched[i] == -1)
3616 operand_reloadnum[i]
3617 = push_reload ((modified[i] != RELOAD_WRITE
3618 ? recog_data.operand[i] : 0),
3619 (modified[i] != RELOAD_READ
3620 ? recog_data.operand[i] : 0),
3621 (modified[i] != RELOAD_WRITE
3622 ? recog_data.operand_loc[i] : 0),
3623 (modified[i] != RELOAD_READ
3624 ? recog_data.operand_loc[i] : 0),
3625 (enum reg_class) goal_alternative[i],
3626 (modified[i] == RELOAD_WRITE
3627 ? VOIDmode : operand_mode[i]),
3628 (modified[i] == RELOAD_READ
3629 ? VOIDmode : operand_mode[i]),
3630 (insn_code_number < 0 ? 0
3631 : insn_data[insn_code_number].operand[i].strict_low),
3632 0, i, operand_type[i]);
3634 /* In a matching pair of operands, one must be input only
3635 and the other must be output only.
3636 Pass the input operand as IN and the other as OUT. */
3637 else if (modified[i] == RELOAD_READ
3638 && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
3640 operand_reloadnum[i]
3641 = push_reload (recog_data.operand[i],
3642 recog_data.operand[goal_alternative_matched[i]],
3643 recog_data.operand_loc[i],
3644 recog_data.operand_loc[goal_alternative_matched[i]],
3645 (enum reg_class) goal_alternative[i],
3646 operand_mode[i],
3647 operand_mode[goal_alternative_matched[i]],
3648 0, 0, i, RELOAD_OTHER);
3649 operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
3651 else if (modified[i] == RELOAD_WRITE
3652 && modified[goal_alternative_matched[i]] == RELOAD_READ)
3654 operand_reloadnum[goal_alternative_matched[i]]
3655 = push_reload (recog_data.operand[goal_alternative_matched[i]],
3656 recog_data.operand[i],
3657 recog_data.operand_loc[goal_alternative_matched[i]],
3658 recog_data.operand_loc[i],
3659 (enum reg_class) goal_alternative[i],
3660 operand_mode[goal_alternative_matched[i]],
3661 operand_mode[i],
3662 0, 0, i, RELOAD_OTHER);
3663 operand_reloadnum[i] = output_reloadnum;
3665 else if (insn_code_number >= 0)
3666 abort ();
3667 else
3669 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3670 /* Avoid further trouble with this insn. */
3671 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3672 n_reloads = 0;
3673 return 0;
3676 else if (goal_alternative_matched[i] < 0
3677 && goal_alternative_matches[i] < 0
3678 && optimize)
3680 /* For each non-matching operand that's a MEM or a pseudo-register
3681 that didn't get a hard register, make an optional reload.
3682 This may get done even if the insn needs no reloads otherwise. */
3684 rtx operand = recog_data.operand[i];
3686 while (GET_CODE (operand) == SUBREG)
3687 operand = XEXP (operand, 0);
3688 if ((GET_CODE (operand) == MEM
3689 || (GET_CODE (operand) == REG
3690 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3691 /* If this is only for an output, the optional reload would not
3692 actually cause us to use a register now, just note that
3693 something is stored here. */
3694 && ((enum reg_class) goal_alternative[i] != NO_REGS
3695 || modified[i] == RELOAD_WRITE)
3696 && ! no_input_reloads
3697 /* An optional output reload might allow to delete INSN later.
3698 We mustn't make in-out reloads on insns that are not permitted
3699 output reloads.
3700 If this is an asm, we can't delete it; we must not even call
3701 push_reload for an optional output reload in this case,
3702 because we can't be sure that the constraint allows a register,
3703 and push_reload verifies the constraints for asms. */
3704 && (modified[i] == RELOAD_READ
3705 || (! no_output_reloads && ! this_insn_is_asm)))
3706 operand_reloadnum[i]
3707 = push_reload ((modified[i] != RELOAD_WRITE
3708 ? recog_data.operand[i] : 0),
3709 (modified[i] != RELOAD_READ
3710 ? recog_data.operand[i] : 0),
3711 (modified[i] != RELOAD_WRITE
3712 ? recog_data.operand_loc[i] : 0),
3713 (modified[i] != RELOAD_READ
3714 ? recog_data.operand_loc[i] : 0),
3715 (enum reg_class) goal_alternative[i],
3716 (modified[i] == RELOAD_WRITE
3717 ? VOIDmode : operand_mode[i]),
3718 (modified[i] == RELOAD_READ
3719 ? VOIDmode : operand_mode[i]),
3720 (insn_code_number < 0 ? 0
3721 : insn_data[insn_code_number].operand[i].strict_low),
3722 1, i, operand_type[i]);
3723 /* If a memory reference remains (either as a MEM or a pseudo that
3724 did not get a hard register), yet we can't make an optional
3725 reload, check if this is actually a pseudo register reference;
3726 we then need to emit a USE and/or a CLOBBER so that reload
3727 inheritance will do the right thing. */
3728 else if (replace
3729 && (GET_CODE (operand) == MEM
3730 || (GET_CODE (operand) == REG
3731 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3732 && reg_renumber [REGNO (operand)] < 0)))
3734 operand = *recog_data.operand_loc[i];
3736 while (GET_CODE (operand) == SUBREG)
3737 operand = XEXP (operand, 0);
3738 if (GET_CODE (operand) == REG)
3740 if (modified[i] != RELOAD_WRITE)
3741 emit_insn_before (gen_rtx_USE (VOIDmode, operand), insn);
3742 if (modified[i] != RELOAD_READ)
3743 emit_insn_after (gen_rtx_CLOBBER (VOIDmode, operand), insn);
3747 else if (goal_alternative_matches[i] >= 0
3748 && goal_alternative_win[goal_alternative_matches[i]]
3749 && modified[i] == RELOAD_READ
3750 && modified[goal_alternative_matches[i]] == RELOAD_WRITE
3751 && ! no_input_reloads && ! no_output_reloads
3752 && optimize)
3754 /* Similarly, make an optional reload for a pair of matching
3755 objects that are in MEM or a pseudo that didn't get a hard reg. */
3757 rtx operand = recog_data.operand[i];
3759 while (GET_CODE (operand) == SUBREG)
3760 operand = XEXP (operand, 0);
3761 if ((GET_CODE (operand) == MEM
3762 || (GET_CODE (operand) == REG
3763 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3764 && ((enum reg_class) goal_alternative[goal_alternative_matches[i]]
3765 != NO_REGS))
3766 operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]]
3767 = push_reload (recog_data.operand[goal_alternative_matches[i]],
3768 recog_data.operand[i],
3769 recog_data.operand_loc[goal_alternative_matches[i]],
3770 recog_data.operand_loc[i],
3771 (enum reg_class) goal_alternative[goal_alternative_matches[i]],
3772 operand_mode[goal_alternative_matches[i]],
3773 operand_mode[i],
3774 0, 1, goal_alternative_matches[i], RELOAD_OTHER);
3777 /* Perform whatever substitutions on the operands we are supposed
3778 to make due to commutativity or replacement of registers
3779 with equivalent constants or memory slots. */
3781 for (i = 0; i < noperands; i++)
3783 /* We only do this on the last pass through reload, because it is
3784 possible for some data (like reg_equiv_address) to be changed during
3785 later passes. Moreover, we loose the opportunity to get a useful
3786 reload_{in,out}_reg when we do these replacements. */
3788 if (replace)
3790 rtx substitution = substed_operand[i];
3792 *recog_data.operand_loc[i] = substitution;
3794 /* If we're replacing an operand with a LABEL_REF, we need
3795 to make sure that there's a REG_LABEL note attached to
3796 this instruction. */
3797 if (GET_CODE (insn) != JUMP_INSN
3798 && GET_CODE (substitution) == LABEL_REF
3799 && !find_reg_note (insn, REG_LABEL, XEXP (substitution, 0)))
3800 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_LABEL,
3801 XEXP (substitution, 0),
3802 REG_NOTES (insn));
3804 else
3805 retval |= (substed_operand[i] != *recog_data.operand_loc[i]);
3808 /* If this insn pattern contains any MATCH_DUP's, make sure that
3809 they will be substituted if the operands they match are substituted.
3810 Also do now any substitutions we already did on the operands.
3812 Don't do this if we aren't making replacements because we might be
3813 propagating things allocated by frame pointer elimination into places
3814 it doesn't expect. */
3816 if (insn_code_number >= 0 && replace)
3817 for (i = insn_data[insn_code_number].n_dups - 1; i >= 0; i--)
3819 int opno = recog_data.dup_num[i];
3820 *recog_data.dup_loc[i] = *recog_data.operand_loc[opno];
3821 if (operand_reloadnum[opno] >= 0)
3822 push_replacement (recog_data.dup_loc[i], operand_reloadnum[opno],
3823 insn_data[insn_code_number].operand[opno].mode);
3826 #if 0
3827 /* This loses because reloading of prior insns can invalidate the equivalence
3828 (or at least find_equiv_reg isn't smart enough to find it any more),
3829 causing this insn to need more reload regs than it needed before.
3830 It may be too late to make the reload regs available.
3831 Now this optimization is done safely in choose_reload_regs. */
3833 /* For each reload of a reg into some other class of reg,
3834 search for an existing equivalent reg (same value now) in the right class.
3835 We can use it as long as we don't need to change its contents. */
3836 for (i = 0; i < n_reloads; i++)
3837 if (rld[i].reg_rtx == 0
3838 && rld[i].in != 0
3839 && GET_CODE (rld[i].in) == REG
3840 && rld[i].out == 0)
3842 rld[i].reg_rtx
3843 = find_equiv_reg (rld[i].in, insn, rld[i].class, -1,
3844 static_reload_reg_p, 0, rld[i].inmode);
3845 /* Prevent generation of insn to load the value
3846 because the one we found already has the value. */
3847 if (rld[i].reg_rtx)
3848 rld[i].in = rld[i].reg_rtx;
3850 #endif
3852 /* Perhaps an output reload can be combined with another
3853 to reduce needs by one. */
3854 if (!goal_earlyclobber)
3855 combine_reloads ();
3857 /* If we have a pair of reloads for parts of an address, they are reloading
3858 the same object, the operands themselves were not reloaded, and they
3859 are for two operands that are supposed to match, merge the reloads and
3860 change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS. */
3862 for (i = 0; i < n_reloads; i++)
3864 int k;
3866 for (j = i + 1; j < n_reloads; j++)
3867 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
3868 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
3869 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
3870 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
3871 && (rld[j].when_needed == RELOAD_FOR_INPUT_ADDRESS
3872 || rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
3873 || rld[j].when_needed == RELOAD_FOR_INPADDR_ADDRESS
3874 || rld[j].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
3875 && rtx_equal_p (rld[i].in, rld[j].in)
3876 && (operand_reloadnum[rld[i].opnum] < 0
3877 || rld[operand_reloadnum[rld[i].opnum]].optional)
3878 && (operand_reloadnum[rld[j].opnum] < 0
3879 || rld[operand_reloadnum[rld[j].opnum]].optional)
3880 && (goal_alternative_matches[rld[i].opnum] == rld[j].opnum
3881 || (goal_alternative_matches[rld[j].opnum]
3882 == rld[i].opnum)))
3884 for (k = 0; k < n_replacements; k++)
3885 if (replacements[k].what == j)
3886 replacements[k].what = i;
3888 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
3889 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
3890 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
3891 else
3892 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
3893 rld[j].in = 0;
3897 /* Scan all the reloads and update their type.
3898 If a reload is for the address of an operand and we didn't reload
3899 that operand, change the type. Similarly, change the operand number
3900 of a reload when two operands match. If a reload is optional, treat it
3901 as though the operand isn't reloaded.
3903 ??? This latter case is somewhat odd because if we do the optional
3904 reload, it means the object is hanging around. Thus we need only
3905 do the address reload if the optional reload was NOT done.
3907 Change secondary reloads to be the address type of their operand, not
3908 the normal type.
3910 If an operand's reload is now RELOAD_OTHER, change any
3911 RELOAD_FOR_INPUT_ADDRESS reloads of that operand to
3912 RELOAD_FOR_OTHER_ADDRESS. */
3914 for (i = 0; i < n_reloads; i++)
3916 if (rld[i].secondary_p
3917 && rld[i].when_needed == operand_type[rld[i].opnum])
3918 rld[i].when_needed = address_type[rld[i].opnum];
3920 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
3921 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
3922 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
3923 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
3924 && (operand_reloadnum[rld[i].opnum] < 0
3925 || rld[operand_reloadnum[rld[i].opnum]].optional))
3927 /* If we have a secondary reload to go along with this reload,
3928 change its type to RELOAD_FOR_OPADDR_ADDR. */
3930 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
3931 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
3932 && rld[i].secondary_in_reload != -1)
3934 int secondary_in_reload = rld[i].secondary_in_reload;
3936 rld[secondary_in_reload].when_needed
3937 = RELOAD_FOR_OPADDR_ADDR;
3939 /* If there's a tertiary reload we have to change it also. */
3940 if (secondary_in_reload > 0
3941 && rld[secondary_in_reload].secondary_in_reload != -1)
3942 rld[rld[secondary_in_reload].secondary_in_reload].when_needed
3943 = RELOAD_FOR_OPADDR_ADDR;
3946 if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
3947 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
3948 && rld[i].secondary_out_reload != -1)
3950 int secondary_out_reload = rld[i].secondary_out_reload;
3952 rld[secondary_out_reload].when_needed
3953 = RELOAD_FOR_OPADDR_ADDR;
3955 /* If there's a tertiary reload we have to change it also. */
3956 if (secondary_out_reload
3957 && rld[secondary_out_reload].secondary_out_reload != -1)
3958 rld[rld[secondary_out_reload].secondary_out_reload].when_needed
3959 = RELOAD_FOR_OPADDR_ADDR;
3962 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
3963 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
3964 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
3965 else
3966 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
3969 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
3970 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
3971 && operand_reloadnum[rld[i].opnum] >= 0
3972 && (rld[operand_reloadnum[rld[i].opnum]].when_needed
3973 == RELOAD_OTHER))
3974 rld[i].when_needed = RELOAD_FOR_OTHER_ADDRESS;
3976 if (goal_alternative_matches[rld[i].opnum] >= 0)
3977 rld[i].opnum = goal_alternative_matches[rld[i].opnum];
3980 /* Scan all the reloads, and check for RELOAD_FOR_OPERAND_ADDRESS reloads.
3981 If we have more than one, then convert all RELOAD_FOR_OPADDR_ADDR
3982 reloads to RELOAD_FOR_OPERAND_ADDRESS reloads.
3984 choose_reload_regs assumes that RELOAD_FOR_OPADDR_ADDR reloads never
3985 conflict with RELOAD_FOR_OPERAND_ADDRESS reloads. This is true for a
3986 single pair of RELOAD_FOR_OPADDR_ADDR/RELOAD_FOR_OPERAND_ADDRESS reloads.
3987 However, if there is more than one RELOAD_FOR_OPERAND_ADDRESS reload,
3988 then a RELOAD_FOR_OPADDR_ADDR reload conflicts with all
3989 RELOAD_FOR_OPERAND_ADDRESS reloads other than the one that uses it.
3990 This is complicated by the fact that a single operand can have more
3991 than one RELOAD_FOR_OPERAND_ADDRESS reload. It is very difficult to fix
3992 choose_reload_regs without affecting code quality, and cases that
3993 actually fail are extremely rare, so it turns out to be better to fix
3994 the problem here by not generating cases that choose_reload_regs will
3995 fail for. */
3996 /* There is a similar problem with RELOAD_FOR_INPUT_ADDRESS /
3997 RELOAD_FOR_OUTPUT_ADDRESS when there is more than one of a kind for
3998 a single operand.
3999 We can reduce the register pressure by exploiting that a
4000 RELOAD_FOR_X_ADDR_ADDR that precedes all RELOAD_FOR_X_ADDRESS reloads
4001 does not conflict with any of them, if it is only used for the first of
4002 the RELOAD_FOR_X_ADDRESS reloads. */
4004 int first_op_addr_num = -2;
4005 int first_inpaddr_num[MAX_RECOG_OPERANDS];
4006 int first_outpaddr_num[MAX_RECOG_OPERANDS];
4007 int need_change= 0;
4008 /* We use last_op_addr_reload and the contents of the above arrays
4009 first as flags - -2 means no instance encountered, -1 means exactly
4010 one instance encountered.
4011 If more than one instance has been encountered, we store the reload
4012 number of the first reload of the kind in question; reload numbers
4013 are known to be non-negative. */
4014 for (i = 0; i < noperands; i++)
4015 first_inpaddr_num[i] = first_outpaddr_num[i] = -2;
4016 for (i = n_reloads - 1; i >= 0; i--)
4018 switch (rld[i].when_needed)
4020 case RELOAD_FOR_OPERAND_ADDRESS:
4021 if (++first_op_addr_num >= 0)
4023 first_op_addr_num = i;
4024 need_change = 1;
4026 break;
4027 case RELOAD_FOR_INPUT_ADDRESS:
4028 if (++first_inpaddr_num[rld[i].opnum] >= 0)
4030 first_inpaddr_num[rld[i].opnum] = i;
4031 need_change = 1;
4033 break;
4034 case RELOAD_FOR_OUTPUT_ADDRESS:
4035 if (++first_outpaddr_num[rld[i].opnum] >= 0)
4037 first_outpaddr_num[rld[i].opnum] = i;
4038 need_change = 1;
4040 break;
4041 default:
4042 break;
4046 if (need_change)
4048 for (i = 0; i < n_reloads; i++)
4050 int first_num, type;
4052 switch (rld[i].when_needed)
4054 case RELOAD_FOR_OPADDR_ADDR:
4055 first_num = first_op_addr_num;
4056 type = RELOAD_FOR_OPERAND_ADDRESS;
4057 break;
4058 case RELOAD_FOR_INPADDR_ADDRESS:
4059 first_num = first_inpaddr_num[rld[i].opnum];
4060 type = RELOAD_FOR_INPUT_ADDRESS;
4061 break;
4062 case RELOAD_FOR_OUTADDR_ADDRESS:
4063 first_num = first_outpaddr_num[rld[i].opnum];
4064 type = RELOAD_FOR_OUTPUT_ADDRESS;
4065 break;
4066 default:
4067 continue;
4069 if (first_num < 0)
4070 continue;
4071 else if (i > first_num)
4072 rld[i].when_needed = type;
4073 else
4075 /* Check if the only TYPE reload that uses reload I is
4076 reload FIRST_NUM. */
4077 for (j = n_reloads - 1; j > first_num; j--)
4079 if (rld[j].when_needed == type
4080 && (rld[i].secondary_p
4081 ? rld[j].secondary_in_reload == i
4082 : reg_mentioned_p (rld[i].in, rld[j].in)))
4084 rld[i].when_needed = type;
4085 break;
4093 /* See if we have any reloads that are now allowed to be merged
4094 because we've changed when the reload is needed to
4095 RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS. Only
4096 check for the most common cases. */
4098 for (i = 0; i < n_reloads; i++)
4099 if (rld[i].in != 0 && rld[i].out == 0
4100 && (rld[i].when_needed == RELOAD_FOR_OPERAND_ADDRESS
4101 || rld[i].when_needed == RELOAD_FOR_OPADDR_ADDR
4102 || rld[i].when_needed == RELOAD_FOR_OTHER_ADDRESS))
4103 for (j = 0; j < n_reloads; j++)
4104 if (i != j && rld[j].in != 0 && rld[j].out == 0
4105 && rld[j].when_needed == rld[i].when_needed
4106 && MATCHES (rld[i].in, rld[j].in)
4107 && rld[i].class == rld[j].class
4108 && !rld[i].nocombine && !rld[j].nocombine
4109 && rld[i].reg_rtx == rld[j].reg_rtx)
4111 rld[i].opnum = MIN (rld[i].opnum, rld[j].opnum);
4112 transfer_replacements (i, j);
4113 rld[j].in = 0;
4116 /* Set which reloads must use registers not used in any group. Start
4117 with those that conflict with a group and then include ones that
4118 conflict with ones that are already known to conflict with a group. */
4120 changed = 0;
4121 for (i = 0; i < n_reloads; i++)
4123 enum machine_mode mode = rld[i].inmode;
4124 enum reg_class class = rld[i].class;
4125 int size;
4127 if (GET_MODE_SIZE (rld[i].outmode) > GET_MODE_SIZE (mode))
4128 mode = rld[i].outmode;
4129 size = CLASS_MAX_NREGS (class, mode);
4131 if (size == 1)
4132 for (j = 0; j < n_reloads; j++)
4133 if ((CLASS_MAX_NREGS (rld[j].class,
4134 (GET_MODE_SIZE (rld[j].outmode)
4135 > GET_MODE_SIZE (rld[j].inmode))
4136 ? rld[j].outmode : rld[j].inmode)
4137 > 1)
4138 && !rld[j].optional
4139 && (rld[j].in != 0 || rld[j].out != 0
4140 || rld[j].secondary_p)
4141 && reloads_conflict (i, j)
4142 && reg_classes_intersect_p (class, rld[j].class))
4144 rld[i].nongroup = 1;
4145 changed = 1;
4146 break;
4150 while (changed)
4152 changed = 0;
4154 for (i = 0; i < n_reloads; i++)
4156 enum machine_mode mode = rld[i].inmode;
4157 enum reg_class class = rld[i].class;
4158 int size;
4160 if (GET_MODE_SIZE (rld[i].outmode) > GET_MODE_SIZE (mode))
4161 mode = rld[i].outmode;
4162 size = CLASS_MAX_NREGS (class, mode);
4164 if (! rld[i].nongroup && size == 1)
4165 for (j = 0; j < n_reloads; j++)
4166 if (rld[j].nongroup
4167 && reloads_conflict (i, j)
4168 && reg_classes_intersect_p (class, rld[j].class))
4170 rld[i].nongroup = 1;
4171 changed = 1;
4172 break;
4177 return retval;
4180 /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
4181 accepts a memory operand with constant address. */
4183 static int
4184 alternative_allows_memconst (constraint, altnum)
4185 const char *constraint;
4186 int altnum;
4188 register int c;
4189 /* Skip alternatives before the one requested. */
4190 while (altnum > 0)
4192 while (*constraint++ != ',');
4193 altnum--;
4195 /* Scan the requested alternative for 'm' or 'o'.
4196 If one of them is present, this alternative accepts memory constants. */
4197 while ((c = *constraint++) && c != ',' && c != '#')
4198 if (c == 'm' || c == 'o')
4199 return 1;
4200 return 0;
4203 /* Scan X for memory references and scan the addresses for reloading.
4204 Also checks for references to "constant" regs that we want to eliminate
4205 and replaces them with the values they stand for.
4206 We may alter X destructively if it contains a reference to such.
4207 If X is just a constant reg, we return the equivalent value
4208 instead of X.
4210 IND_LEVELS says how many levels of indirect addressing this machine
4211 supports.
4213 OPNUM and TYPE identify the purpose of the reload.
4215 IS_SET_DEST is true if X is the destination of a SET, which is not
4216 appropriate to be replaced by a constant.
4218 INSN, if nonzero, is the insn in which we do the reload. It is used
4219 to determine if we may generate output reloads, and where to put USEs
4220 for pseudos that we have to replace with stack slots. */
4222 static rtx
4223 find_reloads_toplev (x, opnum, type, ind_levels, is_set_dest, insn)
4224 rtx x;
4225 int opnum;
4226 enum reload_type type;
4227 int ind_levels;
4228 int is_set_dest;
4229 rtx insn;
4231 register RTX_CODE code = GET_CODE (x);
4233 register const char *fmt = GET_RTX_FORMAT (code);
4234 register int i;
4235 int copied;
4237 if (code == REG)
4239 /* This code is duplicated for speed in find_reloads. */
4240 register int regno = REGNO (x);
4241 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4242 x = reg_equiv_constant[regno];
4243 #if 0
4244 /* This creates (subreg (mem...)) which would cause an unnecessary
4245 reload of the mem. */
4246 else if (reg_equiv_mem[regno] != 0)
4247 x = reg_equiv_mem[regno];
4248 #endif
4249 else if (reg_equiv_memory_loc[regno]
4250 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
4252 rtx mem = make_memloc (x, regno);
4253 if (reg_equiv_address[regno]
4254 || ! rtx_equal_p (mem, reg_equiv_mem[regno]))
4256 /* If this is not a toplevel operand, find_reloads doesn't see
4257 this substitution. We have to emit a USE of the pseudo so
4258 that delete_output_reload can see it. */
4259 if (replace_reloads && recog_data.operand[opnum] != x)
4260 emit_insn_before (gen_rtx_USE (VOIDmode, x), insn);
4261 x = mem;
4262 find_reloads_address (GET_MODE (x), &x, XEXP (x, 0), &XEXP (x, 0),
4263 opnum, type, ind_levels, insn);
4266 return x;
4268 if (code == MEM)
4270 rtx tem = x;
4271 find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
4272 opnum, type, ind_levels, insn);
4273 return tem;
4276 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG)
4278 /* Check for SUBREG containing a REG that's equivalent to a constant.
4279 If the constant has a known value, truncate it right now.
4280 Similarly if we are extracting a single-word of a multi-word
4281 constant. If the constant is symbolic, allow it to be substituted
4282 normally. push_reload will strip the subreg later. If the
4283 constant is VOIDmode, abort because we will lose the mode of
4284 the register (this should never happen because one of the cases
4285 above should handle it). */
4287 register int regno = REGNO (SUBREG_REG (x));
4288 rtx tem;
4290 if (subreg_lowpart_p (x)
4291 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4292 && reg_equiv_constant[regno] != 0
4293 && (tem = gen_lowpart_common (GET_MODE (x),
4294 reg_equiv_constant[regno])) != 0)
4295 return tem;
4297 if (GET_MODE_BITSIZE (GET_MODE (x)) == BITS_PER_WORD
4298 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4299 && reg_equiv_constant[regno] != 0
4300 && (tem = operand_subword (reg_equiv_constant[regno],
4301 SUBREG_WORD (x), 0,
4302 GET_MODE (SUBREG_REG (x)))) != 0)
4304 /* TEM is now a word sized constant for the bits from X that
4305 we wanted. However, TEM may be the wrong representation.
4307 Use gen_lowpart_common to convert a CONST_INT into a
4308 CONST_DOUBLE and vice versa as needed according to by the mode
4309 of the SUBREG. */
4310 tem = gen_lowpart_common (GET_MODE (x), tem);
4311 if (!tem)
4312 abort ();
4313 return tem;
4316 /* If the SUBREG is wider than a word, the above test will fail.
4317 For example, we might have a SImode SUBREG of a DImode SUBREG_REG
4318 for a 16 bit target, or a DImode SUBREG of a TImode SUBREG_REG for
4319 a 32 bit target. We still can - and have to - handle this
4320 for non-paradoxical subregs of CONST_INTs. */
4321 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4322 && reg_equiv_constant[regno] != 0
4323 && GET_CODE (reg_equiv_constant[regno]) == CONST_INT
4324 && (GET_MODE_SIZE (GET_MODE (x))
4325 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
4327 int shift = SUBREG_WORD (x) * BITS_PER_WORD;
4328 if (WORDS_BIG_ENDIAN)
4329 shift = (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x)))
4330 - GET_MODE_BITSIZE (GET_MODE (x))
4331 - shift);
4332 /* Here we use the knowledge that CONST_INTs have a
4333 HOST_WIDE_INT field. */
4334 if (shift >= HOST_BITS_PER_WIDE_INT)
4335 shift = HOST_BITS_PER_WIDE_INT - 1;
4336 return GEN_INT (INTVAL (reg_equiv_constant[regno]) >> shift);
4339 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4340 && reg_equiv_constant[regno] != 0
4341 && GET_MODE (reg_equiv_constant[regno]) == VOIDmode)
4342 abort ();
4344 /* If the subreg contains a reg that will be converted to a mem,
4345 convert the subreg to a narrower memref now.
4346 Otherwise, we would get (subreg (mem ...) ...),
4347 which would force reload of the mem.
4349 We also need to do this if there is an equivalent MEM that is
4350 not offsettable. In that case, alter_subreg would produce an
4351 invalid address on big-endian machines.
4353 For machines that extend byte loads, we must not reload using
4354 a wider mode if we have a paradoxical SUBREG. find_reloads will
4355 force a reload in that case. So we should not do anything here. */
4357 else if (regno >= FIRST_PSEUDO_REGISTER
4358 #ifdef LOAD_EXTEND_OP
4359 && (GET_MODE_SIZE (GET_MODE (x))
4360 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
4361 #endif
4362 && (reg_equiv_address[regno] != 0
4363 || (reg_equiv_mem[regno] != 0
4364 && (! strict_memory_address_p (GET_MODE (x),
4365 XEXP (reg_equiv_mem[regno], 0))
4366 || ! offsettable_memref_p (reg_equiv_mem[regno])
4367 || num_not_at_initial_offset))))
4368 x = find_reloads_subreg_address (x, 1, opnum, type, ind_levels,
4369 insn);
4372 for (copied = 0, i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4374 if (fmt[i] == 'e')
4376 rtx new_part = find_reloads_toplev (XEXP (x, i), opnum, type,
4377 ind_levels, is_set_dest, insn);
4378 /* If we have replaced a reg with it's equivalent memory loc -
4379 that can still be handled here e.g. if it's in a paradoxical
4380 subreg - we must make the change in a copy, rather than using
4381 a destructive change. This way, find_reloads can still elect
4382 not to do the change. */
4383 if (new_part != XEXP (x, i) && ! CONSTANT_P (new_part) && ! copied)
4385 x = shallow_copy_rtx (x);
4386 copied = 1;
4388 XEXP (x, i) = new_part;
4391 return x;
4394 /* Return a mem ref for the memory equivalent of reg REGNO.
4395 This mem ref is not shared with anything. */
4397 static rtx
4398 make_memloc (ad, regno)
4399 rtx ad;
4400 int regno;
4402 /* We must rerun eliminate_regs, in case the elimination
4403 offsets have changed. */
4404 rtx tem
4405 = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0, NULL_RTX), 0);
4407 /* If TEM might contain a pseudo, we must copy it to avoid
4408 modifying it when we do the substitution for the reload. */
4409 if (rtx_varies_p (tem))
4410 tem = copy_rtx (tem);
4412 tem = gen_rtx_MEM (GET_MODE (ad), tem);
4413 RTX_UNCHANGING_P (tem) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
4414 return tem;
4417 /* Record all reloads needed for handling memory address AD
4418 which appears in *LOC in a memory reference to mode MODE
4419 which itself is found in location *MEMREFLOC.
4420 Note that we take shortcuts assuming that no multi-reg machine mode
4421 occurs as part of an address.
4423 OPNUM and TYPE specify the purpose of this reload.
4425 IND_LEVELS says how many levels of indirect addressing this machine
4426 supports.
4428 INSN, if nonzero, is the insn in which we do the reload. It is used
4429 to determine if we may generate output reloads, and where to put USEs
4430 for pseudos that we have to replace with stack slots.
4432 Value is nonzero if this address is reloaded or replaced as a whole.
4433 This is interesting to the caller if the address is an autoincrement.
4435 Note that there is no verification that the address will be valid after
4436 this routine does its work. Instead, we rely on the fact that the address
4437 was valid when reload started. So we need only undo things that reload
4438 could have broken. These are wrong register types, pseudos not allocated
4439 to a hard register, and frame pointer elimination. */
4441 static int
4442 find_reloads_address (mode, memrefloc, ad, loc, opnum, type, ind_levels, insn)
4443 enum machine_mode mode;
4444 rtx *memrefloc;
4445 rtx ad;
4446 rtx *loc;
4447 int opnum;
4448 enum reload_type type;
4449 int ind_levels;
4450 rtx insn;
4452 register int regno;
4453 int removed_and = 0;
4454 rtx tem;
4456 /* If the address is a register, see if it is a legitimate address and
4457 reload if not. We first handle the cases where we need not reload
4458 or where we must reload in a non-standard way. */
4460 if (GET_CODE (ad) == REG)
4462 regno = REGNO (ad);
4464 if (reg_equiv_constant[regno] != 0
4465 && strict_memory_address_p (mode, reg_equiv_constant[regno]))
4467 *loc = ad = reg_equiv_constant[regno];
4468 return 0;
4471 tem = reg_equiv_memory_loc[regno];
4472 if (tem != 0)
4474 if (reg_equiv_address[regno] != 0 || num_not_at_initial_offset)
4476 tem = make_memloc (ad, regno);
4477 if (! strict_memory_address_p (GET_MODE (tem), XEXP (tem, 0)))
4479 find_reloads_address (GET_MODE (tem), NULL_PTR, XEXP (tem, 0),
4480 &XEXP (tem, 0), opnum, ADDR_TYPE (type),
4481 ind_levels, insn);
4483 /* We can avoid a reload if the register's equivalent memory
4484 expression is valid as an indirect memory address.
4485 But not all addresses are valid in a mem used as an indirect
4486 address: only reg or reg+constant. */
4488 if (ind_levels > 0
4489 && strict_memory_address_p (mode, tem)
4490 && (GET_CODE (XEXP (tem, 0)) == REG
4491 || (GET_CODE (XEXP (tem, 0)) == PLUS
4492 && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG
4493 && CONSTANT_P (XEXP (XEXP (tem, 0), 1)))))
4495 /* TEM is not the same as what we'll be replacing the
4496 pseudo with after reload, put a USE in front of INSN
4497 in the final reload pass. */
4498 if (replace_reloads
4499 && num_not_at_initial_offset
4500 && ! rtx_equal_p (tem, reg_equiv_mem[regno]))
4502 *loc = tem;
4503 emit_insn_before (gen_rtx_USE (VOIDmode, ad), insn);
4504 /* This doesn't really count as replacing the address
4505 as a whole, since it is still a memory access. */
4507 return 0;
4509 ad = tem;
4513 /* The only remaining case where we can avoid a reload is if this is a
4514 hard register that is valid as a base register and which is not the
4515 subject of a CLOBBER in this insn. */
4517 else if (regno < FIRST_PSEUDO_REGISTER
4518 && REGNO_MODE_OK_FOR_BASE_P (regno, mode)
4519 && ! regno_clobbered_p (regno, this_insn))
4520 return 0;
4522 /* If we do not have one of the cases above, we must do the reload. */
4523 push_reload (ad, NULL_RTX, loc, NULL_PTR, BASE_REG_CLASS,
4524 GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
4525 return 1;
4528 if (strict_memory_address_p (mode, ad))
4530 /* The address appears valid, so reloads are not needed.
4531 But the address may contain an eliminable register.
4532 This can happen because a machine with indirect addressing
4533 may consider a pseudo register by itself a valid address even when
4534 it has failed to get a hard reg.
4535 So do a tree-walk to find and eliminate all such regs. */
4537 /* But first quickly dispose of a common case. */
4538 if (GET_CODE (ad) == PLUS
4539 && GET_CODE (XEXP (ad, 1)) == CONST_INT
4540 && GET_CODE (XEXP (ad, 0)) == REG
4541 && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
4542 return 0;
4544 subst_reg_equivs_changed = 0;
4545 *loc = subst_reg_equivs (ad, insn);
4547 if (! subst_reg_equivs_changed)
4548 return 0;
4550 /* Check result for validity after substitution. */
4551 if (strict_memory_address_p (mode, ad))
4552 return 0;
4555 #ifdef LEGITIMIZE_RELOAD_ADDRESS
4558 if (memrefloc)
4560 LEGITIMIZE_RELOAD_ADDRESS (ad, GET_MODE (*memrefloc), opnum, type,
4561 ind_levels, win);
4563 break;
4564 win:
4565 *memrefloc = copy_rtx (*memrefloc);
4566 XEXP (*memrefloc, 0) = ad;
4567 move_replacements (&ad, &XEXP (*memrefloc, 0));
4568 return 1;
4570 while (0);
4571 #endif
4573 /* The address is not valid. We have to figure out why. First see if
4574 we have an outer AND and remove it if so. Then analyze what's inside. */
4576 if (GET_CODE (ad) == AND)
4578 removed_and = 1;
4579 loc = &XEXP (ad, 0);
4580 ad = *loc;
4583 /* One possibility for why the address is invalid is that it is itself
4584 a MEM. This can happen when the frame pointer is being eliminated, a
4585 pseudo is not allocated to a hard register, and the offset between the
4586 frame and stack pointers is not its initial value. In that case the
4587 pseudo will have been replaced by a MEM referring to the
4588 stack pointer. */
4589 if (GET_CODE (ad) == MEM)
4591 /* First ensure that the address in this MEM is valid. Then, unless
4592 indirect addresses are valid, reload the MEM into a register. */
4593 tem = ad;
4594 find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
4595 opnum, ADDR_TYPE (type),
4596 ind_levels == 0 ? 0 : ind_levels - 1, insn);
4598 /* If tem was changed, then we must create a new memory reference to
4599 hold it and store it back into memrefloc. */
4600 if (tem != ad && memrefloc)
4602 *memrefloc = copy_rtx (*memrefloc);
4603 copy_replacements (tem, XEXP (*memrefloc, 0));
4604 loc = &XEXP (*memrefloc, 0);
4605 if (removed_and)
4606 loc = &XEXP (*loc, 0);
4609 /* Check similar cases as for indirect addresses as above except
4610 that we can allow pseudos and a MEM since they should have been
4611 taken care of above. */
4613 if (ind_levels == 0
4614 || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
4615 || GET_CODE (XEXP (tem, 0)) == MEM
4616 || ! (GET_CODE (XEXP (tem, 0)) == REG
4617 || (GET_CODE (XEXP (tem, 0)) == PLUS
4618 && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG
4619 && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT)))
4621 /* Must use TEM here, not AD, since it is the one that will
4622 have any subexpressions reloaded, if needed. */
4623 push_reload (tem, NULL_RTX, loc, NULL_PTR,
4624 BASE_REG_CLASS, GET_MODE (tem),
4625 VOIDmode, 0,
4626 0, opnum, type);
4627 return ! removed_and;
4629 else
4630 return 0;
4633 /* If we have address of a stack slot but it's not valid because the
4634 displacement is too large, compute the sum in a register.
4635 Handle all base registers here, not just fp/ap/sp, because on some
4636 targets (namely SH) we can also get too large displacements from
4637 big-endian corrections. */
4638 else if (GET_CODE (ad) == PLUS
4639 && GET_CODE (XEXP (ad, 0)) == REG
4640 && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
4641 && REG_MODE_OK_FOR_BASE_P (XEXP (ad, 0), mode)
4642 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4644 /* Unshare the MEM rtx so we can safely alter it. */
4645 if (memrefloc)
4647 *memrefloc = copy_rtx (*memrefloc);
4648 loc = &XEXP (*memrefloc, 0);
4649 if (removed_and)
4650 loc = &XEXP (*loc, 0);
4653 if (double_reg_address_ok)
4655 /* Unshare the sum as well. */
4656 *loc = ad = copy_rtx (ad);
4658 /* Reload the displacement into an index reg.
4659 We assume the frame pointer or arg pointer is a base reg. */
4660 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4661 INDEX_REG_CLASS, GET_MODE (ad), opnum,
4662 type, ind_levels);
4663 return 0;
4665 else
4667 /* If the sum of two regs is not necessarily valid,
4668 reload the sum into a base reg.
4669 That will at least work. */
4670 find_reloads_address_part (ad, loc, BASE_REG_CLASS,
4671 Pmode, opnum, type, ind_levels);
4673 return ! removed_and;
4676 /* If we have an indexed stack slot, there are three possible reasons why
4677 it might be invalid: The index might need to be reloaded, the address
4678 might have been made by frame pointer elimination and hence have a
4679 constant out of range, or both reasons might apply.
4681 We can easily check for an index needing reload, but even if that is the
4682 case, we might also have an invalid constant. To avoid making the
4683 conservative assumption and requiring two reloads, we see if this address
4684 is valid when not interpreted strictly. If it is, the only problem is
4685 that the index needs a reload and find_reloads_address_1 will take care
4686 of it.
4688 There is still a case when we might generate an extra reload,
4689 however. In certain cases eliminate_regs will return a MEM for a REG
4690 (see the code there for details). In those cases, memory_address_p
4691 applied to our address will return 0 so we will think that our offset
4692 must be too large. But it might indeed be valid and the only problem
4693 is that a MEM is present where a REG should be. This case should be
4694 very rare and there doesn't seem to be any way to avoid it.
4696 If we decide to do something here, it must be that
4697 `double_reg_address_ok' is true and that this address rtl was made by
4698 eliminate_regs. We generate a reload of the fp/sp/ap + constant and
4699 rework the sum so that the reload register will be added to the index.
4700 This is safe because we know the address isn't shared.
4702 We check for fp/ap/sp as both the first and second operand of the
4703 innermost PLUS. */
4705 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4706 && GET_CODE (XEXP (ad, 0)) == PLUS
4707 && (XEXP (XEXP (ad, 0), 0) == frame_pointer_rtx
4708 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
4709 || XEXP (XEXP (ad, 0), 0) == hard_frame_pointer_rtx
4710 #endif
4711 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4712 || XEXP (XEXP (ad, 0), 0) == arg_pointer_rtx
4713 #endif
4714 || XEXP (XEXP (ad, 0), 0) == stack_pointer_rtx)
4715 && ! memory_address_p (mode, ad))
4717 *loc = ad = gen_rtx_PLUS (GET_MODE (ad),
4718 plus_constant (XEXP (XEXP (ad, 0), 0),
4719 INTVAL (XEXP (ad, 1))),
4720 XEXP (XEXP (ad, 0), 1));
4721 find_reloads_address_part (XEXP (ad, 0), &XEXP (ad, 0), BASE_REG_CLASS,
4722 GET_MODE (ad), opnum, type, ind_levels);
4723 find_reloads_address_1 (mode, XEXP (ad, 1), 1, &XEXP (ad, 1), opnum,
4724 type, 0, insn);
4726 return 0;
4729 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
4730 && GET_CODE (XEXP (ad, 0)) == PLUS
4731 && (XEXP (XEXP (ad, 0), 1) == frame_pointer_rtx
4732 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4733 || XEXP (XEXP (ad, 0), 1) == hard_frame_pointer_rtx
4734 #endif
4735 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4736 || XEXP (XEXP (ad, 0), 1) == arg_pointer_rtx
4737 #endif
4738 || XEXP (XEXP (ad, 0), 1) == stack_pointer_rtx)
4739 && ! memory_address_p (mode, ad))
4741 *loc = ad = gen_rtx_PLUS (GET_MODE (ad),
4742 XEXP (XEXP (ad, 0), 0),
4743 plus_constant (XEXP (XEXP (ad, 0), 1),
4744 INTVAL (XEXP (ad, 1))));
4745 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1), BASE_REG_CLASS,
4746 GET_MODE (ad), opnum, type, ind_levels);
4747 find_reloads_address_1 (mode, XEXP (ad, 0), 1, &XEXP (ad, 0), opnum,
4748 type, 0, insn);
4750 return 0;
4753 /* See if address becomes valid when an eliminable register
4754 in a sum is replaced. */
4756 tem = ad;
4757 if (GET_CODE (ad) == PLUS)
4758 tem = subst_indexed_address (ad);
4759 if (tem != ad && strict_memory_address_p (mode, tem))
4761 /* Ok, we win that way. Replace any additional eliminable
4762 registers. */
4764 subst_reg_equivs_changed = 0;
4765 tem = subst_reg_equivs (tem, insn);
4767 /* Make sure that didn't make the address invalid again. */
4769 if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
4771 *loc = tem;
4772 return 0;
4776 /* If constants aren't valid addresses, reload the constant address
4777 into a register. */
4778 if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad))
4780 /* If AD is in address in the constant pool, the MEM rtx may be shared.
4781 Unshare it so we can safely alter it. */
4782 if (memrefloc && GET_CODE (ad) == SYMBOL_REF
4783 && CONSTANT_POOL_ADDRESS_P (ad))
4785 *memrefloc = copy_rtx (*memrefloc);
4786 loc = &XEXP (*memrefloc, 0);
4787 if (removed_and)
4788 loc = &XEXP (*loc, 0);
4791 find_reloads_address_part (ad, loc, BASE_REG_CLASS, Pmode, opnum, type,
4792 ind_levels);
4793 return ! removed_and;
4796 return find_reloads_address_1 (mode, ad, 0, loc, opnum, type, ind_levels,
4797 insn);
4800 /* Find all pseudo regs appearing in AD
4801 that are eliminable in favor of equivalent values
4802 and do not have hard regs; replace them by their equivalents.
4803 INSN, if nonzero, is the insn in which we do the reload. We put USEs in
4804 front of it for pseudos that we have to replace with stack slots. */
4806 static rtx
4807 subst_reg_equivs (ad, insn)
4808 rtx ad;
4809 rtx insn;
4811 register RTX_CODE code = GET_CODE (ad);
4812 register int i;
4813 register const char *fmt;
4815 switch (code)
4817 case HIGH:
4818 case CONST_INT:
4819 case CONST:
4820 case CONST_DOUBLE:
4821 case SYMBOL_REF:
4822 case LABEL_REF:
4823 case PC:
4824 case CC0:
4825 return ad;
4827 case REG:
4829 register int regno = REGNO (ad);
4831 if (reg_equiv_constant[regno] != 0)
4833 subst_reg_equivs_changed = 1;
4834 return reg_equiv_constant[regno];
4836 if (reg_equiv_memory_loc[regno] && num_not_at_initial_offset)
4838 rtx mem = make_memloc (ad, regno);
4839 if (! rtx_equal_p (mem, reg_equiv_mem[regno]))
4841 subst_reg_equivs_changed = 1;
4842 emit_insn_before (gen_rtx_USE (VOIDmode, ad), insn);
4843 return mem;
4847 return ad;
4849 case PLUS:
4850 /* Quickly dispose of a common case. */
4851 if (XEXP (ad, 0) == frame_pointer_rtx
4852 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4853 return ad;
4854 break;
4856 default:
4857 break;
4860 fmt = GET_RTX_FORMAT (code);
4861 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4862 if (fmt[i] == 'e')
4863 XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i), insn);
4864 return ad;
4867 /* Compute the sum of X and Y, making canonicalizations assumed in an
4868 address, namely: sum constant integers, surround the sum of two
4869 constants with a CONST, put the constant as the second operand, and
4870 group the constant on the outermost sum.
4872 This routine assumes both inputs are already in canonical form. */
4875 form_sum (x, y)
4876 rtx x, y;
4878 rtx tem;
4879 enum machine_mode mode = GET_MODE (x);
4881 if (mode == VOIDmode)
4882 mode = GET_MODE (y);
4884 if (mode == VOIDmode)
4885 mode = Pmode;
4887 if (GET_CODE (x) == CONST_INT)
4888 return plus_constant (y, INTVAL (x));
4889 else if (GET_CODE (y) == CONST_INT)
4890 return plus_constant (x, INTVAL (y));
4891 else if (CONSTANT_P (x))
4892 tem = x, x = y, y = tem;
4894 if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
4895 return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
4897 /* Note that if the operands of Y are specified in the opposite
4898 order in the recursive calls below, infinite recursion will occur. */
4899 if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
4900 return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
4902 /* If both constant, encapsulate sum. Otherwise, just form sum. A
4903 constant will have been placed second. */
4904 if (CONSTANT_P (x) && CONSTANT_P (y))
4906 if (GET_CODE (x) == CONST)
4907 x = XEXP (x, 0);
4908 if (GET_CODE (y) == CONST)
4909 y = XEXP (y, 0);
4911 return gen_rtx_CONST (VOIDmode, gen_rtx_PLUS (mode, x, y));
4914 return gen_rtx_PLUS (mode, x, y);
4917 /* If ADDR is a sum containing a pseudo register that should be
4918 replaced with a constant (from reg_equiv_constant),
4919 return the result of doing so, and also apply the associative
4920 law so that the result is more likely to be a valid address.
4921 (But it is not guaranteed to be one.)
4923 Note that at most one register is replaced, even if more are
4924 replaceable. Also, we try to put the result into a canonical form
4925 so it is more likely to be a valid address.
4927 In all other cases, return ADDR. */
4929 static rtx
4930 subst_indexed_address (addr)
4931 rtx addr;
4933 rtx op0 = 0, op1 = 0, op2 = 0;
4934 rtx tem;
4935 int regno;
4937 if (GET_CODE (addr) == PLUS)
4939 /* Try to find a register to replace. */
4940 op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
4941 if (GET_CODE (op0) == REG
4942 && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
4943 && reg_renumber[regno] < 0
4944 && reg_equiv_constant[regno] != 0)
4945 op0 = reg_equiv_constant[regno];
4946 else if (GET_CODE (op1) == REG
4947 && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
4948 && reg_renumber[regno] < 0
4949 && reg_equiv_constant[regno] != 0)
4950 op1 = reg_equiv_constant[regno];
4951 else if (GET_CODE (op0) == PLUS
4952 && (tem = subst_indexed_address (op0)) != op0)
4953 op0 = tem;
4954 else if (GET_CODE (op1) == PLUS
4955 && (tem = subst_indexed_address (op1)) != op1)
4956 op1 = tem;
4957 else
4958 return addr;
4960 /* Pick out up to three things to add. */
4961 if (GET_CODE (op1) == PLUS)
4962 op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
4963 else if (GET_CODE (op0) == PLUS)
4964 op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
4966 /* Compute the sum. */
4967 if (op2 != 0)
4968 op1 = form_sum (op1, op2);
4969 if (op1 != 0)
4970 op0 = form_sum (op0, op1);
4972 return op0;
4974 return addr;
4977 /* Record the pseudo registers we must reload into hard registers in a
4978 subexpression of a would-be memory address, X referring to a value
4979 in mode MODE. (This function is not called if the address we find
4980 is strictly valid.)
4982 CONTEXT = 1 means we are considering regs as index regs,
4983 = 0 means we are considering them as base regs.
4985 OPNUM and TYPE specify the purpose of any reloads made.
4987 IND_LEVELS says how many levels of indirect addressing are
4988 supported at this point in the address.
4990 INSN, if nonzero, is the insn in which we do the reload. It is used
4991 to determine if we may generate output reloads.
4993 We return nonzero if X, as a whole, is reloaded or replaced. */
4995 /* Note that we take shortcuts assuming that no multi-reg machine mode
4996 occurs as part of an address.
4997 Also, this is not fully machine-customizable; it works for machines
4998 such as vaxes and 68000's and 32000's, but other possible machines
4999 could have addressing modes that this does not handle right. */
5001 static int
5002 find_reloads_address_1 (mode, x, context, loc, opnum, type, ind_levels, insn)
5003 enum machine_mode mode;
5004 rtx x;
5005 int context;
5006 rtx *loc;
5007 int opnum;
5008 enum reload_type type;
5009 int ind_levels;
5010 rtx insn;
5012 register RTX_CODE code = GET_CODE (x);
5014 switch (code)
5016 case PLUS:
5018 register rtx orig_op0 = XEXP (x, 0);
5019 register rtx orig_op1 = XEXP (x, 1);
5020 register RTX_CODE code0 = GET_CODE (orig_op0);
5021 register RTX_CODE code1 = GET_CODE (orig_op1);
5022 register rtx op0 = orig_op0;
5023 register rtx op1 = orig_op1;
5025 if (GET_CODE (op0) == SUBREG)
5027 op0 = SUBREG_REG (op0);
5028 code0 = GET_CODE (op0);
5029 if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER)
5030 op0 = gen_rtx_REG (word_mode,
5031 REGNO (op0) + SUBREG_WORD (orig_op0));
5034 if (GET_CODE (op1) == SUBREG)
5036 op1 = SUBREG_REG (op1);
5037 code1 = GET_CODE (op1);
5038 if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER)
5039 op1 = gen_rtx_REG (GET_MODE (op1),
5040 REGNO (op1) + SUBREG_WORD (orig_op1));
5043 if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
5044 || code0 == ZERO_EXTEND || code1 == MEM)
5046 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5047 type, ind_levels, insn);
5048 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5049 type, ind_levels, insn);
5052 else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
5053 || code1 == ZERO_EXTEND || code0 == MEM)
5055 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5056 type, ind_levels, insn);
5057 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5058 type, ind_levels, insn);
5061 else if (code0 == CONST_INT || code0 == CONST
5062 || code0 == SYMBOL_REF || code0 == LABEL_REF)
5063 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5064 type, ind_levels, insn);
5066 else if (code1 == CONST_INT || code1 == CONST
5067 || code1 == SYMBOL_REF || code1 == LABEL_REF)
5068 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5069 type, ind_levels, insn);
5071 else if (code0 == REG && code1 == REG)
5073 if (REG_OK_FOR_INDEX_P (op0)
5074 && REG_MODE_OK_FOR_BASE_P (op1, mode))
5075 return 0;
5076 else if (REG_OK_FOR_INDEX_P (op1)
5077 && REG_MODE_OK_FOR_BASE_P (op0, mode))
5078 return 0;
5079 else if (REG_MODE_OK_FOR_BASE_P (op1, mode))
5080 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5081 type, ind_levels, insn);
5082 else if (REG_MODE_OK_FOR_BASE_P (op0, mode))
5083 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5084 type, ind_levels, insn);
5085 else if (REG_OK_FOR_INDEX_P (op1))
5086 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5087 type, ind_levels, insn);
5088 else if (REG_OK_FOR_INDEX_P (op0))
5089 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5090 type, ind_levels, insn);
5091 else
5093 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5094 type, ind_levels, insn);
5095 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5096 type, ind_levels, insn);
5100 else if (code0 == REG)
5102 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5103 type, ind_levels, insn);
5104 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5105 type, ind_levels, insn);
5108 else if (code1 == REG)
5110 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5111 type, ind_levels, insn);
5112 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5113 type, ind_levels, insn);
5117 return 0;
5119 case POST_INC:
5120 case POST_DEC:
5121 case PRE_INC:
5122 case PRE_DEC:
5123 if (GET_CODE (XEXP (x, 0)) == REG)
5125 register int regno = REGNO (XEXP (x, 0));
5126 int value = 0;
5127 rtx x_orig = x;
5129 /* A register that is incremented cannot be constant! */
5130 if (regno >= FIRST_PSEUDO_REGISTER
5131 && reg_equiv_constant[regno] != 0)
5132 abort ();
5134 /* Handle a register that is equivalent to a memory location
5135 which cannot be addressed directly. */
5136 if (reg_equiv_memory_loc[regno] != 0
5137 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5139 rtx tem = make_memloc (XEXP (x, 0), regno);
5140 if (reg_equiv_address[regno]
5141 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5143 /* First reload the memory location's address.
5144 We can't use ADDR_TYPE (type) here, because we need to
5145 write back the value after reading it, hence we actually
5146 need two registers. */
5147 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5148 &XEXP (tem, 0), opnum, type,
5149 ind_levels, insn);
5150 /* Put this inside a new increment-expression. */
5151 x = gen_rtx_fmt_e (GET_CODE (x), GET_MODE (x), tem);
5152 /* Proceed to reload that, as if it contained a register. */
5156 /* If we have a hard register that is ok as an index,
5157 don't make a reload. If an autoincrement of a nice register
5158 isn't "valid", it must be that no autoincrement is "valid".
5159 If that is true and something made an autoincrement anyway,
5160 this must be a special context where one is allowed.
5161 (For example, a "push" instruction.)
5162 We can't improve this address, so leave it alone. */
5164 /* Otherwise, reload the autoincrement into a suitable hard reg
5165 and record how much to increment by. */
5167 if (reg_renumber[regno] >= 0)
5168 regno = reg_renumber[regno];
5169 if ((regno >= FIRST_PSEUDO_REGISTER
5170 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
5171 : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
5173 #ifdef AUTO_INC_DEC
5174 register rtx link;
5175 #endif
5176 int reloadnum;
5178 /* If we can output the register afterwards, do so, this
5179 saves the extra update.
5180 We can do so if we have an INSN - i.e. no JUMP_INSN nor
5181 CALL_INSN - and it does not set CC0.
5182 But don't do this if we cannot directly address the
5183 memory location, since this will make it harder to
5184 reuse address reloads, and increases register pressure.
5185 Also don't do this if we can probably update x directly. */
5186 rtx equiv = (GET_CODE (XEXP (x, 0)) == MEM
5187 ? XEXP (x, 0)
5188 : reg_equiv_mem[regno]);
5189 int icode = (int) add_optab->handlers[(int) Pmode].insn_code;
5190 if (insn && GET_CODE (insn) == INSN && equiv
5191 && memory_operand (equiv, GET_MODE (equiv))
5192 #ifdef HAVE_cc0
5193 && ! sets_cc0_p (PATTERN (insn))
5194 #endif
5195 && ! (icode != CODE_FOR_nothing
5196 && ((*insn_data[icode].operand[0].predicate)
5197 (equiv, Pmode))
5198 && ((*insn_data[icode].operand[1].predicate)
5199 (equiv, Pmode))))
5201 loc = &XEXP (x, 0);
5202 x = XEXP (x, 0);
5203 reloadnum
5204 = push_reload (x, x, loc, loc,
5205 (context ? INDEX_REG_CLASS : BASE_REG_CLASS),
5206 GET_MODE (x), GET_MODE (x), 0, 0,
5207 opnum, RELOAD_OTHER);
5209 /* If we created a new MEM based on reg_equiv_mem[REGNO], then
5210 LOC above is part of the new MEM, not the MEM in INSN.
5212 We must also replace the address of the MEM in INSN. */
5213 if (&XEXP (x_orig, 0) != loc)
5214 push_replacement (&XEXP (x_orig, 0), reloadnum, VOIDmode);
5217 else
5219 reloadnum
5220 = push_reload (x, NULL_RTX, loc, NULL_PTR,
5221 (context ? INDEX_REG_CLASS : BASE_REG_CLASS),
5222 GET_MODE (x), GET_MODE (x), 0, 0,
5223 opnum, type);
5224 rld[reloadnum].inc
5225 = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
5227 value = 1;
5230 #ifdef AUTO_INC_DEC
5231 /* Update the REG_INC notes. */
5233 for (link = REG_NOTES (this_insn);
5234 link; link = XEXP (link, 1))
5235 if (REG_NOTE_KIND (link) == REG_INC
5236 && REGNO (XEXP (link, 0)) == REGNO (XEXP (x_orig, 0)))
5237 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5238 #endif
5240 return value;
5243 else if (GET_CODE (XEXP (x, 0)) == MEM)
5245 /* This is probably the result of a substitution, by eliminate_regs,
5246 of an equivalent address for a pseudo that was not allocated to a
5247 hard register. Verify that the specified address is valid and
5248 reload it into a register. */
5249 /* Variable `tem' might or might not be used in FIND_REG_INC_NOTE. */
5250 rtx tem ATTRIBUTE_UNUSED = XEXP (x, 0);
5251 register rtx link;
5252 int reloadnum;
5254 /* Since we know we are going to reload this item, don't decrement
5255 for the indirection level.
5257 Note that this is actually conservative: it would be slightly
5258 more efficient to use the value of SPILL_INDIRECT_LEVELS from
5259 reload1.c here. */
5260 /* We can't use ADDR_TYPE (type) here, because we need to
5261 write back the value after reading it, hence we actually
5262 need two registers. */
5263 find_reloads_address (GET_MODE (x), &XEXP (x, 0),
5264 XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0),
5265 opnum, type, ind_levels, insn);
5267 reloadnum = push_reload (x, NULL_RTX, loc, NULL_PTR,
5268 (context ? INDEX_REG_CLASS : BASE_REG_CLASS),
5269 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5270 rld[reloadnum].inc
5271 = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
5273 link = FIND_REG_INC_NOTE (this_insn, tem);
5274 if (link != 0)
5275 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5277 return 1;
5279 return 0;
5281 case MEM:
5282 /* This is probably the result of a substitution, by eliminate_regs, of
5283 an equivalent address for a pseudo that was not allocated to a hard
5284 register. Verify that the specified address is valid and reload it
5285 into a register.
5287 Since we know we are going to reload this item, don't decrement for
5288 the indirection level.
5290 Note that this is actually conservative: it would be slightly more
5291 efficient to use the value of SPILL_INDIRECT_LEVELS from
5292 reload1.c here. */
5294 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5295 opnum, ADDR_TYPE (type), ind_levels, insn);
5296 push_reload (*loc, NULL_RTX, loc, NULL_PTR,
5297 (context ? INDEX_REG_CLASS : BASE_REG_CLASS),
5298 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5299 return 1;
5301 case REG:
5303 register int regno = REGNO (x);
5305 if (reg_equiv_constant[regno] != 0)
5307 find_reloads_address_part (reg_equiv_constant[regno], loc,
5308 (context ? INDEX_REG_CLASS : BASE_REG_CLASS),
5309 GET_MODE (x), opnum, type, ind_levels);
5310 return 1;
5313 #if 0 /* This might screw code in reload1.c to delete prior output-reload
5314 that feeds this insn. */
5315 if (reg_equiv_mem[regno] != 0)
5317 push_reload (reg_equiv_mem[regno], NULL_RTX, loc, NULL_PTR,
5318 (context ? INDEX_REG_CLASS : BASE_REG_CLASS),
5319 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5320 return 1;
5322 #endif
5324 if (reg_equiv_memory_loc[regno]
5325 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5327 rtx tem = make_memloc (x, regno);
5328 if (reg_equiv_address[regno] != 0
5329 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5331 x = tem;
5332 find_reloads_address (GET_MODE (x), &x, XEXP (x, 0),
5333 &XEXP (x, 0), opnum, ADDR_TYPE (type),
5334 ind_levels, insn);
5338 if (reg_renumber[regno] >= 0)
5339 regno = reg_renumber[regno];
5341 if ((regno >= FIRST_PSEUDO_REGISTER
5342 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
5343 : REGNO_MODE_OK_FOR_BASE_P (regno, mode))))
5345 push_reload (x, NULL_RTX, loc, NULL_PTR,
5346 (context ? INDEX_REG_CLASS : BASE_REG_CLASS),
5347 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5348 return 1;
5351 /* If a register appearing in an address is the subject of a CLOBBER
5352 in this insn, reload it into some other register to be safe.
5353 The CLOBBER is supposed to make the register unavailable
5354 from before this insn to after it. */
5355 if (regno_clobbered_p (regno, this_insn))
5357 push_reload (x, NULL_RTX, loc, NULL_PTR,
5358 (context ? INDEX_REG_CLASS : BASE_REG_CLASS),
5359 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5360 return 1;
5363 return 0;
5365 case SUBREG:
5366 if (GET_CODE (SUBREG_REG (x)) == REG)
5368 /* If this is a SUBREG of a hard register and the resulting register
5369 is of the wrong class, reload the whole SUBREG. This avoids
5370 needless copies if SUBREG_REG is multi-word. */
5371 if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5373 int regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
5375 if (! (context ? REGNO_OK_FOR_INDEX_P (regno)
5376 : REGNO_MODE_OK_FOR_BASE_P (regno, mode)))
5378 push_reload (x, NULL_RTX, loc, NULL_PTR,
5379 (context ? INDEX_REG_CLASS : BASE_REG_CLASS),
5380 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5381 return 1;
5384 /* If this is a SUBREG of a pseudo-register, and the pseudo-register
5385 is larger than the class size, then reload the whole SUBREG. */
5386 else
5388 enum reg_class class = (context ? INDEX_REG_CLASS
5389 : BASE_REG_CLASS);
5390 if (CLASS_MAX_NREGS (class, GET_MODE (SUBREG_REG (x)))
5391 > reg_class_size[class])
5393 x = find_reloads_subreg_address (x, 0, opnum, type,
5394 ind_levels, insn);
5395 push_reload (x, NULL_RTX, loc, NULL_PTR, class,
5396 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5397 return 1;
5401 break;
5403 default:
5404 break;
5408 register const char *fmt = GET_RTX_FORMAT (code);
5409 register int i;
5411 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5413 if (fmt[i] == 'e')
5414 find_reloads_address_1 (mode, XEXP (x, i), context, &XEXP (x, i),
5415 opnum, type, ind_levels, insn);
5419 return 0;
5422 /* X, which is found at *LOC, is a part of an address that needs to be
5423 reloaded into a register of class CLASS. If X is a constant, or if
5424 X is a PLUS that contains a constant, check that the constant is a
5425 legitimate operand and that we are supposed to be able to load
5426 it into the register.
5428 If not, force the constant into memory and reload the MEM instead.
5430 MODE is the mode to use, in case X is an integer constant.
5432 OPNUM and TYPE describe the purpose of any reloads made.
5434 IND_LEVELS says how many levels of indirect addressing this machine
5435 supports. */
5437 static void
5438 find_reloads_address_part (x, loc, class, mode, opnum, type, ind_levels)
5439 rtx x;
5440 rtx *loc;
5441 enum reg_class class;
5442 enum machine_mode mode;
5443 int opnum;
5444 enum reload_type type;
5445 int ind_levels;
5447 if (CONSTANT_P (x)
5448 && (! LEGITIMATE_CONSTANT_P (x)
5449 || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
5451 rtx tem;
5453 /* If this is a CONST_INT, it could have been created by a
5454 plus_constant call in eliminate_regs, which means it may be
5455 on the reload_obstack. reload_obstack will be freed later, so
5456 we can't allow such RTL to be put in the constant pool. There
5457 is code in force_const_mem to check for this case, but it doesn't
5458 work because we have already popped off the reload_obstack, so
5459 rtl_obstack == saveable_obstack is true at this point. */
5460 if (GET_CODE (x) == CONST_INT)
5461 tem = x = force_const_mem (mode, GEN_INT (INTVAL (x)));
5462 else
5463 tem = x = force_const_mem (mode, x);
5465 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5466 opnum, type, ind_levels, 0);
5469 else if (GET_CODE (x) == PLUS
5470 && CONSTANT_P (XEXP (x, 1))
5471 && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
5472 || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
5474 rtx tem;
5476 /* See comment above. */
5477 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
5478 tem = force_const_mem (GET_MODE (x), GEN_INT (INTVAL (XEXP (x, 1))));
5479 else
5480 tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
5482 x = gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), tem);
5483 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5484 opnum, type, ind_levels, 0);
5487 push_reload (x, NULL_RTX, loc, NULL_PTR, class,
5488 mode, VOIDmode, 0, 0, opnum, type);
5491 /* X, a subreg of a pseudo, is a part of an address that needs to be
5492 reloaded.
5494 If the pseudo is equivalent to a memory location that cannot be directly
5495 addressed, make the necessary address reloads.
5497 If address reloads have been necessary, or if the address is changed
5498 by register elimination, return the rtx of the memory location;
5499 otherwise, return X.
5501 If FORCE_REPLACE is nonzero, unconditionally replace the subreg with the
5502 memory location.
5504 OPNUM and TYPE identify the purpose of the reload.
5506 IND_LEVELS says how many levels of indirect addressing are
5507 supported at this point in the address.
5509 INSN, if nonzero, is the insn in which we do the reload. It is used
5510 to determine where to put USEs for pseudos that we have to replace with
5511 stack slots. */
5513 static rtx
5514 find_reloads_subreg_address (x, force_replace, opnum, type,
5515 ind_levels, insn)
5516 rtx x;
5517 int force_replace;
5518 int opnum;
5519 enum reload_type type;
5520 int ind_levels;
5521 rtx insn;
5523 int regno = REGNO (SUBREG_REG (x));
5525 if (reg_equiv_memory_loc[regno])
5527 /* If the address is not directly addressable, or if the address is not
5528 offsettable, then it must be replaced. */
5529 if (! force_replace
5530 && (reg_equiv_address[regno]
5531 || ! offsettable_memref_p (reg_equiv_mem[regno])))
5532 force_replace = 1;
5534 if (force_replace || num_not_at_initial_offset)
5536 rtx tem = make_memloc (SUBREG_REG (x), regno);
5538 /* If the address changes because of register elimination, then
5539 it must be replaced. */
5540 if (force_replace
5541 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5543 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
5545 if (BYTES_BIG_ENDIAN)
5547 int size;
5549 size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
5550 offset += MIN (size, UNITS_PER_WORD);
5551 size = GET_MODE_SIZE (GET_MODE (x));
5552 offset -= MIN (size, UNITS_PER_WORD);
5554 XEXP (tem, 0) = plus_constant (XEXP (tem, 0), offset);
5555 PUT_MODE (tem, GET_MODE (x));
5556 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5557 &XEXP (tem, 0), opnum, ADDR_TYPE (type),
5558 ind_levels, insn);
5559 /* If this is not a toplevel operand, find_reloads doesn't see
5560 this substitution. We have to emit a USE of the pseudo so
5561 that delete_output_reload can see it. */
5562 if (replace_reloads && recog_data.operand[opnum] != x)
5563 emit_insn_before (gen_rtx_USE (VOIDmode, SUBREG_REG (x)), insn);
5564 x = tem;
5568 return x;
5571 /* Substitute into the current INSN the registers into which we have reloaded
5572 the things that need reloading. The array `replacements'
5573 says contains the locations of all pointers that must be changed
5574 and says what to replace them with.
5576 Return the rtx that X translates into; usually X, but modified. */
5578 void
5579 subst_reloads ()
5581 register int i;
5583 for (i = 0; i < n_replacements; i++)
5585 register struct replacement *r = &replacements[i];
5586 register rtx reloadreg = rld[r->what].reg_rtx;
5587 if (reloadreg)
5589 /* Encapsulate RELOADREG so its machine mode matches what
5590 used to be there. Note that gen_lowpart_common will
5591 do the wrong thing if RELOADREG is multi-word. RELOADREG
5592 will always be a REG here. */
5593 if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
5594 reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg));
5596 /* If we are putting this into a SUBREG and RELOADREG is a
5597 SUBREG, we would be making nested SUBREGs, so we have to fix
5598 this up. Note that r->where == &SUBREG_REG (*r->subreg_loc). */
5600 if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG)
5602 if (GET_MODE (*r->subreg_loc)
5603 == GET_MODE (SUBREG_REG (reloadreg)))
5604 *r->subreg_loc = SUBREG_REG (reloadreg);
5605 else
5607 *r->where = SUBREG_REG (reloadreg);
5608 SUBREG_WORD (*r->subreg_loc) += SUBREG_WORD (reloadreg);
5611 else
5612 *r->where = reloadreg;
5614 /* If reload got no reg and isn't optional, something's wrong. */
5615 else if (! rld[r->what].optional)
5616 abort ();
5620 /* Make a copy of any replacements being done into X and move those copies
5621 to locations in Y, a copy of X. We only look at the highest level of
5622 the RTL. */
5624 void
5625 copy_replacements (x, y)
5626 rtx x;
5627 rtx y;
5629 int i, j;
5630 enum rtx_code code = GET_CODE (x);
5631 const char *fmt = GET_RTX_FORMAT (code);
5632 struct replacement *r;
5634 /* We can't support X being a SUBREG because we might then need to know its
5635 location if something inside it was replaced. */
5636 if (code == SUBREG)
5637 abort ();
5639 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5640 if (fmt[i] == 'e')
5641 for (j = 0; j < n_replacements; j++)
5643 if (replacements[j].subreg_loc == &XEXP (x, i))
5645 r = &replacements[n_replacements++];
5646 r->where = replacements[j].where;
5647 r->subreg_loc = &XEXP (y, i);
5648 r->what = replacements[j].what;
5649 r->mode = replacements[j].mode;
5651 else if (replacements[j].where == &XEXP (x, i))
5653 r = &replacements[n_replacements++];
5654 r->where = &XEXP (y, i);
5655 r->subreg_loc = 0;
5656 r->what = replacements[j].what;
5657 r->mode = replacements[j].mode;
5662 /* Change any replacements being done to *X to be done to *Y */
5664 void
5665 move_replacements (x, y)
5666 rtx *x;
5667 rtx *y;
5669 int i;
5671 for (i = 0; i < n_replacements; i++)
5672 if (replacements[i].subreg_loc == x)
5673 replacements[i].subreg_loc = y;
5674 else if (replacements[i].where == x)
5676 replacements[i].where = y;
5677 replacements[i].subreg_loc = 0;
5681 /* If LOC was scheduled to be replaced by something, return the replacement.
5682 Otherwise, return *LOC. */
5685 find_replacement (loc)
5686 rtx *loc;
5688 struct replacement *r;
5690 for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
5692 rtx reloadreg = rld[r->what].reg_rtx;
5694 if (reloadreg && r->where == loc)
5696 if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
5697 reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg));
5699 return reloadreg;
5701 else if (reloadreg && r->subreg_loc == loc)
5703 /* RELOADREG must be either a REG or a SUBREG.
5705 ??? Is it actually still ever a SUBREG? If so, why? */
5707 if (GET_CODE (reloadreg) == REG)
5708 return gen_rtx_REG (GET_MODE (*loc),
5709 REGNO (reloadreg) + SUBREG_WORD (*loc));
5710 else if (GET_MODE (reloadreg) == GET_MODE (*loc))
5711 return reloadreg;
5712 else
5713 return gen_rtx_SUBREG (GET_MODE (*loc), SUBREG_REG (reloadreg),
5714 SUBREG_WORD (reloadreg) + SUBREG_WORD (*loc));
5718 /* If *LOC is a PLUS, MINUS, or MULT, see if a replacement is scheduled for
5719 what's inside and make a new rtl if so. */
5720 if (GET_CODE (*loc) == PLUS || GET_CODE (*loc) == MINUS
5721 || GET_CODE (*loc) == MULT)
5723 rtx x = find_replacement (&XEXP (*loc, 0));
5724 rtx y = find_replacement (&XEXP (*loc, 1));
5726 if (x != XEXP (*loc, 0) || y != XEXP (*loc, 1))
5727 return gen_rtx_fmt_ee (GET_CODE (*loc), GET_MODE (*loc), x, y);
5730 return *loc;
5733 /* Return nonzero if register in range [REGNO, ENDREGNO)
5734 appears either explicitly or implicitly in X
5735 other than being stored into (except for earlyclobber operands).
5737 References contained within the substructure at LOC do not count.
5738 LOC may be zero, meaning don't ignore anything.
5740 This is similar to refers_to_regno_p in rtlanal.c except that we
5741 look at equivalences for pseudos that didn't get hard registers. */
5744 refers_to_regno_for_reload_p (regno, endregno, x, loc)
5745 int regno, endregno;
5746 rtx x;
5747 rtx *loc;
5749 register int i;
5750 register RTX_CODE code;
5751 register const char *fmt;
5753 if (x == 0)
5754 return 0;
5756 repeat:
5757 code = GET_CODE (x);
5759 switch (code)
5761 case REG:
5762 i = REGNO (x);
5764 /* If this is a pseudo, a hard register must not have been allocated.
5765 X must therefore either be a constant or be in memory. */
5766 if (i >= FIRST_PSEUDO_REGISTER)
5768 if (reg_equiv_memory_loc[i])
5769 return refers_to_regno_for_reload_p (regno, endregno,
5770 reg_equiv_memory_loc[i],
5771 NULL_PTR);
5773 if (reg_equiv_constant[i])
5774 return 0;
5776 abort ();
5779 return (endregno > i
5780 && regno < i + (i < FIRST_PSEUDO_REGISTER
5781 ? HARD_REGNO_NREGS (i, GET_MODE (x))
5782 : 1));
5784 case SUBREG:
5785 /* If this is a SUBREG of a hard reg, we can see exactly which
5786 registers are being modified. Otherwise, handle normally. */
5787 if (GET_CODE (SUBREG_REG (x)) == REG
5788 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5790 int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
5791 int inner_endregno
5792 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
5793 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
5795 return endregno > inner_regno && regno < inner_endregno;
5797 break;
5799 case CLOBBER:
5800 case SET:
5801 if (&SET_DEST (x) != loc
5802 /* Note setting a SUBREG counts as referring to the REG it is in for
5803 a pseudo but not for hard registers since we can
5804 treat each word individually. */
5805 && ((GET_CODE (SET_DEST (x)) == SUBREG
5806 && loc != &SUBREG_REG (SET_DEST (x))
5807 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
5808 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
5809 && refers_to_regno_for_reload_p (regno, endregno,
5810 SUBREG_REG (SET_DEST (x)),
5811 loc))
5812 /* If the output is an earlyclobber operand, this is
5813 a conflict. */
5814 || ((GET_CODE (SET_DEST (x)) != REG
5815 || earlyclobber_operand_p (SET_DEST (x)))
5816 && refers_to_regno_for_reload_p (regno, endregno,
5817 SET_DEST (x), loc))))
5818 return 1;
5820 if (code == CLOBBER || loc == &SET_SRC (x))
5821 return 0;
5822 x = SET_SRC (x);
5823 goto repeat;
5825 default:
5826 break;
5829 /* X does not match, so try its subexpressions. */
5831 fmt = GET_RTX_FORMAT (code);
5832 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5834 if (fmt[i] == 'e' && loc != &XEXP (x, i))
5836 if (i == 0)
5838 x = XEXP (x, 0);
5839 goto repeat;
5841 else
5842 if (refers_to_regno_for_reload_p (regno, endregno,
5843 XEXP (x, i), loc))
5844 return 1;
5846 else if (fmt[i] == 'E')
5848 register int j;
5849 for (j = XVECLEN (x, i) - 1; j >=0; j--)
5850 if (loc != &XVECEXP (x, i, j)
5851 && refers_to_regno_for_reload_p (regno, endregno,
5852 XVECEXP (x, i, j), loc))
5853 return 1;
5856 return 0;
5859 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
5860 we check if any register number in X conflicts with the relevant register
5861 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
5862 contains a MEM (we don't bother checking for memory addresses that can't
5863 conflict because we expect this to be a rare case.
5865 This function is similar to reg_overlap_mention_p in rtlanal.c except
5866 that we look at equivalences for pseudos that didn't get hard registers. */
5869 reg_overlap_mentioned_for_reload_p (x, in)
5870 rtx x, in;
5872 int regno, endregno;
5874 /* Overly conservative. */
5875 if (GET_CODE (x) == STRICT_LOW_PART)
5876 x = XEXP (x, 0);
5878 /* If either argument is a constant, then modifying X can not affect IN. */
5879 if (CONSTANT_P (x) || CONSTANT_P (in))
5880 return 0;
5881 else if (GET_CODE (x) == SUBREG)
5883 regno = REGNO (SUBREG_REG (x));
5884 if (regno < FIRST_PSEUDO_REGISTER)
5885 regno += SUBREG_WORD (x);
5887 else if (GET_CODE (x) == REG)
5889 regno = REGNO (x);
5891 /* If this is a pseudo, it must not have been assigned a hard register.
5892 Therefore, it must either be in memory or be a constant. */
5894 if (regno >= FIRST_PSEUDO_REGISTER)
5896 if (reg_equiv_memory_loc[regno])
5897 return refers_to_mem_for_reload_p (in);
5898 else if (reg_equiv_constant[regno])
5899 return 0;
5900 abort ();
5903 else if (GET_CODE (x) == MEM)
5904 return refers_to_mem_for_reload_p (in);
5905 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
5906 || GET_CODE (x) == CC0)
5907 return reg_mentioned_p (x, in);
5908 else
5909 abort ();
5911 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
5912 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
5914 return refers_to_regno_for_reload_p (regno, endregno, in, NULL_PTR);
5917 /* Return nonzero if anything in X contains a MEM. Look also for pseudo
5918 registers. */
5921 refers_to_mem_for_reload_p (x)
5922 rtx x;
5924 const char *fmt;
5925 int i;
5927 if (GET_CODE (x) == MEM)
5928 return 1;
5930 if (GET_CODE (x) == REG)
5931 return (REGNO (x) >= FIRST_PSEUDO_REGISTER
5932 && reg_equiv_memory_loc[REGNO (x)]);
5934 fmt = GET_RTX_FORMAT (GET_CODE (x));
5935 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
5936 if (fmt[i] == 'e'
5937 && (GET_CODE (XEXP (x, i)) == MEM
5938 || refers_to_mem_for_reload_p (XEXP (x, i))))
5939 return 1;
5941 return 0;
5944 /* Check the insns before INSN to see if there is a suitable register
5945 containing the same value as GOAL.
5946 If OTHER is -1, look for a register in class CLASS.
5947 Otherwise, just see if register number OTHER shares GOAL's value.
5949 Return an rtx for the register found, or zero if none is found.
5951 If RELOAD_REG_P is (short *)1,
5952 we reject any hard reg that appears in reload_reg_rtx
5953 because such a hard reg is also needed coming into this insn.
5955 If RELOAD_REG_P is any other nonzero value,
5956 it is a vector indexed by hard reg number
5957 and we reject any hard reg whose element in the vector is nonnegative
5958 as well as any that appears in reload_reg_rtx.
5960 If GOAL is zero, then GOALREG is a register number; we look
5961 for an equivalent for that register.
5963 MODE is the machine mode of the value we want an equivalence for.
5964 If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
5966 This function is used by jump.c as well as in the reload pass.
5968 If GOAL is the sum of the stack pointer and a constant, we treat it
5969 as if it were a constant except that sp is required to be unchanging. */
5972 find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode)
5973 register rtx goal;
5974 rtx insn;
5975 enum reg_class class;
5976 register int other;
5977 short *reload_reg_p;
5978 int goalreg;
5979 enum machine_mode mode;
5981 register rtx p = insn;
5982 rtx goaltry, valtry, value, where;
5983 register rtx pat;
5984 register int regno = -1;
5985 int valueno;
5986 int goal_mem = 0;
5987 int goal_const = 0;
5988 int goal_mem_addr_varies = 0;
5989 int need_stable_sp = 0;
5990 int nregs;
5991 int valuenregs;
5993 if (goal == 0)
5994 regno = goalreg;
5995 else if (GET_CODE (goal) == REG)
5996 regno = REGNO (goal);
5997 else if (GET_CODE (goal) == MEM)
5999 enum rtx_code code = GET_CODE (XEXP (goal, 0));
6000 if (MEM_VOLATILE_P (goal))
6001 return 0;
6002 if (flag_float_store && GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT)
6003 return 0;
6004 /* An address with side effects must be reexecuted. */
6005 switch (code)
6007 case POST_INC:
6008 case PRE_INC:
6009 case POST_DEC:
6010 case PRE_DEC:
6011 return 0;
6012 default:
6013 break;
6015 goal_mem = 1;
6017 else if (CONSTANT_P (goal))
6018 goal_const = 1;
6019 else if (GET_CODE (goal) == PLUS
6020 && XEXP (goal, 0) == stack_pointer_rtx
6021 && CONSTANT_P (XEXP (goal, 1)))
6022 goal_const = need_stable_sp = 1;
6023 else if (GET_CODE (goal) == PLUS
6024 && XEXP (goal, 0) == frame_pointer_rtx
6025 && CONSTANT_P (XEXP (goal, 1)))
6026 goal_const = 1;
6027 else
6028 return 0;
6030 /* On some machines, certain regs must always be rejected
6031 because they don't behave the way ordinary registers do. */
6033 #ifdef OVERLAPPING_REGNO_P
6034 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
6035 && OVERLAPPING_REGNO_P (regno))
6036 return 0;
6037 #endif
6039 /* Scan insns back from INSN, looking for one that copies
6040 a value into or out of GOAL.
6041 Stop and give up if we reach a label. */
6043 while (1)
6045 p = PREV_INSN (p);
6046 if (p == 0 || GET_CODE (p) == CODE_LABEL)
6047 return 0;
6048 if (GET_CODE (p) == INSN
6049 /* If we don't want spill regs ... */
6050 && (! (reload_reg_p != 0
6051 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6052 /* ... then ignore insns introduced by reload; they aren't useful
6053 and can cause results in reload_as_needed to be different
6054 from what they were when calculating the need for spills.
6055 If we notice an input-reload insn here, we will reject it below,
6056 but it might hide a usable equivalent. That makes bad code.
6057 It may even abort: perhaps no reg was spilled for this insn
6058 because it was assumed we would find that equivalent. */
6059 || INSN_UID (p) < reload_first_uid))
6061 rtx tem;
6062 pat = single_set (p);
6063 /* First check for something that sets some reg equal to GOAL. */
6064 if (pat != 0
6065 && ((regno >= 0
6066 && true_regnum (SET_SRC (pat)) == regno
6067 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6069 (regno >= 0
6070 && true_regnum (SET_DEST (pat)) == regno
6071 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
6073 (goal_const && rtx_equal_p (SET_SRC (pat), goal)
6074 /* When looking for stack pointer + const,
6075 make sure we don't use a stack adjust. */
6076 && !reg_overlap_mentioned_for_reload_p (SET_DEST (pat), goal)
6077 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6078 || (goal_mem
6079 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
6080 && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
6081 || (goal_mem
6082 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
6083 && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
6084 /* If we are looking for a constant,
6085 and something equivalent to that constant was copied
6086 into a reg, we can use that reg. */
6087 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
6088 NULL_RTX))
6089 && rtx_equal_p (XEXP (tem, 0), goal)
6090 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6091 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
6092 NULL_RTX))
6093 && GET_CODE (SET_DEST (pat)) == REG
6094 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6095 && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
6096 && GET_CODE (goal) == CONST_INT
6097 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 0, 0,
6098 VOIDmode))
6099 && rtx_equal_p (goal, goaltry)
6100 && (valtry = operand_subword (SET_DEST (pat), 0, 0,
6101 VOIDmode))
6102 && (valueno = true_regnum (valtry)) >= 0)
6103 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
6104 NULL_RTX))
6105 && GET_CODE (SET_DEST (pat)) == REG
6106 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6107 && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
6108 && GET_CODE (goal) == CONST_INT
6109 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0,
6110 VOIDmode))
6111 && rtx_equal_p (goal, goaltry)
6112 && (valtry
6113 = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
6114 && (valueno = true_regnum (valtry)) >= 0)))
6115 if (other >= 0
6116 ? valueno == other
6117 : ((unsigned) valueno < FIRST_PSEUDO_REGISTER
6118 && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
6119 valueno)))
6121 value = valtry;
6122 where = p;
6123 break;
6128 /* We found a previous insn copying GOAL into a suitable other reg VALUE
6129 (or copying VALUE into GOAL, if GOAL is also a register).
6130 Now verify that VALUE is really valid. */
6132 /* VALUENO is the register number of VALUE; a hard register. */
6134 /* Don't try to re-use something that is killed in this insn. We want
6135 to be able to trust REG_UNUSED notes. */
6136 if (find_reg_note (where, REG_UNUSED, value))
6137 return 0;
6139 /* If we propose to get the value from the stack pointer or if GOAL is
6140 a MEM based on the stack pointer, we need a stable SP. */
6141 if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM
6142 || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
6143 goal)))
6144 need_stable_sp = 1;
6146 /* Reject VALUE if the copy-insn moved the wrong sort of datum. */
6147 if (GET_MODE (value) != mode)
6148 return 0;
6150 /* Reject VALUE if it was loaded from GOAL
6151 and is also a register that appears in the address of GOAL. */
6153 if (goal_mem && value == SET_DEST (single_set (where))
6154 && refers_to_regno_for_reload_p (valueno,
6155 (valueno
6156 + HARD_REGNO_NREGS (valueno, mode)),
6157 goal, NULL_PTR))
6158 return 0;
6160 /* Reject registers that overlap GOAL. */
6162 if (!goal_mem && !goal_const
6163 && regno + HARD_REGNO_NREGS (regno, mode) > valueno
6164 && regno < valueno + HARD_REGNO_NREGS (valueno, mode))
6165 return 0;
6167 /* Reject VALUE if it is one of the regs reserved for reloads.
6168 Reload1 knows how to reuse them anyway, and it would get
6169 confused if we allocated one without its knowledge.
6170 (Now that insns introduced by reload are ignored above,
6171 this case shouldn't happen, but I'm not positive.) */
6173 if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1
6174 && reload_reg_p[valueno] >= 0)
6175 return 0;
6177 /* On some machines, certain regs must always be rejected
6178 because they don't behave the way ordinary registers do. */
6180 #ifdef OVERLAPPING_REGNO_P
6181 if (OVERLAPPING_REGNO_P (valueno))
6182 return 0;
6183 #endif
6185 nregs = HARD_REGNO_NREGS (regno, mode);
6186 valuenregs = HARD_REGNO_NREGS (valueno, mode);
6188 /* Reject VALUE if it is a register being used for an input reload
6189 even if it is not one of those reserved. */
6191 if (reload_reg_p != 0)
6193 int i;
6194 for (i = 0; i < n_reloads; i++)
6195 if (rld[i].reg_rtx != 0 && rld[i].in)
6197 int regno1 = REGNO (rld[i].reg_rtx);
6198 int nregs1 = HARD_REGNO_NREGS (regno1,
6199 GET_MODE (rld[i].reg_rtx));
6200 if (regno1 < valueno + valuenregs
6201 && regno1 + nregs1 > valueno)
6202 return 0;
6206 if (goal_mem)
6207 /* We must treat frame pointer as varying here,
6208 since it can vary--in a nonlocal goto as generated by expand_goto. */
6209 goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0));
6211 /* Now verify that the values of GOAL and VALUE remain unaltered
6212 until INSN is reached. */
6214 p = insn;
6215 while (1)
6217 p = PREV_INSN (p);
6218 if (p == where)
6219 return value;
6221 /* Don't trust the conversion past a function call
6222 if either of the two is in a call-clobbered register, or memory. */
6223 if (GET_CODE (p) == CALL_INSN
6224 && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER
6225 && call_used_regs[regno])
6227 (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
6228 && call_used_regs[valueno])
6230 goal_mem
6231 || need_stable_sp))
6232 return 0;
6234 #ifdef NON_SAVING_SETJMP
6235 if (NON_SAVING_SETJMP && GET_CODE (p) == NOTE
6236 && NOTE_LINE_NUMBER (p) == NOTE_INSN_SETJMP)
6237 return 0;
6238 #endif
6240 #ifdef INSN_CLOBBERS_REGNO_P
6241 if ((valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
6242 && INSN_CLOBBERS_REGNO_P (p, valueno))
6243 || (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
6244 && INSN_CLOBBERS_REGNO_P (p, regno)))
6245 return 0;
6246 #endif
6248 if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
6250 pat = PATTERN (p);
6252 /* Watch out for unspec_volatile, and volatile asms. */
6253 if (volatile_insn_p (pat))
6254 return 0;
6256 /* If this insn P stores in either GOAL or VALUE, return 0.
6257 If GOAL is a memory ref and this insn writes memory, return 0.
6258 If GOAL is a memory ref and its address is not constant,
6259 and this insn P changes a register used in GOAL, return 0. */
6261 if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
6263 register rtx dest = SET_DEST (pat);
6264 while (GET_CODE (dest) == SUBREG
6265 || GET_CODE (dest) == ZERO_EXTRACT
6266 || GET_CODE (dest) == SIGN_EXTRACT
6267 || GET_CODE (dest) == STRICT_LOW_PART)
6268 dest = XEXP (dest, 0);
6269 if (GET_CODE (dest) == REG)
6271 register int xregno = REGNO (dest);
6272 int xnregs;
6273 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6274 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
6275 else
6276 xnregs = 1;
6277 if (xregno < regno + nregs && xregno + xnregs > regno)
6278 return 0;
6279 if (xregno < valueno + valuenregs
6280 && xregno + xnregs > valueno)
6281 return 0;
6282 if (goal_mem_addr_varies
6283 && reg_overlap_mentioned_for_reload_p (dest, goal))
6284 return 0;
6285 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6286 return 0;
6288 else if (goal_mem && GET_CODE (dest) == MEM
6289 && ! push_operand (dest, GET_MODE (dest)))
6290 return 0;
6291 else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER
6292 && reg_equiv_memory_loc[regno] != 0)
6293 return 0;
6294 else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
6295 return 0;
6297 else if (GET_CODE (pat) == PARALLEL)
6299 register int i;
6300 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
6302 register rtx v1 = XVECEXP (pat, 0, i);
6303 if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
6305 register rtx dest = SET_DEST (v1);
6306 while (GET_CODE (dest) == SUBREG
6307 || GET_CODE (dest) == ZERO_EXTRACT
6308 || GET_CODE (dest) == SIGN_EXTRACT
6309 || GET_CODE (dest) == STRICT_LOW_PART)
6310 dest = XEXP (dest, 0);
6311 if (GET_CODE (dest) == REG)
6313 register int xregno = REGNO (dest);
6314 int xnregs;
6315 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6316 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
6317 else
6318 xnregs = 1;
6319 if (xregno < regno + nregs
6320 && xregno + xnregs > regno)
6321 return 0;
6322 if (xregno < valueno + valuenregs
6323 && xregno + xnregs > valueno)
6324 return 0;
6325 if (goal_mem_addr_varies
6326 && reg_overlap_mentioned_for_reload_p (dest,
6327 goal))
6328 return 0;
6329 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6330 return 0;
6332 else if (goal_mem && GET_CODE (dest) == MEM
6333 && ! push_operand (dest, GET_MODE (dest)))
6334 return 0;
6335 else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER
6336 && reg_equiv_memory_loc[regno] != 0)
6337 return 0;
6338 else if (need_stable_sp
6339 && push_operand (dest, GET_MODE (dest)))
6340 return 0;
6345 if (GET_CODE (p) == CALL_INSN && CALL_INSN_FUNCTION_USAGE (p))
6347 rtx link;
6349 for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0;
6350 link = XEXP (link, 1))
6352 pat = XEXP (link, 0);
6353 if (GET_CODE (pat) == CLOBBER)
6355 register rtx dest = SET_DEST (pat);
6356 while (GET_CODE (dest) == SUBREG
6357 || GET_CODE (dest) == ZERO_EXTRACT
6358 || GET_CODE (dest) == SIGN_EXTRACT
6359 || GET_CODE (dest) == STRICT_LOW_PART)
6360 dest = XEXP (dest, 0);
6361 if (GET_CODE (dest) == REG)
6363 register int xregno = REGNO (dest);
6364 int xnregs;
6365 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6366 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
6367 else
6368 xnregs = 1;
6369 if (xregno < regno + nregs
6370 && xregno + xnregs > regno)
6371 return 0;
6372 if (xregno < valueno + valuenregs
6373 && xregno + xnregs > valueno)
6374 return 0;
6375 if (goal_mem_addr_varies
6376 && reg_overlap_mentioned_for_reload_p (dest,
6377 goal))
6378 return 0;
6380 else if (goal_mem && GET_CODE (dest) == MEM
6381 && ! push_operand (dest, GET_MODE (dest)))
6382 return 0;
6383 else if (need_stable_sp
6384 && push_operand (dest, GET_MODE (dest)))
6385 return 0;
6390 #ifdef AUTO_INC_DEC
6391 /* If this insn auto-increments or auto-decrements
6392 either regno or valueno, return 0 now.
6393 If GOAL is a memory ref and its address is not constant,
6394 and this insn P increments a register used in GOAL, return 0. */
6396 register rtx link;
6398 for (link = REG_NOTES (p); link; link = XEXP (link, 1))
6399 if (REG_NOTE_KIND (link) == REG_INC
6400 && GET_CODE (XEXP (link, 0)) == REG)
6402 register int incno = REGNO (XEXP (link, 0));
6403 if (incno < regno + nregs && incno >= regno)
6404 return 0;
6405 if (incno < valueno + valuenregs && incno >= valueno)
6406 return 0;
6407 if (goal_mem_addr_varies
6408 && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
6409 goal))
6410 return 0;
6413 #endif
6418 /* Find a place where INCED appears in an increment or decrement operator
6419 within X, and return the amount INCED is incremented or decremented by.
6420 The value is always positive. */
6422 static int
6423 find_inc_amount (x, inced)
6424 rtx x, inced;
6426 register enum rtx_code code = GET_CODE (x);
6427 register const char *fmt;
6428 register int i;
6430 if (code == MEM)
6432 register rtx addr = XEXP (x, 0);
6433 if ((GET_CODE (addr) == PRE_DEC
6434 || GET_CODE (addr) == POST_DEC
6435 || GET_CODE (addr) == PRE_INC
6436 || GET_CODE (addr) == POST_INC)
6437 && XEXP (addr, 0) == inced)
6438 return GET_MODE_SIZE (GET_MODE (x));
6441 fmt = GET_RTX_FORMAT (code);
6442 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6444 if (fmt[i] == 'e')
6446 register int tem = find_inc_amount (XEXP (x, i), inced);
6447 if (tem != 0)
6448 return tem;
6450 if (fmt[i] == 'E')
6452 register int j;
6453 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6455 register int tem = find_inc_amount (XVECEXP (x, i, j), inced);
6456 if (tem != 0)
6457 return tem;
6462 return 0;
6465 /* Return 1 if register REGNO is the subject of a clobber in insn INSN. */
6468 regno_clobbered_p (regno, insn)
6469 int regno;
6470 rtx insn;
6472 if (GET_CODE (PATTERN (insn)) == CLOBBER
6473 && GET_CODE (XEXP (PATTERN (insn), 0)) == REG)
6474 return REGNO (XEXP (PATTERN (insn), 0)) == regno;
6476 if (GET_CODE (PATTERN (insn)) == PARALLEL)
6478 int i = XVECLEN (PATTERN (insn), 0) - 1;
6480 for (; i >= 0; i--)
6482 rtx elt = XVECEXP (PATTERN (insn), 0, i);
6483 if (GET_CODE (elt) == CLOBBER && GET_CODE (XEXP (elt, 0)) == REG
6484 && REGNO (XEXP (elt, 0)) == regno)
6485 return 1;
6489 return 0;
6492 static const char *reload_when_needed_name[] =
6494 "RELOAD_FOR_INPUT",
6495 "RELOAD_FOR_OUTPUT",
6496 "RELOAD_FOR_INSN",
6497 "RELOAD_FOR_INPUT_ADDRESS",
6498 "RELOAD_FOR_INPADDR_ADDRESS",
6499 "RELOAD_FOR_OUTPUT_ADDRESS",
6500 "RELOAD_FOR_OUTADDR_ADDRESS",
6501 "RELOAD_FOR_OPERAND_ADDRESS",
6502 "RELOAD_FOR_OPADDR_ADDR",
6503 "RELOAD_OTHER",
6504 "RELOAD_FOR_OTHER_ADDRESS"
6507 static const char * const reg_class_names[] = REG_CLASS_NAMES;
6509 /* These functions are used to print the variables set by 'find_reloads' */
6511 void
6512 debug_reload_to_stream (f)
6513 FILE *f;
6515 int r;
6516 const char *prefix;
6518 if (! f)
6519 f = stderr;
6520 for (r = 0; r < n_reloads; r++)
6522 fprintf (f, "Reload %d: ", r);
6524 if (rld[r].in != 0)
6526 fprintf (f, "reload_in (%s) = ",
6527 GET_MODE_NAME (rld[r].inmode));
6528 print_inline_rtx (f, rld[r].in, 24);
6529 fprintf (f, "\n\t");
6532 if (rld[r].out != 0)
6534 fprintf (f, "reload_out (%s) = ",
6535 GET_MODE_NAME (rld[r].outmode));
6536 print_inline_rtx (f, rld[r].out, 24);
6537 fprintf (f, "\n\t");
6540 fprintf (f, "%s, ", reg_class_names[(int) rld[r].class]);
6542 fprintf (f, "%s (opnum = %d)",
6543 reload_when_needed_name[(int) rld[r].when_needed],
6544 rld[r].opnum);
6546 if (rld[r].optional)
6547 fprintf (f, ", optional");
6549 if (rld[r].nongroup)
6550 fprintf (stderr, ", nongroup");
6552 if (rld[r].inc != 0)
6553 fprintf (f, ", inc by %d", rld[r].inc);
6555 if (rld[r].nocombine)
6556 fprintf (f, ", can't combine");
6558 if (rld[r].secondary_p)
6559 fprintf (f, ", secondary_reload_p");
6561 if (rld[r].in_reg != 0)
6563 fprintf (f, "\n\treload_in_reg: ");
6564 print_inline_rtx (f, rld[r].in_reg, 24);
6567 if (rld[r].out_reg != 0)
6569 fprintf (f, "\n\treload_out_reg: ");
6570 print_inline_rtx (f, rld[r].out_reg, 24);
6573 if (rld[r].reg_rtx != 0)
6575 fprintf (f, "\n\treload_reg_rtx: ");
6576 print_inline_rtx (f, rld[r].reg_rtx, 24);
6579 prefix = "\n\t";
6580 if (rld[r].secondary_in_reload != -1)
6582 fprintf (f, "%ssecondary_in_reload = %d",
6583 prefix, rld[r].secondary_in_reload);
6584 prefix = ", ";
6587 if (rld[r].secondary_out_reload != -1)
6588 fprintf (f, "%ssecondary_out_reload = %d\n",
6589 prefix, rld[r].secondary_out_reload);
6591 prefix = "\n\t";
6592 if (rld[r].secondary_in_icode != CODE_FOR_nothing)
6594 fprintf (stderr, "%ssecondary_in_icode = %s", prefix,
6595 insn_data[rld[r].secondary_in_icode].name);
6596 prefix = ", ";
6599 if (rld[r].secondary_out_icode != CODE_FOR_nothing)
6600 fprintf (stderr, "%ssecondary_out_icode = %s", prefix,
6601 insn_data[rld[r].secondary_out_icode].name);
6603 fprintf (f, "\n");
6607 void
6608 debug_reload ()
6610 debug_reload_to_stream (stderr);