]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
In the flattening phase, reduce the number of tmp-tmp copies
authorJulian Seward <jseward@acm.org>
Tue, 21 Sep 2004 23:00:11 +0000 (23:00 +0000)
committerJulian Seward <jseward@acm.org>
Tue, 21 Sep 2004 23:00:11 +0000 (23:00 +0000)
created.  This reduces the total amount of heap allocated by iropt
by about 10%.

git-svn-id: svn://svn.valgrind.org/vex/trunk@279

VEX/priv/ir/iropt.c

index 2369975f97985149f782d7bc9f73dbb9b88fd2d1..94c3ea0d45cabaf336e5262809bc217ea1305b94 100644 (file)
@@ -142,6 +142,12 @@ static void addToH64 ( Hash64* h, ULong key, ULong val )
 /*--- Flattening out a BB into pure SSA form                  ---*/
 /*---------------------------------------------------------------*/
 
+static Bool isAtom ( IRExpr* e )
+{
+   return e->tag == Iex_Tmp || e->tag == Iex_Const;
+}
+
+
 /* Clone the NULL-terminated vector of IRExpr*s attached to a
    CCall. */
 
@@ -159,6 +165,19 @@ static IRExpr** copyIRExprCallArgs ( IRExpr** vec )
 }
 
 
+/* Non-critical helper, heuristic for reducing the number of tmp-tmp
+   copies made by flattening.  If in doubt return False. */
+
+static Bool isFlat ( IRExpr* e )
+{
+   if (e->tag == Iex_Get) return True;
+   if (e->tag == Iex_Binop)
+      return isAtom(e->Iex.Binop.arg1) && isAtom(e->Iex.Binop.arg2);
+   if (e->tag == Iex_LDle)
+      return isAtom(e->Iex.LDle.addr);
+   return False;
+}
+
 /* Flatten out 'ex' so it is atomic, returning a new expression with
    the same value, after having appended extra IRTemp assignments to
    the end of 'bb'. */
@@ -261,8 +280,15 @@ static void flatten_Stmt ( IRBB* bb, IRStmt* st )
                                        st->Ist.PutI.maxoff));
          break;
       case Ist_Tmp:
-         e1 = flatten_Expr(bb, st->Ist.Tmp.expr);
-         addStmtToIRBB(bb, IRStmt_Tmp(st->Ist.Tmp.tmp, e1));
+         if (isFlat(st->Ist.Tmp.expr)) {
+            /* optimisation, to reduce the number of tmp-tmp
+               copies generated */
+            addStmtToIRBB(bb, st);
+         } else {
+            /* general case, always correct */
+            e1 = flatten_Expr(bb, st->Ist.Tmp.expr);
+            addStmtToIRBB(bb, IRStmt_Tmp(st->Ist.Tmp.tmp, e1));
+         }
          break;
       case Ist_STle:
          e1 = flatten_Expr(bb, st->Ist.STle.addr);
@@ -508,12 +534,6 @@ static IRExpr* fold_Expr ( IRExpr* e )
 }
 
 
-static Bool isAtom ( IRExpr* e )
-{
-   return e->tag == Iex_Tmp || e->tag == Iex_Const;
-}
-
-
 /* Apply the subst to a simple 1-level expression -- guaranteed to be
    1-level due to previous flattening pass. */
 
@@ -1662,7 +1682,7 @@ static void treebuild_BB ( IRBB* bb )
          continue;
      
       if (st->tag == Ist_Tmp) {
-        /* vex_printf("acquire binding\n"); */
+         /* vex_printf("acquire binding\n"); */
          if (!lookupH64(env, &res, (ULong)(st->Ist.Tmp.tmp))) {
             vpanic("treebuild_BB (phase 2): unmapped IRTemp");
          }