* config/rs6000/rs6000.c (rs6000_mangle_fundamental_type): Mangle
[official-gcc.git] / gcc / reload.c
blobceb12ba888bd95c07f97ff23ed240f83de37c662
1 /* Search an insn for pseudo regs that must be in hard regs and are not.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
4 Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 /* This file contains subroutines used only from the file reload1.c.
24 It knows how to scan one insn for operands and values
25 that need to be copied into registers to make valid code.
26 It also finds other operands and values which are valid
27 but for which equivalent values in registers exist and
28 ought to be used instead.
30 Before processing the first insn of the function, call `init_reload'.
31 init_reload actually has to be called earlier anyway.
33 To scan an insn, call `find_reloads'. This does two things:
34 1. sets up tables describing which values must be reloaded
35 for this insn, and what kind of hard regs they must be reloaded into;
36 2. optionally record the locations where those values appear in
37 the data, so they can be replaced properly later.
38 This is done only if the second arg to `find_reloads' is nonzero.
40 The third arg to `find_reloads' specifies the number of levels
41 of indirect addressing supported by the machine. If it is zero,
42 indirect addressing is not valid. If it is one, (MEM (REG n))
43 is valid even if (REG n) did not get a hard register; if it is two,
44 (MEM (MEM (REG n))) is also valid even if (REG n) did not get a
45 hard register, and similarly for higher values.
47 Then you must choose the hard regs to reload those pseudo regs into,
48 and generate appropriate load insns before this insn and perhaps
49 also store insns after this insn. Set up the array `reload_reg_rtx'
50 to contain the REG rtx's for the registers you used. In some
51 cases `find_reloads' will return a nonzero value in `reload_reg_rtx'
52 for certain reloads. Then that tells you which register to use,
53 so you do not need to allocate one. But you still do need to add extra
54 instructions to copy the value into and out of that register.
56 Finally you must call `subst_reloads' to substitute the reload reg rtx's
57 into the locations already recorded.
59 NOTE SIDE EFFECTS:
61 find_reloads can alter the operands of the instruction it is called on.
63 1. Two operands of any sort may be interchanged, if they are in a
64 commutative instruction.
65 This happens only if find_reloads thinks the instruction will compile
66 better that way.
68 2. Pseudo-registers that are equivalent to constants are replaced
69 with those constants if they are not in hard registers.
71 1 happens every time find_reloads is called.
72 2 happens only when REPLACE is 1, which is only when
73 actually doing the reloads, not when just counting them.
75 Using a reload register for several reloads in one insn:
77 When an insn has reloads, it is considered as having three parts:
78 the input reloads, the insn itself after reloading, and the output reloads.
79 Reloads of values used in memory addresses are often needed for only one part.
81 When this is so, reload_when_needed records which part needs the reload.
82 Two reloads for different parts of the insn can share the same reload
83 register.
85 When a reload is used for addresses in multiple parts, or when it is
86 an ordinary operand, it is classified as RELOAD_OTHER, and cannot share
87 a register with any other reload. */
89 #define REG_OK_STRICT
91 #include "config.h"
92 #include "system.h"
93 #include "coretypes.h"
94 #include "tm.h"
95 #include "rtl.h"
96 #include "tm_p.h"
97 #include "insn-config.h"
98 #include "expr.h"
99 #include "optabs.h"
100 #include "recog.h"
101 #include "reload.h"
102 #include "regs.h"
103 #include "hard-reg-set.h"
104 #include "flags.h"
105 #include "real.h"
106 #include "output.h"
107 #include "function.h"
108 #include "toplev.h"
109 #include "params.h"
110 #include "target.h"
112 /* True if X is a constant that can be forced into the constant pool. */
113 #define CONST_POOL_OK_P(X) \
114 (CONSTANT_P (X) \
115 && GET_CODE (X) != HIGH \
116 && !targetm.cannot_force_const_mem (X))
118 /* True if C is a non-empty register class that has too few registers
119 to be safely used as a reload target class. */
120 #define SMALL_REGISTER_CLASS_P(C) \
121 (reg_class_size [(C)] == 1 \
122 || (reg_class_size [(C)] >= 1 && CLASS_LIKELY_SPILLED_P (C)))
125 /* All reloads of the current insn are recorded here. See reload.h for
126 comments. */
127 int n_reloads;
128 struct reload rld[MAX_RELOADS];
130 /* All the "earlyclobber" operands of the current insn
131 are recorded here. */
132 int n_earlyclobbers;
133 rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
135 int reload_n_operands;
137 /* Replacing reloads.
139 If `replace_reloads' is nonzero, then as each reload is recorded
140 an entry is made for it in the table `replacements'.
141 Then later `subst_reloads' can look through that table and
142 perform all the replacements needed. */
144 /* Nonzero means record the places to replace. */
145 static int replace_reloads;
147 /* Each replacement is recorded with a structure like this. */
148 struct replacement
150 rtx *where; /* Location to store in */
151 rtx *subreg_loc; /* Location of SUBREG if WHERE is inside
152 a SUBREG; 0 otherwise. */
153 int what; /* which reload this is for */
154 enum machine_mode mode; /* mode it must have */
157 static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
159 /* Number of replacements currently recorded. */
160 static int n_replacements;
162 /* Used to track what is modified by an operand. */
163 struct decomposition
165 int reg_flag; /* Nonzero if referencing a register. */
166 int safe; /* Nonzero if this can't conflict with anything. */
167 rtx base; /* Base address for MEM. */
168 HOST_WIDE_INT start; /* Starting offset or register number. */
169 HOST_WIDE_INT end; /* Ending offset or register number. */
172 #ifdef SECONDARY_MEMORY_NEEDED
174 /* Save MEMs needed to copy from one class of registers to another. One MEM
175 is used per mode, but normally only one or two modes are ever used.
177 We keep two versions, before and after register elimination. The one
178 after register elimination is record separately for each operand. This
179 is done in case the address is not valid to be sure that we separately
180 reload each. */
182 static rtx secondary_memlocs[NUM_MACHINE_MODES];
183 static rtx secondary_memlocs_elim[NUM_MACHINE_MODES][MAX_RECOG_OPERANDS];
184 static int secondary_memlocs_elim_used = 0;
185 #endif
187 /* The instruction we are doing reloads for;
188 so we can test whether a register dies in it. */
189 static rtx this_insn;
191 /* Nonzero if this instruction is a user-specified asm with operands. */
192 static int this_insn_is_asm;
194 /* If hard_regs_live_known is nonzero,
195 we can tell which hard regs are currently live,
196 at least enough to succeed in choosing dummy reloads. */
197 static int hard_regs_live_known;
199 /* Indexed by hard reg number,
200 element is nonnegative if hard reg has been spilled.
201 This vector is passed to `find_reloads' as an argument
202 and is not changed here. */
203 static short *static_reload_reg_p;
205 /* Set to 1 in subst_reg_equivs if it changes anything. */
206 static int subst_reg_equivs_changed;
208 /* On return from push_reload, holds the reload-number for the OUT
209 operand, which can be different for that from the input operand. */
210 static int output_reloadnum;
212 /* Compare two RTX's. */
213 #define MATCHES(x, y) \
214 (x == y || (x != 0 && (REG_P (x) \
215 ? REG_P (y) && REGNO (x) == REGNO (y) \
216 : rtx_equal_p (x, y) && ! side_effects_p (x))))
218 /* Indicates if two reloads purposes are for similar enough things that we
219 can merge their reloads. */
220 #define MERGABLE_RELOADS(when1, when2, op1, op2) \
221 ((when1) == RELOAD_OTHER || (when2) == RELOAD_OTHER \
222 || ((when1) == (when2) && (op1) == (op2)) \
223 || ((when1) == RELOAD_FOR_INPUT && (when2) == RELOAD_FOR_INPUT) \
224 || ((when1) == RELOAD_FOR_OPERAND_ADDRESS \
225 && (when2) == RELOAD_FOR_OPERAND_ADDRESS) \
226 || ((when1) == RELOAD_FOR_OTHER_ADDRESS \
227 && (when2) == RELOAD_FOR_OTHER_ADDRESS))
229 /* Nonzero if these two reload purposes produce RELOAD_OTHER when merged. */
230 #define MERGE_TO_OTHER(when1, when2, op1, op2) \
231 ((when1) != (when2) \
232 || ! ((op1) == (op2) \
233 || (when1) == RELOAD_FOR_INPUT \
234 || (when1) == RELOAD_FOR_OPERAND_ADDRESS \
235 || (when1) == RELOAD_FOR_OTHER_ADDRESS))
237 /* If we are going to reload an address, compute the reload type to
238 use. */
239 #define ADDR_TYPE(type) \
240 ((type) == RELOAD_FOR_INPUT_ADDRESS \
241 ? RELOAD_FOR_INPADDR_ADDRESS \
242 : ((type) == RELOAD_FOR_OUTPUT_ADDRESS \
243 ? RELOAD_FOR_OUTADDR_ADDRESS \
244 : (type)))
246 static int push_secondary_reload (int, rtx, int, int, enum reg_class,
247 enum machine_mode, enum reload_type,
248 enum insn_code *, secondary_reload_info *);
249 static enum reg_class find_valid_class (enum machine_mode, enum machine_mode,
250 int, unsigned int);
251 static int reload_inner_reg_of_subreg (rtx, enum machine_mode, int);
252 static void push_replacement (rtx *, int, enum machine_mode);
253 static void dup_replacements (rtx *, rtx *);
254 static void combine_reloads (void);
255 static int find_reusable_reload (rtx *, rtx, enum reg_class,
256 enum reload_type, int, int);
257 static rtx find_dummy_reload (rtx, rtx, rtx *, rtx *, enum machine_mode,
258 enum machine_mode, enum reg_class, int, int);
259 static int hard_reg_set_here_p (unsigned int, unsigned int, rtx);
260 static struct decomposition decompose (rtx);
261 static int immune_p (rtx, rtx, struct decomposition);
262 static int alternative_allows_memconst (const char *, int);
263 static rtx find_reloads_toplev (rtx, int, enum reload_type, int, int, rtx,
264 int *);
265 static rtx make_memloc (rtx, int);
266 static int maybe_memory_address_p (enum machine_mode, rtx, rtx *);
267 static int find_reloads_address (enum machine_mode, rtx *, rtx, rtx *,
268 int, enum reload_type, int, rtx);
269 static rtx subst_reg_equivs (rtx, rtx);
270 static rtx subst_indexed_address (rtx);
271 static void update_auto_inc_notes (rtx, int, int);
272 static int find_reloads_address_1 (enum machine_mode, rtx, int, rtx *,
273 int, enum reload_type,int, rtx);
274 static void find_reloads_address_part (rtx, rtx *, enum reg_class,
275 enum machine_mode, int,
276 enum reload_type, int);
277 static rtx find_reloads_subreg_address (rtx, int, int, enum reload_type,
278 int, rtx);
279 static void copy_replacements_1 (rtx *, rtx *, int);
280 static int find_inc_amount (rtx, rtx);
281 static int refers_to_mem_for_reload_p (rtx);
282 static int refers_to_regno_for_reload_p (unsigned int, unsigned int,
283 rtx, rtx *);
285 /* Determine if any secondary reloads are needed for loading (if IN_P is
286 nonzero) or storing (if IN_P is zero) X to or from a reload register of
287 register class RELOAD_CLASS in mode RELOAD_MODE. If secondary reloads
288 are needed, push them.
290 Return the reload number of the secondary reload we made, or -1 if
291 we didn't need one. *PICODE is set to the insn_code to use if we do
292 need a secondary reload. */
294 static int
295 push_secondary_reload (int in_p, rtx x, int opnum, int optional,
296 enum reg_class reload_class,
297 enum machine_mode reload_mode, enum reload_type type,
298 enum insn_code *picode, secondary_reload_info *prev_sri)
300 enum reg_class class = NO_REGS;
301 enum reg_class scratch_class;
302 enum machine_mode mode = reload_mode;
303 enum insn_code icode = CODE_FOR_nothing;
304 enum insn_code t_icode = CODE_FOR_nothing;
305 enum reload_type secondary_type;
306 int s_reload, t_reload = -1;
307 const char *scratch_constraint;
308 char letter;
309 secondary_reload_info sri;
311 if (type == RELOAD_FOR_INPUT_ADDRESS
312 || type == RELOAD_FOR_OUTPUT_ADDRESS
313 || type == RELOAD_FOR_INPADDR_ADDRESS
314 || type == RELOAD_FOR_OUTADDR_ADDRESS)
315 secondary_type = type;
316 else
317 secondary_type = in_p ? RELOAD_FOR_INPUT_ADDRESS : RELOAD_FOR_OUTPUT_ADDRESS;
319 *picode = CODE_FOR_nothing;
321 /* If X is a paradoxical SUBREG, use the inner value to determine both the
322 mode and object being reloaded. */
323 if (GET_CODE (x) == SUBREG
324 && (GET_MODE_SIZE (GET_MODE (x))
325 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
327 x = SUBREG_REG (x);
328 reload_mode = GET_MODE (x);
331 /* If X is a pseudo-register that has an equivalent MEM (actually, if it
332 is still a pseudo-register by now, it *must* have an equivalent MEM
333 but we don't want to assume that), use that equivalent when seeing if
334 a secondary reload is needed since whether or not a reload is needed
335 might be sensitive to the form of the MEM. */
337 if (REG_P (x) && REGNO (x) >= FIRST_PSEUDO_REGISTER
338 && reg_equiv_mem[REGNO (x)] != 0)
339 x = reg_equiv_mem[REGNO (x)];
341 sri.icode = CODE_FOR_nothing;
342 sri.prev_sri = prev_sri;
343 class = targetm.secondary_reload (in_p, x, reload_class, reload_mode, &sri);
344 icode = sri.icode;
346 /* If we don't need any secondary registers, done. */
347 if (class == NO_REGS && icode == CODE_FOR_nothing)
348 return -1;
350 if (class != NO_REGS)
351 t_reload = push_secondary_reload (in_p, x, opnum, optional, class,
352 reload_mode, type, &t_icode, &sri);
354 /* If we will be using an insn, the secondary reload is for a
355 scratch register. */
357 if (icode != CODE_FOR_nothing)
359 /* If IN_P is nonzero, the reload register will be the output in
360 operand 0. If IN_P is zero, the reload register will be the input
361 in operand 1. Outputs should have an initial "=", which we must
362 skip. */
364 /* ??? It would be useful to be able to handle only two, or more than
365 three, operands, but for now we can only handle the case of having
366 exactly three: output, input and one temp/scratch. */
367 gcc_assert (insn_data[(int) icode].n_operands == 3);
369 /* ??? We currently have no way to represent a reload that needs
370 an icode to reload from an intermediate tertiary reload register.
371 We should probably have a new field in struct reload to tag a
372 chain of scratch operand reloads onto. */
373 gcc_assert (class == NO_REGS);
375 scratch_constraint = insn_data[(int) icode].operand[2].constraint;
376 gcc_assert (*scratch_constraint == '=');
377 scratch_constraint++;
378 if (*scratch_constraint == '&')
379 scratch_constraint++;
380 letter = *scratch_constraint;
381 scratch_class = (letter == 'r' ? GENERAL_REGS
382 : REG_CLASS_FROM_CONSTRAINT ((unsigned char) letter,
383 scratch_constraint));
385 class = scratch_class;
386 mode = insn_data[(int) icode].operand[2].mode;
389 /* This case isn't valid, so fail. Reload is allowed to use the same
390 register for RELOAD_FOR_INPUT_ADDRESS and RELOAD_FOR_INPUT reloads, but
391 in the case of a secondary register, we actually need two different
392 registers for correct code. We fail here to prevent the possibility of
393 silently generating incorrect code later.
395 The convention is that secondary input reloads are valid only if the
396 secondary_class is different from class. If you have such a case, you
397 can not use secondary reloads, you must work around the problem some
398 other way.
400 Allow this when a reload_in/out pattern is being used. I.e. assume
401 that the generated code handles this case. */
403 gcc_assert (!in_p || class != reload_class || icode != CODE_FOR_nothing
404 || t_icode != CODE_FOR_nothing);
406 /* See if we can reuse an existing secondary reload. */
407 for (s_reload = 0; s_reload < n_reloads; s_reload++)
408 if (rld[s_reload].secondary_p
409 && (reg_class_subset_p (class, rld[s_reload].class)
410 || reg_class_subset_p (rld[s_reload].class, class))
411 && ((in_p && rld[s_reload].inmode == mode)
412 || (! in_p && rld[s_reload].outmode == mode))
413 && ((in_p && rld[s_reload].secondary_in_reload == t_reload)
414 || (! in_p && rld[s_reload].secondary_out_reload == t_reload))
415 && ((in_p && rld[s_reload].secondary_in_icode == t_icode)
416 || (! in_p && rld[s_reload].secondary_out_icode == t_icode))
417 && (SMALL_REGISTER_CLASS_P (class) || SMALL_REGISTER_CLASSES)
418 && MERGABLE_RELOADS (secondary_type, rld[s_reload].when_needed,
419 opnum, rld[s_reload].opnum))
421 if (in_p)
422 rld[s_reload].inmode = mode;
423 if (! in_p)
424 rld[s_reload].outmode = mode;
426 if (reg_class_subset_p (class, rld[s_reload].class))
427 rld[s_reload].class = class;
429 rld[s_reload].opnum = MIN (rld[s_reload].opnum, opnum);
430 rld[s_reload].optional &= optional;
431 rld[s_reload].secondary_p = 1;
432 if (MERGE_TO_OTHER (secondary_type, rld[s_reload].when_needed,
433 opnum, rld[s_reload].opnum))
434 rld[s_reload].when_needed = RELOAD_OTHER;
437 if (s_reload == n_reloads)
439 #ifdef SECONDARY_MEMORY_NEEDED
440 /* If we need a memory location to copy between the two reload regs,
441 set it up now. Note that we do the input case before making
442 the reload and the output case after. This is due to the
443 way reloads are output. */
445 if (in_p && icode == CODE_FOR_nothing
446 && SECONDARY_MEMORY_NEEDED (class, reload_class, mode))
448 get_secondary_mem (x, reload_mode, opnum, type);
450 /* We may have just added new reloads. Make sure we add
451 the new reload at the end. */
452 s_reload = n_reloads;
454 #endif
456 /* We need to make a new secondary reload for this register class. */
457 rld[s_reload].in = rld[s_reload].out = 0;
458 rld[s_reload].class = class;
460 rld[s_reload].inmode = in_p ? mode : VOIDmode;
461 rld[s_reload].outmode = ! in_p ? mode : VOIDmode;
462 rld[s_reload].reg_rtx = 0;
463 rld[s_reload].optional = optional;
464 rld[s_reload].inc = 0;
465 /* Maybe we could combine these, but it seems too tricky. */
466 rld[s_reload].nocombine = 1;
467 rld[s_reload].in_reg = 0;
468 rld[s_reload].out_reg = 0;
469 rld[s_reload].opnum = opnum;
470 rld[s_reload].when_needed = secondary_type;
471 rld[s_reload].secondary_in_reload = in_p ? t_reload : -1;
472 rld[s_reload].secondary_out_reload = ! in_p ? t_reload : -1;
473 rld[s_reload].secondary_in_icode = in_p ? t_icode : CODE_FOR_nothing;
474 rld[s_reload].secondary_out_icode
475 = ! in_p ? t_icode : CODE_FOR_nothing;
476 rld[s_reload].secondary_p = 1;
478 n_reloads++;
480 #ifdef SECONDARY_MEMORY_NEEDED
481 if (! in_p && icode == CODE_FOR_nothing
482 && SECONDARY_MEMORY_NEEDED (reload_class, class, mode))
483 get_secondary_mem (x, mode, opnum, type);
484 #endif
487 *picode = icode;
488 return s_reload;
491 /* If a secondary reload is needed, return its class. If both an intermediate
492 register and a scratch register is needed, we return the class of the
493 intermediate register. */
494 enum reg_class
495 secondary_reload_class (bool in_p, enum reg_class class,
496 enum machine_mode mode, rtx x)
498 enum insn_code icode;
499 secondary_reload_info sri;
501 sri.icode = CODE_FOR_nothing;
502 sri.prev_sri = NULL;
503 class = targetm.secondary_reload (in_p, x, class, mode, &sri);
504 icode = sri.icode;
506 /* If there are no secondary reloads at all, we return NO_REGS.
507 If an intermediate register is needed, we return its class. */
508 if (icode == CODE_FOR_nothing || class != NO_REGS)
509 return class;
511 /* No intermediate register is needed, but we have a special reload
512 pattern, which we assume for now needs a scratch register. */
513 return scratch_reload_class (icode);
516 /* ICODE is the insn_code of a reload pattern. Check that it has exactly
517 three operands, verify that operand 2 is an output operand, and return
518 its register class.
519 ??? We'd like to be able to handle any pattern with at least 2 operands,
520 for zero or more scratch registers, but that needs more infrastructure. */
521 enum reg_class
522 scratch_reload_class (enum insn_code icode)
524 const char *scratch_constraint;
525 char scratch_letter;
526 enum reg_class class;
528 gcc_assert (insn_data[(int) icode].n_operands == 3);
529 scratch_constraint = insn_data[(int) icode].operand[2].constraint;
530 gcc_assert (*scratch_constraint == '=');
531 scratch_constraint++;
532 if (*scratch_constraint == '&')
533 scratch_constraint++;
534 scratch_letter = *scratch_constraint;
535 if (scratch_letter == 'r')
536 return GENERAL_REGS;
537 class = REG_CLASS_FROM_CONSTRAINT ((unsigned char) scratch_letter,
538 scratch_constraint);
539 gcc_assert (class != NO_REGS);
540 return class;
543 #ifdef SECONDARY_MEMORY_NEEDED
545 /* Return a memory location that will be used to copy X in mode MODE.
546 If we haven't already made a location for this mode in this insn,
547 call find_reloads_address on the location being returned. */
550 get_secondary_mem (rtx x ATTRIBUTE_UNUSED, enum machine_mode mode,
551 int opnum, enum reload_type type)
553 rtx loc;
554 int mem_valid;
556 /* By default, if MODE is narrower than a word, widen it to a word.
557 This is required because most machines that require these memory
558 locations do not support short load and stores from all registers
559 (e.g., FP registers). */
561 #ifdef SECONDARY_MEMORY_NEEDED_MODE
562 mode = SECONDARY_MEMORY_NEEDED_MODE (mode);
563 #else
564 if (GET_MODE_BITSIZE (mode) < BITS_PER_WORD && INTEGRAL_MODE_P (mode))
565 mode = mode_for_size (BITS_PER_WORD, GET_MODE_CLASS (mode), 0);
566 #endif
568 /* If we already have made a MEM for this operand in MODE, return it. */
569 if (secondary_memlocs_elim[(int) mode][opnum] != 0)
570 return secondary_memlocs_elim[(int) mode][opnum];
572 /* If this is the first time we've tried to get a MEM for this mode,
573 allocate a new one. `something_changed' in reload will get set
574 by noticing that the frame size has changed. */
576 if (secondary_memlocs[(int) mode] == 0)
578 #ifdef SECONDARY_MEMORY_NEEDED_RTX
579 secondary_memlocs[(int) mode] = SECONDARY_MEMORY_NEEDED_RTX (mode);
580 #else
581 secondary_memlocs[(int) mode]
582 = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
583 #endif
586 /* Get a version of the address doing any eliminations needed. If that
587 didn't give us a new MEM, make a new one if it isn't valid. */
589 loc = eliminate_regs (secondary_memlocs[(int) mode], VOIDmode, NULL_RTX);
590 mem_valid = strict_memory_address_p (mode, XEXP (loc, 0));
592 if (! mem_valid && loc == secondary_memlocs[(int) mode])
593 loc = copy_rtx (loc);
595 /* The only time the call below will do anything is if the stack
596 offset is too large. In that case IND_LEVELS doesn't matter, so we
597 can just pass a zero. Adjust the type to be the address of the
598 corresponding object. If the address was valid, save the eliminated
599 address. If it wasn't valid, we need to make a reload each time, so
600 don't save it. */
602 if (! mem_valid)
604 type = (type == RELOAD_FOR_INPUT ? RELOAD_FOR_INPUT_ADDRESS
605 : type == RELOAD_FOR_OUTPUT ? RELOAD_FOR_OUTPUT_ADDRESS
606 : RELOAD_OTHER);
608 find_reloads_address (mode, &loc, XEXP (loc, 0), &XEXP (loc, 0),
609 opnum, type, 0, 0);
612 secondary_memlocs_elim[(int) mode][opnum] = loc;
613 if (secondary_memlocs_elim_used <= (int)mode)
614 secondary_memlocs_elim_used = (int)mode + 1;
615 return loc;
618 /* Clear any secondary memory locations we've made. */
620 void
621 clear_secondary_mem (void)
623 memset (secondary_memlocs, 0, sizeof secondary_memlocs);
625 #endif /* SECONDARY_MEMORY_NEEDED */
628 /* Find the largest class which has at least one register valid in
629 mode INNER, and which for every such register, that register number
630 plus N is also valid in OUTER (if in range) and is cheap to move
631 into REGNO. Such a class must exist. */
633 static enum reg_class
634 find_valid_class (enum machine_mode outer ATTRIBUTE_UNUSED,
635 enum machine_mode inner ATTRIBUTE_UNUSED, int n,
636 unsigned int dest_regno ATTRIBUTE_UNUSED)
638 int best_cost = -1;
639 int class;
640 int regno;
641 enum reg_class best_class = NO_REGS;
642 enum reg_class dest_class ATTRIBUTE_UNUSED = REGNO_REG_CLASS (dest_regno);
643 unsigned int best_size = 0;
644 int cost;
646 for (class = 1; class < N_REG_CLASSES; class++)
648 int bad = 0;
649 int good = 0;
650 for (regno = 0; regno < FIRST_PSEUDO_REGISTER - n && ! bad; regno++)
651 if (TEST_HARD_REG_BIT (reg_class_contents[class], regno))
653 if (HARD_REGNO_MODE_OK (regno, inner))
655 good = 1;
656 if (! TEST_HARD_REG_BIT (reg_class_contents[class], regno + n)
657 || ! HARD_REGNO_MODE_OK (regno + n, outer))
658 bad = 1;
662 if (bad || !good)
663 continue;
664 cost = REGISTER_MOVE_COST (outer, class, dest_class);
666 if ((reg_class_size[class] > best_size
667 && (best_cost < 0 || best_cost >= cost))
668 || best_cost > cost)
670 best_class = class;
671 best_size = reg_class_size[class];
672 best_cost = REGISTER_MOVE_COST (outer, class, dest_class);
676 gcc_assert (best_size != 0);
678 return best_class;
681 /* Return the number of a previously made reload that can be combined with
682 a new one, or n_reloads if none of the existing reloads can be used.
683 OUT, CLASS, TYPE and OPNUM are the same arguments as passed to
684 push_reload, they determine the kind of the new reload that we try to
685 combine. P_IN points to the corresponding value of IN, which can be
686 modified by this function.
687 DONT_SHARE is nonzero if we can't share any input-only reload for IN. */
689 static int
690 find_reusable_reload (rtx *p_in, rtx out, enum reg_class class,
691 enum reload_type type, int opnum, int dont_share)
693 rtx in = *p_in;
694 int i;
695 /* We can't merge two reloads if the output of either one is
696 earlyclobbered. */
698 if (earlyclobber_operand_p (out))
699 return n_reloads;
701 /* We can use an existing reload if the class is right
702 and at least one of IN and OUT is a match
703 and the other is at worst neutral.
704 (A zero compared against anything is neutral.)
706 If SMALL_REGISTER_CLASSES, don't use existing reloads unless they are
707 for the same thing since that can cause us to need more reload registers
708 than we otherwise would. */
710 for (i = 0; i < n_reloads; i++)
711 if ((reg_class_subset_p (class, rld[i].class)
712 || reg_class_subset_p (rld[i].class, class))
713 /* If the existing reload has a register, it must fit our class. */
714 && (rld[i].reg_rtx == 0
715 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
716 true_regnum (rld[i].reg_rtx)))
717 && ((in != 0 && MATCHES (rld[i].in, in) && ! dont_share
718 && (out == 0 || rld[i].out == 0 || MATCHES (rld[i].out, out)))
719 || (out != 0 && MATCHES (rld[i].out, out)
720 && (in == 0 || rld[i].in == 0 || MATCHES (rld[i].in, in))))
721 && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
722 && (SMALL_REGISTER_CLASS_P (class) || SMALL_REGISTER_CLASSES)
723 && MERGABLE_RELOADS (type, rld[i].when_needed, opnum, rld[i].opnum))
724 return i;
726 /* Reloading a plain reg for input can match a reload to postincrement
727 that reg, since the postincrement's value is the right value.
728 Likewise, it can match a preincrement reload, since we regard
729 the preincrementation as happening before any ref in this insn
730 to that register. */
731 for (i = 0; i < n_reloads; i++)
732 if ((reg_class_subset_p (class, rld[i].class)
733 || reg_class_subset_p (rld[i].class, class))
734 /* If the existing reload has a register, it must fit our
735 class. */
736 && (rld[i].reg_rtx == 0
737 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
738 true_regnum (rld[i].reg_rtx)))
739 && out == 0 && rld[i].out == 0 && rld[i].in != 0
740 && ((REG_P (in)
741 && GET_RTX_CLASS (GET_CODE (rld[i].in)) == RTX_AUTOINC
742 && MATCHES (XEXP (rld[i].in, 0), in))
743 || (REG_P (rld[i].in)
744 && GET_RTX_CLASS (GET_CODE (in)) == RTX_AUTOINC
745 && MATCHES (XEXP (in, 0), rld[i].in)))
746 && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out))
747 && (SMALL_REGISTER_CLASS_P (class) || SMALL_REGISTER_CLASSES)
748 && MERGABLE_RELOADS (type, rld[i].when_needed,
749 opnum, rld[i].opnum))
751 /* Make sure reload_in ultimately has the increment,
752 not the plain register. */
753 if (REG_P (in))
754 *p_in = rld[i].in;
755 return i;
757 return n_reloads;
760 /* Return nonzero if X is a SUBREG which will require reloading of its
761 SUBREG_REG expression. */
763 static int
764 reload_inner_reg_of_subreg (rtx x, enum machine_mode mode, int output)
766 rtx inner;
768 /* Only SUBREGs are problematical. */
769 if (GET_CODE (x) != SUBREG)
770 return 0;
772 inner = SUBREG_REG (x);
774 /* If INNER is a constant or PLUS, then INNER must be reloaded. */
775 if (CONSTANT_P (inner) || GET_CODE (inner) == PLUS)
776 return 1;
778 /* If INNER is not a hard register, then INNER will not need to
779 be reloaded. */
780 if (!REG_P (inner)
781 || REGNO (inner) >= FIRST_PSEUDO_REGISTER)
782 return 0;
784 /* If INNER is not ok for MODE, then INNER will need reloading. */
785 if (! HARD_REGNO_MODE_OK (subreg_regno (x), mode))
786 return 1;
788 /* If the outer part is a word or smaller, INNER larger than a
789 word and the number of regs for INNER is not the same as the
790 number of words in INNER, then INNER will need reloading. */
791 return (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
792 && output
793 && GET_MODE_SIZE (GET_MODE (inner)) > UNITS_PER_WORD
794 && ((GET_MODE_SIZE (GET_MODE (inner)) / UNITS_PER_WORD)
795 != (int) hard_regno_nregs[REGNO (inner)][GET_MODE (inner)]));
798 /* Return nonzero if IN can be reloaded into REGNO with mode MODE without
799 requiring an extra reload register. The caller has already found that
800 IN contains some reference to REGNO, so check that we can produce the
801 new value in a single step. E.g. if we have
802 (set (reg r13) (plus (reg r13) (const int 1))), and there is an
803 instruction that adds one to a register, this should succeed.
804 However, if we have something like
805 (set (reg r13) (plus (reg r13) (const int 999))), and the constant 999
806 needs to be loaded into a register first, we need a separate reload
807 register.
808 Such PLUS reloads are generated by find_reload_address_part.
809 The out-of-range PLUS expressions are usually introduced in the instruction
810 patterns by register elimination and substituting pseudos without a home
811 by their function-invariant equivalences. */
812 static int
813 can_reload_into (rtx in, int regno, enum machine_mode mode)
815 rtx dst, test_insn;
816 int r = 0;
817 struct recog_data save_recog_data;
819 /* For matching constraints, we often get notional input reloads where
820 we want to use the original register as the reload register. I.e.
821 technically this is a non-optional input-output reload, but IN is
822 already a valid register, and has been chosen as the reload register.
823 Speed this up, since it trivially works. */
824 if (REG_P (in))
825 return 1;
827 /* To test MEMs properly, we'd have to take into account all the reloads
828 that are already scheduled, which can become quite complicated.
829 And since we've already handled address reloads for this MEM, it
830 should always succeed anyway. */
831 if (MEM_P (in))
832 return 1;
834 /* If we can make a simple SET insn that does the job, everything should
835 be fine. */
836 dst = gen_rtx_REG (mode, regno);
837 test_insn = make_insn_raw (gen_rtx_SET (VOIDmode, dst, in));
838 save_recog_data = recog_data;
839 if (recog_memoized (test_insn) >= 0)
841 extract_insn (test_insn);
842 r = constrain_operands (1);
844 recog_data = save_recog_data;
845 return r;
848 /* Record one reload that needs to be performed.
849 IN is an rtx saying where the data are to be found before this instruction.
850 OUT says where they must be stored after the instruction.
851 (IN is zero for data not read, and OUT is zero for data not written.)
852 INLOC and OUTLOC point to the places in the instructions where
853 IN and OUT were found.
854 If IN and OUT are both nonzero, it means the same register must be used
855 to reload both IN and OUT.
857 CLASS is a register class required for the reloaded data.
858 INMODE is the machine mode that the instruction requires
859 for the reg that replaces IN and OUTMODE is likewise for OUT.
861 If IN is zero, then OUT's location and mode should be passed as
862 INLOC and INMODE.
864 STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
866 OPTIONAL nonzero means this reload does not need to be performed:
867 it can be discarded if that is more convenient.
869 OPNUM and TYPE say what the purpose of this reload is.
871 The return value is the reload-number for this reload.
873 If both IN and OUT are nonzero, in some rare cases we might
874 want to make two separate reloads. (Actually we never do this now.)
875 Therefore, the reload-number for OUT is stored in
876 output_reloadnum when we return; the return value applies to IN.
877 Usually (presently always), when IN and OUT are nonzero,
878 the two reload-numbers are equal, but the caller should be careful to
879 distinguish them. */
882 push_reload (rtx in, rtx out, rtx *inloc, rtx *outloc,
883 enum reg_class class, enum machine_mode inmode,
884 enum machine_mode outmode, int strict_low, int optional,
885 int opnum, enum reload_type type)
887 int i;
888 int dont_share = 0;
889 int dont_remove_subreg = 0;
890 rtx *in_subreg_loc = 0, *out_subreg_loc = 0;
891 int secondary_in_reload = -1, secondary_out_reload = -1;
892 enum insn_code secondary_in_icode = CODE_FOR_nothing;
893 enum insn_code secondary_out_icode = CODE_FOR_nothing;
895 /* INMODE and/or OUTMODE could be VOIDmode if no mode
896 has been specified for the operand. In that case,
897 use the operand's mode as the mode to reload. */
898 if (inmode == VOIDmode && in != 0)
899 inmode = GET_MODE (in);
900 if (outmode == VOIDmode && out != 0)
901 outmode = GET_MODE (out);
903 /* If IN is a pseudo register everywhere-equivalent to a constant, and
904 it is not in a hard register, reload straight from the constant,
905 since we want to get rid of such pseudo registers.
906 Often this is done earlier, but not always in find_reloads_address. */
907 if (in != 0 && REG_P (in))
909 int regno = REGNO (in);
911 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
912 && reg_equiv_constant[regno] != 0)
913 in = reg_equiv_constant[regno];
916 /* Likewise for OUT. Of course, OUT will never be equivalent to
917 an actual constant, but it might be equivalent to a memory location
918 (in the case of a parameter). */
919 if (out != 0 && REG_P (out))
921 int regno = REGNO (out);
923 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
924 && reg_equiv_constant[regno] != 0)
925 out = reg_equiv_constant[regno];
928 /* If we have a read-write operand with an address side-effect,
929 change either IN or OUT so the side-effect happens only once. */
930 if (in != 0 && out != 0 && MEM_P (in) && rtx_equal_p (in, out))
931 switch (GET_CODE (XEXP (in, 0)))
933 case POST_INC: case POST_DEC: case POST_MODIFY:
934 in = replace_equiv_address_nv (in, XEXP (XEXP (in, 0), 0));
935 break;
937 case PRE_INC: case PRE_DEC: case PRE_MODIFY:
938 out = replace_equiv_address_nv (out, XEXP (XEXP (out, 0), 0));
939 break;
941 default:
942 break;
945 /* If we are reloading a (SUBREG constant ...), really reload just the
946 inside expression in its own mode. Similarly for (SUBREG (PLUS ...)).
947 If we have (SUBREG:M1 (MEM:M2 ...) ...) (or an inner REG that is still
948 a pseudo and hence will become a MEM) with M1 wider than M2 and the
949 register is a pseudo, also reload the inside expression.
950 For machines that extend byte loads, do this for any SUBREG of a pseudo
951 where both M1 and M2 are a word or smaller, M1 is wider than M2, and
952 M2 is an integral mode that gets extended when loaded.
953 Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
954 either M1 is not valid for R or M2 is wider than a word but we only
955 need one word to store an M2-sized quantity in R.
956 (However, if OUT is nonzero, we need to reload the reg *and*
957 the subreg, so do nothing here, and let following statement handle it.)
959 Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere;
960 we can't handle it here because CONST_INT does not indicate a mode.
962 Similarly, we must reload the inside expression if we have a
963 STRICT_LOW_PART (presumably, in == out in the cas).
965 Also reload the inner expression if it does not require a secondary
966 reload but the SUBREG does.
968 Finally, reload the inner expression if it is a register that is in
969 the class whose registers cannot be referenced in a different size
970 and M1 is not the same size as M2. If subreg_lowpart_p is false, we
971 cannot reload just the inside since we might end up with the wrong
972 register class. But if it is inside a STRICT_LOW_PART, we have
973 no choice, so we hope we do get the right register class there. */
975 if (in != 0 && GET_CODE (in) == SUBREG
976 && (subreg_lowpart_p (in) || strict_low)
977 #ifdef CANNOT_CHANGE_MODE_CLASS
978 && !CANNOT_CHANGE_MODE_CLASS (GET_MODE (SUBREG_REG (in)), inmode, class)
979 #endif
980 && (CONSTANT_P (SUBREG_REG (in))
981 || GET_CODE (SUBREG_REG (in)) == PLUS
982 || strict_low
983 || (((REG_P (SUBREG_REG (in))
984 && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER)
985 || MEM_P (SUBREG_REG (in)))
986 && ((GET_MODE_SIZE (inmode)
987 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
988 #ifdef LOAD_EXTEND_OP
989 || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
990 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
991 <= UNITS_PER_WORD)
992 && (GET_MODE_SIZE (inmode)
993 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
994 && INTEGRAL_MODE_P (GET_MODE (SUBREG_REG (in)))
995 && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (in))) != UNKNOWN)
996 #endif
997 #ifdef WORD_REGISTER_OPERATIONS
998 || ((GET_MODE_SIZE (inmode)
999 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
1000 && ((GET_MODE_SIZE (inmode) - 1) / UNITS_PER_WORD ==
1001 ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))) - 1)
1002 / UNITS_PER_WORD)))
1003 #endif
1005 || (REG_P (SUBREG_REG (in))
1006 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1007 /* The case where out is nonzero
1008 is handled differently in the following statement. */
1009 && (out == 0 || subreg_lowpart_p (in))
1010 && ((GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
1011 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1012 > UNITS_PER_WORD)
1013 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1014 / UNITS_PER_WORD)
1015 != (int) hard_regno_nregs[REGNO (SUBREG_REG (in))]
1016 [GET_MODE (SUBREG_REG (in))]))
1017 || ! HARD_REGNO_MODE_OK (subreg_regno (in), inmode)))
1018 || (secondary_reload_class (1, class, inmode, in) != NO_REGS
1019 && (secondary_reload_class (1, class, GET_MODE (SUBREG_REG (in)),
1020 SUBREG_REG (in))
1021 == NO_REGS))
1022 #ifdef CANNOT_CHANGE_MODE_CLASS
1023 || (REG_P (SUBREG_REG (in))
1024 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1025 && REG_CANNOT_CHANGE_MODE_P
1026 (REGNO (SUBREG_REG (in)), GET_MODE (SUBREG_REG (in)), inmode))
1027 #endif
1030 in_subreg_loc = inloc;
1031 inloc = &SUBREG_REG (in);
1032 in = *inloc;
1033 #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
1034 if (MEM_P (in))
1035 /* This is supposed to happen only for paradoxical subregs made by
1036 combine.c. (SUBREG (MEM)) isn't supposed to occur other ways. */
1037 gcc_assert (GET_MODE_SIZE (GET_MODE (in)) <= GET_MODE_SIZE (inmode));
1038 #endif
1039 inmode = GET_MODE (in);
1042 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
1043 either M1 is not valid for R or M2 is wider than a word but we only
1044 need one word to store an M2-sized quantity in R.
1046 However, we must reload the inner reg *as well as* the subreg in
1047 that case. */
1049 /* Similar issue for (SUBREG constant ...) if it was not handled by the
1050 code above. This can happen if SUBREG_BYTE != 0. */
1052 if (in != 0 && reload_inner_reg_of_subreg (in, inmode, 0))
1054 enum reg_class in_class = class;
1056 if (REG_P (SUBREG_REG (in)))
1057 in_class
1058 = find_valid_class (inmode, GET_MODE (SUBREG_REG (in)),
1059 subreg_regno_offset (REGNO (SUBREG_REG (in)),
1060 GET_MODE (SUBREG_REG (in)),
1061 SUBREG_BYTE (in),
1062 GET_MODE (in)),
1063 REGNO (SUBREG_REG (in)));
1065 /* This relies on the fact that emit_reload_insns outputs the
1066 instructions for input reloads of type RELOAD_OTHER in the same
1067 order as the reloads. Thus if the outer reload is also of type
1068 RELOAD_OTHER, we are guaranteed that this inner reload will be
1069 output before the outer reload. */
1070 push_reload (SUBREG_REG (in), NULL_RTX, &SUBREG_REG (in), (rtx *) 0,
1071 in_class, VOIDmode, VOIDmode, 0, 0, opnum, type);
1072 dont_remove_subreg = 1;
1075 /* Similarly for paradoxical and problematical SUBREGs on the output.
1076 Note that there is no reason we need worry about the previous value
1077 of SUBREG_REG (out); even if wider than out,
1078 storing in a subreg is entitled to clobber it all
1079 (except in the case of STRICT_LOW_PART,
1080 and in that case the constraint should label it input-output.) */
1081 if (out != 0 && GET_CODE (out) == SUBREG
1082 && (subreg_lowpart_p (out) || strict_low)
1083 #ifdef CANNOT_CHANGE_MODE_CLASS
1084 && !CANNOT_CHANGE_MODE_CLASS (GET_MODE (SUBREG_REG (out)), outmode, class)
1085 #endif
1086 && (CONSTANT_P (SUBREG_REG (out))
1087 || strict_low
1088 || (((REG_P (SUBREG_REG (out))
1089 && REGNO (SUBREG_REG (out)) >= FIRST_PSEUDO_REGISTER)
1090 || MEM_P (SUBREG_REG (out)))
1091 && ((GET_MODE_SIZE (outmode)
1092 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))
1093 #ifdef WORD_REGISTER_OPERATIONS
1094 || ((GET_MODE_SIZE (outmode)
1095 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))
1096 && ((GET_MODE_SIZE (outmode) - 1) / UNITS_PER_WORD ==
1097 ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))) - 1)
1098 / UNITS_PER_WORD)))
1099 #endif
1101 || (REG_P (SUBREG_REG (out))
1102 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1103 && ((GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
1104 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1105 > UNITS_PER_WORD)
1106 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
1107 / UNITS_PER_WORD)
1108 != (int) hard_regno_nregs[REGNO (SUBREG_REG (out))]
1109 [GET_MODE (SUBREG_REG (out))]))
1110 || ! HARD_REGNO_MODE_OK (subreg_regno (out), outmode)))
1111 || (secondary_reload_class (0, class, outmode, out) != NO_REGS
1112 && (secondary_reload_class (0, class, GET_MODE (SUBREG_REG (out)),
1113 SUBREG_REG (out))
1114 == NO_REGS))
1115 #ifdef CANNOT_CHANGE_MODE_CLASS
1116 || (REG_P (SUBREG_REG (out))
1117 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1118 && REG_CANNOT_CHANGE_MODE_P (REGNO (SUBREG_REG (out)),
1119 GET_MODE (SUBREG_REG (out)),
1120 outmode))
1121 #endif
1124 out_subreg_loc = outloc;
1125 outloc = &SUBREG_REG (out);
1126 out = *outloc;
1127 #if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS)
1128 gcc_assert (!MEM_P (out)
1129 || GET_MODE_SIZE (GET_MODE (out))
1130 <= GET_MODE_SIZE (outmode));
1131 #endif
1132 outmode = GET_MODE (out);
1135 /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
1136 either M1 is not valid for R or M2 is wider than a word but we only
1137 need one word to store an M2-sized quantity in R.
1139 However, we must reload the inner reg *as well as* the subreg in
1140 that case. In this case, the inner reg is an in-out reload. */
1142 if (out != 0 && reload_inner_reg_of_subreg (out, outmode, 1))
1144 /* This relies on the fact that emit_reload_insns outputs the
1145 instructions for output reloads of type RELOAD_OTHER in reverse
1146 order of the reloads. Thus if the outer reload is also of type
1147 RELOAD_OTHER, we are guaranteed that this inner reload will be
1148 output after the outer reload. */
1149 dont_remove_subreg = 1;
1150 push_reload (SUBREG_REG (out), SUBREG_REG (out), &SUBREG_REG (out),
1151 &SUBREG_REG (out),
1152 find_valid_class (outmode, GET_MODE (SUBREG_REG (out)),
1153 subreg_regno_offset (REGNO (SUBREG_REG (out)),
1154 GET_MODE (SUBREG_REG (out)),
1155 SUBREG_BYTE (out),
1156 GET_MODE (out)),
1157 REGNO (SUBREG_REG (out))),
1158 VOIDmode, VOIDmode, 0, 0,
1159 opnum, RELOAD_OTHER);
1162 /* If IN appears in OUT, we can't share any input-only reload for IN. */
1163 if (in != 0 && out != 0 && MEM_P (out)
1164 && (REG_P (in) || MEM_P (in))
1165 && reg_overlap_mentioned_for_reload_p (in, XEXP (out, 0)))
1166 dont_share = 1;
1168 /* If IN is a SUBREG of a hard register, make a new REG. This
1169 simplifies some of the cases below. */
1171 if (in != 0 && GET_CODE (in) == SUBREG && REG_P (SUBREG_REG (in))
1172 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
1173 && ! dont_remove_subreg)
1174 in = gen_rtx_REG (GET_MODE (in), subreg_regno (in));
1176 /* Similarly for OUT. */
1177 if (out != 0 && GET_CODE (out) == SUBREG
1178 && REG_P (SUBREG_REG (out))
1179 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
1180 && ! dont_remove_subreg)
1181 out = gen_rtx_REG (GET_MODE (out), subreg_regno (out));
1183 /* Narrow down the class of register wanted if that is
1184 desirable on this machine for efficiency. */
1185 if (in != 0)
1186 class = PREFERRED_RELOAD_CLASS (in, class);
1188 /* Output reloads may need analogous treatment, different in detail. */
1189 #ifdef PREFERRED_OUTPUT_RELOAD_CLASS
1190 if (out != 0)
1191 class = PREFERRED_OUTPUT_RELOAD_CLASS (out, class);
1192 #endif
1194 /* Make sure we use a class that can handle the actual pseudo
1195 inside any subreg. For example, on the 386, QImode regs
1196 can appear within SImode subregs. Although GENERAL_REGS
1197 can handle SImode, QImode needs a smaller class. */
1198 #ifdef LIMIT_RELOAD_CLASS
1199 if (in_subreg_loc)
1200 class = LIMIT_RELOAD_CLASS (inmode, class);
1201 else if (in != 0 && GET_CODE (in) == SUBREG)
1202 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (in)), class);
1204 if (out_subreg_loc)
1205 class = LIMIT_RELOAD_CLASS (outmode, class);
1206 if (out != 0 && GET_CODE (out) == SUBREG)
1207 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (out)), class);
1208 #endif
1210 /* Verify that this class is at least possible for the mode that
1211 is specified. */
1212 if (this_insn_is_asm)
1214 enum machine_mode mode;
1215 if (GET_MODE_SIZE (inmode) > GET_MODE_SIZE (outmode))
1216 mode = inmode;
1217 else
1218 mode = outmode;
1219 if (mode == VOIDmode)
1221 error_for_asm (this_insn, "cannot reload integer constant "
1222 "operand in %<asm%>");
1223 mode = word_mode;
1224 if (in != 0)
1225 inmode = word_mode;
1226 if (out != 0)
1227 outmode = word_mode;
1229 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1230 if (HARD_REGNO_MODE_OK (i, mode)
1231 && TEST_HARD_REG_BIT (reg_class_contents[(int) class], i))
1233 int nregs = hard_regno_nregs[i][mode];
1235 int j;
1236 for (j = 1; j < nregs; j++)
1237 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], i + j))
1238 break;
1239 if (j == nregs)
1240 break;
1242 if (i == FIRST_PSEUDO_REGISTER)
1244 error_for_asm (this_insn, "impossible register constraint "
1245 "in %<asm%>");
1246 class = ALL_REGS;
1250 /* Optional output reloads are always OK even if we have no register class,
1251 since the function of these reloads is only to have spill_reg_store etc.
1252 set, so that the storing insn can be deleted later. */
1253 gcc_assert (class != NO_REGS
1254 || (optional != 0 && type == RELOAD_FOR_OUTPUT));
1256 i = find_reusable_reload (&in, out, class, type, opnum, dont_share);
1258 if (i == n_reloads)
1260 /* See if we need a secondary reload register to move between CLASS
1261 and IN or CLASS and OUT. Get the icode and push any required reloads
1262 needed for each of them if so. */
1264 if (in != 0)
1265 secondary_in_reload
1266 = push_secondary_reload (1, in, opnum, optional, class, inmode, type,
1267 &secondary_in_icode, NULL);
1268 if (out != 0 && GET_CODE (out) != SCRATCH)
1269 secondary_out_reload
1270 = push_secondary_reload (0, out, opnum, optional, class, outmode,
1271 type, &secondary_out_icode, NULL);
1273 /* We found no existing reload suitable for re-use.
1274 So add an additional reload. */
1276 #ifdef SECONDARY_MEMORY_NEEDED
1277 /* If a memory location is needed for the copy, make one. */
1278 if (in != 0 && (REG_P (in) || GET_CODE (in) == SUBREG)
1279 && reg_or_subregno (in) < FIRST_PSEUDO_REGISTER
1280 && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (reg_or_subregno (in)),
1281 class, inmode))
1282 get_secondary_mem (in, inmode, opnum, type);
1283 #endif
1285 i = n_reloads;
1286 rld[i].in = in;
1287 rld[i].out = out;
1288 rld[i].class = class;
1289 rld[i].inmode = inmode;
1290 rld[i].outmode = outmode;
1291 rld[i].reg_rtx = 0;
1292 rld[i].optional = optional;
1293 rld[i].inc = 0;
1294 rld[i].nocombine = 0;
1295 rld[i].in_reg = inloc ? *inloc : 0;
1296 rld[i].out_reg = outloc ? *outloc : 0;
1297 rld[i].opnum = opnum;
1298 rld[i].when_needed = type;
1299 rld[i].secondary_in_reload = secondary_in_reload;
1300 rld[i].secondary_out_reload = secondary_out_reload;
1301 rld[i].secondary_in_icode = secondary_in_icode;
1302 rld[i].secondary_out_icode = secondary_out_icode;
1303 rld[i].secondary_p = 0;
1305 n_reloads++;
1307 #ifdef SECONDARY_MEMORY_NEEDED
1308 if (out != 0 && (REG_P (out) || GET_CODE (out) == SUBREG)
1309 && reg_or_subregno (out) < FIRST_PSEUDO_REGISTER
1310 && SECONDARY_MEMORY_NEEDED (class,
1311 REGNO_REG_CLASS (reg_or_subregno (out)),
1312 outmode))
1313 get_secondary_mem (out, outmode, opnum, type);
1314 #endif
1316 else
1318 /* We are reusing an existing reload,
1319 but we may have additional information for it.
1320 For example, we may now have both IN and OUT
1321 while the old one may have just one of them. */
1323 /* The modes can be different. If they are, we want to reload in
1324 the larger mode, so that the value is valid for both modes. */
1325 if (inmode != VOIDmode
1326 && GET_MODE_SIZE (inmode) > GET_MODE_SIZE (rld[i].inmode))
1327 rld[i].inmode = inmode;
1328 if (outmode != VOIDmode
1329 && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (rld[i].outmode))
1330 rld[i].outmode = outmode;
1331 if (in != 0)
1333 rtx in_reg = inloc ? *inloc : 0;
1334 /* If we merge reloads for two distinct rtl expressions that
1335 are identical in content, there might be duplicate address
1336 reloads. Remove the extra set now, so that if we later find
1337 that we can inherit this reload, we can get rid of the
1338 address reloads altogether.
1340 Do not do this if both reloads are optional since the result
1341 would be an optional reload which could potentially leave
1342 unresolved address replacements.
1344 It is not sufficient to call transfer_replacements since
1345 choose_reload_regs will remove the replacements for address
1346 reloads of inherited reloads which results in the same
1347 problem. */
1348 if (rld[i].in != in && rtx_equal_p (in, rld[i].in)
1349 && ! (rld[i].optional && optional))
1351 /* We must keep the address reload with the lower operand
1352 number alive. */
1353 if (opnum > rld[i].opnum)
1355 remove_address_replacements (in);
1356 in = rld[i].in;
1357 in_reg = rld[i].in_reg;
1359 else
1360 remove_address_replacements (rld[i].in);
1362 rld[i].in = in;
1363 rld[i].in_reg = in_reg;
1365 if (out != 0)
1367 rld[i].out = out;
1368 rld[i].out_reg = outloc ? *outloc : 0;
1370 if (reg_class_subset_p (class, rld[i].class))
1371 rld[i].class = class;
1372 rld[i].optional &= optional;
1373 if (MERGE_TO_OTHER (type, rld[i].when_needed,
1374 opnum, rld[i].opnum))
1375 rld[i].when_needed = RELOAD_OTHER;
1376 rld[i].opnum = MIN (rld[i].opnum, opnum);
1379 /* If the ostensible rtx being reloaded differs from the rtx found
1380 in the location to substitute, this reload is not safe to combine
1381 because we cannot reliably tell whether it appears in the insn. */
1383 if (in != 0 && in != *inloc)
1384 rld[i].nocombine = 1;
1386 #if 0
1387 /* This was replaced by changes in find_reloads_address_1 and the new
1388 function inc_for_reload, which go with a new meaning of reload_inc. */
1390 /* If this is an IN/OUT reload in an insn that sets the CC,
1391 it must be for an autoincrement. It doesn't work to store
1392 the incremented value after the insn because that would clobber the CC.
1393 So we must do the increment of the value reloaded from,
1394 increment it, store it back, then decrement again. */
1395 if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
1397 out = 0;
1398 rld[i].out = 0;
1399 rld[i].inc = find_inc_amount (PATTERN (this_insn), in);
1400 /* If we did not find a nonzero amount-to-increment-by,
1401 that contradicts the belief that IN is being incremented
1402 in an address in this insn. */
1403 gcc_assert (rld[i].inc != 0);
1405 #endif
1407 /* If we will replace IN and OUT with the reload-reg,
1408 record where they are located so that substitution need
1409 not do a tree walk. */
1411 if (replace_reloads)
1413 if (inloc != 0)
1415 struct replacement *r = &replacements[n_replacements++];
1416 r->what = i;
1417 r->subreg_loc = in_subreg_loc;
1418 r->where = inloc;
1419 r->mode = inmode;
1421 if (outloc != 0 && outloc != inloc)
1423 struct replacement *r = &replacements[n_replacements++];
1424 r->what = i;
1425 r->where = outloc;
1426 r->subreg_loc = out_subreg_loc;
1427 r->mode = outmode;
1431 /* If this reload is just being introduced and it has both
1432 an incoming quantity and an outgoing quantity that are
1433 supposed to be made to match, see if either one of the two
1434 can serve as the place to reload into.
1436 If one of them is acceptable, set rld[i].reg_rtx
1437 to that one. */
1439 if (in != 0 && out != 0 && in != out && rld[i].reg_rtx == 0)
1441 rld[i].reg_rtx = find_dummy_reload (in, out, inloc, outloc,
1442 inmode, outmode,
1443 rld[i].class, i,
1444 earlyclobber_operand_p (out));
1446 /* If the outgoing register already contains the same value
1447 as the incoming one, we can dispense with loading it.
1448 The easiest way to tell the caller that is to give a phony
1449 value for the incoming operand (same as outgoing one). */
1450 if (rld[i].reg_rtx == out
1451 && (REG_P (in) || CONSTANT_P (in))
1452 && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
1453 static_reload_reg_p, i, inmode))
1454 rld[i].in = out;
1457 /* If this is an input reload and the operand contains a register that
1458 dies in this insn and is used nowhere else, see if it is the right class
1459 to be used for this reload. Use it if so. (This occurs most commonly
1460 in the case of paradoxical SUBREGs and in-out reloads). We cannot do
1461 this if it is also an output reload that mentions the register unless
1462 the output is a SUBREG that clobbers an entire register.
1464 Note that the operand might be one of the spill regs, if it is a
1465 pseudo reg and we are in a block where spilling has not taken place.
1466 But if there is no spilling in this block, that is OK.
1467 An explicitly used hard reg cannot be a spill reg. */
1469 if (rld[i].reg_rtx == 0 && in != 0 && hard_regs_live_known)
1471 rtx note;
1472 int regno;
1473 enum machine_mode rel_mode = inmode;
1475 if (out && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (inmode))
1476 rel_mode = outmode;
1478 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1479 if (REG_NOTE_KIND (note) == REG_DEAD
1480 && REG_P (XEXP (note, 0))
1481 && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1482 && reg_mentioned_p (XEXP (note, 0), in)
1483 /* Check that we don't use a hardreg for an uninitialized
1484 pseudo. See also find_dummy_reload(). */
1485 && (ORIGINAL_REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1486 || ! bitmap_bit_p (ENTRY_BLOCK_PTR->il.rtl->global_live_at_end,
1487 ORIGINAL_REGNO (XEXP (note, 0))))
1488 && ! refers_to_regno_for_reload_p (regno,
1489 (regno
1490 + hard_regno_nregs[regno]
1491 [rel_mode]),
1492 PATTERN (this_insn), inloc)
1493 /* If this is also an output reload, IN cannot be used as
1494 the reload register if it is set in this insn unless IN
1495 is also OUT. */
1496 && (out == 0 || in == out
1497 || ! hard_reg_set_here_p (regno,
1498 (regno
1499 + hard_regno_nregs[regno]
1500 [rel_mode]),
1501 PATTERN (this_insn)))
1502 /* ??? Why is this code so different from the previous?
1503 Is there any simple coherent way to describe the two together?
1504 What's going on here. */
1505 && (in != out
1506 || (GET_CODE (in) == SUBREG
1507 && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1))
1508 / UNITS_PER_WORD)
1509 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1510 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
1511 /* Make sure the operand fits in the reg that dies. */
1512 && (GET_MODE_SIZE (rel_mode)
1513 <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0))))
1514 && HARD_REGNO_MODE_OK (regno, inmode)
1515 && HARD_REGNO_MODE_OK (regno, outmode))
1517 unsigned int offs;
1518 unsigned int nregs = MAX (hard_regno_nregs[regno][inmode],
1519 hard_regno_nregs[regno][outmode]);
1521 for (offs = 0; offs < nregs; offs++)
1522 if (fixed_regs[regno + offs]
1523 || ! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1524 regno + offs))
1525 break;
1527 if (offs == nregs
1528 && (! (refers_to_regno_for_reload_p
1529 (regno, (regno + hard_regno_nregs[regno][inmode]),
1530 in, (rtx *)0))
1531 || can_reload_into (in, regno, inmode)))
1533 rld[i].reg_rtx = gen_rtx_REG (rel_mode, regno);
1534 break;
1539 if (out)
1540 output_reloadnum = i;
1542 return i;
1545 /* Record an additional place we must replace a value
1546 for which we have already recorded a reload.
1547 RELOADNUM is the value returned by push_reload
1548 when the reload was recorded.
1549 This is used in insn patterns that use match_dup. */
1551 static void
1552 push_replacement (rtx *loc, int reloadnum, enum machine_mode mode)
1554 if (replace_reloads)
1556 struct replacement *r = &replacements[n_replacements++];
1557 r->what = reloadnum;
1558 r->where = loc;
1559 r->subreg_loc = 0;
1560 r->mode = mode;
1564 /* Duplicate any replacement we have recorded to apply at
1565 location ORIG_LOC to also be performed at DUP_LOC.
1566 This is used in insn patterns that use match_dup. */
1568 static void
1569 dup_replacements (rtx *dup_loc, rtx *orig_loc)
1571 int i, n = n_replacements;
1573 for (i = 0; i < n; i++)
1575 struct replacement *r = &replacements[i];
1576 if (r->where == orig_loc)
1577 push_replacement (dup_loc, r->what, r->mode);
1581 /* Transfer all replacements that used to be in reload FROM to be in
1582 reload TO. */
1584 void
1585 transfer_replacements (int to, int from)
1587 int i;
1589 for (i = 0; i < n_replacements; i++)
1590 if (replacements[i].what == from)
1591 replacements[i].what = to;
1594 /* IN_RTX is the value loaded by a reload that we now decided to inherit,
1595 or a subpart of it. If we have any replacements registered for IN_RTX,
1596 cancel the reloads that were supposed to load them.
1597 Return nonzero if we canceled any reloads. */
1599 remove_address_replacements (rtx in_rtx)
1601 int i, j;
1602 char reload_flags[MAX_RELOADS];
1603 int something_changed = 0;
1605 memset (reload_flags, 0, sizeof reload_flags);
1606 for (i = 0, j = 0; i < n_replacements; i++)
1608 if (loc_mentioned_in_p (replacements[i].where, in_rtx))
1609 reload_flags[replacements[i].what] |= 1;
1610 else
1612 replacements[j++] = replacements[i];
1613 reload_flags[replacements[i].what] |= 2;
1616 /* Note that the following store must be done before the recursive calls. */
1617 n_replacements = j;
1619 for (i = n_reloads - 1; i >= 0; i--)
1621 if (reload_flags[i] == 1)
1623 deallocate_reload_reg (i);
1624 remove_address_replacements (rld[i].in);
1625 rld[i].in = 0;
1626 something_changed = 1;
1629 return something_changed;
1632 /* If there is only one output reload, and it is not for an earlyclobber
1633 operand, try to combine it with a (logically unrelated) input reload
1634 to reduce the number of reload registers needed.
1636 This is safe if the input reload does not appear in
1637 the value being output-reloaded, because this implies
1638 it is not needed any more once the original insn completes.
1640 If that doesn't work, see we can use any of the registers that
1641 die in this insn as a reload register. We can if it is of the right
1642 class and does not appear in the value being output-reloaded. */
1644 static void
1645 combine_reloads (void)
1647 int i;
1648 int output_reload = -1;
1649 int secondary_out = -1;
1650 rtx note;
1652 /* Find the output reload; return unless there is exactly one
1653 and that one is mandatory. */
1655 for (i = 0; i < n_reloads; i++)
1656 if (rld[i].out != 0)
1658 if (output_reload >= 0)
1659 return;
1660 output_reload = i;
1663 if (output_reload < 0 || rld[output_reload].optional)
1664 return;
1666 /* An input-output reload isn't combinable. */
1668 if (rld[output_reload].in != 0)
1669 return;
1671 /* If this reload is for an earlyclobber operand, we can't do anything. */
1672 if (earlyclobber_operand_p (rld[output_reload].out))
1673 return;
1675 /* If there is a reload for part of the address of this operand, we would
1676 need to chnage it to RELOAD_FOR_OTHER_ADDRESS. But that would extend
1677 its life to the point where doing this combine would not lower the
1678 number of spill registers needed. */
1679 for (i = 0; i < n_reloads; i++)
1680 if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
1681 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
1682 && rld[i].opnum == rld[output_reload].opnum)
1683 return;
1685 /* Check each input reload; can we combine it? */
1687 for (i = 0; i < n_reloads; i++)
1688 if (rld[i].in && ! rld[i].optional && ! rld[i].nocombine
1689 /* Life span of this reload must not extend past main insn. */
1690 && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS
1691 && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS
1692 && rld[i].when_needed != RELOAD_OTHER
1693 && (CLASS_MAX_NREGS (rld[i].class, rld[i].inmode)
1694 == CLASS_MAX_NREGS (rld[output_reload].class,
1695 rld[output_reload].outmode))
1696 && rld[i].inc == 0
1697 && rld[i].reg_rtx == 0
1698 #ifdef SECONDARY_MEMORY_NEEDED
1699 /* Don't combine two reloads with different secondary
1700 memory locations. */
1701 && (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum] == 0
1702 || secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] == 0
1703 || rtx_equal_p (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum],
1704 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum]))
1705 #endif
1706 && (SMALL_REGISTER_CLASSES
1707 ? (rld[i].class == rld[output_reload].class)
1708 : (reg_class_subset_p (rld[i].class,
1709 rld[output_reload].class)
1710 || reg_class_subset_p (rld[output_reload].class,
1711 rld[i].class)))
1712 && (MATCHES (rld[i].in, rld[output_reload].out)
1713 /* Args reversed because the first arg seems to be
1714 the one that we imagine being modified
1715 while the second is the one that might be affected. */
1716 || (! reg_overlap_mentioned_for_reload_p (rld[output_reload].out,
1717 rld[i].in)
1718 /* However, if the input is a register that appears inside
1719 the output, then we also can't share.
1720 Imagine (set (mem (reg 69)) (plus (reg 69) ...)).
1721 If the same reload reg is used for both reg 69 and the
1722 result to be stored in memory, then that result
1723 will clobber the address of the memory ref. */
1724 && ! (REG_P (rld[i].in)
1725 && reg_overlap_mentioned_for_reload_p (rld[i].in,
1726 rld[output_reload].out))))
1727 && ! reload_inner_reg_of_subreg (rld[i].in, rld[i].inmode,
1728 rld[i].when_needed != RELOAD_FOR_INPUT)
1729 && (reg_class_size[(int) rld[i].class]
1730 || SMALL_REGISTER_CLASSES)
1731 /* We will allow making things slightly worse by combining an
1732 input and an output, but no worse than that. */
1733 && (rld[i].when_needed == RELOAD_FOR_INPUT
1734 || rld[i].when_needed == RELOAD_FOR_OUTPUT))
1736 int j;
1738 /* We have found a reload to combine with! */
1739 rld[i].out = rld[output_reload].out;
1740 rld[i].out_reg = rld[output_reload].out_reg;
1741 rld[i].outmode = rld[output_reload].outmode;
1742 /* Mark the old output reload as inoperative. */
1743 rld[output_reload].out = 0;
1744 /* The combined reload is needed for the entire insn. */
1745 rld[i].when_needed = RELOAD_OTHER;
1746 /* If the output reload had a secondary reload, copy it. */
1747 if (rld[output_reload].secondary_out_reload != -1)
1749 rld[i].secondary_out_reload
1750 = rld[output_reload].secondary_out_reload;
1751 rld[i].secondary_out_icode
1752 = rld[output_reload].secondary_out_icode;
1755 #ifdef SECONDARY_MEMORY_NEEDED
1756 /* Copy any secondary MEM. */
1757 if (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] != 0)
1758 secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum]
1759 = secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum];
1760 #endif
1761 /* If required, minimize the register class. */
1762 if (reg_class_subset_p (rld[output_reload].class,
1763 rld[i].class))
1764 rld[i].class = rld[output_reload].class;
1766 /* Transfer all replacements from the old reload to the combined. */
1767 for (j = 0; j < n_replacements; j++)
1768 if (replacements[j].what == output_reload)
1769 replacements[j].what = i;
1771 return;
1774 /* If this insn has only one operand that is modified or written (assumed
1775 to be the first), it must be the one corresponding to this reload. It
1776 is safe to use anything that dies in this insn for that output provided
1777 that it does not occur in the output (we already know it isn't an
1778 earlyclobber. If this is an asm insn, give up. */
1780 if (INSN_CODE (this_insn) == -1)
1781 return;
1783 for (i = 1; i < insn_data[INSN_CODE (this_insn)].n_operands; i++)
1784 if (insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '='
1785 || insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '+')
1786 return;
1788 /* See if some hard register that dies in this insn and is not used in
1789 the output is the right class. Only works if the register we pick
1790 up can fully hold our output reload. */
1791 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1792 if (REG_NOTE_KIND (note) == REG_DEAD
1793 && REG_P (XEXP (note, 0))
1794 && ! reg_overlap_mentioned_for_reload_p (XEXP (note, 0),
1795 rld[output_reload].out)
1796 && REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1797 && HARD_REGNO_MODE_OK (REGNO (XEXP (note, 0)), rld[output_reload].outmode)
1798 && TEST_HARD_REG_BIT (reg_class_contents[(int) rld[output_reload].class],
1799 REGNO (XEXP (note, 0)))
1800 && (hard_regno_nregs[REGNO (XEXP (note, 0))][rld[output_reload].outmode]
1801 <= hard_regno_nregs[REGNO (XEXP (note, 0))][GET_MODE (XEXP (note, 0))])
1802 /* Ensure that a secondary or tertiary reload for this output
1803 won't want this register. */
1804 && ((secondary_out = rld[output_reload].secondary_out_reload) == -1
1805 || (! (TEST_HARD_REG_BIT
1806 (reg_class_contents[(int) rld[secondary_out].class],
1807 REGNO (XEXP (note, 0))))
1808 && ((secondary_out = rld[secondary_out].secondary_out_reload) == -1
1809 || ! (TEST_HARD_REG_BIT
1810 (reg_class_contents[(int) rld[secondary_out].class],
1811 REGNO (XEXP (note, 0)))))))
1812 && ! fixed_regs[REGNO (XEXP (note, 0))])
1814 rld[output_reload].reg_rtx
1815 = gen_rtx_REG (rld[output_reload].outmode,
1816 REGNO (XEXP (note, 0)));
1817 return;
1821 /* Try to find a reload register for an in-out reload (expressions IN and OUT).
1822 See if one of IN and OUT is a register that may be used;
1823 this is desirable since a spill-register won't be needed.
1824 If so, return the register rtx that proves acceptable.
1826 INLOC and OUTLOC are locations where IN and OUT appear in the insn.
1827 CLASS is the register class required for the reload.
1829 If FOR_REAL is >= 0, it is the number of the reload,
1830 and in some cases when it can be discovered that OUT doesn't need
1831 to be computed, clear out rld[FOR_REAL].out.
1833 If FOR_REAL is -1, this should not be done, because this call
1834 is just to see if a register can be found, not to find and install it.
1836 EARLYCLOBBER is nonzero if OUT is an earlyclobber operand. This
1837 puts an additional constraint on being able to use IN for OUT since
1838 IN must not appear elsewhere in the insn (it is assumed that IN itself
1839 is safe from the earlyclobber). */
1841 static rtx
1842 find_dummy_reload (rtx real_in, rtx real_out, rtx *inloc, rtx *outloc,
1843 enum machine_mode inmode, enum machine_mode outmode,
1844 enum reg_class class, int for_real, int earlyclobber)
1846 rtx in = real_in;
1847 rtx out = real_out;
1848 int in_offset = 0;
1849 int out_offset = 0;
1850 rtx value = 0;
1852 /* If operands exceed a word, we can't use either of them
1853 unless they have the same size. */
1854 if (GET_MODE_SIZE (outmode) != GET_MODE_SIZE (inmode)
1855 && (GET_MODE_SIZE (outmode) > UNITS_PER_WORD
1856 || GET_MODE_SIZE (inmode) > UNITS_PER_WORD))
1857 return 0;
1859 /* Note that {in,out}_offset are needed only when 'in' or 'out'
1860 respectively refers to a hard register. */
1862 /* Find the inside of any subregs. */
1863 while (GET_CODE (out) == SUBREG)
1865 if (REG_P (SUBREG_REG (out))
1866 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER)
1867 out_offset += subreg_regno_offset (REGNO (SUBREG_REG (out)),
1868 GET_MODE (SUBREG_REG (out)),
1869 SUBREG_BYTE (out),
1870 GET_MODE (out));
1871 out = SUBREG_REG (out);
1873 while (GET_CODE (in) == SUBREG)
1875 if (REG_P (SUBREG_REG (in))
1876 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER)
1877 in_offset += subreg_regno_offset (REGNO (SUBREG_REG (in)),
1878 GET_MODE (SUBREG_REG (in)),
1879 SUBREG_BYTE (in),
1880 GET_MODE (in));
1881 in = SUBREG_REG (in);
1884 /* Narrow down the reg class, the same way push_reload will;
1885 otherwise we might find a dummy now, but push_reload won't. */
1886 class = PREFERRED_RELOAD_CLASS (in, class);
1888 /* See if OUT will do. */
1889 if (REG_P (out)
1890 && REGNO (out) < FIRST_PSEUDO_REGISTER)
1892 unsigned int regno = REGNO (out) + out_offset;
1893 unsigned int nwords = hard_regno_nregs[regno][outmode];
1894 rtx saved_rtx;
1896 /* When we consider whether the insn uses OUT,
1897 ignore references within IN. They don't prevent us
1898 from copying IN into OUT, because those refs would
1899 move into the insn that reloads IN.
1901 However, we only ignore IN in its role as this reload.
1902 If the insn uses IN elsewhere and it contains OUT,
1903 that counts. We can't be sure it's the "same" operand
1904 so it might not go through this reload. */
1905 saved_rtx = *inloc;
1906 *inloc = const0_rtx;
1908 if (regno < FIRST_PSEUDO_REGISTER
1909 && HARD_REGNO_MODE_OK (regno, outmode)
1910 && ! refers_to_regno_for_reload_p (regno, regno + nwords,
1911 PATTERN (this_insn), outloc))
1913 unsigned int i;
1915 for (i = 0; i < nwords; i++)
1916 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1917 regno + i))
1918 break;
1920 if (i == nwords)
1922 if (REG_P (real_out))
1923 value = real_out;
1924 else
1925 value = gen_rtx_REG (outmode, regno);
1929 *inloc = saved_rtx;
1932 /* Consider using IN if OUT was not acceptable
1933 or if OUT dies in this insn (like the quotient in a divmod insn).
1934 We can't use IN unless it is dies in this insn,
1935 which means we must know accurately which hard regs are live.
1936 Also, the result can't go in IN if IN is used within OUT,
1937 or if OUT is an earlyclobber and IN appears elsewhere in the insn. */
1938 if (hard_regs_live_known
1939 && REG_P (in)
1940 && REGNO (in) < FIRST_PSEUDO_REGISTER
1941 && (value == 0
1942 || find_reg_note (this_insn, REG_UNUSED, real_out))
1943 && find_reg_note (this_insn, REG_DEAD, real_in)
1944 && !fixed_regs[REGNO (in)]
1945 && HARD_REGNO_MODE_OK (REGNO (in),
1946 /* The only case where out and real_out might
1947 have different modes is where real_out
1948 is a subreg, and in that case, out
1949 has a real mode. */
1950 (GET_MODE (out) != VOIDmode
1951 ? GET_MODE (out) : outmode))
1952 /* But only do all this if we can be sure, that this input
1953 operand doesn't correspond with an uninitialized pseudoreg.
1954 global can assign some hardreg to it, which is the same as
1955 a different pseudo also currently live (as it can ignore the
1956 conflict). So we never must introduce writes to such hardregs,
1957 as they would clobber the other live pseudo using the same.
1958 See also PR20973. */
1959 && (ORIGINAL_REGNO (in) < FIRST_PSEUDO_REGISTER
1960 || ! bitmap_bit_p (ENTRY_BLOCK_PTR->il.rtl->global_live_at_end,
1961 ORIGINAL_REGNO (in))))
1963 unsigned int regno = REGNO (in) + in_offset;
1964 unsigned int nwords = hard_regno_nregs[regno][inmode];
1966 if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, (rtx*) 0)
1967 && ! hard_reg_set_here_p (regno, regno + nwords,
1968 PATTERN (this_insn))
1969 && (! earlyclobber
1970 || ! refers_to_regno_for_reload_p (regno, regno + nwords,
1971 PATTERN (this_insn), inloc)))
1973 unsigned int i;
1975 for (i = 0; i < nwords; i++)
1976 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1977 regno + i))
1978 break;
1980 if (i == nwords)
1982 /* If we were going to use OUT as the reload reg
1983 and changed our mind, it means OUT is a dummy that
1984 dies here. So don't bother copying value to it. */
1985 if (for_real >= 0 && value == real_out)
1986 rld[for_real].out = 0;
1987 if (REG_P (real_in))
1988 value = real_in;
1989 else
1990 value = gen_rtx_REG (inmode, regno);
1995 return value;
1998 /* This page contains subroutines used mainly for determining
1999 whether the IN or an OUT of a reload can serve as the
2000 reload register. */
2002 /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
2005 earlyclobber_operand_p (rtx x)
2007 int i;
2009 for (i = 0; i < n_earlyclobbers; i++)
2010 if (reload_earlyclobbers[i] == x)
2011 return 1;
2013 return 0;
2016 /* Return 1 if expression X alters a hard reg in the range
2017 from BEG_REGNO (inclusive) to END_REGNO (exclusive),
2018 either explicitly or in the guise of a pseudo-reg allocated to REGNO.
2019 X should be the body of an instruction. */
2021 static int
2022 hard_reg_set_here_p (unsigned int beg_regno, unsigned int end_regno, rtx x)
2024 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
2026 rtx op0 = SET_DEST (x);
2028 while (GET_CODE (op0) == SUBREG)
2029 op0 = SUBREG_REG (op0);
2030 if (REG_P (op0))
2032 unsigned int r = REGNO (op0);
2034 /* See if this reg overlaps range under consideration. */
2035 if (r < end_regno
2036 && r + hard_regno_nregs[r][GET_MODE (op0)] > beg_regno)
2037 return 1;
2040 else if (GET_CODE (x) == PARALLEL)
2042 int i = XVECLEN (x, 0) - 1;
2044 for (; i >= 0; i--)
2045 if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i)))
2046 return 1;
2049 return 0;
2052 /* Return 1 if ADDR is a valid memory address for mode MODE,
2053 and check that each pseudo reg has the proper kind of
2054 hard reg. */
2057 strict_memory_address_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx addr)
2059 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
2060 return 0;
2062 win:
2063 return 1;
2066 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
2067 if they are the same hard reg, and has special hacks for
2068 autoincrement and autodecrement.
2069 This is specifically intended for find_reloads to use
2070 in determining whether two operands match.
2071 X is the operand whose number is the lower of the two.
2073 The value is 2 if Y contains a pre-increment that matches
2074 a non-incrementing address in X. */
2076 /* ??? To be completely correct, we should arrange to pass
2077 for X the output operand and for Y the input operand.
2078 For now, we assume that the output operand has the lower number
2079 because that is natural in (SET output (... input ...)). */
2082 operands_match_p (rtx x, rtx y)
2084 int i;
2085 RTX_CODE code = GET_CODE (x);
2086 const char *fmt;
2087 int success_2;
2089 if (x == y)
2090 return 1;
2091 if ((code == REG || (code == SUBREG && REG_P (SUBREG_REG (x))))
2092 && (REG_P (y) || (GET_CODE (y) == SUBREG
2093 && REG_P (SUBREG_REG (y)))))
2095 int j;
2097 if (code == SUBREG)
2099 i = REGNO (SUBREG_REG (x));
2100 if (i >= FIRST_PSEUDO_REGISTER)
2101 goto slow;
2102 i += subreg_regno_offset (REGNO (SUBREG_REG (x)),
2103 GET_MODE (SUBREG_REG (x)),
2104 SUBREG_BYTE (x),
2105 GET_MODE (x));
2107 else
2108 i = REGNO (x);
2110 if (GET_CODE (y) == SUBREG)
2112 j = REGNO (SUBREG_REG (y));
2113 if (j >= FIRST_PSEUDO_REGISTER)
2114 goto slow;
2115 j += subreg_regno_offset (REGNO (SUBREG_REG (y)),
2116 GET_MODE (SUBREG_REG (y)),
2117 SUBREG_BYTE (y),
2118 GET_MODE (y));
2120 else
2121 j = REGNO (y);
2123 /* On a WORDS_BIG_ENDIAN machine, point to the last register of a
2124 multiple hard register group of scalar integer registers, so that
2125 for example (reg:DI 0) and (reg:SI 1) will be considered the same
2126 register. */
2127 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
2128 && SCALAR_INT_MODE_P (GET_MODE (x))
2129 && i < FIRST_PSEUDO_REGISTER)
2130 i += hard_regno_nregs[i][GET_MODE (x)] - 1;
2131 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD
2132 && SCALAR_INT_MODE_P (GET_MODE (y))
2133 && j < FIRST_PSEUDO_REGISTER)
2134 j += hard_regno_nregs[j][GET_MODE (y)] - 1;
2136 return i == j;
2138 /* If two operands must match, because they are really a single
2139 operand of an assembler insn, then two postincrements are invalid
2140 because the assembler insn would increment only once.
2141 On the other hand, a postincrement matches ordinary indexing
2142 if the postincrement is the output operand. */
2143 if (code == POST_DEC || code == POST_INC || code == POST_MODIFY)
2144 return operands_match_p (XEXP (x, 0), y);
2145 /* Two preincrements are invalid
2146 because the assembler insn would increment only once.
2147 On the other hand, a preincrement matches ordinary indexing
2148 if the preincrement is the input operand.
2149 In this case, return 2, since some callers need to do special
2150 things when this happens. */
2151 if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC
2152 || GET_CODE (y) == PRE_MODIFY)
2153 return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
2155 slow:
2157 /* Now we have disposed of all the cases in which different rtx codes
2158 can match. */
2159 if (code != GET_CODE (y))
2160 return 0;
2162 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
2163 if (GET_MODE (x) != GET_MODE (y))
2164 return 0;
2166 switch (code)
2168 case CONST_INT:
2169 case CONST_DOUBLE:
2170 return 0;
2172 case LABEL_REF:
2173 return XEXP (x, 0) == XEXP (y, 0);
2174 case SYMBOL_REF:
2175 return XSTR (x, 0) == XSTR (y, 0);
2177 default:
2178 break;
2181 /* Compare the elements. If any pair of corresponding elements
2182 fail to match, return 0 for the whole things. */
2184 success_2 = 0;
2185 fmt = GET_RTX_FORMAT (code);
2186 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2188 int val, j;
2189 switch (fmt[i])
2191 case 'w':
2192 if (XWINT (x, i) != XWINT (y, i))
2193 return 0;
2194 break;
2196 case 'i':
2197 if (XINT (x, i) != XINT (y, i))
2198 return 0;
2199 break;
2201 case 'e':
2202 val = operands_match_p (XEXP (x, i), XEXP (y, i));
2203 if (val == 0)
2204 return 0;
2205 /* If any subexpression returns 2,
2206 we should return 2 if we are successful. */
2207 if (val == 2)
2208 success_2 = 1;
2209 break;
2211 case '0':
2212 break;
2214 case 'E':
2215 if (XVECLEN (x, i) != XVECLEN (y, i))
2216 return 0;
2217 for (j = XVECLEN (x, i) - 1; j >= 0; --j)
2219 val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j));
2220 if (val == 0)
2221 return 0;
2222 if (val == 2)
2223 success_2 = 1;
2225 break;
2227 /* It is believed that rtx's at this level will never
2228 contain anything but integers and other rtx's,
2229 except for within LABEL_REFs and SYMBOL_REFs. */
2230 default:
2231 gcc_unreachable ();
2234 return 1 + success_2;
2237 /* Describe the range of registers or memory referenced by X.
2238 If X is a register, set REG_FLAG and put the first register
2239 number into START and the last plus one into END.
2240 If X is a memory reference, put a base address into BASE
2241 and a range of integer offsets into START and END.
2242 If X is pushing on the stack, we can assume it causes no trouble,
2243 so we set the SAFE field. */
2245 static struct decomposition
2246 decompose (rtx x)
2248 struct decomposition val;
2249 int all_const = 0;
2251 memset (&val, 0, sizeof (val));
2253 switch (GET_CODE (x))
2255 case MEM:
2257 rtx base = NULL_RTX, offset = 0;
2258 rtx addr = XEXP (x, 0);
2260 if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
2261 || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
2263 val.base = XEXP (addr, 0);
2264 val.start = -GET_MODE_SIZE (GET_MODE (x));
2265 val.end = GET_MODE_SIZE (GET_MODE (x));
2266 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2267 return val;
2270 if (GET_CODE (addr) == PRE_MODIFY || GET_CODE (addr) == POST_MODIFY)
2272 if (GET_CODE (XEXP (addr, 1)) == PLUS
2273 && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
2274 && CONSTANT_P (XEXP (XEXP (addr, 1), 1)))
2276 val.base = XEXP (addr, 0);
2277 val.start = -INTVAL (XEXP (XEXP (addr, 1), 1));
2278 val.end = INTVAL (XEXP (XEXP (addr, 1), 1));
2279 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
2280 return val;
2284 if (GET_CODE (addr) == CONST)
2286 addr = XEXP (addr, 0);
2287 all_const = 1;
2289 if (GET_CODE (addr) == PLUS)
2291 if (CONSTANT_P (XEXP (addr, 0)))
2293 base = XEXP (addr, 1);
2294 offset = XEXP (addr, 0);
2296 else if (CONSTANT_P (XEXP (addr, 1)))
2298 base = XEXP (addr, 0);
2299 offset = XEXP (addr, 1);
2303 if (offset == 0)
2305 base = addr;
2306 offset = const0_rtx;
2308 if (GET_CODE (offset) == CONST)
2309 offset = XEXP (offset, 0);
2310 if (GET_CODE (offset) == PLUS)
2312 if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
2314 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 1));
2315 offset = XEXP (offset, 0);
2317 else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
2319 base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 0));
2320 offset = XEXP (offset, 1);
2322 else
2324 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2325 offset = const0_rtx;
2328 else if (GET_CODE (offset) != CONST_INT)
2330 base = gen_rtx_PLUS (GET_MODE (base), base, offset);
2331 offset = const0_rtx;
2334 if (all_const && GET_CODE (base) == PLUS)
2335 base = gen_rtx_CONST (GET_MODE (base), base);
2337 gcc_assert (GET_CODE (offset) == CONST_INT);
2339 val.start = INTVAL (offset);
2340 val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
2341 val.base = base;
2343 break;
2345 case REG:
2346 val.reg_flag = 1;
2347 val.start = true_regnum (x);
2348 if (val.start < 0 || val.start >= FIRST_PSEUDO_REGISTER)
2350 /* A pseudo with no hard reg. */
2351 val.start = REGNO (x);
2352 val.end = val.start + 1;
2354 else
2355 /* A hard reg. */
2356 val.end = val.start + hard_regno_nregs[val.start][GET_MODE (x)];
2357 break;
2359 case SUBREG:
2360 if (!REG_P (SUBREG_REG (x)))
2361 /* This could be more precise, but it's good enough. */
2362 return decompose (SUBREG_REG (x));
2363 val.reg_flag = 1;
2364 val.start = true_regnum (x);
2365 if (val.start < 0 || val.start >= FIRST_PSEUDO_REGISTER)
2366 return decompose (SUBREG_REG (x));
2367 else
2368 /* A hard reg. */
2369 val.end = val.start + hard_regno_nregs[val.start][GET_MODE (x)];
2370 break;
2372 case SCRATCH:
2373 /* This hasn't been assigned yet, so it can't conflict yet. */
2374 val.safe = 1;
2375 break;
2377 default:
2378 gcc_assert (CONSTANT_P (x));
2379 val.safe = 1;
2380 break;
2382 return val;
2385 /* Return 1 if altering Y will not modify the value of X.
2386 Y is also described by YDATA, which should be decompose (Y). */
2388 static int
2389 immune_p (rtx x, rtx y, struct decomposition ydata)
2391 struct decomposition xdata;
2393 if (ydata.reg_flag)
2394 return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, (rtx*) 0);
2395 if (ydata.safe)
2396 return 1;
2398 gcc_assert (MEM_P (y));
2399 /* If Y is memory and X is not, Y can't affect X. */
2400 if (!MEM_P (x))
2401 return 1;
2403 xdata = decompose (x);
2405 if (! rtx_equal_p (xdata.base, ydata.base))
2407 /* If bases are distinct symbolic constants, there is no overlap. */
2408 if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
2409 return 1;
2410 /* Constants and stack slots never overlap. */
2411 if (CONSTANT_P (xdata.base)
2412 && (ydata.base == frame_pointer_rtx
2413 || ydata.base == hard_frame_pointer_rtx
2414 || ydata.base == stack_pointer_rtx))
2415 return 1;
2416 if (CONSTANT_P (ydata.base)
2417 && (xdata.base == frame_pointer_rtx
2418 || xdata.base == hard_frame_pointer_rtx
2419 || xdata.base == stack_pointer_rtx))
2420 return 1;
2421 /* If either base is variable, we don't know anything. */
2422 return 0;
2425 return (xdata.start >= ydata.end || ydata.start >= xdata.end);
2428 /* Similar, but calls decompose. */
2431 safe_from_earlyclobber (rtx op, rtx clobber)
2433 struct decomposition early_data;
2435 early_data = decompose (clobber);
2436 return immune_p (op, clobber, early_data);
2439 /* Main entry point of this file: search the body of INSN
2440 for values that need reloading and record them with push_reload.
2441 REPLACE nonzero means record also where the values occur
2442 so that subst_reloads can be used.
2444 IND_LEVELS says how many levels of indirection are supported by this
2445 machine; a value of zero means that a memory reference is not a valid
2446 memory address.
2448 LIVE_KNOWN says we have valid information about which hard
2449 regs are live at each point in the program; this is true when
2450 we are called from global_alloc but false when stupid register
2451 allocation has been done.
2453 RELOAD_REG_P if nonzero is a vector indexed by hard reg number
2454 which is nonnegative if the reg has been commandeered for reloading into.
2455 It is copied into STATIC_RELOAD_REG_P and referenced from there
2456 by various subroutines.
2458 Return TRUE if some operands need to be changed, because of swapping
2459 commutative operands, reg_equiv_address substitution, or whatever. */
2462 find_reloads (rtx insn, int replace, int ind_levels, int live_known,
2463 short *reload_reg_p)
2465 int insn_code_number;
2466 int i, j;
2467 int noperands;
2468 /* These start out as the constraints for the insn
2469 and they are chewed up as we consider alternatives. */
2470 char *constraints[MAX_RECOG_OPERANDS];
2471 /* These are the preferred classes for an operand, or NO_REGS if it isn't
2472 a register. */
2473 enum reg_class preferred_class[MAX_RECOG_OPERANDS];
2474 char pref_or_nothing[MAX_RECOG_OPERANDS];
2475 /* Nonzero for a MEM operand whose entire address needs a reload.
2476 May be -1 to indicate the entire address may or may not need a reload. */
2477 int address_reloaded[MAX_RECOG_OPERANDS];
2478 /* Nonzero for an address operand that needs to be completely reloaded.
2479 May be -1 to indicate the entire operand may or may not need a reload. */
2480 int address_operand_reloaded[MAX_RECOG_OPERANDS];
2481 /* Value of enum reload_type to use for operand. */
2482 enum reload_type operand_type[MAX_RECOG_OPERANDS];
2483 /* Value of enum reload_type to use within address of operand. */
2484 enum reload_type address_type[MAX_RECOG_OPERANDS];
2485 /* Save the usage of each operand. */
2486 enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS];
2487 int no_input_reloads = 0, no_output_reloads = 0;
2488 int n_alternatives;
2489 int this_alternative[MAX_RECOG_OPERANDS];
2490 char this_alternative_match_win[MAX_RECOG_OPERANDS];
2491 char this_alternative_win[MAX_RECOG_OPERANDS];
2492 char this_alternative_offmemok[MAX_RECOG_OPERANDS];
2493 char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2494 int this_alternative_matches[MAX_RECOG_OPERANDS];
2495 int swapped;
2496 int goal_alternative[MAX_RECOG_OPERANDS];
2497 int this_alternative_number;
2498 int goal_alternative_number = 0;
2499 int operand_reloadnum[MAX_RECOG_OPERANDS];
2500 int goal_alternative_matches[MAX_RECOG_OPERANDS];
2501 int goal_alternative_matched[MAX_RECOG_OPERANDS];
2502 char goal_alternative_match_win[MAX_RECOG_OPERANDS];
2503 char goal_alternative_win[MAX_RECOG_OPERANDS];
2504 char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
2505 char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
2506 int goal_alternative_swapped;
2507 int best;
2508 int commutative;
2509 char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
2510 rtx substed_operand[MAX_RECOG_OPERANDS];
2511 rtx body = PATTERN (insn);
2512 rtx set = single_set (insn);
2513 int goal_earlyclobber = 0, this_earlyclobber;
2514 enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
2515 int retval = 0;
2517 this_insn = insn;
2518 n_reloads = 0;
2519 n_replacements = 0;
2520 n_earlyclobbers = 0;
2521 replace_reloads = replace;
2522 hard_regs_live_known = live_known;
2523 static_reload_reg_p = reload_reg_p;
2525 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
2526 neither are insns that SET cc0. Insns that use CC0 are not allowed
2527 to have any input reloads. */
2528 if (JUMP_P (insn) || CALL_P (insn))
2529 no_output_reloads = 1;
2531 #ifdef HAVE_cc0
2532 if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
2533 no_input_reloads = 1;
2534 if (reg_set_p (cc0_rtx, PATTERN (insn)))
2535 no_output_reloads = 1;
2536 #endif
2538 #ifdef SECONDARY_MEMORY_NEEDED
2539 /* The eliminated forms of any secondary memory locations are per-insn, so
2540 clear them out here. */
2542 if (secondary_memlocs_elim_used)
2544 memset (secondary_memlocs_elim, 0,
2545 sizeof (secondary_memlocs_elim[0]) * secondary_memlocs_elim_used);
2546 secondary_memlocs_elim_used = 0;
2548 #endif
2550 /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2551 is cheap to move between them. If it is not, there may not be an insn
2552 to do the copy, so we may need a reload. */
2553 if (GET_CODE (body) == SET
2554 && REG_P (SET_DEST (body))
2555 && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2556 && REG_P (SET_SRC (body))
2557 && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2558 && REGISTER_MOVE_COST (GET_MODE (SET_SRC (body)),
2559 REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2560 REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2561 return 0;
2563 extract_insn (insn);
2565 noperands = reload_n_operands = recog_data.n_operands;
2566 n_alternatives = recog_data.n_alternatives;
2568 /* Just return "no reloads" if insn has no operands with constraints. */
2569 if (noperands == 0 || n_alternatives == 0)
2570 return 0;
2572 insn_code_number = INSN_CODE (insn);
2573 this_insn_is_asm = insn_code_number < 0;
2575 memcpy (operand_mode, recog_data.operand_mode,
2576 noperands * sizeof (enum machine_mode));
2577 memcpy (constraints, recog_data.constraints, noperands * sizeof (char *));
2579 commutative = -1;
2581 /* If we will need to know, later, whether some pair of operands
2582 are the same, we must compare them now and save the result.
2583 Reloading the base and index registers will clobber them
2584 and afterward they will fail to match. */
2586 for (i = 0; i < noperands; i++)
2588 char *p;
2589 int c;
2591 substed_operand[i] = recog_data.operand[i];
2592 p = constraints[i];
2594 modified[i] = RELOAD_READ;
2596 /* Scan this operand's constraint to see if it is an output operand,
2597 an in-out operand, is commutative, or should match another. */
2599 while ((c = *p))
2601 p += CONSTRAINT_LEN (c, p);
2602 switch (c)
2604 case '=':
2605 modified[i] = RELOAD_WRITE;
2606 break;
2607 case '+':
2608 modified[i] = RELOAD_READ_WRITE;
2609 break;
2610 case '%':
2612 /* The last operand should not be marked commutative. */
2613 gcc_assert (i != noperands - 1);
2615 /* We currently only support one commutative pair of
2616 operands. Some existing asm code currently uses more
2617 than one pair. Previously, that would usually work,
2618 but sometimes it would crash the compiler. We
2619 continue supporting that case as well as we can by
2620 silently ignoring all but the first pair. In the
2621 future we may handle it correctly. */
2622 if (commutative < 0)
2623 commutative = i;
2624 else
2625 gcc_assert (this_insn_is_asm);
2627 break;
2628 /* Use of ISDIGIT is tempting here, but it may get expensive because
2629 of locale support we don't want. */
2630 case '0': case '1': case '2': case '3': case '4':
2631 case '5': case '6': case '7': case '8': case '9':
2633 c = strtoul (p - 1, &p, 10);
2635 operands_match[c][i]
2636 = operands_match_p (recog_data.operand[c],
2637 recog_data.operand[i]);
2639 /* An operand may not match itself. */
2640 gcc_assert (c != i);
2642 /* If C can be commuted with C+1, and C might need to match I,
2643 then C+1 might also need to match I. */
2644 if (commutative >= 0)
2646 if (c == commutative || c == commutative + 1)
2648 int other = c + (c == commutative ? 1 : -1);
2649 operands_match[other][i]
2650 = operands_match_p (recog_data.operand[other],
2651 recog_data.operand[i]);
2653 if (i == commutative || i == commutative + 1)
2655 int other = i + (i == commutative ? 1 : -1);
2656 operands_match[c][other]
2657 = operands_match_p (recog_data.operand[c],
2658 recog_data.operand[other]);
2660 /* Note that C is supposed to be less than I.
2661 No need to consider altering both C and I because in
2662 that case we would alter one into the other. */
2669 /* Examine each operand that is a memory reference or memory address
2670 and reload parts of the addresses into index registers.
2671 Also here any references to pseudo regs that didn't get hard regs
2672 but are equivalent to constants get replaced in the insn itself
2673 with those constants. Nobody will ever see them again.
2675 Finally, set up the preferred classes of each operand. */
2677 for (i = 0; i < noperands; i++)
2679 RTX_CODE code = GET_CODE (recog_data.operand[i]);
2681 address_reloaded[i] = 0;
2682 address_operand_reloaded[i] = 0;
2683 operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT
2684 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT
2685 : RELOAD_OTHER);
2686 address_type[i]
2687 = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS
2688 : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS
2689 : RELOAD_OTHER);
2691 if (*constraints[i] == 0)
2692 /* Ignore things like match_operator operands. */
2694 else if (constraints[i][0] == 'p'
2695 || EXTRA_ADDRESS_CONSTRAINT (constraints[i][0], constraints[i]))
2697 address_operand_reloaded[i]
2698 = find_reloads_address (recog_data.operand_mode[i], (rtx*) 0,
2699 recog_data.operand[i],
2700 recog_data.operand_loc[i],
2701 i, operand_type[i], ind_levels, insn);
2703 /* If we now have a simple operand where we used to have a
2704 PLUS or MULT, re-recognize and try again. */
2705 if ((OBJECT_P (*recog_data.operand_loc[i])
2706 || GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
2707 && (GET_CODE (recog_data.operand[i]) == MULT
2708 || GET_CODE (recog_data.operand[i]) == PLUS))
2710 INSN_CODE (insn) = -1;
2711 retval = find_reloads (insn, replace, ind_levels, live_known,
2712 reload_reg_p);
2713 return retval;
2716 recog_data.operand[i] = *recog_data.operand_loc[i];
2717 substed_operand[i] = recog_data.operand[i];
2719 /* Address operands are reloaded in their existing mode,
2720 no matter what is specified in the machine description. */
2721 operand_mode[i] = GET_MODE (recog_data.operand[i]);
2723 else if (code == MEM)
2725 address_reloaded[i]
2726 = find_reloads_address (GET_MODE (recog_data.operand[i]),
2727 recog_data.operand_loc[i],
2728 XEXP (recog_data.operand[i], 0),
2729 &XEXP (recog_data.operand[i], 0),
2730 i, address_type[i], ind_levels, insn);
2731 recog_data.operand[i] = *recog_data.operand_loc[i];
2732 substed_operand[i] = recog_data.operand[i];
2734 else if (code == SUBREG)
2736 rtx reg = SUBREG_REG (recog_data.operand[i]);
2737 rtx op
2738 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2739 ind_levels,
2740 set != 0
2741 && &SET_DEST (set) == recog_data.operand_loc[i],
2742 insn,
2743 &address_reloaded[i]);
2745 /* If we made a MEM to load (a part of) the stackslot of a pseudo
2746 that didn't get a hard register, emit a USE with a REG_EQUAL
2747 note in front so that we might inherit a previous, possibly
2748 wider reload. */
2750 if (replace
2751 && MEM_P (op)
2752 && REG_P (reg)
2753 && (GET_MODE_SIZE (GET_MODE (reg))
2754 >= GET_MODE_SIZE (GET_MODE (op))))
2755 set_unique_reg_note (emit_insn_before (gen_rtx_USE (VOIDmode, reg),
2756 insn),
2757 REG_EQUAL, reg_equiv_memory_loc[REGNO (reg)]);
2759 substed_operand[i] = recog_data.operand[i] = op;
2761 else if (code == PLUS || GET_RTX_CLASS (code) == RTX_UNARY)
2762 /* We can get a PLUS as an "operand" as a result of register
2763 elimination. See eliminate_regs and gen_reload. We handle
2764 a unary operator by reloading the operand. */
2765 substed_operand[i] = recog_data.operand[i]
2766 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2767 ind_levels, 0, insn,
2768 &address_reloaded[i]);
2769 else if (code == REG)
2771 /* This is equivalent to calling find_reloads_toplev.
2772 The code is duplicated for speed.
2773 When we find a pseudo always equivalent to a constant,
2774 we replace it by the constant. We must be sure, however,
2775 that we don't try to replace it in the insn in which it
2776 is being set. */
2777 int regno = REGNO (recog_data.operand[i]);
2778 if (reg_equiv_constant[regno] != 0
2779 && (set == 0 || &SET_DEST (set) != recog_data.operand_loc[i]))
2781 /* Record the existing mode so that the check if constants are
2782 allowed will work when operand_mode isn't specified. */
2784 if (operand_mode[i] == VOIDmode)
2785 operand_mode[i] = GET_MODE (recog_data.operand[i]);
2787 substed_operand[i] = recog_data.operand[i]
2788 = reg_equiv_constant[regno];
2790 if (reg_equiv_memory_loc[regno] != 0
2791 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
2792 /* We need not give a valid is_set_dest argument since the case
2793 of a constant equivalence was checked above. */
2794 substed_operand[i] = recog_data.operand[i]
2795 = find_reloads_toplev (recog_data.operand[i], i, address_type[i],
2796 ind_levels, 0, insn,
2797 &address_reloaded[i]);
2799 /* If the operand is still a register (we didn't replace it with an
2800 equivalent), get the preferred class to reload it into. */
2801 code = GET_CODE (recog_data.operand[i]);
2802 preferred_class[i]
2803 = ((code == REG && REGNO (recog_data.operand[i])
2804 >= FIRST_PSEUDO_REGISTER)
2805 ? reg_preferred_class (REGNO (recog_data.operand[i]))
2806 : NO_REGS);
2807 pref_or_nothing[i]
2808 = (code == REG
2809 && REGNO (recog_data.operand[i]) >= FIRST_PSEUDO_REGISTER
2810 && reg_alternate_class (REGNO (recog_data.operand[i])) == NO_REGS);
2813 /* If this is simply a copy from operand 1 to operand 0, merge the
2814 preferred classes for the operands. */
2815 if (set != 0 && noperands >= 2 && recog_data.operand[0] == SET_DEST (set)
2816 && recog_data.operand[1] == SET_SRC (set))
2818 preferred_class[0] = preferred_class[1]
2819 = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2820 pref_or_nothing[0] |= pref_or_nothing[1];
2821 pref_or_nothing[1] |= pref_or_nothing[0];
2824 /* Now see what we need for pseudo-regs that didn't get hard regs
2825 or got the wrong kind of hard reg. For this, we must consider
2826 all the operands together against the register constraints. */
2828 best = MAX_RECOG_OPERANDS * 2 + 600;
2830 swapped = 0;
2831 goal_alternative_swapped = 0;
2832 try_swapped:
2834 /* The constraints are made of several alternatives.
2835 Each operand's constraint looks like foo,bar,... with commas
2836 separating the alternatives. The first alternatives for all
2837 operands go together, the second alternatives go together, etc.
2839 First loop over alternatives. */
2841 for (this_alternative_number = 0;
2842 this_alternative_number < n_alternatives;
2843 this_alternative_number++)
2845 /* Loop over operands for one constraint alternative. */
2846 /* LOSERS counts those that don't fit this alternative
2847 and would require loading. */
2848 int losers = 0;
2849 /* BAD is set to 1 if it some operand can't fit this alternative
2850 even after reloading. */
2851 int bad = 0;
2852 /* REJECT is a count of how undesirable this alternative says it is
2853 if any reloading is required. If the alternative matches exactly
2854 then REJECT is ignored, but otherwise it gets this much
2855 counted against it in addition to the reloading needed. Each
2856 ? counts three times here since we want the disparaging caused by
2857 a bad register class to only count 1/3 as much. */
2858 int reject = 0;
2860 this_earlyclobber = 0;
2862 for (i = 0; i < noperands; i++)
2864 char *p = constraints[i];
2865 char *end;
2866 int len;
2867 int win = 0;
2868 int did_match = 0;
2869 /* 0 => this operand can be reloaded somehow for this alternative. */
2870 int badop = 1;
2871 /* 0 => this operand can be reloaded if the alternative allows regs. */
2872 int winreg = 0;
2873 int c;
2874 int m;
2875 rtx operand = recog_data.operand[i];
2876 int offset = 0;
2877 /* Nonzero means this is a MEM that must be reloaded into a reg
2878 regardless of what the constraint says. */
2879 int force_reload = 0;
2880 int offmemok = 0;
2881 /* Nonzero if a constant forced into memory would be OK for this
2882 operand. */
2883 int constmemok = 0;
2884 int earlyclobber = 0;
2886 /* If the predicate accepts a unary operator, it means that
2887 we need to reload the operand, but do not do this for
2888 match_operator and friends. */
2889 if (UNARY_P (operand) && *p != 0)
2890 operand = XEXP (operand, 0);
2892 /* If the operand is a SUBREG, extract
2893 the REG or MEM (or maybe even a constant) within.
2894 (Constants can occur as a result of reg_equiv_constant.) */
2896 while (GET_CODE (operand) == SUBREG)
2898 /* Offset only matters when operand is a REG and
2899 it is a hard reg. This is because it is passed
2900 to reg_fits_class_p if it is a REG and all pseudos
2901 return 0 from that function. */
2902 if (REG_P (SUBREG_REG (operand))
2903 && REGNO (SUBREG_REG (operand)) < FIRST_PSEUDO_REGISTER)
2905 if (!subreg_offset_representable_p
2906 (REGNO (SUBREG_REG (operand)),
2907 GET_MODE (SUBREG_REG (operand)),
2908 SUBREG_BYTE (operand),
2909 GET_MODE (operand)))
2910 force_reload = 1;
2911 offset += subreg_regno_offset (REGNO (SUBREG_REG (operand)),
2912 GET_MODE (SUBREG_REG (operand)),
2913 SUBREG_BYTE (operand),
2914 GET_MODE (operand));
2916 operand = SUBREG_REG (operand);
2917 /* Force reload if this is a constant or PLUS or if there may
2918 be a problem accessing OPERAND in the outer mode. */
2919 if (CONSTANT_P (operand)
2920 || GET_CODE (operand) == PLUS
2921 /* We must force a reload of paradoxical SUBREGs
2922 of a MEM because the alignment of the inner value
2923 may not be enough to do the outer reference. On
2924 big-endian machines, it may also reference outside
2925 the object.
2927 On machines that extend byte operations and we have a
2928 SUBREG where both the inner and outer modes are no wider
2929 than a word and the inner mode is narrower, is integral,
2930 and gets extended when loaded from memory, combine.c has
2931 made assumptions about the behavior of the machine in such
2932 register access. If the data is, in fact, in memory we
2933 must always load using the size assumed to be in the
2934 register and let the insn do the different-sized
2935 accesses.
2937 This is doubly true if WORD_REGISTER_OPERATIONS. In
2938 this case eliminate_regs has left non-paradoxical
2939 subregs for push_reload to see. Make sure it does
2940 by forcing the reload.
2942 ??? When is it right at this stage to have a subreg
2943 of a mem that is _not_ to be handled specially? IMO
2944 those should have been reduced to just a mem. */
2945 || ((MEM_P (operand)
2946 || (REG_P (operand)
2947 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
2948 #ifndef WORD_REGISTER_OPERATIONS
2949 && (((GET_MODE_BITSIZE (GET_MODE (operand))
2950 < BIGGEST_ALIGNMENT)
2951 && (GET_MODE_SIZE (operand_mode[i])
2952 > GET_MODE_SIZE (GET_MODE (operand))))
2953 || BYTES_BIG_ENDIAN
2954 #ifdef LOAD_EXTEND_OP
2955 || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2956 && (GET_MODE_SIZE (GET_MODE (operand))
2957 <= UNITS_PER_WORD)
2958 && (GET_MODE_SIZE (operand_mode[i])
2959 > GET_MODE_SIZE (GET_MODE (operand)))
2960 && INTEGRAL_MODE_P (GET_MODE (operand))
2961 && LOAD_EXTEND_OP (GET_MODE (operand)) != UNKNOWN)
2962 #endif
2964 #endif
2967 force_reload = 1;
2970 this_alternative[i] = (int) NO_REGS;
2971 this_alternative_win[i] = 0;
2972 this_alternative_match_win[i] = 0;
2973 this_alternative_offmemok[i] = 0;
2974 this_alternative_earlyclobber[i] = 0;
2975 this_alternative_matches[i] = -1;
2977 /* An empty constraint or empty alternative
2978 allows anything which matched the pattern. */
2979 if (*p == 0 || *p == ',')
2980 win = 1, badop = 0;
2982 /* Scan this alternative's specs for this operand;
2983 set WIN if the operand fits any letter in this alternative.
2984 Otherwise, clear BADOP if this operand could
2985 fit some letter after reloads,
2986 or set WINREG if this operand could fit after reloads
2987 provided the constraint allows some registers. */
2990 switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
2992 case '\0':
2993 len = 0;
2994 break;
2995 case ',':
2996 c = '\0';
2997 break;
2999 case '=': case '+': case '*':
3000 break;
3002 case '%':
3003 /* We only support one commutative marker, the first
3004 one. We already set commutative above. */
3005 break;
3007 case '?':
3008 reject += 6;
3009 break;
3011 case '!':
3012 reject = 600;
3013 break;
3015 case '#':
3016 /* Ignore rest of this alternative as far as
3017 reloading is concerned. */
3019 p++;
3020 while (*p && *p != ',');
3021 len = 0;
3022 break;
3024 case '0': case '1': case '2': case '3': case '4':
3025 case '5': case '6': case '7': case '8': case '9':
3026 m = strtoul (p, &end, 10);
3027 p = end;
3028 len = 0;
3030 this_alternative_matches[i] = m;
3031 /* We are supposed to match a previous operand.
3032 If we do, we win if that one did.
3033 If we do not, count both of the operands as losers.
3034 (This is too conservative, since most of the time
3035 only a single reload insn will be needed to make
3036 the two operands win. As a result, this alternative
3037 may be rejected when it is actually desirable.) */
3038 if ((swapped && (m != commutative || i != commutative + 1))
3039 /* If we are matching as if two operands were swapped,
3040 also pretend that operands_match had been computed
3041 with swapped.
3042 But if I is the second of those and C is the first,
3043 don't exchange them, because operands_match is valid
3044 only on one side of its diagonal. */
3045 ? (operands_match
3046 [(m == commutative || m == commutative + 1)
3047 ? 2 * commutative + 1 - m : m]
3048 [(i == commutative || i == commutative + 1)
3049 ? 2 * commutative + 1 - i : i])
3050 : operands_match[m][i])
3052 /* If we are matching a non-offsettable address where an
3053 offsettable address was expected, then we must reject
3054 this combination, because we can't reload it. */
3055 if (this_alternative_offmemok[m]
3056 && MEM_P (recog_data.operand[m])
3057 && this_alternative[m] == (int) NO_REGS
3058 && ! this_alternative_win[m])
3059 bad = 1;
3061 did_match = this_alternative_win[m];
3063 else
3065 /* Operands don't match. */
3066 rtx value;
3067 int loc1, loc2;
3068 /* Retroactively mark the operand we had to match
3069 as a loser, if it wasn't already. */
3070 if (this_alternative_win[m])
3071 losers++;
3072 this_alternative_win[m] = 0;
3073 if (this_alternative[m] == (int) NO_REGS)
3074 bad = 1;
3075 /* But count the pair only once in the total badness of
3076 this alternative, if the pair can be a dummy reload.
3077 The pointers in operand_loc are not swapped; swap
3078 them by hand if necessary. */
3079 if (swapped && i == commutative)
3080 loc1 = commutative + 1;
3081 else if (swapped && i == commutative + 1)
3082 loc1 = commutative;
3083 else
3084 loc1 = i;
3085 if (swapped && m == commutative)
3086 loc2 = commutative + 1;
3087 else if (swapped && m == commutative + 1)
3088 loc2 = commutative;
3089 else
3090 loc2 = m;
3091 value
3092 = find_dummy_reload (recog_data.operand[i],
3093 recog_data.operand[m],
3094 recog_data.operand_loc[loc1],
3095 recog_data.operand_loc[loc2],
3096 operand_mode[i], operand_mode[m],
3097 this_alternative[m], -1,
3098 this_alternative_earlyclobber[m]);
3100 if (value != 0)
3101 losers--;
3103 /* This can be fixed with reloads if the operand
3104 we are supposed to match can be fixed with reloads. */
3105 badop = 0;
3106 this_alternative[i] = this_alternative[m];
3108 /* If we have to reload this operand and some previous
3109 operand also had to match the same thing as this
3110 operand, we don't know how to do that. So reject this
3111 alternative. */
3112 if (! did_match || force_reload)
3113 for (j = 0; j < i; j++)
3114 if (this_alternative_matches[j]
3115 == this_alternative_matches[i])
3116 badop = 1;
3117 break;
3119 case 'p':
3120 /* All necessary reloads for an address_operand
3121 were handled in find_reloads_address. */
3122 this_alternative[i] = (int) MODE_BASE_REG_CLASS (VOIDmode);
3123 win = 1;
3124 badop = 0;
3125 break;
3127 case 'm':
3128 if (force_reload)
3129 break;
3130 if (MEM_P (operand)
3131 || (REG_P (operand)
3132 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3133 && reg_renumber[REGNO (operand)] < 0))
3134 win = 1;
3135 if (CONST_POOL_OK_P (operand))
3136 badop = 0;
3137 constmemok = 1;
3138 break;
3140 case '<':
3141 if (MEM_P (operand)
3142 && ! address_reloaded[i]
3143 && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
3144 || GET_CODE (XEXP (operand, 0)) == POST_DEC))
3145 win = 1;
3146 break;
3148 case '>':
3149 if (MEM_P (operand)
3150 && ! address_reloaded[i]
3151 && (GET_CODE (XEXP (operand, 0)) == PRE_INC
3152 || GET_CODE (XEXP (operand, 0)) == POST_INC))
3153 win = 1;
3154 break;
3156 /* Memory operand whose address is not offsettable. */
3157 case 'V':
3158 if (force_reload)
3159 break;
3160 if (MEM_P (operand)
3161 && ! (ind_levels ? offsettable_memref_p (operand)
3162 : offsettable_nonstrict_memref_p (operand))
3163 /* Certain mem addresses will become offsettable
3164 after they themselves are reloaded. This is important;
3165 we don't want our own handling of unoffsettables
3166 to override the handling of reg_equiv_address. */
3167 && !(REG_P (XEXP (operand, 0))
3168 && (ind_levels == 0
3169 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0)))
3170 win = 1;
3171 break;
3173 /* Memory operand whose address is offsettable. */
3174 case 'o':
3175 if (force_reload)
3176 break;
3177 if ((MEM_P (operand)
3178 /* If IND_LEVELS, find_reloads_address won't reload a
3179 pseudo that didn't get a hard reg, so we have to
3180 reject that case. */
3181 && ((ind_levels ? offsettable_memref_p (operand)
3182 : offsettable_nonstrict_memref_p (operand))
3183 /* A reloaded address is offsettable because it is now
3184 just a simple register indirect. */
3185 || address_reloaded[i] == 1))
3186 || (REG_P (operand)
3187 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3188 && reg_renumber[REGNO (operand)] < 0
3189 /* If reg_equiv_address is nonzero, we will be
3190 loading it into a register; hence it will be
3191 offsettable, but we cannot say that reg_equiv_mem
3192 is offsettable without checking. */
3193 && ((reg_equiv_mem[REGNO (operand)] != 0
3194 && offsettable_memref_p (reg_equiv_mem[REGNO (operand)]))
3195 || (reg_equiv_address[REGNO (operand)] != 0))))
3196 win = 1;
3197 if (CONST_POOL_OK_P (operand)
3198 || MEM_P (operand))
3199 badop = 0;
3200 constmemok = 1;
3201 offmemok = 1;
3202 break;
3204 case '&':
3205 /* Output operand that is stored before the need for the
3206 input operands (and their index registers) is over. */
3207 earlyclobber = 1, this_earlyclobber = 1;
3208 break;
3210 case 'E':
3211 case 'F':
3212 if (GET_CODE (operand) == CONST_DOUBLE
3213 || (GET_CODE (operand) == CONST_VECTOR
3214 && (GET_MODE_CLASS (GET_MODE (operand))
3215 == MODE_VECTOR_FLOAT)))
3216 win = 1;
3217 break;
3219 case 'G':
3220 case 'H':
3221 if (GET_CODE (operand) == CONST_DOUBLE
3222 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (operand, c, p))
3223 win = 1;
3224 break;
3226 case 's':
3227 if (GET_CODE (operand) == CONST_INT
3228 || (GET_CODE (operand) == CONST_DOUBLE
3229 && GET_MODE (operand) == VOIDmode))
3230 break;
3231 case 'i':
3232 if (CONSTANT_P (operand)
3233 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand)))
3234 win = 1;
3235 break;
3237 case 'n':
3238 if (GET_CODE (operand) == CONST_INT
3239 || (GET_CODE (operand) == CONST_DOUBLE
3240 && GET_MODE (operand) == VOIDmode))
3241 win = 1;
3242 break;
3244 case 'I':
3245 case 'J':
3246 case 'K':
3247 case 'L':
3248 case 'M':
3249 case 'N':
3250 case 'O':
3251 case 'P':
3252 if (GET_CODE (operand) == CONST_INT
3253 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (operand), c, p))
3254 win = 1;
3255 break;
3257 case 'X':
3258 win = 1;
3259 break;
3261 case 'g':
3262 if (! force_reload
3263 /* A PLUS is never a valid operand, but reload can make
3264 it from a register when eliminating registers. */
3265 && GET_CODE (operand) != PLUS
3266 /* A SCRATCH is not a valid operand. */
3267 && GET_CODE (operand) != SCRATCH
3268 && (! CONSTANT_P (operand)
3269 || ! flag_pic
3270 || LEGITIMATE_PIC_OPERAND_P (operand))
3271 && (GENERAL_REGS == ALL_REGS
3272 || !REG_P (operand)
3273 || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
3274 && reg_renumber[REGNO (operand)] < 0)))
3275 win = 1;
3276 /* Drop through into 'r' case. */
3278 case 'r':
3279 this_alternative[i]
3280 = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
3281 goto reg;
3283 default:
3284 if (REG_CLASS_FROM_CONSTRAINT (c, p) == NO_REGS)
3286 #ifdef EXTRA_CONSTRAINT_STR
3287 if (EXTRA_MEMORY_CONSTRAINT (c, p))
3289 if (force_reload)
3290 break;
3291 if (EXTRA_CONSTRAINT_STR (operand, c, p))
3292 win = 1;
3293 /* If the address was already reloaded,
3294 we win as well. */
3295 else if (MEM_P (operand)
3296 && address_reloaded[i] == 1)
3297 win = 1;
3298 /* Likewise if the address will be reloaded because
3299 reg_equiv_address is nonzero. For reg_equiv_mem
3300 we have to check. */
3301 else if (REG_P (operand)
3302 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3303 && reg_renumber[REGNO (operand)] < 0
3304 && ((reg_equiv_mem[REGNO (operand)] != 0
3305 && EXTRA_CONSTRAINT_STR (reg_equiv_mem[REGNO (operand)], c, p))
3306 || (reg_equiv_address[REGNO (operand)] != 0)))
3307 win = 1;
3309 /* If we didn't already win, we can reload
3310 constants via force_const_mem, and other
3311 MEMs by reloading the address like for 'o'. */
3312 if (CONST_POOL_OK_P (operand)
3313 || MEM_P (operand))
3314 badop = 0;
3315 constmemok = 1;
3316 offmemok = 1;
3317 break;
3319 if (EXTRA_ADDRESS_CONSTRAINT (c, p))
3321 if (EXTRA_CONSTRAINT_STR (operand, c, p))
3322 win = 1;
3324 /* If we didn't already win, we can reload
3325 the address into a base register. */
3326 this_alternative[i] = (int) MODE_BASE_REG_CLASS (VOIDmode);
3327 badop = 0;
3328 break;
3331 if (EXTRA_CONSTRAINT_STR (operand, c, p))
3332 win = 1;
3333 #endif
3334 break;
3337 this_alternative[i]
3338 = (int) (reg_class_subunion
3339 [this_alternative[i]]
3340 [(int) REG_CLASS_FROM_CONSTRAINT (c, p)]);
3341 reg:
3342 if (GET_MODE (operand) == BLKmode)
3343 break;
3344 winreg = 1;
3345 if (REG_P (operand)
3346 && reg_fits_class_p (operand, this_alternative[i],
3347 offset, GET_MODE (recog_data.operand[i])))
3348 win = 1;
3349 break;
3351 while ((p += len), c);
3353 constraints[i] = p;
3355 /* If this operand could be handled with a reg,
3356 and some reg is allowed, then this operand can be handled. */
3357 if (winreg && this_alternative[i] != (int) NO_REGS)
3358 badop = 0;
3360 /* Record which operands fit this alternative. */
3361 this_alternative_earlyclobber[i] = earlyclobber;
3362 if (win && ! force_reload)
3363 this_alternative_win[i] = 1;
3364 else if (did_match && ! force_reload)
3365 this_alternative_match_win[i] = 1;
3366 else
3368 int const_to_mem = 0;
3370 this_alternative_offmemok[i] = offmemok;
3371 losers++;
3372 if (badop)
3373 bad = 1;
3374 /* Alternative loses if it has no regs for a reg operand. */
3375 if (REG_P (operand)
3376 && this_alternative[i] == (int) NO_REGS
3377 && this_alternative_matches[i] < 0)
3378 bad = 1;
3380 /* If this is a constant that is reloaded into the desired
3381 class by copying it to memory first, count that as another
3382 reload. This is consistent with other code and is
3383 required to avoid choosing another alternative when
3384 the constant is moved into memory by this function on
3385 an early reload pass. Note that the test here is
3386 precisely the same as in the code below that calls
3387 force_const_mem. */
3388 if (CONST_POOL_OK_P (operand)
3389 && ((PREFERRED_RELOAD_CLASS (operand,
3390 (enum reg_class) this_alternative[i])
3391 == NO_REGS)
3392 || no_input_reloads)
3393 && operand_mode[i] != VOIDmode)
3395 const_to_mem = 1;
3396 if (this_alternative[i] != (int) NO_REGS)
3397 losers++;
3400 /* If we can't reload this value at all, reject this
3401 alternative. Note that we could also lose due to
3402 LIMIT_RELOAD_RELOAD_CLASS, but we don't check that
3403 here. */
3405 if (! CONSTANT_P (operand)
3406 && (enum reg_class) this_alternative[i] != NO_REGS
3407 && (PREFERRED_RELOAD_CLASS (operand,
3408 (enum reg_class) this_alternative[i])
3409 == NO_REGS))
3410 bad = 1;
3412 /* Alternative loses if it requires a type of reload not
3413 permitted for this insn. We can always reload SCRATCH
3414 and objects with a REG_UNUSED note. */
3415 else if (GET_CODE (operand) != SCRATCH
3416 && modified[i] != RELOAD_READ && no_output_reloads
3417 && ! find_reg_note (insn, REG_UNUSED, operand))
3418 bad = 1;
3419 else if (modified[i] != RELOAD_WRITE && no_input_reloads
3420 && ! const_to_mem)
3421 bad = 1;
3423 /* We prefer to reload pseudos over reloading other things,
3424 since such reloads may be able to be eliminated later.
3425 If we are reloading a SCRATCH, we won't be generating any
3426 insns, just using a register, so it is also preferred.
3427 So bump REJECT in other cases. Don't do this in the
3428 case where we are forcing a constant into memory and
3429 it will then win since we don't want to have a different
3430 alternative match then. */
3431 if (! (REG_P (operand)
3432 && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
3433 && GET_CODE (operand) != SCRATCH
3434 && ! (const_to_mem && constmemok))
3435 reject += 2;
3437 /* Input reloads can be inherited more often than output
3438 reloads can be removed, so penalize output reloads. */
3439 if (operand_type[i] != RELOAD_FOR_INPUT
3440 && GET_CODE (operand) != SCRATCH)
3441 reject++;
3444 /* If this operand is a pseudo register that didn't get a hard
3445 reg and this alternative accepts some register, see if the
3446 class that we want is a subset of the preferred class for this
3447 register. If not, but it intersects that class, use the
3448 preferred class instead. If it does not intersect the preferred
3449 class, show that usage of this alternative should be discouraged;
3450 it will be discouraged more still if the register is `preferred
3451 or nothing'. We do this because it increases the chance of
3452 reusing our spill register in a later insn and avoiding a pair
3453 of memory stores and loads.
3455 Don't bother with this if this alternative will accept this
3456 operand.
3458 Don't do this for a multiword operand, since it is only a
3459 small win and has the risk of requiring more spill registers,
3460 which could cause a large loss.
3462 Don't do this if the preferred class has only one register
3463 because we might otherwise exhaust the class. */
3465 if (! win && ! did_match
3466 && this_alternative[i] != (int) NO_REGS
3467 && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
3468 && reg_class_size [(int) preferred_class[i]] > 0
3469 && ! SMALL_REGISTER_CLASS_P (preferred_class[i]))
3471 if (! reg_class_subset_p (this_alternative[i],
3472 preferred_class[i]))
3474 /* Since we don't have a way of forming the intersection,
3475 we just do something special if the preferred class
3476 is a subset of the class we have; that's the most
3477 common case anyway. */
3478 if (reg_class_subset_p (preferred_class[i],
3479 this_alternative[i]))
3480 this_alternative[i] = (int) preferred_class[i];
3481 else
3482 reject += (2 + 2 * pref_or_nothing[i]);
3487 /* Now see if any output operands that are marked "earlyclobber"
3488 in this alternative conflict with any input operands
3489 or any memory addresses. */
3491 for (i = 0; i < noperands; i++)
3492 if (this_alternative_earlyclobber[i]
3493 && (this_alternative_win[i] || this_alternative_match_win[i]))
3495 struct decomposition early_data;
3497 early_data = decompose (recog_data.operand[i]);
3499 gcc_assert (modified[i] != RELOAD_READ);
3501 if (this_alternative[i] == NO_REGS)
3503 this_alternative_earlyclobber[i] = 0;
3504 gcc_assert (this_insn_is_asm);
3505 error_for_asm (this_insn,
3506 "%<&%> constraint used with no register class");
3509 for (j = 0; j < noperands; j++)
3510 /* Is this an input operand or a memory ref? */
3511 if ((MEM_P (recog_data.operand[j])
3512 || modified[j] != RELOAD_WRITE)
3513 && j != i
3514 /* Ignore things like match_operator operands. */
3515 && *recog_data.constraints[j] != 0
3516 /* Don't count an input operand that is constrained to match
3517 the early clobber operand. */
3518 && ! (this_alternative_matches[j] == i
3519 && rtx_equal_p (recog_data.operand[i],
3520 recog_data.operand[j]))
3521 /* Is it altered by storing the earlyclobber operand? */
3522 && !immune_p (recog_data.operand[j], recog_data.operand[i],
3523 early_data))
3525 /* If the output is in a non-empty few-regs class,
3526 it's costly to reload it, so reload the input instead. */
3527 if (SMALL_REGISTER_CLASS_P (this_alternative[i])
3528 && (REG_P (recog_data.operand[j])
3529 || GET_CODE (recog_data.operand[j]) == SUBREG))
3531 losers++;
3532 this_alternative_win[j] = 0;
3533 this_alternative_match_win[j] = 0;
3535 else
3536 break;
3538 /* If an earlyclobber operand conflicts with something,
3539 it must be reloaded, so request this and count the cost. */
3540 if (j != noperands)
3542 losers++;
3543 this_alternative_win[i] = 0;
3544 this_alternative_match_win[j] = 0;
3545 for (j = 0; j < noperands; j++)
3546 if (this_alternative_matches[j] == i
3547 && this_alternative_match_win[j])
3549 this_alternative_win[j] = 0;
3550 this_alternative_match_win[j] = 0;
3551 losers++;
3556 /* If one alternative accepts all the operands, no reload required,
3557 choose that alternative; don't consider the remaining ones. */
3558 if (losers == 0)
3560 /* Unswap these so that they are never swapped at `finish'. */
3561 if (commutative >= 0)
3563 recog_data.operand[commutative] = substed_operand[commutative];
3564 recog_data.operand[commutative + 1]
3565 = substed_operand[commutative + 1];
3567 for (i = 0; i < noperands; i++)
3569 goal_alternative_win[i] = this_alternative_win[i];
3570 goal_alternative_match_win[i] = this_alternative_match_win[i];
3571 goal_alternative[i] = this_alternative[i];
3572 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3573 goal_alternative_matches[i] = this_alternative_matches[i];
3574 goal_alternative_earlyclobber[i]
3575 = this_alternative_earlyclobber[i];
3577 goal_alternative_number = this_alternative_number;
3578 goal_alternative_swapped = swapped;
3579 goal_earlyclobber = this_earlyclobber;
3580 goto finish;
3583 /* REJECT, set by the ! and ? constraint characters and when a register
3584 would be reloaded into a non-preferred class, discourages the use of
3585 this alternative for a reload goal. REJECT is incremented by six
3586 for each ? and two for each non-preferred class. */
3587 losers = losers * 6 + reject;
3589 /* If this alternative can be made to work by reloading,
3590 and it needs less reloading than the others checked so far,
3591 record it as the chosen goal for reloading. */
3592 if (! bad && best > losers)
3594 for (i = 0; i < noperands; i++)
3596 goal_alternative[i] = this_alternative[i];
3597 goal_alternative_win[i] = this_alternative_win[i];
3598 goal_alternative_match_win[i] = this_alternative_match_win[i];
3599 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
3600 goal_alternative_matches[i] = this_alternative_matches[i];
3601 goal_alternative_earlyclobber[i]
3602 = this_alternative_earlyclobber[i];
3604 goal_alternative_swapped = swapped;
3605 best = losers;
3606 goal_alternative_number = this_alternative_number;
3607 goal_earlyclobber = this_earlyclobber;
3611 /* If insn is commutative (it's safe to exchange a certain pair of operands)
3612 then we need to try each alternative twice,
3613 the second time matching those two operands
3614 as if we had exchanged them.
3615 To do this, really exchange them in operands.
3617 If we have just tried the alternatives the second time,
3618 return operands to normal and drop through. */
3620 if (commutative >= 0)
3622 swapped = !swapped;
3623 if (swapped)
3625 enum reg_class tclass;
3626 int t;
3628 recog_data.operand[commutative] = substed_operand[commutative + 1];
3629 recog_data.operand[commutative + 1] = substed_operand[commutative];
3630 /* Swap the duplicates too. */
3631 for (i = 0; i < recog_data.n_dups; i++)
3632 if (recog_data.dup_num[i] == commutative
3633 || recog_data.dup_num[i] == commutative + 1)
3634 *recog_data.dup_loc[i]
3635 = recog_data.operand[(int) recog_data.dup_num[i]];
3637 tclass = preferred_class[commutative];
3638 preferred_class[commutative] = preferred_class[commutative + 1];
3639 preferred_class[commutative + 1] = tclass;
3641 t = pref_or_nothing[commutative];
3642 pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
3643 pref_or_nothing[commutative + 1] = t;
3645 t = address_reloaded[commutative];
3646 address_reloaded[commutative] = address_reloaded[commutative + 1];
3647 address_reloaded[commutative + 1] = t;
3649 memcpy (constraints, recog_data.constraints,
3650 noperands * sizeof (char *));
3651 goto try_swapped;
3653 else
3655 recog_data.operand[commutative] = substed_operand[commutative];
3656 recog_data.operand[commutative + 1]
3657 = substed_operand[commutative + 1];
3658 /* Unswap the duplicates too. */
3659 for (i = 0; i < recog_data.n_dups; i++)
3660 if (recog_data.dup_num[i] == commutative
3661 || recog_data.dup_num[i] == commutative + 1)
3662 *recog_data.dup_loc[i]
3663 = recog_data.operand[(int) recog_data.dup_num[i]];
3667 /* The operands don't meet the constraints.
3668 goal_alternative describes the alternative
3669 that we could reach by reloading the fewest operands.
3670 Reload so as to fit it. */
3672 if (best == MAX_RECOG_OPERANDS * 2 + 600)
3674 /* No alternative works with reloads?? */
3675 if (insn_code_number >= 0)
3676 fatal_insn ("unable to generate reloads for:", insn);
3677 error_for_asm (insn, "inconsistent operand constraints in an %<asm%>");
3678 /* Avoid further trouble with this insn. */
3679 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3680 n_reloads = 0;
3681 return 0;
3684 /* Jump to `finish' from above if all operands are valid already.
3685 In that case, goal_alternative_win is all 1. */
3686 finish:
3688 /* Right now, for any pair of operands I and J that are required to match,
3689 with I < J,
3690 goal_alternative_matches[J] is I.
3691 Set up goal_alternative_matched as the inverse function:
3692 goal_alternative_matched[I] = J. */
3694 for (i = 0; i < noperands; i++)
3695 goal_alternative_matched[i] = -1;
3697 for (i = 0; i < noperands; i++)
3698 if (! goal_alternative_win[i]
3699 && goal_alternative_matches[i] >= 0)
3700 goal_alternative_matched[goal_alternative_matches[i]] = i;
3702 for (i = 0; i < noperands; i++)
3703 goal_alternative_win[i] |= goal_alternative_match_win[i];
3705 /* If the best alternative is with operands 1 and 2 swapped,
3706 consider them swapped before reporting the reloads. Update the
3707 operand numbers of any reloads already pushed. */
3709 if (goal_alternative_swapped)
3711 rtx tem;
3713 tem = substed_operand[commutative];
3714 substed_operand[commutative] = substed_operand[commutative + 1];
3715 substed_operand[commutative + 1] = tem;
3716 tem = recog_data.operand[commutative];
3717 recog_data.operand[commutative] = recog_data.operand[commutative + 1];
3718 recog_data.operand[commutative + 1] = tem;
3719 tem = *recog_data.operand_loc[commutative];
3720 *recog_data.operand_loc[commutative]
3721 = *recog_data.operand_loc[commutative + 1];
3722 *recog_data.operand_loc[commutative + 1] = tem;
3724 for (i = 0; i < n_reloads; i++)
3726 if (rld[i].opnum == commutative)
3727 rld[i].opnum = commutative + 1;
3728 else if (rld[i].opnum == commutative + 1)
3729 rld[i].opnum = commutative;
3733 for (i = 0; i < noperands; i++)
3735 operand_reloadnum[i] = -1;
3737 /* If this is an earlyclobber operand, we need to widen the scope.
3738 The reload must remain valid from the start of the insn being
3739 reloaded until after the operand is stored into its destination.
3740 We approximate this with RELOAD_OTHER even though we know that we
3741 do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads.
3743 One special case that is worth checking is when we have an
3744 output that is earlyclobber but isn't used past the insn (typically
3745 a SCRATCH). In this case, we only need have the reload live
3746 through the insn itself, but not for any of our input or output
3747 reloads.
3748 But we must not accidentally narrow the scope of an existing
3749 RELOAD_OTHER reload - leave these alone.
3751 In any case, anything needed to address this operand can remain
3752 however they were previously categorized. */
3754 if (goal_alternative_earlyclobber[i] && operand_type[i] != RELOAD_OTHER)
3755 operand_type[i]
3756 = (find_reg_note (insn, REG_UNUSED, recog_data.operand[i])
3757 ? RELOAD_FOR_INSN : RELOAD_OTHER);
3760 /* Any constants that aren't allowed and can't be reloaded
3761 into registers are here changed into memory references. */
3762 for (i = 0; i < noperands; i++)
3763 if (! goal_alternative_win[i]
3764 && CONST_POOL_OK_P (recog_data.operand[i])
3765 && ((PREFERRED_RELOAD_CLASS (recog_data.operand[i],
3766 (enum reg_class) goal_alternative[i])
3767 == NO_REGS)
3768 || no_input_reloads)
3769 && operand_mode[i] != VOIDmode)
3771 substed_operand[i] = recog_data.operand[i]
3772 = find_reloads_toplev (force_const_mem (operand_mode[i],
3773 recog_data.operand[i]),
3774 i, address_type[i], ind_levels, 0, insn,
3775 NULL);
3776 if (alternative_allows_memconst (recog_data.constraints[i],
3777 goal_alternative_number))
3778 goal_alternative_win[i] = 1;
3781 /* Likewise any invalid constants appearing as operand of a PLUS
3782 that is to be reloaded. */
3783 for (i = 0; i < noperands; i++)
3784 if (! goal_alternative_win[i]
3785 && GET_CODE (recog_data.operand[i]) == PLUS
3786 && CONST_POOL_OK_P (XEXP (recog_data.operand[i], 1))
3787 && (PREFERRED_RELOAD_CLASS (XEXP (recog_data.operand[i], 1),
3788 (enum reg_class) goal_alternative[i])
3789 == NO_REGS)
3790 && operand_mode[i] != VOIDmode)
3792 rtx tem = force_const_mem (operand_mode[i],
3793 XEXP (recog_data.operand[i], 1));
3794 tem = gen_rtx_PLUS (operand_mode[i],
3795 XEXP (recog_data.operand[i], 0), tem);
3797 substed_operand[i] = recog_data.operand[i]
3798 = find_reloads_toplev (tem, i, address_type[i],
3799 ind_levels, 0, insn, NULL);
3802 /* Record the values of the earlyclobber operands for the caller. */
3803 if (goal_earlyclobber)
3804 for (i = 0; i < noperands; i++)
3805 if (goal_alternative_earlyclobber[i])
3806 reload_earlyclobbers[n_earlyclobbers++] = recog_data.operand[i];
3808 /* Now record reloads for all the operands that need them. */
3809 for (i = 0; i < noperands; i++)
3810 if (! goal_alternative_win[i])
3812 /* Operands that match previous ones have already been handled. */
3813 if (goal_alternative_matches[i] >= 0)
3815 /* Handle an operand with a nonoffsettable address
3816 appearing where an offsettable address will do
3817 by reloading the address into a base register.
3819 ??? We can also do this when the operand is a register and
3820 reg_equiv_mem is not offsettable, but this is a bit tricky,
3821 so we don't bother with it. It may not be worth doing. */
3822 else if (goal_alternative_matched[i] == -1
3823 && goal_alternative_offmemok[i]
3824 && MEM_P (recog_data.operand[i]))
3826 operand_reloadnum[i]
3827 = push_reload (XEXP (recog_data.operand[i], 0), NULL_RTX,
3828 &XEXP (recog_data.operand[i], 0), (rtx*) 0,
3829 MODE_BASE_REG_CLASS (VOIDmode),
3830 GET_MODE (XEXP (recog_data.operand[i], 0)),
3831 VOIDmode, 0, 0, i, RELOAD_FOR_INPUT);
3832 rld[operand_reloadnum[i]].inc
3833 = GET_MODE_SIZE (GET_MODE (recog_data.operand[i]));
3835 /* If this operand is an output, we will have made any
3836 reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but
3837 now we are treating part of the operand as an input, so
3838 we must change these to RELOAD_FOR_INPUT_ADDRESS. */
3840 if (modified[i] == RELOAD_WRITE)
3842 for (j = 0; j < n_reloads; j++)
3844 if (rld[j].opnum == i)
3846 if (rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS)
3847 rld[j].when_needed = RELOAD_FOR_INPUT_ADDRESS;
3848 else if (rld[j].when_needed
3849 == RELOAD_FOR_OUTADDR_ADDRESS)
3850 rld[j].when_needed = RELOAD_FOR_INPADDR_ADDRESS;
3855 else if (goal_alternative_matched[i] == -1)
3857 operand_reloadnum[i]
3858 = push_reload ((modified[i] != RELOAD_WRITE
3859 ? recog_data.operand[i] : 0),
3860 (modified[i] != RELOAD_READ
3861 ? recog_data.operand[i] : 0),
3862 (modified[i] != RELOAD_WRITE
3863 ? recog_data.operand_loc[i] : 0),
3864 (modified[i] != RELOAD_READ
3865 ? recog_data.operand_loc[i] : 0),
3866 (enum reg_class) goal_alternative[i],
3867 (modified[i] == RELOAD_WRITE
3868 ? VOIDmode : operand_mode[i]),
3869 (modified[i] == RELOAD_READ
3870 ? VOIDmode : operand_mode[i]),
3871 (insn_code_number < 0 ? 0
3872 : insn_data[insn_code_number].operand[i].strict_low),
3873 0, i, operand_type[i]);
3875 /* In a matching pair of operands, one must be input only
3876 and the other must be output only.
3877 Pass the input operand as IN and the other as OUT. */
3878 else if (modified[i] == RELOAD_READ
3879 && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
3881 operand_reloadnum[i]
3882 = push_reload (recog_data.operand[i],
3883 recog_data.operand[goal_alternative_matched[i]],
3884 recog_data.operand_loc[i],
3885 recog_data.operand_loc[goal_alternative_matched[i]],
3886 (enum reg_class) goal_alternative[i],
3887 operand_mode[i],
3888 operand_mode[goal_alternative_matched[i]],
3889 0, 0, i, RELOAD_OTHER);
3890 operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
3892 else if (modified[i] == RELOAD_WRITE
3893 && modified[goal_alternative_matched[i]] == RELOAD_READ)
3895 operand_reloadnum[goal_alternative_matched[i]]
3896 = push_reload (recog_data.operand[goal_alternative_matched[i]],
3897 recog_data.operand[i],
3898 recog_data.operand_loc[goal_alternative_matched[i]],
3899 recog_data.operand_loc[i],
3900 (enum reg_class) goal_alternative[i],
3901 operand_mode[goal_alternative_matched[i]],
3902 operand_mode[i],
3903 0, 0, i, RELOAD_OTHER);
3904 operand_reloadnum[i] = output_reloadnum;
3906 else
3908 gcc_assert (insn_code_number < 0);
3909 error_for_asm (insn, "inconsistent operand constraints "
3910 "in an %<asm%>");
3911 /* Avoid further trouble with this insn. */
3912 PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx);
3913 n_reloads = 0;
3914 return 0;
3917 else if (goal_alternative_matched[i] < 0
3918 && goal_alternative_matches[i] < 0
3919 && address_operand_reloaded[i] != 1
3920 && optimize)
3922 /* For each non-matching operand that's a MEM or a pseudo-register
3923 that didn't get a hard register, make an optional reload.
3924 This may get done even if the insn needs no reloads otherwise. */
3926 rtx operand = recog_data.operand[i];
3928 while (GET_CODE (operand) == SUBREG)
3929 operand = SUBREG_REG (operand);
3930 if ((MEM_P (operand)
3931 || (REG_P (operand)
3932 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
3933 /* If this is only for an output, the optional reload would not
3934 actually cause us to use a register now, just note that
3935 something is stored here. */
3936 && ((enum reg_class) goal_alternative[i] != NO_REGS
3937 || modified[i] == RELOAD_WRITE)
3938 && ! no_input_reloads
3939 /* An optional output reload might allow to delete INSN later.
3940 We mustn't make in-out reloads on insns that are not permitted
3941 output reloads.
3942 If this is an asm, we can't delete it; we must not even call
3943 push_reload for an optional output reload in this case,
3944 because we can't be sure that the constraint allows a register,
3945 and push_reload verifies the constraints for asms. */
3946 && (modified[i] == RELOAD_READ
3947 || (! no_output_reloads && ! this_insn_is_asm)))
3948 operand_reloadnum[i]
3949 = push_reload ((modified[i] != RELOAD_WRITE
3950 ? recog_data.operand[i] : 0),
3951 (modified[i] != RELOAD_READ
3952 ? recog_data.operand[i] : 0),
3953 (modified[i] != RELOAD_WRITE
3954 ? recog_data.operand_loc[i] : 0),
3955 (modified[i] != RELOAD_READ
3956 ? recog_data.operand_loc[i] : 0),
3957 (enum reg_class) goal_alternative[i],
3958 (modified[i] == RELOAD_WRITE
3959 ? VOIDmode : operand_mode[i]),
3960 (modified[i] == RELOAD_READ
3961 ? VOIDmode : operand_mode[i]),
3962 (insn_code_number < 0 ? 0
3963 : insn_data[insn_code_number].operand[i].strict_low),
3964 1, i, operand_type[i]);
3965 /* If a memory reference remains (either as a MEM or a pseudo that
3966 did not get a hard register), yet we can't make an optional
3967 reload, check if this is actually a pseudo register reference;
3968 we then need to emit a USE and/or a CLOBBER so that reload
3969 inheritance will do the right thing. */
3970 else if (replace
3971 && (MEM_P (operand)
3972 || (REG_P (operand)
3973 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3974 && reg_renumber [REGNO (operand)] < 0)))
3976 operand = *recog_data.operand_loc[i];
3978 while (GET_CODE (operand) == SUBREG)
3979 operand = SUBREG_REG (operand);
3980 if (REG_P (operand))
3982 if (modified[i] != RELOAD_WRITE)
3983 /* We mark the USE with QImode so that we recognize
3984 it as one that can be safely deleted at the end
3985 of reload. */
3986 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, operand),
3987 insn), QImode);
3988 if (modified[i] != RELOAD_READ)
3989 emit_insn_after (gen_rtx_CLOBBER (VOIDmode, operand), insn);
3993 else if (goal_alternative_matches[i] >= 0
3994 && goal_alternative_win[goal_alternative_matches[i]]
3995 && modified[i] == RELOAD_READ
3996 && modified[goal_alternative_matches[i]] == RELOAD_WRITE
3997 && ! no_input_reloads && ! no_output_reloads
3998 && optimize)
4000 /* Similarly, make an optional reload for a pair of matching
4001 objects that are in MEM or a pseudo that didn't get a hard reg. */
4003 rtx operand = recog_data.operand[i];
4005 while (GET_CODE (operand) == SUBREG)
4006 operand = SUBREG_REG (operand);
4007 if ((MEM_P (operand)
4008 || (REG_P (operand)
4009 && REGNO (operand) >= FIRST_PSEUDO_REGISTER))
4010 && ((enum reg_class) goal_alternative[goal_alternative_matches[i]]
4011 != NO_REGS))
4012 operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]]
4013 = push_reload (recog_data.operand[goal_alternative_matches[i]],
4014 recog_data.operand[i],
4015 recog_data.operand_loc[goal_alternative_matches[i]],
4016 recog_data.operand_loc[i],
4017 (enum reg_class) goal_alternative[goal_alternative_matches[i]],
4018 operand_mode[goal_alternative_matches[i]],
4019 operand_mode[i],
4020 0, 1, goal_alternative_matches[i], RELOAD_OTHER);
4023 /* Perform whatever substitutions on the operands we are supposed
4024 to make due to commutativity or replacement of registers
4025 with equivalent constants or memory slots. */
4027 for (i = 0; i < noperands; i++)
4029 /* We only do this on the last pass through reload, because it is
4030 possible for some data (like reg_equiv_address) to be changed during
4031 later passes. Moreover, we lose the opportunity to get a useful
4032 reload_{in,out}_reg when we do these replacements. */
4034 if (replace)
4036 rtx substitution = substed_operand[i];
4038 *recog_data.operand_loc[i] = substitution;
4040 /* If we're replacing an operand with a LABEL_REF, we need
4041 to make sure that there's a REG_LABEL note attached to
4042 this instruction. */
4043 if (!JUMP_P (insn)
4044 && GET_CODE (substitution) == LABEL_REF
4045 && !find_reg_note (insn, REG_LABEL, XEXP (substitution, 0)))
4046 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
4047 XEXP (substitution, 0),
4048 REG_NOTES (insn));
4050 else
4051 retval |= (substed_operand[i] != *recog_data.operand_loc[i]);
4054 /* If this insn pattern contains any MATCH_DUP's, make sure that
4055 they will be substituted if the operands they match are substituted.
4056 Also do now any substitutions we already did on the operands.
4058 Don't do this if we aren't making replacements because we might be
4059 propagating things allocated by frame pointer elimination into places
4060 it doesn't expect. */
4062 if (insn_code_number >= 0 && replace)
4063 for (i = insn_data[insn_code_number].n_dups - 1; i >= 0; i--)
4065 int opno = recog_data.dup_num[i];
4066 *recog_data.dup_loc[i] = *recog_data.operand_loc[opno];
4067 dup_replacements (recog_data.dup_loc[i], recog_data.operand_loc[opno]);
4070 #if 0
4071 /* This loses because reloading of prior insns can invalidate the equivalence
4072 (or at least find_equiv_reg isn't smart enough to find it any more),
4073 causing this insn to need more reload regs than it needed before.
4074 It may be too late to make the reload regs available.
4075 Now this optimization is done safely in choose_reload_regs. */
4077 /* For each reload of a reg into some other class of reg,
4078 search for an existing equivalent reg (same value now) in the right class.
4079 We can use it as long as we don't need to change its contents. */
4080 for (i = 0; i < n_reloads; i++)
4081 if (rld[i].reg_rtx == 0
4082 && rld[i].in != 0
4083 && REG_P (rld[i].in)
4084 && rld[i].out == 0)
4086 rld[i].reg_rtx
4087 = find_equiv_reg (rld[i].in, insn, rld[i].class, -1,
4088 static_reload_reg_p, 0, rld[i].inmode);
4089 /* Prevent generation of insn to load the value
4090 because the one we found already has the value. */
4091 if (rld[i].reg_rtx)
4092 rld[i].in = rld[i].reg_rtx;
4094 #endif
4096 /* Perhaps an output reload can be combined with another
4097 to reduce needs by one. */
4098 if (!goal_earlyclobber)
4099 combine_reloads ();
4101 /* If we have a pair of reloads for parts of an address, they are reloading
4102 the same object, the operands themselves were not reloaded, and they
4103 are for two operands that are supposed to match, merge the reloads and
4104 change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS. */
4106 for (i = 0; i < n_reloads; i++)
4108 int k;
4110 for (j = i + 1; j < n_reloads; j++)
4111 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4112 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4113 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4114 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4115 && (rld[j].when_needed == RELOAD_FOR_INPUT_ADDRESS
4116 || rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4117 || rld[j].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4118 || rld[j].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4119 && rtx_equal_p (rld[i].in, rld[j].in)
4120 && (operand_reloadnum[rld[i].opnum] < 0
4121 || rld[operand_reloadnum[rld[i].opnum]].optional)
4122 && (operand_reloadnum[rld[j].opnum] < 0
4123 || rld[operand_reloadnum[rld[j].opnum]].optional)
4124 && (goal_alternative_matches[rld[i].opnum] == rld[j].opnum
4125 || (goal_alternative_matches[rld[j].opnum]
4126 == rld[i].opnum)))
4128 for (k = 0; k < n_replacements; k++)
4129 if (replacements[k].what == j)
4130 replacements[k].what = i;
4132 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4133 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4134 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
4135 else
4136 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
4137 rld[j].in = 0;
4141 /* Scan all the reloads and update their type.
4142 If a reload is for the address of an operand and we didn't reload
4143 that operand, change the type. Similarly, change the operand number
4144 of a reload when two operands match. If a reload is optional, treat it
4145 as though the operand isn't reloaded.
4147 ??? This latter case is somewhat odd because if we do the optional
4148 reload, it means the object is hanging around. Thus we need only
4149 do the address reload if the optional reload was NOT done.
4151 Change secondary reloads to be the address type of their operand, not
4152 the normal type.
4154 If an operand's reload is now RELOAD_OTHER, change any
4155 RELOAD_FOR_INPUT_ADDRESS reloads of that operand to
4156 RELOAD_FOR_OTHER_ADDRESS. */
4158 for (i = 0; i < n_reloads; i++)
4160 if (rld[i].secondary_p
4161 && rld[i].when_needed == operand_type[rld[i].opnum])
4162 rld[i].when_needed = address_type[rld[i].opnum];
4164 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4165 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4166 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4167 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4168 && (operand_reloadnum[rld[i].opnum] < 0
4169 || rld[operand_reloadnum[rld[i].opnum]].optional))
4171 /* If we have a secondary reload to go along with this reload,
4172 change its type to RELOAD_FOR_OPADDR_ADDR. */
4174 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4175 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4176 && rld[i].secondary_in_reload != -1)
4178 int secondary_in_reload = rld[i].secondary_in_reload;
4180 rld[secondary_in_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4182 /* If there's a tertiary reload we have to change it also. */
4183 if (secondary_in_reload > 0
4184 && rld[secondary_in_reload].secondary_in_reload != -1)
4185 rld[rld[secondary_in_reload].secondary_in_reload].when_needed
4186 = RELOAD_FOR_OPADDR_ADDR;
4189 if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS
4190 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4191 && rld[i].secondary_out_reload != -1)
4193 int secondary_out_reload = rld[i].secondary_out_reload;
4195 rld[secondary_out_reload].when_needed = RELOAD_FOR_OPADDR_ADDR;
4197 /* If there's a tertiary reload we have to change it also. */
4198 if (secondary_out_reload
4199 && rld[secondary_out_reload].secondary_out_reload != -1)
4200 rld[rld[secondary_out_reload].secondary_out_reload].when_needed
4201 = RELOAD_FOR_OPADDR_ADDR;
4204 if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS
4205 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS)
4206 rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR;
4207 else
4208 rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS;
4211 if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS
4212 || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS)
4213 && operand_reloadnum[rld[i].opnum] >= 0
4214 && (rld[operand_reloadnum[rld[i].opnum]].when_needed
4215 == RELOAD_OTHER))
4216 rld[i].when_needed = RELOAD_FOR_OTHER_ADDRESS;
4218 if (goal_alternative_matches[rld[i].opnum] >= 0)
4219 rld[i].opnum = goal_alternative_matches[rld[i].opnum];
4222 /* Scan all the reloads, and check for RELOAD_FOR_OPERAND_ADDRESS reloads.
4223 If we have more than one, then convert all RELOAD_FOR_OPADDR_ADDR
4224 reloads to RELOAD_FOR_OPERAND_ADDRESS reloads.
4226 choose_reload_regs assumes that RELOAD_FOR_OPADDR_ADDR reloads never
4227 conflict with RELOAD_FOR_OPERAND_ADDRESS reloads. This is true for a
4228 single pair of RELOAD_FOR_OPADDR_ADDR/RELOAD_FOR_OPERAND_ADDRESS reloads.
4229 However, if there is more than one RELOAD_FOR_OPERAND_ADDRESS reload,
4230 then a RELOAD_FOR_OPADDR_ADDR reload conflicts with all
4231 RELOAD_FOR_OPERAND_ADDRESS reloads other than the one that uses it.
4232 This is complicated by the fact that a single operand can have more
4233 than one RELOAD_FOR_OPERAND_ADDRESS reload. It is very difficult to fix
4234 choose_reload_regs without affecting code quality, and cases that
4235 actually fail are extremely rare, so it turns out to be better to fix
4236 the problem here by not generating cases that choose_reload_regs will
4237 fail for. */
4238 /* There is a similar problem with RELOAD_FOR_INPUT_ADDRESS /
4239 RELOAD_FOR_OUTPUT_ADDRESS when there is more than one of a kind for
4240 a single operand.
4241 We can reduce the register pressure by exploiting that a
4242 RELOAD_FOR_X_ADDR_ADDR that precedes all RELOAD_FOR_X_ADDRESS reloads
4243 does not conflict with any of them, if it is only used for the first of
4244 the RELOAD_FOR_X_ADDRESS reloads. */
4246 int first_op_addr_num = -2;
4247 int first_inpaddr_num[MAX_RECOG_OPERANDS];
4248 int first_outpaddr_num[MAX_RECOG_OPERANDS];
4249 int need_change = 0;
4250 /* We use last_op_addr_reload and the contents of the above arrays
4251 first as flags - -2 means no instance encountered, -1 means exactly
4252 one instance encountered.
4253 If more than one instance has been encountered, we store the reload
4254 number of the first reload of the kind in question; reload numbers
4255 are known to be non-negative. */
4256 for (i = 0; i < noperands; i++)
4257 first_inpaddr_num[i] = first_outpaddr_num[i] = -2;
4258 for (i = n_reloads - 1; i >= 0; i--)
4260 switch (rld[i].when_needed)
4262 case RELOAD_FOR_OPERAND_ADDRESS:
4263 if (++first_op_addr_num >= 0)
4265 first_op_addr_num = i;
4266 need_change = 1;
4268 break;
4269 case RELOAD_FOR_INPUT_ADDRESS:
4270 if (++first_inpaddr_num[rld[i].opnum] >= 0)
4272 first_inpaddr_num[rld[i].opnum] = i;
4273 need_change = 1;
4275 break;
4276 case RELOAD_FOR_OUTPUT_ADDRESS:
4277 if (++first_outpaddr_num[rld[i].opnum] >= 0)
4279 first_outpaddr_num[rld[i].opnum] = i;
4280 need_change = 1;
4282 break;
4283 default:
4284 break;
4288 if (need_change)
4290 for (i = 0; i < n_reloads; i++)
4292 int first_num;
4293 enum reload_type type;
4295 switch (rld[i].when_needed)
4297 case RELOAD_FOR_OPADDR_ADDR:
4298 first_num = first_op_addr_num;
4299 type = RELOAD_FOR_OPERAND_ADDRESS;
4300 break;
4301 case RELOAD_FOR_INPADDR_ADDRESS:
4302 first_num = first_inpaddr_num[rld[i].opnum];
4303 type = RELOAD_FOR_INPUT_ADDRESS;
4304 break;
4305 case RELOAD_FOR_OUTADDR_ADDRESS:
4306 first_num = first_outpaddr_num[rld[i].opnum];
4307 type = RELOAD_FOR_OUTPUT_ADDRESS;
4308 break;
4309 default:
4310 continue;
4312 if (first_num < 0)
4313 continue;
4314 else if (i > first_num)
4315 rld[i].when_needed = type;
4316 else
4318 /* Check if the only TYPE reload that uses reload I is
4319 reload FIRST_NUM. */
4320 for (j = n_reloads - 1; j > first_num; j--)
4322 if (rld[j].when_needed == type
4323 && (rld[i].secondary_p
4324 ? rld[j].secondary_in_reload == i
4325 : reg_mentioned_p (rld[i].in, rld[j].in)))
4327 rld[i].when_needed = type;
4328 break;
4336 /* See if we have any reloads that are now allowed to be merged
4337 because we've changed when the reload is needed to
4338 RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS. Only
4339 check for the most common cases. */
4341 for (i = 0; i < n_reloads; i++)
4342 if (rld[i].in != 0 && rld[i].out == 0
4343 && (rld[i].when_needed == RELOAD_FOR_OPERAND_ADDRESS
4344 || rld[i].when_needed == RELOAD_FOR_OPADDR_ADDR
4345 || rld[i].when_needed == RELOAD_FOR_OTHER_ADDRESS))
4346 for (j = 0; j < n_reloads; j++)
4347 if (i != j && rld[j].in != 0 && rld[j].out == 0
4348 && rld[j].when_needed == rld[i].when_needed
4349 && MATCHES (rld[i].in, rld[j].in)
4350 && rld[i].class == rld[j].class
4351 && !rld[i].nocombine && !rld[j].nocombine
4352 && rld[i].reg_rtx == rld[j].reg_rtx)
4354 rld[i].opnum = MIN (rld[i].opnum, rld[j].opnum);
4355 transfer_replacements (i, j);
4356 rld[j].in = 0;
4359 #ifdef HAVE_cc0
4360 /* If we made any reloads for addresses, see if they violate a
4361 "no input reloads" requirement for this insn. But loads that we
4362 do after the insn (such as for output addresses) are fine. */
4363 if (no_input_reloads)
4364 for (i = 0; i < n_reloads; i++)
4365 gcc_assert (rld[i].in == 0
4366 || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS
4367 || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS);
4368 #endif
4370 /* Compute reload_mode and reload_nregs. */
4371 for (i = 0; i < n_reloads; i++)
4373 rld[i].mode
4374 = (rld[i].inmode == VOIDmode
4375 || (GET_MODE_SIZE (rld[i].outmode)
4376 > GET_MODE_SIZE (rld[i].inmode)))
4377 ? rld[i].outmode : rld[i].inmode;
4379 rld[i].nregs = CLASS_MAX_NREGS (rld[i].class, rld[i].mode);
4382 /* Special case a simple move with an input reload and a
4383 destination of a hard reg, if the hard reg is ok, use it. */
4384 for (i = 0; i < n_reloads; i++)
4385 if (rld[i].when_needed == RELOAD_FOR_INPUT
4386 && GET_CODE (PATTERN (insn)) == SET
4387 && REG_P (SET_DEST (PATTERN (insn)))
4388 && SET_SRC (PATTERN (insn)) == rld[i].in)
4390 rtx dest = SET_DEST (PATTERN (insn));
4391 unsigned int regno = REGNO (dest);
4393 if (regno < FIRST_PSEUDO_REGISTER
4394 && TEST_HARD_REG_BIT (reg_class_contents[rld[i].class], regno)
4395 && HARD_REGNO_MODE_OK (regno, rld[i].mode))
4397 int nr = hard_regno_nregs[regno][rld[i].mode];
4398 int ok = 1, nri;
4400 for (nri = 1; nri < nr; nri ++)
4401 if (! TEST_HARD_REG_BIT (reg_class_contents[rld[i].class], regno + nri))
4402 ok = 0;
4404 if (ok)
4405 rld[i].reg_rtx = dest;
4409 return retval;
4412 /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
4413 accepts a memory operand with constant address. */
4415 static int
4416 alternative_allows_memconst (const char *constraint, int altnum)
4418 int c;
4419 /* Skip alternatives before the one requested. */
4420 while (altnum > 0)
4422 while (*constraint++ != ',');
4423 altnum--;
4425 /* Scan the requested alternative for 'm' or 'o'.
4426 If one of them is present, this alternative accepts memory constants. */
4427 for (; (c = *constraint) && c != ',' && c != '#';
4428 constraint += CONSTRAINT_LEN (c, constraint))
4429 if (c == 'm' || c == 'o' || EXTRA_MEMORY_CONSTRAINT (c, constraint))
4430 return 1;
4431 return 0;
4434 /* Scan X for memory references and scan the addresses for reloading.
4435 Also checks for references to "constant" regs that we want to eliminate
4436 and replaces them with the values they stand for.
4437 We may alter X destructively if it contains a reference to such.
4438 If X is just a constant reg, we return the equivalent value
4439 instead of X.
4441 IND_LEVELS says how many levels of indirect addressing this machine
4442 supports.
4444 OPNUM and TYPE identify the purpose of the reload.
4446 IS_SET_DEST is true if X is the destination of a SET, which is not
4447 appropriate to be replaced by a constant.
4449 INSN, if nonzero, is the insn in which we do the reload. It is used
4450 to determine if we may generate output reloads, and where to put USEs
4451 for pseudos that we have to replace with stack slots.
4453 ADDRESS_RELOADED. If nonzero, is a pointer to where we put the
4454 result of find_reloads_address. */
4456 static rtx
4457 find_reloads_toplev (rtx x, int opnum, enum reload_type type,
4458 int ind_levels, int is_set_dest, rtx insn,
4459 int *address_reloaded)
4461 RTX_CODE code = GET_CODE (x);
4463 const char *fmt = GET_RTX_FORMAT (code);
4464 int i;
4465 int copied;
4467 if (code == REG)
4469 /* This code is duplicated for speed in find_reloads. */
4470 int regno = REGNO (x);
4471 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
4472 x = reg_equiv_constant[regno];
4473 #if 0
4474 /* This creates (subreg (mem...)) which would cause an unnecessary
4475 reload of the mem. */
4476 else if (reg_equiv_mem[regno] != 0)
4477 x = reg_equiv_mem[regno];
4478 #endif
4479 else if (reg_equiv_memory_loc[regno]
4480 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
4482 rtx mem = make_memloc (x, regno);
4483 if (reg_equiv_address[regno]
4484 || ! rtx_equal_p (mem, reg_equiv_mem[regno]))
4486 /* If this is not a toplevel operand, find_reloads doesn't see
4487 this substitution. We have to emit a USE of the pseudo so
4488 that delete_output_reload can see it. */
4489 if (replace_reloads && recog_data.operand[opnum] != x)
4490 /* We mark the USE with QImode so that we recognize it
4491 as one that can be safely deleted at the end of
4492 reload. */
4493 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, x), insn),
4494 QImode);
4495 x = mem;
4496 i = find_reloads_address (GET_MODE (x), &x, XEXP (x, 0), &XEXP (x, 0),
4497 opnum, type, ind_levels, insn);
4498 if (address_reloaded)
4499 *address_reloaded = i;
4502 return x;
4504 if (code == MEM)
4506 rtx tem = x;
4508 i = find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
4509 opnum, type, ind_levels, insn);
4510 if (address_reloaded)
4511 *address_reloaded = i;
4513 return tem;
4516 if (code == SUBREG && REG_P (SUBREG_REG (x)))
4518 /* Check for SUBREG containing a REG that's equivalent to a
4519 constant. If the constant has a known value, truncate it
4520 right now. Similarly if we are extracting a single-word of a
4521 multi-word constant. If the constant is symbolic, allow it
4522 to be substituted normally. push_reload will strip the
4523 subreg later. The constant must not be VOIDmode, because we
4524 will lose the mode of the register (this should never happen
4525 because one of the cases above should handle it). */
4527 int regno = REGNO (SUBREG_REG (x));
4528 rtx tem;
4530 if (subreg_lowpart_p (x)
4531 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4532 && reg_equiv_constant[regno] != 0
4533 && (tem = gen_lowpart_common (GET_MODE (x),
4534 reg_equiv_constant[regno])) != 0)
4535 return tem;
4537 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
4538 && reg_equiv_constant[regno] != 0)
4540 tem =
4541 simplify_gen_subreg (GET_MODE (x), reg_equiv_constant[regno],
4542 GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x));
4543 gcc_assert (tem);
4544 return tem;
4547 /* If the subreg contains a reg that will be converted to a mem,
4548 convert the subreg to a narrower memref now.
4549 Otherwise, we would get (subreg (mem ...) ...),
4550 which would force reload of the mem.
4552 We also need to do this if there is an equivalent MEM that is
4553 not offsettable. In that case, alter_subreg would produce an
4554 invalid address on big-endian machines.
4556 For machines that extend byte loads, we must not reload using
4557 a wider mode if we have a paradoxical SUBREG. find_reloads will
4558 force a reload in that case. So we should not do anything here. */
4560 else if (regno >= FIRST_PSEUDO_REGISTER
4561 #ifdef LOAD_EXTEND_OP
4562 && (GET_MODE_SIZE (GET_MODE (x))
4563 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
4564 #endif
4565 && (reg_equiv_address[regno] != 0
4566 || (reg_equiv_mem[regno] != 0
4567 && (! strict_memory_address_p (GET_MODE (x),
4568 XEXP (reg_equiv_mem[regno], 0))
4569 || ! offsettable_memref_p (reg_equiv_mem[regno])
4570 || num_not_at_initial_offset))))
4571 x = find_reloads_subreg_address (x, 1, opnum, type, ind_levels,
4572 insn);
4575 for (copied = 0, i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4577 if (fmt[i] == 'e')
4579 rtx new_part = find_reloads_toplev (XEXP (x, i), opnum, type,
4580 ind_levels, is_set_dest, insn,
4581 address_reloaded);
4582 /* If we have replaced a reg with it's equivalent memory loc -
4583 that can still be handled here e.g. if it's in a paradoxical
4584 subreg - we must make the change in a copy, rather than using
4585 a destructive change. This way, find_reloads can still elect
4586 not to do the change. */
4587 if (new_part != XEXP (x, i) && ! CONSTANT_P (new_part) && ! copied)
4589 x = shallow_copy_rtx (x);
4590 copied = 1;
4592 XEXP (x, i) = new_part;
4595 return x;
4598 /* Return a mem ref for the memory equivalent of reg REGNO.
4599 This mem ref is not shared with anything. */
4601 static rtx
4602 make_memloc (rtx ad, int regno)
4604 /* We must rerun eliminate_regs, in case the elimination
4605 offsets have changed. */
4606 rtx tem
4607 = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0, NULL_RTX), 0);
4609 /* If TEM might contain a pseudo, we must copy it to avoid
4610 modifying it when we do the substitution for the reload. */
4611 if (rtx_varies_p (tem, 0))
4612 tem = copy_rtx (tem);
4614 tem = replace_equiv_address_nv (reg_equiv_memory_loc[regno], tem);
4615 tem = adjust_address_nv (tem, GET_MODE (ad), 0);
4617 /* Copy the result if it's still the same as the equivalence, to avoid
4618 modifying it when we do the substitution for the reload. */
4619 if (tem == reg_equiv_memory_loc[regno])
4620 tem = copy_rtx (tem);
4621 return tem;
4624 /* Returns true if AD could be turned into a valid memory reference
4625 to mode MODE by reloading the part pointed to by PART into a
4626 register. */
4628 static int
4629 maybe_memory_address_p (enum machine_mode mode, rtx ad, rtx *part)
4631 int retv;
4632 rtx tem = *part;
4633 rtx reg = gen_rtx_REG (GET_MODE (tem), max_reg_num ());
4635 *part = reg;
4636 retv = memory_address_p (mode, ad);
4637 *part = tem;
4639 return retv;
4642 /* Record all reloads needed for handling memory address AD
4643 which appears in *LOC in a memory reference to mode MODE
4644 which itself is found in location *MEMREFLOC.
4645 Note that we take shortcuts assuming that no multi-reg machine mode
4646 occurs as part of an address.
4648 OPNUM and TYPE specify the purpose of this reload.
4650 IND_LEVELS says how many levels of indirect addressing this machine
4651 supports.
4653 INSN, if nonzero, is the insn in which we do the reload. It is used
4654 to determine if we may generate output reloads, and where to put USEs
4655 for pseudos that we have to replace with stack slots.
4657 Value is one if this address is reloaded or replaced as a whole; it is
4658 zero if the top level of this address was not reloaded or replaced, and
4659 it is -1 if it may or may not have been reloaded or replaced.
4661 Note that there is no verification that the address will be valid after
4662 this routine does its work. Instead, we rely on the fact that the address
4663 was valid when reload started. So we need only undo things that reload
4664 could have broken. These are wrong register types, pseudos not allocated
4665 to a hard register, and frame pointer elimination. */
4667 static int
4668 find_reloads_address (enum machine_mode mode, rtx *memrefloc, rtx ad,
4669 rtx *loc, int opnum, enum reload_type type,
4670 int ind_levels, rtx insn)
4672 int regno;
4673 int removed_and = 0;
4674 int op_index;
4675 rtx tem;
4677 /* If the address is a register, see if it is a legitimate address and
4678 reload if not. We first handle the cases where we need not reload
4679 or where we must reload in a non-standard way. */
4681 if (REG_P (ad))
4683 regno = REGNO (ad);
4685 /* If the register is equivalent to an invariant expression, substitute
4686 the invariant, and eliminate any eliminable register references. */
4687 tem = reg_equiv_constant[regno];
4688 if (tem != 0
4689 && (tem = eliminate_regs (tem, mode, insn))
4690 && strict_memory_address_p (mode, tem))
4692 *loc = ad = tem;
4693 return 0;
4696 tem = reg_equiv_memory_loc[regno];
4697 if (tem != 0)
4699 if (reg_equiv_address[regno] != 0 || num_not_at_initial_offset)
4701 tem = make_memloc (ad, regno);
4702 if (! strict_memory_address_p (GET_MODE (tem), XEXP (tem, 0)))
4704 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
4705 &XEXP (tem, 0), opnum,
4706 ADDR_TYPE (type), ind_levels, insn);
4708 /* We can avoid a reload if the register's equivalent memory
4709 expression is valid as an indirect memory address.
4710 But not all addresses are valid in a mem used as an indirect
4711 address: only reg or reg+constant. */
4713 if (ind_levels > 0
4714 && strict_memory_address_p (mode, tem)
4715 && (REG_P (XEXP (tem, 0))
4716 || (GET_CODE (XEXP (tem, 0)) == PLUS
4717 && REG_P (XEXP (XEXP (tem, 0), 0))
4718 && CONSTANT_P (XEXP (XEXP (tem, 0), 1)))))
4720 /* TEM is not the same as what we'll be replacing the
4721 pseudo with after reload, put a USE in front of INSN
4722 in the final reload pass. */
4723 if (replace_reloads
4724 && num_not_at_initial_offset
4725 && ! rtx_equal_p (tem, reg_equiv_mem[regno]))
4727 *loc = tem;
4728 /* We mark the USE with QImode so that we
4729 recognize it as one that can be safely
4730 deleted at the end of reload. */
4731 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad),
4732 insn), QImode);
4734 /* This doesn't really count as replacing the address
4735 as a whole, since it is still a memory access. */
4737 return 0;
4739 ad = tem;
4743 /* The only remaining case where we can avoid a reload is if this is a
4744 hard register that is valid as a base register and which is not the
4745 subject of a CLOBBER in this insn. */
4747 else if (regno < FIRST_PSEUDO_REGISTER
4748 && REGNO_MODE_OK_FOR_BASE_P (regno, mode)
4749 && ! regno_clobbered_p (regno, this_insn, mode, 0))
4750 return 0;
4752 /* If we do not have one of the cases above, we must do the reload. */
4753 push_reload (ad, NULL_RTX, loc, (rtx*) 0, MODE_BASE_REG_CLASS (mode),
4754 GET_MODE (ad), VOIDmode, 0, 0, opnum, type);
4755 return 1;
4758 if (strict_memory_address_p (mode, ad))
4760 /* The address appears valid, so reloads are not needed.
4761 But the address may contain an eliminable register.
4762 This can happen because a machine with indirect addressing
4763 may consider a pseudo register by itself a valid address even when
4764 it has failed to get a hard reg.
4765 So do a tree-walk to find and eliminate all such regs. */
4767 /* But first quickly dispose of a common case. */
4768 if (GET_CODE (ad) == PLUS
4769 && GET_CODE (XEXP (ad, 1)) == CONST_INT
4770 && REG_P (XEXP (ad, 0))
4771 && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
4772 return 0;
4774 subst_reg_equivs_changed = 0;
4775 *loc = subst_reg_equivs (ad, insn);
4777 if (! subst_reg_equivs_changed)
4778 return 0;
4780 /* Check result for validity after substitution. */
4781 if (strict_memory_address_p (mode, ad))
4782 return 0;
4785 #ifdef LEGITIMIZE_RELOAD_ADDRESS
4788 if (memrefloc)
4790 LEGITIMIZE_RELOAD_ADDRESS (ad, GET_MODE (*memrefloc), opnum, type,
4791 ind_levels, win);
4793 break;
4794 win:
4795 *memrefloc = copy_rtx (*memrefloc);
4796 XEXP (*memrefloc, 0) = ad;
4797 move_replacements (&ad, &XEXP (*memrefloc, 0));
4798 return -1;
4800 while (0);
4801 #endif
4803 /* The address is not valid. We have to figure out why. First see if
4804 we have an outer AND and remove it if so. Then analyze what's inside. */
4806 if (GET_CODE (ad) == AND)
4808 removed_and = 1;
4809 loc = &XEXP (ad, 0);
4810 ad = *loc;
4813 /* One possibility for why the address is invalid is that it is itself
4814 a MEM. This can happen when the frame pointer is being eliminated, a
4815 pseudo is not allocated to a hard register, and the offset between the
4816 frame and stack pointers is not its initial value. In that case the
4817 pseudo will have been replaced by a MEM referring to the
4818 stack pointer. */
4819 if (MEM_P (ad))
4821 /* First ensure that the address in this MEM is valid. Then, unless
4822 indirect addresses are valid, reload the MEM into a register. */
4823 tem = ad;
4824 find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
4825 opnum, ADDR_TYPE (type),
4826 ind_levels == 0 ? 0 : ind_levels - 1, insn);
4828 /* If tem was changed, then we must create a new memory reference to
4829 hold it and store it back into memrefloc. */
4830 if (tem != ad && memrefloc)
4832 *memrefloc = copy_rtx (*memrefloc);
4833 copy_replacements (tem, XEXP (*memrefloc, 0));
4834 loc = &XEXP (*memrefloc, 0);
4835 if (removed_and)
4836 loc = &XEXP (*loc, 0);
4839 /* Check similar cases as for indirect addresses as above except
4840 that we can allow pseudos and a MEM since they should have been
4841 taken care of above. */
4843 if (ind_levels == 0
4844 || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
4845 || MEM_P (XEXP (tem, 0))
4846 || ! (REG_P (XEXP (tem, 0))
4847 || (GET_CODE (XEXP (tem, 0)) == PLUS
4848 && REG_P (XEXP (XEXP (tem, 0), 0))
4849 && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT)))
4851 /* Must use TEM here, not AD, since it is the one that will
4852 have any subexpressions reloaded, if needed. */
4853 push_reload (tem, NULL_RTX, loc, (rtx*) 0,
4854 MODE_BASE_REG_CLASS (mode), GET_MODE (tem),
4855 VOIDmode, 0,
4856 0, opnum, type);
4857 return ! removed_and;
4859 else
4860 return 0;
4863 /* If we have address of a stack slot but it's not valid because the
4864 displacement is too large, compute the sum in a register.
4865 Handle all base registers here, not just fp/ap/sp, because on some
4866 targets (namely SH) we can also get too large displacements from
4867 big-endian corrections. */
4868 else if (GET_CODE (ad) == PLUS
4869 && REG_P (XEXP (ad, 0))
4870 && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER
4871 && REG_MODE_OK_FOR_BASE_P (XEXP (ad, 0), mode)
4872 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
4874 /* Unshare the MEM rtx so we can safely alter it. */
4875 if (memrefloc)
4877 *memrefloc = copy_rtx (*memrefloc);
4878 loc = &XEXP (*memrefloc, 0);
4879 if (removed_and)
4880 loc = &XEXP (*loc, 0);
4883 if (double_reg_address_ok)
4885 /* Unshare the sum as well. */
4886 *loc = ad = copy_rtx (ad);
4888 /* Reload the displacement into an index reg.
4889 We assume the frame pointer or arg pointer is a base reg. */
4890 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
4891 INDEX_REG_CLASS, GET_MODE (ad), opnum,
4892 type, ind_levels);
4893 return 0;
4895 else
4897 /* If the sum of two regs is not necessarily valid,
4898 reload the sum into a base reg.
4899 That will at least work. */
4900 find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode),
4901 Pmode, opnum, type, ind_levels);
4903 return ! removed_and;
4906 /* If we have an indexed stack slot, there are three possible reasons why
4907 it might be invalid: The index might need to be reloaded, the address
4908 might have been made by frame pointer elimination and hence have a
4909 constant out of range, or both reasons might apply.
4911 We can easily check for an index needing reload, but even if that is the
4912 case, we might also have an invalid constant. To avoid making the
4913 conservative assumption and requiring two reloads, we see if this address
4914 is valid when not interpreted strictly. If it is, the only problem is
4915 that the index needs a reload and find_reloads_address_1 will take care
4916 of it.
4918 Handle all base registers here, not just fp/ap/sp, because on some
4919 targets (namely SPARC) we can also get invalid addresses from preventive
4920 subreg big-endian corrections made by find_reloads_toplev. We
4921 can also get expressions involving LO_SUM (rather than PLUS) from
4922 find_reloads_subreg_address.
4924 If we decide to do something, it must be that `double_reg_address_ok'
4925 is true. We generate a reload of the base register + constant and
4926 rework the sum so that the reload register will be added to the index.
4927 This is safe because we know the address isn't shared.
4929 We check for the base register as both the first and second operand of
4930 the innermost PLUS and/or LO_SUM. */
4932 for (op_index = 0; op_index < 2; ++op_index)
4934 rtx operand;
4936 if (!(GET_CODE (ad) == PLUS
4937 && GET_CODE (XEXP (ad, 1)) == CONST_INT
4938 && (GET_CODE (XEXP (ad, 0)) == PLUS
4939 || GET_CODE (XEXP (ad, 0)) == LO_SUM)))
4940 continue;
4942 operand = XEXP (XEXP (ad, 0), op_index);
4943 if (!REG_P (operand) || REGNO (operand) >= FIRST_PSEUDO_REGISTER)
4944 continue;
4946 if ((REG_MODE_OK_FOR_BASE_P (operand, mode)
4947 || operand == frame_pointer_rtx
4948 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
4949 || operand == hard_frame_pointer_rtx
4950 #endif
4951 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4952 || operand == arg_pointer_rtx
4953 #endif
4954 || operand == stack_pointer_rtx)
4955 && ! maybe_memory_address_p (mode, ad,
4956 &XEXP (XEXP (ad, 0), 1 - op_index)))
4958 rtx offset_reg;
4959 rtx addend;
4961 offset_reg = plus_constant (operand, INTVAL (XEXP (ad, 1)));
4962 addend = XEXP (XEXP (ad, 0), 1 - op_index);
4964 /* Form the adjusted address. */
4965 if (GET_CODE (XEXP (ad, 0)) == PLUS)
4966 ad = gen_rtx_PLUS (GET_MODE (ad),
4967 op_index == 0 ? offset_reg : addend,
4968 op_index == 0 ? addend : offset_reg);
4969 else
4970 ad = gen_rtx_LO_SUM (GET_MODE (ad),
4971 op_index == 0 ? offset_reg : addend,
4972 op_index == 0 ? addend : offset_reg);
4973 *loc = ad;
4975 find_reloads_address_part (XEXP (ad, op_index),
4976 &XEXP (ad, op_index),
4977 MODE_BASE_REG_CLASS (mode),
4978 GET_MODE (ad), opnum, type, ind_levels);
4979 find_reloads_address_1 (mode,
4980 XEXP (ad, 1 - op_index), 1,
4981 &XEXP (ad, 1 - op_index), opnum,
4982 type, 0, insn);
4984 return 0;
4988 /* See if address becomes valid when an eliminable register
4989 in a sum is replaced. */
4991 tem = ad;
4992 if (GET_CODE (ad) == PLUS)
4993 tem = subst_indexed_address (ad);
4994 if (tem != ad && strict_memory_address_p (mode, tem))
4996 /* Ok, we win that way. Replace any additional eliminable
4997 registers. */
4999 subst_reg_equivs_changed = 0;
5000 tem = subst_reg_equivs (tem, insn);
5002 /* Make sure that didn't make the address invalid again. */
5004 if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
5006 *loc = tem;
5007 return 0;
5011 /* If constants aren't valid addresses, reload the constant address
5012 into a register. */
5013 if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad))
5015 /* If AD is an address in the constant pool, the MEM rtx may be shared.
5016 Unshare it so we can safely alter it. */
5017 if (memrefloc && GET_CODE (ad) == SYMBOL_REF
5018 && CONSTANT_POOL_ADDRESS_P (ad))
5020 *memrefloc = copy_rtx (*memrefloc);
5021 loc = &XEXP (*memrefloc, 0);
5022 if (removed_and)
5023 loc = &XEXP (*loc, 0);
5026 find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode),
5027 Pmode, opnum, type, ind_levels);
5028 return ! removed_and;
5031 return find_reloads_address_1 (mode, ad, 0, loc, opnum, type, ind_levels,
5032 insn);
5035 /* Find all pseudo regs appearing in AD
5036 that are eliminable in favor of equivalent values
5037 and do not have hard regs; replace them by their equivalents.
5038 INSN, if nonzero, is the insn in which we do the reload. We put USEs in
5039 front of it for pseudos that we have to replace with stack slots. */
5041 static rtx
5042 subst_reg_equivs (rtx ad, rtx insn)
5044 RTX_CODE code = GET_CODE (ad);
5045 int i;
5046 const char *fmt;
5048 switch (code)
5050 case HIGH:
5051 case CONST_INT:
5052 case CONST:
5053 case CONST_DOUBLE:
5054 case CONST_VECTOR:
5055 case SYMBOL_REF:
5056 case LABEL_REF:
5057 case PC:
5058 case CC0:
5059 return ad;
5061 case REG:
5063 int regno = REGNO (ad);
5065 if (reg_equiv_constant[regno] != 0)
5067 subst_reg_equivs_changed = 1;
5068 return reg_equiv_constant[regno];
5070 if (reg_equiv_memory_loc[regno] && num_not_at_initial_offset)
5072 rtx mem = make_memloc (ad, regno);
5073 if (! rtx_equal_p (mem, reg_equiv_mem[regno]))
5075 subst_reg_equivs_changed = 1;
5076 /* We mark the USE with QImode so that we recognize it
5077 as one that can be safely deleted at the end of
5078 reload. */
5079 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad), insn),
5080 QImode);
5081 return mem;
5085 return ad;
5087 case PLUS:
5088 /* Quickly dispose of a common case. */
5089 if (XEXP (ad, 0) == frame_pointer_rtx
5090 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
5091 return ad;
5092 break;
5094 default:
5095 break;
5098 fmt = GET_RTX_FORMAT (code);
5099 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5100 if (fmt[i] == 'e')
5101 XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i), insn);
5102 return ad;
5105 /* Compute the sum of X and Y, making canonicalizations assumed in an
5106 address, namely: sum constant integers, surround the sum of two
5107 constants with a CONST, put the constant as the second operand, and
5108 group the constant on the outermost sum.
5110 This routine assumes both inputs are already in canonical form. */
5113 form_sum (rtx x, rtx y)
5115 rtx tem;
5116 enum machine_mode mode = GET_MODE (x);
5118 if (mode == VOIDmode)
5119 mode = GET_MODE (y);
5121 if (mode == VOIDmode)
5122 mode = Pmode;
5124 if (GET_CODE (x) == CONST_INT)
5125 return plus_constant (y, INTVAL (x));
5126 else if (GET_CODE (y) == CONST_INT)
5127 return plus_constant (x, INTVAL (y));
5128 else if (CONSTANT_P (x))
5129 tem = x, x = y, y = tem;
5131 if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
5132 return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
5134 /* Note that if the operands of Y are specified in the opposite
5135 order in the recursive calls below, infinite recursion will occur. */
5136 if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
5137 return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
5139 /* If both constant, encapsulate sum. Otherwise, just form sum. A
5140 constant will have been placed second. */
5141 if (CONSTANT_P (x) && CONSTANT_P (y))
5143 if (GET_CODE (x) == CONST)
5144 x = XEXP (x, 0);
5145 if (GET_CODE (y) == CONST)
5146 y = XEXP (y, 0);
5148 return gen_rtx_CONST (VOIDmode, gen_rtx_PLUS (mode, x, y));
5151 return gen_rtx_PLUS (mode, x, y);
5154 /* If ADDR is a sum containing a pseudo register that should be
5155 replaced with a constant (from reg_equiv_constant),
5156 return the result of doing so, and also apply the associative
5157 law so that the result is more likely to be a valid address.
5158 (But it is not guaranteed to be one.)
5160 Note that at most one register is replaced, even if more are
5161 replaceable. Also, we try to put the result into a canonical form
5162 so it is more likely to be a valid address.
5164 In all other cases, return ADDR. */
5166 static rtx
5167 subst_indexed_address (rtx addr)
5169 rtx op0 = 0, op1 = 0, op2 = 0;
5170 rtx tem;
5171 int regno;
5173 if (GET_CODE (addr) == PLUS)
5175 /* Try to find a register to replace. */
5176 op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
5177 if (REG_P (op0)
5178 && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
5179 && reg_renumber[regno] < 0
5180 && reg_equiv_constant[regno] != 0)
5181 op0 = reg_equiv_constant[regno];
5182 else if (REG_P (op1)
5183 && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
5184 && reg_renumber[regno] < 0
5185 && reg_equiv_constant[regno] != 0)
5186 op1 = reg_equiv_constant[regno];
5187 else if (GET_CODE (op0) == PLUS
5188 && (tem = subst_indexed_address (op0)) != op0)
5189 op0 = tem;
5190 else if (GET_CODE (op1) == PLUS
5191 && (tem = subst_indexed_address (op1)) != op1)
5192 op1 = tem;
5193 else
5194 return addr;
5196 /* Pick out up to three things to add. */
5197 if (GET_CODE (op1) == PLUS)
5198 op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
5199 else if (GET_CODE (op0) == PLUS)
5200 op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
5202 /* Compute the sum. */
5203 if (op2 != 0)
5204 op1 = form_sum (op1, op2);
5205 if (op1 != 0)
5206 op0 = form_sum (op0, op1);
5208 return op0;
5210 return addr;
5213 /* Update the REG_INC notes for an insn. It updates all REG_INC
5214 notes for the instruction which refer to REGNO the to refer
5215 to the reload number.
5217 INSN is the insn for which any REG_INC notes need updating.
5219 REGNO is the register number which has been reloaded.
5221 RELOADNUM is the reload number. */
5223 static void
5224 update_auto_inc_notes (rtx insn ATTRIBUTE_UNUSED, int regno ATTRIBUTE_UNUSED,
5225 int reloadnum ATTRIBUTE_UNUSED)
5227 #ifdef AUTO_INC_DEC
5228 rtx link;
5230 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
5231 if (REG_NOTE_KIND (link) == REG_INC
5232 && (int) REGNO (XEXP (link, 0)) == regno)
5233 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5234 #endif
5237 /* Record the pseudo registers we must reload into hard registers in a
5238 subexpression of a would-be memory address, X referring to a value
5239 in mode MODE. (This function is not called if the address we find
5240 is strictly valid.)
5242 CONTEXT = 1 means we are considering regs as index regs,
5243 = 0 means we are considering them as base regs, = 2 means we
5244 are considering them as base regs for REG + REG.
5246 OPNUM and TYPE specify the purpose of any reloads made.
5248 IND_LEVELS says how many levels of indirect addressing are
5249 supported at this point in the address.
5251 INSN, if nonzero, is the insn in which we do the reload. It is used
5252 to determine if we may generate output reloads.
5254 We return nonzero if X, as a whole, is reloaded or replaced. */
5256 /* Note that we take shortcuts assuming that no multi-reg machine mode
5257 occurs as part of an address.
5258 Also, this is not fully machine-customizable; it works for machines
5259 such as VAXen and 68000's and 32000's, but other possible machines
5260 could have addressing modes that this does not handle right.
5261 If you add push_reload calls here, you need to make sure gen_reload
5262 handles those cases gracefully. */
5264 static int
5265 find_reloads_address_1 (enum machine_mode mode, rtx x, int context,
5266 rtx *loc, int opnum, enum reload_type type,
5267 int ind_levels, rtx insn)
5269 #define REG_OK_FOR_CONTEXT(CONTEXT, REGNO, MODE) \
5270 ((CONTEXT) == 2 \
5271 ? REGNO_MODE_OK_FOR_REG_BASE_P (REGNO, MODE) \
5272 : (CONTEXT) == 1 \
5273 ? REGNO_OK_FOR_INDEX_P (REGNO) \
5274 : REGNO_MODE_OK_FOR_BASE_P (REGNO, MODE))
5276 enum reg_class context_reg_class;
5277 RTX_CODE code = GET_CODE (x);
5279 if (context == 2)
5280 context_reg_class = MODE_BASE_REG_REG_CLASS (mode);
5281 else if (context == 1)
5282 context_reg_class = INDEX_REG_CLASS;
5283 else
5284 context_reg_class = MODE_BASE_REG_CLASS (mode);
5286 switch (code)
5288 case PLUS:
5290 rtx orig_op0 = XEXP (x, 0);
5291 rtx orig_op1 = XEXP (x, 1);
5292 RTX_CODE code0 = GET_CODE (orig_op0);
5293 RTX_CODE code1 = GET_CODE (orig_op1);
5294 rtx op0 = orig_op0;
5295 rtx op1 = orig_op1;
5297 if (GET_CODE (op0) == SUBREG)
5299 op0 = SUBREG_REG (op0);
5300 code0 = GET_CODE (op0);
5301 if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER)
5302 op0 = gen_rtx_REG (word_mode,
5303 (REGNO (op0) +
5304 subreg_regno_offset (REGNO (SUBREG_REG (orig_op0)),
5305 GET_MODE (SUBREG_REG (orig_op0)),
5306 SUBREG_BYTE (orig_op0),
5307 GET_MODE (orig_op0))));
5310 if (GET_CODE (op1) == SUBREG)
5312 op1 = SUBREG_REG (op1);
5313 code1 = GET_CODE (op1);
5314 if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER)
5315 /* ??? Why is this given op1's mode and above for
5316 ??? op0 SUBREGs we use word_mode? */
5317 op1 = gen_rtx_REG (GET_MODE (op1),
5318 (REGNO (op1) +
5319 subreg_regno_offset (REGNO (SUBREG_REG (orig_op1)),
5320 GET_MODE (SUBREG_REG (orig_op1)),
5321 SUBREG_BYTE (orig_op1),
5322 GET_MODE (orig_op1))));
5324 /* Plus in the index register may be created only as a result of
5325 register remateralization for expression like &localvar*4. Reload it.
5326 It may be possible to combine the displacement on the outer level,
5327 but it is probably not worthwhile to do so. */
5328 if (context == 1)
5330 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5331 opnum, ADDR_TYPE (type), ind_levels, insn);
5332 push_reload (*loc, NULL_RTX, loc, (rtx*) 0,
5333 context_reg_class,
5334 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5335 return 1;
5338 if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
5339 || code0 == ZERO_EXTEND || code1 == MEM)
5341 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5342 type, ind_levels, insn);
5343 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5344 type, ind_levels, insn);
5347 else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
5348 || code1 == ZERO_EXTEND || code0 == MEM)
5350 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5351 type, ind_levels, insn);
5352 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5353 type, ind_levels, insn);
5356 else if (code0 == CONST_INT || code0 == CONST
5357 || code0 == SYMBOL_REF || code0 == LABEL_REF)
5358 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5359 type, ind_levels, insn);
5361 else if (code1 == CONST_INT || code1 == CONST
5362 || code1 == SYMBOL_REF || code1 == LABEL_REF)
5363 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5364 type, ind_levels, insn);
5366 else if (code0 == REG && code1 == REG)
5368 if (REG_OK_FOR_INDEX_P (op0)
5369 && REG_MODE_OK_FOR_REG_BASE_P (op1, mode))
5370 return 0;
5371 else if (REG_OK_FOR_INDEX_P (op1)
5372 && REG_MODE_OK_FOR_REG_BASE_P (op0, mode))
5373 return 0;
5374 else if (REG_MODE_OK_FOR_REG_BASE_P (op1, mode))
5375 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5376 type, ind_levels, insn);
5377 else if (REG_MODE_OK_FOR_REG_BASE_P (op0, mode))
5378 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5379 type, ind_levels, insn);
5380 else if (REG_OK_FOR_INDEX_P (op1))
5381 find_reloads_address_1 (mode, orig_op0, 2, &XEXP (x, 0), opnum,
5382 type, ind_levels, insn);
5383 else if (REG_OK_FOR_INDEX_P (op0))
5384 find_reloads_address_1 (mode, orig_op1, 2, &XEXP (x, 1), opnum,
5385 type, ind_levels, insn);
5386 else
5388 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5389 type, ind_levels, insn);
5390 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5391 type, ind_levels, insn);
5395 else if (code0 == REG)
5397 find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum,
5398 type, ind_levels, insn);
5399 find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum,
5400 type, ind_levels, insn);
5403 else if (code1 == REG)
5405 find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum,
5406 type, ind_levels, insn);
5407 find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum,
5408 type, ind_levels, insn);
5412 return 0;
5414 case POST_MODIFY:
5415 case PRE_MODIFY:
5417 rtx op0 = XEXP (x, 0);
5418 rtx op1 = XEXP (x, 1);
5419 int regno;
5420 int reloadnum;
5422 if (GET_CODE (op1) != PLUS && GET_CODE (op1) != MINUS)
5423 return 0;
5425 /* Currently, we only support {PRE,POST}_MODIFY constructs
5426 where a base register is {inc,dec}remented by the contents
5427 of another register or by a constant value. Thus, these
5428 operands must match. */
5429 gcc_assert (op0 == XEXP (op1, 0));
5431 /* Require index register (or constant). Let's just handle the
5432 register case in the meantime... If the target allows
5433 auto-modify by a constant then we could try replacing a pseudo
5434 register with its equivalent constant where applicable. */
5435 if (REG_P (XEXP (op1, 1)))
5436 if (!REGNO_OK_FOR_INDEX_P (REGNO (XEXP (op1, 1))))
5437 find_reloads_address_1 (mode, XEXP (op1, 1), 1, &XEXP (op1, 1),
5438 opnum, type, ind_levels, insn);
5440 gcc_assert (REG_P (XEXP (op1, 0)));
5442 regno = REGNO (XEXP (op1, 0));
5444 /* A register that is incremented cannot be constant! */
5445 gcc_assert (regno < FIRST_PSEUDO_REGISTER
5446 || reg_equiv_constant[regno] == 0);
5448 /* Handle a register that is equivalent to a memory location
5449 which cannot be addressed directly. */
5450 if (reg_equiv_memory_loc[regno] != 0
5451 && (reg_equiv_address[regno] != 0
5452 || num_not_at_initial_offset))
5454 rtx tem = make_memloc (XEXP (x, 0), regno);
5456 if (reg_equiv_address[regno]
5457 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5459 /* First reload the memory location's address.
5460 We can't use ADDR_TYPE (type) here, because we need to
5461 write back the value after reading it, hence we actually
5462 need two registers. */
5463 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5464 &XEXP (tem, 0), opnum,
5465 RELOAD_OTHER,
5466 ind_levels, insn);
5468 /* Then reload the memory location into a base
5469 register. */
5470 reloadnum = push_reload (tem, tem, &XEXP (x, 0),
5471 &XEXP (op1, 0),
5472 MODE_BASE_REG_CLASS (mode),
5473 GET_MODE (x), GET_MODE (x), 0,
5474 0, opnum, RELOAD_OTHER);
5476 update_auto_inc_notes (this_insn, regno, reloadnum);
5477 return 0;
5481 if (reg_renumber[regno] >= 0)
5482 regno = reg_renumber[regno];
5484 /* We require a base register here... */
5485 if (!REGNO_MODE_OK_FOR_BASE_P (regno, GET_MODE (x)))
5487 reloadnum = push_reload (XEXP (op1, 0), XEXP (x, 0),
5488 &XEXP (op1, 0), &XEXP (x, 0),
5489 MODE_BASE_REG_CLASS (mode),
5490 GET_MODE (x), GET_MODE (x), 0, 0,
5491 opnum, RELOAD_OTHER);
5493 update_auto_inc_notes (this_insn, regno, reloadnum);
5494 return 0;
5497 return 0;
5499 case POST_INC:
5500 case POST_DEC:
5501 case PRE_INC:
5502 case PRE_DEC:
5503 if (REG_P (XEXP (x, 0)))
5505 int regno = REGNO (XEXP (x, 0));
5506 int value = 0;
5507 rtx x_orig = x;
5509 /* A register that is incremented cannot be constant! */
5510 gcc_assert (regno < FIRST_PSEUDO_REGISTER
5511 || reg_equiv_constant[regno] == 0);
5513 /* Handle a register that is equivalent to a memory location
5514 which cannot be addressed directly. */
5515 if (reg_equiv_memory_loc[regno] != 0
5516 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5518 rtx tem = make_memloc (XEXP (x, 0), regno);
5519 if (reg_equiv_address[regno]
5520 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5522 /* First reload the memory location's address.
5523 We can't use ADDR_TYPE (type) here, because we need to
5524 write back the value after reading it, hence we actually
5525 need two registers. */
5526 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5527 &XEXP (tem, 0), opnum, type,
5528 ind_levels, insn);
5529 /* Put this inside a new increment-expression. */
5530 x = gen_rtx_fmt_e (GET_CODE (x), GET_MODE (x), tem);
5531 /* Proceed to reload that, as if it contained a register. */
5535 /* If we have a hard register that is ok as an index,
5536 don't make a reload. If an autoincrement of a nice register
5537 isn't "valid", it must be that no autoincrement is "valid".
5538 If that is true and something made an autoincrement anyway,
5539 this must be a special context where one is allowed.
5540 (For example, a "push" instruction.)
5541 We can't improve this address, so leave it alone. */
5543 /* Otherwise, reload the autoincrement into a suitable hard reg
5544 and record how much to increment by. */
5546 if (reg_renumber[regno] >= 0)
5547 regno = reg_renumber[regno];
5548 if (regno >= FIRST_PSEUDO_REGISTER
5549 || !REG_OK_FOR_CONTEXT (context, regno, mode))
5551 int reloadnum;
5553 /* If we can output the register afterwards, do so, this
5554 saves the extra update.
5555 We can do so if we have an INSN - i.e. no JUMP_INSN nor
5556 CALL_INSN - and it does not set CC0.
5557 But don't do this if we cannot directly address the
5558 memory location, since this will make it harder to
5559 reuse address reloads, and increases register pressure.
5560 Also don't do this if we can probably update x directly. */
5561 rtx equiv = (MEM_P (XEXP (x, 0))
5562 ? XEXP (x, 0)
5563 : reg_equiv_mem[regno]);
5564 int icode = (int) add_optab->handlers[(int) Pmode].insn_code;
5565 if (insn && NONJUMP_INSN_P (insn) && equiv
5566 && memory_operand (equiv, GET_MODE (equiv))
5567 #ifdef HAVE_cc0
5568 && ! sets_cc0_p (PATTERN (insn))
5569 #endif
5570 && ! (icode != CODE_FOR_nothing
5571 && ((*insn_data[icode].operand[0].predicate)
5572 (equiv, Pmode))
5573 && ((*insn_data[icode].operand[1].predicate)
5574 (equiv, Pmode))))
5576 /* We use the original pseudo for loc, so that
5577 emit_reload_insns() knows which pseudo this
5578 reload refers to and updates the pseudo rtx, not
5579 its equivalent memory location, as well as the
5580 corresponding entry in reg_last_reload_reg. */
5581 loc = &XEXP (x_orig, 0);
5582 x = XEXP (x, 0);
5583 reloadnum
5584 = push_reload (x, x, loc, loc,
5585 context_reg_class,
5586 GET_MODE (x), GET_MODE (x), 0, 0,
5587 opnum, RELOAD_OTHER);
5589 else
5591 reloadnum
5592 = push_reload (x, NULL_RTX, loc, (rtx*) 0,
5593 context_reg_class,
5594 GET_MODE (x), GET_MODE (x), 0, 0,
5595 opnum, type);
5596 rld[reloadnum].inc
5597 = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
5599 value = 1;
5602 update_auto_inc_notes (this_insn, REGNO (XEXP (x_orig, 0)),
5603 reloadnum);
5605 return value;
5608 else if (MEM_P (XEXP (x, 0)))
5610 /* This is probably the result of a substitution, by eliminate_regs,
5611 of an equivalent address for a pseudo that was not allocated to a
5612 hard register. Verify that the specified address is valid and
5613 reload it into a register. */
5614 /* Variable `tem' might or might not be used in FIND_REG_INC_NOTE. */
5615 rtx tem ATTRIBUTE_UNUSED = XEXP (x, 0);
5616 rtx link;
5617 int reloadnum;
5619 /* Since we know we are going to reload this item, don't decrement
5620 for the indirection level.
5622 Note that this is actually conservative: it would be slightly
5623 more efficient to use the value of SPILL_INDIRECT_LEVELS from
5624 reload1.c here. */
5625 /* We can't use ADDR_TYPE (type) here, because we need to
5626 write back the value after reading it, hence we actually
5627 need two registers. */
5628 find_reloads_address (GET_MODE (x), &XEXP (x, 0),
5629 XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0),
5630 opnum, type, ind_levels, insn);
5632 reloadnum = push_reload (x, NULL_RTX, loc, (rtx*) 0,
5633 context_reg_class,
5634 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5635 rld[reloadnum].inc
5636 = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
5638 link = FIND_REG_INC_NOTE (this_insn, tem);
5639 if (link != 0)
5640 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
5642 return 1;
5644 return 0;
5646 case TRUNCATE:
5647 case SIGN_EXTEND:
5648 case ZERO_EXTEND:
5649 /* Look for parts to reload in the inner expression and reload them
5650 too, in addition to this operation. Reloading all inner parts in
5651 addition to this one shouldn't be necessary, but at this point,
5652 we don't know if we can possibly omit any part that *can* be
5653 reloaded. Targets that are better off reloading just either part
5654 (or perhaps even a different part of an outer expression), should
5655 define LEGITIMIZE_RELOAD_ADDRESS. */
5656 find_reloads_address_1 (GET_MODE (XEXP (x, 0)), XEXP (x, 0),
5657 context, &XEXP (x, 0), opnum,
5658 type, ind_levels, insn);
5659 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5660 context_reg_class,
5661 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5662 return 1;
5664 case MEM:
5665 /* This is probably the result of a substitution, by eliminate_regs, of
5666 an equivalent address for a pseudo that was not allocated to a hard
5667 register. Verify that the specified address is valid and reload it
5668 into a register.
5670 Since we know we are going to reload this item, don't decrement for
5671 the indirection level.
5673 Note that this is actually conservative: it would be slightly more
5674 efficient to use the value of SPILL_INDIRECT_LEVELS from
5675 reload1.c here. */
5677 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
5678 opnum, ADDR_TYPE (type), ind_levels, insn);
5679 push_reload (*loc, NULL_RTX, loc, (rtx*) 0,
5680 context_reg_class,
5681 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5682 return 1;
5684 case REG:
5686 int regno = REGNO (x);
5688 if (reg_equiv_constant[regno] != 0)
5690 find_reloads_address_part (reg_equiv_constant[regno], loc,
5691 context_reg_class,
5692 GET_MODE (x), opnum, type, ind_levels);
5693 return 1;
5696 #if 0 /* This might screw code in reload1.c to delete prior output-reload
5697 that feeds this insn. */
5698 if (reg_equiv_mem[regno] != 0)
5700 push_reload (reg_equiv_mem[regno], NULL_RTX, loc, (rtx*) 0,
5701 context_reg_class,
5702 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5703 return 1;
5705 #endif
5707 if (reg_equiv_memory_loc[regno]
5708 && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset))
5710 rtx tem = make_memloc (x, regno);
5711 if (reg_equiv_address[regno] != 0
5712 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5714 x = tem;
5715 find_reloads_address (GET_MODE (x), &x, XEXP (x, 0),
5716 &XEXP (x, 0), opnum, ADDR_TYPE (type),
5717 ind_levels, insn);
5721 if (reg_renumber[regno] >= 0)
5722 regno = reg_renumber[regno];
5724 if (regno >= FIRST_PSEUDO_REGISTER
5725 || !REG_OK_FOR_CONTEXT (context, regno, mode))
5727 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5728 context_reg_class,
5729 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5730 return 1;
5733 /* If a register appearing in an address is the subject of a CLOBBER
5734 in this insn, reload it into some other register to be safe.
5735 The CLOBBER is supposed to make the register unavailable
5736 from before this insn to after it. */
5737 if (regno_clobbered_p (regno, this_insn, GET_MODE (x), 0))
5739 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5740 context_reg_class,
5741 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5742 return 1;
5745 return 0;
5747 case SUBREG:
5748 if (REG_P (SUBREG_REG (x)))
5750 /* If this is a SUBREG of a hard register and the resulting register
5751 is of the wrong class, reload the whole SUBREG. This avoids
5752 needless copies if SUBREG_REG is multi-word. */
5753 if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
5755 int regno ATTRIBUTE_UNUSED = subreg_regno (x);
5757 if (! REG_OK_FOR_CONTEXT (context, regno, mode))
5759 push_reload (x, NULL_RTX, loc, (rtx*) 0,
5760 context_reg_class,
5761 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5762 return 1;
5765 /* If this is a SUBREG of a pseudo-register, and the pseudo-register
5766 is larger than the class size, then reload the whole SUBREG. */
5767 else
5769 enum reg_class class = context_reg_class;
5770 if ((unsigned) CLASS_MAX_NREGS (class, GET_MODE (SUBREG_REG (x)))
5771 > reg_class_size[class])
5773 x = find_reloads_subreg_address (x, 0, opnum,
5774 ADDR_TYPE (type),
5775 ind_levels, insn);
5776 push_reload (x, NULL_RTX, loc, (rtx*) 0, class,
5777 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
5778 return 1;
5782 break;
5784 default:
5785 break;
5789 const char *fmt = GET_RTX_FORMAT (code);
5790 int i;
5792 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5794 if (fmt[i] == 'e')
5795 find_reloads_address_1 (mode, XEXP (x, i), context, &XEXP (x, i),
5796 opnum, type, ind_levels, insn);
5800 #undef REG_OK_FOR_CONTEXT
5801 return 0;
5804 /* X, which is found at *LOC, is a part of an address that needs to be
5805 reloaded into a register of class CLASS. If X is a constant, or if
5806 X is a PLUS that contains a constant, check that the constant is a
5807 legitimate operand and that we are supposed to be able to load
5808 it into the register.
5810 If not, force the constant into memory and reload the MEM instead.
5812 MODE is the mode to use, in case X is an integer constant.
5814 OPNUM and TYPE describe the purpose of any reloads made.
5816 IND_LEVELS says how many levels of indirect addressing this machine
5817 supports. */
5819 static void
5820 find_reloads_address_part (rtx x, rtx *loc, enum reg_class class,
5821 enum machine_mode mode, int opnum,
5822 enum reload_type type, int ind_levels)
5824 if (CONSTANT_P (x)
5825 && (! LEGITIMATE_CONSTANT_P (x)
5826 || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
5828 rtx tem;
5830 tem = x = force_const_mem (mode, x);
5831 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5832 opnum, type, ind_levels, 0);
5835 else if (GET_CODE (x) == PLUS
5836 && CONSTANT_P (XEXP (x, 1))
5837 && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
5838 || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
5840 rtx tem;
5842 tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
5843 x = gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), tem);
5844 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
5845 opnum, type, ind_levels, 0);
5848 push_reload (x, NULL_RTX, loc, (rtx*) 0, class,
5849 mode, VOIDmode, 0, 0, opnum, type);
5852 /* X, a subreg of a pseudo, is a part of an address that needs to be
5853 reloaded.
5855 If the pseudo is equivalent to a memory location that cannot be directly
5856 addressed, make the necessary address reloads.
5858 If address reloads have been necessary, or if the address is changed
5859 by register elimination, return the rtx of the memory location;
5860 otherwise, return X.
5862 If FORCE_REPLACE is nonzero, unconditionally replace the subreg with the
5863 memory location.
5865 OPNUM and TYPE identify the purpose of the reload.
5867 IND_LEVELS says how many levels of indirect addressing are
5868 supported at this point in the address.
5870 INSN, if nonzero, is the insn in which we do the reload. It is used
5871 to determine where to put USEs for pseudos that we have to replace with
5872 stack slots. */
5874 static rtx
5875 find_reloads_subreg_address (rtx x, int force_replace, int opnum,
5876 enum reload_type type, int ind_levels, rtx insn)
5878 int regno = REGNO (SUBREG_REG (x));
5880 if (reg_equiv_memory_loc[regno])
5882 /* If the address is not directly addressable, or if the address is not
5883 offsettable, then it must be replaced. */
5884 if (! force_replace
5885 && (reg_equiv_address[regno]
5886 || ! offsettable_memref_p (reg_equiv_mem[regno])))
5887 force_replace = 1;
5889 if (force_replace || num_not_at_initial_offset)
5891 rtx tem = make_memloc (SUBREG_REG (x), regno);
5893 /* If the address changes because of register elimination, then
5894 it must be replaced. */
5895 if (force_replace
5896 || ! rtx_equal_p (tem, reg_equiv_mem[regno]))
5898 unsigned outer_size = GET_MODE_SIZE (GET_MODE (x));
5899 unsigned inner_size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
5900 int offset;
5902 /* For big-endian paradoxical subregs, SUBREG_BYTE does not
5903 hold the correct (negative) byte offset. */
5904 if (BYTES_BIG_ENDIAN && outer_size > inner_size)
5905 offset = inner_size - outer_size;
5906 else
5907 offset = SUBREG_BYTE (x);
5909 XEXP (tem, 0) = plus_constant (XEXP (tem, 0), offset);
5910 PUT_MODE (tem, GET_MODE (x));
5912 /* If this was a paradoxical subreg that we replaced, the
5913 resulting memory must be sufficiently aligned to allow
5914 us to widen the mode of the memory. */
5915 if (outer_size > inner_size)
5917 rtx base;
5919 base = XEXP (tem, 0);
5920 if (GET_CODE (base) == PLUS)
5922 if (GET_CODE (XEXP (base, 1)) == CONST_INT
5923 && INTVAL (XEXP (base, 1)) % outer_size != 0)
5924 return x;
5925 base = XEXP (base, 0);
5927 if (!REG_P (base)
5928 || (REGNO_POINTER_ALIGN (REGNO (base))
5929 < outer_size * BITS_PER_UNIT))
5930 return x;
5933 find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0),
5934 &XEXP (tem, 0), opnum, type,
5935 ind_levels, insn);
5937 /* If this is not a toplevel operand, find_reloads doesn't see
5938 this substitution. We have to emit a USE of the pseudo so
5939 that delete_output_reload can see it. */
5940 if (replace_reloads && recog_data.operand[opnum] != x)
5941 /* We mark the USE with QImode so that we recognize it
5942 as one that can be safely deleted at the end of
5943 reload. */
5944 PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode,
5945 SUBREG_REG (x)),
5946 insn), QImode);
5947 x = tem;
5951 return x;
5954 /* Substitute into the current INSN the registers into which we have reloaded
5955 the things that need reloading. The array `replacements'
5956 contains the locations of all pointers that must be changed
5957 and says what to replace them with.
5959 Return the rtx that X translates into; usually X, but modified. */
5961 void
5962 subst_reloads (rtx insn)
5964 int i;
5966 for (i = 0; i < n_replacements; i++)
5968 struct replacement *r = &replacements[i];
5969 rtx reloadreg = rld[r->what].reg_rtx;
5970 if (reloadreg)
5972 #ifdef ENABLE_CHECKING
5973 /* Internal consistency test. Check that we don't modify
5974 anything in the equivalence arrays. Whenever something from
5975 those arrays needs to be reloaded, it must be unshared before
5976 being substituted into; the equivalence must not be modified.
5977 Otherwise, if the equivalence is used after that, it will
5978 have been modified, and the thing substituted (probably a
5979 register) is likely overwritten and not a usable equivalence. */
5980 int check_regno;
5982 for (check_regno = 0; check_regno < max_regno; check_regno++)
5984 #define CHECK_MODF(ARRAY) \
5985 gcc_assert (!ARRAY[check_regno] \
5986 || !loc_mentioned_in_p (r->where, \
5987 ARRAY[check_regno]))
5989 CHECK_MODF (reg_equiv_constant);
5990 CHECK_MODF (reg_equiv_memory_loc);
5991 CHECK_MODF (reg_equiv_address);
5992 CHECK_MODF (reg_equiv_mem);
5993 #undef CHECK_MODF
5995 #endif /* ENABLE_CHECKING */
5997 /* If we're replacing a LABEL_REF with a register, add a
5998 REG_LABEL note to indicate to flow which label this
5999 register refers to. */
6000 if (GET_CODE (*r->where) == LABEL_REF
6001 && JUMP_P (insn))
6003 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
6004 XEXP (*r->where, 0),
6005 REG_NOTES (insn));
6006 JUMP_LABEL (insn) = XEXP (*r->where, 0);
6009 /* Encapsulate RELOADREG so its machine mode matches what
6010 used to be there. Note that gen_lowpart_common will
6011 do the wrong thing if RELOADREG is multi-word. RELOADREG
6012 will always be a REG here. */
6013 if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
6014 reloadreg = reload_adjust_reg_for_mode (reloadreg, r->mode);
6016 /* If we are putting this into a SUBREG and RELOADREG is a
6017 SUBREG, we would be making nested SUBREGs, so we have to fix
6018 this up. Note that r->where == &SUBREG_REG (*r->subreg_loc). */
6020 if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG)
6022 if (GET_MODE (*r->subreg_loc)
6023 == GET_MODE (SUBREG_REG (reloadreg)))
6024 *r->subreg_loc = SUBREG_REG (reloadreg);
6025 else
6027 int final_offset =
6028 SUBREG_BYTE (*r->subreg_loc) + SUBREG_BYTE (reloadreg);
6030 /* When working with SUBREGs the rule is that the byte
6031 offset must be a multiple of the SUBREG's mode. */
6032 final_offset = (final_offset /
6033 GET_MODE_SIZE (GET_MODE (*r->subreg_loc)));
6034 final_offset = (final_offset *
6035 GET_MODE_SIZE (GET_MODE (*r->subreg_loc)));
6037 *r->where = SUBREG_REG (reloadreg);
6038 SUBREG_BYTE (*r->subreg_loc) = final_offset;
6041 else
6042 *r->where = reloadreg;
6044 /* If reload got no reg and isn't optional, something's wrong. */
6045 else
6046 gcc_assert (rld[r->what].optional);
6050 /* Make a copy of any replacements being done into X and move those
6051 copies to locations in Y, a copy of X. */
6053 void
6054 copy_replacements (rtx x, rtx y)
6056 /* We can't support X being a SUBREG because we might then need to know its
6057 location if something inside it was replaced. */
6058 gcc_assert (GET_CODE (x) != SUBREG);
6060 copy_replacements_1 (&x, &y, n_replacements);
6063 static void
6064 copy_replacements_1 (rtx *px, rtx *py, int orig_replacements)
6066 int i, j;
6067 rtx x, y;
6068 struct replacement *r;
6069 enum rtx_code code;
6070 const char *fmt;
6072 for (j = 0; j < orig_replacements; j++)
6074 if (replacements[j].subreg_loc == px)
6076 r = &replacements[n_replacements++];
6077 r->where = replacements[j].where;
6078 r->subreg_loc = py;
6079 r->what = replacements[j].what;
6080 r->mode = replacements[j].mode;
6082 else if (replacements[j].where == px)
6084 r = &replacements[n_replacements++];
6085 r->where = py;
6086 r->subreg_loc = 0;
6087 r->what = replacements[j].what;
6088 r->mode = replacements[j].mode;
6092 x = *px;
6093 y = *py;
6094 code = GET_CODE (x);
6095 fmt = GET_RTX_FORMAT (code);
6097 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6099 if (fmt[i] == 'e')
6100 copy_replacements_1 (&XEXP (x, i), &XEXP (y, i), orig_replacements);
6101 else if (fmt[i] == 'E')
6102 for (j = XVECLEN (x, i); --j >= 0; )
6103 copy_replacements_1 (&XVECEXP (x, i, j), &XVECEXP (y, i, j),
6104 orig_replacements);
6108 /* Change any replacements being done to *X to be done to *Y. */
6110 void
6111 move_replacements (rtx *x, rtx *y)
6113 int i;
6115 for (i = 0; i < n_replacements; i++)
6116 if (replacements[i].subreg_loc == x)
6117 replacements[i].subreg_loc = y;
6118 else if (replacements[i].where == x)
6120 replacements[i].where = y;
6121 replacements[i].subreg_loc = 0;
6125 /* If LOC was scheduled to be replaced by something, return the replacement.
6126 Otherwise, return *LOC. */
6129 find_replacement (rtx *loc)
6131 struct replacement *r;
6133 for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
6135 rtx reloadreg = rld[r->what].reg_rtx;
6137 if (reloadreg && r->where == loc)
6139 if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
6140 reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg));
6142 return reloadreg;
6144 else if (reloadreg && r->subreg_loc == loc)
6146 /* RELOADREG must be either a REG or a SUBREG.
6148 ??? Is it actually still ever a SUBREG? If so, why? */
6150 if (REG_P (reloadreg))
6151 return gen_rtx_REG (GET_MODE (*loc),
6152 (REGNO (reloadreg) +
6153 subreg_regno_offset (REGNO (SUBREG_REG (*loc)),
6154 GET_MODE (SUBREG_REG (*loc)),
6155 SUBREG_BYTE (*loc),
6156 GET_MODE (*loc))));
6157 else if (GET_MODE (reloadreg) == GET_MODE (*loc))
6158 return reloadreg;
6159 else
6161 int final_offset = SUBREG_BYTE (reloadreg) + SUBREG_BYTE (*loc);
6163 /* When working with SUBREGs the rule is that the byte
6164 offset must be a multiple of the SUBREG's mode. */
6165 final_offset = (final_offset / GET_MODE_SIZE (GET_MODE (*loc)));
6166 final_offset = (final_offset * GET_MODE_SIZE (GET_MODE (*loc)));
6167 return gen_rtx_SUBREG (GET_MODE (*loc), SUBREG_REG (reloadreg),
6168 final_offset);
6173 /* If *LOC is a PLUS, MINUS, or MULT, see if a replacement is scheduled for
6174 what's inside and make a new rtl if so. */
6175 if (GET_CODE (*loc) == PLUS || GET_CODE (*loc) == MINUS
6176 || GET_CODE (*loc) == MULT)
6178 rtx x = find_replacement (&XEXP (*loc, 0));
6179 rtx y = find_replacement (&XEXP (*loc, 1));
6181 if (x != XEXP (*loc, 0) || y != XEXP (*loc, 1))
6182 return gen_rtx_fmt_ee (GET_CODE (*loc), GET_MODE (*loc), x, y);
6185 return *loc;
6188 /* Return nonzero if register in range [REGNO, ENDREGNO)
6189 appears either explicitly or implicitly in X
6190 other than being stored into (except for earlyclobber operands).
6192 References contained within the substructure at LOC do not count.
6193 LOC may be zero, meaning don't ignore anything.
6195 This is similar to refers_to_regno_p in rtlanal.c except that we
6196 look at equivalences for pseudos that didn't get hard registers. */
6198 static int
6199 refers_to_regno_for_reload_p (unsigned int regno, unsigned int endregno,
6200 rtx x, rtx *loc)
6202 int i;
6203 unsigned int r;
6204 RTX_CODE code;
6205 const char *fmt;
6207 if (x == 0)
6208 return 0;
6210 repeat:
6211 code = GET_CODE (x);
6213 switch (code)
6215 case REG:
6216 r = REGNO (x);
6218 /* If this is a pseudo, a hard register must not have been allocated.
6219 X must therefore either be a constant or be in memory. */
6220 if (r >= FIRST_PSEUDO_REGISTER)
6222 if (reg_equiv_memory_loc[r])
6223 return refers_to_regno_for_reload_p (regno, endregno,
6224 reg_equiv_memory_loc[r],
6225 (rtx*) 0);
6227 gcc_assert (reg_equiv_constant[r] || reg_equiv_invariant[r]);
6228 return 0;
6231 return (endregno > r
6232 && regno < r + (r < FIRST_PSEUDO_REGISTER
6233 ? hard_regno_nregs[r][GET_MODE (x)]
6234 : 1));
6236 case SUBREG:
6237 /* If this is a SUBREG of a hard reg, we can see exactly which
6238 registers are being modified. Otherwise, handle normally. */
6239 if (REG_P (SUBREG_REG (x))
6240 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
6242 unsigned int inner_regno = subreg_regno (x);
6243 unsigned int inner_endregno
6244 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
6245 ? hard_regno_nregs[inner_regno][GET_MODE (x)] : 1);
6247 return endregno > inner_regno && regno < inner_endregno;
6249 break;
6251 case CLOBBER:
6252 case SET:
6253 if (&SET_DEST (x) != loc
6254 /* Note setting a SUBREG counts as referring to the REG it is in for
6255 a pseudo but not for hard registers since we can
6256 treat each word individually. */
6257 && ((GET_CODE (SET_DEST (x)) == SUBREG
6258 && loc != &SUBREG_REG (SET_DEST (x))
6259 && REG_P (SUBREG_REG (SET_DEST (x)))
6260 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
6261 && refers_to_regno_for_reload_p (regno, endregno,
6262 SUBREG_REG (SET_DEST (x)),
6263 loc))
6264 /* If the output is an earlyclobber operand, this is
6265 a conflict. */
6266 || ((!REG_P (SET_DEST (x))
6267 || earlyclobber_operand_p (SET_DEST (x)))
6268 && refers_to_regno_for_reload_p (regno, endregno,
6269 SET_DEST (x), loc))))
6270 return 1;
6272 if (code == CLOBBER || loc == &SET_SRC (x))
6273 return 0;
6274 x = SET_SRC (x);
6275 goto repeat;
6277 default:
6278 break;
6281 /* X does not match, so try its subexpressions. */
6283 fmt = GET_RTX_FORMAT (code);
6284 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6286 if (fmt[i] == 'e' && loc != &XEXP (x, i))
6288 if (i == 0)
6290 x = XEXP (x, 0);
6291 goto repeat;
6293 else
6294 if (refers_to_regno_for_reload_p (regno, endregno,
6295 XEXP (x, i), loc))
6296 return 1;
6298 else if (fmt[i] == 'E')
6300 int j;
6301 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6302 if (loc != &XVECEXP (x, i, j)
6303 && refers_to_regno_for_reload_p (regno, endregno,
6304 XVECEXP (x, i, j), loc))
6305 return 1;
6308 return 0;
6311 /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
6312 we check if any register number in X conflicts with the relevant register
6313 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
6314 contains a MEM (we don't bother checking for memory addresses that can't
6315 conflict because we expect this to be a rare case.
6317 This function is similar to reg_overlap_mentioned_p in rtlanal.c except
6318 that we look at equivalences for pseudos that didn't get hard registers. */
6321 reg_overlap_mentioned_for_reload_p (rtx x, rtx in)
6323 int regno, endregno;
6325 /* Overly conservative. */
6326 if (GET_CODE (x) == STRICT_LOW_PART
6327 || GET_RTX_CLASS (GET_CODE (x)) == RTX_AUTOINC)
6328 x = XEXP (x, 0);
6330 /* If either argument is a constant, then modifying X can not affect IN. */
6331 if (CONSTANT_P (x) || CONSTANT_P (in))
6332 return 0;
6333 else if (GET_CODE (x) == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
6334 return refers_to_mem_for_reload_p (in);
6335 else if (GET_CODE (x) == SUBREG)
6337 regno = REGNO (SUBREG_REG (x));
6338 if (regno < FIRST_PSEUDO_REGISTER)
6339 regno += subreg_regno_offset (REGNO (SUBREG_REG (x)),
6340 GET_MODE (SUBREG_REG (x)),
6341 SUBREG_BYTE (x),
6342 GET_MODE (x));
6344 else if (REG_P (x))
6346 regno = REGNO (x);
6348 /* If this is a pseudo, it must not have been assigned a hard register.
6349 Therefore, it must either be in memory or be a constant. */
6351 if (regno >= FIRST_PSEUDO_REGISTER)
6353 if (reg_equiv_memory_loc[regno])
6354 return refers_to_mem_for_reload_p (in);
6355 gcc_assert (reg_equiv_constant[regno]);
6356 return 0;
6359 else if (MEM_P (x))
6360 return refers_to_mem_for_reload_p (in);
6361 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
6362 || GET_CODE (x) == CC0)
6363 return reg_mentioned_p (x, in);
6364 else
6366 gcc_assert (GET_CODE (x) == PLUS);
6368 /* We actually want to know if X is mentioned somewhere inside IN.
6369 We must not say that (plus (sp) (const_int 124)) is in
6370 (plus (sp) (const_int 64)), since that can lead to incorrect reload
6371 allocation when spuriously changing a RELOAD_FOR_OUTPUT_ADDRESS
6372 into a RELOAD_OTHER on behalf of another RELOAD_OTHER. */
6373 while (MEM_P (in))
6374 in = XEXP (in, 0);
6375 if (REG_P (in))
6376 return 0;
6377 else if (GET_CODE (in) == PLUS)
6378 return (reg_overlap_mentioned_for_reload_p (x, XEXP (in, 0))
6379 || reg_overlap_mentioned_for_reload_p (x, XEXP (in, 1)));
6380 else return (reg_overlap_mentioned_for_reload_p (XEXP (x, 0), in)
6381 || reg_overlap_mentioned_for_reload_p (XEXP (x, 1), in));
6384 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
6385 ? hard_regno_nregs[regno][GET_MODE (x)] : 1);
6387 return refers_to_regno_for_reload_p (regno, endregno, in, (rtx*) 0);
6390 /* Return nonzero if anything in X contains a MEM. Look also for pseudo
6391 registers. */
6393 static int
6394 refers_to_mem_for_reload_p (rtx x)
6396 const char *fmt;
6397 int i;
6399 if (MEM_P (x))
6400 return 1;
6402 if (REG_P (x))
6403 return (REGNO (x) >= FIRST_PSEUDO_REGISTER
6404 && reg_equiv_memory_loc[REGNO (x)]);
6406 fmt = GET_RTX_FORMAT (GET_CODE (x));
6407 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
6408 if (fmt[i] == 'e'
6409 && (MEM_P (XEXP (x, i))
6410 || refers_to_mem_for_reload_p (XEXP (x, i))))
6411 return 1;
6413 return 0;
6416 /* Check the insns before INSN to see if there is a suitable register
6417 containing the same value as GOAL.
6418 If OTHER is -1, look for a register in class CLASS.
6419 Otherwise, just see if register number OTHER shares GOAL's value.
6421 Return an rtx for the register found, or zero if none is found.
6423 If RELOAD_REG_P is (short *)1,
6424 we reject any hard reg that appears in reload_reg_rtx
6425 because such a hard reg is also needed coming into this insn.
6427 If RELOAD_REG_P is any other nonzero value,
6428 it is a vector indexed by hard reg number
6429 and we reject any hard reg whose element in the vector is nonnegative
6430 as well as any that appears in reload_reg_rtx.
6432 If GOAL is zero, then GOALREG is a register number; we look
6433 for an equivalent for that register.
6435 MODE is the machine mode of the value we want an equivalence for.
6436 If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
6438 This function is used by jump.c as well as in the reload pass.
6440 If GOAL is the sum of the stack pointer and a constant, we treat it
6441 as if it were a constant except that sp is required to be unchanging. */
6444 find_equiv_reg (rtx goal, rtx insn, enum reg_class class, int other,
6445 short *reload_reg_p, int goalreg, enum machine_mode mode)
6447 rtx p = insn;
6448 rtx goaltry, valtry, value, where;
6449 rtx pat;
6450 int regno = -1;
6451 int valueno;
6452 int goal_mem = 0;
6453 int goal_const = 0;
6454 int goal_mem_addr_varies = 0;
6455 int need_stable_sp = 0;
6456 int nregs;
6457 int valuenregs;
6458 int num = 0;
6460 if (goal == 0)
6461 regno = goalreg;
6462 else if (REG_P (goal))
6463 regno = REGNO (goal);
6464 else if (MEM_P (goal))
6466 enum rtx_code code = GET_CODE (XEXP (goal, 0));
6467 if (MEM_VOLATILE_P (goal))
6468 return 0;
6469 if (flag_float_store && SCALAR_FLOAT_MODE_P (GET_MODE (goal)))
6470 return 0;
6471 /* An address with side effects must be reexecuted. */
6472 switch (code)
6474 case POST_INC:
6475 case PRE_INC:
6476 case POST_DEC:
6477 case PRE_DEC:
6478 case POST_MODIFY:
6479 case PRE_MODIFY:
6480 return 0;
6481 default:
6482 break;
6484 goal_mem = 1;
6486 else if (CONSTANT_P (goal))
6487 goal_const = 1;
6488 else if (GET_CODE (goal) == PLUS
6489 && XEXP (goal, 0) == stack_pointer_rtx
6490 && CONSTANT_P (XEXP (goal, 1)))
6491 goal_const = need_stable_sp = 1;
6492 else if (GET_CODE (goal) == PLUS
6493 && XEXP (goal, 0) == frame_pointer_rtx
6494 && CONSTANT_P (XEXP (goal, 1)))
6495 goal_const = 1;
6496 else
6497 return 0;
6499 num = 0;
6500 /* Scan insns back from INSN, looking for one that copies
6501 a value into or out of GOAL.
6502 Stop and give up if we reach a label. */
6504 while (1)
6506 p = PREV_INSN (p);
6507 num++;
6508 if (p == 0 || LABEL_P (p)
6509 || num > PARAM_VALUE (PARAM_MAX_RELOAD_SEARCH_INSNS))
6510 return 0;
6512 if (NONJUMP_INSN_P (p)
6513 /* If we don't want spill regs ... */
6514 && (! (reload_reg_p != 0
6515 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6516 /* ... then ignore insns introduced by reload; they aren't
6517 useful and can cause results in reload_as_needed to be
6518 different from what they were when calculating the need for
6519 spills. If we notice an input-reload insn here, we will
6520 reject it below, but it might hide a usable equivalent.
6521 That makes bad code. It may even fail: perhaps no reg was
6522 spilled for this insn because it was assumed we would find
6523 that equivalent. */
6524 || INSN_UID (p) < reload_first_uid))
6526 rtx tem;
6527 pat = single_set (p);
6529 /* First check for something that sets some reg equal to GOAL. */
6530 if (pat != 0
6531 && ((regno >= 0
6532 && true_regnum (SET_SRC (pat)) == regno
6533 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6535 (regno >= 0
6536 && true_regnum (SET_DEST (pat)) == regno
6537 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
6539 (goal_const && rtx_equal_p (SET_SRC (pat), goal)
6540 /* When looking for stack pointer + const,
6541 make sure we don't use a stack adjust. */
6542 && !reg_overlap_mentioned_for_reload_p (SET_DEST (pat), goal)
6543 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
6544 || (goal_mem
6545 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
6546 && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
6547 || (goal_mem
6548 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
6549 && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
6550 /* If we are looking for a constant,
6551 and something equivalent to that constant was copied
6552 into a reg, we can use that reg. */
6553 || (goal_const && REG_NOTES (p) != 0
6554 && (tem = find_reg_note (p, REG_EQUIV, NULL_RTX))
6555 && ((rtx_equal_p (XEXP (tem, 0), goal)
6556 && (valueno
6557 = true_regnum (valtry = SET_DEST (pat))) >= 0)
6558 || (REG_P (SET_DEST (pat))
6559 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6560 && SCALAR_FLOAT_MODE_P (GET_MODE (XEXP (tem, 0)))
6561 && GET_CODE (goal) == CONST_INT
6562 && 0 != (goaltry
6563 = operand_subword (XEXP (tem, 0), 0, 0,
6564 VOIDmode))
6565 && rtx_equal_p (goal, goaltry)
6566 && (valtry
6567 = operand_subword (SET_DEST (pat), 0, 0,
6568 VOIDmode))
6569 && (valueno = true_regnum (valtry)) >= 0)))
6570 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
6571 NULL_RTX))
6572 && REG_P (SET_DEST (pat))
6573 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
6574 && SCALAR_FLOAT_MODE_P (GET_MODE (XEXP (tem, 0)))
6575 && GET_CODE (goal) == CONST_INT
6576 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0,
6577 VOIDmode))
6578 && rtx_equal_p (goal, goaltry)
6579 && (valtry
6580 = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
6581 && (valueno = true_regnum (valtry)) >= 0)))
6583 if (other >= 0)
6585 if (valueno != other)
6586 continue;
6588 else if ((unsigned) valueno >= FIRST_PSEUDO_REGISTER)
6589 continue;
6590 else
6592 int i;
6594 for (i = hard_regno_nregs[valueno][mode] - 1; i >= 0; i--)
6595 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
6596 valueno + i))
6597 break;
6598 if (i >= 0)
6599 continue;
6601 value = valtry;
6602 where = p;
6603 break;
6608 /* We found a previous insn copying GOAL into a suitable other reg VALUE
6609 (or copying VALUE into GOAL, if GOAL is also a register).
6610 Now verify that VALUE is really valid. */
6612 /* VALUENO is the register number of VALUE; a hard register. */
6614 /* Don't try to re-use something that is killed in this insn. We want
6615 to be able to trust REG_UNUSED notes. */
6616 if (REG_NOTES (where) != 0 && find_reg_note (where, REG_UNUSED, value))
6617 return 0;
6619 /* If we propose to get the value from the stack pointer or if GOAL is
6620 a MEM based on the stack pointer, we need a stable SP. */
6621 if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM
6622 || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
6623 goal)))
6624 need_stable_sp = 1;
6626 /* Reject VALUE if the copy-insn moved the wrong sort of datum. */
6627 if (GET_MODE (value) != mode)
6628 return 0;
6630 /* Reject VALUE if it was loaded from GOAL
6631 and is also a register that appears in the address of GOAL. */
6633 if (goal_mem && value == SET_DEST (single_set (where))
6634 && refers_to_regno_for_reload_p (valueno,
6635 (valueno
6636 + hard_regno_nregs[valueno][mode]),
6637 goal, (rtx*) 0))
6638 return 0;
6640 /* Reject registers that overlap GOAL. */
6642 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
6643 nregs = hard_regno_nregs[regno][mode];
6644 else
6645 nregs = 1;
6646 valuenregs = hard_regno_nregs[valueno][mode];
6648 if (!goal_mem && !goal_const
6649 && regno + nregs > valueno && regno < valueno + valuenregs)
6650 return 0;
6652 /* Reject VALUE if it is one of the regs reserved for reloads.
6653 Reload1 knows how to reuse them anyway, and it would get
6654 confused if we allocated one without its knowledge.
6655 (Now that insns introduced by reload are ignored above,
6656 this case shouldn't happen, but I'm not positive.) */
6658 if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1)
6660 int i;
6661 for (i = 0; i < valuenregs; ++i)
6662 if (reload_reg_p[valueno + i] >= 0)
6663 return 0;
6666 /* Reject VALUE if it is a register being used for an input reload
6667 even if it is not one of those reserved. */
6669 if (reload_reg_p != 0)
6671 int i;
6672 for (i = 0; i < n_reloads; i++)
6673 if (rld[i].reg_rtx != 0 && rld[i].in)
6675 int regno1 = REGNO (rld[i].reg_rtx);
6676 int nregs1 = hard_regno_nregs[regno1]
6677 [GET_MODE (rld[i].reg_rtx)];
6678 if (regno1 < valueno + valuenregs
6679 && regno1 + nregs1 > valueno)
6680 return 0;
6684 if (goal_mem)
6685 /* We must treat frame pointer as varying here,
6686 since it can vary--in a nonlocal goto as generated by expand_goto. */
6687 goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0));
6689 /* Now verify that the values of GOAL and VALUE remain unaltered
6690 until INSN is reached. */
6692 p = insn;
6693 while (1)
6695 p = PREV_INSN (p);
6696 if (p == where)
6697 return value;
6699 /* Don't trust the conversion past a function call
6700 if either of the two is in a call-clobbered register, or memory. */
6701 if (CALL_P (p))
6703 int i;
6705 if (goal_mem || need_stable_sp)
6706 return 0;
6708 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER)
6709 for (i = 0; i < nregs; ++i)
6710 if (call_used_regs[regno + i]
6711 || HARD_REGNO_CALL_PART_CLOBBERED (regno + i, mode))
6712 return 0;
6714 if (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER)
6715 for (i = 0; i < valuenregs; ++i)
6716 if (call_used_regs[valueno + i]
6717 || HARD_REGNO_CALL_PART_CLOBBERED (valueno + i, mode))
6718 return 0;
6721 if (INSN_P (p))
6723 pat = PATTERN (p);
6725 /* Watch out for unspec_volatile, and volatile asms. */
6726 if (volatile_insn_p (pat))
6727 return 0;
6729 /* If this insn P stores in either GOAL or VALUE, return 0.
6730 If GOAL is a memory ref and this insn writes memory, return 0.
6731 If GOAL is a memory ref and its address is not constant,
6732 and this insn P changes a register used in GOAL, return 0. */
6734 if (GET_CODE (pat) == COND_EXEC)
6735 pat = COND_EXEC_CODE (pat);
6736 if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
6738 rtx dest = SET_DEST (pat);
6739 while (GET_CODE (dest) == SUBREG
6740 || GET_CODE (dest) == ZERO_EXTRACT
6741 || GET_CODE (dest) == STRICT_LOW_PART)
6742 dest = XEXP (dest, 0);
6743 if (REG_P (dest))
6745 int xregno = REGNO (dest);
6746 int xnregs;
6747 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6748 xnregs = hard_regno_nregs[xregno][GET_MODE (dest)];
6749 else
6750 xnregs = 1;
6751 if (xregno < regno + nregs && xregno + xnregs > regno)
6752 return 0;
6753 if (xregno < valueno + valuenregs
6754 && xregno + xnregs > valueno)
6755 return 0;
6756 if (goal_mem_addr_varies
6757 && reg_overlap_mentioned_for_reload_p (dest, goal))
6758 return 0;
6759 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6760 return 0;
6762 else if (goal_mem && MEM_P (dest)
6763 && ! push_operand (dest, GET_MODE (dest)))
6764 return 0;
6765 else if (MEM_P (dest) && regno >= FIRST_PSEUDO_REGISTER
6766 && reg_equiv_memory_loc[regno] != 0)
6767 return 0;
6768 else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
6769 return 0;
6771 else if (GET_CODE (pat) == PARALLEL)
6773 int i;
6774 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
6776 rtx v1 = XVECEXP (pat, 0, i);
6777 if (GET_CODE (v1) == COND_EXEC)
6778 v1 = COND_EXEC_CODE (v1);
6779 if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
6781 rtx dest = SET_DEST (v1);
6782 while (GET_CODE (dest) == SUBREG
6783 || GET_CODE (dest) == ZERO_EXTRACT
6784 || GET_CODE (dest) == STRICT_LOW_PART)
6785 dest = XEXP (dest, 0);
6786 if (REG_P (dest))
6788 int xregno = REGNO (dest);
6789 int xnregs;
6790 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
6791 xnregs = hard_regno_nregs[xregno][GET_MODE (dest)];
6792 else
6793 xnregs = 1;
6794 if (xregno < regno + nregs
6795 && xregno + xnregs > regno)
6796 return 0;
6797 if (xregno < valueno + valuenregs
6798 && xregno + xnregs > valueno)
6799 return 0;
6800 if (goal_mem_addr_varies
6801 && reg_overlap_mentioned_for_reload_p (dest,
6802 goal))
6803 return 0;
6804 if (xregno == STACK_POINTER_REGNUM && need_stable_sp)
6805 return 0;
6807 else if (goal_mem && MEM_P (dest)
6808 && ! push_operand (dest, GET_MODE (dest)))
6809 return 0;
6810 else if (MEM_P (dest) && regno >= FIRST_PSEUDO_REGISTER
6811 && reg_equiv_memory_loc[regno] != 0)
6812 return 0;
6813 else if (need_stable_sp
6814 && push_operand (dest, GET_MODE (dest)))
6815 return 0;
6820 if (CALL_P (p) && CALL_INSN_FUNCTION_USAGE (p))
6822 rtx link;
6824 for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0;
6825 link = XEXP (link, 1))
6827 pat = XEXP (link, 0);
6828 if (GET_CODE (pat) == CLOBBER)
6830 rtx dest = SET_DEST (pat);
6832 if (REG_P (dest))
6834 int xregno = REGNO (dest);
6835 int xnregs
6836 = hard_regno_nregs[xregno][GET_MODE (dest)];
6838 if (xregno < regno + nregs
6839 && xregno + xnregs > regno)
6840 return 0;
6841 else if (xregno < valueno + valuenregs
6842 && xregno + xnregs > valueno)
6843 return 0;
6844 else if (goal_mem_addr_varies
6845 && reg_overlap_mentioned_for_reload_p (dest,
6846 goal))
6847 return 0;
6850 else if (goal_mem && MEM_P (dest)
6851 && ! push_operand (dest, GET_MODE (dest)))
6852 return 0;
6853 else if (need_stable_sp
6854 && push_operand (dest, GET_MODE (dest)))
6855 return 0;
6860 #ifdef AUTO_INC_DEC
6861 /* If this insn auto-increments or auto-decrements
6862 either regno or valueno, return 0 now.
6863 If GOAL is a memory ref and its address is not constant,
6864 and this insn P increments a register used in GOAL, return 0. */
6866 rtx link;
6868 for (link = REG_NOTES (p); link; link = XEXP (link, 1))
6869 if (REG_NOTE_KIND (link) == REG_INC
6870 && REG_P (XEXP (link, 0)))
6872 int incno = REGNO (XEXP (link, 0));
6873 if (incno < regno + nregs && incno >= regno)
6874 return 0;
6875 if (incno < valueno + valuenregs && incno >= valueno)
6876 return 0;
6877 if (goal_mem_addr_varies
6878 && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
6879 goal))
6880 return 0;
6883 #endif
6888 /* Find a place where INCED appears in an increment or decrement operator
6889 within X, and return the amount INCED is incremented or decremented by.
6890 The value is always positive. */
6892 static int
6893 find_inc_amount (rtx x, rtx inced)
6895 enum rtx_code code = GET_CODE (x);
6896 const char *fmt;
6897 int i;
6899 if (code == MEM)
6901 rtx addr = XEXP (x, 0);
6902 if ((GET_CODE (addr) == PRE_DEC
6903 || GET_CODE (addr) == POST_DEC
6904 || GET_CODE (addr) == PRE_INC
6905 || GET_CODE (addr) == POST_INC)
6906 && XEXP (addr, 0) == inced)
6907 return GET_MODE_SIZE (GET_MODE (x));
6908 else if ((GET_CODE (addr) == PRE_MODIFY
6909 || GET_CODE (addr) == POST_MODIFY)
6910 && GET_CODE (XEXP (addr, 1)) == PLUS
6911 && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0)
6912 && XEXP (addr, 0) == inced
6913 && GET_CODE (XEXP (XEXP (addr, 1), 1)) == CONST_INT)
6915 i = INTVAL (XEXP (XEXP (addr, 1), 1));
6916 return i < 0 ? -i : i;
6920 fmt = GET_RTX_FORMAT (code);
6921 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6923 if (fmt[i] == 'e')
6925 int tem = find_inc_amount (XEXP (x, i), inced);
6926 if (tem != 0)
6927 return tem;
6929 if (fmt[i] == 'E')
6931 int j;
6932 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6934 int tem = find_inc_amount (XVECEXP (x, i, j), inced);
6935 if (tem != 0)
6936 return tem;
6941 return 0;
6944 /* Return 1 if register REGNO is the subject of a clobber in insn INSN.
6945 If SETS is nonzero, also consider SETs. REGNO must refer to a hard
6946 register. */
6949 regno_clobbered_p (unsigned int regno, rtx insn, enum machine_mode mode,
6950 int sets)
6952 unsigned int nregs, endregno;
6954 /* regno must be a hard register. */
6955 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
6957 nregs = hard_regno_nregs[regno][mode];
6958 endregno = regno + nregs;
6960 if ((GET_CODE (PATTERN (insn)) == CLOBBER
6961 || (sets && GET_CODE (PATTERN (insn)) == SET))
6962 && REG_P (XEXP (PATTERN (insn), 0)))
6964 unsigned int test = REGNO (XEXP (PATTERN (insn), 0));
6966 return test >= regno && test < endregno;
6969 if (GET_CODE (PATTERN (insn)) == PARALLEL)
6971 int i = XVECLEN (PATTERN (insn), 0) - 1;
6973 for (; i >= 0; i--)
6975 rtx elt = XVECEXP (PATTERN (insn), 0, i);
6976 if ((GET_CODE (elt) == CLOBBER
6977 || (sets && GET_CODE (PATTERN (insn)) == SET))
6978 && REG_P (XEXP (elt, 0)))
6980 unsigned int test = REGNO (XEXP (elt, 0));
6982 if (test >= regno && test < endregno)
6983 return 1;
6988 return 0;
6991 /* Find the low part, with mode MODE, of a hard regno RELOADREG. */
6993 reload_adjust_reg_for_mode (rtx reloadreg, enum machine_mode mode)
6995 int regno;
6997 if (GET_MODE (reloadreg) == mode)
6998 return reloadreg;
7000 regno = REGNO (reloadreg);
7002 if (WORDS_BIG_ENDIAN)
7003 regno += (int) hard_regno_nregs[regno][GET_MODE (reloadreg)]
7004 - (int) hard_regno_nregs[regno][mode];
7006 return gen_rtx_REG (mode, regno);
7009 static const char *const reload_when_needed_name[] =
7011 "RELOAD_FOR_INPUT",
7012 "RELOAD_FOR_OUTPUT",
7013 "RELOAD_FOR_INSN",
7014 "RELOAD_FOR_INPUT_ADDRESS",
7015 "RELOAD_FOR_INPADDR_ADDRESS",
7016 "RELOAD_FOR_OUTPUT_ADDRESS",
7017 "RELOAD_FOR_OUTADDR_ADDRESS",
7018 "RELOAD_FOR_OPERAND_ADDRESS",
7019 "RELOAD_FOR_OPADDR_ADDR",
7020 "RELOAD_OTHER",
7021 "RELOAD_FOR_OTHER_ADDRESS"
7024 /* These functions are used to print the variables set by 'find_reloads' */
7026 void
7027 debug_reload_to_stream (FILE *f)
7029 int r;
7030 const char *prefix;
7032 if (! f)
7033 f = stderr;
7034 for (r = 0; r < n_reloads; r++)
7036 fprintf (f, "Reload %d: ", r);
7038 if (rld[r].in != 0)
7040 fprintf (f, "reload_in (%s) = ",
7041 GET_MODE_NAME (rld[r].inmode));
7042 print_inline_rtx (f, rld[r].in, 24);
7043 fprintf (f, "\n\t");
7046 if (rld[r].out != 0)
7048 fprintf (f, "reload_out (%s) = ",
7049 GET_MODE_NAME (rld[r].outmode));
7050 print_inline_rtx (f, rld[r].out, 24);
7051 fprintf (f, "\n\t");
7054 fprintf (f, "%s, ", reg_class_names[(int) rld[r].class]);
7056 fprintf (f, "%s (opnum = %d)",
7057 reload_when_needed_name[(int) rld[r].when_needed],
7058 rld[r].opnum);
7060 if (rld[r].optional)
7061 fprintf (f, ", optional");
7063 if (rld[r].nongroup)
7064 fprintf (f, ", nongroup");
7066 if (rld[r].inc != 0)
7067 fprintf (f, ", inc by %d", rld[r].inc);
7069 if (rld[r].nocombine)
7070 fprintf (f, ", can't combine");
7072 if (rld[r].secondary_p)
7073 fprintf (f, ", secondary_reload_p");
7075 if (rld[r].in_reg != 0)
7077 fprintf (f, "\n\treload_in_reg: ");
7078 print_inline_rtx (f, rld[r].in_reg, 24);
7081 if (rld[r].out_reg != 0)
7083 fprintf (f, "\n\treload_out_reg: ");
7084 print_inline_rtx (f, rld[r].out_reg, 24);
7087 if (rld[r].reg_rtx != 0)
7089 fprintf (f, "\n\treload_reg_rtx: ");
7090 print_inline_rtx (f, rld[r].reg_rtx, 24);
7093 prefix = "\n\t";
7094 if (rld[r].secondary_in_reload != -1)
7096 fprintf (f, "%ssecondary_in_reload = %d",
7097 prefix, rld[r].secondary_in_reload);
7098 prefix = ", ";
7101 if (rld[r].secondary_out_reload != -1)
7102 fprintf (f, "%ssecondary_out_reload = %d\n",
7103 prefix, rld[r].secondary_out_reload);
7105 prefix = "\n\t";
7106 if (rld[r].secondary_in_icode != CODE_FOR_nothing)
7108 fprintf (f, "%ssecondary_in_icode = %s", prefix,
7109 insn_data[rld[r].secondary_in_icode].name);
7110 prefix = ", ";
7113 if (rld[r].secondary_out_icode != CODE_FOR_nothing)
7114 fprintf (f, "%ssecondary_out_icode = %s", prefix,
7115 insn_data[rld[r].secondary_out_icode].name);
7117 fprintf (f, "\n");
7121 void
7122 debug_reload (void)
7124 debug_reload_to_stream (stderr);