OSDN Git Service

entered into RCS
[pf3gnuchains/gcc-fork.git] / gcc / recog.c
1 /* Subroutines used by or related to instruction recognition.
2    Copyright (C) 1987, 1988, 1991, 1992 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 #endif
431
432           new = gen_rtx (MEM, mode, plus_constant (XEXP (to, 0), offset));
433           MEM_VOLATILE_P (new) = MEM_VOLATILE_P (to);
434           RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (to);
435           MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (to);
436           validate_change (object, loc, new, 1);
437           return;
438         }
439       break;
440
441     case ZERO_EXTRACT:
442     case SIGN_EXTRACT:
443       /* If we are replacing a register with memory, try to change the memory
444          to be the mode required for memory in extract operations (this isn't
445          likely to be an insertion operation; if it was, nothing bad will
446          happen, we might just fail in some cases).  */
447
448       if (XEXP (x, 0) == from && GET_CODE (from) == REG && GET_CODE (to) == MEM
449           && GET_CODE (XEXP (x, 1)) == CONST_INT
450           && GET_CODE (XEXP (x, 2)) == CONST_INT
451           && ! mode_dependent_address_p (XEXP (to, 0))
452           && ! MEM_VOLATILE_P (to))
453         {
454           enum machine_mode wanted_mode = VOIDmode;
455           enum machine_mode is_mode = GET_MODE (to);
456           int width = INTVAL (XEXP (x, 1));
457           int pos = INTVAL (XEXP (x, 2));
458
459 #ifdef HAVE_extzv
460           if (code == ZERO_EXTRACT)
461             wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
462 #endif
463 #ifdef HAVE_extv
464           if (code == SIGN_EXTRACT)
465             wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
466 #endif
467
468           /* If we have a narrower mode, we can do something.  */
469           if (wanted_mode != VOIDmode
470               && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
471             {
472               int offset = pos / BITS_PER_UNIT;
473               rtx newmem;
474
475                   /* If the bytes and bits are counted differently, we
476                      must adjust the offset.  */
477 #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
478               offset = (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode)
479                         - offset);
480 #endif
481
482               pos %= GET_MODE_BITSIZE (wanted_mode);
483
484               newmem = gen_rtx (MEM, wanted_mode,
485                                 plus_constant (XEXP (to, 0), offset));
486               RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (to);
487               MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (to);
488               MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (to);
489
490               validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
491               validate_change (object, &XEXP (x, 0), newmem, 1);
492             }
493         }
494
495       break;
496     }
497       
498   fmt = GET_RTX_FORMAT (code);
499   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
500     {
501       if (fmt[i] == 'e')
502         validate_replace_rtx_1 (&XEXP (x, i), from, to, object);
503       else if (fmt[i] == 'E')
504         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
505           validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object);
506     }
507 }
508
509 /* Try replacing every occurrence of FROM in INSN with TO.  After all
510    changes have been made, validate by seeing if INSN is still valid.  */
511
512 int
513 validate_replace_rtx (from, to, insn)
514      rtx from, to, insn;
515 {
516   validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
517   return apply_change_group ();
518 }
519 \f
520 #ifdef HAVE_cc0
521 /* Return 1 if the insn using CC0 set by INSN does not contain
522    any ordered tests applied to the condition codes.
523    EQ and NE tests do not count.  */
524
525 int
526 next_insn_tests_no_inequality (insn)
527      rtx insn;
528 {
529   register rtx next = next_cc0_user (insn);
530
531   /* If there is no next insn, we have to take the conservative choice.  */
532   if (next == 0)
533     return 0;
534
535   return ((GET_CODE (next) == JUMP_INSN
536            || GET_CODE (next) == INSN
537            || GET_CODE (next) == CALL_INSN)
538           && ! inequality_comparisons_p (PATTERN (next)));
539 }
540
541 #if 0  /* This is useless since the insn that sets the cc's
542           must be followed immediately by the use of them.  */
543 /* Return 1 if the CC value set up by INSN is not used.  */
544
545 int
546 next_insns_test_no_inequality (insn)
547      rtx insn;
548 {
549   register rtx next = NEXT_INSN (insn);
550
551   for (; next != 0; next = NEXT_INSN (next))
552     {
553       if (GET_CODE (next) == CODE_LABEL
554           || GET_CODE (next) == BARRIER)
555         return 1;
556       if (GET_CODE (next) == NOTE)
557         continue;
558       if (inequality_comparisons_p (PATTERN (next)))
559         return 0;
560       if (sets_cc0_p (PATTERN (next)) == 1)
561         return 1;
562       if (! reg_mentioned_p (cc0_rtx, PATTERN (next)))
563         return 1;
564     }
565   return 1;
566 }
567 #endif
568 #endif
569 \f
570 /* This is used by find_single_use to locate an rtx that contains exactly one
571    use of DEST, which is typically either a REG or CC0.  It returns a
572    pointer to the innermost rtx expression containing DEST.  Appearances of
573    DEST that are being used to totally replace it are not counted.  */
574
575 static rtx *
576 find_single_use_1 (dest, loc)
577      rtx dest;
578      rtx *loc;
579 {
580   rtx x = *loc;
581   enum rtx_code code = GET_CODE (x);
582   rtx *result = 0;
583   rtx *this_result;
584   int i;
585   char *fmt;
586
587   switch (code)
588     {
589     case CONST_INT:
590     case CONST:
591     case LABEL_REF:
592     case SYMBOL_REF:
593     case CONST_DOUBLE:
594     case CLOBBER:
595       return 0;
596
597     case SET:
598       /* If the destination is anything other than CC0, PC, a REG or a SUBREG
599          of a REG that occupies all of the REG, the insn uses DEST if
600          it is mentioned in the destination or the source.  Otherwise, we
601          need just check the source.  */
602       if (GET_CODE (SET_DEST (x)) != CC0
603           && GET_CODE (SET_DEST (x)) != PC
604           && GET_CODE (SET_DEST (x)) != REG
605           && ! (GET_CODE (SET_DEST (x)) == SUBREG
606                 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
607                 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (x))))
608                       + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
609                     == ((GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
610                          + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
611         break;
612
613       return find_single_use_1 (dest, &SET_SRC (x));
614
615     case MEM:
616     case SUBREG:
617       return find_single_use_1 (dest, &XEXP (x, 0));
618     }
619
620   /* If it wasn't one of the common cases above, check each expression and
621      vector of this code.  Look for a unique usage of DEST.  */
622
623   fmt = GET_RTX_FORMAT (code);
624   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
625     {
626       if (fmt[i] == 'e')
627         {
628           if (dest == XEXP (x, i)
629               || (GET_CODE (dest) == REG && GET_CODE (XEXP (x, i)) == REG
630                   && REGNO (dest) == REGNO (XEXP (x, i))))
631             this_result = loc;
632           else
633             this_result = find_single_use_1 (dest, &XEXP (x, i));
634
635           if (result == 0)
636             result = this_result;
637           else if (this_result)
638             /* Duplicate usage.  */
639             return 0;
640         }
641       else if (fmt[i] == 'E')
642         {
643           int j;
644
645           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
646             {
647               if (XVECEXP (x, i, j) == dest
648                   || (GET_CODE (dest) == REG
649                       && GET_CODE (XVECEXP (x, i, j)) == REG
650                       && REGNO (XVECEXP (x, i, j)) == REGNO (dest)))
651                 this_result = loc;
652               else
653                 this_result = find_single_use_1 (dest, &XVECEXP (x, i, j));
654
655               if (result == 0)
656                 result = this_result;
657               else if (this_result)
658                 return 0;
659             }
660         }
661     }
662
663   return result;
664 }
665 \f
666 /* See if DEST, produced in INSN, is used only a single time in the
667    sequel.  If so, return a pointer to the innermost rtx expression in which
668    it is used.
669
670    If PLOC is non-zero, *PLOC is set to the insn containing the single use.
671
672    This routine will return usually zero either before flow is called (because
673    there will be no LOG_LINKS notes) or after reload (because the REG_DEAD
674    note can't be trusted).
675
676    If DEST is cc0_rtx, we look only at the next insn.  In that case, we don't
677    care about REG_DEAD notes or LOG_LINKS.
678
679    Otherwise, we find the single use by finding an insn that has a
680    LOG_LINKS pointing at INSN and has a REG_DEAD note for DEST.  If DEST is
681    only referenced once in that insn, we know that it must be the first
682    and last insn referencing DEST.  */
683
684 rtx *
685 find_single_use (dest, insn, ploc)
686      rtx dest;
687      rtx insn;
688      rtx *ploc;
689 {
690   rtx next;
691   rtx *result;
692   rtx link;
693
694 #ifdef HAVE_cc0
695   if (dest == cc0_rtx)
696     {
697       next = NEXT_INSN (insn);
698       if (next == 0
699           || (GET_CODE (next) != INSN && GET_CODE (next) != JUMP_INSN))
700         return 0;
701
702       result = find_single_use_1 (dest, &PATTERN (next));
703       if (result && ploc)
704         *ploc = next;
705       return result;
706     }
707 #endif
708
709   if (reload_completed || reload_in_progress || GET_CODE (dest) != REG)
710     return 0;
711
712   for (next = next_nonnote_insn (insn);
713        next != 0 && GET_CODE (next) != CODE_LABEL;
714        next = next_nonnote_insn (next))
715     if (GET_RTX_CLASS (GET_CODE (next)) == 'i' && dead_or_set_p (next, dest))
716       {
717         for (link = LOG_LINKS (next); link; link = XEXP (link, 1))
718           if (XEXP (link, 0) == insn)
719             break;
720
721         if (link)
722           {
723             result = find_single_use_1 (dest, &PATTERN (next));
724             if (ploc)
725               *ploc = next;
726             return result;
727           }
728       }
729
730   return 0;
731 }
732 \f
733 /* Return 1 if OP is a valid general operand for machine mode MODE.
734    This is either a register reference, a memory reference,
735    or a constant.  In the case of a memory reference, the address
736    is checked for general validity for the target machine.
737
738    Register and memory references must have mode MODE in order to be valid,
739    but some constants have no machine mode and are valid for any mode.
740
741    If MODE is VOIDmode, OP is checked for validity for whatever mode
742    it has.
743
744    The main use of this function is as a predicate in match_operand
745    expressions in the machine description.
746
747    For an explanation of this function's behavior for registers of
748    class NO_REGS, see the comment for `register_operand'.  */
749
750 int
751 general_operand (op, mode)
752      register rtx op;
753      enum machine_mode mode;
754 {
755   register enum rtx_code code = GET_CODE (op);
756   int mode_altering_drug = 0;
757
758   if (mode == VOIDmode)
759     mode = GET_MODE (op);
760
761   /* Don't accept CONST_INT or anything similar
762      if the caller wants something floating.  */
763   if (GET_MODE (op) == VOIDmode && mode != VOIDmode
764       && GET_MODE_CLASS (mode) != MODE_INT)
765     return 0;
766
767   if (CONSTANT_P (op))
768     return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
769 #ifdef LEGITIMATE_PIC_OPERAND_P
770             && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
771 #endif
772             && LEGITIMATE_CONSTANT_P (op));
773
774   /* Except for certain constants with VOIDmode, already checked for,
775      OP's mode must match MODE if MODE specifies a mode.  */
776
777   if (GET_MODE (op) != mode)
778     return 0;
779
780   if (code == SUBREG)
781     {
782 #ifdef INSN_SCHEDULING
783       /* On machines that have insn scheduling, we want all memory
784          reference to be explicit, so outlaw paradoxical SUBREGs.  */
785       if (GET_CODE (SUBREG_REG (op)) == MEM
786           && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))))
787         return 0;
788 #endif
789
790       op = SUBREG_REG (op);
791       code = GET_CODE (op);
792 #if 0
793       /* No longer needed, since (SUBREG (MEM...))
794          will load the MEM into a reload reg in the MEM's own mode.  */
795       mode_altering_drug = 1;
796 #endif
797     }
798
799   if (code == REG)
800     /* A register whose class is NO_REGS is not a general operand.  */
801     return (REGNO (op) >= FIRST_PSEUDO_REGISTER
802             || REGNO_REG_CLASS (REGNO (op)) != NO_REGS);
803
804   if (code == MEM)
805     {
806       register rtx y = XEXP (op, 0);
807       if (! volatile_ok && MEM_VOLATILE_P (op))
808         return 0;
809       /* Use the mem's mode, since it will be reloaded thus.  */
810       mode = GET_MODE (op);
811       GO_IF_LEGITIMATE_ADDRESS (mode, y, win);
812     }
813   return 0;
814
815  win:
816   if (mode_altering_drug)
817     return ! mode_dependent_address_p (XEXP (op, 0));
818   return 1;
819 }
820 \f
821 /* Return 1 if OP is a valid memory address for a memory reference
822    of mode MODE.
823
824    The main use of this function is as a predicate in match_operand
825    expressions in the machine description.  */
826
827 int
828 address_operand (op, mode)
829      register rtx op;
830      enum machine_mode mode;
831 {
832   return memory_address_p (mode, op);
833 }
834
835 /* Return 1 if OP is a register reference of mode MODE.
836    If MODE is VOIDmode, accept a register in any mode.
837
838    The main use of this function is as a predicate in match_operand
839    expressions in the machine description.
840
841    As a special exception, registers whose class is NO_REGS are
842    not accepted by `register_operand'.  The reason for this change
843    is to allow the representation of special architecture artifacts
844    (such as a condition code register) without extending the rtl
845    definitions.  Since registers of class NO_REGS cannot be used
846    as registers in any case where register classes are examined,
847    it is most consistent to keep this function from accepting them.  */
848
849 int
850 register_operand (op, mode)
851      register rtx op;
852      enum machine_mode mode;
853 {
854   if (GET_MODE (op) != mode && mode != VOIDmode)
855     return 0;
856
857   if (GET_CODE (op) == SUBREG)
858     {
859       /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
860          because it is guaranteed to be reloaded into one.
861          Just make sure the MEM is valid in itself.
862          (Ideally, (SUBREG (MEM)...) should not exist after reload,
863          but currently it does result from (SUBREG (REG)...) where the
864          reg went on the stack.)  */
865       if (! reload_completed && GET_CODE (SUBREG_REG (op)) == MEM)
866         return general_operand (op, mode);
867       op = SUBREG_REG (op);
868     }
869
870   /* We don't consider registers whose class is NO_REGS
871      to be a register operand.  */
872   return (GET_CODE (op) == REG
873           && (REGNO (op) >= FIRST_PSEUDO_REGISTER
874               || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
875 }
876
877 /* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
878    or a hard register.  */
879
880 int
881 scratch_operand (op, mode)
882      register rtx op;
883      enum machine_mode mode;
884 {
885   return (GET_MODE (op) == mode
886           && (GET_CODE (op) == SCRATCH
887               || (GET_CODE (op) == REG
888                   && REGNO (op) < FIRST_PSEUDO_REGISTER)));
889 }
890
891 /* Return 1 if OP is a valid immediate operand for mode MODE.
892
893    The main use of this function is as a predicate in match_operand
894    expressions in the machine description.  */
895
896 int
897 immediate_operand (op, mode)
898      register rtx op;
899      enum machine_mode mode;
900 {
901   /* Don't accept CONST_INT or anything similar
902      if the caller wants something floating.  */
903   if (GET_MODE (op) == VOIDmode && mode != VOIDmode
904       && GET_MODE_CLASS (mode) != MODE_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     return 0;
939
940   return ((GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT)
941           && (mode == VOIDmode || GET_MODE (op) == mode
942               || GET_MODE (op) == VOIDmode));
943 }
944
945 /* Return 1 if OP is a general operand that is not an immediate operand.  */
946
947 int
948 nonimmediate_operand (op, mode)
949      register rtx op;
950      enum machine_mode mode;
951 {
952   return (general_operand (op, mode) && ! CONSTANT_P (op));
953 }
954
955 /* Return 1 if OP is a register reference or immediate value of mode MODE.  */
956
957 int
958 nonmemory_operand (op, mode)
959      register rtx op;
960      enum machine_mode mode;
961 {
962   if (CONSTANT_P (op))
963     {
964       /* Don't accept CONST_INT or anything similar
965          if the caller wants something floating.  */
966       if (GET_MODE (op) == VOIDmode && mode != VOIDmode
967           && GET_MODE_CLASS (mode) != MODE_INT)
968         return 0;
969
970       return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
971 #ifdef LEGITIMATE_PIC_OPERAND_P
972               && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
973 #endif
974               && LEGITIMATE_CONSTANT_P (op));
975     }
976
977   if (GET_MODE (op) != mode && mode != VOIDmode)
978     return 0;
979
980   if (GET_CODE (op) == SUBREG)
981     {
982       /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
983          because it is guaranteed to be reloaded into one.
984          Just make sure the MEM is valid in itself.
985          (Ideally, (SUBREG (MEM)...) should not exist after reload,
986          but currently it does result from (SUBREG (REG)...) where the
987          reg went on the stack.)  */
988       if (! reload_completed && GET_CODE (SUBREG_REG (op)) == MEM)
989         return general_operand (op, mode);
990       op = SUBREG_REG (op);
991     }
992
993   /* We don't consider registers whose class is NO_REGS
994      to be a register operand.  */
995   return (GET_CODE (op) == REG
996           && (REGNO (op) >= FIRST_PSEUDO_REGISTER
997               || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
998 }
999
1000 /* Return 1 if OP is a valid operand that stands for pushing a
1001    value of mode MODE onto the stack.
1002
1003    The main use of this function is as a predicate in match_operand
1004    expressions in the machine description.  */
1005
1006 int
1007 push_operand (op, mode)
1008      rtx op;
1009      enum machine_mode mode;
1010 {
1011   if (GET_CODE (op) != MEM)
1012     return 0;
1013
1014   if (GET_MODE (op) != mode)
1015     return 0;
1016
1017   op = XEXP (op, 0);
1018
1019   if (GET_CODE (op) != STACK_PUSH_CODE)
1020     return 0;
1021
1022   return XEXP (op, 0) == stack_pointer_rtx;
1023 }
1024
1025 /* Return 1 if ADDR is a valid memory address for mode MODE.  */
1026
1027 int
1028 memory_address_p (mode, addr)
1029      enum machine_mode mode;
1030      register rtx addr;
1031 {
1032   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1033   return 0;
1034
1035  win:
1036   return 1;
1037 }
1038
1039 /* Return 1 if OP is a valid memory reference with mode MODE,
1040    including a valid address.
1041
1042    The main use of this function is as a predicate in match_operand
1043    expressions in the machine description.  */
1044
1045 int
1046 memory_operand (op, mode)
1047      register rtx op;
1048      enum machine_mode mode;
1049 {
1050   rtx inner;
1051
1052   if (! reload_completed)
1053     /* Note that no SUBREG is a memory operand before end of reload pass,
1054        because (SUBREG (MEM...)) forces reloading into a register.  */
1055     return GET_CODE (op) == MEM && general_operand (op, mode);
1056
1057   if (mode != VOIDmode && GET_MODE (op) != mode)
1058     return 0;
1059
1060   inner = op;
1061   if (GET_CODE (inner) == SUBREG)
1062     inner = SUBREG_REG (inner);
1063
1064   return (GET_CODE (inner) == MEM && general_operand (op, mode));
1065 }
1066
1067 /* Return 1 if OP is a valid indirect memory reference with mode MODE;
1068    that is, a memory reference whose address is a general_operand.  */
1069
1070 int
1071 indirect_operand (op, mode)
1072      register rtx op;
1073      enum machine_mode mode;
1074 {
1075   /* Before reload, a SUBREG isn't in memory (see memory_operand, above).  */
1076   if (! reload_completed
1077       && GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == MEM)
1078     {
1079       register int offset = SUBREG_WORD (op) * UNITS_PER_WORD;
1080       rtx inner = SUBREG_REG (op);
1081
1082 #if BYTES_BIG_ENDIAN
1083       offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (op)))
1084                  - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (inner))));
1085 #endif
1086
1087       /* The only way that we can have a general_operand as the resulting
1088          address is if OFFSET is zero and the address already is an operand
1089          or if the address is (plus Y (const_int -OFFSET)) and Y is an
1090          operand.  */
1091
1092       return ((offset == 0 && general_operand (XEXP (inner, 0), Pmode))
1093               || (GET_CODE (XEXP (inner, 0)) == PLUS
1094                   && GET_CODE (XEXP (XEXP (inner, 0), 1)) == CONST_INT
1095                   && INTVAL (XEXP (XEXP (inner, 0), 1)) == -offset
1096                   && general_operand (XEXP (XEXP (inner, 0), 0), Pmode)));
1097     }
1098
1099   return (GET_CODE (op) == MEM
1100           && memory_operand (op, mode)
1101           && general_operand (XEXP (op, 0), Pmode));
1102 }
1103
1104 /* Return 1 if this is a comparison operator.  This allows the use of
1105    MATCH_OPERATOR to recognize all the branch insns.  */
1106
1107 int
1108 comparison_operator (op, mode)
1109     register rtx op;
1110     enum machine_mode mode;
1111 {
1112   return ((mode == VOIDmode || GET_MODE (op) == mode)
1113           && GET_RTX_CLASS (GET_CODE (op)) == '<');
1114 }
1115 \f
1116 /* If BODY is an insn body that uses ASM_OPERANDS,
1117    return the number of operands (both input and output) in the insn.
1118    Otherwise return -1.  */
1119
1120 int
1121 asm_noperands (body)
1122      rtx body;
1123 {
1124   if (GET_CODE (body) == ASM_OPERANDS)
1125     /* No output operands: return number of input operands.  */
1126     return ASM_OPERANDS_INPUT_LENGTH (body);
1127   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1128     /* Single output operand: BODY is (set OUTPUT (asm_operands ...)).  */
1129     return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (body)) + 1;
1130   else if (GET_CODE (body) == PARALLEL
1131            && GET_CODE (XVECEXP (body, 0, 0)) == SET
1132            && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1133     {
1134       /* Multiple output operands, or 1 output plus some clobbers:
1135          body is [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...].  */
1136       int i;
1137       int n_sets;
1138
1139       /* Count backwards through CLOBBERs to determine number of SETs.  */
1140       for (i = XVECLEN (body, 0); i > 0; i--)
1141         {
1142           if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
1143             break;
1144           if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
1145             return -1;
1146         }
1147
1148       /* N_SETS is now number of output operands.  */
1149       n_sets = i;
1150
1151       /* Verify that all the SETs we have
1152          came from a single original asm_operands insn
1153          (so that invalid combinations are blocked).  */
1154       for (i = 0; i < n_sets; i++)
1155         {
1156           rtx elt = XVECEXP (body, 0, i);
1157           if (GET_CODE (elt) != SET)
1158             return -1;
1159           if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
1160             return -1;
1161           /* If these ASM_OPERANDS rtx's came from different original insns
1162              then they aren't allowed together.  */
1163           if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
1164               != ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (body, 0, 0))))
1165             return -1;
1166         }
1167       return (ASM_OPERANDS_INPUT_LENGTH (SET_SRC (XVECEXP (body, 0, 0)))
1168               + n_sets);
1169     }
1170   else if (GET_CODE (body) == PARALLEL
1171            && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1172     {
1173       /* 0 outputs, but some clobbers:
1174          body is [(asm_operands ...) (clobber (reg ...))...].  */
1175       int i;
1176
1177       /* Make sure all the other parallel things really are clobbers.  */
1178       for (i = XVECLEN (body, 0) - 1; i > 0; i--)
1179         if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
1180           return -1;
1181
1182       return ASM_OPERANDS_INPUT_LENGTH (XVECEXP (body, 0, 0));
1183     }
1184   else
1185     return -1;
1186 }
1187
1188 /* Assuming BODY is an insn body that uses ASM_OPERANDS,
1189    copy its operands (both input and output) into the vector OPERANDS,
1190    the locations of the operands within the insn into the vector OPERAND_LOCS,
1191    and the constraints for the operands into CONSTRAINTS.
1192    Write the modes of the operands into MODES.
1193    Return the assembler-template.
1194
1195    If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1196    we don't store that info.  */
1197
1198 char *
1199 decode_asm_operands (body, operands, operand_locs, constraints, modes)
1200      rtx body;
1201      rtx *operands;
1202      rtx **operand_locs;
1203      char **constraints;
1204      enum machine_mode *modes;
1205 {
1206   register int i;
1207   int noperands;
1208   char *template = 0;
1209
1210   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1211     {
1212       rtx asmop = SET_SRC (body);
1213       /* Single output operand: BODY is (set OUTPUT (asm_operands ....)).  */
1214
1215       noperands = ASM_OPERANDS_INPUT_LENGTH (asmop) + 1;
1216
1217       for (i = 1; i < noperands; i++)
1218         {
1219           if (operand_locs)
1220             operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i - 1);
1221           if (operands)
1222             operands[i] = ASM_OPERANDS_INPUT (asmop, i - 1);
1223           if (constraints)
1224             constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i - 1);
1225           if (modes)
1226             modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i - 1);
1227         }
1228
1229       /* The output is in the SET.
1230          Its constraint is in the ASM_OPERANDS itself.  */
1231       if (operands)
1232         operands[0] = SET_DEST (body);
1233       if (operand_locs)
1234         operand_locs[0] = &SET_DEST (body);
1235       if (constraints)
1236         constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
1237       if (modes)
1238         modes[0] = GET_MODE (SET_DEST (body));
1239       template = ASM_OPERANDS_TEMPLATE (asmop);
1240     }
1241   else if (GET_CODE (body) == ASM_OPERANDS)
1242     {
1243       rtx asmop = body;
1244       /* No output operands: BODY is (asm_operands ....).  */
1245
1246       noperands = ASM_OPERANDS_INPUT_LENGTH (asmop);
1247
1248       /* The input operands are found in the 1st element vector.  */
1249       /* Constraints for inputs are in the 2nd element vector.  */
1250       for (i = 0; i < noperands; i++)
1251         {
1252           if (operand_locs)
1253             operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1254           if (operands)
1255             operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1256           if (constraints)
1257             constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1258           if (modes)
1259             modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1260         }
1261       template = ASM_OPERANDS_TEMPLATE (asmop);
1262     }
1263   else if (GET_CODE (body) == PARALLEL
1264            && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1265     {
1266       rtx asmop = SET_SRC (XVECEXP (body, 0, 0));
1267       int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs.  */
1268       int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1269       int nout = 0;             /* Does not include CLOBBERs.  */
1270
1271       /* At least one output, plus some CLOBBERs.  */
1272
1273       /* The outputs are in the SETs.
1274          Their constraints are in the ASM_OPERANDS itself.  */
1275       for (i = 0; i < nparallel; i++)
1276         {
1277           if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1278             break;              /* Past last SET */
1279           
1280           if (operands)
1281             operands[i] = SET_DEST (XVECEXP (body, 0, i));
1282           if (operand_locs)
1283             operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
1284           if (constraints)
1285             constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
1286           if (modes)
1287             modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
1288           nout++;
1289         }
1290
1291       for (i = 0; i < nin; i++)
1292         {
1293           if (operand_locs)
1294             operand_locs[i + nout] = &ASM_OPERANDS_INPUT (asmop, i);
1295           if (operands)
1296             operands[i + nout] = ASM_OPERANDS_INPUT (asmop, i);
1297           if (constraints)
1298             constraints[i + nout] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1299           if (modes)
1300             modes[i + nout] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1301         }
1302
1303       template = ASM_OPERANDS_TEMPLATE (asmop);
1304     }
1305   else if (GET_CODE (body) == PARALLEL
1306            && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1307     {
1308       /* No outputs, but some CLOBBERs.  */
1309
1310       rtx asmop = XVECEXP (body, 0, 0);
1311       int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1312
1313       for (i = 0; i < nin; i++)
1314         {
1315           if (operand_locs)
1316             operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1317           if (operands)
1318             operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1319           if (constraints)
1320             constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1321           if (modes)
1322             modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1323         }
1324
1325       template = ASM_OPERANDS_TEMPLATE (asmop);
1326     }
1327
1328   return template;
1329 }
1330 \f
1331 /* Given an rtx *P, if it is a sum containing an integer constant term,
1332    return the location (type rtx *) of the pointer to that constant term.
1333    Otherwise, return a null pointer.  */
1334
1335 static rtx *
1336 find_constant_term_loc (p)
1337      rtx *p;
1338 {
1339   register rtx *tem;
1340   register enum rtx_code code = GET_CODE (*p);
1341
1342   /* If *P IS such a constant term, P is its location.  */
1343
1344   if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1345       || code == CONST)
1346     return p;
1347
1348   /* Otherwise, if not a sum, it has no constant term.  */
1349
1350   if (GET_CODE (*p) != PLUS)
1351     return 0;
1352
1353   /* If one of the summands is constant, return its location.  */
1354
1355   if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1356       && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1357     return p;
1358
1359   /* Otherwise, check each summand for containing a constant term.  */
1360
1361   if (XEXP (*p, 0) != 0)
1362     {
1363       tem = find_constant_term_loc (&XEXP (*p, 0));
1364       if (tem != 0)
1365         return tem;
1366     }
1367
1368   if (XEXP (*p, 1) != 0)
1369     {
1370       tem = find_constant_term_loc (&XEXP (*p, 1));
1371       if (tem != 0)
1372         return tem;
1373     }
1374
1375   return 0;
1376 }
1377 \f
1378 /* Return 1 if OP is a memory reference
1379    whose address contains no side effects
1380    and remains valid after the addition
1381    of a positive integer less than the
1382    size of the object being referenced.
1383
1384    We assume that the original address is valid and do not check it.
1385
1386    This uses strict_memory_address_p as a subroutine, so
1387    don't use it before reload.  */
1388
1389 int
1390 offsettable_memref_p (op)
1391      rtx op;
1392 {
1393   return ((GET_CODE (op) == MEM)
1394           && offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
1395 }
1396
1397 /* Similar, but don't require a strictly valid mem ref:
1398    consider pseudo-regs valid as index or base regs.  */
1399
1400 int
1401 offsettable_nonstrict_memref_p (op)
1402      rtx op;
1403 {
1404   return ((GET_CODE (op) == MEM)
1405           && offsettable_address_p (0, GET_MODE (op), XEXP (op, 0)));
1406 }
1407
1408 /* Return 1 if Y is a memory address which contains no side effects
1409    and would remain valid after the addition of a positive integer
1410    less than the size of that mode.
1411
1412    We assume that the original address is valid and do not check it.
1413    We do check that it is valid for narrower modes.
1414
1415    If STRICTP is nonzero, we require a strictly valid address,
1416    for the sake of use in reload.c.  */
1417
1418 int
1419 offsettable_address_p (strictp, mode, y)
1420      int strictp;
1421      enum machine_mode mode;
1422      register rtx y;
1423 {
1424   register enum rtx_code ycode = GET_CODE (y);
1425   register rtx z;
1426   rtx y1 = y;
1427   rtx *y2;
1428   int (*addressp) () = (strictp ? strict_memory_address_p : memory_address_p);
1429
1430   if (CONSTANT_ADDRESS_P (y))
1431     return 1;
1432
1433   /* Adjusting an offsettable address involves changing to a narrower mode.
1434      Make sure that's OK.  */
1435
1436   if (mode_dependent_address_p (y))
1437     return 0;
1438
1439   /* If the expression contains a constant term,
1440      see if it remains valid when max possible offset is added.  */
1441
1442   if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
1443     {
1444       int good;
1445
1446       y1 = *y2;
1447       *y2 = plus_constant (*y2, GET_MODE_SIZE (mode) - 1);
1448       /* Use QImode because an odd displacement may be automatically invalid
1449          for any wider mode.  But it should be valid for a single byte.  */
1450       good = (*addressp) (QImode, y);
1451
1452       /* In any case, restore old contents of memory.  */
1453       *y2 = y1;
1454       return good;
1455     }
1456
1457   if (ycode == PRE_DEC || ycode == PRE_INC
1458       || ycode == POST_DEC || ycode == POST_INC)
1459     return 0;
1460
1461   /* The offset added here is chosen as the maximum offset that
1462      any instruction could need to add when operating on something
1463      of the specified mode.  We assume that if Y and Y+c are
1464      valid addresses then so is Y+d for all 0<d<c.  */
1465
1466   z = plus_constant_for_output (y, GET_MODE_SIZE (mode) - 1);
1467
1468   /* Use QImode because an odd displacement may be automatically invalid
1469      for any wider mode.  But it should be valid for a single byte.  */
1470   return (*addressp) (QImode, z);
1471 }
1472
1473 /* Return 1 if ADDR is an address-expression whose effect depends
1474    on the mode of the memory reference it is used in.
1475
1476    Autoincrement addressing is a typical example of mode-dependence
1477    because the amount of the increment depends on the mode.  */
1478
1479 int
1480 mode_dependent_address_p (addr)
1481      rtx addr;
1482 {
1483   GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
1484   return 0;
1485  win:
1486   return 1;
1487 }
1488
1489 /* Return 1 if OP is a general operand
1490    other than a memory ref with a mode dependent address.  */
1491
1492 int
1493 mode_independent_operand (op, mode)
1494      enum machine_mode mode;
1495      rtx op;
1496 {
1497   rtx addr;
1498
1499   if (! general_operand (op, mode))
1500     return 0;
1501
1502   if (GET_CODE (op) != MEM)
1503     return 1;
1504
1505   addr = XEXP (op, 0);
1506   GO_IF_MODE_DEPENDENT_ADDRESS (addr, lose);
1507   return 1;
1508  lose:
1509   return 0;
1510 }
1511
1512 /* Given an operand OP that is a valid memory reference
1513    which satisfies offsettable_memref_p,
1514    return a new memory reference whose address has been adjusted by OFFSET.
1515    OFFSET should be positive and less than the size of the object referenced.
1516 */
1517
1518 rtx
1519 adj_offsettable_operand (op, offset)
1520      rtx op;
1521      int offset;
1522 {
1523   register enum rtx_code code = GET_CODE (op);
1524
1525   if (code == MEM) 
1526     {
1527       register rtx y = XEXP (op, 0);
1528       register rtx new;
1529
1530       if (CONSTANT_ADDRESS_P (y))
1531         {
1532           new = gen_rtx (MEM, GET_MODE (op), plus_constant_for_output (y, offset));
1533           RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1534           return new;
1535         }
1536
1537       if (GET_CODE (y) == PLUS)
1538         {
1539           rtx z = y;
1540           register rtx *const_loc;
1541
1542           op = copy_rtx (op);
1543           z = XEXP (op, 0);
1544           const_loc = find_constant_term_loc (&z);
1545           if (const_loc)
1546             {
1547               *const_loc = plus_constant_for_output (*const_loc, offset);
1548               return op;
1549             }
1550         }
1551
1552       new = gen_rtx (MEM, GET_MODE (op), plus_constant_for_output (y, offset));
1553       RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1554       return new;
1555     }
1556   abort ();
1557 }
1558 \f
1559 #ifdef REGISTER_CONSTRAINTS
1560
1561 /* Check the operands of an insn (found in recog_operands)
1562    against the insn's operand constraints (found via INSN_CODE_NUM)
1563    and return 1 if they are valid.
1564
1565    WHICH_ALTERNATIVE is set to a number which indicates which
1566    alternative of constraints was matched: 0 for the first alternative,
1567    1 for the next, etc.
1568
1569    In addition, when two operands are match
1570    and it happens that the output operand is (reg) while the
1571    input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
1572    make the output operand look like the input.
1573    This is because the output operand is the one the template will print.
1574
1575    This is used in final, just before printing the assembler code and by
1576    the routines that determine an insn's attribute.
1577
1578    If STRICT is a positive non-zero value, it means that we have been
1579    called after reload has been completed.  In that case, we must
1580    do all checks strictly.  If it is zero, it means that we have been called
1581    before reload has completed.  In that case, we first try to see if we can
1582    find an alternative that matches strictly.  If not, we try again, this
1583    time assuming that reload will fix up the insn.  This provides a "best
1584    guess" for the alternative and is used to compute attributes of insns prior
1585    to reload.  A negative value of STRICT is used for this internal call.  */
1586
1587 struct funny_match
1588 {
1589   int this, other;
1590 };
1591
1592 int
1593 constrain_operands (insn_code_num, strict)
1594      int insn_code_num;
1595      int strict;
1596 {
1597   char *constraints[MAX_RECOG_OPERANDS];
1598   int matching_operands[MAX_RECOG_OPERANDS];
1599   enum op_type {OP_IN, OP_OUT, OP_INOUT} op_types[MAX_RECOG_OPERANDS];
1600   int earlyclobber[MAX_RECOG_OPERANDS];
1601   register int c;
1602   int noperands = insn_n_operands[insn_code_num];
1603
1604   struct funny_match funny_match[MAX_RECOG_OPERANDS];
1605   int funny_match_index;
1606   int nalternatives = insn_n_alternatives[insn_code_num];
1607
1608   if (noperands == 0 || nalternatives == 0)
1609     return 1;
1610
1611   for (c = 0; c < noperands; c++)
1612     {
1613       constraints[c] = insn_operand_constraint[insn_code_num][c];
1614       matching_operands[c] = -1;
1615       op_types[c] = OP_IN;
1616     }
1617
1618   which_alternative = 0;
1619
1620   while (which_alternative < nalternatives)
1621     {
1622       register int opno;
1623       int lose = 0;
1624       funny_match_index = 0;
1625
1626       for (opno = 0; opno < noperands; opno++)
1627         {
1628           register rtx op = recog_operand[opno];
1629           enum machine_mode mode = GET_MODE (op);
1630           register char *p = constraints[opno];
1631           int offset = 0;
1632           int win = 0;
1633           int val;
1634
1635           earlyclobber[opno] = 0;
1636
1637           if (GET_CODE (op) == SUBREG)
1638             {
1639               if (GET_CODE (SUBREG_REG (op)) == REG
1640                   && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
1641                 offset = SUBREG_WORD (op);
1642               op = SUBREG_REG (op);
1643             }
1644
1645           /* An empty constraint or empty alternative
1646              allows anything which matched the pattern.  */
1647           if (*p == 0 || *p == ',')
1648             win = 1;
1649
1650           while (*p && (c = *p++) != ',')
1651             switch (c)
1652               {
1653               case '?':
1654               case '#':
1655               case '!':
1656               case '*':
1657               case '%':
1658                 break;
1659
1660               case '=':
1661                 op_types[opno] = OP_OUT;
1662                 break;
1663
1664               case '+':
1665                 op_types[opno] = OP_INOUT;
1666                 break;
1667
1668               case '&':
1669                 earlyclobber[opno] = 1;
1670                 break;
1671
1672               case '0':
1673               case '1':
1674               case '2':
1675               case '3':
1676               case '4':
1677                 /* This operand must be the same as a previous one.
1678                    This kind of constraint is used for instructions such
1679                    as add when they take only two operands.
1680
1681                    Note that the lower-numbered operand is passed first.
1682
1683                    If we are not testing strictly, assume that this constraint
1684                    will be satisfied.  */
1685                 if (strict < 0)
1686                   val = 1;
1687                 else
1688                   val = operands_match_p (recog_operand[c - '0'],
1689                                           recog_operand[opno]);
1690
1691                 matching_operands[opno] = c - '0';
1692                 matching_operands[c - '0'] = opno;
1693
1694                 if (val != 0)
1695                   win = 1;
1696                 /* If output is *x and input is *--x,
1697                    arrange later to change the output to *--x as well,
1698                    since the output op is the one that will be printed.  */
1699                 if (val == 2 && strict > 0)
1700                   {
1701                     funny_match[funny_match_index].this = opno;
1702                     funny_match[funny_match_index++].other = c - '0';
1703                   }
1704                 break;
1705
1706               case 'p':
1707                 /* p is used for address_operands.  When we are called by
1708                    gen_input_reload, no one will have checked that the
1709                    address is strictly valid, i.e., that all pseudos
1710                    requiring hard regs have gotten them.  */
1711                 if (strict <= 0
1712                     || (strict_memory_address_p
1713                         (insn_operand_mode[insn_code_num][opno], op)))
1714                   win = 1;
1715                 break;
1716
1717                 /* No need to check general_operand again;
1718                    it was done in insn-recog.c.  */
1719               case 'g':
1720                 /* Anything goes unless it is a REG and really has a hard reg
1721                    but the hard reg is not in the class GENERAL_REGS.  */
1722                 if (strict < 0
1723                     || GENERAL_REGS == ALL_REGS
1724                     || GET_CODE (op) != REG
1725                     || (reload_in_progress
1726                         && REGNO (op) >= FIRST_PSEUDO_REGISTER)
1727                     || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
1728                   win = 1;
1729                 break;
1730
1731               case 'r':
1732                 if (strict < 0
1733                     || (strict == 0
1734                         && GET_CODE (op) == REG
1735                         && REGNO (op) >= FIRST_PSEUDO_REGISTER)
1736                     || (strict == 0 && GET_CODE (op) == SCRATCH)
1737                     || (GET_CODE (op) == REG
1738                         && (GENERAL_REGS == ALL_REGS
1739                             || reg_fits_class_p (op, GENERAL_REGS,
1740                                                  offset, mode))))
1741                   win = 1;
1742                 break;
1743
1744               case 'X':
1745                 /* This is used for a MATCH_SCRATCH in the cases when we
1746                    don't actually need anything.  So anything goes any time. */
1747                 win = 1;
1748                 break;
1749
1750               case 'm':
1751                 if (GET_CODE (op) == MEM
1752                     /* Before reload, accept what reload can turn into mem.  */
1753                     || (strict < 0 && CONSTANT_P (op))
1754                     /* During reload, accept a pseudo  */
1755                     || (reload_in_progress && GET_CODE (op) == REG
1756                         && REGNO (op) >= FIRST_PSEUDO_REGISTER))
1757                   win = 1;
1758                 break;
1759
1760               case '<':
1761                 if (GET_CODE (op) == MEM
1762                     && (GET_CODE (XEXP (op, 0)) == PRE_DEC
1763                         || GET_CODE (XEXP (op, 0)) == POST_DEC))
1764                   win = 1;
1765                 break;
1766
1767               case '>':
1768                 if (GET_CODE (op) == MEM
1769                     && (GET_CODE (XEXP (op, 0)) == PRE_INC
1770                         || GET_CODE (XEXP (op, 0)) == POST_INC))
1771                   win = 1;
1772                 break;
1773
1774               case 'E':
1775                 /* Match any CONST_DOUBLE, but only if
1776                    we can examine the bits of it reliably.  */
1777                 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
1778                      || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
1779                     && GET_MODE (op) != VOIDmode && ! flag_pretend_float)
1780                   break;
1781                 if (GET_CODE (op) == CONST_DOUBLE)
1782                   win = 1;
1783                 break;
1784
1785               case 'F':
1786                 if (GET_CODE (op) == CONST_DOUBLE)
1787                   win = 1;
1788                 break;
1789
1790               case 'G':
1791               case 'H':
1792                 if (GET_CODE (op) == CONST_DOUBLE
1793                     && CONST_DOUBLE_OK_FOR_LETTER_P (op, c))
1794                   win = 1;
1795                 break;
1796
1797               case 's':
1798                 if (GET_CODE (op) == CONST_INT
1799                     || (GET_CODE (op) == CONST_DOUBLE
1800                         && GET_MODE (op) == VOIDmode))
1801                   break;
1802               case 'i':
1803                 if (CONSTANT_P (op))
1804                   win = 1;
1805                 break;
1806
1807               case 'n':
1808                 if (GET_CODE (op) == CONST_INT
1809                     || (GET_CODE (op) == CONST_DOUBLE
1810                         && GET_MODE (op) == VOIDmode))
1811                   win = 1;
1812                 break;
1813
1814               case 'I':
1815               case 'J':
1816               case 'K':
1817               case 'L':
1818               case 'M':
1819               case 'N':
1820               case 'O':
1821               case 'P':
1822                 if (GET_CODE (op) == CONST_INT
1823                     && CONST_OK_FOR_LETTER_P (INTVAL (op), c))
1824                   win = 1;
1825                 break;
1826
1827 #ifdef EXTRA_CONSTRAINT
1828               case 'Q':
1829               case 'R':
1830               case 'S':
1831               case 'T':
1832               case 'U':
1833                 if (EXTRA_CONSTRAINT (op, c))
1834                   win = 1;
1835                 break;
1836 #endif
1837
1838               case 'V':
1839                 if (GET_CODE (op) == MEM
1840                     && ! offsettable_memref_p (op))
1841                   win = 1;
1842                 break;
1843
1844               case 'o':
1845                 if ((strict > 0 && offsettable_memref_p (op))
1846                     || (strict == 0 && offsettable_nonstrict_memref_p (op))
1847                     /* Before reload, accept what reload can handle.  */
1848                     || (strict < 0
1849                         && (CONSTANT_P (op) || GET_CODE (op) == MEM))
1850                     /* During reload, accept a pseudo  */
1851                     || (reload_in_progress && GET_CODE (op) == REG
1852                         && REGNO (op) >= FIRST_PSEUDO_REGISTER))
1853                   win = 1;
1854                 break;
1855
1856               default:
1857                 if (strict < 0
1858                     || (strict == 0
1859                         && GET_CODE (op) == REG
1860                         && REGNO (op) >= FIRST_PSEUDO_REGISTER)
1861                     || (strict == 0 && GET_CODE (op) == SCRATCH)
1862                     || (GET_CODE (op) == REG
1863                         && reg_fits_class_p (op, REG_CLASS_FROM_LETTER (c),
1864                                              offset, mode)))
1865                   win = 1;
1866               }
1867
1868           constraints[opno] = p;
1869           /* If this operand did not win somehow,
1870              this alternative loses.  */
1871           if (! win)
1872             lose = 1;
1873         }
1874       /* This alternative won; the operands are ok.
1875          Change whichever operands this alternative says to change.  */
1876       if (! lose)
1877         {
1878           int opno, eopno;
1879
1880           /* See if any earlyclobber operand conflicts with some other
1881              operand.  */
1882
1883           if (strict > 0)
1884             for (eopno = 0; eopno < noperands; eopno++)
1885               /* Ignore earlyclobber operands now in memory,
1886                  because we would often report failure when we have
1887                  two memory operands, one of which was formerly a REG.  */
1888               if (earlyclobber[eopno]
1889                   && GET_CODE (recog_operand[eopno]) == REG)
1890                 for (opno = 0; opno < noperands; opno++)
1891                   if ((GET_CODE (recog_operand[opno]) == MEM
1892                        || op_types[opno] != OP_OUT)
1893                       && opno != eopno
1894                       && constraints[opno] != 0
1895                       && ! (matching_operands[opno] == eopno
1896                             && rtx_equal_p (recog_operand[opno],
1897                                             recog_operand[eopno]))
1898                       && ! safe_from_earlyclobber (recog_operand[opno],
1899                                                    recog_operand[eopno]))
1900                     lose = 1;
1901
1902           if (! lose)
1903             {
1904               while (--funny_match_index >= 0)
1905                 {
1906                   recog_operand[funny_match[funny_match_index].other]
1907                     = recog_operand[funny_match[funny_match_index].this];
1908                 }
1909
1910               return 1;
1911             }
1912         }
1913
1914       which_alternative++;
1915     }
1916
1917   /* If we are about to reject this, but we are not to test strictly,
1918      try a very loose test.  Only return failure if it fails also.  */
1919   if (strict == 0)
1920     return constrain_operands (insn_code_num, -1);
1921   else
1922     return 0;
1923 }
1924
1925 /* Return 1 iff OPERAND (assumed to be a REG rtx)
1926    is a hard reg in class CLASS when its regno is offsetted by OFFSET
1927    and changed to mode MODE.
1928    If REG occupies multiple hard regs, all of them must be in CLASS.  */
1929
1930 int
1931 reg_fits_class_p (operand, class, offset, mode)
1932      rtx operand;
1933      register enum reg_class class;
1934      int offset;
1935      enum machine_mode mode;
1936 {
1937   register int regno = REGNO (operand);
1938   if (regno < FIRST_PSEUDO_REGISTER
1939       && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1940                             regno + offset))
1941     {
1942       register int sr;
1943       regno += offset;
1944       for (sr = HARD_REGNO_NREGS (regno, mode) - 1;
1945            sr > 0; sr--)
1946         if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
1947                                  regno + sr))
1948           break;
1949       return sr == 0;
1950     }
1951
1952   return 0;
1953 }
1954
1955 #endif /* REGISTER_CONSTRAINTS */