OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / recog.c
1 /* Subroutines used by or related to instruction recognition.
2    Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
3    1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA.  */
21
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "rtl.h"
28 #include "tm_p.h"
29 #include "insn-config.h"
30 #include "insn-attr.h"
31 #include "hard-reg-set.h"
32 #include "recog.h"
33 #include "regs.h"
34 #include "expr.h"
35 #include "function.h"
36 #include "flags.h"
37 #include "real.h"
38 #include "toplev.h"
39 #include "basic-block.h"
40 #include "output.h"
41 #include "reload.h"
42 #include "timevar.h"
43 #include "tree-pass.h"
44
45 #ifndef STACK_PUSH_CODE
46 #ifdef STACK_GROWS_DOWNWARD
47 #define STACK_PUSH_CODE PRE_DEC
48 #else
49 #define STACK_PUSH_CODE PRE_INC
50 #endif
51 #endif
52
53 #ifndef STACK_POP_CODE
54 #ifdef STACK_GROWS_DOWNWARD
55 #define STACK_POP_CODE POST_INC
56 #else
57 #define STACK_POP_CODE POST_DEC
58 #endif
59 #endif
60
61 static void validate_replace_rtx_1 (rtx *, rtx, rtx, rtx);
62 static rtx *find_single_use_1 (rtx, rtx *);
63 static void validate_replace_src_1 (rtx *, void *);
64 static rtx split_insn (rtx);
65
66 /* Nonzero means allow operands to be volatile.
67    This should be 0 if you are generating rtl, such as if you are calling
68    the functions in optabs.c and expmed.c (most of the time).
69    This should be 1 if all valid insns need to be recognized,
70    such as in regclass.c and final.c and reload.c.
71
72    init_recog and init_recog_no_volatile are responsible for setting this.  */
73
74 int volatile_ok;
75
76 struct recog_data recog_data;
77
78 /* Contains a vector of operand_alternative structures for every operand.
79    Set up by preprocess_constraints.  */
80 struct operand_alternative recog_op_alt[MAX_RECOG_OPERANDS][MAX_RECOG_ALTERNATIVES];
81
82 /* On return from `constrain_operands', indicate which alternative
83    was satisfied.  */
84
85 int which_alternative;
86
87 /* Nonzero after end of reload pass.
88    Set to 1 or 0 by toplev.c.
89    Controls the significance of (SUBREG (MEM)).  */
90
91 int reload_completed;
92
93 /* Nonzero after thread_prologue_and_epilogue_insns has run.  */
94 int epilogue_completed;
95
96 /* Initialize data used by the function `recog'.
97    This must be called once in the compilation of a function
98    before any insn recognition may be done in the function.  */
99
100 void
101 init_recog_no_volatile (void)
102 {
103   volatile_ok = 0;
104 }
105
106 void
107 init_recog (void)
108 {
109   volatile_ok = 1;
110 }
111
112 \f
113 /* Check that X is an insn-body for an `asm' with operands
114    and that the operands mentioned in it are legitimate.  */
115
116 int
117 check_asm_operands (rtx x)
118 {
119   int noperands;
120   rtx *operands;
121   const char **constraints;
122   int i;
123
124   /* Post-reload, be more strict with things.  */
125   if (reload_completed)
126     {
127       /* ??? Doh!  We've not got the wrapping insn.  Cook one up.  */
128       extract_insn (make_insn_raw (x));
129       constrain_operands (1);
130       return which_alternative >= 0;
131     }
132
133   noperands = asm_noperands (x);
134   if (noperands < 0)
135     return 0;
136   if (noperands == 0)
137     return 1;
138
139   operands = alloca (noperands * sizeof (rtx));
140   constraints = alloca (noperands * sizeof (char *));
141
142   decode_asm_operands (x, operands, NULL, constraints, NULL);
143
144   for (i = 0; i < noperands; i++)
145     {
146       const char *c = constraints[i];
147       if (c[0] == '%')
148         c++;
149       if (ISDIGIT ((unsigned char) c[0]) && c[1] == '\0')
150         c = constraints[c[0] - '0'];
151
152       if (! asm_operand_ok (operands[i], c))
153         return 0;
154     }
155
156   return 1;
157 }
158 \f
159 /* Static data for the next two routines.  */
160
161 typedef struct change_t
162 {
163   rtx object;
164   int old_code;
165   rtx *loc;
166   rtx old;
167 } change_t;
168
169 static change_t *changes;
170 static int changes_allocated;
171
172 static int num_changes = 0;
173
174 /* Validate a proposed change to OBJECT.  LOC is the location in the rtl
175    at which NEW will be placed.  If OBJECT is zero, no validation is done,
176    the change is simply made.
177
178    Two types of objects are supported:  If OBJECT is a MEM, memory_address_p
179    will be called with the address and mode as parameters.  If OBJECT is
180    an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
181    the change in place.
182
183    IN_GROUP is nonzero if this is part of a group of changes that must be
184    performed as a group.  In that case, the changes will be stored.  The
185    function `apply_change_group' will validate and apply the changes.
186
187    If IN_GROUP is zero, this is a single change.  Try to recognize the insn
188    or validate the memory reference with the change applied.  If the result
189    is not valid for the machine, suppress the change and return zero.
190    Otherwise, perform the change and return 1.  */
191
192 int
193 validate_change (rtx object, rtx *loc, rtx new, int in_group)
194 {
195   rtx old = *loc;
196
197   if (old == new || rtx_equal_p (old, new))
198     return 1;
199
200   gcc_assert (in_group != 0 || num_changes == 0);
201
202   *loc = new;
203
204   /* Save the information describing this change.  */
205   if (num_changes >= changes_allocated)
206     {
207       if (changes_allocated == 0)
208         /* This value allows for repeated substitutions inside complex
209            indexed addresses, or changes in up to 5 insns.  */
210         changes_allocated = MAX_RECOG_OPERANDS * 5;
211       else
212         changes_allocated *= 2;
213
214       changes = xrealloc (changes, sizeof (change_t) * changes_allocated);
215     }
216
217   changes[num_changes].object = object;
218   changes[num_changes].loc = loc;
219   changes[num_changes].old = old;
220
221   if (object && !MEM_P (object))
222     {
223       /* Set INSN_CODE to force rerecognition of insn.  Save old code in
224          case invalid.  */
225       changes[num_changes].old_code = INSN_CODE (object);
226       INSN_CODE (object) = -1;
227     }
228
229   num_changes++;
230
231   /* If we are making a group of changes, return 1.  Otherwise, validate the
232      change group we made.  */
233
234   if (in_group)
235     return 1;
236   else
237     return apply_change_group ();
238 }
239
240
241 /* Function to be passed to for_each_rtx to test whether a piece of
242    RTL contains any mem/v.  */
243 static int
244 volatile_mem_p (rtx *x, void *data ATTRIBUTE_UNUSED)
245 {
246   return (MEM_P (*x) && MEM_VOLATILE_P (*x));
247 }
248
249 /* Same as validate_change, but doesn't support groups, and it accepts
250    volatile mems if they're already present in the original insn.  */
251
252 int
253 validate_change_maybe_volatile (rtx object, rtx *loc, rtx new)
254 {
255   int result;
256
257   if (validate_change (object, loc, new, 0))
258     return 1;
259
260   if (volatile_ok
261       /* If there isn't a volatile MEM, there's nothing we can do.  */
262       || !for_each_rtx (&PATTERN (object), volatile_mem_p, 0)
263       /* Make sure we're not adding or removing volatile MEMs.  */
264       || for_each_rtx (loc, volatile_mem_p, 0)
265       || for_each_rtx (&new, volatile_mem_p, 0)
266       || !insn_invalid_p (object))
267     return 0;
268
269   volatile_ok = 1;
270
271   gcc_assert (!insn_invalid_p (object));
272
273   result = validate_change (object, loc, new, 0);
274
275   volatile_ok = 0;
276
277   return result;
278 }
279
280 /* This subroutine of apply_change_group verifies whether the changes to INSN
281    were valid; i.e. whether INSN can still be recognized.  */
282
283 int
284 insn_invalid_p (rtx insn)
285 {
286   rtx pat = PATTERN (insn);
287   int num_clobbers = 0;
288   /* If we are before reload and the pattern is a SET, see if we can add
289      clobbers.  */
290   int icode = recog (pat, insn,
291                      (GET_CODE (pat) == SET
292                       && ! reload_completed && ! reload_in_progress)
293                      ? &num_clobbers : 0);
294   int is_asm = icode < 0 && asm_noperands (PATTERN (insn)) >= 0;
295
296
297   /* If this is an asm and the operand aren't legal, then fail.  Likewise if
298      this is not an asm and the insn wasn't recognized.  */
299   if ((is_asm && ! check_asm_operands (PATTERN (insn)))
300       || (!is_asm && icode < 0))
301     return 1;
302
303   /* If we have to add CLOBBERs, fail if we have to add ones that reference
304      hard registers since our callers can't know if they are live or not.
305      Otherwise, add them.  */
306   if (num_clobbers > 0)
307     {
308       rtx newpat;
309
310       if (added_clobbers_hard_reg_p (icode))
311         return 1;
312
313       newpat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_clobbers + 1));
314       XVECEXP (newpat, 0, 0) = pat;
315       add_clobbers (newpat, icode);
316       PATTERN (insn) = pat = newpat;
317     }
318
319   /* After reload, verify that all constraints are satisfied.  */
320   if (reload_completed)
321     {
322       extract_insn (insn);
323
324       if (! constrain_operands (1))
325         return 1;
326     }
327
328   INSN_CODE (insn) = icode;
329   return 0;
330 }
331
332 /* Return number of changes made and not validated yet.  */
333 int
334 num_changes_pending (void)
335 {
336   return num_changes;
337 }
338
339 /* Tentatively apply the changes numbered NUM and up.
340    Return 1 if all changes are valid, zero otherwise.  */
341
342 int
343 verify_changes (int num)
344 {
345   int i;
346   rtx last_validated = NULL_RTX;
347
348   /* The changes have been applied and all INSN_CODEs have been reset to force
349      rerecognition.
350
351      The changes are valid if we aren't given an object, or if we are
352      given a MEM and it still is a valid address, or if this is in insn
353      and it is recognized.  In the latter case, if reload has completed,
354      we also require that the operands meet the constraints for
355      the insn.  */
356
357   for (i = num; i < num_changes; i++)
358     {
359       rtx object = changes[i].object;
360
361       /* If there is no object to test or if it is the same as the one we
362          already tested, ignore it.  */
363       if (object == 0 || object == last_validated)
364         continue;
365
366       if (MEM_P (object))
367         {
368           if (! memory_address_p (GET_MODE (object), XEXP (object, 0)))
369             break;
370         }
371       else if (insn_invalid_p (object))
372         {
373           rtx pat = PATTERN (object);
374
375           /* Perhaps we couldn't recognize the insn because there were
376              extra CLOBBERs at the end.  If so, try to re-recognize
377              without the last CLOBBER (later iterations will cause each of
378              them to be eliminated, in turn).  But don't do this if we
379              have an ASM_OPERAND.  */
380           if (GET_CODE (pat) == PARALLEL
381               && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
382               && asm_noperands (PATTERN (object)) < 0)
383             {
384               rtx newpat;
385
386               if (XVECLEN (pat, 0) == 2)
387                 newpat = XVECEXP (pat, 0, 0);
388               else
389                 {
390                   int j;
391
392                   newpat
393                     = gen_rtx_PARALLEL (VOIDmode,
394                                         rtvec_alloc (XVECLEN (pat, 0) - 1));
395                   for (j = 0; j < XVECLEN (newpat, 0); j++)
396                     XVECEXP (newpat, 0, j) = XVECEXP (pat, 0, j);
397                 }
398
399               /* Add a new change to this group to replace the pattern
400                  with this new pattern.  Then consider this change
401                  as having succeeded.  The change we added will
402                  cause the entire call to fail if things remain invalid.
403
404                  Note that this can lose if a later change than the one
405                  we are processing specified &XVECEXP (PATTERN (object), 0, X)
406                  but this shouldn't occur.  */
407
408               validate_change (object, &PATTERN (object), newpat, 1);
409               continue;
410             }
411           else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
412             /* If this insn is a CLOBBER or USE, it is always valid, but is
413                never recognized.  */
414             continue;
415           else
416             break;
417         }
418       last_validated = object;
419     }
420
421   return (i == num_changes);
422 }
423
424 /* A group of changes has previously been issued with validate_change and
425    verified with verify_changes.  Update the BB_DIRTY flags of the affected
426    blocks, and clear num_changes.  */
427
428 void
429 confirm_change_group (void)
430 {
431   int i;
432   basic_block bb;
433
434   for (i = 0; i < num_changes; i++)
435     if (changes[i].object
436         && INSN_P (changes[i].object)
437         && (bb = BLOCK_FOR_INSN (changes[i].object)))
438       bb->flags |= BB_DIRTY;
439
440   num_changes = 0;
441 }
442
443 /* Apply a group of changes previously issued with `validate_change'.
444    If all changes are valid, call confirm_change_group and return 1,
445    otherwise, call cancel_changes and return 0.  */
446
447 int
448 apply_change_group (void)
449 {
450   if (verify_changes (0))
451     {
452       confirm_change_group ();
453       return 1;
454     }
455   else
456     {
457       cancel_changes (0);
458       return 0;
459     }
460 }
461
462
463 /* Return the number of changes so far in the current group.  */
464
465 int
466 num_validated_changes (void)
467 {
468   return num_changes;
469 }
470
471 /* Retract the changes numbered NUM and up.  */
472
473 void
474 cancel_changes (int num)
475 {
476   int i;
477
478   /* Back out all the changes.  Do this in the opposite order in which
479      they were made.  */
480   for (i = num_changes - 1; i >= num; i--)
481     {
482       *changes[i].loc = changes[i].old;
483       if (changes[i].object && !MEM_P (changes[i].object))
484         INSN_CODE (changes[i].object) = changes[i].old_code;
485     }
486   num_changes = num;
487 }
488
489 /* Replace every occurrence of FROM in X with TO.  Mark each change with
490    validate_change passing OBJECT.  */
491
492 static void
493 validate_replace_rtx_1 (rtx *loc, rtx from, rtx to, rtx object)
494 {
495   int i, j;
496   const char *fmt;
497   rtx x = *loc;
498   enum rtx_code code;
499   enum machine_mode op0_mode = VOIDmode;
500   int prev_changes = num_changes;
501   rtx new;
502
503   if (!x)
504     return;
505
506   code = GET_CODE (x);
507   fmt = GET_RTX_FORMAT (code);
508   if (fmt[0] == 'e')
509     op0_mode = GET_MODE (XEXP (x, 0));
510
511   /* X matches FROM if it is the same rtx or they are both referring to the
512      same register in the same mode.  Avoid calling rtx_equal_p unless the
513      operands look similar.  */
514
515   if (x == from
516       || (REG_P (x) && REG_P (from)
517           && GET_MODE (x) == GET_MODE (from)
518           && REGNO (x) == REGNO (from))
519       || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
520           && rtx_equal_p (x, from)))
521     {
522       validate_change (object, loc, to, 1);
523       return;
524     }
525
526   /* Call ourself recursively to perform the replacements.
527      We must not replace inside already replaced expression, otherwise we
528      get infinite recursion for replacements like (reg X)->(subreg (reg X))
529      done by regmove, so we must special case shared ASM_OPERANDS.  */
530
531   if (GET_CODE (x) == PARALLEL)
532     {
533       for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
534         {
535           if (j && GET_CODE (XVECEXP (x, 0, j)) == SET
536               && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == ASM_OPERANDS)
537             {
538               /* Verify that operands are really shared.  */
539               gcc_assert (ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (x, 0, 0)))
540                           == ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP
541                                                               (x, 0, j))));
542               validate_replace_rtx_1 (&SET_DEST (XVECEXP (x, 0, j)),
543                                       from, to, object);
544             }
545           else
546             validate_replace_rtx_1 (&XVECEXP (x, 0, j), from, to, object);
547         }
548     }
549   else
550     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
551       {
552         if (fmt[i] == 'e')
553           validate_replace_rtx_1 (&XEXP (x, i), from, to, object);
554         else if (fmt[i] == 'E')
555           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
556             validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object);
557       }
558
559   /* If we didn't substitute, there is nothing more to do.  */
560   if (num_changes == prev_changes)
561     return;
562
563   /* Allow substituted expression to have different mode.  This is used by
564      regmove to change mode of pseudo register.  */
565   if (fmt[0] == 'e' && GET_MODE (XEXP (x, 0)) != VOIDmode)
566     op0_mode = GET_MODE (XEXP (x, 0));
567
568   /* Do changes needed to keep rtx consistent.  Don't do any other
569      simplifications, as it is not our job.  */
570
571   if (SWAPPABLE_OPERANDS_P (x)
572       && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
573     {
574       validate_change (object, loc,
575                        gen_rtx_fmt_ee (COMMUTATIVE_ARITH_P (x) ? code
576                                        : swap_condition (code),
577                                        GET_MODE (x), XEXP (x, 1),
578                                        XEXP (x, 0)), 1);
579       x = *loc;
580       code = GET_CODE (x);
581     }
582
583   switch (code)
584     {
585     case PLUS:
586       /* If we have a PLUS whose second operand is now a CONST_INT, use
587          simplify_gen_binary to try to simplify it.
588          ??? We may want later to remove this, once simplification is
589          separated from this function.  */
590       if (GET_CODE (XEXP (x, 1)) == CONST_INT && XEXP (x, 1) == to)
591         validate_change (object, loc,
592                          simplify_gen_binary
593                          (PLUS, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)), 1);
594       break;
595     case MINUS:
596       if (GET_CODE (XEXP (x, 1)) == CONST_INT
597           || GET_CODE (XEXP (x, 1)) == CONST_DOUBLE)
598         validate_change (object, loc,
599                          simplify_gen_binary
600                          (PLUS, GET_MODE (x), XEXP (x, 0),
601                           simplify_gen_unary (NEG,
602                                               GET_MODE (x), XEXP (x, 1),
603                                               GET_MODE (x))), 1);
604       break;
605     case ZERO_EXTEND:
606     case SIGN_EXTEND:
607       if (GET_MODE (XEXP (x, 0)) == VOIDmode)
608         {
609           new = simplify_gen_unary (code, GET_MODE (x), XEXP (x, 0),
610                                     op0_mode);
611           /* If any of the above failed, substitute in something that
612              we know won't be recognized.  */
613           if (!new)
614             new = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
615           validate_change (object, loc, new, 1);
616         }
617       break;
618     case SUBREG:
619       /* All subregs possible to simplify should be simplified.  */
620       new = simplify_subreg (GET_MODE (x), SUBREG_REG (x), op0_mode,
621                              SUBREG_BYTE (x));
622
623       /* Subregs of VOIDmode operands are incorrect.  */
624       if (!new && GET_MODE (SUBREG_REG (x)) == VOIDmode)
625         new = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
626       if (new)
627         validate_change (object, loc, new, 1);
628       break;
629     case ZERO_EXTRACT:
630     case SIGN_EXTRACT:
631       /* If we are replacing a register with memory, try to change the memory
632          to be the mode required for memory in extract operations (this isn't
633          likely to be an insertion operation; if it was, nothing bad will
634          happen, we might just fail in some cases).  */
635
636       if (MEM_P (XEXP (x, 0))
637           && GET_CODE (XEXP (x, 1)) == CONST_INT
638           && GET_CODE (XEXP (x, 2)) == CONST_INT
639           && !mode_dependent_address_p (XEXP (XEXP (x, 0), 0))
640           && !MEM_VOLATILE_P (XEXP (x, 0)))
641         {
642           enum machine_mode wanted_mode = VOIDmode;
643           enum machine_mode is_mode = GET_MODE (XEXP (x, 0));
644           int pos = INTVAL (XEXP (x, 2));
645
646           if (GET_CODE (x) == ZERO_EXTRACT)
647             {
648               enum machine_mode new_mode
649                 = mode_for_extraction (EP_extzv, 1);
650               if (new_mode != MAX_MACHINE_MODE)
651                 wanted_mode = new_mode;
652             }
653           else if (GET_CODE (x) == SIGN_EXTRACT)
654             {
655               enum machine_mode new_mode
656                 = mode_for_extraction (EP_extv, 1);
657               if (new_mode != MAX_MACHINE_MODE)
658                 wanted_mode = new_mode;
659             }
660
661           /* If we have a narrower mode, we can do something.  */
662           if (wanted_mode != VOIDmode
663               && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
664             {
665               int offset = pos / BITS_PER_UNIT;
666               rtx newmem;
667
668               /* If the bytes and bits are counted differently, we
669                  must adjust the offset.  */
670               if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
671                 offset =
672                   (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode) -
673                    offset);
674
675               pos %= GET_MODE_BITSIZE (wanted_mode);
676
677               newmem = adjust_address_nv (XEXP (x, 0), wanted_mode, offset);
678
679               validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
680               validate_change (object, &XEXP (x, 0), newmem, 1);
681             }
682         }
683
684       break;
685
686     default:
687       break;
688     }
689 }
690
691 /* Try replacing every occurrence of FROM in INSN with TO.  After all
692    changes have been made, validate by seeing if INSN is still valid.  */
693
694 int
695 validate_replace_rtx (rtx from, rtx to, rtx insn)
696 {
697   validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
698   return apply_change_group ();
699 }
700
701 /* Try replacing every occurrence of FROM in INSN with TO.  */
702
703 void
704 validate_replace_rtx_group (rtx from, rtx to, rtx insn)
705 {
706   validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
707 }
708
709 /* Function called by note_uses to replace used subexpressions.  */
710 struct validate_replace_src_data
711 {
712   rtx from;                     /* Old RTX */
713   rtx to;                       /* New RTX */
714   rtx insn;                     /* Insn in which substitution is occurring.  */
715 };
716
717 static void
718 validate_replace_src_1 (rtx *x, void *data)
719 {
720   struct validate_replace_src_data *d
721     = (struct validate_replace_src_data *) data;
722
723   validate_replace_rtx_1 (x, d->from, d->to, d->insn);
724 }
725
726 /* Try replacing every occurrence of FROM in INSN with TO, avoiding
727    SET_DESTs.  */
728
729 void
730 validate_replace_src_group (rtx from, rtx to, rtx insn)
731 {
732   struct validate_replace_src_data d;
733
734   d.from = from;
735   d.to = to;
736   d.insn = insn;
737   note_uses (&PATTERN (insn), validate_replace_src_1, &d);
738 }
739 \f
740 #ifdef HAVE_cc0
741 /* Return 1 if the insn using CC0 set by INSN does not contain
742    any ordered tests applied to the condition codes.
743    EQ and NE tests do not count.  */
744
745 int
746 next_insn_tests_no_inequality (rtx insn)
747 {
748   rtx next = next_cc0_user (insn);
749
750   /* If there is no next insn, we have to take the conservative choice.  */
751   if (next == 0)
752     return 0;
753
754   return (INSN_P (next)
755           && ! inequality_comparisons_p (PATTERN (next)));
756 }
757 #endif
758 \f
759 /* This is used by find_single_use to locate an rtx that contains exactly one
760    use of DEST, which is typically either a REG or CC0.  It returns a
761    pointer to the innermost rtx expression containing DEST.  Appearances of
762    DEST that are being used to totally replace it are not counted.  */
763
764 static rtx *
765 find_single_use_1 (rtx dest, rtx *loc)
766 {
767   rtx x = *loc;
768   enum rtx_code code = GET_CODE (x);
769   rtx *result = 0;
770   rtx *this_result;
771   int i;
772   const char *fmt;
773
774   switch (code)
775     {
776     case CONST_INT:
777     case CONST:
778     case LABEL_REF:
779     case SYMBOL_REF:
780     case CONST_DOUBLE:
781     case CONST_VECTOR:
782     case CLOBBER:
783       return 0;
784
785     case SET:
786       /* If the destination is anything other than CC0, PC, a REG or a SUBREG
787          of a REG that occupies all of the REG, the insn uses DEST if
788          it is mentioned in the destination or the source.  Otherwise, we
789          need just check the source.  */
790       if (GET_CODE (SET_DEST (x)) != CC0
791           && GET_CODE (SET_DEST (x)) != PC
792           && !REG_P (SET_DEST (x))
793           && ! (GET_CODE (SET_DEST (x)) == SUBREG
794                 && REG_P (SUBREG_REG (SET_DEST (x)))
795                 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (x))))
796                       + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
797                     == ((GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
798                          + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
799         break;
800
801       return find_single_use_1 (dest, &SET_SRC (x));
802
803     case MEM:
804     case SUBREG:
805       return find_single_use_1 (dest, &XEXP (x, 0));
806
807     default:
808       break;
809     }
810
811   /* If it wasn't one of the common cases above, check each expression and
812      vector of this code.  Look for a unique usage of DEST.  */
813
814   fmt = GET_RTX_FORMAT (code);
815   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
816     {
817       if (fmt[i] == 'e')
818         {
819           if (dest == XEXP (x, i)
820               || (REG_P (dest) && REG_P (XEXP (x, i))
821                   && REGNO (dest) == REGNO (XEXP (x, i))))
822             this_result = loc;
823           else
824             this_result = find_single_use_1 (dest, &XEXP (x, i));
825
826           if (result == 0)
827             result = this_result;
828           else if (this_result)
829             /* Duplicate usage.  */
830             return 0;
831         }
832       else if (fmt[i] == 'E')
833         {
834           int j;
835
836           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
837             {
838               if (XVECEXP (x, i, j) == dest
839                   || (REG_P (dest)
840                       && REG_P (XVECEXP (x, i, j))
841                       && REGNO (XVECEXP (x, i, j)) == REGNO (dest)))
842                 this_result = loc;
843               else
844                 this_result = find_single_use_1 (dest, &XVECEXP (x, i, j));
845
846               if (result == 0)
847                 result = this_result;
848               else if (this_result)
849                 return 0;
850             }
851         }
852     }
853
854   return result;
855 }
856 \f
857 /* See if DEST, produced in INSN, is used only a single time in the
858    sequel.  If so, return a pointer to the innermost rtx expression in which
859    it is used.
860
861    If PLOC is nonzero, *PLOC is set to the insn containing the single use.
862
863    This routine will return usually zero either before flow is called (because
864    there will be no LOG_LINKS notes) or after reload (because the REG_DEAD
865    note can't be trusted).
866
867    If DEST is cc0_rtx, we look only at the next insn.  In that case, we don't
868    care about REG_DEAD notes or LOG_LINKS.
869
870    Otherwise, we find the single use by finding an insn that has a
871    LOG_LINKS pointing at INSN and has a REG_DEAD note for DEST.  If DEST is
872    only referenced once in that insn, we know that it must be the first
873    and last insn referencing DEST.  */
874
875 rtx *
876 find_single_use (rtx dest, rtx insn, rtx *ploc)
877 {
878   rtx next;
879   rtx *result;
880   rtx link;
881
882 #ifdef HAVE_cc0
883   if (dest == cc0_rtx)
884     {
885       next = NEXT_INSN (insn);
886       if (next == 0
887           || (!NONJUMP_INSN_P (next) && !JUMP_P (next)))
888         return 0;
889
890       result = find_single_use_1 (dest, &PATTERN (next));
891       if (result && ploc)
892         *ploc = next;
893       return result;
894     }
895 #endif
896
897   if (reload_completed || reload_in_progress || !REG_P (dest))
898     return 0;
899
900   for (next = next_nonnote_insn (insn);
901        next != 0 && !LABEL_P (next);
902        next = next_nonnote_insn (next))
903     if (INSN_P (next) && dead_or_set_p (next, dest))
904       {
905         for (link = LOG_LINKS (next); link; link = XEXP (link, 1))
906           if (XEXP (link, 0) == insn)
907             break;
908
909         if (link)
910           {
911             result = find_single_use_1 (dest, &PATTERN (next));
912             if (ploc)
913               *ploc = next;
914             return result;
915           }
916       }
917
918   return 0;
919 }
920 \f
921 /* Return 1 if OP is a valid general operand for machine mode MODE.
922    This is either a register reference, a memory reference,
923    or a constant.  In the case of a memory reference, the address
924    is checked for general validity for the target machine.
925
926    Register and memory references must have mode MODE in order to be valid,
927    but some constants have no machine mode and are valid for any mode.
928
929    If MODE is VOIDmode, OP is checked for validity for whatever mode
930    it has.
931
932    The main use of this function is as a predicate in match_operand
933    expressions in the machine description.
934
935    For an explanation of this function's behavior for registers of
936    class NO_REGS, see the comment for `register_operand'.  */
937
938 int
939 general_operand (rtx op, enum machine_mode mode)
940 {
941   enum rtx_code code = GET_CODE (op);
942
943   if (mode == VOIDmode)
944     mode = GET_MODE (op);
945
946   /* Don't accept CONST_INT or anything similar
947      if the caller wants something floating.  */
948   if (GET_MODE (op) == VOIDmode && mode != VOIDmode
949       && GET_MODE_CLASS (mode) != MODE_INT
950       && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
951     return 0;
952
953   if (GET_CODE (op) == CONST_INT
954       && mode != VOIDmode
955       && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
956     return 0;
957
958   if (CONSTANT_P (op))
959     return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
960              || mode == VOIDmode)
961             && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
962             && LEGITIMATE_CONSTANT_P (op));
963
964   /* Except for certain constants with VOIDmode, already checked for,
965      OP's mode must match MODE if MODE specifies a mode.  */
966
967   if (GET_MODE (op) != mode)
968     return 0;
969
970   if (code == SUBREG)
971     {
972       rtx sub = SUBREG_REG (op);
973
974 #ifdef INSN_SCHEDULING
975       /* On machines that have insn scheduling, we want all memory
976          reference to be explicit, so outlaw paradoxical SUBREGs.
977          However, we must allow them after reload so that they can
978          get cleaned up by cleanup_subreg_operands.  */
979       if (!reload_completed && MEM_P (sub)
980           && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (sub)))
981         return 0;
982 #endif
983       /* Avoid memories with nonzero SUBREG_BYTE, as offsetting the memory
984          may result in incorrect reference.  We should simplify all valid
985          subregs of MEM anyway.  But allow this after reload because we
986          might be called from cleanup_subreg_operands.
987
988          ??? This is a kludge.  */
989       if (!reload_completed && SUBREG_BYTE (op) != 0
990           && MEM_P (sub))
991         return 0;
992
993       /* FLOAT_MODE subregs can't be paradoxical.  Combine will occasionally
994          create such rtl, and we must reject it.  */
995       if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
996           && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
997         return 0;
998
999       op = sub;
1000       code = GET_CODE (op);
1001     }
1002
1003   if (code == REG)
1004     /* A register whose class is NO_REGS is not a general operand.  */
1005     return (REGNO (op) >= FIRST_PSEUDO_REGISTER
1006             || REGNO_REG_CLASS (REGNO (op)) != NO_REGS);
1007
1008   if (code == MEM)
1009     {
1010       rtx y = XEXP (op, 0);
1011
1012       if (! volatile_ok && MEM_VOLATILE_P (op))
1013         return 0;
1014
1015       /* Use the mem's mode, since it will be reloaded thus.  */
1016       if (memory_address_p (GET_MODE (op), y))
1017         return 1;
1018     }
1019
1020   return 0;
1021 }
1022 \f
1023 /* Return 1 if OP is a valid memory address for a memory reference
1024    of mode MODE.
1025
1026    The main use of this function is as a predicate in match_operand
1027    expressions in the machine description.  */
1028
1029 int
1030 address_operand (rtx op, enum machine_mode mode)
1031 {
1032   return memory_address_p (mode, op);
1033 }
1034
1035 /* Return 1 if OP is a register reference of mode MODE.
1036    If MODE is VOIDmode, accept a register in any mode.
1037
1038    The main use of this function is as a predicate in match_operand
1039    expressions in the machine description.
1040
1041    As a special exception, registers whose class is NO_REGS are
1042    not accepted by `register_operand'.  The reason for this change
1043    is to allow the representation of special architecture artifacts
1044    (such as a condition code register) without extending the rtl
1045    definitions.  Since registers of class NO_REGS cannot be used
1046    as registers in any case where register classes are examined,
1047    it is most consistent to keep this function from accepting them.  */
1048
1049 int
1050 register_operand (rtx op, enum machine_mode mode)
1051 {
1052   if (GET_MODE (op) != mode && mode != VOIDmode)
1053     return 0;
1054
1055   if (GET_CODE (op) == SUBREG)
1056     {
1057       rtx sub = SUBREG_REG (op);
1058
1059       /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1060          because it is guaranteed to be reloaded into one.
1061          Just make sure the MEM is valid in itself.
1062          (Ideally, (SUBREG (MEM)...) should not exist after reload,
1063          but currently it does result from (SUBREG (REG)...) where the
1064          reg went on the stack.)  */
1065       if (! reload_completed && MEM_P (sub))
1066         return general_operand (op, mode);
1067
1068 #ifdef CANNOT_CHANGE_MODE_CLASS
1069       if (REG_P (sub)
1070           && REGNO (sub) < FIRST_PSEUDO_REGISTER
1071           && REG_CANNOT_CHANGE_MODE_P (REGNO (sub), GET_MODE (sub), mode)
1072           && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_INT
1073           && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_FLOAT)
1074         return 0;
1075 #endif
1076
1077       /* FLOAT_MODE subregs can't be paradoxical.  Combine will occasionally
1078          create such rtl, and we must reject it.  */
1079       if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
1080           && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
1081         return 0;
1082
1083       op = sub;
1084     }
1085
1086   /* We don't consider registers whose class is NO_REGS
1087      to be a register operand.  */
1088   return (REG_P (op)
1089           && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1090               || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1091 }
1092
1093 /* Return 1 for a register in Pmode; ignore the tested mode.  */
1094
1095 int
1096 pmode_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1097 {
1098   return register_operand (op, Pmode);
1099 }
1100
1101 /* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
1102    or a hard register.  */
1103
1104 int
1105 scratch_operand (rtx op, enum machine_mode mode)
1106 {
1107   if (GET_MODE (op) != mode && mode != VOIDmode)
1108     return 0;
1109
1110   return (GET_CODE (op) == SCRATCH
1111           || (REG_P (op)
1112               && REGNO (op) < FIRST_PSEUDO_REGISTER));
1113 }
1114
1115 /* Return 1 if OP is a valid immediate operand for mode MODE.
1116
1117    The main use of this function is as a predicate in match_operand
1118    expressions in the machine description.  */
1119
1120 int
1121 immediate_operand (rtx op, enum machine_mode mode)
1122 {
1123   /* Don't accept CONST_INT or anything similar
1124      if the caller wants something floating.  */
1125   if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1126       && GET_MODE_CLASS (mode) != MODE_INT
1127       && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1128     return 0;
1129
1130   if (GET_CODE (op) == CONST_INT
1131       && mode != VOIDmode
1132       && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1133     return 0;
1134
1135   return (CONSTANT_P (op)
1136           && (GET_MODE (op) == mode || mode == VOIDmode
1137               || GET_MODE (op) == VOIDmode)
1138           && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1139           && LEGITIMATE_CONSTANT_P (op));
1140 }
1141
1142 /* Returns 1 if OP is an operand that is a CONST_INT.  */
1143
1144 int
1145 const_int_operand (rtx op, enum machine_mode mode)
1146 {
1147   if (GET_CODE (op) != CONST_INT)
1148     return 0;
1149
1150   if (mode != VOIDmode
1151       && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1152     return 0;
1153
1154   return 1;
1155 }
1156
1157 /* Returns 1 if OP is an operand that is a constant integer or constant
1158    floating-point number.  */
1159
1160 int
1161 const_double_operand (rtx op, enum machine_mode mode)
1162 {
1163   /* Don't accept CONST_INT or anything similar
1164      if the caller wants something floating.  */
1165   if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1166       && GET_MODE_CLASS (mode) != MODE_INT
1167       && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1168     return 0;
1169
1170   return ((GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT)
1171           && (mode == VOIDmode || GET_MODE (op) == mode
1172               || GET_MODE (op) == VOIDmode));
1173 }
1174
1175 /* Return 1 if OP is a general operand that is not an immediate operand.  */
1176
1177 int
1178 nonimmediate_operand (rtx op, enum machine_mode mode)
1179 {
1180   return (general_operand (op, mode) && ! CONSTANT_P (op));
1181 }
1182
1183 /* Return 1 if OP is a register reference or immediate value of mode MODE.  */
1184
1185 int
1186 nonmemory_operand (rtx op, enum machine_mode mode)
1187 {
1188   if (CONSTANT_P (op))
1189     {
1190       /* Don't accept CONST_INT or anything similar
1191          if the caller wants something floating.  */
1192       if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1193           && GET_MODE_CLASS (mode) != MODE_INT
1194           && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1195         return 0;
1196
1197       if (GET_CODE (op) == CONST_INT
1198           && mode != VOIDmode
1199           && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1200         return 0;
1201
1202       return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
1203                || mode == VOIDmode)
1204               && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1205               && LEGITIMATE_CONSTANT_P (op));
1206     }
1207
1208   if (GET_MODE (op) != mode && mode != VOIDmode)
1209     return 0;
1210
1211   if (GET_CODE (op) == SUBREG)
1212     {
1213       /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1214          because it is guaranteed to be reloaded into one.
1215          Just make sure the MEM is valid in itself.
1216          (Ideally, (SUBREG (MEM)...) should not exist after reload,
1217          but currently it does result from (SUBREG (REG)...) where the
1218          reg went on the stack.)  */
1219       if (! reload_completed && MEM_P (SUBREG_REG (op)))
1220         return general_operand (op, mode);
1221       op = SUBREG_REG (op);
1222     }
1223
1224   /* We don't consider registers whose class is NO_REGS
1225      to be a register operand.  */
1226   return (REG_P (op)
1227           && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1228               || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1229 }
1230
1231 /* Return 1 if OP is a valid operand that stands for pushing a
1232    value of mode MODE onto the stack.
1233
1234    The main use of this function is as a predicate in match_operand
1235    expressions in the machine description.  */
1236
1237 int
1238 push_operand (rtx op, enum machine_mode mode)
1239 {
1240   unsigned int rounded_size = GET_MODE_SIZE (mode);
1241
1242 #ifdef PUSH_ROUNDING
1243   rounded_size = PUSH_ROUNDING (rounded_size);
1244 #endif
1245
1246   if (!MEM_P (op))
1247     return 0;
1248
1249   if (mode != VOIDmode && GET_MODE (op) != mode)
1250     return 0;
1251
1252   op = XEXP (op, 0);
1253
1254   if (rounded_size == GET_MODE_SIZE (mode))
1255     {
1256       if (GET_CODE (op) != STACK_PUSH_CODE)
1257         return 0;
1258     }
1259   else
1260     {
1261       if (GET_CODE (op) != PRE_MODIFY
1262           || GET_CODE (XEXP (op, 1)) != PLUS
1263           || XEXP (XEXP (op, 1), 0) != XEXP (op, 0)
1264           || GET_CODE (XEXP (XEXP (op, 1), 1)) != CONST_INT
1265 #ifdef STACK_GROWS_DOWNWARD
1266           || INTVAL (XEXP (XEXP (op, 1), 1)) != - (int) rounded_size
1267 #else
1268           || INTVAL (XEXP (XEXP (op, 1), 1)) != (int) rounded_size
1269 #endif
1270           )
1271         return 0;
1272     }
1273
1274   return XEXP (op, 0) == stack_pointer_rtx;
1275 }
1276
1277 /* Return 1 if OP is a valid operand that stands for popping a
1278    value of mode MODE off the stack.
1279
1280    The main use of this function is as a predicate in match_operand
1281    expressions in the machine description.  */
1282
1283 int
1284 pop_operand (rtx op, enum machine_mode mode)
1285 {
1286   if (!MEM_P (op))
1287     return 0;
1288
1289   if (mode != VOIDmode && GET_MODE (op) != mode)
1290     return 0;
1291
1292   op = XEXP (op, 0);
1293
1294   if (GET_CODE (op) != STACK_POP_CODE)
1295     return 0;
1296
1297   return XEXP (op, 0) == stack_pointer_rtx;
1298 }
1299
1300 /* Return 1 if ADDR is a valid memory address for mode MODE.  */
1301
1302 int
1303 memory_address_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx addr)
1304 {
1305   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1306   return 0;
1307
1308  win:
1309   return 1;
1310 }
1311
1312 /* Return 1 if OP is a valid memory reference with mode MODE,
1313    including a valid address.
1314
1315    The main use of this function is as a predicate in match_operand
1316    expressions in the machine description.  */
1317
1318 int
1319 memory_operand (rtx op, enum machine_mode mode)
1320 {
1321   rtx inner;
1322
1323   if (! reload_completed)
1324     /* Note that no SUBREG is a memory operand before end of reload pass,
1325        because (SUBREG (MEM...)) forces reloading into a register.  */
1326     return MEM_P (op) && general_operand (op, mode);
1327
1328   if (mode != VOIDmode && GET_MODE (op) != mode)
1329     return 0;
1330
1331   inner = op;
1332   if (GET_CODE (inner) == SUBREG)
1333     inner = SUBREG_REG (inner);
1334
1335   return (MEM_P (inner) && general_operand (op, mode));
1336 }
1337
1338 /* Return 1 if OP is a valid indirect memory reference with mode MODE;
1339    that is, a memory reference whose address is a general_operand.  */
1340
1341 int
1342 indirect_operand (rtx op, enum machine_mode mode)
1343 {
1344   /* Before reload, a SUBREG isn't in memory (see memory_operand, above).  */
1345   if (! reload_completed
1346       && GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))
1347     {
1348       int offset = SUBREG_BYTE (op);
1349       rtx inner = SUBREG_REG (op);
1350
1351       if (mode != VOIDmode && GET_MODE (op) != mode)
1352         return 0;
1353
1354       /* The only way that we can have a general_operand as the resulting
1355          address is if OFFSET is zero and the address already is an operand
1356          or if the address is (plus Y (const_int -OFFSET)) and Y is an
1357          operand.  */
1358
1359       return ((offset == 0 && general_operand (XEXP (inner, 0), Pmode))
1360               || (GET_CODE (XEXP (inner, 0)) == PLUS
1361                   && GET_CODE (XEXP (XEXP (inner, 0), 1)) == CONST_INT
1362                   && INTVAL (XEXP (XEXP (inner, 0), 1)) == -offset
1363                   && general_operand (XEXP (XEXP (inner, 0), 0), Pmode)));
1364     }
1365
1366   return (MEM_P (op)
1367           && memory_operand (op, mode)
1368           && general_operand (XEXP (op, 0), Pmode));
1369 }
1370
1371 /* Return 1 if this is a comparison operator.  This allows the use of
1372    MATCH_OPERATOR to recognize all the branch insns.  */
1373
1374 int
1375 comparison_operator (rtx op, enum machine_mode mode)
1376 {
1377   return ((mode == VOIDmode || GET_MODE (op) == mode)
1378           && COMPARISON_P (op));
1379 }
1380 \f
1381 /* If BODY is an insn body that uses ASM_OPERANDS,
1382    return the number of operands (both input and output) in the insn.
1383    Otherwise return -1.  */
1384
1385 int
1386 asm_noperands (rtx body)
1387 {
1388   switch (GET_CODE (body))
1389     {
1390     case ASM_OPERANDS:
1391       /* No output operands: return number of input operands.  */
1392       return ASM_OPERANDS_INPUT_LENGTH (body);
1393     case SET:
1394       if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1395         /* Single output operand: BODY is (set OUTPUT (asm_operands ...)).  */
1396         return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (body)) + 1;
1397       else
1398         return -1;
1399     case PARALLEL:
1400       if (GET_CODE (XVECEXP (body, 0, 0)) == SET
1401           && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1402         {
1403           /* Multiple output operands, or 1 output plus some clobbers:
1404              body is [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...].  */
1405           int i;
1406           int n_sets;
1407
1408           /* Count backwards through CLOBBERs to determine number of SETs.  */
1409           for (i = XVECLEN (body, 0); i > 0; i--)
1410             {
1411               if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
1412                 break;
1413               if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
1414                 return -1;
1415             }
1416
1417           /* N_SETS is now number of output operands.  */
1418           n_sets = i;
1419
1420           /* Verify that all the SETs we have
1421              came from a single original asm_operands insn
1422              (so that invalid combinations are blocked).  */
1423           for (i = 0; i < n_sets; i++)
1424             {
1425               rtx elt = XVECEXP (body, 0, i);
1426               if (GET_CODE (elt) != SET)
1427                 return -1;
1428               if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
1429                 return -1;
1430               /* If these ASM_OPERANDS rtx's came from different original insns
1431                  then they aren't allowed together.  */
1432               if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
1433                   != ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (body, 0, 0))))
1434                 return -1;
1435             }
1436           return (ASM_OPERANDS_INPUT_LENGTH (SET_SRC (XVECEXP (body, 0, 0)))
1437                   + n_sets);
1438         }
1439       else if (GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1440         {
1441           /* 0 outputs, but some clobbers:
1442              body is [(asm_operands ...) (clobber (reg ...))...].  */
1443           int i;
1444
1445           /* Make sure all the other parallel things really are clobbers.  */
1446           for (i = XVECLEN (body, 0) - 1; i > 0; i--)
1447             if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
1448               return -1;
1449
1450           return ASM_OPERANDS_INPUT_LENGTH (XVECEXP (body, 0, 0));
1451         }
1452       else
1453         return -1;
1454     default:
1455       return -1;
1456     }
1457 }
1458
1459 /* Assuming BODY is an insn body that uses ASM_OPERANDS,
1460    copy its operands (both input and output) into the vector OPERANDS,
1461    the locations of the operands within the insn into the vector OPERAND_LOCS,
1462    and the constraints for the operands into CONSTRAINTS.
1463    Write the modes of the operands into MODES.
1464    Return the assembler-template.
1465
1466    If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1467    we don't store that info.  */
1468
1469 const char *
1470 decode_asm_operands (rtx body, rtx *operands, rtx **operand_locs,
1471                      const char **constraints, enum machine_mode *modes)
1472 {
1473   int i;
1474   int noperands;
1475   const char *template = 0;
1476
1477   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1478     {
1479       rtx asmop = SET_SRC (body);
1480       /* Single output operand: BODY is (set OUTPUT (asm_operands ....)).  */
1481
1482       noperands = ASM_OPERANDS_INPUT_LENGTH (asmop) + 1;
1483
1484       for (i = 1; i < noperands; i++)
1485         {
1486           if (operand_locs)
1487             operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i - 1);
1488           if (operands)
1489             operands[i] = ASM_OPERANDS_INPUT (asmop, i - 1);
1490           if (constraints)
1491             constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i - 1);
1492           if (modes)
1493             modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i - 1);
1494         }
1495
1496       /* The output is in the SET.
1497          Its constraint is in the ASM_OPERANDS itself.  */
1498       if (operands)
1499         operands[0] = SET_DEST (body);
1500       if (operand_locs)
1501         operand_locs[0] = &SET_DEST (body);
1502       if (constraints)
1503         constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
1504       if (modes)
1505         modes[0] = GET_MODE (SET_DEST (body));
1506       template = ASM_OPERANDS_TEMPLATE (asmop);
1507     }
1508   else if (GET_CODE (body) == ASM_OPERANDS)
1509     {
1510       rtx asmop = body;
1511       /* No output operands: BODY is (asm_operands ....).  */
1512
1513       noperands = ASM_OPERANDS_INPUT_LENGTH (asmop);
1514
1515       /* The input operands are found in the 1st element vector.  */
1516       /* Constraints for inputs are in the 2nd element vector.  */
1517       for (i = 0; i < noperands; i++)
1518         {
1519           if (operand_locs)
1520             operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1521           if (operands)
1522             operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1523           if (constraints)
1524             constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1525           if (modes)
1526             modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1527         }
1528       template = ASM_OPERANDS_TEMPLATE (asmop);
1529     }
1530   else if (GET_CODE (body) == PARALLEL
1531            && GET_CODE (XVECEXP (body, 0, 0)) == SET
1532            && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1533     {
1534       rtx asmop = SET_SRC (XVECEXP (body, 0, 0));
1535       int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs.  */
1536       int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1537       int nout = 0;             /* Does not include CLOBBERs.  */
1538
1539       /* At least one output, plus some CLOBBERs.  */
1540
1541       /* The outputs are in the SETs.
1542          Their constraints are in the ASM_OPERANDS itself.  */
1543       for (i = 0; i < nparallel; i++)
1544         {
1545           if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1546             break;              /* Past last SET */
1547
1548           if (operands)
1549             operands[i] = SET_DEST (XVECEXP (body, 0, i));
1550           if (operand_locs)
1551             operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
1552           if (constraints)
1553             constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
1554           if (modes)
1555             modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
1556           nout++;
1557         }
1558
1559       for (i = 0; i < nin; i++)
1560         {
1561           if (operand_locs)
1562             operand_locs[i + nout] = &ASM_OPERANDS_INPUT (asmop, i);
1563           if (operands)
1564             operands[i + nout] = ASM_OPERANDS_INPUT (asmop, i);
1565           if (constraints)
1566             constraints[i + nout] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1567           if (modes)
1568             modes[i + nout] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1569         }
1570
1571       template = ASM_OPERANDS_TEMPLATE (asmop);
1572     }
1573   else if (GET_CODE (body) == PARALLEL
1574            && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1575     {
1576       /* No outputs, but some CLOBBERs.  */
1577
1578       rtx asmop = XVECEXP (body, 0, 0);
1579       int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1580
1581       for (i = 0; i < nin; i++)
1582         {
1583           if (operand_locs)
1584             operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1585           if (operands)
1586             operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1587           if (constraints)
1588             constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1589           if (modes)
1590             modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1591         }
1592
1593       template = ASM_OPERANDS_TEMPLATE (asmop);
1594     }
1595
1596   return template;
1597 }
1598
1599 /* Check if an asm_operand matches its constraints.
1600    Return > 0 if ok, = 0 if bad, < 0 if inconclusive.  */
1601
1602 int
1603 asm_operand_ok (rtx op, const char *constraint)
1604 {
1605   int result = 0;
1606
1607   /* Use constrain_operands after reload.  */
1608   gcc_assert (!reload_completed);
1609
1610   while (*constraint)
1611     {
1612       char c = *constraint;
1613       int len;
1614       switch (c)
1615         {
1616         case ',':
1617           constraint++;
1618           continue;
1619         case '=':
1620         case '+':
1621         case '*':
1622         case '%':
1623         case '!':
1624         case '#':
1625         case '&':
1626         case '?':
1627           break;
1628
1629         case '0': case '1': case '2': case '3': case '4':
1630         case '5': case '6': case '7': case '8': case '9':
1631           /* For best results, our caller should have given us the
1632              proper matching constraint, but we can't actually fail
1633              the check if they didn't.  Indicate that results are
1634              inconclusive.  */
1635           do
1636             constraint++;
1637           while (ISDIGIT (*constraint));
1638           if (! result)
1639             result = -1;
1640           continue;
1641
1642         case 'p':
1643           if (address_operand (op, VOIDmode))
1644             result = 1;
1645           break;
1646
1647         case 'm':
1648         case 'V': /* non-offsettable */
1649           if (memory_operand (op, VOIDmode))
1650             result = 1;
1651           break;
1652
1653         case 'o': /* offsettable */
1654           if (offsettable_nonstrict_memref_p (op))
1655             result = 1;
1656           break;
1657
1658         case '<':
1659           /* ??? Before flow, auto inc/dec insns are not supposed to exist,
1660              excepting those that expand_call created.  Further, on some
1661              machines which do not have generalized auto inc/dec, an inc/dec
1662              is not a memory_operand.
1663
1664              Match any memory and hope things are resolved after reload.  */
1665
1666           if (MEM_P (op)
1667               && (1
1668                   || GET_CODE (XEXP (op, 0)) == PRE_DEC
1669                   || GET_CODE (XEXP (op, 0)) == POST_DEC))
1670             result = 1;
1671           break;
1672
1673         case '>':
1674           if (MEM_P (op)
1675               && (1
1676                   || GET_CODE (XEXP (op, 0)) == PRE_INC
1677                   || GET_CODE (XEXP (op, 0)) == POST_INC))
1678             result = 1;
1679           break;
1680
1681         case 'E':
1682         case 'F':
1683           if (GET_CODE (op) == CONST_DOUBLE
1684               || (GET_CODE (op) == CONST_VECTOR
1685                   && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
1686             result = 1;
1687           break;
1688
1689         case 'G':
1690           if (GET_CODE (op) == CONST_DOUBLE
1691               && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'G', constraint))
1692             result = 1;
1693           break;
1694         case 'H':
1695           if (GET_CODE (op) == CONST_DOUBLE
1696               && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'H', constraint))
1697             result = 1;
1698           break;
1699
1700         case 's':
1701           if (GET_CODE (op) == CONST_INT
1702               || (GET_CODE (op) == CONST_DOUBLE
1703                   && GET_MODE (op) == VOIDmode))
1704             break;
1705           /* Fall through.  */
1706
1707         case 'i':
1708           if (CONSTANT_P (op) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op)))
1709             result = 1;
1710           break;
1711
1712         case 'n':
1713           if (GET_CODE (op) == CONST_INT
1714               || (GET_CODE (op) == CONST_DOUBLE
1715                   && GET_MODE (op) == VOIDmode))
1716             result = 1;
1717           break;
1718
1719         case 'I':
1720           if (GET_CODE (op) == CONST_INT
1721               && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'I', constraint))
1722             result = 1;
1723           break;
1724         case 'J':
1725           if (GET_CODE (op) == CONST_INT
1726               && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'J', constraint))
1727             result = 1;
1728           break;
1729         case 'K':
1730           if (GET_CODE (op) == CONST_INT
1731               && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'K', constraint))
1732             result = 1;
1733           break;
1734         case 'L':
1735           if (GET_CODE (op) == CONST_INT
1736               && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'L', constraint))
1737             result = 1;
1738           break;
1739         case 'M':
1740           if (GET_CODE (op) == CONST_INT
1741               && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'M', constraint))
1742             result = 1;
1743           break;
1744         case 'N':
1745           if (GET_CODE (op) == CONST_INT
1746               && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'N', constraint))
1747             result = 1;
1748           break;
1749         case 'O':
1750           if (GET_CODE (op) == CONST_INT
1751               && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'O', constraint))
1752             result = 1;
1753           break;
1754         case 'P':
1755           if (GET_CODE (op) == CONST_INT
1756               && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'P', constraint))
1757             result = 1;
1758           break;
1759
1760         case 'X':
1761           result = 1;
1762           break;
1763
1764         case 'g':
1765           if (general_operand (op, VOIDmode))
1766             result = 1;
1767           break;
1768
1769         default:
1770           /* For all other letters, we first check for a register class,
1771              otherwise it is an EXTRA_CONSTRAINT.  */
1772           if (REG_CLASS_FROM_CONSTRAINT (c, constraint) != NO_REGS)
1773             {
1774             case 'r':
1775               if (GET_MODE (op) == BLKmode)
1776                 break;
1777               if (register_operand (op, VOIDmode))
1778                 result = 1;
1779             }
1780 #ifdef EXTRA_CONSTRAINT_STR
1781           else if (EXTRA_CONSTRAINT_STR (op, c, constraint))
1782             result = 1;
1783           else if (EXTRA_MEMORY_CONSTRAINT (c, constraint)
1784                    /* Every memory operand can be reloaded to fit.  */
1785                    && memory_operand (op, VOIDmode))
1786             result = 1;
1787           else if (EXTRA_ADDRESS_CONSTRAINT (c, constraint)
1788                    /* Every address operand can be reloaded to fit.  */
1789                    && address_operand (op, VOIDmode))
1790             result = 1;
1791 #endif
1792           break;
1793         }
1794       len = CONSTRAINT_LEN (c, constraint);
1795       do
1796         constraint++;
1797       while (--len && *constraint);
1798       if (len)
1799         return 0;
1800     }
1801
1802   return result;
1803 }
1804 \f
1805 /* Given an rtx *P, if it is a sum containing an integer constant term,
1806    return the location (type rtx *) of the pointer to that constant term.
1807    Otherwise, return a null pointer.  */
1808
1809 rtx *
1810 find_constant_term_loc (rtx *p)
1811 {
1812   rtx *tem;
1813   enum rtx_code code = GET_CODE (*p);
1814
1815   /* If *P IS such a constant term, P is its location.  */
1816
1817   if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1818       || code == CONST)
1819     return p;
1820
1821   /* Otherwise, if not a sum, it has no constant term.  */
1822
1823   if (GET_CODE (*p) != PLUS)
1824     return 0;
1825
1826   /* If one of the summands is constant, return its location.  */
1827
1828   if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1829       && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1830     return p;
1831
1832   /* Otherwise, check each summand for containing a constant term.  */
1833
1834   if (XEXP (*p, 0) != 0)
1835     {
1836       tem = find_constant_term_loc (&XEXP (*p, 0));
1837       if (tem != 0)
1838         return tem;
1839     }
1840
1841   if (XEXP (*p, 1) != 0)
1842     {
1843       tem = find_constant_term_loc (&XEXP (*p, 1));
1844       if (tem != 0)
1845         return tem;
1846     }
1847
1848   return 0;
1849 }
1850 \f
1851 /* Return 1 if OP is a memory reference
1852    whose address contains no side effects
1853    and remains valid after the addition
1854    of a positive integer less than the
1855    size of the object being referenced.
1856
1857    We assume that the original address is valid and do not check it.
1858
1859    This uses strict_memory_address_p as a subroutine, so
1860    don't use it before reload.  */
1861
1862 int
1863 offsettable_memref_p (rtx op)
1864 {
1865   return ((MEM_P (op))
1866           && offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
1867 }
1868
1869 /* Similar, but don't require a strictly valid mem ref:
1870    consider pseudo-regs valid as index or base regs.  */
1871
1872 int
1873 offsettable_nonstrict_memref_p (rtx op)
1874 {
1875   return ((MEM_P (op))
1876           && offsettable_address_p (0, GET_MODE (op), XEXP (op, 0)));
1877 }
1878
1879 /* Return 1 if Y is a memory address which contains no side effects
1880    and would remain valid after the addition of a positive integer
1881    less than the size of that mode.
1882
1883    We assume that the original address is valid and do not check it.
1884    We do check that it is valid for narrower modes.
1885
1886    If STRICTP is nonzero, we require a strictly valid address,
1887    for the sake of use in reload.c.  */
1888
1889 int
1890 offsettable_address_p (int strictp, enum machine_mode mode, rtx y)
1891 {
1892   enum rtx_code ycode = GET_CODE (y);
1893   rtx z;
1894   rtx y1 = y;
1895   rtx *y2;
1896   int (*addressp) (enum machine_mode, rtx) =
1897     (strictp ? strict_memory_address_p : memory_address_p);
1898   unsigned int mode_sz = GET_MODE_SIZE (mode);
1899
1900   if (CONSTANT_ADDRESS_P (y))
1901     return 1;
1902
1903   /* Adjusting an offsettable address involves changing to a narrower mode.
1904      Make sure that's OK.  */
1905
1906   if (mode_dependent_address_p (y))
1907     return 0;
1908
1909   /* ??? How much offset does an offsettable BLKmode reference need?
1910      Clearly that depends on the situation in which it's being used.
1911      However, the current situation in which we test 0xffffffff is
1912      less than ideal.  Caveat user.  */
1913   if (mode_sz == 0)
1914     mode_sz = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
1915
1916   /* If the expression contains a constant term,
1917      see if it remains valid when max possible offset is added.  */
1918
1919   if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
1920     {
1921       int good;
1922
1923       y1 = *y2;
1924       *y2 = plus_constant (*y2, mode_sz - 1);
1925       /* Use QImode because an odd displacement may be automatically invalid
1926          for any wider mode.  But it should be valid for a single byte.  */
1927       good = (*addressp) (QImode, y);
1928
1929       /* In any case, restore old contents of memory.  */
1930       *y2 = y1;
1931       return good;
1932     }
1933
1934   if (GET_RTX_CLASS (ycode) == RTX_AUTOINC)
1935     return 0;
1936
1937   /* The offset added here is chosen as the maximum offset that
1938      any instruction could need to add when operating on something
1939      of the specified mode.  We assume that if Y and Y+c are
1940      valid addresses then so is Y+d for all 0<d<c.  adjust_address will
1941      go inside a LO_SUM here, so we do so as well.  */
1942   if (GET_CODE (y) == LO_SUM
1943       && mode != BLKmode
1944       && mode_sz <= GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT)
1945     z = gen_rtx_LO_SUM (GET_MODE (y), XEXP (y, 0),
1946                         plus_constant (XEXP (y, 1), mode_sz - 1));
1947   else
1948     z = plus_constant (y, mode_sz - 1);
1949
1950   /* Use QImode because an odd displacement may be automatically invalid
1951      for any wider mode.  But it should be valid for a single byte.  */
1952   return (*addressp) (QImode, z);
1953 }
1954
1955 /* Return 1 if ADDR is an address-expression whose effect depends
1956    on the mode of the memory reference it is used in.
1957
1958    Autoincrement addressing is a typical example of mode-dependence
1959    because the amount of the increment depends on the mode.  */
1960
1961 int
1962 mode_dependent_address_p (rtx addr ATTRIBUTE_UNUSED /* Maybe used in GO_IF_MODE_DEPENDENT_ADDRESS.  */)
1963 {
1964   GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
1965   return 0;
1966   /* Label `win' might (not) be used via GO_IF_MODE_DEPENDENT_ADDRESS.  */
1967  win: ATTRIBUTE_UNUSED_LABEL
1968   return 1;
1969 }
1970 \f
1971 /* Like extract_insn, but save insn extracted and don't extract again, when
1972    called again for the same insn expecting that recog_data still contain the
1973    valid information.  This is used primary by gen_attr infrastructure that
1974    often does extract insn again and again.  */
1975 void
1976 extract_insn_cached (rtx insn)
1977 {
1978   if (recog_data.insn == insn && INSN_CODE (insn) >= 0)
1979     return;
1980   extract_insn (insn);
1981   recog_data.insn = insn;
1982 }
1983
1984 /* Do cached extract_insn, constrain_operands and complain about failures.
1985    Used by insn_attrtab.  */
1986 void
1987 extract_constrain_insn_cached (rtx insn)
1988 {
1989   extract_insn_cached (insn);
1990   if (which_alternative == -1
1991       && !constrain_operands (reload_completed))
1992     fatal_insn_not_found (insn);
1993 }
1994
1995 /* Do cached constrain_operands and complain about failures.  */
1996 int
1997 constrain_operands_cached (int strict)
1998 {
1999   if (which_alternative == -1)
2000     return constrain_operands (strict);
2001   else
2002     return 1;
2003 }
2004 \f
2005 /* Analyze INSN and fill in recog_data.  */
2006
2007 void
2008 extract_insn (rtx insn)
2009 {
2010   int i;
2011   int icode;
2012   int noperands;
2013   rtx body = PATTERN (insn);
2014
2015   recog_data.insn = NULL;
2016   recog_data.n_operands = 0;
2017   recog_data.n_alternatives = 0;
2018   recog_data.n_dups = 0;
2019   which_alternative = -1;
2020
2021   switch (GET_CODE (body))
2022     {
2023     case USE:
2024     case CLOBBER:
2025     case ASM_INPUT:
2026     case ADDR_VEC:
2027     case ADDR_DIFF_VEC:
2028       return;
2029
2030     case SET:
2031       if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
2032         goto asm_insn;
2033       else
2034         goto normal_insn;
2035     case PARALLEL:
2036       if ((GET_CODE (XVECEXP (body, 0, 0)) == SET
2037            && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
2038           || GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
2039         goto asm_insn;
2040       else
2041         goto normal_insn;
2042     case ASM_OPERANDS:
2043     asm_insn:
2044       recog_data.n_operands = noperands = asm_noperands (body);
2045       if (noperands >= 0)
2046         {
2047           /* This insn is an `asm' with operands.  */
2048
2049           /* expand_asm_operands makes sure there aren't too many operands.  */
2050           gcc_assert (noperands <= MAX_RECOG_OPERANDS);
2051
2052           /* Now get the operand values and constraints out of the insn.  */
2053           decode_asm_operands (body, recog_data.operand,
2054                                recog_data.operand_loc,
2055                                recog_data.constraints,
2056                                recog_data.operand_mode);
2057           if (noperands > 0)
2058             {
2059               const char *p =  recog_data.constraints[0];
2060               recog_data.n_alternatives = 1;
2061               while (*p)
2062                 recog_data.n_alternatives += (*p++ == ',');
2063             }
2064           break;
2065         }
2066       fatal_insn_not_found (insn);
2067
2068     default:
2069     normal_insn:
2070       /* Ordinary insn: recognize it, get the operands via insn_extract
2071          and get the constraints.  */
2072
2073       icode = recog_memoized (insn);
2074       if (icode < 0)
2075         fatal_insn_not_found (insn);
2076
2077       recog_data.n_operands = noperands = insn_data[icode].n_operands;
2078       recog_data.n_alternatives = insn_data[icode].n_alternatives;
2079       recog_data.n_dups = insn_data[icode].n_dups;
2080
2081       insn_extract (insn);
2082
2083       for (i = 0; i < noperands; i++)
2084         {
2085           recog_data.constraints[i] = insn_data[icode].operand[i].constraint;
2086           recog_data.operand_mode[i] = insn_data[icode].operand[i].mode;
2087           /* VOIDmode match_operands gets mode from their real operand.  */
2088           if (recog_data.operand_mode[i] == VOIDmode)
2089             recog_data.operand_mode[i] = GET_MODE (recog_data.operand[i]);
2090         }
2091     }
2092   for (i = 0; i < noperands; i++)
2093     recog_data.operand_type[i]
2094       = (recog_data.constraints[i][0] == '=' ? OP_OUT
2095          : recog_data.constraints[i][0] == '+' ? OP_INOUT
2096          : OP_IN);
2097
2098   gcc_assert (recog_data.n_alternatives <= MAX_RECOG_ALTERNATIVES);
2099 }
2100
2101 /* After calling extract_insn, you can use this function to extract some
2102    information from the constraint strings into a more usable form.
2103    The collected data is stored in recog_op_alt.  */
2104 void
2105 preprocess_constraints (void)
2106 {
2107   int i;
2108
2109   for (i = 0; i < recog_data.n_operands; i++)
2110     memset (recog_op_alt[i], 0, (recog_data.n_alternatives
2111                                  * sizeof (struct operand_alternative)));
2112
2113   for (i = 0; i < recog_data.n_operands; i++)
2114     {
2115       int j;
2116       struct operand_alternative *op_alt;
2117       const char *p = recog_data.constraints[i];
2118
2119       op_alt = recog_op_alt[i];
2120
2121       for (j = 0; j < recog_data.n_alternatives; j++)
2122         {
2123           op_alt[j].cl = NO_REGS;
2124           op_alt[j].constraint = p;
2125           op_alt[j].matches = -1;
2126           op_alt[j].matched = -1;
2127
2128           if (*p == '\0' || *p == ',')
2129             {
2130               op_alt[j].anything_ok = 1;
2131               continue;
2132             }
2133
2134           for (;;)
2135             {
2136               char c = *p;
2137               if (c == '#')
2138                 do
2139                   c = *++p;
2140                 while (c != ',' && c != '\0');
2141               if (c == ',' || c == '\0')
2142                 {
2143                   p++;
2144                   break;
2145                 }
2146
2147               switch (c)
2148                 {
2149                 case '=': case '+': case '*': case '%':
2150                 case 'E': case 'F': case 'G': case 'H':
2151                 case 's': case 'i': case 'n':
2152                 case 'I': case 'J': case 'K': case 'L':
2153                 case 'M': case 'N': case 'O': case 'P':
2154                   /* These don't say anything we care about.  */
2155                   break;
2156
2157                 case '?':
2158                   op_alt[j].reject += 6;
2159                   break;
2160                 case '!':
2161                   op_alt[j].reject += 600;
2162                   break;
2163                 case '&':
2164                   op_alt[j].earlyclobber = 1;
2165                   break;
2166
2167                 case '0': case '1': case '2': case '3': case '4':
2168                 case '5': case '6': case '7': case '8': case '9':
2169                   {
2170                     char *end;
2171                     op_alt[j].matches = strtoul (p, &end, 10);
2172                     recog_op_alt[op_alt[j].matches][j].matched = i;
2173                     p = end;
2174                   }
2175                   continue;
2176
2177                 case 'm':
2178                   op_alt[j].memory_ok = 1;
2179                   break;
2180                 case '<':
2181                   op_alt[j].decmem_ok = 1;
2182                   break;
2183                 case '>':
2184                   op_alt[j].incmem_ok = 1;
2185                   break;
2186                 case 'V':
2187                   op_alt[j].nonoffmem_ok = 1;
2188                   break;
2189                 case 'o':
2190                   op_alt[j].offmem_ok = 1;
2191                   break;
2192                 case 'X':
2193                   op_alt[j].anything_ok = 1;
2194                   break;
2195
2196                 case 'p':
2197                   op_alt[j].is_address = 1;
2198                   op_alt[j].cl = reg_class_subunion[(int) op_alt[j].cl]
2199                     [(int) MODE_BASE_REG_CLASS (VOIDmode)];
2200                   break;
2201
2202                 case 'g':
2203                 case 'r':
2204                   op_alt[j].cl =
2205                    reg_class_subunion[(int) op_alt[j].cl][(int) GENERAL_REGS];
2206                   break;
2207
2208                 default:
2209                   if (EXTRA_MEMORY_CONSTRAINT (c, p))
2210                     {
2211                       op_alt[j].memory_ok = 1;
2212                       break;
2213                     }
2214                   if (EXTRA_ADDRESS_CONSTRAINT (c, p))
2215                     {
2216                       op_alt[j].is_address = 1;
2217                       op_alt[j].cl
2218                         = (reg_class_subunion
2219                            [(int) op_alt[j].cl]
2220                            [(int) MODE_BASE_REG_CLASS (VOIDmode)]);
2221                       break;
2222                     }
2223
2224                   op_alt[j].cl
2225                     = (reg_class_subunion
2226                        [(int) op_alt[j].cl]
2227                        [(int) REG_CLASS_FROM_CONSTRAINT ((unsigned char) c, p)]);
2228                   break;
2229                 }
2230               p += CONSTRAINT_LEN (c, p);
2231             }
2232         }
2233     }
2234 }
2235
2236 /* Check the operands of an insn against the insn's operand constraints
2237    and return 1 if they are valid.
2238    The information about the insn's operands, constraints, operand modes
2239    etc. is obtained from the global variables set up by extract_insn.
2240
2241    WHICH_ALTERNATIVE is set to a number which indicates which
2242    alternative of constraints was matched: 0 for the first alternative,
2243    1 for the next, etc.
2244
2245    In addition, when two operands are required to match
2246    and it happens that the output operand is (reg) while the
2247    input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
2248    make the output operand look like the input.
2249    This is because the output operand is the one the template will print.
2250
2251    This is used in final, just before printing the assembler code and by
2252    the routines that determine an insn's attribute.
2253
2254    If STRICT is a positive nonzero value, it means that we have been
2255    called after reload has been completed.  In that case, we must
2256    do all checks strictly.  If it is zero, it means that we have been called
2257    before reload has completed.  In that case, we first try to see if we can
2258    find an alternative that matches strictly.  If not, we try again, this
2259    time assuming that reload will fix up the insn.  This provides a "best
2260    guess" for the alternative and is used to compute attributes of insns prior
2261    to reload.  A negative value of STRICT is used for this internal call.  */
2262
2263 struct funny_match
2264 {
2265   int this, other;
2266 };
2267
2268 int
2269 constrain_operands (int strict)
2270 {
2271   const char *constraints[MAX_RECOG_OPERANDS];
2272   int matching_operands[MAX_RECOG_OPERANDS];
2273   int earlyclobber[MAX_RECOG_OPERANDS];
2274   int c;
2275
2276   struct funny_match funny_match[MAX_RECOG_OPERANDS];
2277   int funny_match_index;
2278
2279   which_alternative = 0;
2280   if (recog_data.n_operands == 0 || recog_data.n_alternatives == 0)
2281     return 1;
2282
2283   for (c = 0; c < recog_data.n_operands; c++)
2284     {
2285       constraints[c] = recog_data.constraints[c];
2286       matching_operands[c] = -1;
2287     }
2288
2289   do
2290     {
2291       int seen_earlyclobber_at = -1;
2292       int opno;
2293       int lose = 0;
2294       funny_match_index = 0;
2295
2296       for (opno = 0; opno < recog_data.n_operands; opno++)
2297         {
2298           rtx op = recog_data.operand[opno];
2299           enum machine_mode mode = GET_MODE (op);
2300           const char *p = constraints[opno];
2301           int offset = 0;
2302           int win = 0;
2303           int val;
2304           int len;
2305
2306           earlyclobber[opno] = 0;
2307
2308           /* A unary operator may be accepted by the predicate, but it
2309              is irrelevant for matching constraints.  */
2310           if (UNARY_P (op))
2311             op = XEXP (op, 0);
2312
2313           if (GET_CODE (op) == SUBREG)
2314             {
2315               if (REG_P (SUBREG_REG (op))
2316                   && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
2317                 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
2318                                               GET_MODE (SUBREG_REG (op)),
2319                                               SUBREG_BYTE (op),
2320                                               GET_MODE (op));
2321               op = SUBREG_REG (op);
2322             }
2323
2324           /* An empty constraint or empty alternative
2325              allows anything which matched the pattern.  */
2326           if (*p == 0 || *p == ',')
2327             win = 1;
2328
2329           do
2330             switch (c = *p, len = CONSTRAINT_LEN (c, p), c)
2331               {
2332               case '\0':
2333                 len = 0;
2334                 break;
2335               case ',':
2336                 c = '\0';
2337                 break;
2338
2339               case '?':  case '!': case '*':  case '%':
2340               case '=':  case '+':
2341                 break;
2342
2343               case '#':
2344                 /* Ignore rest of this alternative as far as
2345                    constraint checking is concerned.  */
2346                 do
2347                   p++;
2348                 while (*p && *p != ',');
2349                 len = 0;
2350                 break;
2351
2352               case '&':
2353                 earlyclobber[opno] = 1;
2354                 if (seen_earlyclobber_at < 0)
2355                   seen_earlyclobber_at = opno;
2356                 break;
2357
2358               case '0':  case '1':  case '2':  case '3':  case '4':
2359               case '5':  case '6':  case '7':  case '8':  case '9':
2360                 {
2361                   /* This operand must be the same as a previous one.
2362                      This kind of constraint is used for instructions such
2363                      as add when they take only two operands.
2364
2365                      Note that the lower-numbered operand is passed first.
2366
2367                      If we are not testing strictly, assume that this
2368                      constraint will be satisfied.  */
2369
2370                   char *end;
2371                   int match;
2372
2373                   match = strtoul (p, &end, 10);
2374                   p = end;
2375
2376                   if (strict < 0)
2377                     val = 1;
2378                   else
2379                     {
2380                       rtx op1 = recog_data.operand[match];
2381                       rtx op2 = recog_data.operand[opno];
2382
2383                       /* A unary operator may be accepted by the predicate,
2384                          but it is irrelevant for matching constraints.  */
2385                       if (UNARY_P (op1))
2386                         op1 = XEXP (op1, 0);
2387                       if (UNARY_P (op2))
2388                         op2 = XEXP (op2, 0);
2389
2390                       val = operands_match_p (op1, op2);
2391                     }
2392
2393                   matching_operands[opno] = match;
2394                   matching_operands[match] = opno;
2395
2396                   if (val != 0)
2397                     win = 1;
2398
2399                   /* If output is *x and input is *--x, arrange later
2400                      to change the output to *--x as well, since the
2401                      output op is the one that will be printed.  */
2402                   if (val == 2 && strict > 0)
2403                     {
2404                       funny_match[funny_match_index].this = opno;
2405                       funny_match[funny_match_index++].other = match;
2406                     }
2407                 }
2408                 len = 0;
2409                 break;
2410
2411               case 'p':
2412                 /* p is used for address_operands.  When we are called by
2413                    gen_reload, no one will have checked that the address is
2414                    strictly valid, i.e., that all pseudos requiring hard regs
2415                    have gotten them.  */
2416                 if (strict <= 0
2417                     || (strict_memory_address_p (recog_data.operand_mode[opno],
2418                                                  op)))
2419                   win = 1;
2420                 break;
2421
2422                 /* No need to check general_operand again;
2423                    it was done in insn-recog.c.  Well, except that reload
2424                    doesn't check the validity of its replacements, but
2425                    that should only matter when there's a bug.  */
2426               case 'g':
2427                 /* Anything goes unless it is a REG and really has a hard reg
2428                    but the hard reg is not in the class GENERAL_REGS.  */
2429                 if (REG_P (op))
2430                   {
2431                     if (strict < 0
2432                         || GENERAL_REGS == ALL_REGS
2433                         || (reload_in_progress
2434                             && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2435                         || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
2436                       win = 1;
2437                   }
2438                 else if (strict < 0 || general_operand (op, mode))
2439                   win = 1;
2440                 break;
2441
2442               case 'X':
2443                 /* This is used for a MATCH_SCRATCH in the cases when
2444                    we don't actually need anything.  So anything goes
2445                    any time.  */
2446                 win = 1;
2447                 break;
2448
2449               case 'm':
2450                 /* Memory operands must be valid, to the extent
2451                    required by STRICT.  */
2452                 if (MEM_P (op))
2453                   {
2454                     if (strict > 0
2455                         && !strict_memory_address_p (GET_MODE (op),
2456                                                      XEXP (op, 0)))
2457                       break;
2458                     if (strict == 0
2459                         && !memory_address_p (GET_MODE (op), XEXP (op, 0)))
2460                       break;
2461                     win = 1;
2462                   }
2463                 /* Before reload, accept what reload can turn into mem.  */
2464                 else if (strict < 0 && CONSTANT_P (op))
2465                   win = 1;
2466                 /* During reload, accept a pseudo  */
2467                 else if (reload_in_progress && REG_P (op)
2468                          && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2469                   win = 1;
2470                 break;
2471
2472               case '<':
2473                 if (MEM_P (op)
2474                     && (GET_CODE (XEXP (op, 0)) == PRE_DEC
2475                         || GET_CODE (XEXP (op, 0)) == POST_DEC))
2476                   win = 1;
2477                 break;
2478
2479               case '>':
2480                 if (MEM_P (op)
2481                     && (GET_CODE (XEXP (op, 0)) == PRE_INC
2482                         || GET_CODE (XEXP (op, 0)) == POST_INC))
2483                   win = 1;
2484                 break;
2485
2486               case 'E':
2487               case 'F':
2488                 if (GET_CODE (op) == CONST_DOUBLE
2489                     || (GET_CODE (op) == CONST_VECTOR
2490                         && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
2491                   win = 1;
2492                 break;
2493
2494               case 'G':
2495               case 'H':
2496                 if (GET_CODE (op) == CONST_DOUBLE
2497                     && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, p))
2498                   win = 1;
2499                 break;
2500
2501               case 's':
2502                 if (GET_CODE (op) == CONST_INT
2503                     || (GET_CODE (op) == CONST_DOUBLE
2504                         && GET_MODE (op) == VOIDmode))
2505                   break;
2506               case 'i':
2507                 if (CONSTANT_P (op))
2508                   win = 1;
2509                 break;
2510
2511               case 'n':
2512                 if (GET_CODE (op) == CONST_INT
2513                     || (GET_CODE (op) == CONST_DOUBLE
2514                         && GET_MODE (op) == VOIDmode))
2515                   win = 1;
2516                 break;
2517
2518               case 'I':
2519               case 'J':
2520               case 'K':
2521               case 'L':
2522               case 'M':
2523               case 'N':
2524               case 'O':
2525               case 'P':
2526                 if (GET_CODE (op) == CONST_INT
2527                     && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, p))
2528                   win = 1;
2529                 break;
2530
2531               case 'V':
2532                 if (MEM_P (op)
2533                     && ((strict > 0 && ! offsettable_memref_p (op))
2534                         || (strict < 0
2535                             && !(CONSTANT_P (op) || MEM_P (op)))
2536                         || (reload_in_progress
2537                             && !(REG_P (op)
2538                                  && REGNO (op) >= FIRST_PSEUDO_REGISTER))))
2539                   win = 1;
2540                 break;
2541
2542               case 'o':
2543                 if ((strict > 0 && offsettable_memref_p (op))
2544                     || (strict == 0 && offsettable_nonstrict_memref_p (op))
2545                     /* Before reload, accept what reload can handle.  */
2546                     || (strict < 0
2547                         && (CONSTANT_P (op) || MEM_P (op)))
2548                     /* During reload, accept a pseudo  */
2549                     || (reload_in_progress && REG_P (op)
2550                         && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2551                   win = 1;
2552                 break;
2553
2554               default:
2555                 {
2556                   enum reg_class cl;
2557
2558                   cl = (c == 'r'
2559                            ? GENERAL_REGS : REG_CLASS_FROM_CONSTRAINT (c, p));
2560                   if (cl != NO_REGS)
2561                     {
2562                       if (strict < 0
2563                           || (strict == 0
2564                               && REG_P (op)
2565                               && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2566                           || (strict == 0 && GET_CODE (op) == SCRATCH)
2567                           || (REG_P (op)
2568                               && reg_fits_class_p (op, cl, offset, mode)))
2569                         win = 1;
2570                     }
2571 #ifdef EXTRA_CONSTRAINT_STR
2572                   else if (EXTRA_CONSTRAINT_STR (op, c, p))
2573                     win = 1;
2574
2575                   else if (EXTRA_MEMORY_CONSTRAINT (c, p)
2576                            /* Every memory operand can be reloaded to fit.  */
2577                            && ((strict < 0 && MEM_P (op))
2578                                /* Before reload, accept what reload can turn
2579                                   into mem.  */
2580                                || (strict < 0 && CONSTANT_P (op))
2581                                /* During reload, accept a pseudo  */
2582                                || (reload_in_progress && REG_P (op)
2583                                    && REGNO (op) >= FIRST_PSEUDO_REGISTER)))
2584                     win = 1;
2585                   else if (EXTRA_ADDRESS_CONSTRAINT (c, p)
2586                            /* Every address operand can be reloaded to fit.  */
2587                            && strict < 0)
2588                     win = 1;
2589 #endif
2590                   break;
2591                 }
2592               }
2593           while (p += len, c);
2594
2595           constraints[opno] = p;
2596           /* If this operand did not win somehow,
2597              this alternative loses.  */
2598           if (! win)
2599             lose = 1;
2600         }
2601       /* This alternative won; the operands are ok.
2602          Change whichever operands this alternative says to change.  */
2603       if (! lose)
2604         {
2605           int opno, eopno;
2606
2607           /* See if any earlyclobber operand conflicts with some other
2608              operand.  */
2609
2610           if (strict > 0  && seen_earlyclobber_at >= 0)
2611             for (eopno = seen_earlyclobber_at;
2612                  eopno < recog_data.n_operands;
2613                  eopno++)
2614               /* Ignore earlyclobber operands now in memory,
2615                  because we would often report failure when we have
2616                  two memory operands, one of which was formerly a REG.  */
2617               if (earlyclobber[eopno]
2618                   && REG_P (recog_data.operand[eopno]))
2619                 for (opno = 0; opno < recog_data.n_operands; opno++)
2620                   if ((MEM_P (recog_data.operand[opno])
2621                        || recog_data.operand_type[opno] != OP_OUT)
2622                       && opno != eopno
2623                       /* Ignore things like match_operator operands.  */
2624                       && *recog_data.constraints[opno] != 0
2625                       && ! (matching_operands[opno] == eopno
2626                             && operands_match_p (recog_data.operand[opno],
2627                                                  recog_data.operand[eopno]))
2628                       && ! safe_from_earlyclobber (recog_data.operand[opno],
2629                                                    recog_data.operand[eopno]))
2630                     lose = 1;
2631
2632           if (! lose)
2633             {
2634               while (--funny_match_index >= 0)
2635                 {
2636                   recog_data.operand[funny_match[funny_match_index].other]
2637                     = recog_data.operand[funny_match[funny_match_index].this];
2638                 }
2639
2640               return 1;
2641             }
2642         }
2643
2644       which_alternative++;
2645     }
2646   while (which_alternative < recog_data.n_alternatives);
2647
2648   which_alternative = -1;
2649   /* If we are about to reject this, but we are not to test strictly,
2650      try a very loose test.  Only return failure if it fails also.  */
2651   if (strict == 0)
2652     return constrain_operands (-1);
2653   else
2654     return 0;
2655 }
2656
2657 /* Return 1 iff OPERAND (assumed to be a REG rtx)
2658    is a hard reg in class CLASS when its regno is offset by OFFSET
2659    and changed to mode MODE.
2660    If REG occupies multiple hard regs, all of them must be in CLASS.  */
2661
2662 int
2663 reg_fits_class_p (rtx operand, enum reg_class cl, int offset,
2664                   enum machine_mode mode)
2665 {
2666   int regno = REGNO (operand);
2667
2668   if (cl == NO_REGS)
2669     return 0;
2670
2671   if (regno < FIRST_PSEUDO_REGISTER
2672       && TEST_HARD_REG_BIT (reg_class_contents[(int) cl],
2673                             regno + offset))
2674     {
2675       int sr;
2676       regno += offset;
2677       for (sr = hard_regno_nregs[regno][mode] - 1;
2678            sr > 0; sr--)
2679         if (! TEST_HARD_REG_BIT (reg_class_contents[(int) cl],
2680                                  regno + sr))
2681           break;
2682       return sr == 0;
2683     }
2684
2685   return 0;
2686 }
2687 \f
2688 /* Split single instruction.  Helper function for split_all_insns and
2689    split_all_insns_noflow.  Return last insn in the sequence if successful,
2690    or NULL if unsuccessful.  */
2691
2692 static rtx
2693 split_insn (rtx insn)
2694 {
2695   /* Split insns here to get max fine-grain parallelism.  */
2696   rtx first = PREV_INSN (insn);
2697   rtx last = try_split (PATTERN (insn), insn, 1);
2698
2699   if (last == insn)
2700     return NULL_RTX;
2701
2702   /* try_split returns the NOTE that INSN became.  */
2703   SET_INSN_DELETED (insn);
2704
2705   /* ??? Coddle to md files that generate subregs in post-reload
2706      splitters instead of computing the proper hard register.  */
2707   if (reload_completed && first != last)
2708     {
2709       first = NEXT_INSN (first);
2710       for (;;)
2711         {
2712           if (INSN_P (first))
2713             cleanup_subreg_operands (first);
2714           if (first == last)
2715             break;
2716           first = NEXT_INSN (first);
2717         }
2718     }
2719   return last;
2720 }
2721
2722 /* Split all insns in the function.  If UPD_LIFE, update life info after.  */
2723
2724 void
2725 split_all_insns (int upd_life)
2726 {
2727   sbitmap blocks;
2728   bool changed;
2729   basic_block bb;
2730
2731   blocks = sbitmap_alloc (last_basic_block);
2732   sbitmap_zero (blocks);
2733   changed = false;
2734
2735   FOR_EACH_BB_REVERSE (bb)
2736     {
2737       rtx insn, next;
2738       bool finish = false;
2739
2740       for (insn = BB_HEAD (bb); !finish ; insn = next)
2741         {
2742           /* Can't use `next_real_insn' because that might go across
2743              CODE_LABELS and short-out basic blocks.  */
2744           next = NEXT_INSN (insn);
2745           finish = (insn == BB_END (bb));
2746           if (INSN_P (insn))
2747             {
2748               rtx set = single_set (insn);
2749
2750               /* Don't split no-op move insns.  These should silently
2751                  disappear later in final.  Splitting such insns would
2752                  break the code that handles REG_NO_CONFLICT blocks.  */
2753               if (set && set_noop_p (set))
2754                 {
2755                   /* Nops get in the way while scheduling, so delete them
2756                      now if register allocation has already been done.  It
2757                      is too risky to try to do this before register
2758                      allocation, and there are unlikely to be very many
2759                      nops then anyways.  */
2760                   if (reload_completed)
2761                     {
2762                       /* If the no-op set has a REG_UNUSED note, we need
2763                          to update liveness information.  */
2764                       if (find_reg_note (insn, REG_UNUSED, NULL_RTX))
2765                         {
2766                           SET_BIT (blocks, bb->index);
2767                           changed = true;
2768                         }
2769                       /* ??? Is life info affected by deleting edges?  */
2770                       delete_insn_and_edges (insn);
2771                     }
2772                 }
2773               else
2774                 {
2775                   rtx last = split_insn (insn);
2776                   if (last)
2777                     {
2778                       /* The split sequence may include barrier, but the
2779                          BB boundary we are interested in will be set to
2780                          previous one.  */
2781
2782                       while (BARRIER_P (last))
2783                         last = PREV_INSN (last);
2784                       SET_BIT (blocks, bb->index);
2785                       changed = true;
2786                     }
2787                 }
2788             }
2789         }
2790     }
2791
2792   if (changed)
2793     {
2794       int old_last_basic_block = last_basic_block;
2795
2796       find_many_sub_basic_blocks (blocks);
2797
2798       if (old_last_basic_block != last_basic_block && upd_life)
2799         blocks = sbitmap_resize (blocks, last_basic_block, 1);
2800     }
2801
2802   if (changed && upd_life)
2803     update_life_info (blocks, UPDATE_LIFE_GLOBAL_RM_NOTES,
2804                       PROP_DEATH_NOTES);
2805
2806 #ifdef ENABLE_CHECKING
2807   verify_flow_info ();
2808 #endif
2809
2810   sbitmap_free (blocks);
2811 }
2812
2813 /* Same as split_all_insns, but do not expect CFG to be available.
2814    Used by machine dependent reorg passes.  */
2815
2816 unsigned int
2817 split_all_insns_noflow (void)
2818 {
2819   rtx next, insn;
2820
2821   for (insn = get_insns (); insn; insn = next)
2822     {
2823       next = NEXT_INSN (insn);
2824       if (INSN_P (insn))
2825         {
2826           /* Don't split no-op move insns.  These should silently
2827              disappear later in final.  Splitting such insns would
2828              break the code that handles REG_NO_CONFLICT blocks.  */
2829           rtx set = single_set (insn);
2830           if (set && set_noop_p (set))
2831             {
2832               /* Nops get in the way while scheduling, so delete them
2833                  now if register allocation has already been done.  It
2834                  is too risky to try to do this before register
2835                  allocation, and there are unlikely to be very many
2836                  nops then anyways.
2837
2838                  ??? Should we use delete_insn when the CFG isn't valid?  */
2839               if (reload_completed)
2840                 delete_insn_and_edges (insn);
2841             }
2842           else
2843             split_insn (insn);
2844         }
2845     }
2846   return 0;
2847 }
2848 \f
2849 #ifdef HAVE_peephole2
2850 struct peep2_insn_data
2851 {
2852   rtx insn;
2853   regset live_before;
2854 };
2855
2856 static struct peep2_insn_data peep2_insn_data[MAX_INSNS_PER_PEEP2 + 1];
2857 static int peep2_current;
2858 /* The number of instructions available to match a peep2.  */
2859 int peep2_current_count;
2860
2861 /* A non-insn marker indicating the last insn of the block.
2862    The live_before regset for this element is correct, indicating
2863    global_live_at_end for the block.  */
2864 #define PEEP2_EOB       pc_rtx
2865
2866 /* Return the Nth non-note insn after `current', or return NULL_RTX if it
2867    does not exist.  Used by the recognizer to find the next insn to match
2868    in a multi-insn pattern.  */
2869
2870 rtx
2871 peep2_next_insn (int n)
2872 {
2873   gcc_assert (n <= peep2_current_count);
2874
2875   n += peep2_current;
2876   if (n >= MAX_INSNS_PER_PEEP2 + 1)
2877     n -= MAX_INSNS_PER_PEEP2 + 1;
2878
2879   return peep2_insn_data[n].insn;
2880 }
2881
2882 /* Return true if REGNO is dead before the Nth non-note insn
2883    after `current'.  */
2884
2885 int
2886 peep2_regno_dead_p (int ofs, int regno)
2887 {
2888   gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
2889
2890   ofs += peep2_current;
2891   if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2892     ofs -= MAX_INSNS_PER_PEEP2 + 1;
2893
2894   gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
2895
2896   return ! REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno);
2897 }
2898
2899 /* Similarly for a REG.  */
2900
2901 int
2902 peep2_reg_dead_p (int ofs, rtx reg)
2903 {
2904   int regno, n;
2905
2906   gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
2907
2908   ofs += peep2_current;
2909   if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2910     ofs -= MAX_INSNS_PER_PEEP2 + 1;
2911
2912   gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
2913
2914   regno = REGNO (reg);
2915   n = hard_regno_nregs[regno][GET_MODE (reg)];
2916   while (--n >= 0)
2917     if (REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno + n))
2918       return 0;
2919   return 1;
2920 }
2921
2922 /* Try to find a hard register of mode MODE, matching the register class in
2923    CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
2924    remains available until the end of LAST_INSN.  LAST_INSN may be NULL_RTX,
2925    in which case the only condition is that the register must be available
2926    before CURRENT_INSN.
2927    Registers that already have bits set in REG_SET will not be considered.
2928
2929    If an appropriate register is available, it will be returned and the
2930    corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
2931    returned.  */
2932
2933 rtx
2934 peep2_find_free_register (int from, int to, const char *class_str,
2935                           enum machine_mode mode, HARD_REG_SET *reg_set)
2936 {
2937   static int search_ofs;
2938   enum reg_class cl;
2939   HARD_REG_SET live;
2940   int i;
2941
2942   gcc_assert (from < MAX_INSNS_PER_PEEP2 + 1);
2943   gcc_assert (to < MAX_INSNS_PER_PEEP2 + 1);
2944
2945   from += peep2_current;
2946   if (from >= MAX_INSNS_PER_PEEP2 + 1)
2947     from -= MAX_INSNS_PER_PEEP2 + 1;
2948   to += peep2_current;
2949   if (to >= MAX_INSNS_PER_PEEP2 + 1)
2950     to -= MAX_INSNS_PER_PEEP2 + 1;
2951
2952   gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
2953   REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before);
2954
2955   while (from != to)
2956     {
2957       HARD_REG_SET this_live;
2958
2959       if (++from >= MAX_INSNS_PER_PEEP2 + 1)
2960         from = 0;
2961       gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
2962       REG_SET_TO_HARD_REG_SET (this_live, peep2_insn_data[from].live_before);
2963       IOR_HARD_REG_SET (live, this_live);
2964     }
2965
2966   cl = (class_str[0] == 'r' ? GENERAL_REGS
2967            : REG_CLASS_FROM_CONSTRAINT (class_str[0], class_str));
2968
2969   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2970     {
2971       int raw_regno, regno, success, j;
2972
2973       /* Distribute the free registers as much as possible.  */
2974       raw_regno = search_ofs + i;
2975       if (raw_regno >= FIRST_PSEUDO_REGISTER)
2976         raw_regno -= FIRST_PSEUDO_REGISTER;
2977 #ifdef REG_ALLOC_ORDER
2978       regno = reg_alloc_order[raw_regno];
2979 #else
2980       regno = raw_regno;
2981 #endif
2982
2983       /* Don't allocate fixed registers.  */
2984       if (fixed_regs[regno])
2985         continue;
2986       /* Make sure the register is of the right class.  */
2987       if (! TEST_HARD_REG_BIT (reg_class_contents[cl], regno))
2988         continue;
2989       /* And can support the mode we need.  */
2990       if (! HARD_REGNO_MODE_OK (regno, mode))
2991         continue;
2992       /* And that we don't create an extra save/restore.  */
2993       if (! call_used_regs[regno] && ! regs_ever_live[regno])
2994         continue;
2995       /* And we don't clobber traceback for noreturn functions.  */
2996       if ((regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM)
2997           && (! reload_completed || frame_pointer_needed))
2998         continue;
2999
3000       success = 1;
3001       for (j = hard_regno_nregs[regno][mode] - 1; j >= 0; j--)
3002         {
3003           if (TEST_HARD_REG_BIT (*reg_set, regno + j)
3004               || TEST_HARD_REG_BIT (live, regno + j))
3005             {
3006               success = 0;
3007               break;
3008             }
3009         }
3010       if (success)
3011         {
3012           for (j = hard_regno_nregs[regno][mode] - 1; j >= 0; j--)
3013             SET_HARD_REG_BIT (*reg_set, regno + j);
3014
3015           /* Start the next search with the next register.  */
3016           if (++raw_regno >= FIRST_PSEUDO_REGISTER)
3017             raw_regno = 0;
3018           search_ofs = raw_regno;
3019
3020           return gen_rtx_REG (mode, regno);
3021         }
3022     }
3023
3024   search_ofs = 0;
3025   return NULL_RTX;
3026 }
3027
3028 /* Perform the peephole2 optimization pass.  */
3029
3030 static void
3031 peephole2_optimize (void)
3032 {
3033   rtx insn, prev;
3034   regset live;
3035   int i;
3036   basic_block bb;
3037 #ifdef HAVE_conditional_execution
3038   sbitmap blocks;
3039   bool changed;
3040 #endif
3041   bool do_cleanup_cfg = false;
3042   bool do_global_life_update = false;
3043   bool do_rebuild_jump_labels = false;
3044
3045   /* Initialize the regsets we're going to use.  */
3046   for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3047     peep2_insn_data[i].live_before = ALLOC_REG_SET (&reg_obstack);
3048   live = ALLOC_REG_SET (&reg_obstack);
3049
3050 #ifdef HAVE_conditional_execution
3051   blocks = sbitmap_alloc (last_basic_block);
3052   sbitmap_zero (blocks);
3053   changed = false;
3054 #else
3055   count_or_remove_death_notes (NULL, 1);
3056 #endif
3057
3058   FOR_EACH_BB_REVERSE (bb)
3059     {
3060       struct propagate_block_info *pbi;
3061       reg_set_iterator rsi;
3062       unsigned int j;
3063
3064       /* Indicate that all slots except the last holds invalid data.  */
3065       for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
3066         peep2_insn_data[i].insn = NULL_RTX;
3067       peep2_current_count = 0;
3068
3069       /* Indicate that the last slot contains live_after data.  */
3070       peep2_insn_data[MAX_INSNS_PER_PEEP2].insn = PEEP2_EOB;
3071       peep2_current = MAX_INSNS_PER_PEEP2;
3072
3073       /* Start up propagation.  */
3074       COPY_REG_SET (live, bb->il.rtl->global_live_at_end);
3075       COPY_REG_SET (peep2_insn_data[MAX_INSNS_PER_PEEP2].live_before, live);
3076
3077 #ifdef HAVE_conditional_execution
3078       pbi = init_propagate_block_info (bb, live, NULL, NULL, 0);
3079 #else
3080       pbi = init_propagate_block_info (bb, live, NULL, NULL, PROP_DEATH_NOTES);
3081 #endif
3082
3083       for (insn = BB_END (bb); ; insn = prev)
3084         {
3085           prev = PREV_INSN (insn);
3086           if (INSN_P (insn))
3087             {
3088               rtx try, before_try, x;
3089               int match_len;
3090               rtx note;
3091               bool was_call = false;
3092
3093               /* Record this insn.  */
3094               if (--peep2_current < 0)
3095                 peep2_current = MAX_INSNS_PER_PEEP2;
3096               if (peep2_current_count < MAX_INSNS_PER_PEEP2
3097                   && peep2_insn_data[peep2_current].insn == NULL_RTX)
3098                 peep2_current_count++;
3099               peep2_insn_data[peep2_current].insn = insn;
3100               propagate_one_insn (pbi, insn);
3101               COPY_REG_SET (peep2_insn_data[peep2_current].live_before, live);
3102
3103               if (RTX_FRAME_RELATED_P (insn))
3104                 {
3105                   /* If an insn has RTX_FRAME_RELATED_P set, peephole
3106                      substitution would lose the
3107                      REG_FRAME_RELATED_EXPR that is attached.  */
3108                   peep2_current_count = 0;
3109                   try = NULL;
3110                 }
3111               else
3112                 /* Match the peephole.  */
3113                 try = peephole2_insns (PATTERN (insn), insn, &match_len);
3114
3115               if (try != NULL)
3116                 {
3117                   /* If we are splitting a CALL_INSN, look for the CALL_INSN
3118                      in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other
3119                      cfg-related call notes.  */
3120                   for (i = 0; i <= match_len; ++i)
3121                     {
3122                       int j;
3123                       rtx old_insn, new_insn, note;
3124
3125                       j = i + peep2_current;
3126                       if (j >= MAX_INSNS_PER_PEEP2 + 1)
3127                         j -= MAX_INSNS_PER_PEEP2 + 1;
3128                       old_insn = peep2_insn_data[j].insn;
3129                       if (!CALL_P (old_insn))
3130                         continue;
3131                       was_call = true;
3132
3133                       new_insn = try;
3134                       while (new_insn != NULL_RTX)
3135                         {
3136                           if (CALL_P (new_insn))
3137                             break;
3138                           new_insn = NEXT_INSN (new_insn);
3139                         }
3140
3141                       gcc_assert (new_insn != NULL_RTX);
3142
3143                       CALL_INSN_FUNCTION_USAGE (new_insn)
3144                         = CALL_INSN_FUNCTION_USAGE (old_insn);
3145
3146                       for (note = REG_NOTES (old_insn);
3147                            note;
3148                            note = XEXP (note, 1))
3149                         switch (REG_NOTE_KIND (note))
3150                           {
3151                           case REG_NORETURN:
3152                           case REG_SETJMP:
3153                             REG_NOTES (new_insn)
3154                               = gen_rtx_EXPR_LIST (REG_NOTE_KIND (note),
3155                                                    XEXP (note, 0),
3156                                                    REG_NOTES (new_insn));
3157                           default:
3158                             /* Discard all other reg notes.  */
3159                             break;
3160                           }
3161
3162                       /* Croak if there is another call in the sequence.  */
3163                       while (++i <= match_len)
3164                         {
3165                           j = i + peep2_current;
3166                           if (j >= MAX_INSNS_PER_PEEP2 + 1)
3167                             j -= MAX_INSNS_PER_PEEP2 + 1;
3168                           old_insn = peep2_insn_data[j].insn;
3169                           gcc_assert (!CALL_P (old_insn));
3170                         }
3171                       break;
3172                     }
3173
3174                   i = match_len + peep2_current;
3175                   if (i >= MAX_INSNS_PER_PEEP2 + 1)
3176                     i -= MAX_INSNS_PER_PEEP2 + 1;
3177
3178                   note = find_reg_note (peep2_insn_data[i].insn,
3179                                         REG_EH_REGION, NULL_RTX);
3180
3181                   /* Replace the old sequence with the new.  */
3182                   try = emit_insn_after_setloc (try, peep2_insn_data[i].insn,
3183                                                 INSN_LOCATOR (peep2_insn_data[i].insn));
3184                   before_try = PREV_INSN (insn);
3185                   delete_insn_chain (insn, peep2_insn_data[i].insn);
3186
3187                   /* Re-insert the EH_REGION notes.  */
3188                   if (note || (was_call && nonlocal_goto_handler_labels))
3189                     {
3190                       edge eh_edge;
3191                       edge_iterator ei;
3192
3193                       FOR_EACH_EDGE (eh_edge, ei, bb->succs)
3194                         if (eh_edge->flags & (EDGE_EH | EDGE_ABNORMAL_CALL))
3195                           break;
3196
3197                       for (x = try ; x != before_try ; x = PREV_INSN (x))
3198                         if (CALL_P (x)
3199                             || (flag_non_call_exceptions
3200                                 && may_trap_p (PATTERN (x))
3201                                 && !find_reg_note (x, REG_EH_REGION, NULL)))
3202                           {
3203                             if (note)
3204                               REG_NOTES (x)
3205                                 = gen_rtx_EXPR_LIST (REG_EH_REGION,
3206                                                      XEXP (note, 0),
3207                                                      REG_NOTES (x));
3208
3209                             if (x != BB_END (bb) && eh_edge)
3210                               {
3211                                 edge nfte, nehe;
3212                                 int flags;
3213
3214                                 nfte = split_block (bb, x);
3215                                 flags = (eh_edge->flags
3216                                          & (EDGE_EH | EDGE_ABNORMAL));
3217                                 if (CALL_P (x))
3218                                   flags |= EDGE_ABNORMAL_CALL;
3219                                 nehe = make_edge (nfte->src, eh_edge->dest,
3220                                                   flags);
3221
3222                                 nehe->probability = eh_edge->probability;
3223                                 nfte->probability
3224                                   = REG_BR_PROB_BASE - nehe->probability;
3225
3226                                 do_cleanup_cfg |= purge_dead_edges (nfte->dest);
3227 #ifdef HAVE_conditional_execution
3228                                 SET_BIT (blocks, nfte->dest->index);
3229                                 changed = true;
3230 #endif
3231                                 bb = nfte->src;
3232                                 eh_edge = nehe;
3233                               }
3234                           }
3235
3236                       /* Converting possibly trapping insn to non-trapping is
3237                          possible.  Zap dummy outgoing edges.  */
3238                       do_cleanup_cfg |= purge_dead_edges (bb);
3239                     }
3240
3241 #ifdef HAVE_conditional_execution
3242                   /* With conditional execution, we cannot back up the
3243                      live information so easily, since the conditional
3244                      death data structures are not so self-contained.
3245                      So record that we've made a modification to this
3246                      block and update life information at the end.  */
3247                   SET_BIT (blocks, bb->index);
3248                   changed = true;
3249
3250                   for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3251                     peep2_insn_data[i].insn = NULL_RTX;
3252                   peep2_insn_data[peep2_current].insn = PEEP2_EOB;
3253                   peep2_current_count = 0;
3254 #else
3255                   /* Back up lifetime information past the end of the
3256                      newly created sequence.  */
3257                   if (++i >= MAX_INSNS_PER_PEEP2 + 1)
3258                     i = 0;
3259                   COPY_REG_SET (live, peep2_insn_data[i].live_before);
3260
3261                   /* Update life information for the new sequence.  */
3262                   x = try;
3263                   do
3264                     {
3265                       if (INSN_P (x))
3266                         {
3267                           if (--i < 0)
3268                             i = MAX_INSNS_PER_PEEP2;
3269                           if (peep2_current_count < MAX_INSNS_PER_PEEP2
3270                               && peep2_insn_data[i].insn == NULL_RTX)
3271                             peep2_current_count++;
3272                           peep2_insn_data[i].insn = x;
3273                           propagate_one_insn (pbi, x);
3274                           COPY_REG_SET (peep2_insn_data[i].live_before, live);
3275                         }
3276                       x = PREV_INSN (x);
3277                     }
3278                   while (x != prev);
3279
3280                   /* ??? Should verify that LIVE now matches what we
3281                      had before the new sequence.  */
3282
3283                   peep2_current = i;
3284 #endif
3285
3286                   /* If we generated a jump instruction, it won't have
3287                      JUMP_LABEL set.  Recompute after we're done.  */
3288                   for (x = try; x != before_try; x = PREV_INSN (x))
3289                     if (JUMP_P (x))
3290                       {
3291                         do_rebuild_jump_labels = true;
3292                         break;
3293                       }
3294                 }
3295             }
3296
3297           if (insn == BB_HEAD (bb))
3298             break;
3299         }
3300
3301       /* Some peepholes can decide the don't need one or more of their
3302          inputs.  If this happens, local life update is not enough.  */
3303       EXECUTE_IF_AND_COMPL_IN_BITMAP (bb->il.rtl->global_live_at_start, live,
3304                                       0, j, rsi)
3305         {
3306           do_global_life_update = true;
3307           break;
3308         }
3309
3310       free_propagate_block_info (pbi);
3311     }
3312
3313   for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3314     FREE_REG_SET (peep2_insn_data[i].live_before);
3315   FREE_REG_SET (live);
3316
3317   if (do_rebuild_jump_labels)
3318     rebuild_jump_labels (get_insns ());
3319
3320   /* If we eliminated EH edges, we may be able to merge blocks.  Further,
3321      we've changed global life since exception handlers are no longer
3322      reachable.  */
3323   if (do_cleanup_cfg)
3324     {
3325       cleanup_cfg (0);
3326       do_global_life_update = true;
3327     }
3328   if (do_global_life_update)
3329     update_life_info (0, UPDATE_LIFE_GLOBAL_RM_NOTES, PROP_DEATH_NOTES);
3330 #ifdef HAVE_conditional_execution
3331   else
3332     {
3333       count_or_remove_death_notes (blocks, 1);
3334       update_life_info (blocks, UPDATE_LIFE_LOCAL, PROP_DEATH_NOTES);
3335     }
3336   sbitmap_free (blocks);
3337 #endif
3338 }
3339 #endif /* HAVE_peephole2 */
3340
3341 /* Common predicates for use with define_bypass.  */
3342
3343 /* True if the dependency between OUT_INSN and IN_INSN is on the store
3344    data not the address operand(s) of the store.  IN_INSN must be
3345    single_set.  OUT_INSN must be either a single_set or a PARALLEL with
3346    SETs inside.  */
3347
3348 int
3349 store_data_bypass_p (rtx out_insn, rtx in_insn)
3350 {
3351   rtx out_set, in_set;
3352
3353   in_set = single_set (in_insn);
3354   gcc_assert (in_set);
3355
3356   if (!MEM_P (SET_DEST (in_set)))
3357     return false;
3358
3359   out_set = single_set (out_insn);
3360   if (out_set)
3361     {
3362       if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_set)))
3363         return false;
3364     }
3365   else
3366     {
3367       rtx out_pat;
3368       int i;
3369
3370       out_pat = PATTERN (out_insn);
3371       gcc_assert (GET_CODE (out_pat) == PARALLEL);
3372
3373       for (i = 0; i < XVECLEN (out_pat, 0); i++)
3374         {
3375           rtx exp = XVECEXP (out_pat, 0, i);
3376
3377           if (GET_CODE (exp) == CLOBBER)
3378             continue;
3379
3380           gcc_assert (GET_CODE (exp) == SET);
3381
3382           if (reg_mentioned_p (SET_DEST (exp), SET_DEST (in_set)))
3383             return false;
3384         }
3385     }
3386
3387   return true;
3388 }
3389
3390 /* True if the dependency between OUT_INSN and IN_INSN is in the IF_THEN_ELSE
3391    condition, and not the THEN or ELSE branch.  OUT_INSN may be either a single
3392    or multiple set; IN_INSN should be single_set for truth, but for convenience
3393    of insn categorization may be any JUMP or CALL insn.  */
3394
3395 int
3396 if_test_bypass_p (rtx out_insn, rtx in_insn)
3397 {
3398   rtx out_set, in_set;
3399
3400   in_set = single_set (in_insn);
3401   if (! in_set)
3402     {
3403       gcc_assert (JUMP_P (in_insn) || CALL_P (in_insn));
3404       return false;
3405     }
3406
3407   if (GET_CODE (SET_SRC (in_set)) != IF_THEN_ELSE)
3408     return false;
3409   in_set = SET_SRC (in_set);
3410
3411   out_set = single_set (out_insn);
3412   if (out_set)
3413     {
3414       if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3415           || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3416         return false;
3417     }
3418   else
3419     {
3420       rtx out_pat;
3421       int i;
3422
3423       out_pat = PATTERN (out_insn);
3424       gcc_assert (GET_CODE (out_pat) == PARALLEL);
3425
3426       for (i = 0; i < XVECLEN (out_pat, 0); i++)
3427         {
3428           rtx exp = XVECEXP (out_pat, 0, i);
3429
3430           if (GET_CODE (exp) == CLOBBER)
3431             continue;
3432
3433           gcc_assert (GET_CODE (exp) == SET);
3434
3435           if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3436               || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3437             return false;
3438         }
3439     }
3440
3441   return true;
3442 }
3443 \f
3444 static bool
3445 gate_handle_peephole2 (void)
3446 {
3447   return (optimize > 0 && flag_peephole2);
3448 }
3449
3450 static unsigned int
3451 rest_of_handle_peephole2 (void)
3452 {
3453 #ifdef HAVE_peephole2
3454   peephole2_optimize ();
3455 #endif
3456   return 0;
3457 }
3458
3459 struct tree_opt_pass pass_peephole2 =
3460 {
3461   "peephole2",                          /* name */
3462   gate_handle_peephole2,                /* gate */
3463   rest_of_handle_peephole2,             /* execute */
3464   NULL,                                 /* sub */
3465   NULL,                                 /* next */
3466   0,                                    /* static_pass_number */
3467   TV_PEEPHOLE2,                         /* tv_id */
3468   0,                                    /* properties_required */
3469   0,                                    /* properties_provided */
3470   0,                                    /* properties_destroyed */
3471   0,                                    /* todo_flags_start */
3472   TODO_dump_func,                       /* todo_flags_finish */
3473   'z'                                   /* letter */
3474 };
3475
3476 static unsigned int
3477 rest_of_handle_split_all_insns (void)
3478 {
3479   split_all_insns (1);
3480   return 0;
3481 }
3482
3483 struct tree_opt_pass pass_split_all_insns =
3484 {
3485   "split1",                             /* name */
3486   NULL,                                 /* gate */
3487   rest_of_handle_split_all_insns,       /* execute */
3488   NULL,                                 /* sub */
3489   NULL,                                 /* next */
3490   0,                                    /* static_pass_number */
3491   0,                                    /* tv_id */
3492   0,                                    /* properties_required */
3493   0,                                    /* properties_provided */
3494   0,                                    /* properties_destroyed */
3495   0,                                    /* todo_flags_start */
3496   TODO_dump_func,                       /* todo_flags_finish */
3497   0                                     /* letter */
3498 };
3499
3500 /* The placement of the splitting that we do for shorten_branches
3501    depends on whether regstack is used by the target or not.  */
3502 static bool
3503 gate_do_final_split (void)
3504 {
3505 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3506   return 1;
3507 #else
3508   return 0;
3509 #endif 
3510 }
3511
3512 struct tree_opt_pass pass_split_for_shorten_branches =
3513 {
3514   "split3",                             /* name */
3515   gate_do_final_split,                  /* gate */
3516   split_all_insns_noflow,               /* execute */
3517   NULL,                                 /* sub */
3518   NULL,                                 /* next */
3519   0,                                    /* static_pass_number */
3520   TV_SHORTEN_BRANCH,                    /* tv_id */
3521   0,                                    /* properties_required */
3522   0,                                    /* properties_provided */
3523   0,                                    /* properties_destroyed */
3524   0,                                    /* todo_flags_start */
3525   TODO_dump_func,                       /* todo_flags_finish */
3526   0                                     /* letter */
3527 };
3528
3529
3530 static bool
3531 gate_handle_split_before_regstack (void)
3532 {
3533 #if defined (HAVE_ATTR_length) && defined (STACK_REGS)
3534   /* If flow2 creates new instructions which need splitting
3535      and scheduling after reload is not done, they might not be
3536      split until final which doesn't allow splitting
3537      if HAVE_ATTR_length.  */
3538 # ifdef INSN_SCHEDULING
3539   return (optimize && !flag_schedule_insns_after_reload);
3540 # else
3541   return (optimize);
3542 # endif
3543 #else
3544   return 0;
3545 #endif
3546 }
3547
3548 struct tree_opt_pass pass_split_before_regstack =
3549 {
3550   "split2",                             /* name */
3551   gate_handle_split_before_regstack,    /* gate */
3552   rest_of_handle_split_all_insns,       /* execute */
3553   NULL,                                 /* sub */
3554   NULL,                                 /* next */
3555   0,                                    /* static_pass_number */
3556   TV_SHORTEN_BRANCH,                    /* tv_id */
3557   0,                                    /* properties_required */
3558   0,                                    /* properties_provided */
3559   0,                                    /* properties_destroyed */
3560   0,                                    /* todo_flags_start */
3561   TODO_dump_func,                       /* todo_flags_finish */
3562   0                                     /* letter */
3563 };