]> gcc.gnu.org Git - gcc.git/blame - gcc/reload.c
(get_secondary_mem): Use macro SECONDARY_MEMORY_NEEDED_RTX.
[gcc.git] / gcc / reload.c
CommitLineData
eab89b90
RK
1/* Search an insn for pseudo regs that must be in hard regs and are not.
2 Copyright (C) 1987, 1988, 1989, 1992 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21/* This file contains subroutines used only from the file reload1.c.
22 It knows how to scan one insn for operands and values
23 that need to be copied into registers to make valid code.
24 It also finds other operands and values which are valid
25 but for which equivalent values in registers exist and
26 ought to be used instead.
27
28 Before processing the first insn of the function, call `init_reload'.
29
30 To scan an insn, call `find_reloads'. This does two things:
31 1. sets up tables describing which values must be reloaded
32 for this insn, and what kind of hard regs they must be reloaded into;
33 2. optionally record the locations where those values appear in
34 the data, so they can be replaced properly later.
35 This is done only if the second arg to `find_reloads' is nonzero.
36
37 The third arg to `find_reloads' specifies the number of levels
38 of indirect addressing supported by the machine. If it is zero,
39 indirect addressing is not valid. If it is one, (MEM (REG n))
40 is valid even if (REG n) did not get a hard register; if it is two,
41 (MEM (MEM (REG n))) is also valid even if (REG n) did not get a
42 hard register, and similarly for higher values.
43
44 Then you must choose the hard regs to reload those pseudo regs into,
45 and generate appropriate load insns before this insn and perhaps
46 also store insns after this insn. Set up the array `reload_reg_rtx'
47 to contain the REG rtx's for the registers you used. In some
48 cases `find_reloads' will return a nonzero value in `reload_reg_rtx'
49 for certain reloads. Then that tells you which register to use,
50 so you do not need to allocate one. But you still do need to add extra
51 instructions to copy the value into and out of that register.
52
53 Finally you must call `subst_reloads' to substitute the reload reg rtx's
54 into the locations already recorded.
55
56NOTE SIDE EFFECTS:
57
58 find_reloads can alter the operands of the instruction it is called on.
59
60 1. Two operands of any sort may be interchanged, if they are in a
61 commutative instruction.
62 This happens only if find_reloads thinks the instruction will compile
63 better that way.
64
65 2. Pseudo-registers that are equivalent to constants are replaced
66 with those constants if they are not in hard registers.
67
681 happens every time find_reloads is called.
692 happens only when REPLACE is 1, which is only when
70actually doing the reloads, not when just counting them.
71
72
73Using a reload register for several reloads in one insn:
74
75When an insn has reloads, it is considered as having three parts:
76the input reloads, the insn itself after reloading, and the output reloads.
77Reloads of values used in memory addresses are often needed for only one part.
78
79When this is so, reload_when_needed records which part needs the reload.
80Two reloads for different parts of the insn can share the same reload
81register.
82
83When a reload is used for addresses in multiple parts, or when it is
84an ordinary operand, it is classified as RELOAD_OTHER, and cannot share
85a register with any other reload. */
86
87#define REG_OK_STRICT
88
89#include "config.h"
90#include "rtl.h"
91#include "insn-config.h"
92#include "insn-codes.h"
93#include "recog.h"
94#include "reload.h"
95#include "regs.h"
96#include "hard-reg-set.h"
97#include "flags.h"
98#include "real.h"
99
100#ifndef REGISTER_MOVE_COST
101#define REGISTER_MOVE_COST(x, y) 2
102#endif
103\f
104/* The variables set up by `find_reloads' are:
105
106 n_reloads number of distinct reloads needed; max reload # + 1
107 tables indexed by reload number
108 reload_in rtx for value to reload from
109 reload_out rtx for where to store reload-reg afterward if nec
110 (often the same as reload_in)
111 reload_reg_class enum reg_class, saying what regs to reload into
112 reload_inmode enum machine_mode; mode this operand should have
113 when reloaded, on input.
114 reload_outmode enum machine_mode; mode this operand should have
115 when reloaded, on output.
116 reload_strict_low char; currently always zero; used to mean that this
117 reload is inside a STRICT_LOW_PART, but we don't
118 need to know this anymore.
119 reload_optional char, nonzero for an optional reload.
120 Optional reloads are ignored unless the
121 value is already sitting in a register.
122 reload_inc int, positive amount to increment or decrement by if
123 reload_in is a PRE_DEC, PRE_INC, POST_DEC, POST_INC.
124 Ignored otherwise (don't assume it is zero).
125 reload_in_reg rtx. A reg for which reload_in is the equivalent.
126 If reload_in is a symbol_ref which came from
127 reg_equiv_constant, then this is the pseudo
128 which has that symbol_ref as equivalent.
129 reload_reg_rtx rtx. This is the register to reload into.
130 If it is zero when `find_reloads' returns,
131 you must find a suitable register in the class
132 specified by reload_reg_class, and store here
133 an rtx for that register with mode from
134 reload_inmode or reload_outmode.
135 reload_nocombine char, nonzero if this reload shouldn't be
136 combined with another reload.
137 reload_needed_for rtx, operand this reload is needed for address of.
138 0 means it isn't needed for addressing.
139 reload_needed_for_multiple
140 int, 1 if this reload needed for more than one thing.
141 reload_when_needed enum, classifies reload as needed either for
142 addressing an input reload, addressing an output,
143 for addressing a non-reloaded mem ref,
144 or for unspecified purposes (i.e., more than one
145 of the above).
146 reload_secondary_reload int, gives the reload number of a secondary
147 reload, when needed; otherwise -1
148 reload_secondary_p int, 1 if this is a secondary register for one
149 or more reloads.
150 reload_secondary_icode enum insn_code, if a secondary reload is required,
151 gives the INSN_CODE that uses the secondary
152 reload as a scratch register, or CODE_FOR_nothing
153 if the secondary reload register is to be an
154 intermediate register. */
155int n_reloads;
156
157rtx reload_in[MAX_RELOADS];
158rtx reload_out[MAX_RELOADS];
159enum reg_class reload_reg_class[MAX_RELOADS];
160enum machine_mode reload_inmode[MAX_RELOADS];
161enum machine_mode reload_outmode[MAX_RELOADS];
162char reload_strict_low[MAX_RELOADS];
163rtx reload_reg_rtx[MAX_RELOADS];
164char reload_optional[MAX_RELOADS];
165int reload_inc[MAX_RELOADS];
166rtx reload_in_reg[MAX_RELOADS];
167char reload_nocombine[MAX_RELOADS];
168int reload_needed_for_multiple[MAX_RELOADS];
169rtx reload_needed_for[MAX_RELOADS];
170enum reload_when_needed reload_when_needed[MAX_RELOADS];
171int reload_secondary_reload[MAX_RELOADS];
172int reload_secondary_p[MAX_RELOADS];
173enum insn_code reload_secondary_icode[MAX_RELOADS];
174
175/* All the "earlyclobber" operands of the current insn
176 are recorded here. */
177int n_earlyclobbers;
178rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
179
180/* Replacing reloads.
181
182 If `replace_reloads' is nonzero, then as each reload is recorded
183 an entry is made for it in the table `replacements'.
184 Then later `subst_reloads' can look through that table and
185 perform all the replacements needed. */
186
187/* Nonzero means record the places to replace. */
188static int replace_reloads;
189
190/* Each replacement is recorded with a structure like this. */
191struct replacement
192{
193 rtx *where; /* Location to store in */
194 rtx *subreg_loc; /* Location of SUBREG if WHERE is inside
195 a SUBREG; 0 otherwise. */
196 int what; /* which reload this is for */
197 enum machine_mode mode; /* mode it must have */
198};
199
200static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
201
202/* Number of replacements currently recorded. */
203static int n_replacements;
204
205/* MEM-rtx's created for pseudo-regs in stack slots not directly addressable;
206 (see reg_equiv_address). */
207static rtx memlocs[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
208static int n_memlocs;
209
0dadecf6
RK
210#ifdef SECONDARY_MEMORY_NEEDED
211
212/* Save MEMs needed to copy from one class of registers to another. One MEM
213 is used per mode, but normally only one or two modes are ever used.
214
215 We keep two versions, before and after register elimination. */
216
217static rtx secondary_memlocs[NUM_MACHINE_MODES];
218static rtx secondary_memlocs_elim[NUM_MACHINE_MODES];
219#endif
220
eab89b90
RK
221/* The instruction we are doing reloads for;
222 so we can test whether a register dies in it. */
223static rtx this_insn;
224
225/* Nonzero if this instruction is a user-specified asm with operands. */
226static int this_insn_is_asm;
227
228/* If hard_regs_live_known is nonzero,
229 we can tell which hard regs are currently live,
230 at least enough to succeed in choosing dummy reloads. */
231static int hard_regs_live_known;
232
233/* Indexed by hard reg number,
234 element is nonegative if hard reg has been spilled.
235 This vector is passed to `find_reloads' as an argument
236 and is not changed here. */
237static short *static_reload_reg_p;
238
239/* Set to 1 in subst_reg_equivs if it changes anything. */
240static int subst_reg_equivs_changed;
241
242/* On return from push_reload, holds the reload-number for the OUT
243 operand, which can be different for that from the input operand. */
244static int output_reloadnum;
245
246static int alternative_allows_memconst ();
247static rtx find_dummy_reload ();
248static rtx find_reloads_toplev ();
249static int find_reloads_address ();
250static int find_reloads_address_1 ();
251static void find_reloads_address_part ();
252static int hard_reg_set_here_p ();
253/* static rtx forget_volatility (); */
254static rtx subst_reg_equivs ();
255static rtx subst_indexed_address ();
3c80f7ed 256void copy_replacements ();
eab89b90
RK
257rtx find_equiv_reg ();
258static int find_inc_amount ();
259\f
260#ifdef HAVE_SECONDARY_RELOADS
261
262/* Determine if any secondary reloads are needed for loading (if IN_P is
263 non-zero) or storing (if IN_P is zero) X to or from a reload register of
264 register class RELOAD_CLASS in mode RELOAD_MODE.
265
266 Return the register class of a secondary reload register, or NO_REGS if
267 none. *PMODE is set to the mode that the register is required in.
268 If the reload register is needed as a scratch register instead of an
269 intermediate register, *PICODE is set to the insn_code of the insn to be
270 used to load or store the primary reload register; otherwise *PICODE
271 is set to CODE_FOR_nothing.
272
273 In some cases (such as storing MQ into an external memory location on
274 the RT), both an intermediate register and a scratch register. In that
275 case, *PICODE is set to CODE_FOR_nothing, the class for the intermediate
276 register is returned, and the *PTERTIARY_... variables are set to describe
277 the scratch register. */
278
279static enum reg_class
280find_secondary_reload (x, reload_class, reload_mode, in_p, picode, pmode,
281 ptertiary_class, ptertiary_icode, ptertiary_mode)
282 rtx x;
283 enum reg_class reload_class;
284 enum machine_mode reload_mode;
285 int in_p;
286 enum insn_code *picode;
287 enum machine_mode *pmode;
288 enum reg_class *ptertiary_class;
289 enum insn_code *ptertiary_icode;
290 enum machine_mode *ptertiary_mode;
291{
292 enum reg_class class = NO_REGS;
293 enum machine_mode mode = reload_mode;
294 enum insn_code icode = CODE_FOR_nothing;
295 enum reg_class t_class = NO_REGS;
296 enum machine_mode t_mode = VOIDmode;
297 enum insn_code t_icode = CODE_FOR_nothing;
298
d45cf215
RS
299 /* If X is a pseudo-register that has an equivalent MEM (actually, if it
300 is still a pseudo-register by now, it *must* have an equivalent MEM
301 but we don't want to assume that), use that equivalent when seeing if
302 a secondary reload is needed since whether or not a reload is needed
303 might be sensitive to the form of the MEM. */
304
305 if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER
306 && reg_equiv_mem[REGNO (x)] != 0)
307 x = reg_equiv_mem[REGNO (x)];
308
eab89b90
RK
309#ifdef SECONDARY_INPUT_RELOAD_CLASS
310 if (in_p)
311 class = SECONDARY_INPUT_RELOAD_CLASS (reload_class, reload_mode, x);
312#endif
313
314#ifdef SECONDARY_OUTPUT_RELOAD_CLASS
315 if (! in_p)
316 class = SECONDARY_OUTPUT_RELOAD_CLASS (reload_class, reload_mode, x);
317#endif
318
319 /* If we don't need any secondary registers, go away; the rest of the
320 values won't be used. */
321 if (class == NO_REGS)
322 return NO_REGS;
323
324 /* Get a possible insn to use. If the predicate doesn't accept X, don't
325 use the insn. */
326
327 icode = (in_p ? reload_in_optab[(int) reload_mode]
328 : reload_out_optab[(int) reload_mode]);
329
330 if (icode != CODE_FOR_nothing
331 && insn_operand_predicate[(int) icode][in_p]
332 && (! (insn_operand_predicate[(int) icode][in_p]) (x, reload_mode)))
333 icode = CODE_FOR_nothing;
334
335 /* If we will be using an insn, see if it can directly handle the reload
336 register we will be using. If it can, the secondary reload is for a
337 scratch register. If it can't, we will use the secondary reload for
338 an intermediate register and require a tertiary reload for the scratch
339 register. */
340
341 if (icode != CODE_FOR_nothing)
342 {
343 /* If IN_P is non-zero, the reload register will be the output in
344 operand 0. If IN_P is zero, the reload register will be the input
345 in operand 1. Outputs should have an initial "=", which we must
346 skip. */
347
d45cf215 348 char insn_letter = insn_operand_constraint[(int) icode][!in_p][in_p];
eab89b90 349 enum reg_class insn_class
d45cf215
RS
350 = (insn_letter == 'r' ? GENERAL_REGS
351 : REG_CLASS_FROM_LETTER (insn_letter));
eab89b90
RK
352
353 if (insn_class == NO_REGS
354 || (in_p && insn_operand_constraint[(int) icode][!in_p][0] != '=')
355 /* The scratch register's constraint must start with "=&". */
356 || insn_operand_constraint[(int) icode][2][0] != '='
357 || insn_operand_constraint[(int) icode][2][1] != '&')
358 abort ();
359
360 if (reg_class_subset_p (reload_class, insn_class))
361 mode = insn_operand_mode[(int) icode][2];
362 else
363 {
d45cf215 364 char t_letter = insn_operand_constraint[(int) icode][2][2];
eab89b90
RK
365 class = insn_class;
366 t_mode = insn_operand_mode[(int) icode][2];
d45cf215
RS
367 t_class = (t_letter == 'r' ? GENERAL_REGS
368 : REG_CLASS_FROM_LETTER (t_letter));
eab89b90
RK
369 t_icode = icode;
370 icode = CODE_FOR_nothing;
371 }
372 }
373
374 *pmode = mode;
375 *picode = icode;
376 *ptertiary_class = t_class;
377 *ptertiary_mode = t_mode;
378 *ptertiary_icode = t_icode;
379
380 return class;
381}
382#endif /* HAVE_SECONDARY_RELOADS */
383\f
0dadecf6
RK
384#ifdef SECONDARY_MEMORY_NEEDED
385
386/* Return a memory location that will be used to copy X in mode MODE.
387 If we haven't already made a location for this mode in this insn,
388 call find_reloads_address on the location being returned. */
389
390rtx
391get_secondary_mem (x, mode)
392 rtx x;
393 enum machine_mode mode;
394{
395 rtx loc;
396 int mem_valid;
397
398 /* If MODE is narrower than a word, widen it. This is required because
399 most machines that require these memory locations do not support
400 short load and stores from all registers (e.g., FP registers). We could
401 possibly conditionalize this, but we lose nothing by doing the wider
402 mode. */
403
404 if (GET_MODE_BITSIZE (mode) < BITS_PER_WORD)
405 mode = mode_for_size (BITS_PER_WORD, GET_MODE_CLASS (mode), 0);
406
407 /* If we already have made a MEM for this insn, return it. */
408 if (secondary_memlocs_elim[(int) mode] != 0)
409 return secondary_memlocs_elim[(int) mode];
410
411 /* If this is the first time we've tried to get a MEM for this mode,
412 allocate a new one. `something_changed' in reload will get set
413 by noticing that the frame size has changed. */
414
415 if (secondary_memlocs[(int) mode] == 0)
b24a53d5
JW
416 {
417#ifdef SECONDARY_MEMORY_NEEDED_RTX
418 secondary_memlocs[(int) mode] = SECONDARY_MEMORY_NEEDED_RTX (mode);
419#else
420 secondary_memlocs[(int) mode]
421 = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
422#endif
423 }
0dadecf6
RK
424
425 /* Get a version of the address doing any eliminations needed. If that
426 didn't give us a new MEM, make a new one if it isn't valid. */
427
428 loc = eliminate_regs (secondary_memlocs[(int) mode], 0, NULL_RTX);
429 mem_valid = strict_memory_address_p (mode, XEXP (loc, 0));
430
431 if (! mem_valid && loc == secondary_memlocs[(int) mode])
432 loc = copy_rtx (loc);
433
434 /* The only time the call below will do anything is if the stack
435 offset is too large. In that case IND_LEVELS doesn't matter, so we
436 can just pass a zero. */
437 if (! mem_valid)
438 find_reloads_address (mode, NULL_PTR, XEXP (loc, 0), &XEXP (loc, 0), x, 0);
439
8d618585
JW
440 /* If the address was not valid to begin with, we can not save it, because
441 there is no guarantee that the reloads needed to make it valid will
442 occur before every use of this address. */
443
444 else
445 secondary_memlocs_elim[(int) mode] = loc;
0dadecf6
RK
446
447 return loc;
448}
449
450/* Clear any secondary memory locations we've made. */
451
452void
453clear_secondary_mem ()
454{
455 int i;
456
457 for (i = 0; i < NUM_MACHINE_MODES; i++)
458 secondary_memlocs[i] = 0;
459}
460#endif /* SECONDARY_MEMORY_NEEDED */
461\f
eab89b90
RK
462/* Record one (sometimes two) reload that needs to be performed.
463 IN is an rtx saying where the data are to be found before this instruction.
464 OUT says where they must be stored after the instruction.
465 (IN is zero for data not read, and OUT is zero for data not written.)
466 INLOC and OUTLOC point to the places in the instructions where
467 IN and OUT were found.
468 CLASS is a register class required for the reloaded data.
469 INMODE is the machine mode that the instruction requires
470 for the reg that replaces IN and OUTMODE is likewise for OUT.
471
472 If IN is zero, then OUT's location and mode should be passed as
473 INLOC and INMODE.
474
475 STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
476
477 OPTIONAL nonzero means this reload does not need to be performed:
478 it can be discarded if that is more convenient.
479
480 The return value is the reload-number for this reload.
481
482 If both IN and OUT are nonzero, in some rare cases we might
483 want to make two separate reloads. (Actually we never do this now.)
484 Therefore, the reload-number for OUT is stored in
485 output_reloadnum when we return; the return value applies to IN.
486 Usually (presently always), when IN and OUT are nonzero,
487 the two reload-numbers are equal, but the caller should be careful to
488 distinguish them. */
489
490static int
491push_reload (in, out, inloc, outloc, class,
492 inmode, outmode, strict_low, optional, needed_for)
493 register rtx in, out;
494 rtx *inloc, *outloc;
495 enum reg_class class;
496 enum machine_mode inmode, outmode;
497 int strict_low;
498 int optional;
499 rtx needed_for;
500{
501 register int i;
502 int dont_share = 0;
503 rtx *in_subreg_loc = 0, *out_subreg_loc = 0;
504 int secondary_reload = -1;
505 enum insn_code secondary_icode = CODE_FOR_nothing;
506
507 /* Compare two RTX's. */
508#define MATCHES(x, y) \
509 (x == y || (x != 0 && (GET_CODE (x) == REG \
510 ? GET_CODE (y) == REG && REGNO (x) == REGNO (y) \
511 : rtx_equal_p (x, y) && ! side_effects_p (x))))
512
513 /* INMODE and/or OUTMODE could be VOIDmode if no mode
514 has been specified for the operand. In that case,
515 use the operand's mode as the mode to reload. */
516 if (inmode == VOIDmode && in != 0)
517 inmode = GET_MODE (in);
518 if (outmode == VOIDmode && out != 0)
519 outmode = GET_MODE (out);
520
521 /* If IN is a pseudo register everywhere-equivalent to a constant, and
522 it is not in a hard register, reload straight from the constant,
523 since we want to get rid of such pseudo registers.
524 Often this is done earlier, but not always in find_reloads_address. */
525 if (in != 0 && GET_CODE (in) == REG)
526 {
527 register int regno = REGNO (in);
528
529 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
530 && reg_equiv_constant[regno] != 0)
531 in = reg_equiv_constant[regno];
532 }
533
534 /* Likewise for OUT. Of course, OUT will never be equivalent to
535 an actual constant, but it might be equivalent to a memory location
536 (in the case of a parameter). */
537 if (out != 0 && GET_CODE (out) == REG)
538 {
539 register int regno = REGNO (out);
540
541 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
542 && reg_equiv_constant[regno] != 0)
543 out = reg_equiv_constant[regno];
544 }
545
546 /* If we have a read-write operand with an address side-effect,
547 change either IN or OUT so the side-effect happens only once. */
548 if (in != 0 && out != 0 && GET_CODE (in) == MEM && rtx_equal_p (in, out))
549 {
550 if (GET_CODE (XEXP (in, 0)) == POST_INC
551 || GET_CODE (XEXP (in, 0)) == POST_DEC)
552 in = gen_rtx (MEM, GET_MODE (in), XEXP (XEXP (in, 0), 0));
553 if (GET_CODE (XEXP (in, 0)) == PRE_INC
554 || GET_CODE (XEXP (in, 0)) == PRE_DEC)
555 out = gen_rtx (MEM, GET_MODE (out), XEXP (XEXP (out, 0), 0));
556 }
557
558 /* If we are reloading a (SUBREG (MEM ...) ...) or (SUBREG constant ...),
559 really reload just the inside expression in its own mode.
560 If we have (SUBREG:M1 (REG:M2 ...) ...) with M1 wider than M2 and the
561 register is a pseudo, this will become the same as the above case.
562 Do the same for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where
563 either M1 is not valid for R or M2 is wider than a word but we only
564 need one word to store an M2-sized quantity in R.
565 Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere;
566 we can't handle it here because CONST_INT does not indicate a mode.
567
568 Similarly, we must reload the inside expression if we have a
df62f951
RK
569 STRICT_LOW_PART (presumably, in == out in the cas).
570
571 Also reload the inner expression if it does not require a secondary
572 reload but the SUBREG does. */
eab89b90
RK
573
574 if (in != 0 && GET_CODE (in) == SUBREG
575 && (GET_CODE (SUBREG_REG (in)) != REG
576 || strict_low
577 || (GET_CODE (SUBREG_REG (in)) == REG
578 && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER
579 && (GET_MODE_SIZE (inmode)
580 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))))
581 || (GET_CODE (SUBREG_REG (in)) == REG
582 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER
583 && (! HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (in)), inmode)
584 || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD
585 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
586 > UNITS_PER_WORD)
587 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
588 / UNITS_PER_WORD)
589 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (in)),
df62f951
RK
590 GET_MODE (SUBREG_REG (in)))))))
591#ifdef SECONDARY_INPUT_RELOAD_CLASS
592 || (SECONDARY_INPUT_RELOAD_CLASS (class, inmode, in) != NO_REGS
593 && (SECONDARY_INPUT_RELOAD_CLASS (class,
594 GET_MODE (SUBREG_REG (in)),
595 SUBREG_REG (in))
596 == NO_REGS))
597#endif
598 ))
eab89b90
RK
599 {
600 in_subreg_loc = inloc;
601 inloc = &SUBREG_REG (in);
602 in = *inloc;
603 if (GET_CODE (in) == MEM)
604 /* This is supposed to happen only for paradoxical subregs made by
605 combine.c. (SUBREG (MEM)) isn't supposed to occur other ways. */
606 if (GET_MODE_SIZE (GET_MODE (in)) > GET_MODE_SIZE (inmode))
607 abort ();
608 inmode = GET_MODE (in);
609 }
610
611 /* Similarly for paradoxical and problematical SUBREGs on the output.
612 Note that there is no reason we need worry about the previous value
613 of SUBREG_REG (out); even if wider than out,
614 storing in a subreg is entitled to clobber it all
615 (except in the case of STRICT_LOW_PART,
616 and in that case the constraint should label it input-output.) */
617 if (out != 0 && GET_CODE (out) == SUBREG
618 && (GET_CODE (SUBREG_REG (out)) != REG
619 || strict_low
620 || (GET_CODE (SUBREG_REG (out)) == REG
621 && REGNO (SUBREG_REG (out)) >= FIRST_PSEUDO_REGISTER
622 && (GET_MODE_SIZE (outmode)
623 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))))
624 || (GET_CODE (SUBREG_REG (out)) == REG
625 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER
626 && (! HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (out)), outmode)
627 || (GET_MODE_SIZE (outmode) <= UNITS_PER_WORD
628 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
629 > UNITS_PER_WORD)
630 && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))
631 / UNITS_PER_WORD)
632 != HARD_REGNO_NREGS (REGNO (SUBREG_REG (out)),
df62f951
RK
633 GET_MODE (SUBREG_REG (out)))))))
634#ifdef SECONDARY_OUTPUT_RELOAD_CLASS
635 || (SECONDARY_OUTPUT_RELOAD_CLASS (class, outmode, out) != NO_REGS
636 && (SECONDARY_OUTPUT_RELOAD_CLASS (class,
637 GET_MODE (SUBREG_REG (out)),
638 SUBREG_REG (out))
639 == NO_REGS))
640#endif
641 ))
eab89b90
RK
642 {
643 out_subreg_loc = outloc;
644 outloc = &SUBREG_REG (out);
645 out = *outloc;
646 if (GET_CODE (out) == MEM
647 && GET_MODE_SIZE (GET_MODE (out)) > GET_MODE_SIZE (outmode))
648 abort ();
649 outmode = GET_MODE (out);
650 }
651
652 /* That's all we use STRICT_LOW for, so clear it. At some point,
653 we may want to get rid of reload_strict_low. */
654 strict_low = 0;
655
656 /* If IN appears in OUT, we can't share any input-only reload for IN. */
657 if (in != 0 && out != 0 && GET_CODE (out) == MEM
658 && (GET_CODE (in) == REG || GET_CODE (in) == MEM)
bfa30b22 659 && reg_overlap_mentioned_for_reload_p (in, XEXP (out, 0)))
eab89b90
RK
660 dont_share = 1;
661
0dadecf6
RK
662 /* If IN is a SUBREG of a hard register, make a new REG. This
663 simplifies some of the cases below. */
664
665 if (in != 0 && GET_CODE (in) == SUBREG && GET_CODE (SUBREG_REG (in)) == REG
666 && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER)
667 in = gen_rtx (REG, GET_MODE (in),
668 REGNO (SUBREG_REG (in)) + SUBREG_WORD (in));
669
670 /* Similarly for OUT. */
671 if (out != 0 && GET_CODE (out) == SUBREG
672 && GET_CODE (SUBREG_REG (out)) == REG
673 && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER)
674 out = gen_rtx (REG, GET_MODE (out),
675 REGNO (SUBREG_REG (out)) + SUBREG_WORD (out));
676
eab89b90
RK
677 /* Narrow down the class of register wanted if that is
678 desirable on this machine for efficiency. */
679 if (in != 0)
680 class = PREFERRED_RELOAD_CLASS (in, class);
681
ac2a9454 682 /* Output reloads may need analogous treatment, different in detail. */
18a53b78
RS
683#ifdef PREFERRED_OUTPUT_RELOAD_CLASS
684 if (out != 0)
685 class = PREFERRED_OUTPUT_RELOAD_CLASS (out, class);
686#endif
687
eab89b90
RK
688 /* Make sure we use a class that can handle the actual pseudo
689 inside any subreg. For example, on the 386, QImode regs
690 can appear within SImode subregs. Although GENERAL_REGS
691 can handle SImode, QImode needs a smaller class. */
692#ifdef LIMIT_RELOAD_CLASS
693 if (in_subreg_loc)
694 class = LIMIT_RELOAD_CLASS (inmode, class);
695 else if (in != 0 && GET_CODE (in) == SUBREG)
696 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (in)), class);
697
698 if (out_subreg_loc)
699 class = LIMIT_RELOAD_CLASS (outmode, class);
700 if (out != 0 && GET_CODE (out) == SUBREG)
701 class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (out)), class);
702#endif
703
eab89b90
RK
704 /* Verify that this class is at least possible for the mode that
705 is specified. */
706 if (this_insn_is_asm)
707 {
708 enum machine_mode mode;
709 if (GET_MODE_SIZE (inmode) > GET_MODE_SIZE (outmode))
710 mode = inmode;
711 else
712 mode = outmode;
5488078f
RS
713 if (mode == VOIDmode)
714 {
715 error_for_asm (this_insn, "cannot reload integer constant operand in `asm'");
716 mode = word_mode;
717 if (in != 0)
718 inmode = word_mode;
719 if (out != 0)
720 outmode = word_mode;
721 }
eab89b90
RK
722 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
723 if (HARD_REGNO_MODE_OK (i, mode)
724 && TEST_HARD_REG_BIT (reg_class_contents[(int) class], i))
725 {
726 int nregs = HARD_REGNO_NREGS (i, mode);
727
728 int j;
729 for (j = 1; j < nregs; j++)
730 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], i + j))
731 break;
732 if (j == nregs)
733 break;
734 }
735 if (i == FIRST_PSEUDO_REGISTER)
736 {
737 error_for_asm (this_insn, "impossible register constraint in `asm'");
738 class = ALL_REGS;
739 }
740 }
741
5488078f
RS
742 if (class == NO_REGS)
743 abort ();
744
eab89b90
RK
745 /* We can use an existing reload if the class is right
746 and at least one of IN and OUT is a match
747 and the other is at worst neutral.
748 (A zero compared against anything is neutral.) */
749 for (i = 0; i < n_reloads; i++)
750 if ((reg_class_subset_p (class, reload_reg_class[i])
751 || reg_class_subset_p (reload_reg_class[i], class))
752 && reload_strict_low[i] == strict_low
753 /* If the existing reload has a register, it must fit our class. */
754 && (reload_reg_rtx[i] == 0
755 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
756 true_regnum (reload_reg_rtx[i])))
757 && ((in != 0 && MATCHES (reload_in[i], in) && ! dont_share
758 && (out == 0 || reload_out[i] == 0 || MATCHES (reload_out[i], out)))
759 ||
760 (out != 0 && MATCHES (reload_out[i], out)
761 && (in == 0 || reload_in[i] == 0 || MATCHES (reload_in[i], in)))))
762 break;
763
764 /* Reloading a plain reg for input can match a reload to postincrement
765 that reg, since the postincrement's value is the right value.
766 Likewise, it can match a preincrement reload, since we regard
767 the preincrementation as happening before any ref in this insn
768 to that register. */
769 if (i == n_reloads)
770 for (i = 0; i < n_reloads; i++)
771 if ((reg_class_subset_p (class, reload_reg_class[i])
772 || reg_class_subset_p (reload_reg_class[i], class))
773 /* If the existing reload has a register, it must fit our class. */
774 && (reload_reg_rtx[i] == 0
775 || TEST_HARD_REG_BIT (reg_class_contents[(int) class],
776 true_regnum (reload_reg_rtx[i])))
777 && reload_strict_low[i] == strict_low
778 && out == 0 && reload_out[i] == 0 && reload_in[i] != 0
779 && ((GET_CODE (in) == REG
780 && (GET_CODE (reload_in[i]) == POST_INC
781 || GET_CODE (reload_in[i]) == POST_DEC
782 || GET_CODE (reload_in[i]) == PRE_INC
783 || GET_CODE (reload_in[i]) == PRE_DEC)
784 && MATCHES (XEXP (reload_in[i], 0), in))
785 ||
786 (GET_CODE (reload_in[i]) == REG
787 && (GET_CODE (in) == POST_INC
788 || GET_CODE (in) == POST_DEC
789 || GET_CODE (in) == PRE_INC
790 || GET_CODE (in) == PRE_DEC)
791 && MATCHES (XEXP (in, 0), reload_in[i]))))
792 {
793 /* Make sure reload_in ultimately has the increment,
794 not the plain register. */
795 if (GET_CODE (in) == REG)
796 in = reload_in[i];
797 break;
798 }
799
800 if (i == n_reloads)
801 {
802#ifdef HAVE_SECONDARY_RELOADS
803 enum reg_class secondary_class = NO_REGS;
804 enum reg_class secondary_out_class = NO_REGS;
805 enum machine_mode secondary_mode = inmode;
806 enum machine_mode secondary_out_mode = outmode;
807 enum insn_code secondary_icode;
808 enum insn_code secondary_out_icode = CODE_FOR_nothing;
809 enum reg_class tertiary_class = NO_REGS;
810 enum reg_class tertiary_out_class = NO_REGS;
811 enum machine_mode tertiary_mode;
812 enum machine_mode tertiary_out_mode;
813 enum insn_code tertiary_icode;
814 enum insn_code tertiary_out_icode = CODE_FOR_nothing;
815 int tertiary_reload = -1;
816
817 /* See if we need a secondary reload register to move between
818 CLASS and IN or CLASS and OUT. Get the modes and icodes to
819 use for each of them if so. */
820
821#ifdef SECONDARY_INPUT_RELOAD_CLASS
822 if (in != 0)
823 secondary_class
824 = find_secondary_reload (in, class, inmode, 1, &secondary_icode,
825 &secondary_mode, &tertiary_class,
826 &tertiary_icode, &tertiary_mode);
827#endif
828
829#ifdef SECONDARY_OUTPUT_RELOAD_CLASS
830 if (out != 0 && GET_CODE (out) != SCRATCH)
831 secondary_out_class
832 = find_secondary_reload (out, class, outmode, 0,
833 &secondary_out_icode, &secondary_out_mode,
834 &tertiary_out_class, &tertiary_out_icode,
835 &tertiary_out_mode);
836#endif
837
838 /* We can only record one secondary and one tertiary reload. If both
839 IN and OUT need secondary reloads, we can only make an in-out
840 reload if neither need an insn and if the classes are compatible. */
841
842 if (secondary_class != NO_REGS && secondary_out_class != NO_REGS
843 && reg_class_subset_p (secondary_out_class, secondary_class))
844 secondary_class = secondary_out_class;
845
846 if (secondary_class != NO_REGS && secondary_out_class != NO_REGS
847 && (! reg_class_subset_p (secondary_class, secondary_out_class)
848 || secondary_icode != CODE_FOR_nothing
849 || secondary_out_icode != CODE_FOR_nothing))
850 {
fb3821f7
CH
851 push_reload (NULL_RTX, out, NULL_PTR, outloc, class,
852 VOIDmode, outmode, strict_low, optional, needed_for);
eab89b90
RK
853 out = 0;
854 outloc = 0;
855 outmode = VOIDmode;
856 }
857
858 /* If we need a secondary reload for OUT but not IN, copy the
859 information. */
860 if (secondary_class == NO_REGS && secondary_out_class != NO_REGS)
861 {
862 secondary_class = secondary_out_class;
863 secondary_icode = secondary_out_icode;
864 tertiary_class = tertiary_out_class;
865 tertiary_icode = tertiary_out_icode;
866 tertiary_mode = tertiary_out_mode;
867 }
868
869 if (secondary_class != NO_REGS)
870 {
871 /* If we need a tertiary reload, see if we have one we can reuse
872 or else make one. */
873
874 if (tertiary_class != NO_REGS)
875 {
876 for (tertiary_reload = 0; tertiary_reload < n_reloads;
877 tertiary_reload++)
878 if (reload_secondary_p[tertiary_reload]
879 && (reg_class_subset_p (tertiary_class,
880 reload_reg_class[tertiary_reload])
881 || reg_class_subset_p (reload_reg_class[tertiary_reload],
882 tertiary_class))
883 && ((reload_inmode[tertiary_reload] == tertiary_mode)
884 || reload_inmode[tertiary_reload] == VOIDmode)
885 && ((reload_outmode[tertiary_reload] == tertiary_mode)
886 || reload_outmode[tertiary_reload] == VOIDmode)
887 && (reload_secondary_icode[tertiary_reload]
888 == CODE_FOR_nothing))
889
890 {
891 if (tertiary_mode != VOIDmode)
892 reload_inmode[tertiary_reload] = tertiary_mode;
893 if (tertiary_out_mode != VOIDmode)
894 reload_outmode[tertiary_reload] = tertiary_mode;
895 if (reg_class_subset_p (tertiary_class,
896 reload_reg_class[tertiary_reload]))
897 reload_reg_class[tertiary_reload] = tertiary_class;
898 if (reload_needed_for[tertiary_reload] != needed_for)
899 reload_needed_for_multiple[tertiary_reload] = 1;
900 reload_optional[tertiary_reload] &= optional;
901 reload_secondary_p[tertiary_reload] = 1;
902 }
903
904 if (tertiary_reload == n_reloads)
905 {
906 /* We need to make a new tertiary reload for this register
907 class. */
908 reload_in[tertiary_reload] = reload_out[tertiary_reload] = 0;
909 reload_reg_class[tertiary_reload] = tertiary_class;
910 reload_inmode[tertiary_reload] = tertiary_mode;
911 reload_outmode[tertiary_reload] = tertiary_mode;
912 reload_reg_rtx[tertiary_reload] = 0;
913 reload_optional[tertiary_reload] = optional;
914 reload_inc[tertiary_reload] = 0;
915 reload_strict_low[tertiary_reload] = 0;
916 /* Maybe we could combine these, but it seems too tricky. */
917 reload_nocombine[tertiary_reload] = 1;
918 reload_in_reg[tertiary_reload] = 0;
919 reload_needed_for[tertiary_reload] = needed_for;
920 reload_needed_for_multiple[tertiary_reload] = 0;
921 reload_secondary_reload[tertiary_reload] = -1;
922 reload_secondary_icode[tertiary_reload] = CODE_FOR_nothing;
923 reload_secondary_p[tertiary_reload] = 1;
924
925 n_reloads++;
926 i = n_reloads;
927 }
928 }
929
930 /* See if we can reuse an existing secondary reload. */
931 for (secondary_reload = 0; secondary_reload < n_reloads;
932 secondary_reload++)
933 if (reload_secondary_p[secondary_reload]
934 && (reg_class_subset_p (secondary_class,
935 reload_reg_class[secondary_reload])
936 || reg_class_subset_p (reload_reg_class[secondary_reload],
937 secondary_class))
938 && ((reload_inmode[secondary_reload] == secondary_mode)
939 || reload_inmode[secondary_reload] == VOIDmode)
940 && ((reload_outmode[secondary_reload] == secondary_out_mode)
941 || reload_outmode[secondary_reload] == VOIDmode)
942 && reload_secondary_reload[secondary_reload] == tertiary_reload
943 && reload_secondary_icode[secondary_reload] == tertiary_icode)
944 {
945 if (secondary_mode != VOIDmode)
946 reload_inmode[secondary_reload] = secondary_mode;
947 if (secondary_out_mode != VOIDmode)
948 reload_outmode[secondary_reload] = secondary_out_mode;
949 if (reg_class_subset_p (secondary_class,
950 reload_reg_class[secondary_reload]))
951 reload_reg_class[secondary_reload] = secondary_class;
952 if (reload_needed_for[secondary_reload] != needed_for)
953 reload_needed_for_multiple[secondary_reload] = 1;
954 reload_optional[secondary_reload] &= optional;
955 reload_secondary_p[secondary_reload] = 1;
956 }
957
958 if (secondary_reload == n_reloads)
959 {
960 /* We need to make a new secondary reload for this register
961 class. */
962 reload_in[secondary_reload] = reload_out[secondary_reload] = 0;
963 reload_reg_class[secondary_reload] = secondary_class;
964 reload_inmode[secondary_reload] = secondary_mode;
965 reload_outmode[secondary_reload] = secondary_out_mode;
966 reload_reg_rtx[secondary_reload] = 0;
967 reload_optional[secondary_reload] = optional;
968 reload_inc[secondary_reload] = 0;
969 reload_strict_low[secondary_reload] = 0;
970 /* Maybe we could combine these, but it seems too tricky. */
971 reload_nocombine[secondary_reload] = 1;
972 reload_in_reg[secondary_reload] = 0;
973 reload_needed_for[secondary_reload] = needed_for;
974 reload_needed_for_multiple[secondary_reload] = 0;
975 reload_secondary_reload[secondary_reload] = tertiary_reload;
976 reload_secondary_icode[secondary_reload] = tertiary_icode;
977 reload_secondary_p[secondary_reload] = 1;
978
979 n_reloads++;
980 i = n_reloads;
0dadecf6
RK
981
982#ifdef SECONDARY_MEMORY_NEEDED
983 /* If we need a memory location to copy between the two
984 reload regs, set it up now. */
985
986 if (in != 0 && secondary_icode == CODE_FOR_nothing
987 && SECONDARY_MEMORY_NEEDED (secondary_class, class, inmode))
988 get_secondary_mem (in, inmode);
989
990 if (out != 0 && secondary_icode == CODE_FOR_nothing
991 && SECONDARY_MEMORY_NEEDED (class, secondary_class, outmode))
992 get_secondary_mem (out, outmode);
993#endif
eab89b90
RK
994 }
995 }
996#endif
997
998 /* We found no existing reload suitable for re-use.
999 So add an additional reload. */
1000
1001 reload_in[i] = in;
1002 reload_out[i] = out;
1003 reload_reg_class[i] = class;
1004 reload_inmode[i] = inmode;
1005 reload_outmode[i] = outmode;
1006 reload_reg_rtx[i] = 0;
1007 reload_optional[i] = optional;
1008 reload_inc[i] = 0;
1009 reload_strict_low[i] = strict_low;
1010 reload_nocombine[i] = 0;
1011 reload_in_reg[i] = inloc ? *inloc : 0;
1012 reload_needed_for[i] = needed_for;
1013 reload_needed_for_multiple[i] = 0;
1014 reload_secondary_reload[i] = secondary_reload;
1015 reload_secondary_icode[i] = secondary_icode;
1016 reload_secondary_p[i] = 0;
1017
1018 n_reloads++;
0dadecf6
RK
1019
1020#ifdef SECONDARY_MEMORY_NEEDED
1021 /* If a memory location is needed for the copy, make one. */
1022 if (in != 0 && GET_CODE (in) == REG
1023 && REGNO (in) < FIRST_PSEUDO_REGISTER
1024 && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (REGNO (in)),
1025 class, inmode))
1026 get_secondary_mem (in, inmode);
1027
1028 if (out != 0 && GET_CODE (out) == REG
1029 && REGNO (out) < FIRST_PSEUDO_REGISTER
1030 && SECONDARY_MEMORY_NEEDED (class, REGNO_REG_CLASS (REGNO (out)),
1031 outmode))
1032 get_secondary_mem (out, outmode);
1033#endif
eab89b90
RK
1034 }
1035 else
1036 {
1037 /* We are reusing an existing reload,
1038 but we may have additional information for it.
1039 For example, we may now have both IN and OUT
1040 while the old one may have just one of them. */
1041
1042 if (inmode != VOIDmode)
1043 reload_inmode[i] = inmode;
1044 if (outmode != VOIDmode)
1045 reload_outmode[i] = outmode;
1046 if (in != 0)
1047 reload_in[i] = in;
1048 if (out != 0)
1049 reload_out[i] = out;
1050 if (reg_class_subset_p (class, reload_reg_class[i]))
1051 reload_reg_class[i] = class;
1052 reload_optional[i] &= optional;
1053 if (reload_needed_for[i] != needed_for)
1054 reload_needed_for_multiple[i] = 1;
1055 }
1056
1057 /* If the ostensible rtx being reload differs from the rtx found
1058 in the location to substitute, this reload is not safe to combine
1059 because we cannot reliably tell whether it appears in the insn. */
1060
1061 if (in != 0 && in != *inloc)
1062 reload_nocombine[i] = 1;
1063
1064#if 0
1065 /* This was replaced by changes in find_reloads_address_1 and the new
1066 function inc_for_reload, which go with a new meaning of reload_inc. */
1067
1068 /* If this is an IN/OUT reload in an insn that sets the CC,
1069 it must be for an autoincrement. It doesn't work to store
1070 the incremented value after the insn because that would clobber the CC.
1071 So we must do the increment of the value reloaded from,
1072 increment it, store it back, then decrement again. */
1073 if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
1074 {
1075 out = 0;
1076 reload_out[i] = 0;
1077 reload_inc[i] = find_inc_amount (PATTERN (this_insn), in);
1078 /* If we did not find a nonzero amount-to-increment-by,
1079 that contradicts the belief that IN is being incremented
1080 in an address in this insn. */
1081 if (reload_inc[i] == 0)
1082 abort ();
1083 }
1084#endif
1085
1086 /* If we will replace IN and OUT with the reload-reg,
1087 record where they are located so that substitution need
1088 not do a tree walk. */
1089
1090 if (replace_reloads)
1091 {
1092 if (inloc != 0)
1093 {
1094 register struct replacement *r = &replacements[n_replacements++];
1095 r->what = i;
1096 r->subreg_loc = in_subreg_loc;
1097 r->where = inloc;
1098 r->mode = inmode;
1099 }
1100 if (outloc != 0 && outloc != inloc)
1101 {
1102 register struct replacement *r = &replacements[n_replacements++];
1103 r->what = i;
1104 r->where = outloc;
1105 r->subreg_loc = out_subreg_loc;
1106 r->mode = outmode;
1107 }
1108 }
1109
1110 /* If this reload is just being introduced and it has both
1111 an incoming quantity and an outgoing quantity that are
1112 supposed to be made to match, see if either one of the two
1113 can serve as the place to reload into.
1114
1115 If one of them is acceptable, set reload_reg_rtx[i]
1116 to that one. */
1117
1118 if (in != 0 && out != 0 && in != out && reload_reg_rtx[i] == 0)
1119 {
1120 reload_reg_rtx[i] = find_dummy_reload (in, out, inloc, outloc,
1121 reload_reg_class[i], i);
1122
1123 /* If the outgoing register already contains the same value
1124 as the incoming one, we can dispense with loading it.
1125 The easiest way to tell the caller that is to give a phony
1126 value for the incoming operand (same as outgoing one). */
1127 if (reload_reg_rtx[i] == out
1128 && (GET_CODE (in) == REG || CONSTANT_P (in))
1129 && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
1130 static_reload_reg_p, i, inmode))
1131 reload_in[i] = out;
1132 }
1133
1134 /* If this is an input reload and the operand contains a register that
1135 dies in this insn and is used nowhere else, see if it is the right class
1136 to be used for this reload. Use it if so. (This occurs most commonly
1137 in the case of paradoxical SUBREGs and in-out reloads). We cannot do
1138 this if it is also an output reload that mentions the register unless
1139 the output is a SUBREG that clobbers an entire register.
1140
1141 Note that the operand might be one of the spill regs, if it is a
1142 pseudo reg and we are in a block where spilling has not taken place.
1143 But if there is no spilling in this block, that is OK.
1144 An explicitly used hard reg cannot be a spill reg. */
1145
1146 if (reload_reg_rtx[i] == 0 && in != 0)
1147 {
1148 rtx note;
1149 int regno;
1150
1151 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1152 if (REG_NOTE_KIND (note) == REG_DEAD
1153 && GET_CODE (XEXP (note, 0)) == REG
1154 && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER
1155 && reg_mentioned_p (XEXP (note, 0), in)
1156 && ! refers_to_regno_for_reload_p (regno,
1157 (regno
1158 + HARD_REGNO_NREGS (regno,
1159 inmode)),
1160 PATTERN (this_insn), inloc)
1161 && (in != out
1162 || (GET_CODE (in) == SUBREG
1163 && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1))
1164 / UNITS_PER_WORD)
1165 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))
1166 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
1167 /* Make sure the operand fits in the reg that dies. */
1168 && GET_MODE_SIZE (inmode) <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
1169 && HARD_REGNO_MODE_OK (regno, inmode)
1170 && GET_MODE_SIZE (outmode) <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))
1171 && HARD_REGNO_MODE_OK (regno, outmode)
1172 && TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno)
1173 && !fixed_regs[regno])
1174 {
1175 reload_reg_rtx[i] = gen_rtx (REG, inmode, regno);
1176 break;
1177 }
1178 }
1179
1180 if (out)
1181 output_reloadnum = i;
1182
1183 return i;
1184}
1185
1186/* Record an additional place we must replace a value
1187 for which we have already recorded a reload.
1188 RELOADNUM is the value returned by push_reload
1189 when the reload was recorded.
1190 This is used in insn patterns that use match_dup. */
1191
1192static void
1193push_replacement (loc, reloadnum, mode)
1194 rtx *loc;
1195 int reloadnum;
1196 enum machine_mode mode;
1197{
1198 if (replace_reloads)
1199 {
1200 register struct replacement *r = &replacements[n_replacements++];
1201 r->what = reloadnum;
1202 r->where = loc;
1203 r->subreg_loc = 0;
1204 r->mode = mode;
1205 }
1206}
1207\f
1208/* If there is only one output reload, and it is not for an earlyclobber
1209 operand, try to combine it with a (logically unrelated) input reload
1210 to reduce the number of reload registers needed.
1211
1212 This is safe if the input reload does not appear in
1213 the value being output-reloaded, because this implies
1214 it is not needed any more once the original insn completes.
1215
1216 If that doesn't work, see we can use any of the registers that
1217 die in this insn as a reload register. We can if it is of the right
1218 class and does not appear in the value being output-reloaded. */
1219
1220static void
1221combine_reloads ()
1222{
1223 int i;
1224 int output_reload = -1;
1225 rtx note;
1226
1227 /* Find the output reload; return unless there is exactly one
1228 and that one is mandatory. */
1229
1230 for (i = 0; i < n_reloads; i++)
1231 if (reload_out[i] != 0)
1232 {
1233 if (output_reload >= 0)
1234 return;
1235 output_reload = i;
1236 }
1237
1238 if (output_reload < 0 || reload_optional[output_reload])
1239 return;
1240
1241 /* An input-output reload isn't combinable. */
1242
1243 if (reload_in[output_reload] != 0)
1244 return;
1245
6dc42e49 1246 /* If this reload is for an earlyclobber operand, we can't do anything. */
eab89b90
RK
1247
1248 for (i = 0; i < n_earlyclobbers; i++)
1249 if (reload_out[output_reload] == reload_earlyclobbers[i])
1250 return;
1251
1252 /* Check each input reload; can we combine it? */
1253
1254 for (i = 0; i < n_reloads; i++)
1255 if (reload_in[i] && ! reload_optional[i] && ! reload_nocombine[i]
1256 /* Life span of this reload must not extend past main insn. */
1257 && reload_when_needed[i] != RELOAD_FOR_OUTPUT_RELOAD_ADDRESS
e64708b6 1258 && ! reload_needed_for_multiple[i]
eab89b90
RK
1259 && reload_inmode[i] == reload_outmode[output_reload]
1260 && reload_inc[i] == 0
1261 && reload_reg_rtx[i] == 0
1262 && reload_strict_low[i] == 0
1263 /* Don't combine two reloads with different secondary reloads. */
1264 && (reload_secondary_reload[i] == reload_secondary_reload[output_reload]
1265 || reload_secondary_reload[i] == -1
1266 || reload_secondary_reload[output_reload] == -1)
1267 && (reg_class_subset_p (reload_reg_class[i],
1268 reload_reg_class[output_reload])
1269 || reg_class_subset_p (reload_reg_class[output_reload],
1270 reload_reg_class[i]))
1271 && (MATCHES (reload_in[i], reload_out[output_reload])
1272 /* Args reversed because the first arg seems to be
1273 the one that we imagine being modified
1274 while the second is the one that might be affected. */
bfa30b22
RK
1275 || (! reg_overlap_mentioned_for_reload_p (reload_out[output_reload],
1276 reload_in[i])
eab89b90
RK
1277 /* However, if the input is a register that appears inside
1278 the output, then we also can't share.
1279 Imagine (set (mem (reg 69)) (plus (reg 69) ...)).
1280 If the same reload reg is used for both reg 69 and the
1281 result to be stored in memory, then that result
1282 will clobber the address of the memory ref. */
1283 && ! (GET_CODE (reload_in[i]) == REG
bfa30b22
RK
1284 && reg_overlap_mentioned_for_reload_p (reload_in[i],
1285 reload_out[output_reload])))))
eab89b90
RK
1286 {
1287 int j;
1288
1289 /* We have found a reload to combine with! */
1290 reload_out[i] = reload_out[output_reload];
1291 reload_outmode[i] = reload_outmode[output_reload];
1292 /* Mark the old output reload as inoperative. */
1293 reload_out[output_reload] = 0;
1294 /* The combined reload is needed for the entire insn. */
1295 reload_needed_for_multiple[i] = 1;
1296 reload_when_needed[i] = RELOAD_OTHER;
1297 /* If the output reload had a secondary reload, copy it. */
1298 if (reload_secondary_reload[output_reload] != -1)
1299 reload_secondary_reload[i] = reload_secondary_reload[output_reload];
1300 /* If required, minimize the register class. */
1301 if (reg_class_subset_p (reload_reg_class[output_reload],
1302 reload_reg_class[i]))
1303 reload_reg_class[i] = reload_reg_class[output_reload];
1304
1305 /* Transfer all replacements from the old reload to the combined. */
1306 for (j = 0; j < n_replacements; j++)
1307 if (replacements[j].what == output_reload)
1308 replacements[j].what = i;
1309
1310 return;
1311 }
1312
1313 /* If this insn has only one operand that is modified or written (assumed
1314 to be the first), it must be the one corresponding to this reload. It
1315 is safe to use anything that dies in this insn for that output provided
1316 that it does not occur in the output (we already know it isn't an
1317 earlyclobber. If this is an asm insn, give up. */
1318
1319 if (INSN_CODE (this_insn) == -1)
1320 return;
1321
1322 for (i = 1; i < insn_n_operands[INSN_CODE (this_insn)]; i++)
1323 if (insn_operand_constraint[INSN_CODE (this_insn)][i][0] == '='
1324 || insn_operand_constraint[INSN_CODE (this_insn)][i][0] == '+')
1325 return;
1326
1327 /* See if some hard register that dies in this insn and is not used in
1328 the output is the right class. Only works if the register we pick
1329 up can fully hold our output reload. */
1330 for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1))
1331 if (REG_NOTE_KIND (note) == REG_DEAD
1332 && GET_CODE (XEXP (note, 0)) == REG
bfa30b22
RK
1333 && ! reg_overlap_mentioned_for_reload_p (XEXP (note, 0),
1334 reload_out[output_reload])
eab89b90
RK
1335 && REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER
1336 && HARD_REGNO_MODE_OK (REGNO (XEXP (note, 0)), reload_outmode[output_reload])
1337 && TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[output_reload]],
1338 REGNO (XEXP (note, 0)))
1339 && (HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), reload_outmode[output_reload])
1340 <= HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), GET_MODE (XEXP (note, 0))))
1341 && ! fixed_regs[REGNO (XEXP (note, 0))])
1342 {
1343 reload_reg_rtx[output_reload] = gen_rtx (REG,
1344 reload_outmode[output_reload],
1345 REGNO (XEXP (note, 0)));
1346 return;
1347 }
1348}
1349\f
1350/* Try to find a reload register for an in-out reload (expressions IN and OUT).
1351 See if one of IN and OUT is a register that may be used;
1352 this is desirable since a spill-register won't be needed.
1353 If so, return the register rtx that proves acceptable.
1354
1355 INLOC and OUTLOC are locations where IN and OUT appear in the insn.
1356 CLASS is the register class required for the reload.
1357
1358 If FOR_REAL is >= 0, it is the number of the reload,
1359 and in some cases when it can be discovered that OUT doesn't need
1360 to be computed, clear out reload_out[FOR_REAL].
1361
1362 If FOR_REAL is -1, this should not be done, because this call
1363 is just to see if a register can be found, not to find and install it. */
1364
1365static rtx
1366find_dummy_reload (real_in, real_out, inloc, outloc, class, for_real)
1367 rtx real_in, real_out;
1368 rtx *inloc, *outloc;
1369 enum reg_class class;
1370 int for_real;
1371{
1372 rtx in = real_in;
1373 rtx out = real_out;
1374 int in_offset = 0;
1375 int out_offset = 0;
1376 rtx value = 0;
1377
1378 /* If operands exceed a word, we can't use either of them
1379 unless they have the same size. */
1380 if (GET_MODE_SIZE (GET_MODE (real_out)) != GET_MODE_SIZE (GET_MODE (real_in))
1381 && (GET_MODE_SIZE (GET_MODE (real_out)) > UNITS_PER_WORD
1382 || GET_MODE_SIZE (GET_MODE (real_in)) > UNITS_PER_WORD))
1383 return 0;
1384
1385 /* Find the inside of any subregs. */
1386 while (GET_CODE (out) == SUBREG)
1387 {
1388 out_offset = SUBREG_WORD (out);
1389 out = SUBREG_REG (out);
1390 }
1391 while (GET_CODE (in) == SUBREG)
1392 {
1393 in_offset = SUBREG_WORD (in);
1394 in = SUBREG_REG (in);
1395 }
1396
1397 /* Narrow down the reg class, the same way push_reload will;
1398 otherwise we might find a dummy now, but push_reload won't. */
1399 class = PREFERRED_RELOAD_CLASS (in, class);
1400
1401 /* See if OUT will do. */
1402 if (GET_CODE (out) == REG
1403 && REGNO (out) < FIRST_PSEUDO_REGISTER)
1404 {
1405 register int regno = REGNO (out) + out_offset;
1406 int nwords = HARD_REGNO_NREGS (regno, GET_MODE (real_out));
d3b9996a 1407 rtx saved_rtx;
eab89b90
RK
1408
1409 /* When we consider whether the insn uses OUT,
1410 ignore references within IN. They don't prevent us
1411 from copying IN into OUT, because those refs would
1412 move into the insn that reloads IN.
1413
1414 However, we only ignore IN in its role as this reload.
1415 If the insn uses IN elsewhere and it contains OUT,
1416 that counts. We can't be sure it's the "same" operand
1417 so it might not go through this reload. */
d3b9996a 1418 saved_rtx = *inloc;
eab89b90
RK
1419 *inloc = const0_rtx;
1420
1421 if (regno < FIRST_PSEUDO_REGISTER
1422 /* A fixed reg that can overlap other regs better not be used
1423 for reloading in any way. */
1424#ifdef OVERLAPPING_REGNO_P
1425 && ! (fixed_regs[regno] && OVERLAPPING_REGNO_P (regno))
1426#endif
1427 && ! refers_to_regno_for_reload_p (regno, regno + nwords,
1428 PATTERN (this_insn), outloc))
1429 {
1430 int i;
1431 for (i = 0; i < nwords; i++)
1432 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1433 regno + i))
1434 break;
1435
1436 if (i == nwords)
1437 {
1438 if (GET_CODE (real_out) == REG)
1439 value = real_out;
1440 else
1441 value = gen_rtx (REG, GET_MODE (real_out), regno);
1442 }
1443 }
1444
d3b9996a 1445 *inloc = saved_rtx;
eab89b90
RK
1446 }
1447
1448 /* Consider using IN if OUT was not acceptable
1449 or if OUT dies in this insn (like the quotient in a divmod insn).
1450 We can't use IN unless it is dies in this insn,
1451 which means we must know accurately which hard regs are live.
1452 Also, the result can't go in IN if IN is used within OUT. */
1453 if (hard_regs_live_known
1454 && GET_CODE (in) == REG
1455 && REGNO (in) < FIRST_PSEUDO_REGISTER
1456 && (value == 0
1457 || find_reg_note (this_insn, REG_UNUSED, real_out))
1458 && find_reg_note (this_insn, REG_DEAD, real_in)
1459 && !fixed_regs[REGNO (in)]
1460 && HARD_REGNO_MODE_OK (REGNO (in), GET_MODE (out)))
1461 {
1462 register int regno = REGNO (in) + in_offset;
1463 int nwords = HARD_REGNO_NREGS (regno, GET_MODE (real_in));
1464
fb3821f7 1465 if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, NULL_PTR)
eab89b90
RK
1466 && ! hard_reg_set_here_p (regno, regno + nwords,
1467 PATTERN (this_insn)))
1468 {
1469 int i;
1470 for (i = 0; i < nwords; i++)
1471 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1472 regno + i))
1473 break;
1474
1475 if (i == nwords)
1476 {
1477 /* If we were going to use OUT as the reload reg
1478 and changed our mind, it means OUT is a dummy that
1479 dies here. So don't bother copying value to it. */
1480 if (for_real >= 0 && value == real_out)
1481 reload_out[for_real] = 0;
1482 if (GET_CODE (real_in) == REG)
1483 value = real_in;
1484 else
1485 value = gen_rtx (REG, GET_MODE (real_in), regno);
1486 }
1487 }
1488 }
1489
1490 return value;
1491}
1492\f
1493/* This page contains subroutines used mainly for determining
1494 whether the IN or an OUT of a reload can serve as the
1495 reload register. */
1496
1497/* Return 1 if expression X alters a hard reg in the range
1498 from BEG_REGNO (inclusive) to END_REGNO (exclusive),
1499 either explicitly or in the guise of a pseudo-reg allocated to REGNO.
1500 X should be the body of an instruction. */
1501
1502static int
1503hard_reg_set_here_p (beg_regno, end_regno, x)
1504 register int beg_regno, end_regno;
1505 rtx x;
1506{
1507 if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
1508 {
1509 register rtx op0 = SET_DEST (x);
1510 while (GET_CODE (op0) == SUBREG)
1511 op0 = SUBREG_REG (op0);
1512 if (GET_CODE (op0) == REG)
1513 {
1514 register int r = REGNO (op0);
1515 /* See if this reg overlaps range under consideration. */
1516 if (r < end_regno
1517 && r + HARD_REGNO_NREGS (r, GET_MODE (op0)) > beg_regno)
1518 return 1;
1519 }
1520 }
1521 else if (GET_CODE (x) == PARALLEL)
1522 {
1523 register int i = XVECLEN (x, 0) - 1;
1524 for (; i >= 0; i--)
1525 if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i)))
1526 return 1;
1527 }
1528
1529 return 0;
1530}
1531
1532/* Return 1 if ADDR is a valid memory address for mode MODE,
1533 and check that each pseudo reg has the proper kind of
1534 hard reg. */
1535
1536int
1537strict_memory_address_p (mode, addr)
1538 enum machine_mode mode;
1539 register rtx addr;
1540{
1541 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1542 return 0;
1543
1544 win:
1545 return 1;
1546}
1547
1548\f
1549/* Like rtx_equal_p except that it allows a REG and a SUBREG to match
1550 if they are the same hard reg, and has special hacks for
1551 autoincrement and autodecrement.
1552 This is specifically intended for find_reloads to use
1553 in determining whether two operands match.
1554 X is the operand whose number is the lower of the two.
1555
1556 The value is 2 if Y contains a pre-increment that matches
1557 a non-incrementing address in X. */
1558
1559/* ??? To be completely correct, we should arrange to pass
1560 for X the output operand and for Y the input operand.
1561 For now, we assume that the output operand has the lower number
1562 because that is natural in (SET output (... input ...)). */
1563
1564int
1565operands_match_p (x, y)
1566 register rtx x, y;
1567{
1568 register int i;
1569 register RTX_CODE code = GET_CODE (x);
1570 register char *fmt;
1571 int success_2;
1572
1573 if (x == y)
1574 return 1;
1575 if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
1576 && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
1577 && GET_CODE (SUBREG_REG (y)) == REG)))
1578 {
1579 register int j;
1580
1581 if (code == SUBREG)
1582 {
1583 i = REGNO (SUBREG_REG (x));
1584 if (i >= FIRST_PSEUDO_REGISTER)
1585 goto slow;
1586 i += SUBREG_WORD (x);
1587 }
1588 else
1589 i = REGNO (x);
1590
1591 if (GET_CODE (y) == SUBREG)
1592 {
1593 j = REGNO (SUBREG_REG (y));
1594 if (j >= FIRST_PSEUDO_REGISTER)
1595 goto slow;
1596 j += SUBREG_WORD (y);
1597 }
1598 else
1599 j = REGNO (y);
1600
dca52d80
JW
1601 /* On a WORDS_BIG_ENDIAN machine, point to the last register of a
1602 multiple hard register group, so that for example (reg:DI 0) and
1603 (reg:SI 1) will be considered the same register. */
1604 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
1605 && i < FIRST_PSEUDO_REGISTER)
1606 i += (GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD) - 1;
1607 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD
1608 && j < FIRST_PSEUDO_REGISTER)
1609 j += (GET_MODE_SIZE (GET_MODE (y)) / UNITS_PER_WORD) - 1;
1610
eab89b90
RK
1611 return i == j;
1612 }
1613 /* If two operands must match, because they are really a single
1614 operand of an assembler insn, then two postincrements are invalid
1615 because the assembler insn would increment only once.
1616 On the other hand, an postincrement matches ordinary indexing
1617 if the postincrement is the output operand. */
1618 if (code == POST_DEC || code == POST_INC)
1619 return operands_match_p (XEXP (x, 0), y);
1620 /* Two preincrements are invalid
1621 because the assembler insn would increment only once.
1622 On the other hand, an preincrement matches ordinary indexing
1623 if the preincrement is the input operand.
1624 In this case, return 2, since some callers need to do special
1625 things when this happens. */
1626 if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC)
1627 return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
1628
1629 slow:
1630
1631 /* Now we have disposed of all the cases
1632 in which different rtx codes can match. */
1633 if (code != GET_CODE (y))
1634 return 0;
1635 if (code == LABEL_REF)
1636 return XEXP (x, 0) == XEXP (y, 0);
1637 if (code == SYMBOL_REF)
1638 return XSTR (x, 0) == XSTR (y, 0);
1639
1640 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
1641
1642 if (GET_MODE (x) != GET_MODE (y))
1643 return 0;
1644
1645 /* Compare the elements. If any pair of corresponding elements
1646 fail to match, return 0 for the whole things. */
1647
1648 success_2 = 0;
1649 fmt = GET_RTX_FORMAT (code);
1650 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1651 {
1652 int val;
1653 switch (fmt[i])
1654 {
fb3821f7
CH
1655 case 'w':
1656 if (XWINT (x, i) != XWINT (y, i))
1657 return 0;
1658 break;
1659
eab89b90
RK
1660 case 'i':
1661 if (XINT (x, i) != XINT (y, i))
1662 return 0;
1663 break;
1664
1665 case 'e':
1666 val = operands_match_p (XEXP (x, i), XEXP (y, i));
1667 if (val == 0)
1668 return 0;
1669 /* If any subexpression returns 2,
1670 we should return 2 if we are successful. */
1671 if (val == 2)
1672 success_2 = 1;
1673 break;
1674
1675 case '0':
1676 break;
1677
1678 /* It is believed that rtx's at this level will never
1679 contain anything but integers and other rtx's,
1680 except for within LABEL_REFs and SYMBOL_REFs. */
1681 default:
1682 abort ();
1683 }
1684 }
1685 return 1 + success_2;
1686}
1687\f
1688/* Return the number of times character C occurs in string S. */
1689
e4600702 1690int
eab89b90
RK
1691n_occurrences (c, s)
1692 char c;
1693 char *s;
1694{
1695 int n = 0;
1696 while (*s)
1697 n += (*s++ == c);
1698 return n;
1699}
1700\f
1701struct decomposition
1702{
1703 int reg_flag;
1704 int safe;
1705 rtx base;
fb3821f7
CH
1706 HOST_WIDE_INT start;
1707 HOST_WIDE_INT end;
eab89b90
RK
1708};
1709
1710/* Describe the range of registers or memory referenced by X.
1711 If X is a register, set REG_FLAG and put the first register
1712 number into START and the last plus one into END.
1713 If X is a memory reference, put a base address into BASE
1714 and a range of integer offsets into START and END.
1715 If X is pushing on the stack, we can assume it causes no trouble,
1716 so we set the SAFE field. */
1717
1718static struct decomposition
1719decompose (x)
1720 rtx x;
1721{
1722 struct decomposition val;
1723 int all_const = 0;
1724
1725 val.reg_flag = 0;
1726 val.safe = 0;
1727 if (GET_CODE (x) == MEM)
1728 {
1729 rtx base, offset = 0;
1730 rtx addr = XEXP (x, 0);
1731
1732 if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
1733 || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
1734 {
1735 val.base = XEXP (addr, 0);
1736 val.start = - GET_MODE_SIZE (GET_MODE (x));
1737 val.end = GET_MODE_SIZE (GET_MODE (x));
1738 val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
1739 return val;
1740 }
1741
1742 if (GET_CODE (addr) == CONST)
1743 {
1744 addr = XEXP (addr, 0);
1745 all_const = 1;
1746 }
1747 if (GET_CODE (addr) == PLUS)
1748 {
1749 if (CONSTANT_P (XEXP (addr, 0)))
1750 {
1751 base = XEXP (addr, 1);
1752 offset = XEXP (addr, 0);
1753 }
1754 else if (CONSTANT_P (XEXP (addr, 1)))
1755 {
1756 base = XEXP (addr, 0);
1757 offset = XEXP (addr, 1);
1758 }
1759 }
1760
1761 if (offset == 0)
1762 {
1763 base = addr;
1764 offset = const0_rtx;
1765 }
1766 if (GET_CODE (offset) == CONST)
1767 offset = XEXP (offset, 0);
1768 if (GET_CODE (offset) == PLUS)
1769 {
1770 if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
1771 {
1772 base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 1));
1773 offset = XEXP (offset, 0);
1774 }
1775 else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
1776 {
1777 base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 0));
1778 offset = XEXP (offset, 1);
1779 }
1780 else
1781 {
1782 base = gen_rtx (PLUS, GET_MODE (base), base, offset);
1783 offset = const0_rtx;
1784 }
1785 }
1786 else if (GET_CODE (offset) != CONST_INT)
1787 {
1788 base = gen_rtx (PLUS, GET_MODE (base), base, offset);
1789 offset = const0_rtx;
1790 }
1791
1792 if (all_const && GET_CODE (base) == PLUS)
1793 base = gen_rtx (CONST, GET_MODE (base), base);
1794
1795 if (GET_CODE (offset) != CONST_INT)
1796 abort ();
1797
1798 val.start = INTVAL (offset);
1799 val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
1800 val.base = base;
1801 return val;
1802 }
1803 else if (GET_CODE (x) == REG)
1804 {
1805 val.reg_flag = 1;
1806 val.start = true_regnum (x);
1807 if (val.start < 0)
1808 {
1809 /* A pseudo with no hard reg. */
1810 val.start = REGNO (x);
1811 val.end = val.start + 1;
1812 }
1813 else
1814 /* A hard reg. */
1815 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
1816 }
1817 else if (GET_CODE (x) == SUBREG)
1818 {
1819 if (GET_CODE (SUBREG_REG (x)) != REG)
1820 /* This could be more precise, but it's good enough. */
1821 return decompose (SUBREG_REG (x));
1822 val.reg_flag = 1;
1823 val.start = true_regnum (x);
1824 if (val.start < 0)
1825 return decompose (SUBREG_REG (x));
1826 else
1827 /* A hard reg. */
1828 val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
1829 }
1830 else if (CONSTANT_P (x)
1831 /* This hasn't been assigned yet, so it can't conflict yet. */
1832 || GET_CODE (x) == SCRATCH)
1833 val.safe = 1;
1834 else
1835 abort ();
1836 return val;
1837}
1838
1839/* Return 1 if altering Y will not modify the value of X.
1840 Y is also described by YDATA, which should be decompose (Y). */
1841
1842static int
1843immune_p (x, y, ydata)
1844 rtx x, y;
1845 struct decomposition ydata;
1846{
1847 struct decomposition xdata;
1848
1849 if (ydata.reg_flag)
fb3821f7 1850 return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, NULL_PTR);
eab89b90
RK
1851 if (ydata.safe)
1852 return 1;
1853
1854 if (GET_CODE (y) != MEM)
1855 abort ();
1856 /* If Y is memory and X is not, Y can't affect X. */
1857 if (GET_CODE (x) != MEM)
1858 return 1;
1859
1860 xdata = decompose (x);
1861
1862 if (! rtx_equal_p (xdata.base, ydata.base))
1863 {
1864 /* If bases are distinct symbolic constants, there is no overlap. */
1865 if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
1866 return 1;
1867 /* Constants and stack slots never overlap. */
1868 if (CONSTANT_P (xdata.base)
1869 && (ydata.base == frame_pointer_rtx
1870 || ydata.base == stack_pointer_rtx))
1871 return 1;
1872 if (CONSTANT_P (ydata.base)
1873 && (xdata.base == frame_pointer_rtx
1874 || xdata.base == stack_pointer_rtx))
1875 return 1;
1876 /* If either base is variable, we don't know anything. */
1877 return 0;
1878 }
1879
1880
1881 return (xdata.start >= ydata.end || ydata.start >= xdata.end);
1882}
44ace968 1883
f72aed24 1884/* Similar, but calls decompose. */
44ace968
JW
1885
1886int
1887safe_from_earlyclobber (op, clobber)
1888 rtx op, clobber;
1889{
1890 struct decomposition early_data;
1891
1892 early_data = decompose (clobber);
1893 return immune_p (op, clobber, early_data);
1894}
eab89b90
RK
1895\f
1896/* Main entry point of this file: search the body of INSN
1897 for values that need reloading and record them with push_reload.
1898 REPLACE nonzero means record also where the values occur
1899 so that subst_reloads can be used.
1900
1901 IND_LEVELS says how many levels of indirection are supported by this
1902 machine; a value of zero means that a memory reference is not a valid
1903 memory address.
1904
1905 LIVE_KNOWN says we have valid information about which hard
1906 regs are live at each point in the program; this is true when
1907 we are called from global_alloc but false when stupid register
1908 allocation has been done.
1909
1910 RELOAD_REG_P if nonzero is a vector indexed by hard reg number
1911 which is nonnegative if the reg has been commandeered for reloading into.
1912 It is copied into STATIC_RELOAD_REG_P and referenced from there
1913 by various subroutines. */
1914
1915void
1916find_reloads (insn, replace, ind_levels, live_known, reload_reg_p)
1917 rtx insn;
1918 int replace, ind_levels;
1919 int live_known;
1920 short *reload_reg_p;
1921{
1922 rtx non_reloaded_operands[MAX_RECOG_OPERANDS];
1923 int n_non_reloaded_operands = 0;
1924#ifdef REGISTER_CONSTRAINTS
1925
1926 enum reload_modified { RELOAD_NOTHING, RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE };
1927
1928 register int insn_code_number;
1929 register int i;
1930 int noperands;
1931 /* These are the constraints for the insn. We don't change them. */
1932 char *constraints1[MAX_RECOG_OPERANDS];
1933 /* These start out as the constraints for the insn
1934 and they are chewed up as we consider alternatives. */
1935 char *constraints[MAX_RECOG_OPERANDS];
1936 /* These are the preferred classes for an operand, or NO_REGS if it isn't
1937 a register. */
1938 enum reg_class preferred_class[MAX_RECOG_OPERANDS];
1939 char pref_or_nothing[MAX_RECOG_OPERANDS];
1940 /* Nonzero for a MEM operand whose entire address needs a reload. */
1941 int address_reloaded[MAX_RECOG_OPERANDS];
1942 int no_input_reloads = 0, no_output_reloads = 0;
1943 int n_alternatives;
1944 int this_alternative[MAX_RECOG_OPERANDS];
1945 char this_alternative_win[MAX_RECOG_OPERANDS];
1946 char this_alternative_offmemok[MAX_RECOG_OPERANDS];
1947 char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
1948 int this_alternative_matches[MAX_RECOG_OPERANDS];
1949 int swapped;
1950 int goal_alternative[MAX_RECOG_OPERANDS];
1951 int this_alternative_number;
1952 int goal_alternative_number;
1953 int operand_reloadnum[MAX_RECOG_OPERANDS];
1954 int goal_alternative_matches[MAX_RECOG_OPERANDS];
1955 int goal_alternative_matched[MAX_RECOG_OPERANDS];
1956 char goal_alternative_win[MAX_RECOG_OPERANDS];
1957 char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
1958 char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
1959 int goal_alternative_swapped;
1960 enum reload_modified modified[MAX_RECOG_OPERANDS];
1961 int best;
1962 int commutative;
1963 char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
1964 rtx substed_operand[MAX_RECOG_OPERANDS];
1965 rtx body = PATTERN (insn);
1966 rtx set = single_set (insn);
1967 int goal_earlyclobber, this_earlyclobber;
1968 enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
1969
1970 this_insn = insn;
1971 this_insn_is_asm = 0; /* Tentative. */
1972 n_reloads = 0;
1973 n_replacements = 0;
1974 n_memlocs = 0;
1975 n_earlyclobbers = 0;
1976 replace_reloads = replace;
1977 hard_regs_live_known = live_known;
1978 static_reload_reg_p = reload_reg_p;
1979
1980 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads;
1981 neither are insns that SET cc0. Insns that use CC0 are not allowed
1982 to have any input reloads. */
1983 if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == CALL_INSN)
1984 no_output_reloads = 1;
1985
1986#ifdef HAVE_cc0
1987 if (reg_referenced_p (cc0_rtx, PATTERN (insn)))
1988 no_input_reloads = 1;
1989 if (reg_set_p (cc0_rtx, PATTERN (insn)))
1990 no_output_reloads = 1;
1991#endif
1992
0dadecf6
RK
1993#ifdef SECONDARY_MEMORY_NEEDED
1994 /* The eliminated forms of any secondary memory locations are per-insn, so
1995 clear them out here. */
1996
1997 bzero (secondary_memlocs_elim, sizeof secondary_memlocs_elim);
1998#endif
1999
eab89b90
RK
2000 /* Find what kind of insn this is. NOPERANDS gets number of operands.
2001 Make OPERANDS point to a vector of operand values.
2002 Make OPERAND_LOCS point to a vector of pointers to
2003 where the operands were found.
2004 Fill CONSTRAINTS and CONSTRAINTS1 with pointers to the
2005 constraint-strings for this insn.
2006 Return if the insn needs no reload processing. */
2007
2008 switch (GET_CODE (body))
2009 {
2010 case USE:
2011 case CLOBBER:
2012 case ASM_INPUT:
2013 case ADDR_VEC:
2014 case ADDR_DIFF_VEC:
2015 return;
2016
2017 case SET:
2018 /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it
2019 is cheap to move between them. If it is not, there may not be an insn
2020 to do the copy, so we may need a reload. */
2021 if (GET_CODE (SET_DEST (body)) == REG
2022 && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
2023 && GET_CODE (SET_SRC (body)) == REG
2024 && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER
2025 && REGISTER_MOVE_COST (REGNO_REG_CLASS (REGNO (SET_SRC (body))),
2026 REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2)
2027 return;
2028 case PARALLEL:
2029 case ASM_OPERANDS:
2030 noperands = asm_noperands (body);
2031 if (noperands >= 0)
2032 {
2033 /* This insn is an `asm' with operands. */
2034
2035 insn_code_number = -1;
2036 this_insn_is_asm = 1;
2037
2038 /* expand_asm_operands makes sure there aren't too many operands. */
2039 if (noperands > MAX_RECOG_OPERANDS)
2040 abort ();
2041
2042 /* Now get the operand values and constraints out of the insn. */
2043
2044 decode_asm_operands (body, recog_operand, recog_operand_loc,
2045 constraints, operand_mode);
2046 if (noperands > 0)
2047 {
2048 bcopy (constraints, constraints1, noperands * sizeof (char *));
2049 n_alternatives = n_occurrences (',', constraints[0]) + 1;
2050 for (i = 1; i < noperands; i++)
d45cf215 2051 if (n_alternatives != n_occurrences (',', constraints[i]) + 1)
eab89b90
RK
2052 {
2053 error_for_asm (insn, "operand constraints differ in number of alternatives");
2054 /* Avoid further trouble with this insn. */
2055 PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
2056 n_reloads = 0;
2057 return;
2058 }
2059 }
2060 break;
2061 }
2062
2063 default:
2064 /* Ordinary insn: recognize it, get the operands via insn_extract
2065 and get the constraints. */
2066
2067 insn_code_number = recog_memoized (insn);
2068 if (insn_code_number < 0)
2069 fatal_insn_not_found (insn);
2070
2071 noperands = insn_n_operands[insn_code_number];
2072 n_alternatives = insn_n_alternatives[insn_code_number];
2073 /* Just return "no reloads" if insn has no operands with constraints. */
2074 if (n_alternatives == 0)
2075 return;
2076 insn_extract (insn);
2077 for (i = 0; i < noperands; i++)
2078 {
2079 constraints[i] = constraints1[i]
2080 = insn_operand_constraint[insn_code_number][i];
2081 operand_mode[i] = insn_operand_mode[insn_code_number][i];
2082 }
2083 }
2084
2085 if (noperands == 0)
2086 return;
2087
2088 commutative = -1;
2089
2090 /* If we will need to know, later, whether some pair of operands
2091 are the same, we must compare them now and save the result.
2092 Reloading the base and index registers will clobber them
2093 and afterward they will fail to match. */
2094
2095 for (i = 0; i < noperands; i++)
2096 {
2097 register char *p;
2098 register int c;
2099
2100 substed_operand[i] = recog_operand[i];
2101 p = constraints[i];
2102
2103 /* Scan this operand's constraint to see if it should match another. */
2104
2105 while (c = *p++)
2106 if (c == '%')
2107 {
e53c841d 2108 /* The last operand should not be marked commutative. */
eab89b90 2109 if (i == noperands - 1)
e53c841d
RS
2110 {
2111 if (this_insn_is_asm)
2112 warning_for_asm (this_insn,
6bcd21bb 2113 "`%%' constraint used with last operand");
e53c841d
RS
2114 else
2115 abort ();
2116 }
2117 else
2118 commutative = i;
eab89b90
RK
2119 }
2120 else if (c >= '0' && c <= '9')
2121 {
2122 c -= '0';
2123 operands_match[c][i]
2124 = operands_match_p (recog_operand[c], recog_operand[i]);
ea9c5b9e
JW
2125
2126 /* An operand may not match itself. */
2127 if (c == i)
2128 {
2129 if (this_insn_is_asm)
2130 warning_for_asm (this_insn,
2131 "operand %d has constraint %d", i, c);
2132 else
2133 abort ();
2134 }
2135
eab89b90
RK
2136 /* If C can be commuted with C+1, and C might need to match I,
2137 then C+1 might also need to match I. */
2138 if (commutative >= 0)
2139 {
2140 if (c == commutative || c == commutative + 1)
2141 {
2142 int other = c + (c == commutative ? 1 : -1);
2143 operands_match[other][i]
2144 = operands_match_p (recog_operand[other], recog_operand[i]);
2145 }
2146 if (i == commutative || i == commutative + 1)
2147 {
2148 int other = i + (i == commutative ? 1 : -1);
2149 operands_match[c][other]
2150 = operands_match_p (recog_operand[c], recog_operand[other]);
2151 }
2152 /* Note that C is supposed to be less than I.
2153 No need to consider altering both C and I
2154 because in that case we would alter one into the other. */
2155 }
2156 }
2157 }
2158
2159 /* Examine each operand that is a memory reference or memory address
2160 and reload parts of the addresses into index registers.
2161 While we are at it, initialize the array `modified'.
2162 Also here any references to pseudo regs that didn't get hard regs
2163 but are equivalent to constants get replaced in the insn itself
2164 with those constants. Nobody will ever see them again.
2165
2166 Finally, set up the preferred classes of each operand. */
2167
2168 for (i = 0; i < noperands; i++)
2169 {
2170 register RTX_CODE code = GET_CODE (recog_operand[i]);
2171 modified[i] = RELOAD_READ;
2172 address_reloaded[i] = 0;
eab89b90
RK
2173
2174 if (constraints[i][0] == 'p')
2175 {
fb3821f7 2176 find_reloads_address (VOIDmode, NULL_PTR,
eab89b90
RK
2177 recog_operand[i], recog_operand_loc[i],
2178 recog_operand[i], ind_levels);
2179 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2180 }
2181 else if (code == MEM)
2182 {
2183 if (find_reloads_address (GET_MODE (recog_operand[i]),
2184 recog_operand_loc[i],
2185 XEXP (recog_operand[i], 0),
2186 &XEXP (recog_operand[i], 0),
2187 recog_operand[i], ind_levels))
2188 address_reloaded[i] = 1;
2189 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2190 }
2191 else if (code == SUBREG)
2192 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i]
2193 = find_reloads_toplev (recog_operand[i], ind_levels,
2194 set != 0
2195 && &SET_DEST (set) == recog_operand_loc[i]);
2196 else if (code == REG)
2197 {
2198 /* This is equivalent to calling find_reloads_toplev.
2199 The code is duplicated for speed.
2200 When we find a pseudo always equivalent to a constant,
2201 we replace it by the constant. We must be sure, however,
2202 that we don't try to replace it in the insn in which it
2203 is being set. */
2204 register int regno = REGNO (recog_operand[i]);
2205 if (reg_equiv_constant[regno] != 0
2206 && (set == 0 || &SET_DEST (set) != recog_operand_loc[i]))
2207 substed_operand[i] = recog_operand[i]
2208 = reg_equiv_constant[regno];
2209#if 0 /* This might screw code in reload1.c to delete prior output-reload
2210 that feeds this insn. */
2211 if (reg_equiv_mem[regno] != 0)
2212 substed_operand[i] = recog_operand[i]
2213 = reg_equiv_mem[regno];
2214#endif
2215 if (reg_equiv_address[regno] != 0)
2216 {
2217 /* If reg_equiv_address is not a constant address, copy it,
2218 since it may be shared. */
2219 rtx address = reg_equiv_address[regno];
2220
2221 if (rtx_varies_p (address))
2222 address = copy_rtx (address);
2223
2224 /* If this is an output operand, we must output a CLOBBER
2225 after INSN so find_equiv_reg knows REGNO is being written. */
2226 if (constraints[i][0] == '='
2227 || constraints[i][0] == '+')
2228 emit_insn_after (gen_rtx (CLOBBER, VOIDmode, recog_operand[i]),
2229 insn);
2230
2231 *recog_operand_loc[i] = recog_operand[i]
2232 = gen_rtx (MEM, GET_MODE (recog_operand[i]), address);
2233 RTX_UNCHANGING_P (recog_operand[i])
2234 = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
2235 find_reloads_address (GET_MODE (recog_operand[i]),
130659a4 2236 recog_operand_loc[i],
eab89b90
RK
2237 XEXP (recog_operand[i], 0),
2238 &XEXP (recog_operand[i], 0),
2239 recog_operand[i], ind_levels);
2240 substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
2241 }
2242 }
aaf9712e
RS
2243 /* If the operand is still a register (we didn't replace it with an
2244 equivalent), get the preferred class to reload it into. */
2245 code = GET_CODE (recog_operand[i]);
2246 preferred_class[i]
91f9a6ed 2247 = ((code == REG && REGNO (recog_operand[i]) >= FIRST_PSEUDO_REGISTER)
aaf9712e
RS
2248 ? reg_preferred_class (REGNO (recog_operand[i])) : NO_REGS);
2249 pref_or_nothing[i]
91f9a6ed 2250 = (code == REG && REGNO (recog_operand[i]) >= FIRST_PSEUDO_REGISTER
e4600702 2251 && reg_alternate_class (REGNO (recog_operand[i])) == NO_REGS);
eab89b90
RK
2252 }
2253
2254 /* If this is simply a copy from operand 1 to operand 0, merge the
2255 preferred classes for the operands. */
2256 if (set != 0 && noperands >= 2 && recog_operand[0] == SET_DEST (set)
2257 && recog_operand[1] == SET_SRC (set))
2258 {
2259 preferred_class[0] = preferred_class[1]
2260 = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]];
2261 pref_or_nothing[0] |= pref_or_nothing[1];
2262 pref_or_nothing[1] |= pref_or_nothing[0];
2263 }
2264
2265 /* Now see what we need for pseudo-regs that didn't get hard regs
2266 or got the wrong kind of hard reg. For this, we must consider
2267 all the operands together against the register constraints. */
2268
2269 best = MAX_RECOG_OPERANDS + 300;
2270
2271 swapped = 0;
2272 goal_alternative_swapped = 0;
2273 try_swapped:
2274
2275 /* The constraints are made of several alternatives.
2276 Each operand's constraint looks like foo,bar,... with commas
2277 separating the alternatives. The first alternatives for all
2278 operands go together, the second alternatives go together, etc.
2279
2280 First loop over alternatives. */
2281
2282 for (this_alternative_number = 0;
2283 this_alternative_number < n_alternatives;
2284 this_alternative_number++)
2285 {
2286 /* Loop over operands for one constraint alternative. */
2287 /* LOSERS counts those that don't fit this alternative
2288 and would require loading. */
2289 int losers = 0;
2290 /* BAD is set to 1 if it some operand can't fit this alternative
2291 even after reloading. */
2292 int bad = 0;
2293 /* REJECT is a count of how undesirable this alternative says it is
2294 if any reloading is required. If the alternative matches exactly
2295 then REJECT is ignored, but otherwise it gets this much
2296 counted against it in addition to the reloading needed. Each
2297 ? counts three times here since we want the disparaging caused by
2298 a bad register class to only count 1/3 as much. */
2299 int reject = 0;
2300
2301 this_earlyclobber = 0;
2302
2303 for (i = 0; i < noperands; i++)
2304 {
2305 register char *p = constraints[i];
2306 register int win = 0;
2307 /* 0 => this operand can be reloaded somehow for this alternative */
2308 int badop = 1;
2309 /* 0 => this operand can be reloaded if the alternative allows regs. */
2310 int winreg = 0;
2311 int c;
2312 register rtx operand = recog_operand[i];
2313 int offset = 0;
2314 /* Nonzero means this is a MEM that must be reloaded into a reg
2315 regardless of what the constraint says. */
2316 int force_reload = 0;
2317 int offmemok = 0;
2318 int earlyclobber = 0;
2319
2320 /* If the operand is a SUBREG, extract
2321 the REG or MEM (or maybe even a constant) within.
2322 (Constants can occur as a result of reg_equiv_constant.) */
2323
2324 while (GET_CODE (operand) == SUBREG)
2325 {
2326 offset += SUBREG_WORD (operand);
2327 operand = SUBREG_REG (operand);
2328 /* Force reload if this is not a register or if there may may
2329 be a problem accessing the register in the outer mode. */
2330 if (GET_CODE (operand) != REG
46da6b3a
RK
2331#if defined(BYTE_LOADS_ZERO_EXTEND) || defined(BYTE_LOADS_SIGN_EXTEND)
2332 /* ??? The comment below clearly does not match the code.
3934c98b
RS
2333 What the code below actually does is set force_reload
2334 for a paradoxical subreg of a pseudo. rms and kenner
2335 can't see the point of doing this. */
eab89b90
RK
2336 /* Nonparadoxical subreg of a pseudoreg.
2337 Don't to load the full width if on this machine
46da6b3a 2338 we expected the fetch to extend. */
eab89b90
RK
2339 || ((GET_MODE_SIZE (operand_mode[i])
2340 > GET_MODE_SIZE (GET_MODE (operand)))
2341 && REGNO (operand) >= FIRST_PSEUDO_REGISTER)
46da6b3a 2342#endif
eab89b90
RK
2343 /* Subreg of a hard reg which can't handle the subreg's mode
2344 or which would handle that mode in the wrong number of
2345 registers for subregging to work. */
2346 || (REGNO (operand) < FIRST_PSEUDO_REGISTER
2347 && (! HARD_REGNO_MODE_OK (REGNO (operand),
2348 operand_mode[i])
2349 || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2350 && (GET_MODE_SIZE (GET_MODE (operand))
2351 > UNITS_PER_WORD)
2352 && ((GET_MODE_SIZE (GET_MODE (operand))
2353 / UNITS_PER_WORD)
2354 != HARD_REGNO_NREGS (REGNO (operand),
2355 GET_MODE (operand)))))))
2356 force_reload = 1;
2357 }
2358
2359 this_alternative[i] = (int) NO_REGS;
2360 this_alternative_win[i] = 0;
2361 this_alternative_offmemok[i] = 0;
2362 this_alternative_earlyclobber[i] = 0;
2363 this_alternative_matches[i] = -1;
2364
2365 /* An empty constraint or empty alternative
2366 allows anything which matched the pattern. */
2367 if (*p == 0 || *p == ',')
2368 win = 1, badop = 0;
2369
2370 /* Scan this alternative's specs for this operand;
2371 set WIN if the operand fits any letter in this alternative.
2372 Otherwise, clear BADOP if this operand could
2373 fit some letter after reloads,
2374 or set WINREG if this operand could fit after reloads
2375 provided the constraint allows some registers. */
2376
2377 while (*p && (c = *p++) != ',')
2378 switch (c)
2379 {
2380 case '=':
2381 modified[i] = RELOAD_WRITE;
2382 break;
2383
2384 case '+':
2385 modified[i] = RELOAD_READ_WRITE;
2386 break;
2387
2388 case '*':
2389 break;
2390
2391 case '%':
42add480
TW
2392 /* The last operand should not be marked commutative. */
2393 if (i != noperands - 1)
2394 commutative = i;
eab89b90
RK
2395 break;
2396
2397 case '?':
2398 reject += 3;
2399 break;
2400
2401 case '!':
2402 reject = 300;
2403 break;
2404
2405 case '#':
2406 /* Ignore rest of this alternative as far as
2407 reloading is concerned. */
2408 while (*p && *p != ',') p++;
2409 break;
2410
2411 case '0':
2412 case '1':
2413 case '2':
2414 case '3':
2415 case '4':
2416 c -= '0';
2417 this_alternative_matches[i] = c;
2418 /* We are supposed to match a previous operand.
2419 If we do, we win if that one did.
2420 If we do not, count both of the operands as losers.
2421 (This is too conservative, since most of the time
2422 only a single reload insn will be needed to make
2423 the two operands win. As a result, this alternative
2424 may be rejected when it is actually desirable.) */
2425 if ((swapped && (c != commutative || i != commutative + 1))
2426 /* If we are matching as if two operands were swapped,
2427 also pretend that operands_match had been computed
2428 with swapped.
2429 But if I is the second of those and C is the first,
2430 don't exchange them, because operands_match is valid
2431 only on one side of its diagonal. */
2432 ? (operands_match
2433 [(c == commutative || c == commutative + 1)
2434 ? 2*commutative + 1 - c : c]
2435 [(i == commutative || i == commutative + 1)
2436 ? 2*commutative + 1 - i : i])
2437 : operands_match[c][i])
2438 win = this_alternative_win[c];
2439 else
2440 {
2441 /* Operands don't match. */
2442 rtx value;
2443 /* Retroactively mark the operand we had to match
2444 as a loser, if it wasn't already. */
2445 if (this_alternative_win[c])
2446 losers++;
2447 this_alternative_win[c] = 0;
2448 if (this_alternative[c] == (int) NO_REGS)
2449 bad = 1;
2450 /* But count the pair only once in the total badness of
2451 this alternative, if the pair can be a dummy reload. */
2452 value
2453 = find_dummy_reload (recog_operand[i], recog_operand[c],
2454 recog_operand_loc[i], recog_operand_loc[c],
2455 this_alternative[c], -1);
2456
2457 if (value != 0)
2458 losers--;
2459 }
2460 /* This can be fixed with reloads if the operand
2461 we are supposed to match can be fixed with reloads. */
2462 badop = 0;
2463 this_alternative[i] = this_alternative[c];
2464 break;
2465
2466 case 'p':
2467 /* All necessary reloads for an address_operand
2468 were handled in find_reloads_address. */
2469 this_alternative[i] = (int) ALL_REGS;
2470 win = 1;
2471 break;
2472
2473 case 'm':
2474 if (force_reload)
2475 break;
2476 if (GET_CODE (operand) == MEM
2477 || (GET_CODE (operand) == REG
2478 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
2479 && reg_renumber[REGNO (operand)] < 0))
2480 win = 1;
2481 if (CONSTANT_P (operand))
2482 badop = 0;
2483 break;
2484
2485 case '<':
2486 if (GET_CODE (operand) == MEM
2487 && ! address_reloaded[i]
2488 && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
2489 || GET_CODE (XEXP (operand, 0)) == POST_DEC))
2490 win = 1;
2491 break;
2492
2493 case '>':
2494 if (GET_CODE (operand) == MEM
2495 && ! address_reloaded[i]
2496 && (GET_CODE (XEXP (operand, 0)) == PRE_INC
2497 || GET_CODE (XEXP (operand, 0)) == POST_INC))
2498 win = 1;
2499 break;
2500
2501 /* Memory operand whose address is not offsettable. */
2502 case 'V':
2503 if (force_reload)
2504 break;
2505 if (GET_CODE (operand) == MEM
2506 && ! (ind_levels ? offsettable_memref_p (operand)
2507 : offsettable_nonstrict_memref_p (operand))
2508 /* Certain mem addresses will become offsettable
2509 after they themselves are reloaded. This is important;
2510 we don't want our own handling of unoffsettables
2511 to override the handling of reg_equiv_address. */
2512 && !(GET_CODE (XEXP (operand, 0)) == REG
2513 && (ind_levels == 0
2514 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0)))
2515 win = 1;
2516 break;
2517
2518 /* Memory operand whose address is offsettable. */
2519 case 'o':
2520 if (force_reload)
2521 break;
2522 if ((GET_CODE (operand) == MEM
2523 /* If IND_LEVELS, find_reloads_address won't reload a
2524 pseudo that didn't get a hard reg, so we have to
2525 reject that case. */
2526 && (ind_levels ? offsettable_memref_p (operand)
2527 : offsettable_nonstrict_memref_p (operand)))
2528 /* Certain mem addresses will become offsettable
2529 after they themselves are reloaded. This is important;
2530 we don't want our own handling of unoffsettables
2531 to override the handling of reg_equiv_address. */
2532 || (GET_CODE (operand) == MEM
2533 && GET_CODE (XEXP (operand, 0)) == REG
2534 && (ind_levels == 0
2535 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0))
2536 || (GET_CODE (operand) == REG
2537 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
2538 && reg_renumber[REGNO (operand)] < 0))
2539 win = 1;
2540 if (CONSTANT_P (operand) || GET_CODE (operand) == MEM)
2541 badop = 0;
2542 offmemok = 1;
2543 break;
2544
2545 case '&':
2546 /* Output operand that is stored before the need for the
2547 input operands (and their index registers) is over. */
2548 earlyclobber = 1, this_earlyclobber = 1;
2549 break;
2550
2551 case 'E':
2552 /* Match any floating double constant, but only if
2553 we can examine the bits of it reliably. */
2554 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
fb3821f7 2555 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
eab89b90
RK
2556 && GET_MODE (operand) != VOIDmode && ! flag_pretend_float)
2557 break;
2558 if (GET_CODE (operand) == CONST_DOUBLE)
2559 win = 1;
2560 break;
2561
2562 case 'F':
2563 if (GET_CODE (operand) == CONST_DOUBLE)
2564 win = 1;
2565 break;
2566
2567 case 'G':
2568 case 'H':
2569 if (GET_CODE (operand) == CONST_DOUBLE
2570 && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
2571 win = 1;
2572 break;
2573
2574 case 's':
2575 if (GET_CODE (operand) == CONST_INT
2576 || (GET_CODE (operand) == CONST_DOUBLE
2577 && GET_MODE (operand) == VOIDmode))
2578 break;
2579 case 'i':
2580 if (CONSTANT_P (operand)
2581#ifdef LEGITIMATE_PIC_OPERAND_P
2582 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand))
2583#endif
2584 )
2585 win = 1;
2586 break;
2587
2588 case 'n':
2589 if (GET_CODE (operand) == CONST_INT
2590 || (GET_CODE (operand) == CONST_DOUBLE
2591 && GET_MODE (operand) == VOIDmode))
2592 win = 1;
2593 break;
2594
2595 case 'I':
2596 case 'J':
2597 case 'K':
2598 case 'L':
2599 case 'M':
2600 case 'N':
2601 case 'O':
2602 case 'P':
2603 if (GET_CODE (operand) == CONST_INT
2604 && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
2605 win = 1;
2606 break;
2607
2608 case 'X':
2609 win = 1;
2610 break;
2611
2612 case 'g':
2613 if (! force_reload
2614 /* A PLUS is never a valid operand, but reload can make
2615 it from a register when eliminating registers. */
2616 && GET_CODE (operand) != PLUS
2617 /* A SCRATCH is not a valid operand. */
2618 && GET_CODE (operand) != SCRATCH
2619#ifdef LEGITIMATE_PIC_OPERAND_P
2620 && (! CONSTANT_P (operand)
2621 || ! flag_pic
2622 || LEGITIMATE_PIC_OPERAND_P (operand))
2623#endif
2624 && (GENERAL_REGS == ALL_REGS
2625 || GET_CODE (operand) != REG
2626 || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
2627 && reg_renumber[REGNO (operand)] < 0)))
2628 win = 1;
2629 /* Drop through into 'r' case */
2630
2631 case 'r':
2632 this_alternative[i]
2633 = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
2634 goto reg;
2635
2636#ifdef EXTRA_CONSTRAINT
2637 case 'Q':
2638 case 'R':
2639 case 'S':
2640 case 'T':
2641 case 'U':
2642 if (EXTRA_CONSTRAINT (operand, c))
2643 win = 1;
2644 break;
2645#endif
2646
2647 default:
2648 this_alternative[i]
2649 = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
2650
2651 reg:
2652 if (GET_MODE (operand) == BLKmode)
2653 break;
2654 winreg = 1;
2655 if (GET_CODE (operand) == REG
2656 && reg_fits_class_p (operand, this_alternative[i],
2657 offset, GET_MODE (recog_operand[i])))
2658 win = 1;
2659 break;
2660 }
2661
2662 constraints[i] = p;
2663
2664 /* If this operand could be handled with a reg,
2665 and some reg is allowed, then this operand can be handled. */
2666 if (winreg && this_alternative[i] != (int) NO_REGS)
2667 badop = 0;
2668
2669 /* Record which operands fit this alternative. */
2670 this_alternative_earlyclobber[i] = earlyclobber;
2671 if (win && ! force_reload)
2672 this_alternative_win[i] = 1;
2673 else
2674 {
2675 this_alternative_offmemok[i] = offmemok;
2676 losers++;
2677 if (badop)
2678 bad = 1;
2679 /* Alternative loses if it has no regs for a reg operand. */
2680 if (GET_CODE (operand) == REG
2681 && this_alternative[i] == (int) NO_REGS
2682 && this_alternative_matches[i] < 0)
2683 bad = 1;
2684
2685 /* Alternative loses if it requires a type of reload not
2686 permitted for this insn. We can always reload SCRATCH
2687 and objects with a REG_UNUSED note. */
2688 if (GET_CODE (operand) != SCRATCH && modified[i] != RELOAD_READ
2689 && no_output_reloads
2690 && ! find_reg_note (insn, REG_UNUSED, operand))
2691 bad = 1;
2692 else if (modified[i] != RELOAD_WRITE && no_input_reloads)
2693 bad = 1;
2694
2695 /* We prefer to reload pseudos over reloading other things,
2696 since such reloads may be able to be eliminated later.
2697 If we are reloading a SCRATCH, we won't be generating any
2698 insns, just using a register, so it is also preferred.
2699 So bump REJECT in other cases. */
2700 if (GET_CODE (operand) != REG && GET_CODE (operand) != SCRATCH)
2701 reject++;
2702 }
2703
2704 /* If this operand is a pseudo register that didn't get a hard
2705 reg and this alternative accepts some register, see if the
2706 class that we want is a subset of the preferred class for this
2707 register. If not, but it intersects that class, use the
2708 preferred class instead. If it does not intersect the preferred
2709 class, show that usage of this alternative should be discouraged;
2710 it will be discouraged more still if the register is `preferred
2711 or nothing'. We do this because it increases the chance of
2712 reusing our spill register in a later insn and avoiding a pair
2713 of memory stores and loads.
2714
2715 Don't bother with this if this alternative will accept this
2716 operand.
2717
5aa14fee
RS
2718 Don't do this for a multiword operand, if
2719 we have to worry about small classes, because making reg groups
2720 harder to allocate is asking for trouble.
2721
eab89b90
RK
2722 Don't do this if the preferred class has only one register
2723 because we might otherwise exhaust the class. */
2724
2725
2726 if (! win && this_alternative[i] != (int) NO_REGS
5aa14fee
RS
2727#ifdef SMALL_REGISTER_CLASSES
2728 && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD
2729#endif
eab89b90
RK
2730 && reg_class_size[(int) preferred_class[i]] > 1)
2731 {
2732 if (! reg_class_subset_p (this_alternative[i],
2733 preferred_class[i]))
2734 {
2735 /* Since we don't have a way of forming the intersection,
2736 we just do something special if the preferred class
2737 is a subset of the class we have; that's the most
2738 common case anyway. */
2739 if (reg_class_subset_p (preferred_class[i],
2740 this_alternative[i]))
2741 this_alternative[i] = (int) preferred_class[i];
2742 else
2743 reject += (1 + pref_or_nothing[i]);
2744 }
2745 }
2746 }
2747
2748 /* Now see if any output operands that are marked "earlyclobber"
2749 in this alternative conflict with any input operands
2750 or any memory addresses. */
2751
2752 for (i = 0; i < noperands; i++)
2753 if (this_alternative_earlyclobber[i]
2754 && this_alternative_win[i])
2755 {
2756 struct decomposition early_data;
2757 int j;
2758
2759 early_data = decompose (recog_operand[i]);
2760
2761 if (modified[i] == RELOAD_READ)
2762 {
2763 if (this_insn_is_asm)
2764 warning_for_asm (this_insn,
2765 "`&' constraint used with input operand");
2766 else
2767 abort ();
2768 continue;
2769 }
2770
2771 if (this_alternative[i] == NO_REGS)
2772 {
2773 this_alternative_earlyclobber[i] = 0;
2774 if (this_insn_is_asm)
2775 error_for_asm (this_insn,
2776 "`&' constraint used with no register class");
2777 else
2778 abort ();
2779 }
2780
2781 for (j = 0; j < noperands; j++)
2782 /* Is this an input operand or a memory ref? */
2783 if ((GET_CODE (recog_operand[j]) == MEM
2784 || modified[j] != RELOAD_WRITE)
2785 && j != i
2786 /* Ignore things like match_operator operands. */
2787 && *constraints1[j] != 0
2788 /* Don't count an input operand that is constrained to match
2789 the early clobber operand. */
2790 && ! (this_alternative_matches[j] == i
2791 && rtx_equal_p (recog_operand[i], recog_operand[j]))
2792 /* Is it altered by storing the earlyclobber operand? */
2793 && !immune_p (recog_operand[j], recog_operand[i], early_data))
2794 {
2795 /* If the output is in a single-reg class,
2796 it's costly to reload it, so reload the input instead. */
2797 if (reg_class_size[this_alternative[i]] == 1
2798 && (GET_CODE (recog_operand[j]) == REG
2799 || GET_CODE (recog_operand[j]) == SUBREG))
2800 {
2801 losers++;
2802 this_alternative_win[j] = 0;
2803 }
2804 else
2805 break;
2806 }
2807 /* If an earlyclobber operand conflicts with something,
2808 it must be reloaded, so request this and count the cost. */
2809 if (j != noperands)
2810 {
2811 losers++;
2812 this_alternative_win[i] = 0;
2813 for (j = 0; j < noperands; j++)
2814 if (this_alternative_matches[j] == i
2815 && this_alternative_win[j])
2816 {
2817 this_alternative_win[j] = 0;
2818 losers++;
2819 }
2820 }
2821 }
2822
2823 /* If one alternative accepts all the operands, no reload required,
2824 choose that alternative; don't consider the remaining ones. */
2825 if (losers == 0)
2826 {
2827 /* Unswap these so that they are never swapped at `finish'. */
2828 if (commutative >= 0)
2829 {
2830 recog_operand[commutative] = substed_operand[commutative];
2831 recog_operand[commutative + 1]
2832 = substed_operand[commutative + 1];
2833 }
2834 for (i = 0; i < noperands; i++)
2835 {
2836 goal_alternative_win[i] = 1;
2837 goal_alternative[i] = this_alternative[i];
2838 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
2839 goal_alternative_matches[i] = this_alternative_matches[i];
2840 goal_alternative_earlyclobber[i]
2841 = this_alternative_earlyclobber[i];
2842 }
2843 goal_alternative_number = this_alternative_number;
2844 goal_alternative_swapped = swapped;
2845 goal_earlyclobber = this_earlyclobber;
2846 goto finish;
2847 }
2848
2849 /* REJECT, set by the ! and ? constraint characters and when a register
2850 would be reloaded into a non-preferred class, discourages the use of
2851 this alternative for a reload goal. REJECT is incremented by three
2852 for each ? and one for each non-preferred class. */
2853 losers = losers * 3 + reject;
2854
2855 /* If this alternative can be made to work by reloading,
2856 and it needs less reloading than the others checked so far,
2857 record it as the chosen goal for reloading. */
2858 if (! bad && best > losers)
2859 {
2860 for (i = 0; i < noperands; i++)
2861 {
2862 goal_alternative[i] = this_alternative[i];
2863 goal_alternative_win[i] = this_alternative_win[i];
2864 goal_alternative_offmemok[i] = this_alternative_offmemok[i];
2865 goal_alternative_matches[i] = this_alternative_matches[i];
2866 goal_alternative_earlyclobber[i]
2867 = this_alternative_earlyclobber[i];
2868 }
2869 goal_alternative_swapped = swapped;
2870 best = losers;
2871 goal_alternative_number = this_alternative_number;
2872 goal_earlyclobber = this_earlyclobber;
2873 }
2874 }
2875
2876 /* If insn is commutative (it's safe to exchange a certain pair of operands)
2877 then we need to try each alternative twice,
2878 the second time matching those two operands
2879 as if we had exchanged them.
2880 To do this, really exchange them in operands.
2881
2882 If we have just tried the alternatives the second time,
2883 return operands to normal and drop through. */
2884
2885 if (commutative >= 0)
2886 {
2887 swapped = !swapped;
2888 if (swapped)
2889 {
2890 register enum reg_class tclass;
2891 register int t;
2892
2893 recog_operand[commutative] = substed_operand[commutative + 1];
2894 recog_operand[commutative + 1] = substed_operand[commutative];
2895
2896 tclass = preferred_class[commutative];
2897 preferred_class[commutative] = preferred_class[commutative + 1];
2898 preferred_class[commutative + 1] = tclass;
2899
2900 t = pref_or_nothing[commutative];
2901 pref_or_nothing[commutative] = pref_or_nothing[commutative + 1];
2902 pref_or_nothing[commutative + 1] = t;
2903
2904 bcopy (constraints1, constraints, noperands * sizeof (char *));
2905 goto try_swapped;
2906 }
2907 else
2908 {
2909 recog_operand[commutative] = substed_operand[commutative];
2910 recog_operand[commutative + 1] = substed_operand[commutative + 1];
2911 }
2912 }
2913
2914 /* The operands don't meet the constraints.
2915 goal_alternative describes the alternative
2916 that we could reach by reloading the fewest operands.
2917 Reload so as to fit it. */
2918
2919 if (best == MAX_RECOG_OPERANDS + 300)
2920 {
2921 /* No alternative works with reloads?? */
2922 if (insn_code_number >= 0)
2923 abort ();
2924 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
2925 /* Avoid further trouble with this insn. */
2926 PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
2927 n_reloads = 0;
2928 return;
2929 }
2930
2931 /* Jump to `finish' from above if all operands are valid already.
2932 In that case, goal_alternative_win is all 1. */
2933 finish:
2934
2935 /* Right now, for any pair of operands I and J that are required to match,
2936 with I < J,
2937 goal_alternative_matches[J] is I.
2938 Set up goal_alternative_matched as the inverse function:
2939 goal_alternative_matched[I] = J. */
2940
2941 for (i = 0; i < noperands; i++)
2942 goal_alternative_matched[i] = -1;
2943
2944 for (i = 0; i < noperands; i++)
2945 if (! goal_alternative_win[i]
2946 && goal_alternative_matches[i] >= 0)
2947 goal_alternative_matched[goal_alternative_matches[i]] = i;
2948
2949 /* If the best alternative is with operands 1 and 2 swapped,
2950 consider them swapped before reporting the reloads. */
2951
2952 if (goal_alternative_swapped)
2953 {
2954 register rtx tem;
2955
2956 tem = substed_operand[commutative];
2957 substed_operand[commutative] = substed_operand[commutative + 1];
2958 substed_operand[commutative + 1] = tem;
2959 tem = recog_operand[commutative];
2960 recog_operand[commutative] = recog_operand[commutative + 1];
2961 recog_operand[commutative + 1] = tem;
2962 }
2963
2964 /* Perform whatever substitutions on the operands we are supposed
2965 to make due to commutativity or replacement of registers
2966 with equivalent constants or memory slots. */
2967
2968 for (i = 0; i < noperands; i++)
2969 {
2970 *recog_operand_loc[i] = substed_operand[i];
2971 /* While we are looping on operands, initialize this. */
2972 operand_reloadnum[i] = -1;
2973 }
2974
2975 /* Any constants that aren't allowed and can't be reloaded
2976 into registers are here changed into memory references. */
2977 for (i = 0; i < noperands; i++)
2978 if (! goal_alternative_win[i]
2979 && CONSTANT_P (recog_operand[i])
2980 && (PREFERRED_RELOAD_CLASS (recog_operand[i],
2981 (enum reg_class) goal_alternative[i])
2982 == NO_REGS)
2983 && operand_mode[i] != VOIDmode)
2984 {
2985 *recog_operand_loc[i] = recog_operand[i]
2986 = find_reloads_toplev (force_const_mem (operand_mode[i],
2987 recog_operand[i]),
2988 ind_levels, 0);
2989 if (alternative_allows_memconst (constraints1[i],
2990 goal_alternative_number))
2991 goal_alternative_win[i] = 1;
2992 }
2993
2994 /* Now record reloads for all the operands that need them. */
2995 for (i = 0; i < noperands; i++)
2996 if (! goal_alternative_win[i])
2997 {
2998 /* Operands that match previous ones have already been handled. */
2999 if (goal_alternative_matches[i] >= 0)
3000 ;
3001 /* Handle an operand with a nonoffsettable address
3002 appearing where an offsettable address will do
3003 by reloading the address into a base register. */
3004 else if (goal_alternative_matched[i] == -1
3005 && goal_alternative_offmemok[i]
3006 && GET_CODE (recog_operand[i]) == MEM)
3007 {
3008 operand_reloadnum[i]
fb3821f7
CH
3009 = push_reload (XEXP (recog_operand[i], 0), NULL_RTX,
3010 &XEXP (recog_operand[i], 0), NULL_PTR,
eab89b90 3011 BASE_REG_CLASS, GET_MODE (XEXP (recog_operand[i], 0)),
fb3821f7 3012 VOIDmode, 0, 0, NULL_RTX);
eab89b90
RK
3013 reload_inc[operand_reloadnum[i]]
3014 = GET_MODE_SIZE (GET_MODE (recog_operand[i]));
3015 }
3016 else if (goal_alternative_matched[i] == -1)
3017 operand_reloadnum[i] =
3018 push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
3019 modified[i] != RELOAD_READ ? recog_operand[i] : 0,
3020 modified[i] != RELOAD_WRITE ? recog_operand_loc[i] : 0,
3021 modified[i] != RELOAD_READ ? recog_operand_loc[i] : 0,
3022 (enum reg_class) goal_alternative[i],
3023 (modified[i] == RELOAD_WRITE ? VOIDmode : operand_mode[i]),
3024 (modified[i] == RELOAD_READ ? VOIDmode : operand_mode[i]),
3025 (insn_code_number < 0 ? 0
3026 : insn_operand_strict_low[insn_code_number][i]),
fb3821f7 3027 0, NULL_RTX);
eab89b90
RK
3028 /* In a matching pair of operands, one must be input only
3029 and the other must be output only.
3030 Pass the input operand as IN and the other as OUT. */
3031 else if (modified[i] == RELOAD_READ
3032 && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
3033 {
3034 operand_reloadnum[i]
3035 = push_reload (recog_operand[i],
3036 recog_operand[goal_alternative_matched[i]],
3037 recog_operand_loc[i],
3038 recog_operand_loc[goal_alternative_matched[i]],
3039 (enum reg_class) goal_alternative[i],
3040 operand_mode[i],
3041 operand_mode[goal_alternative_matched[i]],
fb3821f7 3042 0, 0, NULL_RTX);
eab89b90
RK
3043 operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
3044 }
3045 else if (modified[i] == RELOAD_WRITE
3046 && modified[goal_alternative_matched[i]] == RELOAD_READ)
3047 {
3048 operand_reloadnum[goal_alternative_matched[i]]
3049 = push_reload (recog_operand[goal_alternative_matched[i]],
3050 recog_operand[i],
3051 recog_operand_loc[goal_alternative_matched[i]],
3052 recog_operand_loc[i],
3053 (enum reg_class) goal_alternative[i],
3054 operand_mode[goal_alternative_matched[i]],
3055 operand_mode[i],
fb3821f7 3056 0, 0, NULL_RTX);
eab89b90
RK
3057 operand_reloadnum[i] = output_reloadnum;
3058 }
3059 else if (insn_code_number >= 0)
3060 abort ();
3061 else
3062 {
3063 error_for_asm (insn, "inconsistent operand constraints in an `asm'");
3064 /* Avoid further trouble with this insn. */
3065 PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
3066 n_reloads = 0;
3067 return;
3068 }
3069 }
3070 else if (goal_alternative_matched[i] < 0
3071 && goal_alternative_matches[i] < 0
3072 && optimize)
3073 {
3074 rtx operand = recog_operand[i];
3075 /* For each non-matching operand that's a pseudo-register
3076 that didn't get a hard register, make an optional reload.
3077 This may get done even if the insn needs no reloads otherwise. */
3078 /* (It would be safe to make an optional reload for a matching pair
3079 of operands, but we don't bother yet.) */
3080 while (GET_CODE (operand) == SUBREG)
3081 operand = XEXP (operand, 0);
3082 if (GET_CODE (operand) == REG
3083 && REGNO (operand) >= FIRST_PSEUDO_REGISTER
3084 && reg_renumber[REGNO (operand)] < 0
3085 && (enum reg_class) goal_alternative[i] != NO_REGS
3086 /* Don't make optional output reloads for jump insns
3087 (such as aobjeq on the vax). */
3088 && (modified[i] == RELOAD_READ
3089 || GET_CODE (insn) != JUMP_INSN))
3090 operand_reloadnum[i]
3091 = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
3092 modified[i] != RELOAD_READ ? recog_operand[i] : 0,
3093 modified[i] != RELOAD_WRITE ? recog_operand_loc[i] : 0,
3094 modified[i] != RELOAD_READ ? recog_operand_loc[i] : 0,
3095 (enum reg_class) goal_alternative[i],
3096 (modified[i] == RELOAD_WRITE ? VOIDmode : operand_mode[i]),
3097 (modified[i] == RELOAD_READ ? VOIDmode : operand_mode[i]),
3098 (insn_code_number < 0 ? 0
3099 : insn_operand_strict_low[insn_code_number][i]),
fb3821f7 3100 1, NULL_RTX);
eab89b90
RK
3101 /* Make an optional reload for an explicit mem ref. */
3102 else if (GET_CODE (operand) == MEM
3103 && (enum reg_class) goal_alternative[i] != NO_REGS
3104 /* Don't make optional output reloads for jump insns
3105 (such as aobjeq on the vax). */
3106 && (modified[i] == RELOAD_READ
3107 || GET_CODE (insn) != JUMP_INSN))
3108 operand_reloadnum[i]
3109 = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
3110 modified[i] != RELOAD_READ ? recog_operand[i] : 0,
3111 modified[i] != RELOAD_WRITE ? recog_operand_loc[i] : 0,
3112 modified[i] != RELOAD_READ ? recog_operand_loc[i] : 0,
3113 (enum reg_class) goal_alternative[i],
3114 (modified[i] == RELOAD_WRITE ? VOIDmode : operand_mode[i]),
3115 (modified[i] == RELOAD_READ ? VOIDmode : operand_mode[i]),
3116 (insn_code_number < 0 ? 0
3117 : insn_operand_strict_low[insn_code_number][i]),
fb3821f7 3118 1, NULL_RTX);
eab89b90
RK
3119 else
3120 non_reloaded_operands[n_non_reloaded_operands++] = recog_operand[i];
3121 }
3122 else if (goal_alternative_matched[i] < 0
3123 && goal_alternative_matches[i] < 0)
3124 non_reloaded_operands[n_non_reloaded_operands++] = recog_operand[i];
3125
3126 /* Record the values of the earlyclobber operands for the caller. */
3127 if (goal_earlyclobber)
3128 for (i = 0; i < noperands; i++)
3129 if (goal_alternative_earlyclobber[i])
3130 reload_earlyclobbers[n_earlyclobbers++] = recog_operand[i];
3131
3132 /* If this insn pattern contains any MATCH_DUP's, make sure that
3133 they will be substituted if the operands they match are substituted.
3134 Also do now any substitutions we already did on the operands.
3135
3136 Don't do this if we aren't making replacements because we might be
3137 propagating things allocated by frame pointer elimination into places
3138 it doesn't expect. */
3139
3140 if (insn_code_number >= 0 && replace)
3141 for (i = insn_n_dups[insn_code_number] - 1; i >= 0; i--)
3142 {
3143 int opno = recog_dup_num[i];
3144 *recog_dup_loc[i] = *recog_operand_loc[opno];
3145 if (operand_reloadnum[opno] >= 0)
3146 push_replacement (recog_dup_loc[i], operand_reloadnum[opno],
3147 insn_operand_mode[insn_code_number][opno]);
3148 }
3149
3150#if 0
3151 /* This loses because reloading of prior insns can invalidate the equivalence
3152 (or at least find_equiv_reg isn't smart enough to find it any more),
3153 causing this insn to need more reload regs than it needed before.
3154 It may be too late to make the reload regs available.
3155 Now this optimization is done safely in choose_reload_regs. */
3156
3157 /* For each reload of a reg into some other class of reg,
3158 search for an existing equivalent reg (same value now) in the right class.
3159 We can use it as long as we don't need to change its contents. */
3160 for (i = 0; i < n_reloads; i++)
3161 if (reload_reg_rtx[i] == 0
3162 && reload_in[i] != 0
3163 && GET_CODE (reload_in[i]) == REG
3164 && reload_out[i] == 0)
3165 {
3166 reload_reg_rtx[i]
3167 = find_equiv_reg (reload_in[i], insn, reload_reg_class[i], -1,
3168 static_reload_reg_p, 0, reload_inmode[i]);
3169 /* Prevent generation of insn to load the value
3170 because the one we found already has the value. */
3171 if (reload_reg_rtx[i])
3172 reload_in[i] = reload_reg_rtx[i];
3173 }
3174#endif
3175
3176#else /* no REGISTER_CONSTRAINTS */
3177 int noperands;
3178 int insn_code_number;
3179 int goal_earlyclobber = 0; /* Always 0, to make combine_reloads happen. */
3180 register int i;
3181 rtx body = PATTERN (insn);
3182
3183 n_reloads = 0;
3184 n_replacements = 0;
3185 n_earlyclobbers = 0;
3186 replace_reloads = replace;
3187 this_insn = insn;
3188
3189 /* Find what kind of insn this is. NOPERANDS gets number of operands.
3190 Store the operand values in RECOG_OPERAND and the locations
3191 of the words in the insn that point to them in RECOG_OPERAND_LOC.
3192 Return if the insn needs no reload processing. */
3193
3194 switch (GET_CODE (body))
3195 {
3196 case USE:
3197 case CLOBBER:
3198 case ASM_INPUT:
3199 case ADDR_VEC:
3200 case ADDR_DIFF_VEC:
3201 return;
3202
3203 case PARALLEL:
3204 case SET:
3205 noperands = asm_noperands (body);
3206 if (noperands >= 0)
3207 {
3208 /* This insn is an `asm' with operands.
3209 First, find out how many operands, and allocate space. */
3210
3211 insn_code_number = -1;
3212 /* ??? This is a bug! ???
3213 Give up and delete this insn if it has too many operands. */
3214 if (noperands > MAX_RECOG_OPERANDS)
3215 abort ();
3216
3217 /* Now get the operand values out of the insn. */
3218
fb3821f7
CH
3219 decode_asm_operands (body, recog_operand, recog_operand_loc,
3220 NULL_PTR, NULL_PTR);
eab89b90
RK
3221 break;
3222 }
3223
3224 default:
3225 /* Ordinary insn: recognize it, allocate space for operands and
3226 constraints, and get them out via insn_extract. */
3227
3228 insn_code_number = recog_memoized (insn);
3229 noperands = insn_n_operands[insn_code_number];
3230 insn_extract (insn);
3231 }
3232
3233 if (noperands == 0)
3234 return;
3235
3236 for (i = 0; i < noperands; i++)
3237 {
3238 register RTX_CODE code = GET_CODE (recog_operand[i]);
3239 int is_set_dest = GET_CODE (body) == SET && (i == 0);
3240
3241 if (insn_code_number >= 0)
3242 if (insn_operand_address_p[insn_code_number][i])
fb3821f7 3243 find_reloads_address (VOIDmode, NULL_PTR,
eab89b90
RK
3244 recog_operand[i], recog_operand_loc[i],
3245 recog_operand[i], ind_levels);
3246 if (code == MEM)
3247 find_reloads_address (GET_MODE (recog_operand[i]),
3248 recog_operand_loc[i],
3249 XEXP (recog_operand[i], 0),
3250 &XEXP (recog_operand[i], 0),
3251 recog_operand[i], ind_levels);
3252 if (code == SUBREG)
3253 recog_operand[i] = *recog_operand_loc[i]
3254 = find_reloads_toplev (recog_operand[i], ind_levels, is_set_dest);
3255 if (code == REG)
3256 {
3257 register int regno = REGNO (recog_operand[i]);
3258 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
3259 recog_operand[i] = *recog_operand_loc[i]
3260 = reg_equiv_constant[regno];
3261#if 0 /* This might screw code in reload1.c to delete prior output-reload
3262 that feeds this insn. */
3263 if (reg_equiv_mem[regno] != 0)
3264 recog_operand[i] = *recog_operand_loc[i]
3265 = reg_equiv_mem[regno];
3266#endif
3267 }
3268 /* All operands are non-reloaded. */
3269 non_reloaded_operands[n_non_reloaded_operands++] = recog_operand[i];
3270 }
3271#endif /* no REGISTER_CONSTRAINTS */
3272
3273 /* Determine which part of the insn each reload is needed for,
3274 based on which operand the reload is needed for.
3275 Reloads of entire operands are classified as RELOAD_OTHER.
3276 So are reloads for which a unique purpose is not known. */
3277
3278 for (i = 0; i < n_reloads; i++)
3279 {
3280 reload_when_needed[i] = RELOAD_OTHER;
3281
3282 if (reload_needed_for[i] != 0 && ! reload_needed_for_multiple[i])
3283 {
3284 int j;
3285 int output_address = 0;
3286 int input_address = 0;
3287 int operand_address = 0;
3288
3289 /* This reload is needed only for the address of something.
3290 Determine whether it is needed for addressing an operand
3291 being reloaded for input, whether it is needed for an
3292 operand being reloaded for output, and whether it is needed
3293 for addressing an operand that won't really be reloaded.
3294
3295 Note that we know that this reload is needed in only one address,
3296 but we have not yet checked for the case where that same address
3297 is used in both input and output reloads.
3298 The following code detects this case. */
3299
3300 for (j = 0; j < n_reloads; j++)
3301 if (reload_needed_for[i] == reload_in[j]
3302 || reload_needed_for[i] == reload_out[j])
3303 {
3304 if (reload_optional[j])
3305 operand_address = 1;
3306 else
3307 {
3308 if (reload_needed_for[i] == reload_in[j])
3309 input_address = 1;
3310 if (reload_needed_for[i] == reload_out[j])
3311 output_address = 1;
3312 }
3313 }
3314 /* Don't ignore memrefs without optional reloads. */
3315 for (j = 0; j < n_non_reloaded_operands; j++)
3316 if (reload_needed_for[i] == non_reloaded_operands[j])
3317 operand_address = 1;
3318
3319 /* If it is needed for only one of those, record which one. */
3320
3321 if (input_address && ! output_address && ! operand_address)
3322 reload_when_needed[i] = RELOAD_FOR_INPUT_RELOAD_ADDRESS;
3323 if (output_address && ! input_address && ! operand_address)
3324 reload_when_needed[i] = RELOAD_FOR_OUTPUT_RELOAD_ADDRESS;
3325 if (operand_address && ! input_address && ! output_address)
3326 reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
3327
3328 /* Indicate those RELOAD_OTHER reloads which, though they have
3329 0 for reload_output, still cannot overlap an output reload. */
3330
3331 if (output_address && reload_when_needed[i] == RELOAD_OTHER)
3332 reload_needed_for_multiple[i] = 1;
c07c29b9
RS
3333
3334 /* If we have earlyclobbers, make sure nothing overlaps them. */
3335 if (n_earlyclobbers > 0)
3336 {
3337 reload_when_needed[i] = RELOAD_OTHER;
3338 reload_needed_for_multiple[i] = 1;
3339 }
eab89b90
RK
3340 }
3341 }
3342
3343 /* Perhaps an output reload can be combined with another
3344 to reduce needs by one. */
3345 if (!goal_earlyclobber)
3346 combine_reloads ();
3347}
3348
3349/* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
3350 accepts a memory operand with constant address. */
3351
3352static int
3353alternative_allows_memconst (constraint, altnum)
3354 char *constraint;
3355 int altnum;
3356{
3357 register int c;
3358 /* Skip alternatives before the one requested. */
3359 while (altnum > 0)
3360 {
3361 while (*constraint++ != ',');
3362 altnum--;
3363 }
3364 /* Scan the requested alternative for 'm' or 'o'.
3365 If one of them is present, this alternative accepts memory constants. */
3366 while ((c = *constraint++) && c != ',' && c != '#')
3367 if (c == 'm' || c == 'o')
3368 return 1;
3369 return 0;
3370}
3371\f
3372/* Scan X for memory references and scan the addresses for reloading.
3373 Also checks for references to "constant" regs that we want to eliminate
3374 and replaces them with the values they stand for.
6dc42e49 3375 We may alter X destructively if it contains a reference to such.
eab89b90
RK
3376 If X is just a constant reg, we return the equivalent value
3377 instead of X.
3378
3379 IND_LEVELS says how many levels of indirect addressing this machine
3380 supports.
3381
3382 IS_SET_DEST is true if X is the destination of a SET, which is not
3383 appropriate to be replaced by a constant. */
3384
3385static rtx
3386find_reloads_toplev (x, ind_levels, is_set_dest)
3387 rtx x;
3388 int ind_levels;
3389 int is_set_dest;
3390{
3391 register RTX_CODE code = GET_CODE (x);
3392
3393 register char *fmt = GET_RTX_FORMAT (code);
3394 register int i;
3395
3396 if (code == REG)
3397 {
3398 /* This code is duplicated for speed in find_reloads. */
3399 register int regno = REGNO (x);
3400 if (reg_equiv_constant[regno] != 0 && !is_set_dest)
3401 x = reg_equiv_constant[regno];
3402#if 0
3403/* This creates (subreg (mem...)) which would cause an unnecessary
3404 reload of the mem. */
3405 else if (reg_equiv_mem[regno] != 0)
3406 x = reg_equiv_mem[regno];
3407#endif
3408 else if (reg_equiv_address[regno] != 0)
3409 {
3410 /* If reg_equiv_address varies, it may be shared, so copy it. */
3411 rtx addr = reg_equiv_address[regno];
3412
3413 if (rtx_varies_p (addr))
3414 addr = copy_rtx (addr);
3415
3416 x = gen_rtx (MEM, GET_MODE (x), addr);
3417 RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
fb3821f7 3418 find_reloads_address (GET_MODE (x), NULL_PTR,
eab89b90
RK
3419 XEXP (x, 0),
3420 &XEXP (x, 0), x, ind_levels);
3421 }
3422 return x;
3423 }
3424 if (code == MEM)
3425 {
3426 rtx tem = x;
3427 find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0),
3428 x, ind_levels);
3429 return tem;
3430 }
3431
3432 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG)
3433 {
3434 /* Check for SUBREG containing a REG that's equivalent to a constant.
3435 If the constant has a known value, truncate it right now.
3436 Similarly if we are extracting a single-word of a multi-word
3437 constant. If the constant is symbolic, allow it to be substituted
3438 normally. push_reload will strip the subreg later. If the
3439 constant is VOIDmode, abort because we will lose the mode of
3440 the register (this should never happen because one of the cases
3441 above should handle it). */
3442
3443 register int regno = REGNO (SUBREG_REG (x));
3444 rtx tem;
3445
3446 if (subreg_lowpart_p (x)
3447 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
3448 && reg_equiv_constant[regno] != 0
3449 && (tem = gen_lowpart_common (GET_MODE (x),
3450 reg_equiv_constant[regno])) != 0)
3451 return tem;
3452
3453 if (GET_MODE_BITSIZE (GET_MODE (x)) == BITS_PER_WORD
3454 && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
3455 && reg_equiv_constant[regno] != 0
3456 && (tem = operand_subword (reg_equiv_constant[regno],
3457 SUBREG_WORD (x), 0,
3458 GET_MODE (SUBREG_REG (x)))) != 0)
3459 return tem;
3460
3461 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
3462 && reg_equiv_constant[regno] != 0
3463 && GET_MODE (reg_equiv_constant[regno]) == VOIDmode)
3464 abort ();
3465
3466 /* If the subreg contains a reg that will be converted to a mem,
3467 convert the subreg to a narrower memref now.
3468 Otherwise, we would get (subreg (mem ...) ...),
3469 which would force reload of the mem.
3470
3471 We also need to do this if there is an equivalent MEM that is
3472 not offsettable. In that case, alter_subreg would produce an
3473 invalid address on big-endian machines.
3474
46da6b3a 3475 For machines that extend byte loads, we must not reload using
eab89b90
RK
3476 a wider mode if we have a paradoxical SUBREG. find_reloads will
3477 force a reload in that case. So we should not do anything here. */
3478
3479 else if (regno >= FIRST_PSEUDO_REGISTER
46da6b3a 3480#if defined(BYTE_LOADS_ZERO_EXTEND) || defined(BYTE_LOADS_SIGN_EXTEND)
eab89b90
RK
3481 && (GET_MODE_SIZE (GET_MODE (x))
3482 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
3483#endif
3484 && (reg_equiv_address[regno] != 0
3485 || (reg_equiv_mem[regno] != 0
f2fbfe92
JL
3486 && (! strict_memory_address_p (GET_MODE (x),
3487 XEXP (reg_equiv_mem[regno], 0))
3488 || ! offsettable_memref_p (reg_equiv_mem[regno])))))
eab89b90
RK
3489 {
3490 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
3491 rtx addr = (reg_equiv_address[regno] ? reg_equiv_address[regno]
3492 : XEXP (reg_equiv_mem[regno], 0));
3493#if BYTES_BIG_ENDIAN
3494 int size;
3495 size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
3496 offset += MIN (size, UNITS_PER_WORD);
3497 size = GET_MODE_SIZE (GET_MODE (x));
3498 offset -= MIN (size, UNITS_PER_WORD);
3499#endif
3500 addr = plus_constant (addr, offset);
3501 x = gen_rtx (MEM, GET_MODE (x), addr);
3502 RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
fb3821f7 3503 find_reloads_address (GET_MODE (x), NULL_PTR,
eab89b90
RK
3504 XEXP (x, 0),
3505 &XEXP (x, 0), x, ind_levels);
3506 }
3507
3508 }
3509
3510 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3511 {
3512 if (fmt[i] == 'e')
3513 XEXP (x, i) = find_reloads_toplev (XEXP (x, i),
3514 ind_levels, is_set_dest);
3515 }
3516 return x;
3517}
3518
3519static rtx
3520make_memloc (ad, regno)
3521 rtx ad;
3522 int regno;
3523{
3524 register int i;
3525 rtx tem = reg_equiv_address[regno];
3526 for (i = 0; i < n_memlocs; i++)
3527 if (rtx_equal_p (tem, XEXP (memlocs[i], 0)))
3528 return memlocs[i];
3529
3530 /* If TEM might contain a pseudo, we must copy it to avoid
3531 modifying it when we do the substitution for the reload. */
3532 if (rtx_varies_p (tem))
3533 tem = copy_rtx (tem);
3534
3535 tem = gen_rtx (MEM, GET_MODE (ad), tem);
3536 RTX_UNCHANGING_P (tem) = RTX_UNCHANGING_P (regno_reg_rtx[regno]);
3537 memlocs[n_memlocs++] = tem;
3538 return tem;
3539}
3540
3541/* Record all reloads needed for handling memory address AD
3542 which appears in *LOC in a memory reference to mode MODE
3543 which itself is found in location *MEMREFLOC.
3544 Note that we take shortcuts assuming that no multi-reg machine mode
3545 occurs as part of an address.
3546
3547 OPERAND is the operand of the insn within which this address appears.
3548
3549 IND_LEVELS says how many levels of indirect addressing this machine
3550 supports.
3551
3552 Value is nonzero if this address is reloaded or replaced as a whole.
3553 This is interesting to the caller if the address is an autoincrement.
3554
3555 Note that there is no verification that the address will be valid after
3556 this routine does its work. Instead, we rely on the fact that the address
3557 was valid when reload started. So we need only undo things that reload
3558 could have broken. These are wrong register types, pseudos not allocated
3559 to a hard register, and frame pointer elimination. */
3560
3561static int
3562find_reloads_address (mode, memrefloc, ad, loc, operand, ind_levels)
3563 enum machine_mode mode;
3564 rtx *memrefloc;
3565 rtx ad;
3566 rtx *loc;
3567 rtx operand;
3568 int ind_levels;
3569{
3570 register int regno;
3571 rtx tem;
3572
3573 /* If the address is a register, see if it is a legitimate address and
3574 reload if not. We first handle the cases where we need not reload
3575 or where we must reload in a non-standard way. */
3576
3577 if (GET_CODE (ad) == REG)
3578 {
3579 regno = REGNO (ad);
3580
3581 if (reg_equiv_constant[regno] != 0
3582 && strict_memory_address_p (mode, reg_equiv_constant[regno]))
3583 {
3584 *loc = ad = reg_equiv_constant[regno];
3585 return 1;
3586 }
3587
3588 else if (reg_equiv_address[regno] != 0)
3589 {
3590 tem = make_memloc (ad, regno);
fb3821f7 3591 find_reloads_address (GET_MODE (tem), NULL_PTR, XEXP (tem, 0),
eab89b90 3592 &XEXP (tem, 0), operand, ind_levels);
fb3821f7 3593 push_reload (tem, NULL_RTX, loc, NULL_PTR, BASE_REG_CLASS,
eab89b90
RK
3594 GET_MODE (ad), VOIDmode, 0, 0,
3595 operand);
3596 return 1;
3597 }
3598
b39555b4
RS
3599 /* We can avoid a reload if the register's equivalent memory expression
3600 is valid as an indirect memory address. */
3601
3602 else if (reg_equiv_mem[regno] != 0 && ind_levels > 0
3603 && strict_memory_address_p (mode, reg_equiv_mem[regno]))
3604 return 0;
eab89b90
RK
3605
3606 /* The only remaining case where we can avoid a reload is if this is a
3607 hard register that is valid as a base register and which is not the
3608 subject of a CLOBBER in this insn. */
3609
3610 else if (regno < FIRST_PSEUDO_REGISTER && REGNO_OK_FOR_BASE_P (regno)
3611 && ! regno_clobbered_p (regno, this_insn))
3612 return 0;
3613
3614 /* If we do not have one of the cases above, we must do the reload. */
fb3821f7 3615 push_reload (ad, NULL_RTX, loc, NULL_PTR, BASE_REG_CLASS,
eab89b90
RK
3616 GET_MODE (ad), VOIDmode, 0, 0, operand);
3617 return 1;
3618 }
3619
3620 if (strict_memory_address_p (mode, ad))
3621 {
3622 /* The address appears valid, so reloads are not needed.
3623 But the address may contain an eliminable register.
3624 This can happen because a machine with indirect addressing
3625 may consider a pseudo register by itself a valid address even when
3626 it has failed to get a hard reg.
3627 So do a tree-walk to find and eliminate all such regs. */
3628
3629 /* But first quickly dispose of a common case. */
3630 if (GET_CODE (ad) == PLUS
3631 && GET_CODE (XEXP (ad, 1)) == CONST_INT
3632 && GET_CODE (XEXP (ad, 0)) == REG
3633 && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
3634 return 0;
3635
3636 subst_reg_equivs_changed = 0;
3637 *loc = subst_reg_equivs (ad);
3638
3639 if (! subst_reg_equivs_changed)
3640 return 0;
3641
3642 /* Check result for validity after substitution. */
3643 if (strict_memory_address_p (mode, ad))
3644 return 0;
3645 }
3646
3647 /* The address is not valid. We have to figure out why. One possibility
3648 is that it is itself a MEM. This can happen when the frame pointer is
3649 being eliminated, a pseudo is not allocated to a hard register, and the
3650 offset between the frame and stack pointers is not its initial value.
d45cf215 3651 In that case the pseudo will have been replaced by a MEM referring to
eab89b90
RK
3652 the stack pointer. */
3653 if (GET_CODE (ad) == MEM)
3654 {
3655 /* First ensure that the address in this MEM is valid. Then, unless
3656 indirect addresses are valid, reload the MEM into a register. */
3657 tem = ad;
3658 find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0),
3659 operand, ind_levels == 0 ? 0 : ind_levels - 1);
d2555454
RS
3660
3661 /* If tem was changed, then we must create a new memory reference to
3662 hold it and store it back into memrefloc. */
3663 if (tem != ad && memrefloc)
ca3e4a2f
RS
3664 {
3665 rtx oldref = *memrefloc;
3666 *memrefloc = copy_rtx (*memrefloc);
3c80f7ed 3667 copy_replacements (tem, XEXP (*memrefloc, 0));
ca3e4a2f
RS
3668 loc = &XEXP (*memrefloc, 0);
3669 if (operand == oldref)
3670 operand = *memrefloc;
3671 }
d2555454 3672
eab89b90
RK
3673 /* Check similar cases as for indirect addresses as above except
3674 that we can allow pseudos and a MEM since they should have been
3675 taken care of above. */
3676
3677 if (ind_levels == 0
3678 || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok)
3679 || GET_CODE (XEXP (tem, 0)) == MEM
3680 || ! (GET_CODE (XEXP (tem, 0)) == REG
3681 || (GET_CODE (XEXP (tem, 0)) == PLUS
3682 && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG
3683 && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT)))
3684 {
3685 /* Must use TEM here, not AD, since it is the one that will
3686 have any subexpressions reloaded, if needed. */
fb3821f7 3687 push_reload (tem, NULL_RTX, loc, NULL_PTR,
eab89b90
RK
3688 BASE_REG_CLASS, GET_MODE (tem), VOIDmode, 0,
3689 0, operand);
3690 return 1;
3691 }
3692 else
3693 return 0;
3694 }
3695
3696 /* If we have address of a stack slot but it's not valid
3697 (displacement is too large), compute the sum in a register. */
3698 else if (GET_CODE (ad) == PLUS
3699 && (XEXP (ad, 0) == frame_pointer_rtx
3700#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3701 || XEXP (ad, 0) == arg_pointer_rtx
3702#endif
3703 || XEXP (ad, 0) == stack_pointer_rtx)
3704 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
3705 {
3706 /* Unshare the MEM rtx so we can safely alter it. */
3707 if (memrefloc)
3708 {
3709 rtx oldref = *memrefloc;
3710 *memrefloc = copy_rtx (*memrefloc);
3711 loc = &XEXP (*memrefloc, 0);
3712 if (operand == oldref)
3713 operand = *memrefloc;
3714 }
3715 if (double_reg_address_ok)
3716 {
3717 /* Unshare the sum as well. */
3718 *loc = ad = copy_rtx (ad);
3719 /* Reload the displacement into an index reg.
3720 We assume the frame pointer or arg pointer is a base reg. */
3721 find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1),
3722 INDEX_REG_CLASS, GET_MODE (ad), operand,
3723 ind_levels);
3724 }
3725 else
3726 {
3727 /* If the sum of two regs is not necessarily valid,
3728 reload the sum into a base reg.
3729 That will at least work. */
3730 find_reloads_address_part (ad, loc, BASE_REG_CLASS, Pmode,
3731 operand, ind_levels);
3732 }
3733 return 1;
3734 }
3735
3736 /* If we have an indexed stack slot, there are three possible reasons why
3737 it might be invalid: The index might need to be reloaded, the address
3738 might have been made by frame pointer elimination and hence have a
3739 constant out of range, or both reasons might apply.
3740
3741 We can easily check for an index needing reload, but even if that is the
3742 case, we might also have an invalid constant. To avoid making the
3743 conservative assumption and requiring two reloads, we see if this address
3744 is valid when not interpreted strictly. If it is, the only problem is
3745 that the index needs a reload and find_reloads_address_1 will take care
3746 of it.
3747
3748 There is still a case when we might generate an extra reload,
3749 however. In certain cases eliminate_regs will return a MEM for a REG
3750 (see the code there for details). In those cases, memory_address_p
3751 applied to our address will return 0 so we will think that our offset
3752 must be too large. But it might indeed be valid and the only problem
3753 is that a MEM is present where a REG should be. This case should be
3754 very rare and there doesn't seem to be any way to avoid it.
3755
3756 If we decide to do something here, it must be that
3757 `double_reg_address_ok' is true and that this address rtl was made by
3758 eliminate_regs. We generate a reload of the fp/sp/ap + constant and
3759 rework the sum so that the reload register will be added to the index.
3760 This is safe because we know the address isn't shared.
3761
3762 We check for fp/ap/sp as both the first and second operand of the
3763 innermost PLUS. */
3764
3765 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
3766 && GET_CODE (XEXP (ad, 0)) == PLUS
3767 && (XEXP (XEXP (ad, 0), 0) == frame_pointer_rtx
3768#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3769 || XEXP (XEXP (ad, 0), 0) == arg_pointer_rtx
3770#endif
3771 || XEXP (XEXP (ad, 0), 0) == stack_pointer_rtx)
3772 && ! memory_address_p (mode, ad))
3773 {
3774 *loc = ad = gen_rtx (PLUS, GET_MODE (ad),
3775 plus_constant (XEXP (XEXP (ad, 0), 0),
3776 INTVAL (XEXP (ad, 1))),
3777 XEXP (XEXP (ad, 0), 1));
3778 find_reloads_address_part (XEXP (ad, 0), &XEXP (ad, 0), BASE_REG_CLASS,
3779 GET_MODE (ad), operand, ind_levels);
3780 find_reloads_address_1 (XEXP (ad, 1), 1, &XEXP (ad, 1), operand, 0);
3781
3782 return 1;
3783 }
3784
3785 else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT
3786 && GET_CODE (XEXP (ad, 0)) == PLUS
3787 && (XEXP (XEXP (ad, 0), 1) == frame_pointer_rtx
3788#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3789 || XEXP (XEXP (ad, 0), 1) == arg_pointer_rtx
3790#endif
3791 || XEXP (XEXP (ad, 0), 1) == stack_pointer_rtx)
3792 && ! memory_address_p (mode, ad))
3793 {
3794 *loc = ad = gen_rtx (PLUS, GET_MODE (ad),
3795 plus_constant (XEXP (XEXP (ad, 0), 1),
3796 INTVAL (XEXP (ad, 1))),
3797 XEXP (XEXP (ad, 0), 0));
3798 find_reloads_address_part (XEXP (ad, 0), &XEXP (ad, 0), BASE_REG_CLASS,
3799 GET_MODE (ad), operand, ind_levels);
3800 find_reloads_address_1 (XEXP (ad, 1), 1, &XEXP (ad, 1), operand, 0);
3801
3802 return 1;
3803 }
3804
3805 /* See if address becomes valid when an eliminable register
3806 in a sum is replaced. */
3807
3808 tem = ad;
3809 if (GET_CODE (ad) == PLUS)
3810 tem = subst_indexed_address (ad);
3811 if (tem != ad && strict_memory_address_p (mode, tem))
3812 {
3813 /* Ok, we win that way. Replace any additional eliminable
3814 registers. */
3815
3816 subst_reg_equivs_changed = 0;
3817 tem = subst_reg_equivs (tem);
3818
3819 /* Make sure that didn't make the address invalid again. */
3820
3821 if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
3822 {
3823 *loc = tem;
3824 return 0;
3825 }
3826 }
3827
3828 /* If constants aren't valid addresses, reload the constant address
3829 into a register. */
191b18e9 3830 if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad))
eab89b90
RK
3831 {
3832 /* If AD is in address in the constant pool, the MEM rtx may be shared.
3833 Unshare it so we can safely alter it. */
3834 if (memrefloc && GET_CODE (ad) == SYMBOL_REF
3835 && CONSTANT_POOL_ADDRESS_P (ad))
3836 {
3837 rtx oldref = *memrefloc;
3838 *memrefloc = copy_rtx (*memrefloc);
3839 loc = &XEXP (*memrefloc, 0);
3840 if (operand == oldref)
3841 operand = *memrefloc;
3842 }
3843
3844 find_reloads_address_part (ad, loc, BASE_REG_CLASS, Pmode, operand,
3845 ind_levels);
3846 return 1;
3847 }
3848
3849 return find_reloads_address_1 (ad, 0, loc, operand, ind_levels);
3850}
3851\f
3852/* Find all pseudo regs appearing in AD
3853 that are eliminable in favor of equivalent values
3854 and do not have hard regs; replace them by their equivalents. */
3855
3856static rtx
3857subst_reg_equivs (ad)
3858 rtx ad;
3859{
3860 register RTX_CODE code = GET_CODE (ad);
3861 register int i;
3862 register char *fmt;
3863
3864 switch (code)
3865 {
3866 case HIGH:
3867 case CONST_INT:
3868 case CONST:
3869 case CONST_DOUBLE:
3870 case SYMBOL_REF:
3871 case LABEL_REF:
3872 case PC:
3873 case CC0:
3874 return ad;
3875
3876 case REG:
3877 {
3878 register int regno = REGNO (ad);
3879
3880 if (reg_equiv_constant[regno] != 0)
3881 {
3882 subst_reg_equivs_changed = 1;
3883 return reg_equiv_constant[regno];
3884 }
3885 }
3886 return ad;
3887
3888 case PLUS:
3889 /* Quickly dispose of a common case. */
3890 if (XEXP (ad, 0) == frame_pointer_rtx
3891 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
3892 return ad;
3893 }
3894
3895 fmt = GET_RTX_FORMAT (code);
3896 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3897 if (fmt[i] == 'e')
3898 XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i));
3899 return ad;
3900}
3901\f
3902/* Compute the sum of X and Y, making canonicalizations assumed in an
3903 address, namely: sum constant integers, surround the sum of two
3904 constants with a CONST, put the constant as the second operand, and
3905 group the constant on the outermost sum.
3906
3907 This routine assumes both inputs are already in canonical form. */
3908
3909rtx
3910form_sum (x, y)
3911 rtx x, y;
3912{
3913 rtx tem;
3914
3915 if (GET_CODE (x) == CONST_INT)
3916 return plus_constant (y, INTVAL (x));
3917 else if (GET_CODE (y) == CONST_INT)
3918 return plus_constant (x, INTVAL (y));
3919 else if (CONSTANT_P (x))
3920 tem = x, x = y, y = tem;
3921
3922 if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
3923 return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
3924
3925 /* Note that if the operands of Y are specified in the opposite
3926 order in the recursive calls below, infinite recursion will occur. */
3927 if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
3928 return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
3929
3930 /* If both constant, encapsulate sum. Otherwise, just form sum. A
3931 constant will have been placed second. */
3932 if (CONSTANT_P (x) && CONSTANT_P (y))
3933 {
3934 if (GET_CODE (x) == CONST)
3935 x = XEXP (x, 0);
3936 if (GET_CODE (y) == CONST)
3937 y = XEXP (y, 0);
3938
3939 return gen_rtx (CONST, VOIDmode, gen_rtx (PLUS, Pmode, x, y));
3940 }
3941
3942 return gen_rtx (PLUS, Pmode, x, y);
3943}
3944\f
3945/* If ADDR is a sum containing a pseudo register that should be
3946 replaced with a constant (from reg_equiv_constant),
3947 return the result of doing so, and also apply the associative
3948 law so that the result is more likely to be a valid address.
3949 (But it is not guaranteed to be one.)
3950
3951 Note that at most one register is replaced, even if more are
3952 replaceable. Also, we try to put the result into a canonical form
3953 so it is more likely to be a valid address.
3954
3955 In all other cases, return ADDR. */
3956
3957static rtx
3958subst_indexed_address (addr)
3959 rtx addr;
3960{
3961 rtx op0 = 0, op1 = 0, op2 = 0;
3962 rtx tem;
3963 int regno;
3964
3965 if (GET_CODE (addr) == PLUS)
3966 {
3967 /* Try to find a register to replace. */
3968 op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0;
3969 if (GET_CODE (op0) == REG
3970 && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER
3971 && reg_renumber[regno] < 0
3972 && reg_equiv_constant[regno] != 0)
3973 op0 = reg_equiv_constant[regno];
3974 else if (GET_CODE (op1) == REG
3975 && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER
3976 && reg_renumber[regno] < 0
3977 && reg_equiv_constant[regno] != 0)
3978 op1 = reg_equiv_constant[regno];
3979 else if (GET_CODE (op0) == PLUS
3980 && (tem = subst_indexed_address (op0)) != op0)
3981 op0 = tem;
3982 else if (GET_CODE (op1) == PLUS
3983 && (tem = subst_indexed_address (op1)) != op1)
3984 op1 = tem;
3985 else
3986 return addr;
3987
3988 /* Pick out up to three things to add. */
3989 if (GET_CODE (op1) == PLUS)
3990 op2 = XEXP (op1, 1), op1 = XEXP (op1, 0);
3991 else if (GET_CODE (op0) == PLUS)
3992 op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
3993
3994 /* Compute the sum. */
3995 if (op2 != 0)
3996 op1 = form_sum (op1, op2);
3997 if (op1 != 0)
3998 op0 = form_sum (op0, op1);
3999
4000 return op0;
4001 }
4002 return addr;
4003}
4004\f
4005/* Record the pseudo registers we must reload into hard registers
4006 in a subexpression of a would-be memory address, X.
4007 (This function is not called if the address we find is strictly valid.)
4008 CONTEXT = 1 means we are considering regs as index regs,
4009 = 0 means we are considering them as base regs.
4010
4011 OPERAND is the operand of the insn within which this address appears.
4012
4013 IND_LEVELS says how many levels of indirect addressing are
4014 supported at this point in the address.
4015
4016 We return nonzero if X, as a whole, is reloaded or replaced. */
4017
4018/* Note that we take shortcuts assuming that no multi-reg machine mode
4019 occurs as part of an address.
4020 Also, this is not fully machine-customizable; it works for machines
4021 such as vaxes and 68000's and 32000's, but other possible machines
4022 could have addressing modes that this does not handle right. */
4023
4024static int
4025find_reloads_address_1 (x, context, loc, operand, ind_levels)
4026 rtx x;
4027 int context;
4028 rtx *loc;
4029 rtx operand;
4030 int ind_levels;
4031{
4032 register RTX_CODE code = GET_CODE (x);
4033
4034 if (code == PLUS)
4035 {
4036 register rtx op0 = XEXP (x, 0);
4037 register rtx op1 = XEXP (x, 1);
4038 register RTX_CODE code0 = GET_CODE (op0);
4039 register RTX_CODE code1 = GET_CODE (op1);
4040 if (code0 == MULT || code0 == SIGN_EXTEND || code1 == MEM)
4041 {
4042 find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand, ind_levels);
4043 find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand, ind_levels);
4044 }
4045 else if (code1 == MULT || code1 == SIGN_EXTEND || code0 == MEM)
4046 {
4047 find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand, ind_levels);
4048 find_reloads_address_1 (op1, 1, &XEXP (x, 1), operand, ind_levels);
4049 }
4050 else if (code0 == CONST_INT || code0 == CONST
4051 || code0 == SYMBOL_REF || code0 == LABEL_REF)
4052 {
4053 find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand, ind_levels);
4054 }
4055 else if (code1 == CONST_INT || code1 == CONST
4056 || code1 == SYMBOL_REF || code1 == LABEL_REF)
4057 {
4058 find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand, ind_levels);
4059 }
4060 else if (code0 == REG && code1 == REG)
4061 {
4062 if (REG_OK_FOR_INDEX_P (op0)
4063 && REG_OK_FOR_BASE_P (op1))
4064 return 0;
4065 else if (REG_OK_FOR_INDEX_P (op1)
4066 && REG_OK_FOR_BASE_P (op0))
4067 return 0;
4068 else if (REG_OK_FOR_BASE_P (op1))
4069 find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand, ind_levels);
4070 else if (REG_OK_FOR_BASE_P (op0))
4071 find_reloads_address_1 (op1, 1, &XEXP (x, 1), operand, ind_levels);
4072 else if (REG_OK_FOR_INDEX_P (op1))
4073 find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand, ind_levels);
4074 else if (REG_OK_FOR_INDEX_P (op0))
4075 find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand, ind_levels);
4076 else
4077 {
4078 find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand,
4079 ind_levels);
4080 find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand,
4081 ind_levels);
4082 }
4083 }
4084 else if (code0 == REG)
4085 {
4086 find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand, ind_levels);
4087 find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand, ind_levels);
4088 }
4089 else if (code1 == REG)
4090 {
4091 find_reloads_address_1 (op1, 1, &XEXP (x, 1), operand, ind_levels);
4092 find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand, ind_levels);
4093 }
4094 }
4095 else if (code == POST_INC || code == POST_DEC
4096 || code == PRE_INC || code == PRE_DEC)
4097 {
4098 if (GET_CODE (XEXP (x, 0)) == REG)
4099 {
4100 register int regno = REGNO (XEXP (x, 0));
4101 int value = 0;
4102 rtx x_orig = x;
4103
4104 /* A register that is incremented cannot be constant! */
4105 if (regno >= FIRST_PSEUDO_REGISTER
4106 && reg_equiv_constant[regno] != 0)
4107 abort ();
4108
4109 /* Handle a register that is equivalent to a memory location
4110 which cannot be addressed directly. */
4111 if (reg_equiv_address[regno] != 0)
4112 {
4113 rtx tem = make_memloc (XEXP (x, 0), regno);
4114 /* First reload the memory location's address. */
4115 find_reloads_address (GET_MODE (tem), 0, XEXP (tem, 0),
4116 &XEXP (tem, 0), operand, ind_levels);
4117 /* Put this inside a new increment-expression. */
4118 x = gen_rtx (GET_CODE (x), GET_MODE (x), tem);
4119 /* Proceed to reload that, as if it contained a register. */
4120 }
4121
4122 /* If we have a hard register that is ok as an index,
4123 don't make a reload. If an autoincrement of a nice register
4124 isn't "valid", it must be that no autoincrement is "valid".
4125 If that is true and something made an autoincrement anyway,
4126 this must be a special context where one is allowed.
4127 (For example, a "push" instruction.)
4128 We can't improve this address, so leave it alone. */
4129
4130 /* Otherwise, reload the autoincrement into a suitable hard reg
4131 and record how much to increment by. */
4132
4133 if (reg_renumber[regno] >= 0)
4134 regno = reg_renumber[regno];
4135 if ((regno >= FIRST_PSEUDO_REGISTER
4136 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
4137 : REGNO_OK_FOR_BASE_P (regno))))
4138 {
4139 register rtx link;
4140
4141 int reloadnum
fb3821f7 4142 = push_reload (x, NULL_RTX, loc, NULL_PTR,
eab89b90
RK
4143 context ? INDEX_REG_CLASS : BASE_REG_CLASS,
4144 GET_MODE (x), GET_MODE (x), VOIDmode, 0, operand);
4145 reload_inc[reloadnum]
4146 = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0));
4147
4148 value = 1;
4149
4150#ifdef AUTO_INC_DEC
4151 /* Update the REG_INC notes. */
4152
4153 for (link = REG_NOTES (this_insn);
4154 link; link = XEXP (link, 1))
4155 if (REG_NOTE_KIND (link) == REG_INC
4156 && REGNO (XEXP (link, 0)) == REGNO (XEXP (x_orig, 0)))
4157 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
4158#endif
4159 }
4160 return value;
4161 }
4162 else if (GET_CODE (XEXP (x, 0)) == MEM)
4163 {
4164 /* This is probably the result of a substitution, by eliminate_regs,
4165 of an equivalent address for a pseudo that was not allocated to a
4166 hard register. Verify that the specified address is valid and
4167 reload it into a register. */
4168 rtx tem = XEXP (x, 0);
4169 register rtx link;
4170 int reloadnum;
4171
4172 /* Since we know we are going to reload this item, don't decrement
4173 for the indirection level.
4174
4175 Note that this is actually conservative: it would be slightly
4176 more efficient to use the value of SPILL_INDIRECT_LEVELS from
4177 reload1.c here. */
4178 find_reloads_address (GET_MODE (x), &XEXP (x, 0),
4179 XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0),
4180 operand, ind_levels);
4181
fb3821f7 4182 reloadnum = push_reload (x, NULL_RTX, loc, NULL_PTR,
eab89b90
RK
4183 context ? INDEX_REG_CLASS : BASE_REG_CLASS,
4184 GET_MODE (x), VOIDmode, 0, 0, operand);
4185 reload_inc[reloadnum]
4186 = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
4187
4188 link = FIND_REG_INC_NOTE (this_insn, tem);
4189 if (link != 0)
4190 push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
4191
4192 return 1;
4193 }
4194 }
4195 else if (code == MEM)
4196 {
4197 /* This is probably the result of a substitution, by eliminate_regs,
4198 of an equivalent address for a pseudo that was not allocated to a
4199 hard register. Verify that the specified address is valid and reload
4200 it into a register.
4201
4202 Since we know we are going to reload this item, don't decrement
4203 for the indirection level.
4204
4205 Note that this is actually conservative: it would be slightly more
4206 efficient to use the value of SPILL_INDIRECT_LEVELS from
4207 reload1.c here. */
4208
4209 find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0),
4210 operand, ind_levels);
4211
fb3821f7 4212 push_reload (*loc, NULL_RTX, loc, NULL_PTR,
eab89b90
RK
4213 context ? INDEX_REG_CLASS : BASE_REG_CLASS,
4214 GET_MODE (x), VOIDmode, 0, 0, operand);
4215 return 1;
4216 }
4217 else if (code == REG)
4218 {
4219 register int regno = REGNO (x);
4220
4221 if (reg_equiv_constant[regno] != 0)
4222 {
58c8c593
RK
4223 find_reloads_address_part (reg_equiv_constant[regno], loc,
4224 (context ? INDEX_REG_CLASS
4225 : BASE_REG_CLASS),
4226 GET_MODE (x), operand, ind_levels);
eab89b90
RK
4227 return 1;
4228 }
4229
4230#if 0 /* This might screw code in reload1.c to delete prior output-reload
4231 that feeds this insn. */
4232 if (reg_equiv_mem[regno] != 0)
4233 {
fb3821f7 4234 push_reload (reg_equiv_mem[regno], NULL_RTX, loc, NULL_PTR,
eab89b90
RK
4235 context ? INDEX_REG_CLASS : BASE_REG_CLASS,
4236 GET_MODE (x), VOIDmode, 0, 0, operand);
4237 return 1;
4238 }
4239#endif
4240 if (reg_equiv_address[regno] != 0)
4241 {
4242 x = make_memloc (x, regno);
4243 find_reloads_address (GET_MODE (x), 0, XEXP (x, 0), &XEXP (x, 0),
4244 operand, ind_levels);
4245 }
4246
4247 if (reg_renumber[regno] >= 0)
4248 regno = reg_renumber[regno];
4249 if ((regno >= FIRST_PSEUDO_REGISTER
4250 || !(context ? REGNO_OK_FOR_INDEX_P (regno)
4251 : REGNO_OK_FOR_BASE_P (regno))))
4252 {
fb3821f7 4253 push_reload (x, NULL_RTX, loc, NULL_PTR,
eab89b90
RK
4254 context ? INDEX_REG_CLASS : BASE_REG_CLASS,
4255 GET_MODE (x), VOIDmode, 0, 0, operand);
4256 return 1;
4257 }
4258
4259 /* If a register appearing in an address is the subject of a CLOBBER
4260 in this insn, reload it into some other register to be safe.
4261 The CLOBBER is supposed to make the register unavailable
4262 from before this insn to after it. */
4263 if (regno_clobbered_p (regno, this_insn))
4264 {
fb3821f7 4265 push_reload (x, NULL_RTX, loc, NULL_PTR,
eab89b90
RK
4266 context ? INDEX_REG_CLASS : BASE_REG_CLASS,
4267 GET_MODE (x), VOIDmode, 0, 0, operand);
4268 return 1;
4269 }
4270 }
4271 else
4272 {
4273 register char *fmt = GET_RTX_FORMAT (code);
4274 register int i;
4275 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4276 {
4277 if (fmt[i] == 'e')
4278 find_reloads_address_1 (XEXP (x, i), context, &XEXP (x, i),
4279 operand, ind_levels);
4280 }
4281 }
4282
4283 return 0;
4284}
4285\f
4286/* X, which is found at *LOC, is a part of an address that needs to be
4287 reloaded into a register of class CLASS. If X is a constant, or if
4288 X is a PLUS that contains a constant, check that the constant is a
4289 legitimate operand and that we are supposed to be able to load
4290 it into the register.
4291
4292 If not, force the constant into memory and reload the MEM instead.
4293
4294 MODE is the mode to use, in case X is an integer constant.
4295
4296 NEEDED_FOR says which operand this reload is needed for.
4297
4298 IND_LEVELS says how many levels of indirect addressing this machine
4299 supports. */
4300
4301static void
4302find_reloads_address_part (x, loc, class, mode, needed_for, ind_levels)
4303 rtx x;
4304 rtx *loc;
4305 enum reg_class class;
4306 enum machine_mode mode;
4307 rtx needed_for;
4308 int ind_levels;
4309{
4310 if (CONSTANT_P (x)
4311 && (! LEGITIMATE_CONSTANT_P (x)
4312 || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
4313 {
4314 rtx tem = x = force_const_mem (mode, x);
4315 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
4316 needed_for, ind_levels);
4317 }
4318
4319 else if (GET_CODE (x) == PLUS
4320 && CONSTANT_P (XEXP (x, 1))
4321 && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
4322 || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
4323 {
4324 rtx tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
4325
4326 x = gen_rtx (PLUS, GET_MODE (x), XEXP (x, 0), tem);
4327 find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
4328 needed_for, ind_levels);
4329 }
4330
fb3821f7
CH
4331 push_reload (x, NULL_RTX, loc, NULL_PTR, class,
4332 mode, VOIDmode, 0, 0, needed_for);
eab89b90
RK
4333}
4334\f
4335/* Substitute into X the registers into which we have reloaded
4336 the things that need reloading. The array `replacements'
4337 says contains the locations of all pointers that must be changed
4338 and says what to replace them with.
4339
4340 Return the rtx that X translates into; usually X, but modified. */
4341
4342void
4343subst_reloads ()
4344{
4345 register int i;
4346
4347 for (i = 0; i < n_replacements; i++)
4348 {
4349 register struct replacement *r = &replacements[i];
4350 register rtx reloadreg = reload_reg_rtx[r->what];
4351 if (reloadreg)
4352 {
4353 /* Encapsulate RELOADREG so its machine mode matches what
4354 used to be there. */
4355 if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
dca52d80 4356 reloadreg = gen_lowpart_common (r->mode, reloadreg);
eab89b90
RK
4357
4358 /* If we are putting this into a SUBREG and RELOADREG is a
4359 SUBREG, we would be making nested SUBREGs, so we have to fix
4360 this up. Note that r->where == &SUBREG_REG (*r->subreg_loc). */
4361
4362 if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG)
4363 {
4364 if (GET_MODE (*r->subreg_loc)
4365 == GET_MODE (SUBREG_REG (reloadreg)))
4366 *r->subreg_loc = SUBREG_REG (reloadreg);
4367 else
4368 {
4369 *r->where = SUBREG_REG (reloadreg);
4370 SUBREG_WORD (*r->subreg_loc) += SUBREG_WORD (reloadreg);
4371 }
4372 }
4373 else
4374 *r->where = reloadreg;
4375 }
4376 /* If reload got no reg and isn't optional, something's wrong. */
4377 else if (! reload_optional[r->what])
4378 abort ();
4379 }
4380}
4381\f
4382/* Make a copy of any replacements being done into X and move those copies
4383 to locations in Y, a copy of X. We only look at the highest level of
4384 the RTL. */
4385
4386void
4387copy_replacements (x, y)
4388 rtx x;
4389 rtx y;
4390{
4391 int i, j;
4392 enum rtx_code code = GET_CODE (x);
4393 char *fmt = GET_RTX_FORMAT (code);
4394 struct replacement *r;
4395
4396 /* We can't support X being a SUBREG because we might then need to know its
4397 location if something inside it was replaced. */
4398 if (code == SUBREG)
4399 abort ();
4400
4401 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4402 if (fmt[i] == 'e')
4403 for (j = 0; j < n_replacements; j++)
4404 {
4405 if (replacements[j].subreg_loc == &XEXP (x, i))
4406 {
4407 r = &replacements[n_replacements++];
4408 r->where = replacements[j].where;
4409 r->subreg_loc = &XEXP (y, i);
4410 r->what = replacements[j].what;
4411 r->mode = replacements[j].mode;
4412 }
4413 else if (replacements[j].where == &XEXP (x, i))
4414 {
4415 r = &replacements[n_replacements++];
4416 r->where = &XEXP (y, i);
4417 r->subreg_loc = 0;
4418 r->what = replacements[j].what;
4419 r->mode = replacements[j].mode;
4420 }
4421 }
4422}
4423\f
af929c62
RK
4424/* If LOC was scheduled to be replaced by something, return the replacement.
4425 Otherwise, return *LOC. */
4426
4427rtx
4428find_replacement (loc)
4429 rtx *loc;
4430{
4431 struct replacement *r;
4432
4433 for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
4434 {
4435 rtx reloadreg = reload_reg_rtx[r->what];
4436
4437 if (reloadreg && r->where == loc)
4438 {
4439 if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
4440 reloadreg = gen_rtx (REG, r->mode, REGNO (reloadreg));
4441
4442 return reloadreg;
4443 }
4444 else if (reloadreg && r->subreg_loc == loc)
4445 {
4446 /* RELOADREG must be either a REG or a SUBREG.
4447
4448 ??? Is it actually still ever a SUBREG? If so, why? */
4449
4450 if (GET_CODE (reloadreg) == REG)
4451 return gen_rtx (REG, GET_MODE (*loc),
4452 REGNO (reloadreg) + SUBREG_WORD (*loc));
4453 else if (GET_MODE (reloadreg) == GET_MODE (*loc))
4454 return reloadreg;
4455 else
4456 return gen_rtx (SUBREG, GET_MODE (*loc), SUBREG_REG (reloadreg),
4457 SUBREG_WORD (reloadreg) + SUBREG_WORD (*loc));
4458 }
4459 }
4460
4461 return *loc;
4462}
4463\f
eab89b90
RK
4464/* Return nonzero if register in range [REGNO, ENDREGNO)
4465 appears either explicitly or implicitly in X
4466 other than being stored into.
4467
4468 References contained within the substructure at LOC do not count.
4469 LOC may be zero, meaning don't ignore anything.
4470
4471 This is similar to refers_to_regno_p in rtlanal.c except that we
4472 look at equivalences for pseudos that didn't get hard registers. */
4473
4474int
4475refers_to_regno_for_reload_p (regno, endregno, x, loc)
4476 int regno, endregno;
4477 rtx x;
4478 rtx *loc;
4479{
4480 register int i;
4481 register RTX_CODE code;
4482 register char *fmt;
4483
4484 if (x == 0)
4485 return 0;
4486
4487 repeat:
4488 code = GET_CODE (x);
4489
4490 switch (code)
4491 {
4492 case REG:
4493 i = REGNO (x);
4494
4803a34a
RK
4495 /* If this is a pseudo, a hard register must not have been allocated.
4496 X must therefore either be a constant or be in memory. */
4497 if (i >= FIRST_PSEUDO_REGISTER)
4498 {
4499 if (reg_equiv_memory_loc[i])
4500 return refers_to_regno_for_reload_p (regno, endregno,
fb3821f7
CH
4501 reg_equiv_memory_loc[i],
4502 NULL_PTR);
4803a34a
RK
4503
4504 if (reg_equiv_constant[i])
4505 return 0;
4506
4507 abort ();
4508 }
eab89b90
RK
4509
4510 return (endregno > i
4511 && regno < i + (i < FIRST_PSEUDO_REGISTER
4512 ? HARD_REGNO_NREGS (i, GET_MODE (x))
4513 : 1));
4514
4515 case SUBREG:
4516 /* If this is a SUBREG of a hard reg, we can see exactly which
4517 registers are being modified. Otherwise, handle normally. */
4518 if (GET_CODE (SUBREG_REG (x)) == REG
4519 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
4520 {
4521 int inner_regno = REGNO (SUBREG_REG (x)) + SUBREG_WORD (x);
4522 int inner_endregno
4523 = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
4524 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
4525
4526 return endregno > inner_regno && regno < inner_endregno;
4527 }
4528 break;
4529
4530 case CLOBBER:
4531 case SET:
4532 if (&SET_DEST (x) != loc
4533 /* Note setting a SUBREG counts as referring to the REG it is in for
4534 a pseudo but not for hard registers since we can
4535 treat each word individually. */
4536 && ((GET_CODE (SET_DEST (x)) == SUBREG
4537 && loc != &SUBREG_REG (SET_DEST (x))
4538 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
4539 && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
4540 && refers_to_regno_for_reload_p (regno, endregno,
4541 SUBREG_REG (SET_DEST (x)),
4542 loc))
4543 || (GET_CODE (SET_DEST (x)) != REG
4544 && refers_to_regno_for_reload_p (regno, endregno,
4545 SET_DEST (x), loc))))
4546 return 1;
4547
4548 if (code == CLOBBER || loc == &SET_SRC (x))
4549 return 0;
4550 x = SET_SRC (x);
4551 goto repeat;
4552 }
4553
4554 /* X does not match, so try its subexpressions. */
4555
4556 fmt = GET_RTX_FORMAT (code);
4557 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4558 {
4559 if (fmt[i] == 'e' && loc != &XEXP (x, i))
4560 {
4561 if (i == 0)
4562 {
4563 x = XEXP (x, 0);
4564 goto repeat;
4565 }
4566 else
4567 if (refers_to_regno_for_reload_p (regno, endregno,
4568 XEXP (x, i), loc))
4569 return 1;
4570 }
4571 else if (fmt[i] == 'E')
4572 {
4573 register int j;
4574 for (j = XVECLEN (x, i) - 1; j >=0; j--)
4575 if (loc != &XVECEXP (x, i, j)
4576 && refers_to_regno_for_reload_p (regno, endregno,
4577 XVECEXP (x, i, j), loc))
4578 return 1;
4579 }
4580 }
4581 return 0;
4582}
bfa30b22
RK
4583
4584/* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
4585 we check if any register number in X conflicts with the relevant register
4586 numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
4587 contains a MEM (we don't bother checking for memory addresses that can't
4588 conflict because we expect this to be a rare case.
4589
4590 This function is similar to reg_overlap_mention_p in rtlanal.c except
4591 that we look at equivalences for pseudos that didn't get hard registers. */
4592
4593int
4594reg_overlap_mentioned_for_reload_p (x, in)
4595 rtx x, in;
4596{
4597 int regno, endregno;
4598
4599 if (GET_CODE (x) == SUBREG)
4600 {
4601 regno = REGNO (SUBREG_REG (x));
4602 if (regno < FIRST_PSEUDO_REGISTER)
4603 regno += SUBREG_WORD (x);
4604 }
4605 else if (GET_CODE (x) == REG)
4606 {
4607 regno = REGNO (x);
4803a34a
RK
4608
4609 /* If this is a pseudo, it must not have been assigned a hard register.
4610 Therefore, it must either be in memory or be a constant. */
4611
4612 if (regno >= FIRST_PSEUDO_REGISTER)
4613 {
4614 if (reg_equiv_memory_loc[regno])
4615 return refers_to_mem_for_reload_p (in);
4616 else if (reg_equiv_constant[regno])
4617 return 0;
4618 abort ();
4619 }
bfa30b22
RK
4620 }
4621 else if (CONSTANT_P (x))
4622 return 0;
4623 else if (GET_CODE (x) == MEM)
4803a34a 4624 return refers_to_mem_for_reload_p (in);
bfa30b22
RK
4625 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC
4626 || GET_CODE (x) == CC0)
4627 return reg_mentioned_p (x, in);
4628 else
4629 abort ();
4630
4631 endregno = regno + (regno < FIRST_PSEUDO_REGISTER
4632 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1);
4633
fb3821f7 4634 return refers_to_regno_for_reload_p (regno, endregno, in, NULL_PTR);
bfa30b22 4635}
4803a34a
RK
4636
4637/* Return nonzero if anything in X contains a MEM. Look also for pseudo
4638 registers. */
4639
4640int
4641refers_to_mem_for_reload_p (x)
4642 rtx x;
4643{
4644 char *fmt;
4645 int i;
4646
4647 if (GET_CODE (x) == MEM)
4648 return 1;
4649
4650 if (GET_CODE (x) == REG)
4651 return (REGNO (x) >= FIRST_PSEUDO_REGISTER
4652 && reg_equiv_memory_loc[REGNO (x)]);
4653
4654 fmt = GET_RTX_FORMAT (GET_CODE (x));
4655 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
4656 if (fmt[i] == 'e'
4657 && (GET_CODE (XEXP (x, i)) == MEM
4658 || refers_to_mem_for_reload_p (XEXP (x, i))))
4659 return 1;
4660
4661 return 0;
4662}
eab89b90
RK
4663\f
4664#if 0
4665
4666/* [[This function is currently obsolete, now that volatility
4667 is represented by a special bit `volatil' so VOLATILE is never used;
4668 and UNCHANGING has never been brought into use.]]
4669
4670 Alter X by eliminating all VOLATILE and UNCHANGING expressions.
4671 Each of them is replaced by its operand.
4672 Thus, (PLUS (VOLATILE (MEM (REG 5))) (CONST_INT 4))
4673 becomes (PLUS (MEM (REG 5)) (CONST_INT 4)).
4674
4675 If X is itself a VOLATILE expression,
4676 we return the expression that should replace it
4677 but we do not modify X. */
4678
4679static rtx
4680forget_volatility (x)
4681 register rtx x;
4682{
4683 enum rtx_code code = GET_CODE (x);
4684 register char *fmt;
4685 register int i;
4686 register rtx value = 0;
4687
4688 switch (code)
4689 {
4690 case LABEL_REF:
4691 case SYMBOL_REF:
4692 case CONST_INT:
4693 case CONST_DOUBLE:
4694 case CONST:
4695 case REG:
4696 case CC0:
4697 case PC:
4698 return x;
4699
4700 case VOLATILE:
4701 case UNCHANGING:
4702 return XEXP (x, 0);
4703 }
4704
4705 fmt = GET_RTX_FORMAT (code);
4706 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4707 {
4708 if (fmt[i] == 'e')
4709 XEXP (x, i) = forget_volatility (XEXP (x, i));
4710 if (fmt[i] == 'E')
4711 {
4712 register int j;
4713 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
4714 XVECEXP (x, i, j) = forget_volatility (XVECEXP (x, i, j));
4715 }
4716 }
4717
4718 return x;
4719}
4720
4721#endif
4722\f
4723/* Check the insns before INSN to see if there is a suitable register
4724 containing the same value as GOAL.
4725 If OTHER is -1, look for a register in class CLASS.
4726 Otherwise, just see if register number OTHER shares GOAL's value.
4727
4728 Return an rtx for the register found, or zero if none is found.
4729
4730 If RELOAD_REG_P is (short *)1,
4731 we reject any hard reg that appears in reload_reg_rtx
4732 because such a hard reg is also needed coming into this insn.
4733
4734 If RELOAD_REG_P is any other nonzero value,
4735 it is a vector indexed by hard reg number
4736 and we reject any hard reg whose element in the vector is nonnegative
4737 as well as any that appears in reload_reg_rtx.
4738
4739 If GOAL is zero, then GOALREG is a register number; we look
4740 for an equivalent for that register.
4741
4742 MODE is the machine mode of the value we want an equivalence for.
4743 If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
4744
4745 This function is used by jump.c as well as in the reload pass.
4746
4747 If GOAL is the sum of the stack pointer and a constant, we treat it
4748 as if it were a constant except that sp is required to be unchanging. */
4749
4750rtx
4751find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode)
4752 register rtx goal;
4753 rtx insn;
4754 enum reg_class class;
4755 register int other;
4756 short *reload_reg_p;
4757 int goalreg;
4758 enum machine_mode mode;
4759{
4760 register rtx p = insn;
4761 rtx valtry, value, where;
4762 register rtx pat;
4763 register int regno = -1;
4764 int valueno;
4765 int goal_mem = 0;
4766 int goal_const = 0;
4767 int goal_mem_addr_varies = 0;
4768 int need_stable_sp = 0;
4769 int nregs;
4770 int valuenregs;
4771
4772 if (goal == 0)
4773 regno = goalreg;
4774 else if (GET_CODE (goal) == REG)
4775 regno = REGNO (goal);
4776 else if (GET_CODE (goal) == MEM)
4777 {
4778 enum rtx_code code = GET_CODE (XEXP (goal, 0));
4779 if (MEM_VOLATILE_P (goal))
4780 return 0;
4781 if (flag_float_store && GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT)
4782 return 0;
4783 /* An address with side effects must be reexecuted. */
4784 switch (code)
4785 {
4786 case POST_INC:
4787 case PRE_INC:
4788 case POST_DEC:
4789 case PRE_DEC:
4790 return 0;
4791 }
4792 goal_mem = 1;
4793 }
4794 else if (CONSTANT_P (goal))
4795 goal_const = 1;
4796 else if (GET_CODE (goal) == PLUS
4797 && XEXP (goal, 0) == stack_pointer_rtx
4798 && CONSTANT_P (XEXP (goal, 1)))
4799 goal_const = need_stable_sp = 1;
4800 else
4801 return 0;
4802
4803 /* On some machines, certain regs must always be rejected
4804 because they don't behave the way ordinary registers do. */
4805
4806#ifdef OVERLAPPING_REGNO_P
4807 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
4808 && OVERLAPPING_REGNO_P (regno))
4809 return 0;
4810#endif
4811
4812 /* Scan insns back from INSN, looking for one that copies
4813 a value into or out of GOAL.
4814 Stop and give up if we reach a label. */
4815
4816 while (1)
4817 {
4818 p = PREV_INSN (p);
4819 if (p == 0 || GET_CODE (p) == CODE_LABEL)
4820 return 0;
4821 if (GET_CODE (p) == INSN
4822 /* If we don't want spill regs ... */
4823 && (! (reload_reg_p != 0 && reload_reg_p != (short *)1)
4824 /* ... then ignore insns introduced by reload; they aren't useful
4825 and can cause results in reload_as_needed to be different
4826 from what they were when calculating the need for spills.
4827 If we notice an input-reload insn here, we will reject it below,
4828 but it might hide a usable equivalent. That makes bad code.
4829 It may even abort: perhaps no reg was spilled for this insn
4830 because it was assumed we would find that equivalent. */
4831 || INSN_UID (p) < reload_first_uid))
4832 {
e8094962 4833 rtx tem;
eab89b90
RK
4834 pat = single_set (p);
4835 /* First check for something that sets some reg equal to GOAL. */
4836 if (pat != 0
4837 && ((regno >= 0
4838 && true_regnum (SET_SRC (pat)) == regno
4839 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
4840 ||
4841 (regno >= 0
4842 && true_regnum (SET_DEST (pat)) == regno
4843 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0)
4844 ||
4845 (goal_const && rtx_equal_p (SET_SRC (pat), goal)
4846 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
4847 || (goal_mem
4848 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0
4849 && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
4850 || (goal_mem
4851 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0
e8094962
RK
4852 && rtx_renumbered_equal_p (goal, SET_DEST (pat)))
4853 /* If we are looking for a constant,
4854 and something equivalent to that constant was copied
4855 into a reg, we can use that reg. */
fb3821f7
CH
4856 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
4857 NULL_RTX))
e8094962 4858 && rtx_equal_p (XEXP (tem, 0), goal)
95d3562b 4859 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0)
fb3821f7
CH
4860 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
4861 NULL_RTX))
e8094962
RK
4862 && GET_CODE (SET_DEST (pat)) == REG
4863 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
4864 && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
4865 && GET_CODE (goal) == CONST_INT
4866 && INTVAL (goal) == CONST_DOUBLE_LOW (XEXP (tem, 0))
4867 && (valtry = operand_subword (SET_DEST (pat), 0, 0,
4868 VOIDmode))
95d3562b 4869 && (valueno = true_regnum (valtry)) >= 0)
fb3821f7
CH
4870 || (goal_const && (tem = find_reg_note (p, REG_EQUIV,
4871 NULL_RTX))
e8094962
RK
4872 && GET_CODE (SET_DEST (pat)) == REG
4873 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE
4874 && GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) == MODE_FLOAT
4875 && GET_CODE (goal) == CONST_INT
4876 && INTVAL (goal) == CONST_DOUBLE_HIGH (XEXP (tem, 0))
4877 && (valtry
4878 = operand_subword (SET_DEST (pat), 1, 0, VOIDmode))
95d3562b 4879 && (valueno = true_regnum (valtry)) >= 0)))
eab89b90
RK
4880 if (other >= 0
4881 ? valueno == other
4882 : ((unsigned) valueno < FIRST_PSEUDO_REGISTER
4883 && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
4884 valueno)))
4885 {
4886 value = valtry;
4887 where = p;
4888 break;
4889 }
4890 }
4891 }
4892
4893 /* We found a previous insn copying GOAL into a suitable other reg VALUE
4894 (or copying VALUE into GOAL, if GOAL is also a register).
4895 Now verify that VALUE is really valid. */
4896
4897 /* VALUENO is the register number of VALUE; a hard register. */
4898
4899 /* Don't try to re-use something that is killed in this insn. We want
4900 to be able to trust REG_UNUSED notes. */
4901 if (find_reg_note (where, REG_UNUSED, value))
4902 return 0;
4903
4904 /* If we propose to get the value from the stack pointer or if GOAL is
4905 a MEM based on the stack pointer, we need a stable SP. */
4906 if (valueno == STACK_POINTER_REGNUM
bfa30b22
RK
4907 || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx,
4908 goal)))
eab89b90
RK
4909 need_stable_sp = 1;
4910
4911 /* Reject VALUE if the copy-insn moved the wrong sort of datum. */
4912 if (GET_MODE (value) != mode)
4913 return 0;
4914
4915 /* Reject VALUE if it was loaded from GOAL
4916 and is also a register that appears in the address of GOAL. */
4917
4918 if (goal_mem && value == SET_DEST (PATTERN (where))
bfa30b22
RK
4919 && refers_to_regno_for_reload_p (valueno,
4920 (valueno
4921 + HARD_REGNO_NREGS (valueno, mode)),
fb3821f7 4922 goal, NULL_PTR))
eab89b90
RK
4923 return 0;
4924
4925 /* Reject registers that overlap GOAL. */
4926
4927 if (!goal_mem && !goal_const
4928 && regno + HARD_REGNO_NREGS (regno, mode) > valueno
4929 && regno < valueno + HARD_REGNO_NREGS (valueno, mode))
4930 return 0;
4931
4932 /* Reject VALUE if it is one of the regs reserved for reloads.
4933 Reload1 knows how to reuse them anyway, and it would get
4934 confused if we allocated one without its knowledge.
4935 (Now that insns introduced by reload are ignored above,
4936 this case shouldn't happen, but I'm not positive.) */
4937
4938 if (reload_reg_p != 0 && reload_reg_p != (short *)1
4939 && reload_reg_p[valueno] >= 0)
4940 return 0;
4941
4942 /* On some machines, certain regs must always be rejected
4943 because they don't behave the way ordinary registers do. */
4944
4945#ifdef OVERLAPPING_REGNO_P
4946 if (OVERLAPPING_REGNO_P (valueno))
4947 return 0;
4948#endif
4949
4950 nregs = HARD_REGNO_NREGS (regno, mode);
4951 valuenregs = HARD_REGNO_NREGS (valueno, mode);
4952
4953 /* Reject VALUE if it is a register being used for an input reload
4954 even if it is not one of those reserved. */
4955
4956 if (reload_reg_p != 0)
4957 {
4958 int i;
4959 for (i = 0; i < n_reloads; i++)
4960 if (reload_reg_rtx[i] != 0 && reload_in[i])
4961 {
4962 int regno1 = REGNO (reload_reg_rtx[i]);
4963 int nregs1 = HARD_REGNO_NREGS (regno1,
4964 GET_MODE (reload_reg_rtx[i]));
4965 if (regno1 < valueno + valuenregs
4966 && regno1 + nregs1 > valueno)
4967 return 0;
4968 }
4969 }
4970
4971 if (goal_mem)
4972 goal_mem_addr_varies = rtx_addr_varies_p (goal);
4973
4974 /* Now verify that the values of GOAL and VALUE remain unaltered
4975 until INSN is reached. */
4976
4977 p = insn;
4978 while (1)
4979 {
4980 p = PREV_INSN (p);
4981 if (p == where)
4982 return value;
4983
4984 /* Don't trust the conversion past a function call
4985 if either of the two is in a call-clobbered register, or memory. */
4986 if (GET_CODE (p) == CALL_INSN
4987 && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER
4988 && call_used_regs[regno])
4989 ||
4990 (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
4991 && call_used_regs[valueno])
4992 ||
4993 goal_mem
4994 || need_stable_sp))
4995 return 0;
4996
4997#ifdef INSN_CLOBBERS_REGNO_P
4998 if ((valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
4999 && INSN_CLOBBERS_REGNO_P (p, valueno))
5000 || (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
5001 && INSN_CLOBBERS_REGNO_P (p, regno)))
5002 return 0;
5003#endif
5004
5005 if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
5006 {
5007 /* If this insn P stores in either GOAL or VALUE, return 0.
5008 If GOAL is a memory ref and this insn writes memory, return 0.
5009 If GOAL is a memory ref and its address is not constant,
5010 and this insn P changes a register used in GOAL, return 0. */
5011
5012 pat = PATTERN (p);
5013 if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
5014 {
5015 register rtx dest = SET_DEST (pat);
5016 while (GET_CODE (dest) == SUBREG
5017 || GET_CODE (dest) == ZERO_EXTRACT
5018 || GET_CODE (dest) == SIGN_EXTRACT
5019 || GET_CODE (dest) == STRICT_LOW_PART)
5020 dest = XEXP (dest, 0);
5021 if (GET_CODE (dest) == REG)
5022 {
5023 register int xregno = REGNO (dest);
5024 int xnregs;
5025 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5026 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5027 else
5028 xnregs = 1;
5029 if (xregno < regno + nregs && xregno + xnregs > regno)
5030 return 0;
5031 if (xregno < valueno + valuenregs
5032 && xregno + xnregs > valueno)
5033 return 0;
5034 if (goal_mem_addr_varies
bfa30b22 5035 && reg_overlap_mentioned_for_reload_p (dest, goal))
eab89b90
RK
5036 return 0;
5037 }
5038 else if (goal_mem && GET_CODE (dest) == MEM
5039 && ! push_operand (dest, GET_MODE (dest)))
5040 return 0;
5041 else if (need_stable_sp && push_operand (dest, GET_MODE (dest)))
5042 return 0;
5043 }
5044 else if (GET_CODE (pat) == PARALLEL)
5045 {
5046 register int i;
5047 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
5048 {
5049 register rtx v1 = XVECEXP (pat, 0, i);
5050 if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
5051 {
5052 register rtx dest = SET_DEST (v1);
5053 while (GET_CODE (dest) == SUBREG
5054 || GET_CODE (dest) == ZERO_EXTRACT
5055 || GET_CODE (dest) == SIGN_EXTRACT
5056 || GET_CODE (dest) == STRICT_LOW_PART)
5057 dest = XEXP (dest, 0);
5058 if (GET_CODE (dest) == REG)
5059 {
5060 register int xregno = REGNO (dest);
5061 int xnregs;
5062 if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
5063 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
5064 else
5065 xnregs = 1;
5066 if (xregno < regno + nregs
5067 && xregno + xnregs > regno)
5068 return 0;
5069 if (xregno < valueno + valuenregs
5070 && xregno + xnregs > valueno)
5071 return 0;
5072 if (goal_mem_addr_varies
bfa30b22
RK
5073 && reg_overlap_mentioned_for_reload_p (dest,
5074 goal))
eab89b90
RK
5075 return 0;
5076 }
5077 else if (goal_mem && GET_CODE (dest) == MEM
5078 && ! push_operand (dest, GET_MODE (dest)))
5079 return 0;
5080 else if (need_stable_sp
5081 && push_operand (dest, GET_MODE (dest)))
5082 return 0;
5083 }
5084 }
5085 }
5086
5087#ifdef AUTO_INC_DEC
5088 /* If this insn auto-increments or auto-decrements
5089 either regno or valueno, return 0 now.
5090 If GOAL is a memory ref and its address is not constant,
5091 and this insn P increments a register used in GOAL, return 0. */
5092 {
5093 register rtx link;
5094
5095 for (link = REG_NOTES (p); link; link = XEXP (link, 1))
5096 if (REG_NOTE_KIND (link) == REG_INC
5097 && GET_CODE (XEXP (link, 0)) == REG)
5098 {
5099 register int incno = REGNO (XEXP (link, 0));
5100 if (incno < regno + nregs && incno >= regno)
5101 return 0;
5102 if (incno < valueno + valuenregs && incno >= valueno)
5103 return 0;
5104 if (goal_mem_addr_varies
bfa30b22
RK
5105 && reg_overlap_mentioned_for_reload_p (XEXP (link, 0),
5106 goal))
eab89b90
RK
5107 return 0;
5108 }
5109 }
5110#endif
5111 }
5112 }
5113}
5114\f
5115/* Find a place where INCED appears in an increment or decrement operator
5116 within X, and return the amount INCED is incremented or decremented by.
5117 The value is always positive. */
5118
5119static int
5120find_inc_amount (x, inced)
5121 rtx x, inced;
5122{
5123 register enum rtx_code code = GET_CODE (x);
5124 register char *fmt;
5125 register int i;
5126
5127 if (code == MEM)
5128 {
5129 register rtx addr = XEXP (x, 0);
5130 if ((GET_CODE (addr) == PRE_DEC
5131 || GET_CODE (addr) == POST_DEC
5132 || GET_CODE (addr) == PRE_INC
5133 || GET_CODE (addr) == POST_INC)
5134 && XEXP (addr, 0) == inced)
5135 return GET_MODE_SIZE (GET_MODE (x));
5136 }
5137
5138 fmt = GET_RTX_FORMAT (code);
5139 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5140 {
5141 if (fmt[i] == 'e')
5142 {
5143 register int tem = find_inc_amount (XEXP (x, i), inced);
5144 if (tem != 0)
5145 return tem;
5146 }
5147 if (fmt[i] == 'E')
5148 {
5149 register int j;
5150 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5151 {
5152 register int tem = find_inc_amount (XVECEXP (x, i, j), inced);
5153 if (tem != 0)
5154 return tem;
5155 }
5156 }
5157 }
5158
5159 return 0;
5160}
5161\f
5162/* Return 1 if register REGNO is the subject of a clobber in insn INSN. */
5163
5164int
5165regno_clobbered_p (regno, insn)
5166 int regno;
5167 rtx insn;
5168{
5169 if (GET_CODE (PATTERN (insn)) == CLOBBER
5170 && GET_CODE (XEXP (PATTERN (insn), 0)) == REG)
5171 return REGNO (XEXP (PATTERN (insn), 0)) == regno;
5172
5173 if (GET_CODE (PATTERN (insn)) == PARALLEL)
5174 {
5175 int i = XVECLEN (PATTERN (insn), 0) - 1;
5176
5177 for (; i >= 0; i--)
5178 {
5179 rtx elt = XVECEXP (PATTERN (insn), 0, i);
5180 if (GET_CODE (elt) == CLOBBER && GET_CODE (XEXP (elt, 0)) == REG
5181 && REGNO (XEXP (elt, 0)) == regno)
5182 return 1;
5183 }
5184 }
5185
5186 return 0;
5187}
This page took 0.693604 seconds and 5 git commands to generate.