/cp
[official-gcc.git] / gcc / recog.c
blobe2caf9859d8301309676a73656819a787c1e8b77
1 /* Subroutines used by or related to instruction recognition.
2 Copyright (C) 1987-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "rtl-error.h"
27 #include "tm_p.h"
28 #include "insn-config.h"
29 #include "insn-attr.h"
30 #include "hard-reg-set.h"
31 #include "recog.h"
32 #include "regs.h"
33 #include "addresses.h"
34 #include "expr.h"
35 #include "function.h"
36 #include "flags.h"
37 #include "basic-block.h"
38 #include "reload.h"
39 #include "target.h"
40 #include "tree-pass.h"
41 #include "df.h"
42 #include "insn-codes.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 static void validate_replace_rtx_1 (rtx *, rtx, rtx, rtx, bool);
61 static void validate_replace_src_1 (rtx *, void *);
62 static rtx split_insn (rtx);
64 /* Nonzero means allow operands to be volatile.
65 This should be 0 if you are generating rtl, such as if you are calling
66 the functions in optabs.c and expmed.c (most of the time).
67 This should be 1 if all valid insns need to be recognized,
68 such as in reginfo.c and final.c and reload.c.
70 init_recog and init_recog_no_volatile are responsible for setting this. */
72 int volatile_ok;
74 struct recog_data_d recog_data;
76 /* Contains a vector of operand_alternative structures for every operand.
77 Set up by preprocess_constraints. */
78 struct operand_alternative recog_op_alt[MAX_RECOG_OPERANDS][MAX_RECOG_ALTERNATIVES];
80 /* On return from `constrain_operands', indicate which alternative
81 was satisfied. */
83 int which_alternative;
85 /* Nonzero after end of reload pass.
86 Set to 1 or 0 by toplev.c.
87 Controls the significance of (SUBREG (MEM)). */
89 int reload_completed;
91 /* Nonzero after thread_prologue_and_epilogue_insns has run. */
92 int epilogue_completed;
94 /* Initialize data used by the function `recog'.
95 This must be called once in the compilation of a function
96 before any insn recognition may be done in the function. */
98 void
99 init_recog_no_volatile (void)
101 volatile_ok = 0;
104 void
105 init_recog (void)
107 volatile_ok = 1;
111 /* Return true if labels in asm operands BODY are LABEL_REFs. */
113 static bool
114 asm_labels_ok (rtx body)
116 rtx asmop;
117 int i;
119 asmop = extract_asm_operands (body);
120 if (asmop == NULL_RTX)
121 return true;
123 for (i = 0; i < ASM_OPERANDS_LABEL_LENGTH (asmop); i++)
124 if (GET_CODE (ASM_OPERANDS_LABEL (asmop, i)) != LABEL_REF)
125 return false;
127 return true;
130 /* Check that X is an insn-body for an `asm' with operands
131 and that the operands mentioned in it are legitimate. */
134 check_asm_operands (rtx x)
136 int noperands;
137 rtx *operands;
138 const char **constraints;
139 int i;
141 if (!asm_labels_ok (x))
142 return 0;
144 /* Post-reload, be more strict with things. */
145 if (reload_completed)
147 /* ??? Doh! We've not got the wrapping insn. Cook one up. */
148 extract_insn (make_insn_raw (x));
149 constrain_operands (1);
150 return which_alternative >= 0;
153 noperands = asm_noperands (x);
154 if (noperands < 0)
155 return 0;
156 if (noperands == 0)
157 return 1;
159 operands = XALLOCAVEC (rtx, noperands);
160 constraints = XALLOCAVEC (const char *, noperands);
162 decode_asm_operands (x, operands, NULL, constraints, NULL, NULL);
164 for (i = 0; i < noperands; i++)
166 const char *c = constraints[i];
167 if (c[0] == '%')
168 c++;
169 if (! asm_operand_ok (operands[i], c, constraints))
170 return 0;
173 return 1;
176 /* Static data for the next two routines. */
178 typedef struct change_t
180 rtx object;
181 int old_code;
182 rtx *loc;
183 rtx old;
184 bool unshare;
185 } change_t;
187 static change_t *changes;
188 static int changes_allocated;
190 static int num_changes = 0;
192 /* Validate a proposed change to OBJECT. LOC is the location in the rtl
193 at which NEW_RTX will be placed. If OBJECT is zero, no validation is done,
194 the change is simply made.
196 Two types of objects are supported: If OBJECT is a MEM, memory_address_p
197 will be called with the address and mode as parameters. If OBJECT is
198 an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
199 the change in place.
201 IN_GROUP is nonzero if this is part of a group of changes that must be
202 performed as a group. In that case, the changes will be stored. The
203 function `apply_change_group' will validate and apply the changes.
205 If IN_GROUP is zero, this is a single change. Try to recognize the insn
206 or validate the memory reference with the change applied. If the result
207 is not valid for the machine, suppress the change and return zero.
208 Otherwise, perform the change and return 1. */
210 static bool
211 validate_change_1 (rtx object, rtx *loc, rtx new_rtx, bool in_group, bool unshare)
213 rtx old = *loc;
215 if (old == new_rtx || rtx_equal_p (old, new_rtx))
216 return 1;
218 gcc_assert (in_group != 0 || num_changes == 0);
220 *loc = new_rtx;
222 /* Save the information describing this change. */
223 if (num_changes >= changes_allocated)
225 if (changes_allocated == 0)
226 /* This value allows for repeated substitutions inside complex
227 indexed addresses, or changes in up to 5 insns. */
228 changes_allocated = MAX_RECOG_OPERANDS * 5;
229 else
230 changes_allocated *= 2;
232 changes = XRESIZEVEC (change_t, changes, changes_allocated);
235 changes[num_changes].object = object;
236 changes[num_changes].loc = loc;
237 changes[num_changes].old = old;
238 changes[num_changes].unshare = unshare;
240 if (object && !MEM_P (object))
242 /* Set INSN_CODE to force rerecognition of insn. Save old code in
243 case invalid. */
244 changes[num_changes].old_code = INSN_CODE (object);
245 INSN_CODE (object) = -1;
248 num_changes++;
250 /* If we are making a group of changes, return 1. Otherwise, validate the
251 change group we made. */
253 if (in_group)
254 return 1;
255 else
256 return apply_change_group ();
259 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
260 UNSHARE to false. */
262 bool
263 validate_change (rtx object, rtx *loc, rtx new_rtx, bool in_group)
265 return validate_change_1 (object, loc, new_rtx, in_group, false);
268 /* Wrapper for validate_change_1 without the UNSHARE argument defaulting
269 UNSHARE to true. */
271 bool
272 validate_unshare_change (rtx object, rtx *loc, rtx new_rtx, bool in_group)
274 return validate_change_1 (object, loc, new_rtx, in_group, true);
278 /* Keep X canonicalized if some changes have made it non-canonical; only
279 modifies the operands of X, not (for example) its code. Simplifications
280 are not the job of this routine.
282 Return true if anything was changed. */
283 bool
284 canonicalize_change_group (rtx insn, rtx x)
286 if (COMMUTATIVE_P (x)
287 && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
289 /* Oops, the caller has made X no longer canonical.
290 Let's redo the changes in the correct order. */
291 rtx tem = XEXP (x, 0);
292 validate_unshare_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
293 validate_unshare_change (insn, &XEXP (x, 1), tem, 1);
294 return true;
296 else
297 return false;
301 /* This subroutine of apply_change_group verifies whether the changes to INSN
302 were valid; i.e. whether INSN can still be recognized.
304 If IN_GROUP is true clobbers which have to be added in order to
305 match the instructions will be added to the current change group.
306 Otherwise the changes will take effect immediately. */
309 insn_invalid_p (rtx insn, bool in_group)
311 rtx pat = PATTERN (insn);
312 int num_clobbers = 0;
313 /* If we are before reload and the pattern is a SET, see if we can add
314 clobbers. */
315 int icode = recog (pat, insn,
316 (GET_CODE (pat) == SET
317 && ! reload_completed
318 && ! reload_in_progress)
319 ? &num_clobbers : 0);
320 int is_asm = icode < 0 && asm_noperands (PATTERN (insn)) >= 0;
323 /* If this is an asm and the operand aren't legal, then fail. Likewise if
324 this is not an asm and the insn wasn't recognized. */
325 if ((is_asm && ! check_asm_operands (PATTERN (insn)))
326 || (!is_asm && icode < 0))
327 return 1;
329 /* If we have to add CLOBBERs, fail if we have to add ones that reference
330 hard registers since our callers can't know if they are live or not.
331 Otherwise, add them. */
332 if (num_clobbers > 0)
334 rtx newpat;
336 if (added_clobbers_hard_reg_p (icode))
337 return 1;
339 newpat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_clobbers + 1));
340 XVECEXP (newpat, 0, 0) = pat;
341 add_clobbers (newpat, icode);
342 if (in_group)
343 validate_change (insn, &PATTERN (insn), newpat, 1);
344 else
345 PATTERN (insn) = pat = newpat;
348 /* After reload, verify that all constraints are satisfied. */
349 if (reload_completed)
351 extract_insn (insn);
353 if (! constrain_operands (1))
354 return 1;
357 INSN_CODE (insn) = icode;
358 return 0;
361 /* Return number of changes made and not validated yet. */
363 num_changes_pending (void)
365 return num_changes;
368 /* Tentatively apply the changes numbered NUM and up.
369 Return 1 if all changes are valid, zero otherwise. */
372 verify_changes (int num)
374 int i;
375 rtx last_validated = NULL_RTX;
377 /* The changes have been applied and all INSN_CODEs have been reset to force
378 rerecognition.
380 The changes are valid if we aren't given an object, or if we are
381 given a MEM and it still is a valid address, or if this is in insn
382 and it is recognized. In the latter case, if reload has completed,
383 we also require that the operands meet the constraints for
384 the insn. */
386 for (i = num; i < num_changes; i++)
388 rtx object = changes[i].object;
390 /* If there is no object to test or if it is the same as the one we
391 already tested, ignore it. */
392 if (object == 0 || object == last_validated)
393 continue;
395 if (MEM_P (object))
397 if (! memory_address_addr_space_p (GET_MODE (object),
398 XEXP (object, 0),
399 MEM_ADDR_SPACE (object)))
400 break;
402 else if (/* changes[i].old might be zero, e.g. when putting a
403 REG_FRAME_RELATED_EXPR into a previously empty list. */
404 changes[i].old
405 && REG_P (changes[i].old)
406 && asm_noperands (PATTERN (object)) > 0
407 && REG_EXPR (changes[i].old) != NULL_TREE
408 && DECL_ASSEMBLER_NAME_SET_P (REG_EXPR (changes[i].old))
409 && DECL_REGISTER (REG_EXPR (changes[i].old)))
411 /* Don't allow changes of hard register operands to inline
412 assemblies if they have been defined as register asm ("x"). */
413 break;
415 else if (DEBUG_INSN_P (object))
416 continue;
417 else if (insn_invalid_p (object, true))
419 rtx pat = PATTERN (object);
421 /* Perhaps we couldn't recognize the insn because there were
422 extra CLOBBERs at the end. If so, try to re-recognize
423 without the last CLOBBER (later iterations will cause each of
424 them to be eliminated, in turn). But don't do this if we
425 have an ASM_OPERAND. */
426 if (GET_CODE (pat) == PARALLEL
427 && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
428 && asm_noperands (PATTERN (object)) < 0)
430 rtx newpat;
432 if (XVECLEN (pat, 0) == 2)
433 newpat = XVECEXP (pat, 0, 0);
434 else
436 int j;
438 newpat
439 = gen_rtx_PARALLEL (VOIDmode,
440 rtvec_alloc (XVECLEN (pat, 0) - 1));
441 for (j = 0; j < XVECLEN (newpat, 0); j++)
442 XVECEXP (newpat, 0, j) = XVECEXP (pat, 0, j);
445 /* Add a new change to this group to replace the pattern
446 with this new pattern. Then consider this change
447 as having succeeded. The change we added will
448 cause the entire call to fail if things remain invalid.
450 Note that this can lose if a later change than the one
451 we are processing specified &XVECEXP (PATTERN (object), 0, X)
452 but this shouldn't occur. */
454 validate_change (object, &PATTERN (object), newpat, 1);
455 continue;
457 else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER
458 || GET_CODE (pat) == VAR_LOCATION)
459 /* If this insn is a CLOBBER or USE, it is always valid, but is
460 never recognized. */
461 continue;
462 else
463 break;
465 last_validated = object;
468 return (i == num_changes);
471 /* A group of changes has previously been issued with validate_change
472 and verified with verify_changes. Call df_insn_rescan for each of
473 the insn changed and clear num_changes. */
475 void
476 confirm_change_group (void)
478 int i;
479 rtx last_object = NULL;
481 for (i = 0; i < num_changes; i++)
483 rtx object = changes[i].object;
485 if (changes[i].unshare)
486 *changes[i].loc = copy_rtx (*changes[i].loc);
488 /* Avoid unnecessary rescanning when multiple changes to same instruction
489 are made. */
490 if (object)
492 if (object != last_object && last_object && INSN_P (last_object))
493 df_insn_rescan (last_object);
494 last_object = object;
498 if (last_object && INSN_P (last_object))
499 df_insn_rescan (last_object);
500 num_changes = 0;
503 /* Apply a group of changes previously issued with `validate_change'.
504 If all changes are valid, call confirm_change_group and return 1,
505 otherwise, call cancel_changes and return 0. */
508 apply_change_group (void)
510 if (verify_changes (0))
512 confirm_change_group ();
513 return 1;
515 else
517 cancel_changes (0);
518 return 0;
523 /* Return the number of changes so far in the current group. */
526 num_validated_changes (void)
528 return num_changes;
531 /* Retract the changes numbered NUM and up. */
533 void
534 cancel_changes (int num)
536 int i;
538 /* Back out all the changes. Do this in the opposite order in which
539 they were made. */
540 for (i = num_changes - 1; i >= num; i--)
542 *changes[i].loc = changes[i].old;
543 if (changes[i].object && !MEM_P (changes[i].object))
544 INSN_CODE (changes[i].object) = changes[i].old_code;
546 num_changes = num;
549 /* Reduce conditional compilation elsewhere. */
550 #ifndef HAVE_extv
551 #define HAVE_extv 0
552 #define CODE_FOR_extv CODE_FOR_nothing
553 #endif
554 #ifndef HAVE_extzv
555 #define HAVE_extzv 0
556 #define CODE_FOR_extzv CODE_FOR_nothing
557 #endif
559 /* A subroutine of validate_replace_rtx_1 that tries to simplify the resulting
560 rtx. */
562 static void
563 simplify_while_replacing (rtx *loc, rtx to, rtx object,
564 enum machine_mode op0_mode)
566 rtx x = *loc;
567 enum rtx_code code = GET_CODE (x);
568 rtx new_rtx;
570 if (SWAPPABLE_OPERANDS_P (x)
571 && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
573 validate_unshare_change (object, loc,
574 gen_rtx_fmt_ee (COMMUTATIVE_ARITH_P (x) ? code
575 : swap_condition (code),
576 GET_MODE (x), XEXP (x, 1),
577 XEXP (x, 0)), 1);
578 x = *loc;
579 code = GET_CODE (x);
582 switch (code)
584 case PLUS:
585 /* If we have a PLUS whose second operand is now a CONST_INT, use
586 simplify_gen_binary to try to simplify it.
587 ??? We may want later to remove this, once simplification is
588 separated from this function. */
589 if (CONST_INT_P (XEXP (x, 1)) && XEXP (x, 1) == to)
590 validate_change (object, loc,
591 simplify_gen_binary
592 (PLUS, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)), 1);
593 break;
594 case MINUS:
595 if (CONST_SCALAR_INT_P (XEXP (x, 1)))
596 validate_change (object, loc,
597 simplify_gen_binary
598 (PLUS, GET_MODE (x), XEXP (x, 0),
599 simplify_gen_unary (NEG,
600 GET_MODE (x), XEXP (x, 1),
601 GET_MODE (x))), 1);
602 break;
603 case ZERO_EXTEND:
604 case SIGN_EXTEND:
605 if (GET_MODE (XEXP (x, 0)) == VOIDmode)
607 new_rtx = simplify_gen_unary (code, GET_MODE (x), XEXP (x, 0),
608 op0_mode);
609 /* If any of the above failed, substitute in something that
610 we know won't be recognized. */
611 if (!new_rtx)
612 new_rtx = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
613 validate_change (object, loc, new_rtx, 1);
615 break;
616 case SUBREG:
617 /* All subregs possible to simplify should be simplified. */
618 new_rtx = simplify_subreg (GET_MODE (x), SUBREG_REG (x), op0_mode,
619 SUBREG_BYTE (x));
621 /* Subregs of VOIDmode operands are incorrect. */
622 if (!new_rtx && GET_MODE (SUBREG_REG (x)) == VOIDmode)
623 new_rtx = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
624 if (new_rtx)
625 validate_change (object, loc, new_rtx, 1);
626 break;
627 case ZERO_EXTRACT:
628 case SIGN_EXTRACT:
629 /* If we are replacing a register with memory, try to change the memory
630 to be the mode required for memory in extract operations (this isn't
631 likely to be an insertion operation; if it was, nothing bad will
632 happen, we might just fail in some cases). */
634 if (MEM_P (XEXP (x, 0))
635 && CONST_INT_P (XEXP (x, 1))
636 && CONST_INT_P (XEXP (x, 2))
637 && !mode_dependent_address_p (XEXP (XEXP (x, 0), 0),
638 MEM_ADDR_SPACE (XEXP (x, 0)))
639 && !MEM_VOLATILE_P (XEXP (x, 0)))
641 enum machine_mode wanted_mode = VOIDmode;
642 enum machine_mode is_mode = GET_MODE (XEXP (x, 0));
643 int pos = INTVAL (XEXP (x, 2));
645 if (GET_CODE (x) == ZERO_EXTRACT && HAVE_extzv)
647 wanted_mode = insn_data[CODE_FOR_extzv].operand[1].mode;
648 if (wanted_mode == VOIDmode)
649 wanted_mode = word_mode;
651 else if (GET_CODE (x) == SIGN_EXTRACT && HAVE_extv)
653 wanted_mode = insn_data[CODE_FOR_extv].operand[1].mode;
654 if (wanted_mode == VOIDmode)
655 wanted_mode = word_mode;
658 /* If we have a narrower mode, we can do something. */
659 if (wanted_mode != VOIDmode
660 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
662 int offset = pos / BITS_PER_UNIT;
663 rtx newmem;
665 /* If the bytes and bits are counted differently, we
666 must adjust the offset. */
667 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
668 offset =
669 (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode) -
670 offset);
672 gcc_assert (GET_MODE_PRECISION (wanted_mode)
673 == GET_MODE_BITSIZE (wanted_mode));
674 pos %= GET_MODE_BITSIZE (wanted_mode);
676 newmem = adjust_address_nv (XEXP (x, 0), wanted_mode, offset);
678 validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
679 validate_change (object, &XEXP (x, 0), newmem, 1);
683 break;
685 default:
686 break;
690 /* Replace every occurrence of FROM in X with TO. Mark each change with
691 validate_change passing OBJECT. */
693 static void
694 validate_replace_rtx_1 (rtx *loc, rtx from, rtx to, rtx object,
695 bool simplify)
697 int i, j;
698 const char *fmt;
699 rtx x = *loc;
700 enum rtx_code code;
701 enum machine_mode op0_mode = VOIDmode;
702 int prev_changes = num_changes;
704 if (!x)
705 return;
707 code = GET_CODE (x);
708 fmt = GET_RTX_FORMAT (code);
709 if (fmt[0] == 'e')
710 op0_mode = GET_MODE (XEXP (x, 0));
712 /* X matches FROM if it is the same rtx or they are both referring to the
713 same register in the same mode. Avoid calling rtx_equal_p unless the
714 operands look similar. */
716 if (x == from
717 || (REG_P (x) && REG_P (from)
718 && GET_MODE (x) == GET_MODE (from)
719 && REGNO (x) == REGNO (from))
720 || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
721 && rtx_equal_p (x, from)))
723 validate_unshare_change (object, loc, to, 1);
724 return;
727 /* Call ourself recursively to perform the replacements.
728 We must not replace inside already replaced expression, otherwise we
729 get infinite recursion for replacements like (reg X)->(subreg (reg X))
730 so we must special case shared ASM_OPERANDS. */
732 if (GET_CODE (x) == PARALLEL)
734 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
736 if (j && GET_CODE (XVECEXP (x, 0, j)) == SET
737 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == ASM_OPERANDS)
739 /* Verify that operands are really shared. */
740 gcc_assert (ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (x, 0, 0)))
741 == ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP
742 (x, 0, j))));
743 validate_replace_rtx_1 (&SET_DEST (XVECEXP (x, 0, j)),
744 from, to, object, simplify);
746 else
747 validate_replace_rtx_1 (&XVECEXP (x, 0, j), from, to, object,
748 simplify);
751 else
752 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
754 if (fmt[i] == 'e')
755 validate_replace_rtx_1 (&XEXP (x, i), from, to, object, simplify);
756 else if (fmt[i] == 'E')
757 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
758 validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object,
759 simplify);
762 /* If we didn't substitute, there is nothing more to do. */
763 if (num_changes == prev_changes)
764 return;
766 /* ??? The regmove is no more, so is this aberration still necessary? */
767 /* Allow substituted expression to have different mode. This is used by
768 regmove to change mode of pseudo register. */
769 if (fmt[0] == 'e' && GET_MODE (XEXP (x, 0)) != VOIDmode)
770 op0_mode = GET_MODE (XEXP (x, 0));
772 /* Do changes needed to keep rtx consistent. Don't do any other
773 simplifications, as it is not our job. */
774 if (simplify)
775 simplify_while_replacing (loc, to, object, op0_mode);
778 /* Try replacing every occurrence of FROM in subexpression LOC of INSN
779 with TO. After all changes have been made, validate by seeing
780 if INSN is still valid. */
783 validate_replace_rtx_subexp (rtx from, rtx to, rtx insn, rtx *loc)
785 validate_replace_rtx_1 (loc, from, to, insn, true);
786 return apply_change_group ();
789 /* Try replacing every occurrence of FROM in INSN with TO. After all
790 changes have been made, validate by seeing if INSN is still valid. */
793 validate_replace_rtx (rtx from, rtx to, rtx insn)
795 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn, true);
796 return apply_change_group ();
799 /* Try replacing every occurrence of FROM in WHERE with TO. Assume that WHERE
800 is a part of INSN. After all changes have been made, validate by seeing if
801 INSN is still valid.
802 validate_replace_rtx (from, to, insn) is equivalent to
803 validate_replace_rtx_part (from, to, &PATTERN (insn), insn). */
806 validate_replace_rtx_part (rtx from, rtx to, rtx *where, rtx insn)
808 validate_replace_rtx_1 (where, from, to, insn, true);
809 return apply_change_group ();
812 /* Same as above, but do not simplify rtx afterwards. */
814 validate_replace_rtx_part_nosimplify (rtx from, rtx to, rtx *where,
815 rtx insn)
817 validate_replace_rtx_1 (where, from, to, insn, false);
818 return apply_change_group ();
822 /* Try replacing every occurrence of FROM in INSN with TO. This also
823 will replace in REG_EQUAL and REG_EQUIV notes. */
825 void
826 validate_replace_rtx_group (rtx from, rtx to, rtx insn)
828 rtx note;
829 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn, true);
830 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
831 if (REG_NOTE_KIND (note) == REG_EQUAL
832 || REG_NOTE_KIND (note) == REG_EQUIV)
833 validate_replace_rtx_1 (&XEXP (note, 0), from, to, insn, true);
836 /* Function called by note_uses to replace used subexpressions. */
837 struct validate_replace_src_data
839 rtx from; /* Old RTX */
840 rtx to; /* New RTX */
841 rtx insn; /* Insn in which substitution is occurring. */
844 static void
845 validate_replace_src_1 (rtx *x, void *data)
847 struct validate_replace_src_data *d
848 = (struct validate_replace_src_data *) data;
850 validate_replace_rtx_1 (x, d->from, d->to, d->insn, true);
853 /* Try replacing every occurrence of FROM in INSN with TO, avoiding
854 SET_DESTs. */
856 void
857 validate_replace_src_group (rtx from, rtx to, rtx insn)
859 struct validate_replace_src_data d;
861 d.from = from;
862 d.to = to;
863 d.insn = insn;
864 note_uses (&PATTERN (insn), validate_replace_src_1, &d);
867 /* Try simplify INSN.
868 Invoke simplify_rtx () on every SET_SRC and SET_DEST inside the INSN's
869 pattern and return true if something was simplified. */
871 bool
872 validate_simplify_insn (rtx insn)
874 int i;
875 rtx pat = NULL;
876 rtx newpat = NULL;
878 pat = PATTERN (insn);
880 if (GET_CODE (pat) == SET)
882 newpat = simplify_rtx (SET_SRC (pat));
883 if (newpat && !rtx_equal_p (SET_SRC (pat), newpat))
884 validate_change (insn, &SET_SRC (pat), newpat, 1);
885 newpat = simplify_rtx (SET_DEST (pat));
886 if (newpat && !rtx_equal_p (SET_DEST (pat), newpat))
887 validate_change (insn, &SET_DEST (pat), newpat, 1);
889 else if (GET_CODE (pat) == PARALLEL)
890 for (i = 0; i < XVECLEN (pat, 0); i++)
892 rtx s = XVECEXP (pat, 0, i);
894 if (GET_CODE (XVECEXP (pat, 0, i)) == SET)
896 newpat = simplify_rtx (SET_SRC (s));
897 if (newpat && !rtx_equal_p (SET_SRC (s), newpat))
898 validate_change (insn, &SET_SRC (s), newpat, 1);
899 newpat = simplify_rtx (SET_DEST (s));
900 if (newpat && !rtx_equal_p (SET_DEST (s), newpat))
901 validate_change (insn, &SET_DEST (s), newpat, 1);
904 return ((num_changes_pending () > 0) && (apply_change_group () > 0));
907 #ifdef HAVE_cc0
908 /* Return 1 if the insn using CC0 set by INSN does not contain
909 any ordered tests applied to the condition codes.
910 EQ and NE tests do not count. */
913 next_insn_tests_no_inequality (rtx insn)
915 rtx next = next_cc0_user (insn);
917 /* If there is no next insn, we have to take the conservative choice. */
918 if (next == 0)
919 return 0;
921 return (INSN_P (next)
922 && ! inequality_comparisons_p (PATTERN (next)));
924 #endif
926 /* Return 1 if OP is a valid general operand for machine mode MODE.
927 This is either a register reference, a memory reference,
928 or a constant. In the case of a memory reference, the address
929 is checked for general validity for the target machine.
931 Register and memory references must have mode MODE in order to be valid,
932 but some constants have no machine mode and are valid for any mode.
934 If MODE is VOIDmode, OP is checked for validity for whatever mode
935 it has.
937 The main use of this function is as a predicate in match_operand
938 expressions in the machine description. */
941 general_operand (rtx op, enum machine_mode mode)
943 enum rtx_code code = GET_CODE (op);
945 if (mode == VOIDmode)
946 mode = GET_MODE (op);
948 /* Don't accept CONST_INT or anything similar
949 if the caller wants something floating. */
950 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
951 && GET_MODE_CLASS (mode) != MODE_INT
952 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
953 return 0;
955 if (CONST_INT_P (op)
956 && mode != VOIDmode
957 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
958 return 0;
960 if (CONSTANT_P (op))
961 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
962 || mode == VOIDmode)
963 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
964 && targetm.legitimate_constant_p (mode == VOIDmode
965 ? GET_MODE (op)
966 : mode, op));
968 /* Except for certain constants with VOIDmode, already checked for,
969 OP's mode must match MODE if MODE specifies a mode. */
971 if (GET_MODE (op) != mode)
972 return 0;
974 if (code == SUBREG)
976 rtx sub = SUBREG_REG (op);
978 #ifdef INSN_SCHEDULING
979 /* On machines that have insn scheduling, we want all memory
980 reference to be explicit, so outlaw paradoxical SUBREGs.
981 However, we must allow them after reload so that they can
982 get cleaned up by cleanup_subreg_operands. */
983 if (!reload_completed && MEM_P (sub)
984 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (sub)))
985 return 0;
986 #endif
987 /* Avoid memories with nonzero SUBREG_BYTE, as offsetting the memory
988 may result in incorrect reference. We should simplify all valid
989 subregs of MEM anyway. But allow this after reload because we
990 might be called from cleanup_subreg_operands.
992 ??? This is a kludge. */
993 if (!reload_completed && SUBREG_BYTE (op) != 0
994 && MEM_P (sub))
995 return 0;
997 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
998 create such rtl, and we must reject it. */
999 if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
1000 /* LRA can use subreg to store a floating point value in an
1001 integer mode. Although the floating point and the
1002 integer modes need the same number of hard registers, the
1003 size of floating point mode can be less than the integer
1004 mode. */
1005 && ! lra_in_progress
1006 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
1007 return 0;
1009 op = sub;
1010 code = GET_CODE (op);
1013 if (code == REG)
1014 return (REGNO (op) >= FIRST_PSEUDO_REGISTER
1015 || in_hard_reg_set_p (operand_reg_set, GET_MODE (op), REGNO (op)));
1017 if (code == MEM)
1019 rtx y = XEXP (op, 0);
1021 if (! volatile_ok && MEM_VOLATILE_P (op))
1022 return 0;
1024 /* Use the mem's mode, since it will be reloaded thus. LRA can
1025 generate move insn with invalid addresses which is made valid
1026 and efficiently calculated by LRA through further numerous
1027 transformations. */
1028 if (lra_in_progress
1029 || memory_address_addr_space_p (GET_MODE (op), y, MEM_ADDR_SPACE (op)))
1030 return 1;
1033 return 0;
1036 /* Return 1 if OP is a valid memory address for a memory reference
1037 of mode MODE.
1039 The main use of this function is as a predicate in match_operand
1040 expressions in the machine description. */
1043 address_operand (rtx op, enum machine_mode mode)
1045 return memory_address_p (mode, op);
1048 /* Return 1 if OP is a register reference of mode MODE.
1049 If MODE is VOIDmode, accept a register in any mode.
1051 The main use of this function is as a predicate in match_operand
1052 expressions in the machine description. */
1055 register_operand (rtx op, enum machine_mode mode)
1057 if (GET_MODE (op) != mode && mode != VOIDmode)
1058 return 0;
1060 if (GET_CODE (op) == SUBREG)
1062 rtx sub = SUBREG_REG (op);
1064 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1065 because it is guaranteed to be reloaded into one.
1066 Just make sure the MEM is valid in itself.
1067 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1068 but currently it does result from (SUBREG (REG)...) where the
1069 reg went on the stack.) */
1070 if (! reload_completed && MEM_P (sub))
1071 return general_operand (op, mode);
1073 #ifdef CANNOT_CHANGE_MODE_CLASS
1074 if (REG_P (sub)
1075 && REGNO (sub) < FIRST_PSEUDO_REGISTER
1076 && REG_CANNOT_CHANGE_MODE_P (REGNO (sub), GET_MODE (sub), mode)
1077 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_INT
1078 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_FLOAT
1079 /* LRA can generate some invalid SUBREGS just for matched
1080 operand reload presentation. LRA needs to treat them as
1081 valid. */
1082 && ! LRA_SUBREG_P (op))
1083 return 0;
1084 #endif
1086 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
1087 create such rtl, and we must reject it. */
1088 if (SCALAR_FLOAT_MODE_P (GET_MODE (op))
1089 /* LRA can use subreg to store a floating point value in an
1090 integer mode. Although the floating point and the
1091 integer modes need the same number of hard registers, the
1092 size of floating point mode can be less than the integer
1093 mode. */
1094 && ! lra_in_progress
1095 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
1096 return 0;
1098 op = sub;
1101 return (REG_P (op)
1102 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1103 || in_hard_reg_set_p (operand_reg_set,
1104 GET_MODE (op), REGNO (op))));
1107 /* Return 1 for a register in Pmode; ignore the tested mode. */
1110 pmode_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1112 return register_operand (op, Pmode);
1115 /* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
1116 or a hard register. */
1119 scratch_operand (rtx op, enum machine_mode mode)
1121 if (GET_MODE (op) != mode && mode != VOIDmode)
1122 return 0;
1124 return (GET_CODE (op) == SCRATCH
1125 || (REG_P (op)
1126 && (lra_in_progress || REGNO (op) < FIRST_PSEUDO_REGISTER)));
1129 /* Return 1 if OP is a valid immediate operand for mode MODE.
1131 The main use of this function is as a predicate in match_operand
1132 expressions in the machine description. */
1135 immediate_operand (rtx op, enum machine_mode mode)
1137 /* Don't accept CONST_INT or anything similar
1138 if the caller wants something floating. */
1139 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1140 && GET_MODE_CLASS (mode) != MODE_INT
1141 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1142 return 0;
1144 if (CONST_INT_P (op)
1145 && mode != VOIDmode
1146 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1147 return 0;
1149 return (CONSTANT_P (op)
1150 && (GET_MODE (op) == mode || mode == VOIDmode
1151 || GET_MODE (op) == VOIDmode)
1152 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1153 && targetm.legitimate_constant_p (mode == VOIDmode
1154 ? GET_MODE (op)
1155 : mode, op));
1158 /* Returns 1 if OP is an operand that is a CONST_INT. */
1161 const_int_operand (rtx op, enum machine_mode mode)
1163 if (!CONST_INT_P (op))
1164 return 0;
1166 if (mode != VOIDmode
1167 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1168 return 0;
1170 return 1;
1173 /* Returns 1 if OP is an operand that is a constant integer or constant
1174 floating-point number. */
1177 const_double_operand (rtx op, enum machine_mode mode)
1179 /* Don't accept CONST_INT or anything similar
1180 if the caller wants something floating. */
1181 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1182 && GET_MODE_CLASS (mode) != MODE_INT
1183 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1184 return 0;
1186 return ((CONST_DOUBLE_P (op) || CONST_INT_P (op))
1187 && (mode == VOIDmode || GET_MODE (op) == mode
1188 || GET_MODE (op) == VOIDmode));
1191 /* Return 1 if OP is a general operand that is not an immediate operand. */
1194 nonimmediate_operand (rtx op, enum machine_mode mode)
1196 return (general_operand (op, mode) && ! CONSTANT_P (op));
1199 /* Return 1 if OP is a register reference or immediate value of mode MODE. */
1202 nonmemory_operand (rtx op, enum machine_mode mode)
1204 if (CONSTANT_P (op))
1205 return immediate_operand (op, mode);
1207 if (GET_MODE (op) != mode && mode != VOIDmode)
1208 return 0;
1210 if (GET_CODE (op) == SUBREG)
1212 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1213 because it is guaranteed to be reloaded into one.
1214 Just make sure the MEM is valid in itself.
1215 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1216 but currently it does result from (SUBREG (REG)...) where the
1217 reg went on the stack.) */
1218 if (! reload_completed && MEM_P (SUBREG_REG (op)))
1219 return general_operand (op, mode);
1220 op = SUBREG_REG (op);
1223 return (REG_P (op)
1224 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1225 || in_hard_reg_set_p (operand_reg_set,
1226 GET_MODE (op), REGNO (op))));
1229 /* Return 1 if OP is a valid operand that stands for pushing a
1230 value of mode MODE onto the stack.
1232 The main use of this function is as a predicate in match_operand
1233 expressions in the machine description. */
1236 push_operand (rtx op, enum machine_mode mode)
1238 unsigned int rounded_size = GET_MODE_SIZE (mode);
1240 #ifdef PUSH_ROUNDING
1241 rounded_size = PUSH_ROUNDING (rounded_size);
1242 #endif
1244 if (!MEM_P (op))
1245 return 0;
1247 if (mode != VOIDmode && GET_MODE (op) != mode)
1248 return 0;
1250 op = XEXP (op, 0);
1252 if (rounded_size == GET_MODE_SIZE (mode))
1254 if (GET_CODE (op) != STACK_PUSH_CODE)
1255 return 0;
1257 else
1259 if (GET_CODE (op) != PRE_MODIFY
1260 || GET_CODE (XEXP (op, 1)) != PLUS
1261 || XEXP (XEXP (op, 1), 0) != XEXP (op, 0)
1262 || !CONST_INT_P (XEXP (XEXP (op, 1), 1))
1263 #ifdef STACK_GROWS_DOWNWARD
1264 || INTVAL (XEXP (XEXP (op, 1), 1)) != - (int) rounded_size
1265 #else
1266 || INTVAL (XEXP (XEXP (op, 1), 1)) != (int) rounded_size
1267 #endif
1269 return 0;
1272 return XEXP (op, 0) == stack_pointer_rtx;
1275 /* Return 1 if OP is a valid operand that stands for popping a
1276 value of mode MODE off the stack.
1278 The main use of this function is as a predicate in match_operand
1279 expressions in the machine description. */
1282 pop_operand (rtx op, enum machine_mode mode)
1284 if (!MEM_P (op))
1285 return 0;
1287 if (mode != VOIDmode && GET_MODE (op) != mode)
1288 return 0;
1290 op = XEXP (op, 0);
1292 if (GET_CODE (op) != STACK_POP_CODE)
1293 return 0;
1295 return XEXP (op, 0) == stack_pointer_rtx;
1298 /* Return 1 if ADDR is a valid memory address
1299 for mode MODE in address space AS. */
1302 memory_address_addr_space_p (enum machine_mode mode ATTRIBUTE_UNUSED,
1303 rtx addr, addr_space_t as)
1305 #ifdef GO_IF_LEGITIMATE_ADDRESS
1306 gcc_assert (ADDR_SPACE_GENERIC_P (as));
1307 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1308 return 0;
1310 win:
1311 return 1;
1312 #else
1313 return targetm.addr_space.legitimate_address_p (mode, addr, 0, as);
1314 #endif
1317 /* Return 1 if OP is a valid memory reference with mode MODE,
1318 including a valid address.
1320 The main use of this function is as a predicate in match_operand
1321 expressions in the machine description. */
1324 memory_operand (rtx op, enum machine_mode mode)
1326 rtx inner;
1328 if (! reload_completed)
1329 /* Note that no SUBREG is a memory operand before end of reload pass,
1330 because (SUBREG (MEM...)) forces reloading into a register. */
1331 return MEM_P (op) && general_operand (op, mode);
1333 if (mode != VOIDmode && GET_MODE (op) != mode)
1334 return 0;
1336 inner = op;
1337 if (GET_CODE (inner) == SUBREG)
1338 inner = SUBREG_REG (inner);
1340 return (MEM_P (inner) && general_operand (op, mode));
1343 /* Return 1 if OP is a valid indirect memory reference with mode MODE;
1344 that is, a memory reference whose address is a general_operand. */
1347 indirect_operand (rtx op, enum machine_mode mode)
1349 /* Before reload, a SUBREG isn't in memory (see memory_operand, above). */
1350 if (! reload_completed
1351 && GET_CODE (op) == SUBREG && MEM_P (SUBREG_REG (op)))
1353 int offset = SUBREG_BYTE (op);
1354 rtx inner = SUBREG_REG (op);
1356 if (mode != VOIDmode && GET_MODE (op) != mode)
1357 return 0;
1359 /* The only way that we can have a general_operand as the resulting
1360 address is if OFFSET is zero and the address already is an operand
1361 or if the address is (plus Y (const_int -OFFSET)) and Y is an
1362 operand. */
1364 return ((offset == 0 && general_operand (XEXP (inner, 0), Pmode))
1365 || (GET_CODE (XEXP (inner, 0)) == PLUS
1366 && CONST_INT_P (XEXP (XEXP (inner, 0), 1))
1367 && INTVAL (XEXP (XEXP (inner, 0), 1)) == -offset
1368 && general_operand (XEXP (XEXP (inner, 0), 0), Pmode)));
1371 return (MEM_P (op)
1372 && memory_operand (op, mode)
1373 && general_operand (XEXP (op, 0), Pmode));
1376 /* Return 1 if this is an ordered comparison operator (not including
1377 ORDERED and UNORDERED). */
1380 ordered_comparison_operator (rtx op, enum machine_mode mode)
1382 if (mode != VOIDmode && GET_MODE (op) != mode)
1383 return false;
1384 switch (GET_CODE (op))
1386 case EQ:
1387 case NE:
1388 case LT:
1389 case LTU:
1390 case LE:
1391 case LEU:
1392 case GT:
1393 case GTU:
1394 case GE:
1395 case GEU:
1396 return true;
1397 default:
1398 return false;
1402 /* Return 1 if this is a comparison operator. This allows the use of
1403 MATCH_OPERATOR to recognize all the branch insns. */
1406 comparison_operator (rtx op, enum machine_mode mode)
1408 return ((mode == VOIDmode || GET_MODE (op) == mode)
1409 && COMPARISON_P (op));
1412 /* If BODY is an insn body that uses ASM_OPERANDS, return it. */
1415 extract_asm_operands (rtx body)
1417 rtx tmp;
1418 switch (GET_CODE (body))
1420 case ASM_OPERANDS:
1421 return body;
1423 case SET:
1424 /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
1425 tmp = SET_SRC (body);
1426 if (GET_CODE (tmp) == ASM_OPERANDS)
1427 return tmp;
1428 break;
1430 case PARALLEL:
1431 tmp = XVECEXP (body, 0, 0);
1432 if (GET_CODE (tmp) == ASM_OPERANDS)
1433 return tmp;
1434 if (GET_CODE (tmp) == SET)
1436 tmp = SET_SRC (tmp);
1437 if (GET_CODE (tmp) == ASM_OPERANDS)
1438 return tmp;
1440 break;
1442 default:
1443 break;
1445 return NULL;
1448 /* If BODY is an insn body that uses ASM_OPERANDS,
1449 return the number of operands (both input and output) in the insn.
1450 Otherwise return -1. */
1453 asm_noperands (const_rtx body)
1455 rtx asm_op = extract_asm_operands (CONST_CAST_RTX (body));
1456 int n_sets = 0;
1458 if (asm_op == NULL)
1459 return -1;
1461 if (GET_CODE (body) == SET)
1462 n_sets = 1;
1463 else if (GET_CODE (body) == PARALLEL)
1465 int i;
1466 if (GET_CODE (XVECEXP (body, 0, 0)) == SET)
1468 /* Multiple output operands, or 1 output plus some clobbers:
1469 body is
1470 [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...]. */
1471 /* Count backwards through CLOBBERs to determine number of SETs. */
1472 for (i = XVECLEN (body, 0); i > 0; i--)
1474 if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
1475 break;
1476 if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
1477 return -1;
1480 /* N_SETS is now number of output operands. */
1481 n_sets = i;
1483 /* Verify that all the SETs we have
1484 came from a single original asm_operands insn
1485 (so that invalid combinations are blocked). */
1486 for (i = 0; i < n_sets; i++)
1488 rtx elt = XVECEXP (body, 0, i);
1489 if (GET_CODE (elt) != SET)
1490 return -1;
1491 if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
1492 return -1;
1493 /* If these ASM_OPERANDS rtx's came from different original insns
1494 then they aren't allowed together. */
1495 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
1496 != ASM_OPERANDS_INPUT_VEC (asm_op))
1497 return -1;
1500 else
1502 /* 0 outputs, but some clobbers:
1503 body is [(asm_operands ...) (clobber (reg ...))...]. */
1504 /* Make sure all the other parallel things really are clobbers. */
1505 for (i = XVECLEN (body, 0) - 1; i > 0; i--)
1506 if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
1507 return -1;
1511 return (ASM_OPERANDS_INPUT_LENGTH (asm_op)
1512 + ASM_OPERANDS_LABEL_LENGTH (asm_op) + n_sets);
1515 /* Assuming BODY is an insn body that uses ASM_OPERANDS,
1516 copy its operands (both input and output) into the vector OPERANDS,
1517 the locations of the operands within the insn into the vector OPERAND_LOCS,
1518 and the constraints for the operands into CONSTRAINTS.
1519 Write the modes of the operands into MODES.
1520 Return the assembler-template.
1522 If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1523 we don't store that info. */
1525 const char *
1526 decode_asm_operands (rtx body, rtx *operands, rtx **operand_locs,
1527 const char **constraints, enum machine_mode *modes,
1528 location_t *loc)
1530 int nbase = 0, n, i;
1531 rtx asmop;
1533 switch (GET_CODE (body))
1535 case ASM_OPERANDS:
1536 /* Zero output asm: BODY is (asm_operands ...). */
1537 asmop = body;
1538 break;
1540 case SET:
1541 /* Single output asm: BODY is (set OUTPUT (asm_operands ...)). */
1542 asmop = SET_SRC (body);
1544 /* The output is in the SET.
1545 Its constraint is in the ASM_OPERANDS itself. */
1546 if (operands)
1547 operands[0] = SET_DEST (body);
1548 if (operand_locs)
1549 operand_locs[0] = &SET_DEST (body);
1550 if (constraints)
1551 constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
1552 if (modes)
1553 modes[0] = GET_MODE (SET_DEST (body));
1554 nbase = 1;
1555 break;
1557 case PARALLEL:
1559 int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
1561 asmop = XVECEXP (body, 0, 0);
1562 if (GET_CODE (asmop) == SET)
1564 asmop = SET_SRC (asmop);
1566 /* At least one output, plus some CLOBBERs. The outputs are in
1567 the SETs. Their constraints are in the ASM_OPERANDS itself. */
1568 for (i = 0; i < nparallel; i++)
1570 if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1571 break; /* Past last SET */
1572 if (operands)
1573 operands[i] = SET_DEST (XVECEXP (body, 0, i));
1574 if (operand_locs)
1575 operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
1576 if (constraints)
1577 constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
1578 if (modes)
1579 modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
1581 nbase = i;
1583 break;
1586 default:
1587 gcc_unreachable ();
1590 n = ASM_OPERANDS_INPUT_LENGTH (asmop);
1591 for (i = 0; i < n; i++)
1593 if (operand_locs)
1594 operand_locs[nbase + i] = &ASM_OPERANDS_INPUT (asmop, i);
1595 if (operands)
1596 operands[nbase + i] = ASM_OPERANDS_INPUT (asmop, i);
1597 if (constraints)
1598 constraints[nbase + i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1599 if (modes)
1600 modes[nbase + i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1602 nbase += n;
1604 n = ASM_OPERANDS_LABEL_LENGTH (asmop);
1605 for (i = 0; i < n; i++)
1607 if (operand_locs)
1608 operand_locs[nbase + i] = &ASM_OPERANDS_LABEL (asmop, i);
1609 if (operands)
1610 operands[nbase + i] = ASM_OPERANDS_LABEL (asmop, i);
1611 if (constraints)
1612 constraints[nbase + i] = "";
1613 if (modes)
1614 modes[nbase + i] = Pmode;
1617 if (loc)
1618 *loc = ASM_OPERANDS_SOURCE_LOCATION (asmop);
1620 return ASM_OPERANDS_TEMPLATE (asmop);
1623 /* Parse inline assembly string STRING and determine which operands are
1624 referenced by % markers. For the first NOPERANDS operands, set USED[I]
1625 to true if operand I is referenced.
1627 This is intended to distinguish barrier-like asms such as:
1629 asm ("" : "=m" (...));
1631 from real references such as:
1633 asm ("sw\t$0, %0" : "=m" (...)); */
1635 void
1636 get_referenced_operands (const char *string, bool *used,
1637 unsigned int noperands)
1639 memset (used, 0, sizeof (bool) * noperands);
1640 const char *p = string;
1641 while (*p)
1642 switch (*p)
1644 case '%':
1645 p += 1;
1646 /* A letter followed by a digit indicates an operand number. */
1647 if (ISALPHA (p[0]) && ISDIGIT (p[1]))
1648 p += 1;
1649 if (ISDIGIT (*p))
1651 char *endptr;
1652 unsigned long opnum = strtoul (p, &endptr, 10);
1653 if (endptr != p && opnum < noperands)
1654 used[opnum] = true;
1655 p = endptr;
1657 else
1658 p += 1;
1659 break;
1661 default:
1662 p++;
1663 break;
1667 /* Check if an asm_operand matches its constraints.
1668 Return > 0 if ok, = 0 if bad, < 0 if inconclusive. */
1671 asm_operand_ok (rtx op, const char *constraint, const char **constraints)
1673 int result = 0;
1674 #ifdef AUTO_INC_DEC
1675 bool incdec_ok = false;
1676 #endif
1678 /* Use constrain_operands after reload. */
1679 gcc_assert (!reload_completed);
1681 /* Empty constraint string is the same as "X,...,X", i.e. X for as
1682 many alternatives as required to match the other operands. */
1683 if (*constraint == '\0')
1684 result = 1;
1686 while (*constraint)
1688 char c = *constraint;
1689 int len;
1690 switch (c)
1692 case ',':
1693 constraint++;
1694 continue;
1695 case '=':
1696 case '+':
1697 case '*':
1698 case '%':
1699 case '!':
1700 case '#':
1701 case '&':
1702 case '?':
1703 break;
1705 case '0': case '1': case '2': case '3': case '4':
1706 case '5': case '6': case '7': case '8': case '9':
1707 /* If caller provided constraints pointer, look up
1708 the matching constraint. Otherwise, our caller should have
1709 given us the proper matching constraint, but we can't
1710 actually fail the check if they didn't. Indicate that
1711 results are inconclusive. */
1712 if (constraints)
1714 char *end;
1715 unsigned long match;
1717 match = strtoul (constraint, &end, 10);
1718 if (!result)
1719 result = asm_operand_ok (op, constraints[match], NULL);
1720 constraint = (const char *) end;
1722 else
1725 constraint++;
1726 while (ISDIGIT (*constraint));
1727 if (! result)
1728 result = -1;
1730 continue;
1732 case 'p':
1733 if (address_operand (op, VOIDmode))
1734 result = 1;
1735 break;
1737 case TARGET_MEM_CONSTRAINT:
1738 case 'V': /* non-offsettable */
1739 if (memory_operand (op, VOIDmode))
1740 result = 1;
1741 break;
1743 case 'o': /* offsettable */
1744 if (offsettable_nonstrict_memref_p (op))
1745 result = 1;
1746 break;
1748 case '<':
1749 /* ??? Before auto-inc-dec, auto inc/dec insns are not supposed to exist,
1750 excepting those that expand_call created. Further, on some
1751 machines which do not have generalized auto inc/dec, an inc/dec
1752 is not a memory_operand.
1754 Match any memory and hope things are resolved after reload. */
1756 if (MEM_P (op)
1757 && (1
1758 || GET_CODE (XEXP (op, 0)) == PRE_DEC
1759 || GET_CODE (XEXP (op, 0)) == POST_DEC))
1760 result = 1;
1761 #ifdef AUTO_INC_DEC
1762 incdec_ok = true;
1763 #endif
1764 break;
1766 case '>':
1767 if (MEM_P (op)
1768 && (1
1769 || GET_CODE (XEXP (op, 0)) == PRE_INC
1770 || GET_CODE (XEXP (op, 0)) == POST_INC))
1771 result = 1;
1772 #ifdef AUTO_INC_DEC
1773 incdec_ok = true;
1774 #endif
1775 break;
1777 case 'E':
1778 case 'F':
1779 if (CONST_DOUBLE_AS_FLOAT_P (op)
1780 || (GET_CODE (op) == CONST_VECTOR
1781 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
1782 result = 1;
1783 break;
1785 case 'G':
1786 if (CONST_DOUBLE_AS_FLOAT_P (op)
1787 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'G', constraint))
1788 result = 1;
1789 break;
1790 case 'H':
1791 if (CONST_DOUBLE_AS_FLOAT_P (op)
1792 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, 'H', constraint))
1793 result = 1;
1794 break;
1796 case 's':
1797 if (CONST_SCALAR_INT_P (op))
1798 break;
1799 /* Fall through. */
1801 case 'i':
1802 if (CONSTANT_P (op) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op)))
1803 result = 1;
1804 break;
1806 case 'n':
1807 if (CONST_SCALAR_INT_P (op))
1808 result = 1;
1809 break;
1811 case 'I':
1812 if (CONST_INT_P (op)
1813 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'I', constraint))
1814 result = 1;
1815 break;
1816 case 'J':
1817 if (CONST_INT_P (op)
1818 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'J', constraint))
1819 result = 1;
1820 break;
1821 case 'K':
1822 if (CONST_INT_P (op)
1823 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'K', constraint))
1824 result = 1;
1825 break;
1826 case 'L':
1827 if (CONST_INT_P (op)
1828 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'L', constraint))
1829 result = 1;
1830 break;
1831 case 'M':
1832 if (CONST_INT_P (op)
1833 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'M', constraint))
1834 result = 1;
1835 break;
1836 case 'N':
1837 if (CONST_INT_P (op)
1838 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'N', constraint))
1839 result = 1;
1840 break;
1841 case 'O':
1842 if (CONST_INT_P (op)
1843 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'O', constraint))
1844 result = 1;
1845 break;
1846 case 'P':
1847 if (CONST_INT_P (op)
1848 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), 'P', constraint))
1849 result = 1;
1850 break;
1852 case 'X':
1853 result = 1;
1854 break;
1856 case 'g':
1857 if (general_operand (op, VOIDmode))
1858 result = 1;
1859 break;
1861 default:
1862 /* For all other letters, we first check for a register class,
1863 otherwise it is an EXTRA_CONSTRAINT. */
1864 if (REG_CLASS_FROM_CONSTRAINT (c, constraint) != NO_REGS)
1866 case 'r':
1867 if (GET_MODE (op) == BLKmode)
1868 break;
1869 if (register_operand (op, VOIDmode))
1870 result = 1;
1872 #ifdef EXTRA_CONSTRAINT_STR
1873 else if (EXTRA_MEMORY_CONSTRAINT (c, constraint))
1874 /* Every memory operand can be reloaded to fit. */
1875 result = result || memory_operand (op, VOIDmode);
1876 else if (EXTRA_ADDRESS_CONSTRAINT (c, constraint))
1877 /* Every address operand can be reloaded to fit. */
1878 result = result || address_operand (op, VOIDmode);
1879 else if (EXTRA_CONSTRAINT_STR (op, c, constraint))
1880 result = 1;
1881 #endif
1882 break;
1884 len = CONSTRAINT_LEN (c, constraint);
1886 constraint++;
1887 while (--len && *constraint);
1888 if (len)
1889 return 0;
1892 #ifdef AUTO_INC_DEC
1893 /* For operands without < or > constraints reject side-effects. */
1894 if (!incdec_ok && result && MEM_P (op))
1895 switch (GET_CODE (XEXP (op, 0)))
1897 case PRE_INC:
1898 case POST_INC:
1899 case PRE_DEC:
1900 case POST_DEC:
1901 case PRE_MODIFY:
1902 case POST_MODIFY:
1903 return 0;
1904 default:
1905 break;
1907 #endif
1909 return result;
1912 /* Given an rtx *P, if it is a sum containing an integer constant term,
1913 return the location (type rtx *) of the pointer to that constant term.
1914 Otherwise, return a null pointer. */
1916 rtx *
1917 find_constant_term_loc (rtx *p)
1919 rtx *tem;
1920 enum rtx_code code = GET_CODE (*p);
1922 /* If *P IS such a constant term, P is its location. */
1924 if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1925 || code == CONST)
1926 return p;
1928 /* Otherwise, if not a sum, it has no constant term. */
1930 if (GET_CODE (*p) != PLUS)
1931 return 0;
1933 /* If one of the summands is constant, return its location. */
1935 if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1936 && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1937 return p;
1939 /* Otherwise, check each summand for containing a constant term. */
1941 if (XEXP (*p, 0) != 0)
1943 tem = find_constant_term_loc (&XEXP (*p, 0));
1944 if (tem != 0)
1945 return tem;
1948 if (XEXP (*p, 1) != 0)
1950 tem = find_constant_term_loc (&XEXP (*p, 1));
1951 if (tem != 0)
1952 return tem;
1955 return 0;
1958 /* Return 1 if OP is a memory reference
1959 whose address contains no side effects
1960 and remains valid after the addition
1961 of a positive integer less than the
1962 size of the object being referenced.
1964 We assume that the original address is valid and do not check it.
1966 This uses strict_memory_address_p as a subroutine, so
1967 don't use it before reload. */
1970 offsettable_memref_p (rtx op)
1972 return ((MEM_P (op))
1973 && offsettable_address_addr_space_p (1, GET_MODE (op), XEXP (op, 0),
1974 MEM_ADDR_SPACE (op)));
1977 /* Similar, but don't require a strictly valid mem ref:
1978 consider pseudo-regs valid as index or base regs. */
1981 offsettable_nonstrict_memref_p (rtx op)
1983 return ((MEM_P (op))
1984 && offsettable_address_addr_space_p (0, GET_MODE (op), XEXP (op, 0),
1985 MEM_ADDR_SPACE (op)));
1988 /* Return 1 if Y is a memory address which contains no side effects
1989 and would remain valid for address space AS after the addition of
1990 a positive integer less than the size of that mode.
1992 We assume that the original address is valid and do not check it.
1993 We do check that it is valid for narrower modes.
1995 If STRICTP is nonzero, we require a strictly valid address,
1996 for the sake of use in reload.c. */
1999 offsettable_address_addr_space_p (int strictp, enum machine_mode mode, rtx y,
2000 addr_space_t as)
2002 enum rtx_code ycode = GET_CODE (y);
2003 rtx z;
2004 rtx y1 = y;
2005 rtx *y2;
2006 int (*addressp) (enum machine_mode, rtx, addr_space_t) =
2007 (strictp ? strict_memory_address_addr_space_p
2008 : memory_address_addr_space_p);
2009 unsigned int mode_sz = GET_MODE_SIZE (mode);
2011 if (CONSTANT_ADDRESS_P (y))
2012 return 1;
2014 /* Adjusting an offsettable address involves changing to a narrower mode.
2015 Make sure that's OK. */
2017 if (mode_dependent_address_p (y, as))
2018 return 0;
2020 enum machine_mode address_mode = GET_MODE (y);
2021 if (address_mode == VOIDmode)
2022 address_mode = targetm.addr_space.address_mode (as);
2023 #ifdef POINTERS_EXTEND_UNSIGNED
2024 enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as);
2025 #endif
2027 /* ??? How much offset does an offsettable BLKmode reference need?
2028 Clearly that depends on the situation in which it's being used.
2029 However, the current situation in which we test 0xffffffff is
2030 less than ideal. Caveat user. */
2031 if (mode_sz == 0)
2032 mode_sz = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2034 /* If the expression contains a constant term,
2035 see if it remains valid when max possible offset is added. */
2037 if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
2039 int good;
2041 y1 = *y2;
2042 *y2 = plus_constant (address_mode, *y2, mode_sz - 1);
2043 /* Use QImode because an odd displacement may be automatically invalid
2044 for any wider mode. But it should be valid for a single byte. */
2045 good = (*addressp) (QImode, y, as);
2047 /* In any case, restore old contents of memory. */
2048 *y2 = y1;
2049 return good;
2052 if (GET_RTX_CLASS (ycode) == RTX_AUTOINC)
2053 return 0;
2055 /* The offset added here is chosen as the maximum offset that
2056 any instruction could need to add when operating on something
2057 of the specified mode. We assume that if Y and Y+c are
2058 valid addresses then so is Y+d for all 0<d<c. adjust_address will
2059 go inside a LO_SUM here, so we do so as well. */
2060 if (GET_CODE (y) == LO_SUM
2061 && mode != BLKmode
2062 && mode_sz <= GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT)
2063 z = gen_rtx_LO_SUM (address_mode, XEXP (y, 0),
2064 plus_constant (address_mode, XEXP (y, 1),
2065 mode_sz - 1));
2066 #ifdef POINTERS_EXTEND_UNSIGNED
2067 /* Likewise for a ZERO_EXTEND from pointer_mode. */
2068 else if (POINTERS_EXTEND_UNSIGNED > 0
2069 && GET_CODE (y) == ZERO_EXTEND
2070 && GET_MODE (XEXP (y, 0)) == pointer_mode)
2071 z = gen_rtx_ZERO_EXTEND (address_mode,
2072 plus_constant (pointer_mode, XEXP (y, 0),
2073 mode_sz - 1));
2074 #endif
2075 else
2076 z = plus_constant (address_mode, y, mode_sz - 1);
2078 /* Use QImode because an odd displacement may be automatically invalid
2079 for any wider mode. But it should be valid for a single byte. */
2080 return (*addressp) (QImode, z, as);
2083 /* Return 1 if ADDR is an address-expression whose effect depends
2084 on the mode of the memory reference it is used in.
2086 ADDRSPACE is the address space associated with the address.
2088 Autoincrement addressing is a typical example of mode-dependence
2089 because the amount of the increment depends on the mode. */
2091 bool
2092 mode_dependent_address_p (rtx addr, addr_space_t addrspace)
2094 /* Auto-increment addressing with anything other than post_modify
2095 or pre_modify always introduces a mode dependency. Catch such
2096 cases now instead of deferring to the target. */
2097 if (GET_CODE (addr) == PRE_INC
2098 || GET_CODE (addr) == POST_INC
2099 || GET_CODE (addr) == PRE_DEC
2100 || GET_CODE (addr) == POST_DEC)
2101 return true;
2103 return targetm.mode_dependent_address_p (addr, addrspace);
2106 /* Like extract_insn, but save insn extracted and don't extract again, when
2107 called again for the same insn expecting that recog_data still contain the
2108 valid information. This is used primary by gen_attr infrastructure that
2109 often does extract insn again and again. */
2110 void
2111 extract_insn_cached (rtx insn)
2113 if (recog_data.insn == insn && INSN_CODE (insn) >= 0)
2114 return;
2115 extract_insn (insn);
2116 recog_data.insn = insn;
2119 /* Do cached extract_insn, constrain_operands and complain about failures.
2120 Used by insn_attrtab. */
2121 void
2122 extract_constrain_insn_cached (rtx insn)
2124 extract_insn_cached (insn);
2125 if (which_alternative == -1
2126 && !constrain_operands (reload_completed))
2127 fatal_insn_not_found (insn);
2130 /* Do cached constrain_operands and complain about failures. */
2132 constrain_operands_cached (int strict)
2134 if (which_alternative == -1)
2135 return constrain_operands (strict);
2136 else
2137 return 1;
2140 /* Analyze INSN and fill in recog_data. */
2142 void
2143 extract_insn (rtx insn)
2145 int i;
2146 int icode;
2147 int noperands;
2148 rtx body = PATTERN (insn);
2150 recog_data.n_operands = 0;
2151 recog_data.n_alternatives = 0;
2152 recog_data.n_dups = 0;
2153 recog_data.is_asm = false;
2155 switch (GET_CODE (body))
2157 case USE:
2158 case CLOBBER:
2159 case ASM_INPUT:
2160 case ADDR_VEC:
2161 case ADDR_DIFF_VEC:
2162 case VAR_LOCATION:
2163 return;
2165 case SET:
2166 if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
2167 goto asm_insn;
2168 else
2169 goto normal_insn;
2170 case PARALLEL:
2171 if ((GET_CODE (XVECEXP (body, 0, 0)) == SET
2172 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
2173 || GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
2174 goto asm_insn;
2175 else
2176 goto normal_insn;
2177 case ASM_OPERANDS:
2178 asm_insn:
2179 recog_data.n_operands = noperands = asm_noperands (body);
2180 if (noperands >= 0)
2182 /* This insn is an `asm' with operands. */
2184 /* expand_asm_operands makes sure there aren't too many operands. */
2185 gcc_assert (noperands <= MAX_RECOG_OPERANDS);
2187 /* Now get the operand values and constraints out of the insn. */
2188 decode_asm_operands (body, recog_data.operand,
2189 recog_data.operand_loc,
2190 recog_data.constraints,
2191 recog_data.operand_mode, NULL);
2192 memset (recog_data.is_operator, 0, sizeof recog_data.is_operator);
2193 if (noperands > 0)
2195 const char *p = recog_data.constraints[0];
2196 recog_data.n_alternatives = 1;
2197 while (*p)
2198 recog_data.n_alternatives += (*p++ == ',');
2200 recog_data.is_asm = true;
2201 break;
2203 fatal_insn_not_found (insn);
2205 default:
2206 normal_insn:
2207 /* Ordinary insn: recognize it, get the operands via insn_extract
2208 and get the constraints. */
2210 icode = recog_memoized (insn);
2211 if (icode < 0)
2212 fatal_insn_not_found (insn);
2214 recog_data.n_operands = noperands = insn_data[icode].n_operands;
2215 recog_data.n_alternatives = insn_data[icode].n_alternatives;
2216 recog_data.n_dups = insn_data[icode].n_dups;
2218 insn_extract (insn);
2220 for (i = 0; i < noperands; i++)
2222 recog_data.constraints[i] = insn_data[icode].operand[i].constraint;
2223 recog_data.is_operator[i] = insn_data[icode].operand[i].is_operator;
2224 recog_data.operand_mode[i] = insn_data[icode].operand[i].mode;
2225 /* VOIDmode match_operands gets mode from their real operand. */
2226 if (recog_data.operand_mode[i] == VOIDmode)
2227 recog_data.operand_mode[i] = GET_MODE (recog_data.operand[i]);
2230 for (i = 0; i < noperands; i++)
2231 recog_data.operand_type[i]
2232 = (recog_data.constraints[i][0] == '=' ? OP_OUT
2233 : recog_data.constraints[i][0] == '+' ? OP_INOUT
2234 : OP_IN);
2236 gcc_assert (recog_data.n_alternatives <= MAX_RECOG_ALTERNATIVES);
2238 if (INSN_CODE (insn) < 0)
2239 for (i = 0; i < recog_data.n_alternatives; i++)
2240 recog_data.alternative_enabled_p[i] = true;
2241 else
2243 recog_data.insn = insn;
2244 for (i = 0; i < recog_data.n_alternatives; i++)
2246 which_alternative = i;
2247 recog_data.alternative_enabled_p[i]
2248 = HAVE_ATTR_enabled ? get_attr_enabled (insn) : 1;
2252 recog_data.insn = NULL;
2253 which_alternative = -1;
2256 /* After calling extract_insn, you can use this function to extract some
2257 information from the constraint strings into a more usable form.
2258 The collected data is stored in recog_op_alt. */
2259 void
2260 preprocess_constraints (void)
2262 int i;
2264 for (i = 0; i < recog_data.n_operands; i++)
2265 memset (recog_op_alt[i], 0, (recog_data.n_alternatives
2266 * sizeof (struct operand_alternative)));
2268 for (i = 0; i < recog_data.n_operands; i++)
2270 int j;
2271 struct operand_alternative *op_alt;
2272 const char *p = recog_data.constraints[i];
2274 op_alt = recog_op_alt[i];
2276 for (j = 0; j < recog_data.n_alternatives; j++)
2278 op_alt[j].cl = NO_REGS;
2279 op_alt[j].constraint = p;
2280 op_alt[j].matches = -1;
2281 op_alt[j].matched = -1;
2283 if (!recog_data.alternative_enabled_p[j])
2285 p = skip_alternative (p);
2286 continue;
2289 if (*p == '\0' || *p == ',')
2291 op_alt[j].anything_ok = 1;
2292 continue;
2295 for (;;)
2297 char c = *p;
2298 if (c == '#')
2300 c = *++p;
2301 while (c != ',' && c != '\0');
2302 if (c == ',' || c == '\0')
2304 p++;
2305 break;
2308 switch (c)
2310 case '=': case '+': case '*': case '%':
2311 case 'E': case 'F': case 'G': case 'H':
2312 case 's': case 'i': case 'n':
2313 case 'I': case 'J': case 'K': case 'L':
2314 case 'M': case 'N': case 'O': case 'P':
2315 /* These don't say anything we care about. */
2316 break;
2318 case '?':
2319 op_alt[j].reject += 6;
2320 break;
2321 case '!':
2322 op_alt[j].reject += 600;
2323 break;
2324 case '&':
2325 op_alt[j].earlyclobber = 1;
2326 break;
2328 case '0': case '1': case '2': case '3': case '4':
2329 case '5': case '6': case '7': case '8': case '9':
2331 char *end;
2332 op_alt[j].matches = strtoul (p, &end, 10);
2333 recog_op_alt[op_alt[j].matches][j].matched = i;
2334 p = end;
2336 continue;
2338 case TARGET_MEM_CONSTRAINT:
2339 op_alt[j].memory_ok = 1;
2340 break;
2341 case '<':
2342 op_alt[j].decmem_ok = 1;
2343 break;
2344 case '>':
2345 op_alt[j].incmem_ok = 1;
2346 break;
2347 case 'V':
2348 op_alt[j].nonoffmem_ok = 1;
2349 break;
2350 case 'o':
2351 op_alt[j].offmem_ok = 1;
2352 break;
2353 case 'X':
2354 op_alt[j].anything_ok = 1;
2355 break;
2357 case 'p':
2358 op_alt[j].is_address = 1;
2359 op_alt[j].cl = reg_class_subunion[(int) op_alt[j].cl]
2360 [(int) base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
2361 ADDRESS, SCRATCH)];
2362 break;
2364 case 'g':
2365 case 'r':
2366 op_alt[j].cl =
2367 reg_class_subunion[(int) op_alt[j].cl][(int) GENERAL_REGS];
2368 break;
2370 default:
2371 if (EXTRA_MEMORY_CONSTRAINT (c, p))
2373 op_alt[j].memory_ok = 1;
2374 break;
2376 if (EXTRA_ADDRESS_CONSTRAINT (c, p))
2378 op_alt[j].is_address = 1;
2379 op_alt[j].cl
2380 = (reg_class_subunion
2381 [(int) op_alt[j].cl]
2382 [(int) base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
2383 ADDRESS, SCRATCH)]);
2384 break;
2387 op_alt[j].cl
2388 = (reg_class_subunion
2389 [(int) op_alt[j].cl]
2390 [(int) REG_CLASS_FROM_CONSTRAINT ((unsigned char) c, p)]);
2391 break;
2393 p += CONSTRAINT_LEN (c, p);
2399 /* Check the operands of an insn against the insn's operand constraints
2400 and return 1 if they are valid.
2401 The information about the insn's operands, constraints, operand modes
2402 etc. is obtained from the global variables set up by extract_insn.
2404 WHICH_ALTERNATIVE is set to a number which indicates which
2405 alternative of constraints was matched: 0 for the first alternative,
2406 1 for the next, etc.
2408 In addition, when two operands are required to match
2409 and it happens that the output operand is (reg) while the
2410 input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
2411 make the output operand look like the input.
2412 This is because the output operand is the one the template will print.
2414 This is used in final, just before printing the assembler code and by
2415 the routines that determine an insn's attribute.
2417 If STRICT is a positive nonzero value, it means that we have been
2418 called after reload has been completed. In that case, we must
2419 do all checks strictly. If it is zero, it means that we have been called
2420 before reload has completed. In that case, we first try to see if we can
2421 find an alternative that matches strictly. If not, we try again, this
2422 time assuming that reload will fix up the insn. This provides a "best
2423 guess" for the alternative and is used to compute attributes of insns prior
2424 to reload. A negative value of STRICT is used for this internal call. */
2426 struct funny_match
2428 int this_op, other;
2432 constrain_operands (int strict)
2434 const char *constraints[MAX_RECOG_OPERANDS];
2435 int matching_operands[MAX_RECOG_OPERANDS];
2436 int earlyclobber[MAX_RECOG_OPERANDS];
2437 int c;
2439 struct funny_match funny_match[MAX_RECOG_OPERANDS];
2440 int funny_match_index;
2442 which_alternative = 0;
2443 if (recog_data.n_operands == 0 || recog_data.n_alternatives == 0)
2444 return 1;
2446 for (c = 0; c < recog_data.n_operands; c++)
2448 constraints[c] = recog_data.constraints[c];
2449 matching_operands[c] = -1;
2454 int seen_earlyclobber_at = -1;
2455 int opno;
2456 int lose = 0;
2457 funny_match_index = 0;
2459 if (!recog_data.alternative_enabled_p[which_alternative])
2461 int i;
2463 for (i = 0; i < recog_data.n_operands; i++)
2464 constraints[i] = skip_alternative (constraints[i]);
2466 which_alternative++;
2467 continue;
2470 for (opno = 0; opno < recog_data.n_operands; opno++)
2472 rtx op = recog_data.operand[opno];
2473 enum machine_mode mode = GET_MODE (op);
2474 const char *p = constraints[opno];
2475 int offset = 0;
2476 int win = 0;
2477 int val;
2478 int len;
2480 earlyclobber[opno] = 0;
2482 /* A unary operator may be accepted by the predicate, but it
2483 is irrelevant for matching constraints. */
2484 if (UNARY_P (op))
2485 op = XEXP (op, 0);
2487 if (GET_CODE (op) == SUBREG)
2489 if (REG_P (SUBREG_REG (op))
2490 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
2491 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
2492 GET_MODE (SUBREG_REG (op)),
2493 SUBREG_BYTE (op),
2494 GET_MODE (op));
2495 op = SUBREG_REG (op);
2498 /* An empty constraint or empty alternative
2499 allows anything which matched the pattern. */
2500 if (*p == 0 || *p == ',')
2501 win = 1;
2504 switch (c = *p, len = CONSTRAINT_LEN (c, p), c)
2506 case '\0':
2507 len = 0;
2508 break;
2509 case ',':
2510 c = '\0';
2511 break;
2513 case '?': case '!': case '*': case '%':
2514 case '=': case '+':
2515 break;
2517 case '#':
2518 /* Ignore rest of this alternative as far as
2519 constraint checking is concerned. */
2521 p++;
2522 while (*p && *p != ',');
2523 len = 0;
2524 break;
2526 case '&':
2527 earlyclobber[opno] = 1;
2528 if (seen_earlyclobber_at < 0)
2529 seen_earlyclobber_at = opno;
2530 break;
2532 case '0': case '1': case '2': case '3': case '4':
2533 case '5': case '6': case '7': case '8': case '9':
2535 /* This operand must be the same as a previous one.
2536 This kind of constraint is used for instructions such
2537 as add when they take only two operands.
2539 Note that the lower-numbered operand is passed first.
2541 If we are not testing strictly, assume that this
2542 constraint will be satisfied. */
2544 char *end;
2545 int match;
2547 match = strtoul (p, &end, 10);
2548 p = end;
2550 if (strict < 0)
2551 val = 1;
2552 else
2554 rtx op1 = recog_data.operand[match];
2555 rtx op2 = recog_data.operand[opno];
2557 /* A unary operator may be accepted by the predicate,
2558 but it is irrelevant for matching constraints. */
2559 if (UNARY_P (op1))
2560 op1 = XEXP (op1, 0);
2561 if (UNARY_P (op2))
2562 op2 = XEXP (op2, 0);
2564 val = operands_match_p (op1, op2);
2567 matching_operands[opno] = match;
2568 matching_operands[match] = opno;
2570 if (val != 0)
2571 win = 1;
2573 /* If output is *x and input is *--x, arrange later
2574 to change the output to *--x as well, since the
2575 output op is the one that will be printed. */
2576 if (val == 2 && strict > 0)
2578 funny_match[funny_match_index].this_op = opno;
2579 funny_match[funny_match_index++].other = match;
2582 len = 0;
2583 break;
2585 case 'p':
2586 /* p is used for address_operands. When we are called by
2587 gen_reload, no one will have checked that the address is
2588 strictly valid, i.e., that all pseudos requiring hard regs
2589 have gotten them. */
2590 if (strict <= 0
2591 || (strict_memory_address_p (recog_data.operand_mode[opno],
2592 op)))
2593 win = 1;
2594 break;
2596 /* No need to check general_operand again;
2597 it was done in insn-recog.c. Well, except that reload
2598 doesn't check the validity of its replacements, but
2599 that should only matter when there's a bug. */
2600 case 'g':
2601 /* Anything goes unless it is a REG and really has a hard reg
2602 but the hard reg is not in the class GENERAL_REGS. */
2603 if (REG_P (op))
2605 if (strict < 0
2606 || GENERAL_REGS == ALL_REGS
2607 || (reload_in_progress
2608 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2609 || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
2610 win = 1;
2612 else if (strict < 0 || general_operand (op, mode))
2613 win = 1;
2614 break;
2616 case 'X':
2617 /* This is used for a MATCH_SCRATCH in the cases when
2618 we don't actually need anything. So anything goes
2619 any time. */
2620 win = 1;
2621 break;
2623 case TARGET_MEM_CONSTRAINT:
2624 /* Memory operands must be valid, to the extent
2625 required by STRICT. */
2626 if (MEM_P (op))
2628 if (strict > 0
2629 && !strict_memory_address_addr_space_p
2630 (GET_MODE (op), XEXP (op, 0),
2631 MEM_ADDR_SPACE (op)))
2632 break;
2633 if (strict == 0
2634 && !memory_address_addr_space_p
2635 (GET_MODE (op), XEXP (op, 0),
2636 MEM_ADDR_SPACE (op)))
2637 break;
2638 win = 1;
2640 /* Before reload, accept what reload can turn into mem. */
2641 else if (strict < 0 && CONSTANT_P (op))
2642 win = 1;
2643 /* During reload, accept a pseudo */
2644 else if (reload_in_progress && REG_P (op)
2645 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2646 win = 1;
2647 break;
2649 case '<':
2650 if (MEM_P (op)
2651 && (GET_CODE (XEXP (op, 0)) == PRE_DEC
2652 || GET_CODE (XEXP (op, 0)) == POST_DEC))
2653 win = 1;
2654 break;
2656 case '>':
2657 if (MEM_P (op)
2658 && (GET_CODE (XEXP (op, 0)) == PRE_INC
2659 || GET_CODE (XEXP (op, 0)) == POST_INC))
2660 win = 1;
2661 break;
2663 case 'E':
2664 case 'F':
2665 if (CONST_DOUBLE_AS_FLOAT_P (op)
2666 || (GET_CODE (op) == CONST_VECTOR
2667 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
2668 win = 1;
2669 break;
2671 case 'G':
2672 case 'H':
2673 if (CONST_DOUBLE_AS_FLOAT_P (op)
2674 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, p))
2675 win = 1;
2676 break;
2678 case 's':
2679 if (CONST_SCALAR_INT_P (op))
2680 break;
2681 case 'i':
2682 if (CONSTANT_P (op))
2683 win = 1;
2684 break;
2686 case 'n':
2687 if (CONST_SCALAR_INT_P (op))
2688 win = 1;
2689 break;
2691 case 'I':
2692 case 'J':
2693 case 'K':
2694 case 'L':
2695 case 'M':
2696 case 'N':
2697 case 'O':
2698 case 'P':
2699 if (CONST_INT_P (op)
2700 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, p))
2701 win = 1;
2702 break;
2704 case 'V':
2705 if (MEM_P (op)
2706 && ((strict > 0 && ! offsettable_memref_p (op))
2707 || (strict < 0
2708 && !(CONSTANT_P (op) || MEM_P (op)))
2709 || (reload_in_progress
2710 && !(REG_P (op)
2711 && REGNO (op) >= FIRST_PSEUDO_REGISTER))))
2712 win = 1;
2713 break;
2715 case 'o':
2716 if ((strict > 0 && offsettable_memref_p (op))
2717 || (strict == 0 && offsettable_nonstrict_memref_p (op))
2718 /* Before reload, accept what reload can handle. */
2719 || (strict < 0
2720 && (CONSTANT_P (op) || MEM_P (op)))
2721 /* During reload, accept a pseudo */
2722 || (reload_in_progress && REG_P (op)
2723 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2724 win = 1;
2725 break;
2727 default:
2729 enum reg_class cl;
2731 cl = (c == 'r'
2732 ? GENERAL_REGS : REG_CLASS_FROM_CONSTRAINT (c, p));
2733 if (cl != NO_REGS)
2735 if (strict < 0
2736 || (strict == 0
2737 && REG_P (op)
2738 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2739 || (strict == 0 && GET_CODE (op) == SCRATCH)
2740 || (REG_P (op)
2741 && reg_fits_class_p (op, cl, offset, mode)))
2742 win = 1;
2744 #ifdef EXTRA_CONSTRAINT_STR
2745 else if (EXTRA_CONSTRAINT_STR (op, c, p))
2746 win = 1;
2748 else if (EXTRA_MEMORY_CONSTRAINT (c, p)
2749 /* Every memory operand can be reloaded to fit. */
2750 && ((strict < 0 && MEM_P (op))
2751 /* Before reload, accept what reload can turn
2752 into mem. */
2753 || (strict < 0 && CONSTANT_P (op))
2754 /* During reload, accept a pseudo */
2755 || (reload_in_progress && REG_P (op)
2756 && REGNO (op) >= FIRST_PSEUDO_REGISTER)))
2757 win = 1;
2758 else if (EXTRA_ADDRESS_CONSTRAINT (c, p)
2759 /* Every address operand can be reloaded to fit. */
2760 && strict < 0)
2761 win = 1;
2762 /* Cater to architectures like IA-64 that define extra memory
2763 constraints without using define_memory_constraint. */
2764 else if (reload_in_progress
2765 && REG_P (op)
2766 && REGNO (op) >= FIRST_PSEUDO_REGISTER
2767 && reg_renumber[REGNO (op)] < 0
2768 && reg_equiv_mem (REGNO (op)) != 0
2769 && EXTRA_CONSTRAINT_STR
2770 (reg_equiv_mem (REGNO (op)), c, p))
2771 win = 1;
2772 #endif
2773 break;
2776 while (p += len, c);
2778 constraints[opno] = p;
2779 /* If this operand did not win somehow,
2780 this alternative loses. */
2781 if (! win)
2782 lose = 1;
2784 /* This alternative won; the operands are ok.
2785 Change whichever operands this alternative says to change. */
2786 if (! lose)
2788 int opno, eopno;
2790 /* See if any earlyclobber operand conflicts with some other
2791 operand. */
2793 if (strict > 0 && seen_earlyclobber_at >= 0)
2794 for (eopno = seen_earlyclobber_at;
2795 eopno < recog_data.n_operands;
2796 eopno++)
2797 /* Ignore earlyclobber operands now in memory,
2798 because we would often report failure when we have
2799 two memory operands, one of which was formerly a REG. */
2800 if (earlyclobber[eopno]
2801 && REG_P (recog_data.operand[eopno]))
2802 for (opno = 0; opno < recog_data.n_operands; opno++)
2803 if ((MEM_P (recog_data.operand[opno])
2804 || recog_data.operand_type[opno] != OP_OUT)
2805 && opno != eopno
2806 /* Ignore things like match_operator operands. */
2807 && *recog_data.constraints[opno] != 0
2808 && ! (matching_operands[opno] == eopno
2809 && operands_match_p (recog_data.operand[opno],
2810 recog_data.operand[eopno]))
2811 && ! safe_from_earlyclobber (recog_data.operand[opno],
2812 recog_data.operand[eopno]))
2813 lose = 1;
2815 if (! lose)
2817 while (--funny_match_index >= 0)
2819 recog_data.operand[funny_match[funny_match_index].other]
2820 = recog_data.operand[funny_match[funny_match_index].this_op];
2823 #ifdef AUTO_INC_DEC
2824 /* For operands without < or > constraints reject side-effects. */
2825 if (recog_data.is_asm)
2827 for (opno = 0; opno < recog_data.n_operands; opno++)
2828 if (MEM_P (recog_data.operand[opno]))
2829 switch (GET_CODE (XEXP (recog_data.operand[opno], 0)))
2831 case PRE_INC:
2832 case POST_INC:
2833 case PRE_DEC:
2834 case POST_DEC:
2835 case PRE_MODIFY:
2836 case POST_MODIFY:
2837 if (strchr (recog_data.constraints[opno], '<') == NULL
2838 && strchr (recog_data.constraints[opno], '>')
2839 == NULL)
2840 return 0;
2841 break;
2842 default:
2843 break;
2846 #endif
2847 return 1;
2851 which_alternative++;
2853 while (which_alternative < recog_data.n_alternatives);
2855 which_alternative = -1;
2856 /* If we are about to reject this, but we are not to test strictly,
2857 try a very loose test. Only return failure if it fails also. */
2858 if (strict == 0)
2859 return constrain_operands (-1);
2860 else
2861 return 0;
2864 /* Return true iff OPERAND (assumed to be a REG rtx)
2865 is a hard reg in class CLASS when its regno is offset by OFFSET
2866 and changed to mode MODE.
2867 If REG occupies multiple hard regs, all of them must be in CLASS. */
2869 bool
2870 reg_fits_class_p (const_rtx operand, reg_class_t cl, int offset,
2871 enum machine_mode mode)
2873 unsigned int regno = REGNO (operand);
2875 if (cl == NO_REGS)
2876 return false;
2878 /* Regno must not be a pseudo register. Offset may be negative. */
2879 return (HARD_REGISTER_NUM_P (regno)
2880 && HARD_REGISTER_NUM_P (regno + offset)
2881 && in_hard_reg_set_p (reg_class_contents[(int) cl], mode,
2882 regno + offset));
2885 /* Split single instruction. Helper function for split_all_insns and
2886 split_all_insns_noflow. Return last insn in the sequence if successful,
2887 or NULL if unsuccessful. */
2889 static rtx
2890 split_insn (rtx insn)
2892 /* Split insns here to get max fine-grain parallelism. */
2893 rtx first = PREV_INSN (insn);
2894 rtx last = try_split (PATTERN (insn), insn, 1);
2895 rtx insn_set, last_set, note;
2897 if (last == insn)
2898 return NULL_RTX;
2900 /* If the original instruction was a single set that was known to be
2901 equivalent to a constant, see if we can say the same about the last
2902 instruction in the split sequence. The two instructions must set
2903 the same destination. */
2904 insn_set = single_set (insn);
2905 if (insn_set)
2907 last_set = single_set (last);
2908 if (last_set && rtx_equal_p (SET_DEST (last_set), SET_DEST (insn_set)))
2910 note = find_reg_equal_equiv_note (insn);
2911 if (note && CONSTANT_P (XEXP (note, 0)))
2912 set_unique_reg_note (last, REG_EQUAL, XEXP (note, 0));
2913 else if (CONSTANT_P (SET_SRC (insn_set)))
2914 set_unique_reg_note (last, REG_EQUAL,
2915 copy_rtx (SET_SRC (insn_set)));
2919 /* try_split returns the NOTE that INSN became. */
2920 SET_INSN_DELETED (insn);
2922 /* ??? Coddle to md files that generate subregs in post-reload
2923 splitters instead of computing the proper hard register. */
2924 if (reload_completed && first != last)
2926 first = NEXT_INSN (first);
2927 for (;;)
2929 if (INSN_P (first))
2930 cleanup_subreg_operands (first);
2931 if (first == last)
2932 break;
2933 first = NEXT_INSN (first);
2937 return last;
2940 /* Split all insns in the function. If UPD_LIFE, update life info after. */
2942 void
2943 split_all_insns (void)
2945 sbitmap blocks;
2946 bool changed;
2947 basic_block bb;
2949 blocks = sbitmap_alloc (last_basic_block_for_fn (cfun));
2950 bitmap_clear (blocks);
2951 changed = false;
2953 FOR_EACH_BB_REVERSE_FN (bb, cfun)
2955 rtx insn, next;
2956 bool finish = false;
2958 rtl_profile_for_bb (bb);
2959 for (insn = BB_HEAD (bb); !finish ; insn = next)
2961 /* Can't use `next_real_insn' because that might go across
2962 CODE_LABELS and short-out basic blocks. */
2963 next = NEXT_INSN (insn);
2964 finish = (insn == BB_END (bb));
2965 if (INSN_P (insn))
2967 rtx set = single_set (insn);
2969 /* Don't split no-op move insns. These should silently
2970 disappear later in final. Splitting such insns would
2971 break the code that handles LIBCALL blocks. */
2972 if (set && set_noop_p (set))
2974 /* Nops get in the way while scheduling, so delete them
2975 now if register allocation has already been done. It
2976 is too risky to try to do this before register
2977 allocation, and there are unlikely to be very many
2978 nops then anyways. */
2979 if (reload_completed)
2980 delete_insn_and_edges (insn);
2982 else
2984 if (split_insn (insn))
2986 bitmap_set_bit (blocks, bb->index);
2987 changed = true;
2994 default_rtl_profile ();
2995 if (changed)
2996 find_many_sub_basic_blocks (blocks);
2998 #ifdef ENABLE_CHECKING
2999 verify_flow_info ();
3000 #endif
3002 sbitmap_free (blocks);
3005 /* Same as split_all_insns, but do not expect CFG to be available.
3006 Used by machine dependent reorg passes. */
3008 unsigned int
3009 split_all_insns_noflow (void)
3011 rtx next, insn;
3013 for (insn = get_insns (); insn; insn = next)
3015 next = NEXT_INSN (insn);
3016 if (INSN_P (insn))
3018 /* Don't split no-op move insns. These should silently
3019 disappear later in final. Splitting such insns would
3020 break the code that handles LIBCALL blocks. */
3021 rtx set = single_set (insn);
3022 if (set && set_noop_p (set))
3024 /* Nops get in the way while scheduling, so delete them
3025 now if register allocation has already been done. It
3026 is too risky to try to do this before register
3027 allocation, and there are unlikely to be very many
3028 nops then anyways.
3030 ??? Should we use delete_insn when the CFG isn't valid? */
3031 if (reload_completed)
3032 delete_insn_and_edges (insn);
3034 else
3035 split_insn (insn);
3038 return 0;
3041 #ifdef HAVE_peephole2
3042 struct peep2_insn_data
3044 rtx insn;
3045 regset live_before;
3048 static struct peep2_insn_data peep2_insn_data[MAX_INSNS_PER_PEEP2 + 1];
3049 static int peep2_current;
3051 static bool peep2_do_rebuild_jump_labels;
3052 static bool peep2_do_cleanup_cfg;
3054 /* The number of instructions available to match a peep2. */
3055 int peep2_current_count;
3057 /* A non-insn marker indicating the last insn of the block.
3058 The live_before regset for this element is correct, indicating
3059 DF_LIVE_OUT for the block. */
3060 #define PEEP2_EOB pc_rtx
3062 /* Wrap N to fit into the peep2_insn_data buffer. */
3064 static int
3065 peep2_buf_position (int n)
3067 if (n >= MAX_INSNS_PER_PEEP2 + 1)
3068 n -= MAX_INSNS_PER_PEEP2 + 1;
3069 return n;
3072 /* Return the Nth non-note insn after `current', or return NULL_RTX if it
3073 does not exist. Used by the recognizer to find the next insn to match
3074 in a multi-insn pattern. */
3077 peep2_next_insn (int n)
3079 gcc_assert (n <= peep2_current_count);
3081 n = peep2_buf_position (peep2_current + n);
3083 return peep2_insn_data[n].insn;
3086 /* Return true if REGNO is dead before the Nth non-note insn
3087 after `current'. */
3090 peep2_regno_dead_p (int ofs, int regno)
3092 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3094 ofs = peep2_buf_position (peep2_current + ofs);
3096 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3098 return ! REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno);
3101 /* Similarly for a REG. */
3104 peep2_reg_dead_p (int ofs, rtx reg)
3106 int regno, n;
3108 gcc_assert (ofs < MAX_INSNS_PER_PEEP2 + 1);
3110 ofs = peep2_buf_position (peep2_current + ofs);
3112 gcc_assert (peep2_insn_data[ofs].insn != NULL_RTX);
3114 regno = REGNO (reg);
3115 n = hard_regno_nregs[regno][GET_MODE (reg)];
3116 while (--n >= 0)
3117 if (REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno + n))
3118 return 0;
3119 return 1;
3122 /* Regno offset to be used in the register search. */
3123 static int search_ofs;
3125 /* Try to find a hard register of mode MODE, matching the register class in
3126 CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
3127 remains available until the end of LAST_INSN. LAST_INSN may be NULL_RTX,
3128 in which case the only condition is that the register must be available
3129 before CURRENT_INSN.
3130 Registers that already have bits set in REG_SET will not be considered.
3132 If an appropriate register is available, it will be returned and the
3133 corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
3134 returned. */
3137 peep2_find_free_register (int from, int to, const char *class_str,
3138 enum machine_mode mode, HARD_REG_SET *reg_set)
3140 enum reg_class cl;
3141 HARD_REG_SET live;
3142 df_ref *def_rec;
3143 int i;
3145 gcc_assert (from < MAX_INSNS_PER_PEEP2 + 1);
3146 gcc_assert (to < MAX_INSNS_PER_PEEP2 + 1);
3148 from = peep2_buf_position (peep2_current + from);
3149 to = peep2_buf_position (peep2_current + to);
3151 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3152 REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before);
3154 while (from != to)
3156 gcc_assert (peep2_insn_data[from].insn != NULL_RTX);
3158 /* Don't use registers set or clobbered by the insn. */
3159 for (def_rec = DF_INSN_DEFS (peep2_insn_data[from].insn);
3160 *def_rec; def_rec++)
3161 SET_HARD_REG_BIT (live, DF_REF_REGNO (*def_rec));
3163 from = peep2_buf_position (from + 1);
3166 cl = (class_str[0] == 'r' ? GENERAL_REGS
3167 : REG_CLASS_FROM_CONSTRAINT (class_str[0], class_str));
3169 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3171 int raw_regno, regno, success, j;
3173 /* Distribute the free registers as much as possible. */
3174 raw_regno = search_ofs + i;
3175 if (raw_regno >= FIRST_PSEUDO_REGISTER)
3176 raw_regno -= FIRST_PSEUDO_REGISTER;
3177 #ifdef REG_ALLOC_ORDER
3178 regno = reg_alloc_order[raw_regno];
3179 #else
3180 regno = raw_regno;
3181 #endif
3183 /* Can it support the mode we need? */
3184 if (! HARD_REGNO_MODE_OK (regno, mode))
3185 continue;
3187 success = 1;
3188 for (j = 0; success && j < hard_regno_nregs[regno][mode]; j++)
3190 /* Don't allocate fixed registers. */
3191 if (fixed_regs[regno + j])
3193 success = 0;
3194 break;
3196 /* Don't allocate global registers. */
3197 if (global_regs[regno + j])
3199 success = 0;
3200 break;
3202 /* Make sure the register is of the right class. */
3203 if (! TEST_HARD_REG_BIT (reg_class_contents[cl], regno + j))
3205 success = 0;
3206 break;
3208 /* And that we don't create an extra save/restore. */
3209 if (! call_used_regs[regno + j] && ! df_regs_ever_live_p (regno + j))
3211 success = 0;
3212 break;
3215 if (! targetm.hard_regno_scratch_ok (regno + j))
3217 success = 0;
3218 break;
3221 /* And we don't clobber traceback for noreturn functions. */
3222 if ((regno + j == FRAME_POINTER_REGNUM
3223 || regno + j == HARD_FRAME_POINTER_REGNUM)
3224 && (! reload_completed || frame_pointer_needed))
3226 success = 0;
3227 break;
3230 if (TEST_HARD_REG_BIT (*reg_set, regno + j)
3231 || TEST_HARD_REG_BIT (live, regno + j))
3233 success = 0;
3234 break;
3238 if (success)
3240 add_to_hard_reg_set (reg_set, mode, regno);
3242 /* Start the next search with the next register. */
3243 if (++raw_regno >= FIRST_PSEUDO_REGISTER)
3244 raw_regno = 0;
3245 search_ofs = raw_regno;
3247 return gen_rtx_REG (mode, regno);
3251 search_ofs = 0;
3252 return NULL_RTX;
3255 /* Forget all currently tracked instructions, only remember current
3256 LIVE regset. */
3258 static void
3259 peep2_reinit_state (regset live)
3261 int i;
3263 /* Indicate that all slots except the last holds invalid data. */
3264 for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
3265 peep2_insn_data[i].insn = NULL_RTX;
3266 peep2_current_count = 0;
3268 /* Indicate that the last slot contains live_after data. */
3269 peep2_insn_data[MAX_INSNS_PER_PEEP2].insn = PEEP2_EOB;
3270 peep2_current = MAX_INSNS_PER_PEEP2;
3272 COPY_REG_SET (peep2_insn_data[MAX_INSNS_PER_PEEP2].live_before, live);
3275 /* While scanning basic block BB, we found a match of length MATCH_LEN,
3276 starting at INSN. Perform the replacement, removing the old insns and
3277 replacing them with ATTEMPT. Returns the last insn emitted, or NULL
3278 if the replacement is rejected. */
3280 static rtx
3281 peep2_attempt (basic_block bb, rtx insn, int match_len, rtx attempt)
3283 int i;
3284 rtx last, eh_note, as_note, before_try, x;
3285 rtx old_insn, new_insn;
3286 bool was_call = false;
3288 /* If we are splitting an RTX_FRAME_RELATED_P insn, do not allow it to
3289 match more than one insn, or to be split into more than one insn. */
3290 old_insn = peep2_insn_data[peep2_current].insn;
3291 if (RTX_FRAME_RELATED_P (old_insn))
3293 bool any_note = false;
3294 rtx note;
3296 if (match_len != 0)
3297 return NULL;
3299 /* Look for one "active" insn. I.e. ignore any "clobber" insns that
3300 may be in the stream for the purpose of register allocation. */
3301 if (active_insn_p (attempt))
3302 new_insn = attempt;
3303 else
3304 new_insn = next_active_insn (attempt);
3305 if (next_active_insn (new_insn))
3306 return NULL;
3308 /* We have a 1-1 replacement. Copy over any frame-related info. */
3309 RTX_FRAME_RELATED_P (new_insn) = 1;
3311 /* Allow the backend to fill in a note during the split. */
3312 for (note = REG_NOTES (new_insn); note ; note = XEXP (note, 1))
3313 switch (REG_NOTE_KIND (note))
3315 case REG_FRAME_RELATED_EXPR:
3316 case REG_CFA_DEF_CFA:
3317 case REG_CFA_ADJUST_CFA:
3318 case REG_CFA_OFFSET:
3319 case REG_CFA_REGISTER:
3320 case REG_CFA_EXPRESSION:
3321 case REG_CFA_RESTORE:
3322 case REG_CFA_SET_VDRAP:
3323 any_note = true;
3324 break;
3325 default:
3326 break;
3329 /* If the backend didn't supply a note, copy one over. */
3330 if (!any_note)
3331 for (note = REG_NOTES (old_insn); note ; note = XEXP (note, 1))
3332 switch (REG_NOTE_KIND (note))
3334 case REG_FRAME_RELATED_EXPR:
3335 case REG_CFA_DEF_CFA:
3336 case REG_CFA_ADJUST_CFA:
3337 case REG_CFA_OFFSET:
3338 case REG_CFA_REGISTER:
3339 case REG_CFA_EXPRESSION:
3340 case REG_CFA_RESTORE:
3341 case REG_CFA_SET_VDRAP:
3342 add_reg_note (new_insn, REG_NOTE_KIND (note), XEXP (note, 0));
3343 any_note = true;
3344 break;
3345 default:
3346 break;
3349 /* If there still isn't a note, make sure the unwind info sees the
3350 same expression as before the split. */
3351 if (!any_note)
3353 rtx old_set, new_set;
3355 /* The old insn had better have been simple, or annotated. */
3356 old_set = single_set (old_insn);
3357 gcc_assert (old_set != NULL);
3359 new_set = single_set (new_insn);
3360 if (!new_set || !rtx_equal_p (new_set, old_set))
3361 add_reg_note (new_insn, REG_FRAME_RELATED_EXPR, old_set);
3364 /* Copy prologue/epilogue status. This is required in order to keep
3365 proper placement of EPILOGUE_BEG and the DW_CFA_remember_state. */
3366 maybe_copy_prologue_epilogue_insn (old_insn, new_insn);
3369 /* If we are splitting a CALL_INSN, look for the CALL_INSN
3370 in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other
3371 cfg-related call notes. */
3372 for (i = 0; i <= match_len; ++i)
3374 int j;
3375 rtx note;
3377 j = peep2_buf_position (peep2_current + i);
3378 old_insn = peep2_insn_data[j].insn;
3379 if (!CALL_P (old_insn))
3380 continue;
3381 was_call = true;
3383 new_insn = attempt;
3384 while (new_insn != NULL_RTX)
3386 if (CALL_P (new_insn))
3387 break;
3388 new_insn = NEXT_INSN (new_insn);
3391 gcc_assert (new_insn != NULL_RTX);
3393 CALL_INSN_FUNCTION_USAGE (new_insn)
3394 = CALL_INSN_FUNCTION_USAGE (old_insn);
3396 for (note = REG_NOTES (old_insn);
3397 note;
3398 note = XEXP (note, 1))
3399 switch (REG_NOTE_KIND (note))
3401 case REG_NORETURN:
3402 case REG_SETJMP:
3403 case REG_TM:
3404 add_reg_note (new_insn, REG_NOTE_KIND (note),
3405 XEXP (note, 0));
3406 break;
3407 default:
3408 /* Discard all other reg notes. */
3409 break;
3412 /* Croak if there is another call in the sequence. */
3413 while (++i <= match_len)
3415 j = peep2_buf_position (peep2_current + i);
3416 old_insn = peep2_insn_data[j].insn;
3417 gcc_assert (!CALL_P (old_insn));
3419 break;
3422 /* If we matched any instruction that had a REG_ARGS_SIZE, then
3423 move those notes over to the new sequence. */
3424 as_note = NULL;
3425 for (i = match_len; i >= 0; --i)
3427 int j = peep2_buf_position (peep2_current + i);
3428 old_insn = peep2_insn_data[j].insn;
3430 as_note = find_reg_note (old_insn, REG_ARGS_SIZE, NULL);
3431 if (as_note)
3432 break;
3435 i = peep2_buf_position (peep2_current + match_len);
3436 eh_note = find_reg_note (peep2_insn_data[i].insn, REG_EH_REGION, NULL_RTX);
3438 /* Replace the old sequence with the new. */
3439 last = emit_insn_after_setloc (attempt,
3440 peep2_insn_data[i].insn,
3441 INSN_LOCATION (peep2_insn_data[i].insn));
3442 before_try = PREV_INSN (insn);
3443 delete_insn_chain (insn, peep2_insn_data[i].insn, false);
3445 /* Re-insert the EH_REGION notes. */
3446 if (eh_note || (was_call && nonlocal_goto_handler_labels))
3448 edge eh_edge;
3449 edge_iterator ei;
3451 FOR_EACH_EDGE (eh_edge, ei, bb->succs)
3452 if (eh_edge->flags & (EDGE_EH | EDGE_ABNORMAL_CALL))
3453 break;
3455 if (eh_note)
3456 copy_reg_eh_region_note_backward (eh_note, last, before_try);
3458 if (eh_edge)
3459 for (x = last; x != before_try; x = PREV_INSN (x))
3460 if (x != BB_END (bb)
3461 && (can_throw_internal (x)
3462 || can_nonlocal_goto (x)))
3464 edge nfte, nehe;
3465 int flags;
3467 nfte = split_block (bb, x);
3468 flags = (eh_edge->flags
3469 & (EDGE_EH | EDGE_ABNORMAL));
3470 if (CALL_P (x))
3471 flags |= EDGE_ABNORMAL_CALL;
3472 nehe = make_edge (nfte->src, eh_edge->dest,
3473 flags);
3475 nehe->probability = eh_edge->probability;
3476 nfte->probability
3477 = REG_BR_PROB_BASE - nehe->probability;
3479 peep2_do_cleanup_cfg |= purge_dead_edges (nfte->dest);
3480 bb = nfte->src;
3481 eh_edge = nehe;
3484 /* Converting possibly trapping insn to non-trapping is
3485 possible. Zap dummy outgoing edges. */
3486 peep2_do_cleanup_cfg |= purge_dead_edges (bb);
3489 /* Re-insert the ARGS_SIZE notes. */
3490 if (as_note)
3491 fixup_args_size_notes (before_try, last, INTVAL (XEXP (as_note, 0)));
3493 /* If we generated a jump instruction, it won't have
3494 JUMP_LABEL set. Recompute after we're done. */
3495 for (x = last; x != before_try; x = PREV_INSN (x))
3496 if (JUMP_P (x))
3498 peep2_do_rebuild_jump_labels = true;
3499 break;
3502 return last;
3505 /* After performing a replacement in basic block BB, fix up the life
3506 information in our buffer. LAST is the last of the insns that we
3507 emitted as a replacement. PREV is the insn before the start of
3508 the replacement. MATCH_LEN is the number of instructions that were
3509 matched, and which now need to be replaced in the buffer. */
3511 static void
3512 peep2_update_life (basic_block bb, int match_len, rtx last, rtx prev)
3514 int i = peep2_buf_position (peep2_current + match_len + 1);
3515 rtx x;
3516 regset_head live;
3518 INIT_REG_SET (&live);
3519 COPY_REG_SET (&live, peep2_insn_data[i].live_before);
3521 gcc_assert (peep2_current_count >= match_len + 1);
3522 peep2_current_count -= match_len + 1;
3524 x = last;
3527 if (INSN_P (x))
3529 df_insn_rescan (x);
3530 if (peep2_current_count < MAX_INSNS_PER_PEEP2)
3532 peep2_current_count++;
3533 if (--i < 0)
3534 i = MAX_INSNS_PER_PEEP2;
3535 peep2_insn_data[i].insn = x;
3536 df_simulate_one_insn_backwards (bb, x, &live);
3537 COPY_REG_SET (peep2_insn_data[i].live_before, &live);
3540 x = PREV_INSN (x);
3542 while (x != prev);
3543 CLEAR_REG_SET (&live);
3545 peep2_current = i;
3548 /* Add INSN, which is in BB, at the end of the peep2 insn buffer if possible.
3549 Return true if we added it, false otherwise. The caller will try to match
3550 peepholes against the buffer if we return false; otherwise it will try to
3551 add more instructions to the buffer. */
3553 static bool
3554 peep2_fill_buffer (basic_block bb, rtx insn, regset live)
3556 int pos;
3558 /* Once we have filled the maximum number of insns the buffer can hold,
3559 allow the caller to match the insns against peepholes. We wait until
3560 the buffer is full in case the target has similar peepholes of different
3561 length; we always want to match the longest if possible. */
3562 if (peep2_current_count == MAX_INSNS_PER_PEEP2)
3563 return false;
3565 /* If an insn has RTX_FRAME_RELATED_P set, do not allow it to be matched with
3566 any other pattern, lest it change the semantics of the frame info. */
3567 if (RTX_FRAME_RELATED_P (insn))
3569 /* Let the buffer drain first. */
3570 if (peep2_current_count > 0)
3571 return false;
3572 /* Now the insn will be the only thing in the buffer. */
3575 pos = peep2_buf_position (peep2_current + peep2_current_count);
3576 peep2_insn_data[pos].insn = insn;
3577 COPY_REG_SET (peep2_insn_data[pos].live_before, live);
3578 peep2_current_count++;
3580 df_simulate_one_insn_forwards (bb, insn, live);
3581 return true;
3584 /* Perform the peephole2 optimization pass. */
3586 static void
3587 peephole2_optimize (void)
3589 rtx insn;
3590 bitmap live;
3591 int i;
3592 basic_block bb;
3594 peep2_do_cleanup_cfg = false;
3595 peep2_do_rebuild_jump_labels = false;
3597 df_set_flags (DF_LR_RUN_DCE);
3598 df_note_add_problem ();
3599 df_analyze ();
3601 /* Initialize the regsets we're going to use. */
3602 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3603 peep2_insn_data[i].live_before = BITMAP_ALLOC (&reg_obstack);
3604 search_ofs = 0;
3605 live = BITMAP_ALLOC (&reg_obstack);
3607 FOR_EACH_BB_REVERSE_FN (bb, cfun)
3609 bool past_end = false;
3610 int pos;
3612 rtl_profile_for_bb (bb);
3614 /* Start up propagation. */
3615 bitmap_copy (live, DF_LR_IN (bb));
3616 df_simulate_initialize_forwards (bb, live);
3617 peep2_reinit_state (live);
3619 insn = BB_HEAD (bb);
3620 for (;;)
3622 rtx attempt, head;
3623 int match_len;
3625 if (!past_end && !NONDEBUG_INSN_P (insn))
3627 next_insn:
3628 insn = NEXT_INSN (insn);
3629 if (insn == NEXT_INSN (BB_END (bb)))
3630 past_end = true;
3631 continue;
3633 if (!past_end && peep2_fill_buffer (bb, insn, live))
3634 goto next_insn;
3636 /* If we did not fill an empty buffer, it signals the end of the
3637 block. */
3638 if (peep2_current_count == 0)
3639 break;
3641 /* The buffer filled to the current maximum, so try to match. */
3643 pos = peep2_buf_position (peep2_current + peep2_current_count);
3644 peep2_insn_data[pos].insn = PEEP2_EOB;
3645 COPY_REG_SET (peep2_insn_data[pos].live_before, live);
3647 /* Match the peephole. */
3648 head = peep2_insn_data[peep2_current].insn;
3649 attempt = peephole2_insns (PATTERN (head), head, &match_len);
3650 if (attempt != NULL)
3652 rtx last = peep2_attempt (bb, head, match_len, attempt);
3653 if (last)
3655 peep2_update_life (bb, match_len, last, PREV_INSN (attempt));
3656 continue;
3660 /* No match: advance the buffer by one insn. */
3661 peep2_current = peep2_buf_position (peep2_current + 1);
3662 peep2_current_count--;
3666 default_rtl_profile ();
3667 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3668 BITMAP_FREE (peep2_insn_data[i].live_before);
3669 BITMAP_FREE (live);
3670 if (peep2_do_rebuild_jump_labels)
3671 rebuild_jump_labels (get_insns ());
3673 #endif /* HAVE_peephole2 */
3675 /* Common predicates for use with define_bypass. */
3677 /* True if the dependency between OUT_INSN and IN_INSN is on the store
3678 data not the address operand(s) of the store. IN_INSN and OUT_INSN
3679 must be either a single_set or a PARALLEL with SETs inside. */
3682 store_data_bypass_p (rtx out_insn, rtx in_insn)
3684 rtx out_set, in_set;
3685 rtx out_pat, in_pat;
3686 rtx out_exp, in_exp;
3687 int i, j;
3689 in_set = single_set (in_insn);
3690 if (in_set)
3692 if (!MEM_P (SET_DEST (in_set)))
3693 return false;
3695 out_set = single_set (out_insn);
3696 if (out_set)
3698 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_set)))
3699 return false;
3701 else
3703 out_pat = PATTERN (out_insn);
3705 if (GET_CODE (out_pat) != PARALLEL)
3706 return false;
3708 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3710 out_exp = XVECEXP (out_pat, 0, i);
3712 if (GET_CODE (out_exp) == CLOBBER)
3713 continue;
3715 gcc_assert (GET_CODE (out_exp) == SET);
3717 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_set)))
3718 return false;
3722 else
3724 in_pat = PATTERN (in_insn);
3725 gcc_assert (GET_CODE (in_pat) == PARALLEL);
3727 for (i = 0; i < XVECLEN (in_pat, 0); i++)
3729 in_exp = XVECEXP (in_pat, 0, i);
3731 if (GET_CODE (in_exp) == CLOBBER)
3732 continue;
3734 gcc_assert (GET_CODE (in_exp) == SET);
3736 if (!MEM_P (SET_DEST (in_exp)))
3737 return false;
3739 out_set = single_set (out_insn);
3740 if (out_set)
3742 if (reg_mentioned_p (SET_DEST (out_set), SET_DEST (in_exp)))
3743 return false;
3745 else
3747 out_pat = PATTERN (out_insn);
3748 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3750 for (j = 0; j < XVECLEN (out_pat, 0); j++)
3752 out_exp = XVECEXP (out_pat, 0, j);
3754 if (GET_CODE (out_exp) == CLOBBER)
3755 continue;
3757 gcc_assert (GET_CODE (out_exp) == SET);
3759 if (reg_mentioned_p (SET_DEST (out_exp), SET_DEST (in_exp)))
3760 return false;
3766 return true;
3769 /* True if the dependency between OUT_INSN and IN_INSN is in the IF_THEN_ELSE
3770 condition, and not the THEN or ELSE branch. OUT_INSN may be either a single
3771 or multiple set; IN_INSN should be single_set for truth, but for convenience
3772 of insn categorization may be any JUMP or CALL insn. */
3775 if_test_bypass_p (rtx out_insn, rtx in_insn)
3777 rtx out_set, in_set;
3779 in_set = single_set (in_insn);
3780 if (! in_set)
3782 gcc_assert (JUMP_P (in_insn) || CALL_P (in_insn));
3783 return false;
3786 if (GET_CODE (SET_SRC (in_set)) != IF_THEN_ELSE)
3787 return false;
3788 in_set = SET_SRC (in_set);
3790 out_set = single_set (out_insn);
3791 if (out_set)
3793 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3794 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3795 return false;
3797 else
3799 rtx out_pat;
3800 int i;
3802 out_pat = PATTERN (out_insn);
3803 gcc_assert (GET_CODE (out_pat) == PARALLEL);
3805 for (i = 0; i < XVECLEN (out_pat, 0); i++)
3807 rtx exp = XVECEXP (out_pat, 0, i);
3809 if (GET_CODE (exp) == CLOBBER)
3810 continue;
3812 gcc_assert (GET_CODE (exp) == SET);
3814 if (reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 1))
3815 || reg_mentioned_p (SET_DEST (out_set), XEXP (in_set, 2)))
3816 return false;
3820 return true;
3823 static bool
3824 gate_handle_peephole2 (void)
3826 return (optimize > 0 && flag_peephole2);
3829 static unsigned int
3830 rest_of_handle_peephole2 (void)
3832 #ifdef HAVE_peephole2
3833 peephole2_optimize ();
3834 #endif
3835 return 0;
3838 namespace {
3840 const pass_data pass_data_peephole2 =
3842 RTL_PASS, /* type */
3843 "peephole2", /* name */
3844 OPTGROUP_NONE, /* optinfo_flags */
3845 true, /* has_gate */
3846 true, /* has_execute */
3847 TV_PEEPHOLE2, /* tv_id */
3848 0, /* properties_required */
3849 0, /* properties_provided */
3850 0, /* properties_destroyed */
3851 0, /* todo_flags_start */
3852 ( TODO_df_finish | TODO_verify_rtl_sharing | 0 ), /* todo_flags_finish */
3855 class pass_peephole2 : public rtl_opt_pass
3857 public:
3858 pass_peephole2 (gcc::context *ctxt)
3859 : rtl_opt_pass (pass_data_peephole2, ctxt)
3862 /* opt_pass methods: */
3863 /* The epiphany backend creates a second instance of this pass, so we need
3864 a clone method. */
3865 opt_pass * clone () { return new pass_peephole2 (m_ctxt); }
3866 bool gate () { return gate_handle_peephole2 (); }
3867 unsigned int execute () { return rest_of_handle_peephole2 (); }
3869 }; // class pass_peephole2
3871 } // anon namespace
3873 rtl_opt_pass *
3874 make_pass_peephole2 (gcc::context *ctxt)
3876 return new pass_peephole2 (ctxt);
3879 static unsigned int
3880 rest_of_handle_split_all_insns (void)
3882 split_all_insns ();
3883 return 0;
3886 namespace {
3888 const pass_data pass_data_split_all_insns =
3890 RTL_PASS, /* type */
3891 "split1", /* name */
3892 OPTGROUP_NONE, /* optinfo_flags */
3893 false, /* has_gate */
3894 true, /* has_execute */
3895 TV_NONE, /* tv_id */
3896 0, /* properties_required */
3897 0, /* properties_provided */
3898 0, /* properties_destroyed */
3899 0, /* todo_flags_start */
3900 0, /* todo_flags_finish */
3903 class pass_split_all_insns : public rtl_opt_pass
3905 public:
3906 pass_split_all_insns (gcc::context *ctxt)
3907 : rtl_opt_pass (pass_data_split_all_insns, ctxt)
3910 /* opt_pass methods: */
3911 /* The epiphany backend creates a second instance of this pass, so
3912 we need a clone method. */
3913 opt_pass * clone () { return new pass_split_all_insns (m_ctxt); }
3914 unsigned int execute () { return rest_of_handle_split_all_insns (); }
3916 }; // class pass_split_all_insns
3918 } // anon namespace
3920 rtl_opt_pass *
3921 make_pass_split_all_insns (gcc::context *ctxt)
3923 return new pass_split_all_insns (ctxt);
3926 static unsigned int
3927 rest_of_handle_split_after_reload (void)
3929 /* If optimizing, then go ahead and split insns now. */
3930 #ifndef STACK_REGS
3931 if (optimize > 0)
3932 #endif
3933 split_all_insns ();
3934 return 0;
3937 namespace {
3939 const pass_data pass_data_split_after_reload =
3941 RTL_PASS, /* type */
3942 "split2", /* name */
3943 OPTGROUP_NONE, /* optinfo_flags */
3944 false, /* has_gate */
3945 true, /* has_execute */
3946 TV_NONE, /* tv_id */
3947 0, /* properties_required */
3948 0, /* properties_provided */
3949 0, /* properties_destroyed */
3950 0, /* todo_flags_start */
3951 0, /* todo_flags_finish */
3954 class pass_split_after_reload : public rtl_opt_pass
3956 public:
3957 pass_split_after_reload (gcc::context *ctxt)
3958 : rtl_opt_pass (pass_data_split_after_reload, ctxt)
3961 /* opt_pass methods: */
3962 unsigned int execute () { return rest_of_handle_split_after_reload (); }
3964 }; // class pass_split_after_reload
3966 } // anon namespace
3968 rtl_opt_pass *
3969 make_pass_split_after_reload (gcc::context *ctxt)
3971 return new pass_split_after_reload (ctxt);
3974 static bool
3975 gate_handle_split_before_regstack (void)
3977 #if HAVE_ATTR_length && defined (STACK_REGS)
3978 /* If flow2 creates new instructions which need splitting
3979 and scheduling after reload is not done, they might not be
3980 split until final which doesn't allow splitting
3981 if HAVE_ATTR_length. */
3982 # ifdef INSN_SCHEDULING
3983 return (optimize && !flag_schedule_insns_after_reload);
3984 # else
3985 return (optimize);
3986 # endif
3987 #else
3988 return 0;
3989 #endif
3992 static unsigned int
3993 rest_of_handle_split_before_regstack (void)
3995 split_all_insns ();
3996 return 0;
3999 namespace {
4001 const pass_data pass_data_split_before_regstack =
4003 RTL_PASS, /* type */
4004 "split3", /* name */
4005 OPTGROUP_NONE, /* optinfo_flags */
4006 true, /* has_gate */
4007 true, /* has_execute */
4008 TV_NONE, /* tv_id */
4009 0, /* properties_required */
4010 0, /* properties_provided */
4011 0, /* properties_destroyed */
4012 0, /* todo_flags_start */
4013 0, /* todo_flags_finish */
4016 class pass_split_before_regstack : public rtl_opt_pass
4018 public:
4019 pass_split_before_regstack (gcc::context *ctxt)
4020 : rtl_opt_pass (pass_data_split_before_regstack, ctxt)
4023 /* opt_pass methods: */
4024 bool gate () { return gate_handle_split_before_regstack (); }
4025 unsigned int execute () {
4026 return rest_of_handle_split_before_regstack ();
4029 }; // class pass_split_before_regstack
4031 } // anon namespace
4033 rtl_opt_pass *
4034 make_pass_split_before_regstack (gcc::context *ctxt)
4036 return new pass_split_before_regstack (ctxt);
4039 static bool
4040 gate_handle_split_before_sched2 (void)
4042 #ifdef INSN_SCHEDULING
4043 return optimize > 0 && flag_schedule_insns_after_reload;
4044 #else
4045 return 0;
4046 #endif
4049 static unsigned int
4050 rest_of_handle_split_before_sched2 (void)
4052 #ifdef INSN_SCHEDULING
4053 split_all_insns ();
4054 #endif
4055 return 0;
4058 namespace {
4060 const pass_data pass_data_split_before_sched2 =
4062 RTL_PASS, /* type */
4063 "split4", /* name */
4064 OPTGROUP_NONE, /* optinfo_flags */
4065 true, /* has_gate */
4066 true, /* has_execute */
4067 TV_NONE, /* tv_id */
4068 0, /* properties_required */
4069 0, /* properties_provided */
4070 0, /* properties_destroyed */
4071 0, /* todo_flags_start */
4072 TODO_verify_flow, /* todo_flags_finish */
4075 class pass_split_before_sched2 : public rtl_opt_pass
4077 public:
4078 pass_split_before_sched2 (gcc::context *ctxt)
4079 : rtl_opt_pass (pass_data_split_before_sched2, ctxt)
4082 /* opt_pass methods: */
4083 bool gate () { return gate_handle_split_before_sched2 (); }
4084 unsigned int execute () { return rest_of_handle_split_before_sched2 (); }
4086 }; // class pass_split_before_sched2
4088 } // anon namespace
4090 rtl_opt_pass *
4091 make_pass_split_before_sched2 (gcc::context *ctxt)
4093 return new pass_split_before_sched2 (ctxt);
4096 /* The placement of the splitting that we do for shorten_branches
4097 depends on whether regstack is used by the target or not. */
4098 static bool
4099 gate_do_final_split (void)
4101 #if HAVE_ATTR_length && !defined (STACK_REGS)
4102 return 1;
4103 #else
4104 return 0;
4105 #endif
4108 namespace {
4110 const pass_data pass_data_split_for_shorten_branches =
4112 RTL_PASS, /* type */
4113 "split5", /* name */
4114 OPTGROUP_NONE, /* optinfo_flags */
4115 true, /* has_gate */
4116 true, /* has_execute */
4117 TV_NONE, /* tv_id */
4118 0, /* properties_required */
4119 0, /* properties_provided */
4120 0, /* properties_destroyed */
4121 0, /* todo_flags_start */
4122 TODO_verify_rtl_sharing, /* todo_flags_finish */
4125 class pass_split_for_shorten_branches : public rtl_opt_pass
4127 public:
4128 pass_split_for_shorten_branches (gcc::context *ctxt)
4129 : rtl_opt_pass (pass_data_split_for_shorten_branches, ctxt)
4132 /* opt_pass methods: */
4133 bool gate () { return gate_do_final_split (); }
4134 unsigned int execute () { return split_all_insns_noflow (); }
4136 }; // class pass_split_for_shorten_branches
4138 } // anon namespace
4140 rtl_opt_pass *
4141 make_pass_split_for_shorten_branches (gcc::context *ctxt)
4143 return new pass_split_for_shorten_branches (ctxt);