]> gcc.gnu.org Git - gcc.git/blob - gcc/recog.c
(constrain_operands, case 'E'): Make this work like
[gcc.git] / gcc / recog.c
1 /* Subroutines used by or related to instruction recognition.
2 Copyright (C) 1987, 88, 91, 92, 93, 1994 Free Software Foundation, Inc.
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
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21 #include "config.h"
22 #include "rtl.h"
23 #include <stdio.h>
24 #include "insn-config.h"
25 #include "insn-attr.h"
26 #include "insn-flags.h"
27 #include "insn-codes.h"
28 #include "recog.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "flags.h"
32 #include "real.h"
33
34 #ifndef STACK_PUSH_CODE
35 #ifdef STACK_GROWS_DOWNWARD
36 #define STACK_PUSH_CODE PRE_DEC
37 #else
38 #define STACK_PUSH_CODE PRE_INC
39 #endif
40 #endif
41
42 /* Import from final.c: */
43 extern rtx alter_subreg ();
44
45 int strict_memory_address_p ();
46 int memory_address_p ();
47
48 /* Nonzero means allow operands to be volatile.
49 This should be 0 if you are generating rtl, such as if you are calling
50 the functions in optabs.c and expmed.c (most of the time).
51 This should be 1 if all valid insns need to be recognized,
52 such as in regclass.c and final.c and reload.c.
53
54 init_recog and init_recog_no_volatile are responsible for setting this. */
55
56 int volatile_ok;
57
58 /* On return from `constrain_operands', indicate which alternative
59 was satisfied. */
60
61 int which_alternative;
62
63 /* Nonzero after end of reload pass.
64 Set to 1 or 0 by toplev.c.
65 Controls the significance of (SUBREG (MEM)). */
66
67 int reload_completed;
68
69 /* Initialize data used by the function `recog'.
70 This must be called once in the compilation of a function
71 before any insn recognition may be done in the function. */
72
73 void
74 init_recog_no_volatile ()
75 {
76 volatile_ok = 0;
77 }
78
79 void
80 init_recog ()
81 {
82 volatile_ok = 1;
83 }
84
85 /* Try recognizing the instruction INSN,
86 and return the code number that results.
87 Remeber the code so that repeated calls do not
88 need to spend the time for actual rerecognition.
89
90 This function is the normal interface to instruction recognition.
91 The automatically-generated function `recog' is normally called
92 through this one. (The only exception is in combine.c.) */
93
94 int
95 recog_memoized (insn)
96 rtx insn;
97 {
98 if (INSN_CODE (insn) < 0)
99 INSN_CODE (insn) = recog (PATTERN (insn), insn, NULL_PTR);
100 return INSN_CODE (insn);
101 }
102 \f
103 /* Check that X is an insn-body for an `asm' with operands
104 and that the operands mentioned in it are legitimate. */
105
106 int
107 check_asm_operands (x)
108 rtx x;
109 {
110 int noperands = asm_noperands (x);
111 rtx *operands;
112 int i;
113
114 if (noperands < 0)
115 return 0;
116 if (noperands == 0)
117 return 1;
118
119 operands = (rtx *) alloca (noperands * sizeof (rtx));
120 decode_asm_operands (x, operands, NULL_PTR, NULL_PTR, NULL_PTR);
121
122 for (i = 0; i < noperands; i++)
123 if (!general_operand (operands[i], VOIDmode))
124 return 0;
125
126 return 1;
127 }
128 \f
129 /* Static data for the next two routines.
130
131 The maximum number of changes supported is defined as the maximum
132 number of operands times 5. This allows for repeated substitutions
133 inside complex indexed address, or, alternatively, changes in up
134 to 5 insns. */
135
136 #define MAX_CHANGE_LOCS (MAX_RECOG_OPERANDS * 5)
137
138 static rtx change_objects[MAX_CHANGE_LOCS];
139 static int change_old_codes[MAX_CHANGE_LOCS];
140 static rtx *change_locs[MAX_CHANGE_LOCS];
141 static rtx change_olds[MAX_CHANGE_LOCS];
142
143 static int num_changes = 0;
144
145 /* Validate a proposed change to OBJECT. LOC is the location in the rtl for
146 at which NEW will be placed. If OBJECT is zero, no validation is done,
147 the change is simply made.
148
149 Two types of objects are supported: If OBJECT is a MEM, memory_address_p
150 will be called with the address and mode as parameters. If OBJECT is
151 an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
152 the change in place.
153
154 IN_GROUP is non-zero if this is part of a group of changes that must be
155 performed as a group. In that case, the changes will be stored. The
156 function `apply_change_group' will validate and apply the changes.
157
158 If IN_GROUP is zero, this is a single change. Try to recognize the insn
159 or validate the memory reference with the change applied. If the result
160 is not valid for the machine, suppress the change and return zero.
161 Otherwise, perform the change and return 1. */
162
163 int
164 validate_change (object, loc, new, in_group)
165 rtx object;
166 rtx *loc;
167 rtx new;
168 int in_group;
169 {
170 rtx old = *loc;
171
172 if (old == new || rtx_equal_p (old, new))
173 return 1;
174
175 if (num_changes >= MAX_CHANGE_LOCS
176 || (in_group == 0 && num_changes != 0))
177 abort ();
178
179 *loc = new;
180
181 /* Save the information describing this change. */
182 change_objects[num_changes] = object;
183 change_locs[num_changes] = loc;
184 change_olds[num_changes] = old;
185
186 if (object && GET_CODE (object) != MEM)
187 {
188 /* Set INSN_CODE to force rerecognition of insn. Save old code in
189 case invalid. */
190 change_old_codes[num_changes] = INSN_CODE (object);
191 INSN_CODE (object) = -1;
192 }
193
194 num_changes++;
195
196 /* If we are making a group of changes, return 1. Otherwise, validate the
197 change group we made. */
198
199 if (in_group)
200 return 1;
201 else
202 return apply_change_group ();
203 }
204
205 /* Apply a group of changes previously issued with `validate_change'.
206 Return 1 if all changes are valid, zero otherwise. */
207
208 int
209 apply_change_group ()
210 {
211 int i;
212
213 /* The changes have been applied and all INSN_CODEs have been reset to force
214 rerecognition.
215
216 The changes are valid if we aren't given an object, or if we are
217 given a MEM and it still is a valid address, or if this is in insn
218 and it is recognized. In the latter case, if reload has completed,
219 we also require that the operands meet the constraints for
220 the insn. We do not allow modifying an ASM_OPERANDS after reload
221 has completed because verifying the constraints is too difficult. */
222
223 for (i = 0; i < num_changes; i++)
224 {
225 rtx object = change_objects[i];
226
227 if (object == 0)
228 continue;
229
230 if (GET_CODE (object) == MEM)
231 {
232 if (! memory_address_p (GET_MODE (object), XEXP (object, 0)))
233 break;
234 }
235 else if ((recog_memoized (object) < 0
236 && (asm_noperands (PATTERN (object)) < 0
237 || ! check_asm_operands (PATTERN (object))
238 || reload_completed))
239 || (reload_completed
240 && (insn_extract (object),
241 ! constrain_operands (INSN_CODE (object), 1))))
242 {
243 rtx pat = PATTERN (object);
244
245 /* Perhaps we couldn't recognize the insn because there were
246 extra CLOBBERs at the end. If so, try to re-recognize
247 without the last CLOBBER (later iterations will cause each of
248 them to be eliminated, in turn). But don't do this if we
249 have an ASM_OPERAND. */
250 if (GET_CODE (pat) == PARALLEL
251 && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
252 && asm_noperands (PATTERN (object)) < 0)
253 {
254 rtx newpat;
255
256 if (XVECLEN (pat, 0) == 2)
257 newpat = XVECEXP (pat, 0, 0);
258 else
259 {
260 int j;
261
262 newpat = gen_rtx (PARALLEL, VOIDmode,
263 gen_rtvec (XVECLEN (pat, 0) - 1));
264 for (j = 0; j < XVECLEN (newpat, 0); j++)
265 XVECEXP (newpat, 0, j) = XVECEXP (pat, 0, j);
266 }
267
268 /* Add a new change to this group to replace the pattern
269 with this new pattern. Then consider this change
270 as having succeeded. The change we added will
271 cause the entire call to fail if things remain invalid.
272
273 Note that this can lose if a later change than the one
274 we are processing specified &XVECEXP (PATTERN (object), 0, X)
275 but this shouldn't occur. */
276
277 validate_change (object, &PATTERN (object), newpat, 1);
278 }
279 else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
280 /* If this insn is a CLOBBER or USE, it is always valid, but is
281 never recognized. */
282 continue;
283 else
284 break;
285 }
286 }
287
288 if (i == num_changes)
289 {
290 num_changes = 0;
291 return 1;
292 }
293 else
294 {
295 cancel_changes (0);
296 return 0;
297 }
298 }
299
300 /* Return the number of changes so far in the current group. */
301
302 int
303 num_validated_changes ()
304 {
305 return num_changes;
306 }
307
308 /* Retract the changes numbered NUM and up. */
309
310 void
311 cancel_changes (num)
312 int num;
313 {
314 int i;
315
316 /* Back out all the changes. Do this in the opposite order in which
317 they were made. */
318 for (i = num_changes - 1; i >= num; i--)
319 {
320 *change_locs[i] = change_olds[i];
321 if (change_objects[i] && GET_CODE (change_objects[i]) != MEM)
322 INSN_CODE (change_objects[i]) = change_old_codes[i];
323 }
324 num_changes = num;
325 }
326
327 /* Replace every occurrence of FROM in X with TO. Mark each change with
328 validate_change passing OBJECT. */
329
330 static void
331 validate_replace_rtx_1 (loc, from, to, object)
332 rtx *loc;
333 rtx from, to, object;
334 {
335 register int i, j;
336 register char *fmt;
337 register rtx x = *loc;
338 enum rtx_code code = GET_CODE (x);
339
340 /* X matches FROM if it is the same rtx or they are both referring to the
341 same register in the same mode. Avoid calling rtx_equal_p unless the
342 operands look similar. */
343
344 if (x == from
345 || (GET_CODE (x) == REG && GET_CODE (from) == REG
346 && GET_MODE (x) == GET_MODE (from)
347 && REGNO (x) == REGNO (from))
348 || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
349 && rtx_equal_p (x, from)))
350 {
351 validate_change (object, loc, to, 1);
352 return;
353 }
354
355 /* For commutative or comparison operations, try replacing each argument
356 separately and seeing if we made any changes. If so, put a constant
357 argument last.*/
358 if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == 'c')
359 {
360 int prev_changes = num_changes;
361
362 validate_replace_rtx_1 (&XEXP (x, 0), from, to, object);
363 validate_replace_rtx_1 (&XEXP (x, 1), from, to, object);
364 if (prev_changes != num_changes && CONSTANT_P (XEXP (x, 0)))
365 {
366 validate_change (object, loc,
367 gen_rtx (GET_RTX_CLASS (code) == 'c' ? code
368 : swap_condition (code),
369 GET_MODE (x), XEXP (x, 1), XEXP (x, 0)),
370 1);
371 x = *loc;
372 code = GET_CODE (x);
373 }
374 }
375
376 switch (code)
377 {
378 case PLUS:
379 /* If we have have a PLUS whose second operand is now a CONST_INT, use
380 plus_constant to try to simplify it. */
381 if (GET_CODE (XEXP (x, 1)) == CONST_INT && XEXP (x, 1) == to)
382 validate_change (object, loc,
383 plus_constant (XEXP (x, 0), INTVAL (XEXP (x, 1))), 1);
384 return;
385
386 case ZERO_EXTEND:
387 case SIGN_EXTEND:
388 /* In these cases, the operation to be performed depends on the mode
389 of the operand. If we are replacing the operand with a VOIDmode
390 constant, we lose the information. So try to simplify the operation
391 in that case. If it fails, substitute in something that we know
392 won't be recognized. */
393 if (GET_MODE (to) == VOIDmode
394 && (XEXP (x, 0) == from
395 || (GET_CODE (XEXP (x, 0)) == REG && GET_CODE (from) == REG
396 && GET_MODE (XEXP (x, 0)) == GET_MODE (from)
397 && REGNO (XEXP (x, 0)) == REGNO (from))))
398 {
399 rtx new = simplify_unary_operation (code, GET_MODE (x), to,
400 GET_MODE (from));
401 if (new == 0)
402 new = gen_rtx (CLOBBER, GET_MODE (x), const0_rtx);
403
404 validate_change (object, loc, new, 1);
405 return;
406 }
407 break;
408
409 case SUBREG:
410 /* If we have a SUBREG of a register that we are replacing and we are
411 replacing it with a MEM, make a new MEM and try replacing the
412 SUBREG with it. Don't do this if the MEM has a mode-dependent address
413 or if we would be widening it. */
414
415 if (SUBREG_REG (x) == from
416 && GET_CODE (from) == REG
417 && GET_CODE (to) == MEM
418 && ! mode_dependent_address_p (XEXP (to, 0))
419 && ! MEM_VOLATILE_P (to)
420 && GET_MODE_SIZE (GET_MODE (x)) <= GET_MODE_SIZE (GET_MODE (to)))
421 {
422 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
423 enum machine_mode mode = GET_MODE (x);
424 rtx new;
425
426 if (BYTES_BIG_ENDIAN)
427 offset += (MIN (UNITS_PER_WORD,
428 GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
429 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
430
431 new = gen_rtx (MEM, mode, plus_constant (XEXP (to, 0), offset));
432 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (to);
433 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (to);
434 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (to);
435 validate_change (object, loc, new, 1);
436 return;
437 }
438 break;
439
440 case ZERO_EXTRACT:
441 case SIGN_EXTRACT:
442 /* If we are replacing a register with memory, try to change the memory
443 to be the mode required for memory in extract operations (this isn't
444 likely to be an insertion operation; if it was, nothing bad will
445 happen, we might just fail in some cases). */
446
447 if (XEXP (x, 0) == from && GET_CODE (from) == REG && GET_CODE (to) == MEM
448 && GET_CODE (XEXP (x, 1)) == CONST_INT
449 && GET_CODE (XEXP (x, 2)) == CONST_INT
450 && ! mode_dependent_address_p (XEXP (to, 0))
451 && ! MEM_VOLATILE_P (to))
452 {
453 enum machine_mode wanted_mode = VOIDmode;
454 enum machine_mode is_mode = GET_MODE (to);
455 int width = INTVAL (XEXP (x, 1));
456 int pos = INTVAL (XEXP (x, 2));
457
458 #ifdef HAVE_extzv
459 if (code == ZERO_EXTRACT)
460 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
461 #endif
462 #ifdef HAVE_extv
463 if (code == SIGN_EXTRACT)
464 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
465 #endif
466
467 /* If we have a narrower mode, we can do something. */
468 if (wanted_mode != VOIDmode
469 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
470 {
471 int offset = pos / BITS_PER_UNIT;
472 rtx newmem;
473
474 /* If the bytes and bits are counted differently, we
475 must adjust the offset. */
476 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
477 offset = (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode)
478 - offset);
479
480 pos %= GET_MODE_BITSIZE (wanted_mode);
481
482 newmem = gen_rtx (MEM, wanted_mode,
483 plus_constant (XEXP (to, 0), offset));
484 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (to);
485 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (to);
486 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (to);
487
488 validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
489 validate_change (object, &XEXP (x, 0), newmem, 1);
490 }
491 }
492
493 break;
494 }
495
496 fmt = GET_RTX_FORMAT (code);
497 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
498 {
499 if (fmt[i] == 'e')
500 validate_replace_rtx_1 (&XEXP (x, i), from, to, object);
501 else if (fmt[i] == 'E')
502 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
503 validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object);
504 }
505 }
506
507 /* Try replacing every occurrence of FROM in INSN with TO. After all
508 changes have been made, validate by seeing if INSN is still valid. */
509
510 int
511 validate_replace_rtx (from, to, insn)
512 rtx from, to, insn;
513 {
514 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
515 return apply_change_group ();
516 }
517 \f
518 #ifdef HAVE_cc0
519 /* Return 1 if the insn using CC0 set by INSN does not contain
520 any ordered tests applied to the condition codes.
521 EQ and NE tests do not count. */
522
523 int
524 next_insn_tests_no_inequality (insn)
525 rtx insn;
526 {
527 register rtx next = next_cc0_user (insn);
528
529 /* If there is no next insn, we have to take the conservative choice. */
530 if (next == 0)
531 return 0;
532
533 return ((GET_CODE (next) == JUMP_INSN
534 || GET_CODE (next) == INSN
535 || GET_CODE (next) == CALL_INSN)
536 && ! inequality_comparisons_p (PATTERN (next)));
537 }
538
539 #if 0 /* This is useless since the insn that sets the cc's
540 must be followed immediately by the use of them. */
541 /* Return 1 if the CC value set up by INSN is not used. */
542
543 int
544 next_insns_test_no_inequality (insn)
545 rtx insn;
546 {
547 register rtx next = NEXT_INSN (insn);
548
549 for (; next != 0; next = NEXT_INSN (next))
550 {
551 if (GET_CODE (next) == CODE_LABEL
552 || GET_CODE (next) == BARRIER)
553 return 1;
554 if (GET_CODE (next) == NOTE)
555 continue;
556 if (inequality_comparisons_p (PATTERN (next)))
557 return 0;
558 if (sets_cc0_p (PATTERN (next)) == 1)
559 return 1;
560 if (! reg_mentioned_p (cc0_rtx, PATTERN (next)))
561 return 1;
562 }
563 return 1;
564 }
565 #endif
566 #endif
567 \f
568 /* This is used by find_single_use to locate an rtx that contains exactly one
569 use of DEST, which is typically either a REG or CC0. It returns a
570 pointer to the innermost rtx expression containing DEST. Appearances of
571 DEST that are being used to totally replace it are not counted. */
572
573 static rtx *
574 find_single_use_1 (dest, loc)
575 rtx dest;
576 rtx *loc;
577 {
578 rtx x = *loc;
579 enum rtx_code code = GET_CODE (x);
580 rtx *result = 0;
581 rtx *this_result;
582 int i;
583 char *fmt;
584
585 switch (code)
586 {
587 case CONST_INT:
588 case CONST:
589 case LABEL_REF:
590 case SYMBOL_REF:
591 case CONST_DOUBLE:
592 case CLOBBER:
593 return 0;
594
595 case SET:
596 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
597 of a REG that occupies all of the REG, the insn uses DEST if
598 it is mentioned in the destination or the source. Otherwise, we
599 need just check the source. */
600 if (GET_CODE (SET_DEST (x)) != CC0
601 && GET_CODE (SET_DEST (x)) != PC
602 && GET_CODE (SET_DEST (x)) != REG
603 && ! (GET_CODE (SET_DEST (x)) == SUBREG
604 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
605 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (x))))
606 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
607 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
608 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
609 break;
610
611 return find_single_use_1 (dest, &SET_SRC (x));
612
613 case MEM:
614 case SUBREG:
615 return find_single_use_1 (dest, &XEXP (x, 0));
616 }
617
618 /* If it wasn't one of the common cases above, check each expression and
619 vector of this code. Look for a unique usage of DEST. */
620
621 fmt = GET_RTX_FORMAT (code);
622 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
623 {
624 if (fmt[i] == 'e')
625 {
626 if (dest == XEXP (x, i)
627 || (GET_CODE (dest) == REG && GET_CODE (XEXP (x, i)) == REG
628 && REGNO (dest) == REGNO (XEXP (x, i))))
629 this_result = loc;
630 else
631 this_result = find_single_use_1 (dest, &XEXP (x, i));
632
633 if (result == 0)
634 result = this_result;
635 else if (this_result)
636 /* Duplicate usage. */
637 return 0;
638 }
639 else if (fmt[i] == 'E')
640 {
641 int j;
642
643 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
644 {
645 if (XVECEXP (x, i, j) == dest
646 || (GET_CODE (dest) == REG
647 && GET_CODE (XVECEXP (x, i, j)) == REG
648 && REGNO (XVECEXP (x, i, j)) == REGNO (dest)))
649 this_result = loc;
650 else
651 this_result = find_single_use_1 (dest, &XVECEXP (x, i, j));
652
653 if (result == 0)
654 result = this_result;
655 else if (this_result)
656 return 0;
657 }
658 }
659 }
660
661 return result;
662 }
663 \f
664 /* See if DEST, produced in INSN, is used only a single time in the
665 sequel. If so, return a pointer to the innermost rtx expression in which
666 it is used.
667
668 If PLOC is non-zero, *PLOC is set to the insn containing the single use.
669
670 This routine will return usually zero either before flow is called (because
671 there will be no LOG_LINKS notes) or after reload (because the REG_DEAD
672 note can't be trusted).
673
674 If DEST is cc0_rtx, we look only at the next insn. In that case, we don't
675 care about REG_DEAD notes or LOG_LINKS.
676
677 Otherwise, we find the single use by finding an insn that has a
678 LOG_LINKS pointing at INSN and has a REG_DEAD note for DEST. If DEST is
679 only referenced once in that insn, we know that it must be the first
680 and last insn referencing DEST. */
681
682 rtx *
683 find_single_use (dest, insn, ploc)
684 rtx dest;
685 rtx insn;
686 rtx *ploc;
687 {
688 rtx next;
689 rtx *result;
690 rtx link;
691
692 #ifdef HAVE_cc0
693 if (dest == cc0_rtx)
694 {
695 next = NEXT_INSN (insn);
696 if (next == 0
697 || (GET_CODE (next) != INSN && GET_CODE (next) != JUMP_INSN))
698 return 0;
699
700 result = find_single_use_1 (dest, &PATTERN (next));
701 if (result && ploc)
702 *ploc = next;
703 return result;
704 }
705 #endif
706
707 if (reload_completed || reload_in_progress || GET_CODE (dest) != REG)
708 return 0;
709
710 for (next = next_nonnote_insn (insn);
711 next != 0 && GET_CODE (next) != CODE_LABEL;
712 next = next_nonnote_insn (next))
713 if (GET_RTX_CLASS (GET_CODE (next)) == 'i' && dead_or_set_p (next, dest))
714 {
715 for (link = LOG_LINKS (next); link; link = XEXP (link, 1))
716 if (XEXP (link, 0) == insn)
717 break;
718
719 if (link)
720 {
721 result = find_single_use_1 (dest, &PATTERN (next));
722 if (ploc)
723 *ploc = next;
724 return result;
725 }
726 }
727
728 return 0;
729 }
730 \f
731 /* Return 1 if OP is a valid general operand for machine mode MODE.
732 This is either a register reference, a memory reference,
733 or a constant. In the case of a memory reference, the address
734 is checked for general validity for the target machine.
735
736 Register and memory references must have mode MODE in order to be valid,
737 but some constants have no machine mode and are valid for any mode.
738
739 If MODE is VOIDmode, OP is checked for validity for whatever mode
740 it has.
741
742 The main use of this function is as a predicate in match_operand
743 expressions in the machine description.
744
745 For an explanation of this function's behavior for registers of
746 class NO_REGS, see the comment for `register_operand'. */
747
748 int
749 general_operand (op, mode)
750 register rtx op;
751 enum machine_mode mode;
752 {
753 register enum rtx_code code = GET_CODE (op);
754 int mode_altering_drug = 0;
755
756 if (mode == VOIDmode)
757 mode = GET_MODE (op);
758
759 /* Don't accept CONST_INT or anything similar
760 if the caller wants something floating. */
761 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
762 && GET_MODE_CLASS (mode) != MODE_INT
763 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
764 return 0;
765
766 if (CONSTANT_P (op))
767 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
768 #ifdef LEGITIMATE_PIC_OPERAND_P
769 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
770 #endif
771 && LEGITIMATE_CONSTANT_P (op));
772
773 /* Except for certain constants with VOIDmode, already checked for,
774 OP's mode must match MODE if MODE specifies a mode. */
775
776 if (GET_MODE (op) != mode)
777 return 0;
778
779 if (code == SUBREG)
780 {
781 #ifdef INSN_SCHEDULING
782 /* On machines that have insn scheduling, we want all memory
783 reference to be explicit, so outlaw paradoxical SUBREGs. */
784 if (GET_CODE (SUBREG_REG (op)) == MEM
785 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))))
786 return 0;
787 #endif
788
789 op = SUBREG_REG (op);
790 code = GET_CODE (op);
791 #if 0
792 /* No longer needed, since (SUBREG (MEM...))
793 will load the MEM into a reload reg in the MEM's own mode. */
794 mode_altering_drug = 1;
795 #endif
796 }
797
798 if (code == REG)
799 /* A register whose class is NO_REGS is not a general operand. */
800 return (REGNO (op) >= FIRST_PSEUDO_REGISTER
801 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS);
802
803 if (code == MEM)
804 {
805 register rtx y = XEXP (op, 0);
806 if (! volatile_ok && MEM_VOLATILE_P (op))
807 return 0;
808 /* Use the mem's mode, since it will be reloaded thus. */
809 mode = GET_MODE (op);
810 GO_IF_LEGITIMATE_ADDRESS (mode, y, win);
811 }
812 return 0;
813
814 win:
815 if (mode_altering_drug)
816 return ! mode_dependent_address_p (XEXP (op, 0));
817 return 1;
818 }
819 \f
820 /* Return 1 if OP is a valid memory address for a memory reference
821 of mode MODE.
822
823 The main use of this function is as a predicate in match_operand
824 expressions in the machine description. */
825
826 int
827 address_operand (op, mode)
828 register rtx op;
829 enum machine_mode mode;
830 {
831 return memory_address_p (mode, op);
832 }
833
834 /* Return 1 if OP is a register reference of mode MODE.
835 If MODE is VOIDmode, accept a register in any mode.
836
837 The main use of this function is as a predicate in match_operand
838 expressions in the machine description.
839
840 As a special exception, registers whose class is NO_REGS are
841 not accepted by `register_operand'. The reason for this change
842 is to allow the representation of special architecture artifacts
843 (such as a condition code register) without extending the rtl
844 definitions. Since registers of class NO_REGS cannot be used
845 as registers in any case where register classes are examined,
846 it is most consistent to keep this function from accepting them. */
847
848 int
849 register_operand (op, mode)
850 register rtx op;
851 enum machine_mode mode;
852 {
853 if (GET_MODE (op) != mode && mode != VOIDmode)
854 return 0;
855
856 if (GET_CODE (op) == SUBREG)
857 {
858 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
859 because it is guaranteed to be reloaded into one.
860 Just make sure the MEM is valid in itself.
861 (Ideally, (SUBREG (MEM)...) should not exist after reload,
862 but currently it does result from (SUBREG (REG)...) where the
863 reg went on the stack.) */
864 if (! reload_completed && GET_CODE (SUBREG_REG (op)) == MEM)
865 return general_operand (op, mode);
866 op = SUBREG_REG (op);
867 }
868
869 /* We don't consider registers whose class is NO_REGS
870 to be a register operand. */
871 return (GET_CODE (op) == REG
872 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
873 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
874 }
875
876 /* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
877 or a hard register. */
878
879 int
880 scratch_operand (op, mode)
881 register rtx op;
882 enum machine_mode mode;
883 {
884 return (GET_MODE (op) == mode
885 && (GET_CODE (op) == SCRATCH
886 || (GET_CODE (op) == REG
887 && REGNO (op) < FIRST_PSEUDO_REGISTER)));
888 }
889
890 /* Return 1 if OP is a valid immediate operand for mode MODE.
891
892 The main use of this function is as a predicate in match_operand
893 expressions in the machine description. */
894
895 int
896 immediate_operand (op, mode)
897 register rtx op;
898 enum machine_mode mode;
899 {
900 /* Don't accept CONST_INT or anything similar
901 if the caller wants something floating. */
902 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
903 && GET_MODE_CLASS (mode) != MODE_INT
904 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
905 return 0;
906
907 return (CONSTANT_P (op)
908 && (GET_MODE (op) == mode || mode == VOIDmode
909 || GET_MODE (op) == VOIDmode)
910 #ifdef LEGITIMATE_PIC_OPERAND_P
911 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
912 #endif
913 && LEGITIMATE_CONSTANT_P (op));
914 }
915
916 /* Returns 1 if OP is an operand that is a CONST_INT. */
917
918 int
919 const_int_operand (op, mode)
920 register rtx op;
921 enum machine_mode mode;
922 {
923 return GET_CODE (op) == CONST_INT;
924 }
925
926 /* Returns 1 if OP is an operand that is a constant integer or constant
927 floating-point number. */
928
929 int
930 const_double_operand (op, mode)
931 register rtx op;
932 enum machine_mode mode;
933 {
934 /* Don't accept CONST_INT or anything similar
935 if the caller wants something floating. */
936 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
937 && GET_MODE_CLASS (mode) != MODE_INT
938 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
939 return 0;
940
941 return ((GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT)
942 && (mode == VOIDmode || GET_MODE (op) == mode
943 || GET_MODE (op) == VOIDmode));
944 }
945
946 /* Return 1 if OP is a general operand that is not an immediate operand. */
947
948 int
949 nonimmediate_operand (op, mode)
950 register rtx op;
951 enum machine_mode mode;
952 {
953 return (general_operand (op, mode) && ! CONSTANT_P (op));
954 }
955
956 /* Return 1 if OP is a register reference or immediate value of mode MODE. */
957
958 int
959 nonmemory_operand (op, mode)
960 register rtx op;
961 enum machine_mode mode;
962 {
963 if (CONSTANT_P (op))
964 {
965 /* Don't accept CONST_INT or anything similar
966 if the caller wants something floating. */
967 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
968 && GET_MODE_CLASS (mode) != MODE_INT
969 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
970 return 0;
971
972 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
973 #ifdef LEGITIMATE_PIC_OPERAND_P
974 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
975 #endif
976 && LEGITIMATE_CONSTANT_P (op));
977 }
978
979 if (GET_MODE (op) != mode && mode != VOIDmode)
980 return 0;
981
982 if (GET_CODE (op) == SUBREG)
983 {
984 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
985 because it is guaranteed to be reloaded into one.
986 Just make sure the MEM is valid in itself.
987 (Ideally, (SUBREG (MEM)...) should not exist after reload,
988 but currently it does result from (SUBREG (REG)...) where the
989 reg went on the stack.) */
990 if (! reload_completed && GET_CODE (SUBREG_REG (op)) == MEM)
991 return general_operand (op, mode);
992 op = SUBREG_REG (op);
993 }
994
995 /* We don't consider registers whose class is NO_REGS
996 to be a register operand. */
997 return (GET_CODE (op) == REG
998 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
999 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1000 }
1001
1002 /* Return 1 if OP is a valid operand that stands for pushing a
1003 value of mode MODE onto the stack.
1004
1005 The main use of this function is as a predicate in match_operand
1006 expressions in the machine description. */
1007
1008 int
1009 push_operand (op, mode)
1010 rtx op;
1011 enum machine_mode mode;
1012 {
1013 if (GET_CODE (op) != MEM)
1014 return 0;
1015
1016 if (GET_MODE (op) != mode)
1017 return 0;
1018
1019 op = XEXP (op, 0);
1020
1021 if (GET_CODE (op) != STACK_PUSH_CODE)
1022 return 0;
1023
1024 return XEXP (op, 0) == stack_pointer_rtx;
1025 }
1026
1027 /* Return 1 if ADDR is a valid memory address for mode MODE. */
1028
1029 int
1030 memory_address_p (mode, addr)
1031 enum machine_mode mode;
1032 register rtx addr;
1033 {
1034 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1035 return 0;
1036
1037 win:
1038 return 1;
1039 }
1040
1041 /* Return 1 if OP is a valid memory reference with mode MODE,
1042 including a valid address.
1043
1044 The main use of this function is as a predicate in match_operand
1045 expressions in the machine description. */
1046
1047 int
1048 memory_operand (op, mode)
1049 register rtx op;
1050 enum machine_mode mode;
1051 {
1052 rtx inner;
1053
1054 if (! reload_completed)
1055 /* Note that no SUBREG is a memory operand before end of reload pass,
1056 because (SUBREG (MEM...)) forces reloading into a register. */
1057 return GET_CODE (op) == MEM && general_operand (op, mode);
1058
1059 if (mode != VOIDmode && GET_MODE (op) != mode)
1060 return 0;
1061
1062 inner = op;
1063 if (GET_CODE (inner) == SUBREG)
1064 inner = SUBREG_REG (inner);
1065
1066 return (GET_CODE (inner) == MEM && general_operand (op, mode));
1067 }
1068
1069 /* Return 1 if OP is a valid indirect memory reference with mode MODE;
1070 that is, a memory reference whose address is a general_operand. */
1071
1072 int
1073 indirect_operand (op, mode)
1074 register rtx op;
1075 enum machine_mode mode;
1076 {
1077 /* Before reload, a SUBREG isn't in memory (see memory_operand, above). */
1078 if (! reload_completed
1079 && GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == MEM)
1080 {
1081 register int offset = SUBREG_WORD (op) * UNITS_PER_WORD;
1082 rtx inner = SUBREG_REG (op);
1083
1084 if (BYTES_BIG_ENDIAN)
1085 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (op)))
1086 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (inner))));
1087
1088 if (mode != VOIDmode && GET_MODE (op) != mode)
1089 return 0;
1090
1091 /* The only way that we can have a general_operand as the resulting
1092 address is if OFFSET is zero and the address already is an operand
1093 or if the address is (plus Y (const_int -OFFSET)) and Y is an
1094 operand. */
1095
1096 return ((offset == 0 && general_operand (XEXP (inner, 0), Pmode))
1097 || (GET_CODE (XEXP (inner, 0)) == PLUS
1098 && GET_CODE (XEXP (XEXP (inner, 0), 1)) == CONST_INT
1099 && INTVAL (XEXP (XEXP (inner, 0), 1)) == -offset
1100 && general_operand (XEXP (XEXP (inner, 0), 0), Pmode)));
1101 }
1102
1103 return (GET_CODE (op) == MEM
1104 && memory_operand (op, mode)
1105 && general_operand (XEXP (op, 0), Pmode));
1106 }
1107
1108 /* Return 1 if this is a comparison operator. This allows the use of
1109 MATCH_OPERATOR to recognize all the branch insns. */
1110
1111 int
1112 comparison_operator (op, mode)
1113 register rtx op;
1114 enum machine_mode mode;
1115 {
1116 return ((mode == VOIDmode || GET_MODE (op) == mode)
1117 && GET_RTX_CLASS (GET_CODE (op)) == '<');
1118 }
1119 \f
1120 /* If BODY is an insn body that uses ASM_OPERANDS,
1121 return the number of operands (both input and output) in the insn.
1122 Otherwise return -1. */
1123
1124 int
1125 asm_noperands (body)
1126 rtx body;
1127 {
1128 if (GET_CODE (body) == ASM_OPERANDS)
1129 /* No output operands: return number of input operands. */
1130 return ASM_OPERANDS_INPUT_LENGTH (body);
1131 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1132 /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
1133 return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (body)) + 1;
1134 else if (GET_CODE (body) == PARALLEL
1135 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1136 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1137 {
1138 /* Multiple output operands, or 1 output plus some clobbers:
1139 body is [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...]. */
1140 int i;
1141 int n_sets;
1142
1143 /* Count backwards through CLOBBERs to determine number of SETs. */
1144 for (i = XVECLEN (body, 0); i > 0; i--)
1145 {
1146 if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
1147 break;
1148 if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
1149 return -1;
1150 }
1151
1152 /* N_SETS is now number of output operands. */
1153 n_sets = i;
1154
1155 /* Verify that all the SETs we have
1156 came from a single original asm_operands insn
1157 (so that invalid combinations are blocked). */
1158 for (i = 0; i < n_sets; i++)
1159 {
1160 rtx elt = XVECEXP (body, 0, i);
1161 if (GET_CODE (elt) != SET)
1162 return -1;
1163 if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
1164 return -1;
1165 /* If these ASM_OPERANDS rtx's came from different original insns
1166 then they aren't allowed together. */
1167 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
1168 != ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (body, 0, 0))))
1169 return -1;
1170 }
1171 return (ASM_OPERANDS_INPUT_LENGTH (SET_SRC (XVECEXP (body, 0, 0)))
1172 + n_sets);
1173 }
1174 else if (GET_CODE (body) == PARALLEL
1175 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1176 {
1177 /* 0 outputs, but some clobbers:
1178 body is [(asm_operands ...) (clobber (reg ...))...]. */
1179 int i;
1180
1181 /* Make sure all the other parallel things really are clobbers. */
1182 for (i = XVECLEN (body, 0) - 1; i > 0; i--)
1183 if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
1184 return -1;
1185
1186 return ASM_OPERANDS_INPUT_LENGTH (XVECEXP (body, 0, 0));
1187 }
1188 else
1189 return -1;
1190 }
1191
1192 /* Assuming BODY is an insn body that uses ASM_OPERANDS,
1193 copy its operands (both input and output) into the vector OPERANDS,
1194 the locations of the operands within the insn into the vector OPERAND_LOCS,
1195 and the constraints for the operands into CONSTRAINTS.
1196 Write the modes of the operands into MODES.
1197 Return the assembler-template.
1198
1199 If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1200 we don't store that info. */
1201
1202 char *
1203 decode_asm_operands (body, operands, operand_locs, constraints, modes)
1204 rtx body;
1205 rtx *operands;
1206 rtx **operand_locs;
1207 char **constraints;
1208 enum machine_mode *modes;
1209 {
1210 register int i;
1211 int noperands;
1212 char *template = 0;
1213
1214 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1215 {
1216 rtx asmop = SET_SRC (body);
1217 /* Single output operand: BODY is (set OUTPUT (asm_operands ....)). */
1218
1219 noperands = ASM_OPERANDS_INPUT_LENGTH (asmop) + 1;
1220
1221 for (i = 1; i < noperands; i++)
1222 {
1223 if (operand_locs)
1224 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i - 1);
1225 if (operands)
1226 operands[i] = ASM_OPERANDS_INPUT (asmop, i - 1);
1227 if (constraints)
1228 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i - 1);
1229 if (modes)
1230 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i - 1);
1231 }
1232
1233 /* The output is in the SET.
1234 Its constraint is in the ASM_OPERANDS itself. */
1235 if (operands)
1236 operands[0] = SET_DEST (body);
1237 if (operand_locs)
1238 operand_locs[0] = &SET_DEST (body);
1239 if (constraints)
1240 constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
1241 if (modes)
1242 modes[0] = GET_MODE (SET_DEST (body));
1243 template = ASM_OPERANDS_TEMPLATE (asmop);
1244 }
1245 else if (GET_CODE (body) == ASM_OPERANDS)
1246 {
1247 rtx asmop = body;
1248 /* No output operands: BODY is (asm_operands ....). */
1249
1250 noperands = ASM_OPERANDS_INPUT_LENGTH (asmop);
1251
1252 /* The input operands are found in the 1st element vector. */
1253 /* Constraints for inputs are in the 2nd element vector. */
1254 for (i = 0; i < noperands; i++)
1255 {
1256 if (operand_locs)
1257 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1258 if (operands)
1259 operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1260 if (constraints)
1261 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1262 if (modes)
1263 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1264 }
1265 template = ASM_OPERANDS_TEMPLATE (asmop);
1266 }
1267 else if (GET_CODE (body) == PARALLEL
1268 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1269 {
1270 rtx asmop = SET_SRC (XVECEXP (body, 0, 0));
1271 int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
1272 int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1273 int nout = 0; /* Does not include CLOBBERs. */
1274
1275 /* At least one output, plus some CLOBBERs. */
1276
1277 /* The outputs are in the SETs.
1278 Their constraints are in the ASM_OPERANDS itself. */
1279 for (i = 0; i < nparallel; i++)
1280 {
1281 if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1282 break; /* Past last SET */
1283
1284 if (operands)
1285 operands[i] = SET_DEST (XVECEXP (body, 0, i));
1286 if (operand_locs)
1287 operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
1288 if (constraints)
1289 constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
1290 if (modes)
1291 modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
1292 nout++;
1293 }
1294
1295 for (i = 0; i < nin; i++)
1296 {
1297 if (operand_locs)
1298 operand_locs[i + nout] = &ASM_OPERANDS_INPUT (asmop, i);
1299 if (operands)
1300 operands[i + nout] = ASM_OPERANDS_INPUT (asmop, i);
1301 if (constraints)
1302 constraints[i + nout] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1303 if (modes)
1304 modes[i + nout] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1305 }
1306
1307 template = ASM_OPERANDS_TEMPLATE (asmop);
1308 }
1309 else if (GET_CODE (body) == PARALLEL
1310 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1311 {
1312 /* No outputs, but some CLOBBERs. */
1313
1314 rtx asmop = XVECEXP (body, 0, 0);
1315 int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1316
1317 for (i = 0; i < nin; i++)
1318 {
1319 if (operand_locs)
1320 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1321 if (operands)
1322 operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1323 if (constraints)
1324 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1325 if (modes)
1326 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1327 }
1328
1329 template = ASM_OPERANDS_TEMPLATE (asmop);
1330 }
1331
1332 return template;
1333 }
1334 \f
1335 /* Given an rtx *P, if it is a sum containing an integer constant term,
1336 return the location (type rtx *) of the pointer to that constant term.
1337 Otherwise, return a null pointer. */
1338
1339 static rtx *
1340 find_constant_term_loc (p)
1341 rtx *p;
1342 {
1343 register rtx *tem;
1344 register enum rtx_code code = GET_CODE (*p);
1345
1346 /* If *P IS such a constant term, P is its location. */
1347
1348 if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1349 || code == CONST)
1350 return p;
1351
1352 /* Otherwise, if not a sum, it has no constant term. */
1353
1354 if (GET_CODE (*p) != PLUS)
1355 return 0;
1356
1357 /* If one of the summands is constant, return its location. */
1358
1359 if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1360 && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1361 return p;
1362
1363 /* Otherwise, check each summand for containing a constant term. */
1364
1365 if (XEXP (*p, 0) != 0)
1366 {
1367 tem = find_constant_term_loc (&XEXP (*p, 0));
1368 if (tem != 0)
1369 return tem;
1370 }
1371
1372 if (XEXP (*p, 1) != 0)
1373 {
1374 tem = find_constant_term_loc (&XEXP (*p, 1));
1375 if (tem != 0)
1376 return tem;
1377 }
1378
1379 return 0;
1380 }
1381 \f
1382 /* Return 1 if OP is a memory reference
1383 whose address contains no side effects
1384 and remains valid after the addition
1385 of a positive integer less than the
1386 size of the object being referenced.
1387
1388 We assume that the original address is valid and do not check it.
1389
1390 This uses strict_memory_address_p as a subroutine, so
1391 don't use it before reload. */
1392
1393 int
1394 offsettable_memref_p (op)
1395 rtx op;
1396 {
1397 return ((GET_CODE (op) == MEM)
1398 && offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
1399 }
1400
1401 /* Similar, but don't require a strictly valid mem ref:
1402 consider pseudo-regs valid as index or base regs. */
1403
1404 int
1405 offsettable_nonstrict_memref_p (op)
1406 rtx op;
1407 {
1408 return ((GET_CODE (op) == MEM)
1409 && offsettable_address_p (0, GET_MODE (op), XEXP (op, 0)));
1410 }
1411
1412 /* Return 1 if Y is a memory address which contains no side effects
1413 and would remain valid after the addition of a positive integer
1414 less than the size of that mode.
1415
1416 We assume that the original address is valid and do not check it.
1417 We do check that it is valid for narrower modes.
1418
1419 If STRICTP is nonzero, we require a strictly valid address,
1420 for the sake of use in reload.c. */
1421
1422 int
1423 offsettable_address_p (strictp, mode, y)
1424 int strictp;
1425 enum machine_mode mode;
1426 register rtx y;
1427 {
1428 register enum rtx_code ycode = GET_CODE (y);
1429 register rtx z;
1430 rtx y1 = y;
1431 rtx *y2;
1432 int (*addressp) () = (strictp ? strict_memory_address_p : memory_address_p);
1433
1434 if (CONSTANT_ADDRESS_P (y))
1435 return 1;
1436
1437 /* Adjusting an offsettable address involves changing to a narrower mode.
1438 Make sure that's OK. */
1439
1440 if (mode_dependent_address_p (y))
1441 return 0;
1442
1443 /* If the expression contains a constant term,
1444 see if it remains valid when max possible offset is added. */
1445
1446 if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
1447 {
1448 int good;
1449
1450 y1 = *y2;
1451 *y2 = plus_constant (*y2, GET_MODE_SIZE (mode) - 1);
1452 /* Use QImode because an odd displacement may be automatically invalid
1453 for any wider mode. But it should be valid for a single byte. */
1454 good = (*addressp) (QImode, y);
1455
1456 /* In any case, restore old contents of memory. */
1457 *y2 = y1;
1458 return good;
1459 }
1460
1461 if (ycode == PRE_DEC || ycode == PRE_INC
1462 || ycode == POST_DEC || ycode == POST_INC)
1463 return 0;
1464
1465 /* The offset added here is chosen as the maximum offset that
1466 any instruction could need to add when operating on something
1467 of the specified mode. We assume that if Y and Y+c are
1468 valid addresses then so is Y+d for all 0<d<c. */
1469
1470 z = plus_constant_for_output (y, GET_MODE_SIZE (mode) - 1);
1471
1472 /* Use QImode because an odd displacement may be automatically invalid
1473 for any wider mode. But it should be valid for a single byte. */
1474 return (*addressp) (QImode, z);
1475 }
1476
1477 /* Return 1 if ADDR is an address-expression whose effect depends
1478 on the mode of the memory reference it is used in.
1479
1480 Autoincrement addressing is a typical example of mode-dependence
1481 because the amount of the increment depends on the mode. */
1482
1483 int
1484 mode_dependent_address_p (addr)
1485 rtx addr;
1486 {
1487 GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
1488 return 0;
1489 win:
1490 return 1;
1491 }
1492
1493 /* Return 1 if OP is a general operand
1494 other than a memory ref with a mode dependent address. */
1495
1496 int
1497 mode_independent_operand (op, mode)
1498 enum machine_mode mode;
1499 rtx op;
1500 {
1501 rtx addr;
1502
1503 if (! general_operand (op, mode))
1504 return 0;
1505
1506 if (GET_CODE (op) != MEM)
1507 return 1;
1508
1509 addr = XEXP (op, 0);
1510 GO_IF_MODE_DEPENDENT_ADDRESS (addr, lose);
1511 return 1;
1512 lose:
1513 return 0;
1514 }
1515
1516 /* Given an operand OP that is a valid memory reference
1517 which satisfies offsettable_memref_p,
1518 return a new memory reference whose address has been adjusted by OFFSET.
1519 OFFSET should be positive and less than the size of the object referenced.
1520 */
1521
1522 rtx
1523 adj_offsettable_operand (op, offset)
1524 rtx op;
1525 int offset;
1526 {
1527 register enum rtx_code code = GET_CODE (op);
1528
1529 if (code == MEM)
1530 {
1531 register rtx y = XEXP (op, 0);
1532 register rtx new;
1533
1534 if (CONSTANT_ADDRESS_P (y))
1535 {
1536 new = gen_rtx (MEM, GET_MODE (op), plus_constant_for_output (y, offset));
1537 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1538 return new;
1539 }
1540
1541 if (GET_CODE (y) == PLUS)
1542 {
1543 rtx z = y;
1544 register rtx *const_loc;
1545
1546 op = copy_rtx (op);
1547 z = XEXP (op, 0);
1548 const_loc = find_constant_term_loc (&z);
1549 if (const_loc)
1550 {
1551 *const_loc = plus_constant_for_output (*const_loc, offset);
1552 return op;
1553 }
1554 }
1555
1556 new = gen_rtx (MEM, GET_MODE (op), plus_constant_for_output (y, offset));
1557 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1558 return new;
1559 }
1560 abort ();
1561 }
1562 \f
1563 #ifdef REGISTER_CONSTRAINTS
1564
1565 /* Check the operands of an insn (found in recog_operands)
1566 against the insn's operand constraints (found via INSN_CODE_NUM)
1567 and return 1 if they are valid.
1568
1569 WHICH_ALTERNATIVE is set to a number which indicates which
1570 alternative of constraints was matched: 0 for the first alternative,
1571 1 for the next, etc.
1572
1573 In addition, when two operands are match
1574 and it happens that the output operand is (reg) while the
1575 input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
1576 make the output operand look like the input.
1577 This is because the output operand is the one the template will print.
1578
1579 This is used in final, just before printing the assembler code and by
1580 the routines that determine an insn's attribute.
1581
1582 If STRICT is a positive non-zero value, it means that we have been
1583 called after reload has been completed. In that case, we must
1584 do all checks strictly. If it is zero, it means that we have been called
1585 before reload has completed. In that case, we first try to see if we can
1586 find an alternative that matches strictly. If not, we try again, this
1587 time assuming that reload will fix up the insn. This provides a "best
1588 guess" for the alternative and is used to compute attributes of insns prior
1589 to reload. A negative value of STRICT is used for this internal call. */
1590
1591 struct funny_match
1592 {
1593 int this, other;
1594 };
1595
1596 int
1597 constrain_operands (insn_code_num, strict)
1598 int insn_code_num;
1599 int strict;
1600 {
1601 char *constraints[MAX_RECOG_OPERANDS];
1602 int matching_operands[MAX_RECOG_OPERANDS];
1603 enum op_type {OP_IN, OP_OUT, OP_INOUT} op_types[MAX_RECOG_OPERANDS];
1604 int earlyclobber[MAX_RECOG_OPERANDS];
1605 register int c;
1606 int noperands = insn_n_operands[insn_code_num];
1607
1608 struct funny_match funny_match[MAX_RECOG_OPERANDS];
1609 int funny_match_index;
1610 int nalternatives = insn_n_alternatives[insn_code_num];
1611
1612 if (noperands == 0 || nalternatives == 0)
1613 return 1;
1614
1615 for (c = 0; c < noperands; c++)
1616 {
1617 constraints[c] = insn_operand_constraint[insn_code_num][c];
1618 matching_operands[c] = -1;
1619 op_types[c] = OP_IN;
1620 }
1621
1622 which_alternative = 0;
1623
1624 while (which_alternative < nalternatives)
1625 {
1626 register int opno;
1627 int lose = 0;
1628 funny_match_index = 0;
1629
1630 for (opno = 0; opno < noperands; opno++)
1631 {
1632 register rtx op = recog_operand[opno];
1633 enum machine_mode mode = GET_MODE (op);
1634 register char *p = constraints[opno];
1635 int offset = 0;
1636 int win = 0;
1637 int val;
1638
1639 earlyclobber[opno] = 0;
1640
1641 if (GET_CODE (op) == SUBREG)
1642 {
1643 if (GET_CODE (SUBREG_REG (op)) == REG
1644 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
1645 offset = SUBREG_WORD (op);
1646 op = SUBREG_REG (op);
1647 }
1648
1649 /* An empty constraint or empty alternative
1650 allows anything which matched the pattern. */
1651 if (*p == 0 || *p == ',')
1652 win = 1;
1653
1654 while (*p && (c = *p++) != ',')
1655 switch (c)
1656 {
1657 case '?':
1658 case '!':
1659 case '*':
1660 case '%':
1661 break;
1662
1663 case '#':
1664 /* Ignore rest of this alternative as far as
1665 constraint checking is concerned. */
1666 while (*p && *p != ',')
1667 p++;
1668 break;
1669
1670 case '=':
1671 op_types[opno] = OP_OUT;
1672 break;
1673
1674 case '+':
1675 op_types[opno] = OP_INOUT;
1676 break;
1677
1678 case '&':
1679 earlyclobber[opno] = 1;
1680 break;
1681
1682 case '0':
1683 case '1':
1684 case '2':
1685 case '3':
1686 case '4':
1687 /* This operand must be the same as a previous one.
1688 This kind of constraint is used for instructions such
1689 as add when they take only two operands.
1690
1691 Note that the lower-numbered operand is passed first.
1692
1693 If we are not testing strictly, assume that this constraint
1694 will be satisfied. */
1695 if (strict < 0)
1696 val = 1;
1697 else
1698 val = operands_match_p (recog_operand[c - '0'],
1699 recog_operand[opno]);
1700
1701 matching_operands[opno] = c - '0';
1702 matching_operands[c - '0'] = opno;
1703
1704 if (val != 0)
1705 win = 1;
1706 /* If output is *x and input is *--x,
1707 arrange later to change the output to *--x as well,
1708 since the output op is the one that will be printed. */
1709 if (val == 2 && strict > 0)
1710 {
1711 funny_match[funny_match_index].this = opno;
1712 funny_match[funny_match_index++].other = c - '0';
1713 }
1714 break;
1715
1716 case 'p':
1717 /* p is used for address_operands. When we are called by
1718 gen_reload, no one will have checked that the address is
1719 strictly valid, i.e., that all pseudos requiring hard regs
1720 have gotten them. */
1721 if (strict <= 0
1722 || (strict_memory_address_p
1723 (insn_operand_mode[insn_code_num][opno], op)))
1724 win = 1;
1725 break;
1726
1727 /* No need to check general_operand again;
1728 it was done in insn-recog.c. */
1729 case 'g':
1730 /* Anything goes unless it is a REG and really has a hard reg
1731 but the hard reg is not in the class GENERAL_REGS. */
1732 if (strict < 0
1733 || GENERAL_REGS == ALL_REGS
1734 || GET_CODE (op) != REG
1735 || (reload_in_progress
1736 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
1737 || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
1738 win = 1;
1739 break;
1740
1741 case 'r':
1742 if (strict < 0
1743 || (strict == 0
1744 && GET_CODE (op) == REG
1745 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
1746 || (strict == 0 && GET_CODE (op) == SCRATCH)
1747 || (GET_CODE (op) == REG
1748 && ((GENERAL_REGS == ALL_REGS
1749 && REGNO (op) < FIRST_PSEUDO_REGISTER)
1750 || reg_fits_class_p (op, GENERAL_REGS,
1751 offset, mode))))
1752 win = 1;
1753 break;
1754
1755 case 'X':
1756 /* This is used for a MATCH_SCRATCH in the cases when we
1757 don't actually need anything. So anything goes any time. */
1758 win = 1;
1759 break;
1760
1761 case 'm':
1762 if (GET_CODE (op) == MEM
1763 /* Before reload, accept what reload can turn into mem. */
1764 || (strict < 0 && CONSTANT_P (op))
1765 /* During reload, accept a pseudo */
1766 || (reload_in_progress && GET_CODE (op) == REG
1767 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
1768 win = 1;
1769 break;
1770
1771 case '<':
1772 if (GET_CODE (op) == MEM
1773 && (GET_CODE (XEXP (op, 0)) == PRE_DEC
1774 || GET_CODE (XEXP (op, 0)) == POST_DEC))
1775 win = 1;
1776 break;
1777
1778 case '>':
1779 if (GET_CODE (op) == MEM
1780 && (GET_CODE (XEXP (op, 0)) == PRE_INC
1781 || GET_CODE (XEXP (op, 0)) == POST_INC))
1782 win = 1;
1783 break;
1784
1785 case 'E':
1786 #ifndef REAL_ARITHMETIC
1787 /* Match any CONST_DOUBLE, but only if
1788 we can examine the bits of it reliably. */
1789 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
1790 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
1791 && GET_MODE (op) != VOIDmode && ! flag_pretend_float)
1792 break;
1793 #endif
1794 if (GET_CODE (op) == CONST_DOUBLE)
1795 win = 1;
1796 break;
1797
1798 case 'F':
1799 if (GET_CODE (op) == CONST_DOUBLE)
1800 win = 1;
1801 break;
1802
1803 case 'G':
1804 case 'H':
1805 if (GET_CODE (op) == CONST_DOUBLE
1806 && CONST_DOUBLE_OK_FOR_LETTER_P (op, c))
1807 win = 1;
1808 break;
1809
1810 case 's':
1811 if (GET_CODE (op) == CONST_INT
1812 || (GET_CODE (op) == CONST_DOUBLE
1813 && GET_MODE (op) == VOIDmode))
1814 break;
1815 case 'i':
1816 if (CONSTANT_P (op))
1817 win = 1;
1818 break;
1819
1820 case 'n':
1821 if (GET_CODE (op) == CONST_INT
1822 || (GET_CODE (op) == CONST_DOUBLE
1823 && GET_MODE (op) == VOIDmode))
1824 win = 1;
1825 break;
1826
1827 case 'I':
1828 case 'J':
1829 case 'K':
1830 case 'L':
1831 case 'M':
1832 case 'N':
1833 case 'O':
1834 case 'P':
1835 if (GET_CODE (op) == CONST_INT
1836 && CONST_OK_FOR_LETTER_P (INTVAL (op), c))
1837 win = 1;
1838 break;
1839
1840 #ifdef EXTRA_CONSTRAINT
1841 case 'Q':
1842 case 'R':
1843 case 'S':
1844 case 'T':
1845 case 'U':
1846 if (EXTRA_CONSTRAINT (op, c))
1847 win = 1;
1848 break;
1849 #endif
1850
1851 case 'V':
1852 if (GET_CODE (op) == MEM
1853 && ! offsettable_memref_p (op))
1854 win = 1;
1855 break;
1856
1857 case 'o':
1858 if ((strict > 0 && offsettable_memref_p (op))
1859 || (strict == 0 && offsettable_nonstrict_memref_p (op))
1860 /* Before reload, accept what reload can handle. */
1861 || (strict < 0
1862 && (CONSTANT_P (op) || GET_CODE (op) == MEM))
1863 /* During reload, accept a pseudo */
1864 || (reload_in_progress && GET_CODE (op) == REG
1865 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
1866 win = 1;
1867 break;
1868
1869 default:
1870 if (strict < 0
1871 || (strict == 0
1872 && GET_CODE (op) == REG
1873 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
1874 || (strict == 0 && GET_CODE (op) == SCRATCH)
1875 || (GET_CODE (op) == REG
1876 && reg_fits_class_p (op, REG_CLASS_FROM_LETTER (c),
1877 offset, mode)))
1878 win = 1;
1879 }
1880
1881 constraints[opno] = p;
1882 /* If this operand did not win somehow,
1883 this alternative loses. */
1884 if (! win)
1885 lose = 1;
1886 }
1887 /* This alternative won; the operands are ok.
1888 Change whichever operands this alternative says to change. */
1889 if (! lose)
1890 {
1891 int opno, eopno;
1892
1893 /* See if any earlyclobber operand conflicts with some other
1894 operand. */
1895
1896 if (strict > 0)
1897 for (eopno = 0; eopno < noperands; eopno++)
1898 /* Ignore earlyclobber operands now in memory,
1899 because we would often report failure when we have
1900 two memory operands, one of which was formerly a REG. */
1901 if (earlyclobber[eopno]
1902 && GET_CODE (recog_operand[eopno]) == REG)
1903 for (opno = 0; opno < noperands; opno++)
1904 if ((GET_CODE (recog_operand[opno]) == MEM
1905 || op_types[opno] != OP_OUT)
1906 && opno != eopno
1907 /* Ignore things like match_operator operands. */
1908 && *constraints[opno] != 0
1909 && ! (matching_operands[opno] == eopno
1910 && rtx_equal_p (recog_operand[opno],
1911 recog_operand[eopno]))
1912 && ! safe_from_earlyclobber (recog_operand[opno],
1913 recog_operand[eopno]))
1914 lose = 1;
1915
1916 if (! lose)
1917 {
1918 while (--funny_match_index >= 0)
1919 {
1920 recog_operand[funny_match[funny_match_index].other]
1921 = recog_operand[funny_match[funny_match_index].this];
1922 }
1923
1924 return 1;
1925 }
1926 }
1927
1928 which_alternative++;
1929 }
1930
1931 /* If we are about to reject this, but we are not to test strictly,
1932 try a very loose test. Only return failure if it fails also. */
1933 if (strict == 0)
1934 return constrain_operands (insn_code_num, -1);
1935 else
1936 return 0;
1937 }
1938
1939 /* Return 1 iff OPERAND (assumed to be a REG rtx)
1940 is a hard reg in class CLASS when its regno is offsetted by OFFSET
1941 and changed to mode MODE.
1942 If REG occupies multiple hard regs, all of them must be in CLASS. */
1943
1944 int
1945 reg_fits_class_p (operand, class, offset, mode)
1946 rtx operand;
1947 register enum reg_class class;
1948 int offset;
1949 enum machine_mode mode;
1950 {
1951 register int regno = REGNO (operand);
1952 if (regno < FIRST_PSEUDO_REGISTER
1953 && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1954 regno + offset))
1955 {
1956 register int sr;
1957 regno += offset;
1958 for (sr = HARD_REGNO_NREGS (regno, mode) - 1;
1959 sr > 0; sr--)
1960 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1961 regno + sr))
1962 break;
1963 return sr == 0;
1964 }
1965
1966 return 0;
1967 }
1968
1969 #endif /* REGISTER_CONSTRAINTS */
This page took 0.129847 seconds and 6 git commands to generate.