1 19 20 package soot.toolkits.scalar; 21 22 import java.util.*; 23 import soot.*; 24 import soot.options.*; 25 import soot.toolkits.graph.*; 26 import soot.util.*; 27 28 34 public class GuaranteedDefs 35 { 36 protected Map unitToGuaranteedDefs; 37 38 public GuaranteedDefs(UnitGraph graph) 39 { 40 if(Options.v().verbose()) 41 G.v().out.println("[" + graph.getBody().getMethod().getName() + 42 "] Constructing GuaranteedDefs..."); 43 44 GuaranteedDefsAnalysis analysis = new GuaranteedDefsAnalysis(graph); 45 46 { 48 unitToGuaranteedDefs = new HashMap(graph.size() * 2 + 1, 0.7f); 49 Iterator unitIt = graph.iterator(); 50 51 while(unitIt.hasNext()){ 52 Unit s = (Unit) unitIt.next(); 53 FlowSet set = (FlowSet) analysis.getFlowBefore(s); 54 unitToGuaranteedDefs.put 55 (s, Collections.unmodifiableList(set.toList())); 56 } 57 } 58 } 59 60 64 public List getGuaranteedDefs(Unit s) 65 { 66 return (List) unitToGuaranteedDefs.get(s); 67 } 68 } 69 70 74 class GuaranteedDefsAnalysis extends ForwardFlowAnalysis 75 { 76 FlowSet emptySet = new ArraySparseSet(); 77 Map unitToGenerateSet; 78 79 GuaranteedDefsAnalysis(UnitGraph graph) 80 { 81 super(graph); 82 DominatorsFinder df = new MHGDominatorsFinder(graph); 83 unitToGenerateSet = new HashMap(graph.size() * 2 + 1, 0.7f); 84 85 for(Iterator unitIt = graph.iterator(); unitIt.hasNext();){ 87 Unit s = (Unit) unitIt.next(); 88 FlowSet genSet = (FlowSet) emptySet.clone(); 89 90 for(Iterator domsIt = df.getDominators(s).iterator(); domsIt.hasNext();){ 91 Unit dom = (Unit) domsIt.next(); 92 for(Iterator boxIt = dom.getDefBoxes().iterator(); boxIt.hasNext();){ 93 ValueBox box = (ValueBox) boxIt.next(); 94 if(box.getValue() instanceof Local) 95 genSet.add(box.getValue(), genSet); 96 } 97 } 98 99 unitToGenerateSet.put(s, genSet); 100 } 101 102 doAnalysis(); 103 } 104 105 108 protected Object newInitialFlow() 109 { 110 return emptySet.clone(); 111 } 112 113 116 protected Object entryInitialFlow() 117 { 118 return emptySet.clone(); 119 } 120 121 124 protected void flowThrough(Object inValue, Object unit, Object outValue) 125 { 126 FlowSet 127 in = (FlowSet) inValue, 128 out = (FlowSet) outValue; 129 130 in.union((FlowSet) unitToGenerateSet.get(unit), out); 132 } 133 134 137 protected void merge(Object in1, Object in2, Object out) 138 { 139 FlowSet 140 inSet1 = (FlowSet) in1, 141 inSet2 = (FlowSet) in2, 142 outSet = (FlowSet) out; 143 144 inSet1.intersection(inSet2, outSet); 145 } 146 147 protected void copy(Object source, Object dest) 148 { 149 FlowSet 150 sourceSet = (FlowSet) source, 151 destSet = (FlowSet) dest; 152 153 sourceSet.copy(destSet); 154 } 155 } 156 | Popular Tags |