|
From: <sv...@va...> - 2005-09-09 08:33:06
|
Author: sewardj
Date: 2005-09-09 09:33:03 +0100 (Fri, 09 Sep 2005)
New Revision: 1375
Log:
Enhance the dead-code removal pass so that it detects unconditional
side exits and deletes all code after them. This helps clean up the
IR created by {l,st}sw{i,x} from the ppc32 front end. It's also a
general transformation which ought to have been implemented long ago.
Modified:
trunk/priv/ir/iropt.c
Modified: trunk/priv/ir/iropt.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/priv/ir/iropt.c 2005-09-09 08:31:18 UTC (rev 1374)
+++ trunk/priv/ir/iropt.c 2005-09-09 08:33:03 UTC (rev 1375)
@@ -1648,9 +1648,10 @@
return IRStmt_NoOp();
} else {
vassert(fcond->Iex.Const.con->Ico.U1 =3D=3D True);
- /* Hmmm. The exit has become unconditional. Leave it as
- it is for now, since we'd have to truncate the BB at
- this point, which is tricky. */
+ /* Hmmm. The exit has become unconditional. Leave it
+ as it is for now, since we'd have to truncate the BB
+ at this point, which is tricky. Such truncation is
+ done later by the dead-code elimination pass. */
/* fall out into the reconstruct-the-exit code. */
if (vex_control.iropt_verbosity > 0)=20
/* really a misuse of vex_control.iropt_verbosity */
@@ -1737,11 +1738,13 @@
}
=20
=20
-
/*---------------------------------------------------------------*/
/*--- Dead code (t =3D E) removal ---*/
/*---------------------------------------------------------------*/
=20
+/* As a side effect, also removes all code following an unconditional
+ side exit. */
+
/* The type of the HashHW map is: a map from IRTemp to nothing
-- really just operating a set or IRTemps.
*/
@@ -1844,17 +1847,32 @@
&& e->Iex.Const.con->Ico.U1 =3D=3D False );
}
=20
+/* Is this literally IRExpr_Const(IRConst_U1(True)) ? */
+static Bool isOneU1 ( IRExpr* e )
+{
+ return toBool( e->tag =3D=3D Iex_Const
+ && e->Iex.Const.con->tag =3D=3D Ico_U1
+ && e->Iex.Const.con->Ico.U1 =3D=3D True );
+}
=20
+
/* Note, this destructively modifies the given IRBB. */
=20
/* Scan backwards through statements, carrying a set of IRTemps which
are known to be used after the current point. On encountering 't =3D
E', delete the binding if it is not used. Otherwise, add any temp
- uses to the set and keep on moving backwards. */
+ uses to the set and keep on moving backwards.
=20
+ As an enhancement, the first (backwards) pass searches for IR exits
+ with always-taken conditions and notes the location of the earliest
+ one in the block. If any such are found, a second pass copies the
+ exit destination and jump kind to the bb-end. Then, the exit and
+ all statements following it are turned into no-ops.
+*/
+
/* notstatic */ void do_deadcode_BB ( IRBB* bb )
{
- Int i;
+ Int i, i_unconditional_exit;
Int n_tmps =3D bb->tyenv->types_used;
Bool* set =3D LibVEX_Alloc(n_tmps * sizeof(Bool));
IRStmt* st;
@@ -1865,11 +1883,18 @@
/* start off by recording IRTemp uses in the next field. */
addUses_Expr(set, bb->next);
=20
+ /* First pass */
+
/* Work backwards through the stmts */
+ i_unconditional_exit =3D -1;
for (i =3D bb->stmts_used-1; i >=3D 0; i--) {
st =3D bb->stmts[i];
if (st->tag =3D=3D Ist_NoOp)
continue;
+ /* take note of any unconditional exits */
+ if (st->tag =3D=3D Ist_Exit
+ && isOneU1(st->Ist.Exit.guard))
+ i_unconditional_exit =3D i;
if (st->tag =3D=3D Ist_Tmp
&& set[(Int)(st->Ist.Tmp.tmp)] =3D=3D False) {
/* it's an IRTemp which never got used. Delete it. */
@@ -1893,8 +1918,25 @@
addUses_Stmt(set, st);
}
}
+
+ /* Optional second pass: if any unconditional exits were found,=20
+ delete them and all following statements. */
+
+ if (i_unconditional_exit !=3D -1) {
+ if (0) vex_printf("ZAPPING ALL FORWARDS from %d\n",=20
+ i_unconditional_exit);
+ vassert(i_unconditional_exit >=3D 0=20
+ && i_unconditional_exit < bb->stmts_used);
+ bb->next=20
+ =3D IRExpr_Const( bb->stmts[i_unconditional_exit]->Ist.Exit.dst=
);
+ bb->jumpkind
+ =3D bb->stmts[i_unconditional_exit]->Ist.Exit.jk;
+ for (i =3D i_unconditional_exit; i < bb->stmts_used; i++)
+ bb->stmts[i] =3D IRStmt_NoOp();
+ }
}
=20
+
/*---------------------------------------------------------------*/
/*--- Specialisation of helper function calls, in ---*/
/*--- collaboration with the front end ---*/
|
|
From: Julian S. <js...@ac...> - 2005-09-09 08:39:24
|
> On Friday 09 September 2005 09:33, sv...@va... wrote:
> Author: sewardj
> Date: 2005-09-09 09:33:03 +0100 (Fri, 09 Sep 2005)
> New Revision: 1375
>
> Log:
> Enhance the dead-code removal pass so that it detects unconditional
> side exits and deletes all code after them. This helps clean up the
> IR created by {l,st}sw{i,x} from the ppc32 front end. It's also a
> general transformation which ought to have been implemented long ago.
Folks -- note -- this is an IR optimiser change which affects all
targets. As far as I know it should not have any discernable
effect on correctness of the simulation, but ...
so be aware of possible strangeness after you svn up.
J
|