|
From: <sv...@va...> - 2017-03-15 06:54:18
|
Author: iraisr
Date: Wed Mar 15 06:54:05 2017
New Revision: 3320
Log:
Provide a function to deconstruct phi nodes
Modified:
branches/VEX_JIT_HACKS/priv/ir_defs.c
branches/VEX_JIT_HACKS/priv/ir_opt.c
branches/VEX_JIT_HACKS/priv/ir_opt.h
branches/VEX_JIT_HACKS/priv/main_main.c
Modified: branches/VEX_JIT_HACKS/priv/ir_defs.c
==============================================================================
--- branches/VEX_JIT_HACKS/priv/ir_defs.c (original)
+++ branches/VEX_JIT_HACKS/priv/ir_defs.c Wed Mar 15 06:54:05 2017
@@ -3678,7 +3678,8 @@
void addIRPhiToIRPhiVec(IRPhiVec* phi_nodes, IRPhi* phi)
{
if (phi_nodes->phis_used == phi_nodes->phis_size) {
- IRPhi** phis2 = LibVEX_Alloc_inline(2 * phi_nodes->phis_size * sizeof(IRPhi*));
+ IRPhi** phis2
+ = LibVEX_Alloc_inline(2 * phi_nodes->phis_size * sizeof(IRPhi*));
for (UInt i = 0; i < phi_nodes->phis_size; i++)
phis2[i] = phi_nodes->phis[i];
phi_nodes->phis = phis2;
@@ -3698,7 +3699,8 @@
void addStmtToIRStmtVec(IRStmtVec* stmts, IRStmt* st)
{
if (stmts->stmts_used == stmts->stmts_size) {
- IRStmt** stmts2 = LibVEX_Alloc_inline(2 * stmts->stmts_size * sizeof(IRStmt*));
+ IRStmt** stmts2
+ = LibVEX_Alloc_inline(2 * stmts->stmts_size * sizeof(IRStmt*));
for (UInt i = 0; i < stmts->stmts_size; i++)
stmts2[i] = stmts->stmts[i];
stmts->stmts = stmts2;
Modified: branches/VEX_JIT_HACKS/priv/ir_opt.c
==============================================================================
--- branches/VEX_JIT_HACKS/priv/ir_opt.c (original)
+++ branches/VEX_JIT_HACKS/priv/ir_opt.c Wed Mar 15 06:54:05 2017
@@ -6151,6 +6151,54 @@
/*---------------------------------------------------------------*/
+/*--- The phi nodes deconstruction ---*/
+/*---------------------------------------------------------------*/
+
+/* This isn't part of IR optimisation however this pass is needed before IRSB
+ is handed to instruction selection phase. Deconstructs all phi nodes.
+ Consider this example:
+ t0:2 = phi(t1:0,t2:1)
+ which gets trivially deconstructed into statements appended to:
+ - then leg:
+ t0:2 = t1:0
+ - else leg:
+ t0:2 = t2:1
+
+ Such an IRSB no longer holds SSA property after this pass but subsequent
+ phases do no require it. */
+static void deconstruct_phi_nodes_IRStmtVec(IRStmtVec* stmts)
+{
+ for (UInt i = 0; i < stmts->stmts_used; i++) {
+ IRStmt* st = stmts->stmts[i];
+ if (st->tag != Ist_IfThenElse) {
+ continue;
+ }
+
+ IRStmtVec* then_leg = st->Ist.IfThenElse.then_leg;
+ IRStmtVec* else_leg = st->Ist.IfThenElse.else_leg;
+ IRPhiVec* phi_nodes = st->Ist.IfThenElse.phi_nodes;
+ if (phi_nodes != NULL) {
+ for (UInt j = 0; j < phi_nodes->phis_used; j++) {
+ IRPhi* phi = phi_nodes->phis[j];
+ addStmtToIRStmtVec(then_leg, IRStmt_WrTmp(phi->dst,
+ IRExpr_RdTmp(phi->srcThen)));
+ addStmtToIRStmtVec(else_leg, IRStmt_WrTmp(phi->dst,
+ IRExpr_RdTmp(phi->srcElse)));
+ }
+ }
+
+ deconstruct_phi_nodes_IRStmtVec(then_leg);
+ deconstruct_phi_nodes_IRStmtVec(else_leg);
+ }
+}
+
+void deconstruct_phi_nodes(IRSB *irsb)
+{
+ deconstruct_phi_nodes_IRStmtVec(irsb->stmts);
+}
+
+
+/*---------------------------------------------------------------*/
/*--- MSVC specific transformation hacks ---*/
/*---------------------------------------------------------------*/
Modified: branches/VEX_JIT_HACKS/priv/ir_opt.h
==============================================================================
--- branches/VEX_JIT_HACKS/priv/ir_opt.h (original)
+++ branches/VEX_JIT_HACKS/priv/ir_opt.h Wed Mar 15 06:54:05 2017
@@ -72,6 +72,9 @@
VexRegisterUpdates pxControl
);
+/* Deconstructs phi nodes. IRSB is modified and no longer holds SSA propery. */
+extern void deconstruct_phi_nodes(IRSB* bb);
+
#endif /* ndef __VEX_IR_OPT_H */
/*---------------------------------------------------------------*/
Modified: branches/VEX_JIT_HACKS/priv/main_main.c
==============================================================================
--- branches/VEX_JIT_HACKS/priv/main_main.c (original)
+++ branches/VEX_JIT_HACKS/priv/main_main.c Wed Mar 15 06:54:05 2017
@@ -1009,6 +1009,14 @@
}
/* end HACK */
+ if (irsb->id_seq > 1) {
+ /* We have some IfThenElse statements. Deconstruct phi nodes. */
+ deconstruct_phi_nodes(irsb);
+ }
+
+ /* Now the IRSB no longer holds SSA. However there is no need to because
+ instruction selection pass does not rely on SSA property. */
+
if (vex_traceflags & VEX_TRACE_VCODE)
vex_printf("\n------------------------"
" Instruction selection "
|