/* Optimize jump instructions, for GNU compiler.
Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997
- 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
- Free Software Foundation, Inc.
+ 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010,
+ 2011 Free Software Foundation, Inc.
This file is part of GCC.
JUMP_LABEL internal field. With this we can detect labels that
become unused because of the deletion of all the jumps that
formerly used them. The JUMP_LABEL info is sometimes looked
- at by later passes.
+ at by later passes. For return insns, it contains either a
+ RETURN or a SIMPLE_RETURN rtx.
The subroutines redirect_jump and invert_jump are used
from other passes as well. */
return (GET_CODE (x) == IF_THEN_ELSE
&& ((GET_CODE (XEXP (x, 2)) == PC
&& (GET_CODE (XEXP (x, 1)) == LABEL_REF
- || GET_CODE (XEXP (x, 1)) == RETURN))
+ || ANY_RETURN_P (XEXP (x, 1))))
|| (GET_CODE (XEXP (x, 1)) == PC
&& (GET_CODE (XEXP (x, 2)) == LABEL_REF
- || GET_CODE (XEXP (x, 2)) == RETURN))));
+ || ANY_RETURN_P (XEXP (x, 2))))));
}
/* Return nonzero if INSN is a (possibly) conditional jump inside a
return 0;
if (XEXP (SET_SRC (x), 2) == pc_rtx
&& (GET_CODE (XEXP (SET_SRC (x), 1)) == LABEL_REF
- || GET_CODE (XEXP (SET_SRC (x), 1)) == RETURN))
+ || ANY_RETURN_P (XEXP (SET_SRC (x), 1))))
return 1;
if (XEXP (SET_SRC (x), 1) == pc_rtx
&& (GET_CODE (XEXP (SET_SRC (x), 2)) == LABEL_REF
- || GET_CODE (XEXP (SET_SRC (x), 2)) == RETURN))
+ || ANY_RETURN_P (XEXP (SET_SRC (x), 2))))
return 1;
return 0;
}
a = GET_CODE (XEXP (SET_SRC (x), 1));
b = GET_CODE (XEXP (SET_SRC (x), 2));
- return ((b == PC && (a == LABEL_REF || a == RETURN))
- || (a == PC && (b == LABEL_REF || b == RETURN)));
+ return ((b == PC && (a == LABEL_REF || a == RETURN || a == SIMPLE_RETURN))
+ || (a == PC
+ && (b == LABEL_REF || b == RETURN || b == SIMPLE_RETURN)));
}
/* Return the label of a conditional jump. */
switch (GET_CODE (x))
{
case RETURN:
+ case SIMPLE_RETURN:
case EH_RETURN:
return true;
return 1;
}
+/* Return true iff INSN is a jump and its JUMP_LABEL is a label, not
+ NULL or a return. */
+bool
+jump_to_label_p (rtx insn)
+{
+ return (JUMP_P (insn)
+ && JUMP_LABEL (insn) != NULL && !ANY_RETURN_P (JUMP_LABEL (insn)));
+}
+
#ifdef HAVE_cc0
/* Return nonzero if X is an RTX that only sets the condition codes
notes. If INSN is an INSN or a CALL_INSN or non-target operands of
a JUMP_INSN, and there is at least one CODE_LABEL referenced in
INSN, add a REG_LABEL_OPERAND note containing that label to INSN.
+ For returnjumps, the JUMP_LABEL will also be set as appropriate.
Note that two labels separated by a loop-beginning note
must be kept distinct if we have not yet done loop-optimization,
case CALL:
return;
+ case RETURN:
+ if (is_target)
+ {
+ gcc_assert (JUMP_LABEL (insn) == NULL || JUMP_LABEL (insn) == x);
+ JUMP_LABEL (insn) = x;
+ }
+ return;
+
case MEM:
in_mem = true;
break;
/* If deleting a jump, decrement the count of the label,
and delete the label if it is now unused. */
- if (JUMP_P (insn) && JUMP_LABEL (insn))
+ if (jump_to_label_p (insn))
{
rtx lab = JUMP_LABEL (insn), lab_next;
is also an unconditional jump in that case. */
}
\f
+/* A helper function for redirect_exp_1; examines its input X and returns
+ either a LABEL_REF around a label, or a RETURN if X was NULL. */
+static rtx
+redirect_target (rtx x)
+{
+ if (x == NULL_RTX)
+ return ret_rtx;
+ if (!ANY_RETURN_P (x))
+ return gen_rtx_LABEL_REF (Pmode, x);
+ return x;
+}
+
/* Throughout LOC, redirect OLABEL to NLABEL. Treat null OLABEL or
NLABEL as a return. Accrue modifications into the change group. */
int i;
const char *fmt;
- if (code == LABEL_REF)
- {
- if (XEXP (x, 0) == olabel)
- {
- rtx n;
- if (nlabel)
- n = gen_rtx_LABEL_REF (Pmode, nlabel);
- else
- n = ret_rtx;
-
- validate_change (insn, loc, n, 1);
- return;
- }
- }
- else if (code == RETURN && olabel == 0)
+ if ((code == LABEL_REF && XEXP (x, 0) == olabel)
+ || x == olabel)
{
- if (nlabel)
- x = gen_rtx_LABEL_REF (Pmode, nlabel);
- else
- x = ret_rtx;
- if (loc == &PATTERN (insn))
- x = gen_rtx_SET (VOIDmode, pc_rtx, x);
+ x = redirect_target (nlabel);
+ if (GET_CODE (x) == LABEL_REF && loc == &PATTERN (insn))
+ x = gen_rtx_SET (VOIDmode, pc_rtx, x);
validate_change (insn, loc, x, 1);
return;
}
- if (code == SET && nlabel == 0 && SET_DEST (x) == pc_rtx
+ if (code == SET && SET_DEST (x) == pc_rtx
+ && ANY_RETURN_P (nlabel)
&& GET_CODE (SET_SRC (x)) == LABEL_REF
&& XEXP (SET_SRC (x), 0) == olabel)
{
- validate_change (insn, loc, ret_rtx, 1);
+ validate_change (insn, loc, nlabel, 1);
return;
}
int ochanges = num_validated_changes ();
rtx *loc, asmop;
+ gcc_assert (nlabel != NULL_RTX);
asmop = extract_asm_operands (PATTERN (jump));
if (asmop)
{
jump target label is unused as a result, it and the code following
it may be deleted.
- If NLABEL is zero, we are to turn the jump into a (possibly conditional)
- RETURN insn.
+ Normally, NLABEL will be a label, but it may also be a RETURN rtx;
+ in that case we are to turn the jump into a (possibly conditional)
+ return insn.
The return value will be 1 if the change was made, 0 if it wasn't
- (this can only occur for NLABEL == 0). */
+ (this can only occur when trying to produce return insns). */
int
redirect_jump (rtx jump, rtx nlabel, int delete_unused)
{
rtx olabel = JUMP_LABEL (jump);
+ gcc_assert (nlabel != NULL_RTX);
+
if (nlabel == olabel)
return 1;
about this. */
gcc_assert (delete_unused >= 0);
JUMP_LABEL (jump) = nlabel;
- if (nlabel)
+ if (!ANY_RETURN_P (nlabel))
++LABEL_NUSES (nlabel);
/* Update labels in any REG_EQUAL note. */
if ((note = find_reg_note (jump, REG_EQUAL, NULL_RTX)) != NULL_RTX)
{
- if (!nlabel || (invert && !invert_exp_1 (XEXP (note, 0), jump)))
+ if (ANY_RETURN_P (nlabel)
+ || (invert && !invert_exp_1 (XEXP (note, 0), jump)))
remove_note (jump, note);
else
{
}
}
- if (olabel && --LABEL_NUSES (olabel) == 0 && delete_unused > 0
+ if (!ANY_RETURN_P (olabel)
+ && --LABEL_NUSES (olabel) == 0 && delete_unused > 0
/* Undefined labels will remain outside the insn stream. */
&& INSN_UID (olabel))
delete_related_insns (olabel);