soot.shimple.toolkits.scalar
Class SConstantPropagatorAndFolder

java.lang.Object
  |
  +--soot.Transformer
        |
        +--soot.BodyTransformer
              |
              +--soot.shimple.toolkits.scalar.SConstantPropagatorAndFolder

public class SConstantPropagatorAndFolder
extends BodyTransformer

An example of constant propagation using Shimple.

This analysis is already more powerful than the simplistic soot.jimple.toolkits.scalar.ConstantPropagatorAndFolder and demonstrates some of the benefits of SSA -- particularly the fact that Phi nodes represent natural merge points in the control flow. This implementation also shows how to access U/D and D/U chains in Shimple.

To use this analysis from the command line in Soot, try something like: soot.Main -f shimple -p sop on <classname> or soot.Main -f jimple --via-shimple -p sop on -p shimple naive-phi-elimination <classname>.

To compare the results with the non-SSA propagator, you can use (this disables all optimizations but constant propagation and folding): soot.Main -f jimple -p jop on -p jop.cpf on -p jop.cse off -p jop.bcm off -p off jop.lcm -p off jop.cp -p jop.cbf off -p jop.dae off -p jop.uce1 off -p jop.ubf1 off -p jop.uce2 off -p jop.ubf2 off -p jop.ubf2 off * <classname>

The analysis is based on the efficient linear algorithm described in section 1.1, P5 of the Cytron paper with the exception that conditional control flow is not considered (conservatively estimated). This is not necessarily the best implementation (in fact, it's a somewhat brute force approach to programming!) -- improvements and suggestions are welcome.

See Also:
ConstantPropagatorAndFolder, ShimpleLocalDefs, SimpleLocalUses, Efficiently Computing Static Single Assignment Form and the Control Dependence Graph

Field Summary
protected  ShimpleLocalDefs localDefs
           
protected  java.util.Map localToConstant
          Map that keeps track of our assumptions on whether a local is a constant or not.
protected  LocalUses localUses
           
 
Constructor Summary
SConstantPropagatorAndFolder(Singletons.Global g)
           
 
Method Summary
protected  void internalTransform(Body b, java.lang.String phaseName, java.util.Map options)
          This method is called to perform the transformation itself.
protected  boolean merge(Local local, Constant constant)
          Returns true if the merge changed anything in the corrected assumptions about local, and false otherwise.
protected  void propagate(Unit unit)
          Recursive flow analysis function.
static SConstantPropagatorAndFolder v()
           
 
Methods inherited from class soot.BodyTransformer
transform, transform, transform
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

localToConstant

protected java.util.Map localToConstant
Map that keeps track of our assumptions on whether a local is a constant or not. Initially we assume all Locals are TopConstant.

localDefs

protected ShimpleLocalDefs localDefs

localUses

protected LocalUses localUses
Constructor Detail

SConstantPropagatorAndFolder

public SConstantPropagatorAndFolder(Singletons.Global g)
Method Detail

v

public static SConstantPropagatorAndFolder v()

internalTransform

protected void internalTransform(Body b,
                                 java.lang.String phaseName,
                                 java.util.Map options)
Description copied from class: BodyTransformer
This method is called to perform the transformation itself. It is declared abstract; subclasses must implement this method by making it the entry point to their actual Body transformation.
Overrides:
internalTransform in class BodyTransformer
Tags copied from class: BodyTransformer
Parameters:
b - the body on which to apply the transformation
phaseName - the phasename for this transform; not typically used by implementations.
options - the actual computed options; a combination of default options and Scene specified options.

propagate

protected void propagate(Unit unit)
Recursive flow analysis function. Our assumptions are maintained in the localToConstant table. Initially all Locals are assumed to be the TopConstant and assumptions are corrected until there are no more changes.

This function observes a Unit and recursively updates assumptions if new defining information is found.


merge

protected boolean merge(Local local,
                        Constant constant)
Returns true if the merge changed anything in the corrected assumptions about local, and false otherwise.