01: package soot.jbco.bafTransformations;
02:
03: import java.util.*;
04:
05: import soot.*;
06: import soot.baf.*;
07: import soot.jbco.IJbcoTransform;
08: import soot.toolkits.graph.ExceptionalUnitGraph;
09: import soot.util.Chain;
10:
11: /**
12: * @author Michael Batchelder
13: *
14: * Created on 16-Jun-2006
15: */
16: public class RemoveRedundantPushStores extends BodyTransformer
17: implements IJbcoTransform {
18:
19: public static String dependancies[] = new String[] { "bb.jbco_rrps" };
20:
21: public String[] getDependancies() {
22: return dependancies;
23: }
24:
25: public static String name = "bb.jbco_rrps";
26:
27: public String getName() {
28: return name;
29: }
30:
31: public void outputSummary() {
32: }
33:
34: protected void internalTransform(Body b, String phaseName,
35: Map options) {
36: // removes all redundant load-stores
37: boolean changed = true;
38: PatchingChain units = b.getUnits();
39: while (changed) {
40: changed = false;
41: Unit prevprevprev = null, prevprev = null, prev = null;
42: ExceptionalUnitGraph eug = new ExceptionalUnitGraph(b);
43: Iterator it = units.snapshotIterator();
44: while (it.hasNext()) {
45: Unit u = (Unit) it.next();
46: if (prev != null && prev instanceof PushInst
47: && u instanceof StoreInst) {
48: if (prevprev != null
49: && prevprev instanceof StoreInst
50: && prevprevprev != null
51: && prevprevprev instanceof PushInst) {
52: Local lprev = ((StoreInst) prevprev).getLocal();
53: Local l = ((StoreInst) u).getLocal();
54: if (l == lprev
55: && eug.getSuccsOf(prevprevprev).size() == 1
56: && eug.getSuccsOf(prevprev).size() == 1) {
57: fixJumps(prevprevprev, prev, b.getTraps());
58: fixJumps(prevprev, u, b.getTraps());
59: units.remove(prevprevprev);
60: units.remove(prevprev);
61: changed = true;
62: break;
63: }
64: }
65: }
66: prevprevprev = prevprev;
67: prevprev = prev;
68: prev = u;
69: }
70: } // end while changes have been made
71: }
72:
73: private void fixJumps(Unit from, Unit to, Chain t) {
74: from.redirectJumpsToThisTo(to);
75: Iterator it = t.iterator();
76: while (it.hasNext()) {
77: Trap trap = (Trap) it.next();
78: if (trap.getBeginUnit() == from)
79: trap.setBeginUnit(to);
80: if (trap.getEndUnit() == from)
81: trap.setEndUnit(to);
82: if (trap.getHandlerUnit() == from)
83: trap.setHandlerUnit(to);
84: }
85: }
86: }
|