[Soot-list] Redundant field access

Arie Zilberstein arie.zilberstein at gmail.com
Fri Mar 26 12:11:40 EDT 2010


Hi,

I want to be able to eliminate field accesses in loops. See the following
examples:

EXAMPLE 1:
for (int i=0; i<c.x; ++i)  { System.out.println("In loop"); }

What happens is that the field c.x is read at every iteration of the loop.
Is there any analysis in soot that is able to deduce that c.x is loop
invariant, and therefore store its value in a local variable (before
looping) and use it in the loop?
I hoped LazyCodeMotion analysis would do it, but it did not. Any ideas why?
I tried the unsafe mode and used whole program analysis.

EXAMPLE 2:
for (Integer integer : collection) { c.x += integer; }

What happens is that the field c.x is updated in every iteration of the
loop. I want to be able to rewrite this code, such that, the field c.x will
be updated only once, at the end of the loop. The loop would actually
increment a local variable instead of a field reference. Is there any
analysis that does that?

Your help is greatly appreciated.

Best,
Arie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20100326/cc73fddd/attachment.html 


More information about the Soot-list mailing list