* intrinsic.c (char_conversions, ncharconv): New static variables.
[official-gcc.git] / gcc / recog.c
blob9ede30f90fd40802b21c3917d199b336ca686ddc
1 /* Subroutines used by or related to instruction recognition.
2 Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "rtl.h"
28 #include "tm_p.h"
29 #include "insn-config.h"
30 #include "insn-attr.h"
31 #include "hard-reg-set.h"
32 #include "recog.h"
33 #include "regs.h"
34 #include "addresses.h"
35 #include "expr.h"
36 #include "function.h"
37 #include "flags.h"
38 #include "real.h"
39 #include "toplev.h"
40 #include "basic-block.h"
41 #include "output.h"
42 #include "reload.h"
43 #include "timevar.h"
44 #include "tree-pass.h"
45 #include "df.h"
47 #ifndef STACK_PUSH_CODE
48 #ifdef STACK_GROWS_DOWNWARD
49 #define STACK_PUSH_CODE PRE_DEC
50 #else
51 #define STACK_PUSH_CODE PRE_INC
52 #endif
53 #endif
55 #ifndef STACK_POP_CODE
56 #ifdef STACK_GROWS_DOWNWARD
57 #define STACK_POP_CODE POST_INC
58 #else
59 #define STACK_POP_CODE POST_DEC
60 #endif
61 #endif
63 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_unshare_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)
1493 *loc = ASM_OPERANDS_SOURCE_LOCATION (asmop);
1495 return ASM_OPERANDS_TEMPLATE (asmop);
1498 /* Check if an asm_operand matches its constraints.
1499 Return > 0 if ok, = 0 if bad, < 0 if inconclusive. */
1502 asm_operand_ok (rtx op, const char *constraint)
1504 int result = 0;
1506 /* Use constrain_operands after reload. */
1507 gcc_assert (!reload_completed);
1509 while (*constraint)
1511 char c = *constraint;
1512 int len;
1513 switch (c)
1515 case ',':
1516 constraint++;
1517 continue;
1518 case '=':
1519 case '+':
1520 case '*':
1521 case '%':
1522 case '!':
1523 case '#':
1524 case '&':
1525 case '?':
1526 break;
1528 case '0': case '1': case '2': case '3': case '4':
1529 case '5': case '6': case '7': case '8': case '9':
1530 /* For best results, our caller should have given us the
1531 proper matching constraint, but we can't actually fail
1532 the check if they didn't. Indicate that results are
1533 inconclusive. */
1535 constraint++;
1536 while (ISDIGIT (*constraint));
1537 if (! result)
1538 result = -1;
1539 continue;
1541 case 'p':
1542 if (address_operand (op, VOIDmode))
1543 result = 1;
1544 break;
1546 case 'm':
1547 case 'V': /* non-offsettable */
1548 if (memory_operand (op, VOIDmode))
1549 result = 1;
1550 break;
1552 case 'o': /* offsettable */
1553 if (offsettable_nonstrict_memref_p (op))
1554 result = 1;
1555 break;
1557 case '<':
1558 /* ??? Before auto-inc-dec, auto inc/dec insns are not supposed to exist,
1559 excepting those that expand_call created. Further, on some
1560 machines which do not have generalized auto inc/dec, an inc/dec
1561 is not a memory_operand.
1563 Match any memory and hope things are resolved after reload. */
1565 if (MEM_P (op)
1566 && (1
1567 || GET_CODE (XEXP (op, 0)) == PRE_DEC
1568 || GET_CODE (XEXP (op, 0)) == POST_DEC))
1569 result = 1;
1570 break;
1572 case '>':
1573 if (MEM_P (op)
1574 && (1
1575 || GET_CODE (XEXP (op, 0)) == PRE_INC
1576 || GET_CODE (XEXP (op, 0)) == POST_INC))
1577 result = 1;
1578 break;
1580 case 'E':
1581 case 'F':
1582 if (GET_CODE (op) == CONST_DOUBLE
1583 || (GET_CODE (op) == CONST_VECTOR
1584 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
1585 result = 1;
1586 break;
1588 case 'G':
1589 if (GET_CODE (op) == CONST_DOUBLE
1590 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'G', constraint))
1591 result = 1;
1592 break;
1593 case 'H':
1594 if (GET_CODE (op) == CONST_DOUBLE
1595 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'H', constraint))
1596 result = 1;
1597 break;
1599 case 's':
1600 if (GET_CODE (op) == CONST_INT
1601 || (GET_CODE (op) == CONST_DOUBLE
1602 && GET_MODE (op) == VOIDmode))
1603 break;
1604 /* Fall through. */
1606 case 'i':
1607 if (CONSTANT_P (op) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op)))
1608 result = 1;
1609 break;
1611 case 'n':
1612 if (GET_CODE (op) == CONST_INT
1613 || (GET_CODE (op) == CONST_DOUBLE
1614 && GET_MODE (op) == VOIDmode))
1615 result = 1;
1616 break;
1618 case 'I':
1619 if (GET_CODE (op) == CONST_INT
1620 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'I', constraint))
1621 result = 1;
1622 break;
1623 case 'J':
1624 if (GET_CODE (op) == CONST_INT
1625 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'J', constraint))
1626 result = 1;
1627 break;
1628 case 'K':
1629 if (GET_CODE (op) == CONST_INT
1630 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'K', constraint))
1631 result = 1;
1632 break;
1633 case 'L':
1634 if (GET_CODE (op) == CONST_INT
1635 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'L', constraint))
1636 result = 1;
1637 break;
1638 case 'M':
1639 if (GET_CODE (op) == CONST_INT
1640 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'M', constraint))
1641 result = 1;
1642 break;
1643 case 'N':
1644 if (GET_CODE (op) == CONST_INT
1645 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'N', constraint))
1646 result = 1;
1647 break;
1648 case 'O':
1649 if (GET_CODE (op) == CONST_INT
1650 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'O', constraint))
1651 result = 1;
1652 break;
1653 case 'P':
1654 if (GET_CODE (op) == CONST_INT
1655 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'P', constraint))
1656 result = 1;
1657 break;
1659 case 'X':
1660 result = 1;
1661 break;
1663 case 'g':
1664 if (general_operand (op, VOIDmode))
1665 result = 1;
1666 break;
1668 default:
1669 /* For all other letters, we first check for a register class,
1670 otherwise it is an EXTRA_CONSTRAINT. */
1671 if (REG_CLASS_FROM_CONSTRAINT (c, constraint) != NO_REGS)
1673 case 'r':
1674 if (GET_MODE (op) == BLKmode)
1675 break;
1676 if (register_operand (op, VOIDmode))
1677 result = 1;
1679 #ifdef EXTRA_CONSTRAINT_STR
1680 else if (EXTRA_CONSTRAINT_STR (op, c, constraint))
1681 result = 1;
1682 else if (EXTRA_MEMORY_CONSTRAINT (c, constraint)
1683 /* Every memory operand can be reloaded to fit. */
1684 && memory_operand (op, VOIDmode))
1685 result = 1;
1686 else if (EXTRA_ADDRESS_CONSTRAINT (c, constraint)
1687 /* Every address operand can be reloaded to fit. */
1688 && address_operand (op, VOIDmode))
1689 result = 1;
1690 #endif
1691 break;
1693 len = CONSTRAINT_LEN (c, constraint);
1695 constraint++;
1696 while (--len && *constraint);
1697 if (len)
1698 return 0;
1701 return result;
1704 /* Given an rtx *P, if it is a sum containing an integer constant term,
1705 return the location (type rtx *) of the pointer to that constant term.
1706 Otherwise, return a null pointer. */
1708 rtx *
1709 find_constant_term_loc (rtx *p)
1711 rtx *tem;
1712 enum rtx_code code = GET_CODE (*p);
1714 /* If *P IS such a constant term, P is its location. */
1716 if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1717 || code == CONST)
1718 return p;
1720 /* Otherwise, if not a sum, it has no constant term. */
1722 if (GET_CODE (*p) != PLUS)
1723 return 0;
1725 /* If one of the summands is constant, return its location. */
1727 if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1728 && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1729 return p;
1731 /* Otherwise, check each summand for containing a constant term. */
1733 if (XEXP (*p, 0) != 0)
1735 tem = find_constant_term_loc (&XEXP (*p, 0));
1736 if (tem != 0)
1737 return tem;
1740 if (XEXP (*p, 1) != 0)
1742 tem = find_constant_term_loc (&XEXP (*p, 1));
1743 if (tem != 0)
1744 return tem;
1747 return 0;
1750 /* Return 1 if OP is a memory reference
1751 whose address contains no side effects
1752 and remains valid after the addition
1753 of a positive integer less than the
1754 size of the object being referenced.
1756 We assume that the original address is valid and do not check it.
1758 This uses strict_memory_address_p as a subroutine, so
1759 don't use it before reload. */
1762 offsettable_memref_p (rtx op)
1764 return ((MEM_P (op))
1765 && offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
1768 /* Similar, but don't require a strictly valid mem ref:
1769 consider pseudo-regs valid as index or base regs. */
1772 offsettable_nonstrict_memref_p (rtx op)
1774 return ((MEM_P (op))
1775 && offsettable_address_p (0, GET_MODE (op), XEXP (op, 0)));
1778 /* Return 1 if Y is a memory address which contains no side effects
1779 and would remain valid after the addition of a positive integer
1780 less than the size of that mode.
1782 We assume that the original address is valid and do not check it.
1783 We do check that it is valid for narrower modes.
1785 If STRICTP is nonzero, we require a strictly valid address,
1786 for the sake of use in reload.c. */
1789 offsettable_address_p (int strictp, enum machine_mode mode, rtx y)
1791 enum rtx_code ycode = GET_CODE (y);
1792 rtx z;
1793 rtx y1 = y;
1794 rtx *y2;
1795 int (*addressp) (enum machine_mode, rtx) =
1796 (strictp ? strict_memory_address_p : memory_address_p);
1797 unsigned int mode_sz = GET_MODE_SIZE (mode);
1799 if (CONSTANT_ADDRESS_P (y))
1800 return 1;
1802 /* Adjusting an offsettable address involves changing to a narrower mode.
1803 Make sure that's OK. */
1805 if (mode_dependent_address_p (y))
1806 return 0;
1808 /* ??? How much offset does an offsettable BLKmode reference need?
1809 Clearly that depends on the situation in which it's being used.
1810 However, the current situation in which we test 0xffffffff is
1811 less than ideal. Caveat user. */
1812 if (mode_sz == 0)
1813 mode_sz = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
1815 /* If the expression contains a constant term,
1816 see if it remains valid when max possible offset is added. */
1818 if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
1820 int good;
1822 y1 = *y2;
1823 *y2 = plus_constant (*y2, mode_sz - 1);
1824 /* Use QImode because an odd displacement may be automatically invalid
1825 for any wider mode. But it should be valid for a single byte. */
1826 good = (*addressp) (QImode, y);
1828 /* In any case, restore old contents of memory. */
1829 *y2 = y1;
1830 return good;
1833 if (GET_RTX_CLASS (ycode) == RTX_AUTOINC)
1834 return 0;
1836 /* The offset added here is chosen as the maximum offset that
1837 any instruction could need to add when operating on something
1838 of the specified mode. We assume that if Y and Y+c are
1839 valid addresses then so is Y+d for all 0<d<c. adjust_address will
1840 go inside a LO_SUM here, so we do so as well. */
1841 if (GET_CODE (y) == LO_SUM
1842 && mode != BLKmode
1843 && mode_sz <= GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT)
1844 z = gen_rtx_LO_SUM (GET_MODE (y), XEXP (y, 0),
1845 plus_constant (XEXP (y, 1), mode_sz - 1));
1846 else
1847 z = plus_constant (y, mode_sz - 1);
1849 /* Use QImode because an odd displacement may be automatically invalid
1850 for any wider mode. But it should be valid for a single byte. */
1851 return (*addressp) (QImode, z);
1854 /* Return 1 if ADDR is an address-expression whose effect depends
1855 on the mode of the memory reference it is used in.
1857 Autoincrement addressing is a typical example of mode-dependence
1858 because the amount of the increment depends on the mode. */
1861 mode_dependent_address_p (rtx addr)
1863 /* Auto-increment addressing with anything other than post_modify
1864 or pre_modify always introduces a mode dependency. Catch such
1865 cases now instead of deferring to the target. */
1866 if (GET_CODE (addr) == PRE_INC
1867 || GET_CODE (addr) == POST_INC
1868 || GET_CODE (addr) == PRE_DEC
1869 || GET_CODE (addr) == POST_DEC)
1870 return 1;
1872 GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
1873 return 0;
1874 /* Label `win' might (not) be used via GO_IF_MODE_DEPENDENT_ADDRESS. */
1875 win: ATTRIBUTE_UNUSED_LABEL
1876 return 1;
1879 /* Like extract_insn, but save insn extracted and don't extract again, when
1880 called again for the same insn expecting that recog_data still contain the
1881 valid information. This is used primary by gen_attr infrastructure that
1882 often does extract insn again and again. */
1883 void
1884 extract_insn_cached (rtx insn)
1886 if (recog_data.insn == insn && INSN_CODE (insn) >= 0)
1887 return;
1888 extract_insn (insn);
1889 recog_data.insn = insn;
1892 /* Do cached extract_insn, constrain_operands and complain about failures.
1893 Used by insn_attrtab. */
1894 void
1895 extract_constrain_insn_cached (rtx insn)
1897 extract_insn_cached (insn);
1898 if (which_alternative == -1
1899 && !constrain_operands (reload_completed))
1900 fatal_insn_not_found (insn);
1903 /* Do cached constrain_operands and complain about failures. */
1905 constrain_operands_cached (int strict)
1907 if (which_alternative == -1)
1908 return constrain_operands (strict);
1909 else
1910 return 1;
1913 /* Analyze INSN and fill in recog_data. */
1915 void
1916 extract_insn (rtx insn)
1918 int i;
1919 int icode;
1920 int noperands;
1921 rtx body = PATTERN (insn);
1923 recog_data.insn = NULL;
1924 recog_data.n_operands = 0;
1925 recog_data.n_alternatives = 0;
1926 recog_data.n_dups = 0;
1927 which_alternative = -1;
1929 switch (GET_CODE (body))
1931 case USE:
1932 case CLOBBER:
1933 case ASM_INPUT:
1934 case ADDR_VEC:
1935 case ADDR_DIFF_VEC:
1936 return;
1938 case SET:
1939 if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1940 goto asm_insn;
1941 else
1942 goto normal_insn;
1943 case PARALLEL:
1944 if ((GET_CODE (XVECEXP (body, 0, 0)) == SET
1945 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1946 || GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1947 goto asm_insn;
1948 else
1949 goto normal_insn;
1950 case ASM_OPERANDS:
1951 asm_insn:
1952 recog_data.n_operands = noperands = asm_noperands (body);
1953 if (noperands >= 0)
1955 /* This insn is an `asm' with operands. */
1957 /* expand_asm_operands makes sure there aren't too many operands. */
1958 gcc_assert (noperands <= MAX_RECOG_OPERANDS);
1960 /* Now get the operand values and constraints out of the insn. */
1961 decode_asm_operands (body, recog_data.operand,
1962 recog_data.operand_loc,
1963 recog_data.constraints,
1964 recog_data.operand_mode, NULL);
1965 if (noperands > 0)
1967 const char *p = recog_data.constraints[0];
1968 recog_data.n_alternatives = 1;
1969 while (*p)
1970 recog_data.n_alternatives += (*p++ == ',');
1972 break;
1974 fatal_insn_not_found (insn);
1976 default:
1977 normal_insn:
1978 /* Ordinary insn: recognize it, get the operands via insn_extract
1979 and get the constraints. */
1981 icode = recog_memoized (insn);
1982 if (icode < 0)
1983 fatal_insn_not_found (insn);
1985 recog_data.n_operands = noperands = insn_data[icode].n_operands;
1986 recog_data.n_alternatives = insn_data[icode].n_alternatives;
1987 recog_data.n_dups = insn_data[icode].n_dups;
1989 insn_extract (insn);
1991 for (i = 0; i < noperands; i++)
1993 recog_data.constraints[i] = insn_data[icode].operand[i].constraint;
1994 recog_data.operand_mode[i] = insn_data[icode].operand[i].mode;
1995 /* VOIDmode match_operands gets mode from their real operand. */
1996 if (recog_data.operand_mode[i] == VOIDmode)
1997 recog_data.operand_mode[i] = GET_MODE (recog_data.operand[i]);
2000 for (i = 0; i < noperands; i++)
2001 recog_data.operand_type[i]
2002 = (recog_data.constraints[i][0] == '=' ? OP_OUT
2003 : recog_data.constraints[i][0] == '+' ? OP_INOUT
2004 : OP_IN);
2006 gcc_assert (recog_data.n_alternatives <= MAX_RECOG_ALTERNATIVES);
2009 /* After calling extract_insn, you can use this function to extract some
2010 information from the constraint strings into a more usable form.
2011 The collected data is stored in recog_op_alt. */
2012 void
2013 preprocess_constraints (void)
2015 int i;
2017 for (i = 0; i < recog_data.n_operands; i++)
2018 memset (recog_op_alt[i], 0, (recog_data.n_alternatives
2019 * sizeof (struct operand_alternative)));
2021 for (i = 0; i < recog_data.n_operands; i++)
2023 int j;
2024 struct operand_alternative *op_alt;
2025 const char *p = recog_data.constraints[i];
2027 op_alt = recog_op_alt[i];
2029 for (j = 0; j < recog_data.n_alternatives; j++)
2031 op_alt[j].cl = NO_REGS;
2032 op_alt[j].constraint = p;
2033 op_alt[j].matches = -1;
2034 op_alt[j].matched = -1;
2036 if (*p == '\0' || *p == ',')
2038 op_alt[j].anything_ok = 1;
2039 continue;
2042 for (;;)
2044 char c = *p;
2045 if (c == '#')
2047 c = *++p;
2048 while (c != ',' && c != '\0');
2049 if (c == ',' || c == '\0')
2051 p++;
2052 break;
2055 switch (c)
2057 case '=': case '+': case '*': case '%':
2058 case 'E': case 'F': case 'G': case 'H':
2059 case 's': case 'i': case 'n':
2060 case 'I': case 'J': case 'K': case 'L':
2061 case 'M': case 'N': case 'O': case 'P':
2062 /* These don't say anything we care about. */
2063 break;
2065 case '?':
2066 op_alt[j].reject += 6;
2067 break;
2068 case '!':
2069 op_alt[j].reject += 600;
2070 break;
2071 case '&':
2072 op_alt[j].earlyclobber = 1;
2073 break;
2075 case '0': case '1': case '2': case '3': case '4':
2076 case '5': case '6': case '7': case '8': case '9':
2078 char *end;
2079 op_alt[j].matches = strtoul (p, &end, 10);
2080 recog_op_alt[op_alt[j].matches][j].matched = i;
2081 p = end;
2083 continue;
2085 case 'm':
2086 op_alt[j].memory_ok = 1;
2087 break;
2088 case '<':
2089 op_alt[j].decmem_ok = 1;
2090 break;
2091 case '>':
2092 op_alt[j].incmem_ok = 1;
2093 break;
2094 case 'V':
2095 op_alt[j].nonoffmem_ok = 1;
2096 break;
2097 case 'o':
2098 op_alt[j].offmem_ok = 1;
2099 break;
2100 case 'X':
2101 op_alt[j].anything_ok = 1;
2102 break;
2104 case 'p':
2105 op_alt[j].is_address = 1;
2106 op_alt[j].cl = reg_class_subunion[(int) op_alt[j].cl]
2107 [(int) base_reg_class (VOIDmode, ADDRESS, SCRATCH)];
2108 break;
2110 case 'g':
2111 case 'r':
2112 op_alt[j].cl =
2113 reg_class_subunion[(int) op_alt[j].cl][(int) GENERAL_REGS];
2114 break;
2116 default:
2117 if (EXTRA_MEMORY_CONSTRAINT (c, p))
2119 op_alt[j].memory_ok = 1;
2120 break;
2122 if (EXTRA_ADDRESS_CONSTRAINT (c, p))
2124 op_alt[j].is_address = 1;
2125 op_alt[j].cl
2126 = (reg_class_subunion
2127 [(int) op_alt[j].cl]
2128 [(int) base_reg_class (VOIDmode, ADDRESS,
2129 SCRATCH)]);
2130 break;
2133 op_alt[j].cl
2134 = (reg_class_subunion
2135 [(int) op_alt[j].cl]
2136 [(int) REG_CLASS_FROM_CONSTRAINT ((unsigned char) c, p)]);
2137 break;
2139 p += CONSTRAINT_LEN (c, p);
2145 /* Check the operands of an insn against the insn's operand constraints
2146 and return 1 if they are valid.
2147 The information about the insn's operands, constraints, operand modes
2148 etc. is obtained from the global variables set up by extract_insn.
2150 WHICH_ALTERNATIVE is set to a number which indicates which
2151 alternative of constraints was matched: 0 for the first alternative,
2152 1 for the next, etc.
2154 In addition, when two operands are required to match
2155 and it happens that the output operand is (reg) while the
2156 input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
2157 make the output operand look like the input.
2158 This is because the output operand is the one the template will print.
2160 This is used in final, just before printing the assembler code and by
2161 the routines that determine an insn's attribute.
2163 If STRICT is a positive nonzero value, it means that we have been
2164 called after reload has been completed. In that case, we must
2165 do all checks strictly. If it is zero, it means that we have been called
2166 before reload has completed. In that case, we first try to see if we can
2167 find an alternative that matches strictly. If not, we try again, this
2168 time assuming that reload will fix up the insn. This provides a "best
2169 guess" for the alternative and is used to compute attributes of insns prior
2170 to reload. A negative value of STRICT is used for this internal call. */
2172 struct funny_match
2174 int this, other;
2178 constrain_operands (int strict)
2180 const char *constraints[MAX_RECOG_OPERANDS];
2181 int matching_operands[MAX_RECOG_OPERANDS];
2182 int earlyclobber[MAX_RECOG_OPERANDS];
2183 int c;
2185 struct funny_match funny_match[MAX_RECOG_OPERANDS];
2186 int funny_match_index;
2188 which_alternative = 0;
2189 if (recog_data.n_operands == 0 || recog_data.n_alternatives == 0)
2190 return 1;
2192 for (c = 0; c < recog_data.n_operands; c++)
2194 constraints[c] = recog_data.constraints[c];
2195 matching_operands[c] = -1;
2200 int seen_earlyclobber_at = -1;
2201 int opno;
2202 int lose = 0;
2203 funny_match_index = 0;
2205 for (opno = 0; opno < recog_data.n_operands; opno++)
2207 rtx op = recog_data.operand[opno];
2208 enum machine_mode mode = GET_MODE (op);
2209 const char *p = constraints[opno];
2210 int offset = 0;
2211 int win = 0;
2212 int val;
2213 int len;
2215 earlyclobber[opno] = 0;
2217 /* A unary operator may be accepted by the predicate, but it
2218 is irrelevant for matching constraints. */
2219 if (UNARY_P (op))
2220 op = XEXP (op, 0);
2222 if (GET_CODE (op) == SUBREG)
2224 if (REG_P (SUBREG_REG (op))
2225 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
2226 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
2227 GET_MODE (SUBREG_REG (op)),
2228 SUBREG_BYTE (op),
2229 GET_MODE (op));
2230 op = SUBREG_REG (op);
2233 /* An empty constraint or empty alternative
2234 allows anything which matched the pattern. */
2235 if (*p == 0 || *p == ',')
2236 win = 1;
2239 switch (c = *p, len = CONSTRAINT_LEN (c, p), c)
2241 case '\0':
2242 len = 0;
2243 break;
2244 case ',':
2245 c = '\0';
2246 break;
2248 case '?': case '!': case '*': case '%':
2249 case '=': case '+':
2250 break;
2252 case '#':
2253 /* Ignore rest of this alternative as far as
2254 constraint checking is concerned. */
2256 p++;
2257 while (*p && *p != ',');
2258 len = 0;
2259 break;
2261 case '&':
2262 earlyclobber[opno] = 1;
2263 if (seen_earlyclobber_at < 0)
2264 seen_earlyclobber_at = opno;
2265 break;
2267 case '0': case '1': case '2': case '3': case '4':
2268 case '5': case '6': case '7': case '8': case '9':
2270 /* This operand must be the same as a previous one.
2271 This kind of constraint is used for instructions such
2272 as add when they take only two operands.
2274 Note that the lower-numbered operand is passed first.
2276 If we are not testing strictly, assume that this
2277 constraint will be satisfied. */
2279 char *end;
2280 int match;
2282 match = strtoul (p, &end, 10);
2283 p = end;
2285 if (strict < 0)
2286 val = 1;
2287 else
2289 rtx op1 = recog_data.operand[match];
2290 rtx op2 = recog_data.operand[opno];
2292 /* A unary operator may be accepted by the predicate,
2293 but it is irrelevant for matching constraints. */
2294 if (UNARY_P (op1))
2295 op1 = XEXP (op1, 0);
2296 if (UNARY_P (op2))
2297 op2 = XEXP (op2, 0);
2299 val = operands_match_p (op1, op2);
2302 matching_operands[opno] = match;
2303 matching_operands[match] = opno;
2305 if (val != 0)
2306 win = 1;
2308 /* If output is *x and input is *--x, arrange later
2309 to change the output to *--x as well, since the
2310 output op is the one that will be printed. */
2311 if (val == 2 && strict > 0)
2313 funny_match[funny_match_index].this = opno;
2314 funny_match[funny_match_index++].other = match;
2317 len = 0;
2318 break;
2320 case 'p':
2321 /* p is used for address_operands. When we are called by
2322 gen_reload, no one will have checked that the address is
2323 strictly valid, i.e., that all pseudos requiring hard regs
2324 have gotten them. */
2325 if (strict <= 0
2326 || (strict_memory_address_p (recog_data.operand_mode[opno],
2327 op)))
2328 win = 1;
2329 break;
2331 /* No need to check general_operand again;
2332 it was done in insn-recog.c. Well, except that reload
2333 doesn't check the validity of its replacements, but
2334 that should only matter when there's a bug. */
2335 case 'g':
2336 /* Anything goes unless it is a REG and really has a hard reg
2337 but the hard reg is not in the class GENERAL_REGS. */
2338 if (REG_P (op))
2340 if (strict < 0
2341 || GENERAL_REGS == ALL_REGS
2342 || (reload_in_progress
2343 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2344 || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
2345 win = 1;
2347 else if (strict < 0 || general_operand (op, mode))
2348 win = 1;
2349 break;
2351 case 'X':
2352 /* This is used for a MATCH_SCRATCH in the cases when
2353 we don't actually need anything. So anything goes
2354 any time. */
2355 win = 1;
2356 break;
2358 case 'm':
2359 /* Memory operands must be valid, to the extent
2360 required by STRICT. */
2361 if (MEM_P (op))
2363 if (strict > 0
2364 && !strict_memory_address_p (GET_MODE (op),
2365 XEXP (op, 0)))
2366 break;
2367 if (strict == 0
2368 && !memory_address_p (GET_MODE (op), XEXP (op, 0)))
2369 break;
2370 win = 1;
2372 /* Before reload, accept what reload can turn into mem. */
2373 else if (strict < 0 && CONSTANT_P (op))
2374 win = 1;
2375 /* During reload, accept a pseudo */
2376 else if (reload_in_progress && REG_P (op)
2377 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2378 win = 1;
2379 break;
2381 case '<':
2382 if (MEM_P (op)
2383 && (GET_CODE (XEXP (op, 0)) == PRE_DEC
2384 || GET_CODE (XEXP (op, 0)) == POST_DEC))
2385 win = 1;
2386 break;
2388 case '>':
2389 if (MEM_P (op)
2390 && (GET_CODE (XEXP (op, 0)) == PRE_INC
2391 || GET_CODE (XEXP (op, 0)) == POST_INC))
2392 win = 1;
2393 break;
2395 case 'E':
2396 case 'F':
2397 if (GET_CODE (op) == CONST_DOUBLE
2398 || (GET_CODE (op) == CONST_VECTOR
2399 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
2400 win = 1;
2401 break;
2403 case 'G':
2404 case 'H':
2405 if (GET_CODE (op) == CONST_DOUBLE
2406 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, p))
2407 win = 1;
2408 break;
2410 case 's':
2411 if (GET_CODE (op) == CONST_INT
2412 || (GET_CODE (op) == CONST_DOUBLE
2413 && GET_MODE (op) == VOIDmode))
2414 break;
2415 case 'i':
2416 if (CONSTANT_P (op))
2417 win = 1;
2418 break;
2420 case 'n':
2421 if (GET_CODE (op) == CONST_INT
2422 || (GET_CODE (op) == CONST_DOUBLE
2423 && GET_MODE (op) == VOIDmode))
2424 win = 1;
2425 break;
2427 case 'I':
2428 case 'J':
2429 case 'K':
2430 case 'L':
2431 case 'M':
2432 case 'N':
2433 case 'O':
2434 case 'P':
2435 if (GET_CODE (op) == CONST_INT
2436 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, p))
2437 win = 1;
2438 break;
2440 case 'V':
2441 if (MEM_P (op)
2442 && ((strict > 0 && ! offsettable_memref_p (op))
2443 || (strict < 0
2444 && !(CONSTANT_P (op) || MEM_P (op)))
2445 || (reload_in_progress
2446 && !(REG_P (op)
2447 && REGNO (op) >= FIRST_PSEUDO_REGISTER))))
2448 win = 1;
2449 break;
2451 case 'o':
2452 if ((strict > 0 && offsettable_memref_p (op))
2453 || (strict == 0 && offsettable_nonstrict_memref_p (op))
2454 /* Before reload, accept what reload can handle. */
2455 || (strict < 0
2456 && (CONSTANT_P (op) || MEM_P (op)))
2457 /* During reload, accept a pseudo */
2458 || (reload_in_progress && REG_P (op)
2459 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2460 win = 1;
2461 break;
2463 default:
2465 enum reg_class cl;
2467 cl = (c == 'r'
2468 ? GENERAL_REGS : REG_CLASS_FROM_CONSTRAINT (c, p));
2469 if (cl != NO_REGS)
2471 if (strict < 0
2472 || (strict == 0
2473 && REG_P (op)
2474 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2475 || (strict == 0 && GET_CODE (op) == SCRATCH)
2476 || (REG_P (op)
2477 && reg_fits_class_p (op, cl, offset, mode)))
2478 win = 1;
2480 #ifdef EXTRA_CONSTRAINT_STR
2481 else if (EXTRA_CONSTRAINT_STR (op, c, p))
2482 win = 1;
2484 else if (EXTRA_MEMORY_CONSTRAINT (c, p)
2485 /* Every memory operand can be reloaded to fit. */
2486 && ((strict < 0 && MEM_P (op))
2487 /* Before reload, accept what reload can turn
2488 into mem. */
2489 || (strict < 0 && CONSTANT_P (op))
2490 /* During reload, accept a pseudo */
2491 || (reload_in_progress && REG_P (op)
2492 && REGNO (op) >= FIRST_PSEUDO_REGISTER)))
2493 win = 1;
2494 else if (EXTRA_ADDRESS_CONSTRAINT (c, p)
2495 /* Every address operand can be reloaded to fit. */
2496 && strict < 0)
2497 win = 1;
2498 #endif
2499 break;
2502 while (p += len, c);
2504 constraints[opno] = p;
2505 /* If this operand did not win somehow,
2506 this alternative loses. */
2507 if (! win)
2508 lose = 1;
2510 /* This alternative won; the operands are ok.
2511 Change whichever operands this alternative says to change. */
2512 if (! lose)
2514 int opno, eopno;
2516 /* See if any earlyclobber operand conflicts with some other
2517 operand. */
2519 if (strict > 0 && seen_earlyclobber_at >= 0)
2520 for (eopno = seen_earlyclobber_at;
2521 eopno < recog_data.n_operands;
2522 eopno++)
2523 /* Ignore earlyclobber operands now in memory,
2524 because we would often report failure when we have
2525 two memory operands, one of which was formerly a REG. */
2526 if (earlyclobber[eopno]
2527 && REG_P (recog_data.operand[eopno]))
2528 for (opno = 0; opno < recog_data.n_operands; opno++)
2529 if ((MEM_P (recog_data.operand[opno])
2530 || recog_data.operand_type[opno] != OP_OUT)
2531 && opno != eopno
2532 /* Ignore things like match_operator operands. */
2533 && *recog_data.constraints[opno] != 0
2534 && ! (matching_operands[opno] == eopno
2535 && operands_match_p (recog_data.operand[opno],
2536 recog_data.operand[eopno]))
2537 && ! safe_from_earlyclobber (recog_data.operand[opno],
2538 recog_data.operand[eopno]))
2539 lose = 1;
2541 if (! lose)
2543 while (--funny_match_index >= 0)
2545 recog_data.operand[funny_match[funny_match_index].other]
2546 = recog_data.operand[funny_match[funny_match_index].this];
2549 return 1;
2553 which_alternative++;
2555 while (which_alternative < recog_data.n_alternatives);
2557 which_alternative = -1;
2558 /* If we are about to reject this, but we are not to test strictly,
2559 try a very loose test. Only return failure if it fails also. */
2560 if (strict == 0)
2561 return constrain_operands (-1);
2562 else
2563 return 0;
2566 /* Return 1 iff OPERAND (assumed to be a REG rtx)
2567 is a hard reg in class CLASS when its regno is offset by OFFSET
2568 and changed to mode MODE.
2569 If REG occupies multiple hard regs, all of them must be in CLASS. */
2572 reg_fits_class_p (rtx operand, enum reg_class cl, int offset,
2573 enum machine_mode mode)
2575 int regno = REGNO (operand);
2577 if (cl == NO_REGS)
2578 return 0;
2580 return (regno < FIRST_PSEUDO_REGISTER
2581 && in_hard_reg_set_p (reg_class_contents[(int) cl],
2582 mode, regno + offset));
2585 /* Split single instruction. Helper function for split_all_insns and
2586 split_all_insns_noflow. Return last insn in the sequence if successful,
2587 or NULL if unsuccessful. */
2589 static rtx
2590 split_insn (rtx insn)
2592 /* Split insns here to get max fine-grain parallelism. */
2593 rtx first = PREV_INSN (insn);
2594 rtx last = try_split (PATTERN (insn), insn, 1);
2596 if (last == insn)
2597 return NULL_RTX;
2599 /* try_split returns the NOTE that INSN became. */
2600 SET_INSN_DELETED (insn);
2602 /* ??? Coddle to md files that generate subregs in post-reload
2603 splitters instead of computing the proper hard register. */
2604 if (reload_completed && first != last)
2606 first = NEXT_INSN (first);
2607 for (;;)
2609 if (INSN_P (first))
2610 cleanup_subreg_operands (first);
2611 if (first == last)
2612 break;
2613 first = NEXT_INSN (first);
2616 return last;
2619 /* Split all insns in the function. If UPD_LIFE, update life info after. */
2621 void
2622 split_all_insns (void)
2624 sbitmap blocks;
2625 bool changed;
2626 basic_block bb;
2628 blocks = sbitmap_alloc (last_basic_block);
2629 sbitmap_zero (blocks);
2630 changed = false;
2632 FOR_EACH_BB_REVERSE (bb)
2634 rtx insn, next;
2635 bool finish = false;
2637 for (insn = BB_HEAD (bb); !finish ; insn = next)
2639 /* Can't use `next_real_insn' because that might go across
2640 CODE_LABELS and short-out basic blocks. */
2641 next = NEXT_INSN (insn);
2642 finish = (insn == BB_END (bb));
2643 if (INSN_P (insn))
2645 rtx set = single_set (insn);
2647 /* Don't split no-op move insns. These should silently
2648 disappear later in final. Splitting such insns would
2649 break the code that handles LIBCALL blocks. */
2650 if (set && set_noop_p (set))
2652 /* Nops get in the way while scheduling, so delete them
2653 now if register allocation has already been done. It
2654 is too risky to try to do this before register
2655 allocation, and there are unlikely to be very many
2656 nops then anyways. */
2657 if (reload_completed)
2658 delete_insn_and_edges (insn);
2660 else
2662 rtx last = split_insn (insn);
2663 if (last)
2665 /* The split sequence may include barrier, but the
2666 BB boundary we are interested in will be set to
2667 previous one. */
2669 while (BARRIER_P (last))
2670 last = PREV_INSN (last);
2671 SET_BIT (blocks, bb->index);
2672 changed = true;
2679 if (changed)
2680 find_many_sub_basic_blocks (blocks);
2682 #ifdef ENABLE_CHECKING
2683 verify_flow_info ();
2684 #endif
2686 sbitmap_free (blocks);
2689 /* Same as split_all_insns, but do not expect CFG to be available.
2690 Used by machine dependent reorg passes. */
2692 unsigned int
2693 split_all_insns_noflow (void)
2695 rtx next, insn;
2697 for (insn = get_insns (); insn; insn = next)
2699 next = NEXT_INSN (insn);
2700 if (INSN_P (insn))
2702 /* Don't split no-op move insns. These should silently
2703 disappear later in final. Splitting such insns would
2704 break the code that handles LIBCALL blocks. */
2705 rtx set = single_set (insn);
2706 if (set && set_noop_p (set))
2708 /* Nops get in the way while scheduling, so delete them
2709 now if register allocation has already been done. It
2710 is too risky to try to do this before register
2711 allocation, and there are unlikely to be very many
2712 nops then anyways.
2714 ??? Should we use delete_insn when the CFG isn't valid? */
2715 if (reload_completed)
2716 delete_insn_and_edges (insn);
2718 else
2719 split_insn (insn);
2722 return 0;
2725 #ifdef HAVE_peephole2
2726 struct peep2_insn_data
2728 rtx insn;
2729 regset live_before;
2732 static struct peep2_insn_data peep2_insn_data[MAX_INSNS_PER_PEEP2 + 1];
2733 static int peep2_current;
2734 /* The number of instructions available to match a peep2. */
2735 int peep2_current_count;
2737 /* A non-insn marker indicating the last insn of the block.
2738 The live_before regset for this element is correct, indicating
2739 DF_LIVE_OUT for the block. */
2740 #define PEEP2_EOB pc_rtx
2742 /* Return the Nth non-note insn after `current', or return NULL_RTX if it
2743 does not exist. Used by the recognizer to find the next insn to match
2744 in a multi-insn pattern. */
2747 peep2_next_insn (int n)
2749 gcc_assert (n <= peep2_current_count);
2751 n += peep2_current;
2752 if (n >= MAX_INSNS_PER_PEEP2 + 1)
2753 n -= MAX_INSNS_PER_PEEP2 + 1;
2755 return peep2_insn_data[n].insn;
2758 /* Return true if REGNO is dead before the Nth non-note insn
2759 after `current'. */
2762 peep2_regno_dead_p (int ofs, int regno)
2764 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
2766 ofs += peep2_current;
2767 if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2768 ofs -= MAX_INSNS_PER_PEEP2 + 1;
2770 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
2772 return ! REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno);
2775 /* Similarly for a REG. */
2778 peep2_reg_dead_p (int ofs, rtx reg)
2780 int regno, n;
2782 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
2784 ofs += peep2_current;
2785 if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2786 ofs -= MAX_INSNS_PER_PEEP2 + 1;
2788 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
2790 regno = REGNO (reg);
2791 n = hard_regno_nregs[regno][GET_MODE (reg)];
2792 while (--n >= 0)
2793 if (REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno + n))
2794 return 0;
2795 return 1;
2798 /* Try to find a hard register of mode MODE, matching the register class in
2799 CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
2800 remains available until the end of LAST_INSN. LAST_INSN may be NULL_RTX,
2801 in which case the only condition is that the register must be available
2802 before CURRENT_INSN.
2803 Registers that already have bits set in REG_SET will not be considered.
2805 If an appropriate register is available, it will be returned and the
2806 corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
2807 returned. */
2810 peep2_find_free_register (int from, int to, const char *class_str,
2811 enum machine_mode mode, HARD_REG_SET *reg_set)
2813 static int search_ofs;
2814 enum reg_class cl;
2815 HARD_REG_SET live;
2816 int i;
2818 gcc_assert (from < MAX_INSNS_PER_PEEP2 + 1);
2819 gcc_assert (to < MAX_INSNS_PER_PEEP2 + 1);
2821 from += peep2_current;
2822 if (from >= MAX_INSNS_PER_PEEP2 + 1)
2823 from -= MAX_INSNS_PER_PEEP2 + 1;
2824 to += peep2_current;
2825 if (to >= MAX_INSNS_PER_PEEP2 + 1)
2826 to -= MAX_INSNS_PER_PEEP2 + 1;
2828 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
2829 REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before);
2831 while (from != to)
2833 HARD_REG_SET this_live;
2835 if (++from >= MAX_INSNS_PER_PEEP2 + 1)
2836 from = 0;
2837 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
2838 REG_SET_TO_HARD_REG_SET (this_live, peep2_insn_data[from].live_before);
2839 IOR_HARD_REG_SET (live, this_live);
2842 cl = (class_str[0] == 'r' ? GENERAL_REGS
2843 : REG_CLASS_FROM_CONSTRAINT (class_str[0], class_str));
2845 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2847 int raw_regno, regno, success, j;
2849 /* Distribute the free registers as much as possible. */
2850 raw_regno = search_ofs + i;
2851 if (raw_regno >= FIRST_PSEUDO_REGISTER)
2852 raw_regno -= FIRST_PSEUDO_REGISTER;
2853 #ifdef REG_ALLOC_ORDER
2854 regno = reg_alloc_order[raw_regno];
2855 #else
2856 regno = raw_regno;
2857 #endif
2859 /* Don't allocate fixed registers. */
2860 if (fixed_regs[regno])
2861 continue;
2862 /* Make sure the register is of the right class. */
2863 if (! TEST_HARD_REG_BIT (reg_class_contents[cl], regno))
2864 continue;
2865 /* And can support the mode we need. */
2866 if (! HARD_REGNO_MODE_OK (regno, mode))
2867 continue;
2868 /* And that we don't create an extra save/restore. */
2869 if (! call_used_regs[regno] && ! df_regs_ever_live_p (regno))
2870 continue;
2871 /* And we don't clobber traceback for noreturn functions. */
2872 if ((regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM)
2873 && (! reload_completed || frame_pointer_needed))
2874 continue;
2876 success = 1;
2877 for (j = hard_regno_nregs[regno][mode] - 1; j >= 0; j--)
2879 if (TEST_HARD_REG_BIT (*reg_set, regno + j)
2880 || TEST_HARD_REG_BIT (live, regno + j))
2882 success = 0;
2883 break;
2886 if (success)
2888 add_to_hard_reg_set (reg_set, mode, regno);
2890 /* Start the next search with the next register. */
2891 if (++raw_regno >= FIRST_PSEUDO_REGISTER)
2892 raw_regno = 0;
2893 search_ofs = raw_regno;
2895 return gen_rtx_REG (mode, regno);
2899 search_ofs = 0;
2900 return NULL_RTX;
2903 /* Perform the peephole2 optimization pass. */
2905 static void
2906 peephole2_optimize (void)
2908 rtx insn, prev;
2909 bitmap live;
2910 int i;
2911 basic_block bb;
2912 bool do_cleanup_cfg = false;
2913 bool do_rebuild_jump_labels = false;
2915 df_set_flags (DF_LR_RUN_DCE);
2916 df_analyze ();
2918 /* Initialize the regsets we're going to use. */
2919 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
2920 peep2_insn_data[i].live_before = BITMAP_ALLOC (&reg_obstack);
2921 live = BITMAP_ALLOC (&reg_obstack);
2923 FOR_EACH_BB_REVERSE (bb)
2925 /* Indicate that all slots except the last holds invalid data. */
2926 for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
2927 peep2_insn_data[i].insn = NULL_RTX;
2928 peep2_current_count = 0;
2930 /* Indicate that the last slot contains live_after data. */
2931 peep2_insn_data[MAX_INSNS_PER_PEEP2].insn = PEEP2_EOB;
2932 peep2_current = MAX_INSNS_PER_PEEP2;
2934 /* Start up propagation. */
2935 bitmap_copy (live, DF_LR_OUT (bb));
2936 df_simulate_artificial_refs_at_end (bb, live);
2937 bitmap_copy (peep2_insn_data[MAX_INSNS_PER_PEEP2].live_before, live);
2939 for (insn = BB_END (bb); ; insn = prev)
2941 prev = PREV_INSN (insn);
2942 if (INSN_P (insn))
2944 rtx try, before_try, x;
2945 int match_len;
2946 rtx note;
2947 bool was_call = false;
2949 /* Record this insn. */
2950 if (--peep2_current < 0)
2951 peep2_current = MAX_INSNS_PER_PEEP2;
2952 if (peep2_current_count < MAX_INSNS_PER_PEEP2
2953 && peep2_insn_data[peep2_current].insn == NULL_RTX)
2954 peep2_current_count++;
2955 peep2_insn_data[peep2_current].insn = insn;
2956 df_simulate_one_insn (bb, insn, live);
2957 COPY_REG_SET (peep2_insn_data[peep2_current].live_before, live);
2959 if (RTX_FRAME_RELATED_P (insn))
2961 /* If an insn has RTX_FRAME_RELATED_P set, peephole
2962 substitution would lose the
2963 REG_FRAME_RELATED_EXPR that is attached. */
2964 peep2_current_count = 0;
2965 try = NULL;
2967 else
2968 /* Match the peephole. */
2969 try = peephole2_insns (PATTERN (insn), insn, &match_len);
2971 if (try != NULL)
2973 /* If we are splitting a CALL_INSN, look for the CALL_INSN
2974 in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other
2975 cfg-related call notes. */
2976 for (i = 0; i <= match_len; ++i)
2978 int j;
2979 rtx old_insn, new_insn, note;
2981 j = i + peep2_current;
2982 if (j >= MAX_INSNS_PER_PEEP2 + 1)
2983 j -= MAX_INSNS_PER_PEEP2 + 1;
2984 old_insn = peep2_insn_data[j].insn;
2985 if (!CALL_P (old_insn))
2986 continue;
2987 was_call = true;
2989 new_insn = try;
2990 while (new_insn != NULL_RTX)
2992 if (CALL_P (new_insn))
2993 break;
2994 new_insn = NEXT_INSN (new_insn);
2997 gcc_assert (new_insn != NULL_RTX);
2999 CALL_INSN_FUNCTION_USAGE (new_insn)
3000 = CALL_INSN_FUNCTION_USAGE (old_insn);
3002 for (note = REG_NOTES (old_insn);
3003 note;
3004 note = XEXP (note, 1))
3005 switch (REG_NOTE_KIND (note))
3007 case REG_NORETURN:
3008 case REG_SETJMP:
3009 REG_NOTES (new_insn)
3010 = gen_rtx_EXPR_LIST (REG_NOTE_KIND (note),
3011 XEXP (note, 0),
3012 REG_NOTES (new_insn));
3013 default:
3014 /* Discard all other reg notes. */
3015 break;
3018 /* Croak if there is another call in the sequence. */
3019 while (++i <= match_len)
3021 j = i + peep2_current;
3022 if (j >= MAX_INSNS_PER_PEEP2 + 1)
3023 j -= MAX_INSNS_PER_PEEP2 + 1;
3024 old_insn = peep2_insn_data[j].insn;
3025 gcc_assert (!CALL_P (old_insn));
3027 break;
3030 i = match_len + peep2_current;
3031 if (i >= MAX_INSNS_PER_PEEP2 + 1)
3032 i -= MAX_INSNS_PER_PEEP2 + 1;
3034 note = find_reg_note (peep2_insn_data[i].insn,
3035 REG_EH_REGION, NULL_RTX);
3037 /* Replace the old sequence with the new. */
3038 try = emit_insn_after_setloc (try, peep2_insn_data[i].insn,
3039 INSN_LOCATOR (peep2_insn_data[i].insn));
3040 before_try = PREV_INSN (insn);
3041 delete_insn_chain (insn, peep2_insn_data[i].insn, false);
3043 /* Re-insert the EH_REGION notes. */
3044 if (note || (was_call && nonlocal_goto_handler_labels))
3046 edge eh_edge;
3047 edge_iterator ei;
3049 FOR_EACH_EDGE (eh_edge, ei, bb->succs)
3050 if (eh_edge->flags & (EDGE_EH | EDGE_ABNORMAL_CALL))
3051 break;
3053 for (x = try ; x != before_try ; x = PREV_INSN (x))
3054 if (CALL_P (x)
3055 || (flag_non_call_exceptions
3056 && may_trap_p (PATTERN (x))
3057 && !find_reg_note (x, REG_EH_REGION, NULL)))
3059 if (note)
3060 REG_NOTES (x)
3061 = gen_rtx_EXPR_LIST (REG_EH_REGION,
3062 XEXP (note, 0),
3063 REG_NOTES (x));
3065 if (x != BB_END (bb) && eh_edge)
3067 edge nfte, nehe;
3068 int flags;
3070 nfte = split_block (bb, x);
3071 flags = (eh_edge->flags
3072 & (EDGE_EH | EDGE_ABNORMAL));
3073 if (CALL_P (x))
3074 flags |= EDGE_ABNORMAL_CALL;
3075 nehe = make_edge (nfte->src, eh_edge->dest,
3076 flags);
3078 nehe->probability = eh_edge->probability;
3079 nfte->probability
3080 = REG_BR_PROB_BASE - nehe->probability;
3082 do_cleanup_cfg |= purge_dead_edges (nfte->dest);
3083 bb = nfte->src;
3084 eh_edge = nehe;
3088 /* Converting possibly trapping insn to non-trapping is
3089 possible. Zap dummy outgoing edges. */
3090 do_cleanup_cfg |= purge_dead_edges (bb);
3093 #ifdef HAVE_conditional_execution
3094 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3095 peep2_insn_data[i].insn = NULL_RTX;
3096 peep2_insn_data[peep2_current].insn = PEEP2_EOB;
3097 peep2_current_count = 0;
3098 #else
3099 /* Back up lifetime information past the end of the
3100 newly created sequence. */
3101 if (++i >= MAX_INSNS_PER_PEEP2 + 1)
3102 i = 0;
3103 bitmap_copy (live, peep2_insn_data[i].live_before);
3105 /* Update life information for the new sequence. */
3106 x = try;
3109 if (INSN_P (x))
3111 if (--i < 0)
3112 i = MAX_INSNS_PER_PEEP2;
3113 if (peep2_current_count < MAX_INSNS_PER_PEEP2
3114 && peep2_insn_data[i].insn == NULL_RTX)
3115 peep2_current_count++;
3116 peep2_insn_data[i].insn = x;
3117 df_insn_rescan (x);
3118 df_simulate_one_insn (bb, x, live);
3119 bitmap_copy (peep2_insn_data[i].live_before, live);
3121 x = PREV_INSN (x);
3123 while (x != prev);
3125 peep2_current = i;
3126 #endif
3128 /* If we generated a jump instruction, it won't have
3129 JUMP_LABEL set. Recompute after we're done. */
3130 for (x = try; x != before_try; x = PREV_INSN (x))
3131 if (JUMP_P (x))
3133 do_rebuild_jump_labels = true;
3134 break;
3139 if (insn == BB_HEAD (bb))
3140 break;
3144 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3145 BITMAP_FREE (peep2_insn_data[i].live_before);
3146 BITMAP_FREE (live);
3147 if (do_rebuild_jump_labels)
3148 rebuild_jump_labels (get_insns ());
3150 #endif /* HAVE_peephole2 */
3152 /* Common predicates for use with define_bypass. */
3154 /* True if the dependency between OUT_INSN and IN_INSN is on the store
3155 data not the address operand(s) of the store. IN_INSN and OUT_INSN
3156 must be either a single_set or a PARALLEL with SETs inside. */
3159 store_data_bypass_p (rtx out_insn, rtx in_insn)
3161 rtx out_set, in_set;
3162 rtx out_pat, in_pat;
3163 rtx out_exp, in_exp;
3164 int i, j;
3166 in_set = single_set (in_insn);
3167 if (in_set)
3169 if (!MEM_P (SET_DEST (in_set)))
3170 return false;
3172 out_set = single_set (out_insn);
3173 if (out_set)
3175 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_set)))
3176 return false;
3178 else
3180 out_pat = PATTERN (out_insn);
3182 if (GET_CODE (out_pat) != PARALLEL)
3183 return false;
3185 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3187 out_exp = XVECEXP (out_pat, 0, i);
3189 if (GET_CODE (out_exp) == CLOBBER)
3190 continue;
3192 gcc_assert (GET_CODE (out_exp) == SET);
3194 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_set)))
3195 return false;
3199 else
3201 in_pat = PATTERN (in_insn);
3202 gcc_assert (GET_CODE (in_pat) == PARALLEL);
3204 for (i = 0; i < XVECLEN (in_pat, 0); i++)
3206 in_exp = XVECEXP (in_pat, 0, i);
3208 if (GET_CODE (in_exp) == CLOBBER)
3209 continue;
3211 gcc_assert (GET_CODE (in_exp) == SET);
3213 if (!MEM_P (SET_DEST (in_exp)))
3214 return false;
3216 out_set = single_set (out_insn);
3217 if (out_set)
3219 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_exp)))
3220 return false;
3222 else
3224 out_pat = PATTERN (out_insn);
3225 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3227 for (j = 0; j < XVECLEN (out_pat, 0); j++)
3229 out_exp = XVECEXP (out_pat, 0, j);
3231 if (GET_CODE (out_exp) == CLOBBER)
3232 continue;
3234 gcc_assert (GET_CODE (out_exp) == SET);
3236 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_exp)))
3237 return false;
3243 return true;
3246 /* True if the dependency between OUT_INSN and IN_INSN is in the IF_THEN_ELSE
3247 condition, and not the THEN or ELSE branch. OUT_INSN may be either a single
3248 or multiple set; IN_INSN should be single_set for truth, but for convenience
3249 of insn categorization may be any JUMP or CALL insn. */
3252 if_test_bypass_p (rtx out_insn, rtx in_insn)
3254 rtx out_set, in_set;
3256 in_set = single_set (in_insn);
3257 if (! in_set)
3259 gcc_assert (JUMP_P (in_insn) || CALL_P (in_insn));
3260 return false;
3263 if (GET_CODE (SET_SRC (in_set)) != IF_THEN_ELSE)
3264 return false;
3265 in_set = SET_SRC (in_set);
3267 out_set = single_set (out_insn);
3268 if (out_set)
3270 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3271 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3272 return false;
3274 else
3276 rtx out_pat;
3277 int i;
3279 out_pat = PATTERN (out_insn);
3280 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3282 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3284 rtx exp = XVECEXP (out_pat, 0, i);
3286 if (GET_CODE (exp) == CLOBBER)
3287 continue;
3289 gcc_assert (GET_CODE (exp) == SET);
3291 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3292 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3293 return false;
3297 return true;
3300 static bool
3301 gate_handle_peephole2 (void)
3303 return (optimize > 0 && flag_peephole2);
3306 static unsigned int
3307 rest_of_handle_peephole2 (void)
3309 #ifdef HAVE_peephole2
3310 peephole2_optimize ();
3311 #endif
3312 return 0;
3315 struct rtl_opt_pass pass_peephole2 =
3318 RTL_PASS,
3319 "peephole2", /* name */
3320 gate_handle_peephole2, /* gate */
3321 rest_of_handle_peephole2, /* execute */
3322 NULL, /* sub */
3323 NULL, /* next */
3324 0, /* static_pass_number */
3325 TV_PEEPHOLE2, /* tv_id */
3326 0, /* properties_required */
3327 0, /* properties_provided */
3328 0, /* properties_destroyed */
3329 0, /* todo_flags_start */
3330 TODO_df_finish | TODO_verify_rtl_sharing |
3331 TODO_dump_func /* todo_flags_finish */
3335 static unsigned int
3336 rest_of_handle_split_all_insns (void)
3338 split_all_insns ();
3339 return 0;
3342 struct rtl_opt_pass pass_split_all_insns =
3345 RTL_PASS,
3346 "split1", /* name */
3347 NULL, /* gate */
3348 rest_of_handle_split_all_insns, /* execute */
3349 NULL, /* sub */
3350 NULL, /* next */
3351 0, /* static_pass_number */
3352 0, /* tv_id */
3353 0, /* properties_required */
3354 0, /* properties_provided */
3355 0, /* properties_destroyed */
3356 0, /* todo_flags_start */
3357 TODO_dump_func /* todo_flags_finish */
3361 static unsigned int
3362 rest_of_handle_split_after_reload (void)
3364 /* If optimizing, then go ahead and split insns now. */
3365 #ifndef STACK_REGS
3366 if (optimize > 0)
3367 #endif
3368 split_all_insns ();
3369 return 0;
3372 struct rtl_opt_pass pass_split_after_reload =
3375 RTL_PASS,
3376 "split2", /* name */
3377 NULL, /* gate */
3378 rest_of_handle_split_after_reload, /* execute */
3379 NULL, /* sub */
3380 NULL, /* next */
3381 0, /* static_pass_number */
3382 0, /* tv_id */
3383 0, /* properties_required */
3384 0, /* properties_provided */
3385 0, /* properties_destroyed */
3386 0, /* todo_flags_start */
3387 TODO_dump_func /* todo_flags_finish */
3391 static bool
3392 gate_handle_split_before_regstack (void)
3394 #if defined (HAVE_ATTR_length) && defined (STACK_REGS)
3395 /* If flow2 creates new instructions which need splitting
3396 and scheduling after reload is not done, they might not be
3397 split until final which doesn't allow splitting
3398 if HAVE_ATTR_length. */
3399 # ifdef INSN_SCHEDULING
3400 return (optimize && !flag_schedule_insns_after_reload);
3401 # else
3402 return (optimize);
3403 # endif
3404 #else
3405 return 0;
3406 #endif
3409 static unsigned int
3410 rest_of_handle_split_before_regstack (void)
3412 split_all_insns ();
3413 return 0;
3416 struct rtl_opt_pass pass_split_before_regstack =
3419 RTL_PASS,
3420 "split3", /* name */
3421 gate_handle_split_before_regstack, /* gate */
3422 rest_of_handle_split_before_regstack, /* execute */
3423 NULL, /* sub */
3424 NULL, /* next */
3425 0, /* static_pass_number */
3426 0, /* tv_id */
3427 0, /* properties_required */
3428 0, /* properties_provided */
3429 0, /* properties_destroyed */
3430 0, /* todo_flags_start */
3431 TODO_dump_func /* todo_flags_finish */
3435 static bool
3436 gate_handle_split_before_sched2 (void)
3438 #ifdef INSN_SCHEDULING
3439 return optimize > 0 && flag_schedule_insns_after_reload;
3440 #else
3441 return 0;
3442 #endif
3445 static unsigned int
3446 rest_of_handle_split_before_sched2 (void)
3448 #ifdef INSN_SCHEDULING
3449 split_all_insns ();
3450 #endif
3451 return 0;
3454 struct rtl_opt_pass pass_split_before_sched2 =
3457 RTL_PASS,
3458 "split4", /* name */
3459 gate_handle_split_before_sched2, /* gate */
3460 rest_of_handle_split_before_sched2, /* execute */
3461 NULL, /* sub */
3462 NULL, /* next */
3463 0, /* static_pass_number */
3464 0, /* tv_id */
3465 0, /* properties_required */
3466 0, /* properties_provided */
3467 0, /* properties_destroyed */
3468 0, /* todo_flags_start */
3469 TODO_verify_flow |
3470 TODO_dump_func /* todo_flags_finish */
3474 /* The placement of the splitting that we do for shorten_branches
3475 depends on whether regstack is used by the target or not. */
3476 static bool
3477 gate_do_final_split (void)
3479 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3480 return 1;
3481 #else
3482 return 0;
3483 #endif
3486 struct rtl_opt_pass pass_split_for_shorten_branches =
3489 RTL_PASS,
3490 "split5", /* name */
3491 gate_do_final_split, /* gate */
3492 split_all_insns_noflow, /* execute */
3493 NULL, /* sub */
3494 NULL, /* next */
3495 0, /* static_pass_number */
3496 0, /* tv_id */
3497 0, /* properties_required */
3498 0, /* properties_provided */
3499 0, /* properties_destroyed */
3500 0, /* todo_flags_start */
3501 TODO_dump_func | TODO_verify_rtl_sharing /* todo_flags_finish */