vex: r3339 - in /branches/VEX_JIT_HACKS/priv: ir_defs.c ir_opt.c

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

vex: r3339 - in /branches/VEX_JIT_HACKS/priv: ir_defs.c ir_opt.c

svn-2
Author: iraisr
Date: Fri Mar 31 18:06:01 2017
New Revision: 3339

Log:
Fix constant propagation and folding IR transformation pass for IfThenElse.

Modified:
    branches/VEX_JIT_HACKS/priv/ir_defs.c
    branches/VEX_JIT_HACKS/priv/ir_opt.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 Fri Mar 31 18:06:01 2017
@@ -1706,7 +1706,7 @@
       if (i % 8 == 0)
          print_depth(1);
       ppIRTemp(i);
-      vex_printf(":%u=", env->ids[i]);
+      vex_printf("[%u]:", env->ids[i]);
       ppIRType(env->types[i]);
       if (i % 8 == 7)
          vex_printf( "\n");
@@ -1732,7 +1732,7 @@
             IRTemp tmp = slot * sizeof(UChar) + bit;
             ppIRTemp(tmp);
             if (tyenv != NULL) {
-               vex_printf("=");
+               vex_printf(":");
                ppIRType(tyenv->types[tmp]);
             }
 

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 Fri Mar 31 18:06:01 2017
@@ -1105,7 +1105,7 @@
    UInt  n_tmps = tyenv->used;
    env->map     = LibVEX_Alloc_inline(n_tmps * sizeof(IRExpr*));
    for (UInt i = 0; i < n_tmps; i++)
-      env->map[i] = NULL;
+      env->map[i] = (parent_env == NULL) ? NULL : parent_env->map[i];
    return env;
 }
 
@@ -2629,6 +2629,28 @@
    }
 }
 
+/* A phi node of the form dst = phi(srcThen, srcElse) behaves much like
+   a WrTmp. Ensure that the connection between src{Then,Else} and assignments
+   in the corresponding leg is not broken:
+   - either add WrTemp assignment for src{Then,Else} in the leg, or
+   - adjust src{Then,Else} for the phi node. */
+static void subst_and_fold_PhiNodes(SubstEnv* env, IRStmtVec* stmts,
+                                    Bool srcThen, IRPhiVec* phi_nodes)
+{
+   for (UInt i = 0; i < phi_nodes->phis_used; i++) {
+      IRPhi* phi = phi_nodes->phis[i];
+      IRTemp* tmp = (srcThen) ? &phi->srcThen : &phi->srcElse;
+      IRExpr* expr = env->map[*tmp];
+      vassert(expr != NULL);
+
+      if (expr->tag == Iex_RdTmp) {
+         *tmp = expr->Iex.RdTmp.tmp;
+      } else {
+         addStmtToIRStmtVec(stmts, IRStmt_WrTmp(*tmp, expr));
+      }
+   }
+}
+
 static IRStmtVec* subst_and_fold_Stmts(SubstEnv* env, IRStmtVec* in);
 
 /* Apply the subst to stmt, then fold the result as much as possible.
@@ -2872,11 +2894,15 @@
              = newSubstEnv(env->tyenv, st->Ist.IfThenElse.then_leg, env);
          IRStmtVec* then_stmts
              = subst_and_fold_Stmts(then_env, st->Ist.IfThenElse.then_leg);
+         subst_and_fold_PhiNodes(then_env, then_stmts, True /* srcThen */,
+                                 st->Ist.IfThenElse.phi_nodes);
 
          SubstEnv* else_env
              = newSubstEnv(env->tyenv, st->Ist.IfThenElse.else_leg, env);
          IRStmtVec* else_stmts
              = subst_and_fold_Stmts(else_env, st->Ist.IfThenElse.else_leg);
+         subst_and_fold_PhiNodes(else_env, else_stmts, False /* srcThen */,
+                                 st->Ist.IfThenElse.phi_nodes);
 
          return IRStmt_IfThenElse(fcond, then_stmts, else_stmts,
                                   st->Ist.IfThenElse.phi_nodes);
@@ -6684,7 +6710,7 @@
 /*--- iropt main                                              ---*/
 /*---------------------------------------------------------------*/
 
-static Bool iropt_verbose = True; /* True; */
+static Bool iropt_verbose = False; /* True; */
 
 
 /* Do a simple cleanup pass on bb.  This is: redundant Get removal,


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-developers
Loading...