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