Commit 0a634832 by J"orn Rennecke Committed by Joern Rennecke

recog.c (verify_changes, [...]): New functions, broken out of apply_change_group.

	* recog.c (verify_changes, confirm_change_group): New functions,
	broken out of apply_change_group.
	(apply_change_group): Use them.
	* recog.h (verify_change, confirm_change_group): Declare.
	* rtl.h (redirect_jump_2): Declare.
	* jump.c (redirect_exp, invert_exp): Delete.
	(invert_exp_1): Take second parameter.  Return value.  Changed caller.
	(redirect_jump_2): New function, broken out of redirect_jump.
	(redirect_jump): Use redirect_jump_1 and redirect_jump_2.
	(invert_jump): Use invert_jump_1 and redirect_jump_2.
	* ifcvt.c (dead_or_predicable): Use redirect_jump_2.

From-SVN: r95813
parent 7df74013
2005-03-02 J"orn Rennecke <joern.rennecke@st.com>
* recog.c (verify_changes, confirm_change_group): New functions,
broken out of apply_change_group.
(apply_change_group): Use them.
* recog.h (verify_change, confirm_change_group): Declare.
* rtl.h (redirect_jump_2): Declare.
* jump.c (redirect_exp, invert_exp): Delete.
(invert_exp_1): Take second parameter. Return value. Changed caller.
(redirect_jump_2): New function, broken out of redirect_jump.
(redirect_jump): Use redirect_jump_1 and redirect_jump_2.
(invert_jump): Use invert_jump_1 and redirect_jump_2.
* ifcvt.c (dead_or_predicable): Use redirect_jump_2.
2005-03-02 Geoffrey Keating <geoffk@apple.com> 2005-03-02 Geoffrey Keating <geoffk@apple.com>
* varasm.c (named_section): Use xstrdup rather than doing it by * varasm.c (named_section): Use xstrdup rather than doing it by
......
...@@ -3258,13 +3258,7 @@ dead_or_predicable (basic_block test_bb, basic_block merge_bb, ...@@ -3258,13 +3258,7 @@ dead_or_predicable (basic_block test_bb, basic_block merge_bb,
if (other_bb != new_dest) if (other_bb != new_dest)
{ {
if (old_dest) redirect_jump_2 (jump, old_dest, new_label, -1, reversep);
LABEL_NUSES (old_dest) -= 1;
if (new_label)
LABEL_NUSES (new_label) += 1;
JUMP_LABEL (jump) = new_label;
if (reversep)
invert_br_probabilities (jump);
redirect_edge_succ (BRANCH_EDGE (test_bb), new_dest); redirect_edge_succ (BRANCH_EDGE (test_bb), new_dest);
if (reversep) if (reversep)
......
...@@ -67,9 +67,7 @@ static void init_label_info (rtx); ...@@ -67,9 +67,7 @@ static void init_label_info (rtx);
static void mark_all_labels (rtx); static void mark_all_labels (rtx);
static void delete_computation (rtx); static void delete_computation (rtx);
static void redirect_exp_1 (rtx *, rtx, rtx, rtx); static void redirect_exp_1 (rtx *, rtx, rtx, rtx);
static int redirect_exp (rtx, rtx, rtx); static int invert_exp_1 (rtx, rtx);
static void invert_exp_1 (rtx);
static int invert_exp (rtx);
static int returnjump_p_1 (rtx *, void *); static int returnjump_p_1 (rtx *, void *);
static void delete_prior_computation (rtx, rtx); static void delete_prior_computation (rtx, rtx);
...@@ -1570,25 +1568,6 @@ redirect_exp_1 (rtx *loc, rtx olabel, rtx nlabel, rtx insn) ...@@ -1570,25 +1568,6 @@ redirect_exp_1 (rtx *loc, rtx olabel, rtx nlabel, rtx insn)
} }
} }
/* Similar, but apply the change group and report success or failure. */
static int
redirect_exp (rtx olabel, rtx nlabel, rtx insn)
{
rtx *loc;
if (GET_CODE (PATTERN (insn)) == PARALLEL)
loc = &XVECEXP (PATTERN (insn), 0, 0);
else
loc = &PATTERN (insn);
redirect_exp_1 (loc, olabel, nlabel, insn);
if (num_validated_changes () == 0)
return 0;
return apply_change_group ();
}
/* Make JUMP go to NLABEL instead of where it jumps now. Accrue /* Make JUMP go to NLABEL instead of where it jumps now. Accrue
the modifications into the change group. Return false if we did the modifications into the change group. Return false if we did
not see how to do that. */ not see how to do that. */
...@@ -1622,14 +1601,28 @@ int ...@@ -1622,14 +1601,28 @@ int
redirect_jump (rtx jump, rtx nlabel, int delete_unused) redirect_jump (rtx jump, rtx nlabel, int delete_unused)
{ {
rtx olabel = JUMP_LABEL (jump); rtx olabel = JUMP_LABEL (jump);
rtx note;
if (nlabel == olabel) if (nlabel == olabel)
return 1; return 1;
if (! redirect_exp (olabel, nlabel, jump)) if (! redirect_jump_1 (jump, nlabel) || ! apply_change_group ())
return 0; return 0;
redirect_jump_2 (jump, olabel, nlabel, delete_unused, 0);
return 1;
}
/* Fix up JUMP_LABEL and label ref counts after OLABEL has been replaced with
NLABEL in JUMP. If DELETE_UNUSED is non-negative, copy a
NOTE_INSN_FUNCTION_END found after OLABEL to the place after NLABEL.
If DELETE_UNUSED is positive, delete related insn to OLABEL if its ref
count has dropped to zero. */
void
redirect_jump_2 (rtx jump, rtx olabel, rtx nlabel, int delete_unused,
int invert)
{
rtx note;
JUMP_LABEL (jump) = nlabel; JUMP_LABEL (jump) = nlabel;
if (nlabel) if (nlabel)
++LABEL_NUSES (nlabel); ++LABEL_NUSES (nlabel);
...@@ -1637,24 +1630,13 @@ redirect_jump (rtx jump, rtx nlabel, int delete_unused) ...@@ -1637,24 +1630,13 @@ redirect_jump (rtx jump, rtx nlabel, int delete_unused)
/* Update labels in any REG_EQUAL note. */ /* Update labels in any REG_EQUAL note. */
if ((note = find_reg_note (jump, REG_EQUAL, NULL_RTX)) != NULL_RTX) if ((note = find_reg_note (jump, REG_EQUAL, NULL_RTX)) != NULL_RTX)
{ {
if (nlabel && olabel) if (!nlabel || (invert && !invert_exp_1 (XEXP (note, 0), jump)))
remove_note (jump, note);
else
{ {
rtx dest = XEXP (note, 0); redirect_exp_1 (&XEXP (note, 0), olabel, nlabel, jump);
confirm_change_group ();
if (GET_CODE (dest) == IF_THEN_ELSE)
{
if (GET_CODE (XEXP (dest, 1)) == LABEL_REF
&& XEXP (XEXP (dest, 1), 0) == olabel)
XEXP (XEXP (dest, 1), 0) = nlabel;
if (GET_CODE (XEXP (dest, 2)) == LABEL_REF
&& XEXP (XEXP (dest, 2), 0) == olabel)
XEXP (XEXP (dest, 2), 0) = nlabel;
}
else
remove_note (jump, note);
} }
else
remove_note (jump, note);
} }
/* If we're eliding the jump over exception cleanups at the end of a /* If we're eliding the jump over exception cleanups at the end of a
...@@ -1662,31 +1644,24 @@ redirect_jump (rtx jump, rtx nlabel, int delete_unused) ...@@ -1662,31 +1644,24 @@ redirect_jump (rtx jump, rtx nlabel, int delete_unused)
if (olabel && nlabel if (olabel && nlabel
&& NEXT_INSN (olabel) && NEXT_INSN (olabel)
&& NOTE_P (NEXT_INSN (olabel)) && NOTE_P (NEXT_INSN (olabel))
&& NOTE_LINE_NUMBER (NEXT_INSN (olabel)) == NOTE_INSN_FUNCTION_END) && NOTE_LINE_NUMBER (NEXT_INSN (olabel)) == NOTE_INSN_FUNCTION_END
&& delete_unused >= 0)
emit_note_after (NOTE_INSN_FUNCTION_END, nlabel); emit_note_after (NOTE_INSN_FUNCTION_END, nlabel);
if (olabel && --LABEL_NUSES (olabel) == 0 && delete_unused if (olabel && --LABEL_NUSES (olabel) == 0 && delete_unused > 0
/* Undefined labels will remain outside the insn stream. */ /* Undefined labels will remain outside the insn stream. */
&& INSN_UID (olabel)) && INSN_UID (olabel))
delete_related_insns (olabel); delete_related_insns (olabel);
if (invert)
return 1; invert_br_probabilities (jump);
} }
/* Invert the jump condition of rtx X contained in jump insn, INSN. /* Invert the jump condition X contained in jump insn INSN. Accrue the
Accrue the modifications into the change group. */ modifications into the change group. Return nonzero for success. */
static int
static void invert_exp_1 (rtx x, rtx insn)
invert_exp_1 (rtx insn)
{ {
RTX_CODE code; RTX_CODE code = GET_CODE (x);
rtx x = pc_set (insn);
if (!x)
abort ();
x = SET_SRC (x);
code = GET_CODE (x);
if (code == IF_THEN_ELSE) if (code == IF_THEN_ELSE)
{ {
...@@ -1708,30 +1683,16 @@ invert_exp_1 (rtx insn) ...@@ -1708,30 +1683,16 @@ invert_exp_1 (rtx insn)
GET_MODE (comp), XEXP (comp, 0), GET_MODE (comp), XEXP (comp, 0),
XEXP (comp, 1)), XEXP (comp, 1)),
1); 1);
return; return 1;
} }
tem = XEXP (x, 1); tem = XEXP (x, 1);
validate_change (insn, &XEXP (x, 1), XEXP (x, 2), 1); validate_change (insn, &XEXP (x, 1), XEXP (x, 2), 1);
validate_change (insn, &XEXP (x, 2), tem, 1); validate_change (insn, &XEXP (x, 2), tem, 1);
return 1;
} }
else else
abort ();
}
/* Invert the jump condition of conditional jump insn, INSN.
Return 1 if we can do so, 0 if we cannot find a way to do so that
matches a pattern. */
static int
invert_exp (rtx insn)
{
invert_exp_1 (insn);
if (num_validated_changes () == 0)
return 0; return 0;
return apply_change_group ();
} }
/* Invert the condition of the jump JUMP, and make it jump to label /* Invert the condition of the jump JUMP, and make it jump to label
...@@ -1742,10 +1703,12 @@ invert_exp (rtx insn) ...@@ -1742,10 +1703,12 @@ invert_exp (rtx insn)
int int
invert_jump_1 (rtx jump, rtx nlabel) invert_jump_1 (rtx jump, rtx nlabel)
{ {
rtx x = pc_set (jump);
int ochanges; int ochanges;
ochanges = num_validated_changes (); ochanges = num_validated_changes ();
invert_exp_1 (jump); if (!x || !invert_exp_1 (SET_SRC (x), jump))
abort ();
if (num_validated_changes () == ochanges) if (num_validated_changes () == ochanges)
return 0; return 0;
...@@ -1758,30 +1721,14 @@ invert_jump_1 (rtx jump, rtx nlabel) ...@@ -1758,30 +1721,14 @@ invert_jump_1 (rtx jump, rtx nlabel)
int int
invert_jump (rtx jump, rtx nlabel, int delete_unused) invert_jump (rtx jump, rtx nlabel, int delete_unused)
{ {
/* We have to either invert the condition and change the label or rtx olabel = JUMP_LABEL (jump);
do neither. Either operation could fail. We first try to invert
the jump. If that succeeds, we try changing the label. If that fails,
we invert the jump back to what it was. */
if (! invert_exp (jump))
return 0;
if (redirect_jump (jump, nlabel, delete_unused)) if (invert_jump_1 (jump, nlabel) && apply_change_group ())
{ {
/* Remove REG_EQUAL note if we have one. */ redirect_jump_2 (jump, olabel, nlabel, delete_unused, 1);
rtx note = find_reg_note (jump, REG_EQUAL, NULL_RTX);
if (note)
remove_note (jump, note);
invert_br_probabilities (jump);
return 1; return 1;
} }
cancel_changes (0);
if (! invert_exp (jump))
/* This should just be putting it back the way it was. */
abort ();
return 0; return 0;
} }
......
...@@ -294,11 +294,11 @@ num_changes_pending (void) ...@@ -294,11 +294,11 @@ num_changes_pending (void)
return num_changes; return num_changes;
} }
/* Apply a group of changes previously issued with `validate_change'. /* Tentatively apply the changes numbered NUM and up.
Return 1 if all changes are valid, zero otherwise. */ Return 1 if all changes are valid, zero otherwise. */
int int
apply_change_group (void) verify_changes (int num)
{ {
int i; int i;
rtx last_validated = NULL_RTX; rtx last_validated = NULL_RTX;
...@@ -312,7 +312,7 @@ apply_change_group (void) ...@@ -312,7 +312,7 @@ apply_change_group (void)
we also require that the operands meet the constraints for we also require that the operands meet the constraints for
the insn. */ the insn. */
for (i = 0; i < num_changes; i++) for (i = num; i < num_changes; i++)
{ {
rtx object = changes[i].object; rtx object = changes[i].object;
...@@ -376,17 +376,38 @@ apply_change_group (void) ...@@ -376,17 +376,38 @@ apply_change_group (void)
last_validated = object; last_validated = object;
} }
if (i == num_changes) return (i == num_changes);
{ }
basic_block bb;
for (i = 0; i < num_changes; i++) /* A group of changes has previously been issued with validate_change and
if (changes[i].object verified with verify_changes. Update the BB_DIRTY flags of the affected
&& INSN_P (changes[i].object) blocks, and clear num_changes. */
&& (bb = BLOCK_FOR_INSN (changes[i].object)))
bb->flags |= BB_DIRTY;
num_changes = 0; void
confirm_change_group (void)
{
int i;
basic_block bb;
for (i = 0; i < num_changes; i++)
if (changes[i].object
&& INSN_P (changes[i].object)
&& (bb = BLOCK_FOR_INSN (changes[i].object)))
bb->flags |= BB_DIRTY;
num_changes = 0;
}
/* Apply a group of changes previously issued with `validate_change'.
If all changes are valid, call confirm_change_group and return 1,
otherwise, call cancel_changes and return 0. */
int
apply_change_group (void)
{
if (verify_changes (0))
{
confirm_change_group ();
return 1; return 1;
} }
else else
...@@ -396,6 +417,7 @@ apply_change_group (void) ...@@ -396,6 +417,7 @@ apply_change_group (void)
} }
} }
/* Return the number of changes so far in the current group. */ /* Return the number of changes so far in the current group. */
int int
......
...@@ -75,6 +75,8 @@ extern int check_asm_operands (rtx); ...@@ -75,6 +75,8 @@ extern int check_asm_operands (rtx);
extern int asm_operand_ok (rtx, const char *); extern int asm_operand_ok (rtx, const char *);
extern int validate_change (rtx, rtx *, rtx, int); extern int validate_change (rtx, rtx *, rtx, int);
extern int insn_invalid_p (rtx); extern int insn_invalid_p (rtx);
extern int verify_changes (int);
extern void confirm_change_group (void);
extern int apply_change_group (void); extern int apply_change_group (void);
extern int num_validated_changes (void); extern int num_validated_changes (void);
extern void cancel_changes (int); extern void cancel_changes (int);
......
...@@ -1912,6 +1912,7 @@ extern int rtx_renumbered_equal_p (rtx, rtx); ...@@ -1912,6 +1912,7 @@ extern int rtx_renumbered_equal_p (rtx, rtx);
extern int true_regnum (rtx); extern int true_regnum (rtx);
extern unsigned int reg_or_subregno (rtx); extern unsigned int reg_or_subregno (rtx);
extern int redirect_jump_1 (rtx, rtx); extern int redirect_jump_1 (rtx, rtx);
extern void redirect_jump_2 (rtx, rtx, rtx, int, int);
extern int redirect_jump (rtx, rtx, int); extern int redirect_jump (rtx, rtx, int);
extern void rebuild_jump_labels (rtx); extern void rebuild_jump_labels (rtx);
extern enum rtx_code reversed_comparison_code (rtx, rtx); extern enum rtx_code reversed_comparison_code (rtx, rtx);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment