1 19 20 25 26 27 28 29 30 31 package soot.toolkits.scalar; 32 import soot.options.*; 33 34 import soot.*; 35 import soot.util.*; 36 import java.util.*; 37 import soot.jimple.*; 38 import soot.toolkits.graph.*; 39 40 41 44 public class SimpleLiveLocals implements LiveLocals 45 { 46 Map unitToLocalsAfter; 47 Map unitToLocalsBefore; 48 49 50 51 61 public SimpleLiveLocals(UnitGraph graph) 62 { 63 if(Options.v().time()) 64 Timers.v().liveTimer.start(); 65 66 if(Options.v().verbose()) 67 G.v().out.println("[" + graph.getBody().getMethod().getName() + 68 "] Constructing SimpleLiveLocals..."); 69 70 71 SimpleLiveLocalsAnalysis analysis = new SimpleLiveLocalsAnalysis(graph); 72 73 if(Options.v().time()) 74 Timers.v().livePostTimer.start(); 75 76 { 78 unitToLocalsAfter = new HashMap(graph.size() * 2 + 1, 0.7f); 79 unitToLocalsBefore = new HashMap(graph.size() * 2 + 1, 0.7f); 80 81 Iterator unitIt = graph.iterator(); 82 83 while(unitIt.hasNext()) 84 { 85 Unit s = (Unit) unitIt.next(); 86 87 FlowSet set = (FlowSet) analysis.getFlowBefore(s); 88 unitToLocalsBefore.put(s, Collections.unmodifiableList(set.toList())); 89 90 set = (FlowSet) analysis.getFlowAfter(s); 91 unitToLocalsAfter.put(s, Collections.unmodifiableList(set.toList())); 92 } 93 } 94 95 if(Options.v().time()) 96 Timers.v().livePostTimer.end(); 97 98 if(Options.v().time()) 99 Timers.v().liveTimer.end(); 100 } 101 102 public List getLiveLocalsAfter(Unit s) 103 { 104 return (List) unitToLocalsAfter.get(s); 105 } 106 107 public List getLiveLocalsBefore(Unit s) 108 { 109 return (List) unitToLocalsBefore.get(s); 110 } 111 } 112 113 class SimpleLiveLocalsAnalysis extends BackwardFlowAnalysis 114 { 115 FlowSet emptySet; 116 Map unitToGenerateSet; 117 Map unitToKillSet; 118 119 SimpleLiveLocalsAnalysis(UnitGraph g) 120 { 121 super(g); 122 123 if(Options.v().time()) 124 Timers.v().liveSetupTimer.start(); 125 126 emptySet = new ArraySparseSet(); 127 128 { 130 unitToKillSet = new HashMap(g.size() * 2 + 1, 0.7f); 131 132 Iterator unitIt = g.iterator(); 133 134 while(unitIt.hasNext()) 135 { 136 Unit s = (Unit) unitIt.next(); 137 138 FlowSet killSet = (FlowSet) emptySet.clone(); 139 140 Iterator boxIt = s.getDefBoxes().iterator(); 141 142 while(boxIt.hasNext()) 143 { 144 ValueBox box = (ValueBox) boxIt.next(); 145 146 if(box.getValue() instanceof Local) 147 killSet.add(box.getValue(), killSet); 148 } 149 150 unitToKillSet.put(s, killSet); 151 } 152 } 153 154 { 156 unitToGenerateSet = new HashMap(g.size() * 2 + 1, 0.7f); 157 158 Iterator unitIt = g.iterator(); 159 160 while(unitIt.hasNext()) 161 { 162 Unit s = (Unit) unitIt.next(); 163 164 FlowSet genSet = (FlowSet) emptySet.clone(); 165 166 Iterator boxIt = s.getUseBoxes().iterator(); 167 168 while(boxIt.hasNext()) 169 { 170 ValueBox box = (ValueBox) boxIt.next(); 171 172 if(box.getValue() instanceof Local) 173 genSet.add(box.getValue(), genSet); 174 } 175 176 unitToGenerateSet.put(s, genSet); 177 } 178 } 179 180 if(Options.v().time()) 181 Timers.v().liveSetupTimer.end(); 182 183 if(Options.v().time()) 184 Timers.v().liveAnalysisTimer.start(); 185 186 doAnalysis(); 187 188 if(Options.v().time()) 189 Timers.v().liveAnalysisTimer.end(); 190 191 } 192 193 protected Object newInitialFlow() 194 { 195 return emptySet.clone(); 196 } 197 198 protected Object entryInitialFlow() 199 { 200 return emptySet.clone(); 201 } 202 203 protected void flowThrough(Object inValue, Object unit, Object outValue) 204 { 205 FlowSet in = (FlowSet) inValue, out = (FlowSet) outValue; 206 207 in.difference((FlowSet) unitToKillSet.get(unit), out); 209 210 out.union((FlowSet) unitToGenerateSet.get(unit), out); 212 } 213 214 protected void merge(Object in1, Object in2, Object out) 215 { 216 FlowSet inSet1 = (FlowSet) in1, 217 inSet2 = (FlowSet) in2; 218 219 FlowSet outSet = (FlowSet) out; 220 221 inSet1.union(inSet2, outSet); 222 } 223 224 protected void copy(Object source, Object dest) 225 { 226 FlowSet sourceSet = (FlowSet) source, 227 destSet = (FlowSet) dest; 228 229 sourceSet.copy(destSet); 230 } 231 } 232 | Popular Tags |