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);
}