Search in sources :

Example 1 with PushInst

use of soot.baf.PushInst in project soot by Sable.

the class StoreChainOptimizer method internalTransform.

@Override
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
    // We keep track of all the stored values
    Map<Local, Pair<Unit, Unit>> stores = new HashMap<Local, Pair<Unit, Unit>>();
    Set<Unit> toRemove = new HashSet<Unit>();
    Unit lastPush = null;
    for (Unit u : b.getUnits()) {
        // If we can jump here from somewhere, do not modify this code
        if (!u.getBoxesPointingToThis().isEmpty()) {
            stores.clear();
            lastPush = null;
        } else // Emulate pushing stuff on the stack
        if (u instanceof PushInst) {
            lastPush = u;
        } else if (u instanceof StoreInst && lastPush != null) {
            StoreInst si = (StoreInst) u;
            Pair<Unit, Unit> pushStorePair = stores.get(si.getLocal());
            if (pushStorePair != null) {
                // We can remove the push and the store
                toRemove.add(pushStorePair.getO1());
                toRemove.add(pushStorePair.getO2());
            }
            stores.put(si.getLocal(), new Pair<Unit, Unit>(lastPush, u));
        } else {
            // We're outside of the trivial initialization chain
            stores.clear();
            lastPush = null;
        }
    }
    b.getUnits().removeAll(toRemove);
}
Also used : PushInst(soot.baf.PushInst) StoreInst(soot.baf.StoreInst) HashMap(java.util.HashMap) Local(soot.Local) Unit(soot.Unit) Pair(soot.toolkits.scalar.Pair) HashSet(java.util.HashSet)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Local (soot.Local)1 Unit (soot.Unit)1 PushInst (soot.baf.PushInst)1 StoreInst (soot.baf.StoreInst)1 Pair (soot.toolkits.scalar.Pair)1