2012-08-01 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / gcc / recog.c
bloba05e8c608f7cd59c01e7ef0f5bbfaee77e4d4069
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, 2009, 2010
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-error.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 "basic-block.h"
39 #include "reload.h"
40 #include "target.h"
41 #include "tree-pass.h"
42 #include "df.h"
44 #ifndef STACK_PUSH_CODE
45 #ifdef STACK_GROWS_DOWNWARD
46 #define STACK_PUSH_CODE PRE_DEC
47 #else
48 #define STACK_PUSH_CODE PRE_INC
49 #endif
50 #endif
52 #ifndef STACK_POP_CODE
53 #ifdef STACK_GROWS_DOWNWARD
54 #define STACK_POP_CODE POST_INC
55 #else
56 #define STACK_POP_CODE POST_DEC
57 #endif
58 #endif
60 #ifndef HAVE_ATTR_enabled
61 static inline bool
62 get_attr_enabled (rtx insn ATTRIBUTE_UNUSED)
64 return true;
66 #endif
68 static void validate_replace_rtx_1 (rtx *, rtx, rtx, rtx, bool);
69 static void validate_replace_src_1 (rtx *, void *);
70 static rtx split_insn (rtx);
72 /* Nonzero means allow operands to be volatile.
73 This should be 0 if you are generating rtl, such as if you are calling
74 the functions in optabs.c and expmed.c (most of the time).
75 This should be 1 if all valid insns need to be recognized,
76 such as in reginfo.c and final.c and reload.c.
78 init_recog and init_recog_no_volatile are responsible for setting this. */
80 int volatile_ok;
82 struct recog_data recog_data;
84 /* Contains a vector of operand_alternative structures for every operand.
85 Set up by preprocess_constraints. */
86 struct operand_alternative recog_op_alt[MAX_RECOG_OPERANDS][MAX_RECOG_ALTERNATIVES];
88 /* On return from `constrain_operands', indicate which alternative
89 was satisfied. */
91 int which_alternative;
93 /* Nonzero after end of reload pass.
94 Set to 1 or 0 by toplev.c.
95 Controls the significance of (SUBREG (MEM)). */
97 int reload_completed;
99 /* Nonzero after thread_prologue_and_epilogue_insns has run. */
100 int epilogue_completed;
102 /* Initialize data used by the function `recog'.
103 This must be called once in the compilation of a function
104 before any insn recognition may be done in the function. */
106 void
107 init_recog_no_volatile (void)
109 volatile_ok = 0;
112 void
113 init_recog (void)
115 volatile_ok = 1;
119 /* Return true if labels in asm operands BODY are LABEL_REFs. */
121 static bool
122 asm_labels_ok (rtx body)
124 rtx asmop;
125 int i;
127 asmop = extract_asm_operands (body);
128 if (asmop == NULL_RTX)
129 return true;
131 for (i = 0; i < ASM_OPERANDS_LABEL_LENGTH (asmop); i++)
132 if (GET_CODE (ASM_OPERANDS_LABEL (asmop, i)) != LABEL_REF)
133 return false;
135 return true;
138 /* Check that X is an insn-body for an `asm' with operands
139 and that the operands mentioned in it are legitimate. */
142 check_asm_operands (rtx x)
144 int noperands;
145 rtx *operands;
146 const char **constraints;
147 int i;
149 if (!asm_labels_ok (x))
150 return 0;
152 /* Post-reload, be more strict with things. */
153 if (reload_completed)
155 /* ??? Doh! We've not got the wrapping insn. Cook one up. */
156 extract_insn (make_insn_raw (x));
157 constrain_operands (1);
158 return which_alternative >= 0;
161 noperands = asm_noperands (x);
162 if (noperands < 0)
163 return 0;
164 if (noperands == 0)
165 return 1;
167 operands = XALLOCAVEC (rtx, noperands);
168 constraints = XALLOCAVEC (const char *, noperands);
170 decode_asm_operands (x, operands, NULL, constraints, NULL, NULL);
172 for (i = 0; i < noperands; i++)
174 const char *c = constraints[i];
175 if (c[0] == '%')
176 c++;
177 if (! asm_operand_ok (operands[i], c, constraints))
178 return 0;
181 return 1;
184 /* Static data for the next two routines. */
186 typedef struct change_t
188 rtx object;
189 int old_code;
190 rtx *loc;
191 rtx old;
192 bool unshare;
193 } change_t;
195 static change_t *changes;
196 static int changes_allocated;
198 static int num_changes = 0;
200 /* Validate a proposed change to OBJECT. LOC is the location in the rtl
201 at which NEW_RTX will be placed. If OBJECT is zero, no validation is done,
202 the change is simply made.
204 Two types of objects are supported: If OBJECT is a MEM, memory_address_p
205 will be called with the address and mode as parameters. If OBJECT is
206 an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
207 the change in place.
209 IN_GROUP is nonzero if this is part of a group of changes that must be
210 performed as a group. In that case, the changes will be stored. The
211 function `apply_change_group' will validate and apply the changes.
213 If IN_GROUP is zero, this is a single change. Try to recognize the insn
214 or validate the memory reference with the change applied. If the result
215 is not valid for the machine, suppress the change and return zero.
216 Otherwise, perform the change and return 1. */
218 static bool
219 validate_change_1 (rtx object, rtx *loc, rtx new_rtx, bool in_group, bool unshare)
221 rtx old = *loc;
223 if (old == new_rtx || rtx_equal_p (old, new_rtx))
224 return 1;
226 gcc_assert (in_group != 0 || num_changes == 0);
228 *loc = new_rtx;
230 /* Save the information describing this change. */
231 if (num_changes >= changes_allocated)
233 if (changes_allocated == 0)
234 /* This value allows for repeated substitutions inside complex
235 indexed addresses, or changes in up to 5 insns. */
236 changes_allocated = MAX_RECOG_OPERANDS * 5;
237 else
238 changes_allocated *= 2;
240 changes = XRESIZEVEC (change_t, changes, changes_allocated);
243 changes[num_changes].object = object;
244 changes[num_changes].loc = loc;
245 changes[num_changes].old = old;
246 changes[num_changes].unshare = unshare;
248 if (object && !MEM_P (object))
250 /* Set INSN_CODE to force rerecognition of insn. Save old code in
251 case invalid. */
252 changes[num_changes].old_code = INSN_CODE (object);
253 INSN_CODE (object) = -1;
256 num_changes++;
258 /* If we are making a group of changes, return 1. Otherwise, validate the
259 change group we made. */
261 if (in_group)
262 return 1;
263 else
264 return apply_change_group ();
267 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
268 UNSHARE to false. */
270 bool
271 validate_change (rtx object, rtx *loc, rtx new_rtx, bool in_group)
273 return validate_change_1 (object, loc, new_rtx, in_group, false);
276 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
277 UNSHARE to true. */
279 bool
280 validate_unshare_change (rtx object, rtx *loc, rtx new_rtx, bool in_group)
282 return validate_change_1 (object, loc, new_rtx, in_group, true);
286 /* Keep X canonicalized if some changes have made it non-canonical; only
287 modifies the operands of X, not (for example) its code. Simplifications
288 are not the job of this routine.
290 Return true if anything was changed. */
291 bool
292 canonicalize_change_group (rtx insn, rtx x)
294 if (COMMUTATIVE_P (x)
295 && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
297 /* Oops, the caller has made X no longer canonical.
298 Let's redo the changes in the correct order. */
299 rtx tem = XEXP (x, 0);
300 validate_unshare_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
301 validate_unshare_change (insn, &XEXP (x, 1), tem, 1);
302 return true;
304 else
305 return false;
309 /* This subroutine of apply_change_group verifies whether the changes to INSN
310 were valid; i.e. whether INSN can still be recognized.
312 If IN_GROUP is true clobbers which have to be added in order to
313 match the instructions will be added to the current change group.
314 Otherwise the changes will take effect immediately. */
317 insn_invalid_p (rtx insn, bool in_group)
319 rtx pat = PATTERN (insn);
320 int num_clobbers = 0;
321 /* If we are before reload and the pattern is a SET, see if we can add
322 clobbers. */
323 int icode = recog (pat, insn,
324 (GET_CODE (pat) == SET
325 && ! reload_completed && ! reload_in_progress)
326 ? &num_clobbers : 0);
327 int is_asm = icode < 0 && asm_noperands (PATTERN (insn)) >= 0;
330 /* If this is an asm and the operand aren't legal, then fail. Likewise if
331 this is not an asm and the insn wasn't recognized. */
332 if ((is_asm && ! check_asm_operands (PATTERN (insn)))
333 || (!is_asm && icode < 0))
334 return 1;
336 /* If we have to add CLOBBERs, fail if we have to add ones that reference
337 hard registers since our callers can't know if they are live or not.
338 Otherwise, add them. */
339 if (num_clobbers > 0)
341 rtx newpat;
343 if (added_clobbers_hard_reg_p (icode))
344 return 1;
346 newpat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_clobbers + 1));
347 XVECEXP (newpat, 0, 0) = pat;
348 add_clobbers (newpat, icode);
349 if (in_group)
350 validate_change (insn, &PATTERN (insn), newpat, 1);
351 else
352 PATTERN (insn) = pat = newpat;
355 /* After reload, verify that all constraints are satisfied. */
356 if (reload_completed)
358 extract_insn (insn);
360 if (! constrain_operands (1))
361 return 1;
364 INSN_CODE (insn) = icode;
365 return 0;
368 /* Return number of changes made and not validated yet. */
370 num_changes_pending (void)
372 return num_changes;
375 /* Tentatively apply the changes numbered NUM and up.
376 Return 1 if all changes are valid, zero otherwise. */
379 verify_changes (int num)
381 int i;
382 rtx last_validated = NULL_RTX;
384 /* The changes have been applied and all INSN_CODEs have been reset to force
385 rerecognition.
387 The changes are valid if we aren't given an object, or if we are
388 given a MEM and it still is a valid address, or if this is in insn
389 and it is recognized. In the latter case, if reload has completed,
390 we also require that the operands meet the constraints for
391 the insn. */
393 for (i = num; i < num_changes; i++)
395 rtx object = changes[i].object;
397 /* If there is no object to test or if it is the same as the one we
398 already tested, ignore it. */
399 if (object == 0 || object == last_validated)
400 continue;
402 if (MEM_P (object))
404 if (! memory_address_addr_space_p (GET_MODE (object),
405 XEXP (object, 0),
406 MEM_ADDR_SPACE (object)))
407 break;
409 else if (REG_P (changes[i].old)
410 && asm_noperands (PATTERN (object)) > 0
411 && REG_EXPR (changes[i].old) != NULL_TREE
412 && DECL_ASSEMBLER_NAME_SET_P (REG_EXPR (changes[i].old))
413 && DECL_REGISTER (REG_EXPR (changes[i].old)))
415 /* Don't allow changes of hard register operands to inline
416 assemblies if they have been defined as register asm ("x"). */
417 break;
419 else if (DEBUG_INSN_P (object))
420 continue;
421 else if (insn_invalid_p (object, true))
423 rtx pat = PATTERN (object);
425 /* Perhaps we couldn't recognize the insn because there were
426 extra CLOBBERs at the end. If so, try to re-recognize
427 without the last CLOBBER (later iterations will cause each of
428 them to be eliminated, in turn). But don't do this if we
429 have an ASM_OPERAND. */
430 if (GET_CODE (pat) == PARALLEL
431 && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
432 && asm_noperands (PATTERN (object)) < 0)
434 rtx newpat;
436 if (XVECLEN (pat, 0) == 2)
437 newpat = XVECEXP (pat, 0, 0);
438 else
440 int j;
442 newpat
443 = gen_rtx_PARALLEL (VOIDmode,
444 rtvec_alloc (XVECLEN (pat, 0) - 1));
445 for (j = 0; j < XVECLEN (newpat, 0); j++)
446 XVECEXP (newpat, 0, j) = XVECEXP (pat, 0, j);
449 /* Add a new change to this group to replace the pattern
450 with this new pattern. Then consider this change
451 as having succeeded. The change we added will
452 cause the entire call to fail if things remain invalid.
454 Note that this can lose if a later change than the one
455 we are processing specified &XVECEXP (PATTERN (object), 0, X)
456 but this shouldn't occur. */
458 validate_change (object, &PATTERN (object), newpat, 1);
459 continue;
461 else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER
462 || GET_CODE (pat) == VAR_LOCATION)
463 /* If this insn is a CLOBBER or USE, it is always valid, but is
464 never recognized. */
465 continue;
466 else
467 break;
469 last_validated = object;
472 return (i == num_changes);
475 /* A group of changes has previously been issued with validate_change
476 and verified with verify_changes. Call df_insn_rescan for each of
477 the insn changed and clear num_changes. */
479 void
480 confirm_change_group (void)
482 int i;
483 rtx last_object = NULL;
485 for (i = 0; i < num_changes; i++)
487 rtx object = changes[i].object;
489 if (changes[i].unshare)
490 *changes[i].loc = copy_rtx (*changes[i].loc);
492 /* Avoid unnecessary rescanning when multiple changes to same instruction
493 are made. */
494 if (object)
496 if (object != last_object && last_object && INSN_P (last_object))
497 df_insn_rescan (last_object);
498 last_object = object;
502 if (last_object && INSN_P (last_object))
503 df_insn_rescan (last_object);
504 num_changes = 0;
507 /* Apply a group of changes previously issued with `validate_change'.
508 If all changes are valid, call confirm_change_group and return 1,
509 otherwise, call cancel_changes and return 0. */
512 apply_change_group (void)
514 if (verify_changes (0))
516 confirm_change_group ();
517 return 1;
519 else
521 cancel_changes (0);
522 return 0;
527 /* Return the number of changes so far in the current group. */
530 num_validated_changes (void)
532 return num_changes;
535 /* Retract the changes numbered NUM and up. */
537 void
538 cancel_changes (int num)
540 int i;
542 /* Back out all the changes. Do this in the opposite order in which
543 they were made. */
544 for (i = num_changes - 1; i >= num; i--)
546 *changes[i].loc = changes[i].old;
547 if (changes[i].object && !MEM_P (changes[i].object))
548 INSN_CODE (changes[i].object) = changes[i].old_code;
550 num_changes = num;
553 /* A subroutine of validate_replace_rtx_1 that tries to simplify the resulting
554 rtx. */
556 static void
557 simplify_while_replacing (rtx *loc, rtx to, rtx object,
558 enum machine_mode op0_mode)
560 rtx x = *loc;
561 enum rtx_code code = GET_CODE (x);
562 rtx new_rtx;
564 if (SWAPPABLE_OPERANDS_P (x)
565 && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
567 validate_unshare_change (object, loc,
568 gen_rtx_fmt_ee (COMMUTATIVE_ARITH_P (x) ? code
569 : swap_condition (code),
570 GET_MODE (x), XEXP (x, 1),
571 XEXP (x, 0)), 1);
572 x = *loc;
573 code = GET_CODE (x);
576 switch (code)
578 case PLUS:
579 /* If we have a PLUS whose second operand is now a CONST_INT, use
580 simplify_gen_binary to try to simplify it.
581 ??? We may want later to remove this, once simplification is
582 separated from this function. */
583 if (CONST_INT_P (XEXP (x, 1)) && XEXP (x, 1) == to)
584 validate_change (object, loc,
585 simplify_gen_binary
586 (PLUS, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)), 1);
587 break;
588 case MINUS:
589 if (CONST_INT_P (XEXP (x, 1))
590 || GET_CODE (XEXP (x, 1)) == CONST_DOUBLE)
591 validate_change (object, loc,
592 simplify_gen_binary
593 (PLUS, GET_MODE (x), XEXP (x, 0),
594 simplify_gen_unary (NEG,
595 GET_MODE (x), XEXP (x, 1),
596 GET_MODE (x))), 1);
597 break;
598 case ZERO_EXTEND:
599 case SIGN_EXTEND:
600 if (GET_MODE (XEXP (x, 0)) == VOIDmode)
602 new_rtx = simplify_gen_unary (code, GET_MODE (x), XEXP (x, 0),
603 op0_mode);
604 /* If any of the above failed, substitute in something that
605 we know won't be recognized. */
606 if (!new_rtx)
607 new_rtx = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
608 validate_change (object, loc, new_rtx, 1);
610 break;
611 case SUBREG:
612 /* All subregs possible to simplify should be simplified. */
613 new_rtx = simplify_subreg (GET_MODE (x), SUBREG_REG (x), op0_mode,
614 SUBREG_BYTE (x));
616 /* Subregs of VOIDmode operands are incorrect. */
617 if (!new_rtx && GET_MODE (SUBREG_REG (x)) == VOIDmode)
618 new_rtx = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
619 if (new_rtx)
620 validate_change (object, loc, new_rtx, 1);
621 break;
622 case ZERO_EXTRACT:
623 case SIGN_EXTRACT:
624 /* If we are replacing a register with memory, try to change the memory
625 to be the mode required for memory in extract operations (this isn't
626 likely to be an insertion operation; if it was, nothing bad will
627 happen, we might just fail in some cases). */
629 if (MEM_P (XEXP (x, 0))
630 && CONST_INT_P (XEXP (x, 1))
631 && CONST_INT_P (XEXP (x, 2))
632 && !mode_dependent_address_p (XEXP (XEXP (x, 0), 0))
633 && !MEM_VOLATILE_P (XEXP (x, 0)))
635 enum machine_mode wanted_mode = VOIDmode;
636 enum machine_mode is_mode = GET_MODE (XEXP (x, 0));
637 int pos = INTVAL (XEXP (x, 2));
639 if (GET_CODE (x) == ZERO_EXTRACT)
641 enum machine_mode new_mode
642 = mode_for_extraction (EP_extzv, 1);
643 if (new_mode != MAX_MACHINE_MODE)
644 wanted_mode = new_mode;
646 else if (GET_CODE (x) == SIGN_EXTRACT)
648 enum machine_mode new_mode
649 = mode_for_extraction (EP_extv, 1);
650 if (new_mode != MAX_MACHINE_MODE)
651 wanted_mode = new_mode;
654 /* If we have a narrower mode, we can do something. */
655 if (wanted_mode != VOIDmode
656 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
658 int offset = pos / BITS_PER_UNIT;
659 rtx newmem;
661 /* If the bytes and bits are counted differently, we
662 must adjust the offset. */
663 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
664 offset =
665 (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode) -
666 offset);
668 gcc_assert (GET_MODE_PRECISION (wanted_mode)
669 == GET_MODE_BITSIZE (wanted_mode));
670 pos %= GET_MODE_BITSIZE (wanted_mode);
672 newmem = adjust_address_nv (XEXP (x, 0), wanted_mode, offset);
674 validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
675 validate_change (object, &XEXP (x, 0), newmem, 1);
679 break;
681 default:
682 break;
686 /* Replace every occurrence of FROM in X with TO. Mark each change with
687 validate_change passing OBJECT. */
689 static void
690 validate_replace_rtx_1 (rtx *loc, rtx from, rtx to, rtx object,
691 bool simplify)
693 int i, j;
694 const char *fmt;
695 rtx x = *loc;
696 enum rtx_code code;
697 enum machine_mode op0_mode = VOIDmode;
698 int prev_changes = num_changes;
700 if (!x)
701 return;
703 code = GET_CODE (x);
704 fmt = GET_RTX_FORMAT (code);
705 if (fmt[0] == 'e')
706 op0_mode = GET_MODE (XEXP (x, 0));
708 /* X matches FROM if it is the same rtx or they are both referring to the
709 same register in the same mode. Avoid calling rtx_equal_p unless the
710 operands look similar. */
712 if (x == from
713 || (REG_P (x) && REG_P (from)
714 && GET_MODE (x) == GET_MODE (from)
715 && REGNO (x) == REGNO (from))
716 || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
717 && rtx_equal_p (x, from)))
719 validate_unshare_change (object, loc, to, 1);
720 return;
723 /* Call ourself recursively to perform the replacements.
724 We must not replace inside already replaced expression, otherwise we
725 get infinite recursion for replacements like (reg X)->(subreg (reg X))
726 done by regmove, so we must special case shared ASM_OPERANDS. */
728 if (GET_CODE (x) == PARALLEL)
730 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
732 if (j && GET_CODE (XVECEXP (x, 0, j)) == SET
733 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == ASM_OPERANDS)
735 /* Verify that operands are really shared. */
736 gcc_assert (ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (x, 0, 0)))
737 == ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP
738 (x, 0, j))));
739 validate_replace_rtx_1 (&SET_DEST (XVECEXP (x, 0, j)),
740 from, to, object, simplify);
742 else
743 validate_replace_rtx_1 (&XVECEXP (x, 0, j), from, to, object,
744 simplify);
747 else
748 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
750 if (fmt[i] == 'e')
751 validate_replace_rtx_1 (&XEXP (x, i), from, to, object, simplify);
752 else if (fmt[i] == 'E')
753 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
754 validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object,
755 simplify);
758 /* If we didn't substitute, there is nothing more to do. */
759 if (num_changes == prev_changes)
760 return;
762 /* Allow substituted expression to have different mode. This is used by
763 regmove to change mode of pseudo register. */
764 if (fmt[0] == 'e' && GET_MODE (XEXP (x, 0)) != VOIDmode)
765 op0_mode = GET_MODE (XEXP (x, 0));
767 /* Do changes needed to keep rtx consistent. Don't do any other
768 simplifications, as it is not our job. */
769 if (simplify)
770 simplify_while_replacing (loc, to, object, op0_mode);
773 /* Try replacing every occurrence of FROM in subexpression LOC of INSN
774 with TO. After all changes have been made, validate by seeing
775 if INSN is still valid. */
778 validate_replace_rtx_subexp (rtx from, rtx to, rtx insn, rtx *loc)
780 validate_replace_rtx_1 (loc, from, to, insn, true);
781 return apply_change_group ();
784 /* Try replacing every occurrence of FROM in INSN with TO. After all
785 changes have been made, validate by seeing if INSN is still valid. */
788 validate_replace_rtx (rtx from, rtx to, rtx insn)
790 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn, true);
791 return apply_change_group ();
794 /* Try replacing every occurrence of FROM in WHERE with TO. Assume that WHERE
795 is a part of INSN. After all changes have been made, validate by seeing if
796 INSN is still valid.
797 validate_replace_rtx (from, to, insn) is equivalent to
798 validate_replace_rtx_part (from, to, &PATTERN (insn), insn). */
801 validate_replace_rtx_part (rtx from, rtx to, rtx *where, rtx insn)
803 validate_replace_rtx_1 (where, from, to, insn, true);
804 return apply_change_group ();
807 /* Same as above, but do not simplify rtx afterwards. */
809 validate_replace_rtx_part_nosimplify (rtx from, rtx to, rtx *where,
810 rtx insn)
812 validate_replace_rtx_1 (where, from, to, insn, false);
813 return apply_change_group ();
817 /* Try replacing every occurrence of FROM in INSN with TO. This also
818 will replace in REG_EQUAL and REG_EQUIV notes. */
820 void
821 validate_replace_rtx_group (rtx from, rtx to, rtx insn)
823 rtx note;
824 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn, true);
825 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
826 if (REG_NOTE_KIND (note) == REG_EQUAL
827 || REG_NOTE_KIND (note) == REG_EQUIV)
828 validate_replace_rtx_1 (&XEXP (note, 0), from, to, insn, true);
831 /* Function called by note_uses to replace used subexpressions. */
832 struct validate_replace_src_data
834 rtx from; /* Old RTX */
835 rtx to; /* New RTX */
836 rtx insn; /* Insn in which substitution is occurring. */
839 static void
840 validate_replace_src_1 (rtx *x, void *data)
842 struct validate_replace_src_data *d
843 = (struct validate_replace_src_data *) data;
845 validate_replace_rtx_1 (x, d->from, d->to, d->insn, true);
848 /* Try replacing every occurrence of FROM in INSN with TO, avoiding
849 SET_DESTs. */
851 void
852 validate_replace_src_group (rtx from, rtx to, rtx insn)
854 struct validate_replace_src_data d;
856 d.from = from;
857 d.to = to;
858 d.insn = insn;
859 note_uses (&PATTERN (insn), validate_replace_src_1, &d);
862 /* Try simplify INSN.
863 Invoke simplify_rtx () on every SET_SRC and SET_DEST inside the INSN's
864 pattern and return true if something was simplified. */
866 bool
867 validate_simplify_insn (rtx insn)
869 int i;
870 rtx pat = NULL;
871 rtx newpat = NULL;
873 pat = PATTERN (insn);
875 if (GET_CODE (pat) == SET)
877 newpat = simplify_rtx (SET_SRC (pat));
878 if (newpat && !rtx_equal_p (SET_SRC (pat), newpat))
879 validate_change (insn, &SET_SRC (pat), newpat, 1);
880 newpat = simplify_rtx (SET_DEST (pat));
881 if (newpat && !rtx_equal_p (SET_DEST (pat), newpat))
882 validate_change (insn, &SET_DEST (pat), newpat, 1);
884 else if (GET_CODE (pat) == PARALLEL)
885 for (i = 0; i < XVECLEN (pat, 0); i++)
887 rtx s = XVECEXP (pat, 0, i);
889 if (GET_CODE (XVECEXP (pat, 0, i)) == SET)
891 newpat = simplify_rtx (SET_SRC (s));
892 if (newpat && !rtx_equal_p (SET_SRC (s), newpat))
893 validate_change (insn, &SET_SRC (s), newpat, 1);
894 newpat = simplify_rtx (SET_DEST (s));
895 if (newpat && !rtx_equal_p (SET_DEST (s), newpat))
896 validate_change (insn, &SET_DEST (s), newpat, 1);
899 return ((num_changes_pending () > 0) && (apply_change_group () > 0));
902 #ifdef HAVE_cc0
903 /* Return 1 if the insn using CC0 set by INSN does not contain
904 any ordered tests applied to the condition codes.
905 EQ and NE tests do not count. */
908 next_insn_tests_no_inequality (rtx insn)
910 rtx next = next_cc0_user (insn);
912 /* If there is no next insn, we have to take the conservative choice. */
913 if (next == 0)
914 return 0;
916 return (INSN_P (next)
917 && ! inequality_comparisons_p (PATTERN (next)));
919 #endif
921 /* Return 1 if OP is a valid general operand for machine mode MODE.
922 This is either a register reference, a memory reference,
923 or a constant. In the case of a memory reference, the address
924 is checked for general validity for the target machine.
926 Register and memory references must have mode MODE in order to be valid,
927 but some constants have no machine mode and are valid for any mode.
929 If MODE is VOIDmode, OP is checked for validity for whatever mode
930 it has.
932 The main use of this function is as a predicate in match_operand
933 expressions in the machine description. */
936 general_operand (rtx op, enum machine_mode mode)
938 enum rtx_code code = GET_CODE (op);
940 if (mode == VOIDmode)
941 mode = GET_MODE (op);
943 /* Don't accept CONST_INT or anything similar
944 if the caller wants something floating. */
945 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
946 && GET_MODE_CLASS (mode) != MODE_INT
947 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
948 return 0;
950 if (CONST_INT_P (op)
951 && mode != VOIDmode
952 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
953 return 0;
955 if (CONSTANT_P (op))
956 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
957 || mode == VOIDmode)
958 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
959 && targetm.legitimate_constant_p (mode == VOIDmode
960 ? GET_MODE (op)
961 : mode, op));
963 /* Except for certain constants with VOIDmode, already checked for,
964 OP's mode must match MODE if MODE specifies a mode. */
966 if (GET_MODE (op) != mode)
967 return 0;
969 if (code == SUBREG)
971 rtx sub = SUBREG_REG (op);
973 #ifdef INSN_SCHEDULING
974 /* On machines that have insn scheduling, we want all memory
975 reference to be explicit, so outlaw paradoxical SUBREGs.
976 However, we must allow them after reload so that they can
977 get cleaned up by cleanup_subreg_operands. */
978 if (!reload_completed && MEM_P (sub)
979 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (sub)))
980 return 0;
981 #endif
982 /* Avoid memories with nonzero SUBREG_BYTE, as offsetting the memory
983 may result in incorrect reference. We should simplify all valid
984 subregs of MEM anyway. But allow this after reload because we
985 might be called from cleanup_subreg_operands.
987 ??? This is a kludge. */
988 if (!reload_completed && SUBREG_BYTE (op) != 0
989 && MEM_P (sub))
990 return 0;
992 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
993 create such rtl, and we must reject it. */
994 if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
995 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
996 return 0;
998 op = sub;
999 code = GET_CODE (op);
1002 if (code == REG)
1003 return (REGNO (op) >= FIRST_PSEUDO_REGISTER
1004 || in_hard_reg_set_p (operand_reg_set, GET_MODE (op), REGNO (op)));
1006 if (code == MEM)
1008 rtx y = XEXP (op, 0);
1010 if (! volatile_ok && MEM_VOLATILE_P (op))
1011 return 0;
1013 /* Use the mem's mode, since it will be reloaded thus. */
1014 if (memory_address_addr_space_p (GET_MODE (op), y, MEM_ADDR_SPACE (op)))
1015 return 1;
1018 return 0;
1021 /* Return 1 if OP is a valid memory address for a memory reference
1022 of mode MODE.
1024 The main use of this function is as a predicate in match_operand
1025 expressions in the machine description. */
1028 address_operand (rtx op, enum machine_mode mode)
1030 return memory_address_p (mode, op);
1033 /* Return 1 if OP is a register reference of mode MODE.
1034 If MODE is VOIDmode, accept a register in any mode.
1036 The main use of this function is as a predicate in match_operand
1037 expressions in the machine description. */
1040 register_operand (rtx op, enum machine_mode mode)
1042 if (GET_MODE (op) != mode && mode != VOIDmode)
1043 return 0;
1045 if (GET_CODE (op) == SUBREG)
1047 rtx sub = SUBREG_REG (op);
1049 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1050 because it is guaranteed to be reloaded into one.
1051 Just make sure the MEM is valid in itself.
1052 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1053 but currently it does result from (SUBREG (REG)...) where the
1054 reg went on the stack.) */
1055 if (! reload_completed && MEM_P (sub))
1056 return general_operand (op, mode);
1058 #ifdef CANNOT_CHANGE_MODE_CLASS
1059 if (REG_P (sub)
1060 && REGNO (sub) < FIRST_PSEUDO_REGISTER
1061 && REG_CANNOT_CHANGE_MODE_P (REGNO (sub), GET_MODE (sub), mode)
1062 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_INT
1063 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_FLOAT)
1064 return 0;
1065 #endif
1067 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
1068 create such rtl, and we must reject it. */
1069 if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
1070 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
1071 return 0;
1073 op = sub;
1076 return (REG_P (op)
1077 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1078 || in_hard_reg_set_p (operand_reg_set,
1079 GET_MODE (op), REGNO (op))));
1082 /* Return 1 for a register in Pmode; ignore the tested mode. */
1085 pmode_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1087 return register_operand (op, Pmode);
1090 /* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
1091 or a hard register. */
1094 scratch_operand (rtx op, enum machine_mode mode)
1096 if (GET_MODE (op) != mode && mode != VOIDmode)
1097 return 0;
1099 return (GET_CODE (op) == SCRATCH
1100 || (REG_P (op)
1101 && REGNO (op) < FIRST_PSEUDO_REGISTER));
1104 /* Return 1 if OP is a valid immediate operand for mode MODE.
1106 The main use of this function is as a predicate in match_operand
1107 expressions in the machine description. */
1110 immediate_operand (rtx op, enum machine_mode mode)
1112 /* Don't accept CONST_INT or anything similar
1113 if the caller wants something floating. */
1114 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1115 && GET_MODE_CLASS (mode) != MODE_INT
1116 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1117 return 0;
1119 if (CONST_INT_P (op)
1120 && mode != VOIDmode
1121 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1122 return 0;
1124 return (CONSTANT_P (op)
1125 && (GET_MODE (op) == mode || mode == VOIDmode
1126 || GET_MODE (op) == VOIDmode)
1127 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1128 && targetm.legitimate_constant_p (mode == VOIDmode
1129 ? GET_MODE (op)
1130 : mode, op));
1133 /* Returns 1 if OP is an operand that is a CONST_INT. */
1136 const_int_operand (rtx op, enum machine_mode mode)
1138 if (!CONST_INT_P (op))
1139 return 0;
1141 if (mode != VOIDmode
1142 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1143 return 0;
1145 return 1;
1148 /* Returns 1 if OP is an operand that is a constant integer or constant
1149 floating-point number. */
1152 const_double_operand (rtx op, enum machine_mode mode)
1154 /* Don't accept CONST_INT or anything similar
1155 if the caller wants something floating. */
1156 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1157 && GET_MODE_CLASS (mode) != MODE_INT
1158 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1159 return 0;
1161 return ((GET_CODE (op) == CONST_DOUBLE || CONST_INT_P (op))
1162 && (mode == VOIDmode || GET_MODE (op) == mode
1163 || GET_MODE (op) == VOIDmode));
1166 /* Return 1 if OP is a general operand that is not an immediate operand. */
1169 nonimmediate_operand (rtx op, enum machine_mode mode)
1171 return (general_operand (op, mode) && ! CONSTANT_P (op));
1174 /* Return 1 if OP is a register reference or immediate value of mode MODE. */
1177 nonmemory_operand (rtx op, enum machine_mode mode)
1179 if (CONSTANT_P (op))
1180 return immediate_operand (op, mode);
1182 if (GET_MODE (op) != mode && mode != VOIDmode)
1183 return 0;
1185 if (GET_CODE (op) == SUBREG)
1187 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1188 because it is guaranteed to be reloaded into one.
1189 Just make sure the MEM is valid in itself.
1190 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1191 but currently it does result from (SUBREG (REG)...) where the
1192 reg went on the stack.) */
1193 if (! reload_completed && MEM_P (SUBREG_REG (op)))
1194 return general_operand (op, mode);
1195 op = SUBREG_REG (op);
1198 return (REG_P (op)
1199 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1200 || in_hard_reg_set_p (operand_reg_set,
1201 GET_MODE (op), REGNO (op))));
1204 /* Return 1 if OP is a valid operand that stands for pushing a
1205 value of mode MODE onto the stack.
1207 The main use of this function is as a predicate in match_operand
1208 expressions in the machine description. */
1211 push_operand (rtx op, enum machine_mode mode)
1213 unsigned int rounded_size = GET_MODE_SIZE (mode);
1215 #ifdef PUSH_ROUNDING
1216 rounded_size = PUSH_ROUNDING (rounded_size);
1217 #endif
1219 if (!MEM_P (op))
1220 return 0;
1222 if (mode != VOIDmode && GET_MODE (op) != mode)
1223 return 0;
1225 op = XEXP (op, 0);
1227 if (rounded_size == GET_MODE_SIZE (mode))
1229 if (GET_CODE (op) != STACK_PUSH_CODE)
1230 return 0;
1232 else
1234 if (GET_CODE (op) != PRE_MODIFY
1235 || GET_CODE (XEXP (op, 1)) != PLUS
1236 || XEXP (XEXP (op, 1), 0) != XEXP (op, 0)
1237 || !CONST_INT_P (XEXP (XEXP (op, 1), 1))
1238 #ifdef STACK_GROWS_DOWNWARD
1239 || INTVAL (XEXP (XEXP (op, 1), 1)) != - (int) rounded_size
1240 #else
1241 || INTVAL (XEXP (XEXP (op, 1), 1)) != (int) rounded_size
1242 #endif
1244 return 0;
1247 return XEXP (op, 0) == stack_pointer_rtx;
1250 /* Return 1 if OP is a valid operand that stands for popping a
1251 value of mode MODE off the stack.
1253 The main use of this function is as a predicate in match_operand
1254 expressions in the machine description. */
1257 pop_operand (rtx op, enum machine_mode mode)
1259 if (!MEM_P (op))
1260 return 0;
1262 if (mode != VOIDmode && GET_MODE (op) != mode)
1263 return 0;
1265 op = XEXP (op, 0);
1267 if (GET_CODE (op) != STACK_POP_CODE)
1268 return 0;
1270 return XEXP (op, 0) == stack_pointer_rtx;
1273 /* Return 1 if ADDR is a valid memory address
1274 for mode MODE in address space AS. */
1277 memory_address_addr_space_p (enum machine_mode mode ATTRIBUTE_UNUSED,
1278 rtx addr, addr_space_t as)
1280 #ifdef GO_IF_LEGITIMATE_ADDRESS
1281 gcc_assert (ADDR_SPACE_GENERIC_P (as));
1282 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1283 return 0;
1285 win:
1286 return 1;
1287 #else
1288 return targetm.addr_space.legitimate_address_p (mode, addr, 0, as);
1289 #endif
1292 /* Return 1 if OP is a valid memory reference with mode MODE,
1293 including a valid address.
1295 The main use of this function is as a predicate in match_operand
1296 expressions in the machine description. */
1299 memory_operand (rtx op, enum machine_mode mode)
1301 rtx inner;
1303 if (! reload_completed)
1304 /* Note that no SUBREG is a memory operand before end of reload pass,
1305 because (SUBREG (MEM...)) forces reloading into a register. */
1306 return MEM_P (op) && general_operand (op, mode);
1308 if (mode != VOIDmode && GET_MODE (op) != mode)
1309 return 0;
1311 inner = op;
1312 if (GET_CODE (inner) == SUBREG)
1313 inner = SUBREG_REG (inner);
1315 return (MEM_P (inner) && general_operand (op, mode));
1318 /* Return 1 if OP is a valid indirect memory reference with mode MODE;
1319 that is, a memory reference whose address is a general_operand. */
1322 indirect_operand (rtx op, enum machine_mode mode)
1324 /* Before reload, a SUBREG isn't in memory (see memory_operand, above). */
1325 if (! reload_completed
1326 && GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))
1328 int offset = SUBREG_BYTE (op);
1329 rtx inner = SUBREG_REG (op);
1331 if (mode != VOIDmode && GET_MODE (op) != mode)
1332 return 0;
1334 /* The only way that we can have a general_operand as the resulting
1335 address is if OFFSET is zero and the address already is an operand
1336 or if the address is (plus Y (const_int -OFFSET)) and Y is an
1337 operand. */
1339 return ((offset == 0 && general_operand (XEXP (inner, 0), Pmode))
1340 || (GET_CODE (XEXP (inner, 0)) == PLUS
1341 && CONST_INT_P (XEXP (XEXP (inner, 0), 1))
1342 && INTVAL (XEXP (XEXP (inner, 0), 1)) == -offset
1343 && general_operand (XEXP (XEXP (inner, 0), 0), Pmode)));
1346 return (MEM_P (op)
1347 && memory_operand (op, mode)
1348 && general_operand (XEXP (op, 0), Pmode));
1351 /* Return 1 if this is an ordered comparison operator (not including
1352 ORDERED and UNORDERED). */
1355 ordered_comparison_operator (rtx op, enum machine_mode mode)
1357 if (mode != VOIDmode && GET_MODE (op) != mode)
1358 return false;
1359 switch (GET_CODE (op))
1361 case EQ:
1362 case NE:
1363 case LT:
1364 case LTU:
1365 case LE:
1366 case LEU:
1367 case GT:
1368 case GTU:
1369 case GE:
1370 case GEU:
1371 return true;
1372 default:
1373 return false;
1377 /* Return 1 if this is a comparison operator. This allows the use of
1378 MATCH_OPERATOR to recognize all the branch insns. */
1381 comparison_operator (rtx op, enum machine_mode mode)
1383 return ((mode == VOIDmode || GET_MODE (op) == mode)
1384 && COMPARISON_P (op));
1387 /* If BODY is an insn body that uses ASM_OPERANDS, return it. */
1390 extract_asm_operands (rtx body)
1392 rtx tmp;
1393 switch (GET_CODE (body))
1395 case ASM_OPERANDS:
1396 return body;
1398 case SET:
1399 /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
1400 tmp = SET_SRC (body);
1401 if (GET_CODE (tmp) == ASM_OPERANDS)
1402 return tmp;
1403 break;
1405 case PARALLEL:
1406 tmp = XVECEXP (body, 0, 0);
1407 if (GET_CODE (tmp) == ASM_OPERANDS)
1408 return tmp;
1409 if (GET_CODE (tmp) == SET)
1411 tmp = SET_SRC (tmp);
1412 if (GET_CODE (tmp) == ASM_OPERANDS)
1413 return tmp;
1415 break;
1417 default:
1418 break;
1420 return NULL;
1423 /* If BODY is an insn body that uses ASM_OPERANDS,
1424 return the number of operands (both input and output) in the insn.
1425 Otherwise return -1. */
1428 asm_noperands (const_rtx body)
1430 rtx asm_op = extract_asm_operands (CONST_CAST_RTX (body));
1431 int n_sets = 0;
1433 if (asm_op == NULL)
1434 return -1;
1436 if (GET_CODE (body) == SET)
1437 n_sets = 1;
1438 else if (GET_CODE (body) == PARALLEL)
1440 int i;
1441 if (GET_CODE (XVECEXP (body, 0, 0)) == SET)
1443 /* Multiple output operands, or 1 output plus some clobbers:
1444 body is
1445 [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...]. */
1446 /* Count backwards through CLOBBERs to determine number of SETs. */
1447 for (i = XVECLEN (body, 0); i > 0; i--)
1449 if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
1450 break;
1451 if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
1452 return -1;
1455 /* N_SETS is now number of output operands. */
1456 n_sets = i;
1458 /* Verify that all the SETs we have
1459 came from a single original asm_operands insn
1460 (so that invalid combinations are blocked). */
1461 for (i = 0; i < n_sets; i++)
1463 rtx elt = XVECEXP (body, 0, i);
1464 if (GET_CODE (elt) != SET)
1465 return -1;
1466 if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
1467 return -1;
1468 /* If these ASM_OPERANDS rtx's came from different original insns
1469 then they aren't allowed together. */
1470 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
1471 != ASM_OPERANDS_INPUT_VEC (asm_op))
1472 return -1;
1475 else
1477 /* 0 outputs, but some clobbers:
1478 body is [(asm_operands ...) (clobber (reg ...))...]. */
1479 /* Make sure all the other parallel things really are clobbers. */
1480 for (i = XVECLEN (body, 0) - 1; i > 0; i--)
1481 if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
1482 return -1;
1486 return (ASM_OPERANDS_INPUT_LENGTH (asm_op)
1487 + ASM_OPERANDS_LABEL_LENGTH (asm_op) + n_sets);
1490 /* Assuming BODY is an insn body that uses ASM_OPERANDS,
1491 copy its operands (both input and output) into the vector OPERANDS,
1492 the locations of the operands within the insn into the vector OPERAND_LOCS,
1493 and the constraints for the operands into CONSTRAINTS.
1494 Write the modes of the operands into MODES.
1495 Return the assembler-template.
1497 If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1498 we don't store that info. */
1500 const char *
1501 decode_asm_operands (rtx body, rtx *operands, rtx **operand_locs,
1502 const char **constraints, enum machine_mode *modes,
1503 location_t *loc)
1505 int nbase = 0, n, i;
1506 rtx asmop;
1508 switch (GET_CODE (body))
1510 case ASM_OPERANDS:
1511 /* Zero output asm: BODY is (asm_operands ...). */
1512 asmop = body;
1513 break;
1515 case SET:
1516 /* Single output asm: BODY is (set OUTPUT (asm_operands ...)). */
1517 asmop = SET_SRC (body);
1519 /* The output is in the SET.
1520 Its constraint is in the ASM_OPERANDS itself. */
1521 if (operands)
1522 operands[0] = SET_DEST (body);
1523 if (operand_locs)
1524 operand_locs[0] = &SET_DEST (body);
1525 if (constraints)
1526 constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
1527 if (modes)
1528 modes[0] = GET_MODE (SET_DEST (body));
1529 nbase = 1;
1530 break;
1532 case PARALLEL:
1534 int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
1536 asmop = XVECEXP (body, 0, 0);
1537 if (GET_CODE (asmop) == SET)
1539 asmop = SET_SRC (asmop);
1541 /* At least one output, plus some CLOBBERs. The outputs are in
1542 the SETs. Their constraints are in the ASM_OPERANDS itself. */
1543 for (i = 0; i < nparallel; i++)
1545 if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1546 break; /* Past last SET */
1547 if (operands)
1548 operands[i] = SET_DEST (XVECEXP (body, 0, i));
1549 if (operand_locs)
1550 operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
1551 if (constraints)
1552 constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
1553 if (modes)
1554 modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
1556 nbase = i;
1558 break;
1561 default:
1562 gcc_unreachable ();
1565 n = ASM_OPERANDS_INPUT_LENGTH (asmop);
1566 for (i = 0; i < n; i++)
1568 if (operand_locs)
1569 operand_locs[nbase + i] = &ASM_OPERANDS_INPUT (asmop, i);
1570 if (operands)
1571 operands[nbase + i] = ASM_OPERANDS_INPUT (asmop, i);
1572 if (constraints)
1573 constraints[nbase + i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1574 if (modes)
1575 modes[nbase + i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1577 nbase += n;
1579 n = ASM_OPERANDS_LABEL_LENGTH (asmop);
1580 for (i = 0; i < n; i++)
1582 if (operand_locs)
1583 operand_locs[nbase + i] = &ASM_OPERANDS_LABEL (asmop, i);
1584 if (operands)
1585 operands[nbase + i] = ASM_OPERANDS_LABEL (asmop, i);
1586 if (constraints)
1587 constraints[nbase + i] = "";
1588 if (modes)
1589 modes[nbase + i] = Pmode;
1592 if (loc)
1593 *loc = ASM_OPERANDS_SOURCE_LOCATION (asmop);
1595 return ASM_OPERANDS_TEMPLATE (asmop);
1598 /* Check if an asm_operand matches its constraints.
1599 Return > 0 if ok, = 0 if bad, < 0 if inconclusive. */
1602 asm_operand_ok (rtx op, const char *constraint, const char **constraints)
1604 int result = 0;
1605 #ifdef AUTO_INC_DEC
1606 bool incdec_ok = false;
1607 #endif
1609 /* Use constrain_operands after reload. */
1610 gcc_assert (!reload_completed);
1612 /* Empty constraint string is the same as "X,...,X", i.e. X for as
1613 many alternatives as required to match the other operands. */
1614 if (*constraint == '\0')
1615 result = 1;
1617 while (*constraint)
1619 char c = *constraint;
1620 int len;
1621 switch (c)
1623 case ',':
1624 constraint++;
1625 continue;
1626 case '=':
1627 case '+':
1628 case '*':
1629 case '%':
1630 case '!':
1631 case '#':
1632 case '&':
1633 case '?':
1634 break;
1636 case '0': case '1': case '2': case '3': case '4':
1637 case '5': case '6': case '7': case '8': case '9':
1638 /* If caller provided constraints pointer, look up
1639 the maching constraint. Otherwise, our caller should have
1640 given us the proper matching constraint, but we can't
1641 actually fail the check if they didn't. Indicate that
1642 results are inconclusive. */
1643 if (constraints)
1645 char *end;
1646 unsigned long match;
1648 match = strtoul (constraint, &end, 10);
1649 if (!result)
1650 result = asm_operand_ok (op, constraints[match], NULL);
1651 constraint = (const char *) end;
1653 else
1656 constraint++;
1657 while (ISDIGIT (*constraint));
1658 if (! result)
1659 result = -1;
1661 continue;
1663 case 'p':
1664 if (address_operand (op, VOIDmode))
1665 result = 1;
1666 break;
1668 case TARGET_MEM_CONSTRAINT:
1669 case 'V': /* non-offsettable */
1670 if (memory_operand (op, VOIDmode))
1671 result = 1;
1672 break;
1674 case 'o': /* offsettable */
1675 if (offsettable_nonstrict_memref_p (op))
1676 result = 1;
1677 break;
1679 case '<':
1680 /* ??? Before auto-inc-dec, auto inc/dec insns are not supposed to exist,
1681 excepting those that expand_call created. Further, on some
1682 machines which do not have generalized auto inc/dec, an inc/dec
1683 is not a memory_operand.
1685 Match any memory and hope things are resolved after reload. */
1687 if (MEM_P (op)
1688 && (1
1689 || GET_CODE (XEXP (op, 0)) == PRE_DEC
1690 || GET_CODE (XEXP (op, 0)) == POST_DEC))
1691 result = 1;
1692 #ifdef AUTO_INC_DEC
1693 incdec_ok = true;
1694 #endif
1695 break;
1697 case '>':
1698 if (MEM_P (op)
1699 && (1
1700 || GET_CODE (XEXP (op, 0)) == PRE_INC
1701 || GET_CODE (XEXP (op, 0)) == POST_INC))
1702 result = 1;
1703 #ifdef AUTO_INC_DEC
1704 incdec_ok = true;
1705 #endif
1706 break;
1708 case 'E':
1709 case 'F':
1710 if (GET_CODE (op) == CONST_DOUBLE
1711 || (GET_CODE (op) == CONST_VECTOR
1712 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
1713 result = 1;
1714 break;
1716 case 'G':
1717 if (GET_CODE (op) == CONST_DOUBLE
1718 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'G', constraint))
1719 result = 1;
1720 break;
1721 case 'H':
1722 if (GET_CODE (op) == CONST_DOUBLE
1723 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'H', constraint))
1724 result = 1;
1725 break;
1727 case 's':
1728 if (CONST_INT_P (op)
1729 || (GET_CODE (op) == CONST_DOUBLE
1730 && GET_MODE (op) == VOIDmode))
1731 break;
1732 /* Fall through. */
1734 case 'i':
1735 if (CONSTANT_P (op) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op)))
1736 result = 1;
1737 break;
1739 case 'n':
1740 if (CONST_INT_P (op)
1741 || (GET_CODE (op) == CONST_DOUBLE
1742 && GET_MODE (op) == VOIDmode))
1743 result = 1;
1744 break;
1746 case 'I':
1747 if (CONST_INT_P (op)
1748 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'I', constraint))
1749 result = 1;
1750 break;
1751 case 'J':
1752 if (CONST_INT_P (op)
1753 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'J', constraint))
1754 result = 1;
1755 break;
1756 case 'K':
1757 if (CONST_INT_P (op)
1758 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'K', constraint))
1759 result = 1;
1760 break;
1761 case 'L':
1762 if (CONST_INT_P (op)
1763 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'L', constraint))
1764 result = 1;
1765 break;
1766 case 'M':
1767 if (CONST_INT_P (op)
1768 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'M', constraint))
1769 result = 1;
1770 break;
1771 case 'N':
1772 if (CONST_INT_P (op)
1773 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'N', constraint))
1774 result = 1;
1775 break;
1776 case 'O':
1777 if (CONST_INT_P (op)
1778 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'O', constraint))
1779 result = 1;
1780 break;
1781 case 'P':
1782 if (CONST_INT_P (op)
1783 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'P', constraint))
1784 result = 1;
1785 break;
1787 case 'X':
1788 result = 1;
1789 break;
1791 case 'g':
1792 if (general_operand (op, VOIDmode))
1793 result = 1;
1794 break;
1796 default:
1797 /* For all other letters, we first check for a register class,
1798 otherwise it is an EXTRA_CONSTRAINT. */
1799 if (REG_CLASS_FROM_CONSTRAINT (c, constraint) != NO_REGS)
1801 case 'r':
1802 if (GET_MODE (op) == BLKmode)
1803 break;
1804 if (register_operand (op, VOIDmode))
1805 result = 1;
1807 #ifdef EXTRA_CONSTRAINT_STR
1808 else if (EXTRA_MEMORY_CONSTRAINT (c, constraint))
1809 /* Every memory operand can be reloaded to fit. */
1810 result = result || memory_operand (op, VOIDmode);
1811 else if (EXTRA_ADDRESS_CONSTRAINT (c, constraint))
1812 /* Every address operand can be reloaded to fit. */
1813 result = result || address_operand (op, VOIDmode);
1814 else if (EXTRA_CONSTRAINT_STR (op, c, constraint))
1815 result = 1;
1816 #endif
1817 break;
1819 len = CONSTRAINT_LEN (c, constraint);
1821 constraint++;
1822 while (--len && *constraint);
1823 if (len)
1824 return 0;
1827 #ifdef AUTO_INC_DEC
1828 /* For operands without < or > constraints reject side-effects. */
1829 if (!incdec_ok && result && MEM_P (op))
1830 switch (GET_CODE (XEXP (op, 0)))
1832 case PRE_INC:
1833 case POST_INC:
1834 case PRE_DEC:
1835 case POST_DEC:
1836 case PRE_MODIFY:
1837 case POST_MODIFY:
1838 return 0;
1839 default:
1840 break;
1842 #endif
1844 return result;
1847 /* Given an rtx *P, if it is a sum containing an integer constant term,
1848 return the location (type rtx *) of the pointer to that constant term.
1849 Otherwise, return a null pointer. */
1851 rtx *
1852 find_constant_term_loc (rtx *p)
1854 rtx *tem;
1855 enum rtx_code code = GET_CODE (*p);
1857 /* If *P IS such a constant term, P is its location. */
1859 if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1860 || code == CONST)
1861 return p;
1863 /* Otherwise, if not a sum, it has no constant term. */
1865 if (GET_CODE (*p) != PLUS)
1866 return 0;
1868 /* If one of the summands is constant, return its location. */
1870 if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1871 && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1872 return p;
1874 /* Otherwise, check each summand for containing a constant term. */
1876 if (XEXP (*p, 0) != 0)
1878 tem = find_constant_term_loc (&XEXP (*p, 0));
1879 if (tem != 0)
1880 return tem;
1883 if (XEXP (*p, 1) != 0)
1885 tem = find_constant_term_loc (&XEXP (*p, 1));
1886 if (tem != 0)
1887 return tem;
1890 return 0;
1893 /* Return 1 if OP is a memory reference
1894 whose address contains no side effects
1895 and remains valid after the addition
1896 of a positive integer less than the
1897 size of the object being referenced.
1899 We assume that the original address is valid and do not check it.
1901 This uses strict_memory_address_p as a subroutine, so
1902 don't use it before reload. */
1905 offsettable_memref_p (rtx op)
1907 return ((MEM_P (op))
1908 && offsettable_address_addr_space_p (1, GET_MODE (op), XEXP (op, 0),
1909 MEM_ADDR_SPACE (op)));
1912 /* Similar, but don't require a strictly valid mem ref:
1913 consider pseudo-regs valid as index or base regs. */
1916 offsettable_nonstrict_memref_p (rtx op)
1918 return ((MEM_P (op))
1919 && offsettable_address_addr_space_p (0, GET_MODE (op), XEXP (op, 0),
1920 MEM_ADDR_SPACE (op)));
1923 /* Return 1 if Y is a memory address which contains no side effects
1924 and would remain valid for address space AS after the addition of
1925 a positive integer less than the size of that mode.
1927 We assume that the original address is valid and do not check it.
1928 We do check that it is valid for narrower modes.
1930 If STRICTP is nonzero, we require a strictly valid address,
1931 for the sake of use in reload.c. */
1934 offsettable_address_addr_space_p (int strictp, enum machine_mode mode, rtx y,
1935 addr_space_t as)
1937 enum rtx_code ycode = GET_CODE (y);
1938 rtx z;
1939 rtx y1 = y;
1940 rtx *y2;
1941 int (*addressp) (enum machine_mode, rtx, addr_space_t) =
1942 (strictp ? strict_memory_address_addr_space_p
1943 : memory_address_addr_space_p);
1944 unsigned int mode_sz = GET_MODE_SIZE (mode);
1946 if (CONSTANT_ADDRESS_P (y))
1947 return 1;
1949 /* Adjusting an offsettable address involves changing to a narrower mode.
1950 Make sure that's OK. */
1952 if (mode_dependent_address_p (y))
1953 return 0;
1955 /* ??? How much offset does an offsettable BLKmode reference need?
1956 Clearly that depends on the situation in which it's being used.
1957 However, the current situation in which we test 0xffffffff is
1958 less than ideal. Caveat user. */
1959 if (mode_sz == 0)
1960 mode_sz = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
1962 /* If the expression contains a constant term,
1963 see if it remains valid when max possible offset is added. */
1965 if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
1967 int good;
1969 y1 = *y2;
1970 *y2 = plus_constant (GET_MODE (y), *y2, mode_sz - 1);
1971 /* Use QImode because an odd displacement may be automatically invalid
1972 for any wider mode. But it should be valid for a single byte. */
1973 good = (*addressp) (QImode, y, as);
1975 /* In any case, restore old contents of memory. */
1976 *y2 = y1;
1977 return good;
1980 if (GET_RTX_CLASS (ycode) == RTX_AUTOINC)
1981 return 0;
1983 /* The offset added here is chosen as the maximum offset that
1984 any instruction could need to add when operating on something
1985 of the specified mode. We assume that if Y and Y+c are
1986 valid addresses then so is Y+d for all 0<d<c. adjust_address will
1987 go inside a LO_SUM here, so we do so as well. */
1988 if (GET_CODE (y) == LO_SUM
1989 && mode != BLKmode
1990 && mode_sz <= GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT)
1991 z = gen_rtx_LO_SUM (GET_MODE (y), XEXP (y, 0),
1992 plus_constant (GET_MODE (y), XEXP (y, 1),
1993 mode_sz - 1));
1994 else
1995 z = plus_constant (GET_MODE (y), y, mode_sz - 1);
1997 /* Use QImode because an odd displacement may be automatically invalid
1998 for any wider mode. But it should be valid for a single byte. */
1999 return (*addressp) (QImode, z, as);
2002 /* Return 1 if ADDR is an address-expression whose effect depends
2003 on the mode of the memory reference it is used in.
2005 Autoincrement addressing is a typical example of mode-dependence
2006 because the amount of the increment depends on the mode. */
2008 bool
2009 mode_dependent_address_p (rtx addr)
2011 /* Auto-increment addressing with anything other than post_modify
2012 or pre_modify always introduces a mode dependency. Catch such
2013 cases now instead of deferring to the target. */
2014 if (GET_CODE (addr) == PRE_INC
2015 || GET_CODE (addr) == POST_INC
2016 || GET_CODE (addr) == PRE_DEC
2017 || GET_CODE (addr) == POST_DEC)
2018 return true;
2020 return targetm.mode_dependent_address_p (addr);
2023 /* Like extract_insn, but save insn extracted and don't extract again, when
2024 called again for the same insn expecting that recog_data still contain the
2025 valid information. This is used primary by gen_attr infrastructure that
2026 often does extract insn again and again. */
2027 void
2028 extract_insn_cached (rtx insn)
2030 if (recog_data.insn == insn && INSN_CODE (insn) >= 0)
2031 return;
2032 extract_insn (insn);
2033 recog_data.insn = insn;
2036 /* Do cached extract_insn, constrain_operands and complain about failures.
2037 Used by insn_attrtab. */
2038 void
2039 extract_constrain_insn_cached (rtx insn)
2041 extract_insn_cached (insn);
2042 if (which_alternative == -1
2043 && !constrain_operands (reload_completed))
2044 fatal_insn_not_found (insn);
2047 /* Do cached constrain_operands and complain about failures. */
2049 constrain_operands_cached (int strict)
2051 if (which_alternative == -1)
2052 return constrain_operands (strict);
2053 else
2054 return 1;
2057 /* Analyze INSN and fill in recog_data. */
2059 void
2060 extract_insn (rtx insn)
2062 int i;
2063 int icode;
2064 int noperands;
2065 rtx body = PATTERN (insn);
2067 recog_data.n_operands = 0;
2068 recog_data.n_alternatives = 0;
2069 recog_data.n_dups = 0;
2070 recog_data.is_asm = false;
2072 switch (GET_CODE (body))
2074 case USE:
2075 case CLOBBER:
2076 case ASM_INPUT:
2077 case ADDR_VEC:
2078 case ADDR_DIFF_VEC:
2079 case VAR_LOCATION:
2080 return;
2082 case SET:
2083 if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
2084 goto asm_insn;
2085 else
2086 goto normal_insn;
2087 case PARALLEL:
2088 if ((GET_CODE (XVECEXP (body, 0, 0)) == SET
2089 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
2090 || GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
2091 goto asm_insn;
2092 else
2093 goto normal_insn;
2094 case ASM_OPERANDS:
2095 asm_insn:
2096 recog_data.n_operands = noperands = asm_noperands (body);
2097 if (noperands >= 0)
2099 /* This insn is an `asm' with operands. */
2101 /* expand_asm_operands makes sure there aren't too many operands. */
2102 gcc_assert (noperands <= MAX_RECOG_OPERANDS);
2104 /* Now get the operand values and constraints out of the insn. */
2105 decode_asm_operands (body, recog_data.operand,
2106 recog_data.operand_loc,
2107 recog_data.constraints,
2108 recog_data.operand_mode, NULL);
2109 memset (recog_data.is_operator, 0, sizeof recog_data.is_operator);
2110 if (noperands > 0)
2112 const char *p = recog_data.constraints[0];
2113 recog_data.n_alternatives = 1;
2114 while (*p)
2115 recog_data.n_alternatives += (*p++ == ',');
2117 recog_data.is_asm = true;
2118 break;
2120 fatal_insn_not_found (insn);
2122 default:
2123 normal_insn:
2124 /* Ordinary insn: recognize it, get the operands via insn_extract
2125 and get the constraints. */
2127 icode = recog_memoized (insn);
2128 if (icode < 0)
2129 fatal_insn_not_found (insn);
2131 recog_data.n_operands = noperands = insn_data[icode].n_operands;
2132 recog_data.n_alternatives = insn_data[icode].n_alternatives;
2133 recog_data.n_dups = insn_data[icode].n_dups;
2135 insn_extract (insn);
2137 for (i = 0; i < noperands; i++)
2139 recog_data.constraints[i] = insn_data[icode].operand[i].constraint;
2140 recog_data.is_operator[i] = insn_data[icode].operand[i].is_operator;
2141 recog_data.operand_mode[i] = insn_data[icode].operand[i].mode;
2142 /* VOIDmode match_operands gets mode from their real operand. */
2143 if (recog_data.operand_mode[i] == VOIDmode)
2144 recog_data.operand_mode[i] = GET_MODE (recog_data.operand[i]);
2147 for (i = 0; i < noperands; i++)
2148 recog_data.operand_type[i]
2149 = (recog_data.constraints[i][0] == '=' ? OP_OUT
2150 : recog_data.constraints[i][0] == '+' ? OP_INOUT
2151 : OP_IN);
2153 gcc_assert (recog_data.n_alternatives <= MAX_RECOG_ALTERNATIVES);
2155 if (INSN_CODE (insn) < 0)
2156 for (i = 0; i < recog_data.n_alternatives; i++)
2157 recog_data.alternative_enabled_p[i] = true;
2158 else
2160 recog_data.insn = insn;
2161 for (i = 0; i < recog_data.n_alternatives; i++)
2163 which_alternative = i;
2164 recog_data.alternative_enabled_p[i] = get_attr_enabled (insn);
2168 recog_data.insn = NULL;
2169 which_alternative = -1;
2172 /* After calling extract_insn, you can use this function to extract some
2173 information from the constraint strings into a more usable form.
2174 The collected data is stored in recog_op_alt. */
2175 void
2176 preprocess_constraints (void)
2178 int i;
2180 for (i = 0; i < recog_data.n_operands; i++)
2181 memset (recog_op_alt[i], 0, (recog_data.n_alternatives
2182 * sizeof (struct operand_alternative)));
2184 for (i = 0; i < recog_data.n_operands; i++)
2186 int j;
2187 struct operand_alternative *op_alt;
2188 const char *p = recog_data.constraints[i];
2190 op_alt = recog_op_alt[i];
2192 for (j = 0; j < recog_data.n_alternatives; j++)
2194 op_alt[j].cl = NO_REGS;
2195 op_alt[j].constraint = p;
2196 op_alt[j].matches = -1;
2197 op_alt[j].matched = -1;
2199 if (!recog_data.alternative_enabled_p[j])
2201 p = skip_alternative (p);
2202 continue;
2205 if (*p == '\0' || *p == ',')
2207 op_alt[j].anything_ok = 1;
2208 continue;
2211 for (;;)
2213 char c = *p;
2214 if (c == '#')
2216 c = *++p;
2217 while (c != ',' && c != '\0');
2218 if (c == ',' || c == '\0')
2220 p++;
2221 break;
2224 switch (c)
2226 case '=': case '+': case '*': case '%':
2227 case 'E': case 'F': case 'G': case 'H':
2228 case 's': case 'i': case 'n':
2229 case 'I': case 'J': case 'K': case 'L':
2230 case 'M': case 'N': case 'O': case 'P':
2231 /* These don't say anything we care about. */
2232 break;
2234 case '?':
2235 op_alt[j].reject += 6;
2236 break;
2237 case '!':
2238 op_alt[j].reject += 600;
2239 break;
2240 case '&':
2241 op_alt[j].earlyclobber = 1;
2242 break;
2244 case '0': case '1': case '2': case '3': case '4':
2245 case '5': case '6': case '7': case '8': case '9':
2247 char *end;
2248 op_alt[j].matches = strtoul (p, &end, 10);
2249 recog_op_alt[op_alt[j].matches][j].matched = i;
2250 p = end;
2252 continue;
2254 case TARGET_MEM_CONSTRAINT:
2255 op_alt[j].memory_ok = 1;
2256 break;
2257 case '<':
2258 op_alt[j].decmem_ok = 1;
2259 break;
2260 case '>':
2261 op_alt[j].incmem_ok = 1;
2262 break;
2263 case 'V':
2264 op_alt[j].nonoffmem_ok = 1;
2265 break;
2266 case 'o':
2267 op_alt[j].offmem_ok = 1;
2268 break;
2269 case 'X':
2270 op_alt[j].anything_ok = 1;
2271 break;
2273 case 'p':
2274 op_alt[j].is_address = 1;
2275 op_alt[j].cl = reg_class_subunion[(int) op_alt[j].cl]
2276 [(int) base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
2277 ADDRESS, SCRATCH)];
2278 break;
2280 case 'g':
2281 case 'r':
2282 op_alt[j].cl =
2283 reg_class_subunion[(int) op_alt[j].cl][(int) GENERAL_REGS];
2284 break;
2286 default:
2287 if (EXTRA_MEMORY_CONSTRAINT (c, p))
2289 op_alt[j].memory_ok = 1;
2290 break;
2292 if (EXTRA_ADDRESS_CONSTRAINT (c, p))
2294 op_alt[j].is_address = 1;
2295 op_alt[j].cl
2296 = (reg_class_subunion
2297 [(int) op_alt[j].cl]
2298 [(int) base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
2299 ADDRESS, SCRATCH)]);
2300 break;
2303 op_alt[j].cl
2304 = (reg_class_subunion
2305 [(int) op_alt[j].cl]
2306 [(int) REG_CLASS_FROM_CONSTRAINT ((unsigned char) c, p)]);
2307 break;
2309 p += CONSTRAINT_LEN (c, p);
2315 /* Check the operands of an insn against the insn's operand constraints
2316 and return 1 if they are valid.
2317 The information about the insn's operands, constraints, operand modes
2318 etc. is obtained from the global variables set up by extract_insn.
2320 WHICH_ALTERNATIVE is set to a number which indicates which
2321 alternative of constraints was matched: 0 for the first alternative,
2322 1 for the next, etc.
2324 In addition, when two operands are required to match
2325 and it happens that the output operand is (reg) while the
2326 input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
2327 make the output operand look like the input.
2328 This is because the output operand is the one the template will print.
2330 This is used in final, just before printing the assembler code and by
2331 the routines that determine an insn's attribute.
2333 If STRICT is a positive nonzero value, it means that we have been
2334 called after reload has been completed. In that case, we must
2335 do all checks strictly. If it is zero, it means that we have been called
2336 before reload has completed. In that case, we first try to see if we can
2337 find an alternative that matches strictly. If not, we try again, this
2338 time assuming that reload will fix up the insn. This provides a "best
2339 guess" for the alternative and is used to compute attributes of insns prior
2340 to reload. A negative value of STRICT is used for this internal call. */
2342 struct funny_match
2344 int this_op, other;
2348 constrain_operands (int strict)
2350 const char *constraints[MAX_RECOG_OPERANDS];
2351 int matching_operands[MAX_RECOG_OPERANDS];
2352 int earlyclobber[MAX_RECOG_OPERANDS];
2353 int c;
2355 struct funny_match funny_match[MAX_RECOG_OPERANDS];
2356 int funny_match_index;
2358 which_alternative = 0;
2359 if (recog_data.n_operands == 0 || recog_data.n_alternatives == 0)
2360 return 1;
2362 for (c = 0; c < recog_data.n_operands; c++)
2364 constraints[c] = recog_data.constraints[c];
2365 matching_operands[c] = -1;
2370 int seen_earlyclobber_at = -1;
2371 int opno;
2372 int lose = 0;
2373 funny_match_index = 0;
2375 if (!recog_data.alternative_enabled_p[which_alternative])
2377 int i;
2379 for (i = 0; i < recog_data.n_operands; i++)
2380 constraints[i] = skip_alternative (constraints[i]);
2382 which_alternative++;
2383 continue;
2386 for (opno = 0; opno < recog_data.n_operands; opno++)
2388 rtx op = recog_data.operand[opno];
2389 enum machine_mode mode = GET_MODE (op);
2390 const char *p = constraints[opno];
2391 int offset = 0;
2392 int win = 0;
2393 int val;
2394 int len;
2396 earlyclobber[opno] = 0;
2398 /* A unary operator may be accepted by the predicate, but it
2399 is irrelevant for matching constraints. */
2400 if (UNARY_P (op))
2401 op = XEXP (op, 0);
2403 if (GET_CODE (op) == SUBREG)
2405 if (REG_P (SUBREG_REG (op))
2406 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
2407 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
2408 GET_MODE (SUBREG_REG (op)),
2409 SUBREG_BYTE (op),
2410 GET_MODE (op));
2411 op = SUBREG_REG (op);
2414 /* An empty constraint or empty alternative
2415 allows anything which matched the pattern. */
2416 if (*p == 0 || *p == ',')
2417 win = 1;
2420 switch (c = *p, len = CONSTRAINT_LEN (c, p), c)
2422 case '\0':
2423 len = 0;
2424 break;
2425 case ',':
2426 c = '\0';
2427 break;
2429 case '?': case '!': case '*': case '%':
2430 case '=': case '+':
2431 break;
2433 case '#':
2434 /* Ignore rest of this alternative as far as
2435 constraint checking is concerned. */
2437 p++;
2438 while (*p && *p != ',');
2439 len = 0;
2440 break;
2442 case '&':
2443 earlyclobber[opno] = 1;
2444 if (seen_earlyclobber_at < 0)
2445 seen_earlyclobber_at = opno;
2446 break;
2448 case '0': case '1': case '2': case '3': case '4':
2449 case '5': case '6': case '7': case '8': case '9':
2451 /* This operand must be the same as a previous one.
2452 This kind of constraint is used for instructions such
2453 as add when they take only two operands.
2455 Note that the lower-numbered operand is passed first.
2457 If we are not testing strictly, assume that this
2458 constraint will be satisfied. */
2460 char *end;
2461 int match;
2463 match = strtoul (p, &end, 10);
2464 p = end;
2466 if (strict < 0)
2467 val = 1;
2468 else
2470 rtx op1 = recog_data.operand[match];
2471 rtx op2 = recog_data.operand[opno];
2473 /* A unary operator may be accepted by the predicate,
2474 but it is irrelevant for matching constraints. */
2475 if (UNARY_P (op1))
2476 op1 = XEXP (op1, 0);
2477 if (UNARY_P (op2))
2478 op2 = XEXP (op2, 0);
2480 val = operands_match_p (op1, op2);
2483 matching_operands[opno] = match;
2484 matching_operands[match] = opno;
2486 if (val != 0)
2487 win = 1;
2489 /* If output is *x and input is *--x, arrange later
2490 to change the output to *--x as well, since the
2491 output op is the one that will be printed. */
2492 if (val == 2 && strict > 0)
2494 funny_match[funny_match_index].this_op = opno;
2495 funny_match[funny_match_index++].other = match;
2498 len = 0;
2499 break;
2501 case 'p':
2502 /* p is used for address_operands. When we are called by
2503 gen_reload, no one will have checked that the address is
2504 strictly valid, i.e., that all pseudos requiring hard regs
2505 have gotten them. */
2506 if (strict <= 0
2507 || (strict_memory_address_p (recog_data.operand_mode[opno],
2508 op)))
2509 win = 1;
2510 break;
2512 /* No need to check general_operand again;
2513 it was done in insn-recog.c. Well, except that reload
2514 doesn't check the validity of its replacements, but
2515 that should only matter when there's a bug. */
2516 case 'g':
2517 /* Anything goes unless it is a REG and really has a hard reg
2518 but the hard reg is not in the class GENERAL_REGS. */
2519 if (REG_P (op))
2521 if (strict < 0
2522 || GENERAL_REGS == ALL_REGS
2523 || (reload_in_progress
2524 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2525 || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
2526 win = 1;
2528 else if (strict < 0 || general_operand (op, mode))
2529 win = 1;
2530 break;
2532 case 'X':
2533 /* This is used for a MATCH_SCRATCH in the cases when
2534 we don't actually need anything. So anything goes
2535 any time. */
2536 win = 1;
2537 break;
2539 case TARGET_MEM_CONSTRAINT:
2540 /* Memory operands must be valid, to the extent
2541 required by STRICT. */
2542 if (MEM_P (op))
2544 if (strict > 0
2545 && !strict_memory_address_addr_space_p
2546 (GET_MODE (op), XEXP (op, 0),
2547 MEM_ADDR_SPACE (op)))
2548 break;
2549 if (strict == 0
2550 && !memory_address_addr_space_p
2551 (GET_MODE (op), XEXP (op, 0),
2552 MEM_ADDR_SPACE (op)))
2553 break;
2554 win = 1;
2556 /* Before reload, accept what reload can turn into mem. */
2557 else if (strict < 0 && CONSTANT_P (op))
2558 win = 1;
2559 /* During reload, accept a pseudo */
2560 else if (reload_in_progress && REG_P (op)
2561 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2562 win = 1;
2563 break;
2565 case '<':
2566 if (MEM_P (op)
2567 && (GET_CODE (XEXP (op, 0)) == PRE_DEC
2568 || GET_CODE (XEXP (op, 0)) == POST_DEC))
2569 win = 1;
2570 break;
2572 case '>':
2573 if (MEM_P (op)
2574 && (GET_CODE (XEXP (op, 0)) == PRE_INC
2575 || GET_CODE (XEXP (op, 0)) == POST_INC))
2576 win = 1;
2577 break;
2579 case 'E':
2580 case 'F':
2581 if (GET_CODE (op) == CONST_DOUBLE
2582 || (GET_CODE (op) == CONST_VECTOR
2583 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
2584 win = 1;
2585 break;
2587 case 'G':
2588 case 'H':
2589 if (GET_CODE (op) == CONST_DOUBLE
2590 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, p))
2591 win = 1;
2592 break;
2594 case 's':
2595 if (CONST_INT_P (op)
2596 || (GET_CODE (op) == CONST_DOUBLE
2597 && GET_MODE (op) == VOIDmode))
2598 break;
2599 case 'i':
2600 if (CONSTANT_P (op))
2601 win = 1;
2602 break;
2604 case 'n':
2605 if (CONST_INT_P (op)
2606 || (GET_CODE (op) == CONST_DOUBLE
2607 && GET_MODE (op) == VOIDmode))
2608 win = 1;
2609 break;
2611 case 'I':
2612 case 'J':
2613 case 'K':
2614 case 'L':
2615 case 'M':
2616 case 'N':
2617 case 'O':
2618 case 'P':
2619 if (CONST_INT_P (op)
2620 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, p))
2621 win = 1;
2622 break;
2624 case 'V':
2625 if (MEM_P (op)
2626 && ((strict > 0 && ! offsettable_memref_p (op))
2627 || (strict < 0
2628 && !(CONSTANT_P (op) || MEM_P (op)))
2629 || (reload_in_progress
2630 && !(REG_P (op)
2631 && REGNO (op) >= FIRST_PSEUDO_REGISTER))))
2632 win = 1;
2633 break;
2635 case 'o':
2636 if ((strict > 0 && offsettable_memref_p (op))
2637 || (strict == 0 && offsettable_nonstrict_memref_p (op))
2638 /* Before reload, accept what reload can handle. */
2639 || (strict < 0
2640 && (CONSTANT_P (op) || MEM_P (op)))
2641 /* During reload, accept a pseudo */
2642 || (reload_in_progress && REG_P (op)
2643 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2644 win = 1;
2645 break;
2647 default:
2649 enum reg_class cl;
2651 cl = (c == 'r'
2652 ? GENERAL_REGS : REG_CLASS_FROM_CONSTRAINT (c, p));
2653 if (cl != NO_REGS)
2655 if (strict < 0
2656 || (strict == 0
2657 && REG_P (op)
2658 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2659 || (strict == 0 && GET_CODE (op) == SCRATCH)
2660 || (REG_P (op)
2661 && reg_fits_class_p (op, cl, offset, mode)))
2662 win = 1;
2664 #ifdef EXTRA_CONSTRAINT_STR
2665 else if (EXTRA_CONSTRAINT_STR (op, c, p))
2666 win = 1;
2668 else if (EXTRA_MEMORY_CONSTRAINT (c, p)
2669 /* Every memory operand can be reloaded to fit. */
2670 && ((strict < 0 && MEM_P (op))
2671 /* Before reload, accept what reload can turn
2672 into mem. */
2673 || (strict < 0 && CONSTANT_P (op))
2674 /* During reload, accept a pseudo */
2675 || (reload_in_progress && REG_P (op)
2676 && REGNO (op) >= FIRST_PSEUDO_REGISTER)))
2677 win = 1;
2678 else if (EXTRA_ADDRESS_CONSTRAINT (c, p)
2679 /* Every address operand can be reloaded to fit. */
2680 && strict < 0)
2681 win = 1;
2682 /* Cater to architectures like IA-64 that define extra memory
2683 constraints without using define_memory_constraint. */
2684 else if (reload_in_progress
2685 && REG_P (op)
2686 && REGNO (op) >= FIRST_PSEUDO_REGISTER
2687 && reg_renumber[REGNO (op)] < 0
2688 && reg_equiv_mem (REGNO (op)) != 0
2689 && EXTRA_CONSTRAINT_STR
2690 (reg_equiv_mem (REGNO (op)), c, p))
2691 win = 1;
2692 #endif
2693 break;
2696 while (p += len, c);
2698 constraints[opno] = p;
2699 /* If this operand did not win somehow,
2700 this alternative loses. */
2701 if (! win)
2702 lose = 1;
2704 /* This alternative won; the operands are ok.
2705 Change whichever operands this alternative says to change. */
2706 if (! lose)
2708 int opno, eopno;
2710 /* See if any earlyclobber operand conflicts with some other
2711 operand. */
2713 if (strict > 0 && seen_earlyclobber_at >= 0)
2714 for (eopno = seen_earlyclobber_at;
2715 eopno < recog_data.n_operands;
2716 eopno++)
2717 /* Ignore earlyclobber operands now in memory,
2718 because we would often report failure when we have
2719 two memory operands, one of which was formerly a REG. */
2720 if (earlyclobber[eopno]
2721 && REG_P (recog_data.operand[eopno]))
2722 for (opno = 0; opno < recog_data.n_operands; opno++)
2723 if ((MEM_P (recog_data.operand[opno])
2724 || recog_data.operand_type[opno] != OP_OUT)
2725 && opno != eopno
2726 /* Ignore things like match_operator operands. */
2727 && *recog_data.constraints[opno] != 0
2728 && ! (matching_operands[opno] == eopno
2729 && operands_match_p (recog_data.operand[opno],
2730 recog_data.operand[eopno]))
2731 && ! safe_from_earlyclobber (recog_data.operand[opno],
2732 recog_data.operand[eopno]))
2733 lose = 1;
2735 if (! lose)
2737 while (--funny_match_index >= 0)
2739 recog_data.operand[funny_match[funny_match_index].other]
2740 = recog_data.operand[funny_match[funny_match_index].this_op];
2743 #ifdef AUTO_INC_DEC
2744 /* For operands without < or > constraints reject side-effects. */
2745 if (recog_data.is_asm)
2747 for (opno = 0; opno < recog_data.n_operands; opno++)
2748 if (MEM_P (recog_data.operand[opno]))
2749 switch (GET_CODE (XEXP (recog_data.operand[opno], 0)))
2751 case PRE_INC:
2752 case POST_INC:
2753 case PRE_DEC:
2754 case POST_DEC:
2755 case PRE_MODIFY:
2756 case POST_MODIFY:
2757 if (strchr (recog_data.constraints[opno], '<') == NULL
2758 && strchr (recog_data.constraints[opno], '>')
2759 == NULL)
2760 return 0;
2761 break;
2762 default:
2763 break;
2766 #endif
2767 return 1;
2771 which_alternative++;
2773 while (which_alternative < recog_data.n_alternatives);
2775 which_alternative = -1;
2776 /* If we are about to reject this, but we are not to test strictly,
2777 try a very loose test. Only return failure if it fails also. */
2778 if (strict == 0)
2779 return constrain_operands (-1);
2780 else
2781 return 0;
2784 /* Return true iff OPERAND (assumed to be a REG rtx)
2785 is a hard reg in class CLASS when its regno is offset by OFFSET
2786 and changed to mode MODE.
2787 If REG occupies multiple hard regs, all of them must be in CLASS. */
2789 bool
2790 reg_fits_class_p (const_rtx operand, reg_class_t cl, int offset,
2791 enum machine_mode mode)
2793 unsigned int regno = REGNO (operand);
2795 if (cl == NO_REGS)
2796 return false;
2798 /* Regno must not be a pseudo register. Offset may be negative. */
2799 return (HARD_REGISTER_NUM_P (regno)
2800 && HARD_REGISTER_NUM_P (regno + offset)
2801 && in_hard_reg_set_p (reg_class_contents[(int) cl], mode,
2802 regno + offset));
2805 /* Split single instruction. Helper function for split_all_insns and
2806 split_all_insns_noflow. Return last insn in the sequence if successful,
2807 or NULL if unsuccessful. */
2809 static rtx
2810 split_insn (rtx insn)
2812 /* Split insns here to get max fine-grain parallelism. */
2813 rtx first = PREV_INSN (insn);
2814 rtx last = try_split (PATTERN (insn), insn, 1);
2815 rtx insn_set, last_set, note;
2817 if (last == insn)
2818 return NULL_RTX;
2820 /* If the original instruction was a single set that was known to be
2821 equivalent to a constant, see if we can say the same about the last
2822 instruction in the split sequence. The two instructions must set
2823 the same destination. */
2824 insn_set = single_set (insn);
2825 if (insn_set)
2827 last_set = single_set (last);
2828 if (last_set && rtx_equal_p (SET_DEST (last_set), SET_DEST (insn_set)))
2830 note = find_reg_equal_equiv_note (insn);
2831 if (note && CONSTANT_P (XEXP (note, 0)))
2832 set_unique_reg_note (last, REG_EQUAL, XEXP (note, 0));
2833 else if (CONSTANT_P (SET_SRC (insn_set)))
2834 set_unique_reg_note (last, REG_EQUAL, SET_SRC (insn_set));
2838 /* try_split returns the NOTE that INSN became. */
2839 SET_INSN_DELETED (insn);
2841 /* ??? Coddle to md files that generate subregs in post-reload
2842 splitters instead of computing the proper hard register. */
2843 if (reload_completed && first != last)
2845 first = NEXT_INSN (first);
2846 for (;;)
2848 if (INSN_P (first))
2849 cleanup_subreg_operands (first);
2850 if (first == last)
2851 break;
2852 first = NEXT_INSN (first);
2856 return last;
2859 /* Split all insns in the function. If UPD_LIFE, update life info after. */
2861 void
2862 split_all_insns (void)
2864 sbitmap blocks;
2865 bool changed;
2866 basic_block bb;
2868 blocks = sbitmap_alloc (last_basic_block);
2869 sbitmap_zero (blocks);
2870 changed = false;
2872 FOR_EACH_BB_REVERSE (bb)
2874 rtx insn, next;
2875 bool finish = false;
2877 rtl_profile_for_bb (bb);
2878 for (insn = BB_HEAD (bb); !finish ; insn = next)
2880 /* Can't use `next_real_insn' because that might go across
2881 CODE_LABELS and short-out basic blocks. */
2882 next = NEXT_INSN (insn);
2883 finish = (insn == BB_END (bb));
2884 if (INSN_P (insn))
2886 rtx set = single_set (insn);
2888 /* Don't split no-op move insns. These should silently
2889 disappear later in final. Splitting such insns would
2890 break the code that handles LIBCALL blocks. */
2891 if (set && set_noop_p (set))
2893 /* Nops get in the way while scheduling, so delete them
2894 now if register allocation has already been done. It
2895 is too risky to try to do this before register
2896 allocation, and there are unlikely to be very many
2897 nops then anyways. */
2898 if (reload_completed)
2899 delete_insn_and_edges (insn);
2901 else
2903 if (split_insn (insn))
2905 SET_BIT (blocks, bb->index);
2906 changed = true;
2913 default_rtl_profile ();
2914 if (changed)
2915 find_many_sub_basic_blocks (blocks);
2917 #ifdef ENABLE_CHECKING
2918 verify_flow_info ();
2919 #endif
2921 sbitmap_free (blocks);
2924 /* Same as split_all_insns, but do not expect CFG to be available.
2925 Used by machine dependent reorg passes. */
2927 unsigned int
2928 split_all_insns_noflow (void)
2930 rtx next, insn;
2932 for (insn = get_insns (); insn; insn = next)
2934 next = NEXT_INSN (insn);
2935 if (INSN_P (insn))
2937 /* Don't split no-op move insns. These should silently
2938 disappear later in final. Splitting such insns would
2939 break the code that handles LIBCALL blocks. */
2940 rtx set = single_set (insn);
2941 if (set && set_noop_p (set))
2943 /* Nops get in the way while scheduling, so delete them
2944 now if register allocation has already been done. It
2945 is too risky to try to do this before register
2946 allocation, and there are unlikely to be very many
2947 nops then anyways.
2949 ??? Should we use delete_insn when the CFG isn't valid? */
2950 if (reload_completed)
2951 delete_insn_and_edges (insn);
2953 else
2954 split_insn (insn);
2957 return 0;
2960 #ifdef HAVE_peephole2
2961 struct peep2_insn_data
2963 rtx insn;
2964 regset live_before;
2967 static struct peep2_insn_data peep2_insn_data[MAX_INSNS_PER_PEEP2 + 1];
2968 static int peep2_current;
2970 static bool peep2_do_rebuild_jump_labels;
2971 static bool peep2_do_cleanup_cfg;
2973 /* The number of instructions available to match a peep2. */
2974 int peep2_current_count;
2976 /* A non-insn marker indicating the last insn of the block.
2977 The live_before regset for this element is correct, indicating
2978 DF_LIVE_OUT for the block. */
2979 #define PEEP2_EOB pc_rtx
2981 /* Wrap N to fit into the peep2_insn_data buffer. */
2983 static int
2984 peep2_buf_position (int n)
2986 if (n >= MAX_INSNS_PER_PEEP2 + 1)
2987 n -= MAX_INSNS_PER_PEEP2 + 1;
2988 return n;
2991 /* Return the Nth non-note insn after `current', or return NULL_RTX if it
2992 does not exist. Used by the recognizer to find the next insn to match
2993 in a multi-insn pattern. */
2996 peep2_next_insn (int n)
2998 gcc_assert (n <= peep2_current_count);
3000 n = peep2_buf_position (peep2_current + n);
3002 return peep2_insn_data[n].insn;
3005 /* Return true if REGNO is dead before the Nth non-note insn
3006 after `current'. */
3009 peep2_regno_dead_p (int ofs, int regno)
3011 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3013 ofs = peep2_buf_position (peep2_current + ofs);
3015 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3017 return ! REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno);
3020 /* Similarly for a REG. */
3023 peep2_reg_dead_p (int ofs, rtx reg)
3025 int regno, n;
3027 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3029 ofs = peep2_buf_position (peep2_current + ofs);
3031 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3033 regno = REGNO (reg);
3034 n = hard_regno_nregs[regno][GET_MODE (reg)];
3035 while (--n >= 0)
3036 if (REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno + n))
3037 return 0;
3038 return 1;
3041 /* Try to find a hard register of mode MODE, matching the register class in
3042 CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
3043 remains available until the end of LAST_INSN. LAST_INSN may be NULL_RTX,
3044 in which case the only condition is that the register must be available
3045 before CURRENT_INSN.
3046 Registers that already have bits set in REG_SET will not be considered.
3048 If an appropriate register is available, it will be returned and the
3049 corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
3050 returned. */
3053 peep2_find_free_register (int from, int to, const char *class_str,
3054 enum machine_mode mode, HARD_REG_SET *reg_set)
3056 static int search_ofs;
3057 enum reg_class cl;
3058 HARD_REG_SET live;
3059 df_ref *def_rec;
3060 int i;
3062 gcc_assert (from < MAX_INSNS_PER_PEEP2 + 1);
3063 gcc_assert (to < MAX_INSNS_PER_PEEP2 + 1);
3065 from = peep2_buf_position (peep2_current + from);
3066 to = peep2_buf_position (peep2_current + to);
3068 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3069 REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before);
3071 while (from != to)
3073 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3075 /* Don't use registers set or clobbered by the insn. */
3076 for (def_rec = DF_INSN_DEFS (peep2_insn_data[from].insn);
3077 *def_rec; def_rec++)
3078 SET_HARD_REG_BIT (live, DF_REF_REGNO (*def_rec));
3080 from = peep2_buf_position (from + 1);
3083 cl = (class_str[0] == 'r' ? GENERAL_REGS
3084 : REG_CLASS_FROM_CONSTRAINT (class_str[0], class_str));
3086 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3088 int raw_regno, regno, success, j;
3090 /* Distribute the free registers as much as possible. */
3091 raw_regno = search_ofs + i;
3092 if (raw_regno >= FIRST_PSEUDO_REGISTER)
3093 raw_regno -= FIRST_PSEUDO_REGISTER;
3094 #ifdef REG_ALLOC_ORDER
3095 regno = reg_alloc_order[raw_regno];
3096 #else
3097 regno = raw_regno;
3098 #endif
3100 /* Don't allocate fixed registers. */
3101 if (fixed_regs[regno])
3102 continue;
3103 /* Don't allocate global registers. */
3104 if (global_regs[regno])
3105 continue;
3106 /* Make sure the register is of the right class. */
3107 if (! TEST_HARD_REG_BIT (reg_class_contents[cl], regno))
3108 continue;
3109 /* And can support the mode we need. */
3110 if (! HARD_REGNO_MODE_OK (regno, mode))
3111 continue;
3112 /* And that we don't create an extra save/restore. */
3113 if (! call_used_regs[regno] && ! df_regs_ever_live_p (regno))
3114 continue;
3115 if (! targetm.hard_regno_scratch_ok (regno))
3116 continue;
3118 /* And we don't clobber traceback for noreturn functions. */
3119 if ((regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM)
3120 && (! reload_completed || frame_pointer_needed))
3121 continue;
3123 success = 1;
3124 for (j = hard_regno_nregs[regno][mode] - 1; j >= 0; j--)
3126 if (TEST_HARD_REG_BIT (*reg_set, regno + j)
3127 || TEST_HARD_REG_BIT (live, regno + j))
3129 success = 0;
3130 break;
3133 if (success)
3135 add_to_hard_reg_set (reg_set, mode, regno);
3137 /* Start the next search with the next register. */
3138 if (++raw_regno >= FIRST_PSEUDO_REGISTER)
3139 raw_regno = 0;
3140 search_ofs = raw_regno;
3142 return gen_rtx_REG (mode, regno);
3146 search_ofs = 0;
3147 return NULL_RTX;
3150 /* Forget all currently tracked instructions, only remember current
3151 LIVE regset. */
3153 static void
3154 peep2_reinit_state (regset live)
3156 int i;
3158 /* Indicate that all slots except the last holds invalid data. */
3159 for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
3160 peep2_insn_data[i].insn = NULL_RTX;
3161 peep2_current_count = 0;
3163 /* Indicate that the last slot contains live_after data. */
3164 peep2_insn_data[MAX_INSNS_PER_PEEP2].insn = PEEP2_EOB;
3165 peep2_current = MAX_INSNS_PER_PEEP2;
3167 COPY_REG_SET (peep2_insn_data[MAX_INSNS_PER_PEEP2].live_before, live);
3170 /* While scanning basic block BB, we found a match of length MATCH_LEN,
3171 starting at INSN. Perform the replacement, removing the old insns and
3172 replacing them with ATTEMPT. Returns the last insn emitted, or NULL
3173 if the replacement is rejected. */
3175 static rtx
3176 peep2_attempt (basic_block bb, rtx insn, int match_len, rtx attempt)
3178 int i;
3179 rtx last, eh_note, as_note, before_try, x;
3180 rtx old_insn, new_insn;
3181 bool was_call = false;
3183 /* If we are splitting an RTX_FRAME_RELATED_P insn, do not allow it to
3184 match more than one insn, or to be split into more than one insn. */
3185 old_insn = peep2_insn_data[peep2_current].insn;
3186 if (RTX_FRAME_RELATED_P (old_insn))
3188 bool any_note = false;
3189 rtx note;
3191 if (match_len != 0)
3192 return NULL;
3194 /* Look for one "active" insn. I.e. ignore any "clobber" insns that
3195 may be in the stream for the purpose of register allocation. */
3196 if (active_insn_p (attempt))
3197 new_insn = attempt;
3198 else
3199 new_insn = next_active_insn (attempt);
3200 if (next_active_insn (new_insn))
3201 return NULL;
3203 /* We have a 1-1 replacement. Copy over any frame-related info. */
3204 RTX_FRAME_RELATED_P (new_insn) = 1;
3206 /* Allow the backend to fill in a note during the split. */
3207 for (note = REG_NOTES (new_insn); note ; note = XEXP (note, 1))
3208 switch (REG_NOTE_KIND (note))
3210 case REG_FRAME_RELATED_EXPR:
3211 case REG_CFA_DEF_CFA:
3212 case REG_CFA_ADJUST_CFA:
3213 case REG_CFA_OFFSET:
3214 case REG_CFA_REGISTER:
3215 case REG_CFA_EXPRESSION:
3216 case REG_CFA_RESTORE:
3217 case REG_CFA_SET_VDRAP:
3218 any_note = true;
3219 break;
3220 default:
3221 break;
3224 /* If the backend didn't supply a note, copy one over. */
3225 if (!any_note)
3226 for (note = REG_NOTES (old_insn); note ; note = XEXP (note, 1))
3227 switch (REG_NOTE_KIND (note))
3229 case REG_FRAME_RELATED_EXPR:
3230 case REG_CFA_DEF_CFA:
3231 case REG_CFA_ADJUST_CFA:
3232 case REG_CFA_OFFSET:
3233 case REG_CFA_REGISTER:
3234 case REG_CFA_EXPRESSION:
3235 case REG_CFA_RESTORE:
3236 case REG_CFA_SET_VDRAP:
3237 add_reg_note (new_insn, REG_NOTE_KIND (note), XEXP (note, 0));
3238 any_note = true;
3239 break;
3240 default:
3241 break;
3244 /* If there still isn't a note, make sure the unwind info sees the
3245 same expression as before the split. */
3246 if (!any_note)
3248 rtx old_set, new_set;
3250 /* The old insn had better have been simple, or annotated. */
3251 old_set = single_set (old_insn);
3252 gcc_assert (old_set != NULL);
3254 new_set = single_set (new_insn);
3255 if (!new_set || !rtx_equal_p (new_set, old_set))
3256 add_reg_note (new_insn, REG_FRAME_RELATED_EXPR, old_set);
3259 /* Copy prologue/epilogue status. This is required in order to keep
3260 proper placement of EPILOGUE_BEG and the DW_CFA_remember_state. */
3261 maybe_copy_prologue_epilogue_insn (old_insn, new_insn);
3264 /* If we are splitting a CALL_INSN, look for the CALL_INSN
3265 in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other
3266 cfg-related call notes. */
3267 for (i = 0; i <= match_len; ++i)
3269 int j;
3270 rtx note;
3272 j = peep2_buf_position (peep2_current + i);
3273 old_insn = peep2_insn_data[j].insn;
3274 if (!CALL_P (old_insn))
3275 continue;
3276 was_call = true;
3278 new_insn = attempt;
3279 while (new_insn != NULL_RTX)
3281 if (CALL_P (new_insn))
3282 break;
3283 new_insn = NEXT_INSN (new_insn);
3286 gcc_assert (new_insn != NULL_RTX);
3288 CALL_INSN_FUNCTION_USAGE (new_insn)
3289 = CALL_INSN_FUNCTION_USAGE (old_insn);
3291 for (note = REG_NOTES (old_insn);
3292 note;
3293 note = XEXP (note, 1))
3294 switch (REG_NOTE_KIND (note))
3296 case REG_NORETURN:
3297 case REG_SETJMP:
3298 case REG_TM:
3299 add_reg_note (new_insn, REG_NOTE_KIND (note),
3300 XEXP (note, 0));
3301 break;
3302 default:
3303 /* Discard all other reg notes. */
3304 break;
3307 /* Croak if there is another call in the sequence. */
3308 while (++i <= match_len)
3310 j = peep2_buf_position (peep2_current + i);
3311 old_insn = peep2_insn_data[j].insn;
3312 gcc_assert (!CALL_P (old_insn));
3314 break;
3317 /* If we matched any instruction that had a REG_ARGS_SIZE, then
3318 move those notes over to the new sequence. */
3319 as_note = NULL;
3320 for (i = match_len; i >= 0; --i)
3322 int j = peep2_buf_position (peep2_current + i);
3323 old_insn = peep2_insn_data[j].insn;
3325 as_note = find_reg_note (old_insn, REG_ARGS_SIZE, NULL);
3326 if (as_note)
3327 break;
3330 i = peep2_buf_position (peep2_current + match_len);
3331 eh_note = find_reg_note (peep2_insn_data[i].insn, REG_EH_REGION, NULL_RTX);
3333 /* Replace the old sequence with the new. */
3334 last = emit_insn_after_setloc (attempt,
3335 peep2_insn_data[i].insn,
3336 INSN_LOCATOR (peep2_insn_data[i].insn));
3337 before_try = PREV_INSN (insn);
3338 delete_insn_chain (insn, peep2_insn_data[i].insn, false);
3340 /* Re-insert the EH_REGION notes. */
3341 if (eh_note || (was_call && nonlocal_goto_handler_labels))
3343 edge eh_edge;
3344 edge_iterator ei;
3346 FOR_EACH_EDGE (eh_edge, ei, bb->succs)
3347 if (eh_edge->flags & (EDGE_EH | EDGE_ABNORMAL_CALL))
3348 break;
3350 if (eh_note)
3351 copy_reg_eh_region_note_backward (eh_note, last, before_try);
3353 if (eh_edge)
3354 for (x = last; x != before_try; x = PREV_INSN (x))
3355 if (x != BB_END (bb)
3356 && (can_throw_internal (x)
3357 || can_nonlocal_goto (x)))
3359 edge nfte, nehe;
3360 int flags;
3362 nfte = split_block (bb, x);
3363 flags = (eh_edge->flags
3364 & (EDGE_EH | EDGE_ABNORMAL));
3365 if (CALL_P (x))
3366 flags |= EDGE_ABNORMAL_CALL;
3367 nehe = make_edge (nfte->src, eh_edge->dest,
3368 flags);
3370 nehe->probability = eh_edge->probability;
3371 nfte->probability
3372 = REG_BR_PROB_BASE - nehe->probability;
3374 peep2_do_cleanup_cfg |= purge_dead_edges (nfte->dest);
3375 bb = nfte->src;
3376 eh_edge = nehe;
3379 /* Converting possibly trapping insn to non-trapping is
3380 possible. Zap dummy outgoing edges. */
3381 peep2_do_cleanup_cfg |= purge_dead_edges (bb);
3384 /* Re-insert the ARGS_SIZE notes. */
3385 if (as_note)
3386 fixup_args_size_notes (before_try, last, INTVAL (XEXP (as_note, 0)));
3388 /* If we generated a jump instruction, it won't have
3389 JUMP_LABEL set. Recompute after we're done. */
3390 for (x = last; x != before_try; x = PREV_INSN (x))
3391 if (JUMP_P (x))
3393 peep2_do_rebuild_jump_labels = true;
3394 break;
3397 return last;
3400 /* After performing a replacement in basic block BB, fix up the life
3401 information in our buffer. LAST is the last of the insns that we
3402 emitted as a replacement. PREV is the insn before the start of
3403 the replacement. MATCH_LEN is the number of instructions that were
3404 matched, and which now need to be replaced in the buffer. */
3406 static void
3407 peep2_update_life (basic_block bb, int match_len, rtx last, rtx prev)
3409 int i = peep2_buf_position (peep2_current + match_len + 1);
3410 rtx x;
3411 regset_head live;
3413 INIT_REG_SET (&live);
3414 COPY_REG_SET (&live, peep2_insn_data[i].live_before);
3416 gcc_assert (peep2_current_count >= match_len + 1);
3417 peep2_current_count -= match_len + 1;
3419 x = last;
3422 if (INSN_P (x))
3424 df_insn_rescan (x);
3425 if (peep2_current_count < MAX_INSNS_PER_PEEP2)
3427 peep2_current_count++;
3428 if (--i < 0)
3429 i = MAX_INSNS_PER_PEEP2;
3430 peep2_insn_data[i].insn = x;
3431 df_simulate_one_insn_backwards (bb, x, &live);
3432 COPY_REG_SET (peep2_insn_data[i].live_before, &live);
3435 x = PREV_INSN (x);
3437 while (x != prev);
3438 CLEAR_REG_SET (&live);
3440 peep2_current = i;
3443 /* Add INSN, which is in BB, at the end of the peep2 insn buffer if possible.
3444 Return true if we added it, false otherwise. The caller will try to match
3445 peepholes against the buffer if we return false; otherwise it will try to
3446 add more instructions to the buffer. */
3448 static bool
3449 peep2_fill_buffer (basic_block bb, rtx insn, regset live)
3451 int pos;
3453 /* Once we have filled the maximum number of insns the buffer can hold,
3454 allow the caller to match the insns against peepholes. We wait until
3455 the buffer is full in case the target has similar peepholes of different
3456 length; we always want to match the longest if possible. */
3457 if (peep2_current_count == MAX_INSNS_PER_PEEP2)
3458 return false;
3460 /* If an insn has RTX_FRAME_RELATED_P set, do not allow it to be matched with
3461 any other pattern, lest it change the semantics of the frame info. */
3462 if (RTX_FRAME_RELATED_P (insn))
3464 /* Let the buffer drain first. */
3465 if (peep2_current_count > 0)
3466 return false;
3467 /* Now the insn will be the only thing in the buffer. */
3470 pos = peep2_buf_position (peep2_current + peep2_current_count);
3471 peep2_insn_data[pos].insn = insn;
3472 COPY_REG_SET (peep2_insn_data[pos].live_before, live);
3473 peep2_current_count++;
3475 df_simulate_one_insn_forwards (bb, insn, live);
3476 return true;
3479 /* Perform the peephole2 optimization pass. */
3481 static void
3482 peephole2_optimize (void)
3484 rtx insn;
3485 bitmap live;
3486 int i;
3487 basic_block bb;
3489 peep2_do_cleanup_cfg = false;
3490 peep2_do_rebuild_jump_labels = false;
3492 df_set_flags (DF_LR_RUN_DCE);
3493 df_note_add_problem ();
3494 df_analyze ();
3496 /* Initialize the regsets we're going to use. */
3497 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3498 peep2_insn_data[i].live_before = BITMAP_ALLOC (&reg_obstack);
3499 live = BITMAP_ALLOC (&reg_obstack);
3501 FOR_EACH_BB_REVERSE (bb)
3503 bool past_end = false;
3504 int pos;
3506 rtl_profile_for_bb (bb);
3508 /* Start up propagation. */
3509 bitmap_copy (live, DF_LR_IN (bb));
3510 df_simulate_initialize_forwards (bb, live);
3511 peep2_reinit_state (live);
3513 insn = BB_HEAD (bb);
3514 for (;;)
3516 rtx attempt, head;
3517 int match_len;
3519 if (!past_end && !NONDEBUG_INSN_P (insn))
3521 next_insn:
3522 insn = NEXT_INSN (insn);
3523 if (insn == NEXT_INSN (BB_END (bb)))
3524 past_end = true;
3525 continue;
3527 if (!past_end && peep2_fill_buffer (bb, insn, live))
3528 goto next_insn;
3530 /* If we did not fill an empty buffer, it signals the end of the
3531 block. */
3532 if (peep2_current_count == 0)
3533 break;
3535 /* The buffer filled to the current maximum, so try to match. */
3537 pos = peep2_buf_position (peep2_current + peep2_current_count);
3538 peep2_insn_data[pos].insn = PEEP2_EOB;
3539 COPY_REG_SET (peep2_insn_data[pos].live_before, live);
3541 /* Match the peephole. */
3542 head = peep2_insn_data[peep2_current].insn;
3543 attempt = peephole2_insns (PATTERN (head), head, &match_len);
3544 if (attempt != NULL)
3546 rtx last = peep2_attempt (bb, head, match_len, attempt);
3547 if (last)
3549 peep2_update_life (bb, match_len, last, PREV_INSN (attempt));
3550 continue;
3554 /* No match: advance the buffer by one insn. */
3555 peep2_current = peep2_buf_position (peep2_current + 1);
3556 peep2_current_count--;
3560 default_rtl_profile ();
3561 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3562 BITMAP_FREE (peep2_insn_data[i].live_before);
3563 BITMAP_FREE (live);
3564 if (peep2_do_rebuild_jump_labels)
3565 rebuild_jump_labels (get_insns ());
3567 #endif /* HAVE_peephole2 */
3569 /* Common predicates for use with define_bypass. */
3571 /* True if the dependency between OUT_INSN and IN_INSN is on the store
3572 data not the address operand(s) of the store. IN_INSN and OUT_INSN
3573 must be either a single_set or a PARALLEL with SETs inside. */
3576 store_data_bypass_p (rtx out_insn, rtx in_insn)
3578 rtx out_set, in_set;
3579 rtx out_pat, in_pat;
3580 rtx out_exp, in_exp;
3581 int i, j;
3583 in_set = single_set (in_insn);
3584 if (in_set)
3586 if (!MEM_P (SET_DEST (in_set)))
3587 return false;
3589 out_set = single_set (out_insn);
3590 if (out_set)
3592 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_set)))
3593 return false;
3595 else
3597 out_pat = PATTERN (out_insn);
3599 if (GET_CODE (out_pat) != PARALLEL)
3600 return false;
3602 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3604 out_exp = XVECEXP (out_pat, 0, i);
3606 if (GET_CODE (out_exp) == CLOBBER)
3607 continue;
3609 gcc_assert (GET_CODE (out_exp) == SET);
3611 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_set)))
3612 return false;
3616 else
3618 in_pat = PATTERN (in_insn);
3619 gcc_assert (GET_CODE (in_pat) == PARALLEL);
3621 for (i = 0; i < XVECLEN (in_pat, 0); i++)
3623 in_exp = XVECEXP (in_pat, 0, i);
3625 if (GET_CODE (in_exp) == CLOBBER)
3626 continue;
3628 gcc_assert (GET_CODE (in_exp) == SET);
3630 if (!MEM_P (SET_DEST (in_exp)))
3631 return false;
3633 out_set = single_set (out_insn);
3634 if (out_set)
3636 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_exp)))
3637 return false;
3639 else
3641 out_pat = PATTERN (out_insn);
3642 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3644 for (j = 0; j < XVECLEN (out_pat, 0); j++)
3646 out_exp = XVECEXP (out_pat, 0, j);
3648 if (GET_CODE (out_exp) == CLOBBER)
3649 continue;
3651 gcc_assert (GET_CODE (out_exp) == SET);
3653 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_exp)))
3654 return false;
3660 return true;
3663 /* True if the dependency between OUT_INSN and IN_INSN is in the IF_THEN_ELSE
3664 condition, and not the THEN or ELSE branch. OUT_INSN may be either a single
3665 or multiple set; IN_INSN should be single_set for truth, but for convenience
3666 of insn categorization may be any JUMP or CALL insn. */
3669 if_test_bypass_p (rtx out_insn, rtx in_insn)
3671 rtx out_set, in_set;
3673 in_set = single_set (in_insn);
3674 if (! in_set)
3676 gcc_assert (JUMP_P (in_insn) || CALL_P (in_insn));
3677 return false;
3680 if (GET_CODE (SET_SRC (in_set)) != IF_THEN_ELSE)
3681 return false;
3682 in_set = SET_SRC (in_set);
3684 out_set = single_set (out_insn);
3685 if (out_set)
3687 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3688 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3689 return false;
3691 else
3693 rtx out_pat;
3694 int i;
3696 out_pat = PATTERN (out_insn);
3697 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3699 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3701 rtx exp = XVECEXP (out_pat, 0, i);
3703 if (GET_CODE (exp) == CLOBBER)
3704 continue;
3706 gcc_assert (GET_CODE (exp) == SET);
3708 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3709 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3710 return false;
3714 return true;
3717 static bool
3718 gate_handle_peephole2 (void)
3720 return (optimize > 0 && flag_peephole2);
3723 static unsigned int
3724 rest_of_handle_peephole2 (void)
3726 #ifdef HAVE_peephole2
3727 peephole2_optimize ();
3728 #endif
3729 return 0;
3732 struct rtl_opt_pass pass_peephole2 =
3735 RTL_PASS,
3736 "peephole2", /* name */
3737 gate_handle_peephole2, /* gate */
3738 rest_of_handle_peephole2, /* execute */
3739 NULL, /* sub */
3740 NULL, /* next */
3741 0, /* static_pass_number */
3742 TV_PEEPHOLE2, /* tv_id */
3743 0, /* properties_required */
3744 0, /* properties_provided */
3745 0, /* properties_destroyed */
3746 0, /* todo_flags_start */
3747 TODO_df_finish | TODO_verify_rtl_sharing |
3748 0 /* todo_flags_finish */
3752 static unsigned int
3753 rest_of_handle_split_all_insns (void)
3755 split_all_insns ();
3756 return 0;
3759 struct rtl_opt_pass pass_split_all_insns =
3762 RTL_PASS,
3763 "split1", /* name */
3764 NULL, /* gate */
3765 rest_of_handle_split_all_insns, /* execute */
3766 NULL, /* sub */
3767 NULL, /* next */
3768 0, /* static_pass_number */
3769 TV_NONE, /* tv_id */
3770 0, /* properties_required */
3771 0, /* properties_provided */
3772 0, /* properties_destroyed */
3773 0, /* todo_flags_start */
3774 0 /* todo_flags_finish */
3778 static unsigned int
3779 rest_of_handle_split_after_reload (void)
3781 /* If optimizing, then go ahead and split insns now. */
3782 #ifndef STACK_REGS
3783 if (optimize > 0)
3784 #endif
3785 split_all_insns ();
3786 return 0;
3789 struct rtl_opt_pass pass_split_after_reload =
3792 RTL_PASS,
3793 "split2", /* name */
3794 NULL, /* gate */
3795 rest_of_handle_split_after_reload, /* execute */
3796 NULL, /* sub */
3797 NULL, /* next */
3798 0, /* static_pass_number */
3799 TV_NONE, /* tv_id */
3800 0, /* properties_required */
3801 0, /* properties_provided */
3802 0, /* properties_destroyed */
3803 0, /* todo_flags_start */
3804 0 /* todo_flags_finish */
3808 static bool
3809 gate_handle_split_before_regstack (void)
3811 #if defined (HAVE_ATTR_length) && defined (STACK_REGS)
3812 /* If flow2 creates new instructions which need splitting
3813 and scheduling after reload is not done, they might not be
3814 split until final which doesn't allow splitting
3815 if HAVE_ATTR_length. */
3816 # ifdef INSN_SCHEDULING
3817 return (optimize && !flag_schedule_insns_after_reload);
3818 # else
3819 return (optimize);
3820 # endif
3821 #else
3822 return 0;
3823 #endif
3826 static unsigned int
3827 rest_of_handle_split_before_regstack (void)
3829 split_all_insns ();
3830 return 0;
3833 struct rtl_opt_pass pass_split_before_regstack =
3836 RTL_PASS,
3837 "split3", /* name */
3838 gate_handle_split_before_regstack, /* gate */
3839 rest_of_handle_split_before_regstack, /* execute */
3840 NULL, /* sub */
3841 NULL, /* next */
3842 0, /* static_pass_number */
3843 TV_NONE, /* tv_id */
3844 0, /* properties_required */
3845 0, /* properties_provided */
3846 0, /* properties_destroyed */
3847 0, /* todo_flags_start */
3848 0 /* todo_flags_finish */
3852 static bool
3853 gate_handle_split_before_sched2 (void)
3855 #ifdef INSN_SCHEDULING
3856 return optimize > 0 && flag_schedule_insns_after_reload;
3857 #else
3858 return 0;
3859 #endif
3862 static unsigned int
3863 rest_of_handle_split_before_sched2 (void)
3865 #ifdef INSN_SCHEDULING
3866 split_all_insns ();
3867 #endif
3868 return 0;
3871 struct rtl_opt_pass pass_split_before_sched2 =
3874 RTL_PASS,
3875 "split4", /* name */
3876 gate_handle_split_before_sched2, /* gate */
3877 rest_of_handle_split_before_sched2, /* execute */
3878 NULL, /* sub */
3879 NULL, /* next */
3880 0, /* static_pass_number */
3881 TV_NONE, /* tv_id */
3882 0, /* properties_required */
3883 0, /* properties_provided */
3884 0, /* properties_destroyed */
3885 0, /* todo_flags_start */
3886 TODO_verify_flow /* todo_flags_finish */
3890 /* The placement of the splitting that we do for shorten_branches
3891 depends on whether regstack is used by the target or not. */
3892 static bool
3893 gate_do_final_split (void)
3895 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3896 return 1;
3897 #else
3898 return 0;
3899 #endif
3902 struct rtl_opt_pass pass_split_for_shorten_branches =
3905 RTL_PASS,
3906 "split5", /* name */
3907 gate_do_final_split, /* gate */
3908 split_all_insns_noflow, /* execute */
3909 NULL, /* sub */
3910 NULL, /* next */
3911 0, /* static_pass_number */
3912 TV_NONE, /* tv_id */
3913 0, /* properties_required */
3914 0, /* properties_provided */
3915 0, /* properties_destroyed */
3916 0, /* todo_flags_start */
3917 TODO_verify_rtl_sharing /* todo_flags_finish */