[Soot-list] qustion about loop fusion

John Jorgensen jorgnsn at lcd.uregina.ca
Mon Mar 27 22:26:41 EST 2006


>>>>> "caoj" == caoj  <caoj at purdue.edu> writes:

    caoj> Is there any function call in the soot to set
    caoj> "i" in the second loop to be the same as "i" in the
    caoj> first loop? 

Once you've identified the Local objects corresponding to the
index variables in the first loop and the second loop, something
as simple as this should work (where b is the method's Body):

  for (Iterator boxIt = b.getUseAndDefBoxes().iterator(); boxIt.hasNext(); ) {
    ValueBox box = (ValueBox) boxIt.next();
    if (box.getValue() == fromVar) {
      box.setValue(toVar);
    }
  }

You might be able to avoid looping through all the Values in the
Body by using one of the LocalDefs analyses to find all uses of
fromVar.  In itself that probably doesn't save any time (since
the LocalDefs analysis will have to iterate through the Body),
but you're likely doing some sort of variable use analysis
already in order to identify the loops which can be fused.

I think
src/soot/toolkits/scalar/{LocalSplitter.java,LocalPacker.java}
provide examples of changing local variables (and LocalSplitter
also illustrates how the variable splitting that leads your
original loop fuser to generate verification errors).

As I wrote that last sentence, it occurred to me that you might
be able to make your original transformation work by turning off
the LocalSplitter with the phase option:

  -p jb.ls enabled:false

but that would be a ugly kludge even if it works.

I haven't coded such transformations myself, so I may be unaware
of some superior techniques.  Hopefully other people on soot-list
will tell us about other possibilites.


More information about the Soot-list mailing list