From: Julian Seward Date: Tue, 21 Sep 2004 23:00:11 +0000 (+0000) Subject: In the flattening phase, reduce the number of tmp-tmp copies X-Git-Tag: svn/VALGRIND_3_0_1^2~1055 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8aa873c20c3bbd9f3cc801a937f65486d1cc646b;p=thirdparty%2Fvalgrind.git In the flattening phase, reduce the number of tmp-tmp copies created. This reduces the total amount of heap allocated by iropt by about 10%. git-svn-id: svn://svn.valgrind.org/vex/trunk@279 --- diff --git a/VEX/priv/ir/iropt.c b/VEX/priv/ir/iropt.c index 2369975f97..94c3ea0d45 100644 --- a/VEX/priv/ir/iropt.c +++ b/VEX/priv/ir/iropt.c @@ -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"); }