1 19 20 25 26 27 package soot.jimple.toolkits.scalar.pre; 28 import soot.*; 29 import soot.toolkits.scalar.*; 30 import soot.toolkits.graph.*; 31 import soot.jimple.toolkits.scalar.*; 32 import soot.jimple.*; 33 import java.util.*; 34 import soot.util.*; 35 36 56 public class EarliestnessComputation { 57 private Map unitToEarliest; 58 private SideEffectTester sideEffect; 59 60 70 public EarliestnessComputation(UnitGraph unitGraph, UpSafetyAnalysis upSafe, 71 DownSafetyAnalysis downSafe, SideEffectTester sideEffect) { 72 this(unitGraph, upSafe, downSafe, sideEffect, new ArraySparseSet()); 73 } 74 75 88 public EarliestnessComputation(UnitGraph unitGraph, UpSafetyAnalysis upSafe, 89 DownSafetyAnalysis downSafe, SideEffectTester sideEffect, FlowSet set) { 90 this.sideEffect = sideEffect; 91 92 unitToEarliest = new HashMap(unitGraph.size() + 1, 0.7f); 93 94 Iterator unitIt = unitGraph.iterator(); 95 while (unitIt.hasNext()) { 96 97 Unit currentUnit = (Unit)unitIt.next(); 98 FlowSet earliest = (FlowSet)set.emptySet(); 99 unitToEarliest.put(currentUnit, earliest); 100 101 102 FlowSet downSafeSet = 103 (FlowSet)((FlowSet)downSafe.getFlowBefore(currentUnit)).clone(); 104 105 List predList = unitGraph.getPredsOf(currentUnit); 106 if (predList.size() == 0) { 109 earliest.union(downSafeSet); 110 } else { 111 Iterator predIt = predList.iterator(); 112 while(predIt.hasNext()) { 113 Unit predecessor = (Unit)predIt.next(); 114 115 { 118 119 121 Iterator downSafeIt = downSafeSet.iterator(); 122 while (downSafeIt.hasNext()) { 123 EquivalentValue equiVal = (EquivalentValue)downSafeIt.next(); 124 Value avail = equiVal.getValue(); 125 if (avail instanceof FieldRef) { 126 if (sideEffect.unitCanWriteTo(predecessor, avail)) { 127 earliest.add(equiVal); 128 downSafeIt.remove(); 129 } 130 } else { 131 Iterator usesIt = avail.getUseBoxes().iterator(); 132 133 while (usesIt.hasNext()) { 135 Value use = ((ValueBox)usesIt.next()).getValue(); 136 137 if (sideEffect.unitCanWriteTo(predecessor, use)) { 138 earliest.add(equiVal); 139 downSafeIt.remove(); 140 break; 141 } 142 } 143 } 144 } 145 } 146 147 { 149 Iterator downSafeIt = downSafeSet.iterator(); 150 while (downSafeIt.hasNext()) { 151 EquivalentValue equiVal = (EquivalentValue)downSafeIt.next(); 152 Value avail = equiVal.getValue(); 153 FlowSet preDown = (FlowSet)downSafe.getFlowBefore(predecessor); 154 FlowSet preUp = (FlowSet)upSafe.getFlowBefore(predecessor); 155 if (!preDown.contains(equiVal) && !preUp.contains(equiVal)) { 156 earliest.add(equiVal); 157 downSafeIt.remove(); 158 } 159 } 160 } 161 } 162 } 163 } 164 } 165 166 173 public Object getFlowBefore(Object node) { 174 return unitToEarliest.get(node); 175 } 176 } 177 | Popular Tags |