| 1 19 20 25 26 27 package soot.jimple.toolkits.scalar; 28 import soot.options.*; 29 import soot.*; 30 import soot.toolkits.scalar.*; 31 import soot.toolkits.graph.*; 32 import soot.jimple.*; 33 import java.util.*; 34 import soot.util.*; 35 36 38 public class FastAvailableExpressions implements AvailableExpressions 39 { 40 Map unitToPairsAfter; 41 Map unitToPairsBefore; 42 Map unitToEquivsAfter; 43 Map unitToEquivsBefore; 44 45 46 public FastAvailableExpressions(Body b, SideEffectTester st) 47 { 48 if(Options.v().verbose()) 49 G.v().out.println("[" + b.getMethod().getName() + 50 "] Finding available expressions..."); 51 52 FastAvailableExpressionsAnalysis analysis = 53 new FastAvailableExpressionsAnalysis(new ExceptionalUnitGraph(b), 54 b.getMethod(), st); 55 56 { 58 unitToPairsAfter = new HashMap(b.getUnits().size() * 2 + 1, 0.7f); 59 unitToPairsBefore = new HashMap(b.getUnits().size() * 2 + 1, 0.7f); 60 unitToEquivsAfter = new HashMap(b.getUnits().size() * 2 + 1, 0.7f); 61 unitToEquivsBefore = new HashMap(b.getUnits().size() * 2 + 1, 0.7f); 62 63 Iterator unitIt = b.getUnits().iterator(); 64 65 while(unitIt.hasNext()) 66 { 67 Unit s = (Unit) unitIt.next(); 68 69 FlowSet set = (FlowSet) analysis.getFlowBefore(s); 70 71 List pairsBefore = new ArrayList(); 72 List pairsAfter = new ArrayList(); 73 74 Chain equivsBefore = new HashChain(); 75 Chain equivsAfter = new HashChain(); 76 77 if (set instanceof ToppedSet && 78 ((ToppedSet)set).isTop()) 79 throw new RuntimeException ("top! on "+s); 80 81 List setAsList = set.toList(); 82 Iterator si = setAsList.iterator(); 83 while (si.hasNext()) 84 { 85 Value v = (Value)si.next(); 86 Stmt containingStmt = (Stmt)analysis.rhsToContainingStmt.get(v); 87 UnitValueBoxPair p = new UnitValueBoxPair 88 (containingStmt, ((AssignStmt)containingStmt).getRightOpBox()); 89 pairsBefore.add(p); 90 91 EquivalentValue ev = new EquivalentValue(v); 92 if (!equivsBefore.contains(ev)) 93 equivsBefore.add(ev); 94 } 95 96 unitToPairsBefore.put(s, pairsBefore); 97 unitToEquivsBefore.put(s, equivsBefore); 98 99 set = (FlowSet) analysis.getFlowAfter(s); 100 setAsList = set.toList(); 101 si = setAsList.iterator(); 102 while (si.hasNext()) 103 { 104 Value v = (Value)si.next(); 105 Stmt containingStmt = (Stmt)analysis.rhsToContainingStmt.get(v); 106 UnitValueBoxPair p = new UnitValueBoxPair 107 (containingStmt, ((AssignStmt)containingStmt).getRightOpBox()); 108 pairsAfter.add(p); 109 110 EquivalentValue ev = new EquivalentValue(v); 111 if (!equivsAfter.contains(ev)) 112 equivsAfter.add(ev); 113 } 114 115 unitToPairsAfter.put(s, pairsAfter); 116 unitToEquivsAfter.put(s, equivsAfter); 117 } 118 } 119 120 if(Options.v().verbose()) 121 G.v().out.println("[" + b.getMethod().getName() + 122 "] Found available expressions..."); 123 } 124 125 126 public List getAvailablePairsBefore(Unit u) 127 { 128 return (List)unitToPairsBefore.get(u); 129 } 130 131 132 public Chain getAvailableEquivsBefore(Unit u) 133 { 134 return (Chain)unitToEquivsBefore.get(u); 135 } 136 137 138 public List getAvailablePairsAfter(Unit u) 139 { 140 return (List)unitToPairsAfter.get(u); 141 } 142 143 144 public Chain getAvailableEquivsAfter(Unit u) 145 { 146 return (Chain)unitToEquivsAfter.get(u); 147 } 148 } 149 150 | Popular Tags |