[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Avoiding redundant loads in jimple



Hello,

I see that there are a lot of redundant loads in the jimple code. As a
result without some pre-processing, the analyzes may not be effective (at
least in my case). Also the number of stack locals increases due to this
-- however this is taken care of by local packer to some extent.

The simplest example is:
{
  x.member.fun();
  x.member.fun();
}

The pseudo-jimple code produced with default options is:
{
 $r0 = x.member;
 $r0.fun();
 $r1 = x.member;
 $r1.fun();
}

Instead, I would prefer to have:
{
 $r0 = x.member;
 $r0.fun();
 $r0.fun();
}

A little more formally, while generating a jimple load statement, Soot
should take into account if the value of right handside ( x.member ) is
already in exactly one stack local. (I say exactly one to take care of
merge of two branches where two branches load x.member into two different
stack locals). If yes dont generate another load and use the current
stack local instead.

If there is already a solution to this in Soot or anybody has done it
already please save me from that hack :).

Also if I have:
{
 x.member = new Member();
 x.member.fun();
}

I want to have:
{
 $r0 = new Member();
 x.member = $r0;
 $r0.fun();
}

instead of: (which soot produces)
{
 $r0 = new Member();
 x.member = $r0;
 $r1 = x.member;
 $r1.fun();
}

Thanks
Saswat