2008-01-25 Douglas Gregor <doug.gregor@gmail.com>
[official-gcc.git] / gcc / recog.c
blob6a9ae4510c0d6f47472f2a07f226a9fbc3224b49
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
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 static void validate_replace_rtx_1 (rtx *, rtx, rtx, rtx);
64 static void validate_replace_src_1 (rtx *, void *);
65 static rtx split_insn (rtx);
67 /* Nonzero means allow operands to be volatile.
68 This should be 0 if you are generating rtl, such as if you are calling
69 the functions in optabs.c and expmed.c (most of the time).
70 This should be 1 if all valid insns need to be recognized,
71 such as in regclass.c and final.c and reload.c.
73 init_recog and init_recog_no_volatile are responsible for setting this. */
75 int volatile_ok;
77 struct recog_data recog_data;
79 /* Contains a vector of operand_alternative structures for every operand.
80 Set up by preprocess_constraints. */
81 struct operand_alternative recog_op_alt[MAX_RECOG_OPERANDS][MAX_RECOG_ALTERNATIVES];
83 /* On return from `constrain_operands', indicate which alternative
84 was satisfied. */
86 int which_alternative;
88 /* Nonzero after end of reload pass.
89 Set to 1 or 0 by toplev.c.
90 Controls the significance of (SUBREG (MEM)). */
92 int reload_completed;
94 /* Nonzero after thread_prologue_and_epilogue_insns has run. */
95 int epilogue_completed;
97 /* Initialize data used by the function `recog'.
98 This must be called once in the compilation of a function
99 before any insn recognition may be done in the function. */
101 void
102 init_recog_no_volatile (void)
104 volatile_ok = 0;
107 void
108 init_recog (void)
110 volatile_ok = 1;
114 /* Check that X is an insn-body for an `asm' with operands
115 and that the operands mentioned in it are legitimate. */
118 check_asm_operands (rtx x)
120 int noperands;
121 rtx *operands;
122 const char **constraints;
123 int i;
125 /* Post-reload, be more strict with things. */
126 if (reload_completed)
128 /* ??? Doh! We've not got the wrapping insn. Cook one up. */
129 extract_insn (make_insn_raw (x));
130 constrain_operands (1);
131 return which_alternative >= 0;
134 noperands = asm_noperands (x);
135 if (noperands < 0)
136 return 0;
137 if (noperands == 0)
138 return 1;
140 operands = alloca (noperands * sizeof (rtx));
141 constraints = alloca (noperands * sizeof (char *));
143 decode_asm_operands (x, operands, NULL, constraints, NULL, NULL);
145 for (i = 0; i < noperands; i++)
147 const char *c = constraints[i];
148 if (c[0] == '%')
149 c++;
150 if (ISDIGIT ((unsigned char) c[0]) && c[1] == '\0')
151 c = constraints[c[0] - '0'];
153 if (! asm_operand_ok (operands[i], c))
154 return 0;
157 return 1;
160 /* Static data for the next two routines. */
162 typedef struct change_t
164 rtx object;
165 int old_code;
166 rtx *loc;
167 rtx old;
168 bool unshare;
169 } change_t;
171 static change_t *changes;
172 static int changes_allocated;
174 static int num_changes = 0;
176 /* Validate a proposed change to OBJECT. LOC is the location in the rtl
177 at which NEW will be placed. If OBJECT is zero, no validation is done,
178 the change is simply made.
180 Two types of objects are supported: If OBJECT is a MEM, memory_address_p
181 will be called with the address and mode as parameters. If OBJECT is
182 an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
183 the change in place.
185 IN_GROUP is nonzero if this is part of a group of changes that must be
186 performed as a group. In that case, the changes will be stored. The
187 function `apply_change_group' will validate and apply the changes.
189 If IN_GROUP is zero, this is a single change. Try to recognize the insn
190 or validate the memory reference with the change applied. If the result
191 is not valid for the machine, suppress the change and return zero.
192 Otherwise, perform the change and return 1. */
194 static bool
195 validate_change_1 (rtx object, rtx *loc, rtx new, bool in_group, bool unshare)
197 rtx old = *loc;
199 if (old == new || rtx_equal_p (old, new))
200 return 1;
202 gcc_assert (in_group != 0 || num_changes == 0);
204 *loc = new;
206 /* Save the information describing this change. */
207 if (num_changes >= changes_allocated)
209 if (changes_allocated == 0)
210 /* This value allows for repeated substitutions inside complex
211 indexed addresses, or changes in up to 5 insns. */
212 changes_allocated = MAX_RECOG_OPERANDS * 5;
213 else
214 changes_allocated *= 2;
216 changes = xrealloc (changes, sizeof (change_t) * changes_allocated);
219 changes[num_changes].object = object;
220 changes[num_changes].loc = loc;
221 changes[num_changes].old = old;
222 changes[num_changes].unshare = unshare;
224 if (object && !MEM_P (object))
226 /* Set INSN_CODE to force rerecognition of insn. Save old code in
227 case invalid. */
228 changes[num_changes].old_code = INSN_CODE (object);
229 INSN_CODE (object) = -1;
232 num_changes++;
234 /* If we are making a group of changes, return 1. Otherwise, validate the
235 change group we made. */
237 if (in_group)
238 return 1;
239 else
240 return apply_change_group ();
243 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
244 UNSHARE to false. */
246 bool
247 validate_change (rtx object, rtx *loc, rtx new, bool in_group)
249 return validate_change_1 (object, loc, new, in_group, false);
252 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
253 UNSHARE to true. */
255 bool
256 validate_unshare_change (rtx object, rtx *loc, rtx new, bool in_group)
258 return validate_change_1 (object, loc, new, in_group, true);
262 /* Keep X canonicalized if some changes have made it non-canonical; only
263 modifies the operands of X, not (for example) its code. Simplifications
264 are not the job of this routine.
266 Return true if anything was changed. */
267 bool
268 canonicalize_change_group (rtx insn, rtx x)
270 if (COMMUTATIVE_P (x)
271 && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
273 /* Oops, the caller has made X no longer canonical.
274 Let's redo the changes in the correct order. */
275 rtx tem = XEXP (x, 0);
276 validate_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
277 validate_change (insn, &XEXP (x, 1), tem, 1);
278 return true;
280 else
281 return false;
285 /* This subroutine of apply_change_group verifies whether the changes to INSN
286 were valid; i.e. whether INSN can still be recognized. */
289 insn_invalid_p (rtx insn)
291 rtx pat = PATTERN (insn);
292 int num_clobbers = 0;
293 /* If we are before reload and the pattern is a SET, see if we can add
294 clobbers. */
295 int icode = recog (pat, insn,
296 (GET_CODE (pat) == SET
297 && ! reload_completed && ! reload_in_progress)
298 ? &num_clobbers : 0);
299 int is_asm = icode < 0 && asm_noperands (PATTERN (insn)) >= 0;
302 /* If this is an asm and the operand aren't legal, then fail. Likewise if
303 this is not an asm and the insn wasn't recognized. */
304 if ((is_asm && ! check_asm_operands (PATTERN (insn)))
305 || (!is_asm && icode < 0))
306 return 1;
308 /* If we have to add CLOBBERs, fail if we have to add ones that reference
309 hard registers since our callers can't know if they are live or not.
310 Otherwise, add them. */
311 if (num_clobbers > 0)
313 rtx newpat;
315 if (added_clobbers_hard_reg_p (icode))
316 return 1;
318 newpat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_clobbers + 1));
319 XVECEXP (newpat, 0, 0) = pat;
320 add_clobbers (newpat, icode);
321 PATTERN (insn) = pat = newpat;
324 /* After reload, verify that all constraints are satisfied. */
325 if (reload_completed)
327 extract_insn (insn);
329 if (! constrain_operands (1))
330 return 1;
333 INSN_CODE (insn) = icode;
334 return 0;
337 /* Return number of changes made and not validated yet. */
339 num_changes_pending (void)
341 return num_changes;
344 /* Tentatively apply the changes numbered NUM and up.
345 Return 1 if all changes are valid, zero otherwise. */
348 verify_changes (int num)
350 int i;
351 rtx last_validated = NULL_RTX;
353 /* The changes have been applied and all INSN_CODEs have been reset to force
354 rerecognition.
356 The changes are valid if we aren't given an object, or if we are
357 given a MEM and it still is a valid address, or if this is in insn
358 and it is recognized. In the latter case, if reload has completed,
359 we also require that the operands meet the constraints for
360 the insn. */
362 for (i = num; i < num_changes; i++)
364 rtx object = changes[i].object;
366 /* If there is no object to test or if it is the same as the one we
367 already tested, ignore it. */
368 if (object == 0 || object == last_validated)
369 continue;
371 if (MEM_P (object))
373 if (! memory_address_p (GET_MODE (object), XEXP (object, 0)))
374 break;
376 else if (insn_invalid_p (object))
378 rtx pat = PATTERN (object);
380 /* Perhaps we couldn't recognize the insn because there were
381 extra CLOBBERs at the end. If so, try to re-recognize
382 without the last CLOBBER (later iterations will cause each of
383 them to be eliminated, in turn). But don't do this if we
384 have an ASM_OPERAND. */
385 if (GET_CODE (pat) == PARALLEL
386 && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
387 && asm_noperands (PATTERN (object)) < 0)
389 rtx newpat;
391 if (XVECLEN (pat, 0) == 2)
392 newpat = XVECEXP (pat, 0, 0);
393 else
395 int j;
397 newpat
398 = gen_rtx_PARALLEL (VOIDmode,
399 rtvec_alloc (XVECLEN (pat, 0) - 1));
400 for (j = 0; j < XVECLEN (newpat, 0); j++)
401 XVECEXP (newpat, 0, j) = XVECEXP (pat, 0, j);
404 /* Add a new change to this group to replace the pattern
405 with this new pattern. Then consider this change
406 as having succeeded. The change we added will
407 cause the entire call to fail if things remain invalid.
409 Note that this can lose if a later change than the one
410 we are processing specified &XVECEXP (PATTERN (object), 0, X)
411 but this shouldn't occur. */
413 validate_change (object, &PATTERN (object), newpat, 1);
414 continue;
416 else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
417 /* If this insn is a CLOBBER or USE, it is always valid, but is
418 never recognized. */
419 continue;
420 else
421 break;
423 last_validated = object;
426 return (i == num_changes);
429 /* A group of changes has previously been issued with validate_change
430 and verified with verify_changes. Call df_insn_rescan for each of
431 the insn changed and clear num_changes. */
433 void
434 confirm_change_group (void)
436 int i;
437 rtx last_object = NULL;
439 for (i = 0; i < num_changes; i++)
441 rtx object = changes[i].object;
443 if (changes[i].unshare)
444 *changes[i].loc = copy_rtx (*changes[i].loc);
446 /* Avoid unnecesary rescanning when multiple changes to same instruction
447 are made. */
448 if (object)
450 if (object != last_object && last_object && INSN_P (last_object))
451 df_insn_rescan (last_object);
452 last_object = object;
456 if (last_object && INSN_P (last_object))
457 df_insn_rescan (last_object);
458 num_changes = 0;
461 /* Apply a group of changes previously issued with `validate_change'.
462 If all changes are valid, call confirm_change_group and return 1,
463 otherwise, call cancel_changes and return 0. */
466 apply_change_group (void)
468 if (verify_changes (0))
470 confirm_change_group ();
471 return 1;
473 else
475 cancel_changes (0);
476 return 0;
481 /* Return the number of changes so far in the current group. */
484 num_validated_changes (void)
486 return num_changes;
489 /* Retract the changes numbered NUM and up. */
491 void
492 cancel_changes (int num)
494 int i;
496 /* Back out all the changes. Do this in the opposite order in which
497 they were made. */
498 for (i = num_changes - 1; i >= num; i--)
500 *changes[i].loc = changes[i].old;
501 if (changes[i].object && !MEM_P (changes[i].object))
502 INSN_CODE (changes[i].object) = changes[i].old_code;
504 num_changes = num;
507 /* Replace every occurrence of FROM in X with TO. Mark each change with
508 validate_change passing OBJECT. */
510 static void
511 validate_replace_rtx_1 (rtx *loc, rtx from, rtx to, rtx object)
513 int i, j;
514 const char *fmt;
515 rtx x = *loc;
516 enum rtx_code code;
517 enum machine_mode op0_mode = VOIDmode;
518 int prev_changes = num_changes;
519 rtx new;
521 if (!x)
522 return;
524 code = GET_CODE (x);
525 fmt = GET_RTX_FORMAT (code);
526 if (fmt[0] == 'e')
527 op0_mode = GET_MODE (XEXP (x, 0));
529 /* X matches FROM if it is the same rtx or they are both referring to the
530 same register in the same mode. Avoid calling rtx_equal_p unless the
531 operands look similar. */
533 if (x == from
534 || (REG_P (x) && REG_P (from)
535 && GET_MODE (x) == GET_MODE (from)
536 && REGNO (x) == REGNO (from))
537 || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
538 && rtx_equal_p (x, from)))
540 validate_unshare_change (object, loc, to, 1);
541 return;
544 /* Call ourself recursively to perform the replacements.
545 We must not replace inside already replaced expression, otherwise we
546 get infinite recursion for replacements like (reg X)->(subreg (reg X))
547 done by regmove, so we must special case shared ASM_OPERANDS. */
549 if (GET_CODE (x) == PARALLEL)
551 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
553 if (j && GET_CODE (XVECEXP (x, 0, j)) == SET
554 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == ASM_OPERANDS)
556 /* Verify that operands are really shared. */
557 gcc_assert (ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (x, 0, 0)))
558 == ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP
559 (x, 0, j))));
560 validate_replace_rtx_1 (&SET_DEST (XVECEXP (x, 0, j)),
561 from, to, object);
563 else
564 validate_replace_rtx_1 (&XVECEXP (x, 0, j), from, to, object);
567 else
568 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
570 if (fmt[i] == 'e')
571 validate_replace_rtx_1 (&XEXP (x, i), from, to, object);
572 else if (fmt[i] == 'E')
573 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
574 validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object);
577 /* If we didn't substitute, there is nothing more to do. */
578 if (num_changes == prev_changes)
579 return;
581 /* Allow substituted expression to have different mode. This is used by
582 regmove to change mode of pseudo register. */
583 if (fmt[0] == 'e' && GET_MODE (XEXP (x, 0)) != VOIDmode)
584 op0_mode = GET_MODE (XEXP (x, 0));
586 /* Do changes needed to keep rtx consistent. Don't do any other
587 simplifications, as it is not our job. */
589 if (SWAPPABLE_OPERANDS_P (x)
590 && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
592 validate_change (object, loc,
593 gen_rtx_fmt_ee (COMMUTATIVE_ARITH_P (x) ? code
594 : swap_condition (code),
595 GET_MODE (x), XEXP (x, 1),
596 XEXP (x, 0)), 1);
597 x = *loc;
598 code = GET_CODE (x);
601 switch (code)
603 case PLUS:
604 /* If we have a PLUS whose second operand is now a CONST_INT, use
605 simplify_gen_binary to try to simplify it.
606 ??? We may want later to remove this, once simplification is
607 separated from this function. */
608 if (GET_CODE (XEXP (x, 1)) == CONST_INT && XEXP (x, 1) == to)
609 validate_change (object, loc,
610 simplify_gen_binary
611 (PLUS, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)), 1);
612 break;
613 case MINUS:
614 if (GET_CODE (XEXP (x, 1)) == CONST_INT
615 || GET_CODE (XEXP (x, 1)) == CONST_DOUBLE)
616 validate_change (object, loc,
617 simplify_gen_binary
618 (PLUS, GET_MODE (x), XEXP (x, 0),
619 simplify_gen_unary (NEG,
620 GET_MODE (x), XEXP (x, 1),
621 GET_MODE (x))), 1);
622 break;
623 case ZERO_EXTEND:
624 case SIGN_EXTEND:
625 if (GET_MODE (XEXP (x, 0)) == VOIDmode)
627 new = simplify_gen_unary (code, GET_MODE (x), XEXP (x, 0),
628 op0_mode);
629 /* If any of the above failed, substitute in something that
630 we know won't be recognized. */
631 if (!new)
632 new = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
633 validate_change (object, loc, new, 1);
635 break;
636 case SUBREG:
637 /* All subregs possible to simplify should be simplified. */
638 new = simplify_subreg (GET_MODE (x), SUBREG_REG (x), op0_mode,
639 SUBREG_BYTE (x));
641 /* Subregs of VOIDmode operands are incorrect. */
642 if (!new && GET_MODE (SUBREG_REG (x)) == VOIDmode)
643 new = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
644 if (new)
645 validate_change (object, loc, new, 1);
646 break;
647 case ZERO_EXTRACT:
648 case SIGN_EXTRACT:
649 /* If we are replacing a register with memory, try to change the memory
650 to be the mode required for memory in extract operations (this isn't
651 likely to be an insertion operation; if it was, nothing bad will
652 happen, we might just fail in some cases). */
654 if (MEM_P (XEXP (x, 0))
655 && GET_CODE (XEXP (x, 1)) == CONST_INT
656 && GET_CODE (XEXP (x, 2)) == CONST_INT
657 && !mode_dependent_address_p (XEXP (XEXP (x, 0), 0))
658 && !MEM_VOLATILE_P (XEXP (x, 0)))
660 enum machine_mode wanted_mode = VOIDmode;
661 enum machine_mode is_mode = GET_MODE (XEXP (x, 0));
662 int pos = INTVAL (XEXP (x, 2));
664 if (GET_CODE (x) == ZERO_EXTRACT)
666 enum machine_mode new_mode
667 = mode_for_extraction (EP_extzv, 1);
668 if (new_mode != MAX_MACHINE_MODE)
669 wanted_mode = new_mode;
671 else if (GET_CODE (x) == SIGN_EXTRACT)
673 enum machine_mode new_mode
674 = mode_for_extraction (EP_extv, 1);
675 if (new_mode != MAX_MACHINE_MODE)
676 wanted_mode = new_mode;
679 /* If we have a narrower mode, we can do something. */
680 if (wanted_mode != VOIDmode
681 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
683 int offset = pos / BITS_PER_UNIT;
684 rtx newmem;
686 /* If the bytes and bits are counted differently, we
687 must adjust the offset. */
688 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
689 offset =
690 (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode) -
691 offset);
693 pos %= GET_MODE_BITSIZE (wanted_mode);
695 newmem = adjust_address_nv (XEXP (x, 0), wanted_mode, offset);
697 validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
698 validate_change (object, &XEXP (x, 0), newmem, 1);
702 break;
704 default:
705 break;
709 /* Try replacing every occurrence of FROM in INSN with TO. After all
710 changes have been made, validate by seeing if INSN is still valid. */
713 validate_replace_rtx (rtx from, rtx to, rtx insn)
715 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
716 return apply_change_group ();
719 /* Try replacing every occurrence of FROM in INSN with TO. */
721 void
722 validate_replace_rtx_group (rtx from, rtx to, rtx insn)
724 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
727 /* Function called by note_uses to replace used subexpressions. */
728 struct validate_replace_src_data
730 rtx from; /* Old RTX */
731 rtx to; /* New RTX */
732 rtx insn; /* Insn in which substitution is occurring. */
735 static void
736 validate_replace_src_1 (rtx *x, void *data)
738 struct validate_replace_src_data *d
739 = (struct validate_replace_src_data *) data;
741 validate_replace_rtx_1 (x, d->from, d->to, d->insn);
744 /* Try replacing every occurrence of FROM in INSN with TO, avoiding
745 SET_DESTs. */
747 void
748 validate_replace_src_group (rtx from, rtx to, rtx insn)
750 struct validate_replace_src_data d;
752 d.from = from;
753 d.to = to;
754 d.insn = insn;
755 note_uses (&PATTERN (insn), validate_replace_src_1, &d);
758 /* Try simplify INSN.
759 Invoke simplify_rtx () on every SET_SRC and SET_DEST inside the INSN's
760 pattern and return true if something was simplified. */
762 bool
763 validate_simplify_insn (rtx insn)
765 int i;
766 rtx pat = NULL;
767 rtx newpat = NULL;
769 pat = PATTERN (insn);
771 if (GET_CODE (pat) == SET)
773 newpat = simplify_rtx (SET_SRC (pat));
774 if (newpat && !rtx_equal_p (SET_SRC (pat), newpat))
775 validate_change (insn, &SET_SRC (pat), newpat, 1);
776 newpat = simplify_rtx (SET_DEST (pat));
777 if (newpat && !rtx_equal_p (SET_DEST (pat), newpat))
778 validate_change (insn, &SET_DEST (pat), newpat, 1);
780 else if (GET_CODE (pat) == PARALLEL)
781 for (i = 0; i < XVECLEN (pat, 0); i++)
783 rtx s = XVECEXP (pat, 0, i);
785 if (GET_CODE (XVECEXP (pat, 0, i)) == SET)
787 newpat = simplify_rtx (SET_SRC (s));
788 if (newpat && !rtx_equal_p (SET_SRC (s), newpat))
789 validate_change (insn, &SET_SRC (s), newpat, 1);
790 newpat = simplify_rtx (SET_DEST (s));
791 if (newpat && !rtx_equal_p (SET_DEST (s), newpat))
792 validate_change (insn, &SET_DEST (s), newpat, 1);
795 return ((num_changes_pending () > 0) && (apply_change_group () > 0));
798 #ifdef HAVE_cc0
799 /* Return 1 if the insn using CC0 set by INSN does not contain
800 any ordered tests applied to the condition codes.
801 EQ and NE tests do not count. */
804 next_insn_tests_no_inequality (rtx insn)
806 rtx next = next_cc0_user (insn);
808 /* If there is no next insn, we have to take the conservative choice. */
809 if (next == 0)
810 return 0;
812 return (INSN_P (next)
813 && ! inequality_comparisons_p (PATTERN (next)));
815 #endif
817 /* Return 1 if OP is a valid general operand for machine mode MODE.
818 This is either a register reference, a memory reference,
819 or a constant. In the case of a memory reference, the address
820 is checked for general validity for the target machine.
822 Register and memory references must have mode MODE in order to be valid,
823 but some constants have no machine mode and are valid for any mode.
825 If MODE is VOIDmode, OP is checked for validity for whatever mode
826 it has.
828 The main use of this function is as a predicate in match_operand
829 expressions in the machine description.
831 For an explanation of this function's behavior for registers of
832 class NO_REGS, see the comment for `register_operand'. */
835 general_operand (rtx op, enum machine_mode mode)
837 enum rtx_code code = GET_CODE (op);
839 if (mode == VOIDmode)
840 mode = GET_MODE (op);
842 /* Don't accept CONST_INT or anything similar
843 if the caller wants something floating. */
844 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
845 && GET_MODE_CLASS (mode) != MODE_INT
846 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
847 return 0;
849 if (GET_CODE (op) == CONST_INT
850 && mode != VOIDmode
851 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
852 return 0;
854 if (CONSTANT_P (op))
855 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
856 || mode == VOIDmode)
857 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
858 && LEGITIMATE_CONSTANT_P (op));
860 /* Except for certain constants with VOIDmode, already checked for,
861 OP's mode must match MODE if MODE specifies a mode. */
863 if (GET_MODE (op) != mode)
864 return 0;
866 if (code == SUBREG)
868 rtx sub = SUBREG_REG (op);
870 #ifdef INSN_SCHEDULING
871 /* On machines that have insn scheduling, we want all memory
872 reference to be explicit, so outlaw paradoxical SUBREGs.
873 However, we must allow them after reload so that they can
874 get cleaned up by cleanup_subreg_operands. */
875 if (!reload_completed && MEM_P (sub)
876 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (sub)))
877 return 0;
878 #endif
879 /* Avoid memories with nonzero SUBREG_BYTE, as offsetting the memory
880 may result in incorrect reference. We should simplify all valid
881 subregs of MEM anyway. But allow this after reload because we
882 might be called from cleanup_subreg_operands.
884 ??? This is a kludge. */
885 if (!reload_completed && SUBREG_BYTE (op) != 0
886 && MEM_P (sub))
887 return 0;
889 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
890 create such rtl, and we must reject it. */
891 if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
892 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
893 return 0;
895 op = sub;
896 code = GET_CODE (op);
899 if (code == REG)
900 /* A register whose class is NO_REGS is not a general operand. */
901 return (REGNO (op) >= FIRST_PSEUDO_REGISTER
902 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS);
904 if (code == MEM)
906 rtx y = XEXP (op, 0);
908 if (! volatile_ok && MEM_VOLATILE_P (op))
909 return 0;
911 /* Use the mem's mode, since it will be reloaded thus. */
912 if (memory_address_p (GET_MODE (op), y))
913 return 1;
916 return 0;
919 /* Return 1 if OP is a valid memory address for a memory reference
920 of mode MODE.
922 The main use of this function is as a predicate in match_operand
923 expressions in the machine description. */
926 address_operand (rtx op, enum machine_mode mode)
928 return memory_address_p (mode, op);
931 /* Return 1 if OP is a register reference of mode MODE.
932 If MODE is VOIDmode, accept a register in any mode.
934 The main use of this function is as a predicate in match_operand
935 expressions in the machine description.
937 As a special exception, registers whose class is NO_REGS are
938 not accepted by `register_operand'. The reason for this change
939 is to allow the representation of special architecture artifacts
940 (such as a condition code register) without extending the rtl
941 definitions. Since registers of class NO_REGS cannot be used
942 as registers in any case where register classes are examined,
943 it is most consistent to keep this function from accepting them. */
946 register_operand (rtx op, enum machine_mode mode)
948 if (GET_MODE (op) != mode && mode != VOIDmode)
949 return 0;
951 if (GET_CODE (op) == SUBREG)
953 rtx sub = SUBREG_REG (op);
955 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
956 because it is guaranteed to be reloaded into one.
957 Just make sure the MEM is valid in itself.
958 (Ideally, (SUBREG (MEM)...) should not exist after reload,
959 but currently it does result from (SUBREG (REG)...) where the
960 reg went on the stack.) */
961 if (! reload_completed && MEM_P (sub))
962 return general_operand (op, mode);
964 #ifdef CANNOT_CHANGE_MODE_CLASS
965 if (REG_P (sub)
966 && REGNO (sub) < FIRST_PSEUDO_REGISTER
967 && REG_CANNOT_CHANGE_MODE_P (REGNO (sub), GET_MODE (sub), mode)
968 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_INT
969 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_FLOAT)
970 return 0;
971 #endif
973 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
974 create such rtl, and we must reject it. */
975 if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
976 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
977 return 0;
979 op = sub;
982 /* We don't consider registers whose class is NO_REGS
983 to be a register operand. */
984 return (REG_P (op)
985 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
986 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
989 /* Return 1 for a register in Pmode; ignore the tested mode. */
992 pmode_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
994 return register_operand (op, Pmode);
997 /* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
998 or a hard register. */
1001 scratch_operand (rtx op, enum machine_mode mode)
1003 if (GET_MODE (op) != mode && mode != VOIDmode)
1004 return 0;
1006 return (GET_CODE (op) == SCRATCH
1007 || (REG_P (op)
1008 && REGNO (op) < FIRST_PSEUDO_REGISTER));
1011 /* Return 1 if OP is a valid immediate operand for mode MODE.
1013 The main use of this function is as a predicate in match_operand
1014 expressions in the machine description. */
1017 immediate_operand (rtx op, enum machine_mode mode)
1019 /* Don't accept CONST_INT or anything similar
1020 if the caller wants something floating. */
1021 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1022 && GET_MODE_CLASS (mode) != MODE_INT
1023 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1024 return 0;
1026 if (GET_CODE (op) == CONST_INT
1027 && mode != VOIDmode
1028 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1029 return 0;
1031 return (CONSTANT_P (op)
1032 && (GET_MODE (op) == mode || mode == VOIDmode
1033 || GET_MODE (op) == VOIDmode)
1034 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1035 && LEGITIMATE_CONSTANT_P (op));
1038 /* Returns 1 if OP is an operand that is a CONST_INT. */
1041 const_int_operand (rtx op, enum machine_mode mode)
1043 if (GET_CODE (op) != CONST_INT)
1044 return 0;
1046 if (mode != VOIDmode
1047 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1048 return 0;
1050 return 1;
1053 /* Returns 1 if OP is an operand that is a constant integer or constant
1054 floating-point number. */
1057 const_double_operand (rtx op, enum machine_mode mode)
1059 /* Don't accept CONST_INT or anything similar
1060 if the caller wants something floating. */
1061 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1062 && GET_MODE_CLASS (mode) != MODE_INT
1063 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1064 return 0;
1066 return ((GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT)
1067 && (mode == VOIDmode || GET_MODE (op) == mode
1068 || GET_MODE (op) == VOIDmode));
1071 /* Return 1 if OP is a general operand that is not an immediate operand. */
1074 nonimmediate_operand (rtx op, enum machine_mode mode)
1076 return (general_operand (op, mode) && ! CONSTANT_P (op));
1079 /* Return 1 if OP is a register reference or immediate value of mode MODE. */
1082 nonmemory_operand (rtx op, enum machine_mode mode)
1084 if (CONSTANT_P (op))
1086 /* Don't accept CONST_INT or anything similar
1087 if the caller wants something floating. */
1088 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1089 && GET_MODE_CLASS (mode) != MODE_INT
1090 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1091 return 0;
1093 if (GET_CODE (op) == CONST_INT
1094 && mode != VOIDmode
1095 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1096 return 0;
1098 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
1099 || mode == VOIDmode)
1100 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1101 && LEGITIMATE_CONSTANT_P (op));
1104 if (GET_MODE (op) != mode && mode != VOIDmode)
1105 return 0;
1107 if (GET_CODE (op) == SUBREG)
1109 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1110 because it is guaranteed to be reloaded into one.
1111 Just make sure the MEM is valid in itself.
1112 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1113 but currently it does result from (SUBREG (REG)...) where the
1114 reg went on the stack.) */
1115 if (! reload_completed && MEM_P (SUBREG_REG (op)))
1116 return general_operand (op, mode);
1117 op = SUBREG_REG (op);
1120 /* We don't consider registers whose class is NO_REGS
1121 to be a register operand. */
1122 return (REG_P (op)
1123 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1124 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1127 /* Return 1 if OP is a valid operand that stands for pushing a
1128 value of mode MODE onto the stack.
1130 The main use of this function is as a predicate in match_operand
1131 expressions in the machine description. */
1134 push_operand (rtx op, enum machine_mode mode)
1136 unsigned int rounded_size = GET_MODE_SIZE (mode);
1138 #ifdef PUSH_ROUNDING
1139 rounded_size = PUSH_ROUNDING (rounded_size);
1140 #endif
1142 if (!MEM_P (op))
1143 return 0;
1145 if (mode != VOIDmode && GET_MODE (op) != mode)
1146 return 0;
1148 op = XEXP (op, 0);
1150 if (rounded_size == GET_MODE_SIZE (mode))
1152 if (GET_CODE (op) != STACK_PUSH_CODE)
1153 return 0;
1155 else
1157 if (GET_CODE (op) != PRE_MODIFY
1158 || GET_CODE (XEXP (op, 1)) != PLUS
1159 || XEXP (XEXP (op, 1), 0) != XEXP (op, 0)
1160 || GET_CODE (XEXP (XEXP (op, 1), 1)) != CONST_INT
1161 #ifdef STACK_GROWS_DOWNWARD
1162 || INTVAL (XEXP (XEXP (op, 1), 1)) != - (int) rounded_size
1163 #else
1164 || INTVAL (XEXP (XEXP (op, 1), 1)) != (int) rounded_size
1165 #endif
1167 return 0;
1170 return XEXP (op, 0) == stack_pointer_rtx;
1173 /* Return 1 if OP is a valid operand that stands for popping a
1174 value of mode MODE off the stack.
1176 The main use of this function is as a predicate in match_operand
1177 expressions in the machine description. */
1180 pop_operand (rtx op, enum machine_mode mode)
1182 if (!MEM_P (op))
1183 return 0;
1185 if (mode != VOIDmode && GET_MODE (op) != mode)
1186 return 0;
1188 op = XEXP (op, 0);
1190 if (GET_CODE (op) != STACK_POP_CODE)
1191 return 0;
1193 return XEXP (op, 0) == stack_pointer_rtx;
1196 /* Return 1 if ADDR is a valid memory address for mode MODE. */
1199 memory_address_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx addr)
1201 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1202 return 0;
1204 win:
1205 return 1;
1208 /* Return 1 if OP is a valid memory reference with mode MODE,
1209 including a valid address.
1211 The main use of this function is as a predicate in match_operand
1212 expressions in the machine description. */
1215 memory_operand (rtx op, enum machine_mode mode)
1217 rtx inner;
1219 if (! reload_completed)
1220 /* Note that no SUBREG is a memory operand before end of reload pass,
1221 because (SUBREG (MEM...)) forces reloading into a register. */
1222 return MEM_P (op) && general_operand (op, mode);
1224 if (mode != VOIDmode && GET_MODE (op) != mode)
1225 return 0;
1227 inner = op;
1228 if (GET_CODE (inner) == SUBREG)
1229 inner = SUBREG_REG (inner);
1231 return (MEM_P (inner) && general_operand (op, mode));
1234 /* Return 1 if OP is a valid indirect memory reference with mode MODE;
1235 that is, a memory reference whose address is a general_operand. */
1238 indirect_operand (rtx op, enum machine_mode mode)
1240 /* Before reload, a SUBREG isn't in memory (see memory_operand, above). */
1241 if (! reload_completed
1242 && GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))
1244 int offset = SUBREG_BYTE (op);
1245 rtx inner = SUBREG_REG (op);
1247 if (mode != VOIDmode && GET_MODE (op) != mode)
1248 return 0;
1250 /* The only way that we can have a general_operand as the resulting
1251 address is if OFFSET is zero and the address already is an operand
1252 or if the address is (plus Y (const_int -OFFSET)) and Y is an
1253 operand. */
1255 return ((offset == 0 && general_operand (XEXP (inner, 0), Pmode))
1256 || (GET_CODE (XEXP (inner, 0)) == PLUS
1257 && GET_CODE (XEXP (XEXP (inner, 0), 1)) == CONST_INT
1258 && INTVAL (XEXP (XEXP (inner, 0), 1)) == -offset
1259 && general_operand (XEXP (XEXP (inner, 0), 0), Pmode)));
1262 return (MEM_P (op)
1263 && memory_operand (op, mode)
1264 && general_operand (XEXP (op, 0), Pmode));
1267 /* Return 1 if this is a comparison operator. This allows the use of
1268 MATCH_OPERATOR to recognize all the branch insns. */
1271 comparison_operator (rtx op, enum machine_mode mode)
1273 return ((mode == VOIDmode || GET_MODE (op) == mode)
1274 && COMPARISON_P (op));
1277 /* If BODY is an insn body that uses ASM_OPERANDS,
1278 return the number of operands (both input and output) in the insn.
1279 Otherwise return -1. */
1282 asm_noperands (const_rtx body)
1284 switch (GET_CODE (body))
1286 case ASM_OPERANDS:
1287 /* No output operands: return number of input operands. */
1288 return ASM_OPERANDS_INPUT_LENGTH (body);
1289 case SET:
1290 if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1291 /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
1292 return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (body)) + 1;
1293 else
1294 return -1;
1295 case PARALLEL:
1296 if (GET_CODE (XVECEXP (body, 0, 0)) == SET
1297 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1299 /* Multiple output operands, or 1 output plus some clobbers:
1300 body is [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...]. */
1301 int i;
1302 int n_sets;
1304 /* Count backwards through CLOBBERs to determine number of SETs. */
1305 for (i = XVECLEN (body, 0); i > 0; i--)
1307 if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
1308 break;
1309 if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
1310 return -1;
1313 /* N_SETS is now number of output operands. */
1314 n_sets = i;
1316 /* Verify that all the SETs we have
1317 came from a single original asm_operands insn
1318 (so that invalid combinations are blocked). */
1319 for (i = 0; i < n_sets; i++)
1321 rtx elt = XVECEXP (body, 0, i);
1322 if (GET_CODE (elt) != SET)
1323 return -1;
1324 if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
1325 return -1;
1326 /* If these ASM_OPERANDS rtx's came from different original insns
1327 then they aren't allowed together. */
1328 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
1329 != ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (body, 0, 0))))
1330 return -1;
1332 return (ASM_OPERANDS_INPUT_LENGTH (SET_SRC (XVECEXP (body, 0, 0)))
1333 + n_sets);
1335 else if (GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1337 /* 0 outputs, but some clobbers:
1338 body is [(asm_operands ...) (clobber (reg ...))...]. */
1339 int i;
1341 /* Make sure all the other parallel things really are clobbers. */
1342 for (i = XVECLEN (body, 0) - 1; i > 0; i--)
1343 if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
1344 return -1;
1346 return ASM_OPERANDS_INPUT_LENGTH (XVECEXP (body, 0, 0));
1348 else
1349 return -1;
1350 default:
1351 return -1;
1355 /* Assuming BODY is an insn body that uses ASM_OPERANDS,
1356 copy its operands (both input and output) into the vector OPERANDS,
1357 the locations of the operands within the insn into the vector OPERAND_LOCS,
1358 and the constraints for the operands into CONSTRAINTS.
1359 Write the modes of the operands into MODES.
1360 Return the assembler-template.
1362 If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1363 we don't store that info. */
1365 const char *
1366 decode_asm_operands (rtx body, rtx *operands, rtx **operand_locs,
1367 const char **constraints, enum machine_mode *modes,
1368 location_t *loc)
1370 int i;
1371 int noperands;
1372 rtx asmop = 0;
1374 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1376 asmop = SET_SRC (body);
1377 /* Single output operand: BODY is (set OUTPUT (asm_operands ....)). */
1379 noperands = ASM_OPERANDS_INPUT_LENGTH (asmop) + 1;
1381 for (i = 1; i < noperands; i++)
1383 if (operand_locs)
1384 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i - 1);
1385 if (operands)
1386 operands[i] = ASM_OPERANDS_INPUT (asmop, i - 1);
1387 if (constraints)
1388 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i - 1);
1389 if (modes)
1390 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i - 1);
1393 /* The output is in the SET.
1394 Its constraint is in the ASM_OPERANDS itself. */
1395 if (operands)
1396 operands[0] = SET_DEST (body);
1397 if (operand_locs)
1398 operand_locs[0] = &SET_DEST (body);
1399 if (constraints)
1400 constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
1401 if (modes)
1402 modes[0] = GET_MODE (SET_DEST (body));
1404 else if (GET_CODE (body) == ASM_OPERANDS)
1406 asmop = body;
1407 /* No output operands: BODY is (asm_operands ....). */
1409 noperands = ASM_OPERANDS_INPUT_LENGTH (asmop);
1411 /* The input operands are found in the 1st element vector. */
1412 /* Constraints for inputs are in the 2nd element vector. */
1413 for (i = 0; i < noperands; i++)
1415 if (operand_locs)
1416 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1417 if (operands)
1418 operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1419 if (constraints)
1420 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1421 if (modes)
1422 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1425 else if (GET_CODE (body) == PARALLEL
1426 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1427 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1429 int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
1430 int nin;
1431 int nout = 0; /* Does not include CLOBBERs. */
1433 asmop = SET_SRC (XVECEXP (body, 0, 0));
1434 nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1436 /* At least one output, plus some CLOBBERs. */
1438 /* The outputs are in the SETs.
1439 Their constraints are in the ASM_OPERANDS itself. */
1440 for (i = 0; i < nparallel; i++)
1442 if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1443 break; /* Past last SET */
1445 if (operands)
1446 operands[i] = SET_DEST (XVECEXP (body, 0, i));
1447 if (operand_locs)
1448 operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
1449 if (constraints)
1450 constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
1451 if (modes)
1452 modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
1453 nout++;
1456 for (i = 0; i < nin; i++)
1458 if (operand_locs)
1459 operand_locs[i + nout] = &ASM_OPERANDS_INPUT (asmop, i);
1460 if (operands)
1461 operands[i + nout] = ASM_OPERANDS_INPUT (asmop, i);
1462 if (constraints)
1463 constraints[i + nout] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1464 if (modes)
1465 modes[i + nout] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1468 else if (GET_CODE (body) == PARALLEL
1469 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1471 /* No outputs, but some CLOBBERs. */
1473 int nin;
1475 asmop = XVECEXP (body, 0, 0);
1476 nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1478 for (i = 0; i < nin; i++)
1480 if (operand_locs)
1481 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1482 if (operands)
1483 operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1484 if (constraints)
1485 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1486 if (modes)
1487 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1492 if (loc)
1494 #ifdef USE_MAPPED_LOCATION
1495 *loc = ASM_OPERANDS_SOURCE_LOCATION (asmop);
1496 #else
1497 loc->file = ASM_OPERANDS_SOURCE_FILE (asmop);
1498 loc->line = ASM_OPERANDS_SOURCE_LINE (asmop);
1499 #endif
1502 return ASM_OPERANDS_TEMPLATE (asmop);
1505 /* Check if an asm_operand matches its constraints.
1506 Return > 0 if ok, = 0 if bad, < 0 if inconclusive. */
1509 asm_operand_ok (rtx op, const char *constraint)
1511 int result = 0;
1513 /* Use constrain_operands after reload. */
1514 gcc_assert (!reload_completed);
1516 while (*constraint)
1518 char c = *constraint;
1519 int len;
1520 switch (c)
1522 case ',':
1523 constraint++;
1524 continue;
1525 case '=':
1526 case '+':
1527 case '*':
1528 case '%':
1529 case '!':
1530 case '#':
1531 case '&':
1532 case '?':
1533 break;
1535 case '0': case '1': case '2': case '3': case '4':
1536 case '5': case '6': case '7': case '8': case '9':
1537 /* For best results, our caller should have given us the
1538 proper matching constraint, but we can't actually fail
1539 the check if they didn't. Indicate that results are
1540 inconclusive. */
1542 constraint++;
1543 while (ISDIGIT (*constraint));
1544 if (! result)
1545 result = -1;
1546 continue;
1548 case 'p':
1549 if (address_operand (op, VOIDmode))
1550 result = 1;
1551 break;
1553 case 'm':
1554 case 'V': /* non-offsettable */
1555 if (memory_operand (op, VOIDmode))
1556 result = 1;
1557 break;
1559 case 'o': /* offsettable */
1560 if (offsettable_nonstrict_memref_p (op))
1561 result = 1;
1562 break;
1564 case '<':
1565 /* ??? Before auto-inc-dec, auto inc/dec insns are not supposed to exist,
1566 excepting those that expand_call created. Further, on some
1567 machines which do not have generalized auto inc/dec, an inc/dec
1568 is not a memory_operand.
1570 Match any memory and hope things are resolved after reload. */
1572 if (MEM_P (op)
1573 && (1
1574 || GET_CODE (XEXP (op, 0)) == PRE_DEC
1575 || GET_CODE (XEXP (op, 0)) == POST_DEC))
1576 result = 1;
1577 break;
1579 case '>':
1580 if (MEM_P (op)
1581 && (1
1582 || GET_CODE (XEXP (op, 0)) == PRE_INC
1583 || GET_CODE (XEXP (op, 0)) == POST_INC))
1584 result = 1;
1585 break;
1587 case 'E':
1588 case 'F':
1589 if (GET_CODE (op) == CONST_DOUBLE
1590 || (GET_CODE (op) == CONST_VECTOR
1591 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
1592 result = 1;
1593 break;
1595 case 'G':
1596 if (GET_CODE (op) == CONST_DOUBLE
1597 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'G', constraint))
1598 result = 1;
1599 break;
1600 case 'H':
1601 if (GET_CODE (op) == CONST_DOUBLE
1602 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'H', constraint))
1603 result = 1;
1604 break;
1606 case 's':
1607 if (GET_CODE (op) == CONST_INT
1608 || (GET_CODE (op) == CONST_DOUBLE
1609 && GET_MODE (op) == VOIDmode))
1610 break;
1611 /* Fall through. */
1613 case 'i':
1614 if (CONSTANT_P (op) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op)))
1615 result = 1;
1616 break;
1618 case 'n':
1619 if (GET_CODE (op) == CONST_INT
1620 || (GET_CODE (op) == CONST_DOUBLE
1621 && GET_MODE (op) == VOIDmode))
1622 result = 1;
1623 break;
1625 case 'I':
1626 if (GET_CODE (op) == CONST_INT
1627 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'I', constraint))
1628 result = 1;
1629 break;
1630 case 'J':
1631 if (GET_CODE (op) == CONST_INT
1632 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'J', constraint))
1633 result = 1;
1634 break;
1635 case 'K':
1636 if (GET_CODE (op) == CONST_INT
1637 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'K', constraint))
1638 result = 1;
1639 break;
1640 case 'L':
1641 if (GET_CODE (op) == CONST_INT
1642 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'L', constraint))
1643 result = 1;
1644 break;
1645 case 'M':
1646 if (GET_CODE (op) == CONST_INT
1647 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'M', constraint))
1648 result = 1;
1649 break;
1650 case 'N':
1651 if (GET_CODE (op) == CONST_INT
1652 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'N', constraint))
1653 result = 1;
1654 break;
1655 case 'O':
1656 if (GET_CODE (op) == CONST_INT
1657 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'O', constraint))
1658 result = 1;
1659 break;
1660 case 'P':
1661 if (GET_CODE (op) == CONST_INT
1662 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'P', constraint))
1663 result = 1;
1664 break;
1666 case 'X':
1667 result = 1;
1668 break;
1670 case 'g':
1671 if (general_operand (op, VOIDmode))
1672 result = 1;
1673 break;
1675 default:
1676 /* For all other letters, we first check for a register class,
1677 otherwise it is an EXTRA_CONSTRAINT. */
1678 if (REG_CLASS_FROM_CONSTRAINT (c, constraint) != NO_REGS)
1680 case 'r':
1681 if (GET_MODE (op) == BLKmode)
1682 break;
1683 if (register_operand (op, VOIDmode))
1684 result = 1;
1686 #ifdef EXTRA_CONSTRAINT_STR
1687 else if (EXTRA_CONSTRAINT_STR (op, c, constraint))
1688 result = 1;
1689 else if (EXTRA_MEMORY_CONSTRAINT (c, constraint)
1690 /* Every memory operand can be reloaded to fit. */
1691 && memory_operand (op, VOIDmode))
1692 result = 1;
1693 else if (EXTRA_ADDRESS_CONSTRAINT (c, constraint)
1694 /* Every address operand can be reloaded to fit. */
1695 && address_operand (op, VOIDmode))
1696 result = 1;
1697 #endif
1698 break;
1700 len = CONSTRAINT_LEN (c, constraint);
1702 constraint++;
1703 while (--len && *constraint);
1704 if (len)
1705 return 0;
1708 return result;
1711 /* Given an rtx *P, if it is a sum containing an integer constant term,
1712 return the location (type rtx *) of the pointer to that constant term.
1713 Otherwise, return a null pointer. */
1715 rtx *
1716 find_constant_term_loc (rtx *p)
1718 rtx *tem;
1719 enum rtx_code code = GET_CODE (*p);
1721 /* If *P IS such a constant term, P is its location. */
1723 if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1724 || code == CONST)
1725 return p;
1727 /* Otherwise, if not a sum, it has no constant term. */
1729 if (GET_CODE (*p) != PLUS)
1730 return 0;
1732 /* If one of the summands is constant, return its location. */
1734 if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1735 && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1736 return p;
1738 /* Otherwise, check each summand for containing a constant term. */
1740 if (XEXP (*p, 0) != 0)
1742 tem = find_constant_term_loc (&XEXP (*p, 0));
1743 if (tem != 0)
1744 return tem;
1747 if (XEXP (*p, 1) != 0)
1749 tem = find_constant_term_loc (&XEXP (*p, 1));
1750 if (tem != 0)
1751 return tem;
1754 return 0;
1757 /* Return 1 if OP is a memory reference
1758 whose address contains no side effects
1759 and remains valid after the addition
1760 of a positive integer less than the
1761 size of the object being referenced.
1763 We assume that the original address is valid and do not check it.
1765 This uses strict_memory_address_p as a subroutine, so
1766 don't use it before reload. */
1769 offsettable_memref_p (rtx op)
1771 return ((MEM_P (op))
1772 && offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
1775 /* Similar, but don't require a strictly valid mem ref:
1776 consider pseudo-regs valid as index or base regs. */
1779 offsettable_nonstrict_memref_p (rtx op)
1781 return ((MEM_P (op))
1782 && offsettable_address_p (0, GET_MODE (op), XEXP (op, 0)));
1785 /* Return 1 if Y is a memory address which contains no side effects
1786 and would remain valid after the addition of a positive integer
1787 less than the size of that mode.
1789 We assume that the original address is valid and do not check it.
1790 We do check that it is valid for narrower modes.
1792 If STRICTP is nonzero, we require a strictly valid address,
1793 for the sake of use in reload.c. */
1796 offsettable_address_p (int strictp, enum machine_mode mode, rtx y)
1798 enum rtx_code ycode = GET_CODE (y);
1799 rtx z;
1800 rtx y1 = y;
1801 rtx *y2;
1802 int (*addressp) (enum machine_mode, rtx) =
1803 (strictp ? strict_memory_address_p : memory_address_p);
1804 unsigned int mode_sz = GET_MODE_SIZE (mode);
1806 if (CONSTANT_ADDRESS_P (y))
1807 return 1;
1809 /* Adjusting an offsettable address involves changing to a narrower mode.
1810 Make sure that's OK. */
1812 if (mode_dependent_address_p (y))
1813 return 0;
1815 /* ??? How much offset does an offsettable BLKmode reference need?
1816 Clearly that depends on the situation in which it's being used.
1817 However, the current situation in which we test 0xffffffff is
1818 less than ideal. Caveat user. */
1819 if (mode_sz == 0)
1820 mode_sz = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
1822 /* If the expression contains a constant term,
1823 see if it remains valid when max possible offset is added. */
1825 if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
1827 int good;
1829 y1 = *y2;
1830 *y2 = plus_constant (*y2, mode_sz - 1);
1831 /* Use QImode because an odd displacement may be automatically invalid
1832 for any wider mode. But it should be valid for a single byte. */
1833 good = (*addressp) (QImode, y);
1835 /* In any case, restore old contents of memory. */
1836 *y2 = y1;
1837 return good;
1840 if (GET_RTX_CLASS (ycode) == RTX_AUTOINC)
1841 return 0;
1843 /* The offset added here is chosen as the maximum offset that
1844 any instruction could need to add when operating on something
1845 of the specified mode. We assume that if Y and Y+c are
1846 valid addresses then so is Y+d for all 0<d<c. adjust_address will
1847 go inside a LO_SUM here, so we do so as well. */
1848 if (GET_CODE (y) == LO_SUM
1849 && mode != BLKmode
1850 && mode_sz <= GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT)
1851 z = gen_rtx_LO_SUM (GET_MODE (y), XEXP (y, 0),
1852 plus_constant (XEXP (y, 1), mode_sz - 1));
1853 else
1854 z = plus_constant (y, mode_sz - 1);
1856 /* Use QImode because an odd displacement may be automatically invalid
1857 for any wider mode. But it should be valid for a single byte. */
1858 return (*addressp) (QImode, z);
1861 /* Return 1 if ADDR is an address-expression whose effect depends
1862 on the mode of the memory reference it is used in.
1864 Autoincrement addressing is a typical example of mode-dependence
1865 because the amount of the increment depends on the mode. */
1868 mode_dependent_address_p (rtx addr)
1870 /* Auto-increment addressing with anything other than post_modify
1871 or pre_modify always introduces a mode dependency. Catch such
1872 cases now instead of deferring to the target. */
1873 if (GET_CODE (addr) == PRE_INC
1874 || GET_CODE (addr) == POST_INC
1875 || GET_CODE (addr) == PRE_DEC
1876 || GET_CODE (addr) == POST_DEC)
1877 return 1;
1879 GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
1880 return 0;
1881 /* Label `win' might (not) be used via GO_IF_MODE_DEPENDENT_ADDRESS. */
1882 win: ATTRIBUTE_UNUSED_LABEL
1883 return 1;
1886 /* Like extract_insn, but save insn extracted and don't extract again, when
1887 called again for the same insn expecting that recog_data still contain the
1888 valid information. This is used primary by gen_attr infrastructure that
1889 often does extract insn again and again. */
1890 void
1891 extract_insn_cached (rtx insn)
1893 if (recog_data.insn == insn && INSN_CODE (insn) >= 0)
1894 return;
1895 extract_insn (insn);
1896 recog_data.insn = insn;
1899 /* Do cached extract_insn, constrain_operands and complain about failures.
1900 Used by insn_attrtab. */
1901 void
1902 extract_constrain_insn_cached (rtx insn)
1904 extract_insn_cached (insn);
1905 if (which_alternative == -1
1906 && !constrain_operands (reload_completed))
1907 fatal_insn_not_found (insn);
1910 /* Do cached constrain_operands and complain about failures. */
1912 constrain_operands_cached (int strict)
1914 if (which_alternative == -1)
1915 return constrain_operands (strict);
1916 else
1917 return 1;
1920 /* Analyze INSN and fill in recog_data. */
1922 void
1923 extract_insn (rtx insn)
1925 int i;
1926 int icode;
1927 int noperands;
1928 rtx body = PATTERN (insn);
1930 recog_data.insn = NULL;
1931 recog_data.n_operands = 0;
1932 recog_data.n_alternatives = 0;
1933 recog_data.n_dups = 0;
1934 which_alternative = -1;
1936 switch (GET_CODE (body))
1938 case USE:
1939 case CLOBBER:
1940 case ASM_INPUT:
1941 case ADDR_VEC:
1942 case ADDR_DIFF_VEC:
1943 return;
1945 case SET:
1946 if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1947 goto asm_insn;
1948 else
1949 goto normal_insn;
1950 case PARALLEL:
1951 if ((GET_CODE (XVECEXP (body, 0, 0)) == SET
1952 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1953 || GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1954 goto asm_insn;
1955 else
1956 goto normal_insn;
1957 case ASM_OPERANDS:
1958 asm_insn:
1959 recog_data.n_operands = noperands = asm_noperands (body);
1960 if (noperands >= 0)
1962 /* This insn is an `asm' with operands. */
1964 /* expand_asm_operands makes sure there aren't too many operands. */
1965 gcc_assert (noperands <= MAX_RECOG_OPERANDS);
1967 /* Now get the operand values and constraints out of the insn. */
1968 decode_asm_operands (body, recog_data.operand,
1969 recog_data.operand_loc,
1970 recog_data.constraints,
1971 recog_data.operand_mode, NULL);
1972 if (noperands > 0)
1974 const char *p = recog_data.constraints[0];
1975 recog_data.n_alternatives = 1;
1976 while (*p)
1977 recog_data.n_alternatives += (*p++ == ',');
1979 break;
1981 fatal_insn_not_found (insn);
1983 default:
1984 normal_insn:
1985 /* Ordinary insn: recognize it, get the operands via insn_extract
1986 and get the constraints. */
1988 icode = recog_memoized (insn);
1989 if (icode < 0)
1990 fatal_insn_not_found (insn);
1992 recog_data.n_operands = noperands = insn_data[icode].n_operands;
1993 recog_data.n_alternatives = insn_data[icode].n_alternatives;
1994 recog_data.n_dups = insn_data[icode].n_dups;
1996 insn_extract (insn);
1998 for (i = 0; i < noperands; i++)
2000 recog_data.constraints[i] = insn_data[icode].operand[i].constraint;
2001 recog_data.operand_mode[i] = insn_data[icode].operand[i].mode;
2002 /* VOIDmode match_operands gets mode from their real operand. */
2003 if (recog_data.operand_mode[i] == VOIDmode)
2004 recog_data.operand_mode[i] = GET_MODE (recog_data.operand[i]);
2007 for (i = 0; i < noperands; i++)
2008 recog_data.operand_type[i]
2009 = (recog_data.constraints[i][0] == '=' ? OP_OUT
2010 : recog_data.constraints[i][0] == '+' ? OP_INOUT
2011 : OP_IN);
2013 gcc_assert (recog_data.n_alternatives <= MAX_RECOG_ALTERNATIVES);
2016 /* After calling extract_insn, you can use this function to extract some
2017 information from the constraint strings into a more usable form.
2018 The collected data is stored in recog_op_alt. */
2019 void
2020 preprocess_constraints (void)
2022 int i;
2024 for (i = 0; i < recog_data.n_operands; i++)
2025 memset (recog_op_alt[i], 0, (recog_data.n_alternatives
2026 * sizeof (struct operand_alternative)));
2028 for (i = 0; i < recog_data.n_operands; i++)
2030 int j;
2031 struct operand_alternative *op_alt;
2032 const char *p = recog_data.constraints[i];
2034 op_alt = recog_op_alt[i];
2036 for (j = 0; j < recog_data.n_alternatives; j++)
2038 op_alt[j].cl = NO_REGS;
2039 op_alt[j].constraint = p;
2040 op_alt[j].matches = -1;
2041 op_alt[j].matched = -1;
2043 if (*p == '\0' || *p == ',')
2045 op_alt[j].anything_ok = 1;
2046 continue;
2049 for (;;)
2051 char c = *p;
2052 if (c == '#')
2054 c = *++p;
2055 while (c != ',' && c != '\0');
2056 if (c == ',' || c == '\0')
2058 p++;
2059 break;
2062 switch (c)
2064 case '=': case '+': case '*': case '%':
2065 case 'E': case 'F': case 'G': case 'H':
2066 case 's': case 'i': case 'n':
2067 case 'I': case 'J': case 'K': case 'L':
2068 case 'M': case 'N': case 'O': case 'P':
2069 /* These don't say anything we care about. */
2070 break;
2072 case '?':
2073 op_alt[j].reject += 6;
2074 break;
2075 case '!':
2076 op_alt[j].reject += 600;
2077 break;
2078 case '&':
2079 op_alt[j].earlyclobber = 1;
2080 break;
2082 case '0': case '1': case '2': case '3': case '4':
2083 case '5': case '6': case '7': case '8': case '9':
2085 char *end;
2086 op_alt[j].matches = strtoul (p, &end, 10);
2087 recog_op_alt[op_alt[j].matches][j].matched = i;
2088 p = end;
2090 continue;
2092 case 'm':
2093 op_alt[j].memory_ok = 1;
2094 break;
2095 case '<':
2096 op_alt[j].decmem_ok = 1;
2097 break;
2098 case '>':
2099 op_alt[j].incmem_ok = 1;
2100 break;
2101 case 'V':
2102 op_alt[j].nonoffmem_ok = 1;
2103 break;
2104 case 'o':
2105 op_alt[j].offmem_ok = 1;
2106 break;
2107 case 'X':
2108 op_alt[j].anything_ok = 1;
2109 break;
2111 case 'p':
2112 op_alt[j].is_address = 1;
2113 op_alt[j].cl = reg_class_subunion[(int) op_alt[j].cl]
2114 [(int) base_reg_class (VOIDmode, ADDRESS, SCRATCH)];
2115 break;
2117 case 'g':
2118 case 'r':
2119 op_alt[j].cl =
2120 reg_class_subunion[(int) op_alt[j].cl][(int) GENERAL_REGS];
2121 break;
2123 default:
2124 if (EXTRA_MEMORY_CONSTRAINT (c, p))
2126 op_alt[j].memory_ok = 1;
2127 break;
2129 if (EXTRA_ADDRESS_CONSTRAINT (c, p))
2131 op_alt[j].is_address = 1;
2132 op_alt[j].cl
2133 = (reg_class_subunion
2134 [(int) op_alt[j].cl]
2135 [(int) base_reg_class (VOIDmode, ADDRESS,
2136 SCRATCH)]);
2137 break;
2140 op_alt[j].cl
2141 = (reg_class_subunion
2142 [(int) op_alt[j].cl]
2143 [(int) REG_CLASS_FROM_CONSTRAINT ((unsigned char) c, p)]);
2144 break;
2146 p += CONSTRAINT_LEN (c, p);
2152 /* Check the operands of an insn against the insn's operand constraints
2153 and return 1 if they are valid.
2154 The information about the insn's operands, constraints, operand modes
2155 etc. is obtained from the global variables set up by extract_insn.
2157 WHICH_ALTERNATIVE is set to a number which indicates which
2158 alternative of constraints was matched: 0 for the first alternative,
2159 1 for the next, etc.
2161 In addition, when two operands are required to match
2162 and it happens that the output operand is (reg) while the
2163 input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
2164 make the output operand look like the input.
2165 This is because the output operand is the one the template will print.
2167 This is used in final, just before printing the assembler code and by
2168 the routines that determine an insn's attribute.
2170 If STRICT is a positive nonzero value, it means that we have been
2171 called after reload has been completed. In that case, we must
2172 do all checks strictly. If it is zero, it means that we have been called
2173 before reload has completed. In that case, we first try to see if we can
2174 find an alternative that matches strictly. If not, we try again, this
2175 time assuming that reload will fix up the insn. This provides a "best
2176 guess" for the alternative and is used to compute attributes of insns prior
2177 to reload. A negative value of STRICT is used for this internal call. */
2179 struct funny_match
2181 int this, other;
2185 constrain_operands (int strict)
2187 const char *constraints[MAX_RECOG_OPERANDS];
2188 int matching_operands[MAX_RECOG_OPERANDS];
2189 int earlyclobber[MAX_RECOG_OPERANDS];
2190 int c;
2192 struct funny_match funny_match[MAX_RECOG_OPERANDS];
2193 int funny_match_index;
2195 which_alternative = 0;
2196 if (recog_data.n_operands == 0 || recog_data.n_alternatives == 0)
2197 return 1;
2199 for (c = 0; c < recog_data.n_operands; c++)
2201 constraints[c] = recog_data.constraints[c];
2202 matching_operands[c] = -1;
2207 int seen_earlyclobber_at = -1;
2208 int opno;
2209 int lose = 0;
2210 funny_match_index = 0;
2212 for (opno = 0; opno < recog_data.n_operands; opno++)
2214 rtx op = recog_data.operand[opno];
2215 enum machine_mode mode = GET_MODE (op);
2216 const char *p = constraints[opno];
2217 int offset = 0;
2218 int win = 0;
2219 int val;
2220 int len;
2222 earlyclobber[opno] = 0;
2224 /* A unary operator may be accepted by the predicate, but it
2225 is irrelevant for matching constraints. */
2226 if (UNARY_P (op))
2227 op = XEXP (op, 0);
2229 if (GET_CODE (op) == SUBREG)
2231 if (REG_P (SUBREG_REG (op))
2232 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
2233 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
2234 GET_MODE (SUBREG_REG (op)),
2235 SUBREG_BYTE (op),
2236 GET_MODE (op));
2237 op = SUBREG_REG (op);
2240 /* An empty constraint or empty alternative
2241 allows anything which matched the pattern. */
2242 if (*p == 0 || *p == ',')
2243 win = 1;
2246 switch (c = *p, len = CONSTRAINT_LEN (c, p), c)
2248 case '\0':
2249 len = 0;
2250 break;
2251 case ',':
2252 c = '\0';
2253 break;
2255 case '?': case '!': case '*': case '%':
2256 case '=': case '+':
2257 break;
2259 case '#':
2260 /* Ignore rest of this alternative as far as
2261 constraint checking is concerned. */
2263 p++;
2264 while (*p && *p != ',');
2265 len = 0;
2266 break;
2268 case '&':
2269 earlyclobber[opno] = 1;
2270 if (seen_earlyclobber_at < 0)
2271 seen_earlyclobber_at = opno;
2272 break;
2274 case '0': case '1': case '2': case '3': case '4':
2275 case '5': case '6': case '7': case '8': case '9':
2277 /* This operand must be the same as a previous one.
2278 This kind of constraint is used for instructions such
2279 as add when they take only two operands.
2281 Note that the lower-numbered operand is passed first.
2283 If we are not testing strictly, assume that this
2284 constraint will be satisfied. */
2286 char *end;
2287 int match;
2289 match = strtoul (p, &end, 10);
2290 p = end;
2292 if (strict < 0)
2293 val = 1;
2294 else
2296 rtx op1 = recog_data.operand[match];
2297 rtx op2 = recog_data.operand[opno];
2299 /* A unary operator may be accepted by the predicate,
2300 but it is irrelevant for matching constraints. */
2301 if (UNARY_P (op1))
2302 op1 = XEXP (op1, 0);
2303 if (UNARY_P (op2))
2304 op2 = XEXP (op2, 0);
2306 val = operands_match_p (op1, op2);
2309 matching_operands[opno] = match;
2310 matching_operands[match] = opno;
2312 if (val != 0)
2313 win = 1;
2315 /* If output is *x and input is *--x, arrange later
2316 to change the output to *--x as well, since the
2317 output op is the one that will be printed. */
2318 if (val == 2 && strict > 0)
2320 funny_match[funny_match_index].this = opno;
2321 funny_match[funny_match_index++].other = match;
2324 len = 0;
2325 break;
2327 case 'p':
2328 /* p is used for address_operands. When we are called by
2329 gen_reload, no one will have checked that the address is
2330 strictly valid, i.e., that all pseudos requiring hard regs
2331 have gotten them. */
2332 if (strict <= 0
2333 || (strict_memory_address_p (recog_data.operand_mode[opno],
2334 op)))
2335 win = 1;
2336 break;
2338 /* No need to check general_operand again;
2339 it was done in insn-recog.c. Well, except that reload
2340 doesn't check the validity of its replacements, but
2341 that should only matter when there's a bug. */
2342 case 'g':
2343 /* Anything goes unless it is a REG and really has a hard reg
2344 but the hard reg is not in the class GENERAL_REGS. */
2345 if (REG_P (op))
2347 if (strict < 0
2348 || GENERAL_REGS == ALL_REGS
2349 || (reload_in_progress
2350 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2351 || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
2352 win = 1;
2354 else if (strict < 0 || general_operand (op, mode))
2355 win = 1;
2356 break;
2358 case 'X':
2359 /* This is used for a MATCH_SCRATCH in the cases when
2360 we don't actually need anything. So anything goes
2361 any time. */
2362 win = 1;
2363 break;
2365 case 'm':
2366 /* Memory operands must be valid, to the extent
2367 required by STRICT. */
2368 if (MEM_P (op))
2370 if (strict > 0
2371 && !strict_memory_address_p (GET_MODE (op),
2372 XEXP (op, 0)))
2373 break;
2374 if (strict == 0
2375 && !memory_address_p (GET_MODE (op), XEXP (op, 0)))
2376 break;
2377 win = 1;
2379 /* Before reload, accept what reload can turn into mem. */
2380 else if (strict < 0 && CONSTANT_P (op))
2381 win = 1;
2382 /* During reload, accept a pseudo */
2383 else if (reload_in_progress && REG_P (op)
2384 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2385 win = 1;
2386 break;
2388 case '<':
2389 if (MEM_P (op)
2390 && (GET_CODE (XEXP (op, 0)) == PRE_DEC
2391 || GET_CODE (XEXP (op, 0)) == POST_DEC))
2392 win = 1;
2393 break;
2395 case '>':
2396 if (MEM_P (op)
2397 && (GET_CODE (XEXP (op, 0)) == PRE_INC
2398 || GET_CODE (XEXP (op, 0)) == POST_INC))
2399 win = 1;
2400 break;
2402 case 'E':
2403 case 'F':
2404 if (GET_CODE (op) == CONST_DOUBLE
2405 || (GET_CODE (op) == CONST_VECTOR
2406 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
2407 win = 1;
2408 break;
2410 case 'G':
2411 case 'H':
2412 if (GET_CODE (op) == CONST_DOUBLE
2413 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, p))
2414 win = 1;
2415 break;
2417 case 's':
2418 if (GET_CODE (op) == CONST_INT
2419 || (GET_CODE (op) == CONST_DOUBLE
2420 && GET_MODE (op) == VOIDmode))
2421 break;
2422 case 'i':
2423 if (CONSTANT_P (op))
2424 win = 1;
2425 break;
2427 case 'n':
2428 if (GET_CODE (op) == CONST_INT
2429 || (GET_CODE (op) == CONST_DOUBLE
2430 && GET_MODE (op) == VOIDmode))
2431 win = 1;
2432 break;
2434 case 'I':
2435 case 'J':
2436 case 'K':
2437 case 'L':
2438 case 'M':
2439 case 'N':
2440 case 'O':
2441 case 'P':
2442 if (GET_CODE (op) == CONST_INT
2443 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, p))
2444 win = 1;
2445 break;
2447 case 'V':
2448 if (MEM_P (op)
2449 && ((strict > 0 && ! offsettable_memref_p (op))
2450 || (strict < 0
2451 && !(CONSTANT_P (op) || MEM_P (op)))
2452 || (reload_in_progress
2453 && !(REG_P (op)
2454 && REGNO (op) >= FIRST_PSEUDO_REGISTER))))
2455 win = 1;
2456 break;
2458 case 'o':
2459 if ((strict > 0 && offsettable_memref_p (op))
2460 || (strict == 0 && offsettable_nonstrict_memref_p (op))
2461 /* Before reload, accept what reload can handle. */
2462 || (strict < 0
2463 && (CONSTANT_P (op) || MEM_P (op)))
2464 /* During reload, accept a pseudo */
2465 || (reload_in_progress && REG_P (op)
2466 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2467 win = 1;
2468 break;
2470 default:
2472 enum reg_class cl;
2474 cl = (c == 'r'
2475 ? GENERAL_REGS : REG_CLASS_FROM_CONSTRAINT (c, p));
2476 if (cl != NO_REGS)
2478 if (strict < 0
2479 || (strict == 0
2480 && REG_P (op)
2481 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2482 || (strict == 0 && GET_CODE (op) == SCRATCH)
2483 || (REG_P (op)
2484 && reg_fits_class_p (op, cl, offset, mode)))
2485 win = 1;
2487 #ifdef EXTRA_CONSTRAINT_STR
2488 else if (EXTRA_CONSTRAINT_STR (op, c, p))
2489 win = 1;
2491 else if (EXTRA_MEMORY_CONSTRAINT (c, p)
2492 /* Every memory operand can be reloaded to fit. */
2493 && ((strict < 0 && MEM_P (op))
2494 /* Before reload, accept what reload can turn
2495 into mem. */
2496 || (strict < 0 && CONSTANT_P (op))
2497 /* During reload, accept a pseudo */
2498 || (reload_in_progress && REG_P (op)
2499 && REGNO (op) >= FIRST_PSEUDO_REGISTER)))
2500 win = 1;
2501 else if (EXTRA_ADDRESS_CONSTRAINT (c, p)
2502 /* Every address operand can be reloaded to fit. */
2503 && strict < 0)
2504 win = 1;
2505 #endif
2506 break;
2509 while (p += len, c);
2511 constraints[opno] = p;
2512 /* If this operand did not win somehow,
2513 this alternative loses. */
2514 if (! win)
2515 lose = 1;
2517 /* This alternative won; the operands are ok.
2518 Change whichever operands this alternative says to change. */
2519 if (! lose)
2521 int opno, eopno;
2523 /* See if any earlyclobber operand conflicts with some other
2524 operand. */
2526 if (strict > 0 && seen_earlyclobber_at >= 0)
2527 for (eopno = seen_earlyclobber_at;
2528 eopno < recog_data.n_operands;
2529 eopno++)
2530 /* Ignore earlyclobber operands now in memory,
2531 because we would often report failure when we have
2532 two memory operands, one of which was formerly a REG. */
2533 if (earlyclobber[eopno]
2534 && REG_P (recog_data.operand[eopno]))
2535 for (opno = 0; opno < recog_data.n_operands; opno++)
2536 if ((MEM_P (recog_data.operand[opno])
2537 || recog_data.operand_type[opno] != OP_OUT)
2538 && opno != eopno
2539 /* Ignore things like match_operator operands. */
2540 && *recog_data.constraints[opno] != 0
2541 && ! (matching_operands[opno] == eopno
2542 && operands_match_p (recog_data.operand[opno],
2543 recog_data.operand[eopno]))
2544 && ! safe_from_earlyclobber (recog_data.operand[opno],
2545 recog_data.operand[eopno]))
2546 lose = 1;
2548 if (! lose)
2550 while (--funny_match_index >= 0)
2552 recog_data.operand[funny_match[funny_match_index].other]
2553 = recog_data.operand[funny_match[funny_match_index].this];
2556 return 1;
2560 which_alternative++;
2562 while (which_alternative < recog_data.n_alternatives);
2564 which_alternative = -1;
2565 /* If we are about to reject this, but we are not to test strictly,
2566 try a very loose test. Only return failure if it fails also. */
2567 if (strict == 0)
2568 return constrain_operands (-1);
2569 else
2570 return 0;
2573 /* Return 1 iff OPERAND (assumed to be a REG rtx)
2574 is a hard reg in class CLASS when its regno is offset by OFFSET
2575 and changed to mode MODE.
2576 If REG occupies multiple hard regs, all of them must be in CLASS. */
2579 reg_fits_class_p (rtx operand, enum reg_class cl, int offset,
2580 enum machine_mode mode)
2582 int regno = REGNO (operand);
2584 if (cl == NO_REGS)
2585 return 0;
2587 return (regno < FIRST_PSEUDO_REGISTER
2588 && in_hard_reg_set_p (reg_class_contents[(int) cl],
2589 mode, regno + offset));
2592 /* Split single instruction. Helper function for split_all_insns and
2593 split_all_insns_noflow. Return last insn in the sequence if successful,
2594 or NULL if unsuccessful. */
2596 static rtx
2597 split_insn (rtx insn)
2599 /* Split insns here to get max fine-grain parallelism. */
2600 rtx first = PREV_INSN (insn);
2601 rtx last = try_split (PATTERN (insn), insn, 1);
2603 if (last == insn)
2604 return NULL_RTX;
2606 /* try_split returns the NOTE that INSN became. */
2607 SET_INSN_DELETED (insn);
2609 /* ??? Coddle to md files that generate subregs in post-reload
2610 splitters instead of computing the proper hard register. */
2611 if (reload_completed && first != last)
2613 first = NEXT_INSN (first);
2614 for (;;)
2616 if (INSN_P (first))
2617 cleanup_subreg_operands (first);
2618 if (first == last)
2619 break;
2620 first = NEXT_INSN (first);
2623 return last;
2626 /* Split all insns in the function. If UPD_LIFE, update life info after. */
2628 void
2629 split_all_insns (void)
2631 sbitmap blocks;
2632 bool changed;
2633 basic_block bb;
2635 blocks = sbitmap_alloc (last_basic_block);
2636 sbitmap_zero (blocks);
2637 changed = false;
2639 FOR_EACH_BB_REVERSE (bb)
2641 rtx insn, next;
2642 bool finish = false;
2644 for (insn = BB_HEAD (bb); !finish ; insn = next)
2646 /* Can't use `next_real_insn' because that might go across
2647 CODE_LABELS and short-out basic blocks. */
2648 next = NEXT_INSN (insn);
2649 finish = (insn == BB_END (bb));
2650 if (INSN_P (insn))
2652 rtx set = single_set (insn);
2654 /* Don't split no-op move insns. These should silently
2655 disappear later in final. Splitting such insns would
2656 break the code that handles REG_NO_CONFLICT blocks. */
2657 if (set && set_noop_p (set))
2659 /* Nops get in the way while scheduling, so delete them
2660 now if register allocation has already been done. It
2661 is too risky to try to do this before register
2662 allocation, and there are unlikely to be very many
2663 nops then anyways. */
2664 if (reload_completed)
2665 delete_insn_and_edges (insn);
2667 else
2669 rtx last = split_insn (insn);
2670 if (last)
2672 /* The split sequence may include barrier, but the
2673 BB boundary we are interested in will be set to
2674 previous one. */
2676 while (BARRIER_P (last))
2677 last = PREV_INSN (last);
2678 SET_BIT (blocks, bb->index);
2679 changed = true;
2686 if (changed)
2687 find_many_sub_basic_blocks (blocks);
2689 #ifdef ENABLE_CHECKING
2690 verify_flow_info ();
2691 #endif
2693 sbitmap_free (blocks);
2696 /* Same as split_all_insns, but do not expect CFG to be available.
2697 Used by machine dependent reorg passes. */
2699 unsigned int
2700 split_all_insns_noflow (void)
2702 rtx next, insn;
2704 for (insn = get_insns (); insn; insn = next)
2706 next = NEXT_INSN (insn);
2707 if (INSN_P (insn))
2709 /* Don't split no-op move insns. These should silently
2710 disappear later in final. Splitting such insns would
2711 break the code that handles REG_NO_CONFLICT blocks. */
2712 rtx set = single_set (insn);
2713 if (set && set_noop_p (set))
2715 /* Nops get in the way while scheduling, so delete them
2716 now if register allocation has already been done. It
2717 is too risky to try to do this before register
2718 allocation, and there are unlikely to be very many
2719 nops then anyways.
2721 ??? Should we use delete_insn when the CFG isn't valid? */
2722 if (reload_completed)
2723 delete_insn_and_edges (insn);
2725 else
2726 split_insn (insn);
2729 return 0;
2732 #ifdef HAVE_peephole2
2733 struct peep2_insn_data
2735 rtx insn;
2736 regset live_before;
2739 static struct peep2_insn_data peep2_insn_data[MAX_INSNS_PER_PEEP2 + 1];
2740 static int peep2_current;
2741 /* The number of instructions available to match a peep2. */
2742 int peep2_current_count;
2744 /* A non-insn marker indicating the last insn of the block.
2745 The live_before regset for this element is correct, indicating
2746 DF_LIVE_OUT for the block. */
2747 #define PEEP2_EOB pc_rtx
2749 /* Return the Nth non-note insn after `current', or return NULL_RTX if it
2750 does not exist. Used by the recognizer to find the next insn to match
2751 in a multi-insn pattern. */
2754 peep2_next_insn (int n)
2756 gcc_assert (n <= peep2_current_count);
2758 n += peep2_current;
2759 if (n >= MAX_INSNS_PER_PEEP2 + 1)
2760 n -= MAX_INSNS_PER_PEEP2 + 1;
2762 return peep2_insn_data[n].insn;
2765 /* Return true if REGNO is dead before the Nth non-note insn
2766 after `current'. */
2769 peep2_regno_dead_p (int ofs, int regno)
2771 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
2773 ofs += peep2_current;
2774 if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2775 ofs -= MAX_INSNS_PER_PEEP2 + 1;
2777 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
2779 return ! REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno);
2782 /* Similarly for a REG. */
2785 peep2_reg_dead_p (int ofs, rtx reg)
2787 int regno, n;
2789 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
2791 ofs += peep2_current;
2792 if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2793 ofs -= MAX_INSNS_PER_PEEP2 + 1;
2795 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
2797 regno = REGNO (reg);
2798 n = hard_regno_nregs[regno][GET_MODE (reg)];
2799 while (--n >= 0)
2800 if (REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno + n))
2801 return 0;
2802 return 1;
2805 /* Try to find a hard register of mode MODE, matching the register class in
2806 CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
2807 remains available until the end of LAST_INSN. LAST_INSN may be NULL_RTX,
2808 in which case the only condition is that the register must be available
2809 before CURRENT_INSN.
2810 Registers that already have bits set in REG_SET will not be considered.
2812 If an appropriate register is available, it will be returned and the
2813 corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
2814 returned. */
2817 peep2_find_free_register (int from, int to, const char *class_str,
2818 enum machine_mode mode, HARD_REG_SET *reg_set)
2820 static int search_ofs;
2821 enum reg_class cl;
2822 HARD_REG_SET live;
2823 int i;
2825 gcc_assert (from < MAX_INSNS_PER_PEEP2 + 1);
2826 gcc_assert (to < MAX_INSNS_PER_PEEP2 + 1);
2828 from += peep2_current;
2829 if (from >= MAX_INSNS_PER_PEEP2 + 1)
2830 from -= MAX_INSNS_PER_PEEP2 + 1;
2831 to += peep2_current;
2832 if (to >= MAX_INSNS_PER_PEEP2 + 1)
2833 to -= MAX_INSNS_PER_PEEP2 + 1;
2835 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
2836 REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before);
2838 while (from != to)
2840 HARD_REG_SET this_live;
2842 if (++from >= MAX_INSNS_PER_PEEP2 + 1)
2843 from = 0;
2844 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
2845 REG_SET_TO_HARD_REG_SET (this_live, peep2_insn_data[from].live_before);
2846 IOR_HARD_REG_SET (live, this_live);
2849 cl = (class_str[0] == 'r' ? GENERAL_REGS
2850 : REG_CLASS_FROM_CONSTRAINT (class_str[0], class_str));
2852 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2854 int raw_regno, regno, success, j;
2856 /* Distribute the free registers as much as possible. */
2857 raw_regno = search_ofs + i;
2858 if (raw_regno >= FIRST_PSEUDO_REGISTER)
2859 raw_regno -= FIRST_PSEUDO_REGISTER;
2860 #ifdef REG_ALLOC_ORDER
2861 regno = reg_alloc_order[raw_regno];
2862 #else
2863 regno = raw_regno;
2864 #endif
2866 /* Don't allocate fixed registers. */
2867 if (fixed_regs[regno])
2868 continue;
2869 /* Make sure the register is of the right class. */
2870 if (! TEST_HARD_REG_BIT (reg_class_contents[cl], regno))
2871 continue;
2872 /* And can support the mode we need. */
2873 if (! HARD_REGNO_MODE_OK (regno, mode))
2874 continue;
2875 /* And that we don't create an extra save/restore. */
2876 if (! call_used_regs[regno] && ! df_regs_ever_live_p (regno))
2877 continue;
2878 /* And we don't clobber traceback for noreturn functions. */
2879 if ((regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM)
2880 && (! reload_completed || frame_pointer_needed))
2881 continue;
2883 success = 1;
2884 for (j = hard_regno_nregs[regno][mode] - 1; j >= 0; j--)
2886 if (TEST_HARD_REG_BIT (*reg_set, regno + j)
2887 || TEST_HARD_REG_BIT (live, regno + j))
2889 success = 0;
2890 break;
2893 if (success)
2895 add_to_hard_reg_set (reg_set, mode, regno);
2897 /* Start the next search with the next register. */
2898 if (++raw_regno >= FIRST_PSEUDO_REGISTER)
2899 raw_regno = 0;
2900 search_ofs = raw_regno;
2902 return gen_rtx_REG (mode, regno);
2906 search_ofs = 0;
2907 return NULL_RTX;
2910 /* Perform the peephole2 optimization pass. */
2912 static void
2913 peephole2_optimize (void)
2915 rtx insn, prev;
2916 bitmap live;
2917 int i;
2918 basic_block bb;
2919 bool do_cleanup_cfg = false;
2920 bool do_rebuild_jump_labels = false;
2922 df_set_flags (DF_LR_RUN_DCE);
2923 df_analyze ();
2925 /* Initialize the regsets we're going to use. */
2926 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
2927 peep2_insn_data[i].live_before = BITMAP_ALLOC (&reg_obstack);
2928 live = BITMAP_ALLOC (&reg_obstack);
2930 FOR_EACH_BB_REVERSE (bb)
2932 /* Indicate that all slots except the last holds invalid data. */
2933 for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
2934 peep2_insn_data[i].insn = NULL_RTX;
2935 peep2_current_count = 0;
2937 /* Indicate that the last slot contains live_after data. */
2938 peep2_insn_data[MAX_INSNS_PER_PEEP2].insn = PEEP2_EOB;
2939 peep2_current = MAX_INSNS_PER_PEEP2;
2941 /* Start up propagation. */
2942 bitmap_copy (live, DF_LR_OUT (bb));
2943 df_simulate_artificial_refs_at_end (bb, live);
2944 bitmap_copy (peep2_insn_data[MAX_INSNS_PER_PEEP2].live_before, live);
2946 for (insn = BB_END (bb); ; insn = prev)
2948 prev = PREV_INSN (insn);
2949 if (INSN_P (insn))
2951 rtx try, before_try, x;
2952 int match_len;
2953 rtx note;
2954 bool was_call = false;
2956 /* Record this insn. */
2957 if (--peep2_current < 0)
2958 peep2_current = MAX_INSNS_PER_PEEP2;
2959 if (peep2_current_count < MAX_INSNS_PER_PEEP2
2960 && peep2_insn_data[peep2_current].insn == NULL_RTX)
2961 peep2_current_count++;
2962 peep2_insn_data[peep2_current].insn = insn;
2963 df_simulate_one_insn_backwards (bb, insn, live);
2964 COPY_REG_SET (peep2_insn_data[peep2_current].live_before, live);
2966 if (RTX_FRAME_RELATED_P (insn))
2968 /* If an insn has RTX_FRAME_RELATED_P set, peephole
2969 substitution would lose the
2970 REG_FRAME_RELATED_EXPR that is attached. */
2971 peep2_current_count = 0;
2972 try = NULL;
2974 else
2975 /* Match the peephole. */
2976 try = peephole2_insns (PATTERN (insn), insn, &match_len);
2978 if (try != NULL)
2980 /* If we are splitting a CALL_INSN, look for the CALL_INSN
2981 in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other
2982 cfg-related call notes. */
2983 for (i = 0; i <= match_len; ++i)
2985 int j;
2986 rtx old_insn, new_insn, note;
2988 j = i + peep2_current;
2989 if (j >= MAX_INSNS_PER_PEEP2 + 1)
2990 j -= MAX_INSNS_PER_PEEP2 + 1;
2991 old_insn = peep2_insn_data[j].insn;
2992 if (!CALL_P (old_insn))
2993 continue;
2994 was_call = true;
2996 new_insn = try;
2997 while (new_insn != NULL_RTX)
2999 if (CALL_P (new_insn))
3000 break;
3001 new_insn = NEXT_INSN (new_insn);
3004 gcc_assert (new_insn != NULL_RTX);
3006 CALL_INSN_FUNCTION_USAGE (new_insn)
3007 = CALL_INSN_FUNCTION_USAGE (old_insn);
3009 for (note = REG_NOTES (old_insn);
3010 note;
3011 note = XEXP (note, 1))
3012 switch (REG_NOTE_KIND (note))
3014 case REG_NORETURN:
3015 case REG_SETJMP:
3016 REG_NOTES (new_insn)
3017 = gen_rtx_EXPR_LIST (REG_NOTE_KIND (note),
3018 XEXP (note, 0),
3019 REG_NOTES (new_insn));
3020 default:
3021 /* Discard all other reg notes. */
3022 break;
3025 /* Croak if there is another call in the sequence. */
3026 while (++i <= match_len)
3028 j = i + peep2_current;
3029 if (j >= MAX_INSNS_PER_PEEP2 + 1)
3030 j -= MAX_INSNS_PER_PEEP2 + 1;
3031 old_insn = peep2_insn_data[j].insn;
3032 gcc_assert (!CALL_P (old_insn));
3034 break;
3037 i = match_len + peep2_current;
3038 if (i >= MAX_INSNS_PER_PEEP2 + 1)
3039 i -= MAX_INSNS_PER_PEEP2 + 1;
3041 note = find_reg_note (peep2_insn_data[i].insn,
3042 REG_EH_REGION, NULL_RTX);
3044 /* Replace the old sequence with the new. */
3045 try = emit_insn_after_setloc (try, peep2_insn_data[i].insn,
3046 INSN_LOCATOR (peep2_insn_data[i].insn));
3047 before_try = PREV_INSN (insn);
3048 delete_insn_chain (insn, peep2_insn_data[i].insn, false);
3050 /* Re-insert the EH_REGION notes. */
3051 if (note || (was_call && nonlocal_goto_handler_labels))
3053 edge eh_edge;
3054 edge_iterator ei;
3056 FOR_EACH_EDGE (eh_edge, ei, bb->succs)
3057 if (eh_edge->flags & (EDGE_EH | EDGE_ABNORMAL_CALL))
3058 break;
3060 for (x = try ; x != before_try ; x = PREV_INSN (x))
3061 if (CALL_P (x)
3062 || (flag_non_call_exceptions
3063 && may_trap_p (PATTERN (x))
3064 && !find_reg_note (x, REG_EH_REGION, NULL)))
3066 if (note)
3067 REG_NOTES (x)
3068 = gen_rtx_EXPR_LIST (REG_EH_REGION,
3069 XEXP (note, 0),
3070 REG_NOTES (x));
3072 if (x != BB_END (bb) && eh_edge)
3074 edge nfte, nehe;
3075 int flags;
3077 nfte = split_block (bb, x);
3078 flags = (eh_edge->flags
3079 & (EDGE_EH | EDGE_ABNORMAL));
3080 if (CALL_P (x))
3081 flags |= EDGE_ABNORMAL_CALL;
3082 nehe = make_edge (nfte->src, eh_edge->dest,
3083 flags);
3085 nehe->probability = eh_edge->probability;
3086 nfte->probability
3087 = REG_BR_PROB_BASE - nehe->probability;
3089 do_cleanup_cfg |= purge_dead_edges (nfte->dest);
3090 bb = nfte->src;
3091 eh_edge = nehe;
3095 /* Converting possibly trapping insn to non-trapping is
3096 possible. Zap dummy outgoing edges. */
3097 do_cleanup_cfg |= purge_dead_edges (bb);
3100 #ifdef HAVE_conditional_execution
3101 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3102 peep2_insn_data[i].insn = NULL_RTX;
3103 peep2_insn_data[peep2_current].insn = PEEP2_EOB;
3104 peep2_current_count = 0;
3105 #else
3106 /* Back up lifetime information past the end of the
3107 newly created sequence. */
3108 if (++i >= MAX_INSNS_PER_PEEP2 + 1)
3109 i = 0;
3110 bitmap_copy (live, peep2_insn_data[i].live_before);
3112 /* Update life information for the new sequence. */
3113 x = try;
3116 if (INSN_P (x))
3118 if (--i < 0)
3119 i = MAX_INSNS_PER_PEEP2;
3120 if (peep2_current_count < MAX_INSNS_PER_PEEP2
3121 && peep2_insn_data[i].insn == NULL_RTX)
3122 peep2_current_count++;
3123 peep2_insn_data[i].insn = x;
3124 df_insn_rescan (x);
3125 df_simulate_one_insn_backwards (bb, x, live);
3126 bitmap_copy (peep2_insn_data[i].live_before, live);
3128 x = PREV_INSN (x);
3130 while (x != prev);
3132 peep2_current = i;
3133 #endif
3135 /* If we generated a jump instruction, it won't have
3136 JUMP_LABEL set. Recompute after we're done. */
3137 for (x = try; x != before_try; x = PREV_INSN (x))
3138 if (JUMP_P (x))
3140 do_rebuild_jump_labels = true;
3141 break;
3146 if (insn == BB_HEAD (bb))
3147 break;
3151 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3152 BITMAP_FREE (peep2_insn_data[i].live_before);
3153 BITMAP_FREE (live);
3154 if (do_rebuild_jump_labels)
3155 rebuild_jump_labels (get_insns ());
3157 #endif /* HAVE_peephole2 */
3159 /* Common predicates for use with define_bypass. */
3161 /* True if the dependency between OUT_INSN and IN_INSN is on the store
3162 data not the address operand(s) of the store. IN_INSN and OUT_INSN
3163 must be either a single_set or a PARALLEL with SETs inside. */
3166 store_data_bypass_p (rtx out_insn, rtx in_insn)
3168 rtx out_set, in_set;
3169 rtx out_pat, in_pat;
3170 rtx out_exp, in_exp;
3171 int i, j;
3173 in_set = single_set (in_insn);
3174 if (in_set)
3176 if (!MEM_P (SET_DEST (in_set)))
3177 return false;
3179 out_set = single_set (out_insn);
3180 if (out_set)
3182 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_set)))
3183 return false;
3185 else
3187 out_pat = PATTERN (out_insn);
3189 if (GET_CODE (out_pat) != PARALLEL)
3190 return false;
3192 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3194 out_exp = XVECEXP (out_pat, 0, i);
3196 if (GET_CODE (out_exp) == CLOBBER)
3197 continue;
3199 gcc_assert (GET_CODE (out_exp) == SET);
3201 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_set)))
3202 return false;
3206 else
3208 in_pat = PATTERN (in_insn);
3209 gcc_assert (GET_CODE (in_pat) == PARALLEL);
3211 for (i = 0; i < XVECLEN (in_pat, 0); i++)
3213 in_exp = XVECEXP (in_pat, 0, i);
3215 if (GET_CODE (in_exp) == CLOBBER)
3216 continue;
3218 gcc_assert (GET_CODE (in_exp) == SET);
3220 if (!MEM_P (SET_DEST (in_exp)))
3221 return false;
3223 out_set = single_set (out_insn);
3224 if (out_set)
3226 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_exp)))
3227 return false;
3229 else
3231 out_pat = PATTERN (out_insn);
3232 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3234 for (j = 0; j < XVECLEN (out_pat, 0); j++)
3236 out_exp = XVECEXP (out_pat, 0, j);
3238 if (GET_CODE (out_exp) == CLOBBER)
3239 continue;
3241 gcc_assert (GET_CODE (out_exp) == SET);
3243 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_exp)))
3244 return false;
3250 return true;
3253 /* True if the dependency between OUT_INSN and IN_INSN is in the IF_THEN_ELSE
3254 condition, and not the THEN or ELSE branch. OUT_INSN may be either a single
3255 or multiple set; IN_INSN should be single_set for truth, but for convenience
3256 of insn categorization may be any JUMP or CALL insn. */
3259 if_test_bypass_p (rtx out_insn, rtx in_insn)
3261 rtx out_set, in_set;
3263 in_set = single_set (in_insn);
3264 if (! in_set)
3266 gcc_assert (JUMP_P (in_insn) || CALL_P (in_insn));
3267 return false;
3270 if (GET_CODE (SET_SRC (in_set)) != IF_THEN_ELSE)
3271 return false;
3272 in_set = SET_SRC (in_set);
3274 out_set = single_set (out_insn);
3275 if (out_set)
3277 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3278 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3279 return false;
3281 else
3283 rtx out_pat;
3284 int i;
3286 out_pat = PATTERN (out_insn);
3287 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3289 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3291 rtx exp = XVECEXP (out_pat, 0, i);
3293 if (GET_CODE (exp) == CLOBBER)
3294 continue;
3296 gcc_assert (GET_CODE (exp) == SET);
3298 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3299 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3300 return false;
3304 return true;
3307 static bool
3308 gate_handle_peephole2 (void)
3310 return (optimize > 0 && flag_peephole2);
3313 static unsigned int
3314 rest_of_handle_peephole2 (void)
3316 #ifdef HAVE_peephole2
3317 peephole2_optimize ();
3318 #endif
3319 return 0;
3322 struct tree_opt_pass pass_peephole2 =
3324 "peephole2", /* name */
3325 gate_handle_peephole2, /* gate */
3326 rest_of_handle_peephole2, /* execute */
3327 NULL, /* sub */
3328 NULL, /* next */
3329 0, /* static_pass_number */
3330 TV_PEEPHOLE2, /* tv_id */
3331 0, /* properties_required */
3332 0, /* properties_provided */
3333 0, /* properties_destroyed */
3334 0, /* todo_flags_start */
3335 TODO_df_finish | TODO_verify_rtl_sharing |
3336 TODO_dump_func, /* todo_flags_finish */
3337 'z' /* letter */
3340 static unsigned int
3341 rest_of_handle_split_all_insns (void)
3343 split_all_insns ();
3344 return 0;
3347 struct tree_opt_pass pass_split_all_insns =
3349 "split1", /* name */
3350 NULL, /* gate */
3351 rest_of_handle_split_all_insns, /* execute */
3352 NULL, /* sub */
3353 NULL, /* next */
3354 0, /* static_pass_number */
3355 0, /* tv_id */
3356 0, /* properties_required */
3357 0, /* properties_provided */
3358 0, /* properties_destroyed */
3359 0, /* todo_flags_start */
3360 TODO_dump_func, /* todo_flags_finish */
3361 0 /* letter */
3364 static unsigned int
3365 rest_of_handle_split_after_reload (void)
3367 /* If optimizing, then go ahead and split insns now. */
3368 #ifndef STACK_REGS
3369 if (optimize > 0)
3370 #endif
3371 split_all_insns ();
3372 return 0;
3375 struct tree_opt_pass pass_split_after_reload =
3377 "split2", /* name */
3378 NULL, /* gate */
3379 rest_of_handle_split_after_reload, /* execute */
3380 NULL, /* sub */
3381 NULL, /* next */
3382 0, /* static_pass_number */
3383 0, /* tv_id */
3384 0, /* properties_required */
3385 0, /* properties_provided */
3386 0, /* properties_destroyed */
3387 0, /* todo_flags_start */
3388 TODO_dump_func, /* todo_flags_finish */
3389 0 /* letter */
3392 static bool
3393 gate_handle_split_before_regstack (void)
3395 #if defined (HAVE_ATTR_length) && defined (STACK_REGS)
3396 /* If flow2 creates new instructions which need splitting
3397 and scheduling after reload is not done, they might not be
3398 split until final which doesn't allow splitting
3399 if HAVE_ATTR_length. */
3400 # ifdef INSN_SCHEDULING
3401 return (optimize && !flag_schedule_insns_after_reload);
3402 # else
3403 return (optimize);
3404 # endif
3405 #else
3406 return 0;
3407 #endif
3410 static unsigned int
3411 rest_of_handle_split_before_regstack (void)
3413 split_all_insns ();
3414 return 0;
3417 struct tree_opt_pass pass_split_before_regstack =
3419 "split3", /* name */
3420 gate_handle_split_before_regstack, /* gate */
3421 rest_of_handle_split_before_regstack, /* execute */
3422 NULL, /* sub */
3423 NULL, /* next */
3424 0, /* static_pass_number */
3425 0, /* tv_id */
3426 0, /* properties_required */
3427 0, /* properties_provided */
3428 0, /* properties_destroyed */
3429 0, /* todo_flags_start */
3430 TODO_dump_func, /* todo_flags_finish */
3431 0 /* letter */
3434 static bool
3435 gate_handle_split_before_sched2 (void)
3437 #ifdef INSN_SCHEDULING
3438 return optimize > 0 && flag_schedule_insns_after_reload;
3439 #else
3440 return 0;
3441 #endif
3444 static unsigned int
3445 rest_of_handle_split_before_sched2 (void)
3447 #ifdef INSN_SCHEDULING
3448 split_all_insns ();
3449 #endif
3450 return 0;
3453 struct tree_opt_pass pass_split_before_sched2 =
3455 "split4", /* name */
3456 gate_handle_split_before_sched2, /* gate */
3457 rest_of_handle_split_before_sched2, /* execute */
3458 NULL, /* sub */
3459 NULL, /* next */
3460 0, /* static_pass_number */
3461 0, /* tv_id */
3462 0, /* properties_required */
3463 0, /* properties_provided */
3464 0, /* properties_destroyed */
3465 0, /* todo_flags_start */
3466 TODO_verify_flow |
3467 TODO_dump_func, /* todo_flags_finish */
3468 0 /* letter */
3471 /* The placement of the splitting that we do for shorten_branches
3472 depends on whether regstack is used by the target or not. */
3473 static bool
3474 gate_do_final_split (void)
3476 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3477 return 1;
3478 #else
3479 return 0;
3480 #endif
3483 struct tree_opt_pass pass_split_for_shorten_branches =
3485 "split5", /* name */
3486 gate_do_final_split, /* gate */
3487 split_all_insns_noflow, /* execute */
3488 NULL, /* sub */
3489 NULL, /* next */
3490 0, /* static_pass_number */
3491 0, /* tv_id */
3492 0, /* properties_required */
3493 0, /* properties_provided */
3494 0, /* properties_destroyed */
3495 0, /* todo_flags_start */
3496 TODO_dump_func | TODO_verify_rtl_sharing, /* todo_flags_finish */
3497 0 /* letter */