Update concepts branch to revision 131834
[official-gcc.git] / gcc / recog.c
blobbf4c2b4a64ff3f4ed89b5ebc66e1ff491f38272f
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, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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 "addresses.h"
35 #include "expr.h"
36 #include "function.h"
37 #include "flags.h"
38 #include "real.h"
39 #include "toplev.h"
40 #include "basic-block.h"
41 #include "output.h"
42 #include "reload.h"
43 #include "timevar.h"
44 #include "tree-pass.h"
45 #include "df.h"
47 #ifndef STACK_PUSH_CODE
48 #ifdef STACK_GROWS_DOWNWARD
49 #define STACK_PUSH_CODE PRE_DEC
50 #else
51 #define STACK_PUSH_CODE PRE_INC
52 #endif
53 #endif
55 #ifndef STACK_POP_CODE
56 #ifdef STACK_GROWS_DOWNWARD
57 #define STACK_POP_CODE POST_INC
58 #else
59 #define STACK_POP_CODE POST_DEC
60 #endif
61 #endif
63 #ifndef HAVE_ATTR_enabled
64 static inline bool
65 get_attr_enabled (rtx insn ATTRIBUTE_UNUSED)
67 return true;
69 #endif
71 static void validate_replace_rtx_1 (rtx *, rtx, rtx, rtx);
72 static void validate_replace_src_1 (rtx *, void *);
73 static rtx split_insn (rtx);
75 /* Nonzero means allow operands to be volatile.
76 This should be 0 if you are generating rtl, such as if you are calling
77 the functions in optabs.c and expmed.c (most of the time).
78 This should be 1 if all valid insns need to be recognized,
79 such as in regclass.c and final.c and reload.c.
81 init_recog and init_recog_no_volatile are responsible for setting this. */
83 int volatile_ok;
85 struct recog_data recog_data;
87 /* Contains a vector of operand_alternative structures for every operand.
88 Set up by preprocess_constraints. */
89 struct operand_alternative recog_op_alt[MAX_RECOG_OPERANDS][MAX_RECOG_ALTERNATIVES];
91 /* On return from `constrain_operands', indicate which alternative
92 was satisfied. */
94 int which_alternative;
96 /* Nonzero after end of reload pass.
97 Set to 1 or 0 by toplev.c.
98 Controls the significance of (SUBREG (MEM)). */
100 int reload_completed;
102 /* Nonzero after thread_prologue_and_epilogue_insns has run. */
103 int epilogue_completed;
105 /* Initialize data used by the function `recog'.
106 This must be called once in the compilation of a function
107 before any insn recognition may be done in the function. */
109 void
110 init_recog_no_volatile (void)
112 volatile_ok = 0;
115 void
116 init_recog (void)
118 volatile_ok = 1;
122 /* Check that X is an insn-body for an `asm' with operands
123 and that the operands mentioned in it are legitimate. */
126 check_asm_operands (rtx x)
128 int noperands;
129 rtx *operands;
130 const char **constraints;
131 int i;
133 /* Post-reload, be more strict with things. */
134 if (reload_completed)
136 /* ??? Doh! We've not got the wrapping insn. Cook one up. */
137 extract_insn (make_insn_raw (x));
138 constrain_operands (1);
139 return which_alternative >= 0;
142 noperands = asm_noperands (x);
143 if (noperands < 0)
144 return 0;
145 if (noperands == 0)
146 return 1;
148 operands = alloca (noperands * sizeof (rtx));
149 constraints = alloca (noperands * sizeof (char *));
151 decode_asm_operands (x, operands, NULL, constraints, NULL, NULL);
153 for (i = 0; i < noperands; i++)
155 const char *c = constraints[i];
156 if (c[0] == '%')
157 c++;
158 if (ISDIGIT ((unsigned char) c[0]) && c[1] == '\0')
159 c = constraints[c[0] - '0'];
161 if (! asm_operand_ok (operands[i], c))
162 return 0;
165 return 1;
168 /* Static data for the next two routines. */
170 typedef struct change_t
172 rtx object;
173 int old_code;
174 rtx *loc;
175 rtx old;
176 bool unshare;
177 } change_t;
179 static change_t *changes;
180 static int changes_allocated;
182 static int num_changes = 0;
184 /* Validate a proposed change to OBJECT. LOC is the location in the rtl
185 at which NEW will be placed. If OBJECT is zero, no validation is done,
186 the change is simply made.
188 Two types of objects are supported: If OBJECT is a MEM, memory_address_p
189 will be called with the address and mode as parameters. If OBJECT is
190 an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
191 the change in place.
193 IN_GROUP is nonzero if this is part of a group of changes that must be
194 performed as a group. In that case, the changes will be stored. The
195 function `apply_change_group' will validate and apply the changes.
197 If IN_GROUP is zero, this is a single change. Try to recognize the insn
198 or validate the memory reference with the change applied. If the result
199 is not valid for the machine, suppress the change and return zero.
200 Otherwise, perform the change and return 1. */
202 static bool
203 validate_change_1 (rtx object, rtx *loc, rtx new, bool in_group, bool unshare)
205 rtx old = *loc;
207 if (old == new || rtx_equal_p (old, new))
208 return 1;
210 gcc_assert (in_group != 0 || num_changes == 0);
212 *loc = new;
214 /* Save the information describing this change. */
215 if (num_changes >= changes_allocated)
217 if (changes_allocated == 0)
218 /* This value allows for repeated substitutions inside complex
219 indexed addresses, or changes in up to 5 insns. */
220 changes_allocated = MAX_RECOG_OPERANDS * 5;
221 else
222 changes_allocated *= 2;
224 changes = xrealloc (changes, sizeof (change_t) * changes_allocated);
227 changes[num_changes].object = object;
228 changes[num_changes].loc = loc;
229 changes[num_changes].old = old;
230 changes[num_changes].unshare = unshare;
232 if (object && !MEM_P (object))
234 /* Set INSN_CODE to force rerecognition of insn. Save old code in
235 case invalid. */
236 changes[num_changes].old_code = INSN_CODE (object);
237 INSN_CODE (object) = -1;
240 num_changes++;
242 /* If we are making a group of changes, return 1. Otherwise, validate the
243 change group we made. */
245 if (in_group)
246 return 1;
247 else
248 return apply_change_group ();
251 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
252 UNSHARE to false. */
254 bool
255 validate_change (rtx object, rtx *loc, rtx new, bool in_group)
257 return validate_change_1 (object, loc, new, in_group, false);
260 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
261 UNSHARE to true. */
263 bool
264 validate_unshare_change (rtx object, rtx *loc, rtx new, bool in_group)
266 return validate_change_1 (object, loc, new, in_group, true);
270 /* Keep X canonicalized if some changes have made it non-canonical; only
271 modifies the operands of X, not (for example) its code. Simplifications
272 are not the job of this routine.
274 Return true if anything was changed. */
275 bool
276 canonicalize_change_group (rtx insn, rtx x)
278 if (COMMUTATIVE_P (x)
279 && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
281 /* Oops, the caller has made X no longer canonical.
282 Let's redo the changes in the correct order. */
283 rtx tem = XEXP (x, 0);
284 validate_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
285 validate_change (insn, &XEXP (x, 1), tem, 1);
286 return true;
288 else
289 return false;
293 /* This subroutine of apply_change_group verifies whether the changes to INSN
294 were valid; i.e. whether INSN can still be recognized. */
297 insn_invalid_p (rtx insn)
299 rtx pat = PATTERN (insn);
300 int num_clobbers = 0;
301 /* If we are before reload and the pattern is a SET, see if we can add
302 clobbers. */
303 int icode = recog (pat, insn,
304 (GET_CODE (pat) == SET
305 && ! reload_completed && ! reload_in_progress)
306 ? &num_clobbers : 0);
307 int is_asm = icode < 0 && asm_noperands (PATTERN (insn)) >= 0;
310 /* If this is an asm and the operand aren't legal, then fail. Likewise if
311 this is not an asm and the insn wasn't recognized. */
312 if ((is_asm && ! check_asm_operands (PATTERN (insn)))
313 || (!is_asm && icode < 0))
314 return 1;
316 /* If we have to add CLOBBERs, fail if we have to add ones that reference
317 hard registers since our callers can't know if they are live or not.
318 Otherwise, add them. */
319 if (num_clobbers > 0)
321 rtx newpat;
323 if (added_clobbers_hard_reg_p (icode))
324 return 1;
326 newpat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_clobbers + 1));
327 XVECEXP (newpat, 0, 0) = pat;
328 add_clobbers (newpat, icode);
329 PATTERN (insn) = pat = newpat;
332 /* After reload, verify that all constraints are satisfied. */
333 if (reload_completed)
335 extract_insn (insn);
337 if (! constrain_operands (1))
338 return 1;
341 INSN_CODE (insn) = icode;
342 return 0;
345 /* Return number of changes made and not validated yet. */
347 num_changes_pending (void)
349 return num_changes;
352 /* Tentatively apply the changes numbered NUM and up.
353 Return 1 if all changes are valid, zero otherwise. */
356 verify_changes (int num)
358 int i;
359 rtx last_validated = NULL_RTX;
361 /* The changes have been applied and all INSN_CODEs have been reset to force
362 rerecognition.
364 The changes are valid if we aren't given an object, or if we are
365 given a MEM and it still is a valid address, or if this is in insn
366 and it is recognized. In the latter case, if reload has completed,
367 we also require that the operands meet the constraints for
368 the insn. */
370 for (i = num; i < num_changes; i++)
372 rtx object = changes[i].object;
374 /* If there is no object to test or if it is the same as the one we
375 already tested, ignore it. */
376 if (object == 0 || object == last_validated)
377 continue;
379 if (MEM_P (object))
381 if (! memory_address_p (GET_MODE (object), XEXP (object, 0)))
382 break;
384 else if (insn_invalid_p (object))
386 rtx pat = PATTERN (object);
388 /* Perhaps we couldn't recognize the insn because there were
389 extra CLOBBERs at the end. If so, try to re-recognize
390 without the last CLOBBER (later iterations will cause each of
391 them to be eliminated, in turn). But don't do this if we
392 have an ASM_OPERAND. */
393 if (GET_CODE (pat) == PARALLEL
394 && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
395 && asm_noperands (PATTERN (object)) < 0)
397 rtx newpat;
399 if (XVECLEN (pat, 0) == 2)
400 newpat = XVECEXP (pat, 0, 0);
401 else
403 int j;
405 newpat
406 = gen_rtx_PARALLEL (VOIDmode,
407 rtvec_alloc (XVECLEN (pat, 0) - 1));
408 for (j = 0; j < XVECLEN (newpat, 0); j++)
409 XVECEXP (newpat, 0, j) = XVECEXP (pat, 0, j);
412 /* Add a new change to this group to replace the pattern
413 with this new pattern. Then consider this change
414 as having succeeded. The change we added will
415 cause the entire call to fail if things remain invalid.
417 Note that this can lose if a later change than the one
418 we are processing specified &XVECEXP (PATTERN (object), 0, X)
419 but this shouldn't occur. */
421 validate_change (object, &PATTERN (object), newpat, 1);
422 continue;
424 else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
425 /* If this insn is a CLOBBER or USE, it is always valid, but is
426 never recognized. */
427 continue;
428 else
429 break;
431 last_validated = object;
434 return (i == num_changes);
437 /* A group of changes has previously been issued with validate_change
438 and verified with verify_changes. Call df_insn_rescan for each of
439 the insn changed and clear num_changes. */
441 void
442 confirm_change_group (void)
444 int i;
445 rtx last_object = NULL;
447 for (i = 0; i < num_changes; i++)
449 rtx object = changes[i].object;
451 if (changes[i].unshare)
452 *changes[i].loc = copy_rtx (*changes[i].loc);
454 /* Avoid unnecessary rescanning when multiple changes to same instruction
455 are made. */
456 if (object)
458 if (object != last_object && last_object && INSN_P (last_object))
459 df_insn_rescan (last_object);
460 last_object = object;
464 if (last_object && INSN_P (last_object))
465 df_insn_rescan (last_object);
466 num_changes = 0;
469 /* Apply a group of changes previously issued with `validate_change'.
470 If all changes are valid, call confirm_change_group and return 1,
471 otherwise, call cancel_changes and return 0. */
474 apply_change_group (void)
476 if (verify_changes (0))
478 confirm_change_group ();
479 return 1;
481 else
483 cancel_changes (0);
484 return 0;
489 /* Return the number of changes so far in the current group. */
492 num_validated_changes (void)
494 return num_changes;
497 /* Retract the changes numbered NUM and up. */
499 void
500 cancel_changes (int num)
502 int i;
504 /* Back out all the changes. Do this in the opposite order in which
505 they were made. */
506 for (i = num_changes - 1; i >= num; i--)
508 *changes[i].loc = changes[i].old;
509 if (changes[i].object && !MEM_P (changes[i].object))
510 INSN_CODE (changes[i].object) = changes[i].old_code;
512 num_changes = num;
515 /* Replace every occurrence of FROM in X with TO. Mark each change with
516 validate_change passing OBJECT. */
518 static void
519 validate_replace_rtx_1 (rtx *loc, rtx from, rtx to, rtx object)
521 int i, j;
522 const char *fmt;
523 rtx x = *loc;
524 enum rtx_code code;
525 enum machine_mode op0_mode = VOIDmode;
526 int prev_changes = num_changes;
527 rtx new;
529 if (!x)
530 return;
532 code = GET_CODE (x);
533 fmt = GET_RTX_FORMAT (code);
534 if (fmt[0] == 'e')
535 op0_mode = GET_MODE (XEXP (x, 0));
537 /* X matches FROM if it is the same rtx or they are both referring to the
538 same register in the same mode. Avoid calling rtx_equal_p unless the
539 operands look similar. */
541 if (x == from
542 || (REG_P (x) && REG_P (from)
543 && GET_MODE (x) == GET_MODE (from)
544 && REGNO (x) == REGNO (from))
545 || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
546 && rtx_equal_p (x, from)))
548 validate_unshare_change (object, loc, to, 1);
549 return;
552 /* Call ourself recursively to perform the replacements.
553 We must not replace inside already replaced expression, otherwise we
554 get infinite recursion for replacements like (reg X)->(subreg (reg X))
555 done by regmove, so we must special case shared ASM_OPERANDS. */
557 if (GET_CODE (x) == PARALLEL)
559 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
561 if (j && GET_CODE (XVECEXP (x, 0, j)) == SET
562 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == ASM_OPERANDS)
564 /* Verify that operands are really shared. */
565 gcc_assert (ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (x, 0, 0)))
566 == ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP
567 (x, 0, j))));
568 validate_replace_rtx_1 (&SET_DEST (XVECEXP (x, 0, j)),
569 from, to, object);
571 else
572 validate_replace_rtx_1 (&XVECEXP (x, 0, j), from, to, object);
575 else
576 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
578 if (fmt[i] == 'e')
579 validate_replace_rtx_1 (&XEXP (x, i), from, to, object);
580 else if (fmt[i] == 'E')
581 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
582 validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object);
585 /* If we didn't substitute, there is nothing more to do. */
586 if (num_changes == prev_changes)
587 return;
589 /* Allow substituted expression to have different mode. This is used by
590 regmove to change mode of pseudo register. */
591 if (fmt[0] == 'e' && GET_MODE (XEXP (x, 0)) != VOIDmode)
592 op0_mode = GET_MODE (XEXP (x, 0));
594 /* Do changes needed to keep rtx consistent. Don't do any other
595 simplifications, as it is not our job. */
597 if (SWAPPABLE_OPERANDS_P (x)
598 && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
600 validate_unshare_change (object, loc,
601 gen_rtx_fmt_ee (COMMUTATIVE_ARITH_P (x) ? code
602 : swap_condition (code),
603 GET_MODE (x), XEXP (x, 1),
604 XEXP (x, 0)), 1);
605 x = *loc;
606 code = GET_CODE (x);
609 switch (code)
611 case PLUS:
612 /* If we have a PLUS whose second operand is now a CONST_INT, use
613 simplify_gen_binary to try to simplify it.
614 ??? We may want later to remove this, once simplification is
615 separated from this function. */
616 if (GET_CODE (XEXP (x, 1)) == CONST_INT && XEXP (x, 1) == to)
617 validate_change (object, loc,
618 simplify_gen_binary
619 (PLUS, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)), 1);
620 break;
621 case MINUS:
622 if (GET_CODE (XEXP (x, 1)) == CONST_INT
623 || GET_CODE (XEXP (x, 1)) == CONST_DOUBLE)
624 validate_change (object, loc,
625 simplify_gen_binary
626 (PLUS, GET_MODE (x), XEXP (x, 0),
627 simplify_gen_unary (NEG,
628 GET_MODE (x), XEXP (x, 1),
629 GET_MODE (x))), 1);
630 break;
631 case ZERO_EXTEND:
632 case SIGN_EXTEND:
633 if (GET_MODE (XEXP (x, 0)) == VOIDmode)
635 new = simplify_gen_unary (code, GET_MODE (x), XEXP (x, 0),
636 op0_mode);
637 /* If any of the above failed, substitute in something that
638 we know won't be recognized. */
639 if (!new)
640 new = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
641 validate_change (object, loc, new, 1);
643 break;
644 case SUBREG:
645 /* All subregs possible to simplify should be simplified. */
646 new = simplify_subreg (GET_MODE (x), SUBREG_REG (x), op0_mode,
647 SUBREG_BYTE (x));
649 /* Subregs of VOIDmode operands are incorrect. */
650 if (!new && GET_MODE (SUBREG_REG (x)) == VOIDmode)
651 new = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
652 if (new)
653 validate_change (object, loc, new, 1);
654 break;
655 case ZERO_EXTRACT:
656 case SIGN_EXTRACT:
657 /* If we are replacing a register with memory, try to change the memory
658 to be the mode required for memory in extract operations (this isn't
659 likely to be an insertion operation; if it was, nothing bad will
660 happen, we might just fail in some cases). */
662 if (MEM_P (XEXP (x, 0))
663 && GET_CODE (XEXP (x, 1)) == CONST_INT
664 && GET_CODE (XEXP (x, 2)) == CONST_INT
665 && !mode_dependent_address_p (XEXP (XEXP (x, 0), 0))
666 && !MEM_VOLATILE_P (XEXP (x, 0)))
668 enum machine_mode wanted_mode = VOIDmode;
669 enum machine_mode is_mode = GET_MODE (XEXP (x, 0));
670 int pos = INTVAL (XEXP (x, 2));
672 if (GET_CODE (x) == ZERO_EXTRACT)
674 enum machine_mode new_mode
675 = mode_for_extraction (EP_extzv, 1);
676 if (new_mode != MAX_MACHINE_MODE)
677 wanted_mode = new_mode;
679 else if (GET_CODE (x) == SIGN_EXTRACT)
681 enum machine_mode new_mode
682 = mode_for_extraction (EP_extv, 1);
683 if (new_mode != MAX_MACHINE_MODE)
684 wanted_mode = new_mode;
687 /* If we have a narrower mode, we can do something. */
688 if (wanted_mode != VOIDmode
689 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
691 int offset = pos / BITS_PER_UNIT;
692 rtx newmem;
694 /* If the bytes and bits are counted differently, we
695 must adjust the offset. */
696 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
697 offset =
698 (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode) -
699 offset);
701 pos %= GET_MODE_BITSIZE (wanted_mode);
703 newmem = adjust_address_nv (XEXP (x, 0), wanted_mode, offset);
705 validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
706 validate_change (object, &XEXP (x, 0), newmem, 1);
710 break;
712 default:
713 break;
717 /* Try replacing every occurrence of FROM in INSN with TO. After all
718 changes have been made, validate by seeing if INSN is still valid. */
721 validate_replace_rtx (rtx from, rtx to, rtx insn)
723 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
724 return apply_change_group ();
727 /* Try replacing every occurrence of FROM in INSN with TO. */
729 void
730 validate_replace_rtx_group (rtx from, rtx to, rtx insn)
732 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
735 /* Function called by note_uses to replace used subexpressions. */
736 struct validate_replace_src_data
738 rtx from; /* Old RTX */
739 rtx to; /* New RTX */
740 rtx insn; /* Insn in which substitution is occurring. */
743 static void
744 validate_replace_src_1 (rtx *x, void *data)
746 struct validate_replace_src_data *d
747 = (struct validate_replace_src_data *) data;
749 validate_replace_rtx_1 (x, d->from, d->to, d->insn);
752 /* Try replacing every occurrence of FROM in INSN with TO, avoiding
753 SET_DESTs. */
755 void
756 validate_replace_src_group (rtx from, rtx to, rtx insn)
758 struct validate_replace_src_data d;
760 d.from = from;
761 d.to = to;
762 d.insn = insn;
763 note_uses (&PATTERN (insn), validate_replace_src_1, &d);
766 /* Try simplify INSN.
767 Invoke simplify_rtx () on every SET_SRC and SET_DEST inside the INSN's
768 pattern and return true if something was simplified. */
770 bool
771 validate_simplify_insn (rtx insn)
773 int i;
774 rtx pat = NULL;
775 rtx newpat = NULL;
777 pat = PATTERN (insn);
779 if (GET_CODE (pat) == SET)
781 newpat = simplify_rtx (SET_SRC (pat));
782 if (newpat && !rtx_equal_p (SET_SRC (pat), newpat))
783 validate_change (insn, &SET_SRC (pat), newpat, 1);
784 newpat = simplify_rtx (SET_DEST (pat));
785 if (newpat && !rtx_equal_p (SET_DEST (pat), newpat))
786 validate_change (insn, &SET_DEST (pat), newpat, 1);
788 else if (GET_CODE (pat) == PARALLEL)
789 for (i = 0; i < XVECLEN (pat, 0); i++)
791 rtx s = XVECEXP (pat, 0, i);
793 if (GET_CODE (XVECEXP (pat, 0, i)) == SET)
795 newpat = simplify_rtx (SET_SRC (s));
796 if (newpat && !rtx_equal_p (SET_SRC (s), newpat))
797 validate_change (insn, &SET_SRC (s), newpat, 1);
798 newpat = simplify_rtx (SET_DEST (s));
799 if (newpat && !rtx_equal_p (SET_DEST (s), newpat))
800 validate_change (insn, &SET_DEST (s), newpat, 1);
803 return ((num_changes_pending () > 0) && (apply_change_group () > 0));
806 #ifdef HAVE_cc0
807 /* Return 1 if the insn using CC0 set by INSN does not contain
808 any ordered tests applied to the condition codes.
809 EQ and NE tests do not count. */
812 next_insn_tests_no_inequality (rtx insn)
814 rtx next = next_cc0_user (insn);
816 /* If there is no next insn, we have to take the conservative choice. */
817 if (next == 0)
818 return 0;
820 return (INSN_P (next)
821 && ! inequality_comparisons_p (PATTERN (next)));
823 #endif
825 /* Return 1 if OP is a valid general operand for machine mode MODE.
826 This is either a register reference, a memory reference,
827 or a constant. In the case of a memory reference, the address
828 is checked for general validity for the target machine.
830 Register and memory references must have mode MODE in order to be valid,
831 but some constants have no machine mode and are valid for any mode.
833 If MODE is VOIDmode, OP is checked for validity for whatever mode
834 it has.
836 The main use of this function is as a predicate in match_operand
837 expressions in the machine description.
839 For an explanation of this function's behavior for registers of
840 class NO_REGS, see the comment for `register_operand'. */
843 general_operand (rtx op, enum machine_mode mode)
845 enum rtx_code code = GET_CODE (op);
847 if (mode == VOIDmode)
848 mode = GET_MODE (op);
850 /* Don't accept CONST_INT or anything similar
851 if the caller wants something floating. */
852 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
853 && GET_MODE_CLASS (mode) != MODE_INT
854 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
855 return 0;
857 if (GET_CODE (op) == CONST_INT
858 && mode != VOIDmode
859 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
860 return 0;
862 if (CONSTANT_P (op))
863 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
864 || mode == VOIDmode)
865 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
866 && LEGITIMATE_CONSTANT_P (op));
868 /* Except for certain constants with VOIDmode, already checked for,
869 OP's mode must match MODE if MODE specifies a mode. */
871 if (GET_MODE (op) != mode)
872 return 0;
874 if (code == SUBREG)
876 rtx sub = SUBREG_REG (op);
878 #ifdef INSN_SCHEDULING
879 /* On machines that have insn scheduling, we want all memory
880 reference to be explicit, so outlaw paradoxical SUBREGs.
881 However, we must allow them after reload so that they can
882 get cleaned up by cleanup_subreg_operands. */
883 if (!reload_completed && MEM_P (sub)
884 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (sub)))
885 return 0;
886 #endif
887 /* Avoid memories with nonzero SUBREG_BYTE, as offsetting the memory
888 may result in incorrect reference. We should simplify all valid
889 subregs of MEM anyway. But allow this after reload because we
890 might be called from cleanup_subreg_operands.
892 ??? This is a kludge. */
893 if (!reload_completed && SUBREG_BYTE (op) != 0
894 && MEM_P (sub))
895 return 0;
897 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
898 create such rtl, and we must reject it. */
899 if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
900 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
901 return 0;
903 op = sub;
904 code = GET_CODE (op);
907 if (code == REG)
908 /* A register whose class is NO_REGS is not a general operand. */
909 return (REGNO (op) >= FIRST_PSEUDO_REGISTER
910 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS);
912 if (code == MEM)
914 rtx y = XEXP (op, 0);
916 if (! volatile_ok && MEM_VOLATILE_P (op))
917 return 0;
919 /* Use the mem's mode, since it will be reloaded thus. */
920 if (memory_address_p (GET_MODE (op), y))
921 return 1;
924 return 0;
927 /* Return 1 if OP is a valid memory address for a memory reference
928 of mode MODE.
930 The main use of this function is as a predicate in match_operand
931 expressions in the machine description. */
934 address_operand (rtx op, enum machine_mode mode)
936 return memory_address_p (mode, op);
939 /* Return 1 if OP is a register reference of mode MODE.
940 If MODE is VOIDmode, accept a register in any mode.
942 The main use of this function is as a predicate in match_operand
943 expressions in the machine description.
945 As a special exception, registers whose class is NO_REGS are
946 not accepted by `register_operand'. The reason for this change
947 is to allow the representation of special architecture artifacts
948 (such as a condition code register) without extending the rtl
949 definitions. Since registers of class NO_REGS cannot be used
950 as registers in any case where register classes are examined,
951 it is most consistent to keep this function from accepting them. */
954 register_operand (rtx op, enum machine_mode mode)
956 if (GET_MODE (op) != mode && mode != VOIDmode)
957 return 0;
959 if (GET_CODE (op) == SUBREG)
961 rtx sub = SUBREG_REG (op);
963 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
964 because it is guaranteed to be reloaded into one.
965 Just make sure the MEM is valid in itself.
966 (Ideally, (SUBREG (MEM)...) should not exist after reload,
967 but currently it does result from (SUBREG (REG)...) where the
968 reg went on the stack.) */
969 if (! reload_completed && MEM_P (sub))
970 return general_operand (op, mode);
972 #ifdef CANNOT_CHANGE_MODE_CLASS
973 if (REG_P (sub)
974 && REGNO (sub) < FIRST_PSEUDO_REGISTER
975 && REG_CANNOT_CHANGE_MODE_P (REGNO (sub), GET_MODE (sub), mode)
976 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_INT
977 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_FLOAT)
978 return 0;
979 #endif
981 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
982 create such rtl, and we must reject it. */
983 if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
984 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
985 return 0;
987 op = sub;
990 /* We don't consider registers whose class is NO_REGS
991 to be a register operand. */
992 return (REG_P (op)
993 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
994 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
997 /* Return 1 for a register in Pmode; ignore the tested mode. */
1000 pmode_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1002 return register_operand (op, Pmode);
1005 /* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
1006 or a hard register. */
1009 scratch_operand (rtx op, enum machine_mode mode)
1011 if (GET_MODE (op) != mode && mode != VOIDmode)
1012 return 0;
1014 return (GET_CODE (op) == SCRATCH
1015 || (REG_P (op)
1016 && REGNO (op) < FIRST_PSEUDO_REGISTER));
1019 /* Return 1 if OP is a valid immediate operand for mode MODE.
1021 The main use of this function is as a predicate in match_operand
1022 expressions in the machine description. */
1025 immediate_operand (rtx op, enum machine_mode mode)
1027 /* Don't accept CONST_INT or anything similar
1028 if the caller wants something floating. */
1029 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1030 && GET_MODE_CLASS (mode) != MODE_INT
1031 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1032 return 0;
1034 if (GET_CODE (op) == CONST_INT
1035 && mode != VOIDmode
1036 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1037 return 0;
1039 return (CONSTANT_P (op)
1040 && (GET_MODE (op) == mode || mode == VOIDmode
1041 || GET_MODE (op) == VOIDmode)
1042 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1043 && LEGITIMATE_CONSTANT_P (op));
1046 /* Returns 1 if OP is an operand that is a CONST_INT. */
1049 const_int_operand (rtx op, enum machine_mode mode)
1051 if (GET_CODE (op) != CONST_INT)
1052 return 0;
1054 if (mode != VOIDmode
1055 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1056 return 0;
1058 return 1;
1061 /* Returns 1 if OP is an operand that is a constant integer or constant
1062 floating-point number. */
1065 const_double_operand (rtx op, enum machine_mode mode)
1067 /* Don't accept CONST_INT or anything similar
1068 if the caller wants something floating. */
1069 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1070 && GET_MODE_CLASS (mode) != MODE_INT
1071 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1072 return 0;
1074 return ((GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT)
1075 && (mode == VOIDmode || GET_MODE (op) == mode
1076 || GET_MODE (op) == VOIDmode));
1079 /* Return 1 if OP is a general operand that is not an immediate operand. */
1082 nonimmediate_operand (rtx op, enum machine_mode mode)
1084 return (general_operand (op, mode) && ! CONSTANT_P (op));
1087 /* Return 1 if OP is a register reference or immediate value of mode MODE. */
1090 nonmemory_operand (rtx op, enum machine_mode mode)
1092 if (CONSTANT_P (op))
1094 /* Don't accept CONST_INT or anything similar
1095 if the caller wants something floating. */
1096 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1097 && GET_MODE_CLASS (mode) != MODE_INT
1098 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1099 return 0;
1101 if (GET_CODE (op) == CONST_INT
1102 && mode != VOIDmode
1103 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1104 return 0;
1106 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
1107 || mode == VOIDmode)
1108 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1109 && LEGITIMATE_CONSTANT_P (op));
1112 if (GET_MODE (op) != mode && mode != VOIDmode)
1113 return 0;
1115 if (GET_CODE (op) == SUBREG)
1117 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1118 because it is guaranteed to be reloaded into one.
1119 Just make sure the MEM is valid in itself.
1120 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1121 but currently it does result from (SUBREG (REG)...) where the
1122 reg went on the stack.) */
1123 if (! reload_completed && MEM_P (SUBREG_REG (op)))
1124 return general_operand (op, mode);
1125 op = SUBREG_REG (op);
1128 /* We don't consider registers whose class is NO_REGS
1129 to be a register operand. */
1130 return (REG_P (op)
1131 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1132 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1135 /* Return 1 if OP is a valid operand that stands for pushing a
1136 value of mode MODE onto the stack.
1138 The main use of this function is as a predicate in match_operand
1139 expressions in the machine description. */
1142 push_operand (rtx op, enum machine_mode mode)
1144 unsigned int rounded_size = GET_MODE_SIZE (mode);
1146 #ifdef PUSH_ROUNDING
1147 rounded_size = PUSH_ROUNDING (rounded_size);
1148 #endif
1150 if (!MEM_P (op))
1151 return 0;
1153 if (mode != VOIDmode && GET_MODE (op) != mode)
1154 return 0;
1156 op = XEXP (op, 0);
1158 if (rounded_size == GET_MODE_SIZE (mode))
1160 if (GET_CODE (op) != STACK_PUSH_CODE)
1161 return 0;
1163 else
1165 if (GET_CODE (op) != PRE_MODIFY
1166 || GET_CODE (XEXP (op, 1)) != PLUS
1167 || XEXP (XEXP (op, 1), 0) != XEXP (op, 0)
1168 || GET_CODE (XEXP (XEXP (op, 1), 1)) != CONST_INT
1169 #ifdef STACK_GROWS_DOWNWARD
1170 || INTVAL (XEXP (XEXP (op, 1), 1)) != - (int) rounded_size
1171 #else
1172 || INTVAL (XEXP (XEXP (op, 1), 1)) != (int) rounded_size
1173 #endif
1175 return 0;
1178 return XEXP (op, 0) == stack_pointer_rtx;
1181 /* Return 1 if OP is a valid operand that stands for popping a
1182 value of mode MODE off the stack.
1184 The main use of this function is as a predicate in match_operand
1185 expressions in the machine description. */
1188 pop_operand (rtx op, enum machine_mode mode)
1190 if (!MEM_P (op))
1191 return 0;
1193 if (mode != VOIDmode && GET_MODE (op) != mode)
1194 return 0;
1196 op = XEXP (op, 0);
1198 if (GET_CODE (op) != STACK_POP_CODE)
1199 return 0;
1201 return XEXP (op, 0) == stack_pointer_rtx;
1204 /* Return 1 if ADDR is a valid memory address for mode MODE. */
1207 memory_address_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx addr)
1209 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1210 return 0;
1212 win:
1213 return 1;
1216 /* Return 1 if OP is a valid memory reference with mode MODE,
1217 including a valid address.
1219 The main use of this function is as a predicate in match_operand
1220 expressions in the machine description. */
1223 memory_operand (rtx op, enum machine_mode mode)
1225 rtx inner;
1227 if (! reload_completed)
1228 /* Note that no SUBREG is a memory operand before end of reload pass,
1229 because (SUBREG (MEM...)) forces reloading into a register. */
1230 return MEM_P (op) && general_operand (op, mode);
1232 if (mode != VOIDmode && GET_MODE (op) != mode)
1233 return 0;
1235 inner = op;
1236 if (GET_CODE (inner) == SUBREG)
1237 inner = SUBREG_REG (inner);
1239 return (MEM_P (inner) && general_operand (op, mode));
1242 /* Return 1 if OP is a valid indirect memory reference with mode MODE;
1243 that is, a memory reference whose address is a general_operand. */
1246 indirect_operand (rtx op, enum machine_mode mode)
1248 /* Before reload, a SUBREG isn't in memory (see memory_operand, above). */
1249 if (! reload_completed
1250 && GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))
1252 int offset = SUBREG_BYTE (op);
1253 rtx inner = SUBREG_REG (op);
1255 if (mode != VOIDmode && GET_MODE (op) != mode)
1256 return 0;
1258 /* The only way that we can have a general_operand as the resulting
1259 address is if OFFSET is zero and the address already is an operand
1260 or if the address is (plus Y (const_int -OFFSET)) and Y is an
1261 operand. */
1263 return ((offset == 0 && general_operand (XEXP (inner, 0), Pmode))
1264 || (GET_CODE (XEXP (inner, 0)) == PLUS
1265 && GET_CODE (XEXP (XEXP (inner, 0), 1)) == CONST_INT
1266 && INTVAL (XEXP (XEXP (inner, 0), 1)) == -offset
1267 && general_operand (XEXP (XEXP (inner, 0), 0), Pmode)));
1270 return (MEM_P (op)
1271 && memory_operand (op, mode)
1272 && general_operand (XEXP (op, 0), Pmode));
1275 /* Return 1 if this is a comparison operator. This allows the use of
1276 MATCH_OPERATOR to recognize all the branch insns. */
1279 comparison_operator (rtx op, enum machine_mode mode)
1281 return ((mode == VOIDmode || GET_MODE (op) == mode)
1282 && COMPARISON_P (op));
1285 /* If BODY is an insn body that uses ASM_OPERANDS,
1286 return the number of operands (both input and output) in the insn.
1287 Otherwise return -1. */
1290 asm_noperands (const_rtx body)
1292 switch (GET_CODE (body))
1294 case ASM_OPERANDS:
1295 /* No output operands: return number of input operands. */
1296 return ASM_OPERANDS_INPUT_LENGTH (body);
1297 case SET:
1298 if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1299 /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
1300 return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (body)) + 1;
1301 else
1302 return -1;
1303 case PARALLEL:
1304 if (GET_CODE (XVECEXP (body, 0, 0)) == SET
1305 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1307 /* Multiple output operands, or 1 output plus some clobbers:
1308 body is [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...]. */
1309 int i;
1310 int n_sets;
1312 /* Count backwards through CLOBBERs to determine number of SETs. */
1313 for (i = XVECLEN (body, 0); i > 0; i--)
1315 if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
1316 break;
1317 if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
1318 return -1;
1321 /* N_SETS is now number of output operands. */
1322 n_sets = i;
1324 /* Verify that all the SETs we have
1325 came from a single original asm_operands insn
1326 (so that invalid combinations are blocked). */
1327 for (i = 0; i < n_sets; i++)
1329 rtx elt = XVECEXP (body, 0, i);
1330 if (GET_CODE (elt) != SET)
1331 return -1;
1332 if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
1333 return -1;
1334 /* If these ASM_OPERANDS rtx's came from different original insns
1335 then they aren't allowed together. */
1336 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
1337 != ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (body, 0, 0))))
1338 return -1;
1340 return (ASM_OPERANDS_INPUT_LENGTH (SET_SRC (XVECEXP (body, 0, 0)))
1341 + n_sets);
1343 else if (GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1345 /* 0 outputs, but some clobbers:
1346 body is [(asm_operands ...) (clobber (reg ...))...]. */
1347 int i;
1349 /* Make sure all the other parallel things really are clobbers. */
1350 for (i = XVECLEN (body, 0) - 1; i > 0; i--)
1351 if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
1352 return -1;
1354 return ASM_OPERANDS_INPUT_LENGTH (XVECEXP (body, 0, 0));
1356 else
1357 return -1;
1358 default:
1359 return -1;
1363 /* Assuming BODY is an insn body that uses ASM_OPERANDS,
1364 copy its operands (both input and output) into the vector OPERANDS,
1365 the locations of the operands within the insn into the vector OPERAND_LOCS,
1366 and the constraints for the operands into CONSTRAINTS.
1367 Write the modes of the operands into MODES.
1368 Return the assembler-template.
1370 If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1371 we don't store that info. */
1373 const char *
1374 decode_asm_operands (rtx body, rtx *operands, rtx **operand_locs,
1375 const char **constraints, enum machine_mode *modes,
1376 location_t *loc)
1378 int i;
1379 int noperands;
1380 rtx asmop = 0;
1382 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1384 asmop = SET_SRC (body);
1385 /* Single output operand: BODY is (set OUTPUT (asm_operands ....)). */
1387 noperands = ASM_OPERANDS_INPUT_LENGTH (asmop) + 1;
1389 for (i = 1; i < noperands; i++)
1391 if (operand_locs)
1392 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i - 1);
1393 if (operands)
1394 operands[i] = ASM_OPERANDS_INPUT (asmop, i - 1);
1395 if (constraints)
1396 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i - 1);
1397 if (modes)
1398 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i - 1);
1401 /* The output is in the SET.
1402 Its constraint is in the ASM_OPERANDS itself. */
1403 if (operands)
1404 operands[0] = SET_DEST (body);
1405 if (operand_locs)
1406 operand_locs[0] = &SET_DEST (body);
1407 if (constraints)
1408 constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
1409 if (modes)
1410 modes[0] = GET_MODE (SET_DEST (body));
1412 else if (GET_CODE (body) == ASM_OPERANDS)
1414 asmop = body;
1415 /* No output operands: BODY is (asm_operands ....). */
1417 noperands = ASM_OPERANDS_INPUT_LENGTH (asmop);
1419 /* The input operands are found in the 1st element vector. */
1420 /* Constraints for inputs are in the 2nd element vector. */
1421 for (i = 0; i < noperands; i++)
1423 if (operand_locs)
1424 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1425 if (operands)
1426 operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1427 if (constraints)
1428 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1429 if (modes)
1430 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1433 else if (GET_CODE (body) == PARALLEL
1434 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1435 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1437 int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
1438 int nin;
1439 int nout = 0; /* Does not include CLOBBERs. */
1441 asmop = SET_SRC (XVECEXP (body, 0, 0));
1442 nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1444 /* At least one output, plus some CLOBBERs. */
1446 /* The outputs are in the SETs.
1447 Their constraints are in the ASM_OPERANDS itself. */
1448 for (i = 0; i < nparallel; i++)
1450 if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1451 break; /* Past last SET */
1453 if (operands)
1454 operands[i] = SET_DEST (XVECEXP (body, 0, i));
1455 if (operand_locs)
1456 operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
1457 if (constraints)
1458 constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
1459 if (modes)
1460 modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
1461 nout++;
1464 for (i = 0; i < nin; i++)
1466 if (operand_locs)
1467 operand_locs[i + nout] = &ASM_OPERANDS_INPUT (asmop, i);
1468 if (operands)
1469 operands[i + nout] = ASM_OPERANDS_INPUT (asmop, i);
1470 if (constraints)
1471 constraints[i + nout] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1472 if (modes)
1473 modes[i + nout] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1476 else if (GET_CODE (body) == PARALLEL
1477 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1479 /* No outputs, but some CLOBBERs. */
1481 int nin;
1483 asmop = XVECEXP (body, 0, 0);
1484 nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1486 for (i = 0; i < nin; i++)
1488 if (operand_locs)
1489 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1490 if (operands)
1491 operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1492 if (constraints)
1493 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1494 if (modes)
1495 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1500 if (loc)
1501 *loc = ASM_OPERANDS_SOURCE_LOCATION (asmop);
1503 return ASM_OPERANDS_TEMPLATE (asmop);
1506 /* Check if an asm_operand matches its constraints.
1507 Return > 0 if ok, = 0 if bad, < 0 if inconclusive. */
1510 asm_operand_ok (rtx op, const char *constraint)
1512 int result = 0;
1514 /* Use constrain_operands after reload. */
1515 gcc_assert (!reload_completed);
1517 while (*constraint)
1519 char c = *constraint;
1520 int len;
1521 switch (c)
1523 case ',':
1524 constraint++;
1525 continue;
1526 case '=':
1527 case '+':
1528 case '*':
1529 case '%':
1530 case '!':
1531 case '#':
1532 case '&':
1533 case '?':
1534 break;
1536 case '0': case '1': case '2': case '3': case '4':
1537 case '5': case '6': case '7': case '8': case '9':
1538 /* For best results, our caller should have given us the
1539 proper matching constraint, but we can't actually fail
1540 the check if they didn't. Indicate that results are
1541 inconclusive. */
1543 constraint++;
1544 while (ISDIGIT (*constraint));
1545 if (! result)
1546 result = -1;
1547 continue;
1549 case 'p':
1550 if (address_operand (op, VOIDmode))
1551 result = 1;
1552 break;
1554 case TARGET_MEM_CONSTRAINT:
1555 case 'V': /* non-offsettable */
1556 if (memory_operand (op, VOIDmode))
1557 result = 1;
1558 break;
1560 case 'o': /* offsettable */
1561 if (offsettable_nonstrict_memref_p (op))
1562 result = 1;
1563 break;
1565 case '<':
1566 /* ??? Before auto-inc-dec, auto inc/dec insns are not supposed to exist,
1567 excepting those that expand_call created. Further, on some
1568 machines which do not have generalized auto inc/dec, an inc/dec
1569 is not a memory_operand.
1571 Match any memory and hope things are resolved after reload. */
1573 if (MEM_P (op)
1574 && (1
1575 || GET_CODE (XEXP (op, 0)) == PRE_DEC
1576 || GET_CODE (XEXP (op, 0)) == POST_DEC))
1577 result = 1;
1578 break;
1580 case '>':
1581 if (MEM_P (op)
1582 && (1
1583 || GET_CODE (XEXP (op, 0)) == PRE_INC
1584 || GET_CODE (XEXP (op, 0)) == POST_INC))
1585 result = 1;
1586 break;
1588 case 'E':
1589 case 'F':
1590 if (GET_CODE (op) == CONST_DOUBLE
1591 || (GET_CODE (op) == CONST_VECTOR
1592 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
1593 result = 1;
1594 break;
1596 case 'G':
1597 if (GET_CODE (op) == CONST_DOUBLE
1598 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'G', constraint))
1599 result = 1;
1600 break;
1601 case 'H':
1602 if (GET_CODE (op) == CONST_DOUBLE
1603 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'H', constraint))
1604 result = 1;
1605 break;
1607 case 's':
1608 if (GET_CODE (op) == CONST_INT
1609 || (GET_CODE (op) == CONST_DOUBLE
1610 && GET_MODE (op) == VOIDmode))
1611 break;
1612 /* Fall through. */
1614 case 'i':
1615 if (CONSTANT_P (op) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op)))
1616 result = 1;
1617 break;
1619 case 'n':
1620 if (GET_CODE (op) == CONST_INT
1621 || (GET_CODE (op) == CONST_DOUBLE
1622 && GET_MODE (op) == VOIDmode))
1623 result = 1;
1624 break;
1626 case 'I':
1627 if (GET_CODE (op) == CONST_INT
1628 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'I', constraint))
1629 result = 1;
1630 break;
1631 case 'J':
1632 if (GET_CODE (op) == CONST_INT
1633 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'J', constraint))
1634 result = 1;
1635 break;
1636 case 'K':
1637 if (GET_CODE (op) == CONST_INT
1638 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'K', constraint))
1639 result = 1;
1640 break;
1641 case 'L':
1642 if (GET_CODE (op) == CONST_INT
1643 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'L', constraint))
1644 result = 1;
1645 break;
1646 case 'M':
1647 if (GET_CODE (op) == CONST_INT
1648 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'M', constraint))
1649 result = 1;
1650 break;
1651 case 'N':
1652 if (GET_CODE (op) == CONST_INT
1653 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'N', constraint))
1654 result = 1;
1655 break;
1656 case 'O':
1657 if (GET_CODE (op) == CONST_INT
1658 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'O', constraint))
1659 result = 1;
1660 break;
1661 case 'P':
1662 if (GET_CODE (op) == CONST_INT
1663 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'P', constraint))
1664 result = 1;
1665 break;
1667 case 'X':
1668 result = 1;
1669 break;
1671 case 'g':
1672 if (general_operand (op, VOIDmode))
1673 result = 1;
1674 break;
1676 default:
1677 /* For all other letters, we first check for a register class,
1678 otherwise it is an EXTRA_CONSTRAINT. */
1679 if (REG_CLASS_FROM_CONSTRAINT (c, constraint) != NO_REGS)
1681 case 'r':
1682 if (GET_MODE (op) == BLKmode)
1683 break;
1684 if (register_operand (op, VOIDmode))
1685 result = 1;
1687 #ifdef EXTRA_CONSTRAINT_STR
1688 else if (EXTRA_CONSTRAINT_STR (op, c, constraint))
1689 result = 1;
1690 else if (EXTRA_MEMORY_CONSTRAINT (c, constraint)
1691 /* Every memory operand can be reloaded to fit. */
1692 && memory_operand (op, VOIDmode))
1693 result = 1;
1694 else if (EXTRA_ADDRESS_CONSTRAINT (c, constraint)
1695 /* Every address operand can be reloaded to fit. */
1696 && address_operand (op, VOIDmode))
1697 result = 1;
1698 #endif
1699 break;
1701 len = CONSTRAINT_LEN (c, constraint);
1703 constraint++;
1704 while (--len && *constraint);
1705 if (len)
1706 return 0;
1709 return result;
1712 /* Given an rtx *P, if it is a sum containing an integer constant term,
1713 return the location (type rtx *) of the pointer to that constant term.
1714 Otherwise, return a null pointer. */
1716 rtx *
1717 find_constant_term_loc (rtx *p)
1719 rtx *tem;
1720 enum rtx_code code = GET_CODE (*p);
1722 /* If *P IS such a constant term, P is its location. */
1724 if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1725 || code == CONST)
1726 return p;
1728 /* Otherwise, if not a sum, it has no constant term. */
1730 if (GET_CODE (*p) != PLUS)
1731 return 0;
1733 /* If one of the summands is constant, return its location. */
1735 if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1736 && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1737 return p;
1739 /* Otherwise, check each summand for containing a constant term. */
1741 if (XEXP (*p, 0) != 0)
1743 tem = find_constant_term_loc (&XEXP (*p, 0));
1744 if (tem != 0)
1745 return tem;
1748 if (XEXP (*p, 1) != 0)
1750 tem = find_constant_term_loc (&XEXP (*p, 1));
1751 if (tem != 0)
1752 return tem;
1755 return 0;
1758 /* Return 1 if OP is a memory reference
1759 whose address contains no side effects
1760 and remains valid after the addition
1761 of a positive integer less than the
1762 size of the object being referenced.
1764 We assume that the original address is valid and do not check it.
1766 This uses strict_memory_address_p as a subroutine, so
1767 don't use it before reload. */
1770 offsettable_memref_p (rtx op)
1772 return ((MEM_P (op))
1773 && offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
1776 /* Similar, but don't require a strictly valid mem ref:
1777 consider pseudo-regs valid as index or base regs. */
1780 offsettable_nonstrict_memref_p (rtx op)
1782 return ((MEM_P (op))
1783 && offsettable_address_p (0, GET_MODE (op), XEXP (op, 0)));
1786 /* Return 1 if Y is a memory address which contains no side effects
1787 and would remain valid after the addition of a positive integer
1788 less than the size of that mode.
1790 We assume that the original address is valid and do not check it.
1791 We do check that it is valid for narrower modes.
1793 If STRICTP is nonzero, we require a strictly valid address,
1794 for the sake of use in reload.c. */
1797 offsettable_address_p (int strictp, enum machine_mode mode, rtx y)
1799 enum rtx_code ycode = GET_CODE (y);
1800 rtx z;
1801 rtx y1 = y;
1802 rtx *y2;
1803 int (*addressp) (enum machine_mode, rtx) =
1804 (strictp ? strict_memory_address_p : memory_address_p);
1805 unsigned int mode_sz = GET_MODE_SIZE (mode);
1807 if (CONSTANT_ADDRESS_P (y))
1808 return 1;
1810 /* Adjusting an offsettable address involves changing to a narrower mode.
1811 Make sure that's OK. */
1813 if (mode_dependent_address_p (y))
1814 return 0;
1816 /* ??? How much offset does an offsettable BLKmode reference need?
1817 Clearly that depends on the situation in which it's being used.
1818 However, the current situation in which we test 0xffffffff is
1819 less than ideal. Caveat user. */
1820 if (mode_sz == 0)
1821 mode_sz = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
1823 /* If the expression contains a constant term,
1824 see if it remains valid when max possible offset is added. */
1826 if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
1828 int good;
1830 y1 = *y2;
1831 *y2 = plus_constant (*y2, mode_sz - 1);
1832 /* Use QImode because an odd displacement may be automatically invalid
1833 for any wider mode. But it should be valid for a single byte. */
1834 good = (*addressp) (QImode, y);
1836 /* In any case, restore old contents of memory. */
1837 *y2 = y1;
1838 return good;
1841 if (GET_RTX_CLASS (ycode) == RTX_AUTOINC)
1842 return 0;
1844 /* The offset added here is chosen as the maximum offset that
1845 any instruction could need to add when operating on something
1846 of the specified mode. We assume that if Y and Y+c are
1847 valid addresses then so is Y+d for all 0<d<c. adjust_address will
1848 go inside a LO_SUM here, so we do so as well. */
1849 if (GET_CODE (y) == LO_SUM
1850 && mode != BLKmode
1851 && mode_sz <= GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT)
1852 z = gen_rtx_LO_SUM (GET_MODE (y), XEXP (y, 0),
1853 plus_constant (XEXP (y, 1), mode_sz - 1));
1854 else
1855 z = plus_constant (y, mode_sz - 1);
1857 /* Use QImode because an odd displacement may be automatically invalid
1858 for any wider mode. But it should be valid for a single byte. */
1859 return (*addressp) (QImode, z);
1862 /* Return 1 if ADDR is an address-expression whose effect depends
1863 on the mode of the memory reference it is used in.
1865 Autoincrement addressing is a typical example of mode-dependence
1866 because the amount of the increment depends on the mode. */
1869 mode_dependent_address_p (rtx addr)
1871 /* Auto-increment addressing with anything other than post_modify
1872 or pre_modify always introduces a mode dependency. Catch such
1873 cases now instead of deferring to the target. */
1874 if (GET_CODE (addr) == PRE_INC
1875 || GET_CODE (addr) == POST_INC
1876 || GET_CODE (addr) == PRE_DEC
1877 || GET_CODE (addr) == POST_DEC)
1878 return 1;
1880 GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
1881 return 0;
1882 /* Label `win' might (not) be used via GO_IF_MODE_DEPENDENT_ADDRESS. */
1883 win: ATTRIBUTE_UNUSED_LABEL
1884 return 1;
1887 /* Like extract_insn, but save insn extracted and don't extract again, when
1888 called again for the same insn expecting that recog_data still contain the
1889 valid information. This is used primary by gen_attr infrastructure that
1890 often does extract insn again and again. */
1891 void
1892 extract_insn_cached (rtx insn)
1894 if (recog_data.insn == insn && INSN_CODE (insn) >= 0)
1895 return;
1896 extract_insn (insn);
1897 recog_data.insn = insn;
1900 /* Do cached extract_insn, constrain_operands and complain about failures.
1901 Used by insn_attrtab. */
1902 void
1903 extract_constrain_insn_cached (rtx insn)
1905 extract_insn_cached (insn);
1906 if (which_alternative == -1
1907 && !constrain_operands (reload_completed))
1908 fatal_insn_not_found (insn);
1911 /* Do cached constrain_operands and complain about failures. */
1913 constrain_operands_cached (int strict)
1915 if (which_alternative == -1)
1916 return constrain_operands (strict);
1917 else
1918 return 1;
1921 /* Analyze INSN and fill in recog_data. */
1923 void
1924 extract_insn (rtx insn)
1926 int i;
1927 int icode;
1928 int noperands;
1929 rtx body = PATTERN (insn);
1931 recog_data.n_operands = 0;
1932 recog_data.n_alternatives = 0;
1933 recog_data.n_dups = 0;
1935 switch (GET_CODE (body))
1937 case USE:
1938 case CLOBBER:
1939 case ASM_INPUT:
1940 case ADDR_VEC:
1941 case ADDR_DIFF_VEC:
1942 return;
1944 case SET:
1945 if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1946 goto asm_insn;
1947 else
1948 goto normal_insn;
1949 case PARALLEL:
1950 if ((GET_CODE (XVECEXP (body, 0, 0)) == SET
1951 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1952 || GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1953 goto asm_insn;
1954 else
1955 goto normal_insn;
1956 case ASM_OPERANDS:
1957 asm_insn:
1958 recog_data.n_operands = noperands = asm_noperands (body);
1959 if (noperands >= 0)
1961 /* This insn is an `asm' with operands. */
1963 /* expand_asm_operands makes sure there aren't too many operands. */
1964 gcc_assert (noperands <= MAX_RECOG_OPERANDS);
1966 /* Now get the operand values and constraints out of the insn. */
1967 decode_asm_operands (body, recog_data.operand,
1968 recog_data.operand_loc,
1969 recog_data.constraints,
1970 recog_data.operand_mode, NULL);
1971 if (noperands > 0)
1973 const char *p = recog_data.constraints[0];
1974 recog_data.n_alternatives = 1;
1975 while (*p)
1976 recog_data.n_alternatives += (*p++ == ',');
1978 break;
1980 fatal_insn_not_found (insn);
1982 default:
1983 normal_insn:
1984 /* Ordinary insn: recognize it, get the operands via insn_extract
1985 and get the constraints. */
1987 icode = recog_memoized (insn);
1988 if (icode < 0)
1989 fatal_insn_not_found (insn);
1991 recog_data.n_operands = noperands = insn_data[icode].n_operands;
1992 recog_data.n_alternatives = insn_data[icode].n_alternatives;
1993 recog_data.n_dups = insn_data[icode].n_dups;
1995 insn_extract (insn);
1997 for (i = 0; i < noperands; i++)
1999 recog_data.constraints[i] = insn_data[icode].operand[i].constraint;
2000 recog_data.operand_mode[i] = insn_data[icode].operand[i].mode;
2001 /* VOIDmode match_operands gets mode from their real operand. */
2002 if (recog_data.operand_mode[i] == VOIDmode)
2003 recog_data.operand_mode[i] = GET_MODE (recog_data.operand[i]);
2006 for (i = 0; i < noperands; i++)
2007 recog_data.operand_type[i]
2008 = (recog_data.constraints[i][0] == '=' ? OP_OUT
2009 : recog_data.constraints[i][0] == '+' ? OP_INOUT
2010 : OP_IN);
2012 gcc_assert (recog_data.n_alternatives <= MAX_RECOG_ALTERNATIVES);
2014 if (INSN_CODE (insn) < 0)
2015 for (i = 0; i < recog_data.n_alternatives; i++)
2016 recog_data.alternative_enabled_p[i] = true;
2017 else
2019 recog_data.insn = insn;
2020 for (i = 0; i < recog_data.n_alternatives; i++)
2022 which_alternative = i;
2023 recog_data.alternative_enabled_p[i] = get_attr_enabled (insn);
2027 recog_data.insn = NULL;
2028 which_alternative = -1;
2031 /* After calling extract_insn, you can use this function to extract some
2032 information from the constraint strings into a more usable form.
2033 The collected data is stored in recog_op_alt. */
2034 void
2035 preprocess_constraints (void)
2037 int i;
2039 for (i = 0; i < recog_data.n_operands; i++)
2040 memset (recog_op_alt[i], 0, (recog_data.n_alternatives
2041 * sizeof (struct operand_alternative)));
2043 for (i = 0; i < recog_data.n_operands; i++)
2045 int j;
2046 struct operand_alternative *op_alt;
2047 const char *p = recog_data.constraints[i];
2049 op_alt = recog_op_alt[i];
2051 for (j = 0; j < recog_data.n_alternatives; j++)
2053 op_alt[j].cl = NO_REGS;
2054 op_alt[j].constraint = p;
2055 op_alt[j].matches = -1;
2056 op_alt[j].matched = -1;
2058 if (!recog_data.alternative_enabled_p[j])
2060 p = skip_alternative (p);
2061 continue;
2064 if (*p == '\0' || *p == ',')
2066 op_alt[j].anything_ok = 1;
2067 continue;
2070 for (;;)
2072 char c = *p;
2073 if (c == '#')
2075 c = *++p;
2076 while (c != ',' && c != '\0');
2077 if (c == ',' || c == '\0')
2079 p++;
2080 break;
2083 switch (c)
2085 case '=': case '+': case '*': case '%':
2086 case 'E': case 'F': case 'G': case 'H':
2087 case 's': case 'i': case 'n':
2088 case 'I': case 'J': case 'K': case 'L':
2089 case 'M': case 'N': case 'O': case 'P':
2090 /* These don't say anything we care about. */
2091 break;
2093 case '?':
2094 op_alt[j].reject += 6;
2095 break;
2096 case '!':
2097 op_alt[j].reject += 600;
2098 break;
2099 case '&':
2100 op_alt[j].earlyclobber = 1;
2101 break;
2103 case '0': case '1': case '2': case '3': case '4':
2104 case '5': case '6': case '7': case '8': case '9':
2106 char *end;
2107 op_alt[j].matches = strtoul (p, &end, 10);
2108 recog_op_alt[op_alt[j].matches][j].matched = i;
2109 p = end;
2111 continue;
2113 case TARGET_MEM_CONSTRAINT:
2114 op_alt[j].memory_ok = 1;
2115 break;
2116 case '<':
2117 op_alt[j].decmem_ok = 1;
2118 break;
2119 case '>':
2120 op_alt[j].incmem_ok = 1;
2121 break;
2122 case 'V':
2123 op_alt[j].nonoffmem_ok = 1;
2124 break;
2125 case 'o':
2126 op_alt[j].offmem_ok = 1;
2127 break;
2128 case 'X':
2129 op_alt[j].anything_ok = 1;
2130 break;
2132 case 'p':
2133 op_alt[j].is_address = 1;
2134 op_alt[j].cl = reg_class_subunion[(int) op_alt[j].cl]
2135 [(int) base_reg_class (VOIDmode, ADDRESS, SCRATCH)];
2136 break;
2138 case 'g':
2139 case 'r':
2140 op_alt[j].cl =
2141 reg_class_subunion[(int) op_alt[j].cl][(int) GENERAL_REGS];
2142 break;
2144 default:
2145 if (EXTRA_MEMORY_CONSTRAINT (c, p))
2147 op_alt[j].memory_ok = 1;
2148 break;
2150 if (EXTRA_ADDRESS_CONSTRAINT (c, p))
2152 op_alt[j].is_address = 1;
2153 op_alt[j].cl
2154 = (reg_class_subunion
2155 [(int) op_alt[j].cl]
2156 [(int) base_reg_class (VOIDmode, ADDRESS,
2157 SCRATCH)]);
2158 break;
2161 op_alt[j].cl
2162 = (reg_class_subunion
2163 [(int) op_alt[j].cl]
2164 [(int) REG_CLASS_FROM_CONSTRAINT ((unsigned char) c, p)]);
2165 break;
2167 p += CONSTRAINT_LEN (c, p);
2173 /* Check the operands of an insn against the insn's operand constraints
2174 and return 1 if they are valid.
2175 The information about the insn's operands, constraints, operand modes
2176 etc. is obtained from the global variables set up by extract_insn.
2178 WHICH_ALTERNATIVE is set to a number which indicates which
2179 alternative of constraints was matched: 0 for the first alternative,
2180 1 for the next, etc.
2182 In addition, when two operands are required to match
2183 and it happens that the output operand is (reg) while the
2184 input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
2185 make the output operand look like the input.
2186 This is because the output operand is the one the template will print.
2188 This is used in final, just before printing the assembler code and by
2189 the routines that determine an insn's attribute.
2191 If STRICT is a positive nonzero value, it means that we have been
2192 called after reload has been completed. In that case, we must
2193 do all checks strictly. If it is zero, it means that we have been called
2194 before reload has completed. In that case, we first try to see if we can
2195 find an alternative that matches strictly. If not, we try again, this
2196 time assuming that reload will fix up the insn. This provides a "best
2197 guess" for the alternative and is used to compute attributes of insns prior
2198 to reload. A negative value of STRICT is used for this internal call. */
2200 struct funny_match
2202 int this, other;
2206 constrain_operands (int strict)
2208 const char *constraints[MAX_RECOG_OPERANDS];
2209 int matching_operands[MAX_RECOG_OPERANDS];
2210 int earlyclobber[MAX_RECOG_OPERANDS];
2211 int c;
2213 struct funny_match funny_match[MAX_RECOG_OPERANDS];
2214 int funny_match_index;
2216 which_alternative = 0;
2217 if (recog_data.n_operands == 0 || recog_data.n_alternatives == 0)
2218 return 1;
2220 for (c = 0; c < recog_data.n_operands; c++)
2222 constraints[c] = recog_data.constraints[c];
2223 matching_operands[c] = -1;
2228 int seen_earlyclobber_at = -1;
2229 int opno;
2230 int lose = 0;
2231 funny_match_index = 0;
2233 if (!recog_data.alternative_enabled_p[which_alternative])
2235 int i;
2237 for (i = 0; i < recog_data.n_operands; i++)
2238 constraints[i] = skip_alternative (constraints[i]);
2240 which_alternative++;
2241 continue;
2244 for (opno = 0; opno < recog_data.n_operands; opno++)
2246 rtx op = recog_data.operand[opno];
2247 enum machine_mode mode = GET_MODE (op);
2248 const char *p = constraints[opno];
2249 int offset = 0;
2250 int win = 0;
2251 int val;
2252 int len;
2254 earlyclobber[opno] = 0;
2256 /* A unary operator may be accepted by the predicate, but it
2257 is irrelevant for matching constraints. */
2258 if (UNARY_P (op))
2259 op = XEXP (op, 0);
2261 if (GET_CODE (op) == SUBREG)
2263 if (REG_P (SUBREG_REG (op))
2264 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
2265 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
2266 GET_MODE (SUBREG_REG (op)),
2267 SUBREG_BYTE (op),
2268 GET_MODE (op));
2269 op = SUBREG_REG (op);
2272 /* An empty constraint or empty alternative
2273 allows anything which matched the pattern. */
2274 if (*p == 0 || *p == ',')
2275 win = 1;
2278 switch (c = *p, len = CONSTRAINT_LEN (c, p), c)
2280 case '\0':
2281 len = 0;
2282 break;
2283 case ',':
2284 c = '\0';
2285 break;
2287 case '?': case '!': case '*': case '%':
2288 case '=': case '+':
2289 break;
2291 case '#':
2292 /* Ignore rest of this alternative as far as
2293 constraint checking is concerned. */
2295 p++;
2296 while (*p && *p != ',');
2297 len = 0;
2298 break;
2300 case '&':
2301 earlyclobber[opno] = 1;
2302 if (seen_earlyclobber_at < 0)
2303 seen_earlyclobber_at = opno;
2304 break;
2306 case '0': case '1': case '2': case '3': case '4':
2307 case '5': case '6': case '7': case '8': case '9':
2309 /* This operand must be the same as a previous one.
2310 This kind of constraint is used for instructions such
2311 as add when they take only two operands.
2313 Note that the lower-numbered operand is passed first.
2315 If we are not testing strictly, assume that this
2316 constraint will be satisfied. */
2318 char *end;
2319 int match;
2321 match = strtoul (p, &end, 10);
2322 p = end;
2324 if (strict < 0)
2325 val = 1;
2326 else
2328 rtx op1 = recog_data.operand[match];
2329 rtx op2 = recog_data.operand[opno];
2331 /* A unary operator may be accepted by the predicate,
2332 but it is irrelevant for matching constraints. */
2333 if (UNARY_P (op1))
2334 op1 = XEXP (op1, 0);
2335 if (UNARY_P (op2))
2336 op2 = XEXP (op2, 0);
2338 val = operands_match_p (op1, op2);
2341 matching_operands[opno] = match;
2342 matching_operands[match] = opno;
2344 if (val != 0)
2345 win = 1;
2347 /* If output is *x and input is *--x, arrange later
2348 to change the output to *--x as well, since the
2349 output op is the one that will be printed. */
2350 if (val == 2 && strict > 0)
2352 funny_match[funny_match_index].this = opno;
2353 funny_match[funny_match_index++].other = match;
2356 len = 0;
2357 break;
2359 case 'p':
2360 /* p is used for address_operands. When we are called by
2361 gen_reload, no one will have checked that the address is
2362 strictly valid, i.e., that all pseudos requiring hard regs
2363 have gotten them. */
2364 if (strict <= 0
2365 || (strict_memory_address_p (recog_data.operand_mode[opno],
2366 op)))
2367 win = 1;
2368 break;
2370 /* No need to check general_operand again;
2371 it was done in insn-recog.c. Well, except that reload
2372 doesn't check the validity of its replacements, but
2373 that should only matter when there's a bug. */
2374 case 'g':
2375 /* Anything goes unless it is a REG and really has a hard reg
2376 but the hard reg is not in the class GENERAL_REGS. */
2377 if (REG_P (op))
2379 if (strict < 0
2380 || GENERAL_REGS == ALL_REGS
2381 || (reload_in_progress
2382 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2383 || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
2384 win = 1;
2386 else if (strict < 0 || general_operand (op, mode))
2387 win = 1;
2388 break;
2390 case 'X':
2391 /* This is used for a MATCH_SCRATCH in the cases when
2392 we don't actually need anything. So anything goes
2393 any time. */
2394 win = 1;
2395 break;
2397 case TARGET_MEM_CONSTRAINT:
2398 /* Memory operands must be valid, to the extent
2399 required by STRICT. */
2400 if (MEM_P (op))
2402 if (strict > 0
2403 && !strict_memory_address_p (GET_MODE (op),
2404 XEXP (op, 0)))
2405 break;
2406 if (strict == 0
2407 && !memory_address_p (GET_MODE (op), XEXP (op, 0)))
2408 break;
2409 win = 1;
2411 /* Before reload, accept what reload can turn into mem. */
2412 else if (strict < 0 && CONSTANT_P (op))
2413 win = 1;
2414 /* During reload, accept a pseudo */
2415 else if (reload_in_progress && REG_P (op)
2416 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2417 win = 1;
2418 break;
2420 case '<':
2421 if (MEM_P (op)
2422 && (GET_CODE (XEXP (op, 0)) == PRE_DEC
2423 || GET_CODE (XEXP (op, 0)) == POST_DEC))
2424 win = 1;
2425 break;
2427 case '>':
2428 if (MEM_P (op)
2429 && (GET_CODE (XEXP (op, 0)) == PRE_INC
2430 || GET_CODE (XEXP (op, 0)) == POST_INC))
2431 win = 1;
2432 break;
2434 case 'E':
2435 case 'F':
2436 if (GET_CODE (op) == CONST_DOUBLE
2437 || (GET_CODE (op) == CONST_VECTOR
2438 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
2439 win = 1;
2440 break;
2442 case 'G':
2443 case 'H':
2444 if (GET_CODE (op) == CONST_DOUBLE
2445 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, p))
2446 win = 1;
2447 break;
2449 case 's':
2450 if (GET_CODE (op) == CONST_INT
2451 || (GET_CODE (op) == CONST_DOUBLE
2452 && GET_MODE (op) == VOIDmode))
2453 break;
2454 case 'i':
2455 if (CONSTANT_P (op))
2456 win = 1;
2457 break;
2459 case 'n':
2460 if (GET_CODE (op) == CONST_INT
2461 || (GET_CODE (op) == CONST_DOUBLE
2462 && GET_MODE (op) == VOIDmode))
2463 win = 1;
2464 break;
2466 case 'I':
2467 case 'J':
2468 case 'K':
2469 case 'L':
2470 case 'M':
2471 case 'N':
2472 case 'O':
2473 case 'P':
2474 if (GET_CODE (op) == CONST_INT
2475 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, p))
2476 win = 1;
2477 break;
2479 case 'V':
2480 if (MEM_P (op)
2481 && ((strict > 0 && ! offsettable_memref_p (op))
2482 || (strict < 0
2483 && !(CONSTANT_P (op) || MEM_P (op)))
2484 || (reload_in_progress
2485 && !(REG_P (op)
2486 && REGNO (op) >= FIRST_PSEUDO_REGISTER))))
2487 win = 1;
2488 break;
2490 case 'o':
2491 if ((strict > 0 && offsettable_memref_p (op))
2492 || (strict == 0 && offsettable_nonstrict_memref_p (op))
2493 /* Before reload, accept what reload can handle. */
2494 || (strict < 0
2495 && (CONSTANT_P (op) || MEM_P (op)))
2496 /* During reload, accept a pseudo */
2497 || (reload_in_progress && REG_P (op)
2498 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2499 win = 1;
2500 break;
2502 default:
2504 enum reg_class cl;
2506 cl = (c == 'r'
2507 ? GENERAL_REGS : REG_CLASS_FROM_CONSTRAINT (c, p));
2508 if (cl != NO_REGS)
2510 if (strict < 0
2511 || (strict == 0
2512 && REG_P (op)
2513 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2514 || (strict == 0 && GET_CODE (op) == SCRATCH)
2515 || (REG_P (op)
2516 && reg_fits_class_p (op, cl, offset, mode)))
2517 win = 1;
2519 #ifdef EXTRA_CONSTRAINT_STR
2520 else if (EXTRA_CONSTRAINT_STR (op, c, p))
2521 win = 1;
2523 else if (EXTRA_MEMORY_CONSTRAINT (c, p)
2524 /* Every memory operand can be reloaded to fit. */
2525 && ((strict < 0 && MEM_P (op))
2526 /* Before reload, accept what reload can turn
2527 into mem. */
2528 || (strict < 0 && CONSTANT_P (op))
2529 /* During reload, accept a pseudo */
2530 || (reload_in_progress && REG_P (op)
2531 && REGNO (op) >= FIRST_PSEUDO_REGISTER)))
2532 win = 1;
2533 else if (EXTRA_ADDRESS_CONSTRAINT (c, p)
2534 /* Every address operand can be reloaded to fit. */
2535 && strict < 0)
2536 win = 1;
2537 #endif
2538 break;
2541 while (p += len, c);
2543 constraints[opno] = p;
2544 /* If this operand did not win somehow,
2545 this alternative loses. */
2546 if (! win)
2547 lose = 1;
2549 /* This alternative won; the operands are ok.
2550 Change whichever operands this alternative says to change. */
2551 if (! lose)
2553 int opno, eopno;
2555 /* See if any earlyclobber operand conflicts with some other
2556 operand. */
2558 if (strict > 0 && seen_earlyclobber_at >= 0)
2559 for (eopno = seen_earlyclobber_at;
2560 eopno < recog_data.n_operands;
2561 eopno++)
2562 /* Ignore earlyclobber operands now in memory,
2563 because we would often report failure when we have
2564 two memory operands, one of which was formerly a REG. */
2565 if (earlyclobber[eopno]
2566 && REG_P (recog_data.operand[eopno]))
2567 for (opno = 0; opno < recog_data.n_operands; opno++)
2568 if ((MEM_P (recog_data.operand[opno])
2569 || recog_data.operand_type[opno] != OP_OUT)
2570 && opno != eopno
2571 /* Ignore things like match_operator operands. */
2572 && *recog_data.constraints[opno] != 0
2573 && ! (matching_operands[opno] == eopno
2574 && operands_match_p (recog_data.operand[opno],
2575 recog_data.operand[eopno]))
2576 && ! safe_from_earlyclobber (recog_data.operand[opno],
2577 recog_data.operand[eopno]))
2578 lose = 1;
2580 if (! lose)
2582 while (--funny_match_index >= 0)
2584 recog_data.operand[funny_match[funny_match_index].other]
2585 = recog_data.operand[funny_match[funny_match_index].this];
2588 return 1;
2592 which_alternative++;
2594 while (which_alternative < recog_data.n_alternatives);
2596 which_alternative = -1;
2597 /* If we are about to reject this, but we are not to test strictly,
2598 try a very loose test. Only return failure if it fails also. */
2599 if (strict == 0)
2600 return constrain_operands (-1);
2601 else
2602 return 0;
2605 /* Return 1 iff OPERAND (assumed to be a REG rtx)
2606 is a hard reg in class CLASS when its regno is offset by OFFSET
2607 and changed to mode MODE.
2608 If REG occupies multiple hard regs, all of them must be in CLASS. */
2611 reg_fits_class_p (rtx operand, enum reg_class cl, int offset,
2612 enum machine_mode mode)
2614 int regno = REGNO (operand);
2616 if (cl == NO_REGS)
2617 return 0;
2619 return (regno < FIRST_PSEUDO_REGISTER
2620 && in_hard_reg_set_p (reg_class_contents[(int) cl],
2621 mode, regno + offset));
2624 /* Split single instruction. Helper function for split_all_insns and
2625 split_all_insns_noflow. Return last insn in the sequence if successful,
2626 or NULL if unsuccessful. */
2628 static rtx
2629 split_insn (rtx insn)
2631 /* Split insns here to get max fine-grain parallelism. */
2632 rtx first = PREV_INSN (insn);
2633 rtx last = try_split (PATTERN (insn), insn, 1);
2635 if (last == insn)
2636 return NULL_RTX;
2638 /* try_split returns the NOTE that INSN became. */
2639 SET_INSN_DELETED (insn);
2641 /* ??? Coddle to md files that generate subregs in post-reload
2642 splitters instead of computing the proper hard register. */
2643 if (reload_completed && first != last)
2645 first = NEXT_INSN (first);
2646 for (;;)
2648 if (INSN_P (first))
2649 cleanup_subreg_operands (first);
2650 if (first == last)
2651 break;
2652 first = NEXT_INSN (first);
2655 return last;
2658 /* Split all insns in the function. If UPD_LIFE, update life info after. */
2660 void
2661 split_all_insns (void)
2663 sbitmap blocks;
2664 bool changed;
2665 basic_block bb;
2667 blocks = sbitmap_alloc (last_basic_block);
2668 sbitmap_zero (blocks);
2669 changed = false;
2671 FOR_EACH_BB_REVERSE (bb)
2673 rtx insn, next;
2674 bool finish = false;
2676 for (insn = BB_HEAD (bb); !finish ; insn = next)
2678 /* Can't use `next_real_insn' because that might go across
2679 CODE_LABELS and short-out basic blocks. */
2680 next = NEXT_INSN (insn);
2681 finish = (insn == BB_END (bb));
2682 if (INSN_P (insn))
2684 rtx set = single_set (insn);
2686 /* Don't split no-op move insns. These should silently
2687 disappear later in final. Splitting such insns would
2688 break the code that handles LIBCALL blocks. */
2689 if (set && set_noop_p (set))
2691 /* Nops get in the way while scheduling, so delete them
2692 now if register allocation has already been done. It
2693 is too risky to try to do this before register
2694 allocation, and there are unlikely to be very many
2695 nops then anyways. */
2696 if (reload_completed)
2697 delete_insn_and_edges (insn);
2699 else
2701 rtx last = split_insn (insn);
2702 if (last)
2704 /* The split sequence may include barrier, but the
2705 BB boundary we are interested in will be set to
2706 previous one. */
2708 while (BARRIER_P (last))
2709 last = PREV_INSN (last);
2710 SET_BIT (blocks, bb->index);
2711 changed = true;
2718 if (changed)
2719 find_many_sub_basic_blocks (blocks);
2721 #ifdef ENABLE_CHECKING
2722 verify_flow_info ();
2723 #endif
2725 sbitmap_free (blocks);
2728 /* Same as split_all_insns, but do not expect CFG to be available.
2729 Used by machine dependent reorg passes. */
2731 unsigned int
2732 split_all_insns_noflow (void)
2734 rtx next, insn;
2736 for (insn = get_insns (); insn; insn = next)
2738 next = NEXT_INSN (insn);
2739 if (INSN_P (insn))
2741 /* Don't split no-op move insns. These should silently
2742 disappear later in final. Splitting such insns would
2743 break the code that handles LIBCALL blocks. */
2744 rtx set = single_set (insn);
2745 if (set && set_noop_p (set))
2747 /* Nops get in the way while scheduling, so delete them
2748 now if register allocation has already been done. It
2749 is too risky to try to do this before register
2750 allocation, and there are unlikely to be very many
2751 nops then anyways.
2753 ??? Should we use delete_insn when the CFG isn't valid? */
2754 if (reload_completed)
2755 delete_insn_and_edges (insn);
2757 else
2758 split_insn (insn);
2761 return 0;
2764 #ifdef HAVE_peephole2
2765 struct peep2_insn_data
2767 rtx insn;
2768 regset live_before;
2771 static struct peep2_insn_data peep2_insn_data[MAX_INSNS_PER_PEEP2 + 1];
2772 static int peep2_current;
2773 /* The number of instructions available to match a peep2. */
2774 int peep2_current_count;
2776 /* A non-insn marker indicating the last insn of the block.
2777 The live_before regset for this element is correct, indicating
2778 DF_LIVE_OUT for the block. */
2779 #define PEEP2_EOB pc_rtx
2781 /* Return the Nth non-note insn after `current', or return NULL_RTX if it
2782 does not exist. Used by the recognizer to find the next insn to match
2783 in a multi-insn pattern. */
2786 peep2_next_insn (int n)
2788 gcc_assert (n <= peep2_current_count);
2790 n += peep2_current;
2791 if (n >= MAX_INSNS_PER_PEEP2 + 1)
2792 n -= MAX_INSNS_PER_PEEP2 + 1;
2794 return peep2_insn_data[n].insn;
2797 /* Return true if REGNO is dead before the Nth non-note insn
2798 after `current'. */
2801 peep2_regno_dead_p (int ofs, int regno)
2803 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
2805 ofs += peep2_current;
2806 if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2807 ofs -= MAX_INSNS_PER_PEEP2 + 1;
2809 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
2811 return ! REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno);
2814 /* Similarly for a REG. */
2817 peep2_reg_dead_p (int ofs, rtx reg)
2819 int regno, n;
2821 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
2823 ofs += peep2_current;
2824 if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2825 ofs -= MAX_INSNS_PER_PEEP2 + 1;
2827 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
2829 regno = REGNO (reg);
2830 n = hard_regno_nregs[regno][GET_MODE (reg)];
2831 while (--n >= 0)
2832 if (REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno + n))
2833 return 0;
2834 return 1;
2837 /* Try to find a hard register of mode MODE, matching the register class in
2838 CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
2839 remains available until the end of LAST_INSN. LAST_INSN may be NULL_RTX,
2840 in which case the only condition is that the register must be available
2841 before CURRENT_INSN.
2842 Registers that already have bits set in REG_SET will not be considered.
2844 If an appropriate register is available, it will be returned and the
2845 corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
2846 returned. */
2849 peep2_find_free_register (int from, int to, const char *class_str,
2850 enum machine_mode mode, HARD_REG_SET *reg_set)
2852 static int search_ofs;
2853 enum reg_class cl;
2854 HARD_REG_SET live;
2855 int i;
2857 gcc_assert (from < MAX_INSNS_PER_PEEP2 + 1);
2858 gcc_assert (to < MAX_INSNS_PER_PEEP2 + 1);
2860 from += peep2_current;
2861 if (from >= MAX_INSNS_PER_PEEP2 + 1)
2862 from -= MAX_INSNS_PER_PEEP2 + 1;
2863 to += peep2_current;
2864 if (to >= MAX_INSNS_PER_PEEP2 + 1)
2865 to -= MAX_INSNS_PER_PEEP2 + 1;
2867 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
2868 REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before);
2870 while (from != to)
2872 HARD_REG_SET this_live;
2874 if (++from >= MAX_INSNS_PER_PEEP2 + 1)
2875 from = 0;
2876 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
2877 REG_SET_TO_HARD_REG_SET (this_live, peep2_insn_data[from].live_before);
2878 IOR_HARD_REG_SET (live, this_live);
2881 cl = (class_str[0] == 'r' ? GENERAL_REGS
2882 : REG_CLASS_FROM_CONSTRAINT (class_str[0], class_str));
2884 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2886 int raw_regno, regno, success, j;
2888 /* Distribute the free registers as much as possible. */
2889 raw_regno = search_ofs + i;
2890 if (raw_regno >= FIRST_PSEUDO_REGISTER)
2891 raw_regno -= FIRST_PSEUDO_REGISTER;
2892 #ifdef REG_ALLOC_ORDER
2893 regno = reg_alloc_order[raw_regno];
2894 #else
2895 regno = raw_regno;
2896 #endif
2898 /* Don't allocate fixed registers. */
2899 if (fixed_regs[regno])
2900 continue;
2901 /* Make sure the register is of the right class. */
2902 if (! TEST_HARD_REG_BIT (reg_class_contents[cl], regno))
2903 continue;
2904 /* And can support the mode we need. */
2905 if (! HARD_REGNO_MODE_OK (regno, mode))
2906 continue;
2907 /* And that we don't create an extra save/restore. */
2908 if (! call_used_regs[regno] && ! df_regs_ever_live_p (regno))
2909 continue;
2910 /* And we don't clobber traceback for noreturn functions. */
2911 if ((regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM)
2912 && (! reload_completed || frame_pointer_needed))
2913 continue;
2915 success = 1;
2916 for (j = hard_regno_nregs[regno][mode] - 1; j >= 0; j--)
2918 if (TEST_HARD_REG_BIT (*reg_set, regno + j)
2919 || TEST_HARD_REG_BIT (live, regno + j))
2921 success = 0;
2922 break;
2925 if (success)
2927 add_to_hard_reg_set (reg_set, mode, regno);
2929 /* Start the next search with the next register. */
2930 if (++raw_regno >= FIRST_PSEUDO_REGISTER)
2931 raw_regno = 0;
2932 search_ofs = raw_regno;
2934 return gen_rtx_REG (mode, regno);
2938 search_ofs = 0;
2939 return NULL_RTX;
2942 /* Perform the peephole2 optimization pass. */
2944 static void
2945 peephole2_optimize (void)
2947 rtx insn, prev;
2948 bitmap live;
2949 int i;
2950 basic_block bb;
2951 bool do_cleanup_cfg = false;
2952 bool do_rebuild_jump_labels = false;
2954 df_set_flags (DF_LR_RUN_DCE);
2955 df_analyze ();
2957 /* Initialize the regsets we're going to use. */
2958 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
2959 peep2_insn_data[i].live_before = BITMAP_ALLOC (&reg_obstack);
2960 live = BITMAP_ALLOC (&reg_obstack);
2962 FOR_EACH_BB_REVERSE (bb)
2964 /* Indicate that all slots except the last holds invalid data. */
2965 for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
2966 peep2_insn_data[i].insn = NULL_RTX;
2967 peep2_current_count = 0;
2969 /* Indicate that the last slot contains live_after data. */
2970 peep2_insn_data[MAX_INSNS_PER_PEEP2].insn = PEEP2_EOB;
2971 peep2_current = MAX_INSNS_PER_PEEP2;
2973 /* Start up propagation. */
2974 bitmap_copy (live, DF_LR_OUT (bb));
2975 df_simulate_artificial_refs_at_end (bb, live);
2976 bitmap_copy (peep2_insn_data[MAX_INSNS_PER_PEEP2].live_before, live);
2978 for (insn = BB_END (bb); ; insn = prev)
2980 prev = PREV_INSN (insn);
2981 if (INSN_P (insn))
2983 rtx try, before_try, x;
2984 int match_len;
2985 rtx note;
2986 bool was_call = false;
2988 /* Record this insn. */
2989 if (--peep2_current < 0)
2990 peep2_current = MAX_INSNS_PER_PEEP2;
2991 if (peep2_current_count < MAX_INSNS_PER_PEEP2
2992 && peep2_insn_data[peep2_current].insn == NULL_RTX)
2993 peep2_current_count++;
2994 peep2_insn_data[peep2_current].insn = insn;
2995 df_simulate_one_insn (bb, insn, live);
2996 COPY_REG_SET (peep2_insn_data[peep2_current].live_before, live);
2998 if (RTX_FRAME_RELATED_P (insn))
3000 /* If an insn has RTX_FRAME_RELATED_P set, peephole
3001 substitution would lose the
3002 REG_FRAME_RELATED_EXPR that is attached. */
3003 peep2_current_count = 0;
3004 try = NULL;
3006 else
3007 /* Match the peephole. */
3008 try = peephole2_insns (PATTERN (insn), insn, &match_len);
3010 if (try != NULL)
3012 /* If we are splitting a CALL_INSN, look for the CALL_INSN
3013 in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other
3014 cfg-related call notes. */
3015 for (i = 0; i <= match_len; ++i)
3017 int j;
3018 rtx old_insn, new_insn, note;
3020 j = i + peep2_current;
3021 if (j >= MAX_INSNS_PER_PEEP2 + 1)
3022 j -= MAX_INSNS_PER_PEEP2 + 1;
3023 old_insn = peep2_insn_data[j].insn;
3024 if (!CALL_P (old_insn))
3025 continue;
3026 was_call = true;
3028 new_insn = try;
3029 while (new_insn != NULL_RTX)
3031 if (CALL_P (new_insn))
3032 break;
3033 new_insn = NEXT_INSN (new_insn);
3036 gcc_assert (new_insn != NULL_RTX);
3038 CALL_INSN_FUNCTION_USAGE (new_insn)
3039 = CALL_INSN_FUNCTION_USAGE (old_insn);
3041 for (note = REG_NOTES (old_insn);
3042 note;
3043 note = XEXP (note, 1))
3044 switch (REG_NOTE_KIND (note))
3046 case REG_NORETURN:
3047 case REG_SETJMP:
3048 REG_NOTES (new_insn)
3049 = gen_rtx_EXPR_LIST (REG_NOTE_KIND (note),
3050 XEXP (note, 0),
3051 REG_NOTES (new_insn));
3052 default:
3053 /* Discard all other reg notes. */
3054 break;
3057 /* Croak if there is another call in the sequence. */
3058 while (++i <= match_len)
3060 j = i + peep2_current;
3061 if (j >= MAX_INSNS_PER_PEEP2 + 1)
3062 j -= MAX_INSNS_PER_PEEP2 + 1;
3063 old_insn = peep2_insn_data[j].insn;
3064 gcc_assert (!CALL_P (old_insn));
3066 break;
3069 i = match_len + peep2_current;
3070 if (i >= MAX_INSNS_PER_PEEP2 + 1)
3071 i -= MAX_INSNS_PER_PEEP2 + 1;
3073 note = find_reg_note (peep2_insn_data[i].insn,
3074 REG_EH_REGION, NULL_RTX);
3076 /* Replace the old sequence with the new. */
3077 try = emit_insn_after_setloc (try, peep2_insn_data[i].insn,
3078 INSN_LOCATOR (peep2_insn_data[i].insn));
3079 before_try = PREV_INSN (insn);
3080 delete_insn_chain (insn, peep2_insn_data[i].insn, false);
3082 /* Re-insert the EH_REGION notes. */
3083 if (note || (was_call && nonlocal_goto_handler_labels))
3085 edge eh_edge;
3086 edge_iterator ei;
3088 FOR_EACH_EDGE (eh_edge, ei, bb->succs)
3089 if (eh_edge->flags & (EDGE_EH | EDGE_ABNORMAL_CALL))
3090 break;
3092 for (x = try ; x != before_try ; x = PREV_INSN (x))
3093 if (CALL_P (x)
3094 || (flag_non_call_exceptions
3095 && may_trap_p (PATTERN (x))
3096 && !find_reg_note (x, REG_EH_REGION, NULL)))
3098 if (note)
3099 REG_NOTES (x)
3100 = gen_rtx_EXPR_LIST (REG_EH_REGION,
3101 XEXP (note, 0),
3102 REG_NOTES (x));
3104 if (x != BB_END (bb) && eh_edge)
3106 edge nfte, nehe;
3107 int flags;
3109 nfte = split_block (bb, x);
3110 flags = (eh_edge->flags
3111 & (EDGE_EH | EDGE_ABNORMAL));
3112 if (CALL_P (x))
3113 flags |= EDGE_ABNORMAL_CALL;
3114 nehe = make_edge (nfte->src, eh_edge->dest,
3115 flags);
3117 nehe->probability = eh_edge->probability;
3118 nfte->probability
3119 = REG_BR_PROB_BASE - nehe->probability;
3121 do_cleanup_cfg |= purge_dead_edges (nfte->dest);
3122 bb = nfte->src;
3123 eh_edge = nehe;
3127 /* Converting possibly trapping insn to non-trapping is
3128 possible. Zap dummy outgoing edges. */
3129 do_cleanup_cfg |= purge_dead_edges (bb);
3132 #ifdef HAVE_conditional_execution
3133 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3134 peep2_insn_data[i].insn = NULL_RTX;
3135 peep2_insn_data[peep2_current].insn = PEEP2_EOB;
3136 peep2_current_count = 0;
3137 #else
3138 /* Back up lifetime information past the end of the
3139 newly created sequence. */
3140 if (++i >= MAX_INSNS_PER_PEEP2 + 1)
3141 i = 0;
3142 bitmap_copy (live, peep2_insn_data[i].live_before);
3144 /* Update life information for the new sequence. */
3145 x = try;
3148 if (INSN_P (x))
3150 if (--i < 0)
3151 i = MAX_INSNS_PER_PEEP2;
3152 if (peep2_current_count < MAX_INSNS_PER_PEEP2
3153 && peep2_insn_data[i].insn == NULL_RTX)
3154 peep2_current_count++;
3155 peep2_insn_data[i].insn = x;
3156 df_insn_rescan (x);
3157 df_simulate_one_insn (bb, x, live);
3158 bitmap_copy (peep2_insn_data[i].live_before, live);
3160 x = PREV_INSN (x);
3162 while (x != prev);
3164 peep2_current = i;
3165 #endif
3167 /* If we generated a jump instruction, it won't have
3168 JUMP_LABEL set. Recompute after we're done. */
3169 for (x = try; x != before_try; x = PREV_INSN (x))
3170 if (JUMP_P (x))
3172 do_rebuild_jump_labels = true;
3173 break;
3178 if (insn == BB_HEAD (bb))
3179 break;
3183 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3184 BITMAP_FREE (peep2_insn_data[i].live_before);
3185 BITMAP_FREE (live);
3186 if (do_rebuild_jump_labels)
3187 rebuild_jump_labels (get_insns ());
3189 #endif /* HAVE_peephole2 */
3191 /* Common predicates for use with define_bypass. */
3193 /* True if the dependency between OUT_INSN and IN_INSN is on the store
3194 data not the address operand(s) of the store. IN_INSN and OUT_INSN
3195 must be either a single_set or a PARALLEL with SETs inside. */
3198 store_data_bypass_p (rtx out_insn, rtx in_insn)
3200 rtx out_set, in_set;
3201 rtx out_pat, in_pat;
3202 rtx out_exp, in_exp;
3203 int i, j;
3205 in_set = single_set (in_insn);
3206 if (in_set)
3208 if (!MEM_P (SET_DEST (in_set)))
3209 return false;
3211 out_set = single_set (out_insn);
3212 if (out_set)
3214 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_set)))
3215 return false;
3217 else
3219 out_pat = PATTERN (out_insn);
3221 if (GET_CODE (out_pat) != PARALLEL)
3222 return false;
3224 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3226 out_exp = XVECEXP (out_pat, 0, i);
3228 if (GET_CODE (out_exp) == CLOBBER)
3229 continue;
3231 gcc_assert (GET_CODE (out_exp) == SET);
3233 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_set)))
3234 return false;
3238 else
3240 in_pat = PATTERN (in_insn);
3241 gcc_assert (GET_CODE (in_pat) == PARALLEL);
3243 for (i = 0; i < XVECLEN (in_pat, 0); i++)
3245 in_exp = XVECEXP (in_pat, 0, i);
3247 if (GET_CODE (in_exp) == CLOBBER)
3248 continue;
3250 gcc_assert (GET_CODE (in_exp) == SET);
3252 if (!MEM_P (SET_DEST (in_exp)))
3253 return false;
3255 out_set = single_set (out_insn);
3256 if (out_set)
3258 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_exp)))
3259 return false;
3261 else
3263 out_pat = PATTERN (out_insn);
3264 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3266 for (j = 0; j < XVECLEN (out_pat, 0); j++)
3268 out_exp = XVECEXP (out_pat, 0, j);
3270 if (GET_CODE (out_exp) == CLOBBER)
3271 continue;
3273 gcc_assert (GET_CODE (out_exp) == SET);
3275 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_exp)))
3276 return false;
3282 return true;
3285 /* True if the dependency between OUT_INSN and IN_INSN is in the IF_THEN_ELSE
3286 condition, and not the THEN or ELSE branch. OUT_INSN may be either a single
3287 or multiple set; IN_INSN should be single_set for truth, but for convenience
3288 of insn categorization may be any JUMP or CALL insn. */
3291 if_test_bypass_p (rtx out_insn, rtx in_insn)
3293 rtx out_set, in_set;
3295 in_set = single_set (in_insn);
3296 if (! in_set)
3298 gcc_assert (JUMP_P (in_insn) || CALL_P (in_insn));
3299 return false;
3302 if (GET_CODE (SET_SRC (in_set)) != IF_THEN_ELSE)
3303 return false;
3304 in_set = SET_SRC (in_set);
3306 out_set = single_set (out_insn);
3307 if (out_set)
3309 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3310 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3311 return false;
3313 else
3315 rtx out_pat;
3316 int i;
3318 out_pat = PATTERN (out_insn);
3319 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3321 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3323 rtx exp = XVECEXP (out_pat, 0, i);
3325 if (GET_CODE (exp) == CLOBBER)
3326 continue;
3328 gcc_assert (GET_CODE (exp) == SET);
3330 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3331 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3332 return false;
3336 return true;
3339 static bool
3340 gate_handle_peephole2 (void)
3342 return (optimize > 0 && flag_peephole2);
3345 static unsigned int
3346 rest_of_handle_peephole2 (void)
3348 #ifdef HAVE_peephole2
3349 peephole2_optimize ();
3350 #endif
3351 return 0;
3354 struct rtl_opt_pass pass_peephole2 =
3357 RTL_PASS,
3358 "peephole2", /* name */
3359 gate_handle_peephole2, /* gate */
3360 rest_of_handle_peephole2, /* execute */
3361 NULL, /* sub */
3362 NULL, /* next */
3363 0, /* static_pass_number */
3364 TV_PEEPHOLE2, /* tv_id */
3365 0, /* properties_required */
3366 0, /* properties_provided */
3367 0, /* properties_destroyed */
3368 0, /* todo_flags_start */
3369 TODO_df_finish | TODO_verify_rtl_sharing |
3370 TODO_dump_func /* todo_flags_finish */
3374 static unsigned int
3375 rest_of_handle_split_all_insns (void)
3377 split_all_insns ();
3378 return 0;
3381 struct rtl_opt_pass pass_split_all_insns =
3384 RTL_PASS,
3385 "split1", /* name */
3386 NULL, /* gate */
3387 rest_of_handle_split_all_insns, /* execute */
3388 NULL, /* sub */
3389 NULL, /* next */
3390 0, /* static_pass_number */
3391 0, /* tv_id */
3392 0, /* properties_required */
3393 0, /* properties_provided */
3394 0, /* properties_destroyed */
3395 0, /* todo_flags_start */
3396 TODO_dump_func /* todo_flags_finish */
3400 static unsigned int
3401 rest_of_handle_split_after_reload (void)
3403 /* If optimizing, then go ahead and split insns now. */
3404 #ifndef STACK_REGS
3405 if (optimize > 0)
3406 #endif
3407 split_all_insns ();
3408 return 0;
3411 struct rtl_opt_pass pass_split_after_reload =
3414 RTL_PASS,
3415 "split2", /* name */
3416 NULL, /* gate */
3417 rest_of_handle_split_after_reload, /* execute */
3418 NULL, /* sub */
3419 NULL, /* next */
3420 0, /* static_pass_number */
3421 0, /* tv_id */
3422 0, /* properties_required */
3423 0, /* properties_provided */
3424 0, /* properties_destroyed */
3425 0, /* todo_flags_start */
3426 TODO_dump_func /* todo_flags_finish */
3430 static bool
3431 gate_handle_split_before_regstack (void)
3433 #if defined (HAVE_ATTR_length) && defined (STACK_REGS)
3434 /* If flow2 creates new instructions which need splitting
3435 and scheduling after reload is not done, they might not be
3436 split until final which doesn't allow splitting
3437 if HAVE_ATTR_length. */
3438 # ifdef INSN_SCHEDULING
3439 return (optimize && !flag_schedule_insns_after_reload);
3440 # else
3441 return (optimize);
3442 # endif
3443 #else
3444 return 0;
3445 #endif
3448 static unsigned int
3449 rest_of_handle_split_before_regstack (void)
3451 split_all_insns ();
3452 return 0;
3455 struct rtl_opt_pass pass_split_before_regstack =
3458 RTL_PASS,
3459 "split3", /* name */
3460 gate_handle_split_before_regstack, /* gate */
3461 rest_of_handle_split_before_regstack, /* execute */
3462 NULL, /* sub */
3463 NULL, /* next */
3464 0, /* static_pass_number */
3465 0, /* tv_id */
3466 0, /* properties_required */
3467 0, /* properties_provided */
3468 0, /* properties_destroyed */
3469 0, /* todo_flags_start */
3470 TODO_dump_func /* todo_flags_finish */
3474 static bool
3475 gate_handle_split_before_sched2 (void)
3477 #ifdef INSN_SCHEDULING
3478 return optimize > 0 && flag_schedule_insns_after_reload;
3479 #else
3480 return 0;
3481 #endif
3484 static unsigned int
3485 rest_of_handle_split_before_sched2 (void)
3487 #ifdef INSN_SCHEDULING
3488 split_all_insns ();
3489 #endif
3490 return 0;
3493 struct rtl_opt_pass pass_split_before_sched2 =
3496 RTL_PASS,
3497 "split4", /* name */
3498 gate_handle_split_before_sched2, /* gate */
3499 rest_of_handle_split_before_sched2, /* execute */
3500 NULL, /* sub */
3501 NULL, /* next */
3502 0, /* static_pass_number */
3503 0, /* tv_id */
3504 0, /* properties_required */
3505 0, /* properties_provided */
3506 0, /* properties_destroyed */
3507 0, /* todo_flags_start */
3508 TODO_verify_flow |
3509 TODO_dump_func /* todo_flags_finish */
3513 /* The placement of the splitting that we do for shorten_branches
3514 depends on whether regstack is used by the target or not. */
3515 static bool
3516 gate_do_final_split (void)
3518 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3519 return 1;
3520 #else
3521 return 0;
3522 #endif
3525 struct rtl_opt_pass pass_split_for_shorten_branches =
3528 RTL_PASS,
3529 "split5", /* name */
3530 gate_do_final_split, /* gate */
3531 split_all_insns_noflow, /* execute */
3532 NULL, /* sub */
3533 NULL, /* next */
3534 0, /* static_pass_number */
3535 0, /* tv_id */
3536 0, /* properties_required */
3537 0, /* properties_provided */
3538 0, /* properties_destroyed */
3539 0, /* todo_flags_start */
3540 TODO_dump_func | TODO_verify_rtl_sharing /* todo_flags_finish */