PR middle-end/54635
[official-gcc.git] / gcc / recog.c
blobf28b0219d95db8f03b07c2bed95cb85437692866
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 || CONST_DOUBLE_AS_INT_P (XEXP (x, 1)))
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_ADDR_SPACE (XEXP (x, 0)))
634 && !MEM_VOLATILE_P (XEXP (x, 0)))
636 enum machine_mode wanted_mode = VOIDmode;
637 enum machine_mode is_mode = GET_MODE (XEXP (x, 0));
638 int pos = INTVAL (XEXP (x, 2));
640 if (GET_CODE (x) == ZERO_EXTRACT)
642 enum machine_mode new_mode
643 = mode_for_extraction (EP_extzv, 1);
644 if (new_mode != MAX_MACHINE_MODE)
645 wanted_mode = new_mode;
647 else if (GET_CODE (x) == SIGN_EXTRACT)
649 enum machine_mode new_mode
650 = mode_for_extraction (EP_extv, 1);
651 if (new_mode != MAX_MACHINE_MODE)
652 wanted_mode = new_mode;
655 /* If we have a narrower mode, we can do something. */
656 if (wanted_mode != VOIDmode
657 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
659 int offset = pos / BITS_PER_UNIT;
660 rtx newmem;
662 /* If the bytes and bits are counted differently, we
663 must adjust the offset. */
664 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
665 offset =
666 (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode) -
667 offset);
669 gcc_assert (GET_MODE_PRECISION (wanted_mode)
670 == GET_MODE_BITSIZE (wanted_mode));
671 pos %= GET_MODE_BITSIZE (wanted_mode);
673 newmem = adjust_address_nv (XEXP (x, 0), wanted_mode, offset);
675 validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
676 validate_change (object, &XEXP (x, 0), newmem, 1);
680 break;
682 default:
683 break;
687 /* Replace every occurrence of FROM in X with TO. Mark each change with
688 validate_change passing OBJECT. */
690 static void
691 validate_replace_rtx_1 (rtx *loc, rtx from, rtx to, rtx object,
692 bool simplify)
694 int i, j;
695 const char *fmt;
696 rtx x = *loc;
697 enum rtx_code code;
698 enum machine_mode op0_mode = VOIDmode;
699 int prev_changes = num_changes;
701 if (!x)
702 return;
704 code = GET_CODE (x);
705 fmt = GET_RTX_FORMAT (code);
706 if (fmt[0] == 'e')
707 op0_mode = GET_MODE (XEXP (x, 0));
709 /* X matches FROM if it is the same rtx or they are both referring to the
710 same register in the same mode. Avoid calling rtx_equal_p unless the
711 operands look similar. */
713 if (x == from
714 || (REG_P (x) && REG_P (from)
715 && GET_MODE (x) == GET_MODE (from)
716 && REGNO (x) == REGNO (from))
717 || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
718 && rtx_equal_p (x, from)))
720 validate_unshare_change (object, loc, to, 1);
721 return;
724 /* Call ourself recursively to perform the replacements.
725 We must not replace inside already replaced expression, otherwise we
726 get infinite recursion for replacements like (reg X)->(subreg (reg X))
727 done by regmove, so we must special case shared ASM_OPERANDS. */
729 if (GET_CODE (x) == PARALLEL)
731 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
733 if (j && GET_CODE (XVECEXP (x, 0, j)) == SET
734 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == ASM_OPERANDS)
736 /* Verify that operands are really shared. */
737 gcc_assert (ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (x, 0, 0)))
738 == ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP
739 (x, 0, j))));
740 validate_replace_rtx_1 (&SET_DEST (XVECEXP (x, 0, j)),
741 from, to, object, simplify);
743 else
744 validate_replace_rtx_1 (&XVECEXP (x, 0, j), from, to, object,
745 simplify);
748 else
749 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
751 if (fmt[i] == 'e')
752 validate_replace_rtx_1 (&XEXP (x, i), from, to, object, simplify);
753 else if (fmt[i] == 'E')
754 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
755 validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object,
756 simplify);
759 /* If we didn't substitute, there is nothing more to do. */
760 if (num_changes == prev_changes)
761 return;
763 /* Allow substituted expression to have different mode. This is used by
764 regmove to change mode of pseudo register. */
765 if (fmt[0] == 'e' && GET_MODE (XEXP (x, 0)) != VOIDmode)
766 op0_mode = GET_MODE (XEXP (x, 0));
768 /* Do changes needed to keep rtx consistent. Don't do any other
769 simplifications, as it is not our job. */
770 if (simplify)
771 simplify_while_replacing (loc, to, object, op0_mode);
774 /* Try replacing every occurrence of FROM in subexpression LOC of INSN
775 with TO. After all changes have been made, validate by seeing
776 if INSN is still valid. */
779 validate_replace_rtx_subexp (rtx from, rtx to, rtx insn, rtx *loc)
781 validate_replace_rtx_1 (loc, from, to, insn, true);
782 return apply_change_group ();
785 /* Try replacing every occurrence of FROM in INSN with TO. After all
786 changes have been made, validate by seeing if INSN is still valid. */
789 validate_replace_rtx (rtx from, rtx to, rtx insn)
791 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn, true);
792 return apply_change_group ();
795 /* Try replacing every occurrence of FROM in WHERE with TO. Assume that WHERE
796 is a part of INSN. After all changes have been made, validate by seeing if
797 INSN is still valid.
798 validate_replace_rtx (from, to, insn) is equivalent to
799 validate_replace_rtx_part (from, to, &PATTERN (insn), insn). */
802 validate_replace_rtx_part (rtx from, rtx to, rtx *where, rtx insn)
804 validate_replace_rtx_1 (where, from, to, insn, true);
805 return apply_change_group ();
808 /* Same as above, but do not simplify rtx afterwards. */
810 validate_replace_rtx_part_nosimplify (rtx from, rtx to, rtx *where,
811 rtx insn)
813 validate_replace_rtx_1 (where, from, to, insn, false);
814 return apply_change_group ();
818 /* Try replacing every occurrence of FROM in INSN with TO. This also
819 will replace in REG_EQUAL and REG_EQUIV notes. */
821 void
822 validate_replace_rtx_group (rtx from, rtx to, rtx insn)
824 rtx note;
825 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn, true);
826 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
827 if (REG_NOTE_KIND (note) == REG_EQUAL
828 || REG_NOTE_KIND (note) == REG_EQUIV)
829 validate_replace_rtx_1 (&XEXP (note, 0), from, to, insn, true);
832 /* Function called by note_uses to replace used subexpressions. */
833 struct validate_replace_src_data
835 rtx from; /* Old RTX */
836 rtx to; /* New RTX */
837 rtx insn; /* Insn in which substitution is occurring. */
840 static void
841 validate_replace_src_1 (rtx *x, void *data)
843 struct validate_replace_src_data *d
844 = (struct validate_replace_src_data *) data;
846 validate_replace_rtx_1 (x, d->from, d->to, d->insn, true);
849 /* Try replacing every occurrence of FROM in INSN with TO, avoiding
850 SET_DESTs. */
852 void
853 validate_replace_src_group (rtx from, rtx to, rtx insn)
855 struct validate_replace_src_data d;
857 d.from = from;
858 d.to = to;
859 d.insn = insn;
860 note_uses (&PATTERN (insn), validate_replace_src_1, &d);
863 /* Try simplify INSN.
864 Invoke simplify_rtx () on every SET_SRC and SET_DEST inside the INSN's
865 pattern and return true if something was simplified. */
867 bool
868 validate_simplify_insn (rtx insn)
870 int i;
871 rtx pat = NULL;
872 rtx newpat = NULL;
874 pat = PATTERN (insn);
876 if (GET_CODE (pat) == SET)
878 newpat = simplify_rtx (SET_SRC (pat));
879 if (newpat && !rtx_equal_p (SET_SRC (pat), newpat))
880 validate_change (insn, &SET_SRC (pat), newpat, 1);
881 newpat = simplify_rtx (SET_DEST (pat));
882 if (newpat && !rtx_equal_p (SET_DEST (pat), newpat))
883 validate_change (insn, &SET_DEST (pat), newpat, 1);
885 else if (GET_CODE (pat) == PARALLEL)
886 for (i = 0; i < XVECLEN (pat, 0); i++)
888 rtx s = XVECEXP (pat, 0, i);
890 if (GET_CODE (XVECEXP (pat, 0, i)) == SET)
892 newpat = simplify_rtx (SET_SRC (s));
893 if (newpat && !rtx_equal_p (SET_SRC (s), newpat))
894 validate_change (insn, &SET_SRC (s), newpat, 1);
895 newpat = simplify_rtx (SET_DEST (s));
896 if (newpat && !rtx_equal_p (SET_DEST (s), newpat))
897 validate_change (insn, &SET_DEST (s), newpat, 1);
900 return ((num_changes_pending () > 0) && (apply_change_group () > 0));
903 #ifdef HAVE_cc0
904 /* Return 1 if the insn using CC0 set by INSN does not contain
905 any ordered tests applied to the condition codes.
906 EQ and NE tests do not count. */
909 next_insn_tests_no_inequality (rtx insn)
911 rtx next = next_cc0_user (insn);
913 /* If there is no next insn, we have to take the conservative choice. */
914 if (next == 0)
915 return 0;
917 return (INSN_P (next)
918 && ! inequality_comparisons_p (PATTERN (next)));
920 #endif
922 /* Return 1 if OP is a valid general operand for machine mode MODE.
923 This is either a register reference, a memory reference,
924 or a constant. In the case of a memory reference, the address
925 is checked for general validity for the target machine.
927 Register and memory references must have mode MODE in order to be valid,
928 but some constants have no machine mode and are valid for any mode.
930 If MODE is VOIDmode, OP is checked for validity for whatever mode
931 it has.
933 The main use of this function is as a predicate in match_operand
934 expressions in the machine description. */
937 general_operand (rtx op, enum machine_mode mode)
939 enum rtx_code code = GET_CODE (op);
941 if (mode == VOIDmode)
942 mode = GET_MODE (op);
944 /* Don't accept CONST_INT or anything similar
945 if the caller wants something floating. */
946 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
947 && GET_MODE_CLASS (mode) != MODE_INT
948 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
949 return 0;
951 if (CONST_INT_P (op)
952 && mode != VOIDmode
953 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
954 return 0;
956 if (CONSTANT_P (op))
957 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
958 || mode == VOIDmode)
959 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
960 && targetm.legitimate_constant_p (mode == VOIDmode
961 ? GET_MODE (op)
962 : mode, op));
964 /* Except for certain constants with VOIDmode, already checked for,
965 OP's mode must match MODE if MODE specifies a mode. */
967 if (GET_MODE (op) != mode)
968 return 0;
970 if (code == SUBREG)
972 rtx sub = SUBREG_REG (op);
974 #ifdef INSN_SCHEDULING
975 /* On machines that have insn scheduling, we want all memory
976 reference to be explicit, so outlaw paradoxical SUBREGs.
977 However, we must allow them after reload so that they can
978 get cleaned up by cleanup_subreg_operands. */
979 if (!reload_completed && MEM_P (sub)
980 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (sub)))
981 return 0;
982 #endif
983 /* Avoid memories with nonzero SUBREG_BYTE, as offsetting the memory
984 may result in incorrect reference. We should simplify all valid
985 subregs of MEM anyway. But allow this after reload because we
986 might be called from cleanup_subreg_operands.
988 ??? This is a kludge. */
989 if (!reload_completed && SUBREG_BYTE (op) != 0
990 && MEM_P (sub))
991 return 0;
993 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
994 create such rtl, and we must reject it. */
995 if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
996 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
997 return 0;
999 op = sub;
1000 code = GET_CODE (op);
1003 if (code == REG)
1004 return (REGNO (op) >= FIRST_PSEUDO_REGISTER
1005 || in_hard_reg_set_p (operand_reg_set, GET_MODE (op), REGNO (op)));
1007 if (code == MEM)
1009 rtx y = XEXP (op, 0);
1011 if (! volatile_ok && MEM_VOLATILE_P (op))
1012 return 0;
1014 /* Use the mem's mode, since it will be reloaded thus. */
1015 if (memory_address_addr_space_p (GET_MODE (op), y, MEM_ADDR_SPACE (op)))
1016 return 1;
1019 return 0;
1022 /* Return 1 if OP is a valid memory address for a memory reference
1023 of mode MODE.
1025 The main use of this function is as a predicate in match_operand
1026 expressions in the machine description. */
1029 address_operand (rtx op, enum machine_mode mode)
1031 return memory_address_p (mode, op);
1034 /* Return 1 if OP is a register reference of mode MODE.
1035 If MODE is VOIDmode, accept a register in any mode.
1037 The main use of this function is as a predicate in match_operand
1038 expressions in the machine description. */
1041 register_operand (rtx op, enum machine_mode mode)
1043 if (GET_MODE (op) != mode && mode != VOIDmode)
1044 return 0;
1046 if (GET_CODE (op) == SUBREG)
1048 rtx sub = SUBREG_REG (op);
1050 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1051 because it is guaranteed to be reloaded into one.
1052 Just make sure the MEM is valid in itself.
1053 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1054 but currently it does result from (SUBREG (REG)...) where the
1055 reg went on the stack.) */
1056 if (! reload_completed && MEM_P (sub))
1057 return general_operand (op, mode);
1059 #ifdef CANNOT_CHANGE_MODE_CLASS
1060 if (REG_P (sub)
1061 && REGNO (sub) < FIRST_PSEUDO_REGISTER
1062 && REG_CANNOT_CHANGE_MODE_P (REGNO (sub), GET_MODE (sub), mode)
1063 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_INT
1064 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_FLOAT)
1065 return 0;
1066 #endif
1068 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
1069 create such rtl, and we must reject it. */
1070 if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
1071 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
1072 return 0;
1074 op = sub;
1077 return (REG_P (op)
1078 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1079 || in_hard_reg_set_p (operand_reg_set,
1080 GET_MODE (op), REGNO (op))));
1083 /* Return 1 for a register in Pmode; ignore the tested mode. */
1086 pmode_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1088 return register_operand (op, Pmode);
1091 /* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
1092 or a hard register. */
1095 scratch_operand (rtx op, enum machine_mode mode)
1097 if (GET_MODE (op) != mode && mode != VOIDmode)
1098 return 0;
1100 return (GET_CODE (op) == SCRATCH
1101 || (REG_P (op)
1102 && REGNO (op) < FIRST_PSEUDO_REGISTER));
1105 /* Return 1 if OP is a valid immediate operand for mode MODE.
1107 The main use of this function is as a predicate in match_operand
1108 expressions in the machine description. */
1111 immediate_operand (rtx op, enum machine_mode mode)
1113 /* Don't accept CONST_INT or anything similar
1114 if the caller wants something floating. */
1115 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1116 && GET_MODE_CLASS (mode) != MODE_INT
1117 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1118 return 0;
1120 if (CONST_INT_P (op)
1121 && mode != VOIDmode
1122 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1123 return 0;
1125 return (CONSTANT_P (op)
1126 && (GET_MODE (op) == mode || mode == VOIDmode
1127 || GET_MODE (op) == VOIDmode)
1128 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1129 && targetm.legitimate_constant_p (mode == VOIDmode
1130 ? GET_MODE (op)
1131 : mode, op));
1134 /* Returns 1 if OP is an operand that is a CONST_INT. */
1137 const_int_operand (rtx op, enum machine_mode mode)
1139 if (!CONST_INT_P (op))
1140 return 0;
1142 if (mode != VOIDmode
1143 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1144 return 0;
1146 return 1;
1149 /* Returns 1 if OP is an operand that is a constant integer or constant
1150 floating-point number. */
1153 const_double_operand (rtx op, enum machine_mode mode)
1155 /* Don't accept CONST_INT or anything similar
1156 if the caller wants something floating. */
1157 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1158 && GET_MODE_CLASS (mode) != MODE_INT
1159 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1160 return 0;
1162 return ((CONST_DOUBLE_P (op) || CONST_INT_P (op))
1163 && (mode == VOIDmode || GET_MODE (op) == mode
1164 || GET_MODE (op) == VOIDmode));
1167 /* Return 1 if OP is a general operand that is not an immediate operand. */
1170 nonimmediate_operand (rtx op, enum machine_mode mode)
1172 return (general_operand (op, mode) && ! CONSTANT_P (op));
1175 /* Return 1 if OP is a register reference or immediate value of mode MODE. */
1178 nonmemory_operand (rtx op, enum machine_mode mode)
1180 if (CONSTANT_P (op))
1181 return immediate_operand (op, mode);
1183 if (GET_MODE (op) != mode && mode != VOIDmode)
1184 return 0;
1186 if (GET_CODE (op) == SUBREG)
1188 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1189 because it is guaranteed to be reloaded into one.
1190 Just make sure the MEM is valid in itself.
1191 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1192 but currently it does result from (SUBREG (REG)...) where the
1193 reg went on the stack.) */
1194 if (! reload_completed && MEM_P (SUBREG_REG (op)))
1195 return general_operand (op, mode);
1196 op = SUBREG_REG (op);
1199 return (REG_P (op)
1200 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1201 || in_hard_reg_set_p (operand_reg_set,
1202 GET_MODE (op), REGNO (op))));
1205 /* Return 1 if OP is a valid operand that stands for pushing a
1206 value of mode MODE onto the stack.
1208 The main use of this function is as a predicate in match_operand
1209 expressions in the machine description. */
1212 push_operand (rtx op, enum machine_mode mode)
1214 unsigned int rounded_size = GET_MODE_SIZE (mode);
1216 #ifdef PUSH_ROUNDING
1217 rounded_size = PUSH_ROUNDING (rounded_size);
1218 #endif
1220 if (!MEM_P (op))
1221 return 0;
1223 if (mode != VOIDmode && GET_MODE (op) != mode)
1224 return 0;
1226 op = XEXP (op, 0);
1228 if (rounded_size == GET_MODE_SIZE (mode))
1230 if (GET_CODE (op) != STACK_PUSH_CODE)
1231 return 0;
1233 else
1235 if (GET_CODE (op) != PRE_MODIFY
1236 || GET_CODE (XEXP (op, 1)) != PLUS
1237 || XEXP (XEXP (op, 1), 0) != XEXP (op, 0)
1238 || !CONST_INT_P (XEXP (XEXP (op, 1), 1))
1239 #ifdef STACK_GROWS_DOWNWARD
1240 || INTVAL (XEXP (XEXP (op, 1), 1)) != - (int) rounded_size
1241 #else
1242 || INTVAL (XEXP (XEXP (op, 1), 1)) != (int) rounded_size
1243 #endif
1245 return 0;
1248 return XEXP (op, 0) == stack_pointer_rtx;
1251 /* Return 1 if OP is a valid operand that stands for popping a
1252 value of mode MODE off the stack.
1254 The main use of this function is as a predicate in match_operand
1255 expressions in the machine description. */
1258 pop_operand (rtx op, enum machine_mode mode)
1260 if (!MEM_P (op))
1261 return 0;
1263 if (mode != VOIDmode && GET_MODE (op) != mode)
1264 return 0;
1266 op = XEXP (op, 0);
1268 if (GET_CODE (op) != STACK_POP_CODE)
1269 return 0;
1271 return XEXP (op, 0) == stack_pointer_rtx;
1274 /* Return 1 if ADDR is a valid memory address
1275 for mode MODE in address space AS. */
1278 memory_address_addr_space_p (enum machine_mode mode ATTRIBUTE_UNUSED,
1279 rtx addr, addr_space_t as)
1281 #ifdef GO_IF_LEGITIMATE_ADDRESS
1282 gcc_assert (ADDR_SPACE_GENERIC_P (as));
1283 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1284 return 0;
1286 win:
1287 return 1;
1288 #else
1289 return targetm.addr_space.legitimate_address_p (mode, addr, 0, as);
1290 #endif
1293 /* Return 1 if OP is a valid memory reference with mode MODE,
1294 including a valid address.
1296 The main use of this function is as a predicate in match_operand
1297 expressions in the machine description. */
1300 memory_operand (rtx op, enum machine_mode mode)
1302 rtx inner;
1304 if (! reload_completed)
1305 /* Note that no SUBREG is a memory operand before end of reload pass,
1306 because (SUBREG (MEM...)) forces reloading into a register. */
1307 return MEM_P (op) && general_operand (op, mode);
1309 if (mode != VOIDmode && GET_MODE (op) != mode)
1310 return 0;
1312 inner = op;
1313 if (GET_CODE (inner) == SUBREG)
1314 inner = SUBREG_REG (inner);
1316 return (MEM_P (inner) && general_operand (op, mode));
1319 /* Return 1 if OP is a valid indirect memory reference with mode MODE;
1320 that is, a memory reference whose address is a general_operand. */
1323 indirect_operand (rtx op, enum machine_mode mode)
1325 /* Before reload, a SUBREG isn't in memory (see memory_operand, above). */
1326 if (! reload_completed
1327 && GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))
1329 int offset = SUBREG_BYTE (op);
1330 rtx inner = SUBREG_REG (op);
1332 if (mode != VOIDmode && GET_MODE (op) != mode)
1333 return 0;
1335 /* The only way that we can have a general_operand as the resulting
1336 address is if OFFSET is zero and the address already is an operand
1337 or if the address is (plus Y (const_int -OFFSET)) and Y is an
1338 operand. */
1340 return ((offset == 0 && general_operand (XEXP (inner, 0), Pmode))
1341 || (GET_CODE (XEXP (inner, 0)) == PLUS
1342 && CONST_INT_P (XEXP (XEXP (inner, 0), 1))
1343 && INTVAL (XEXP (XEXP (inner, 0), 1)) == -offset
1344 && general_operand (XEXP (XEXP (inner, 0), 0), Pmode)));
1347 return (MEM_P (op)
1348 && memory_operand (op, mode)
1349 && general_operand (XEXP (op, 0), Pmode));
1352 /* Return 1 if this is an ordered comparison operator (not including
1353 ORDERED and UNORDERED). */
1356 ordered_comparison_operator (rtx op, enum machine_mode mode)
1358 if (mode != VOIDmode && GET_MODE (op) != mode)
1359 return false;
1360 switch (GET_CODE (op))
1362 case EQ:
1363 case NE:
1364 case LT:
1365 case LTU:
1366 case LE:
1367 case LEU:
1368 case GT:
1369 case GTU:
1370 case GE:
1371 case GEU:
1372 return true;
1373 default:
1374 return false;
1378 /* Return 1 if this is a comparison operator. This allows the use of
1379 MATCH_OPERATOR to recognize all the branch insns. */
1382 comparison_operator (rtx op, enum machine_mode mode)
1384 return ((mode == VOIDmode || GET_MODE (op) == mode)
1385 && COMPARISON_P (op));
1388 /* If BODY is an insn body that uses ASM_OPERANDS, return it. */
1391 extract_asm_operands (rtx body)
1393 rtx tmp;
1394 switch (GET_CODE (body))
1396 case ASM_OPERANDS:
1397 return body;
1399 case SET:
1400 /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
1401 tmp = SET_SRC (body);
1402 if (GET_CODE (tmp) == ASM_OPERANDS)
1403 return tmp;
1404 break;
1406 case PARALLEL:
1407 tmp = XVECEXP (body, 0, 0);
1408 if (GET_CODE (tmp) == ASM_OPERANDS)
1409 return tmp;
1410 if (GET_CODE (tmp) == SET)
1412 tmp = SET_SRC (tmp);
1413 if (GET_CODE (tmp) == ASM_OPERANDS)
1414 return tmp;
1416 break;
1418 default:
1419 break;
1421 return NULL;
1424 /* If BODY is an insn body that uses ASM_OPERANDS,
1425 return the number of operands (both input and output) in the insn.
1426 Otherwise return -1. */
1429 asm_noperands (const_rtx body)
1431 rtx asm_op = extract_asm_operands (CONST_CAST_RTX (body));
1432 int n_sets = 0;
1434 if (asm_op == NULL)
1435 return -1;
1437 if (GET_CODE (body) == SET)
1438 n_sets = 1;
1439 else if (GET_CODE (body) == PARALLEL)
1441 int i;
1442 if (GET_CODE (XVECEXP (body, 0, 0)) == SET)
1444 /* Multiple output operands, or 1 output plus some clobbers:
1445 body is
1446 [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...]. */
1447 /* Count backwards through CLOBBERs to determine number of SETs. */
1448 for (i = XVECLEN (body, 0); i > 0; i--)
1450 if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
1451 break;
1452 if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
1453 return -1;
1456 /* N_SETS is now number of output operands. */
1457 n_sets = i;
1459 /* Verify that all the SETs we have
1460 came from a single original asm_operands insn
1461 (so that invalid combinations are blocked). */
1462 for (i = 0; i < n_sets; i++)
1464 rtx elt = XVECEXP (body, 0, i);
1465 if (GET_CODE (elt) != SET)
1466 return -1;
1467 if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
1468 return -1;
1469 /* If these ASM_OPERANDS rtx's came from different original insns
1470 then they aren't allowed together. */
1471 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
1472 != ASM_OPERANDS_INPUT_VEC (asm_op))
1473 return -1;
1476 else
1478 /* 0 outputs, but some clobbers:
1479 body is [(asm_operands ...) (clobber (reg ...))...]. */
1480 /* Make sure all the other parallel things really are clobbers. */
1481 for (i = XVECLEN (body, 0) - 1; i > 0; i--)
1482 if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
1483 return -1;
1487 return (ASM_OPERANDS_INPUT_LENGTH (asm_op)
1488 + ASM_OPERANDS_LABEL_LENGTH (asm_op) + n_sets);
1491 /* Assuming BODY is an insn body that uses ASM_OPERANDS,
1492 copy its operands (both input and output) into the vector OPERANDS,
1493 the locations of the operands within the insn into the vector OPERAND_LOCS,
1494 and the constraints for the operands into CONSTRAINTS.
1495 Write the modes of the operands into MODES.
1496 Return the assembler-template.
1498 If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1499 we don't store that info. */
1501 const char *
1502 decode_asm_operands (rtx body, rtx *operands, rtx **operand_locs,
1503 const char **constraints, enum machine_mode *modes,
1504 location_t *loc)
1506 int nbase = 0, n, i;
1507 rtx asmop;
1509 switch (GET_CODE (body))
1511 case ASM_OPERANDS:
1512 /* Zero output asm: BODY is (asm_operands ...). */
1513 asmop = body;
1514 break;
1516 case SET:
1517 /* Single output asm: BODY is (set OUTPUT (asm_operands ...)). */
1518 asmop = SET_SRC (body);
1520 /* The output is in the SET.
1521 Its constraint is in the ASM_OPERANDS itself. */
1522 if (operands)
1523 operands[0] = SET_DEST (body);
1524 if (operand_locs)
1525 operand_locs[0] = &SET_DEST (body);
1526 if (constraints)
1527 constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
1528 if (modes)
1529 modes[0] = GET_MODE (SET_DEST (body));
1530 nbase = 1;
1531 break;
1533 case PARALLEL:
1535 int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
1537 asmop = XVECEXP (body, 0, 0);
1538 if (GET_CODE (asmop) == SET)
1540 asmop = SET_SRC (asmop);
1542 /* At least one output, plus some CLOBBERs. The outputs are in
1543 the SETs. Their constraints are in the ASM_OPERANDS itself. */
1544 for (i = 0; i < nparallel; i++)
1546 if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1547 break; /* Past last SET */
1548 if (operands)
1549 operands[i] = SET_DEST (XVECEXP (body, 0, i));
1550 if (operand_locs)
1551 operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
1552 if (constraints)
1553 constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
1554 if (modes)
1555 modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
1557 nbase = i;
1559 break;
1562 default:
1563 gcc_unreachable ();
1566 n = ASM_OPERANDS_INPUT_LENGTH (asmop);
1567 for (i = 0; i < n; i++)
1569 if (operand_locs)
1570 operand_locs[nbase + i] = &ASM_OPERANDS_INPUT (asmop, i);
1571 if (operands)
1572 operands[nbase + i] = ASM_OPERANDS_INPUT (asmop, i);
1573 if (constraints)
1574 constraints[nbase + i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1575 if (modes)
1576 modes[nbase + i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1578 nbase += n;
1580 n = ASM_OPERANDS_LABEL_LENGTH (asmop);
1581 for (i = 0; i < n; i++)
1583 if (operand_locs)
1584 operand_locs[nbase + i] = &ASM_OPERANDS_LABEL (asmop, i);
1585 if (operands)
1586 operands[nbase + i] = ASM_OPERANDS_LABEL (asmop, i);
1587 if (constraints)
1588 constraints[nbase + i] = "";
1589 if (modes)
1590 modes[nbase + i] = Pmode;
1593 if (loc)
1594 *loc = ASM_OPERANDS_SOURCE_LOCATION (asmop);
1596 return ASM_OPERANDS_TEMPLATE (asmop);
1599 /* Check if an asm_operand matches its constraints.
1600 Return > 0 if ok, = 0 if bad, < 0 if inconclusive. */
1603 asm_operand_ok (rtx op, const char *constraint, const char **constraints)
1605 int result = 0;
1606 #ifdef AUTO_INC_DEC
1607 bool incdec_ok = false;
1608 #endif
1610 /* Use constrain_operands after reload. */
1611 gcc_assert (!reload_completed);
1613 /* Empty constraint string is the same as "X,...,X", i.e. X for as
1614 many alternatives as required to match the other operands. */
1615 if (*constraint == '\0')
1616 result = 1;
1618 while (*constraint)
1620 char c = *constraint;
1621 int len;
1622 switch (c)
1624 case ',':
1625 constraint++;
1626 continue;
1627 case '=':
1628 case '+':
1629 case '*':
1630 case '%':
1631 case '!':
1632 case '#':
1633 case '&':
1634 case '?':
1635 break;
1637 case '0': case '1': case '2': case '3': case '4':
1638 case '5': case '6': case '7': case '8': case '9':
1639 /* If caller provided constraints pointer, look up
1640 the maching constraint. Otherwise, our caller should have
1641 given us the proper matching constraint, but we can't
1642 actually fail the check if they didn't. Indicate that
1643 results are inconclusive. */
1644 if (constraints)
1646 char *end;
1647 unsigned long match;
1649 match = strtoul (constraint, &end, 10);
1650 if (!result)
1651 result = asm_operand_ok (op, constraints[match], NULL);
1652 constraint = (const char *) end;
1654 else
1657 constraint++;
1658 while (ISDIGIT (*constraint));
1659 if (! result)
1660 result = -1;
1662 continue;
1664 case 'p':
1665 if (address_operand (op, VOIDmode))
1666 result = 1;
1667 break;
1669 case TARGET_MEM_CONSTRAINT:
1670 case 'V': /* non-offsettable */
1671 if (memory_operand (op, VOIDmode))
1672 result = 1;
1673 break;
1675 case 'o': /* offsettable */
1676 if (offsettable_nonstrict_memref_p (op))
1677 result = 1;
1678 break;
1680 case '<':
1681 /* ??? Before auto-inc-dec, auto inc/dec insns are not supposed to exist,
1682 excepting those that expand_call created. Further, on some
1683 machines which do not have generalized auto inc/dec, an inc/dec
1684 is not a memory_operand.
1686 Match any memory and hope things are resolved after reload. */
1688 if (MEM_P (op)
1689 && (1
1690 || GET_CODE (XEXP (op, 0)) == PRE_DEC
1691 || GET_CODE (XEXP (op, 0)) == POST_DEC))
1692 result = 1;
1693 #ifdef AUTO_INC_DEC
1694 incdec_ok = true;
1695 #endif
1696 break;
1698 case '>':
1699 if (MEM_P (op)
1700 && (1
1701 || GET_CODE (XEXP (op, 0)) == PRE_INC
1702 || GET_CODE (XEXP (op, 0)) == POST_INC))
1703 result = 1;
1704 #ifdef AUTO_INC_DEC
1705 incdec_ok = true;
1706 #endif
1707 break;
1709 case 'E':
1710 case 'F':
1711 if (CONST_DOUBLE_AS_FLOAT_P (op)
1712 || (GET_CODE (op) == CONST_VECTOR
1713 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
1714 result = 1;
1715 break;
1717 case 'G':
1718 if (CONST_DOUBLE_AS_FLOAT_P (op)
1719 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'G', constraint))
1720 result = 1;
1721 break;
1722 case 'H':
1723 if (CONST_DOUBLE_AS_FLOAT_P (op)
1724 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'H', constraint))
1725 result = 1;
1726 break;
1728 case 's':
1729 if (CONST_INT_P (op) || CONST_DOUBLE_AS_INT_P (op))
1730 break;
1731 /* Fall through. */
1733 case 'i':
1734 if (CONSTANT_P (op) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op)))
1735 result = 1;
1736 break;
1738 case 'n':
1739 if (CONST_INT_P (op) || CONST_DOUBLE_AS_INT_P (op))
1740 result = 1;
1741 break;
1743 case 'I':
1744 if (CONST_INT_P (op)
1745 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'I', constraint))
1746 result = 1;
1747 break;
1748 case 'J':
1749 if (CONST_INT_P (op)
1750 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'J', constraint))
1751 result = 1;
1752 break;
1753 case 'K':
1754 if (CONST_INT_P (op)
1755 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'K', constraint))
1756 result = 1;
1757 break;
1758 case 'L':
1759 if (CONST_INT_P (op)
1760 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'L', constraint))
1761 result = 1;
1762 break;
1763 case 'M':
1764 if (CONST_INT_P (op)
1765 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'M', constraint))
1766 result = 1;
1767 break;
1768 case 'N':
1769 if (CONST_INT_P (op)
1770 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'N', constraint))
1771 result = 1;
1772 break;
1773 case 'O':
1774 if (CONST_INT_P (op)
1775 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'O', constraint))
1776 result = 1;
1777 break;
1778 case 'P':
1779 if (CONST_INT_P (op)
1780 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'P', constraint))
1781 result = 1;
1782 break;
1784 case 'X':
1785 result = 1;
1786 break;
1788 case 'g':
1789 if (general_operand (op, VOIDmode))
1790 result = 1;
1791 break;
1793 default:
1794 /* For all other letters, we first check for a register class,
1795 otherwise it is an EXTRA_CONSTRAINT. */
1796 if (REG_CLASS_FROM_CONSTRAINT (c, constraint) != NO_REGS)
1798 case 'r':
1799 if (GET_MODE (op) == BLKmode)
1800 break;
1801 if (register_operand (op, VOIDmode))
1802 result = 1;
1804 #ifdef EXTRA_CONSTRAINT_STR
1805 else if (EXTRA_MEMORY_CONSTRAINT (c, constraint))
1806 /* Every memory operand can be reloaded to fit. */
1807 result = result || memory_operand (op, VOIDmode);
1808 else if (EXTRA_ADDRESS_CONSTRAINT (c, constraint))
1809 /* Every address operand can be reloaded to fit. */
1810 result = result || address_operand (op, VOIDmode);
1811 else if (EXTRA_CONSTRAINT_STR (op, c, constraint))
1812 result = 1;
1813 #endif
1814 break;
1816 len = CONSTRAINT_LEN (c, constraint);
1818 constraint++;
1819 while (--len && *constraint);
1820 if (len)
1821 return 0;
1824 #ifdef AUTO_INC_DEC
1825 /* For operands without < or > constraints reject side-effects. */
1826 if (!incdec_ok && result && MEM_P (op))
1827 switch (GET_CODE (XEXP (op, 0)))
1829 case PRE_INC:
1830 case POST_INC:
1831 case PRE_DEC:
1832 case POST_DEC:
1833 case PRE_MODIFY:
1834 case POST_MODIFY:
1835 return 0;
1836 default:
1837 break;
1839 #endif
1841 return result;
1844 /* Given an rtx *P, if it is a sum containing an integer constant term,
1845 return the location (type rtx *) of the pointer to that constant term.
1846 Otherwise, return a null pointer. */
1848 rtx *
1849 find_constant_term_loc (rtx *p)
1851 rtx *tem;
1852 enum rtx_code code = GET_CODE (*p);
1854 /* If *P IS such a constant term, P is its location. */
1856 if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1857 || code == CONST)
1858 return p;
1860 /* Otherwise, if not a sum, it has no constant term. */
1862 if (GET_CODE (*p) != PLUS)
1863 return 0;
1865 /* If one of the summands is constant, return its location. */
1867 if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1868 && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1869 return p;
1871 /* Otherwise, check each summand for containing a constant term. */
1873 if (XEXP (*p, 0) != 0)
1875 tem = find_constant_term_loc (&XEXP (*p, 0));
1876 if (tem != 0)
1877 return tem;
1880 if (XEXP (*p, 1) != 0)
1882 tem = find_constant_term_loc (&XEXP (*p, 1));
1883 if (tem != 0)
1884 return tem;
1887 return 0;
1890 /* Return 1 if OP is a memory reference
1891 whose address contains no side effects
1892 and remains valid after the addition
1893 of a positive integer less than the
1894 size of the object being referenced.
1896 We assume that the original address is valid and do not check it.
1898 This uses strict_memory_address_p as a subroutine, so
1899 don't use it before reload. */
1902 offsettable_memref_p (rtx op)
1904 return ((MEM_P (op))
1905 && offsettable_address_addr_space_p (1, GET_MODE (op), XEXP (op, 0),
1906 MEM_ADDR_SPACE (op)));
1909 /* Similar, but don't require a strictly valid mem ref:
1910 consider pseudo-regs valid as index or base regs. */
1913 offsettable_nonstrict_memref_p (rtx op)
1915 return ((MEM_P (op))
1916 && offsettable_address_addr_space_p (0, GET_MODE (op), XEXP (op, 0),
1917 MEM_ADDR_SPACE (op)));
1920 /* Return 1 if Y is a memory address which contains no side effects
1921 and would remain valid for address space AS after the addition of
1922 a positive integer less than the size of that mode.
1924 We assume that the original address is valid and do not check it.
1925 We do check that it is valid for narrower modes.
1927 If STRICTP is nonzero, we require a strictly valid address,
1928 for the sake of use in reload.c. */
1931 offsettable_address_addr_space_p (int strictp, enum machine_mode mode, rtx y,
1932 addr_space_t as)
1934 enum rtx_code ycode = GET_CODE (y);
1935 rtx z;
1936 rtx y1 = y;
1937 rtx *y2;
1938 int (*addressp) (enum machine_mode, rtx, addr_space_t) =
1939 (strictp ? strict_memory_address_addr_space_p
1940 : memory_address_addr_space_p);
1941 unsigned int mode_sz = GET_MODE_SIZE (mode);
1943 if (CONSTANT_ADDRESS_P (y))
1944 return 1;
1946 /* Adjusting an offsettable address involves changing to a narrower mode.
1947 Make sure that's OK. */
1949 if (mode_dependent_address_p (y, as))
1950 return 0;
1952 /* ??? How much offset does an offsettable BLKmode reference need?
1953 Clearly that depends on the situation in which it's being used.
1954 However, the current situation in which we test 0xffffffff is
1955 less than ideal. Caveat user. */
1956 if (mode_sz == 0)
1957 mode_sz = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
1959 /* If the expression contains a constant term,
1960 see if it remains valid when max possible offset is added. */
1962 if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
1964 int good;
1966 y1 = *y2;
1967 *y2 = plus_constant (GET_MODE (y), *y2, mode_sz - 1);
1968 /* Use QImode because an odd displacement may be automatically invalid
1969 for any wider mode. But it should be valid for a single byte. */
1970 good = (*addressp) (QImode, y, as);
1972 /* In any case, restore old contents of memory. */
1973 *y2 = y1;
1974 return good;
1977 if (GET_RTX_CLASS (ycode) == RTX_AUTOINC)
1978 return 0;
1980 /* The offset added here is chosen as the maximum offset that
1981 any instruction could need to add when operating on something
1982 of the specified mode. We assume that if Y and Y+c are
1983 valid addresses then so is Y+d for all 0<d<c. adjust_address will
1984 go inside a LO_SUM here, so we do so as well. */
1985 if (GET_CODE (y) == LO_SUM
1986 && mode != BLKmode
1987 && mode_sz <= GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT)
1988 z = gen_rtx_LO_SUM (GET_MODE (y), XEXP (y, 0),
1989 plus_constant (GET_MODE (y), XEXP (y, 1),
1990 mode_sz - 1));
1991 else
1992 z = plus_constant (GET_MODE (y), y, mode_sz - 1);
1994 /* Use QImode because an odd displacement may be automatically invalid
1995 for any wider mode. But it should be valid for a single byte. */
1996 return (*addressp) (QImode, z, as);
1999 /* Return 1 if ADDR is an address-expression whose effect depends
2000 on the mode of the memory reference it is used in.
2002 ADDRSPACE is the address space associated with the address.
2004 Autoincrement addressing is a typical example of mode-dependence
2005 because the amount of the increment depends on the mode. */
2007 bool
2008 mode_dependent_address_p (rtx addr, addr_space_t addrspace)
2010 /* Auto-increment addressing with anything other than post_modify
2011 or pre_modify always introduces a mode dependency. Catch such
2012 cases now instead of deferring to the target. */
2013 if (GET_CODE (addr) == PRE_INC
2014 || GET_CODE (addr) == POST_INC
2015 || GET_CODE (addr) == PRE_DEC
2016 || GET_CODE (addr) == POST_DEC)
2017 return true;
2019 return targetm.mode_dependent_address_p (addr, addrspace);
2022 /* Like extract_insn, but save insn extracted and don't extract again, when
2023 called again for the same insn expecting that recog_data still contain the
2024 valid information. This is used primary by gen_attr infrastructure that
2025 often does extract insn again and again. */
2026 void
2027 extract_insn_cached (rtx insn)
2029 if (recog_data.insn == insn && INSN_CODE (insn) >= 0)
2030 return;
2031 extract_insn (insn);
2032 recog_data.insn = insn;
2035 /* Do cached extract_insn, constrain_operands and complain about failures.
2036 Used by insn_attrtab. */
2037 void
2038 extract_constrain_insn_cached (rtx insn)
2040 extract_insn_cached (insn);
2041 if (which_alternative == -1
2042 && !constrain_operands (reload_completed))
2043 fatal_insn_not_found (insn);
2046 /* Do cached constrain_operands and complain about failures. */
2048 constrain_operands_cached (int strict)
2050 if (which_alternative == -1)
2051 return constrain_operands (strict);
2052 else
2053 return 1;
2056 /* Analyze INSN and fill in recog_data. */
2058 void
2059 extract_insn (rtx insn)
2061 int i;
2062 int icode;
2063 int noperands;
2064 rtx body = PATTERN (insn);
2066 recog_data.n_operands = 0;
2067 recog_data.n_alternatives = 0;
2068 recog_data.n_dups = 0;
2069 recog_data.is_asm = false;
2071 switch (GET_CODE (body))
2073 case USE:
2074 case CLOBBER:
2075 case ASM_INPUT:
2076 case ADDR_VEC:
2077 case ADDR_DIFF_VEC:
2078 case VAR_LOCATION:
2079 return;
2081 case SET:
2082 if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
2083 goto asm_insn;
2084 else
2085 goto normal_insn;
2086 case PARALLEL:
2087 if ((GET_CODE (XVECEXP (body, 0, 0)) == SET
2088 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
2089 || GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
2090 goto asm_insn;
2091 else
2092 goto normal_insn;
2093 case ASM_OPERANDS:
2094 asm_insn:
2095 recog_data.n_operands = noperands = asm_noperands (body);
2096 if (noperands >= 0)
2098 /* This insn is an `asm' with operands. */
2100 /* expand_asm_operands makes sure there aren't too many operands. */
2101 gcc_assert (noperands <= MAX_RECOG_OPERANDS);
2103 /* Now get the operand values and constraints out of the insn. */
2104 decode_asm_operands (body, recog_data.operand,
2105 recog_data.operand_loc,
2106 recog_data.constraints,
2107 recog_data.operand_mode, NULL);
2108 memset (recog_data.is_operator, 0, sizeof recog_data.is_operator);
2109 if (noperands > 0)
2111 const char *p = recog_data.constraints[0];
2112 recog_data.n_alternatives = 1;
2113 while (*p)
2114 recog_data.n_alternatives += (*p++ == ',');
2116 recog_data.is_asm = true;
2117 break;
2119 fatal_insn_not_found (insn);
2121 default:
2122 normal_insn:
2123 /* Ordinary insn: recognize it, get the operands via insn_extract
2124 and get the constraints. */
2126 icode = recog_memoized (insn);
2127 if (icode < 0)
2128 fatal_insn_not_found (insn);
2130 recog_data.n_operands = noperands = insn_data[icode].n_operands;
2131 recog_data.n_alternatives = insn_data[icode].n_alternatives;
2132 recog_data.n_dups = insn_data[icode].n_dups;
2134 insn_extract (insn);
2136 for (i = 0; i < noperands; i++)
2138 recog_data.constraints[i] = insn_data[icode].operand[i].constraint;
2139 recog_data.is_operator[i] = insn_data[icode].operand[i].is_operator;
2140 recog_data.operand_mode[i] = insn_data[icode].operand[i].mode;
2141 /* VOIDmode match_operands gets mode from their real operand. */
2142 if (recog_data.operand_mode[i] == VOIDmode)
2143 recog_data.operand_mode[i] = GET_MODE (recog_data.operand[i]);
2146 for (i = 0; i < noperands; i++)
2147 recog_data.operand_type[i]
2148 = (recog_data.constraints[i][0] == '=' ? OP_OUT
2149 : recog_data.constraints[i][0] == '+' ? OP_INOUT
2150 : OP_IN);
2152 gcc_assert (recog_data.n_alternatives <= MAX_RECOG_ALTERNATIVES);
2154 if (INSN_CODE (insn) < 0)
2155 for (i = 0; i < recog_data.n_alternatives; i++)
2156 recog_data.alternative_enabled_p[i] = true;
2157 else
2159 recog_data.insn = insn;
2160 for (i = 0; i < recog_data.n_alternatives; i++)
2162 which_alternative = i;
2163 recog_data.alternative_enabled_p[i] = get_attr_enabled (insn);
2167 recog_data.insn = NULL;
2168 which_alternative = -1;
2171 /* After calling extract_insn, you can use this function to extract some
2172 information from the constraint strings into a more usable form.
2173 The collected data is stored in recog_op_alt. */
2174 void
2175 preprocess_constraints (void)
2177 int i;
2179 for (i = 0; i < recog_data.n_operands; i++)
2180 memset (recog_op_alt[i], 0, (recog_data.n_alternatives
2181 * sizeof (struct operand_alternative)));
2183 for (i = 0; i < recog_data.n_operands; i++)
2185 int j;
2186 struct operand_alternative *op_alt;
2187 const char *p = recog_data.constraints[i];
2189 op_alt = recog_op_alt[i];
2191 for (j = 0; j < recog_data.n_alternatives; j++)
2193 op_alt[j].cl = NO_REGS;
2194 op_alt[j].constraint = p;
2195 op_alt[j].matches = -1;
2196 op_alt[j].matched = -1;
2198 if (!recog_data.alternative_enabled_p[j])
2200 p = skip_alternative (p);
2201 continue;
2204 if (*p == '\0' || *p == ',')
2206 op_alt[j].anything_ok = 1;
2207 continue;
2210 for (;;)
2212 char c = *p;
2213 if (c == '#')
2215 c = *++p;
2216 while (c != ',' && c != '\0');
2217 if (c == ',' || c == '\0')
2219 p++;
2220 break;
2223 switch (c)
2225 case '=': case '+': case '*': case '%':
2226 case 'E': case 'F': case 'G': case 'H':
2227 case 's': case 'i': case 'n':
2228 case 'I': case 'J': case 'K': case 'L':
2229 case 'M': case 'N': case 'O': case 'P':
2230 /* These don't say anything we care about. */
2231 break;
2233 case '?':
2234 op_alt[j].reject += 6;
2235 break;
2236 case '!':
2237 op_alt[j].reject += 600;
2238 break;
2239 case '&':
2240 op_alt[j].earlyclobber = 1;
2241 break;
2243 case '0': case '1': case '2': case '3': case '4':
2244 case '5': case '6': case '7': case '8': case '9':
2246 char *end;
2247 op_alt[j].matches = strtoul (p, &end, 10);
2248 recog_op_alt[op_alt[j].matches][j].matched = i;
2249 p = end;
2251 continue;
2253 case TARGET_MEM_CONSTRAINT:
2254 op_alt[j].memory_ok = 1;
2255 break;
2256 case '<':
2257 op_alt[j].decmem_ok = 1;
2258 break;
2259 case '>':
2260 op_alt[j].incmem_ok = 1;
2261 break;
2262 case 'V':
2263 op_alt[j].nonoffmem_ok = 1;
2264 break;
2265 case 'o':
2266 op_alt[j].offmem_ok = 1;
2267 break;
2268 case 'X':
2269 op_alt[j].anything_ok = 1;
2270 break;
2272 case 'p':
2273 op_alt[j].is_address = 1;
2274 op_alt[j].cl = reg_class_subunion[(int) op_alt[j].cl]
2275 [(int) base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
2276 ADDRESS, SCRATCH)];
2277 break;
2279 case 'g':
2280 case 'r':
2281 op_alt[j].cl =
2282 reg_class_subunion[(int) op_alt[j].cl][(int) GENERAL_REGS];
2283 break;
2285 default:
2286 if (EXTRA_MEMORY_CONSTRAINT (c, p))
2288 op_alt[j].memory_ok = 1;
2289 break;
2291 if (EXTRA_ADDRESS_CONSTRAINT (c, p))
2293 op_alt[j].is_address = 1;
2294 op_alt[j].cl
2295 = (reg_class_subunion
2296 [(int) op_alt[j].cl]
2297 [(int) base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
2298 ADDRESS, SCRATCH)]);
2299 break;
2302 op_alt[j].cl
2303 = (reg_class_subunion
2304 [(int) op_alt[j].cl]
2305 [(int) REG_CLASS_FROM_CONSTRAINT ((unsigned char) c, p)]);
2306 break;
2308 p += CONSTRAINT_LEN (c, p);
2314 /* Check the operands of an insn against the insn's operand constraints
2315 and return 1 if they are valid.
2316 The information about the insn's operands, constraints, operand modes
2317 etc. is obtained from the global variables set up by extract_insn.
2319 WHICH_ALTERNATIVE is set to a number which indicates which
2320 alternative of constraints was matched: 0 for the first alternative,
2321 1 for the next, etc.
2323 In addition, when two operands are required to match
2324 and it happens that the output operand is (reg) while the
2325 input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
2326 make the output operand look like the input.
2327 This is because the output operand is the one the template will print.
2329 This is used in final, just before printing the assembler code and by
2330 the routines that determine an insn's attribute.
2332 If STRICT is a positive nonzero value, it means that we have been
2333 called after reload has been completed. In that case, we must
2334 do all checks strictly. If it is zero, it means that we have been called
2335 before reload has completed. In that case, we first try to see if we can
2336 find an alternative that matches strictly. If not, we try again, this
2337 time assuming that reload will fix up the insn. This provides a "best
2338 guess" for the alternative and is used to compute attributes of insns prior
2339 to reload. A negative value of STRICT is used for this internal call. */
2341 struct funny_match
2343 int this_op, other;
2347 constrain_operands (int strict)
2349 const char *constraints[MAX_RECOG_OPERANDS];
2350 int matching_operands[MAX_RECOG_OPERANDS];
2351 int earlyclobber[MAX_RECOG_OPERANDS];
2352 int c;
2354 struct funny_match funny_match[MAX_RECOG_OPERANDS];
2355 int funny_match_index;
2357 which_alternative = 0;
2358 if (recog_data.n_operands == 0 || recog_data.n_alternatives == 0)
2359 return 1;
2361 for (c = 0; c < recog_data.n_operands; c++)
2363 constraints[c] = recog_data.constraints[c];
2364 matching_operands[c] = -1;
2369 int seen_earlyclobber_at = -1;
2370 int opno;
2371 int lose = 0;
2372 funny_match_index = 0;
2374 if (!recog_data.alternative_enabled_p[which_alternative])
2376 int i;
2378 for (i = 0; i < recog_data.n_operands; i++)
2379 constraints[i] = skip_alternative (constraints[i]);
2381 which_alternative++;
2382 continue;
2385 for (opno = 0; opno < recog_data.n_operands; opno++)
2387 rtx op = recog_data.operand[opno];
2388 enum machine_mode mode = GET_MODE (op);
2389 const char *p = constraints[opno];
2390 int offset = 0;
2391 int win = 0;
2392 int val;
2393 int len;
2395 earlyclobber[opno] = 0;
2397 /* A unary operator may be accepted by the predicate, but it
2398 is irrelevant for matching constraints. */
2399 if (UNARY_P (op))
2400 op = XEXP (op, 0);
2402 if (GET_CODE (op) == SUBREG)
2404 if (REG_P (SUBREG_REG (op))
2405 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
2406 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
2407 GET_MODE (SUBREG_REG (op)),
2408 SUBREG_BYTE (op),
2409 GET_MODE (op));
2410 op = SUBREG_REG (op);
2413 /* An empty constraint or empty alternative
2414 allows anything which matched the pattern. */
2415 if (*p == 0 || *p == ',')
2416 win = 1;
2419 switch (c = *p, len = CONSTRAINT_LEN (c, p), c)
2421 case '\0':
2422 len = 0;
2423 break;
2424 case ',':
2425 c = '\0';
2426 break;
2428 case '?': case '!': case '*': case '%':
2429 case '=': case '+':
2430 break;
2432 case '#':
2433 /* Ignore rest of this alternative as far as
2434 constraint checking is concerned. */
2436 p++;
2437 while (*p && *p != ',');
2438 len = 0;
2439 break;
2441 case '&':
2442 earlyclobber[opno] = 1;
2443 if (seen_earlyclobber_at < 0)
2444 seen_earlyclobber_at = opno;
2445 break;
2447 case '0': case '1': case '2': case '3': case '4':
2448 case '5': case '6': case '7': case '8': case '9':
2450 /* This operand must be the same as a previous one.
2451 This kind of constraint is used for instructions such
2452 as add when they take only two operands.
2454 Note that the lower-numbered operand is passed first.
2456 If we are not testing strictly, assume that this
2457 constraint will be satisfied. */
2459 char *end;
2460 int match;
2462 match = strtoul (p, &end, 10);
2463 p = end;
2465 if (strict < 0)
2466 val = 1;
2467 else
2469 rtx op1 = recog_data.operand[match];
2470 rtx op2 = recog_data.operand[opno];
2472 /* A unary operator may be accepted by the predicate,
2473 but it is irrelevant for matching constraints. */
2474 if (UNARY_P (op1))
2475 op1 = XEXP (op1, 0);
2476 if (UNARY_P (op2))
2477 op2 = XEXP (op2, 0);
2479 val = operands_match_p (op1, op2);
2482 matching_operands[opno] = match;
2483 matching_operands[match] = opno;
2485 if (val != 0)
2486 win = 1;
2488 /* If output is *x and input is *--x, arrange later
2489 to change the output to *--x as well, since the
2490 output op is the one that will be printed. */
2491 if (val == 2 && strict > 0)
2493 funny_match[funny_match_index].this_op = opno;
2494 funny_match[funny_match_index++].other = match;
2497 len = 0;
2498 break;
2500 case 'p':
2501 /* p is used for address_operands. When we are called by
2502 gen_reload, no one will have checked that the address is
2503 strictly valid, i.e., that all pseudos requiring hard regs
2504 have gotten them. */
2505 if (strict <= 0
2506 || (strict_memory_address_p (recog_data.operand_mode[opno],
2507 op)))
2508 win = 1;
2509 break;
2511 /* No need to check general_operand again;
2512 it was done in insn-recog.c. Well, except that reload
2513 doesn't check the validity of its replacements, but
2514 that should only matter when there's a bug. */
2515 case 'g':
2516 /* Anything goes unless it is a REG and really has a hard reg
2517 but the hard reg is not in the class GENERAL_REGS. */
2518 if (REG_P (op))
2520 if (strict < 0
2521 || GENERAL_REGS == ALL_REGS
2522 || (reload_in_progress
2523 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2524 || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
2525 win = 1;
2527 else if (strict < 0 || general_operand (op, mode))
2528 win = 1;
2529 break;
2531 case 'X':
2532 /* This is used for a MATCH_SCRATCH in the cases when
2533 we don't actually need anything. So anything goes
2534 any time. */
2535 win = 1;
2536 break;
2538 case TARGET_MEM_CONSTRAINT:
2539 /* Memory operands must be valid, to the extent
2540 required by STRICT. */
2541 if (MEM_P (op))
2543 if (strict > 0
2544 && !strict_memory_address_addr_space_p
2545 (GET_MODE (op), XEXP (op, 0),
2546 MEM_ADDR_SPACE (op)))
2547 break;
2548 if (strict == 0
2549 && !memory_address_addr_space_p
2550 (GET_MODE (op), XEXP (op, 0),
2551 MEM_ADDR_SPACE (op)))
2552 break;
2553 win = 1;
2555 /* Before reload, accept what reload can turn into mem. */
2556 else if (strict < 0 && CONSTANT_P (op))
2557 win = 1;
2558 /* During reload, accept a pseudo */
2559 else if (reload_in_progress && REG_P (op)
2560 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2561 win = 1;
2562 break;
2564 case '<':
2565 if (MEM_P (op)
2566 && (GET_CODE (XEXP (op, 0)) == PRE_DEC
2567 || GET_CODE (XEXP (op, 0)) == POST_DEC))
2568 win = 1;
2569 break;
2571 case '>':
2572 if (MEM_P (op)
2573 && (GET_CODE (XEXP (op, 0)) == PRE_INC
2574 || GET_CODE (XEXP (op, 0)) == POST_INC))
2575 win = 1;
2576 break;
2578 case 'E':
2579 case 'F':
2580 if (CONST_DOUBLE_AS_FLOAT_P (op)
2581 || (GET_CODE (op) == CONST_VECTOR
2582 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
2583 win = 1;
2584 break;
2586 case 'G':
2587 case 'H':
2588 if (CONST_DOUBLE_AS_FLOAT_P (op)
2589 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, p))
2590 win = 1;
2591 break;
2593 case 's':
2594 if (CONST_INT_P (op) || CONST_DOUBLE_AS_INT_P (op))
2595 break;
2596 case 'i':
2597 if (CONSTANT_P (op))
2598 win = 1;
2599 break;
2601 case 'n':
2602 if (CONST_INT_P (op) || CONST_DOUBLE_AS_INT_P (op))
2603 win = 1;
2604 break;
2606 case 'I':
2607 case 'J':
2608 case 'K':
2609 case 'L':
2610 case 'M':
2611 case 'N':
2612 case 'O':
2613 case 'P':
2614 if (CONST_INT_P (op)
2615 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, p))
2616 win = 1;
2617 break;
2619 case 'V':
2620 if (MEM_P (op)
2621 && ((strict > 0 && ! offsettable_memref_p (op))
2622 || (strict < 0
2623 && !(CONSTANT_P (op) || MEM_P (op)))
2624 || (reload_in_progress
2625 && !(REG_P (op)
2626 && REGNO (op) >= FIRST_PSEUDO_REGISTER))))
2627 win = 1;
2628 break;
2630 case 'o':
2631 if ((strict > 0 && offsettable_memref_p (op))
2632 || (strict == 0 && offsettable_nonstrict_memref_p (op))
2633 /* Before reload, accept what reload can handle. */
2634 || (strict < 0
2635 && (CONSTANT_P (op) || MEM_P (op)))
2636 /* During reload, accept a pseudo */
2637 || (reload_in_progress && REG_P (op)
2638 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2639 win = 1;
2640 break;
2642 default:
2644 enum reg_class cl;
2646 cl = (c == 'r'
2647 ? GENERAL_REGS : REG_CLASS_FROM_CONSTRAINT (c, p));
2648 if (cl != NO_REGS)
2650 if (strict < 0
2651 || (strict == 0
2652 && REG_P (op)
2653 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2654 || (strict == 0 && GET_CODE (op) == SCRATCH)
2655 || (REG_P (op)
2656 && reg_fits_class_p (op, cl, offset, mode)))
2657 win = 1;
2659 #ifdef EXTRA_CONSTRAINT_STR
2660 else if (EXTRA_CONSTRAINT_STR (op, c, p))
2661 win = 1;
2663 else if (EXTRA_MEMORY_CONSTRAINT (c, p)
2664 /* Every memory operand can be reloaded to fit. */
2665 && ((strict < 0 && MEM_P (op))
2666 /* Before reload, accept what reload can turn
2667 into mem. */
2668 || (strict < 0 && CONSTANT_P (op))
2669 /* During reload, accept a pseudo */
2670 || (reload_in_progress && REG_P (op)
2671 && REGNO (op) >= FIRST_PSEUDO_REGISTER)))
2672 win = 1;
2673 else if (EXTRA_ADDRESS_CONSTRAINT (c, p)
2674 /* Every address operand can be reloaded to fit. */
2675 && strict < 0)
2676 win = 1;
2677 /* Cater to architectures like IA-64 that define extra memory
2678 constraints without using define_memory_constraint. */
2679 else if (reload_in_progress
2680 && REG_P (op)
2681 && REGNO (op) >= FIRST_PSEUDO_REGISTER
2682 && reg_renumber[REGNO (op)] < 0
2683 && reg_equiv_mem (REGNO (op)) != 0
2684 && EXTRA_CONSTRAINT_STR
2685 (reg_equiv_mem (REGNO (op)), c, p))
2686 win = 1;
2687 #endif
2688 break;
2691 while (p += len, c);
2693 constraints[opno] = p;
2694 /* If this operand did not win somehow,
2695 this alternative loses. */
2696 if (! win)
2697 lose = 1;
2699 /* This alternative won; the operands are ok.
2700 Change whichever operands this alternative says to change. */
2701 if (! lose)
2703 int opno, eopno;
2705 /* See if any earlyclobber operand conflicts with some other
2706 operand. */
2708 if (strict > 0 && seen_earlyclobber_at >= 0)
2709 for (eopno = seen_earlyclobber_at;
2710 eopno < recog_data.n_operands;
2711 eopno++)
2712 /* Ignore earlyclobber operands now in memory,
2713 because we would often report failure when we have
2714 two memory operands, one of which was formerly a REG. */
2715 if (earlyclobber[eopno]
2716 && REG_P (recog_data.operand[eopno]))
2717 for (opno = 0; opno < recog_data.n_operands; opno++)
2718 if ((MEM_P (recog_data.operand[opno])
2719 || recog_data.operand_type[opno] != OP_OUT)
2720 && opno != eopno
2721 /* Ignore things like match_operator operands. */
2722 && *recog_data.constraints[opno] != 0
2723 && ! (matching_operands[opno] == eopno
2724 && operands_match_p (recog_data.operand[opno],
2725 recog_data.operand[eopno]))
2726 && ! safe_from_earlyclobber (recog_data.operand[opno],
2727 recog_data.operand[eopno]))
2728 lose = 1;
2730 if (! lose)
2732 while (--funny_match_index >= 0)
2734 recog_data.operand[funny_match[funny_match_index].other]
2735 = recog_data.operand[funny_match[funny_match_index].this_op];
2738 #ifdef AUTO_INC_DEC
2739 /* For operands without < or > constraints reject side-effects. */
2740 if (recog_data.is_asm)
2742 for (opno = 0; opno < recog_data.n_operands; opno++)
2743 if (MEM_P (recog_data.operand[opno]))
2744 switch (GET_CODE (XEXP (recog_data.operand[opno], 0)))
2746 case PRE_INC:
2747 case POST_INC:
2748 case PRE_DEC:
2749 case POST_DEC:
2750 case PRE_MODIFY:
2751 case POST_MODIFY:
2752 if (strchr (recog_data.constraints[opno], '<') == NULL
2753 && strchr (recog_data.constraints[opno], '>')
2754 == NULL)
2755 return 0;
2756 break;
2757 default:
2758 break;
2761 #endif
2762 return 1;
2766 which_alternative++;
2768 while (which_alternative < recog_data.n_alternatives);
2770 which_alternative = -1;
2771 /* If we are about to reject this, but we are not to test strictly,
2772 try a very loose test. Only return failure if it fails also. */
2773 if (strict == 0)
2774 return constrain_operands (-1);
2775 else
2776 return 0;
2779 /* Return true iff OPERAND (assumed to be a REG rtx)
2780 is a hard reg in class CLASS when its regno is offset by OFFSET
2781 and changed to mode MODE.
2782 If REG occupies multiple hard regs, all of them must be in CLASS. */
2784 bool
2785 reg_fits_class_p (const_rtx operand, reg_class_t cl, int offset,
2786 enum machine_mode mode)
2788 unsigned int regno = REGNO (operand);
2790 if (cl == NO_REGS)
2791 return false;
2793 /* Regno must not be a pseudo register. Offset may be negative. */
2794 return (HARD_REGISTER_NUM_P (regno)
2795 && HARD_REGISTER_NUM_P (regno + offset)
2796 && in_hard_reg_set_p (reg_class_contents[(int) cl], mode,
2797 regno + offset));
2800 /* Split single instruction. Helper function for split_all_insns and
2801 split_all_insns_noflow. Return last insn in the sequence if successful,
2802 or NULL if unsuccessful. */
2804 static rtx
2805 split_insn (rtx insn)
2807 /* Split insns here to get max fine-grain parallelism. */
2808 rtx first = PREV_INSN (insn);
2809 rtx last = try_split (PATTERN (insn), insn, 1);
2810 rtx insn_set, last_set, note;
2812 if (last == insn)
2813 return NULL_RTX;
2815 /* If the original instruction was a single set that was known to be
2816 equivalent to a constant, see if we can say the same about the last
2817 instruction in the split sequence. The two instructions must set
2818 the same destination. */
2819 insn_set = single_set (insn);
2820 if (insn_set)
2822 last_set = single_set (last);
2823 if (last_set && rtx_equal_p (SET_DEST (last_set), SET_DEST (insn_set)))
2825 note = find_reg_equal_equiv_note (insn);
2826 if (note && CONSTANT_P (XEXP (note, 0)))
2827 set_unique_reg_note (last, REG_EQUAL, XEXP (note, 0));
2828 else if (CONSTANT_P (SET_SRC (insn_set)))
2829 set_unique_reg_note (last, REG_EQUAL,
2830 copy_rtx (SET_SRC (insn_set)));
2834 /* try_split returns the NOTE that INSN became. */
2835 SET_INSN_DELETED (insn);
2837 /* ??? Coddle to md files that generate subregs in post-reload
2838 splitters instead of computing the proper hard register. */
2839 if (reload_completed && first != last)
2841 first = NEXT_INSN (first);
2842 for (;;)
2844 if (INSN_P (first))
2845 cleanup_subreg_operands (first);
2846 if (first == last)
2847 break;
2848 first = NEXT_INSN (first);
2852 return last;
2855 /* Split all insns in the function. If UPD_LIFE, update life info after. */
2857 void
2858 split_all_insns (void)
2860 sbitmap blocks;
2861 bool changed;
2862 basic_block bb;
2864 blocks = sbitmap_alloc (last_basic_block);
2865 sbitmap_zero (blocks);
2866 changed = false;
2868 FOR_EACH_BB_REVERSE (bb)
2870 rtx insn, next;
2871 bool finish = false;
2873 rtl_profile_for_bb (bb);
2874 for (insn = BB_HEAD (bb); !finish ; insn = next)
2876 /* Can't use `next_real_insn' because that might go across
2877 CODE_LABELS and short-out basic blocks. */
2878 next = NEXT_INSN (insn);
2879 finish = (insn == BB_END (bb));
2880 if (INSN_P (insn))
2882 rtx set = single_set (insn);
2884 /* Don't split no-op move insns. These should silently
2885 disappear later in final. Splitting such insns would
2886 break the code that handles LIBCALL blocks. */
2887 if (set && set_noop_p (set))
2889 /* Nops get in the way while scheduling, so delete them
2890 now if register allocation has already been done. It
2891 is too risky to try to do this before register
2892 allocation, and there are unlikely to be very many
2893 nops then anyways. */
2894 if (reload_completed)
2895 delete_insn_and_edges (insn);
2897 else
2899 if (split_insn (insn))
2901 SET_BIT (blocks, bb->index);
2902 changed = true;
2909 default_rtl_profile ();
2910 if (changed)
2911 find_many_sub_basic_blocks (blocks);
2913 #ifdef ENABLE_CHECKING
2914 verify_flow_info ();
2915 #endif
2917 sbitmap_free (blocks);
2920 /* Same as split_all_insns, but do not expect CFG to be available.
2921 Used by machine dependent reorg passes. */
2923 unsigned int
2924 split_all_insns_noflow (void)
2926 rtx next, insn;
2928 for (insn = get_insns (); insn; insn = next)
2930 next = NEXT_INSN (insn);
2931 if (INSN_P (insn))
2933 /* Don't split no-op move insns. These should silently
2934 disappear later in final. Splitting such insns would
2935 break the code that handles LIBCALL blocks. */
2936 rtx set = single_set (insn);
2937 if (set && set_noop_p (set))
2939 /* Nops get in the way while scheduling, so delete them
2940 now if register allocation has already been done. It
2941 is too risky to try to do this before register
2942 allocation, and there are unlikely to be very many
2943 nops then anyways.
2945 ??? Should we use delete_insn when the CFG isn't valid? */
2946 if (reload_completed)
2947 delete_insn_and_edges (insn);
2949 else
2950 split_insn (insn);
2953 return 0;
2956 #ifdef HAVE_peephole2
2957 struct peep2_insn_data
2959 rtx insn;
2960 regset live_before;
2963 static struct peep2_insn_data peep2_insn_data[MAX_INSNS_PER_PEEP2 + 1];
2964 static int peep2_current;
2966 static bool peep2_do_rebuild_jump_labels;
2967 static bool peep2_do_cleanup_cfg;
2969 /* The number of instructions available to match a peep2. */
2970 int peep2_current_count;
2972 /* A non-insn marker indicating the last insn of the block.
2973 The live_before regset for this element is correct, indicating
2974 DF_LIVE_OUT for the block. */
2975 #define PEEP2_EOB pc_rtx
2977 /* Wrap N to fit into the peep2_insn_data buffer. */
2979 static int
2980 peep2_buf_position (int n)
2982 if (n >= MAX_INSNS_PER_PEEP2 + 1)
2983 n -= MAX_INSNS_PER_PEEP2 + 1;
2984 return n;
2987 /* Return the Nth non-note insn after `current', or return NULL_RTX if it
2988 does not exist. Used by the recognizer to find the next insn to match
2989 in a multi-insn pattern. */
2992 peep2_next_insn (int n)
2994 gcc_assert (n <= peep2_current_count);
2996 n = peep2_buf_position (peep2_current + n);
2998 return peep2_insn_data[n].insn;
3001 /* Return true if REGNO is dead before the Nth non-note insn
3002 after `current'. */
3005 peep2_regno_dead_p (int ofs, int regno)
3007 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3009 ofs = peep2_buf_position (peep2_current + ofs);
3011 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3013 return ! REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno);
3016 /* Similarly for a REG. */
3019 peep2_reg_dead_p (int ofs, rtx reg)
3021 int regno, n;
3023 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3025 ofs = peep2_buf_position (peep2_current + ofs);
3027 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3029 regno = REGNO (reg);
3030 n = hard_regno_nregs[regno][GET_MODE (reg)];
3031 while (--n >= 0)
3032 if (REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno + n))
3033 return 0;
3034 return 1;
3037 /* Try to find a hard register of mode MODE, matching the register class in
3038 CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
3039 remains available until the end of LAST_INSN. LAST_INSN may be NULL_RTX,
3040 in which case the only condition is that the register must be available
3041 before CURRENT_INSN.
3042 Registers that already have bits set in REG_SET will not be considered.
3044 If an appropriate register is available, it will be returned and the
3045 corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
3046 returned. */
3049 peep2_find_free_register (int from, int to, const char *class_str,
3050 enum machine_mode mode, HARD_REG_SET *reg_set)
3052 static int search_ofs;
3053 enum reg_class cl;
3054 HARD_REG_SET live;
3055 df_ref *def_rec;
3056 int i;
3058 gcc_assert (from < MAX_INSNS_PER_PEEP2 + 1);
3059 gcc_assert (to < MAX_INSNS_PER_PEEP2 + 1);
3061 from = peep2_buf_position (peep2_current + from);
3062 to = peep2_buf_position (peep2_current + to);
3064 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3065 REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before);
3067 while (from != to)
3069 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3071 /* Don't use registers set or clobbered by the insn. */
3072 for (def_rec = DF_INSN_DEFS (peep2_insn_data[from].insn);
3073 *def_rec; def_rec++)
3074 SET_HARD_REG_BIT (live, DF_REF_REGNO (*def_rec));
3076 from = peep2_buf_position (from + 1);
3079 cl = (class_str[0] == 'r' ? GENERAL_REGS
3080 : REG_CLASS_FROM_CONSTRAINT (class_str[0], class_str));
3082 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3084 int raw_regno, regno, success, j;
3086 /* Distribute the free registers as much as possible. */
3087 raw_regno = search_ofs + i;
3088 if (raw_regno >= FIRST_PSEUDO_REGISTER)
3089 raw_regno -= FIRST_PSEUDO_REGISTER;
3090 #ifdef REG_ALLOC_ORDER
3091 regno = reg_alloc_order[raw_regno];
3092 #else
3093 regno = raw_regno;
3094 #endif
3096 /* Don't allocate fixed registers. */
3097 if (fixed_regs[regno])
3098 continue;
3099 /* Don't allocate global registers. */
3100 if (global_regs[regno])
3101 continue;
3102 /* Make sure the register is of the right class. */
3103 if (! TEST_HARD_REG_BIT (reg_class_contents[cl], regno))
3104 continue;
3105 /* And can support the mode we need. */
3106 if (! HARD_REGNO_MODE_OK (regno, mode))
3107 continue;
3108 /* And that we don't create an extra save/restore. */
3109 if (! call_used_regs[regno] && ! df_regs_ever_live_p (regno))
3110 continue;
3111 if (! targetm.hard_regno_scratch_ok (regno))
3112 continue;
3114 /* And we don't clobber traceback for noreturn functions. */
3115 if ((regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM)
3116 && (! reload_completed || frame_pointer_needed))
3117 continue;
3119 success = 1;
3120 for (j = hard_regno_nregs[regno][mode] - 1; j >= 0; j--)
3122 if (TEST_HARD_REG_BIT (*reg_set, regno + j)
3123 || TEST_HARD_REG_BIT (live, regno + j))
3125 success = 0;
3126 break;
3129 if (success)
3131 add_to_hard_reg_set (reg_set, mode, regno);
3133 /* Start the next search with the next register. */
3134 if (++raw_regno >= FIRST_PSEUDO_REGISTER)
3135 raw_regno = 0;
3136 search_ofs = raw_regno;
3138 return gen_rtx_REG (mode, regno);
3142 search_ofs = 0;
3143 return NULL_RTX;
3146 /* Forget all currently tracked instructions, only remember current
3147 LIVE regset. */
3149 static void
3150 peep2_reinit_state (regset live)
3152 int i;
3154 /* Indicate that all slots except the last holds invalid data. */
3155 for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
3156 peep2_insn_data[i].insn = NULL_RTX;
3157 peep2_current_count = 0;
3159 /* Indicate that the last slot contains live_after data. */
3160 peep2_insn_data[MAX_INSNS_PER_PEEP2].insn = PEEP2_EOB;
3161 peep2_current = MAX_INSNS_PER_PEEP2;
3163 COPY_REG_SET (peep2_insn_data[MAX_INSNS_PER_PEEP2].live_before, live);
3166 /* While scanning basic block BB, we found a match of length MATCH_LEN,
3167 starting at INSN. Perform the replacement, removing the old insns and
3168 replacing them with ATTEMPT. Returns the last insn emitted, or NULL
3169 if the replacement is rejected. */
3171 static rtx
3172 peep2_attempt (basic_block bb, rtx insn, int match_len, rtx attempt)
3174 int i;
3175 rtx last, eh_note, as_note, before_try, x;
3176 rtx old_insn, new_insn;
3177 bool was_call = false;
3179 /* If we are splitting an RTX_FRAME_RELATED_P insn, do not allow it to
3180 match more than one insn, or to be split into more than one insn. */
3181 old_insn = peep2_insn_data[peep2_current].insn;
3182 if (RTX_FRAME_RELATED_P (old_insn))
3184 bool any_note = false;
3185 rtx note;
3187 if (match_len != 0)
3188 return NULL;
3190 /* Look for one "active" insn. I.e. ignore any "clobber" insns that
3191 may be in the stream for the purpose of register allocation. */
3192 if (active_insn_p (attempt))
3193 new_insn = attempt;
3194 else
3195 new_insn = next_active_insn (attempt);
3196 if (next_active_insn (new_insn))
3197 return NULL;
3199 /* We have a 1-1 replacement. Copy over any frame-related info. */
3200 RTX_FRAME_RELATED_P (new_insn) = 1;
3202 /* Allow the backend to fill in a note during the split. */
3203 for (note = REG_NOTES (new_insn); note ; note = XEXP (note, 1))
3204 switch (REG_NOTE_KIND (note))
3206 case REG_FRAME_RELATED_EXPR:
3207 case REG_CFA_DEF_CFA:
3208 case REG_CFA_ADJUST_CFA:
3209 case REG_CFA_OFFSET:
3210 case REG_CFA_REGISTER:
3211 case REG_CFA_EXPRESSION:
3212 case REG_CFA_RESTORE:
3213 case REG_CFA_SET_VDRAP:
3214 any_note = true;
3215 break;
3216 default:
3217 break;
3220 /* If the backend didn't supply a note, copy one over. */
3221 if (!any_note)
3222 for (note = REG_NOTES (old_insn); note ; note = XEXP (note, 1))
3223 switch (REG_NOTE_KIND (note))
3225 case REG_FRAME_RELATED_EXPR:
3226 case REG_CFA_DEF_CFA:
3227 case REG_CFA_ADJUST_CFA:
3228 case REG_CFA_OFFSET:
3229 case REG_CFA_REGISTER:
3230 case REG_CFA_EXPRESSION:
3231 case REG_CFA_RESTORE:
3232 case REG_CFA_SET_VDRAP:
3233 add_reg_note (new_insn, REG_NOTE_KIND (note), XEXP (note, 0));
3234 any_note = true;
3235 break;
3236 default:
3237 break;
3240 /* If there still isn't a note, make sure the unwind info sees the
3241 same expression as before the split. */
3242 if (!any_note)
3244 rtx old_set, new_set;
3246 /* The old insn had better have been simple, or annotated. */
3247 old_set = single_set (old_insn);
3248 gcc_assert (old_set != NULL);
3250 new_set = single_set (new_insn);
3251 if (!new_set || !rtx_equal_p (new_set, old_set))
3252 add_reg_note (new_insn, REG_FRAME_RELATED_EXPR, old_set);
3255 /* Copy prologue/epilogue status. This is required in order to keep
3256 proper placement of EPILOGUE_BEG and the DW_CFA_remember_state. */
3257 maybe_copy_prologue_epilogue_insn (old_insn, new_insn);
3260 /* If we are splitting a CALL_INSN, look for the CALL_INSN
3261 in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other
3262 cfg-related call notes. */
3263 for (i = 0; i <= match_len; ++i)
3265 int j;
3266 rtx note;
3268 j = peep2_buf_position (peep2_current + i);
3269 old_insn = peep2_insn_data[j].insn;
3270 if (!CALL_P (old_insn))
3271 continue;
3272 was_call = true;
3274 new_insn = attempt;
3275 while (new_insn != NULL_RTX)
3277 if (CALL_P (new_insn))
3278 break;
3279 new_insn = NEXT_INSN (new_insn);
3282 gcc_assert (new_insn != NULL_RTX);
3284 CALL_INSN_FUNCTION_USAGE (new_insn)
3285 = CALL_INSN_FUNCTION_USAGE (old_insn);
3287 for (note = REG_NOTES (old_insn);
3288 note;
3289 note = XEXP (note, 1))
3290 switch (REG_NOTE_KIND (note))
3292 case REG_NORETURN:
3293 case REG_SETJMP:
3294 case REG_TM:
3295 add_reg_note (new_insn, REG_NOTE_KIND (note),
3296 XEXP (note, 0));
3297 break;
3298 default:
3299 /* Discard all other reg notes. */
3300 break;
3303 /* Croak if there is another call in the sequence. */
3304 while (++i <= match_len)
3306 j = peep2_buf_position (peep2_current + i);
3307 old_insn = peep2_insn_data[j].insn;
3308 gcc_assert (!CALL_P (old_insn));
3310 break;
3313 /* If we matched any instruction that had a REG_ARGS_SIZE, then
3314 move those notes over to the new sequence. */
3315 as_note = NULL;
3316 for (i = match_len; i >= 0; --i)
3318 int j = peep2_buf_position (peep2_current + i);
3319 old_insn = peep2_insn_data[j].insn;
3321 as_note = find_reg_note (old_insn, REG_ARGS_SIZE, NULL);
3322 if (as_note)
3323 break;
3326 i = peep2_buf_position (peep2_current + match_len);
3327 eh_note = find_reg_note (peep2_insn_data[i].insn, REG_EH_REGION, NULL_RTX);
3329 /* Replace the old sequence with the new. */
3330 last = emit_insn_after_setloc (attempt,
3331 peep2_insn_data[i].insn,
3332 INSN_LOCATION (peep2_insn_data[i].insn));
3333 before_try = PREV_INSN (insn);
3334 delete_insn_chain (insn, peep2_insn_data[i].insn, false);
3336 /* Re-insert the EH_REGION notes. */
3337 if (eh_note || (was_call && nonlocal_goto_handler_labels))
3339 edge eh_edge;
3340 edge_iterator ei;
3342 FOR_EACH_EDGE (eh_edge, ei, bb->succs)
3343 if (eh_edge->flags & (EDGE_EH | EDGE_ABNORMAL_CALL))
3344 break;
3346 if (eh_note)
3347 copy_reg_eh_region_note_backward (eh_note, last, before_try);
3349 if (eh_edge)
3350 for (x = last; x != before_try; x = PREV_INSN (x))
3351 if (x != BB_END (bb)
3352 && (can_throw_internal (x)
3353 || can_nonlocal_goto (x)))
3355 edge nfte, nehe;
3356 int flags;
3358 nfte = split_block (bb, x);
3359 flags = (eh_edge->flags
3360 & (EDGE_EH | EDGE_ABNORMAL));
3361 if (CALL_P (x))
3362 flags |= EDGE_ABNORMAL_CALL;
3363 nehe = make_edge (nfte->src, eh_edge->dest,
3364 flags);
3366 nehe->probability = eh_edge->probability;
3367 nfte->probability
3368 = REG_BR_PROB_BASE - nehe->probability;
3370 peep2_do_cleanup_cfg |= purge_dead_edges (nfte->dest);
3371 bb = nfte->src;
3372 eh_edge = nehe;
3375 /* Converting possibly trapping insn to non-trapping is
3376 possible. Zap dummy outgoing edges. */
3377 peep2_do_cleanup_cfg |= purge_dead_edges (bb);
3380 /* Re-insert the ARGS_SIZE notes. */
3381 if (as_note)
3382 fixup_args_size_notes (before_try, last, INTVAL (XEXP (as_note, 0)));
3384 /* If we generated a jump instruction, it won't have
3385 JUMP_LABEL set. Recompute after we're done. */
3386 for (x = last; x != before_try; x = PREV_INSN (x))
3387 if (JUMP_P (x))
3389 peep2_do_rebuild_jump_labels = true;
3390 break;
3393 return last;
3396 /* After performing a replacement in basic block BB, fix up the life
3397 information in our buffer. LAST is the last of the insns that we
3398 emitted as a replacement. PREV is the insn before the start of
3399 the replacement. MATCH_LEN is the number of instructions that were
3400 matched, and which now need to be replaced in the buffer. */
3402 static void
3403 peep2_update_life (basic_block bb, int match_len, rtx last, rtx prev)
3405 int i = peep2_buf_position (peep2_current + match_len + 1);
3406 rtx x;
3407 regset_head live;
3409 INIT_REG_SET (&live);
3410 COPY_REG_SET (&live, peep2_insn_data[i].live_before);
3412 gcc_assert (peep2_current_count >= match_len + 1);
3413 peep2_current_count -= match_len + 1;
3415 x = last;
3418 if (INSN_P (x))
3420 df_insn_rescan (x);
3421 if (peep2_current_count < MAX_INSNS_PER_PEEP2)
3423 peep2_current_count++;
3424 if (--i < 0)
3425 i = MAX_INSNS_PER_PEEP2;
3426 peep2_insn_data[i].insn = x;
3427 df_simulate_one_insn_backwards (bb, x, &live);
3428 COPY_REG_SET (peep2_insn_data[i].live_before, &live);
3431 x = PREV_INSN (x);
3433 while (x != prev);
3434 CLEAR_REG_SET (&live);
3436 peep2_current = i;
3439 /* Add INSN, which is in BB, at the end of the peep2 insn buffer if possible.
3440 Return true if we added it, false otherwise. The caller will try to match
3441 peepholes against the buffer if we return false; otherwise it will try to
3442 add more instructions to the buffer. */
3444 static bool
3445 peep2_fill_buffer (basic_block bb, rtx insn, regset live)
3447 int pos;
3449 /* Once we have filled the maximum number of insns the buffer can hold,
3450 allow the caller to match the insns against peepholes. We wait until
3451 the buffer is full in case the target has similar peepholes of different
3452 length; we always want to match the longest if possible. */
3453 if (peep2_current_count == MAX_INSNS_PER_PEEP2)
3454 return false;
3456 /* If an insn has RTX_FRAME_RELATED_P set, do not allow it to be matched with
3457 any other pattern, lest it change the semantics of the frame info. */
3458 if (RTX_FRAME_RELATED_P (insn))
3460 /* Let the buffer drain first. */
3461 if (peep2_current_count > 0)
3462 return false;
3463 /* Now the insn will be the only thing in the buffer. */
3466 pos = peep2_buf_position (peep2_current + peep2_current_count);
3467 peep2_insn_data[pos].insn = insn;
3468 COPY_REG_SET (peep2_insn_data[pos].live_before, live);
3469 peep2_current_count++;
3471 df_simulate_one_insn_forwards (bb, insn, live);
3472 return true;
3475 /* Perform the peephole2 optimization pass. */
3477 static void
3478 peephole2_optimize (void)
3480 rtx insn;
3481 bitmap live;
3482 int i;
3483 basic_block bb;
3485 peep2_do_cleanup_cfg = false;
3486 peep2_do_rebuild_jump_labels = false;
3488 df_set_flags (DF_LR_RUN_DCE);
3489 df_note_add_problem ();
3490 df_analyze ();
3492 /* Initialize the regsets we're going to use. */
3493 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3494 peep2_insn_data[i].live_before = BITMAP_ALLOC (&reg_obstack);
3495 live = BITMAP_ALLOC (&reg_obstack);
3497 FOR_EACH_BB_REVERSE (bb)
3499 bool past_end = false;
3500 int pos;
3502 rtl_profile_for_bb (bb);
3504 /* Start up propagation. */
3505 bitmap_copy (live, DF_LR_IN (bb));
3506 df_simulate_initialize_forwards (bb, live);
3507 peep2_reinit_state (live);
3509 insn = BB_HEAD (bb);
3510 for (;;)
3512 rtx attempt, head;
3513 int match_len;
3515 if (!past_end && !NONDEBUG_INSN_P (insn))
3517 next_insn:
3518 insn = NEXT_INSN (insn);
3519 if (insn == NEXT_INSN (BB_END (bb)))
3520 past_end = true;
3521 continue;
3523 if (!past_end && peep2_fill_buffer (bb, insn, live))
3524 goto next_insn;
3526 /* If we did not fill an empty buffer, it signals the end of the
3527 block. */
3528 if (peep2_current_count == 0)
3529 break;
3531 /* The buffer filled to the current maximum, so try to match. */
3533 pos = peep2_buf_position (peep2_current + peep2_current_count);
3534 peep2_insn_data[pos].insn = PEEP2_EOB;
3535 COPY_REG_SET (peep2_insn_data[pos].live_before, live);
3537 /* Match the peephole. */
3538 head = peep2_insn_data[peep2_current].insn;
3539 attempt = peephole2_insns (PATTERN (head), head, &match_len);
3540 if (attempt != NULL)
3542 rtx last = peep2_attempt (bb, head, match_len, attempt);
3543 if (last)
3545 peep2_update_life (bb, match_len, last, PREV_INSN (attempt));
3546 continue;
3550 /* No match: advance the buffer by one insn. */
3551 peep2_current = peep2_buf_position (peep2_current + 1);
3552 peep2_current_count--;
3556 default_rtl_profile ();
3557 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3558 BITMAP_FREE (peep2_insn_data[i].live_before);
3559 BITMAP_FREE (live);
3560 if (peep2_do_rebuild_jump_labels)
3561 rebuild_jump_labels (get_insns ());
3563 #endif /* HAVE_peephole2 */
3565 /* Common predicates for use with define_bypass. */
3567 /* True if the dependency between OUT_INSN and IN_INSN is on the store
3568 data not the address operand(s) of the store. IN_INSN and OUT_INSN
3569 must be either a single_set or a PARALLEL with SETs inside. */
3572 store_data_bypass_p (rtx out_insn, rtx in_insn)
3574 rtx out_set, in_set;
3575 rtx out_pat, in_pat;
3576 rtx out_exp, in_exp;
3577 int i, j;
3579 in_set = single_set (in_insn);
3580 if (in_set)
3582 if (!MEM_P (SET_DEST (in_set)))
3583 return false;
3585 out_set = single_set (out_insn);
3586 if (out_set)
3588 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_set)))
3589 return false;
3591 else
3593 out_pat = PATTERN (out_insn);
3595 if (GET_CODE (out_pat) != PARALLEL)
3596 return false;
3598 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3600 out_exp = XVECEXP (out_pat, 0, i);
3602 if (GET_CODE (out_exp) == CLOBBER)
3603 continue;
3605 gcc_assert (GET_CODE (out_exp) == SET);
3607 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_set)))
3608 return false;
3612 else
3614 in_pat = PATTERN (in_insn);
3615 gcc_assert (GET_CODE (in_pat) == PARALLEL);
3617 for (i = 0; i < XVECLEN (in_pat, 0); i++)
3619 in_exp = XVECEXP (in_pat, 0, i);
3621 if (GET_CODE (in_exp) == CLOBBER)
3622 continue;
3624 gcc_assert (GET_CODE (in_exp) == SET);
3626 if (!MEM_P (SET_DEST (in_exp)))
3627 return false;
3629 out_set = single_set (out_insn);
3630 if (out_set)
3632 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_exp)))
3633 return false;
3635 else
3637 out_pat = PATTERN (out_insn);
3638 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3640 for (j = 0; j < XVECLEN (out_pat, 0); j++)
3642 out_exp = XVECEXP (out_pat, 0, j);
3644 if (GET_CODE (out_exp) == CLOBBER)
3645 continue;
3647 gcc_assert (GET_CODE (out_exp) == SET);
3649 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_exp)))
3650 return false;
3656 return true;
3659 /* True if the dependency between OUT_INSN and IN_INSN is in the IF_THEN_ELSE
3660 condition, and not the THEN or ELSE branch. OUT_INSN may be either a single
3661 or multiple set; IN_INSN should be single_set for truth, but for convenience
3662 of insn categorization may be any JUMP or CALL insn. */
3665 if_test_bypass_p (rtx out_insn, rtx in_insn)
3667 rtx out_set, in_set;
3669 in_set = single_set (in_insn);
3670 if (! in_set)
3672 gcc_assert (JUMP_P (in_insn) || CALL_P (in_insn));
3673 return false;
3676 if (GET_CODE (SET_SRC (in_set)) != IF_THEN_ELSE)
3677 return false;
3678 in_set = SET_SRC (in_set);
3680 out_set = single_set (out_insn);
3681 if (out_set)
3683 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3684 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3685 return false;
3687 else
3689 rtx out_pat;
3690 int i;
3692 out_pat = PATTERN (out_insn);
3693 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3695 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3697 rtx exp = XVECEXP (out_pat, 0, i);
3699 if (GET_CODE (exp) == CLOBBER)
3700 continue;
3702 gcc_assert (GET_CODE (exp) == SET);
3704 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3705 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3706 return false;
3710 return true;
3713 static bool
3714 gate_handle_peephole2 (void)
3716 return (optimize > 0 && flag_peephole2);
3719 static unsigned int
3720 rest_of_handle_peephole2 (void)
3722 #ifdef HAVE_peephole2
3723 peephole2_optimize ();
3724 #endif
3725 return 0;
3728 struct rtl_opt_pass pass_peephole2 =
3731 RTL_PASS,
3732 "peephole2", /* name */
3733 gate_handle_peephole2, /* gate */
3734 rest_of_handle_peephole2, /* execute */
3735 NULL, /* sub */
3736 NULL, /* next */
3737 0, /* static_pass_number */
3738 TV_PEEPHOLE2, /* tv_id */
3739 0, /* properties_required */
3740 0, /* properties_provided */
3741 0, /* properties_destroyed */
3742 0, /* todo_flags_start */
3743 TODO_df_finish | TODO_verify_rtl_sharing |
3744 0 /* todo_flags_finish */
3748 static unsigned int
3749 rest_of_handle_split_all_insns (void)
3751 split_all_insns ();
3752 return 0;
3755 struct rtl_opt_pass pass_split_all_insns =
3758 RTL_PASS,
3759 "split1", /* name */
3760 NULL, /* gate */
3761 rest_of_handle_split_all_insns, /* execute */
3762 NULL, /* sub */
3763 NULL, /* next */
3764 0, /* static_pass_number */
3765 TV_NONE, /* tv_id */
3766 0, /* properties_required */
3767 0, /* properties_provided */
3768 0, /* properties_destroyed */
3769 0, /* todo_flags_start */
3770 0 /* todo_flags_finish */
3774 static unsigned int
3775 rest_of_handle_split_after_reload (void)
3777 /* If optimizing, then go ahead and split insns now. */
3778 #ifndef STACK_REGS
3779 if (optimize > 0)
3780 #endif
3781 split_all_insns ();
3782 return 0;
3785 struct rtl_opt_pass pass_split_after_reload =
3788 RTL_PASS,
3789 "split2", /* name */
3790 NULL, /* gate */
3791 rest_of_handle_split_after_reload, /* execute */
3792 NULL, /* sub */
3793 NULL, /* next */
3794 0, /* static_pass_number */
3795 TV_NONE, /* tv_id */
3796 0, /* properties_required */
3797 0, /* properties_provided */
3798 0, /* properties_destroyed */
3799 0, /* todo_flags_start */
3800 0 /* todo_flags_finish */
3804 static bool
3805 gate_handle_split_before_regstack (void)
3807 #if defined (HAVE_ATTR_length) && defined (STACK_REGS)
3808 /* If flow2 creates new instructions which need splitting
3809 and scheduling after reload is not done, they might not be
3810 split until final which doesn't allow splitting
3811 if HAVE_ATTR_length. */
3812 # ifdef INSN_SCHEDULING
3813 return (optimize && !flag_schedule_insns_after_reload);
3814 # else
3815 return (optimize);
3816 # endif
3817 #else
3818 return 0;
3819 #endif
3822 static unsigned int
3823 rest_of_handle_split_before_regstack (void)
3825 split_all_insns ();
3826 return 0;
3829 struct rtl_opt_pass pass_split_before_regstack =
3832 RTL_PASS,
3833 "split3", /* name */
3834 gate_handle_split_before_regstack, /* gate */
3835 rest_of_handle_split_before_regstack, /* execute */
3836 NULL, /* sub */
3837 NULL, /* next */
3838 0, /* static_pass_number */
3839 TV_NONE, /* tv_id */
3840 0, /* properties_required */
3841 0, /* properties_provided */
3842 0, /* properties_destroyed */
3843 0, /* todo_flags_start */
3844 0 /* todo_flags_finish */
3848 static bool
3849 gate_handle_split_before_sched2 (void)
3851 #ifdef INSN_SCHEDULING
3852 return optimize > 0 && flag_schedule_insns_after_reload;
3853 #else
3854 return 0;
3855 #endif
3858 static unsigned int
3859 rest_of_handle_split_before_sched2 (void)
3861 #ifdef INSN_SCHEDULING
3862 split_all_insns ();
3863 #endif
3864 return 0;
3867 struct rtl_opt_pass pass_split_before_sched2 =
3870 RTL_PASS,
3871 "split4", /* name */
3872 gate_handle_split_before_sched2, /* gate */
3873 rest_of_handle_split_before_sched2, /* execute */
3874 NULL, /* sub */
3875 NULL, /* next */
3876 0, /* static_pass_number */
3877 TV_NONE, /* tv_id */
3878 0, /* properties_required */
3879 0, /* properties_provided */
3880 0, /* properties_destroyed */
3881 0, /* todo_flags_start */
3882 TODO_verify_flow /* todo_flags_finish */
3886 /* The placement of the splitting that we do for shorten_branches
3887 depends on whether regstack is used by the target or not. */
3888 static bool
3889 gate_do_final_split (void)
3891 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3892 return 1;
3893 #else
3894 return 0;
3895 #endif
3898 struct rtl_opt_pass pass_split_for_shorten_branches =
3901 RTL_PASS,
3902 "split5", /* name */
3903 gate_do_final_split, /* gate */
3904 split_all_insns_noflow, /* execute */
3905 NULL, /* sub */
3906 NULL, /* next */
3907 0, /* static_pass_number */
3908 TV_NONE, /* tv_id */
3909 0, /* properties_required */
3910 0, /* properties_provided */
3911 0, /* properties_destroyed */
3912 0, /* todo_flags_start */
3913 TODO_verify_rtl_sharing /* todo_flags_finish */